GeneticAlgorithmSolver

class GeneticAlgorithmSolver @JvmOverloads constructor(problemDefinition: ProblemDefinition, evaluator: EvaluatorIfc, streamNum: Int = 0, streamProvider: RNStreamProviderIfc = RNStreamProvider(), populationSize: Int = defaultPopulationSize, selectionOperator: SelectionOperatorIfc = TournamentSelection(), crossoverOperator: CrossoverOperatorIfc = BlendCrossover(), mutationOperator: MutationOperatorIfc = GaussianMutation(problemDefinition), maximumIterations: Int = gaDefaultMaxIterations, replicationsPerEvaluation: ReplicationPerEvaluationIfc, solutionEqualityChecker: SolutionEqualityIfc = InputsAndConfidenceIntervalEquality(), name: String? = null) : StochasticSolver(source)

A generational genetic algorithm (GA) solver with elitism for simulation optimization.

Each call to mainIteration produces one generation: the best eliteCount solutions are carried forward unchanged; parents are chosen by the selectionOperator; offspring are produced by the crossoverOperator (gated by crossoverRate) and the mutationOperator (gated by the per-individual mutationRate); the whole offspring set is evaluated in a single batch oracle call (via the inherited requestEvaluations); and the next generation is the best of the elites plus the offspring. The best solution found is tracked automatically by the base class through the currentSolution setter.

All randomness is drawn through the solver's single random number stream (rnStream); the genetic operators draw from it as well, so a run is reproducible for a fixed stream number.

Parameters

problemDefinition

the problem being solved

evaluator

the evaluator responsible for assessing the quality of solutions

streamNum

the random number stream number; 0 (the default) means the next available stream

streamProvider

the provider of random number streams; defaults to a fresh RNStreamProvider

populationSize

the number of individuals per generation

selectionOperator

the parent-selection strategy; defaults to TournamentSelection

crossoverOperator

the recombination strategy; defaults to BlendCrossover

mutationOperator

the mutation strategy; defaults to GaussianMutation

maximumIterations

the maximum number of generations

replicationsPerEvaluation

strategy to determine the number of replications per evaluation

solutionEqualityChecker

used to detect convergence (no-improvement). The default is InputsAndConfidenceIntervalEquality.

name

an optional name for the solver

Constructors

Link copied to clipboard
constructor(problemDefinition: ProblemDefinition, evaluator: EvaluatorIfc, streamNum: Int = 0, streamProvider: RNStreamProviderIfc = RNStreamProvider(), populationSize: Int = defaultPopulationSize, selectionOperator: SelectionOperatorIfc = TournamentSelection(), crossoverOperator: CrossoverOperatorIfc = BlendCrossover(), mutationOperator: MutationOperatorIfc = GaussianMutation(problemDefinition), maximumIterations: Int = gaDefaultMaxIterations, replicationsPerEvaluation: ReplicationPerEvaluationIfc, solutionEqualityChecker: SolutionEqualityIfc = InputsAndConfidenceIntervalEquality(), name: String? = null)
constructor(problemDefinition: ProblemDefinition, evaluator: EvaluatorIfc, streamNum: Int = 0, streamProvider: RNStreamProviderIfc = RNStreamProvider(), populationSize: Int = defaultPopulationSize, selectionOperator: SelectionOperatorIfc = TournamentSelection(), crossoverOperator: CrossoverOperatorIfc = BlendCrossover(), mutationOperator: MutationOperatorIfc = GaussianMutation(problemDefinition), maximumIterations: Int = gaDefaultMaxIterations, replicationsPerEvaluation: Int = defaultReplicationsPerEvaluation, solutionEqualityChecker: SolutionEqualityIfc = InputsAndConfidenceIntervalEquality(), name: String? = null)

Constructs a genetic algorithm solver using a fixed number of replications per evaluation.

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

Structured, ordered snapshot of the solver's configuration — the same fields the toString implementations expose, in a form that downstream consumers can iterate (reporting, machine-readable summary artifacts, "compare two runs" tooling).

Link copied to clipboard

The recombination (crossover) strategy. Cannot be changed while the solver is running.

Link copied to clipboard

The probability that a selected pair of parents is recombined via crossover (otherwise the parents are copied). Must be in 0,1.

Link copied to clipboard

The number of best individuals carried forward unchanged into the next generation. Must be

Link copied to clipboard

The mutation strategy. Cannot be changed while the solver is running.

Link copied to clipboard

The probability that an offspring individual is mutated — i.e. that the mutation operator is applied to it at all. Must be in 0,1.

Link copied to clipboard

If supplied, this function determines the per-individual mutation rate, overriding mutationRate.

Link copied to clipboard

A read-only, best-first ordered view of the current population.

Link copied to clipboard

The number of individuals per generation. Must be at least defaultMinPopulationSize.

Link copied to clipboard

If supplied, this function determines the population size, overriding populationSize.

Link copied to clipboard

The parent-selection strategy. Cannot be changed while the solver is running.

Link copied to clipboard

Used to check whether the most recent best solutions have converged (no improvement).

Functions

Link copied to clipboard
protected open override fun extractSolverSpecificState(): Map<String, Double>

A hook for subclasses to inject their specific internal state metrics into the snapshot without having to override the entire makeSolverStateSnapshot method.

Link copied to clipboard
protected open override fun initializeIterations()

Subclasses may implement this function to prepare the solver before running the first iteration. Generally, it is sufficient to just implement the startingPoint() function.

Link copied to clipboard
protected open override fun isStoppingCriteriaSatisfied(): Boolean

Subclasses should implement this function to determine if the solver should continue running iterations. This will likely include some implementation of stopping criteria. This function should implement stopping criteria based on the quality of the solution. The number of iterations, compared to the maximum number of iterations, is automatically checked after each step in the iterative process. Unless overridden, this function returns false by default, which indicates that the solution quality criteria have not been satisfied. This will cause the solver to iterate through all iterations of the solution process up to the maximum number of iterations. Alternatively, the user can specify an instance of the SolutionQualityEvaluatorIfc interface to determine if the solution quality has been reached.

Link copied to clipboard
protected open override fun mainIteration()

This function should contain the logic that iteratively executes until the maximum number of iterations is reached or until the stopping criteria is met. The base implementation calls nextPoint() to determine the next point to evaluate, requests an evaluation of the point, and then updates the current solution if the resulting solution is better than the current solution. Generally, implementing startingPoint() and nextPoint() should be adequate. The property iterationCounter represents the current iteration within the mainIteration() function. That is, the value of iterationCounter is incremented prior to the execution of the mainIteration() function.

Link copied to clipboard

The effective per-individual mutation rate: the value from mutationRateFn if supplied, otherwise mutationRate.

Link copied to clipboard

The effective population size: the value from populationSizeFn if supplied, otherwise populationSize.

Link copied to clipboard
open override fun toString(): String