# `FunctionSlot` – function slots module

The function slot concept is large used by Pyevolve, the idea is simple, each genetic operator or any operator, can be assigned to a slot, by this way, we can add more than simple one operator, we can have for example, two or more mutator operators at same time, two or more evaluation functions, etc. In this `FunctionSlot` module, you’ll find the class `FunctionSlot.FunctionSlot`, which is the slot class.

class `FunctionSlot.``FunctionSlot`(name='Anonymous Function', rand_apply=False)

  FunctionSlot Class - The function slot

  Example:

        >>> genome.evaluator.set(eval_func)
        >>> genome.evaluator[0]
        <function eval_func at 0x018C8930>
        >>> genome.evaluator
        Slot [Evaluation Function] (Count: 1)
                  Name: eval_func
        >>> genome.evaluator.clear()
        >>> genome.evaluator
        Slot [Evaluation Function] (Count: 0)
                  No function

  You can add weight to functions when using the rand_apply paramter:

        >>> genome.evaluator.set(eval_main, 0.9)
        >>> genome.evaluator.add(eval_sec,  0.3)
        >>> genome.evaluator.setRandomApply()

  In the above example, the function eval_main will be called with 90% of probability and the eval_sec will be called with 30% of probability.

  There are another way to add functions too:

        >>> genome.evaluator += eval_func

  Parameters:

  - name – the slot name
  - rand_apply – if True, just one of the functions in the slot will be applied, this function is randomly picked based on the weight of the function added.

  `add`(func, weight=0.5)

    Used to add a function to the slot

    Parameters:

    - func – the function to be added in the slot
    - weight – used when you enable the random apply, it’s the weight of the function for the random selection

    New in version 0.6: The weight parameter.

  `apply`(index, obj, **args)

    Apply the index function

    Parameters:

    - index – the index of the function
    - obj – this object is passes as parameter to the function
    - args – this args dictionary is passed to the function

  `applyFunctions`(obj=None, **args)

    Generator to apply all function slots in obj

    Parameters:

    - obj – this object is passes as parameter to the function
    - args – this args dictionary is passed to the function

  `clear`()

    Used to clear the functions in the slot

  `isEmpty`()

    Return true if the function slot is empy

  `set`(func, weight=0.5)

    Used to clear all functions in the slot and add one

    Parameters:

    - func – the function to be added in the slot
    - weight – used when you enable the random apply, it’s the weight of the function for the random selection

    New in version 0.6: The weight parameter.

    Note

    the method set of the function slot remove all previous functions added to the slot.

  `setRandomApply`(flag=True)

    Sets the random function application, in this mode, the function will randomly choose one slot to apply

    Parameters: | flag – True or False