Package net.sf.tweety.math.opt.solver
Class SimpleGeneticOptimizationSolver
- java.lang.Object
-
- net.sf.tweety.math.opt.Solver
-
- net.sf.tweety.math.opt.solver.SimpleGeneticOptimizationSolver
-
public class SimpleGeneticOptimizationSolver extends Solver
This class implements a simple genetic optimization algorithm for solving optimization problems with box or equality constraints on float variables. Note that equality constraints are encoded in the target function!- Author:
- Matthias Thimm
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classSimpleGeneticOptimizationSolver.FitnessComparatorCompares individuals by the fitness (value of the target function)
-
Field Summary
Fields Modifier and Type Field Description private static org.slf4j.LoggerlogLoggerprivate intminIterationsThe minimal number of iterations.private intpopulationIncreaseCrossOverHow many new individuals are created by cross-over (per pair of individuals)private intpopulationIncreaseMutationHow many new individuals are created by mutation (per individual)private intpopulationSizeThe size of the populationprivate doubleprecisionIf an iteration improves less than this value the algorithm ends.private java.util.RandomrandFor randomizationprivate static doubleVAR_CROSSOVER_PROBThe probability of taking the average value of a variable in the crossover step.private static doubleVAR_MUTATE_PROBThe probability of changing the value of a variable in the mutation step.private static doubleVAR_MUTATE_STRENGTHThe magnitude of changing the value of a variable in the mutation step.private static IntegerConstantVERY_LARGE_NUMBERA very large number for encoding constraints in the target function.
-
Constructor Summary
Constructors Constructor Description SimpleGeneticOptimizationSolver(int populationSize, int populationIncreaseMutation, int populationIncreaseCrossOver, int minIterations, double precision)Creates a new simple genetic optimization solver.
-
Method Summary
Modifier and Type Method 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 individualsstatic booleanisInstalled()private java.util.Map<FloatVariable,Term>mutate(java.util.Map<FloatVariable,Term> ind)Mutates the given individualjava.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).-
Methods inherited from class net.sf.tweety.math.opt.Solver
getDefaultGeneralSolver, getDefaultIntegerLinearSolver, getDefaultLinearSolver, hasDefaultGeneralSolver, hasDefaultIntegerLinearSolver, hasDefaultLinearSolver, setDefaultGeneralSolver, setDefaultIntegerLinearSolver, setDefaultLinearSolver
-
-
-
-
Field Detail
-
log
private static org.slf4j.Logger log
Logger
-
VAR_MUTATE_PROB
private static final double VAR_MUTATE_PROB
The probability of changing the value of a variable in the mutation step.- See Also:
- Constant Field Values
-
VAR_MUTATE_STRENGTH
private static final double VAR_MUTATE_STRENGTH
The magnitude of changing the value of a variable in the mutation step.- See Also:
- Constant Field Values
-
VAR_CROSSOVER_PROB
private static final double VAR_CROSSOVER_PROB
The probability of taking the average value of a variable in the crossover step.- See Also:
- Constant Field Values
-
VERY_LARGE_NUMBER
private static final IntegerConstant VERY_LARGE_NUMBER
A very large number for encoding constraints in the target function.
-
rand
private java.util.Random rand
For randomization
-
populationSize
private int populationSize
The size of the population
-
populationIncreaseMutation
private int populationIncreaseMutation
How many new individuals are created by mutation (per individual)
-
populationIncreaseCrossOver
private int populationIncreaseCrossOver
How many new individuals are created by cross-over (per pair of individuals)
-
precision
private double precision
If an iteration improves less than this value the algorithm ends.
-
minIterations
private int minIterations
The minimal number of iterations.
-
-
Constructor Detail
-
SimpleGeneticOptimizationSolver
public SimpleGeneticOptimizationSolver(int populationSize, int populationIncreaseMutation, int populationIncreaseCrossOver, int minIterations, double precision)Creates a new simple genetic optimization solver.- Parameters:
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 ends
-
-
Method Detail
-
solve
public java.util.Map<Variable,Term> solve(ConstraintSatisfactionProblem problem) throws GeneralMathException
Description copied from class:SolverComputes a solution to the given constraint satisfaction or optimization problem, i.e. a mapping from variables of the problem to terms.- Specified by:
solvein classSolver- Parameters:
problem- the actual problem- Returns:
- a mapping from variables of the problem to terms.
- Throws:
GeneralMathException- if something went wrong.
-
mutate
private java.util.Map<FloatVariable,Term> mutate(java.util.Map<FloatVariable,Term> ind)
Mutates the given individual- Parameters:
ind- some individual- Returns:
- a new individual
-
crossover
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- Parameters:
ind1- some individualind2- some individual- Returns:
- a new individual
-
solve
public java.util.Map<Variable,Term> solve(Term t, int optimization_objective) throws GeneralMathException
Returns the variable assignment that maximizes/minimizes the given term (which only contains variables with defined upper and lower bounds).- Parameters:
t- the term to be evaluatedoptimization_objective- one of OptimizationProblem.MAXIMIZE, OptimizationProblem.MINIMIZE- Returns:
- the optimal variable assignment
- Throws:
GeneralMathException- if some issue occured during computation.
-
isInstalled
public static boolean isInstalled() throws java.lang.UnsupportedOperationException- Throws:
java.lang.UnsupportedOperationException
-
-