/** Test of createRangeMap method, of class FitnessProportionateMechanism. */
 public void testCreateRangeMap() {
   System.out.println("createRangeMap");
   Population<PhenoType> population =
       TestUtils.createPopulation(
           new String[] {
             "11111111", "11111111",
             "11111111", "11111111",
             "11111111", "11111111",
             "11111111", "11111111",
             "11111111", "11111111"
           });
   FitnessMap<PhenoType> fitnessMap = mock(FitnessMap.class);
   FitnessHandler fitnessHandler = mock(BinaryFitnessHandler.class);
   when(fitnessMap.get(any(PhenoType.class))).thenReturn(1., 2., 3., 4., 5., 6., 7., 8., 9., 10.);
   when(fitnessHandler.getFitness(any(PhenoType.class), any(Population.class)))
       .thenReturn(1., 2., 3., 4., 5., 6., 7., 8., 9., 10.);
   when(fitnessHandler.generateFitnessMap(any(Population.class))).thenReturn(fitnessMap);
   GALoop ga = new GALoop(null);
   FitnessProportionateMechanism instance = new FitnessProportionateMechanism(ga);
   instance.createRangeMap(population, fitnessHandler);
   RangeMap<PhenoType> map = instance.getRangeMap();
   double[] expResult =
       new double[] {
         0.02, 0.04,
         0.05, 0.07,
         0.09, 0.11,
         0.13, 0.15,
         0.16, 0.18
       };
   int c = 0;
   for (Entry<Range, PhenoType> r : map.entrySet()) {
     System.out.println(r);
     assertEquals(expResult[c++], round(r.getKey().getEnd() - r.getKey().getStart()));
     //            assertEquals(expResult[c++], r.getKey().getEnd()-r.getKey().getStart(),
     // 0.00000001);
   }
 }
Beispiel #2
0
 public List<PhenoType> parse(Population<S> p, FitnessHandler fitnessHandler) {
   FitnessMap<S> generateFitnessMap = fitnessHandler.generateFitnessMap(p);
   return parse(p, generateFitnessMap);
 }