Base

class Fitness(values=None)

A fitness object measures the quality of a solution. The class attribute ‘weights’ must be set before a Fitness object can be instantiated. A fitness can be instantiated without arguments, but the fitness then remains invalid until a valid sequence of numbers has been assigned to the ‘values’ property.

Parameters

values (SeqOfNum) – The values of the fitness object, optional.

weights: tuple = ()

The weights are used to compare the fitness of different individuals. They are shared between all individuals of the same type. When subclassing ‘Fitness’, the ‘weights’ class attribute must be a tuple of real numbers, where each element is associated to an objective: a negative weight element corresponds to the minimization and a positive weight to the maximization of the associated objective.

wvalues: tuple = ()

Contains the weighted values of the fitness. These are obtained by multiplying the fitness values by the weights. It is generally unnecessary to manipulate this attribute directly, as it’s mostly used internally by the Fitness comparison operators.

property values: Iterable[float]

Fitness values of the individual. The setter accepts either a number or a sequence of numbers as input. If the input is a number, it is added as the first element of an empty tuple. The getter returns a tuple of floats and the deleter sets the internal ‘wvalues’ attribute to an empty tuple.

dominates(other, slc=None)

Returns true if each objective of ‘self’ is not worse than the corresponding objective of the other and at least one objective of ‘self’ is better.

Parameters
  • other (Fitness) – An instance of Fitness to test against.

  • slc (Optional[slice]) – A slice of objectives to test for domination, optional.

Returns

True if ‘self’ dominates the ‘other’.

Return type

bool

is_valid()

A Fitness instance is valid when the Fitness ‘weights’ class attribute length is larger than 0 and the instance property ‘values’ has the same length as the ‘weights’ attribute.

Returns

True if the Fitness instance is valid.

Return type

bool

class Toolbox

A container for evolutionary operators. Toolboxes are essential components which facilitate the process of computational evolution.

register(alias, func, *args, **kwargs)

Registers a func in the toolbox under the name alias. Any args or kwargs will be automatically passed to the registered function when it’s called. Fixed arguments can be overridden at function call time.

Parameters
  • alias (str) – The name to register the ‘func’ under. The alias will be overwritten if it already exists.

  • func (Callable) – The function to which the alias is going to refer.

  • args (Optional) – Positional arguments which are automatically passed to the ‘func’ when it’s called, optional.

  • kwargs (Optional) – Keyword arguments which are automatically passed to the ‘func’ when it’s called, optional.

Returns

Nothing.

Return type

None

unregister(alias)

Removes an operator with the name alias from the toolbox.

Parameters

alias (str) – The name of the operator to remove from the toolbox.

Returns

Nothing.

Return type

None

decorate(alias, *decorators)

Decorates an operator alias with the provided decorators.

Parameters
  • alias (str) – Name of the operator to decorate. The ‘alias’ must be a registered operator in the toolbox.

  • decorators (Optional[Callable]) – Positional arguments of decorator functions to apply to the ‘alias’, optional. If none are provided, the operator is left unchanged. If multiple are provided, they are applied in order of iteration over the ‘decorators’.