platypus.algorithms module

class platypus.algorithms.AbstractGeneticAlgorithm(problem, population_size=100, generator=<platypus.operators.RandomGenerator object>, **kwargs)

Abstract class for genetic algorithms.

Generally speaking, optimization algorithms based on genetic algorithms involve:

  1. Initialization, where the population is filled with random solutions.

  2. Mating selection, where the parents for mating are selected using some preference.

  3. Recombination, where any crossover or mutation operators are applied to produce offspring.

  4. Survival selection, where the content of the next generation is selected.

Parameters

problemProblem

The problem to optimize.

population_sizeint

The size of the population.

generatorGenerator

The method for generating the initial population.

initialize()

Initializes the algorithm.

This method is called exactly once on the first call to step() to initialize the population. Subclasses can use this perform any other initialization required.

abstract iterate()

Performs one iteration of the algorithm.

The definition of an iteration depends on the specific algorithm, which could mean evolving the entire population (generational) or a single solution.

At a minimum, this method must produce and evaluate at least one offspring (to avoid an infinite loop). If the offspring is selected to survive to the next iteration, update the population.

step()

Performs one logical step of the algorithm.

In most contexts, the first invocation to step should initialize the algorithm, usually generating an initial population randomly. All subsequent calls to step evolve the population one “generation”.

Each step is expected to geneate and evaluate at least one solution in order to avoid looping indenfinitely. Any termination conditions and callbacks are called after each step.

class platypus.algorithms.AdaptiveTimeContinuation(algorithm, window_size=100, max_window_size=1000, population_ratio=4.0, min_population_size=10, max_population_size=10000, mutator=<platypus.operators.UM object>)

Wraps an algorithm to enable adaptive time continuation.

Adaptive time continuation performs two key functions:

First, it scales the population based on the size of the archive. The idea being a larger archive, with more non-dominated solutions, requires a larger population to cover the search space.

Second, it periodically introduces extra randomness or diversity into the population. This helps avoid or escape local optima.

Parameters

algorithmAlgorithm

The underlying algorithm.

window_sizeint

The number of iterations between calls to check().

max_window_sizeint

The maximum number of iterations before a restart is required.

population_ratofloat

The ratio between the desired population size and archive size, used to scale the population size after each restart.

min_population_sizeint

The minimum allowed population size.

max_population_sizeint

The maximum allowed population size.

mutatorVariator

The mutation operator applied during restarts to introduce additional randomness or diversity into the population. Must have an arity of 1.

check()

Checks if a restart is required.

do_action()

Performs the action.

restart()

Performs the restart procedure.

class platypus.algorithms.CMAES(problem, offspring_size=100, cc=None, cs=None, damps=None, ccov=None, ccovsep=None, sigma=None, diagonal_iterations=0, indicator='crowding', initial_search_point=None, check_consistency=False, epsilons=None, **kwargs)

Covariance matrix adaption evolution strategy (CMA-ES).

step()

Performs one logical step of the algorithm.

In most contexts, the first invocation to step should initialize the algorithm, usually generating an initial population randomly. All subsequent calls to step evolve the population one “generation”.

Each step is expected to geneate and evaluate at least one solution in order to avoid looping indenfinitely. Any termination conditions and callbacks are called after each step.

class platypus.algorithms.EpsMOEA(problem, epsilons, population_size=100, generator=<platypus.operators.RandomGenerator object>, selector=<platypus.operators.TournamentSelector object>, variator=None, **kwargs)

\epsilon-MOEA.

Uses an epsilon-dominance archive to bound the size of the archive. Additionally, mating occurs between a member of the population and a member of the archive.

See EpsilonBoxArchive for more details on epsilon dominance.

Parameters

problemProblem

The problem to optimize.

epsilonslist of float

The epsilon values.

population_sizeint

The size of the population.

generatorGenerator

The method for generating the initial population.

selectorSelector

The method for selecting parents for mating.

variatorVariator, optional

The variator used during mating to produce offspring. If None, the default variator configured in PlatypusConfig is selected.

initialize()

Initializes the algorithm.

