Introduce new AbstractOptimizer

closes #21
- Remove methods implemented in AbstractOptimizer from optimizers whenever possible.
This commit is contained in:
Fabian Becker 2014-10-25 02:27:07 +02:00
parent a42bbf685a
commit 2ae2a17cfe
34 changed files with 192 additions and 1627 deletions

View File

@ -402,16 +402,15 @@ public class OptimizerFactory {
* are linear, grid and star.
*
* @param problem
* @param mut
* @param popsize
* @param phi1
* @param phi2
* @param speedLim
* @param selectedTopology
* @param topologyRange
* @param listener
* @param topology
* @return An optimization algorithm that performs particle swarm
* optimization.
* @see ParticleSwarmOpimization
*/
public static ParticleSwarmOptimization createParticleSwarmOptimization(
AbstractOptimizationProblem problem, int popsize, double phi1,

View File

@ -396,7 +396,7 @@ public class PostProcess {
// HC depends heavily on the selected mutation operator!
hc.setProblem(problem);
mute.init(problem.getIndividualTemplate(), problem);
hc.SetMutationOperator(mute);
hc.setMutationOperator(mute);
if (pop.size() != pop.getTargetSize()) {
System.err.println(pop.size() + " vs. " + pop.getTargetSize());
System.err.println("warning: population size and vector size dont match! (PostProcess::processWithHC)");

View File

@ -61,7 +61,7 @@ import java.util.Vector;
*
* @author aschoff, mkron
*/
public class ANPSO extends NichePSO implements InterfaceOptimizer, InterfaceAdditionalPopulationInformer, java.io.Serializable {
public class ANPSO extends NichePSO implements InterfaceAdditionalPopulationInformer, java.io.Serializable {
/**
@ -493,7 +493,7 @@ public class ANPSO extends NichePSO implements InterfaceOptimizer, InterfaceAddi
}
getMainSwarm().getPopulation().incrFunctionCallsBy(calls);
this.SetSubSwarms(newSubSwarms);
this.setSubSwarms(newSubSwarms);
}
/**
@ -928,7 +928,7 @@ public class ANPSO extends NichePSO implements InterfaceOptimizer, InterfaceAddi
anpso.getMainSwarm().setPhi1(1.2);
anpso.getMainSwarm().setPhi2(0.6); // ANPSO uses communication in the main swarm
//Possible topologies are: "Linear", "Grid", "Star", "Multi-Swarm", "Tree", "HPSO", "Random" in that order starting by 0.
anpso.SetMainSwarmTopologyTag(3); //"Multi-Swarm" favors the formation of groups in the main swarm
anpso.setMainSwarmTopologyTag(3); //"Multi-Swarm" favors the formation of groups in the main swarm
anpso.setMainSwarmTopologyRange(2); // range for topologies like random, grid etc. (does not affect "Multi-Swarm")
anpso.setMaxInitialSubSwarmSize(0); // deactivate early reinits
@ -948,7 +948,7 @@ public class ANPSO extends NichePSO implements InterfaceOptimizer, InterfaceAddi
anpso.getMainSwarm().setPhi1(1.2);
anpso.getMainSwarm().setPhi2(1.2); // ANPSO uses communication in the main swarm
//Possible topologies are: "Linear", "Grid", "Star", "Multi-Swarm", "Tree", "HPSO", "Random" in that order starting by 0.
anpso.SetMainSwarmTopologyTag(3); //"Multi-Swarm" favors the formation of groups in the main swarm
anpso.setMainSwarmTopologyTag(3); //"Multi-Swarm" favors the formation of groups in the main swarm
anpso.setMainSwarmTopologyRange(4); // range for topologies like random, grid etc. (does not affect "Multi-Swarm")
// es gibt kein species size limit wie im orig-paper, aber sie berichten dort, dass sie für
@ -985,7 +985,7 @@ public class ANPSO extends NichePSO implements InterfaceOptimizer, InterfaceAddi
*/
public static OptimizationParameters starTopoANPSO(AbstractOptimizationProblem problem, long randSeed, int evalCnt, int topology, int topologyRange) {
OptimizationParameters params = starANPSO(problem, randSeed, evalCnt);
((ANPSO) params.getOptimizer()).SetMainSwarmTopologyTag(topology);
((ANPSO) params.getOptimizer()).setMainSwarmTopologyTag(topology);
((ANPSO) params.getOptimizer()).setMainSwarmTopologyRange(topologyRange);
((ANPSO) params.getOptimizer()).getMainSwarm().setInertnessOrChi(0.73);

View File

@ -0,0 +1,78 @@
package eva2.optimization.strategies;
import eva2.optimization.go.InterfacePopulationChangedEventListener;
import eva2.optimization.population.Population;
import eva2.problems.F1Problem;
import eva2.problems.InterfaceOptimizationProblem;
import eva2.util.annotation.Parameter;
import java.util.ArrayList;
/**
*
*/
public abstract class AbstractOptimizer implements InterfaceOptimizer {
@Parameter(name = "Population", description = "Edit the properties of the population used.")
protected Population population = new Population();
protected InterfaceOptimizationProblem optimizationProblem = new F1Problem();
protected ArrayList<InterfacePopulationChangedEventListener> populationChangedEventListeners;
abstract public Object clone();
@Override
public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) {
if (populationChangedEventListeners == null) {
populationChangedEventListeners = new ArrayList<>();
}
populationChangedEventListeners.add(ea);
}
@Override
public boolean removePopulationChangedEventListener(InterfacePopulationChangedEventListener ea) {
return populationChangedEventListeners != null && populationChangedEventListeners.remove(ea);
}
/**
* Something has changed
*
* @param name Event name
*/
protected void firePropertyChangedEvent(String name) {
if (this.populationChangedEventListeners != null) {
for (InterfacePopulationChangedEventListener listener : this.populationChangedEventListeners) {
listener.registerPopulationStateChanged(this, name);
}
}
}
@Override
public Population getPopulation() {
return this.population;
}
@Override
public void setPopulation(Population pop) {
this.population = pop;
}
/**
* This method will set the problem that is to be optimized
*
* @param problem
*/
@Override
public void setProblem(InterfaceOptimizationProblem problem) {
this.optimizationProblem = problem;
}
@Override
public InterfaceOptimizationProblem getProblem() {
return this.optimizationProblem;
}
}

View File

@ -14,12 +14,11 @@ import java.util.ArrayList;
*
*/
@Description(value = "Artificial Bee Colony Optimizer")
public class ArtificialBeeColony implements InterfaceOptimizer {
public class ArtificialBeeColony extends AbstractOptimizer {
protected AbstractOptimizationProblem optimizationProblem = new F1Problem();
protected Population population;
private ArrayList<InterfacePopulationChangedEventListener> populationChangedEventListeners;
public ArtificialBeeColony() {
@ -39,19 +38,6 @@ public class ArtificialBeeColony implements InterfaceOptimizer {
return "Artificial Bee Colony";
}
@Override
public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) {
if (populationChangedEventListeners == null) {
populationChangedEventListeners = new ArrayList<>();
}
populationChangedEventListeners.add(ea);
}
@Override
public boolean removePopulationChangedEventListener(InterfacePopulationChangedEventListener ea) {
return populationChangedEventListeners != null && populationChangedEventListeners.remove(ea);
}
@Override
public void initialize() {
@ -73,19 +59,6 @@ public class ArtificialBeeColony implements InterfaceOptimizer {
}
}
/**
* Something has changed
*
* @param name Event name
*/
protected void firePropertyChangedEvent(String name) {
if (this.populationChangedEventListeners != null) {
for (InterfacePopulationChangedEventListener listener : this.populationChangedEventListeners) {
listener.registerPopulationStateChanged(this, name);
}
}
}
/**
* This method will evaluate the current population using the given problem.
*
@ -104,36 +77,11 @@ public class ArtificialBeeColony implements InterfaceOptimizer {
}
@Override
public Population getPopulation() {
return this.population;
}
@Override
public void setPopulation(Population pop) {
this.population = pop;
}
@Override
public InterfaceSolutionSet getAllSolutions() {
return null;
}
/**
* This method will set the problem that is to be optimized
*
* @param problem
*/
@Override
public void setProblem(InterfaceOptimizationProblem problem) {
this.optimizationProblem = (AbstractOptimizationProblem) problem;
}
@Override
public InterfaceOptimizationProblem getProblem() {
return this.optimizationProblem;
}
@Override
public String getStringRepresentation() {
return this.toString();

View File

@ -2,7 +2,6 @@ package eva2.optimization.strategies;
import eva2.gui.BeanInspector;
import eva2.optimization.enums.BOAScoringMethods;
import eva2.optimization.go.InterfacePopulationChangedEventListener;
import eva2.optimization.individuals.AbstractEAIndividual;
import eva2.optimization.individuals.GAIndividualBinaryData;
import eva2.optimization.individuals.InterfaceDataTypeBinary;
@ -12,7 +11,6 @@ import eva2.optimization.population.Population;
import eva2.optimization.population.SolutionSet;
import eva2.problems.AbstractOptimizationProblem;
import eva2.problems.BKnapsackProblem;
import eva2.problems.InterfaceOptimizationProblem;
import eva2.tools.Pair;
import eva2.tools.math.BayNet;
import eva2.tools.math.RNG;
@ -34,18 +32,15 @@ import java.util.logging.Logger;
* Optimization Algorithm' the works by Martin Pelikan and David E. Goldberg.
* Genetic and Evolutionary Computation Conference (GECCO-99), pp. 525-532
*/
@Description(value = "Basic implementation of the Bayesian Optimization Algorithm based on the works by Martin Pelikan and David E. Goldberg.")
public class BOA implements InterfaceOptimizer, java.io.Serializable {
@Description("Basic implementation of the Bayesian Optimization Algorithm based on the works by Martin Pelikan and David E. Goldberg.")
public class BOA extends AbstractOptimizer implements java.io.Serializable {
private static final Logger LOGGER = Logger.getLogger(BOA.class.getName());
transient private InterfacePopulationChangedEventListener populationChangedEventListener = null;
private String identifier = "BOA";
private int probDim = 8;
private int fitCrit = -1;
private int PopSize = 50;
private int numberOfParents = 3;
private transient BayNet network = null;
private Population population = new Population();
private AbstractOptimizationProblem problem = new BKnapsackProblem();
private AbstractOptimizationProblem optimizationProblem = new BKnapsackProblem();
private AbstractEAIndividual template = null;
private double learningSetRatio = 0.5;
private double resampleRatio = 0.5;
@ -82,15 +77,13 @@ public class BOA implements InterfaceOptimizer, java.io.Serializable {
}
public BOA(BOA b) {
this.populationChangedEventListener = b.populationChangedEventListener;
this.identifier = b.identifier;
this.probDim = b.probDim;
this.fitCrit = b.fitCrit;
this.PopSize = b.PopSize;
this.numberOfParents = b.numberOfParents;
this.network = (BayNet) b.network.clone();
this.population = (Population) b.population.clone();
this.problem = (AbstractOptimizationProblem) b.problem.clone();
this.optimizationProblem = (AbstractOptimizationProblem) b.optimizationProblem.clone();
this.template = (AbstractEAIndividual) b.template.clone();
this.learningSetRatio = b.learningSetRatio;
this.resampleRatio = b.resampleRatio;
@ -104,7 +97,6 @@ public class BOA implements InterfaceOptimizer, java.io.Serializable {
System.arraycopy(b.edgeRate[i], 0, this.edgeRate[i], 0, this.edgeRate[i].length);
}
this.scoringMethod = b.scoringMethod;
// this.printExtraOutput = b.printExtraOutput;
this.printNetworks = b.printNetworks;
this.printMetrics = b.printMetrics;
this.printEdgeRate = b.printEdgeRate;
@ -121,12 +113,6 @@ public class BOA implements InterfaceOptimizer, java.io.Serializable {
return "Bayesian Optimization Algorithm";
}
@Override
public void addPopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) {
this.populationChangedEventListener = ea;
}
private void createDirectoryIfNeeded(String directoryName) {
File theDir = new File(directoryName);
// if the directory does not exist, create it
@ -136,17 +122,6 @@ public class BOA implements InterfaceOptimizer, java.io.Serializable {
}
}
@Override
public boolean removePopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) {
if (populationChangedEventListener == ea) {
populationChangedEventListener = null;
return true;
} else {
return false;
}
}
private static BitSet getBinaryData(AbstractEAIndividual indy) {
if (indy instanceof InterfaceGAIndividual) {
return ((InterfaceGAIndividual) indy).getBGenotype();
@ -171,7 +146,7 @@ public class BOA implements InterfaceOptimizer, java.io.Serializable {
LOGGER.log(Level.WARNING, "tried to evaluate null");
return;
}
this.problem.evaluate(indy);
this.optimizationProblem.evaluate(indy);
// increment the number of evaluations
this.population.incrFunctionCalls();
}
@ -191,11 +166,11 @@ public class BOA implements InterfaceOptimizer, java.io.Serializable {
} else {
this.population.setTargetPopSize(this.PopSize);
}
this.template = this.problem.getIndividualTemplate();
this.template = this.optimizationProblem.getIndividualTemplate();
if (!(template instanceof InterfaceDataTypeBinary)) {
LOGGER.log(Level.WARNING, "Requiring binary data!");
} else {
Object dim = BeanInspector.callIfAvailable(problem,
Object dim = BeanInspector.callIfAvailable(optimizationProblem,
"getProblemDimension", null);
if (dim == null) {
LOGGER.log(Level.WARNING, "Coudn't get problem dimension!");
@ -212,7 +187,7 @@ public class BOA implements InterfaceOptimizer, java.io.Serializable {
@Override
public void initialize() {
defaultInit();
this.problem.initializePopulation(this.population);
this.optimizationProblem.initializePopulation(this.population);
this.evaluatePopulation(this.population);
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
}
@ -495,7 +470,7 @@ public class BOA implements InterfaceOptimizer, java.io.Serializable {
@Override
public void optimize() {
this.problem.evaluatePopulationStart(this.population);
this.optimizationProblem.evaluatePopulationStart(this.population);
// get the best individuals from the population
Population best = this.population.getBestNIndividuals(
calcLearningSetSize(), this.fitCrit);
@ -516,7 +491,7 @@ public class BOA implements InterfaceOptimizer, java.io.Serializable {
this.count++;
// we are done with one generation
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
this.problem.evaluatePopulationEnd(this.population);
this.optimizationProblem.evaluatePopulationEnd(this.population);
// print output if desired
// if (this.printExtraOutput) {
if (printNetworks) {
@ -534,40 +509,11 @@ public class BOA implements InterfaceOptimizer, java.io.Serializable {
// }
}
/**
* Something has changed
*/
protected void firePropertyChangedEvent(String name) {
if (this.populationChangedEventListener != null) {
this.populationChangedEventListener.registerPopulationStateChanged(this, name);
}
}
@Override
public Population getPopulation() {
return this.population;
}
@Override
public void setPopulation(Population pop) {
this.population = pop;
}
@Override
public InterfaceSolutionSet getAllSolutions() {
return new SolutionSet(this.population);
}
@Override
public void setProblem(InterfaceOptimizationProblem problem) {
this.problem = (AbstractOptimizationProblem) problem;
}
@Override
public InterfaceOptimizationProblem getProblem() {
return this.problem;
}
@Override
public String getStringRepresentation() {
return "Bayesian Network";

View File

@ -29,9 +29,7 @@ import java.util.BitSet;
* research, vol. 37, no. 11, pp. 1977-1986 (2010)
*/
@Description("A basic implementation of a Binary ScatterSearch")
public class BinaryScatterSearch implements InterfaceOptimizer, java.io.Serializable, InterfacePopulationChangedEventListener {
transient private InterfacePopulationChangedEventListener populationChangedEventListener = null;
private String identifier = "BinaryScatterSearch";
public class BinaryScatterSearch extends AbstractOptimizer implements java.io.Serializable, InterfacePopulationChangedEventListener {
private int MaxImpIter = 5;
private int poolSize = 100;
private int refSetSize = 10;
@ -44,7 +42,7 @@ public class BinaryScatterSearch implements InterfaceOptimizer, java.io.Serializ
private double g2 = 1.0 / 3.0;
private boolean firstTime = true;
private AbstractEAIndividual template = null;
private AbstractOptimizationProblem problem = new B1Problem();
private AbstractOptimizationProblem optimizationProblem = new B1Problem();
private Population pool = new Population();
private Population refSet = new Population(10);
private AdaptiveCrossoverEAMixer cross = new AdaptiveCrossoverEAMixer(new CM1(), new CM2(), new CM3(), new CM4(), new CM5(), new CM6(), new CM7());
@ -62,8 +60,7 @@ public class BinaryScatterSearch implements InterfaceOptimizer, java.io.Serializ
* @param b
*/
public BinaryScatterSearch(BinaryScatterSearch b) {
this.populationChangedEventListener = b.populationChangedEventListener;
this.identifier = b.identifier;
this.populationChangedEventListeners = b.populationChangedEventListeners;
this.MaxImpIter = b.MaxImpIter;
this.poolSize = b.poolSize;
this.refSetSize = b.refSetSize;
@ -76,7 +73,7 @@ public class BinaryScatterSearch implements InterfaceOptimizer, java.io.Serializ
this.g2 = b.g2;
this.firstTime = b.firstTime;
this.template = (AbstractEAIndividual) b.template.clone();
this.problem = (AbstractOptimizationProblem) b.problem.clone();
this.optimizationProblem = (AbstractOptimizationProblem) b.optimizationProblem.clone();
this.pool = (Population) b.pool.clone();
this.refSet = (Population) b.refSet.clone();
this.cross = b.cross;
@ -104,7 +101,7 @@ public class BinaryScatterSearch implements InterfaceOptimizer, java.io.Serializ
this.th2 = upperThreshold;
this.g1 = perCentFirstIndGenerator;
this.g2 = perCentSecondIndGenerator;
this.problem = prob;
this.optimizationProblem = prob;
}
/**
@ -131,7 +128,7 @@ public class BinaryScatterSearch implements InterfaceOptimizer, java.io.Serializ
this.th2 = upperThreshold;
this.g1 = perCentFirstIndGenerator;
this.g2 = perCentSecondIndGenerator;
this.problem = prob;
this.optimizationProblem = prob;
this.cross = cross;
}
@ -148,23 +145,6 @@ public class BinaryScatterSearch implements InterfaceOptimizer, java.io.Serializ
return "BSS";
}
@Override
public void addPopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) {
this.populationChangedEventListener = ea;
}
@Override
public boolean removePopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) {
if (populationChangedEventListener == ea) {
populationChangedEventListener = null;
return true;
} else {
return false;
}
}
/**
* evaluate the given Individual and increments the counter. if the
* individual is null, only the counter is incremented
@ -177,7 +157,7 @@ public class BinaryScatterSearch implements InterfaceOptimizer, java.io.Serializ
System.err.println("tried to evaluate null");
return;
}
this.problem.evaluate(indy);
this.optimizationProblem.evaluate(indy);
// increment the number of evaluations
this.refSet.incrFunctionCalls();
}
@ -187,11 +167,11 @@ public class BinaryScatterSearch implements InterfaceOptimizer, java.io.Serializ
*/
private void defaultInit() {
this.refSet = new Population();
this.template = this.problem.getIndividualTemplate();
this.template = this.optimizationProblem.getIndividualTemplate();
if (!(template instanceof InterfaceDataTypeBinary)) {
System.err.println("Requiring binary data!");
} else {
Object dim = BeanInspector.callIfAvailable(problem, "getProblemDimension", null);
Object dim = BeanInspector.callIfAvailable(optimizationProblem, "getProblemDimension", null);
if (dim == null) {
System.err.println("Couldnt get problem dimension!");
}
@ -199,7 +179,7 @@ public class BinaryScatterSearch implements InterfaceOptimizer, java.io.Serializ
((InterfaceDataTypeBinary) this.template).setBinaryGenotype(new BitSet(probDim));
}
this.firstTime = true;
this.cross.init(this.template, problem, refSet, Double.MAX_VALUE);
this.cross.init(this.template, optimizationProblem, refSet, Double.MAX_VALUE);
refSet.addPopulationChangedEventListener(this);
this.refSet.setNotifyEvalInterval(this.generationCycle);
}
@ -246,7 +226,7 @@ public class BinaryScatterSearch implements InterfaceOptimizer, java.io.Serializ
* 000...000, then 010101...01, 101010...10, 001001001...001,
* 110110110...110 and so on The returned population is evaluated.
*
* @param pop the initial Population
* @param numToInit
* @return the new Population
*/
private Population generateG1(int numToInit) {
@ -471,7 +451,7 @@ public class BinaryScatterSearch implements InterfaceOptimizer, java.io.Serializ
* @param pop the generated Pool
*/
private void initRefSet(Population pop) {
this.problem.evaluatePopulationStart(this.refSet);
this.optimizationProblem.evaluatePopulationStart(this.refSet);
this.pool = pop;
refSetUpdate(true);
Population best = this.refSet.getBestNIndividuals(this.refSetSize / 2, fitCrit);
@ -484,7 +464,7 @@ public class BinaryScatterSearch implements InterfaceOptimizer, java.io.Serializ
this.refSet.add(x);
}
}
this.problem.evaluatePopulationEnd(this.refSet);
this.optimizationProblem.evaluatePopulationEnd(this.refSet);
}
/**
@ -665,7 +645,7 @@ public class BinaryScatterSearch implements InterfaceOptimizer, java.io.Serializ
for (int i = 0; i < this.refSet.size(); i++) {
pop.add(this.refSet.getEAIndividual(i));
}
this.cross.update(indy1, problem, refSet, indy1.getFitness(0));
this.cross.update(indy1, optimizationProblem, refSet, indy1.getFitness(0));
result = this.cross.mate(indy1, pop)[0];
//result = indy1.mateWith(s)[0];
} else if (pop.size() > 0) {
@ -701,7 +681,7 @@ public class BinaryScatterSearch implements InterfaceOptimizer, java.io.Serializ
@Override
public void optimize() {
problem.evaluatePopulationStart(refSet);
optimizationProblem.evaluatePopulationStart(refSet);
int funCallsStart = this.refSet.getFunctionCalls();
do {
// generate a new Pool
@ -738,12 +718,7 @@ public class BinaryScatterSearch implements InterfaceOptimizer, java.io.Serializ
refSetUpdate(true);
}
} while (refSet.getFunctionCalls() - funCallsStart < generationCycle);
problem.evaluatePopulationEnd(refSet);
}
@Override
public Population getPopulation() {
return this.refSet;
optimizationProblem.evaluatePopulationEnd(refSet);
}
@Override
@ -761,27 +736,11 @@ public class BinaryScatterSearch implements InterfaceOptimizer, java.io.Serializ
return new SolutionSet(this.refSet);
}
@Override
public void setProblem(InterfaceOptimizationProblem problem) {
this.problem = (AbstractOptimizationProblem) problem;
}
@Override
public InterfaceOptimizationProblem getProblem() {
return this.problem;
}
@Override
public String getStringRepresentation() {
return "BinaryScatterSearch";
}
protected void firePropertyChangedEvent(String name) {
if (this.populationChangedEventListener != null) {
this.populationChangedEventListener.registerPopulationStateChanged(this, name);
}
}
@Override
public void registerPopulationStateChanged(Object source, String name) {
// The events of the interim hill climbing population will be caught here
@ -795,7 +754,6 @@ public class BinaryScatterSearch implements InterfaceOptimizer, java.io.Serializ
}
}
//----------GUI----------
public int getPoolSize() {
return this.poolSize;
}

View File

@ -26,19 +26,15 @@ import java.util.BitSet;
* ToDo: Check implementation for correctness.
*/
@eva2.util.annotation.Description("This is an implementation of the CHC Adaptive Search Algorithm by Eselman.")
public class CHCAdaptiveSearchAlgorithm implements InterfaceOptimizer, java.io.Serializable {
public class CHCAdaptiveSearchAlgorithm extends AbstractOptimizer implements java.io.Serializable {
private double initialDifferenceThreshold = 0.25;
private int differenceThreshold;
private double divergenceRate = 0.35;
private boolean useElitism = true;
private int numberOfPartners = 1;
private Population population = new Population();
private InterfaceOptimizationProblem optimizationProblem = new B1Problem();
private InterfaceSelection recombSelectionOperator = new SelectRandom();
private InterfaceSelection populationSelectionOperator = new SelectBestSingle();
transient private String identifier = "";
transient private InterfacePopulationChangedEventListener interfacePopulationChangedEventListener;
public CHCAdaptiveSearchAlgorithm() {
}
@ -231,46 +227,6 @@ public class CHCAdaptiveSearchAlgorithm implements InterfaceOptimizer, java.io.S
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
}
@Override
public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) {
this.interfacePopulationChangedEventListener = ea;
}
@Override
public boolean removePopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) {
if (interfacePopulationChangedEventListener == ea) {
interfacePopulationChangedEventListener = null;
return true;
} else {
return false;
}
}
/**
* Something has changed
*/
protected void firePropertyChangedEvent(String name) {
if (this.interfacePopulationChangedEventListener != null) {
this.interfacePopulationChangedEventListener.registerPopulationStateChanged(this, name);
}
}
/**
* This method will set the problem that is to be optimized
*
* @param problem
*/
@Override
public void setProblem(InterfaceOptimizationProblem problem) {
this.optimizationProblem = problem;
}
@Override
public InterfaceOptimizationProblem getProblem() {
return this.optimizationProblem;
}
/**
* This method will return a string describing all properties of the
* optimizer and the applied methods.
@ -297,27 +253,6 @@ public class CHCAdaptiveSearchAlgorithm implements InterfaceOptimizer, java.io.S
return "CHC";
}
/**
* Assuming that all optimizer will store thier data in a population we will
* allow acess to this population to query to current state of the
* optimizer.
*
* @return The population of current solutions to a given problem.
*/
@Override
public Population getPopulation() {
return this.population;
}
@Override
public void setPopulation(Population pop) {
this.population = pop;
}
public String populationTipText() {
return "Edit the properties of the population used.";
}
@Override
public InterfaceSolutionSet getAllSolutions() {
return new SolutionSet(getPopulation());

View File

@ -44,10 +44,9 @@ import java.util.*;
* species clustering actually makes sense).
*/
@Description("This is a versatile species based niching EA method.")
public class ClusterBasedNichingEA implements InterfacePopulationChangedEventListener, InterfaceAdditionalPopulationInformer, InterfaceOptimizer, java.io.Serializable {
public class ClusterBasedNichingEA extends AbstractOptimizer implements InterfacePopulationChangedEventListener, InterfaceAdditionalPopulationInformer, java.io.Serializable {
private static final long serialVersionUID = -3143069327594708609L;
private Population population = new Population();
private transient Population populationArchive = new Population();
private ArrayList<Population> species = new ArrayList<>();
private Population undifferentiatedPopulation = new Population();
@ -59,8 +58,6 @@ public class ClusterBasedNichingEA implements InterfacePopulationChangedEventLis
private double clusterDiffDist = 0.05;
private boolean useDistraction = false;
private double epsilonBound = 1e-10;
transient private String identifier = "";
transient private InterfacePopulationChangedEventListener populationChangedEventListener;
private int speciesCycle = 1;
private int minGroupSize = 3;
@ -783,28 +780,6 @@ public class ClusterBasedNichingEA implements InterfacePopulationChangedEventLis
//Population population = ((InterfaceOptimizer)source).getPopulation();
}
@Override
public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) {
this.populationChangedEventListener = ea;
}
@Override
public boolean removePopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) {
if (populationChangedEventListener == ea) {
populationChangedEventListener = null;
return true;
} else {
return false;
}
}
protected void firePropertyChangedEvent(String name) {
if (this.populationChangedEventListener != null) {
this.populationChangedEventListener.registerPopulationStateChanged(this, name);
}
}
/**
* This method will set the problem that is to be optimized
*
@ -816,11 +791,6 @@ public class ClusterBasedNichingEA implements InterfacePopulationChangedEventLis
this.optimizer.setProblem(this.optimizationProblem);
}
@Override
public InterfaceOptimizationProblem getProblem() {
return this.optimizationProblem;
}
/**
* This method will return a string describing all properties of the
* optimizer and the applied methods.
@ -848,14 +818,6 @@ public class ClusterBasedNichingEA implements InterfacePopulationChangedEventLis
return "CBN-EA";
}
@Override
public Population getPopulation() {
// this.population = (Population)undifferentiatedPopulation.clone();
// for (int i = 0; i < this.species.size(); i++) this.population.addPopulation((Population)this.species.get(i));
// population.setPopulationSize(population.size()); // set it to true value
return this.population;
}
@Override
public void setPopulation(Population pop) {
this.undifferentiatedPopulation = pop;
@ -875,10 +837,6 @@ public class ClusterBasedNichingEA implements InterfacePopulationChangedEventLis
pop.setUseHistory(true);
}
public String populationTipText() {
return "Edit the properties of the population used.";
}
public Population getArchivedSolutions() {
return (Population) populationArchive.clone();
}
@ -1070,34 +1028,6 @@ public class ClusterBasedNichingEA implements InterfacePopulationChangedEventLis
return "Number of generations after which a cluster without improvement is seen as converged and deactivated; set to zero to disable.";
}
// /**
// * @return the useDistraction
// */
// public boolean isDistractionActive() {
// return useDistraction;
// }
//
// /**
// * @param useDistraction the useDistraction to set
// */
// public void setDistractionActive(boolean useDistraction) {
// this.useDistraction = useDistraction;
// }
// /**
// * @return the distrDefaultStrength
// */
// public double getDistrStrength() {
// return distrDefaultStrength;
// }
//
// /**
// * @param distrDefaultStrength the distrDefaultStrength to set
// */
// public void setDistrStrength(double distrDefaultStrength) {
// this.distrDefaultStrength = distrDefaultStrength;
// distraction.setDefaultStrength(distrDefaultStrength);
// }
/**
* @return the sleepTime
*/

View File

@ -31,13 +31,8 @@ import java.util.Vector;
* doomed and replaced by the next challenge vector, even if its worse.
*/
@Description(value = "Differential Evolution using a steady-state population scheme.")
public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serializable {
@Parameter(name = "Population", description = "Edit the properties of the population used.")
protected Population population = new Population();
public class DifferentialEvolution extends AbstractOptimizer implements java.io.Serializable {
protected transient Population children = null;
protected AbstractOptimizationProblem optimizationProblem = new F1Problem();
@Parameter(name = "DEType", description = "Mutation type for DE")
private eva2.optimization.enums.DEType DEType;
@ -60,7 +55,6 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial
private boolean randomizeFKLambda = false;
private boolean generational = true;
private String identifier = "";
transient private Vector<InterfacePopulationChangedEventListener> populationChangedEventListeners = new Vector<>();
private boolean forceRange = true;
private boolean cyclePop = false; // if true, individuals are used as parents in a cyclic sequence - otherwise randomly
private boolean compareToParent = true; // if true, the challenge indy is compared to its parent, otherwise to a random individual
@ -592,7 +586,7 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial
int nextDoomed = getNextDoomed(population, 0);
// required for dynamic problems especially
optimizationProblem.evaluatePopulationStart(population);
((AbstractOptimizationProblem) optimizationProblem).evaluatePopulationStart(population);
/**
* Reevalutation mechanism for dynamically changing problems
@ -643,7 +637,7 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial
}
}
optimizationProblem.evaluatePopulationEnd(population);
((AbstractOptimizationProblem) optimizationProblem).evaluatePopulationEnd(population);
this.population.incrGeneration();
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
}
@ -669,53 +663,6 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial
return -1;
}
/**
* This method allows you to add the LectureGUI as listener to the Optimizer
*
* @param ea
*/
@Override
public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) {
if (this.populationChangedEventListeners == null) {
this.populationChangedEventListeners = new Vector<>();
}
this.populationChangedEventListeners.add(ea);
}
@Override
public boolean removePopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) {
return populationChangedEventListeners != null && populationChangedEventListeners.removeElement(ea);
}
/**
* Something has changed
*
* @param name Event name
*/
protected void firePropertyChangedEvent(String name) {
if (this.populationChangedEventListeners != null) {
for (InterfacePopulationChangedEventListener listener : this.populationChangedEventListeners) {
listener.registerPopulationStateChanged(this, name);
}
}
}
/**
* This method will set the problem that is to be optimized
*
* @param problem
*/
@Override
public void setProblem(InterfaceOptimizationProblem problem) {
this.optimizationProblem = (AbstractOptimizationProblem) problem;
}
@Override
public InterfaceOptimizationProblem getProblem() {
return this.optimizationProblem;
}
/**
* This method will return a string describing all properties of the
* optimizer and the applied methods.
@ -742,22 +689,6 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial
return "Differential Evolution";
}
/**
* Assuming that all optimizers will store their data in a population we will
* allow access to this population to query to current state of the
* optimizer.
*
* @return The population of current solutions to a given problem.
*/
@Override
public Population getPopulation() {
return this.population;
}
@Override
public void setPopulation(Population pop) {
this.population = pop;
}
public String populationTipText() {
return "Edit the properties of the population used.";

View File

@ -19,7 +19,6 @@ import eva2.util.annotation.Description;
public class DynamicParticleSwarmOptimization extends ParticleSwarmOptimization {
private boolean envHasChanged = false;
// private boolean useCurrentFit = true;
/**
* switch for the speed adaptation mechanism
*/

View File

@ -48,7 +48,7 @@ import java.util.Formatter;
* number of peak populations is produced.
* <p/>
* Also, they gave a general rule for setting the niche radius depending on the
* problem domain, however in their experiments, they were able to identify
* optimizationProblem domain, however in their experiments, they were able to identify
* optima which were much closer (i.e., on Ackley's), so it is unclear which
* niche radius was actually used there
* <p/>
@ -89,7 +89,7 @@ import java.util.Formatter;
@Description("A niching ES with dynamic peak identification, after Shir and Bäck: Niching in Evolution Strategies, "
+ "GECCO 2005. Basically, there are several variants of a (mu,lambda)-ES performed "
+ "in parallel, which are reclustered in each iteration based on the dynamic peak set.")
public class EsDpiNiching implements InterfaceOptimizer, Serializable, InterfaceAdditionalPopulationInformer, InterfacePopulationChangedEventListener {
public class EsDpiNiching extends AbstractOptimizer implements Serializable, InterfaceAdditionalPopulationInformer, InterfacePopulationChangedEventListener {
private double nicheRadius = 0.3;
private int expectedPeaks = 5;
@ -104,10 +104,6 @@ public class EsDpiNiching implements InterfaceOptimizer, Serializable, Interface
private transient Population archive = new Population(); // collect deactivated optima
protected ParameterControlManager paramControl = new ParameterControlManager();
private transient EvolutionStrategies[] peakOpts = null;
Population population = new Population();
private InterfaceOptimizationProblem problem;
private transient InterfacePopulationChangedEventListener populationChangedEventListener;
private String identifier = "Niching-ES";
private transient TopoPlot plot = null;
private transient Population randomNewIndies = null;
private int plotInterval = 0;
@ -202,10 +198,9 @@ public class EsDpiNiching implements InterfaceOptimizer, Serializable, Interface
if (o.population != null) {
this.population = (Population) o.population.clone();
}
if (o.problem != null) {
this.problem = (InterfaceOptimizationProblem) o.problem.clone();
if (o.optimizationProblem != null) {
this.optimizationProblem = (InterfaceOptimizationProblem) o.optimizationProblem.clone();
}
this.identifier = o.identifier;
this.plotInterval = o.plotInterval;
}
@ -240,7 +235,7 @@ public class EsDpiNiching implements InterfaceOptimizer, Serializable, Interface
// Trying to come close to the selection scheme of Shir&Bäck'05:
peakOpts[i].setParentSelection(parentSel);
peakOpts[i].setPartnerSelection(new SelectBestSingle(true));
peakOpts[i].setProblem(problem);
peakOpts[i].setProblem(optimizationProblem);
peakOpts[i].initialize();
peakOpts[i].setLambda(lambdaPerPeak); // set lambda after initialization
peakOpts[i].setForceOrigPopSize(false);
@ -293,7 +288,7 @@ public class EsDpiNiching implements InterfaceOptimizer, Serializable, Interface
}
/**
* Calculate the estimated maximal niche radius for a given problem range.
* Calculate the estimated maximal niche radius for a given optimizationProblem range.
* This is an estimate on the q-th part of the volume transfered to the
* radius of a hypersphere, where q is the number of expected peaks.
*
@ -464,7 +459,7 @@ public class EsDpiNiching implements InterfaceOptimizer, Serializable, Interface
population.incrFunctionCallsBy(optimizedSpecies.size());
}
// we may have a problem if, by chance, all species have been deactivated simultaneously AND there are no unclustered !
// we may have a optimizationProblem if, by chance, all species have been deactivated simultaneously AND there are no unclustered !
if (dynamicPopSize() == 0) {
// if this is the case, we just reinit a single in analogy to a missing peak
peakOpts[0].getPopulation().addPopulation(initRandomPeakPop(getMuPerPeak()));
@ -638,7 +633,7 @@ public class EsDpiNiching implements InterfaceOptimizer, Serializable, Interface
/**
* Initialize a new peak population with the given number of indies, which
* are initialized randomly (using the problem instance) and assigned a
* are initialized randomly (using the optimizationProblem instance) and assigned a
* maximally bad fitness.
*
* @param cntPerNewSpecies
@ -646,7 +641,7 @@ public class EsDpiNiching implements InterfaceOptimizer, Serializable, Interface
*/
private Population initRandomPeakPop(int cntPerNewSpecies) {
Population newPop = new Population(cntPerNewSpecies);
problem.initializePopulation(newPop);
optimizationProblem.initializePopulation(newPop);
newPop.putData(EvolutionStrategies.esLambdaParam, getLambdaPerPeak());
newPop.putData(EvolutionStrategies.esMuParam, getMuPerPeak());
newPop.setMaxHistoryLength(haltingWindowLen);
@ -659,23 +654,14 @@ public class EsDpiNiching implements InterfaceOptimizer, Serializable, Interface
private void generateEvalImmigrants(int cnt) {
if (cnt > 0) {
randomNewIndies = new Population(cnt);
problem.initializePopulation(randomNewIndies);
problem.evaluate(randomNewIndies);
optimizationProblem.initializePopulation(randomNewIndies);
optimizationProblem.evaluate(randomNewIndies);
population.incrFunctionCallsBy(cnt);
} else {
randomNewIndies = null;
}
}
/**
* Something has changed
*/
protected void firePropertyChangedEvent(String name) {
if (this.populationChangedEventListener != null) {
this.populationChangedEventListener.registerPopulationStateChanged(this, name);
}
}
private AbstractEAIndividual selectBestFromOtherSpecies(int i, Population[] clusteredSpecies) {
// the index must be >0 and != i:
int rndIndex = RNG.randomInt(clusteredSpecies.length - 2);
@ -702,8 +688,8 @@ public class EsDpiNiching implements InterfaceOptimizer, Serializable, Interface
if (plot == null) {
plot = new TopoPlot("Niching-ES " + npop.getGeneration(), "x", "y");
plot.setParams(50, 50);
if (problem instanceof Interface2DBorderProblem) {
plot.setTopology((Interface2DBorderProblem) problem);
if (optimizationProblem instanceof Interface2DBorderProblem) {
plot.setTopology((Interface2DBorderProblem) optimizationProblem);
}
}
ClusterBasedNichingEA.plotPopConnected(plot, npop);
@ -892,24 +878,7 @@ public class EsDpiNiching implements InterfaceOptimizer, Serializable, Interface
@Override
public String getName() {
return identifier + "_" + getExpectedPeaks() + "_" + getNicheRadius();
}
@Override
public void addPopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) {
populationChangedEventListener = ea;
}
@Override
public boolean removePopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) {
if (ea.equals(populationChangedEventListener)) {
populationChangedEventListener = null;
return true;
} else {
return false;
}
return "Niching-ES_" + getExpectedPeaks() + "_" + getNicheRadius();
}
@Override
@ -925,32 +894,11 @@ public class EsDpiNiching implements InterfaceOptimizer, Serializable, Interface
return new SolutionSet(getPopulation(), peaks);
}
@Override
public void setPopulation(Population pop) {
// this might cause problems if the pop.size() does not fit the EsDpiNiching parameters mu/lamba per peak
this.population = pop;
}
@Override
public Population getPopulation() {
return population;
}
@Override
public InterfaceOptimizationProblem getProblem() {
return problem;
}
@Override
public void setProblem(InterfaceOptimizationProblem prob) {
this.problem = prob;
}
@Override
public String getStringRepresentation() {
StringBuilder sb = new StringBuilder("EsDpiNiching:\n");
sb.append("Optimization Problem: ");
sb.append(this.problem.getStringRepresentationForProblem(this));
sb.append(this.optimizationProblem.getStringRepresentationForProblem(this));
sb.append("\n");
sb.append(this.population.getStringRepresentation());
return sb.toString();
@ -958,11 +906,10 @@ public class EsDpiNiching implements InterfaceOptimizer, Serializable, Interface
@Override
public void initializeByPopulation(Population pop, boolean reset) {
// int pSize = pop.size();
this.population = (Population) pop.clone();
if (reset) {
this.population.init();
this.problem.evaluate(population);
this.optimizationProblem.evaluate(population);
population.incrGeneration();
}
}

View File

@ -1,6 +1,5 @@
package eva2.optimization.strategies;
import eva2.optimization.go.InterfacePopulationChangedEventListener;
import eva2.optimization.individuals.AbstractEAIndividual;
import eva2.optimization.operator.mutation.InterfaceAdaptOperatorGenerational;
import eva2.optimization.operator.selection.InterfaceSelection;
@ -9,13 +8,10 @@ import eva2.optimization.operator.selection.SelectRandom;
import eva2.optimization.population.InterfaceSolutionSet;
import eva2.optimization.population.Population;
import eva2.optimization.population.SolutionSet;
import eva2.problems.B1Problem;
import eva2.problems.InterfaceOptimizationProblem;
import eva2.util.annotation.Description;
import eva2.util.annotation.Parameter;
import java.util.Vector;
/**
* Evolution strategies by Rechenberg and Schwefel, but please remember that
* this only gives the generation strategy and not the coding. But this is the
@ -27,7 +23,7 @@ import java.util.Vector;
* Evolution Strategies.
*/
@Description(value = "This is an Evolution Strategy. Note that the population size depends on mu (number of parents) and lambda (number of offspring)")
public class EvolutionStrategies implements InterfaceOptimizer, java.io.Serializable {
public class EvolutionStrategies extends AbstractOptimizer implements java.io.Serializable {
@Parameter(description = "Mu", name = "mu")
protected int mu = 5;
@ -37,17 +33,12 @@ public class EvolutionStrategies implements InterfaceOptimizer, java.io.Serializ
@Parameter(description = "Determines whether the +-Strategy should be used.", name = "usePlus")
protected boolean usePlusStrategy = false;
protected Population population = new Population();
protected InterfaceOptimizationProblem optimizationProblem = new B1Problem();
private InterfaceSelection parentSelection = new SelectRandom();
private InterfaceSelection partnerSelection = new SelectRandom();
private InterfaceSelection environmentSelection = new SelectBestIndividuals();
private int numberOfPartners = 1;
protected int origPopSize = -1; // especially for CBN
private boolean forceOrigPopSize = true;// especially for CBN
transient private String identifier = "";
transient private Vector<InterfacePopulationChangedEventListener> changeListener;
public static final String esMuParam = "EvolutionStrategyMuParameter";
public static final String esLambdaParam = "EvolutionStrategyLambdaParameter";
@ -243,53 +234,6 @@ public class EvolutionStrategies implements InterfaceOptimizer, java.io.Serializ
return nextGeneration;
}
/**
* This method allows you to add the LectureGUI as listener to the Optimizer
*
* @param ea
*/
@Override
public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) {
if (this.changeListener == null) {
this.changeListener = new Vector<>();
}
this.changeListener.add(ea);
}
@Override
public boolean removePopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) {
return changeListener != null && changeListener.removeElement(ea);
}
/**
* Something has changed
*
* @param name
*/
protected void firePropertyChangedEvent(String name) {
if (this.changeListener != null) {
for (int i = 0; i < this.changeListener.size(); i++) {
this.changeListener.get(i).registerPopulationStateChanged(this, name);
}
}
}
/**
* This method will set the problem that is to be optimized
*
* @param problem
*/
@Override
public void setProblem(InterfaceOptimizationProblem problem) {
this.optimizationProblem = problem;
}
@Override
public InterfaceOptimizationProblem getProblem() {
return this.optimizationProblem;
}
/**
* This method will return a string describing all properties of the
* optimizer and the applied methods.
@ -351,18 +295,6 @@ public class EvolutionStrategies implements InterfaceOptimizer, java.io.Serializ
return "(" + getMu() + (isPlusStrategy() ? "+" : ",") + getLambda() + ")-ES";
}
/**
* Assuming that all optimizer will store their data in a population we will
* allow access to this population to query to current state of the
* optimizer.
*
* @return The population of current solutions to a given problem.
*/
@Override
public Population getPopulation() {
return this.population;
}
// for internal usage
protected void setPop(Population pop) {
this.population = pop;
@ -374,10 +306,6 @@ public class EvolutionStrategies implements InterfaceOptimizer, java.io.Serializ
this.population = pop;
}
public String populationTipText() {
return "Edit the properties of the population used.";
}
@Override
public InterfaceSolutionSet getAllSolutions() {
return new SolutionSet(getPopulation());

View File

@ -21,11 +21,9 @@ import java.util.List;
* David B. Fogel (1992).
*/
@Description("This is a basic Evolutionary Programming scheme.")
public class EvolutionaryProgramming implements InterfaceOptimizer, java.io.Serializable {
public class EvolutionaryProgramming extends AbstractOptimizer implements java.io.Serializable {
private int populationSize = 0;
private Population population = new Population();
private InterfaceOptimizationProblem optimizationProblem = new F1Problem();
private InterfaceSelection environmentSelection = new SelectEPTournaments();
private String identifier = "";
transient private List<InterfacePopulationChangedEventListener> populationChangedEventListeners = new ArrayList<>();
@ -114,46 +112,6 @@ public class EvolutionaryProgramming implements InterfaceOptimizer, java.io.Seri
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
}
/**
* This method allows you to add the LectureGUI as listener to the Optimizer
*
* @param ea
*/
@Override
public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) {
this.populationChangedEventListeners.add(ea);
}
@Override
public boolean removePopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) {
return this.populationChangedEventListeners.remove(ea);
}
/**
* Something has changed
*/
protected void firePropertyChangedEvent(String name) {
for(InterfacePopulationChangedEventListener l : this.populationChangedEventListeners) {
l.registerPopulationStateChanged(this, name);
}
}
/**
* This method will set the problem that is to be optimized
*
* @param problem
*/
@Override
public void setProblem(InterfaceOptimizationProblem problem) {
this.optimizationProblem = problem;
}
@Override
public InterfaceOptimizationProblem getProblem() {
return this.optimizationProblem;
}
/**
* This method will return a string describing all properties of the
* optimizer and the applied methods.
@ -180,22 +138,6 @@ public class EvolutionaryProgramming implements InterfaceOptimizer, java.io.Seri
return "EP";
}
/**
* Assuming that all optimizer will store thier data in a population we will
* allow acess to this population to query to current state of the
* optimizer.
*
* @return The population of current solutions to a given problem.
*/
@Override
public Population getPopulation() {
return this.population;
}
@Override
public void setPopulation(Population pop) {
this.population = pop;
}
public String populationTipText() {
return "Edit the properties of the population used.";

View File

@ -20,20 +20,13 @@ import eva2.util.annotation.Description;
* one-dimensional fitness.
*/
@Description("The flood algorithm uses an declining flood peak to accpect new solutions (*shudder* check inital flood peak and drain very carefully!).")
public class FloodAlgorithm implements InterfaceOptimizer, java.io.Serializable {
// These variables are necessary for the simple testcase
private InterfaceOptimizationProblem optimizationProblem = new B1Problem();
public class FloodAlgorithm extends AbstractOptimizer implements java.io.Serializable {
private int multiRuns = 100;
private int fitnessCalls = 100;
private int fitnessCallsNeeded = 0;
GAIndividualBinaryData bestIndividual, testIndividual;
public double initialFloodPeak = 2000.0, currentFloodPeak;
public double drainRate = 1.0;
// These variables are necessary for the more complex LectureGUI enviroment
transient private String identifier = "";
transient private InterfacePopulationChangedEventListener listener;
private Population population;
public FloodAlgorithm() {
this.population = new Population();
@ -125,21 +118,6 @@ public class FloodAlgorithm implements InterfaceOptimizer, java.io.Serializable
return result;
}
/**
* This method will set the problem that is to be optimized
*
* @param problem
*/
@Override
public void setProblem(InterfaceOptimizationProblem problem) {
this.optimizationProblem = problem;
}
@Override
public InterfaceOptimizationProblem getProblem() {
return this.optimizationProblem;
}
/**
* This method will initialize the HillClimber
*/
@ -185,36 +163,6 @@ public class FloodAlgorithm implements InterfaceOptimizer, java.io.Serializable
System.out.println("(" + program.multiRuns + "/" + program.fitnessCalls + ") Mean Fitness : " + TmpMeanFitness + " Mean Calls needed: " + TmpMeanCalls);
}
/**
* This method allows you to add the LectureGUI as listener to the Optimizer
*
* @param ea
*/
@Override
public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) {
this.listener = ea;
}
@Override
public boolean removePopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) {
if (listener == ea) {
listener = null;
return true;
} else {
return false;
}
}
/**
* Something has changed
*/
protected void firePropertyChangedEvent(String name) {
if (this.listener != null) {
this.listener.registerPopulationStateChanged(this, name);
}
}
/**
* This method will return a string describing all properties of the
* optimizer and the applied methods.
@ -245,23 +193,6 @@ public class FloodAlgorithm implements InterfaceOptimizer, java.io.Serializable
return "MS-FA";
}
/**
* Assuming that all optimizer will store thier data in a population we will
* allow acess to this population to query to current state of the
* optimizer.
*
* @return The population of current solutions to a given problem.
*/
@Override
public Population getPopulation() {
return this.population;
}
@Override
public void setPopulation(Population pop) {
this.population = pop;
}
public String populationTipText() {
return "Change the number of best individuals stored (MS-FA).";
}

View File

@ -22,16 +22,13 @@ import java.util.Vector;
* GA might not converge. This is a implementation of Genetic Algorithms.
*/
@Description(value = "This is a basic generational Genetic Algorithm.")
public class GeneticAlgorithm implements InterfaceOptimizer, java.io.Serializable {
public class GeneticAlgorithm extends AbstractOptimizer implements java.io.Serializable {
private Population population = new Population();
private InterfaceOptimizationProblem optimizationProblem = new F1Problem();
private InterfaceSelection parentSelection = new SelectXProbRouletteWheel();
private InterfaceSelection partnerSelection = new SelectRandom();
private boolean useElitism = true;
private int plague = 0;
private int numberOfPartners = 1;
private String identifier = "";
transient private Vector<InterfacePopulationChangedEventListener> changeListener;
public GeneticAlgorithm() {
@ -40,7 +37,6 @@ public class GeneticAlgorithm implements InterfaceOptimizer, java.io.Serializabl
public GeneticAlgorithm(GeneticAlgorithm ga) {
this.population = (Population) ga.population.clone();
this.optimizationProblem = (InterfaceOptimizationProblem) ga.optimizationProblem.clone();
this.identifier = ga.identifier;
this.plague = ga.plague;
this.numberOfPartners = ga.numberOfPartners;
this.useElitism = ga.useElitism;
@ -236,27 +232,6 @@ public class GeneticAlgorithm implements InterfaceOptimizer, java.io.Serializabl
return "Genetic Algorithm";
}
/**
* Assuming that all optimizer will store thier data in a population we will
* allow acess to this population to query to current state of the
* optimizer.
*
* @return The population of current solutions to a given problem.
*/
@Override
public Population getPopulation() {
return this.population;
}
@Override
public void setPopulation(Population pop) {
this.population = pop;
}
public String populationTipText() {
return "Edit the properties of the population used.";
}
@Override
public InterfaceSolutionSet getAllSolutions() {
return new SolutionSet(getPopulation());

View File

@ -1,6 +1,5 @@
package eva2.optimization.strategies;
import eva2.optimization.go.InterfacePopulationChangedEventListener;
import eva2.optimization.individuals.AbstractEAIndividual;
import eva2.optimization.individuals.InterfaceDataTypeDouble;
import eva2.optimization.population.InterfaceSolutionSet;
@ -21,9 +20,8 @@ import eva2.util.annotation.Description;
*
*/
@Description("Gradient Descent can be applied to derivable functions (InterfaceFirstOrderDerivableProblem).")
public class GradientDescentAlgorithm implements InterfaceOptimizer, java.io.Serializable {
public class GradientDescentAlgorithm extends AbstractOptimizer implements java.io.Serializable {
private InterfaceOptimizationProblem optimizationProblem;
InterfaceDataTypeDouble bestDataTypeDouble, testDataTypeDouble;
private int iterations = 1;
private double wDecreaseStepSize = 0.5;
@ -40,12 +38,8 @@ public class GradientDescentAlgorithm implements InterfaceOptimizer, java.io.Ser
double localmaxstepsize = 10;
double localminstepsize = 1e-10;
private boolean momentumterm = false;
transient private InterfacePopulationChangedEventListener populationChangedEventListener;
public double maximumabsolutechange = 0.2;
// Hashtable indyhash;
// These variables are necessary for the more complex LectureGUI enviroment
transient private String identifier = "";
private Population population;
private static final String lockKey = "gdaLockDataKey";
private static final String lastFitnessKey = "gdaLastFitDataKey";
private static final String stepSizeKey = "gdaStepSizeDataKey";
@ -62,12 +56,9 @@ public class GradientDescentAlgorithm implements InterfaceOptimizer, java.io.Ser
this.optimizationProblem.evaluate(this.getPopulation());
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
}
//System.out.println("initializeByPopulation() called");
// indyhash = new Hashtable();
}
public GradientDescentAlgorithm() {
// indyhash = new Hashtable();
this.population = new Population();
this.population.setTargetSize(1);
}
@ -281,14 +272,12 @@ public class GradientDescentAlgorithm implements InterfaceOptimizer, java.io.Ser
} else {
indystepsize *= wIncreaseStepSize;
}
//System.out.println("newstepsize" + indystepsize);
indystepsize = (indystepsize > globalmaxstepsize) ? globalmaxstepsize : indystepsize;
indystepsize = (indystepsize < globalminstepsize) ? globalminstepsize : indystepsize;
indy.putData(stepSizeKey, indystepsize);
}
//System.out.println("newstepsize in bounds" + indystepsize);
indy.putData(lastFitnessKey, new Double(indy.getFitness()[0]));
indy.putData(lastFitnessKey, indy.getFitness()[0]);
}
}
@ -299,59 +288,16 @@ public class GradientDescentAlgorithm implements InterfaceOptimizer, java.io.Ser
private double momentumweigth = 0.1;
protected void firePropertyChangedEvent(String name) {
if (this.populationChangedEventListener != null) {
this.populationChangedEventListener.registerPopulationStateChanged(this, name);
}
}
@Override
public Population getPopulation() {
return this.population;
}
@Override
public InterfaceSolutionSet getAllSolutions() {
return new SolutionSet(getPopulation());
}
@Override
public void setPopulation(Population pop) {
this.population = pop;
}
@Override
public void setProblem(InterfaceOptimizationProblem problem) {
optimizationProblem = problem;
}
@Override
public InterfaceOptimizationProblem getProblem() {
return optimizationProblem;
}
@Override
public String getStringRepresentation() {
return "GradientDescentAlgorithm";
}
@Override
public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) {
this.populationChangedEventListener = ea;
}
@Override
public boolean removePopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) {
if (populationChangedEventListener == ea) {
populationChangedEventListener = null;
return true;
} else {
return false;
}
}
public static void main(String[] args) {
GradientDescentAlgorithm program = new GradientDescentAlgorithm();
InterfaceOptimizationProblem problem = new F1Problem();

View File

@ -1,6 +1,5 @@
package eva2.optimization.strategies;
import eva2.optimization.go.InterfacePopulationChangedEventListener;
import eva2.optimization.individuals.AbstractEAIndividual;
import eva2.optimization.operator.mutation.InterfaceMutation;
import eva2.optimization.population.InterfaceSolutionSet;
@ -16,15 +15,11 @@ import eva2.util.annotation.Description;
* strategy sets the mutation rate temporarily to 1.0.
*/
@Description("The Hill Climber uses the default EA mutation and initializing operators. If the population size is bigger than one a multi-start Hill Climber is performed.")
public class HillClimbing implements InterfaceOptimizer, java.io.Serializable {
public class HillClimbing extends AbstractOptimizer implements java.io.Serializable {
// These variables are necessary for the simple testcase
private InterfaceOptimizationProblem optimizationProblem = new B1Problem();
private InterfaceMutation mutator = null;
// These variables are necessary for the more complex LectureGUI enviroment
transient private String identifier = "";
transient private InterfacePopulationChangedEventListener populationChangedEventListener;
private Population population;
public HillClimbing() {
this.population = new Population();
@ -85,7 +80,6 @@ public class HillClimbing implements InterfaceOptimizer, java.io.Serializable {
this.optimizationProblem.evaluate(this.population);
for (int i = 0; i < this.population.size(); i++) {
if (((AbstractEAIndividual) original.get(i)).isDominatingDebConstraints(((AbstractEAIndividual) this.population.get(i)))) {
// this.population.remove(i);
// throw away mutated one and replace by old one
this.population.set(i, original.get(i));
} else {
@ -93,20 +87,6 @@ public class HillClimbing implements InterfaceOptimizer, java.io.Serializable {
}
}
this.population.incrGeneration();
// for (int i = 0; i < this.population.size(); i++) {
// indy1 = (AbstractEAIndividual) this.population.get(i);
// indy2 = (AbstractEAIndividual)(indy1).clone();
// indy2.mutate();
// this.problem.evaluate((AbstractEAIndividual) indy2);
// //indy2.SetFitness(0, indy2.evaulateAsMiniBits());
// this.population.incrFunctionCalls();
// //if (indy2.getFitness(0) < indy1.getFitness(0)) {
// if (indy2.isDominating(indy1)) {
// this.population.remove(i);
// this.population.add(i, indy2);
// }
// }
// this.population.incrGeneration();
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
}
@ -121,55 +101,10 @@ public class HillClimbing implements InterfaceOptimizer, java.io.Serializable {
*
* @param mute
*/
public void SetMutationOperator(InterfaceMutation mute) {
public void setMutationOperator(InterfaceMutation mute) {
mutator = mute;
}
/**
* This method will set the problem that is to be optimized
*
* @param problem
*/
@Override
public void setProblem(InterfaceOptimizationProblem problem) {
this.optimizationProblem = problem;
}
@Override
public InterfaceOptimizationProblem getProblem() {
return this.optimizationProblem;
}
/**
* This method allows you to add the LectureGUI as listener to the Optimizer
*
* @param ea
*/
@Override
public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) {
this.populationChangedEventListener = ea;
}
@Override
public boolean removePopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) {
if (populationChangedEventListener == ea) {
populationChangedEventListener = null;
return true;
} else {
return false;
}
}
/**
* Something has changed
*/
protected void firePropertyChangedEvent(String name) {
if (this.populationChangedEventListener != null) {
this.populationChangedEventListener.registerPopulationStateChanged(this, name);
}
}
/**
* This method will return a string describing all properties of the
* optimizer and the applied methods.
@ -200,16 +135,6 @@ public class HillClimbing implements InterfaceOptimizer, java.io.Serializable {
return "MS-HC";
}
@Override
public Population getPopulation() {
return this.population;
}
@Override
public void setPopulation(Population pop) {
this.population = pop;
}
@Override
public InterfaceSolutionSet getAllSolutions() {
return new SolutionSet(getPopulation());

View File

@ -23,30 +23,25 @@ import java.util.logging.Level;
import java.util.logging.Logger;
@Description("Basic implementation of the Linkage Tree Genetic Algorithm based on the works by Dirk Thierens.")
public class LTGA implements InterfaceOptimizer, java.io.Serializable, InterfacePopulationChangedEventListener {
public class LTGA extends AbstractOptimizer implements java.io.Serializable, InterfacePopulationChangedEventListener {
private static final Logger LOGGER = Logger.getLogger(LTGA.class.getName());
transient private InterfacePopulationChangedEventListener populationChangedEventListener = null;
private String identifier = "LTGA";
private int probDim = 8;
private int fitCrit = -1;
private int popSize = 50;
private Population population = new Population();
private AbstractOptimizationProblem problem = new BKnapsackProblem();
private AbstractOptimizationProblem optimizationProblem = new BKnapsackProblem();
private AbstractEAIndividual template = null;
private int generationCycle = 500;
private boolean elitism = true;
public LTGA() {
}
public LTGA(LTGA l) {
this.populationChangedEventListener = l.populationChangedEventListener;
this.identifier = l.identifier;
this.probDim = l.probDim;
this.popSize = l.popSize;
this.population = (Population) l.population.clone();
this.problem = (AbstractOptimizationProblem) l.problem.clone();
this.template = (AbstractEAIndividual) template.clone();
}
@ -60,35 +55,17 @@ public class LTGA implements InterfaceOptimizer, java.io.Serializable, Interface
return "Linkage Tree Genetic Algorithm";
}
@Override
public void addPopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) {
this.populationChangedEventListener = ea;
}
@Override
public boolean removePopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) {
if (populationChangedEventListener == ea) {
populationChangedEventListener = null;
return true;
} else {
return false;
}
}
private void defaultInit() {
if (population == null) {
this.population = new Population(this.popSize);
} else {
this.population.setTargetPopSize(this.popSize);
}
this.template = this.problem.getIndividualTemplate();
this.template = this.optimizationProblem.getIndividualTemplate();
if (!(template instanceof InterfaceDataTypeBinary)) {
LOGGER.log(Level.WARNING, "Requiring binary data!");
} else {
Object dim = BeanInspector.callIfAvailable(problem,
Object dim = BeanInspector.callIfAvailable(optimizationProblem,
"getProblemDimension", null);
if (dim == null) {
LOGGER.log(Level.WARNING, "Couldn't get problem dimension!");
@ -115,7 +92,7 @@ public class LTGA implements InterfaceOptimizer, java.io.Serializable, Interface
@Override
public void initialize() {
this.defaultInit();
this.problem.initializePopulation(this.population);
this.optimizationProblem.initializePopulation(this.population);
this.evaluatePopulation(this.population);
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
}
@ -138,7 +115,7 @@ public class LTGA implements InterfaceOptimizer, java.io.Serializable, Interface
LOGGER.log(Level.WARNING, "tried to evaluate null");
return;
}
this.problem.evaluate(indy);
this.optimizationProblem.evaluate(indy);
// increment the number of evaluations
this.population.incrFunctionCalls();
}
@ -242,7 +219,7 @@ public class LTGA implements InterfaceOptimizer, java.io.Serializable, Interface
@Override
public void optimize() {
this.problem.evaluatePopulationStart(this.population);
this.optimizationProblem.evaluatePopulationStart(this.population);
Stack<Set<Integer>> linkageTree = this.buildLinkageTree();
Population newPop = new Population(this.popSize);
if (elitism) {
@ -260,7 +237,7 @@ public class LTGA implements InterfaceOptimizer, java.io.Serializable, Interface
}
this.population.clear();
this.population.addAll(newPop);
this.problem.evaluatePopulationEnd(this.population);
this.optimizationProblem.evaluatePopulationEnd(this.population);
}
private Population buildNewIndies(Population indies,
@ -302,35 +279,11 @@ public class LTGA implements InterfaceOptimizer, java.io.Serializable, Interface
return result;
}
/**
* Something has changed
*/
protected void firePropertyChangedEvent(String name) {
if (this.populationChangedEventListener != null) {
this.populationChangedEventListener.registerPopulationStateChanged(this, name);
}
}
@Override
public Population getPopulation() {
return this.population;
}
@Override
public void setPopulation(Population pop) {
this.population = pop;
}
@Override
public InterfaceSolutionSet getAllSolutions() {
return new SolutionSet(this.population);
}
@Override
public void setProblem(InterfaceOptimizationProblem problem) {
this.problem = (AbstractOptimizationProblem) problem;
}
public boolean getElitism() {
return this.elitism;
}
@ -343,11 +296,6 @@ public class LTGA implements InterfaceOptimizer, java.io.Serializable, Interface
return "use elitism?";
}
@Override
public InterfaceOptimizationProblem getProblem() {
return this.problem;
}
@Override
public String getStringRepresentation() {
return "Linkage Tree GA";

View File

@ -9,10 +9,9 @@ import eva2.optimization.population.InterfaceSolutionSet;
import eva2.optimization.population.Population;
import eva2.optimization.population.SolutionSet;
import eva2.problems.AbstractOptimizationProblem;
import eva2.problems.BKnapsackProblem;
import eva2.problems.InterfaceOptimizationProblem;
import eva2.tools.Pair;
import eva2.tools.math.SpecialFunction;
import eva2.util.annotation.Description;
import java.util.BitSet;
import java.util.HashSet;
@ -21,16 +20,13 @@ import java.util.Stack;
import java.util.logging.Level;
import java.util.logging.Logger;
public class MLTGA implements InterfaceOptimizer, java.io.Serializable, InterfacePopulationChangedEventListener {
@Description("Modified implementation of the Linkage Tree Genetic Algorithm.")
public class MLTGA extends AbstractOptimizer implements java.io.Serializable, InterfacePopulationChangedEventListener {
private static final Logger LOGGER = Logger.getLogger(MLTGA.class.getName());
transient private InterfacePopulationChangedEventListener populationChangedEventListener = null;
private String identifier = "MLTGA";
private int probDim = 8;
private int fitCrit = -1;
private int popSize = 50;
private Population population = new Population();
private AbstractOptimizationProblem problem = new BKnapsackProblem();
private AbstractEAIndividual template = null;
private int generationCycle = 500;
private boolean elitism = true;
@ -39,12 +35,10 @@ public class MLTGA implements InterfaceOptimizer, java.io.Serializable, Interfac
}
public MLTGA(MLTGA l) {
this.populationChangedEventListener = l.populationChangedEventListener;
this.identifier = l.identifier;
this.probDim = l.probDim;
this.popSize = l.popSize;
this.population = (Population) l.population.clone();
this.problem = (AbstractOptimizationProblem) l.problem.clone();
this.optimizationProblem = (AbstractOptimizationProblem) l.optimizationProblem.clone();
this.template = (AbstractEAIndividual) template.clone();
}
@ -58,39 +52,17 @@ public class MLTGA implements InterfaceOptimizer, java.io.Serializable, Interfac
return "Mutating Linkage Tree Genetic Algorithm";
}
public static String globalInfo() {
return "Modified implementation of the Linkage Tree Genetic Algorithm.";
}
@Override
public void addPopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) {
this.populationChangedEventListener = ea;
}
@Override
public boolean removePopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) {
if (populationChangedEventListener == ea) {
populationChangedEventListener = null;
return true;
} else {
return false;
}
}
private void defaultInit() {
if (population == null) {
this.population = new Population(this.popSize);
} else {
this.population.setTargetPopSize(this.popSize);
}
this.template = this.problem.getIndividualTemplate();
this.template = ((AbstractOptimizationProblem) this.optimizationProblem).getIndividualTemplate();
if (!(template instanceof InterfaceDataTypeBinary)) {
LOGGER.log(Level.WARNING, "Requiring binary data!");
} else {
Object dim = BeanInspector.callIfAvailable(problem,
Object dim = BeanInspector.callIfAvailable(optimizationProblem,
"getProblemDimension", null);
if (dim == null) {
LOGGER.log(Level.WARNING, "Couldn't get problem dimension!");
@ -117,7 +89,7 @@ public class MLTGA implements InterfaceOptimizer, java.io.Serializable, Interfac
@Override
public void initialize() {
defaultInit();
this.problem.initializePopulation(this.population);
this.optimizationProblem.initializePopulation(this.population);
this.evaluatePopulation(this.population);
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
}
@ -140,7 +112,7 @@ public class MLTGA implements InterfaceOptimizer, java.io.Serializable, Interfac
LOGGER.log(Level.WARNING, "tried to evaluate null");
return;
}
this.problem.evaluate(indy);
this.optimizationProblem.evaluate(indy);
// increment the number of evaluations
this.population.incrFunctionCalls();
}
@ -160,7 +132,7 @@ public class MLTGA implements InterfaceOptimizer, java.io.Serializable, Interfac
Stack<Set<Integer>> linkageTree = new Stack<>();
// the stack to cluster here clusters can be removed
Stack<Set<Integer>> workingTree = new Stack<>();
// add the problem variables to the stacks
// add the optimizationProblem variables to the stacks
for (int i = 0; i < this.probDim; i++) {
Set<Integer> s1 = new HashSet<>();
Set<Integer> s2 = new HashSet<>();
@ -169,7 +141,6 @@ public class MLTGA implements InterfaceOptimizer, java.io.Serializable, Interfac
linkageTree.add(s1);
workingTree.add(s2);
}
// double[] probMass = calculateProbabilityMassFunction();
// until there is only one cluster left
while (workingTree.size() > 1) {
Pair<Set<Integer>, Set<Integer>> toCluster = findNearestClusters(workingTree);
@ -244,7 +215,7 @@ public class MLTGA implements InterfaceOptimizer, java.io.Serializable, Interfac
@Override
public void optimize() {
this.problem.evaluatePopulationStart(this.population);
((AbstractOptimizationProblem) this.optimizationProblem).evaluatePopulationStart(this.population);
Stack<Set<Integer>> linkageTree = buildLinkageTree();
Population newPop = new Population(this.popSize);
if (elitism) {
@ -262,7 +233,7 @@ public class MLTGA implements InterfaceOptimizer, java.io.Serializable, Interfac
}
this.population.clear();
this.population.addAll(newPop);
this.problem.evaluatePopulationEnd(this.population);
((AbstractOptimizationProblem) this.optimizationProblem).evaluatePopulationEnd(this.population);
}
private AbstractEAIndividual buildNewIndy(AbstractEAIndividual indy,
@ -283,35 +254,11 @@ public class MLTGA implements InterfaceOptimizer, java.io.Serializable, Interfac
return indy;
}
/**
* Something has changed
*/
protected void firePropertyChangedEvent(String name) {
if (this.populationChangedEventListener != null) {
this.populationChangedEventListener.registerPopulationStateChanged(this, name);
}
}
@Override
public Population getPopulation() {
return this.population;
}
@Override
public void setPopulation(Population pop) {
this.population = pop;
}
@Override
public InterfaceSolutionSet getAllSolutions() {
return new SolutionSet(this.population);
}
@Override
public void setProblem(InterfaceOptimizationProblem problem) {
this.problem = (AbstractOptimizationProblem) problem;
}
public boolean getElitism() {
return this.elitism;
}
@ -324,11 +271,6 @@ public class MLTGA implements InterfaceOptimizer, java.io.Serializable, Interfac
return "use elitism?";
}
@Override
public InterfaceOptimizationProblem getProblem() {
return this.problem;
}
@Override
public String getStringRepresentation() {
return "Linkage Tree GA";

View File

@ -23,8 +23,7 @@ import java.util.Hashtable;
@Description("This is a basic generational Memetic Algorithm. Local search steps are performed on a selected subset "
+ "of individuals after certain numbers of global search iterations. Note "
+ "that the problem class must implement InterfaceLocalSearchable.")
public class MemeticAlgorithm implements InterfaceOptimizer,
java.io.Serializable {
public class MemeticAlgorithm implements InterfaceOptimizer, java.io.Serializable {
/**
* serial version uid.

View File

@ -17,22 +17,12 @@ import eva2.util.annotation.Description;
* characteristics may be problem dependent.
*/
@Description("The Monte Carlo Search repeatively creates random individuals and stores the best individuals found.")
public class MonteCarloSearch implements InterfaceOptimizer, java.io.Serializable {
public class MonteCarloSearch extends AbstractOptimizer implements java.io.Serializable {
/**
* Generated serial version id.
*/
private static final long serialVersionUID = -751760624411490405L;
// These variables are necessary for the simple testcase
private InterfaceOptimizationProblem optimizationProblem = new B1Problem();
private int multiRuns = 100;
private int fitnessCalls = 100;
private int fitnessCallsNeeded = 0;
private Population population;
private GAIndividualBinaryData bestIndividual;
// These variables are necessary for the more complex LectureGUI enviroment
transient private String identifier = "";
transient private InterfacePopulationChangedEventListener populationChangedEventListener;
public MonteCarloSearch() {
this.population = new Population();
@ -100,21 +90,6 @@ public class MonteCarloSearch implements InterfaceOptimizer, java.io.Serializabl
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
}
/**
* This method will set the problem that is to be optimized
*
* @param problem
*/
@Override
public void setProblem(InterfaceOptimizationProblem problem) {
this.optimizationProblem = problem;
}
@Override
public InterfaceOptimizationProblem getProblem() {
return this.optimizationProblem;
}
/**
* This method will initialize the HillClimber
*/
@ -161,36 +136,6 @@ public class MonteCarloSearch implements InterfaceOptimizer, java.io.Serializabl
System.out.println("(" + program.multiRuns + "/" + program.fitnessCalls + ") Mean Fitness : " + TmpMeanFitness + " Mean Calls needed: " + TmpMeanCalls);
}
/**
* This method allows you to add the LectureGUI as listener to the Optimizer
*
* @param ea
*/
@Override
public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) {
this.populationChangedEventListener = ea;
}
@Override
public boolean removePopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) {
if (populationChangedEventListener == ea) {
populationChangedEventListener = null;
return true;
} else {
return false;
}
}
/**
* Something has changed
*/
protected void firePropertyChangedEvent(String name) {
if (this.populationChangedEventListener != null) {
this.populationChangedEventListener.registerPopulationStateChanged(this, name);
}
}
/**
* This method will return a string describing all properties of the
* optimizer and the applied methods.
@ -218,27 +163,6 @@ public class MonteCarloSearch implements InterfaceOptimizer, java.io.Serializabl
return "MCS";
}
/**
* Assuming that all optimizer will store thier data in a population we will
* allow acess to this population to query to current state of the
* optimizer.
*
* @return The population of current solutions to a given problem.
*/
@Override
public Population getPopulation() {
return this.population;
}
@Override
public void setPopulation(Population pop) {
this.population = pop;
}
public String populationTipText() {
return "Change the number of best individuals stored.";
}
@Override
public InterfaceSolutionSet getAllSolutions() {
return new SolutionSet(getPopulation());

View File

@ -20,7 +20,7 @@ import java.util.HashMap;
* ToDo: Document
*/
@Description("A multi-objective CMA-ES variant after Igel, Hansen and Roth 2007 (EC 15(1),1-28).")
public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable {
public class MultiObjectiveCMAES extends AbstractOptimizer implements Serializable {
/**
* Generated serial version identifier
@ -40,10 +40,6 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable {
public boolean seen = false;
}
private String identifier = "MOCMAES";
private Population population;
private AbstractOptimizationProblem optimizationProblem;
transient private InterfacePopulationChangedEventListener populationChangedEventListener;
private int lambda = 1;
private int lambdaMO = 1;
@ -66,30 +62,6 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable {
GenericObjectEditor
.setHideProperty(this.getClass(), "population", true);
}
/*
* (non-Javadoc)
*
* @see
* eva2.optimization.strategies.InterfaceOptimizer#SetProblem(eva2.optimization
* .problems.InterfaceOptimizationProblem)
*/
@Override
public void setProblem(InterfaceOptimizationProblem problem) {
optimizationProblem = (AbstractOptimizationProblem) problem;
}
/**
* This method allows you to add the LectureGUI as listener to the Optimizer
*
* @param ea
*/
@Override
public void addPopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) {
this.populationChangedEventListener = ea;
}
/*
* (non-Javadoc)
*
@ -111,26 +83,6 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable {
return "(1+" + lambda + ") MO-CMA-ES";
}
/*
* (non-Javadoc)
*
* @see eva2.optimization.strategies.InterfaceOptimizer#getPopulation()
*/
@Override
public Population getPopulation() {
return population;
}
/*
* (non-Javadoc)
*
* @see eva2.optimization.strategies.InterfaceOptimizer#getProblem()
*/
@Override
public InterfaceOptimizationProblem getProblem() {
return optimizationProblem;
}
/*
* (non-Javadoc)
*
@ -326,19 +278,6 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable {
}
/*
* (non-Javadoc)
*
* @seeeva2.optimization.strategies.InterfaceOptimizer#
* removePopulationChangedEventListener
* (eva2.optimization.InterfacePopulationChangedEventListener)
*/
@Override
public boolean removePopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) {
return false;
}
/*
* (non-Javadoc)
*
@ -354,17 +293,6 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable {
}
/**
* Something has changed
*
* @param name
*/
protected void firePropertyChangedEvent(String name) {
if (this.populationChangedEventListener != null) {
this.populationChangedEventListener.registerPopulationStateChanged(this, name);
}
}
public int getLambda() {
return lambda;
}

View File

@ -22,16 +22,13 @@ import java.util.Vector;
* available by projection at the bounds.
*/
@Description("The Nelder-Mead simplex search algorithm for local search. Reflection on bounds may be used for constraint handling.")
public class NelderMeadSimplex implements InterfaceOptimizer, Serializable, InterfacePopulationChangedEventListener {
public class NelderMeadSimplex extends AbstractOptimizer implements Serializable, InterfacePopulationChangedEventListener {
private int populationSize = 100;
// simulating the generational cycle. Set rather small (eg 5) for use as local search, higher for global search (eg 50)
private int generationCycle = 50;
private int fitIndex = 0; // choose criterion for multi objective functions
private Population population;
private AbstractOptimizationProblem optimizationProblem;
private transient Vector<InterfacePopulationChangedEventListener> populationChangedEventListeners;
private String identifier = "NelderMeadSimplex";
private boolean checkConstraints = true;
public NelderMeadSimplex() {
@ -48,7 +45,6 @@ public class NelderMeadSimplex implements InterfaceOptimizer, Serializable, Inte
setPopulation((Population) a.population.clone());
populationSize = a.populationSize;
generationCycle = a.generationCycle;
identifier = a.identifier;
}
@Override
@ -76,29 +72,6 @@ public class NelderMeadSimplex implements InterfaceOptimizer, Serializable, Inte
return false;
}
@Override
public void addPopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) {
if (ea != null) {
if (populationChangedEventListeners == null) {
populationChangedEventListeners = new Vector<>();
}
if (!populationChangedEventListeners.contains(ea)) {
populationChangedEventListeners.add(ea);
}
}
}
@Override
public boolean removePopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) {
if (populationChangedEventListeners == null) {
return false;
} else {
return populationChangedEventListeners.remove(ea);
}
}
protected double[] calcChallengeVect(double[] centroid, double[] refX) {
double[] r = new double[centroid.length];
for (int i = 0; i < r.length; i++) {
@ -218,17 +191,7 @@ public class NelderMeadSimplex implements InterfaceOptimizer, Serializable, Inte
@Override
public String getName() {
return identifier;
}
@Override
public Population getPopulation() {
return population;
}
@Override
public InterfaceOptimizationProblem getProblem() {
return optimizationProblem;
return "NelderMeadSimplex";
}
@Override
@ -257,14 +220,6 @@ public class NelderMeadSimplex implements InterfaceOptimizer, Serializable, Inte
// fireNextGenerationPerformed();
}
private void fireNextGenerationPerformed() {
if (populationChangedEventListeners != null) {
for (int i = 0; i < populationChangedEventListeners.size(); i++) {
populationChangedEventListeners.elementAt(i).registerPopulationStateChanged(this, Population.NEXT_GENERATION_PERFORMED);
}
}
}
@Override
public void optimize() {
// make at least as many calls as there are individuals within the population.
@ -279,10 +234,6 @@ public class NelderMeadSimplex implements InterfaceOptimizer, Serializable, Inte
double[][] range = ((InterfaceDataTypeDouble) ind).getDoubleRange();
if (!Mathematics.isInRange(x, range)) {
System.err.println("WARNING: nelder mead step produced indy out of range!");
// Mathematics.projectToRange(x, range);
// ((InterfaceDataTypeDouble)ind).setDoubleGenotype(x);
// problem.evaluate(ind);
// this.population.incrFunctionCalls();
}
population.set(population.getIndexOfWorstIndividualNoConstr(fitIndex), ind, fitIndex);
} else {//keine Verbesserung gefunden shrink!!
@ -343,8 +294,8 @@ public class NelderMeadSimplex implements InterfaceOptimizer, Serializable, Inte
@Override
public void registerPopulationStateChanged(Object source, String name) {
if (name.compareTo(Population.FUN_CALL_INTERVAL_REACHED) == 0) {
fireNextGenerationPerformed();
}// else System.err.println("unknown event!");
firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
}
}
/**

View File

@ -75,8 +75,8 @@ import java.util.Vector;
* Yilmaz. Particle Swarms for Multimodal Optimization. In: ICANNGA (1), Seiten
* 366<EFBFBD>375, 2007
*/
@Description(value = "A Niching Particle Swarm Optimizer")
public class NichePSO implements InterfaceAdditionalPopulationInformer, InterfaceOptimizer, java.io.Serializable {
@Description("A Niching Particle Swarm Optimizer")
public class NichePSO extends AbstractOptimizer implements InterfaceAdditionalPopulationInformer, java.io.Serializable {
/**
*
@ -120,10 +120,6 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
protected InterfaceSubswarmCreationStrategy subswarmCreationStrategy = new StandardSubswarmCreationStrategy();
// the problem
protected InterfaceOptimizationProblem optimizationProblem = new FM0Problem();
// only used by island model ?
protected String identifier = "";
// eventListener
transient protected InterfacePopulationChangedEventListener populationChangedEventListener;
// for debugging: file containing the output
transient protected BufferedWriter outputFile = null;
// for debugging and plotting -----------------------------------------------
@ -203,10 +199,10 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
this.useSinglePlotWindow = a.useSinglePlotWindow;
this.savePlots = a.savePlots;
this.showCycle = a.showCycle;
this.SetDirForCurrentExperiment(a.getDirForCurrentExperiment());
this.setDirForCurrentExperiment(a.getDirForCurrentExperiment());
this.setMainSwarm((ParticleSubSwarmOptimization) a.getMainSwarm().clone());
this.SetSubSwarms((Vector<ParticleSubSwarmOptimization>) a.getSubSwarms().clone());
this.setSubSwarms((Vector<ParticleSubSwarmOptimization>) a.getSubSwarms().clone());
this.setSubswarmOptimizerTemplate((ParticleSubSwarmOptimization) a.getSubswarmOptimizerTemplate().clone());
this.deactivationStrategy = (InterfaceDeactivationStrategy) a.deactivationStrategy.clone();
@ -215,8 +211,6 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
this.subswarmCreationStrategy = (InterfaceSubswarmCreationStrategy) a.subswarmCreationStrategy.clone();
this.optimizationProblem = (InterfaceOptimizationProblem) a.optimizationProblem.clone();
this.identifier = a.identifier;
}
/**
@ -228,10 +222,6 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
return new NichePSO(this);
}
/**
* ********************************************************************************************************************
* inits
*/
/**
* @tested ps sets the mainswarm according to the NichePSO Parameters,
* called via initialize()
@ -318,7 +308,7 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
// initialize subswarms
//initSubswarmOptimizerTemplate(); //only in ctor, would change parameters for the next multirun
//subwarmOptimizerTemplate.initialize(); // dont initialize and evaluate individuals !
SetSubSwarms(new Vector<ParticleSubSwarmOptimization>()); // dont want to use subswarms from old optimization run (especially not in multiruns)...
setSubSwarms(new Vector<ParticleSubSwarmOptimization>()); // dont want to use subswarms from old optimization run (especially not in multiruns)...
indicesToReinit = null;
// show in plot
//MainSwarm.setShow(true);
@ -694,52 +684,12 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
}
}
/**
* ********************************************************************************************************************
* event listening
*/
/**
* @tested Something has changed
*/
protected void firePropertyChangedEvent(String name) {
if (this.populationChangedEventListener != null) {
this.populationChangedEventListener.registerPopulationStateChanged(this, name);
}
}
/**
* @param ea
* @tested This method allows you to add the LectureGUI as listener to the
* Optimizer
*/
@Override
public void addPopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) {
this.populationChangedEventListener = ea;
}
@Override
public boolean removePopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) {
if (populationChangedEventListener == ea) {
populationChangedEventListener = null;
return true;
} else {
return false;
}
}
/**
* @tested nn This method is required to free the memory on a RMIServer, but
* there is nothing to implement.
*/
/**
* ********************************************************************************************************************
* setter, getter: population and solutions
*/
/**
* @tested nn (non-Javadoc)
* @see eva2.optimization.strategies.InterfaceOptimizer#setPopulation(javaeva.server.oa.go.Populations.Population)
*/
@Override
public void setPopulation(Population pop) {
@ -996,23 +946,7 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
return "weights the cognitive component for the PSO used to train the main swarm";
}
// public void setMainSwarmPhi2(double p2) {
// this.SetMainSwarmPhi2(p2);
// }
//
// public void setMainSwarmPhi2(double mainSwarmPhi2) {
// this.mainSwarmPhi2 = mainSwarmPhi2;
// double inertChi = getMainSwarm().getInertnessOrChi();
// getMainSwarm().setPhi2(mainSwarmPhi2);
//// mainSwarmParamAging.setStartValue(getMainSwarm().getInertnessOrChi());
// // if constriction calc. changed the inertness, update it here, else dont.
//// if (getMainSwarm().getInertnessOrChi() != inertChi) mainSwarmParamAging.setStartValue(getMainSwarm().getInertnessOrChi());
// if (getMainSwarm().getInertnessOrChi() != inertChi) getMainSwarm().setInertnessOrChi(mainSwarmPhi2);
// }
// public int getMainSwarmTopologyTag() {
// return mainSwarmTopologyTag;
// }
public void SetMainSwarmTopologyTag(int mainSwarmTopologyTag) {
public void setMainSwarmTopologyTag(int mainSwarmTopologyTag) {
// Possible topologies are: "Linear", "Grid", "Star", "Multi-Swarm", "Tree", "HPSO", "Random" in that order starting by 0.
this.mainSwarmTopology = PSOTopology.getFromId(mainSwarmTopologyTag);
}
@ -1172,7 +1106,7 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
*
* @param dirForCurrentExperiment
*/
public void SetDirForCurrentExperiment(String dirForCurrentExperiment) {
public void setDirForCurrentExperiment(String dirForCurrentExperiment) {
this.dirForCurrentExperiment = dirForCurrentExperiment;
}
@ -1184,21 +1118,11 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
return mainSwarm;
}
// public InterfaceParameterAging getMainSwarmInertness(){
// return mainSwarmParamAging;
//// return this.mainSwarm.getInertnessAging();
// }
//
// public void setMainSwarmInertness(InterfaceParameterAging pa){
// mainSwarmParamAging = pa;
// this.mainSwarm.setInertnessAging(pa);
// getMainSwarm().setInertnessOrChi(pa.getStartValue());
// }
public String mainSwarmInertnessTipText() {
return "sets the inertness weight used for the PSO to train the main swarm (see help for details)";
}
public void SetSubSwarms(Vector<ParticleSubSwarmOptimization> subSwarms) {
public void setSubSwarms(Vector<ParticleSubSwarmOptimization> subSwarms) {
this.subSwarms = subSwarms;
}
@ -1265,16 +1189,6 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
public String subswarmCreationStrategyTipText() {
return "sets the strategy to create subswarms from the main swarm";
}
/**
* @tested nn (non-Javadoc)
* @see javaeva.server.oa.go.Strategies.InterfaceOptimizer#getProblem()
*/
@Override
public InterfaceOptimizationProblem getProblem() {
return this.optimizationProblem;
}
/**
* @param problem
* @tested ps This method will set the problem that is to be optimized
@ -2114,7 +2028,7 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
* @param randSeed
* @param evalCnt
* @return
* @see #stdNPSO(AbstractOptimizationProblem, long, int)
* @see #stdNPSO(AbstractOptimizer, long, int)
*/
public static OptimizationParameters stdNPSO(NichePSO npso, AbstractOptimizationProblem problem, long randSeed, int evalCnt) {
if (npso == null) {
@ -2136,7 +2050,7 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
npso.getMainSwarmAlgoType().setSelectedTag("Inertness");
npso.getMainSwarm().setPhi1(1.2);
npso.getMainSwarm().setPhi2(0); // by default no communication in the mainswarm
npso.SetMainSwarmTopologyTag(0); // this doesnt have any effect due to no communication
npso.setMainSwarmTopologyTag(0); // this doesnt have any effect due to no communication
npso.setMainSwarmTopologyRange(0);
npso.mainSwarmAlgoType = 0;
npso.getMainSwarm().setParameterControl(new ParamAdaption[]{getDefaultInertnessAdaption()});
@ -2159,12 +2073,12 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
* Optimizer. SEAL 2002. Exeption: the swarm size is 200 by default, because
* 30 (of the orig. paper) seems way too low.
*
* @param an already existing NichePSO instance or null to create a new one
* @param npso an already existing NichePSO instance or null to create a new one
* @param problem
* @param randSeed
* @param evalCnt
* @return
* @see #stdNPSO(AbstractOptimizationProblem, long, int)
* @see #stdNPSO(AbstractOptimizer, long, int)
*/
public static OptimizationParameters starNPSO(NichePSO npso, AbstractOptimizationProblem problem, long randSeed, int evalCnt) {
starNPSO(npso, evalCnt);
@ -2191,7 +2105,7 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
npso.setMainSwarmAlgoType(npso.getMainSwarm().getAlgoType().setSelectedTag("Inertness")); // constriction
npso.getMainSwarm().setPhi1(1.2);
// npso.SetMainSwarmPhi2(0); // by default no communication in the mainswarm
npso.SetMainSwarmTopologyTag(0); // this doesnt have any effect due to no communication
npso.setMainSwarmTopologyTag(0); // this doesnt have any effect due to no communication
npso.setMainSwarmTopologyRange(0);
npso.mainSwarmAlgoType = 0;
npso.getMainSwarm().setParameterControl(new ParamAdaption[]{getDefaultInertnessAdaption()});

View File

@ -24,17 +24,9 @@ import eva2.util.annotation.Description;
* now.
*/
@Description("This is a Particle Filter Algorithm.")
public class ParticleFilterOptimization implements InterfaceOptimizer, java.io.Serializable {
public class ParticleFilterOptimization extends AbstractOptimizer implements java.io.Serializable {
/**
* Comment for
* <code>serialVersionUID</code>
*/
private static final long serialVersionUID = 1L;
private Population population = new Population();
private InterfaceOptimizationProblem optimizationProblem = new F1Problem();
private InterfaceSelection parentSelection = new SelectParticleWheel(0.5);
private String identifier = "";
private boolean withShow = false;
private double mutationSigma = 0.01;
private double randomImmigrationQuota = 0.05;
@ -43,7 +35,6 @@ public class ParticleFilterOptimization implements InterfaceOptimizer, java.io.S
private int popSize = 300;
private int sleepTime = 0;
transient private int indCount = 0;
transient private InterfacePopulationChangedEventListener populationChangedEventListener;
transient Plot myPlot = null;
public ParticleFilterOptimization() {
@ -66,7 +57,6 @@ public class ParticleFilterOptimization implements InterfaceOptimizer, java.io.S
public ParticleFilterOptimization(ParticleFilterOptimization a) {
this.population = (Population) a.population.clone();
this.optimizationProblem = (InterfaceOptimizationProblem) a.optimizationProblem.clone();
this.identifier = a.identifier;
this.parentSelection = (InterfaceSelection) a.parentSelection.clone();
if (a.withShow) {
setWithShow(true);
@ -84,9 +74,6 @@ public class ParticleFilterOptimization implements InterfaceOptimizer, java.io.S
@Override
public void initialize() {
//System.out.println("popsize is " + population.size());
//System.out.println("pops targ is " + population.getPopulationSize());
if (initialVelocity <= 0.) {
(((AbstractOptimizationProblem) optimizationProblem).getIndividualTemplate()).setMutationOperator(new MutateESFixedStepSize(mutationSigma));
} else {
@ -203,13 +190,6 @@ public class ParticleFilterOptimization implements InterfaceOptimizer, java.io.S
} else {
myPlot.setUnconnectedPoint(curPosition[0], curPosition[1], graphLabel);
}
// myPlot.setConnectedPoint(curPosition[0], curPosition[1], graphLabel);
// if ( !useCircles && (pop.getEAIndividual(i).hasData(MutateESCorrVector.vectorKey))) {
// double[] v=(double[])pop.getEAIndividual(i).getData(MutateESCorrVector.vectorKey);
// myPlot.setConnectedPoint(curPosition[0], curPosition[1], graphLabel+5);
// curPosition=Mathematics.vvAdd(v, curPosition);
// myPlot.setConnectedPoint(curPosition[0], curPosition[1], graphLabel+5);
// }
}
}
}
@ -250,28 +230,6 @@ public class ParticleFilterOptimization implements InterfaceOptimizer, java.io.S
}
@Override
public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) {
this.populationChangedEventListener = ea;
}
@Override
public boolean removePopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) {
if (populationChangedEventListener == ea) {
populationChangedEventListener = null;
return true;
} else {
return false;
}
}
protected void firePropertyChangedEvent(String name) {
if (this.populationChangedEventListener != null) {
this.populationChangedEventListener.registerPopulationStateChanged(this, name);
}
}
/**
* This method will set the problem that is to be optimized
*
@ -285,11 +243,6 @@ public class ParticleFilterOptimization implements InterfaceOptimizer, java.io.S
}
}
@Override
public InterfaceOptimizationProblem getProblem() {
return this.optimizationProblem;
}
/**
* This method will return a string describing all properties of the
* optimizer and the applied methods.
@ -316,27 +269,6 @@ public class ParticleFilterOptimization implements InterfaceOptimizer, java.io.S
return "PF";
}
/**
* Assuming that all optimizer will store thier data in a population we will
* allow acess to this population to query to current state of the
* optimizer.
*
* @return The population of current solutions to a given problem.
*/
@Override
public Population getPopulation() {
return this.population;
}
@Override
public void setPopulation(Population pop) {
this.population = pop;
}
public String populationTipText() {
return "Edit the properties of the population used.";
}
@Override
public InterfaceSolutionSet getAllSolutions() {
return new SolutionSet(getPopulation());
@ -386,9 +318,9 @@ public class ParticleFilterOptimization implements InterfaceOptimizer, java.io.S
/**
* @param withShow the withShow to set
*/
public void setWithShow(boolean wShow) {
this.withShow = wShow;
if (!withShow) {
public void setWithShow(boolean withShow) {
this.withShow = withShow;
if (!this.withShow) {
myPlot = null;
} else {
double[][] range;

View File

@ -31,12 +31,6 @@ public class ParticleSubSwarmOptimization extends ParticleSwarmOptimizationGCPSO
private int particleIndexCounter; // used to give each particle a unique index (for debbugging and plotting)
private int fitnessArchiveSize = 15; // maximal number of fitnessvalues remembered from former iterations
//ParameterupdateStrategies
// InterfaceParameterAging inertnessAging = new NoParameterAging();
/**********************************************************************************************************************
* ctors, clone
*/
/**
* @tested ps
* ctor

View File

@ -40,16 +40,14 @@ import java.util.Vector;
* "HPSO", "Random" in that order starting by 0.
*/
@Description("Particle Swarm Optimization by Kennedy and Eberhart.")
public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Serializable, InterfaceAdditionalPopulationInformer {
public class ParticleSwarmOptimization extends AbstractOptimizer implements java.io.Serializable, InterfaceAdditionalPopulationInformer {
/**
* Generated serial version uid.
*/
private static final long serialVersionUID = -149996122795669589L;
protected Population population = new Population();
Object[] sortedPop = null;
protected AbstractEAIndividual bestIndividual = null;
protected InterfaceOptimizationProblem optimizationProblem = new F1Problem();
protected boolean checkRange = true;
protected boolean checkSpeedLimit = false;
protected boolean useAlternative = false;
@ -1458,53 +1456,6 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
}
}
/**
* This method allows you to add the LectureGUI as listener to the Optimizer
*
* @param ea
*/
@Override
public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) {
if (this.changeListener == null) {
this.changeListener = new Vector<>();
}
this.changeListener.add(ea);
}
@Override
public boolean removePopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) {
return changeListener != null && changeListener.removeElement(ea);
}
/**
* Something has changed
*
* @param name
*/
protected void firePropertyChangedEvent(String name) {
if (this.changeListener != null) {
for (int i = 0; i < this.changeListener.size(); i++) {
this.changeListener.get(i).registerPopulationStateChanged(this, name);
}
}
}
/**
* This method will set the problem that is to be optimized
*
* @param problem
*/
@Override
public void setProblem(InterfaceOptimizationProblem problem) {
this.optimizationProblem = problem;
}
@Override
public InterfaceOptimizationProblem getProblem() {
return this.optimizationProblem;
}
/**
* This method will return a string describing all properties of the
* optimizer and the applied methods.
@ -1531,11 +1482,6 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
return "PSO-" + getTopology() + getTopologyRange() + "_" + getPhi1() + "_" + getPhi2();
}
@Override
public Population getPopulation() {
return this.population;
}
@Override
public void setPopulation(Population pop) {
this.population = pop;
@ -1558,10 +1504,6 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
bestIndividual = pop.getBestEAIndividual();
}
public String populationTipText() {
return "Edit the properties of the population used.";
}
@Override
public InterfaceSolutionSet getAllSolutions() {
return new SolutionSet(getPopulation());

View File

@ -25,7 +25,7 @@ import eva2.util.annotation.Description;
* a new meta-heuristic. TecReport 215. Univ. de Tours, 1999.
*/
@Description("The Population based incremental learning is based on a statistical distribution of bit positions. Please note: This optimizer requires a binary genotype!")
public class PopulationBasedIncrementalLearning implements InterfaceOptimizer, java.io.Serializable {
public class PopulationBasedIncrementalLearning extends AbstractOptimizer implements java.io.Serializable {
// These variables are necessary for the simple testcase
private InterfaceOptimizationProblem optimizationProblem = new B1Problem();
@ -153,36 +153,6 @@ public class PopulationBasedIncrementalLearning implements InterfaceOptimizer, j
}
}
@Override
public InterfaceOptimizationProblem getProblem() {
return this.optimizationProblem;
}
@Override
public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) {
this.populationChangedEventListener = ea;
}
@Override
public boolean removePopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) {
if (populationChangedEventListener == ea) {
populationChangedEventListener = null;
return true;
} else {
return false;
}
}
/**
* Something has changed
*/
protected void firePropertyChangedEvent(String name) {
if (this.populationChangedEventListener != null) {
this.populationChangedEventListener.registerPopulationStateChanged(this, name);
}
}
/**
* This method will return a string describing all properties of the
* optimizer and the applied methods.
@ -209,27 +179,6 @@ public class PopulationBasedIncrementalLearning implements InterfaceOptimizer, j
return "PBIL";
}
/**
* Assuming that all optimizer will store thier data in a population we will
* allow acess to this population to query to current state of the
* optimizer.
*
* @return The population of current solutions to a given problem.
*/
@Override
public Population getPopulation() {
return this.population;
}
@Override
public void setPopulation(Population pop) {
this.population = pop;
}
public String populationTipText() {
return "Edit the properties of the PBIL population used.";
}
@Override
public InterfaceSolutionSet getAllSolutions() {
return new SolutionSet(getPopulation());

View File

@ -1,12 +1,10 @@
package eva2.optimization.strategies;
import eva2.optimization.go.InterfacePopulationChangedEventListener;
import eva2.optimization.individuals.AbstractEAIndividual;
import eva2.optimization.individuals.GAIndividualBinaryData;
import eva2.optimization.population.InterfaceSolutionSet;
import eva2.optimization.population.Population;
import eva2.optimization.population.SolutionSet;
import eva2.problems.B1Problem;
import eva2.problems.InterfaceOptimizationProblem;
import eva2.tools.math.RNG;
import eva2.util.annotation.Description;
@ -18,20 +16,13 @@ import eva2.util.annotation.Description;
* size gives the number of multi-starts.
*/
@Description("The simulated annealing uses an additional cooling rate instead of a simple dominate criteria to accept worse solutions by chance.")
public class SimulatedAnnealing implements InterfaceOptimizer, java.io.Serializable {
// These variables are necessary for the simple testcase
private InterfaceOptimizationProblem optimizationProblem = new B1Problem();
public class SimulatedAnnealing extends AbstractOptimizer implements java.io.Serializable {
private int multiRuns = 100;
private int fitnessCalls = 100;
private int fitnessCallsNeeded = 0;
GAIndividualBinaryData bestIndividual, testIndividual;
public double initialTemperature = 2, currentTemperature;
public double alpha = 0.9;
// These variables are necessary for the more complex LectureGUI enviroment
transient private String identifier = "";
transient private InterfacePopulationChangedEventListener populationChangedEventListener;
private Population population;
public SimulatedAnnealing() {
this.population = new Population();
@ -131,21 +122,6 @@ public class SimulatedAnnealing implements InterfaceOptimizer, java.io.Serializa
return result;
}
/**
* This method will set the problem that is to be optimized
*
* @param problem
*/
@Override
public void setProblem(InterfaceOptimizationProblem problem) {
this.optimizationProblem = problem;
}
@Override
public InterfaceOptimizationProblem getProblem() {
return this.optimizationProblem;
}
/**
* This method will initialize the HillClimber
*/
@ -191,28 +167,6 @@ public class SimulatedAnnealing implements InterfaceOptimizer, java.io.Serializa
System.out.println("(" + program.multiRuns + "/" + program.fitnessCalls + ") Mean Fitness : " + TmpMeanFitness + " Mean Calls needed: " + TmpMeanCalls);
}
@Override
public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) {
this.populationChangedEventListener = ea;
}
@Override
public boolean removePopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) {
if (populationChangedEventListener == ea) {
populationChangedEventListener = null;
return true;
} else {
return false;
}
}
protected void firePropertyChangedEvent(String name) {
if (this.populationChangedEventListener != null) {
this.populationChangedEventListener.registerPopulationStateChanged(this, name);
}
}
/**
* This method will return a string describing all properties of the
* optimizer and the applied methods.
@ -244,27 +198,6 @@ public class SimulatedAnnealing implements InterfaceOptimizer, java.io.Serializa
return "MS-SA";
}
/**
* Assuming that all optimizer will store thier data in a population we will
* allow acess to this population to query to current state of the
* optimizer.
*
* @return The population of current solutions to a given problem.
*/
@Override
public Population getPopulation() {
return this.population;
}
@Override
public void setPopulation(Population pop) {
this.population = pop;
}
public String populationTipText() {
return "Change the number of best individuals stored (MS-SA)).";
}
@Override
public InterfaceSolutionSet getAllSolutions() {
return new SolutionSet(getPopulation());

View File

@ -18,7 +18,7 @@ public class StarANPSO extends ANPSO {
getMainSwarm().setPhi1(1.2);
getMainSwarm().setPhi2(0.6); // ANPSO uses communication in the main swarm
//Possible topologies are: "Linear", "Grid", "Star", "Multi-Swarm", "Tree", "HPSO", "Random" in that order starting by 0.
SetMainSwarmTopologyTag(3); //"Multi-Swarm" favors the formation of groups in the main swarm
setMainSwarmTopologyTag(3); //"Multi-Swarm" favors the formation of groups in the main swarm
setMainSwarmTopologyRange(2); // range for topologies like random, grid etc. (does not affect "Multi-Swarm")
setMaxInitialSubSwarmSize(0); // deactivate early reinits
}

View File

@ -1,6 +1,5 @@
package eva2.optimization.strategies;
import eva2.optimization.go.InterfacePopulationChangedEventListener;
import eva2.optimization.individuals.AbstractEAIndividual;
import eva2.optimization.individuals.GAIndividualBinaryData;
import eva2.optimization.operator.selection.InterfaceSelection;
@ -20,16 +19,13 @@ import eva2.util.annotation.Description;
* are performed each time optimize() is called.
*/
@Description("This is a Steady-State Genetic Algorithm.")
public class SteadyStateGA implements InterfaceOptimizer, java.io.Serializable {
public class SteadyStateGA extends AbstractOptimizer implements java.io.Serializable {
private Population population = new Population();
private InterfaceOptimizationProblem optimizationProblem = new B1Problem();
private InterfaceSelection parentSelection = new SelectTournament();
private InterfaceSelection partnerSelection = new SelectTournament();
private InterfaceReplacement replacementSelection = new ReplaceWorst();
private int numberOfPartners = 1;
private String identifier = "";
transient private InterfacePopulationChangedEventListener populationChangedEventListener;
public SteadyStateGA() {
}
@ -37,7 +33,6 @@ public class SteadyStateGA implements InterfaceOptimizer, java.io.Serializable {
public SteadyStateGA(SteadyStateGA a) {
this.population = (Population) a.population.clone();
this.optimizationProblem = (InterfaceOptimizationProblem) a.optimizationProblem.clone();
this.identifier = a.identifier;
this.numberOfPartners = a.numberOfPartners;
this.parentSelection = (InterfaceSelection) a.parentSelection.clone();
this.partnerSelection = (InterfaceSelection) a.partnerSelection.clone();
@ -123,43 +118,6 @@ public class SteadyStateGA implements InterfaceOptimizer, java.io.Serializable {
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
}
@Override
public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) {
this.populationChangedEventListener = ea;
}
@Override
public boolean removePopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) {
if (populationChangedEventListener == ea) {
populationChangedEventListener = null;
return true;
} else {
return false;
}
}
protected void firePropertyChangedEvent(String name) {
if (this.populationChangedEventListener != null) {
this.populationChangedEventListener.registerPopulationStateChanged(this, name);
}
}
/**
* This method will set the problem that is to be optimized
*
* @param problem
*/
@Override
public void setProblem(InterfaceOptimizationProblem problem) {
this.optimizationProblem = problem;
}
@Override
public InterfaceOptimizationProblem getProblem() {
return this.optimizationProblem;
}
/**
* This method will return a string describing all properties of the
* optimizer and the applied methods.
@ -186,22 +144,6 @@ public class SteadyStateGA implements InterfaceOptimizer, java.io.Serializable {
return "SS-GA";
}
/**
* Assuming that all optimizers will store their data in a population we will
* allow access to this population to query to current state of the
* optimizer.
*
* @return The population of current solutions to a given problem.
*/
@Override
public Population getPopulation() {
return this.population;
}
@Override
public void setPopulation(Population pop) {
this.population = pop;
}
public String populationTipText() {
return "Edit the properties of the population used.";

View File

@ -15,20 +15,13 @@ import eva2.util.annotation.Description;
* similar problems.
*/
@Description("The threshold algorithm uses an declining threshold to accpect new solutions.")
public class ThresholdAlgorithm implements InterfaceOptimizer, java.io.Serializable {
// These variables are necessary for the simple testcase
private InterfaceOptimizationProblem optimizationProblem = new B1Problem();
public class ThresholdAlgorithm extends AbstractOptimizer implements java.io.Serializable {
private int multiRuns = 100;
private int fitnessCalls = 100;
private int fitnessCallsNeeded = 0;
GAIndividualBinaryData bestIndividual, testIndividual;
public double initialT = 2, currentT;
public double alpha = 0.9;
// These variables are necessary for the more complex LectureGUI enviroment
transient private String indentifier = "";
transient private InterfacePopulationChangedEventListener populationChangedEventListener;
private Population population;
public ThresholdAlgorithm() {
this.population = new Population();
@ -182,28 +175,6 @@ public class ThresholdAlgorithm implements InterfaceOptimizer, java.io.Serializa
System.out.println("(" + program.multiRuns + "/" + program.fitnessCalls + ") Mean Fitness : " + TmpMeanFitness + " Mean Calls needed: " + TmpMeanCalls);
}
@Override
public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) {
this.populationChangedEventListener = ea;
}
@Override
public boolean removePopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) {
if (populationChangedEventListener == ea) {
populationChangedEventListener = null;
return true;
} else {
return false;
}
}
protected void firePropertyChangedEvent(String name) {
if (this.populationChangedEventListener != null) {
this.populationChangedEventListener.registerPopulationStateChanged(this, name);
}
}
/**
* This method will return a string describing all properties of the
* optimizer and the applied methods.
@ -234,27 +205,6 @@ public class ThresholdAlgorithm implements InterfaceOptimizer, java.io.Serializa
return "MS-TA";
}
/**
* Assuming that all optimizer will store thier data in a population we will
* allow acess to this population to query to current state of the
* optimizer.
*
* @return The population of current solutions to a given problem.
*/
@Override
public Population getPopulation() {
return this.population;
}
@Override
public void setPopulation(Population pop) {
this.population = pop;
}
public String populationTipText() {
return "Change the number of best individuals stored (MS-TA).";
}
@Override
public InterfaceSolutionSet getAllSolutions() {
return new SolutionSet(getPopulation());

View File

@ -29,7 +29,6 @@ public class WingedMultiObjectiveEA implements InterfaceOptimizer, java.io.Seria
private int migrationRate = 5;
private int outputDimension = 2;
private InterfaceOptimizationProblem optimizationProblem = new FM0Problem();
private String identifier = "";
transient private InterfacePopulationChangedEventListener populationChangedEventListener;
public WingedMultiObjectiveEA() {