Class GeneticAlgorithm


  • public class GeneticAlgorithm
    extends Object
    Implementation of a genetic algorithm. All factors that govern the operation of the algorithm can be configured for a specific problem.
    Since:
    2.0
    • Method Detail

      • setRandomGenerator

        public static void setRandomGenerator​(org.apache.commons.rng.UniformRandomProvider random)
        Set the (static) random generator.
        Parameters:
        random - random generator
      • getRandomGenerator

        public static org.apache.commons.rng.UniformRandomProvider getRandomGenerator()
        Returns the (static) random generator.
        Returns:
        the static random generator shared by GA implementation classes
      • evolve

        public Population evolve​(Population initial,
                                 StoppingCondition condition)
        Evolve the given population. Evolution stops when the stopping condition is satisfied. Updates the generationsEvolved property with the number of generations evolved before the StoppingCondition is satisfied.
        Parameters:
        initial - the initial, seed population.
        condition - the stopping condition used to stop evolution.
        Returns:
        the population that satisfies the stopping condition.
      • nextGeneration

        public Population nextGeneration​(Population current)
        Evolve the given population into the next generation.
        1. Get nextGeneration population to fill from current generation, using its nextGeneration method
        2. Loop until new generation is filled:
        3. Return nextGeneration
        Parameters:
        current - the current population.
        Returns:
        the population for the next generation.
      • getCrossoverRate

        public double getCrossoverRate()
        Returns the crossover rate.
        Returns:
        crossover rate
      • getMutationRate

        public double getMutationRate()
        Returns the mutation rate.
        Returns:
        mutation rate
      • getGenerationsEvolved

        public int getGenerationsEvolved()
        Returns the number of generations evolved to reach StoppingCondition in the last run.
        Returns:
        number of generations evolved
        Since:
        2.1