public class SimpleGeneticOptimizationSolver extends Solver
Modifier and Type | Class and Description |
---|---|
private class |
SimpleGeneticOptimizationSolver.FitnessComparator
Compares individuals by the fitness (value of the target function)
|
Modifier and Type | Field and Description |
---|---|
private static org.slf4j.Logger |
log
Logger
|
private int |
minIterations
The minimal number of iterations.
|
private int |
populationIncreaseCrossOver
How many new individuals are created by cross-over (per pair of individuals)
|
private int |
populationIncreaseMutation
How many new individuals are created by mutation (per individual)
|
private int |
populationSize
The size of the population
|
private double |
precision
If an iteration improves less than this value the algorithm ends.
|
private java.util.Random |
rand
For randomization
|
private static double |
VAR_CROSSOVER_PROB
The probability of taking the average value of a variable in the crossover step.
|
private static double |
VAR_MUTATE_PROB
The probability of changing the value of a variable in the mutation step.
|
private static double |
VAR_MUTATE_STRENGTH
The magnitude of changing the value of a variable in the mutation step.
|
private static IntegerConstant |
VERY_LARGE_NUMBER
A very large number for encoding constraints in the target function.
|
Constructor and Description |
---|
SimpleGeneticOptimizationSolver(int populationSize,
int populationIncreaseMutation,
int populationIncreaseCrossOver,
int minIterations,
double precision)
Creates a new simple genetic optimization solver.
|
Modifier and Type | Method and Description |
---|---|
private java.util.Map<FloatVariable,Term> |
crossover(java.util.Map<FloatVariable,Term> ind1,
java.util.Map<FloatVariable,Term> ind2)
Makes a crossover of the two individuals
|
static boolean |
isInstalled() |
private java.util.Map<FloatVariable,Term> |
mutate(java.util.Map<FloatVariable,Term> ind)
Mutates the given individual
|
java.util.Map<Variable,Term> |
solve(ConstraintSatisfactionProblem problem)
Computes a solution to the given constraint satisfaction or optimization problem, i.e.
|
java.util.Map<Variable,Term> |
solve(Term t,
int optimization_objective)
Returns the variable assignment that maximizes/minimizes the given term
(which only contains variables with defined upper and lower bounds).
|
getDefaultGeneralSolver, getDefaultIntegerLinearSolver, getDefaultLinearSolver, hasDefaultGeneralSolver, hasDefaultIntegerLinearSolver, hasDefaultLinearSolver, setDefaultGeneralSolver, setDefaultIntegerLinearSolver, setDefaultLinearSolver
private static org.slf4j.Logger log
private static final double VAR_MUTATE_PROB
private static final double VAR_MUTATE_STRENGTH
private static final double VAR_CROSSOVER_PROB
private static final IntegerConstant VERY_LARGE_NUMBER
private java.util.Random rand
private int populationSize
private int populationIncreaseMutation
private int populationIncreaseCrossOver
private double precision
private int minIterations
public SimpleGeneticOptimizationSolver(int populationSize, int populationIncreaseMutation, int populationIncreaseCrossOver, int minIterations, double precision)
populationSize
- The size of the populationpopulationIncreaseMutation
- How many new individuals are created by mutation (per individual)populationIncreaseCrossOver
- How many new individuals are created by cross-over (per pair of individuals)minIterations
- The minimal number of iterationsprecision
- If an iteration improves less than this value the algorithm endspublic java.util.Map<Variable,Term> solve(ConstraintSatisfactionProblem problem) throws GeneralMathException
Solver
solve
in class Solver
problem
- the actual problemGeneralMathException
- if something went wrong.private java.util.Map<FloatVariable,Term> mutate(java.util.Map<FloatVariable,Term> ind)
ind
- some individualprivate java.util.Map<FloatVariable,Term> crossover(java.util.Map<FloatVariable,Term> ind1, java.util.Map<FloatVariable,Term> ind2)
ind1
- some individualind2
- some individualpublic java.util.Map<Variable,Term> solve(Term t, int optimization_objective) throws GeneralMathException
t
- the term to be evaluatedoptimization_objective
- one of OptimizationProblem.MAXIMIZE, OptimizationProblem.MINIMIZEGeneralMathException
public static boolean isInstalled() throws java.lang.UnsupportedOperationException
java.lang.UnsupportedOperationException