Operators

Subpackages

Submodules

pygenalgo.operators.genetic_operator module

class pygenalgo.operators.genetic_operator.GeneticOperator(probability: float)[source]

Bases: object

Description:

Provides the parent class (interface) for a Genetic Operator. This class includes the common variables, such as the probability and the application counter, along with access to them.

All genetic operators (Selection, Crossover, Mutation, Migration) should inherit this class.

property counter: int

Accessor (getter) of the application counter.

Returns:

the int value of the counter variable.

inc_counter() None[source]

Increase the counter value by one. This is applied after each application of the genetic operator.

Returns:

None.

is_operator_applicable() bool[source]

Since to apply a genetic operator we have to check it probabilistically, we set the condition in here so that the objects inheriting from this class can call only this function.

If the genetic probability is higher than a uniformly random value, apply the operator’s changes.

Returns:

(bool) the output of the: probability > U(0,1).

property items: Any

Accessor (getter) of the _items container.

Returns:

_items (if any).

property iteration: int

Accessor (getter) of the iteration parameter.

Returns:

the iteration value.

property probability: float

Accessor (getter) of the probability.

Returns:

the float value of the probability.

reset_counter() None[source]

Sets the counter value to zero.

Returns:

None.

property rng: Generator

Get access of the Class variable (_rng).

Returns:

the random number generator.

classmethod set_iteration(value: int) None[source]

Accessor (setter) of the iteration value.

Parameters:

value – (int).

classmethod set_seed(new_seed=None) None[source]

Sets a new seed for the random number generator.

Parameters:

new_seed – New seed value (default=None).

Returns:

None.

pygenalgo.operators.genetic_operator.increase_counter(method)[source]

Decorator function that is used in the derived classes main operation to increase the counter by one.

Parameters:

method – that we wrap its functionality.

Returns:

the wrapper function.

Module contents