Search in sources :

Example 36 with Chromosome

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

the class MaxLengthStoppingCondition method iteration.

/**
 * {@inheritDoc}
 */
@Override
public void iteration(GeneticAlgorithm<?> algorithm) {
    double avg = 0.0;
    for (Chromosome c : algorithm.getPopulation()) {
        avg += c.size();
    }
    averageLength = avg / algorithm.getPopulation().size();
}
Also used : Chromosome(org.evosuite.ga.Chromosome)

Example 37 with Chromosome

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

the class CellularGASystemTest method setup.

public List<Chromosome> setup(StoppingCondition sc, int budget, String cut) {
    Properties.CRITERION = new Criterion[1];
    Properties.CRITERION[0] = Criterion.BRANCH;
    Properties.ALGORITHM = Algorithm.CELLULAR_GA;
    Properties.POPULATION = 50;
    Properties.STOPPING_CONDITION = sc;
    Properties.SEARCH_BUDGET = budget;
    Properties.MINIMIZE = false;
    EvoSuite evosuite = new EvoSuite();
    String targetClass = cut;
    Properties.TARGET_CLASS = targetClass;
    String[] command = new String[] { "-generateSuite", "-class", targetClass };
    Object result = evosuite.parseCommandLine(command);
    Assert.assertNotNull(result);
    GeneticAlgorithm<?> ga = getGAFromResult(result);
    List<Chromosome> population = new ArrayList<Chromosome>(ga.getBestIndividuals());
    return population;
}
Also used : EvoSuite(org.evosuite.EvoSuite) ArrayList(java.util.ArrayList) Chromosome(org.evosuite.ga.Chromosome)

Example 38 with Chromosome

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

the class NSGAIISystemTest method testIntegration.

@Test
public void testIntegration() {
    Properties.MUTATION_RATE = 1d / 1d;
    Properties.CRITERION = new Criterion[2];
    Properties.CRITERION[0] = Criterion.RHO;
    Properties.CRITERION[1] = Criterion.AMBIGUITY;
    Properties.ALGORITHM = Algorithm.NSGAII;
    EvoSuite evosuite = new EvoSuite();
    String targetClass = Calculator.class.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;
    String[] command = new String[] { "-Dselection_function=BINARY_TOURNAMENT", "-Dminimize_values=false", "-Dinline=false", "-Dminimize=true", "-Dstop_zero=false", "-Dcoverage=false", "-Djunit_tests=true", "-Dassertions=true", "-Dsandbox=true", "-Dnew_statistics=false", "-generateSuite", "-class", targetClass };
    Object result = evosuite.parseCommandLine(command);
    Assert.assertNotNull(result);
    GeneticAlgorithm<?> ga = getGAFromResult(result);
    final FitnessFunction rho = ga.getFitnessFunctions().get(0);
    final FitnessFunction ag = ga.getFitnessFunctions().get(1);
    List<Chromosome> population = new ArrayList<Chromosome>(ga.getBestIndividuals());
    Collections.sort(population, new SortByFitness(rho, false));
    for (Chromosome p : population) {
        System.out.println("Rho: " + p.getFitness(rho) + ", AG: " + p.getFitness(ag) + " | Rank: " + p.getRank());
        Assert.assertEquals(0.0, p.getFitness(rho), 0.0);
        Assert.assertEquals(0.0, p.getFitness(ag), 0.0);
        Assert.assertEquals(0, p.getRank());
    }
}
Also used : EvoSuite(org.evosuite.EvoSuite) ArrayList(java.util.ArrayList) Chromosome(org.evosuite.ga.Chromosome) NSGAChromosome(org.evosuite.ga.NSGAChromosome) SortByFitness(org.evosuite.ga.comparators.SortByFitness) FitnessFunction(org.evosuite.ga.FitnessFunction) Test(org.junit.Test)

Example 39 with Chromosome

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

the class SPEA2Test method testEnvironmentalSelection_SmallArchive.

@Test
public void testEnvironmentalSelection_SmallArchive() {
    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 = 5;
    SPEA2<Chromosome> algorithm = new SPEA2<Chromosome>(null);
    List<Chromosome> archive = algorithm.environmentalSelection(population);
    assertEquals(3, archive.size());
    population.clear();
    population.add(t1);
    population.add(t2);
    population.add(t3);
    TestSuiteChromosome t4 = new TestSuiteChromosome();
    t4.setDistance(1.0);
    population.add(t4);
    TestSuiteChromosome t5 = new TestSuiteChromosome();
    t5.setDistance(1.0);
    population.add(t5);
    archive = algorithm.environmentalSelection(population);
    assertEquals(5, archive.size());
}
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 40 with Chromosome

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

the class SPEA2Test method testDistanceOfEqualChromosomes.

@Test
public void testDistanceOfEqualChromosomes() {
    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.5);
    t2.setFitness(line, 0.3);
    assertEquals(0.0, algorithm.distanceBetweenObjectives(t1, t2), 0.0);
}
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)

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