From 226365bd6a0f56143ffbce7379857ff3e126fbaf Mon Sep 17 00:00:00 2001 From: Eduardo Pedroni Date: Mon, 7 Apr 2014 15:58:30 +0100 Subject: Refactoring resources for (hopefully) the last time --- src/jcgp/backend/modules/ea/MuPlusLambda.java | 98 --------------------------- 1 file changed, 98 deletions(-) delete mode 100644 src/jcgp/backend/modules/ea/MuPlusLambda.java (limited to 'src/jcgp/backend/modules/ea/MuPlusLambda.java') diff --git a/src/jcgp/backend/modules/ea/MuPlusLambda.java b/src/jcgp/backend/modules/ea/MuPlusLambda.java deleted file mode 100644 index 0d16111..0000000 --- a/src/jcgp/backend/modules/ea/MuPlusLambda.java +++ /dev/null @@ -1,98 +0,0 @@ -package jcgp.backend.modules.ea; - -import jcgp.backend.modules.mutator.Mutator; -import jcgp.backend.population.Population; -import jcgp.backend.resources.Resources; -import jcgp.backend.resources.parameters.BooleanParameter; -import jcgp.backend.resources.parameters.IntegerParameter; -import jcgp.backend.resources.parameters.Parameter; -import jcgp.backend.resources.parameters.ParameterStatus; - -/** - * (μ + λ) EA. - * - * - * @author Eduardo Pedroni - * - */ -public class MuPlusLambda implements EvolutionaryAlgorithm { - - private int fittestChromosome; - - private IntegerParameter parents, offspring; - private BooleanParameter report; - - public MuPlusLambda(final Resources resources) { - parents = new IntegerParameter(1, "Parents") { - @Override - public void validate(int newValue) { - if (newValue + offspring.get() != resources.getInt("popSize")) { - status = ParameterStatus.INVALID; - status.setDetails("Parents + offspring must equal population size."); - } else if (newValue <= 0) { - status = ParameterStatus.INVALID; - status.setDetails("EA needs at least 1 parent."); - } else { - status = ParameterStatus.VALID; - } - } - }; - offspring = new IntegerParameter(4, "Offspring") { - @Override - public void validate(int newValue) { - if (newValue + parents.get() != resources.getInt("popSize")) { - status = ParameterStatus.INVALID; - status.setDetails("Parents + offspring must equal population size."); - } else if (newValue <= 0) { - status = ParameterStatus.INVALID; - status.setDetails("EA needs at least 1 offspring."); - } else { - status = ParameterStatus.VALID; - } - } - }; - report = new BooleanParameter(false, "Report") { - @Override - public void validate(boolean newValue) { - // nothing - } - }; - } - - @Override - public void evolve(Population population, Mutator mutator, Resources resources) { - // select fittest chromosomes - fittestChromosome = 0; - - for (int i = 1; i < resources.getInt("popSize"); i++) { - if (population.getChromosome(i).getFitness() >= population.getChromosome(fittestChromosome).getFitness()) { - fittestChromosome = i; - } - } - - // create copies of fittest chromosome, mutate them - for (int i = 0; i < resources.getInt("popSize"); i++) { - if (i != fittestChromosome) { - population.copyChromosome(fittestChromosome, i); - mutator.mutate(population.getChromosome(i), resources); - } - } - - } - - @Override - public int getFittestChromosome() { - return fittestChromosome; - } - - @Override - public Parameter[] getLocalParameters() { - return new Parameter[] {parents, offspring, report}; - } - - @Override - public String toString() { - return "(μ + λ)"; - } - -} -- cgit v1.2.3