Class 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
    • 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 population
        populationIncreaseMutation - 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 iterations
        precision - 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: Solver
        Computes a solution to the given constraint satisfaction or optimization problem, i.e. a mapping from variables of the problem to terms.
        Specified by:
        solve in class Solver
        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 individual
        ind2 - 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 evaluated
        optimization_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