Search in sources :

Example 1 with NSGAChromosome

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);
}
Also used : NSGAChromosome(org.evosuite.ga.NSGAChromosome) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 2 with NSGAChromosome

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);
}
Also used : NSGAChromosome(org.evosuite.ga.NSGAChromosome) Problem(org.evosuite.ga.problems.Problem) FitnessFunction(org.evosuite.ga.FitnessFunction) Test(org.junit.Test)

Example 3 with NSGAChromosome

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);
}
Also used : NSGAChromosome(org.evosuite.ga.NSGAChromosome) Problem(org.evosuite.ga.problems.Problem) FitnessFunction(org.evosuite.ga.FitnessFunction) Test(org.junit.Test)

Example 4 with NSGAChromosome

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);
}
Also used : NSGAChromosome(org.evosuite.ga.NSGAChromosome) Problem(org.evosuite.ga.problems.Problem) FitnessFunction(org.evosuite.ga.FitnessFunction) Test(org.junit.Test)

Example 5 with NSGAChromosome

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