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