@Test public void selectBestKChromosomeWithoutFitnessCalculation() { Assert.assertNull(population.selectBestKChromosome(K)); }
public Chromosome[] selectBestKChromosome(int k) { if (fitnessCalculatedFlags.cardinality() == chromosomes.length) { Chromosome[] cp = Arrays.copyOf(chromosomes, chromosomes.length); Arrays.sort(cp); return Arrays.copyOfRange(cp, cp.length - k, cp.length); } return null; }
Population { public Chromosome[] selectBestKChromosome(int k) { if (fitnessCalculatedFlags.cardinality() == chromosomes.length) { Chromosome[] cp = Arrays.copyOf(chromosomes, chromosomes.length); Arrays.sort(cp); return Arrays.copyOfRange(cp, cp.length - k, cp.length); } return null; } }
Population { public Chromosome[] selectBestKChromosome(int k) { if (fitnessCalculatedFlags.cardinality() == chromosomes.length) { Chromosome[] cp = Arrays.copyOf(chromosomes, chromosomes.length); Arrays.sort(cp); return Arrays.copyOfRange(cp, cp.length - k, cp.length); } return null; } Population(int size); }
Population { public Chromosome[] selectBestKChromosome(int k) { if (fitnessCalculatedFlags.cardinality() == chromosomes.length) { Chromosome[] cp = Arrays.copyOf(chromosomes, chromosomes.length); Arrays.sort(cp); return Arrays.copyOfRange(cp, cp.length - k, cp.length); } return null; } 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 Chromosome[] selectBestKChromosome(int k) { if (fitnessCalculatedFlags.cardinality() == chromosomes.length) { Chromosome[] cp = Arrays.copyOf(chromosomes, chromosomes.length); Arrays.sort(cp); return Arrays.copyOfRange(cp, cp.length - k, cp.length); } return null; } 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);  }