private void initializePopulation(int populationSize, State<T, U> seed) { population = Lists.newArrayList(seed); for (int i = 0; i < populationSize; i++) { population.add(seed.mutate()); } }
private void initializePopulation(int populationSize, State<T, U> seed) { population = Lists.newArrayList(seed); for (int i = 0; i < populationSize; i++) { population.add(seed.mutate()); } }
private void initializePopulation(int populationSize, State<T, U> seed) { population = Lists.newArrayList(seed); for (int i = 0; i < populationSize; i++) { population.add(seed.mutate()); } }
/** * Nuke all but a few of the current population and then repopulate with * variants of the survivors. * @param survivors How many survivors we want to keep. */ public void mutatePopulation(int survivors) { // largest value first, oldest first in case of ties Collections.sort(population); // we copy here to avoid concurrent modification List<State<T, U>> parents = Lists.newArrayList(population.subList(0, survivors)); population.subList(survivors, population.size()).clear(); // fill out the population with offspring from the survivors int i = 0; while (population.size() < populationSize) { population.add(parents.get(i % survivors).mutate()); i++; } }
/** * Nuke all but a few of the current population and then repopulate with * variants of the survivors. * @param survivors How many survivors we want to keep. */ public void mutatePopulation(int survivors) { // largest value first, oldest first in case of ties Collections.sort(population); // we copy here to avoid concurrent modification List<State<T, U>> parents = Lists.newArrayList(population.subList(0, survivors)); population.subList(survivors, population.size()).clear(); // fill out the population with offspring from the survivors int i = 0; while (population.size() < populationSize) { population.add(parents.get(i % survivors).mutate()); i++; } }
/** * Nuke all but a few of the current population and then repopulate with * variants of the survivors. * @param survivors How many survivors we want to keep. */ public void mutatePopulation(int survivors) { // largest value first, oldest first in case of ties Collections.sort(population); // we copy here to avoid concurrent modification List<State<T, U>> parents = new ArrayList<>(population.subList(0, survivors)); population.subList(survivors, population.size()).clear(); // fill out the population with offspring from the survivors int i = 0; while (population.size() < populationSize) { population.add(parents.get(i % survivors).mutate()); i++; } }