This method is called exactly once on the first call to step() to initialize the population. Subclasses can use this perform any other initialization required.

iterate()

Performs one iteration of the algorithm.

The definition of an iteration depends on the specific algorithm, which could mean evolving the entire population (generational) or a single solution.

At a minimum, this method must produce and evaluate at least one offspring (to avoid an infinite loop). If the offspring is selected to survive to the next iteration, update the population.

step()

Performs one logical step of the algorithm.

In most contexts, the first invocation to step should initialize the algorithm, usually generating an initial population randomly. All subsequent calls to step evolve the population one “generation”.

Each step is expected to geneate and evaluate at least one solution in order to avoid looping indenfinitely. Any termination conditions and callbacks are called after each step.

class platypus.algorithms.EpsNSGAII(problem, epsilons, population_size=100, generator=<platypus.operators.RandomGenerator object>, selector=<platypus.operators.TournamentSelector object>, variator=None, **kwargs)

Epsilon-dominance NSGA-II (\epsilon-NSGA-II).

Extends NSGA-II to use an epsilon-dominance archive to track the best solutions found during search. This is essentially a form of elitism for multi-objective problems.

Parameters

problemProblem

The problem to optimize.

epsilonslist of float

The epsilons used to configure the epsilon-dominance archive.

population_sizeint

The size of the population.

generatorGenerator

The method for generating the initial population.

selectorSelector

The method for selecting parents for mating.

variatorVariator, optional

The variator used during mating to produce offspring. If None, the default variator configured in PlatypusConfig is selected.

class platypus.algorithms.EpsilonProgressContinuation(algorithm, window_size=100, max_window_size=1000, population_ratio=4.0, min_population_size=10, max_population_size=10000, mutator=<platypus.operators.UM object>)

Wraps an algorithm to enable epsilon-progress continuation.

Epsilon-progress continuation extends adaptive time continuation to also track the number of improvements made in the EpsilonBoxArchive. A restart is triggered if no improvements were recorded, as that often occurs when the algorithm as converged to a local optima.

Parameters

algorithmAlgorithm

The underlying algorithm.

window_sizeint

The number of iterations between calls to check().

max_window_sizeint

The maximum number of iterations before a restart is required.

population_ratofloat

The ratio between the desired population size and archive size, used to scale the population size after each restart.

min_population_sizeint

The minimum allowed population size.

max_population_sizeint

The maximum allowed population size.

mutatorVariator

The mutation operator applied during restarts to introduce additional randomness or diversity into the population. Must have an arity of 1.

check()

Checks if a restart is required.

restart()

Performs the restart procedure.

class platypus.algorithms.EvolutionaryStrategy(problem, population_size=100, offspring_size=100, generator=<platypus.operators.RandomGenerator object>, comparator=<platypus.core.ParetoDominance object>, variator=None, **kwargs)

Single-objective evolutionary strategy (ES).

Parameters

problemProblem

The problem to optimize.

population_sizeint

The size of the population.

offspring_sizeint

The number of offspring to generate each iteration.

generatorGenerator

The method for generating the initial population.

comparatorDominance

The dominance criteria for ranking solutions.

variatorVariator, optional

The variator used during mating to produce offspring. Must have an arity of 1. If None, the default mutation configured in PlatypusConfig is selected.

initialize()

Initializes the algorithm.

This method is called exactly once on the first call to step() to initialize the population. Subclasses can use this perform any other initialization required.

iterate()

Performs one iteration of the algorithm.

The definition of an iteration depends on the specific algorithm, which could mean evolving the entire population (generational) or a single solution.

At a minimum, this method must produce and evaluate at least one offspring (to avoid an infinite loop). If the offspring is selected to survive to the next iteration, update the population.

class platypus.algorithms.GDE3(problem, population_size=100, generator=<platypus.operators.RandomGenerator object>, variator=<platypus.operators.DifferentialEvolution object>, **kwargs)

Generalized differential evolution (GDE3).

Only supporting real-valued problems, GDE3 uses differential evolution to evolve the population.

Parameters

problemProblem

The problem to optimize.

population_sizeint

The size of the population.

