Search in sources :

Example 6 with Problem

use of org.evosuite.ga.problems.Problem in project evosuite by EvoSuite.

the class POLIntTest method testPOLFitnesses.

@Test
public void testPOLFitnesses() {
    Problem p = new POL();
    FitnessFunction f1 = (FitnessFunction) p.getFitnessFunctions().get(0);
    FitnessFunction f2 = (FitnessFunction) p.getFitnessFunctions().get(1);
    double[] values = { -2.9272124303, 2.7365080818 };
    NSGAChromosome c = new NSGAChromosome(-Math.PI, Math.PI, values);
    Assert.assertEquals(f1.getFitness(c), 9.25584063461892, 0.0);
    Assert.assertEquals(f2.getFitness(c), 13.966790675659546, 0.0);
}
Also used : NSGAChromosome(org.evosuite.ga.NSGAChromosome) Problem(org.evosuite.ga.problems.Problem) FitnessFunction(org.evosuite.ga.FitnessFunction) Test(org.junit.Test)

Example 7 with Problem

use of org.evosuite.ga.problems.Problem in project evosuite by EvoSuite.

the class SCHIntTest method testSCH.

/**
 * Testing NSGA-II with SCH Problem
 *
 * @throws IOException
 * @throws NumberFormatException
 */
@Test
public void testSCH() throws NumberFormatException, IOException {
    Properties.MUTATION_RATE = 1d / 1d;
    ChromosomeFactory<?> factory = new RandomFactory(false, 1, Math.pow(-10.0, 3.0), Math.pow(10.0, 3.0));
    GeneticAlgorithm<?> ga = new NSGAII(factory);
    BinaryTournamentSelectionCrowdedComparison ts = new BinaryTournamentSelectionCrowdedComparison();
    ts.setMaximize(false);
    ga.setSelectionFunction(ts);
    ga.setCrossOverFunction(new SBXCrossover());
    Problem p = new SCH();
    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];
    int index = 0;
    for (Chromosome chromosome : chromosomes) {
        System.out.printf("%f,%f\n", chromosome.getFitness(f1), chromosome.getFitness(f2));
        front[index][0] = Double.valueOf(chromosome.getFitness(f1));
        front[index][1] = Double.valueOf(chromosome.getFitness(f2));
        index++;
    }
    // load True Pareto Front
    double[][] trueParetoFront = Metrics.readFront("Schaffer.pf");
    GenerationalDistance gd = new GenerationalDistance();
    double gdd = gd.evaluate(front, trueParetoFront);
    System.out.println("GenerationalDistance: " + gdd);
    Assert.assertEquals(gdd, 0.0006, 0.0001);
    Spacing sp = new Spacing();
    double spd = sp.evaluate(front);
    double spdt = sp.evaluate(trueParetoFront);
    System.out.println("SpacingFront (" + spd + ") - SpacingTrueFront (" + spdt + ") = " + Math.abs(spd - spdt));
    Assert.assertEquals(Math.abs(spd - spdt), 1.15, 0.05);
}
Also used : Chromosome(org.evosuite.ga.Chromosome) NSGAChromosome(org.evosuite.ga.NSGAChromosome) FitnessFunction(org.evosuite.ga.FitnessFunction) Spacing(org.evosuite.ga.problems.metrics.Spacing) RandomFactory(org.evosuite.ga.metaheuristics.RandomFactory) NSGAII(org.evosuite.ga.metaheuristics.NSGAII) GenerationalDistance(org.evosuite.ga.problems.metrics.GenerationalDistance) BinaryTournamentSelectionCrowdedComparison(org.evosuite.ga.operators.selection.BinaryTournamentSelectionCrowdedComparison) Problem(org.evosuite.ga.problems.Problem) List(java.util.List) SBXCrossover(org.evosuite.ga.operators.crossover.SBXCrossover) Test(org.junit.Test)

Example 8 with Problem

use of org.evosuite.ga.problems.Problem in project evosuite by EvoSuite.

the class ZDT4IntTest method testZDT4.

/**
 * Testing NSGA-II with ZDT4 Problem
 *
 * @throws IOException
 * @throws NumberFormatException
 */
@Test
public void testZDT4() throws NumberFormatException, IOException {
    Properties.MUTATION_RATE = 1d / 10d;
    ChromosomeFactory<?> factory = new RandomFactory(true, 10, -5.0, 5.0);
    GeneticAlgorithm<?> ga = new NSGAII(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];
    int index = 0;
    for (Chromosome chromosome : chromosomes) {
        System.out.printf("%f,%f\n", chromosome.getFitness(f1), chromosome.getFitness(f2));
        front[index][0] = Double.valueOf(chromosome.getFitness(f1));
        front[index][1] = Double.valueOf(chromosome.getFitness(f2));
        index++;
    }
    // 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);
    Assert.assertEquals(gdd, 0.0006, 0.0001);
    Spacing sp = new Spacing();
    double spd = sp.evaluate(front);
    double spdt = sp.evaluate(trueParetoFront);
    System.out.println("SpacingFront (" + spd + ") - SpacingTrueFront (" + spdt + ") = " + Math.abs(spd - spdt));
    Assert.assertEquals(Math.abs(spd - spdt), 0.20, 0.10);
}
Also used : Chromosome(org.evosuite.ga.Chromosome) NSGAChromosome(org.evosuite.ga.NSGAChromosome) FitnessFunction(org.evosuite.ga.FitnessFunction) Spacing(org.evosuite.ga.problems.metrics.Spacing) RandomFactory(org.evosuite.ga.metaheuristics.RandomFactory) NSGAII(org.evosuite.ga.metaheuristics.NSGAII) GenerationalDistance(org.evosuite.ga.problems.metrics.GenerationalDistance) BinaryTournamentSelectionCrowdedComparison(org.evosuite.ga.operators.selection.BinaryTournamentSelectionCrowdedComparison) Problem(org.evosuite.ga.problems.Problem) List(java.util.List) SBXCrossover(org.evosuite.ga.operators.crossover.SBXCrossover) Test(org.junit.Test)

