Search in sources :

Example 26 with Chromosome

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

the class SPEA2Test method testComputeStrength.

@Test
public void testComputeStrength() {
    List<Chromosome> population = new ArrayList<Chromosome>();
    BranchCoverageSuiteFitness branch = new BranchCoverageSuiteFitness();
    LineCoverageSuiteFitness line = new LineCoverageSuiteFitness();
    // dominates all the other two chromosomes
    TestSuiteChromosome t1 = new TestSuiteChromosome();
    t1.setFitness(branch, 0.0);
    t1.setFitness(line, 0.0);
    population.add(t1);
    // t2 only dominates t3
    TestSuiteChromosome t2 = new TestSuiteChromosome();
    t2.setFitness(branch, 0.5);
    t2.setFitness(line, 0.5);
    population.add(t2);
    // t3 is dominated by all chromosomes
    TestSuiteChromosome t3 = new TestSuiteChromosome();
    t3.setFitness(branch, 1.0);
    t3.setFitness(line, 1.0);
    population.add(t3);
    SPEA2<Chromosome> algorithm = new SPEA2<Chromosome>(null);
    algorithm.computeStrength(population);
    assertEquals(0.36, t1.getDistance(), 0.01);
    assertEquals(2.36, t2.getDistance(), 0.01);
    assertEquals(3.36, t3.getDistance(), 0.01);
    // invert order of chromosomes
    population.clear();
    population.add(t3);
    population.add(t2);
    population.add(t1);
    algorithm.computeStrength(population);
    assertEquals(0.36, t1.getDistance(), 0.01);
    assertEquals(2.36, t2.getDistance(), 0.01);
    assertEquals(3.36, t3.getDistance(), 0.01);
}
Also used : LineCoverageSuiteFitness(org.evosuite.coverage.line.LineCoverageSuiteFitness) BranchCoverageSuiteFitness(org.evosuite.coverage.branch.BranchCoverageSuiteFitness) ArrayList(java.util.ArrayList) Chromosome(org.evosuite.ga.Chromosome) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) Test(org.junit.Test)

Example 27 with Chromosome

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

the class SPEA2Test method testDistanceOfDifferentChromosomes.

@Test
public void testDistanceOfDifferentChromosomes() {
    SPEA2<Chromosome> algorithm = new SPEA2<Chromosome>(null);
    BranchCoverageSuiteFitness branch = new BranchCoverageSuiteFitness();
    LineCoverageSuiteFitness line = new LineCoverageSuiteFitness();
    TestSuiteChromosome t1 = new TestSuiteChromosome();
    t1.setFitness(branch, 0.5);
    t1.setFitness(line, 0.3);
    TestSuiteChromosome t2 = new TestSuiteChromosome();
    t2.setFitness(branch, 0.3);
    t2.setFitness(line, 0.5);
    assertEquals(0.28, algorithm.distanceBetweenObjectives(t1, t2), 0.01);
}
Also used : LineCoverageSuiteFitness(org.evosuite.coverage.line.LineCoverageSuiteFitness) BranchCoverageSuiteFitness(org.evosuite.coverage.branch.BranchCoverageSuiteFitness) Chromosome(org.evosuite.ga.Chromosome) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) Test(org.junit.Test)

Example 28 with Chromosome

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

the class SPEA2Test method testEnvironmentalSelection_ArchiveTruncation.

@Test
public void testEnvironmentalSelection_ArchiveTruncation() {
    List<Chromosome> population = new ArrayList<Chromosome>();
    BranchCoverageSuiteFitness branch = new BranchCoverageSuiteFitness();
    LineCoverageSuiteFitness line = new LineCoverageSuiteFitness();
    // fill population with good solutions
    TestSuiteChromosome t1 = new TestSuiteChromosome();
    t1.setFitness(branch, 0.0);
    t1.setFitness(line, 0.0);
    population.add(t1);
    TestSuiteChromosome t2 = new TestSuiteChromosome();
    t2.setFitness(branch, 0.01);
    t2.setFitness(line, 0.1);
    population.add(t2);
    TestSuiteChromosome t3 = new TestSuiteChromosome();
    t3.setFitness(branch, 0.5);
    t3.setFitness(line, 0.5);
    population.add(t3);
    TestSuiteChromosome t4 = new TestSuiteChromosome();
    t4.setFitness(branch, 0.75);
    t4.setFitness(line, 0.5);
    population.add(t4);
    TestSuiteChromosome t5 = new TestSuiteChromosome();
    t5.setFitness(branch, 0.75);
    t5.setFitness(line, 0.5);
    population.add(t5);
    TestSuiteChromosome t6 = new TestSuiteChromosome();
    t6.setFitness(branch, 0.80);
    t6.setFitness(line, 0.80);
    population.add(t6);
    // max number of solutions
    Properties.POPULATION = 3;
    SPEA2<Chromosome> algorithm = new SPEA2<Chromosome>(null);
    List<Chromosome> archive = algorithm.environmentalSelection(population);
    assertEquals(3, archive.size());
    assertTrue(t1.equals(archive.get(0)));
    assertTrue(t3.equals(archive.get(1)));
    assertTrue(t6.equals(archive.get(2)));
}
Also used : LineCoverageSuiteFitness(org.evosuite.coverage.line.LineCoverageSuiteFitness) BranchCoverageSuiteFitness(org.evosuite.coverage.branch.BranchCoverageSuiteFitness) ArrayList(java.util.ArrayList) Chromosome(org.evosuite.ga.Chromosome) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) Test(org.junit.Test)

