commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pste...@apache.org
Subject svn commit: r883132 - in /commons/proper/math/trunk: pom.xml src/main/java/org/apache/commons/math/genetics/GeneticAlgorithm.java src/site/xdoc/changes.xml
Date Sun, 22 Nov 2009 19:50:54 GMT
Author: psteitz
Date: Sun Nov 22 19:50:54 2009
New Revision: 883132

URL: http://svn.apache.org/viewvc?rev=883132&view=rev
Log:
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

Modified:
    commons/proper/math/trunk/pom.xml
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/genetics/GeneticAlgorithm.java
    commons/proper/math/trunk/src/site/xdoc/changes.xml

Modified: commons/proper/math/trunk/pom.xml
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/pom.xml?rev=883132&r1=883131&r2=883132&view=diff
==============================================================================
--- commons/proper/math/trunk/pom.xml (original)
+++ commons/proper/math/trunk/pom.xml Sun Nov 22 19:50:54 2009
@@ -103,6 +103,9 @@
       <name>C. Scott Ananian</name>
     </contributor>
     <contributor>
+      <name>Mikkel Meyer Andersen</name>
+    </contributor>
+    <contributor>
       <name>Mark Anderson</name>
     </contributor>
     <contributor>

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/genetics/GeneticAlgorithm.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/genetics/GeneticAlgorithm.java?rev=883132&r1=883131&r2=883132&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/genetics/GeneticAlgorithm.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/genetics/GeneticAlgorithm.java
Sun Nov 22 19:50:54 2009
@@ -34,7 +34,6 @@
      * 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 @@
     /** 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 @@
 
     /**
      * 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 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 @@
         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;
+    }
+
 }

Modified: commons/proper/math/trunk/src/site/xdoc/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/site/xdoc/changes.xml?rev=883132&r1=883131&r2=883132&view=diff
==============================================================================
--- commons/proper/math/trunk/src/site/xdoc/changes.xml (original)
+++ commons/proper/math/trunk/src/site/xdoc/changes.xml Sun Nov 22 19:50:54 2009
@@ -39,6 +39,10 @@
   </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.



Mime
View raw message