Search in sources :

Example 11 with NSGAChromosome

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

the class TestBinaryTournamentSelectionCrowdedComparison method testNonDominationRankMaximize.

@Test
public void testNonDominationRankMaximize() {
    NSGAII<NSGAChromosome> ga = new NSGAII<NSGAChromosome>(null);
    BinaryTournamentSelectionCrowdedComparison ts = new BinaryTournamentSelectionCrowdedComparison(true);
    ts.setMaximize(true);
    ga.setSelectionFunction(ts);
    NSGAChromosome c1 = new NSGAChromosome();
    NSGAChromosome c2 = new NSGAChromosome();
    // Set Rank
    c1.setRank(1);
    c2.setRank(0);
    List<NSGAChromosome> population = new ArrayList<NSGAChromosome>();
    population.add(c1);
    population.add(c2);
    Assert.assertTrue(ts.getIndex(population) == 0);
}
Also used : NSGAChromosome(org.evosuite.ga.NSGAChromosome) NSGAII(org.evosuite.ga.metaheuristics.NSGAII) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 12 with NSGAChromosome

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

the class TestBinaryTournamentSelectionCrowdedComparison method testCrowdingDistanceMinimize.

@Test
public void testCrowdingDistanceMinimize() {
    NSGAII<NSGAChromosome> ga = new NSGAII<NSGAChromosome>(null);
    BinaryTournamentSelectionCrowdedComparison ts = new BinaryTournamentSelectionCrowdedComparison(false);
    ts.setMaximize(false);
    ga.setSelectionFunction(ts);
    NSGAChromosome c1 = new NSGAChromosome();
    NSGAChromosome c2 = new NSGAChromosome();
    // Set Rank
    c1.setRank(0);
    c2.setRank(0);
    // Set Distance
    c1.setDistance(0.1);
    c2.setDistance(0.5);
    List<NSGAChromosome> population = new ArrayList<NSGAChromosome>();
    population.add(c1);
    population.add(c2);
    Assert.assertTrue(ts.getIndex(population) == 1);
}
Also used : NSGAChromosome(org.evosuite.ga.NSGAChromosome) NSGAII(org.evosuite.ga.metaheuristics.NSGAII) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 13 with NSGAChromosome

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

the class TestBinaryTournamentSelectionCrowdedComparison method testCrowdingDistanceMaximize.

@Test
public void testCrowdingDistanceMaximize() {
    NSGAII<NSGAChromosome> ga = new NSGAII<NSGAChromosome>(null);
    BinaryTournamentSelectionCrowdedComparison ts = new BinaryTournamentSelectionCrowdedComparison(true);
    ts.setMaximize(true);
    ga.setSelectionFunction(ts);
    NSGAChromosome c1 = new NSGAChromosome();
    NSGAChromosome c2 = new NSGAChromosome();
    // Set Rank
    c1.setRank(0);
    c2.setRank(0);
    // Set Distance
    c1.setDistance(0.1);
    c2.setDistance(0.5);
    List<NSGAChromosome> population = new ArrayList<NSGAChromosome>();
    population.add(c1);
    population.add(c2);
    Assert.assertTrue(ts.getIndex(population) == 1);
}
Also used : NSGAChromosome(org.evosuite.ga.NSGAChromosome) NSGAII(org.evosuite.ga.metaheuristics.NSGAII) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 14 with NSGAChromosome

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

the class SCH2IntTest method testSCH2Fitnesses.

@Test
public void testSCH2Fitnesses() {
    Problem p = new SCH2();
    FitnessFunction f1 = (FitnessFunction) p.getFitnessFunctions().get(0);
    FitnessFunction f2 = (FitnessFunction) p.getFitnessFunctions().get(1);
    double[] values_n = { -3.0 };
    NSGAChromosome c = new NSGAChromosome(-5.0, 10.0, values_n);
    Assert.assertEquals(((DoubleVariable) c.getVariables().get(0)).getValue(), -3.0, 0.0);
    Assert.assertEquals(f1.getFitness(c), 3.0, 0.0);
    Assert.assertEquals(f2.getFitness(c), 64.0, 0.0);
    double[] values_z = { 0.0 };
    c = new NSGAChromosome(-5.0, 10.0, values_z);
    Assert.assertEquals(((DoubleVariable) c.getVariables().get(0)).getValue(), 0.0, 0.0);
    Assert.assertEquals(f1.getFitness(c), 0.0, 0.0);
    Assert.assertEquals(f2.getFitness(c), 25.0, 0.0);
    double[] values_p = { 9.0 };
    c = new NSGAChromosome(-5.0, 10.0, values_p);
    Assert.assertEquals(((DoubleVariable) c.getVariables().get(0)).getValue(), 9.0, 0.0);
    Assert.assertEquals(f1.getFitness(c), 5.0, 0.0);
    Assert.assertEquals(f2.getFitness(c), 16.0, 0.0);
}
Also used : NSGAChromosome(org.evosuite.ga.NSGAChromosome) Problem(org.evosuite.ga.problems.Problem) FitnessFunction(org.evosuite.ga.FitnessFunction) Test(org.junit.Test)

Example 15 with NSGAChromosome

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

the class TestBooths method testBoothsFitness.

@Test
public void testBoothsFitness() {
    Problem p = new Booths();
    FitnessFunction f1 = (FitnessFunction) p.getFitnessFunctions().get(0);
    double[] values = { -2.0, 1.0 };
    NSGAChromosome c = new NSGAChromosome(-10.0, 10.0, values);
    Assert.assertEquals(((DoubleVariable) c.getVariables().get(0)).getValue(), -2.0, 0.0);
    Assert.assertEquals(((DoubleVariable) c.getVariables().get(1)).getValue(), 1.0, 0.0);
    Assert.assertEquals(f1.getFitness(c), 113.0, 0.0);
    double[] values_m = { 1.0, 3.0 };
    c = new NSGAChromosome(-10.0, 10.0, values_m);
    Assert.assertEquals(f1.getFitness(c), 0.0, 0.0);
}
Also used : NSGAChromosome(org.evosuite.ga.NSGAChromosome) Problem(org.evosuite.ga.problems.Problem) FitnessFunction(org.evosuite.ga.FitnessFunction) 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