Example 29 with Chromosome

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

the class SPEA2Test method testEnvironmentalSelection_FitArchive.

@Test
public void testEnvironmentalSelection_FitArchive() {
    List<Chromosome> population = new ArrayList<Chromosome>();
    TestSuiteChromosome t1 = new TestSuiteChromosome();
    t1.setDistance(0.0);
    population.add(t1);
    TestSuiteChromosome t2 = new TestSuiteChromosome();
    t2.setDistance(0.1);
    population.add(t2);
    TestSuiteChromosome t3 = new TestSuiteChromosome();
    t3.setDistance(0.2);
    population.add(t3);
    Properties.POPULATION = 3;
    SPEA2<Chromosome> algorithm = new SPEA2<Chromosome>(null);
    List<Chromosome> archive = algorithm.environmentalSelection(population);
    assertEquals(3, archive.size());
    assertEquals(0.0, archive.get(0).getDistance(), 0.0);
    assertEquals(0.1, archive.get(1).getDistance(), 0.0);
    assertEquals(0.2, archive.get(2).getDistance(), 0.0);
}
Also used : ArrayList(java.util.ArrayList) Chromosome(org.evosuite.ga.Chromosome) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) Test(org.junit.Test)

Example 30 with Chromosome

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

the class SPEA2Test method testEuclideanDistanceMatrix.

@Test
public void testEuclideanDistanceMatrix() {
    List<Chromosome> population = new ArrayList<Chromosome>();
    BranchCoverageSuiteFitness branch = new BranchCoverageSuiteFitness();
    LineCoverageSuiteFitness line = new LineCoverageSuiteFitness();
    TestSuiteChromosome t1 = new TestSuiteChromosome();
    t1.setFitness(branch, 0.5);
    t1.setFitness(line, 0.3);
    population.add(t1);
    TestSuiteChromosome t2 = new TestSuiteChromosome();
    t2.setFitness(branch, 0.3);
    t2.setFitness(line, 0.5);
    population.add(t2);
    SPEA2<Chromosome> algorithm = new SPEA2<Chromosome>(null);
    double[][] matrix = algorithm.euclideanDistanceMatrix(population);
    assertEquals(2, matrix.length);
    assertEquals(2, matrix[0].length);
    assertEquals(2, matrix[1].length);
    assertEquals(0.0, matrix[0][0], 0.0);
    assertEquals(0.0, matrix[1][1], 0.0);
    assertEquals(0.28, matrix[0][1], 0.01);
    assertEquals(0.28, matrix[1][0], 0.01);
}
Also used : LineCoverageSuiteFitness(org.evosuite.coverage.line.LineCoverageSuiteFitness) BranchCoverageSuiteFitness(org.evosuite.coverage.branch.BranchCoverageSuiteFitness) ArrayList(java.util.ArrayList) Chromosome(org.evosuite.ga.Chromosome) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) Test(org.junit.Test)

Aggregations

Chromosome (org.evosuite.ga.Chromosome)60 Test (org.junit.Test)41 TestSuiteChromosome (org.evosuite.testsuite.TestSuiteChromosome)32 ArrayList (java.util.ArrayList)29 Neighbourhood (org.evosuite.ga.Neighbourhood)20 FitnessFunction (org.evosuite.ga.FitnessFunction)15 List (java.util.List)13 SBXCrossover (org.evosuite.ga.operators.crossover.SBXCrossover)13 BinaryTournamentSelectionCrowdedComparison (org.evosuite.ga.operators.selection.BinaryTournamentSelectionCrowdedComparison)13 Problem (org.evosuite.ga.problems.Problem)13 NSGAChromosome (org.evosuite.ga.NSGAChromosome)12 NSGAII (org.evosuite.ga.metaheuristics.NSGAII)12 RandomFactory (org.evosuite.ga.metaheuristics.RandomFactory)12 GenerationalDistance (org.evosuite.ga.problems.metrics.GenerationalDistance)9 Spacing (org.evosuite.ga.problems.metrics.Spacing)9 TestChromosome (org.evosuite.testcase.TestChromosome)6 BranchCoverageSuiteFitness (org.evosuite.coverage.branch.BranchCoverageSuiteFitness)5 LineCoverageSuiteFitness (org.evosuite.coverage.line.LineCoverageSuiteFitness)5 DoubleVariable (org.evosuite.ga.variables.DoubleVariable)4 EvoSuite (org.evosuite.EvoSuite)3