You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by tn...@apache.org on 2012/04/12 20:18:25 UTC
svn commit: r1325422 - in
/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics:
ElitisticListPopulation.java ListPopulation.java
Author: tn
Date: Thu Apr 12 18:18:25 2012
New Revision: 1325422
URL: http://svn.apache.org/viewvc?rev=1325422&view=rev
Log:
[MATH-775] reverted internal list in ListPopulation to private scope and added protected getter.
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/ElitisticListPopulation.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/ListPopulation.java
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/ElitisticListPopulation.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/ElitisticListPopulation.java?rev=1325422&r1=1325421&r2=1325422&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/ElitisticListPopulation.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/ElitisticListPopulation.java Thu Apr 12 18:18:25 2012
@@ -76,13 +76,13 @@ public class ElitisticListPopulation ext
ElitisticListPopulation nextGeneration =
new ElitisticListPopulation(getPopulationLimit(), getElitismRate());
- // sort the chromosomes inplace
- Collections.sort(chromosomes);
+ final List<Chromosome> oldChromosomes = getChromosomeList();
+ Collections.sort(oldChromosomes);
// index of the last "not good enough" chromosome
- int boundIndex = (int) FastMath.ceil((1.0 - getElitismRate()) * chromosomes.size());
- for (int i = boundIndex; i < chromosomes.size(); i++) {
- nextGeneration.addChromosome(chromosomes.get(i));
+ int boundIndex = (int) FastMath.ceil((1.0 - getElitismRate()) * oldChromosomes.size());
+ for (int i = boundIndex; i < oldChromosomes.size(); i++) {
+ nextGeneration.addChromosome(oldChromosomes.get(i));
}
return nextGeneration;
}
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/ListPopulation.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/ListPopulation.java?rev=1325422&r1=1325421&r2=1325422&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/ListPopulation.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/ListPopulation.java Thu Apr 12 18:18:25 2012
@@ -37,7 +37,7 @@ import org.apache.commons.math3.exceptio
public abstract class ListPopulation implements Population {
/** List of chromosomes */
- protected List<Chromosome> chromosomes;
+ private List<Chromosome> chromosomes;
/** maximal size of the population */
private int populationLimit;
@@ -114,13 +114,21 @@ public abstract class ListPopulation imp
/**
* Returns an unmodifiable list of the chromosomes in this population.
- * @return the list of chromosomes
+ * @return the unmodifiable list of chromosomes
*/
public List<Chromosome> getChromosomes() {
return Collections.unmodifiableList(chromosomes);
}
/**
+ * Access the list of chromosomes.
+ * @return the list of chromosomes
+ */
+ protected List<Chromosome> getChromosomeList() {
+ return chromosomes;
+ }
+
+ /**
* Add the given chromosome to the population.
* @param chromosome the chromosome to add.
* @throws NumberIsTooLargeException if the population would exceed the {@code populationLimit} after