generatorGenerator

The method for generating the initial population.

variatorVariator

The variator used during mating to produce offspring. Must use the differential evolution operator.

initialize()

Initializes the algorithm.

This method is called exactly once on the first call to step() to initialize the population. Subclasses can use this perform any other initialization required.

iterate()

Performs one iteration of the algorithm.

The definition of an iteration depends on the specific algorithm, which could mean evolving the entire population (generational) or a single solution.

At a minimum, this method must produce and evaluate at least one offspring (to avoid an infinite loop). If the offspring is selected to survive to the next iteration, update the population.

class platypus.algorithms.GeneticAlgorithm(problem, population_size=100, offspring_size=100, generator=<platypus.operators.RandomGenerator object>, selector=<platypus.operators.TournamentSelector object>, comparator=<platypus.core.ParetoDominance object>, variator=None, **kwargs)

Single-objective genetic algorithm (GA).

A genetic algorithm is a generational algorithm that evolves a population of solutions. Each iteration, some number of offspring are produced by applying the given selection and variation operators. Then, the combined population of parents and offspring are ranked according to the comparison operator and truncated.

This implementation keeps track of the fittest individual in the population, ensuring it always survives to the next generation.

Parameters

problemProblem

The problem to optimize.

population_sizeint

The size of the population.

offspring_sizeint

The number of offspring to generate each iteration.

generatorGenerator

The method for generating the initial population.

selectorSelector

The method for selecting parents for mating.

comparatorDominance

The dominance criteria for ranking solutions.

variatorVariator, optional

The variator used during mating to produce offspring. If None, the default variator configured in PlatypusConfig is selected.

Attributes

fittestSolution

The fittest solution found thus far.

initialize()

Initializes the algorithm.

This method is called exactly once on the first call to step() to initialize the population. Subclasses can use this perform any other initialization required.

iterate()

Performs one iteration of the algorithm.

The definition of an iteration depends on the specific algorithm, which could mean evolving the entire population (generational) or a single solution.

At a minimum, this method must produce and evaluate at least one offspring (to avoid an infinite loop). If the offspring is selected to survive to the next iteration, update the population.

class platypus.algorithms.IBEA(problem, population_size=100, generator=<platypus.operators.RandomGenerator object>, fitness_evaluator=<platypus.core.HypervolumeFitnessEvaluator object>, fitness_comparator=<platypus.core.AttributeDominance object>, variator=None, **kwargs)

Indicator-based evolutionary algorithm (IBEA).

Uses a FitnessEvaluator to measure the fitness of solutions, typically based on hypervolume.

Parameters

problemProblem

The problem to optimize.

population_sizeint

The size of the population.

generatorGenerator

The method for generating the initial population.

fitness_evaluatorFitnessEvaluator

The method for computing the fitness of solutions. Default uses hypervolume.

fitness_comparatorDominance

The domnance criteria using the fitness value.

variatorVariator

The variator used during mating to produce offspring. If None, the default variator configured in PlatypusConfig is selected.

initialize()

Initializes the algorithm.

This method is called exactly once on the first call to step() to initialize the population. Subclasses can use this perform any other initialization required.

iterate()

Performs one iteration of the algorithm.

The definition of an iteration depends on the specific algorithm, which could mean evolving the entire population (generational) or a single solution.

At a minimum, this method must produce and evaluate at least one offspring (to avoid an infinite loop). If the offspring is selected to survive to the next iteration, update the population.

class platypus.algorithms.MOEAD(problem, neighborhood_size=10, generator=<platypus.operators.RandomGenerator object>, variator=None, delta=0.8, eta=1, update_utility=None, weight_generator=<function random_weights>, scalarizing_function=<function chebyshev>, **kwargs)

Multiobjective evolutionary algorithm with decomposition (MOEA/D).

initialize()

Initializes the algorithm.

This method is called exactly once on the first call to step() to initialize the population. Subclasses can use this perform any other initialization required.

iterate()

Performs one iteration of the algorithm.

The definition of an iteration depends on the specific algorithm, which could mean evolving the entire population (generational) or a single solution.

