use of org.evosuite.ga.NSGAChromosome in project evosuite by EvoSuite.
the class TestCrowdingComparator method testCrowdingComparisonOperatorMaximize.
@Test
public void testCrowdingComparisonOperatorMaximize() {
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(true);
Collections.sort(population, cc);
// assert by Rank
Assert.assertTrue(population.get(0).getRank() == 1);
Assert.assertTrue(population.get(1).getRank() == 0);
Assert.assertTrue(population.get(2).getRank() == 0);
// assert by Distance
Assert.assertTrue(population.get(0).getDistance() == 0.1);
Assert.assertTrue(population.get(1).getDistance() == 0.5);
Assert.assertTrue(population.get(2).getDistance() == 0.4);
}
use of org.evosuite.ga.NSGAChromosome in project evosuite by EvoSuite.
the class FONIntTest method testFONFitnesses.
@Test
public void testFONFitnesses() {
Problem p = new FON();
FitnessFunction f1 = (FitnessFunction) p.getFitnessFunctions().get(0);
FitnessFunction f2 = (FitnessFunction) p.getFitnessFunctions().get(1);
double[] values = { -2.0, 1.0, 3.0 };
NSGAChromosome c = new NSGAChromosome(-4.0, 4.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(((DoubleVariable) c.getVariables().get(2)).getValue(), 3.0, 0.0);
Assert.assertEquals(f1.getFitness(c), 0.9999969200553233, 0.0);
Assert.assertEquals(f2.getFitness(c), 0.9999999696175615, 0.0);
}
use of org.evosuite.ga.NSGAChromosome in project evosuite by EvoSuite.
the class KURIntTest method testKURFitnesses.
@Test
public void testKURFitnesses() {
Problem p = new KUR();
FitnessFunction f1 = (FitnessFunction) p.getFitnessFunctions().get(0);
FitnessFunction f2 = (FitnessFunction) p.getFitnessFunctions().get(1);
double[] values = { -2, 1, 3 };
NSGAChromosome c = new NSGAChromosome(-5.0, 5.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(((DoubleVariable) c.getVariables().get(2)).getValue(), 3.0, 0.0);
Assert.assertEquals(f1.getFitness(c), -11.706929282948648, 0.0);
Assert.assertEquals(f2.getFitness(c), 9.191769144818029, 0.0);
}
use of org.evosuite.ga.NSGAChromosome in project evosuite by EvoSuite.
the class POLIntTest method testPOLFitnesses.
@Test
public void testPOLFitnesses() {
Problem p = new POL();
FitnessFunction f1 = (FitnessFunction) p.getFitnessFunctions().get(0);
FitnessFunction f2 = (FitnessFunction) p.getFitnessFunctions().get(1);
double[] values = { -2.9272124303, 2.7365080818 };
NSGAChromosome c = new NSGAChromosome(-Math.PI, Math.PI, values);
Assert.assertEquals(f1.getFitness(c), 9.25584063461892, 0.0);
Assert.assertEquals(f2.getFitness(c), 13.966790675659546, 0.0);
}
use of org.evosuite.ga.NSGAChromosome in project evosuite by EvoSuite.
the class ZDT6IntTest method testZDT6Fitnesses.
@Test
public void testZDT6Fitnesses() {
Problem p = new ZDT6();
FitnessFunction f1 = (FitnessFunction) p.getFitnessFunctions().get(0);
FitnessFunction f2 = (FitnessFunction) p.getFitnessFunctions().get(1);
double[] values = { 0.541, 0.585, 0.915, 0.624, 0.493, 0.142, 0.971, 0.836, 0.763, 0.323 };
NSGAChromosome c = new NSGAChromosome(0.0, 1.0, values);
Assert.assertEquals(f1.getFitness(c), 0.9866973935066625, 0.0);
Assert.assertEquals(f2.getFitness(c), 8.903810335418541, 0.0);
}
Aggregations