$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.RunTimeParameters;
11import denoptim.programs.denovo.GAParameters;
12import denoptim.utils.Randomizer;;
13
21{
22//------------------------------------------------------------------------------
23
24 @SuppressWarnings("null")
25 @Test
26 public void testPerformSUS() {
27 // Create a sample population of candidates
28 List<Candidate> population = new ArrayList<>();
29 Double[] fitnesses = {3.0, 2.0, 1.1, -1.3, -2.4};
30 for (int i=0; i<fitnesses.length; i++)
31 {
32 population.add(new Candidate());
33 population.get(i).setFitness(fitnesses[i]);
34 }
35
36 // Set the number of individuals to select
37 int sz1 = 1;
38 int sz2 = 2;
39
40 // Create a settings object with a randomizer
41 GAParameters settings = new GAParameters();
42 settings.setRandomizer(new Randomizer());
43
44 // Perform SUS and obtain the selection
45 Candidate[] selection1 = SelectionHelper.performSUS(population, sz1, settings);
46 Candidate[] selection2 = SelectionHelper.performSUS(population, sz2, settings);
47
48
49 // Check if the selection size is as expected
50 assertEquals(sz1, selection1.length);
51 assertEquals(sz2, selection2.length);
52
53 // Check if the selected candidates are part of the population
54// for (Candidate candidate : selection) {
55// assertTrue(population.contains(candidate));
56// }
57
58 }
59
60}
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