Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.commons.math.genetics
Class GeneticAlgorithm

    java.lang.Object
      org.apache.commons.math.genetics.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
Version:
  $Revision: 925812 $ $Date: 2010-03-21 16:49:31 +0100 (dim. 21 mars 2010) $

Constructor Summary
`GeneticAlgorithm(CrossoverPolicy crossoverPolicy, double crossoverRate, MutationPolicy mutationPolicy, double mutationRate, SelectionPolicy selectionPolicy)`

Method Summary
`Population` | `evolve(Population initial, StoppingCondition condition)` Evolve the given population.
`CrossoverPolicy` | `getCrossoverPolicy()` Returns the crossover policy.
`double` | `getCrossoverRate()` Returns the crossover rate.
`int` | `getGenerationsEvolved()` Returns the number of generations evolved to reach `StoppingCondition` in the last run.
`MutationPolicy` | `getMutationPolicy()` Returns the mutation policy.
`double` | `getMutationRate()` Returns the mutation rate.
`static RandomGenerator` | `getRandomGenerator()` Returns the (static) random generator.
`SelectionPolicy` | `getSelectionPolicy()` Returns the selection policy.
`Population` | `nextGeneration(Population current)` Evolve the given population into the next generation.
`static void` | `setRandomGenerator(RandomGenerator random)` Set the (static) random generator.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### GeneticAlgorithm

    public GeneticAlgorithm(CrossoverPolicy crossoverPolicy,
                            double crossoverRate,
                            MutationPolicy mutationPolicy,
                            double mutationRate,
                            SelectionPolicy selectionPolicy)

Parameters:
  `crossoverPolicy` - The `CrossoverPolicy`
  `crossoverRate` - The crossover rate as a percentage (0-1 inclusive)
  `mutationPolicy` - The `MutationPolicy`
  `mutationRate` - The mutation rate as a percentage (0-1 inclusive)
  `selectionPolicy` - The `SelectionPolicy`

Method Detail

### setRandomGenerator

    public static void setRandomGenerator(RandomGenerator random)

  Set the (static) random generator.

  Parameters:
    `random` - random generator

### getRandomGenerator

    public static RandomGenerator 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:
  - Apply configured SelectionPolicy to select a pair of parents from `current`
  - With probability = `getCrossoverRate()`, apply configured `CrossoverPolicy` to parents
  - With probability = `getMutationRate()`, apply configured `MutationPolicy` to each of the offspring
  - Add offspring individually to nextGeneration, space permitting
  3. Return nextGeneration

  Parameters:
    `current` - the current population.
  Returns:
    the population for the next generation.

### getCrossoverPolicy

    public CrossoverPolicy getCrossoverPolicy()

  Returns the crossover policy.

  Returns:
    crossover policy

### getCrossoverRate

    public double getCrossoverRate()

  Returns the crossover rate.

  Returns:
    crossover rate

### getMutationPolicy

    public MutationPolicy getMutationPolicy()

  Returns the mutation policy.

  Returns:
    mutation policy

### getMutationRate

    public double getMutationRate()

  Returns the mutation rate.

  Returns:
    mutation rate

### getSelectionPolicy

    public SelectionPolicy getSelectionPolicy()

  Returns the selection policy.

  Returns:
    selection policy

### 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

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2003-2011 The Apache Software Foundation. All Rights Reserved.