ScaledRouletteWheel 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(); tmp = this.sumFit - tmp; 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; } } } ScaledRouletteWheel(int size, RandomNumberGenerator rng);  ScaledRouletteWheel(); static void main(String[] args);  }
@Test public void testCalculateAccumulatedFitnessProbabilities() { System.out.println("calculateAccumulatedFitnessProbabilities"); ScaledRouletteWheel instance = new ScaledRouletteWheel(); instance.rankPopulation(individuals); instance.calculateFitnessSum(individuals); double[] expResults = new double[] {0.4166666666666667,0.75,1.0}; assertEquals(30,instance.sumFit,9e-16); instance.calculateAccumulatedFitnessProbabilities(individuals); JUnitHelper.checkArrays(expResults,instance.accProbs); assertEquals(30,instance.sumFit,9e-16); }