At a minimum, this method must produce and evaluate at least one offspring (to avoid an infinite loop). If the offspring is selected to survive to the next iteration, update the population.

class platypus.algorithms.NSGAII(problem, population_size=100, generator=<platypus.operators.RandomGenerator object>, selector=<platypus.operators.TournamentSelector object>, variator=None, archive=None, **kwargs)

Non-dominated sorting genetic algorithm (NSGA-II).

Most notably, NSGA-II uses non-dominated sorting during survival selection to assign rank and crowding distance values to solutions. The next generation is filled with solutions with lower ranks. When selecting from the last rank, solutions with larger crowding distances (more diverse) are preferred.

See nondominated_sort() for more details on non-dominated sorting.

Parameters

problemProblem

The problem to optimize.

population_sizeint

The size of the population.

generatorGenerator

The method for generating the initial population.

selectorSelector

The method for selecting parents for mating.

variatorVariator, optional

The variator used during mating to produce offspring. If None, the default variator configured in PlatypusConfig is selected.

archiveArchive, optional

The archive to store the best solutions found during optimization.

initialize()

Initializes the algorithm.

This method is called exactly once on the first call to step() to initialize the population. Subclasses can use this perform any other initialization required.

iterate()

Performs one iteration of the algorithm.

The definition of an iteration depends on the specific algorithm, which could mean evolving the entire population (generational) or a single solution.

At a minimum, this method must produce and evaluate at least one offspring (to avoid an infinite loop). If the offspring is selected to survive to the next iteration, update the population.

step()

Performs one logical step of the algorithm.

In most contexts, the first invocation to step should initialize the algorithm, usually generating an initial population randomly. All subsequent calls to step evolve the population one “generation”.

Each step is expected to geneate and evaluate at least one solution in order to avoid looping indenfinitely. Any termination conditions and callbacks are called after each step.

class platypus.algorithms.NSGAIII(problem, divisions_outer, divisions_inner=0, generator=<platypus.operators.RandomGenerator object>, selector=<platypus.operators.TournamentSelector object>, variator=None, **kwargs)

Non-dominated sorting genetic algorithm with reference ponts (NSGA-III).

Replaces NSGA-II’s crowding distance-based selection with one using reference points. At a high level, the advantage of reference points is two-fold. First, they can provide a better distribution of points, especially on problems with many objectives where most solutions tend to be non-dominated. Second, the reference points can be selected to target specific regions of interest.

Parameters

problemProblem

The problem to optimize.

divisions_outerint

The number of divisions. When divisions_inner is non-zero, this represents the number of outer divisions.

divisions_innerint

The number of inner divisions.

generatorGenerator

The method for generating the initial population.

selectorSelector

The method for selecting parents for mating.

variatorVariator

The variator used during mating to produce offspring. Must use the differential evolution operator.

initialize()

Initializes the algorithm.

This method is called exactly once on the first call to step() to initialize the population. Subclasses can use this perform any other initialization required.

iterate()

Performs one iteration of the algorithm.

The definition of an iteration depends on the specific algorithm, which could mean evolving the entire population (generational) or a single solution.

At a minimum, this method must produce and evaluate at least one offspring (to avoid an infinite loop). If the offspring is selected to survive to the next iteration, update the population.

class platypus.algorithms.OMOPSO(problem, epsilons, swarm_size=100, leader_size=100, generator=<platypus.operators.RandomGenerator object>, mutation_probability=0.1, mutation_perturbation=0.5, max_iterations=100, **kwargs)

Multi-objective particle swarm optimizer (OMOPSO).

Notably, OMOPSO introduces a uniform and non-uniform mutation operator that are applied to offspring. The non-uniform operator scales itself based on the maximum number of iterations, reducing the magnitude of mutations as the run progresses.

Parameters

problemProblem

The problem to optimize.

epsilonslist of float

The epsilons controlling the size of the epsilon-dominance archive.

swarm_sizeint

The size of the swarm (synonymous to a population).

leader_sizeint

The number of leaders to track (synonymous to an archive).

generatorGenerator

The method for generating the initial population.

