opytimizer.optimizers.evolutionary.ga

Genetic Algorithm.

class opytimizer.optimizers.evolutionary.ga.GA(params: Optional[Dict[str, Any]] = None)

An GA class, inherited from Optimizer.

This is the designed class to define GA-related variables and methods.

References

  1. Mitchell. An introduction to genetic algorithms. MIT Press (1998).
__init__(params: Optional[Dict[str, Any]] = None) → None

Initialization method.

Parameters:params – Contains key-value parameters to the meta-heuristics.
p_selection

Probability of selection.

p_mutation

Probability of mutation.

p_crossover

Probability of crossover.

_roulette_selection(n_agents: int, fitness: List[float]) → List[int]

Performs a roulette selection on the population (p. 8).

Parameters:
  • n_agents – Number of agents allowed in the space.
  • fitness – A fitness list of every agent.
Returns:

The selected indexes of the population.

Return type:

(List[int])

_crossover(father: opytimizer.core.agent.Agent, mother: opytimizer.core.agent.Agent) → Tuple[opytimizer.core.agent.Agent, opytimizer.core.agent.Agent]

Performs the crossover between a pair of parents (p. 8).

Parameters:
  • father – Father to produce the offsprings.
  • mother – Mother to produce the offsprings.
Returns:

Two generated offsprings based on parents.

Return type:

(Tuple[Agent, Agent])

_mutation(alpha: opytimizer.core.agent.Agent, beta: opytimizer.core.agent.Agent) → Tuple[opytimizer.core.agent.Agent, opytimizer.core.agent.Agent]

Performs the mutation over offsprings (p. 8).

Parameters:
  • alpha – First offspring.
  • beta – Second offspring.
Returns:

Two mutated offsprings.

Return type:

(Tuple[Agent, Agent])

update(space: opytimizer.core.space.Space, function: opytimizer.core.function.Function) → None

Wraps Genetic Algorithm over all agents and variables.

Parameters:
  • space – Space containing agents and update-related information.
  • function – A Function object that will be used as the objective function.