Search in sources :

Example 6 with Booths

use of org.evosuite.ga.problems.singleobjective.Booths in project evosuite by EvoSuite.

the class TestSortByFitness method testSortByFitnessC1win.

@Test
public void testSortByFitnessC1win() {
    Problem p = new Booths<NSGAChromosome>();
    List<FitnessFunction<NSGAChromosome>> fitnessFunctions = p.getFitnessFunctions();
    FitnessFunction<NSGAChromosome> ff = fitnessFunctions.get(0);
    NSGAChromosome c1 = new NSGAChromosome();
    NSGAChromosome c2 = new NSGAChromosome();
    // Set Fitness
    c1.setFitness(ff, 0.7);
    c2.setFitness(ff, 0.3);
    List<NSGAChromosome> population = new ArrayList<NSGAChromosome>();
    population.add(c1);
    population.add(c2);
    SortByFitness sf = new SortByFitness(ff, true);
    Collections.sort(population, sf);
    Assert.assertTrue(population.get(0) == c1);
    Assert.assertEquals(population.get(0).getFitness(ff), 0.7, 0.0);
    Assert.assertTrue(population.get(1) == c2);
    Assert.assertEquals(population.get(1).getFitness(ff), 0.3, 0.0);
}
Also used : NSGAChromosome(org.evosuite.ga.NSGAChromosome) ArrayList(java.util.ArrayList) Problem(org.evosuite.ga.problems.Problem) FitnessFunction(org.evosuite.ga.FitnessFunction) Booths(org.evosuite.ga.problems.singleobjective.Booths) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)6 FitnessFunction (org.evosuite.ga.FitnessFunction)6 NSGAChromosome (org.evosuite.ga.NSGAChromosome)6 Problem (org.evosuite.ga.problems.Problem)6 Booths (org.evosuite.ga.problems.singleobjective.Booths)6 Test (org.junit.Test)6 List (java.util.List)1 CrowdingComparator (org.evosuite.ga.comparators.CrowdingComparator)1 FONIntTest (org.evosuite.ga.problems.multiobjective.FONIntTest)1