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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations