Search in sources :

Example 26 with NSGAChromosome

use of org.evosuite.ga.NSGAChromosome in project evosuite by EvoSuite.

the class TestCrowdingComparator method testCrowdingComparisonOperatorMinimize.

@Test
public void testCrowdingComparisonOperatorMinimize() {
    NSGAChromosome c1 = new NSGAChromosome();
    NSGAChromosome c2 = new NSGAChromosome();
    NSGAChromosome c3 = new NSGAChromosome();
    // Set Rank
    c1.setRank(1);
    c2.setRank(0);
    c3.setRank(0);
    // Set Distance
    c1.setDistance(0.1);
    c2.setDistance(0.5);
    c3.setDistance(0.4);
    List<NSGAChromosome> population = new ArrayList<NSGAChromosome>();
    population.add(c1);
    population.add(c2);
    population.add(c3);
    CrowdingComparator cc = new CrowdingComparator(false);
    Collections.sort(population, cc);
    // assert by Rank
    Assert.assertTrue(population.get(0).getRank() == 0);
    Assert.assertTrue(population.get(1).getRank() == 0);
    Assert.assertTrue(population.get(2).getRank() == 1);
    // assert by Distance
    Assert.assertTrue(population.get(0).getDistance() == 0.5);
    Assert.assertTrue(population.get(1).getDistance() == 0.4);
    Assert.assertTrue(population.get(2).getDistance() == 0.1);
}
Also used : NSGAChromosome(org.evosuite.ga.NSGAChromosome) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 27 with NSGAChromosome

use of org.evosuite.ga.NSGAChromosome in project evosuite by EvoSuite.

the class TestSortByFitness method testSortByFitnessC2win.

@Test
public void testSortByFitnessC2win() {
    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.3);
    c2.setFitness(ff, 0.7);
    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) == c2);
    Assert.assertEquals(population.get(0).getFitness(ff), 0.7, 0.0);
    Assert.assertEquals(population.get(1).getFitness(ff), 0.3, 0.0);
    Assert.assertTrue(population.get(1) == c1);
}
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)

Example 28 with NSGAChromosome

use of org.evosuite.ga.NSGAChromosome in project evosuite by EvoSuite.

the class TestSortByFitness method testSortByFitnessEqual.

@Test
public void testSortByFitnessEqual() {
    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.5);
    c2.setFitness(ff, 0.5);
    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.5, 0.0);
    Assert.assertEquals(population.get(1).getFitness(ff), 0.5, 0.0);
    Assert.assertTrue(population.get(1) == c2);
}
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)

Example 29 with NSGAChromosome

use of org.evosuite.ga.NSGAChromosome 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)

Example 30 with NSGAChromosome

use of org.evosuite.ga.NSGAChromosome in project evosuite by EvoSuite.

the class TestSBXCrossOver method crossoverDifferentChromosomes.

@Test
public void crossoverDifferentChromosomes() throws Exception {
    NSGAChromosome c1 = new NSGAChromosome();
    c1.addVariable(new DoubleVariable(0.9, 0.0, 1.0));
    NSGAChromosome c2 = new NSGAChromosome();
    c2.addVariable(new DoubleVariable(0.1, 0.0, 1.0));
    SBXCrossover sbx = new SBXCrossover();
    sbx.crossOver(c1, c2);
    double v_c1 = ((DoubleVariable) c1.getVariable(0)).getValue();
    Assert.assertEquals(v_c1, 0.1, 0.01);
    double v_c2 = ((DoubleVariable) c2.getVariable(0)).getValue();
    Assert.assertEquals(v_c2, 0.9, 0.01);
}
Also used : NSGAChromosome(org.evosuite.ga.NSGAChromosome) DoubleVariable(org.evosuite.ga.variables.DoubleVariable) Test(org.junit.Test)

Aggregations

NSGAChromosome (org.evosuite.ga.NSGAChromosome)36 Test (org.junit.Test)35 FitnessFunction (org.evosuite.ga.FitnessFunction)24 Problem (org.evosuite.ga.problems.Problem)24 ArrayList (java.util.ArrayList)16 NSGAII (org.evosuite.ga.metaheuristics.NSGAII)8 DoubleVariable (org.evosuite.ga.variables.DoubleVariable)7 Booths (org.evosuite.ga.problems.singleobjective.Booths)6 List (java.util.List)5 Chromosome (org.evosuite.ga.Chromosome)4 RandomFactory (org.evosuite.ga.metaheuristics.RandomFactory)4 SBXCrossover (org.evosuite.ga.operators.crossover.SBXCrossover)4 BinaryTournamentSelectionCrowdedComparison (org.evosuite.ga.operators.selection.BinaryTournamentSelectionCrowdedComparison)4 FONIntTest (org.evosuite.ga.problems.multiobjective.FONIntTest)3 CrowdingComparator (org.evosuite.ga.comparators.CrowdingComparator)2 FON (org.evosuite.ga.problems.multiobjective.FON)2 SCH (org.evosuite.ga.problems.multiobjective.SCH)1 Variable (org.evosuite.ga.variables.Variable)1