Added generationsEvolved property to GeneticAlgorithm to track the number

of generations evolved by the evolve() method before reaching the StoppingCondition.
JIRA: MATH-315
Reported and patched by Mikkel Meyer Andersen

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@883132 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Phil Steitz 2009-11-22 19:50:54 +00:00
parent bf451895d5
commit 80f4084139
3 changed files with 24 additions and 1 deletions

View File

@ -102,6 +102,9 @@
<contributor>
<name>C. Scott Ananian</name>
</contributor>
<contributor>
<name>Mikkel Meyer Andersen</name>
</contributor>
<contributor>
<name>Mark Anderson</name>
</contributor>

View File

@ -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;
}
}

View File

@ -39,6 +39,10 @@ The <action> type attribute can be add,update,fix,remove.
</properties>
<body>
<release version="2.1" date="TBD" description="TBD">
<action dev="psteitz" type="update" issue="MATH-315" due-to="Mikkel Meyer Andersen">
Added generationsEvolved property to GeneticAlgorithm to track the number of generations
evolved by the evolve() method before reaching the StoppingCondition.
</action>
<action dev="luc" type="fix" issue="MATH-318" due-to="Dimitri Pourbaix">
Fixed an index computation error in eigen decomposition. Once again, kudos to Dimitri
for debugging this.