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