mutation_probabilityfloat

The probability of mutation.

mutation_perturbationfloat

Controls the distribution of offspring produced by mutation.

max_iterationsint

The maximum number of iterations you expect to run this algorithm. This controls how quickly the non-uniform mutation scales.

step()

Performs one logical step of the algorithm.

In most contexts, the first invocation to step should initialize the algorithm, usually generating an initial population randomly. All subsequent calls to step evolve the population one “generation”.

Each step is expected to geneate and evaluate at least one solution in order to avoid looping indenfinitely. Any termination conditions and callbacks are called after each step.

class platypus.algorithms.PAES(problem, divisions=8, capacity=100, generator=<platypus.operators.RandomGenerator object>, variator=None, **kwargs)

Pareto archived evolutionary strategy (PAES).

Uses an adaptive grid archive to maintain a set of diverse solutions. See AdaptiveGridArchive for more details.

Parameters

problemProblem

The problem to optimize.

divisionsint

The number of divisions used by the adaptive grid archive.

capacityint

The maximum capacity of the adaptive grid archive.

generatorGenerator

The method for generating the initial population.

variatorVariator

The variator used during mating to produce offspring. If None, the default variator configured in PlatypusConfig is selected.

initialize()

Initializes the algorithm.

This method is called exactly once on the first call to step() to initialize the population. Subclasses can use this perform any other initialization required.

iterate()

Performs one iteration of the algorithm.

The definition of an iteration depends on the specific algorithm, which could mean evolving the entire population (generational) or a single solution.

At a minimum, this method must produce and evaluate at least one offspring (to avoid an infinite loop). If the offspring is selected to survive to the next iteration, update the population.

step()

Performs one logical step of the algorithm.

In most contexts, the first invocation to step should initialize the algorithm, usually generating an initial population randomly. All subsequent calls to step evolve the population one “generation”.

Each step is expected to geneate and evaluate at least one solution in order to avoid looping indenfinitely. Any termination conditions and callbacks are called after each step.

class platypus.algorithms.PESA2(problem, population_size=100, divisions=8, capacity=100, generator=<platypus.operators.RandomGenerator object>, variator=None, **kwargs)

Pareto envelope-based selection algorithm (PESA2).

Uses an adaptive grid archive to maintain a set of diverse solutions. See AdaptiveGridArchive for more details.

Parameters

problemProblem

The problem to optimize.

population_sizeint

The size of the population.

divisionsint

The number of divisions used by the adaptive grid archive.

capacityint

The maximum capacity of the adaptive grid archive.

generatorGenerator

The method for generating the initial population.

variatorVariator

The variator used during mating to produce offspring. If None, the default variator configured in PlatypusConfig is selected.

initialize()

Initializes the algorithm.

This method is called exactly once on the first call to step() to initialize the population. Subclasses can use this perform any other initialization required.

iterate()

Performs one iteration of the algorithm.

The definition of an iteration depends on the specific algorithm, which could mean evolving the entire population (generational) or a single solution.

At a minimum, this method must produce and evaluate at least one offspring (to avoid an infinite loop). If the offspring is selected to survive to the next iteration, update the population.

step()

Performs one logical step of the algorithm.

In most contexts, the first invocation to step should initialize the algorithm, usually generating an initial population randomly. All subsequent calls to step evolve the population one “generation”.

Each step is expected to geneate and evaluate at least one solution in order to avoid looping indenfinitely. Any termination conditions and callbacks are called after each step.

class platypus.algorithms.ParticleSwarm(problem, swarm_size=100, leader_size=100, generator=<platypus.operators.RandomGenerator object>, mutate=None, leader_comparator=<platypus.core.AttributeDominance object>, dominance=<platypus.core.ParetoDominance object>, fitness=None, larger_preferred=True, fitness_getter=<function fitness_key>, **kwargs)

Abstract class for particle swarm optimization (PSO) algorithms.

Parameters

problemProblem

The problem to optimize.

swarm_sizeint

The size of the swarm (synonymous to a population).

leader_sizeint

The number of leaders to track (synonymous to an archive).

generatorGenerator

