21import java.util.ArrayList;
22import java.util.Arrays;
23import java.util.Collections;
24import java.util.Comparator;
28import denoptim.graph.Candidate;
29import denoptim.programs.RunTimeParameters;
30import denoptim.programs.denovo.GAParameters;
58 List<Candidate> eligibleParents,
int sz,
62 for (
int i=0; i<sz; i++)
64 List<Candidate> pool =
new ArrayList<Candidate>();
71 selection[i] = Collections.max(pool, Comparator.comparing(
72 c -> c.getFitness()));
90 for (
int i=0; i<sz; i++)
110 int k = population.size();
113 double aggregateFitness = 0;
114 List<Double> fitnesses =
new ArrayList<>();
118 for (
int i=0; i<k; i++)
120 fitnesses.add(population.get(i).getFitness());
122 double offSet = Math.abs(Collections.min(fitnesses));
126 for (
int i=0; i<k; i++)
128 aggregateFitness += population.get(i).getFitness() + offSet;
133 double cumulativeExpectation = 0;
136 for (
int i=0; i<k; i++)
141 cumulativeExpectation += (population.get(i).getFitness() + offSet)
142 / aggregateFitness * sz;
146 while (cumulativeExpectation > randomPointer + index)
148 selection[c] = population.get(i);
176 int k = population.size();
179 double[] cumulativeFitnesses =
new double[k];
180 cumulativeFitnesses[0] = population.get(0).
getFitness();
182 for (
int i=1; i<k; i++)
184 double fitness = population.get(i).getFitness();
186 cumulativeFitnesses[i] = cumulativeFitnesses[i-1] + fitness;
189 for (
int i=0; i<sz; i++)
192 cumulativeFitnesses[cumulativeFitnesses.length-1];
193 int index = Arrays.binarySearch(cumulativeFitnesses, randomFitness);
197 index = Math.abs(index + 1);
199 selection[i] = population.get(index);
Class that offers methods to performs fitness-driven selection of candidates.
static Candidate[] performRandomSelection(List< Candidate > population, int sz, RunTimeParameters settings)
Randomly select k individuals from the population.
static Candidate[] performRWS(List< Candidate > population, int sz, RunTimeParameters settings)
Roulette wheel selection is implemented as follows:
static Candidate[] performSUS(List< Candidate > population, int sz, RunTimeParameters settings)
Stochastic Uniform Sampling Note: this implementation is based on the WATCHMAKER framework http://wat...
static Candidate[] performTournamentSelection(List< Candidate > eligibleParents, int sz, GAParameters settings)
Select a number individuals at random (i.e., tournamentSize).
A candidate is the combination of a denoptim graph with molecular representation and may include also...
Collection of parameters controlling the behavior of the software.
Randomizer getRandomizer()
Returns the current program-specific randomizer.
Parameters for genetic algorithm.
int getSelectivePressure()
public< T > T randomlyChooseOne(Collection< T > c)
Chooses one member among the given collection.
double nextDouble()
Returns the next pseudo-random, uniformly distributed double value between 0.0 and 1....