$darkmode
DENOPTIM
SeelctionHelperTest.java
Go to the documentation of this file.
1package denoptim.ga;
2
3import static org.junit.jupiter.api.Assertions.assertEquals;
4import org.junit.Test;
5
6import java.util.ArrayList;
7import java.util.List;
8
9import denoptim.graph.Candidate;
10import denoptim.programs.denovo.GAParameters;
11import denoptim.utils.Randomizer;;
12
20{
21//------------------------------------------------------------------------------
22
23 @SuppressWarnings("null")
24 @Test
25 public void testPerformSUS() {
26 // Create a sample population of candidates
27 List<Candidate> population = new ArrayList<>();
28 Double[] fitnesses = {3.0, 2.0, 1.1, -1.3, -2.4};
29 for (int i=0; i<fitnesses.length; i++)
30 {
31 population.add(new Candidate());
32 population.get(i).setFitness(fitnesses[i]);
33 }
34
35 // Set the number of individuals to select
36 int sz1 = 1;
37 int sz2 = 2;
38
39 // Create a settings object with a randomizer
40 GAParameters settings = new GAParameters();
41 settings.setRandomizer(new Randomizer());
42
43 // Perform SUS and obtain the selection
44 Candidate[] selection1 = SelectionHelper.performSUS(population, sz1, settings);
45 Candidate[] selection2 = SelectionHelper.performSUS(population, sz2, settings);
46
47
48 // Check if the selection size is as expected
49 assertEquals(sz1, selection1.length);
50 assertEquals(sz2, selection2.length);
51
52 // Check if the selected candidates are part of the population
53// for (Candidate candidate : selection) {
54// assertTrue(population.contains(candidate));
55// }
56
57 }
58
59}
Class that offers methods to performs fitness-driven selection of candidates.
static Candidate[] performSUS(List< Candidate > population, int sz, RunTimeParameters settings)
Stochastic Uniform Sampling Note: this implementation is based on the WATCHMAKER framework http://wat...
A candidate is the combination of a denoptim graph with molecular representation and may include also...
Definition: Candidate.java:40
void setRandomizer(Randomizer rng)
Sets the randomizer.
Parameters for genetic algorithm.
Tool to generate random numbers and random decisions.
Definition: Randomizer.java:35