ProportionalRouletteWheel extends RouletteWheel implements Stochastic { protected void calculateAccumulatedFitnessProbabilities(List<Individual> operands) { if (this.sumFit == 0) { return; } this.accProbs = new double[operands.size()]; double[] tmpA = new double[accProbs.length]; double tmp; double tmpSum = 0; for (int cnt = 0; cnt < operands.size(); cnt++) { tmp = operands.get(cnt).getFitness().getDouble(); if(this.smallFit == true) { tmp= tmp * 1000; } tmp = 1/(tmp+1); tmpA[cnt] = tmp; tmpSum += tmp; } for (int cnt = 0; cnt < operands.size(); cnt++) { tmp = tmpA[cnt]; tmp /= tmpSum; if (cnt > 0) { accProbs[cnt] = accProbs[cnt - 1] + tmp; } else { accProbs[cnt] = tmp; } if (accProbs[cnt] > 1) { accProbs[cnt] = 1; } } } ProportionalRouletteWheel(int size, RandomNumberGenerator rng);  ProportionalRouletteWheel(); static void main(String[] args);  }
@Test public void testCalculateAccumulatedFitnessProbabilities() { System.out.println("calculateAccumulatedFitnessProbabilities"); ProportionalRouletteWheel instance = new ProportionalRouletteWheel(); double[] expResults = new double[]{0.5207100591715976,0.8047337278106509,1.0}; instance.rankPopulation(individuals); instance.calculateFitnessSum(individuals); assertEquals(false,instance.smallFit); assertEquals(30,instance.sumFit,9e-16); instance.calculateAccumulatedFitnessProbabilities(individuals); JUnitHelper.checkArrays(expResults,instance.accProbs); ProportionalRouletteWheel instance2 = new ProportionalRouletteWheel(); instance2.rankPopulation(individuals2); instance2.calculateFitnessSum(individuals2); expResults = new double[] {0.48333189103950924,0.806088402996125,1.0}; assertEquals(1,instance2.sumFit,9e-16); assertEquals(true,instance2.smallFit); instance2.calculateAccumulatedFitnessProbabilities(individuals2); JUnitHelper.checkArrays(expResults,instance2.accProbs); }