The method for generating the initial population.

mutateVariator

The mutation used during mating to produce offspring. Must have an arity of 1.

leader_comparatorDominance

The dominance criteria for selecting leaders.

dominanceDominance

The dominance criteria for ranking solutions.

fitnessCallable

Function for measuring the fitness of solutions.

larger_preferredboolean

Indicates if larger or smaller fitness values are preferred.

fitness_getterCallable

Function to read the fitness value assigned to solutions.

step()

Performs one logical step of the algorithm.

In most contexts, the first invocation to step should initialize the algorithm, usually generating an initial population randomly. All subsequent calls to step evolve the population one “generation”.

Each step is expected to geneate and evaluate at least one solution in order to avoid looping indenfinitely. Any termination conditions and callbacks are called after each step.

class platypus.algorithms.PeriodicAction(algorithm, frequency=10000, by_nfe=True)

Wrapper for algorithms that performs some action at a fixed interval.

Parameters

algorithmAlgorithm

The underlying algorithm.

frequencyint

The frequency the action occurs.

by_nfebool

If True, the frequency is given in number of function evaluations. If False, the frequency is given in the number of iterations.

abstract do_action()

Performs the action.

step()

Performs one logical step of the algorithm.

In most contexts, the first invocation to step should initialize the algorithm, usually generating an initial population randomly. All subsequent calls to step evolve the population one “generation”.

Each step is expected to geneate and evaluate at least one solution in order to avoid looping indenfinitely. Any termination conditions and callbacks are called after each step.

class platypus.algorithms.RegionBasedSelector(archive, grid)

Region-based selector using density from an adaptive grid archive.

Parameters

archiveAdaptiveGridArchive

The adaptive grid archive

griddict

Mapping from grid indices to solutions.

draw()

Draw a solution at random from the archive.

select_one(population)

Selects one of two solutions drawn from the archive based on density.

class platypus.algorithms.SMPSO(problem, swarm_size=100, leader_size=100, generator=<platypus.operators.RandomGenerator object>, max_iterations=100, mutate=None, **kwargs)

Speed-constrained particle swarm optimizer (SMPSO).

Parameters

problemProblem

The problem to optimize.

swarm_sizeint

The size of the swarm (synonymous to a population).

leader_sizeint

The number of leaders to track (synonymous to an archive).

generatorGenerator

The method for generating the initial population.

max_iterationsint

The maximum number of iterations you expect to run this algorithm. This controls how quickly the non-uniform mutation scales.

mutateVariator

The mutation operator. Must have an arity of 1.

class platypus.algorithms.SPEA2(problem, population_size=100, generator=<platypus.operators.RandomGenerator object>, variator=None, dominance=<platypus.core.ParetoDominance object>, k=1, **kwargs)

Improved strength-based Pareto evolutionary algorithm (SPEA2).

SPEA2 uses a novel strengh-based measure of fitness, which is a combination of the number other solutions that are dominated plus a density or crowding distance measure.

Parameters

problemProblem

The problem to optimize.

population_sizeint

The size of the population.

generatorGenerator

The method for generating the initial population.

variatorVariator

The variator used during mating to produce offspring. Must use the differential evolution operator.

dominanceDominance

The dominance criteria for ranking solutions.

kint

Niching parameter specifying that crowding is based on the k-th nearest neighbor.

initialize()

Initializes the algorithm.

This method is called exactly once on the first call to step() to initialize the population. Subclasses can use this perform any other initialization required.

iterate()

Performs one iteration of the algorithm.

The definition of an iteration depends on the specific algorithm, which could mean evolving the entire population (generational) or a single solution.

At a minimum, this method must produce and evaluate at least one offspring (to avoid an infinite loop). If the offspring is selected to survive to the next iteration, update the population.

class platypus.algorithms.SingleObjectiveAlgorithm(problem, population_size=100, generator=<platypus.operators.RandomGenerator object>, **kwargs)

Abstract class for single-objective optimization algorithms.

Parameters

problemProblem

The problem to optimize.

population_sizeint

The size of the population.

generatorGenerator

The method for generating the initial population.