21import java.util.ArrayList;
22import java.util.Arrays;
23import java.util.Collections;
27import denoptim.graph.Candidate;
28import denoptim.programs.RunTimeParameters;
58 for (
int i=0; i<sz; i++)
95 for (
int i=0; i<sz; i++)
115 int k = population.size();
118 double aggregateFitness = 0;
119 List<Double> fitnesses =
new ArrayList<>();
123 for (
int i=0; i<k; i++)
125 fitnesses.add(population.get(i).getFitness());
127 double offSet = Math.abs(Collections.min(fitnesses));
131 for (
int i=0; i<k; i++)
133 aggregateFitness += population.get(i).getFitness() + offSet;
138 double cumulativeExpectation = 0;
141 for (
int i=0; i<k; i++)
146 cumulativeExpectation += (population.get(i).getFitness() + offSet)
147 / aggregateFitness * sz;
151 while (cumulativeExpectation > randomPointer + index)
153 selection[c] = population.get(i);
181 int k = population.size();
184 double[] cumulativeFitnesses =
new double[k];
185 cumulativeFitnesses[0] = population.get(0).
getFitness();
187 for (
int i=1; i<k; i++)
189 double fitness = population.get(i).getFitness();
191 cumulativeFitnesses[i] = cumulativeFitnesses[i-1] + fitness;
194 for (
int i=0; i<sz; i++)
197 cumulativeFitnesses[cumulativeFitnesses.length-1];
198 int index = Arrays.binarySearch(cumulativeFitnesses, randomFitness);
202 index = Math.abs(index + 1);
204 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[] performTournamentSelection(List< Candidate > eligibleParents, int sz, RunTimeParameters settings)
Select p individuals at random.
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...
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.
boolean nextBoolean()
Returns the next pseudo-random, uniformly distributed boolean value from this random number generator...
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....