This class represents a basic (\(\mu+\lambda\)) genetic algorithm for single-objective problems. The figure below shows the flow of a genetic algorithm in general. In the following, it is explained how pymoo does allow to customize the modules.
Initial Population:: A starting population is sampled in the beginning. In this framework, this can be either a Sampling object, which defines different initial sampling strategies, or Population where the X and F values are set, or a simple numpy array (pop_size x n_var).
Evaluation: It is executed using the problem defined to be solved.
Survival: It is very often the core of the genetic algorithm that is used. For simple single-objective genetic algorithm, the individuals can be sorted by their fitness and survival of the fittest can be applied.
Selection: In the beginning of the recombination process individuals need to be selected to participate in mating. Depending on the recombination crossover a different number of parents is is used to select some individual to be the parents of a new offspring. Different kind of selections can increase the convergence of the algorithm.
Crossover: When the parents are selected the actual mating is done. A crossover operator combines parents into one or several offspring. Commonly, problem information, such as the variable bounds, are needed to perform the mating. For more customized problems even more information might be necessary (e.g. current generation, diversity measure of the population, …)
Mutation: It is performed after the offsprings are created through crossover. Usually, the mutation is executed with a predefined probability. This operator helps to increase the diversity in the population.
from pymoo.algorithms.so_genetic_algorithm import GA from pymoo.factory import get_problem from pymoo.optimize import minimize problem = get_problem("g01") algorithm = GA( pop_size=100, eliminate_duplicates=True) res = minimize(problem, algorithm, termination=('n_gen', 50), verbose=False) print("Best solution found: \nX = %s\nF = %s" % (res.X, res.F))
Best solution found: X = [0.99303414 0.99782661 0.99754116 0.99912976 0.99483 0.99544777 0.98882008 0.97191879 0.9899395 2.9192581 2.80936782 2.33122498 0.9894118 ] F = [-13.92817742]
GA(pop_size=100, sampling=<pymoo.operators.sampling.random_sampling.FloatRandomSampling object>, selection=<pymoo.operators.selection.tournament_selection.TournamentSelection object>, crossover=<pymoo.operators.crossover.simulated_binary_crossover.SimulatedBinaryCrossover object>, mutation=<pymoo.operators.mutation.polynomial_mutation.PolynomialMutation object>, eliminate_duplicates=True, n_offsprings=None, **kwargs)
This class represents the abstract class for any algorithm to be implemented. Most importantly it provides the solve method that is used to optimize a given problem.
The solve method provides a wrapper function which does validate the input.
- problem: class
Problem to be solved by the algorithm
- termination: class
Object that tells the algorithm when to terminate.
- seed: int
Random seed to be used. Same seed is supposed to return the same result. If set to None, a random seed is chosen randomly and stored in the result object to ensure reproducibility.
If true information during the algorithm execution are displayed
A callback function can be passed that is executed every generation. The parameters for the function are the algorithm itself, the number of evaluations so far and the current population.
- def callback(algorithm):
If true, a current snapshot of each generation is saved.
The Pareto-front for the given problem. If provided performance metrics are printed during execution.
The evaluator which can be used to make modifications before calling the evaluate function of a problem.