Crossover

Crossover

class gaggle.operators.crossover.crossover.Crossover(ga_args: GAArgs = None)[source]

Bases: object

The parent class for any Crossover Operator. It gives a basic function to crossover a whole population once the function for crossing over a single pair of parents is specified

children_per_crossover = 0
abstract crossover_individual(individuals: list[gaggle.population.individual.Individual]) list[gaggle.population.individual.Individual][source]

Speficies how to create children from parents :param individuals: a list of parents to crossover (typically 2)

Returns:

A list of children created from the parents (typically 2)

crossover_pop(manager: PopulationManager) PopulationManager[source]

Calls the crossover indivual operator over the whole popualtion while maintaining the protected parents For each pair of parents, crossover is called with probability ga_args.parent_survival_rate :param manager: PopulationManager object holding the current population

Returns:

Modified PopulationManager object

mates_per_crossover = 0

Crossover_factory module

class gaggle.operators.crossover.crossover_factory.CrossoverFactory[source]

Bases: object

Factory that generates pre-existing available crossover operators. CrossoverFactory.crossovers stores said crossover operators as a dictionary with their name as the key and the uninitialized crossover object as the value.

crossovers = {'k_point': <class 'gaggle.operators.crossover.base_crossovers.k_point_crossover.KPointCrossover'>, 'uniform': <class 'gaggle.operators.crossover.base_crossovers.uniform_crossover.UniformCrossover'>}
classmethod from_ga_args(ga_args: GAArgs = None) Crossover[source]

Initializes the requested crossover from the dictionary of available crossovers.

This is done by using the attribute ga_args.crossover as the lookup key to CrossoverFactory.crossovers.

Parameters:

ga_args – GAArgs object for the current run

Returns:

An initialized Crossover class object.

classmethod get_keys()[source]

Returns the list of currently registered crossovers

classmethod update(key, crossover)[source]

Add a new crossover operator to the dictionary of crossovers that can be created.

It is added to CrossoverFactory.crossovers

Parameters:
  • key – crossover name that will be used as the dictionary lookup key

  • crossover – Crossover class object, it needs to not be already initialized