Search in sources :

Example 1 with RankSelection

use of org.evosuite.ga.operators.selection.RankSelection in project evosuite by EvoSuite.

the class TestSelectionOperators method testMaximizeVariable.

@Test
public void testMaximizeVariable() {
    SelectionFunction[] v = new SelectionFunction[] { new TournamentSelection(), new FitnessProportionateSelection(), new RankSelection() };
    for (SelectionFunction sf : v) {
        sf.setMaximize(true);
        Assert.assertTrue(sf.isMaximize());
        sf.setMaximize(false);
        Assert.assertTrue(!sf.isMaximize());
    }
}
Also used : SelectionFunction(org.evosuite.ga.operators.selection.SelectionFunction) RankSelection(org.evosuite.ga.operators.selection.RankSelection) TournamentSelection(org.evosuite.ga.operators.selection.TournamentSelection) FitnessProportionateSelection(org.evosuite.ga.operators.selection.FitnessProportionateSelection)

Example 2 with RankSelection

use of org.evosuite.ga.operators.selection.RankSelection in project evosuite by EvoSuite.

the class TestSelectionOperators method testProportions.

@Ignore
@Test
public void testProportions() {
    boolean[] maximize = new boolean[] { false, true };
    SelectionFunction[] v = new SelectionFunction[] { new TournamentSelection(), new FitnessProportionateSelection(), new RankSelection() };
    final int N = 10;
    for (boolean b : maximize) {
        List<Chromosome> population = new LinkedList<Chromosome>();
        for (int i = 0; i < N; i++) {
            ExecutableChromosome ind = new TestChromosome();
            double fit = b ? N - i : i;
            // ind.setFitness(fit);
            ind.addFitness(null, fit);
            // Rank selection assumes the population in order, but for the others does not matter
            population.add(ind);
        }
        for (SelectionFunction sf : v) {
            sf.setMaximize(b);
            int[] counter = new int[N];
            for (int j = 0; j < 10000; j++) {
                int index = sf.getIndex(population);
                counter[index]++;
            }
            for (int j = 0; j < N - 1; j++) {
                Assert.assertTrue("" + counter[j] + " " + counter[j + 1], counter[j] > counter[j + 1]);
            }
            Assert.assertTrue(counter[N - 1] > 0);
        }
    }
}
Also used : RankSelection(org.evosuite.ga.operators.selection.RankSelection) Chromosome(org.evosuite.ga.Chromosome) TournamentSelection(org.evosuite.ga.operators.selection.TournamentSelection) SelectionFunction(org.evosuite.ga.operators.selection.SelectionFunction) FitnessProportionateSelection(org.evosuite.ga.operators.selection.FitnessProportionateSelection)

Aggregations

FitnessProportionateSelection (org.evosuite.ga.operators.selection.FitnessProportionateSelection)2 RankSelection (org.evosuite.ga.operators.selection.RankSelection)2 SelectionFunction (org.evosuite.ga.operators.selection.SelectionFunction)2 TournamentSelection (org.evosuite.ga.operators.selection.TournamentSelection)2 Chromosome (org.evosuite.ga.Chromosome)1