Search in sources :

Example 16 with Chromosome

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

the class NeighbourhoodTest method testSouthWestNeighbour.

@Test
public void testSouthWestNeighbour() {
    this.constructPopulation();
    Neighbourhood<Chromosome> neighbourhood = new Neighbourhood<>(Properties.POPULATION);
    List<Chromosome> neighbors = new ArrayList<>();
    neighbors = neighbourhood.compactNine(population, 5);
    Chromosome exepcted_individual = population.get(8);
    Chromosome returned_individual = neighbors.get(5);
    assertEquals(exepcted_individual, returned_individual);
}
Also used : Neighbourhood(org.evosuite.ga.Neighbourhood) ArrayList(java.util.ArrayList) Chromosome(org.evosuite.ga.Chromosome) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) Test(org.junit.Test)

Example 17 with Chromosome

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

the class NeighbourhoodTest method testSouthNeighbour.

@Test
public void testSouthNeighbour() {
    this.constructPopulation();
    Neighbourhood<Chromosome> neighbourhood = new Neighbourhood<>(Properties.POPULATION);
    List<Chromosome> neighbors = new ArrayList<>();
    neighbors = neighbourhood.linearFive(population, 5);
    Chromosome exepcted_individual = population.get(9);
    Chromosome returned_individual = neighbors.get(1);
    assertEquals(exepcted_individual, returned_individual);
}
Also used : Neighbourhood(org.evosuite.ga.Neighbourhood) ArrayList(java.util.ArrayList) Chromosome(org.evosuite.ga.Chromosome) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) Test(org.junit.Test)

Example 18 with Chromosome

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

the class NeighbourhoodTest method testSouthEastNeighbour.

@Test
public void testSouthEastNeighbour() {
    this.constructPopulation();
    Neighbourhood<Chromosome> neighbourhood = new Neighbourhood<>(Properties.POPULATION);
    List<Chromosome> neighbors = new ArrayList<>();
    neighbors = neighbourhood.compactNine(population, 5);
    Chromosome exepcted_individual = population.get(10);
    Chromosome returned_individual = neighbors.get(7);
    assertEquals(exepcted_individual, returned_individual);
}
Also used : Neighbourhood(org.evosuite.ga.Neighbourhood) ArrayList(java.util.ArrayList) Chromosome(org.evosuite.ga.Chromosome) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) Test(org.junit.Test)

Example 19 with Chromosome

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

the class MOSATournamentSelection method getIndex.

/**
 * {@inheritDoc}
 *
 * Perform the tournament on the population, return one index
 */
@Override
public int getIndex(List<T> population) {
    int new_num = Randomness.nextInt(population.size());
    int winner = new_num;
    int round = 0;
    while (round < Properties.TOURNAMENT_SIZE - 1) {
        new_num = Randomness.nextInt(population.size());
        if (new_num == winner)
            new_num = (new_num + 1) % population.size();
        Chromosome selected = population.get(new_num);
        int flag = comparator.compare(selected, population.get(winner));
        if (flag == -1) {
            winner = new_num;
        }
        round++;
    }
    return winner;
}
Also used : Chromosome(org.evosuite.ga.Chromosome)

Example 20 with Chromosome

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

the class SinglePointCrossOver method crossOver.

/**
 * {@inheritDoc}
 *
 * A different splitting point is selected for each individual
 */
@Override
public void crossOver(Chromosome parent1, Chromosome parent2) throws ConstructionFailedException {
    if (parent1.size() < 2 || parent2.size() < 2) {
        return;
    }
    // Choose a position in the middle
    int point1 = Randomness.nextInt(parent1.size() - 1) + 1;
    int point2 = Randomness.nextInt(parent2.size() - 1) + 1;
    Chromosome t1 = parent1.clone();
    Chromosome t2 = parent2.clone();
    parent1.crossOver(t2, point1, point2);
    parent2.crossOver(t1, point2, point1);
}
Also used : Chromosome(org.evosuite.ga.Chromosome)

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