@Test public void getAverageFitness() { double res = population.getAverageFitness(); Assert.assertEquals(res, Double.NaN, PRECISION); population.calculateFitnessForAll(fitnessFunction); res = population.getAverageFitness(); Assert.assertEquals(res, 99.0, PRECISION); }
public double getAverageFitness() { if (fitnessCalculatedFlags.cardinality() == chromosomes.length) { double totalFitness = 0.0; for (int i = 0; i < chromosomes.length; i++) totalFitness += chromosomes[i].getFitness(); return totalFitness / chromosomes.length; } return Double.NaN; }
Population { public double getAverageFitness() { if (fitnessCalculatedFlags.cardinality() == chromosomes.length) { double totalFitness = 0.0; for (int i = 0; i < chromosomes.length; i++) totalFitness += chromosomes[i].getFitness(); return totalFitness / chromosomes.length; } return Double.NaN; } }
Population { public double getAverageFitness() { if (fitnessCalculatedFlags.cardinality() == chromosomes.length) { double totalFitness = 0.0; for (int i = 0; i < chromosomes.length; i++) totalFitness += chromosomes[i].getFitness(); return totalFitness / chromosomes.length; } return Double.NaN; } Population(int size); }
Population { public double getAverageFitness() { if (fitnessCalculatedFlags.cardinality() == chromosomes.length) { double totalFitness = 0.0; for (int i = 0; i < chromosomes.length; i++) totalFitness += chromosomes[i].getFitness(); return totalFitness / chromosomes.length; } return Double.NaN; } Population(int size); Chromosome getChromosome(int idx); double calculateFitnessForChromosome(int idx, Function<Chromosome, Double> fitnessFunction); void calculateFitnessForAll(Function<Chromosome, Double> fitnessFunction); void setChromosome(int idx, Chromosome chromosome); Chromosome getChromosome(Integer idx); Chromosome[] selectBestKChromosome(int k); double getTotalFitness(); double getAverageFitness(); int size(); void setFitness(Integer idx, Double fitness); }
Population { public double getAverageFitness() { if (fitnessCalculatedFlags.cardinality() == chromosomes.length) { double totalFitness = 0.0; for (int i = 0; i < chromosomes.length; i++) totalFitness += chromosomes[i].getFitness(); return totalFitness / chromosomes.length; } return Double.NaN; } Population(int size); Chromosome getChromosome(int idx); double calculateFitnessForChromosome(int idx, Function<Chromosome, Double> fitnessFunction); void calculateFitnessForAll(Function<Chromosome, Double> fitnessFunction); void setChromosome(int idx, Chromosome chromosome); Chromosome getChromosome(Integer idx); Chromosome[] selectBestKChromosome(int k); double getTotalFitness(); double getAverageFitness(); int size(); void setFitness(Integer idx, Double fitness);  }