diff --git a/pom.xml b/pom.xml index 81dd54b9d..55360633b 100644 --- a/pom.xml +++ b/pom.xml @@ -102,6 +102,9 @@ C. Scott Ananian + + Mikkel Meyer Andersen + Mark Anderson diff --git a/src/main/java/org/apache/commons/math/genetics/GeneticAlgorithm.java b/src/main/java/org/apache/commons/math/genetics/GeneticAlgorithm.java index 04ae10f53..a2794441e 100644 --- a/src/main/java/org/apache/commons/math/genetics/GeneticAlgorithm.java +++ b/src/main/java/org/apache/commons/math/genetics/GeneticAlgorithm.java @@ -34,7 +34,6 @@ public class GeneticAlgorithm { * Use {@link #setRandomGenerator(RandomGenerator)} to supply an alternative * to the default JDK-provided PRNG. */ - //@GuardedBy("this") private static RandomGenerator randomGenerator = new JDKRandomGenerator(); /** the crossover policy used by the algorithm. */ @@ -52,6 +51,9 @@ public class GeneticAlgorithm { /** the selection policy used by the algorithm. */ private final SelectionPolicy selectionPolicy; + /** the number of generations evolved to reach {@link StoppingCondition} in the last run. */ + private int generationsEvolved = 0; + /** * @param crossoverPolicy The {@link CrossoverPolicy} * @param crossoverRate The crossover rate as a percentage (0-1 inclusive) @@ -96,6 +98,8 @@ public class GeneticAlgorithm { /** * Evolve the given population. Evolution stops when the stopping condition + * is satisfied. Updates the {@link #getGenerationsEvolved() generationsEvolved} + * property with the number of generations evolved before the StoppingCondition * is satisfied. * * @param initial the initial, seed population. @@ -104,8 +108,10 @@ public class GeneticAlgorithm { */ public Population evolve(Population initial, StoppingCondition condition) { Population current = initial; + generationsEvolved = 0; while (!condition.isSatisfied(current)) { current = nextGeneration(current); + generationsEvolved++; } return current; } @@ -207,4 +213,14 @@ public class GeneticAlgorithm { return selectionPolicy; } + /** + * Returns the number of generations evolved to + * reach {@link StoppingCondition} in the last run. + * + * @return number of generations evolved + */ + public int getGenerationsEvolved() { + return generationsEvolved; + } + } diff --git a/src/site/xdoc/changes.xml b/src/site/xdoc/changes.xml index e1a7df0ce..3c94d22e9 100644 --- a/src/site/xdoc/changes.xml +++ b/src/site/xdoc/changes.xml @@ -39,6 +39,10 @@ The type attribute can be add,update,fix,remove. + + Added generationsEvolved property to GeneticAlgorithm to track the number of generations + evolved by the evolve() method before reaching the StoppingCondition. + Fixed an index computation error in eigen decomposition. Once again, kudos to Dimitri for debugging this.