Author: tn
Date: Tue May 29 22:26:22 2012
New Revision: 1344031

URL: http://svn.apache.org/viewvc?rev=1344031&view=rev
Log:
Cleanup of OnePointCrossover.

Modified:
    
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/OnePointCrossover.java

Modified: 
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/OnePointCrossover.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/OnePointCrossover.java?rev=1344031&r1=1344030&r2=1344031&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/OnePointCrossover.java
 (original)
+++ 
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/OnePointCrossover.java
 Tue May 29 22:26:22 2012
@@ -32,17 +32,17 @@ import org.apache.commons.math3.exceptio
  * Example:
  * <pre>
  * -C- denotes a crossover point
- *                   -C-                                -C-
+ *                   -C-                                 -C-
  * p1 = (1 0 1 0 0 1  | 0 1 1)    X    p2 = (0 1 1 0 1 0  | 1 1 1)
- *         \------------/ \-----/              \------------/ \-----/
+ *      \------------/ \-----/              \------------/ \-----/
  *            ||         (*)                       ||        (**)
  *            VV         (**)                      VV        (*)
  *      /------------\ /-----\              /------------\ /-----\
- * c1 = (1 0 1 0 0 1  | 1 1 1)    X    p2 = (0 1 1 0 1 0  | 0 1 1)
+ * c1 = (1 0 1 0 0 1  | 1 1 1)    X    c2 = (0 1 1 0 1 0  | 0 1 1)
  * </pre>
  *
  * This policy works only on {@link AbstractListChromosome}, and therefore it
- * is parametrized by T. Moreover, the chromosomes must have same lengths.
+ * is parameterized by T. Moreover, the chromosomes must have same lengths.
  *
  * @param <T> generic type of the {@link AbstractListChromosome}s for crossover
  * @since 2.0
@@ -57,14 +57,16 @@ public class OnePointCrossover<T> implem
      * second parts are copied crosswise.
      *
      * Example:
+     * <pre>
      * -C- denotes a crossover point
-     *                   -C-                                -C-
+     *                   -C-                                 -C-
      * p1 = (1 0 1 0 0 1  | 0 1 1)    X    p2 = (0 1 1 0 1 0  | 1 1 1)
-     *         \------------/ \-----/              \------------/ \-----/
+     *      \------------/ \-----/              \------------/ \-----/
      *            ||         (*)                       ||        (**)
      *            VV         (**)                      VV        (*)
      *      /------------\ /-----\              /------------\ /-----\
-     * c1 = (1 0 1 0 0 1  | 1 1 1)    X    p2 = (0 1 1 0 1 0  | 0 1 1)
+     * c1 = (1 0 1 0 0 1  | 1 1 1)    X    c2 = (0 1 1 0 1 0  | 0 1 1)
+     * </pre>
      *
      * @param first first parent (p1)
      * @param second second parent (p2)
@@ -92,20 +94,20 @@ public class OnePointCrossover<T> implem
      */
     private ChromosomePair crossover(final AbstractListChromosome<T> first,
                                      final AbstractListChromosome<T> second) {
-        int length = first.getLength();
+        final int length = first.getLength();
         if (length != second.getLength()) {
             throw new DimensionMismatchException(second.getLength(), length);
         }
 
         // array representations of the parents
-        List<T> parent1Rep = first.getRepresentation();
-        List<T> parent2Rep = second.getRepresentation();
+        final List<T> parent1Rep = first.getRepresentation();
+        final List<T> parent2Rep = second.getRepresentation();
         // and of the children
-        ArrayList<T> child1Rep = new ArrayList<T> (first.getLength());
-        ArrayList<T> child2Rep = new ArrayList<T> (second.getLength());
+        final ArrayList<T> child1Rep = new ArrayList<T> (first.getLength());
+        final ArrayList<T> child2Rep = new ArrayList<T> (second.getLength());
 
         // select a crossover point at random (0 and length makes no sense)
-        int crossoverIndex = 1 + 
(GeneticAlgorithm.getRandomGenerator().nextInt(length-2));
+        final int crossoverIndex = 1 + 
(GeneticAlgorithm.getRandomGenerator().nextInt(length-2));
 
         // copy the first part
         for (int i = 0; i < crossoverIndex; i++) {


Reply via email to