Merging mk branch revs. 543:546 (except niching constructors in OptimizerFactory)
This commit is contained in:
parent
b735e9402b
commit
89975518ef
@ -10,6 +10,7 @@ import eva2.server.go.IndividualInterface;
|
|||||||
import eva2.server.go.InterfacePopulationChangedEventListener;
|
import eva2.server.go.InterfacePopulationChangedEventListener;
|
||||||
import eva2.server.go.InterfaceTerminator;
|
import eva2.server.go.InterfaceTerminator;
|
||||||
import eva2.server.go.enums.DETypeEnum;
|
import eva2.server.go.enums.DETypeEnum;
|
||||||
|
import eva2.server.go.enums.MutateESCrossoverTypeEnum;
|
||||||
import eva2.server.go.enums.PSOTopologyEnum;
|
import eva2.server.go.enums.PSOTopologyEnum;
|
||||||
import eva2.server.go.enums.PostProcessMethod;
|
import eva2.server.go.enums.PostProcessMethod;
|
||||||
import eva2.server.go.individuals.AbstractEAIndividual;
|
import eva2.server.go.individuals.AbstractEAIndividual;
|
||||||
@ -144,11 +145,7 @@ public class OptimizerFactory {
|
|||||||
|
|
||||||
problem.initProblem();
|
problem.initProblem();
|
||||||
|
|
||||||
AbstractEAIndividual tmpIndi = problem.getIndividualTemplate();
|
setTemplateOperators(problem, new NoMutation(), 0, new NoCrossover(), 0);
|
||||||
tmpIndi.setCrossoverOperator(new NoCrossover());
|
|
||||||
tmpIndi.setCrossoverProbability(0.0);
|
|
||||||
tmpIndi.setMutationOperator(new NoMutation());
|
|
||||||
tmpIndi.setMutationProbability(0.0);
|
|
||||||
|
|
||||||
DifferentialEvolution de = new DifferentialEvolution();
|
DifferentialEvolution de = new DifferentialEvolution();
|
||||||
de.SetProblem(problem);
|
de.SetProblem(problem);
|
||||||
@ -261,11 +258,7 @@ public class OptimizerFactory {
|
|||||||
|
|
||||||
problem.initProblem();
|
problem.initProblem();
|
||||||
|
|
||||||
AbstractEAIndividual tmpIndi = problem.getIndividualTemplate();
|
setTemplateOperators(problem, mut, pm, cross, pc);
|
||||||
tmpIndi.setCrossoverOperator(cross);
|
|
||||||
tmpIndi.setCrossoverProbability(pc);
|
|
||||||
tmpIndi.setMutationOperator(mut);
|
|
||||||
tmpIndi.setMutationProbability(pm);
|
|
||||||
|
|
||||||
GeneticAlgorithm ga = new GeneticAlgorithm();
|
GeneticAlgorithm ga = new GeneticAlgorithm();
|
||||||
ga.SetProblem(problem);
|
ga.SetProblem(problem);
|
||||||
@ -374,13 +367,7 @@ public class OptimizerFactory {
|
|||||||
|
|
||||||
problem.initProblem();
|
problem.initProblem();
|
||||||
|
|
||||||
MutateESFixedStepSize mutator = new MutateESFixedStepSize();
|
setTemplateOperators(problem, new MutateESFixedStepSize(0.2), 1., new NoCrossover(), 0);
|
||||||
mutator.setSigma(0.2); // mutations step size
|
|
||||||
AbstractEAIndividual tmpIndi = problem.getIndividualTemplate();
|
|
||||||
tmpIndi.setMutationOperator(mutator);
|
|
||||||
tmpIndi.setMutationProbability(1.0);
|
|
||||||
tmpIndi.setCrossoverOperator(new NoCrossover());
|
|
||||||
tmpIndi.setCrossoverProbability(0);
|
|
||||||
|
|
||||||
HillClimbing hc = new HillClimbing();
|
HillClimbing hc = new HillClimbing();
|
||||||
hc.getPopulation().setTargetSize(pop);
|
hc.getPopulation().setTargetSize(pop);
|
||||||
@ -407,11 +394,7 @@ public class OptimizerFactory {
|
|||||||
InterfacePopulationChangedEventListener listener) {
|
InterfacePopulationChangedEventListener listener) {
|
||||||
|
|
||||||
problem.initProblem();
|
problem.initProblem();
|
||||||
AbstractEAIndividual tmpIndi = problem.getIndividualTemplate();
|
setTemplateOperators(problem, new NoMutation(), 0, new NoCrossover(), 0);
|
||||||
tmpIndi.setMutationOperator(new NoMutation());
|
|
||||||
tmpIndi.setMutationProbability(0);
|
|
||||||
tmpIndi.setCrossoverOperator(new NoCrossover());
|
|
||||||
tmpIndi.setCrossoverProbability(0);
|
|
||||||
|
|
||||||
MonteCarloSearch mc = new MonteCarloSearch();
|
MonteCarloSearch mc = new MonteCarloSearch();
|
||||||
mc.getPopulation().setTargetSize(popsize);
|
mc.getPopulation().setTargetSize(popsize);
|
||||||
@ -426,7 +409,7 @@ public class OptimizerFactory {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This method performs a particle swarm optimization. Standard topologies are
|
* This method performs a particle swarm optimization. Standard topologies are
|
||||||
* linear (0), grid (1) and star (2).
|
* linear, grid and star.
|
||||||
*
|
*
|
||||||
* @param problem
|
* @param problem
|
||||||
* @param mut
|
* @param mut
|
||||||
@ -447,11 +430,7 @@ public class OptimizerFactory {
|
|||||||
|
|
||||||
problem.initProblem();
|
problem.initProblem();
|
||||||
|
|
||||||
AbstractEAIndividual tmpIndi = problem.getIndividualTemplate();
|
setTemplateOperators(problem, new NoMutation(), 0, new NoCrossover(), 0);
|
||||||
tmpIndi.setCrossoverOperator(new NoCrossover());
|
|
||||||
tmpIndi.setCrossoverProbability(0.0);
|
|
||||||
tmpIndi.setMutationOperator(new NoMutation());
|
|
||||||
tmpIndi.setMutationProbability(0.0);
|
|
||||||
|
|
||||||
ParticleSwarmOptimization pso = new ParticleSwarmOptimization();
|
ParticleSwarmOptimization pso = new ParticleSwarmOptimization();
|
||||||
pso.SetProblem(problem);
|
pso.SetProblem(problem);
|
||||||
@ -492,11 +471,7 @@ public class OptimizerFactory {
|
|||||||
|
|
||||||
problem.initProblem();
|
problem.initProblem();
|
||||||
|
|
||||||
AbstractEAIndividual tmpIndi = problem.getIndividualTemplate();
|
setTemplateOperators(problem, mut, 1, new NoCrossover(), 0);
|
||||||
tmpIndi.setCrossoverOperator(new NoCrossover());
|
|
||||||
tmpIndi.setCrossoverProbability(0.0);
|
|
||||||
tmpIndi.setMutationOperator(mut);
|
|
||||||
tmpIndi.setMutationProbability(1.0);
|
|
||||||
|
|
||||||
SimulatedAnnealing sa = new SimulatedAnnealing();
|
SimulatedAnnealing sa = new SimulatedAnnealing();
|
||||||
sa.setAlpha(alpha);
|
sa.setAlpha(alpha);
|
||||||
@ -927,19 +902,19 @@ public class OptimizerFactory {
|
|||||||
String outputFilePrefix) {
|
String outputFilePrefix) {
|
||||||
OptimizerRunnable runnable = optimize(new OptimizerRunnable(params,
|
OptimizerRunnable runnable = optimize(new OptimizerRunnable(params,
|
||||||
outputFilePrefix));
|
outputFilePrefix));
|
||||||
return runnable.getSolutionSet();
|
return runnable.getResultPopulation();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Population optimizeToPop(final int optType,
|
public static Population optimizeToPop(final int optType,
|
||||||
AbstractOptimizationProblem problem, String outputFilePrefix) {
|
AbstractOptimizationProblem problem, String outputFilePrefix) {
|
||||||
OptimizerRunnable runnable = optimize(optType, problem,
|
OptimizerRunnable runnable = optimize(optType, problem,
|
||||||
outputFilePrefix);
|
outputFilePrefix);
|
||||||
return (runnable != null) ? runnable.getSolutionSet() : null;
|
return (runnable != null) ? runnable.getResultPopulation() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Population optimizeToPop(OptimizerRunnable runnable) {
|
public static Population optimizeToPop(OptimizerRunnable runnable) {
|
||||||
optimize(runnable);
|
optimize(runnable);
|
||||||
return (runnable != null) ? runnable.getSolutionSet() : null;
|
return (runnable != null) ? runnable.getResultPopulation() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////// post processing
|
///////////////////////////// post processing
|
||||||
@ -985,7 +960,7 @@ public class OptimizerFactory {
|
|||||||
runnable.run(); // this run will not set the lastRunnable -
|
runnable.run(); // this run will not set the lastRunnable -
|
||||||
// postProcessing
|
// postProcessing
|
||||||
// starts always anew
|
// starts always anew
|
||||||
return runnable.getSolutionSet();
|
return runnable.getResultPopulation();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Vector<BitSet> postProcessBinVec(int steps, double sigma,
|
public static Vector<BitSet> postProcessBinVec(int steps, double sigma,
|
||||||
@ -1354,17 +1329,10 @@ public class OptimizerFactory {
|
|||||||
es.setLambda(50);
|
es.setLambda(50);
|
||||||
es.setPlusStrategy(false);
|
es.setPlusStrategy(false);
|
||||||
|
|
||||||
AbstractEAIndividual indyTemplate = problem.getIndividualTemplate();
|
if (assertIndyType(problem,InterfaceESIndividual.class)) {
|
||||||
if ((indyTemplate != null)
|
setTemplateOperators(problem, new MutateESCovarianceMatrixAdaption(true), 1, new CrossoverESDefault(), 0);
|
||||||
&& (indyTemplate instanceof InterfaceESIndividual)) {
|
|
||||||
// Set CMA operator for mutation
|
|
||||||
AbstractEAIndividual indy = (AbstractEAIndividual) indyTemplate;
|
|
||||||
MutateESCovarianceMatrixAdaption cmaMut = new MutateESCovarianceMatrixAdaption();
|
|
||||||
cmaMut.setCheckConstraints(true);
|
|
||||||
AbstractEAIndividual.setOperators(indy, cmaMut, 1., new CrossoverESDefault(), 0.);
|
|
||||||
} else {
|
} else {
|
||||||
System.err
|
System.err.println("Error, CMA-ES is implemented for ES individuals only (requires double data types)");
|
||||||
.println("Error, CMA-ES is implemented for ES individuals only (requires double data types)");
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1417,6 +1385,12 @@ public class OptimizerFactory {
|
|||||||
return makeParams(nms, 50, problem, randSeed, makeDefaultTerminator());
|
return makeParams(nms, 50, problem, randSeed, makeDefaultTerminator());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This constructs a standard DE variant with current-to-best/1 scheme, F=0.8,
|
||||||
|
* k=0.6, lambda=0.6. The population size is 50 by default.
|
||||||
|
* @param problem
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public static final GOParameters standardDE(
|
public static final GOParameters standardDE(
|
||||||
AbstractOptimizationProblem problem) {
|
AbstractOptimizationProblem problem) {
|
||||||
DifferentialEvolution de = new DifferentialEvolution();
|
DifferentialEvolution de = new DifferentialEvolution();
|
||||||
@ -1424,7 +1398,7 @@ public class OptimizerFactory {
|
|||||||
de.setF(0.8);
|
de.setF(0.8);
|
||||||
de.setK(0.6);
|
de.setK(0.6);
|
||||||
de.setLambda(0.6);
|
de.setLambda(0.6);
|
||||||
de.setMt(0.05);
|
de.setMt(0.05); // this is not really employed for currentToBest
|
||||||
return makeParams(de, 50, problem, randSeed, makeDefaultTerminator());
|
return makeParams(de, 50, problem, randSeed, makeDefaultTerminator());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1435,18 +1409,12 @@ public class OptimizerFactory {
|
|||||||
es.setLambda(50);
|
es.setLambda(50);
|
||||||
es.setPlusStrategy(false);
|
es.setPlusStrategy(false);
|
||||||
|
|
||||||
AbstractEAIndividual indy = problem.getIndividualTemplate();
|
if (assertIndyType(problem,InterfaceESIndividual.class)) {
|
||||||
|
setTemplateOperators(problem, new MutateESGlobal(0.2, MutateESCrossoverTypeEnum.intermediate), 0.9, new CrossoverESDefault(), 0.2);
|
||||||
if ((indy != null) && (indy instanceof InterfaceESIndividual)) {
|
|
||||||
// Set CMA operator for mutation
|
|
||||||
indy.setMutationOperator(new MutateESGlobal());
|
|
||||||
indy.setCrossoverOperator(new CrossoverESDefault());
|
|
||||||
} else {
|
} else {
|
||||||
System.err
|
System.err.println("Error, standard ES is implemented for ES individuals only (requires double data types)");
|
||||||
.println("Error, standard ES is implemented for ES individuals only (requires double data types)");
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return makeESParams(es, problem);
|
return makeESParams(es, problem);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1458,6 +1426,12 @@ public class OptimizerFactory {
|
|||||||
return makeParams(ga, 100, problem, randSeed, makeDefaultTerminator());
|
return makeParams(ga, 100, problem, randSeed, makeDefaultTerminator());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A standard constricted PSO instance with phi1=phi2=2.05, grid topology of range 1 and
|
||||||
|
* a population size of 30. The chi parameter is set to approx. 0.73 automatically.
|
||||||
|
* @param problem
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public static final GOParameters standardPSO(
|
public static final GOParameters standardPSO(
|
||||||
AbstractOptimizationProblem problem) {
|
AbstractOptimizationProblem problem) {
|
||||||
ParticleSwarmOptimization pso = new ParticleSwarmOptimization();
|
ParticleSwarmOptimization pso = new ParticleSwarmOptimization();
|
||||||
@ -1471,4 +1445,31 @@ public class OptimizerFactory {
|
|||||||
public static final GOParameters tribes(AbstractOptimizationProblem problem) {
|
public static final GOParameters tribes(AbstractOptimizationProblem problem) {
|
||||||
return makeParams(new Tribes(), 1, problem, randSeed, makeDefaultTerminator());
|
return makeParams(new Tribes(), 1, problem, randSeed, makeDefaultTerminator());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a given problem instance has a template individual matching the given class.
|
||||||
|
*
|
||||||
|
* @param prob
|
||||||
|
* @param cls
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private static boolean assertIndyType(AbstractOptimizationProblem prob,
|
||||||
|
Class<InterfaceESIndividual> cls) {
|
||||||
|
return cls.isAssignableFrom(prob.getIndividualTemplate().getClass());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the evolutionary operators of the individual template of the given problem instance.
|
||||||
|
* @param prob
|
||||||
|
* @param mute
|
||||||
|
* @param pMut
|
||||||
|
* @param cross
|
||||||
|
* @param pCross
|
||||||
|
*/
|
||||||
|
public static void setTemplateOperators(AbstractOptimizationProblem prob, InterfaceMutation mute, double pMut, InterfaceCrossover cross, double pCross) {
|
||||||
|
AbstractEAIndividual indy = prob.getIndividualTemplate();
|
||||||
|
if ((indy != null)) {
|
||||||
|
indy.setOperators(mute, pMut, cross, pCross);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,9 +4,9 @@ import java.io.PrintWriter;
|
|||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.util.BitSet;
|
import java.util.BitSet;
|
||||||
|
|
||||||
|
|
||||||
import eva2.server.go.IndividualInterface;
|
import eva2.server.go.IndividualInterface;
|
||||||
import eva2.server.go.InterfaceGOParameters;
|
import eva2.server.go.InterfaceGOParameters;
|
||||||
|
import eva2.server.go.InterfaceNotifyOnInformers;
|
||||||
import eva2.server.go.InterfaceTerminator;
|
import eva2.server.go.InterfaceTerminator;
|
||||||
import eva2.server.go.individuals.InterfaceDataTypeBinary;
|
import eva2.server.go.individuals.InterfaceDataTypeBinary;
|
||||||
import eva2.server.go.individuals.InterfaceDataTypeDouble;
|
import eva2.server.go.individuals.InterfaceDataTypeDouble;
|
||||||
@ -14,12 +14,13 @@ import eva2.server.go.individuals.InterfaceDataTypeInteger;
|
|||||||
import eva2.server.go.operators.postprocess.InterfacePostProcessParams;
|
import eva2.server.go.operators.postprocess.InterfacePostProcessParams;
|
||||||
import eva2.server.go.operators.postprocess.PostProcessParams;
|
import eva2.server.go.operators.postprocess.PostProcessParams;
|
||||||
import eva2.server.go.populations.Population;
|
import eva2.server.go.populations.Population;
|
||||||
|
import eva2.server.go.populations.SolutionSet;
|
||||||
import eva2.server.modules.GOParameters;
|
import eva2.server.modules.GOParameters;
|
||||||
import eva2.server.modules.Processor;
|
import eva2.server.modules.Processor;
|
||||||
import eva2.server.stat.AbstractStatistics;
|
import eva2.server.stat.AbstractStatistics;
|
||||||
import eva2.server.stat.InterfaceStatistics;
|
import eva2.server.stat.InterfaceStatistics;
|
||||||
import eva2.server.stat.StatisticsDummy;
|
|
||||||
import eva2.server.stat.InterfaceTextListener;
|
import eva2.server.stat.InterfaceTextListener;
|
||||||
|
import eva2.server.stat.StatisticsDummy;
|
||||||
import eva2.server.stat.StatisticsStandalone;
|
import eva2.server.stat.StatisticsStandalone;
|
||||||
import eva2.server.stat.StatsParameter;
|
import eva2.server.stat.StatsParameter;
|
||||||
import eva2.tools.jproxy.RemoteStateListener;
|
import eva2.tools.jproxy.RemoteStateListener;
|
||||||
@ -87,6 +88,10 @@ public class OptimizerRunnable implements Runnable {
|
|||||||
public OptimizerRunnable(GOParameters params, InterfaceStatistics stats, boolean restart) {
|
public OptimizerRunnable(GOParameters params, InterfaceStatistics stats, boolean restart) {
|
||||||
rnblID = cntID;
|
rnblID = cntID;
|
||||||
cntID++;
|
cntID++;
|
||||||
|
if (stats.getStatisticsParameter() instanceof InterfaceNotifyOnInformers) {
|
||||||
|
// addition for the statistics revision with selectable strings - make sure the go parameters are represented within the statistics
|
||||||
|
params.addInformableInstance((InterfaceNotifyOnInformers)(stats.getStatisticsParameter()));
|
||||||
|
}
|
||||||
proc = new Processor(stats, null, params);
|
proc = new Processor(stats, null, params);
|
||||||
if (proc.getStatistics() instanceof AbstractStatistics) ((AbstractStatistics)proc.getStatistics()).setSaveParams(false);
|
if (proc.getStatistics() instanceof AbstractStatistics) ((AbstractStatistics)proc.getStatistics()).setSaveParams(false);
|
||||||
doRestart = restart;
|
doRestart = restart;
|
||||||
@ -121,6 +126,10 @@ public class OptimizerRunnable implements Runnable {
|
|||||||
InterfaceGOParameters params = proc.getGOParams();
|
InterfaceGOParameters params = proc.getGOParams();
|
||||||
proc = new Processor(stats, null, params);
|
proc = new Processor(stats, null, params);
|
||||||
if (proc.getStatistics() instanceof AbstractStatistics) ((AbstractStatistics)proc.getStatistics()).setSaveParams(false);
|
if (proc.getStatistics() instanceof AbstractStatistics) ((AbstractStatistics)proc.getStatistics()).setSaveParams(false);
|
||||||
|
if (stats.getStatisticsParameter() instanceof InterfaceNotifyOnInformers) {
|
||||||
|
// addition for the statistics revision with selectable strings - make sure the go parameters are represented within the statistics
|
||||||
|
params.addInformableInstance((InterfaceNotifyOnInformers)(stats.getStatisticsParameter()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTextListener(InterfaceTextListener lsnr) {
|
public void setTextListener(InterfaceTextListener lsnr) {
|
||||||
@ -184,10 +193,14 @@ public class OptimizerRunnable implements Runnable {
|
|||||||
return proc.getStatistics().getBestSolution();
|
return proc.getStatistics().getBestSolution();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Population getSolutionSet() {
|
public Population getResultPopulation() {
|
||||||
return proc.getResultPopulation();
|
return proc.getResultPopulation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SolutionSet getSolutionSet() {
|
||||||
|
return (SolutionSet)proc.getGOParams().getOptimizer().getAllSolutions();
|
||||||
|
}
|
||||||
|
|
||||||
public void setPostProcessingParams(InterfacePostProcessParams ppp) {
|
public void setPostProcessingParams(InterfacePostProcessParams ppp) {
|
||||||
proc.getGOParams().setPostProcessParams(ppp);
|
proc.getGOParams().setPostProcessParams(ppp);
|
||||||
}
|
}
|
||||||
|
@ -65,6 +65,15 @@ public class MutateESCovarianceMatrixAdaption implements InterfaceMutation, java
|
|||||||
if (mutator.m_Eigenvalues != null) this.m_Eigenvalues = (double[]) mutator.m_Eigenvalues.clone();
|
if (mutator.m_Eigenvalues != null) this.m_Eigenvalues = (double[]) mutator.m_Eigenvalues.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor allowing to set the range check option.
|
||||||
|
*
|
||||||
|
* @param doCheckConstraints if true, the range constraints are enforced on mutation.
|
||||||
|
*/
|
||||||
|
public MutateESCovarianceMatrixAdaption(boolean doCheckConstraints) {
|
||||||
|
setCheckConstraints(doCheckConstraints);
|
||||||
|
}
|
||||||
|
|
||||||
/** This method will enable you to clone a given mutation operator
|
/** This method will enable you to clone a given mutation operator
|
||||||
* @return The clone
|
* @return The clone
|
||||||
*/
|
*/
|
||||||
|
@ -40,7 +40,7 @@ class WaitForEvARunnable implements Runnable {
|
|||||||
mp.log("\n");
|
mp.log("\n");
|
||||||
// write results back to matlab
|
// write results back to matlab
|
||||||
mp.exportResultToMatlab(runnable);
|
mp.exportResultToMatlab(runnable);
|
||||||
mp.exportResultPopulationToMatlab(runnable.getSolutionSet());
|
mp.exportResultPopulationToMatlab(runnable.getResultPopulation());
|
||||||
mp.log("reported results.\n");
|
mp.log("reported results.\n");
|
||||||
mp.notifyFinished();
|
mp.notifyFinished();
|
||||||
mp.log("notified finish.\n");
|
mp.log("notified finish.\n");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user