use of org.evosuite.ga.problems.multiobjective.ZDT4 in project evosuite by EvoSuite.
the class SPEA2Test method testZDT4.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testZDT4() throws IOException {
Properties.MUTATION_RATE = 1d / 10d;
Properties.POPULATION = 100;
Properties.SEARCH_BUDGET = 250;
Properties.STOPPING_CONDITION = StoppingCondition.MAXGENERATIONS;
Properties.CROSSOVER_RATE = 0.9;
Properties.RANDOM_SEED = 1l;
ChromosomeFactory<?> factory = new RandomFactory(true, 10, -5.0, 5.0);
GeneticAlgorithm<?> ga = new SPEA2(factory);
BinaryTournamentSelectionCrowdedComparison ts = new BinaryTournamentSelectionCrowdedComparison();
ts.setMaximize(false);
ga.setSelectionFunction(ts);
ga.setCrossOverFunction(new SBXCrossover());
Problem p = new ZDT4();
final FitnessFunction f1 = (FitnessFunction) p.getFitnessFunctions().get(0);
final FitnessFunction f2 = (FitnessFunction) p.getFitnessFunctions().get(1);
ga.addFitnessFunction(f1);
ga.addFitnessFunction(f2);
// execute
ga.generateSolution();
List<Chromosome> chromosomes = (List<Chromosome>) ga.getPopulation();
Collections.sort(chromosomes, new Comparator<Chromosome>() {
@Override
public int compare(Chromosome arg0, Chromosome arg1) {
return Double.compare(arg0.getFitness(f1), arg1.getFitness(f1));
}
});
double[][] front = new double[Properties.POPULATION][2];
for (int i = 0; i < chromosomes.size(); i++) {
Chromosome chromosome = chromosomes.get(i);
System.out.printf("%f,%f\n", chromosome.getFitness(f1), chromosome.getFitness(f2));
front[i][0] = Double.valueOf(chromosome.getFitness(f1));
front[i][1] = Double.valueOf(chromosome.getFitness(f2));
}
// load True Pareto Front
double[][] trueParetoFront = Metrics.readFront("ZDT4.pf");
GenerationalDistance gd = new GenerationalDistance();
double gdd = gd.evaluate(front, trueParetoFront);
System.out.println("GenerationalDistance: " + gdd);
assertEquals(0.00, gdd, 0.01);
Spacing sp = new Spacing();
double spd = sp.evaluate(front);
System.out.println("SpacingFront: " + spd);
assertEquals(0.71, spd, 0.01);
}
Aggregations