Example 9 with Problem

use of org.evosuite.ga.problems.Problem in project evosuite by EvoSuite.

the class ZDT6IntTest method testZDT6Fitnesses.

@Test
public void testZDT6Fitnesses() {
    Problem p = new ZDT6();
    FitnessFunction f1 = (FitnessFunction) p.getFitnessFunctions().get(0);
    FitnessFunction f2 = (FitnessFunction) p.getFitnessFunctions().get(1);
    double[] values = { 0.541, 0.585, 0.915, 0.624, 0.493, 0.142, 0.971, 0.836, 0.763, 0.323 };
    NSGAChromosome c = new NSGAChromosome(0.0, 1.0, values);
    Assert.assertEquals(f1.getFitness(c), 0.9866973935066625, 0.0);
    Assert.assertEquals(f2.getFitness(c), 8.903810335418541, 0.0);
}
Also used : NSGAChromosome(org.evosuite.ga.NSGAChromosome) Problem(org.evosuite.ga.problems.Problem) FitnessFunction(org.evosuite.ga.FitnessFunction) Test(org.junit.Test)

Example 10 with Problem

use of org.evosuite.ga.problems.Problem in project evosuite by EvoSuite.

the class ZDT6IntTest method testZDT6.

/**
 * Testing NSGA-II with ZDT6 Problem
 *
 * @throws IOException
 * @throws NumberFormatException
 */
@Test
public void testZDT6() throws NumberFormatException, IOException {
    Properties.MUTATION_RATE = 1d / 10d;
    ChromosomeFactory<?> factory = new RandomFactory(false, 10, 0.0, 1.0);
    GeneticAlgorithm<?> ga = new NSGAII(factory);
    BinaryTournamentSelectionCrowdedComparison ts = new BinaryTournamentSelectionCrowdedComparison();
    ts.setMaximize(false);
    ga.setSelectionFunction(ts);
    ga.setCrossOverFunction(new SBXCrossover());
    Problem p = new ZDT6();
    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];
    int index = 0;
    for (Chromosome chromosome : chromosomes) {
        System.out.printf("%f,%f\n", chromosome.getFitness(f1), chromosome.getFitness(f2));
        front[index][0] = Double.valueOf(chromosome.getFitness(f1));
        front[index][1] = Double.valueOf(chromosome.getFitness(f2));
        index++;
    }
    // load True Pareto Front
    double[][] trueParetoFront = Metrics.readFront("ZDT6.pf");
    GenerationalDistance gd = new GenerationalDistance();
    double gdd = gd.evaluate(front, trueParetoFront);
    System.out.println("GenerationalDistance: " + gdd);
    Assert.assertEquals(gdd, 0.0005, 0.0005);
    Spacing sp = new Spacing();
    double spd = sp.evaluate(front);
    double spdt = sp.evaluate(trueParetoFront);
    System.out.println("SpacingFront (" + spd + ") - SpacingTrueFront (" + spdt + ") = " + Math.abs(spd - spdt));
    Assert.assertEquals(Math.abs(spd - spdt), 0.15, 0.05);
}
Also used : Chromosome(org.evosuite.ga.Chromosome) NSGAChromosome(org.evosuite.ga.NSGAChromosome) FitnessFunction(org.evosuite.ga.FitnessFunction) Spacing(org.evosuite.ga.problems.metrics.Spacing) RandomFactory(org.evosuite.ga.metaheuristics.RandomFactory) NSGAII(org.evosuite.ga.metaheuristics.NSGAII) GenerationalDistance(org.evosuite.ga.problems.metrics.GenerationalDistance) BinaryTournamentSelectionCrowdedComparison(org.evosuite.ga.operators.selection.BinaryTournamentSelectionCrowdedComparison) Problem(org.evosuite.ga.problems.Problem) List(java.util.List) SBXCrossover(org.evosuite.ga.operators.crossover.SBXCrossover) Test(org.junit.Test)

Aggregations

FitnessFunction (org.evosuite.ga.FitnessFunction)33 Problem (org.evosuite.ga.problems.Problem)33 Test (org.junit.Test)33 NSGAChromosome (org.evosuite.ga.NSGAChromosome)31 List (java.util.List)14 Chromosome (org.evosuite.ga.Chromosome)13 SBXCrossover (org.evosuite.ga.operators.crossover.SBXCrossover)13 BinaryTournamentSelectionCrowdedComparison (org.evosuite.ga.operators.selection.BinaryTournamentSelectionCrowdedComparison)13 NSGAII (org.evosuite.ga.metaheuristics.NSGAII)12 RandomFactory (org.evosuite.ga.metaheuristics.RandomFactory)12 ArrayList (java.util.ArrayList)10 GenerationalDistance (org.evosuite.ga.problems.metrics.GenerationalDistance)9 Spacing (org.evosuite.ga.problems.metrics.Spacing)9 Booths (org.evosuite.ga.problems.singleobjective.Booths)6 DoubleVariable (org.evosuite.ga.variables.DoubleVariable)4 FONIntTest (org.evosuite.ga.problems.multiobjective.FONIntTest)3 CrowdingComparator (org.evosuite.ga.comparators.CrowdingComparator)2 FON (org.evosuite.ga.problems.multiobjective.FON)2 SCH (org.evosuite.ga.problems.multiobjective.SCH)1 ZDT4 (org.evosuite.ga.problems.multiobjective.ZDT4)1