Some updates to OptimizerFactory, PostProcess. Minor clean-up in benchmarks.
This commit is contained in:
parent
f010fc827c
commit
232113e061
@ -1,19 +1,28 @@
|
|||||||
package javaeva;
|
package javaeva;
|
||||||
|
|
||||||
|
import java.util.BitSet;
|
||||||
|
import java.util.Vector;
|
||||||
|
|
||||||
import javaeva.gui.BeanInspector;
|
import javaeva.gui.BeanInspector;
|
||||||
import javaeva.server.go.IndividualInterface;
|
import javaeva.server.go.IndividualInterface;
|
||||||
import javaeva.server.go.InterfaceTerminator;
|
import javaeva.server.go.InterfaceTerminator;
|
||||||
import javaeva.server.go.individuals.AbstractEAIndividual;
|
import javaeva.server.go.individuals.AbstractEAIndividual;
|
||||||
|
import javaeva.server.go.individuals.InterfaceDataTypeBinary;
|
||||||
|
import javaeva.server.go.individuals.InterfaceDataTypeDouble;
|
||||||
import javaeva.server.go.individuals.InterfaceESIndividual;
|
import javaeva.server.go.individuals.InterfaceESIndividual;
|
||||||
import javaeva.server.go.operators.cluster.ClusteringDensityBased;
|
import javaeva.server.go.operators.cluster.ClusteringDensityBased;
|
||||||
import javaeva.server.go.operators.crossover.CrossoverESDefault;
|
import javaeva.server.go.operators.crossover.CrossoverESDefault;
|
||||||
import javaeva.server.go.operators.mutation.MutateESCovarianceMartixAdaption;
|
import javaeva.server.go.operators.mutation.MutateESCovarianceMartixAdaption;
|
||||||
import javaeva.server.go.operators.mutation.MutateESGlobal;
|
import javaeva.server.go.operators.mutation.MutateESGlobal;
|
||||||
|
import javaeva.server.go.operators.postprocess.InterfacePostProcessParams;
|
||||||
|
import javaeva.server.go.operators.postprocess.PostProcessParams;
|
||||||
import javaeva.server.go.operators.terminators.CombinedTerminator;
|
import javaeva.server.go.operators.terminators.CombinedTerminator;
|
||||||
import javaeva.server.go.operators.terminators.EvaluationTerminator;
|
import javaeva.server.go.operators.terminators.EvaluationTerminator;
|
||||||
|
import javaeva.server.go.operators.terminators.FitnessConvergenceTerminator;
|
||||||
import javaeva.server.go.populations.Population;
|
import javaeva.server.go.populations.Population;
|
||||||
import javaeva.server.go.problems.AbstractOptimizationProblem;
|
import javaeva.server.go.problems.AbstractOptimizationProblem;
|
||||||
import javaeva.server.go.strategies.ClusterBasedNichingEA;
|
import javaeva.server.go.strategies.ClusterBasedNichingEA;
|
||||||
|
import javaeva.server.go.strategies.ClusteringHillClimbing;
|
||||||
import javaeva.server.go.strategies.DifferentialEvolution;
|
import javaeva.server.go.strategies.DifferentialEvolution;
|
||||||
import javaeva.server.go.strategies.EvolutionStrategies;
|
import javaeva.server.go.strategies.EvolutionStrategies;
|
||||||
import javaeva.server.go.strategies.GeneticAlgorithm;
|
import javaeva.server.go.strategies.GeneticAlgorithm;
|
||||||
@ -43,17 +52,21 @@ public class OptimizerFactory {
|
|||||||
public final static int RANDOM = 7;
|
public final static int RANDOM = 7;
|
||||||
public final static int HILLCL = 8;
|
public final static int HILLCL = 8;
|
||||||
public final static int CBN_ES = 9;
|
public final static int CBN_ES = 9;
|
||||||
|
public final static int CL_HILLCL = 10;
|
||||||
|
|
||||||
public final static int defaultFitCalls = 10000;
|
public final static int defaultFitCalls = 10000;
|
||||||
public final static int randSeed = 0;
|
public final static int randSeed = 0;
|
||||||
|
|
||||||
|
private static OptimizerRunnable lastRunnable = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a simple String showing the accessible optimizers. For external access."
|
* Return a simple String showing the accessible optimizers. For external access."
|
||||||
*
|
*
|
||||||
* @return a String listing the accessible optimizers
|
* @return a String listing the accessible optimizers
|
||||||
*/
|
*/
|
||||||
public static String showOptimizers() {
|
public static String showOptimizers() {
|
||||||
return "1: Standard ES; 2: CMA-ES; 3: GA; 4: PSO; 5: DE; 6: Tribes; 7: Random (Monte Carlo); 8: HillClimbing; 9: Cluster-based niching ES";
|
return "1: Standard ES \n2: CMA-ES \n3: GA \n4: PSO \n5: DE \n6: Tribes \n7: Random (Monte Carlo) " +
|
||||||
|
"\n8: Hill-Climbing \n9: Cluster-based niching ES \n10: Clustering Hill-Climbing";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -81,14 +94,195 @@ public class OptimizerFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO hier weiter kommentieren
|
// TODO hier weiter kommentieren
|
||||||
public static IndividualInterface optimize(final int optType, AbstractOptimizationProblem problem, String outputFilePrefix) {
|
public static OptimizerRunnable optimize(final int optType, AbstractOptimizationProblem problem, String outputFilePrefix) {
|
||||||
OptimizerRunnable runnable = getOptRunnable(optType, problem, outputFilePrefix);
|
return optimize(getOptRunnable(optType, problem, outputFilePrefix));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static OptimizerRunnable optimize(OptimizerRunnable runnable) {
|
||||||
if (runnable != null) {
|
if (runnable != null) {
|
||||||
new Thread(runnable).run();
|
new Thread(runnable).run();
|
||||||
return runnable.getSolution();
|
lastRunnable = runnable;
|
||||||
|
return runnable;
|
||||||
} else return null;
|
} else return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String terminatedBecause() {
|
||||||
|
if (lastRunnable != null) return lastRunnable.terminatedBecause();
|
||||||
|
else return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int lastEvalsPerformed() {
|
||||||
|
if (lastRunnable != null) return lastRunnable.getProgress();
|
||||||
|
else return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/////////////////////////////// Optimize a given parameter instance
|
||||||
|
public static BitSet optimizeToBinary(GOParameters params, String outputFilePrefix) {
|
||||||
|
OptimizerRunnable runnable = optimize(new OptimizerRunnable(params, outputFilePrefix));
|
||||||
|
return runnable.getBinarySolution();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double[] optimizeToDouble(GOParameters params, String outputFilePrefix) {
|
||||||
|
OptimizerRunnable runnable = optimize(new OptimizerRunnable(params, outputFilePrefix));
|
||||||
|
return runnable.getDoubleSolution();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IndividualInterface optimizeToInd(GOParameters params, String outputFilePrefix) {
|
||||||
|
OptimizerRunnable runnable = optimize(new OptimizerRunnable(params, outputFilePrefix));
|
||||||
|
return runnable.getResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Population optimizeToPop(GOParameters params, String outputFilePrefix) {
|
||||||
|
OptimizerRunnable runnable = optimize(new OptimizerRunnable(params, outputFilePrefix));
|
||||||
|
return runnable.getSolutionSet();
|
||||||
|
}
|
||||||
|
|
||||||
|
/////////////////////////////// Optimize a given runnable
|
||||||
|
public static BitSet optimizeToBinary(OptimizerRunnable runnable) {
|
||||||
|
optimize(runnable);
|
||||||
|
if (runnable != null) return runnable.getBinarySolution();
|
||||||
|
else return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double[] optimizeToDouble(OptimizerRunnable runnable) {
|
||||||
|
optimize(runnable);
|
||||||
|
if (runnable != null) return runnable.getDoubleSolution();
|
||||||
|
else return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IndividualInterface optimizeToInd(OptimizerRunnable runnable) {
|
||||||
|
optimize(runnable);
|
||||||
|
if (runnable != null) return runnable.getResult();
|
||||||
|
else return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Population optimizeToPop(OptimizerRunnable runnable) {
|
||||||
|
optimize(runnable);
|
||||||
|
if (runnable != null) return runnable.getSolutionSet();
|
||||||
|
else return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/////////////////////////////// Optimize using a default strategy
|
||||||
|
public static BitSet optimizeToBinary(final int optType, AbstractOptimizationProblem problem, String outputFilePrefix) {
|
||||||
|
OptimizerRunnable runnable = optimize(optType, problem, outputFilePrefix);
|
||||||
|
if (runnable != null) return runnable.getBinarySolution();
|
||||||
|
else return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double[] optimizeToDouble(final int optType, AbstractOptimizationProblem problem, String outputFilePrefix) {
|
||||||
|
OptimizerRunnable runnable = optimize(optType, problem, outputFilePrefix);
|
||||||
|
if (runnable != null) return runnable.getDoubleSolution();
|
||||||
|
else return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IndividualInterface optimizeToInd(final int optType, AbstractOptimizationProblem problem, String outputFilePrefix) {
|
||||||
|
OptimizerRunnable runnable = optimize(optType, problem, outputFilePrefix);
|
||||||
|
if (runnable != null) return runnable.getResult();
|
||||||
|
else return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Population optimizeToPop(final int optType, AbstractOptimizationProblem problem, String outputFilePrefix) {
|
||||||
|
OptimizerRunnable runnable = optimize(optType, problem, outputFilePrefix);
|
||||||
|
if (runnable != null) return runnable.getSolutionSet();
|
||||||
|
else return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////// post processing
|
||||||
|
public static Vector<AbstractEAIndividual> postProcessIndVec(OptimizerRunnable runnable, int steps, double sigma, int nBest) {
|
||||||
|
return postProcessIndVec(runnable, new PostProcessParams(steps, sigma, nBest));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Vector<AbstractEAIndividual> postProcessIndVec(int steps, double sigma, int nBest) {
|
||||||
|
return (lastRunnable != null) ? postProcessIndVec(lastRunnable, new PostProcessParams(steps, sigma, nBest)) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Vector<AbstractEAIndividual> postProcessIndVec(InterfacePostProcessParams ppp) {
|
||||||
|
return (lastRunnable != null) ? postProcessIndVec(lastRunnable, ppp) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Vector<AbstractEAIndividual> postProcessIndVec(OptimizerRunnable runnable, InterfacePostProcessParams ppp) {
|
||||||
|
Population resPop = postProcess(runnable, ppp);
|
||||||
|
Vector<AbstractEAIndividual> ret = new Vector<AbstractEAIndividual>(resPop.size());
|
||||||
|
for (Object o : resPop) {
|
||||||
|
if (o instanceof AbstractEAIndividual) {
|
||||||
|
AbstractEAIndividual indy = (AbstractEAIndividual)o;
|
||||||
|
ret.add(indy);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Vector<BitSet> postProcessBinVec(InterfacePostProcessParams ppp) {
|
||||||
|
return (lastRunnable != null) ? postProcessBinVec(lastRunnable, ppp) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Vector<BitSet> postProcessBinVec(OptimizerRunnable runnable, InterfacePostProcessParams ppp) {
|
||||||
|
Population resPop = postProcess(runnable, ppp);
|
||||||
|
Vector<BitSet> ret = new Vector<BitSet>(resPop.size());
|
||||||
|
for (Object o : resPop) {
|
||||||
|
if (o instanceof InterfaceDataTypeBinary) {
|
||||||
|
InterfaceDataTypeBinary indy = (InterfaceDataTypeBinary)o;
|
||||||
|
ret.add(indy.getBinaryData());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Vector<BitSet> postProcessBinVec(int steps, double sigma, int nBest) {
|
||||||
|
return (lastRunnable != null) ? postProcessBinVec(lastRunnable, new PostProcessParams(steps, sigma, nBest)) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Vector<BitSet> postProcessBinVec(OptimizerRunnable runnable, int steps, double sigma, int nBest) {
|
||||||
|
return postProcessBinVec(runnable, new PostProcessParams(steps, sigma, nBest));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Vector<double[]> postProcessDblVec(InterfacePostProcessParams ppp) {
|
||||||
|
if (lastRunnable != null) return postProcessDblVec(lastRunnable, ppp);
|
||||||
|
else return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Vector<double[]> postProcessDblVec(OptimizerRunnable runnable, InterfacePostProcessParams ppp) {
|
||||||
|
Population resPop = postProcess(runnable, ppp);
|
||||||
|
Vector<double[]> ret = new Vector<double[]>(resPop.size());
|
||||||
|
for (Object o : resPop) {
|
||||||
|
if (o instanceof InterfaceDataTypeDouble) {
|
||||||
|
InterfaceDataTypeDouble indy = (InterfaceDataTypeDouble)o;
|
||||||
|
ret.add(indy.getDoubleData());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Vector<double[]> postProcessDblVec(int steps, double sigma, int nBest) {
|
||||||
|
return (lastRunnable == null) ? null : postProcessDblVec(lastRunnable, new PostProcessParams(steps, sigma, nBest));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Vector<double[]> postProcessDblVec(OptimizerRunnable runnable, int steps, double sigma, int nBest) {
|
||||||
|
return postProcessDblVec(runnable, new PostProcessParams(steps, sigma, nBest));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Population postProcess(int steps, double sigma, int nBest) {
|
||||||
|
return (lastRunnable == null) ? null : postProcess(lastRunnable, new PostProcessParams(steps, sigma, nBest));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Population postProcess(OptimizerRunnable runnable, int steps, double sigma, int nBest) {
|
||||||
|
PostProcessParams ppp = new PostProcessParams(steps, sigma, nBest);
|
||||||
|
return postProcess(runnable, ppp);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Population postProcess(InterfacePostProcessParams ppp) {
|
||||||
|
return (lastRunnable == null) ? null : postProcess(lastRunnable, ppp);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Population postProcess(OptimizerRunnable runnable, InterfacePostProcessParams ppp) {
|
||||||
|
runnable.setDoRestart(true);
|
||||||
|
runnable.setDoPostProcessOnly(true);
|
||||||
|
runnable.setPostProcessingParams(ppp);
|
||||||
|
runnable.run(); // this run will not set the lastRunnable - postProcessing starts always anew
|
||||||
|
return runnable.getSolutionSet();
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////// constructing a default OptimizerRunnable
|
||||||
public static OptimizerRunnable getOptRunnable(final int optType, AbstractOptimizationProblem problem, String outputFilePrefix) {
|
public static OptimizerRunnable getOptRunnable(final int optType, AbstractOptimizationProblem problem, String outputFilePrefix) {
|
||||||
return getOptRunnable(optType, problem, defaultFitCalls, outputFilePrefix);
|
return getOptRunnable(optType, problem, defaultFitCalls, outputFilePrefix);
|
||||||
}
|
}
|
||||||
@ -123,6 +317,9 @@ public class OptimizerFactory {
|
|||||||
case CBN_ES:
|
case CBN_ES:
|
||||||
opt = new OptimizerRunnable(cbnES(problem), outputFilePrefix);
|
opt = new OptimizerRunnable(cbnES(problem), outputFilePrefix);
|
||||||
break;
|
break;
|
||||||
|
case CL_HILLCL:
|
||||||
|
opt = new OptimizerRunnable(clusteringHillClimbing(problem), outputFilePrefix);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
System.err.println("Error: optimizer type " + optType + " is unknown!");
|
System.err.println("Error: optimizer type " + optType + " is unknown!");
|
||||||
return null;
|
return null;
|
||||||
@ -131,10 +328,19 @@ public class OptimizerFactory {
|
|||||||
return opt;
|
return opt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///////////////////////////// Termination criteria
|
||||||
public static InterfaceTerminator defaultTerminator() {
|
public static InterfaceTerminator defaultTerminator() {
|
||||||
if (term == null) term = new EvaluationTerminator(defaultFitCalls);
|
if (term == null) term = new EvaluationTerminator(defaultFitCalls);
|
||||||
return term;
|
return term;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setEvaluationTerminator(int maxEvals) {
|
||||||
|
setTerminator(new EvaluationTerminator(maxEvals));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setFitnessConvergenceTerminator(double fitThresh) {
|
||||||
|
setTerminator(new FitnessConvergenceTerminator(fitThresh, 100, true, true));
|
||||||
|
}
|
||||||
|
|
||||||
public static void setTerminator(InterfaceTerminator term) {
|
public static void setTerminator(InterfaceTerminator term) {
|
||||||
OptimizerFactory.term = term;
|
OptimizerFactory.term = term;
|
||||||
@ -156,6 +362,7 @@ public class OptimizerFactory {
|
|||||||
else setTerminator(new CombinedTerminator(OptimizerFactory.term, newTerm, bAnd));
|
else setTerminator(new CombinedTerminator(OptimizerFactory.term, newTerm, bAnd));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///////////////////////// Creating default strategies
|
||||||
public static GOParameters makeParams(InterfaceOptimizer opt, Population pop, AbstractOptimizationProblem problem, long seed, InterfaceTerminator term) {
|
public static GOParameters makeParams(InterfaceOptimizer opt, Population pop, AbstractOptimizationProblem problem, long seed, InterfaceTerminator term) {
|
||||||
GOParameters params = new GOParameters();
|
GOParameters params = new GOParameters();
|
||||||
params.setProblem(problem);
|
params.setProblem(problem);
|
||||||
@ -169,14 +376,14 @@ public class OptimizerFactory {
|
|||||||
|
|
||||||
public static GOParameters standardES(AbstractOptimizationProblem problem) {
|
public static GOParameters standardES(AbstractOptimizationProblem problem) {
|
||||||
EvolutionStrategies es = new EvolutionStrategies();
|
EvolutionStrategies es = new EvolutionStrategies();
|
||||||
es.setMyu(15);
|
es.setMu(15);
|
||||||
es.setLambda(50);
|
es.setLambda(50);
|
||||||
es.setPlusStrategy(false);
|
es.setPlusStrategy(false);
|
||||||
|
|
||||||
Object maybeTemplate = BeanInspector.callIfAvailable(problem, "getEAIndividual", null);
|
AbstractEAIndividual indy = problem.getIndividualTemplate();
|
||||||
if ((maybeTemplate != null) && (maybeTemplate instanceof InterfaceESIndividual)) {
|
|
||||||
|
if ((indy != null) && (indy instanceof InterfaceESIndividual)) {
|
||||||
// Set CMA operator for mutation
|
// Set CMA operator for mutation
|
||||||
AbstractEAIndividual indy = (AbstractEAIndividual)maybeTemplate;
|
|
||||||
indy.setMutationOperator(new MutateESGlobal());
|
indy.setMutationOperator(new MutateESGlobal());
|
||||||
indy.setCrossoverOperator(new CrossoverESDefault());
|
indy.setCrossoverOperator(new CrossoverESDefault());
|
||||||
} else {
|
} else {
|
||||||
@ -192,7 +399,7 @@ public class OptimizerFactory {
|
|||||||
|
|
||||||
public static GOParameters cmaES(AbstractOptimizationProblem problem) {
|
public static GOParameters cmaES(AbstractOptimizationProblem problem) {
|
||||||
EvolutionStrategies es = new EvolutionStrategies();
|
EvolutionStrategies es = new EvolutionStrategies();
|
||||||
es.setMyu(15);
|
es.setMu(15);
|
||||||
es.setLambda(50);
|
es.setLambda(50);
|
||||||
es.setPlusStrategy(false);
|
es.setPlusStrategy(false);
|
||||||
|
|
||||||
@ -278,14 +485,14 @@ public class OptimizerFactory {
|
|||||||
public static GOParameters cbnES(AbstractOptimizationProblem problem) {
|
public static GOParameters cbnES(AbstractOptimizationProblem problem) {
|
||||||
ClusterBasedNichingEA cbn = new ClusterBasedNichingEA();
|
ClusterBasedNichingEA cbn = new ClusterBasedNichingEA();
|
||||||
EvolutionStrategies es = new EvolutionStrategies();
|
EvolutionStrategies es = new EvolutionStrategies();
|
||||||
es.setMyu(15);
|
es.setMu(15);
|
||||||
es.setLambda(50);
|
es.setLambda(50);
|
||||||
es.setPlusStrategy(false);
|
es.setPlusStrategy(false);
|
||||||
cbn.setOptimizer(es);
|
cbn.setOptimizer(es);
|
||||||
ClusteringDensityBased clustering = new ClusteringDensityBased(0.1);
|
ClusteringDensityBased clustering = new ClusteringDensityBased(0.1);
|
||||||
cbn.setConvergenceCA((ClusteringDensityBased)clustering.clone());
|
cbn.setConvergenceCA((ClusteringDensityBased)clustering.clone());
|
||||||
cbn.setDifferentationCA(clustering);
|
cbn.setDifferentationCA(clustering);
|
||||||
cbn.setShowCycle(10); // dont do graphical output
|
cbn.setShowCycle(0); // dont do graphical output
|
||||||
|
|
||||||
Population pop = new Population();
|
Population pop = new Population();
|
||||||
pop.setPopulationSize(100);
|
pop.setPopulationSize(100);
|
||||||
@ -293,4 +500,20 @@ public class OptimizerFactory {
|
|||||||
|
|
||||||
return makeParams(cbn, pop, problem, randSeed, defaultTerminator());
|
return makeParams(cbn, pop, problem, randSeed, defaultTerminator());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static GOParameters clusteringHillClimbing(AbstractOptimizationProblem problem) {
|
||||||
|
ClusteringHillClimbing chc = new ClusteringHillClimbing();
|
||||||
|
chc.SetProblem(problem);
|
||||||
|
Population pop = new Population();
|
||||||
|
pop.setPopulationSize(100);
|
||||||
|
problem.initPopulation(pop);
|
||||||
|
chc.setHcEvalCycle(1000);
|
||||||
|
chc.setInitialPopSize(100);
|
||||||
|
chc.setStepSizeInitial(0.05);
|
||||||
|
chc.setMinImprovement(0.000001);
|
||||||
|
chc.setNotifyGuiEvery(0);
|
||||||
|
chc.setStepSizeThreshold(0.000001);
|
||||||
|
chc.setSigmaClust(0.05);
|
||||||
|
return makeParams(chc, pop, problem, randSeed, defaultTerminator());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,16 +4,18 @@ import java.io.PrintWriter;
|
|||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.util.BitSet;
|
import java.util.BitSet;
|
||||||
|
|
||||||
import javaeva.gui.BeanInspector;
|
|
||||||
import javaeva.server.go.IndividualInterface;
|
import javaeva.server.go.IndividualInterface;
|
||||||
import javaeva.server.go.InterfaceTerminator;
|
|
||||||
import javaeva.server.go.InterfaceGOParameters;
|
import javaeva.server.go.InterfaceGOParameters;
|
||||||
|
import javaeva.server.go.InterfaceTerminator;
|
||||||
import javaeva.server.go.individuals.InterfaceDataTypeBinary;
|
import javaeva.server.go.individuals.InterfaceDataTypeBinary;
|
||||||
import javaeva.server.go.individuals.InterfaceDataTypeDouble;
|
import javaeva.server.go.individuals.InterfaceDataTypeDouble;
|
||||||
import javaeva.server.go.individuals.InterfaceDataTypeInteger;
|
import javaeva.server.go.individuals.InterfaceDataTypeInteger;
|
||||||
import javaeva.server.go.operators.terminators.CombinedTerminator;
|
import javaeva.server.go.operators.postprocess.InterfacePostProcessParams;
|
||||||
|
import javaeva.server.go.operators.postprocess.PostProcessParams;
|
||||||
|
import javaeva.server.go.populations.Population;
|
||||||
import javaeva.server.modules.GOParameters;
|
import javaeva.server.modules.GOParameters;
|
||||||
import javaeva.server.modules.Processor;
|
import javaeva.server.modules.Processor;
|
||||||
|
import javaeva.server.stat.InterfaceTextListener;
|
||||||
import javaeva.server.stat.StatisticsStandalone;
|
import javaeva.server.stat.StatisticsStandalone;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -26,6 +28,8 @@ public class OptimizerRunnable implements Runnable {
|
|||||||
Processor proc;
|
Processor proc;
|
||||||
boolean isFinished = false;
|
boolean isFinished = false;
|
||||||
boolean doRestart = false; // indicate whether start or restart should be done --> whether pop will be reinitialized.
|
boolean doRestart = false; // indicate whether start or restart should be done --> whether pop will be reinitialized.
|
||||||
|
boolean postProcessOnly = false;
|
||||||
|
InterfaceTextListener listener = null;
|
||||||
|
|
||||||
public OptimizerRunnable(GOParameters params, String outputFilePrefix) {
|
public OptimizerRunnable(GOParameters params, String outputFilePrefix) {
|
||||||
this(params, outputFilePrefix, false);
|
this(params, outputFilePrefix, false);
|
||||||
@ -40,13 +44,25 @@ public class OptimizerRunnable implements Runnable {
|
|||||||
return proc.getGOParams();
|
return proc.getGOParams();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setTextListener(InterfaceTextListener lsnr) {
|
||||||
|
this.listener = lsnr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDoRestart(boolean restart) {
|
||||||
|
doRestart = restart;
|
||||||
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
isFinished = false;
|
isFinished = false;
|
||||||
try {
|
try {
|
||||||
proc.setSaveParams(false);
|
proc.setSaveParams(false);
|
||||||
if (doRestart) proc.restartOpt();
|
if (postProcessOnly) {
|
||||||
else proc.startOpt();
|
proc.performNewPostProcessing((PostProcessParams)proc.getGOParams().getPostProcessParams(), listener);
|
||||||
proc.runOptOnce();
|
} else {
|
||||||
|
if (doRestart) proc.restartOpt();
|
||||||
|
else proc.startOpt();
|
||||||
|
proc.runOptOnce();
|
||||||
|
}
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
proc.getStatistics().printToTextListener("Exception in OptimizeThread::run: " + e.getMessage() + "\n");
|
proc.getStatistics().printToTextListener("Exception in OptimizeThread::run: " + e.getMessage() + "\n");
|
||||||
StringWriter sw = new StringWriter();
|
StringWriter sw = new StringWriter();
|
||||||
@ -59,45 +75,65 @@ public class OptimizerRunnable implements Runnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setDoPostProcessOnly(boolean poPO) {
|
||||||
|
postProcessOnly = poPO;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isFinished() {
|
public boolean isFinished() {
|
||||||
return isFinished;
|
return isFinished;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void restartOpt() {
|
||||||
|
proc.restartOpt();
|
||||||
|
}
|
||||||
|
|
||||||
public void stopOpt() {
|
public void stopOpt() {
|
||||||
proc.stopOpt();
|
proc.stopOpt();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IndividualInterface getSolution() {
|
public IndividualInterface getResult() {
|
||||||
return proc.getStatistics().getBestSolution();
|
return proc.getStatistics().getBestSolution();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Population getSolutionSet() {
|
||||||
|
return proc.getResultPopulation();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPostProcessingParams(InterfacePostProcessParams ppp) {
|
||||||
|
proc.getGOParams().setPostProcessParams(ppp);
|
||||||
|
}
|
||||||
|
|
||||||
public int getProgress() {
|
public int getProgress() {
|
||||||
return proc.getGOParams().getOptimizer().getPopulation().getFunctionCalls();
|
return proc.getGOParams().getOptimizer().getPopulation().getFunctionCalls();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String terminatedBecause() {
|
public String terminatedBecause() {
|
||||||
if (isFinished) {
|
if (isFinished) {
|
||||||
InterfaceTerminator term = proc.getGOParams().getTerminator();
|
if (postProcessOnly) {
|
||||||
return term.terminatedBecause(proc.getGOParams().getOptimizer().getPopulation());
|
return "Post processing finished";
|
||||||
|
} else {
|
||||||
|
InterfaceTerminator term = proc.getGOParams().getTerminator();
|
||||||
|
return term.terminatedBecause(proc.getGOParams().getOptimizer().getPopulation());
|
||||||
|
}
|
||||||
} else return "Not yet terminated";
|
} else return "Not yet terminated";
|
||||||
}
|
}
|
||||||
|
|
||||||
public double[] getDoubleSolution() {
|
public double[] getDoubleSolution() {
|
||||||
IndividualInterface indy = getSolution();
|
IndividualInterface indy = getResult();
|
||||||
if (indy instanceof InterfaceDataTypeDouble) {
|
if (indy instanceof InterfaceDataTypeDouble) {
|
||||||
return ((InterfaceDataTypeDouble)indy).getDoubleData();
|
return ((InterfaceDataTypeDouble)indy).getDoubleData();
|
||||||
} else return null;
|
} else return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BitSet getBinarySolution() {
|
public BitSet getBinarySolution() {
|
||||||
IndividualInterface indy = getSolution();
|
IndividualInterface indy = getResult();
|
||||||
if (indy instanceof InterfaceDataTypeBinary) {
|
if (indy instanceof InterfaceDataTypeBinary) {
|
||||||
return ((InterfaceDataTypeBinary)indy).getBinaryData();
|
return ((InterfaceDataTypeBinary)indy).getBinaryData();
|
||||||
} else return null;
|
} else return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int[] getIntegerSolution() {
|
public int[] getIntegerSolution() {
|
||||||
IndividualInterface indy = getSolution();
|
IndividualInterface indy = getResult();
|
||||||
if (indy instanceof InterfaceDataTypeInteger) {
|
if (indy instanceof InterfaceDataTypeInteger) {
|
||||||
return ((InterfaceDataTypeInteger)indy).getIntegerData();
|
return ((InterfaceDataTypeInteger)indy).getIntegerData();
|
||||||
} else return null;
|
} else return null;
|
||||||
|
@ -658,6 +658,17 @@ public abstract class AbstractEAIndividual implements IndividualInterface, java.
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static String getDefaultDataString(IndividualInterface individual) {
|
public static String getDefaultDataString(IndividualInterface individual) {
|
||||||
|
return getDefaultDataString(individual, "; ");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method creates a default String representation for a number Individual interfaces
|
||||||
|
* containing the genotype.
|
||||||
|
*
|
||||||
|
* @param individual
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String getDefaultDataString(IndividualInterface individual, String separator) {
|
||||||
StringBuffer sb = new StringBuffer("");
|
StringBuffer sb = new StringBuffer("");
|
||||||
char left = '[';
|
char left = '[';
|
||||||
char right = ']';
|
char right = ']';
|
||||||
@ -672,25 +683,25 @@ public abstract class AbstractEAIndividual implements IndividualInterface, java.
|
|||||||
int[] b = ((InterfaceDataTypeInteger)individual).getIntegerData();
|
int[] b = ((InterfaceDataTypeInteger)individual).getIntegerData();
|
||||||
for (int i = 0; i < b.length; i++) {
|
for (int i = 0; i < b.length; i++) {
|
||||||
sb.append(b[i]);
|
sb.append(b[i]);
|
||||||
if ((i+1) < b.length) sb.append("; ");
|
if ((i+1) < b.length) sb.append(separator);
|
||||||
}
|
}
|
||||||
} else if (individual instanceof InterfaceDataTypeDouble) {
|
} else if (individual instanceof InterfaceDataTypeDouble) {
|
||||||
double[] b = ((InterfaceDataTypeDouble)individual).getDoubleData();
|
double[] b = ((InterfaceDataTypeDouble)individual).getDoubleData();
|
||||||
for (int i = 0; i < b.length; i++) {
|
for (int i = 0; i < b.length; i++) {
|
||||||
sb.append(b[i]);
|
sb.append(b[i]);
|
||||||
if ((i+1) < b.length) sb.append("; ");
|
if ((i+1) < b.length) sb.append(separator);
|
||||||
}
|
}
|
||||||
} else if (individual instanceof InterfaceDataTypePermutation) {
|
} else if (individual instanceof InterfaceDataTypePermutation) {
|
||||||
int[] b = ((InterfaceDataTypePermutation)individual).getPermutationData()[0];
|
int[] b = ((InterfaceDataTypePermutation)individual).getPermutationData()[0];
|
||||||
for (int i = 0; i < b.length; i++) {
|
for (int i = 0; i < b.length; i++) {
|
||||||
sb.append(b[i]);
|
sb.append(b[i]);
|
||||||
if ((i+1) < b.length) sb.append("; ");
|
if ((i+1) < b.length) sb.append(separator);
|
||||||
}
|
}
|
||||||
} else if (individual instanceof InterfaceDataTypeProgram) {
|
} else if (individual instanceof InterfaceDataTypeProgram) {
|
||||||
InterfaceProgram[] b = ((InterfaceDataTypeProgram)individual).getProgramData();
|
InterfaceProgram[] b = ((InterfaceDataTypeProgram)individual).getProgramData();
|
||||||
for (int i = 0; i < b.length; i++) {
|
for (int i = 0; i < b.length; i++) {
|
||||||
sb.append(b[i].getStringRepresentation());
|
sb.append(b[i].getStringRepresentation());
|
||||||
if ((i+1) < b.length) sb.append("; ");
|
if ((i+1) < b.length) sb.append(separator);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
System.err.println("error in AbstractEAIndividual::getDefaultDataString: type " + individual.getClass() + " not implemented");
|
System.err.println("error in AbstractEAIndividual::getDefaultDataString: type " + individual.getClass() + " not implemented");
|
||||||
|
@ -35,6 +35,15 @@ public class ClusteringDensityBased implements InterfaceClustering, java.io.Seri
|
|||||||
m_ClusterDistance = sigma;
|
m_ClusterDistance = sigma;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Directly set the minimum cluster distance sigma and minimum group size.
|
||||||
|
* @param sigma the minimum cluster distance
|
||||||
|
*/
|
||||||
|
public ClusteringDensityBased(double sigma, int minGSize) {
|
||||||
|
m_ClusterDistance = sigma;
|
||||||
|
m_MinimumGroupSize = minGSize;
|
||||||
|
}
|
||||||
|
|
||||||
public ClusteringDensityBased(ClusteringDensityBased a) {
|
public ClusteringDensityBased(ClusteringDensityBased a) {
|
||||||
if (a.m_Metric != null) this.m_Metric = (InterfaceDistanceMetric)a.m_Metric.clone();
|
if (a.m_Metric != null) this.m_Metric = (InterfaceDistanceMetric)a.m_Metric.clone();
|
||||||
this.m_TestConvergingSpeciesOnBestOnly = a.m_TestConvergingSpeciesOnBestOnly;
|
this.m_TestConvergingSpeciesOnBestOnly = a.m_TestConvergingSpeciesOnBestOnly;
|
||||||
|
@ -1,16 +1,14 @@
|
|||||||
package javaeva.server.go.operators.mutation;
|
package javaeva.server.go.operators.mutation;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import javaeva.server.go.individuals.AbstractEAIndividual;
|
import javaeva.server.go.individuals.AbstractEAIndividual;
|
||||||
import javaeva.server.go.individuals.InterfaceDataTypeDouble;
|
|
||||||
import javaeva.server.go.individuals.InterfaceESIndividual;
|
import javaeva.server.go.individuals.InterfaceESIndividual;
|
||||||
import javaeva.server.go.populations.Population;
|
import javaeva.server.go.populations.Population;
|
||||||
import javaeva.server.go.problems.InterfaceOptimizationProblem;
|
import javaeva.server.go.problems.InterfaceOptimizationProblem;
|
||||||
import javaeva.server.go.tools.RandomNumberGenerator;
|
import javaeva.server.go.tools.RandomNumberGenerator;
|
||||||
import javaeva.tools.Tag;
|
|
||||||
import javaeva.tools.SelectedTag;
|
import javaeva.tools.SelectedTag;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by IntelliJ IDEA.
|
* Created by IntelliJ IDEA.
|
||||||
* User: streiche
|
* User: streiche
|
||||||
@ -41,11 +39,7 @@ public class MutateESGlobal implements InterfaceMutation, java.io.Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void initTags() {
|
protected void initTags() {
|
||||||
Tag[] tag = new Tag[3];
|
this.m_CrossoverType = new SelectedTag(new String[]{"None", "Intermediate", "Discrete"});
|
||||||
tag[0] = new Tag(0, "None");
|
|
||||||
tag[1] = new Tag(1, "Intermediate");
|
|
||||||
tag[2] = new Tag(2, "Discrete");
|
|
||||||
this.m_CrossoverType = new SelectedTag(0, tag);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method will enable you to clone a given mutation operator
|
/** This method will enable you to clone a given mutation operator
|
||||||
@ -105,7 +99,7 @@ public class MutateESGlobal implements InterfaceMutation, java.io.Serializable {
|
|||||||
* @param partners The original partners
|
* @param partners The original partners
|
||||||
*/
|
*/
|
||||||
public void crossoverOnStrategyParameters(AbstractEAIndividual indy1, Population partners) {
|
public void crossoverOnStrategyParameters(AbstractEAIndividual indy1, Population partners) {
|
||||||
ArrayList tmpList = new ArrayList();
|
ArrayList<Double> tmpList = new ArrayList<Double>();
|
||||||
if (indy1.getMutationOperator() instanceof MutateESGlobal) tmpList.add(new Double(((MutateESGlobal)indy1.getMutationOperator()).m_MutationStepSize));
|
if (indy1.getMutationOperator() instanceof MutateESGlobal) tmpList.add(new Double(((MutateESGlobal)indy1.getMutationOperator()).m_MutationStepSize));
|
||||||
for (int i = 0; i < partners.size(); i++) {
|
for (int i = 0; i < partners.size(); i++) {
|
||||||
if (((AbstractEAIndividual)partners.get(i)).getMutationOperator() instanceof MutateESGlobal) tmpList.add(new Double(((MutateESGlobal)((AbstractEAIndividual)partners.get(i)).getMutationOperator()).m_MutationStepSize));
|
if (((AbstractEAIndividual)partners.get(i)).getMutationOperator() instanceof MutateESGlobal) tmpList.add(new Double(((MutateESGlobal)((AbstractEAIndividual)partners.get(i)).getMutationOperator()).m_MutationStepSize));
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package javaeva.server.go.operators.postprocess;
|
package javaeva.server.go.operators.postprocess;
|
||||||
|
|
||||||
import java.io.PrintStream;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javaeva.OptimizerFactory;
|
import javaeva.OptimizerFactory;
|
||||||
import javaeva.OptimizerRunnable;
|
import javaeva.OptimizerRunnable;
|
||||||
@ -19,7 +17,6 @@ import javaeva.server.go.operators.terminators.EvaluationTerminator;
|
|||||||
import javaeva.server.go.populations.Population;
|
import javaeva.server.go.populations.Population;
|
||||||
import javaeva.server.go.problems.AbstractOptimizationProblem;
|
import javaeva.server.go.problems.AbstractOptimizationProblem;
|
||||||
import javaeva.server.go.problems.FM0Problem;
|
import javaeva.server.go.problems.FM0Problem;
|
||||||
import javaeva.server.go.problems.InterfaceMultimodalProblem;
|
|
||||||
import javaeva.server.go.problems.InterfaceMultimodalProblemKnown;
|
import javaeva.server.go.problems.InterfaceMultimodalProblemKnown;
|
||||||
import javaeva.server.go.strategies.HillClimbing;
|
import javaeva.server.go.strategies.HillClimbing;
|
||||||
import javaeva.server.stat.InterfaceTextListener;
|
import javaeva.server.stat.InterfaceTextListener;
|
||||||
@ -36,6 +33,8 @@ public class PostProcess {
|
|||||||
private static final boolean TRACE = false;
|
private static final boolean TRACE = false;
|
||||||
// the default mutation step size for HC post processing
|
// the default mutation step size for HC post processing
|
||||||
private static double defaultMutationStepSize = 0.01;
|
private static double defaultMutationStepSize = 0.01;
|
||||||
|
// used for hill climbing post processing and only alive during that period
|
||||||
|
private static OptimizerRunnable hcRunnable = null;
|
||||||
|
|
||||||
public static final int BEST_ONLY = 1;
|
public static final int BEST_ONLY = 1;
|
||||||
public static final int BEST_RAND = 2;
|
public static final int BEST_RAND = 2;
|
||||||
@ -108,11 +107,13 @@ public class PostProcess {
|
|||||||
for (int i=0; i<optsFound.length; i++) {
|
for (int i=0; i<optsFound.length; i++) {
|
||||||
if (optsFound[i] != null) result.add(optsFound[i]);
|
if (optsFound[i] != null) result.add(optsFound[i]);
|
||||||
}
|
}
|
||||||
|
result.setPopulationSize(result.size());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calls clusterBest with a ClusteringDensitiyBased clustering object with the given sigma.
|
* Calls clusterBest with a ClusteringDensitiyBased clustering object with the given sigma and a
|
||||||
|
* minimum group size of 2.
|
||||||
* @see clusterBest(Population pop, InterfaceClustering clustering, double returnQuota, int lonerMode, int takeOverMode)
|
* @see clusterBest(Population pop, InterfaceClustering clustering, double returnQuota, int lonerMode, int takeOverMode)
|
||||||
* @param pop
|
* @param pop
|
||||||
* @param sigmaCluster
|
* @param sigmaCluster
|
||||||
@ -122,7 +123,7 @@ public class PostProcess {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static Population clusterBest(Population pop, double sigmaCluster, double returnQuota, int lonerMode, int takeOverMode) {
|
public static Population clusterBest(Population pop, double sigmaCluster, double returnQuota, int lonerMode, int takeOverMode) {
|
||||||
return clusterBest(pop, new ClusteringDensityBased(sigmaCluster), returnQuota, lonerMode, takeOverMode);
|
return clusterBest(pop, new ClusteringDensityBased(sigmaCluster, 2), returnQuota, lonerMode, takeOverMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -348,10 +349,19 @@ public class PostProcess {
|
|||||||
}
|
}
|
||||||
hc.setPopulation(pop);
|
hc.setPopulation(pop);
|
||||||
// hc.initByPopulation(pop, false);
|
// hc.initByPopulation(pop, false);
|
||||||
OptimizerRunnable runnable = new OptimizerRunnable(OptimizerFactory.makeParams(hc, pop, problem, 0, term), null, true);
|
hcRunnable = new OptimizerRunnable(OptimizerFactory.makeParams(hc, pop, problem, 0, term), null, true);
|
||||||
runnable.getGOParams().setDoPostProcessing(false);
|
hcRunnable.getGOParams().setDoPostProcessing(false);
|
||||||
runnable.run();
|
hcRunnable.run();
|
||||||
|
hcRunnable = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stop the hill-climbing post processing if its currently running.
|
||||||
|
*/
|
||||||
|
public static void stopHC() {
|
||||||
|
if (hcRunnable != null) synchronized (hcRunnable) {
|
||||||
|
if (hcRunnable != null) hcRunnable.stopOpt();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
@ -399,12 +409,12 @@ public class PostProcess {
|
|||||||
* @return a pair of the optimized population and the improvement in the mean fitness (not normed) achieved by the HC run
|
* @return a pair of the optimized population and the improvement in the mean fitness (not normed) achieved by the HC run
|
||||||
*/
|
*/
|
||||||
public static Pair<Population, Double> clusterHC(Population pop, AbstractOptimizationProblem problem, double sigmaCluster, int funCalls, double keepClusterRatio, InterfaceMutation mute) {
|
public static Pair<Population, Double> clusterHC(Population pop, AbstractOptimizationProblem problem, double sigmaCluster, int funCalls, double keepClusterRatio, InterfaceMutation mute) {
|
||||||
Population clust = (Population)clusterBest(pop, new ClusteringDensityBased(sigmaCluster), keepClusterRatio, KEEP_LONERS, BEST_RAND).clone();
|
Population clust = (Population)clusterBest(pop, new ClusteringDensityBased(sigmaCluster, 2), keepClusterRatio, KEEP_LONERS, BEST_RAND).clone();
|
||||||
// System.out.println("keeping " + clust.size() + " for hc....");
|
// System.out.println("keeping " + clust.size() + " for hc....");
|
||||||
double[] meanFit = clust.getMeanFitness();
|
double[] meanFit = clust.getMeanFitness();
|
||||||
processWithHC(clust, problem, new EvaluationTerminator(pop.getFunctionCalls()+funCalls), mute);
|
processWithHC(clust, problem, new EvaluationTerminator(pop.getFunctionCalls()+funCalls), mute);
|
||||||
double improvement = PhenotypeMetric.euclidianDistance(meanFit, clust.getMeanFitness());
|
double improvement = PhenotypeMetric.euclidianDistance(meanFit, clust.getMeanFitness());
|
||||||
System.out.println("improvement by " + improvement);
|
if (TRACE) System.out.println("improvement by " + improvement);
|
||||||
return new Pair<Population, Double>(clust, improvement);
|
return new Pair<Population, Double>(clust, improvement);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -457,15 +467,18 @@ public class PostProcess {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Do some data output for multimodal problems with known optima.
|
* Do some data output for multimodal problems with known optima. The listener may be null, but then the method is
|
||||||
|
* not really doing much at this state.
|
||||||
*/
|
*/
|
||||||
public static void procMultiModalKnown(Population solutions, InterfaceMultimodalProblemKnown mmkProb, InterfaceTextListener listener) {
|
public static void procMultiModalKnown(Population solutions, InterfaceMultimodalProblemKnown mmkProb, InterfaceTextListener listener) {
|
||||||
// Population found = getFoundOptima(solutions, mmkProb.getRealOptima(), mmkProb.getEpsilon(), true);
|
// Population found = getFoundOptima(solutions, mmkProb.getRealOptima(), mmkProb.getEpsilon(), true);
|
||||||
listener.println("default epsilon is " + mmkProb.getEpsilon());
|
if (listener != null) {
|
||||||
listener.println("max peak ratio is " + mmkProb.getMaximumPeakRatio(getFoundOptima(solutions, mmkProb.getRealOptima(), mmkProb.getEpsilon(), true)));
|
listener.println("default epsilon is " + mmkProb.getEpsilon());
|
||||||
|
listener.println("max peak ratio is " + mmkProb.getMaximumPeakRatio(getFoundOptima(solutions, mmkProb.getRealOptima(), mmkProb.getEpsilon(), true)));
|
||||||
|
}
|
||||||
for (double epsilon=0.1; epsilon > 0.00000001; epsilon/=10.) {
|
for (double epsilon=0.1; epsilon > 0.00000001; epsilon/=10.) {
|
||||||
// out.println("no optima found: " + ((InterfaceMultimodalProblemKnown)mmProb).getNumberOfFoundOptima(pop));
|
// out.println("no optima found: " + ((InterfaceMultimodalProblemKnown)mmProb).getNumberOfFoundOptima(pop));
|
||||||
listener.println("found " + getFoundOptima(solutions, mmkProb.getRealOptima(), epsilon, true).size() + " for epsilon = " + epsilon);
|
if (listener != null) listener.println("found " + getFoundOptima(solutions, mmkProb.getRealOptima(), epsilon, true).size() + " for epsilon = " + epsilon);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -478,38 +491,50 @@ public class PostProcess {
|
|||||||
* @param solutions
|
* @param solutions
|
||||||
* @param problem
|
* @param problem
|
||||||
* @param listener
|
* @param listener
|
||||||
|
* @return the clustered, post-processed population
|
||||||
*/
|
*/
|
||||||
public static void postProcess(InterfacePostProcessParams params, Population solutions, AbstractOptimizationProblem problem, InterfaceTextListener listener) {
|
public static Population postProcess(InterfacePostProcessParams params, Population solutions, AbstractOptimizationProblem problem, InterfaceTextListener listener) {
|
||||||
if (params.isDoPostProcessing()) {
|
if (params.isDoPostProcessing()) {
|
||||||
Population outputPop;
|
Population outputPop;
|
||||||
if (params.getPostProcessClusterSigma() > 0) {
|
if (params.getPostProcessClusterSigma() > 0) {
|
||||||
outputPop = (Population)PostProcess.clusterBest(solutions, params.getPostProcessClusterSigma(), 0, PostProcess.KEEP_LONERS, PostProcess.BEST_ONLY).clone();
|
outputPop = (Population)PostProcess.clusterBest(solutions, params.getPostProcessClusterSigma(), 0, PostProcess.KEEP_LONERS, PostProcess.BEST_ONLY).clone();
|
||||||
if (outputPop.size() < solutions.size()) {
|
if (outputPop.size() < solutions.size()) {
|
||||||
listener.println("Clustering reduced population size from " + solutions.size() + " to " + outputPop.size());
|
if (listener != null) listener.println("Initial clustering reduced population size from " + solutions.size() + " to " + outputPop.size());
|
||||||
} else listener.println("Clustering yielded no size reduction.");
|
} else if (listener != null) listener.println("Initial clustering yielded no size reduction.");
|
||||||
} else outputPop = solutions;
|
} else outputPop = solutions;
|
||||||
|
|
||||||
if (params.getPostProcessSteps() > 0) {
|
if (params.getPostProcessSteps() > 0) {
|
||||||
processWithHC(outputPop, problem, params.getPostProcessSteps());
|
processWithHC(outputPop, problem, params.getPostProcessSteps());
|
||||||
listener.println("HC post processing done.");
|
if (listener != null) listener.println("HC post processing done.");
|
||||||
|
// some individuals may have now converged again
|
||||||
|
if (params.getPostProcessClusterSigma() > 0) {
|
||||||
|
// so if wished, cluster again.
|
||||||
|
outputPop = (Population)PostProcess.clusterBest(outputPop, params.getPostProcessClusterSigma(), 0, PostProcess.KEEP_LONERS, PostProcess.BEST_ONLY).clone();
|
||||||
|
if (outputPop.size() < solutions.size()) {
|
||||||
|
if (listener != null) listener.println("Second clustering reduced population size from " + solutions.size() + " to " + outputPop.size());
|
||||||
|
} else if (listener != null) listener.println("Second clustering yielded no size reduction.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
double upBnd = PhenotypeMetric.norm(outputPop.getWorstEAIndividual().getFitness())*1.1;
|
double upBnd = PhenotypeMetric.norm(outputPop.getWorstEAIndividual().getFitness())*1.1;
|
||||||
upBnd = Math.pow(10,Math.floor(Math.log10(upBnd)+1));
|
upBnd = Math.pow(10,Math.floor(Math.log10(upBnd)+1));
|
||||||
double lowBnd = 0;
|
double lowBnd = 0;
|
||||||
int[] sols = PostProcess.createFitNormHistogram(outputPop, lowBnd, upBnd, 20);
|
int[] sols = PostProcess.createFitNormHistogram(outputPop, lowBnd, upBnd, 20);
|
||||||
// PostProcessInterim.outputResult((AbstractOptimizationProblem)goParams.getProblem(), outputPop, 0.01, System.out, 0, 2000, 20, goParams.getPostProcessSteps());
|
// PostProcessInterim.outputResult((AbstractOptimizationProblem)goParams.getProblem(), outputPop, 0.01, System.out, 0, 2000, 20, goParams.getPostProcessSteps());
|
||||||
listener.println("measures: " + BeanInspector.toString(outputPop.getPopulationMeasures()));
|
if (listener != null) listener.println("measures: " + BeanInspector.toString(outputPop.getPopulationMeasures()));
|
||||||
listener.println("solution histogram in [" + lowBnd + "," + upBnd + "]: " + BeanInspector.toString(sols));
|
if (listener != null) listener.println("solution histogram in [" + lowBnd + "," + upBnd + "]: " + BeanInspector.toString(sols));
|
||||||
|
|
||||||
//////////// multimodal data output?
|
//////////// multimodal data output?
|
||||||
if (problem instanceof InterfaceMultimodalProblemKnown) procMultiModalKnown(outputPop, (InterfaceMultimodalProblemKnown)problem, listener);
|
if (problem instanceof InterfaceMultimodalProblemKnown) procMultiModalKnown(outputPop, (InterfaceMultimodalProblemKnown)problem, listener);
|
||||||
|
|
||||||
|
Population resPop = outputPop.getBestNIndividuals(params.getPrintNBest()); // n individuals are returned and sorted, all of them if n<=0
|
||||||
|
if (listener != null) listener.println("Best after post process:" + ((outputPop.size()>resPop.size()) ? ( "(first " + resPop.size() + " of " + outputPop.size() + ")") : ""));
|
||||||
//////////// output some individual data
|
//////////// output some individual data
|
||||||
List<AbstractEAIndividual> bestList = outputPop.getBestNIndividuals(params.getPrintNBest()); // n individuals are returned and sorted, all of them if n<=0
|
if (listener != null) for (int i=0; i<resPop.size(); i++) {
|
||||||
listener.println("Best after post process:" + ((outputPop.size()>bestList.size()) ? ( "(first " + bestList.size() + " of " + outputPop.size() + ")") : ""));
|
listener.println(AbstractEAIndividual.getDefaultStringRepresentation(resPop.getEAIndividual(i)));
|
||||||
for (AbstractEAIndividual indy : bestList) {
|
|
||||||
listener.println(AbstractEAIndividual.getDefaultStringRepresentation(indy));
|
|
||||||
}
|
}
|
||||||
}
|
return resPop;
|
||||||
|
} else return solutions;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,9 +25,14 @@ public class PostProcessParams implements InterfacePostProcessParams, Serializab
|
|||||||
}
|
}
|
||||||
|
|
||||||
public PostProcessParams(int steps, double clusterSigma) {
|
public PostProcessParams(int steps, double clusterSigma) {
|
||||||
|
this(steps, clusterSigma, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PostProcessParams(int steps, double clusterSigma, int nBest) {
|
||||||
postProcessSteps = steps;
|
postProcessSteps = steps;
|
||||||
postProcess = true;
|
postProcess = true;
|
||||||
postProcessClusterSigma = clusterSigma;
|
postProcessClusterSigma = clusterSigma;
|
||||||
|
printNBest = nBest;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void hideHideable() {
|
public void hideHideable() {
|
||||||
@ -65,7 +70,7 @@ public class PostProcessParams implements InterfacePostProcessParams, Serializab
|
|||||||
this.postProcessClusterSigma = postProcessClusterSigma;
|
this.postProcessClusterSigma = postProcessClusterSigma;
|
||||||
}
|
}
|
||||||
public String postProcessClusterSigmaTipText() {
|
public String postProcessClusterSigmaTipText() {
|
||||||
return "Set the sigma parameter for clustering during post processing. Set to zero for no clustering.";
|
return "Set the sigma parameter for clustering during post processing; set to 0 for no clustering.";
|
||||||
}
|
}
|
||||||
|
|
||||||
public String postProcessStepsTipText() {
|
public String postProcessStepsTipText() {
|
||||||
@ -85,7 +90,7 @@ public class PostProcessParams implements InterfacePostProcessParams, Serializab
|
|||||||
printNBest = nBest;
|
printNBest = nBest;
|
||||||
}
|
}
|
||||||
public String printNBestTipText() {
|
public String printNBestTipText() {
|
||||||
return "Print as many solutions at max. Set to -1 to print all";
|
return "Print as many solutions at max; set to -1 to print all";
|
||||||
}
|
}
|
||||||
//////////////////////// GUI
|
//////////////////////// GUI
|
||||||
|
|
||||||
|
@ -1,11 +1,9 @@
|
|||||||
package javaeva.server.go.operators.terminators;
|
package javaeva.server.go.operators.terminators;
|
||||||
|
|
||||||
import java.beans.BeanInfo;
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
import javaeva.gui.BeanInspector;
|
|
||||||
import javaeva.server.go.PopulationInterface;
|
|
||||||
import javaeva.server.go.InterfaceTerminator;
|
import javaeva.server.go.InterfaceTerminator;
|
||||||
|
import javaeva.server.go.PopulationInterface;
|
||||||
import javaeva.tools.SelectedTag;
|
import javaeva.tools.SelectedTag;
|
||||||
|
|
||||||
public class CombinedTerminator implements InterfaceTerminator, Serializable {
|
public class CombinedTerminator implements InterfaceTerminator, Serializable {
|
||||||
|
@ -48,10 +48,10 @@ Serializable {
|
|||||||
pMetric = new PhenotypeMetric();
|
pMetric = new PhenotypeMetric();
|
||||||
}
|
}
|
||||||
|
|
||||||
public FitnessConvergenceTerminator(double thresh, int stagnTime, boolean bFitCallBased, boolean bAbsolute) {
|
public FitnessConvergenceTerminator(double thresh, int stagnPeriod, boolean bFitCallBased, boolean bAbsolute) {
|
||||||
pMetric = new PhenotypeMetric();
|
pMetric = new PhenotypeMetric();
|
||||||
convThresh = thresh;
|
convThresh = thresh;
|
||||||
this.m_stagTime = stagnTime;
|
this.m_stagTime = stagnPeriod;
|
||||||
if (bFitCallBased) stagnationMeasure.setSelectedTag("Fitness calls");
|
if (bFitCallBased) stagnationMeasure.setSelectedTag("Fitness calls");
|
||||||
else stagnationMeasure.setSelectedTag("Generations");
|
else stagnationMeasure.setSelectedTag("Generations");
|
||||||
if (bAbsolute) convergenceCondition.setSelectedTag("Absolute");
|
if (bAbsolute) convergenceCondition.setSelectedTag("Absolute");
|
||||||
|
@ -43,8 +43,8 @@ Serializable {
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public FitnessValueTerminator( double[] x) {
|
public FitnessValueTerminator( double[] v) {
|
||||||
m_FitnessValue = (double[])x.clone();
|
m_FitnessValue = (double[])v.clone();
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -26,7 +26,7 @@ import javaeva.server.go.InterfaceTerminator;
|
|||||||
public class GenerationTerminator implements InterfaceTerminator,
|
public class GenerationTerminator implements InterfaceTerminator,
|
||||||
Serializable {
|
Serializable {
|
||||||
/**
|
/**
|
||||||
* Number of fitnness calls on the problem which is optimized
|
* Number of fitness calls on the problem which is optimized
|
||||||
*/
|
*/
|
||||||
protected int m_Generations = 100;
|
protected int m_Generations = 100;
|
||||||
public void init(){}
|
public void init(){}
|
||||||
@ -41,6 +41,12 @@ public class GenerationTerminator implements InterfaceTerminator,
|
|||||||
*/
|
*/
|
||||||
public GenerationTerminator() {
|
public GenerationTerminator() {
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public GenerationTerminator(int gens) {
|
||||||
|
m_Generations = gens;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@ -19,7 +19,7 @@ public class PhenotypeConvergenceTerminator extends FitnessConvergenceTerminator
|
|||||||
super(thresh, stagnTime, bFitCallBased, bAbsolute);
|
super(thresh, stagnTime, bFitCallBased, bAbsolute);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Return true if |oldPhen - curPhen| < |oldPhen| * thresh% (relative case)
|
* Return true if |oldPhen - curPhen| < |oldPhen| * thresh (relative case)
|
||||||
* and if |oldFit - curFit| < thresh (absolute case).
|
* and if |oldFit - curFit| < thresh (absolute case).
|
||||||
*
|
*
|
||||||
* @param curFit
|
* @param curFit
|
||||||
|
@ -40,8 +40,15 @@ public class Population extends ArrayList implements PopulationInterface, Clonea
|
|||||||
public Population() {
|
public Population() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor setting initial capacity and population size to the given
|
||||||
|
* integer value.
|
||||||
|
*
|
||||||
|
* @param initialCapacity initial capacity and population size of the instance
|
||||||
|
*/
|
||||||
public Population(int initialCapacity) {
|
public Population(int initialCapacity) {
|
||||||
super(initialCapacity);
|
super(initialCapacity);
|
||||||
|
setPopulationSize(initialCapacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Population(Population population) {
|
public Population(Population population) {
|
||||||
@ -308,19 +315,20 @@ public class Population extends ArrayList implements PopulationInterface, Clonea
|
|||||||
* @return The m best individuals, where m <= n
|
* @return The m best individuals, where m <= n
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public List<AbstractEAIndividual> getBestNIndividuals(int n) {
|
public Population getBestNIndividuals(int n) {
|
||||||
LinkedList<AbstractEAIndividual> indList = new LinkedList<AbstractEAIndividual>();
|
if (n <= 0) n = super.size();
|
||||||
|
Population result = new Population(n);
|
||||||
PriorityQueue<AbstractEAIndividual> queue = new PriorityQueue<AbstractEAIndividual>(super.size(), new AbstractEAIndividualComparator());
|
PriorityQueue<AbstractEAIndividual> queue = new PriorityQueue<AbstractEAIndividual>(super.size(), new AbstractEAIndividualComparator());
|
||||||
|
|
||||||
for (int i = 0; i < super.size(); i++) {
|
for (int i = 0; i < super.size(); i++) {
|
||||||
queue.add(getEAIndividual(i));
|
queue.add(getEAIndividual(i));
|
||||||
}
|
}
|
||||||
if (n <= 0) n = queue.size();
|
|
||||||
for (int i = 0; i<n ; i++) {
|
for (int i = 0; i<n ; i++) {
|
||||||
if (queue.size() == 0) break;
|
if (queue.size() == 0) break;
|
||||||
indList.add(queue.poll());
|
result.add(queue.poll());
|
||||||
}
|
}
|
||||||
return indList;
|
result.setPopulationSize(result.size());
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method returns n random best individuals from the population.
|
/** This method returns n random best individuals from the population.
|
||||||
|
@ -0,0 +1,306 @@
|
|||||||
|
package javaeva.server.go.problems;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javaeva.server.go.PopulationInterface;
|
||||||
|
import javaeva.server.go.individuals.AbstractEAIndividual;
|
||||||
|
import javaeva.server.go.individuals.ESIndividualDoubleData;
|
||||||
|
import javaeva.server.go.individuals.InterfaceDataTypeDouble;
|
||||||
|
import javaeva.server.go.operators.distancemetric.InterfaceDistanceMetric;
|
||||||
|
import javaeva.server.go.operators.distancemetric.PhenotypeMetric;
|
||||||
|
import javaeva.server.go.operators.postprocess.PostProcess;
|
||||||
|
import javaeva.server.go.populations.Population;
|
||||||
|
|
||||||
|
public abstract class AbstractMultiModalProblemKnown extends AbstractProblemDouble implements Interface2DBorderProblem, InterfaceMultimodalProblemKnown {
|
||||||
|
protected static InterfaceDistanceMetric m_Metric = new PhenotypeMetric();
|
||||||
|
private double m_GlobalOpt = 0;
|
||||||
|
private Population m_Optima;
|
||||||
|
protected double m_Epsilon = 0.05;
|
||||||
|
// protected double[][] m_Range;
|
||||||
|
// protected double[] m_Extrema;
|
||||||
|
protected int m_ProblemDimension = 2;
|
||||||
|
// if the global optimum is zero and we want to see logarithmic plots, the offset must be a little lower. see addOptimum()
|
||||||
|
protected boolean makeGlobalOptUnreachable = false;
|
||||||
|
|
||||||
|
public AbstractMultiModalProblemKnown() {
|
||||||
|
this.m_ProblemDimension = 2;
|
||||||
|
this.m_Template = new ESIndividualDoubleData();
|
||||||
|
// this.m_Extrema = new double[2];
|
||||||
|
// this.m_Range = makeRange();
|
||||||
|
// this.m_Extrema[0] = -2;
|
||||||
|
// this.m_Extrema[1] = 6;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void cloneObjects(AbstractMultiModalProblemKnown b) {
|
||||||
|
super.cloneObjects(b);
|
||||||
|
if (b.m_Optima != null)
|
||||||
|
this.m_Optima = (Population)((Population)b.m_Optima).clone();
|
||||||
|
// if (b.m_Range != null) {
|
||||||
|
// this.m_Range = new double[b.m_Range.length][b.m_Range[0].length];
|
||||||
|
// for (int i = 0; i < this.m_Range.length; i++) {
|
||||||
|
// for (int j = 0; j < this.m_Range[i].length; j++) {
|
||||||
|
// this.m_Range[i][j] = b.m_Range[i][j];
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
this.m_ProblemDimension = b.m_ProblemDimension;
|
||||||
|
this.m_GlobalOpt = b.m_GlobalOpt;
|
||||||
|
this.m_Epsilon = b.m_Epsilon;
|
||||||
|
// if (b.m_Extrema != null) {
|
||||||
|
// this.m_Extrema = new double[b.m_Extrema.length];
|
||||||
|
// for (int i = 0; i < this.m_Extrema.length; i++) {
|
||||||
|
// this.m_Extrema[i] = b.m_Extrema[i];
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
public AbstractMultiModalProblemKnown(AbstractMultiModalProblemKnown b) {
|
||||||
|
cloneObjects(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
// /** This method returns a deep clone of the problem.
|
||||||
|
// * @return the clone
|
||||||
|
// */
|
||||||
|
// public Object clone() {
|
||||||
|
// return (Object) new AbstractMultiModalProblem(this);
|
||||||
|
// }
|
||||||
|
|
||||||
|
/** This method inits a given population
|
||||||
|
* @param population The populations that is to be inited
|
||||||
|
*/
|
||||||
|
public void initPopulation(Population population) {
|
||||||
|
AbstractEAIndividual tmpIndy;
|
||||||
|
|
||||||
|
population.clear();
|
||||||
|
|
||||||
|
// this.m_ProblemDimension = 2;
|
||||||
|
((InterfaceDataTypeDouble)this.m_Template).setDoubleDataLength(this.m_ProblemDimension);
|
||||||
|
((InterfaceDataTypeDouble)this.m_Template).SetDoubleRange(makeRange());
|
||||||
|
for (int i = 0; i < population.getPopulationSize(); i++) {
|
||||||
|
tmpIndy = (AbstractEAIndividual)((AbstractEAIndividual)this.m_Template).clone();
|
||||||
|
tmpIndy.init(this);
|
||||||
|
population.add(tmpIndy);
|
||||||
|
}
|
||||||
|
// population init must be last
|
||||||
|
// it set's fitcalls and generation to zero
|
||||||
|
population.init();
|
||||||
|
this.m_GlobalOpt = Double.NEGATIVE_INFINITY;
|
||||||
|
m_Optima = new Population();
|
||||||
|
this.initListOfOptima();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initProblem() {
|
||||||
|
super.initProblem();
|
||||||
|
this.m_GlobalOpt = Double.NEGATIVE_INFINITY;
|
||||||
|
m_Optima = new Population();
|
||||||
|
this.initListOfOptima();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Ths method allows you to evaluate a simple bit string to determine the fitness
|
||||||
|
* @param x The n-dimensional input vector
|
||||||
|
* @return The m-dimensional output vector.
|
||||||
|
*/
|
||||||
|
public double[] eval(double[] x) {
|
||||||
|
double[] result = new double[1];
|
||||||
|
result[0] = this.m_GlobalOpt - evalUnnormalized(x)[0];
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method returns the unnormalized function value for an maximization problem
|
||||||
|
* @param x The n-dimensional input vector
|
||||||
|
* @return The m-dimensional output vector.
|
||||||
|
*/
|
||||||
|
public abstract double[] evalUnnormalized(double[] x);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method returns the header for the additional data that is to be written into a file
|
||||||
|
* @param pop The population that is to be refined.
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
public String getAdditionalFileStringHeader(PopulationInterface pop) {
|
||||||
|
return "Solution \t Number of Optima found \t Maximum Peak Ratio";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method returns the additional data that is to be written into a file
|
||||||
|
* @param pop The population that is to be refined.
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
public String getAdditionalFileStringValue(PopulationInterface pop) {
|
||||||
|
String result = "";
|
||||||
|
result += AbstractEAIndividual.getDefaultDataString(pop.getBestIndividual()) +"\t";
|
||||||
|
result += this.getNumberOfFoundOptima((Population)pop)+"\t";
|
||||||
|
result += this.getMaximumPeakRatio((Population)pop);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// /** This method returns a string describing the optimization problem.
|
||||||
|
// * @return The description.
|
||||||
|
// */
|
||||||
|
// public String getStringRepresentation() {
|
||||||
|
// String result = "";
|
||||||
|
//
|
||||||
|
// result += "M0 function:\n";
|
||||||
|
// result += "This problem has one global and one local optimum.\n";
|
||||||
|
// result += "Parameters:\n";
|
||||||
|
// result += "Dimension : " + this.m_ProblemDimension +"\n";
|
||||||
|
// result += "Noise level : " + this.getNoise() + "\n";
|
||||||
|
// result += "Solution representation:\n";
|
||||||
|
// //result += this.m_Template.getSolutionRepresentationFor();
|
||||||
|
// return result;
|
||||||
|
// }
|
||||||
|
|
||||||
|
/**********************************************************************************************************************
|
||||||
|
* Implementation of InterfaceMultimodalProblemKnown
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** This method allows you to add a 2d optima to the list of optima
|
||||||
|
* @param x
|
||||||
|
* @param y
|
||||||
|
*/
|
||||||
|
protected void add2DOptimum(double x, double y) {
|
||||||
|
double[] point = new double[2];
|
||||||
|
point[0] = x;
|
||||||
|
point[1] = y;
|
||||||
|
addOptimum(point);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** This method allows you to add a 2d optima to the list of optima
|
||||||
|
* @param x
|
||||||
|
* @param y
|
||||||
|
*/
|
||||||
|
protected void addOptimum(double[] point) {
|
||||||
|
InterfaceDataTypeDouble tmpIndy;
|
||||||
|
tmpIndy = (InterfaceDataTypeDouble)((AbstractEAIndividual)this.m_Template).clone();
|
||||||
|
tmpIndy.SetDoubleDataLamarkian(point);
|
||||||
|
((AbstractEAIndividual)tmpIndy).SetFitness(evalUnnormalized(point));
|
||||||
|
if (((AbstractEAIndividual)tmpIndy).getFitness(0)>=m_GlobalOpt) {
|
||||||
|
m_GlobalOpt = ((AbstractEAIndividual)tmpIndy).getFitness(0);
|
||||||
|
if (makeGlobalOptUnreachable) {
|
||||||
|
double tmp=m_GlobalOpt;
|
||||||
|
double dx = 1e-30;
|
||||||
|
while (tmp==m_GlobalOpt) {
|
||||||
|
// this increases the optimum until there is a real difference.
|
||||||
|
// tries to avoid zero y-values which break the logarithmic plot
|
||||||
|
tmp+=dx;
|
||||||
|
dx *= 10;
|
||||||
|
}
|
||||||
|
m_GlobalOpt = tmp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.m_Optima.add(tmpIndy);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method will prepare the problem to return a list of all optima
|
||||||
|
* if possible and to return quality measures like NumberOfOptimaFound and
|
||||||
|
* the MaximumPeakRatio. When implementing, use the addOptimum(double[])
|
||||||
|
* method for every optimum, as it keeps track the global optimum.
|
||||||
|
* This method will be called on initialization.
|
||||||
|
*/
|
||||||
|
public abstract void initListOfOptima();
|
||||||
|
|
||||||
|
/** This method returns a list of all optima as population
|
||||||
|
* @return population
|
||||||
|
*/
|
||||||
|
public Population getRealOptima() {
|
||||||
|
return this.m_Optima;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** This method returns the Number of Identified optima
|
||||||
|
* @param pop A population of possible solutions.
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public int getNumberOfFoundOptima(Population pop) {
|
||||||
|
List<AbstractEAIndividual> sols = PostProcess.getFoundOptima(pop, m_Optima, m_Epsilon, true);
|
||||||
|
return sols.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method returns the maximum peak ratio, which is the ratio of found fitness values corresponding to
|
||||||
|
* known optima with the internal epsilon criterion and the sum of all fitness values seen as maximization.
|
||||||
|
* Thus, if all optima are perfectly found, 1 is returned. If no optimum is found, zero is returned.
|
||||||
|
* A return value of 0.5 may mean, e.g., that half of n similar optima have been found perfectly, or that 1 major
|
||||||
|
* optimum of equal weight than all the others has been found perfectly, or that all optima have been found
|
||||||
|
* with about 50% accuracy, etc.
|
||||||
|
*
|
||||||
|
* @param pop A population of possible solutions.
|
||||||
|
* @return double
|
||||||
|
*/
|
||||||
|
public double getMaximumPeakRatio(Population pop) {
|
||||||
|
double optimaInvertedSum = 0, foundInvertedSum = 0;
|
||||||
|
AbstractEAIndividual[] optsFound = PostProcess.getFoundOptimaArray(pop, m_Optima, m_Epsilon, true);
|
||||||
|
|
||||||
|
for (int i=0; i<m_Optima.size(); i++) {
|
||||||
|
// sum up known optimal fitness values
|
||||||
|
optimaInvertedSum += m_Optima.getEAIndividual(i).getFitness(0);
|
||||||
|
// sum up best found hits, with inverted fitness
|
||||||
|
if (optsFound[i] != null) foundInvertedSum += m_GlobalOpt - optsFound[i].getFitness(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return foundInvertedSum/optimaInvertedSum;
|
||||||
|
}
|
||||||
|
|
||||||
|
// public double getMaximumPeakRatio(Population pop) {
|
||||||
|
// double result = 0, sum = 0;
|
||||||
|
// AbstractEAIndividual posOpt, opt;
|
||||||
|
// boolean[] found = new boolean[this.m_Optima.size()];
|
||||||
|
// for (int i = 0; i < found.length; i++) {
|
||||||
|
// found[i] = false;
|
||||||
|
// sum += ((AbstractEAIndividual)this.m_Optima.get(i)).getFitness(0) ;
|
||||||
|
// //System.out.println("Optimum " + i + ".: " + (((AbstractEAIndividual)this.m_Optima.get(i)).getFitness(0)));
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// for (int i = 0; i < pop.size(); i++) {
|
||||||
|
// posOpt = (AbstractEAIndividual) pop.get(i);
|
||||||
|
// for (int j = 0; j < this.m_Optima.size(); j++) {
|
||||||
|
// if (!found[j]) {
|
||||||
|
// opt = (AbstractEAIndividual) this.m_Optima.get(j);
|
||||||
|
// if (this.m_Metric.distance(posOpt, opt) < this.m_Epsilon) {
|
||||||
|
// found[j] = true;
|
||||||
|
// result += this.m_GlobalOpt - posOpt.getFitness(0);
|
||||||
|
// //System.out.println("Found Optimum " + j + ".: " + (this.m_GlobalOpt - posOpt.getFitness(0)));
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// return result/sum;
|
||||||
|
// }
|
||||||
|
/**********************************************************************************************************************
|
||||||
|
* These are for GUI
|
||||||
|
*/
|
||||||
|
|
||||||
|
// /** This method returns this min and may fitness occuring
|
||||||
|
// * @return double[]
|
||||||
|
// */
|
||||||
|
// public double[] getExtrema() {
|
||||||
|
// double[] range = new double[2];
|
||||||
|
// range[0] = -5;
|
||||||
|
// range[1] = 5;
|
||||||
|
// return range;
|
||||||
|
// }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the m_Epsilon
|
||||||
|
*/
|
||||||
|
public double getEpsilon() {
|
||||||
|
return m_Epsilon;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param epsilon the m_Epsilon to set
|
||||||
|
*/
|
||||||
|
public void setEpsilon(double epsilon) {
|
||||||
|
m_Epsilon = epsilon;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String epsilonTipText() {
|
||||||
|
return "Epsilon criterion indicating whether an optimum was found";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getProblemDimension() {
|
||||||
|
return m_ProblemDimension;
|
||||||
|
}
|
||||||
|
}
|
@ -178,6 +178,18 @@ public abstract class AbstractOptimizationProblem implements InterfaceOptimizati
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This allows "anyone" to access the problem template and set operators etc.
|
||||||
|
* Subclasses may have a method getEAIndividual additionally with a more
|
||||||
|
* specific interface signature, which makes sense for the GUI which decides
|
||||||
|
* on what classes to present to the user based on the interface signature.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public AbstractEAIndividual getIndividualTemplate() {
|
||||||
|
return m_Template;
|
||||||
|
}
|
||||||
|
|
||||||
/**********************************************************************************************************************
|
/**********************************************************************************************************************
|
||||||
* These are for GUI
|
* These are for GUI
|
||||||
*/
|
*/
|
||||||
|
@ -19,16 +19,8 @@ public abstract class AbstractProblemBinary extends AbstractOptimizationProblem
|
|||||||
((InterfaceDataTypeBinary)this.m_Template).setBinaryDataLength(this.getProblemDimension());
|
((InterfaceDataTypeBinary)this.m_Template).setBinaryDataLength(this.getProblemDimension());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void cloneObjects(AbstractProblemBinary o) {
|
||||||
public Object clone() {
|
if (o.m_Template != null) m_Template = (AbstractEAIndividual)o.m_Template.clone();
|
||||||
try {
|
|
||||||
AbstractProblemBinary prob = this.getClass().newInstance();
|
|
||||||
prob.m_Template = (AbstractEAIndividual)m_Template.clone();
|
|
||||||
return prob;
|
|
||||||
} catch(Exception e) {
|
|
||||||
System.err.println("Error: couldnt instantiate "+this.getClass().getName());
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -44,12 +36,19 @@ public abstract class AbstractProblemBinary extends AbstractOptimizationProblem
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Evaluate a double vector
|
* Evaluate a BitSet representing a possible solution. This is the target
|
||||||
* @param x
|
* function implementation.
|
||||||
|
*
|
||||||
|
* @param x a BitSet representing a possible
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public abstract double[] eval(BitSet bs);
|
public abstract double[] eval(BitSet bs);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the problem dimension.
|
||||||
|
*
|
||||||
|
* @return the problem dimension
|
||||||
|
*/
|
||||||
public abstract int getProblemDimension();
|
public abstract int getProblemDimension();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -82,7 +81,7 @@ public abstract class AbstractProblemBinary extends AbstractOptimizationProblem
|
|||||||
* @return The name.
|
* @return The name.
|
||||||
*/
|
*/
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "SimpleProblemBinary";
|
return "AbstractProblemBinary";
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method returns a global info string
|
/** This method returns a global info string
|
||||||
|
@ -7,34 +7,38 @@ import javaeva.server.go.populations.Population;
|
|||||||
import javaeva.server.go.strategies.InterfaceOptimizer;
|
import javaeva.server.go.strategies.InterfaceOptimizer;
|
||||||
import javaeva.server.go.tools.RandomNumberGenerator;
|
import javaeva.server.go.tools.RandomNumberGenerator;
|
||||||
|
|
||||||
public abstract class AbstractProblemDouble extends AbstractOptimizationProblem {
|
public abstract class AbstractProblemDouble extends AbstractOptimizationProblem implements Interface2DBorderProblem {
|
||||||
protected double m_DefaultRange = 10;
|
private double m_DefaultRange = 10;
|
||||||
protected double m_Noise = 0;
|
private double m_Noise = 0;
|
||||||
|
|
||||||
public AbstractProblemDouble() {
|
public AbstractProblemDouble() {
|
||||||
initTemplate();
|
initTemplate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// public AbstractProblemDouble(AbstractProblemDouble o) {
|
||||||
|
// cloneObjects(o);
|
||||||
|
// }
|
||||||
|
|
||||||
protected void initTemplate() {
|
protected void initTemplate() {
|
||||||
this.m_Template = new ESIndividualDoubleData();
|
this.m_Template = new ESIndividualDoubleData();
|
||||||
((ESIndividualDoubleData)this.m_Template).setDoubleDataLength(getProblemDimension());
|
if (getProblemDimension() > 0) { // avoid evil case setting dim to 0 during object init
|
||||||
((ESIndividualDoubleData)this.m_Template).SetDoubleRange(makeRange());
|
((ESIndividualDoubleData)this.m_Template).setDoubleDataLength(getProblemDimension());
|
||||||
}
|
((ESIndividualDoubleData)this.m_Template).SetDoubleRange(makeRange());
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object clone() {
|
|
||||||
try {
|
|
||||||
AbstractProblemDouble prob = this.getClass().newInstance();
|
|
||||||
prob.m_DefaultRange = m_DefaultRange;
|
|
||||||
prob.m_Noise = m_Noise;
|
|
||||||
prob.m_Template = (AbstractEAIndividual)m_Template.clone();
|
|
||||||
return prob;
|
|
||||||
} catch(Exception e) {
|
|
||||||
System.err.println("Error: couldnt instantiate "+this.getClass().getName());
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void cloneObjects(AbstractProblemDouble o) {
|
||||||
|
this.m_DefaultRange = o.m_DefaultRange;
|
||||||
|
this.m_Noise = o.m_Noise;
|
||||||
|
if (o.m_Template != null) this.m_Template = (AbstractEAIndividual)o.m_Template.clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve and copy the double solution representation from an individual.
|
||||||
|
*
|
||||||
|
* @param individual
|
||||||
|
* @return the double solution representation
|
||||||
|
*/
|
||||||
protected double[] getEvalArray(AbstractEAIndividual individual){
|
protected double[] getEvalArray(AbstractEAIndividual individual){
|
||||||
double[] x = new double[((InterfaceDataTypeDouble) individual).getDoubleData().length];
|
double[] x = new double[((InterfaceDataTypeDouble) individual).getDoubleData().length];
|
||||||
System.arraycopy(((InterfaceDataTypeDouble) individual).getDoubleData(), 0, x, 0, x.length);
|
System.arraycopy(((InterfaceDataTypeDouble) individual).getDoubleData(), 0, x, 0, x.length);
|
||||||
@ -55,17 +59,30 @@ public abstract class AbstractProblemDouble extends AbstractOptimizationProblem
|
|||||||
setEvalFitness(individual, x, fitness);
|
setEvalFitness(individual, x, fitness);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write a fitness value back to an individual. May be overridden to add constraints.
|
||||||
|
*
|
||||||
|
* @param individual
|
||||||
|
* @param x
|
||||||
|
* @param fit
|
||||||
|
*/
|
||||||
protected void setEvalFitness(AbstractEAIndividual individual, double[] x, double[] fit) {
|
protected void setEvalFitness(AbstractEAIndividual individual, double[] x, double[] fit) {
|
||||||
individual.SetFitness(fit);
|
individual.SetFitness(fit);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Evaluate a double vector
|
* Evaluate a double vector, representing the target function.
|
||||||
* @param x
|
*
|
||||||
* @return
|
* @param x the vector to evaluate
|
||||||
|
* @return the target function value
|
||||||
*/
|
*/
|
||||||
public abstract double[] eval(double[] x);
|
public abstract double[] eval(double[] x);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the problem dimension.
|
||||||
|
*
|
||||||
|
* @return the problem dimension
|
||||||
|
*/
|
||||||
public abstract int getProblemDimension();
|
public abstract int getProblemDimension();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -84,6 +101,11 @@ public abstract class AbstractProblemDouble extends AbstractOptimizationProblem
|
|||||||
population.init();
|
population.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new range array by using the getRangeLowerBound and getRangeUpperBound methods.
|
||||||
|
*
|
||||||
|
* @return a range array
|
||||||
|
*/
|
||||||
protected double[][] makeRange() {
|
protected double[][] makeRange() {
|
||||||
double[][] range = new double[this.getProblemDimension()][2];
|
double[][] range = new double[this.getProblemDimension()][2];
|
||||||
for (int i = 0; i < range.length; i++) {
|
for (int i = 0; i < range.length; i++) {
|
||||||
@ -93,10 +115,28 @@ public abstract class AbstractProblemDouble extends AbstractOptimizationProblem
|
|||||||
return range;
|
return range;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the lower bound of the double range in the given dimension. Override
|
||||||
|
* this to implement non-symmetric ranges. User setDefaultRange for symmetric ranges.
|
||||||
|
*
|
||||||
|
* @see makeRange()
|
||||||
|
* @see getRangeUpperBound(int dim)
|
||||||
|
* @param dim
|
||||||
|
* @return the lower bound of the double range in the given dimension
|
||||||
|
*/
|
||||||
protected double getRangeLowerBound(int dim) {
|
protected double getRangeLowerBound(int dim) {
|
||||||
return -m_DefaultRange;
|
return -m_DefaultRange;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the upper bound of the double range in the given dimension. Override
|
||||||
|
* this to implement non-symmetric ranges. User setDefaultRange for symmetric ranges.
|
||||||
|
*
|
||||||
|
* @see makeRange()
|
||||||
|
* @see getRangeLowerBound(int dim)
|
||||||
|
* @param dim
|
||||||
|
* @return the upper bound of the double range in the given dimension
|
||||||
|
*/
|
||||||
protected double getRangeUpperBound(int dim) {
|
protected double getRangeUpperBound(int dim) {
|
||||||
return m_DefaultRange;
|
return m_DefaultRange;
|
||||||
}
|
}
|
||||||
@ -106,7 +146,8 @@ public abstract class AbstractProblemDouble extends AbstractOptimizationProblem
|
|||||||
initTemplate();
|
initTemplate();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method allows you to choose how much noise is to be added to the
|
/**
|
||||||
|
* This method allows you to choose how much noise is to be added to the
|
||||||
* fitness. This can be used to make the optimization problem more difficult.
|
* fitness. This can be used to make the optimization problem more difficult.
|
||||||
* @param noise The sigma for a gaussian random number.
|
* @param noise The sigma for a gaussian random number.
|
||||||
*/
|
*/
|
||||||
@ -114,6 +155,10 @@ public abstract class AbstractProblemDouble extends AbstractOptimizationProblem
|
|||||||
if (noise < 0) noise = 0;
|
if (noise < 0) noise = 0;
|
||||||
this.m_Noise = noise;
|
this.m_Noise = noise;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Get the current noise level.
|
||||||
|
* @return the current noise level
|
||||||
|
*/
|
||||||
public double getNoise() {
|
public double getNoise() {
|
||||||
return this.m_Noise;
|
return this.m_Noise;
|
||||||
}
|
}
|
||||||
@ -121,13 +166,20 @@ public abstract class AbstractProblemDouble extends AbstractOptimizationProblem
|
|||||||
return "Gaussian noise level on the fitness value.";
|
return "Gaussian noise level on the fitness value.";
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method allows you to choose the EA individual
|
/**
|
||||||
|
* This method allows you to choose the EA individual used by the problem.
|
||||||
|
*
|
||||||
* @param indy The EAIndividual type
|
* @param indy The EAIndividual type
|
||||||
*/
|
*/
|
||||||
public void setEAIndividual(InterfaceDataTypeDouble indy) {
|
public void setEAIndividual(InterfaceDataTypeDouble indy) {
|
||||||
this.m_Template = (AbstractEAIndividual)indy;
|
this.m_Template = (AbstractEAIndividual)indy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the EA individual template currently used by the problem.
|
||||||
|
*
|
||||||
|
* @return the EA individual template currently used
|
||||||
|
*/
|
||||||
public InterfaceDataTypeDouble getEAIndividual() {
|
public InterfaceDataTypeDouble getEAIndividual() {
|
||||||
return (InterfaceDataTypeDouble)this.m_Template;
|
return (InterfaceDataTypeDouble)this.m_Template;
|
||||||
}
|
}
|
||||||
@ -160,18 +212,36 @@ public abstract class AbstractProblemDouble extends AbstractOptimizationProblem
|
|||||||
return "Absolute limit for the symmetric range in any dimension";
|
return "Absolute limit for the symmetric range in any dimension";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**********************************************************************************************************************
|
||||||
|
* These are for Interface2DBorderProblem
|
||||||
|
*/
|
||||||
|
public double[][] get2DBorder() {
|
||||||
|
return makeRange();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public double functionValue(double[] point) {
|
||||||
|
double x[] = new double[getProblemDimension()];
|
||||||
|
for (int i=0; i<point.length; i++) x[i]=point[i];
|
||||||
|
for (int i=point.length; i<x.length; i++) x[i] = 0;
|
||||||
|
return Math.sqrt(eval(x)[0]);
|
||||||
|
}
|
||||||
/**********************************************************************************************************************
|
/**********************************************************************************************************************
|
||||||
* These are for GUI
|
* These are for GUI
|
||||||
*/
|
*/
|
||||||
/** This method allows the CommonJavaObjectEditorPanel to read the
|
|
||||||
|
/**
|
||||||
|
* This method allows the GUI to read the
|
||||||
* name to the current object.
|
* name to the current object.
|
||||||
* @return The name.
|
* @return the name of the object
|
||||||
*/
|
*/
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "SimpleProblemDouble";
|
return "AbstractProblemDouble";
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method returns a global info string
|
/**
|
||||||
|
* This method returns a global info string.
|
||||||
* @return description
|
* @return description
|
||||||
*/
|
*/
|
||||||
public String globalInfo() {
|
public String globalInfo() {
|
||||||
|
@ -23,10 +23,8 @@ public class B1Problem extends AbstractProblemBinary implements java.io.Serializ
|
|||||||
}
|
}
|
||||||
|
|
||||||
public B1Problem(B1Problem b) {
|
public B1Problem(B1Problem b) {
|
||||||
//AbstractOptimizationProblem
|
super.cloneObjects(b);
|
||||||
if (b.m_Template != null)
|
|
||||||
this.m_Template = (AbstractEAIndividual)((AbstractEAIndividual)b.m_Template).clone();
|
|
||||||
//AbstractBinaryOptimizationProblem
|
|
||||||
this.m_ProblemDimension = b.m_ProblemDimension;
|
this.m_ProblemDimension = b.m_ProblemDimension;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ public class F10Problem extends F1Problem implements InterfaceMultimodalProblem,
|
|||||||
result += "F10 Weierstrass-Mandelbrot Fractal Function:\n";
|
result += "F10 Weierstrass-Mandelbrot Fractal Function:\n";
|
||||||
result += "Parameters:\n";
|
result += "Parameters:\n";
|
||||||
result += "Dimension : " + this.m_ProblemDimension +"\n";
|
result += "Dimension : " + this.m_ProblemDimension +"\n";
|
||||||
result += "Noise level : " + this.m_Noise + "\n";
|
result += "Noise level : " + this.getNoise() + "\n";
|
||||||
result += "Solution representation:\n";
|
result += "Solution representation:\n";
|
||||||
//result += this.m_Template.getSolutionRepresentationFor();
|
//result += this.m_Template.getSolutionRepresentationFor();
|
||||||
return result;
|
return result;
|
||||||
|
@ -19,7 +19,7 @@ public class F11Problem extends F1Problem implements InterfaceMultimodalProblem,
|
|||||||
public F11Problem() {
|
public F11Problem() {
|
||||||
this.m_ProblemDimension = 10;
|
this.m_ProblemDimension = 10;
|
||||||
this.m_Template = new ESIndividualDoubleData();
|
this.m_Template = new ESIndividualDoubleData();
|
||||||
this.m_DefaultRange = 600;
|
setDefaultRange(600);
|
||||||
}
|
}
|
||||||
|
|
||||||
public F11Problem(F11Problem b) {
|
public F11Problem(F11Problem b) {
|
||||||
@ -46,7 +46,7 @@ public class F11Problem extends F1Problem implements InterfaceMultimodalProblem,
|
|||||||
result[0] += Math.pow(x[i], 2);
|
result[0] += Math.pow(x[i], 2);
|
||||||
tmpProd *= Math.cos((x[i])/Math.sqrt(i+1));
|
tmpProd *= Math.cos((x[i])/Math.sqrt(i+1));
|
||||||
}
|
}
|
||||||
result[0] = ((1./this.m_D) * result[0] - tmpProd + 1);
|
result[0] = ((result[0]/this.m_D) - tmpProd + 1);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,7 +59,7 @@ public class F11Problem extends F1Problem implements InterfaceMultimodalProblem,
|
|||||||
result += "F11 Griewank Function:\n";
|
result += "F11 Griewank Function:\n";
|
||||||
result += "Parameters:\n";
|
result += "Parameters:\n";
|
||||||
result += "Dimension : " + this.m_ProblemDimension +"\n";
|
result += "Dimension : " + this.m_ProblemDimension +"\n";
|
||||||
result += "Noise level : " + this.m_Noise + "\n";
|
result += "Noise level : " + this.getNoise() + "\n";
|
||||||
// result += "Solution representation:\n";
|
// result += "Solution representation:\n";
|
||||||
//result += this.m_Template.getSolutionRepresentationFor();
|
//result += this.m_Template.getSolutionRepresentationFor();
|
||||||
return result;
|
return result;
|
||||||
|
@ -80,7 +80,7 @@ public class F12Problem extends F1Problem implements java.io.Serializable {
|
|||||||
result += "F12 Galar:\n";
|
result += "F12 Galar:\n";
|
||||||
result += "Parameters:\n";
|
result += "Parameters:\n";
|
||||||
result += "Dimension : " + this.m_ProblemDimension +"\n";
|
result += "Dimension : " + this.m_ProblemDimension +"\n";
|
||||||
result += "Noise level : " + this.m_Noise + "\n";
|
result += "Noise level : " + this.getNoise() + "\n";
|
||||||
result += "Solution representation:\n";
|
result += "Solution representation:\n";
|
||||||
//result += this.m_Template.getSolutionRepresentationFor();
|
//result += this.m_Template.getSolutionRepresentationFor();
|
||||||
return result;
|
return result;
|
||||||
|
@ -58,7 +58,7 @@ public class F13Problem extends F1Problem implements InterfaceMultimodalProblem
|
|||||||
result += "F13 Schwefel:\n";
|
result += "F13 Schwefel:\n";
|
||||||
result += "Parameters:\n";
|
result += "Parameters:\n";
|
||||||
result += "Dimension : " + this.m_ProblemDimension +"\n";
|
result += "Dimension : " + this.m_ProblemDimension +"\n";
|
||||||
result += "Noise level : " + this.m_Noise + "\n";
|
result += "Noise level : " + this.getNoise() + "\n";
|
||||||
result += "Solution representation:\n";
|
result += "Solution representation:\n";
|
||||||
//result += this.m_Template.getSolutionRepresentationFor();
|
//result += this.m_Template.getSolutionRepresentationFor();
|
||||||
return result;
|
return result;
|
||||||
|
@ -26,21 +26,16 @@ public class F1Problem extends AbstractProblemDouble implements Interface2DBorde
|
|||||||
|
|
||||||
public F1Problem() {
|
public F1Problem() {
|
||||||
super();
|
super();
|
||||||
|
setDefaultRange(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
public F1Problem(F1Problem b) {
|
public F1Problem(F1Problem b) {
|
||||||
//AbstractOptimizationProblem
|
super();
|
||||||
if (b.m_Template != null)
|
super.cloneObjects(b);
|
||||||
this.m_Template = (AbstractEAIndividual)((AbstractEAIndividual)b.m_Template).clone();
|
this.m_ProblemDimension = b.m_ProblemDimension;
|
||||||
//F1Problem
|
this.m_XOffSet = b.m_XOffSet;
|
||||||
// if (b.m_OverallBest != null)
|
this.m_YOffSet = b.m_YOffSet;
|
||||||
// this.m_OverallBest = (AbstractEAIndividual)((AbstractEAIndividual)b.m_OverallBest).clone();
|
this.m_UseTestConstraint = b.m_UseTestConstraint;
|
||||||
this.m_ProblemDimension = b.m_ProblemDimension;
|
|
||||||
this.m_Noise = b.m_Noise;
|
|
||||||
this.m_DefaultRange = b.m_DefaultRange;
|
|
||||||
this.m_XOffSet = b.m_XOffSet;
|
|
||||||
this.m_YOffSet = b.m_YOffSet;
|
|
||||||
this.m_UseTestConstraint = b.m_UseTestConstraint;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method returns a deep clone of the problem.
|
/** This method returns a deep clone of the problem.
|
||||||
@ -105,7 +100,7 @@ public class F1Problem extends AbstractProblemDouble implements Interface2DBorde
|
|||||||
sb.append("Dimension : ");
|
sb.append("Dimension : ");
|
||||||
sb.append(this.m_ProblemDimension);
|
sb.append(this.m_ProblemDimension);
|
||||||
sb.append("\nNoise level : ");
|
sb.append("\nNoise level : ");
|
||||||
sb.append(this.m_Noise);
|
sb.append(this.getNoise());
|
||||||
// sb.append("\nSolution representation:\n");
|
// sb.append("\nSolution representation:\n");
|
||||||
// sb.append(this.m_Template.getSolutionRepresentationFor());
|
// sb.append(this.m_Template.getSolutionRepresentationFor());
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
@ -179,15 +174,4 @@ public class F1Problem extends AbstractProblemDouble implements Interface2DBorde
|
|||||||
public String useTestConstraintTipText() {
|
public String useTestConstraintTipText() {
|
||||||
return "Just a simple test constraint of x[0] >= 1.";
|
return "Just a simple test constraint of x[0] >= 1.";
|
||||||
}
|
}
|
||||||
|
|
||||||
public double functionValue(double[] point) {
|
|
||||||
double x[] = new double[m_ProblemDimension];
|
|
||||||
for (int i=0; i<point.length; i++) x[i]=point[i];
|
|
||||||
for (int i=point.length; i<m_ProblemDimension; i++) x[i] = 0;
|
|
||||||
return Math.sqrt(eval(x)[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public double[][] get2DBorder() {
|
|
||||||
return ((InterfaceDataTypeDouble)this.m_Template).getDoubleRange();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ public class F2Problem extends F1Problem implements InterfaceMultimodalProblem,
|
|||||||
result += "This problem has a deceptive optimum at (0,0,..), the true optimum is at (1,1,1,..).\n";
|
result += "This problem has a deceptive optimum at (0,0,..), the true optimum is at (1,1,1,..).\n";
|
||||||
result += "Parameters:\n";
|
result += "Parameters:\n";
|
||||||
result += "Dimension : " + this.m_ProblemDimension +"\n";
|
result += "Dimension : " + this.m_ProblemDimension +"\n";
|
||||||
result += "Noise level : " + this.m_Noise + "\n";
|
result += "Noise level : " + this.getNoise() + "\n";
|
||||||
result += "Solution representation:\n";
|
result += "Solution representation:\n";
|
||||||
//result += this.m_Template.getSolutionRepresentationFor();
|
//result += this.m_Template.getSolutionRepresentationFor();
|
||||||
return result;
|
return result;
|
||||||
|
@ -49,7 +49,7 @@ public class F3Problem extends F1Problem implements java.io.Serializable {
|
|||||||
result += "This problem is discontinuos.\n";
|
result += "This problem is discontinuos.\n";
|
||||||
result += "Parameters:\n";
|
result += "Parameters:\n";
|
||||||
result += "Dimension : " + this.m_ProblemDimension +"\n";
|
result += "Dimension : " + this.m_ProblemDimension +"\n";
|
||||||
result += "Noise level : " + this.m_Noise + "\n";
|
result += "Noise level : " + this.getNoise() + "\n";
|
||||||
result += "Solution representation:\n";
|
result += "Solution representation:\n";
|
||||||
//result += this.m_Template.getSolutionRepresentationFor();
|
//result += this.m_Template.getSolutionRepresentationFor();
|
||||||
return result;
|
return result;
|
||||||
|
@ -80,7 +80,7 @@ public class F4Problem extends F1Problem implements java.io.Serializable {
|
|||||||
result += "This problem is noisey.\n";
|
result += "This problem is noisey.\n";
|
||||||
result += "Parameters:\n";
|
result += "Parameters:\n";
|
||||||
result += "Dimension : " + this.m_ProblemDimension +"\n";
|
result += "Dimension : " + this.m_ProblemDimension +"\n";
|
||||||
result += "Noise level : " + this.m_Noise + "\n";
|
result += "Noise level : " + this.getNoise() + "\n";
|
||||||
result += "Solution representation:\n";
|
result += "Solution representation:\n";
|
||||||
//result += this.m_Template.getSolutionRepresentationFor();
|
//result += this.m_Template.getSolutionRepresentationFor();
|
||||||
return result;
|
return result;
|
||||||
|
@ -85,7 +85,7 @@ public class F5Problem extends F1Problem implements java.io.Serializable {
|
|||||||
result += "This problem is unimodal.\n";
|
result += "This problem is unimodal.\n";
|
||||||
result += "Parameters:\n";
|
result += "Parameters:\n";
|
||||||
result += "Dimension : " + this.m_ProblemDimension +"\n";
|
result += "Dimension : " + this.m_ProblemDimension +"\n";
|
||||||
result += "Noise level : " + this.m_Noise + "\n";
|
result += "Noise level : " + this.getNoise() + "\n";
|
||||||
result += "Solution representation:\n";
|
result += "Solution representation:\n";
|
||||||
//result += this.m_Template.getSolutionRepresentationFor();
|
//result += this.m_Template.getSolutionRepresentationFor();
|
||||||
return result;
|
return result;
|
||||||
|
@ -72,7 +72,7 @@ public class F6Problem extends F1Problem implements InterfaceMultimodalProblem,
|
|||||||
result += "F6 Generalized Rastrigin's Function:\n";
|
result += "F6 Generalized Rastrigin's Function:\n";
|
||||||
result += "Parameters:\n";
|
result += "Parameters:\n";
|
||||||
result += "Dimension : " + this.m_ProblemDimension +"\n";
|
result += "Dimension : " + this.m_ProblemDimension +"\n";
|
||||||
result += "Noise level : " + this.m_Noise + "\n";
|
result += "Noise level : " + this.getNoise() + "\n";
|
||||||
result += "Solution representation:\n";
|
result += "Solution representation:\n";
|
||||||
//result += this.m_Template.getSolutionRepresentationFor();
|
//result += this.m_Template.getSolutionRepresentationFor();
|
||||||
return result;
|
return result;
|
||||||
|
@ -79,7 +79,7 @@ public class F7Problem extends F1Problem implements java.io.Serializable {
|
|||||||
fitness = this.eval(x);
|
fitness = this.eval(x);
|
||||||
for (int i = 0; i < fitness.length; i++) {
|
for (int i = 0; i < fitness.length; i++) {
|
||||||
// add noise to the fitness
|
// add noise to the fitness
|
||||||
fitness[i] += RandomNumberGenerator.gaussianDouble(this.m_Noise);
|
fitness[i] += RandomNumberGenerator.gaussianDouble(this.getNoise());
|
||||||
fitness[i] += this.m_YOffSet;
|
fitness[i] += this.m_YOffSet;
|
||||||
// set the fitness of the individual
|
// set the fitness of the individual
|
||||||
individual.SetFitness(i, fitness[i]);
|
individual.SetFitness(i, fitness[i]);
|
||||||
@ -120,7 +120,7 @@ public class F7Problem extends F1Problem implements java.io.Serializable {
|
|||||||
result += "F7 Sphere Model, changing Environemt:\n";
|
result += "F7 Sphere Model, changing Environemt:\n";
|
||||||
result += "Parameters:\n";
|
result += "Parameters:\n";
|
||||||
result += "Dimension : " + this.m_ProblemDimension +"\n";
|
result += "Dimension : " + this.m_ProblemDimension +"\n";
|
||||||
result += "Noise level : " + this.m_Noise + "\n";
|
result += "Noise level : " + this.getNoise() + "\n";
|
||||||
result += "Solution representation:\n";
|
result += "Solution representation:\n";
|
||||||
//result += this.m_Template.getSolutionRepresentationFor();
|
//result += this.m_Template.getSolutionRepresentationFor();
|
||||||
return result;
|
return result;
|
||||||
|
@ -92,7 +92,7 @@ public class F8Problem extends F1Problem implements InterfaceMultimodalProblem,
|
|||||||
result += "This problem is multimodal.\n";
|
result += "This problem is multimodal.\n";
|
||||||
result += "Parameters:\n";
|
result += "Parameters:\n";
|
||||||
result += "Dimension : " + this.m_ProblemDimension +"\n";
|
result += "Dimension : " + this.m_ProblemDimension +"\n";
|
||||||
result += "Noise level : " + this.m_Noise + "\n";
|
result += "Noise level : " + this.getNoise() + "\n";
|
||||||
result += "Solution representation:\n";
|
result += "Solution representation:\n";
|
||||||
//result += this.m_Template.getSolutionRepresentationFor();
|
//result += this.m_Template.getSolutionRepresentationFor();
|
||||||
return result;
|
return result;
|
||||||
|
@ -48,7 +48,7 @@ public class F9Problem extends F1Problem implements java.io.Serializable {
|
|||||||
result += "F9 Weighted Sphere Model:\n";
|
result += "F9 Weighted Sphere Model:\n";
|
||||||
result += "Parameters:\n";
|
result += "Parameters:\n";
|
||||||
result += "Dimension : " + this.m_ProblemDimension +"\n";
|
result += "Dimension : " + this.m_ProblemDimension +"\n";
|
||||||
result += "Noise level : " + this.m_Noise + "\n";
|
result += "Noise level : " + this.getNoise() + "\n";
|
||||||
result += "Solution representation:\n";
|
result += "Solution representation:\n";
|
||||||
//result += this.m_Template.getSolutionRepresentationFor();
|
//result += this.m_Template.getSolutionRepresentationFor();
|
||||||
return result;
|
return result;
|
||||||
|
@ -3,11 +3,10 @@ package javaeva.server.go.problems;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import javaeva.server.go.PopulationInterface;
|
||||||
import javaeva.server.go.individuals.AbstractEAIndividual;
|
import javaeva.server.go.individuals.AbstractEAIndividual;
|
||||||
import javaeva.server.go.individuals.ESIndividualDoubleData;
|
import javaeva.server.go.individuals.ESIndividualDoubleData;
|
||||||
import javaeva.server.go.individuals.InterfaceDataTypeDouble;
|
import javaeva.server.go.individuals.InterfaceDataTypeDouble;
|
||||||
import javaeva.server.go.operators.distancemetric.InterfaceDistanceMetric;
|
|
||||||
import javaeva.server.go.operators.distancemetric.PhenotypeMetric;
|
|
||||||
import javaeva.server.go.operators.postprocess.PostProcess;
|
import javaeva.server.go.operators.postprocess.PostProcess;
|
||||||
import javaeva.server.go.populations.Population;
|
import javaeva.server.go.populations.Population;
|
||||||
|
|
||||||
@ -18,29 +17,19 @@ import javaeva.server.go.populations.Population;
|
|||||||
* Time: 11:10:43
|
* Time: 11:10:43
|
||||||
* To change this template use Options | File Templates.
|
* To change this template use Options | File Templates.
|
||||||
*/
|
*/
|
||||||
public class FM0Problem extends AbstractProblemDouble implements Interface2DBorderProblem, InterfaceMultimodalProblemKnown, Serializable {
|
public class FM0Problem extends AbstractMultiModalProblemKnown implements Interface2DBorderProblem, InterfaceMultimodalProblemKnown, Serializable {
|
||||||
|
|
||||||
protected static InterfaceDistanceMetric m_Metric = new PhenotypeMetric();
|
public FM0Problem() {
|
||||||
protected double m_GlobalOpt = 0;
|
|
||||||
protected Population m_Optima;
|
|
||||||
protected double m_Epsilon = 0.05;
|
|
||||||
// protected boolean m_UseXCrit = true;
|
|
||||||
// protected boolean m_UseYCrit = true;
|
|
||||||
protected double[][] m_Range;
|
|
||||||
protected double[] m_Extrema;
|
|
||||||
protected int m_ProblemDimension = 2;
|
|
||||||
|
|
||||||
public FM0Problem() {
|
|
||||||
this.m_Template = new ESIndividualDoubleData();
|
|
||||||
this.m_ProblemDimension = 2;
|
this.m_ProblemDimension = 2;
|
||||||
this.m_Range = new double [this.m_ProblemDimension][2];
|
this.m_Template = new ESIndividualDoubleData();
|
||||||
this.m_Range[0][0] = -2.0;
|
// this.m_Extrema = new double[2];
|
||||||
this.m_Range[0][1] = 2.0;
|
// this.m_Range = new double [this.m_ProblemDimension][2];
|
||||||
this.m_Range[1][0] = -2.8;
|
// this.m_Range[0][0] = -2.0;
|
||||||
this.m_Range[1][1] = 2.8;
|
// this.m_Range[0][1] = 2.0;
|
||||||
this.m_Extrema = new double[2];
|
// this.m_Range[1][0] = -2.8;
|
||||||
this.m_Extrema[0] = -2;
|
// this.m_Range[1][1] = 2.8;
|
||||||
this.m_Extrema[1] = 6;
|
// this.m_Extrema[0] = -2;
|
||||||
|
// this.m_Extrema[1] = 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected double getRangeUpperBound(int dim) {
|
protected double getRangeUpperBound(int dim) {
|
||||||
@ -53,34 +42,7 @@ public class FM0Problem extends AbstractProblemDouble implements Interface2DBord
|
|||||||
}
|
}
|
||||||
|
|
||||||
public FM0Problem(FM0Problem b) {
|
public FM0Problem(FM0Problem b) {
|
||||||
//AbstractOptimizationProblem
|
cloneObjects(b);
|
||||||
if (b.m_Template != null)
|
|
||||||
this.m_Template = (AbstractEAIndividual)((AbstractEAIndividual)b.m_Template).clone();
|
|
||||||
|
|
||||||
// AbstractProblemDouble
|
|
||||||
this.m_Noise = b.m_Noise;
|
|
||||||
this.m_DefaultRange = b.m_DefaultRange;
|
|
||||||
|
|
||||||
// myself
|
|
||||||
this.m_ProblemDimension = b.m_ProblemDimension;
|
|
||||||
this.m_GlobalOpt = b.m_GlobalOpt;
|
|
||||||
this.m_Epsilon = b.m_Epsilon;
|
|
||||||
if (b.m_Optima != null)
|
|
||||||
this.m_Optima = (Population)((Population)b.m_Optima).clone();
|
|
||||||
if (b.m_Extrema != null) {
|
|
||||||
this.m_Extrema = new double[b.m_Extrema.length];
|
|
||||||
for (int i = 0; i < this.m_Extrema.length; i++) {
|
|
||||||
this.m_Extrema[i] = b.m_Extrema[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (b.m_Range != null) {
|
|
||||||
this.m_Range = new double[b.m_Range.length][b.m_Range[0].length];
|
|
||||||
for (int i = 0; i < this.m_Range.length; i++) {
|
|
||||||
for (int j = 0; j < this.m_Range[i].length; j++) {
|
|
||||||
this.m_Range[i][j] = b.m_Range[i][j];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method returns a deep clone of the problem.
|
/** This method returns a deep clone of the problem.
|
||||||
@ -90,38 +52,6 @@ public class FM0Problem extends AbstractProblemDouble implements Interface2DBord
|
|||||||
return (Object) new FM0Problem(this);
|
return (Object) new FM0Problem(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method inits a given population
|
|
||||||
* @param population The populations that is to be inited
|
|
||||||
*/
|
|
||||||
public void initPopulation(Population population) {
|
|
||||||
AbstractEAIndividual tmpIndy;
|
|
||||||
|
|
||||||
population.clear();
|
|
||||||
|
|
||||||
this.m_ProblemDimension = 2;
|
|
||||||
((InterfaceDataTypeDouble)this.m_Template).setDoubleDataLength(this.m_ProblemDimension);
|
|
||||||
((InterfaceDataTypeDouble)this.m_Template).SetDoubleRange(this.m_Range);
|
|
||||||
for (int i = 0; i < population.getPopulationSize(); i++) {
|
|
||||||
tmpIndy = (AbstractEAIndividual)((AbstractEAIndividual)this.m_Template).clone();
|
|
||||||
tmpIndy.init(this);
|
|
||||||
population.add(tmpIndy);
|
|
||||||
}
|
|
||||||
// population init must be last
|
|
||||||
// it set's fitcalls and generation to zero
|
|
||||||
population.init();
|
|
||||||
this.initListOfOptima();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Ths method allows you to evaluate a simple bit string to determine the fitness
|
|
||||||
* @param x The n-dimensional input vector
|
|
||||||
* @return The m-dimensional output vector.
|
|
||||||
*/
|
|
||||||
public double[] eval(double[] x) {
|
|
||||||
double[] result = new double[1];
|
|
||||||
result[0] = this.m_GlobalOpt - evalUnnormalized(x)[0];
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** This method returns the unnormalized function value for an maximization problem
|
/** This method returns the unnormalized function value for an maximization problem
|
||||||
* @param x The n-dimensional input vector
|
* @param x The n-dimensional input vector
|
||||||
* @return The m-dimensional output vector.
|
* @return The m-dimensional output vector.
|
||||||
@ -132,88 +62,27 @@ public class FM0Problem extends AbstractProblemDouble implements Interface2DBord
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method returns the header for the additional data that is to be written into a file
|
|
||||||
* @param pop The population that is to be refined.
|
|
||||||
* @return String
|
|
||||||
*/
|
|
||||||
public String getAdditionalFileStringHeader(Population pop) {
|
|
||||||
return "Solution \t Number of Optima found \t Maximum Peak Ratio";
|
|
||||||
}
|
|
||||||
|
|
||||||
/** This method returns the additional data that is to be written into a file
|
|
||||||
* @param pop The population that is to be refined.
|
|
||||||
* @return String
|
|
||||||
*/
|
|
||||||
public String getAdditionalFileStringValue(Population pop) {
|
|
||||||
String result = "";
|
|
||||||
result += AbstractEAIndividual.getDefaultDataString(pop.getBestEAIndividual()) +"\t";
|
|
||||||
result += this.getNumberOfFoundOptima(pop)+"\t";
|
|
||||||
result += this.getMaximumPeakRatio(pop);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** This method returns a string describing the optimization problem.
|
/** This method returns a string describing the optimization problem.
|
||||||
* @return The description.
|
* @return The description.
|
||||||
*/
|
*/
|
||||||
public String getStringRepresentationForProblem() {
|
public String getStringRepresentation() {
|
||||||
String result = "";
|
String result = "";
|
||||||
|
|
||||||
result += "M0 function:\n";
|
result += "M0 function:\n";
|
||||||
result += "This problem has one global and one local optimum.\n";
|
result += "This problem has one global and one local optimum.\n";
|
||||||
result += "Parameters:\n";
|
result += "Parameters:\n";
|
||||||
result += "Dimension : " + this.m_ProblemDimension +"\n";
|
result += "Dimension : " + this.m_ProblemDimension +"\n";
|
||||||
result += "Noise level : " + this.m_Noise + "\n";
|
result += "Noise level : " + this.getNoise() + "\n";
|
||||||
result += "Solution representation:\n";
|
result += "Solution representation:\n";
|
||||||
//result += this.m_Template.getSolutionRepresentationFor();
|
//result += this.m_Template.getSolutionRepresentationFor();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**********************************************************************************************************************
|
|
||||||
* Implementation of InterfaceMultimodalProblem
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** This method allows you to add a 2d optima to the list of optima
|
|
||||||
* @param x
|
|
||||||
* @param y
|
|
||||||
*/
|
|
||||||
protected void add2DOptimum(double x, double y) {
|
|
||||||
double[] point = new double[2];
|
|
||||||
point[0] = x;
|
|
||||||
point[1] = y;
|
|
||||||
addOptimum(point);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** This method allows you to add a 2d optima to the list of optima
|
|
||||||
* @param x
|
|
||||||
* @param y
|
|
||||||
*/
|
|
||||||
protected void addOptimum(double[] point) {
|
|
||||||
InterfaceDataTypeDouble tmpIndy;
|
|
||||||
tmpIndy = (InterfaceDataTypeDouble)((AbstractEAIndividual)this.m_Template).clone();
|
|
||||||
tmpIndy.SetDoubleDataLamarkian(point);
|
|
||||||
((AbstractEAIndividual)tmpIndy).SetFitness(evalUnnormalized(point));
|
|
||||||
if (((AbstractEAIndividual)tmpIndy).getFitness(0)>=m_GlobalOpt) {
|
|
||||||
m_GlobalOpt = ((AbstractEAIndividual)tmpIndy).getFitness(0);
|
|
||||||
double tmp=m_GlobalOpt;
|
|
||||||
double dx = 1e-30;
|
|
||||||
while (tmp==m_GlobalOpt) {
|
|
||||||
// this increases the optimum until there is a real difference.
|
|
||||||
// tries to avoid zero y-values which break the logarithmic plot
|
|
||||||
tmp+=dx;
|
|
||||||
dx *= 10;
|
|
||||||
}
|
|
||||||
m_GlobalOpt = tmp;
|
|
||||||
}
|
|
||||||
this.m_Optima.add(tmpIndy);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** This method will prepare the problem to return a list of all optima
|
/** This method will prepare the problem to return a list of all optima
|
||||||
* if possible and to return quality measures like NumberOfOptimaFound and
|
* if possible and to return quality measures like NumberOfOptimaFound and
|
||||||
* the MaximumPeakRatio. This method should be called by the user.
|
* the MaximumPeakRatio. This method should be called by the user.
|
||||||
*/
|
*/
|
||||||
public void initListOfOptima() {
|
public void initListOfOptima() {
|
||||||
this.m_GlobalOpt = Double.NEGATIVE_INFINITY;
|
|
||||||
this.m_Optima = new Population();
|
|
||||||
//this.add2DOptimum((Math.PI - (Math.PI - Math.acos(-1/4.0)) + Math.PI/2.0)/2.0, 0);
|
//this.add2DOptimum((Math.PI - (Math.PI - Math.acos(-1/4.0)) + Math.PI/2.0)/2.0, 0);
|
||||||
//this.add2DOptimum((-Math.PI - (Math.PI - Math.acos(-1/4.0)) + Math.PI/2.0)/2.0, 0);
|
//this.add2DOptimum((-Math.PI - (Math.PI - Math.acos(-1/4.0)) + Math.PI/2.0)/2.0, 0);
|
||||||
|
|
||||||
@ -222,71 +91,7 @@ public class FM0Problem extends AbstractProblemDouble implements Interface2DBord
|
|||||||
this.add2DOptimum(-1.44445618316078, 0.00000000700284);
|
this.add2DOptimum(-1.44445618316078, 0.00000000700284);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method returns a list of all optima as population
|
|
||||||
* @return population
|
|
||||||
*/
|
|
||||||
public Population getRealOptima() {
|
|
||||||
return this.m_Optima;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** This method returns the Number of Identified optima
|
|
||||||
* @param pop A population of possible solutions.
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public int getNumberOfFoundOptima(Population pop) {
|
|
||||||
List<AbstractEAIndividual> sols = PostProcess.getFoundOptima(pop, m_Optima, m_Epsilon, true);
|
|
||||||
return sols.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method returns the maximum peak ratio, which is the ratio of found fitness values corresponding to
|
|
||||||
* known optima with the internal epsilon criterion and the sum of all fitness values seen as maximization.
|
|
||||||
* Thus, if all optima are perfectly found, 1 is returned. If no optimum is found, zero is returned.
|
|
||||||
* A return value of 0.5 may mean, e.g., that half of n similar optima have been found perfectly, or that 1 major
|
|
||||||
* optimum of equal weight than all the others has been found perfectly, or that all optima have been found
|
|
||||||
* with about 50% accuracy, etc.
|
|
||||||
*
|
|
||||||
* @param pop A population of possible solutions.
|
|
||||||
* @return double
|
|
||||||
*/
|
|
||||||
public double getMaximumPeakRatio(Population pop) {
|
|
||||||
double optimaInvertedSum = 0, foundInvertedSum = 0;
|
|
||||||
AbstractEAIndividual[] optsFound = PostProcess.getFoundOptimaArray(pop, m_Optima, m_Epsilon, true);
|
|
||||||
|
|
||||||
for (int i=0; i<m_Optima.size(); i++) {
|
|
||||||
// sum up known optimal fitness values
|
|
||||||
optimaInvertedSum += m_Optima.getEAIndividual(i).getFitness(0);
|
|
||||||
// sum up best found hits, with inverted fitness
|
|
||||||
if (optsFound[i] != null) foundInvertedSum += m_GlobalOpt - optsFound[i].getFitness(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
return foundInvertedSum/optimaInvertedSum;
|
|
||||||
}
|
|
||||||
// public double getMaximumPeakRatio(Population pop) {
|
|
||||||
// double result = 0, sum = 0;
|
|
||||||
// AbstractEAIndividual posOpt, opt;
|
|
||||||
// boolean[] found = new boolean[this.m_Optima.size()];
|
|
||||||
// for (int i = 0; i < found.length; i++) {
|
|
||||||
// found[i] = false;
|
|
||||||
// sum += ((AbstractEAIndividual)this.m_Optima.get(i)).getFitness(0) ;
|
|
||||||
// //System.out.println("Optimum " + i + ".: " + (((AbstractEAIndividual)this.m_Optima.get(i)).getFitness(0)));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// for (int i = 0; i < pop.size(); i++) {
|
|
||||||
// posOpt = (AbstractEAIndividual) pop.get(i);
|
|
||||||
// for (int j = 0; j < this.m_Optima.size(); j++) {
|
|
||||||
// if (!found[j]) {
|
|
||||||
// opt = (AbstractEAIndividual) this.m_Optima.get(j);
|
|
||||||
// if (this.m_Metric.distance(posOpt, opt) < this.m_Epsilon) {
|
|
||||||
// found[j] = true;
|
|
||||||
// result += this.m_GlobalOpt - posOpt.getFitness(0);
|
|
||||||
// //System.out.println("Found Optimum " + j + ".: " + (this.m_GlobalOpt - posOpt.getFitness(0)));
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return result/sum;
|
|
||||||
// }
|
|
||||||
/**********************************************************************************************************************
|
/**********************************************************************************************************************
|
||||||
* These are for GUI
|
* These are for GUI
|
||||||
*/
|
*/
|
||||||
@ -304,52 +109,4 @@ public class FM0Problem extends AbstractProblemDouble implements Interface2DBord
|
|||||||
public String globalInfo() {
|
public String globalInfo() {
|
||||||
return "M0(x) = sin(2*x - 0.5*PI) + 1 + 2*cos(y) + 0.5*x is to be maximized.";
|
return "M0(x) = sin(2*x - 0.5*PI) + 1 + 2*cos(y) + 0.5*x is to be maximized.";
|
||||||
}
|
}
|
||||||
|
|
||||||
/*** For Debugging only ***/
|
|
||||||
/** This method returns the 2d borders of the problem
|
|
||||||
* @return double[][]
|
|
||||||
*/
|
|
||||||
public double[][] get2DBorder() {
|
|
||||||
return this.m_Range;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** This method returns the double value
|
|
||||||
* @param point The double[2] that is queried.
|
|
||||||
* @return double
|
|
||||||
*/
|
|
||||||
public double functionValue(double[] point) {
|
|
||||||
return evalUnnormalized(point)[0];
|
|
||||||
}
|
|
||||||
// /** This method returns this min and may fitness occuring
|
|
||||||
// * @return double[]
|
|
||||||
// */
|
|
||||||
// public double[] getExtrema() {
|
|
||||||
// double[] range = new double[2];
|
|
||||||
// range[0] = -5;
|
|
||||||
// range[1] = 5;
|
|
||||||
// return range;
|
|
||||||
// }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the m_Epsilon
|
|
||||||
*/
|
|
||||||
public double getEpsilon() {
|
|
||||||
return m_Epsilon;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param epsilon the m_Epsilon to set
|
|
||||||
*/
|
|
||||||
public void setEpsilon(double epsilon) {
|
|
||||||
m_Epsilon = epsilon;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String epsilonTipText() {
|
|
||||||
return "Epsilon criterion indicating whether an optimum was found";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getProblemDimension() {
|
|
||||||
return m_ProblemDimension;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -313,7 +313,7 @@ public class ClusterBasedNichingEA implements InterfacePopulationChangedEventLis
|
|||||||
if (TRACE) System.err.println("warning, muLambdaRatio produced mu >= lambda.. reducing to mu=lambda-1");
|
if (TRACE) System.err.println("warning, muLambdaRatio produced mu >= lambda.. reducing to mu=lambda-1");
|
||||||
mu = species.size() - 1;
|
mu = species.size() - 1;
|
||||||
}
|
}
|
||||||
es.setMyu(mu);
|
es.setMu(mu);
|
||||||
es.setLambda(species.size());
|
es.setLambda(species.size());
|
||||||
}
|
}
|
||||||
if (TRACE) {
|
if (TRACE) {
|
||||||
@ -384,12 +384,12 @@ public class ClusterBasedNichingEA implements InterfacePopulationChangedEventLis
|
|||||||
m_Species.remove(i); //REMOVES the converged Species
|
m_Species.remove(i); //REMOVES the converged Species
|
||||||
reinitCount = curSpecies.size(); // add all as new
|
reinitCount = curSpecies.size(); // add all as new
|
||||||
} else {
|
} else {
|
||||||
// now reset the converged species to inactivity size = 1
|
// now reset the converged species to inactivity size = 1
|
||||||
curSpecies.setPopulationSize(1);
|
reinitCount = curSpecies.size()-1; // add all but one as new
|
||||||
// m_Undifferentiated.incrFunctionCallsby(1); // TODO not so good
|
curSpecies.setPopulationSize(1);
|
||||||
curSpecies.clear();
|
// m_Undifferentiated.incrFunctionCallsby(1); // TODO not so good
|
||||||
curSpecies.add(best);
|
curSpecies.clear();
|
||||||
reinitCount = curSpecies.size()-1; // add all but one as new
|
curSpecies.add(best);
|
||||||
}
|
}
|
||||||
// reinit the surplus individuals and add these new individuals to undifferentiated
|
// reinit the surplus individuals and add these new individuals to undifferentiated
|
||||||
m_Undifferentiated.addPopulation(this.initializeIndividuals(reinitCount));
|
m_Undifferentiated.addPopulation(this.initializeIndividuals(reinitCount));
|
||||||
@ -427,8 +427,8 @@ public class ClusterBasedNichingEA implements InterfacePopulationChangedEventLis
|
|||||||
m_Undifferentiated.incrFunctionCallsby(m_Undifferentiated.size());
|
m_Undifferentiated.incrFunctionCallsby(m_Undifferentiated.size());
|
||||||
}
|
}
|
||||||
if (this.m_Undifferentiated.getFunctionCalls() % this.m_PopulationSize != 0) {
|
if (this.m_Undifferentiated.getFunctionCalls() % this.m_PopulationSize != 0) {
|
||||||
if (true) System.out.println("### mismatching number of funcalls, inactive species? Correcting by " + (m_PopulationSize - (m_Undifferentiated.getFunctionCalls() % m_PopulationSize)));
|
if (TRACE) System.out.println("### mismatching number of funcalls, inactive species? Correcting by " + (m_PopulationSize - (m_Undifferentiated.getFunctionCalls() % m_PopulationSize)));
|
||||||
if (true) System.out.println("### undiff " + ((isActive(m_Undifferentiated)) ? "active!" : "inactive!"));
|
if (TRACE) System.out.println("### undiff " + ((isActive(m_Undifferentiated)) ? "active!" : "inactive!"));
|
||||||
m_Undifferentiated.incrFunctionCallsby(m_PopulationSize - (m_Undifferentiated.getFunctionCalls() % m_PopulationSize));
|
m_Undifferentiated.incrFunctionCallsby(m_PopulationSize - (m_Undifferentiated.getFunctionCalls() % m_PopulationSize));
|
||||||
} else if (TRACE) System.out.println("### undiff active: " + isActive(m_Undifferentiated));
|
} else if (TRACE) System.out.println("### undiff active: " + isActive(m_Undifferentiated));
|
||||||
|
|
||||||
@ -438,7 +438,7 @@ public class ClusterBasedNichingEA implements InterfacePopulationChangedEventLis
|
|||||||
|
|
||||||
if (this.m_UseSpeciesDifferentation) {
|
if (this.m_UseSpeciesDifferentation) {
|
||||||
// species differentation phase
|
// species differentation phase
|
||||||
if (TRACE) System.out.println("-Sepecies Differentation:");
|
if (TRACE) System.out.println("-Species Differentation:");
|
||||||
Population[] ClusterResult;
|
Population[] ClusterResult;
|
||||||
ArrayList<Population> newSpecies = new ArrayList<Population>();
|
ArrayList<Population> newSpecies = new ArrayList<Population>();
|
||||||
//cluster the undifferentiated population
|
//cluster the undifferentiated population
|
||||||
@ -755,7 +755,7 @@ public class ClusterBasedNichingEA implements InterfacePopulationChangedEventLis
|
|||||||
this.m_Optimizer = b;
|
this.m_Optimizer = b;
|
||||||
if (b instanceof EvolutionStrategies) {
|
if (b instanceof EvolutionStrategies) {
|
||||||
EvolutionStrategies es = (EvolutionStrategies)b;
|
EvolutionStrategies es = (EvolutionStrategies)b;
|
||||||
setMuLambdaRatio(es.getMyu()/(double)es.getLambda());
|
setMuLambdaRatio(es.getMu()/(double)es.getLambda());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public String optimizerTipText() {
|
public String optimizerTipText() {
|
||||||
|
@ -12,21 +12,40 @@ import javaeva.server.go.problems.F1Problem;
|
|||||||
import javaeva.server.go.problems.InterfaceOptimizationProblem;
|
import javaeva.server.go.problems.InterfaceOptimizationProblem;
|
||||||
import javaeva.tools.Pair;
|
import javaeva.tools.Pair;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The clustering hill climber is similar to a multi-start hill climber. In addition so optimizing
|
||||||
|
* a set of individuals in parallel using a (1+1) strategy, the population is clustered in regular
|
||||||
|
* intervals. If several individuals have gathered together in the sense that they are interpreted
|
||||||
|
* as a cluster, only a subset of representatives of the cluster is taken over to the next HC step
|
||||||
|
* while the rest is discarded. This means that the population size may be reduced.
|
||||||
|
*
|
||||||
|
* As soon as the improvement by HC lies below a threshold, the mutation step size is decreased.
|
||||||
|
* If the step size is decreased below a certain threshold, the current population is stored to
|
||||||
|
* an archive and reinitialized. Thus, the number of optima that may be found and returned by
|
||||||
|
* getAllSolutions is higher than the population size.
|
||||||
|
*
|
||||||
|
* @author mkron
|
||||||
|
*
|
||||||
|
*/
|
||||||
public class ClusteringHillClimbing implements InterfacePopulationChangedEventListener, InterfaceOptimizer, Serializable {
|
public class ClusteringHillClimbing implements InterfacePopulationChangedEventListener, InterfaceOptimizer, Serializable {
|
||||||
transient private InterfacePopulationChangedEventListener m_Listener;
|
transient private InterfacePopulationChangedEventListener m_Listener;
|
||||||
|
public static final boolean TRACE = false;
|
||||||
|
|
||||||
transient private String m_Identifier = "";
|
transient private String m_Identifier = "";
|
||||||
private Population m_Population = new Population();
|
private Population m_Population = new Population();
|
||||||
private transient Population archive = new Population();
|
private transient Population archive = new Population();
|
||||||
private InterfaceOptimizationProblem m_Problem = new F1Problem();
|
private InterfaceOptimizationProblem m_Problem = new F1Problem();
|
||||||
private int hcEvalCycle = 1000;
|
private int hcEvalCycle = 1000;
|
||||||
private int initialPopSize = 200;
|
private int initialPopSize = 100;
|
||||||
private int loopCnt = 0;
|
private int loopCnt = 0;
|
||||||
// private int baseEvalCnt = 0;
|
// private int baseEvalCnt = 0;
|
||||||
private int notifyGuiEvery = 50;
|
private int notifyGuiEvery = 50;
|
||||||
private double sigma = 0.01;
|
private double sigmaClust = 0.01;
|
||||||
private double minImprovement = 0.000001;
|
private double minImprovement = 0.000001;
|
||||||
private double reinitForStepSize = 0.000001;
|
private double stepSizeThreshold = 0.000001;
|
||||||
private double initialStepSize = 0.1;
|
private double initialStepSize = 0.1;
|
||||||
|
// reduce the step size when there is hardy improvement.
|
||||||
|
private double reduceFactor = 0.2;
|
||||||
private MutateESFixedStepSize mutator = new MutateESFixedStepSize(0.1);
|
private MutateESFixedStepSize mutator = new MutateESFixedStepSize(0.1);
|
||||||
|
|
||||||
public ClusteringHillClimbing() {
|
public ClusteringHillClimbing() {
|
||||||
@ -37,8 +56,16 @@ public class ClusteringHillClimbing implements InterfacePopulationChangedEventLi
|
|||||||
hideHideable();
|
hideHideable();
|
||||||
m_Population = (Population)other.m_Population.clone();
|
m_Population = (Population)other.m_Population.clone();
|
||||||
m_Problem = (InterfaceOptimizationProblem)other.m_Problem.clone();
|
m_Problem = (InterfaceOptimizationProblem)other.m_Problem.clone();
|
||||||
|
|
||||||
hcEvalCycle = other.hcEvalCycle;
|
hcEvalCycle = other.hcEvalCycle;
|
||||||
initialPopSize = other.initialPopSize;
|
initialPopSize = other.initialPopSize;
|
||||||
|
notifyGuiEvery = other.notifyGuiEvery;
|
||||||
|
sigmaClust = other.sigmaClust;
|
||||||
|
minImprovement = other.minImprovement;
|
||||||
|
stepSizeThreshold = other.stepSizeThreshold;
|
||||||
|
initialStepSize = other.initialStepSize;
|
||||||
|
reduceFactor = other.reduceFactor;
|
||||||
|
mutator = (MutateESFixedStepSize)other.mutator.clone();
|
||||||
loopCnt = 0;
|
loopCnt = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,7 +108,7 @@ public class ClusteringHillClimbing implements InterfacePopulationChangedEventLi
|
|||||||
hideHideable();
|
hideHideable();
|
||||||
m_Population.setPopulationSize(initialPopSize);
|
m_Population.setPopulationSize(initialPopSize);
|
||||||
this.m_Problem.initPopulation(this.m_Population);
|
this.m_Problem.initPopulation(this.m_Population);
|
||||||
m_Population.addPopulationChangedEventListener(null);
|
m_Population.addPopulationChangedEventListener(null); // noone will be notified directly on pop changes
|
||||||
this.m_Problem.evaluate(this.m_Population);
|
this.m_Problem.evaluate(this.m_Population);
|
||||||
this.firePropertyChangedEvent("NextGenerationPerformed");
|
this.firePropertyChangedEvent("NextGenerationPerformed");
|
||||||
}
|
}
|
||||||
@ -111,16 +138,16 @@ public class ClusteringHillClimbing implements InterfacePopulationChangedEventLi
|
|||||||
loopCnt++;
|
loopCnt++;
|
||||||
m_Population.addPopulationChangedEventListener(this);
|
m_Population.addPopulationChangedEventListener(this);
|
||||||
m_Population.setNotifyEvalInterval(notifyGuiEvery);
|
m_Population.setNotifyEvalInterval(notifyGuiEvery);
|
||||||
Pair<Population, Double> popD = PostProcess.clusterHC(m_Population, (AbstractOptimizationProblem)m_Problem, sigma, hcEvalCycle - (m_Population.getFunctionCalls() % hcEvalCycle), 0.5, mutator);
|
Pair<Population, Double> popD = PostProcess.clusterHC(m_Population, (AbstractOptimizationProblem)m_Problem, sigmaClust, hcEvalCycle - (m_Population.getFunctionCalls() % hcEvalCycle), 0.5, mutator);
|
||||||
improvement = popD.tail();
|
improvement = popD.tail();
|
||||||
|
m_Population = popD.head();
|
||||||
|
|
||||||
popD.head().setGenerationTo(m_Population.getGeneration()+1);
|
popD.head().setGenerationTo(m_Population.getGeneration()+1);
|
||||||
m_Population = popD.head();
|
|
||||||
|
|
||||||
if (improvement < minImprovement) {
|
if (improvement < minImprovement) {
|
||||||
System.out.println("improvement below " + minImprovement);
|
if (TRACE) System.out.println("improvement below " + minImprovement);
|
||||||
if (mutator.getSigma() < reinitForStepSize) { // reinit!
|
if (mutator.getSigma() < stepSizeThreshold) { // reinit!
|
||||||
System.out.println("REINIT!!");
|
if (TRACE) System.out.println("REINIT!!");
|
||||||
// store results
|
// store results
|
||||||
mutator.setSigma(initialStepSize);
|
mutator.setSigma(initialStepSize);
|
||||||
archive.SetFunctionCalls(m_Population.getFunctionCalls());
|
archive.SetFunctionCalls(m_Population.getFunctionCalls());
|
||||||
@ -139,12 +166,12 @@ public class ClusteringHillClimbing implements InterfacePopulationChangedEventLi
|
|||||||
m_Population.incrFunctionCallsby(tmpPop.size());
|
m_Population.incrFunctionCallsby(tmpPop.size());
|
||||||
|
|
||||||
} else { // decrease step size
|
} else { // decrease step size
|
||||||
mutator.setSigma(mutator.getSigma()/2);
|
mutator.setSigma(mutator.getSigma()*reduceFactor);
|
||||||
System.out.println("halfed sigma to " + mutator.getSigma());
|
if (TRACE) System.out.println("mutation stepsize reduced to " + mutator.getSigma());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// System.out.println("funcalls: " + evalCnt);
|
// System.out.println("funcalls: " + evalCnt);
|
||||||
// this.firePropertyChangedEvent("NextGenerationPerformed");
|
this.firePropertyChangedEvent("NextGenerationPerformed");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -219,6 +246,10 @@ public class ClusteringHillClimbing implements InterfacePopulationChangedEventLi
|
|||||||
public void setHcEvalCycle(int hcEvalCycle) {
|
public void setHcEvalCycle(int hcEvalCycle) {
|
||||||
this.hcEvalCycle = hcEvalCycle;
|
this.hcEvalCycle = hcEvalCycle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String hcEvalCycleTipText() {
|
||||||
|
return "The number of evaluations between two clustering/adaption steps.";
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the initialPopSize
|
* @return the initialPopSize
|
||||||
@ -234,21 +265,25 @@ public class ClusteringHillClimbing implements InterfacePopulationChangedEventLi
|
|||||||
this.initialPopSize = initialPopSize;
|
this.initialPopSize = initialPopSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String initialPopSizeTipText() {
|
||||||
|
return "Population size at the start and at reinitialization times.";
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the sigma
|
* @return the sigma
|
||||||
*/
|
*/
|
||||||
public double getSigma() {
|
public double getSigmaClust() {
|
||||||
return sigma;
|
return sigmaClust;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param sigma the sigma to set
|
* @param sigma the sigma to set
|
||||||
*/
|
*/
|
||||||
public void setSigma(double sigma) {
|
public void setSigmaClust(double sigma) {
|
||||||
this.sigma = sigma;
|
this.sigmaClust = sigma;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String sigmaTipText() {
|
public String sigmaClustTipText() {
|
||||||
return "Defines the sigma distance parameter for density based clustering.";
|
return "Defines the sigma distance parameter for density based clustering.";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -266,6 +301,10 @@ public class ClusteringHillClimbing implements InterfacePopulationChangedEventLi
|
|||||||
this.notifyGuiEvery = notifyGuiEvery;
|
this.notifyGuiEvery = notifyGuiEvery;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String notifyGuiEveryTipText() {
|
||||||
|
return "How often to notify the GUI to plot the fitness etc.";
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the minImprovement
|
* @return the minImprovement
|
||||||
*/
|
*/
|
||||||
@ -280,33 +319,45 @@ public class ClusteringHillClimbing implements InterfacePopulationChangedEventLi
|
|||||||
this.minImprovement = minImprovement;
|
this.minImprovement = minImprovement;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String minImprovementTipText() {
|
||||||
|
return "Improvement threshold below which the mutation step size is reduced or the population reinitialized.";
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the reinitForStepSize
|
* @return the reinitForStepSize
|
||||||
*/
|
*/
|
||||||
public double getReinitForStepSize() {
|
public double getStepSizeThreshold() {
|
||||||
return reinitForStepSize;
|
return stepSizeThreshold;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param reinitForStepSize the reinitForStepSize to set
|
* @param reinitForStepSize the reinitForStepSize to set
|
||||||
*/
|
*/
|
||||||
public void setReinitForStepSize(double reinitForStepSize) {
|
public void setStepSizeThreshold(double reinitForStepSize) {
|
||||||
this.reinitForStepSize = reinitForStepSize;
|
this.stepSizeThreshold = reinitForStepSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String stepSizeThresholdTipText() {
|
||||||
|
return "Threshold for the mutation step size below which the population is seen as converged and reinitialized.";
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the initialStepSize
|
* @return the initialStepSize
|
||||||
*/
|
*/
|
||||||
public double getInitialStepSize() {
|
public double getStepSizeInitial() {
|
||||||
return initialStepSize;
|
return initialStepSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param initialStepSize the initialStepSize to set
|
* @param initialStepSize the initialStepSize to set
|
||||||
*/
|
*/
|
||||||
public void setInitialStepSize(double initialStepSize) {
|
public void setStepSizeInitial(double initialStepSize) {
|
||||||
this.initialStepSize = initialStepSize;
|
this.initialStepSize = initialStepSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String stepSizeInitialTipText() {
|
||||||
|
return "Initial mutation step size, relative to the problem range.";
|
||||||
|
}
|
||||||
|
|
||||||
// /**
|
// /**
|
||||||
// * @return the mutator
|
// * @return the mutator
|
||||||
|
@ -29,7 +29,7 @@ import javaeva.server.go.problems.InterfaceOptimizationProblem;
|
|||||||
public class EvolutionStrategies implements InterfaceOptimizer, java.io.Serializable {
|
public class EvolutionStrategies implements InterfaceOptimizer, java.io.Serializable {
|
||||||
|
|
||||||
//private double m_MyuRatio = 6;
|
//private double m_MyuRatio = 6;
|
||||||
private int m_Myu = 5;
|
private int m_Mu = 5;
|
||||||
private int m_Lambda = 20;
|
private int m_Lambda = 20;
|
||||||
private int m_InitialPopulationSize = 0;
|
private int m_InitialPopulationSize = 0;
|
||||||
private boolean m_UsePlusStrategy = false;
|
private boolean m_UsePlusStrategy = false;
|
||||||
@ -49,7 +49,7 @@ public class EvolutionStrategies implements InterfaceOptimizer, java.io.Serializ
|
|||||||
}
|
}
|
||||||
|
|
||||||
public EvolutionStrategies(int mu, int lambda, boolean usePlus) {
|
public EvolutionStrategies(int mu, int lambda, boolean usePlus) {
|
||||||
setMyu(mu);
|
setMu(mu);
|
||||||
setLambda(lambda);
|
setLambda(lambda);
|
||||||
setPlusStrategy(usePlus);
|
setPlusStrategy(usePlus);
|
||||||
this.m_Population.setPopulationSize(this.m_Lambda);
|
this.m_Population.setPopulationSize(this.m_Lambda);
|
||||||
@ -58,7 +58,7 @@ public class EvolutionStrategies implements InterfaceOptimizer, java.io.Serializ
|
|||||||
public EvolutionStrategies(EvolutionStrategies a) {
|
public EvolutionStrategies(EvolutionStrategies a) {
|
||||||
this.m_Population = (Population)a.m_Population.clone();
|
this.m_Population = (Population)a.m_Population.clone();
|
||||||
this.m_Problem = (InterfaceOptimizationProblem)a.m_Problem.clone();
|
this.m_Problem = (InterfaceOptimizationProblem)a.m_Problem.clone();
|
||||||
this.m_Myu = a.m_Myu;
|
this.m_Mu = a.m_Mu;
|
||||||
this.m_Lambda = a.m_Lambda;
|
this.m_Lambda = a.m_Lambda;
|
||||||
this.m_InitialPopulationSize = a.m_InitialPopulationSize;
|
this.m_InitialPopulationSize = a.m_InitialPopulationSize;
|
||||||
this.m_UsePlusStrategy = a.m_UsePlusStrategy;
|
this.m_UsePlusStrategy = a.m_UsePlusStrategy;
|
||||||
@ -183,7 +183,7 @@ public class EvolutionStrategies implements InterfaceOptimizer, java.io.Serializ
|
|||||||
//System.out.println("optimize");
|
//System.out.println("optimize");
|
||||||
// first perform the environment selection to select myu parents
|
// first perform the environment selection to select myu parents
|
||||||
this.m_EnvironmentSelection.prepareSelection(this.m_Population);
|
this.m_EnvironmentSelection.prepareSelection(this.m_Population);
|
||||||
parents = this.m_EnvironmentSelection.selectFrom(this.m_Population, this.m_Myu);
|
parents = this.m_EnvironmentSelection.selectFrom(this.m_Population, this.m_Mu);
|
||||||
this.m_Population.clear();
|
this.m_Population.clear();
|
||||||
this.m_Population.addPopulation(parents);
|
this.m_Population.addPopulation(parents);
|
||||||
// now generate the lambda offsprings
|
// now generate the lambda offsprings
|
||||||
@ -296,7 +296,7 @@ public class EvolutionStrategies implements InterfaceOptimizer, java.io.Serializ
|
|||||||
* @param plus True if plus, false if comma strategy
|
* @param plus True if plus, false if comma strategy
|
||||||
*/
|
*/
|
||||||
public void setGenerationStrategy(int myu, int lambda, boolean plus) {
|
public void setGenerationStrategy(int myu, int lambda, boolean plus) {
|
||||||
this.m_Myu = myu;
|
this.m_Mu = myu;
|
||||||
this.m_Lambda = lambda;
|
this.m_Lambda = lambda;
|
||||||
this.m_UsePlusStrategy = plus;
|
this.m_UsePlusStrategy = plus;
|
||||||
this.checkPopulationConstraints();
|
this.checkPopulationConstraints();
|
||||||
@ -307,8 +307,8 @@ public class EvolutionStrategies implements InterfaceOptimizer, java.io.Serializ
|
|||||||
* accordingly.
|
* accordingly.
|
||||||
*/
|
*/
|
||||||
private void checkPopulationConstraints() {
|
private void checkPopulationConstraints() {
|
||||||
if (this.m_Lambda < this.m_Myu) this.m_Lambda = this.m_Myu;
|
if (this.m_Lambda < this.m_Mu) this.m_Lambda = this.m_Mu;
|
||||||
if (this.m_UsePlusStrategy) this.m_Population.setPopulationSize(this.m_Myu + this.m_Lambda);
|
if (this.m_UsePlusStrategy) this.m_Population.setPopulationSize(this.m_Mu + this.m_Lambda);
|
||||||
else this.m_Population.setPopulationSize(this.m_Lambda);
|
else this.m_Population.setPopulationSize(this.m_Lambda);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -341,7 +341,7 @@ public class EvolutionStrategies implements InterfaceOptimizer, java.io.Serializ
|
|||||||
* @return The name of the algorithm
|
* @return The name of the algorithm
|
||||||
*/
|
*/
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "("+getMyu()+(getPlusStrategy() ? "+" : ",")+getLambda()+")-ES";
|
return "("+getMu()+(getPlusStrategy() ? "+" : ",")+getLambda()+")-ES";
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Assuming that all optimizer will store thier data in a population
|
/** Assuming that all optimizer will store thier data in a population
|
||||||
@ -473,14 +473,14 @@ public class EvolutionStrategies implements InterfaceOptimizer, java.io.Serializ
|
|||||||
/** This method allows you to set parent population size myu
|
/** This method allows you to set parent population size myu
|
||||||
* @param myu The parent population size.
|
* @param myu The parent population size.
|
||||||
*/
|
*/
|
||||||
public void setMyu(int myu) {
|
public void setMu(int mu) {
|
||||||
this.m_Myu = myu;
|
this.m_Mu = mu;
|
||||||
this.checkPopulationConstraints();
|
this.checkPopulationConstraints();
|
||||||
}
|
}
|
||||||
public int getMyu() {
|
public int getMu() {
|
||||||
return this.m_Myu;
|
return this.m_Mu;
|
||||||
}
|
}
|
||||||
public String myuTipText() {
|
public String muTipText() {
|
||||||
return "This is the parent population size.";
|
return "This is the parent population size.";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,6 +64,7 @@ public class TribesSwarm implements java.io.Serializable{
|
|||||||
for (int i=0; i<tribes[n].explorerNb; i++) pop.add(tribes[n].explorer[i]);
|
for (int i=0; i<tribes[n].explorerNb; i++) pop.add(tribes[n].explorer[i]);
|
||||||
}
|
}
|
||||||
pop.add(getBestMemory().asDummyExplorer(range, masterTribe.getObjectiveFirstDim()));
|
pop.add(getBestMemory().asDummyExplorer(range, masterTribe.getObjectiveFirstDim()));
|
||||||
|
pop.setPopulationSize(pop.size());
|
||||||
return pop;
|
return pop;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ import javaeva.server.go.strategies.InterfaceOptimizer;
|
|||||||
|
|
||||||
public abstract class AbstractGOParameters implements InterfaceGOParameters, Serializable {
|
public abstract class AbstractGOParameters implements InterfaceGOParameters, Serializable {
|
||||||
public static boolean TRACE = false;
|
public static boolean TRACE = false;
|
||||||
protected long m_Seed = (long)100.0;
|
protected long m_Seed = (long)0.0;
|
||||||
|
|
||||||
// Opt. Algorithms and Parameters
|
// Opt. Algorithms and Parameters
|
||||||
protected InterfaceOptimizer m_Optimizer;
|
protected InterfaceOptimizer m_Optimizer;
|
||||||
|
@ -6,6 +6,7 @@ import javaeva.server.go.InterfacePopulationChangedEventListener;
|
|||||||
import javaeva.server.go.InterfaceProcessor;
|
import javaeva.server.go.InterfaceProcessor;
|
||||||
import javaeva.server.go.PopulationInterface;
|
import javaeva.server.go.PopulationInterface;
|
||||||
import javaeva.server.go.operators.postprocess.PostProcess;
|
import javaeva.server.go.operators.postprocess.PostProcess;
|
||||||
|
import javaeva.server.go.operators.postprocess.PostProcessParams;
|
||||||
import javaeva.server.go.operators.terminators.EvaluationTerminator;
|
import javaeva.server.go.operators.terminators.EvaluationTerminator;
|
||||||
import javaeva.server.go.populations.Population;
|
import javaeva.server.go.populations.Population;
|
||||||
import javaeva.server.go.problems.AbstractOptimizationProblem;
|
import javaeva.server.go.problems.AbstractOptimizationProblem;
|
||||||
@ -27,6 +28,7 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
|
|||||||
private boolean wasRestarted = false;
|
private boolean wasRestarted = false;
|
||||||
// private int postProcessSteps = 0;
|
// private int postProcessSteps = 0;
|
||||||
private int runCounter = 0;
|
private int runCounter = 0;
|
||||||
|
private Population resPop = null;
|
||||||
|
|
||||||
// transient private String m_OutputPath = "";
|
// transient private String m_OutputPath = "";
|
||||||
// transient private BufferedWriter m_OutputFile = null;
|
// transient private BufferedWriter m_OutputFile = null;
|
||||||
@ -68,11 +70,6 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
|
|||||||
saveParams = doSave;
|
saveParams = doSave;
|
||||||
}
|
}
|
||||||
|
|
||||||
// public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) {
|
|
||||||
// listener = ea;
|
|
||||||
//// hier weiter! TODO
|
|
||||||
// }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ -83,6 +80,7 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
|
|||||||
System.err.println("ERROR: Processor is already running !!");
|
System.err.println("ERROR: Processor is already running !!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
resPop = null;
|
||||||
wasRestarted = false;
|
wasRestarted = false;
|
||||||
setOptRunning(true);
|
setOptRunning(true);
|
||||||
}
|
}
|
||||||
@ -107,17 +105,9 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
|
|||||||
public void stopOpt() { // this means user break
|
public void stopOpt() { // this means user break
|
||||||
if (TRACE) System.out.println("called StopOpt");
|
if (TRACE) System.out.println("called StopOpt");
|
||||||
setOptRunning(false);
|
setOptRunning(false);
|
||||||
// m_doRunScript = false;
|
|
||||||
if (TRACE) System.out.println("m_doRunScript = false ");
|
if (TRACE) System.out.println("m_doRunScript = false ");
|
||||||
}
|
}
|
||||||
|
|
||||||
// /**
|
|
||||||
// *
|
|
||||||
// */
|
|
||||||
// public void runScript() {
|
|
||||||
// m_doRunScript = true;
|
|
||||||
// }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ -133,12 +123,12 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void runOptOnce() {
|
public Population runOptOnce() {
|
||||||
try {
|
try {
|
||||||
while (isOptRunning()) {
|
while (isOptRunning()) {
|
||||||
setPriority(3);
|
setPriority(3);
|
||||||
if (saveParams) goParams.saveInstance();
|
if (saveParams) goParams.saveInstance();
|
||||||
optimize("Run");
|
resPop = optimize("Run");
|
||||||
setPriority(1);
|
setPriority(1);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -149,12 +139,16 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
|
|||||||
if (m_ListenerModule!=null) m_ListenerModule.performedStop(); // is only needed in client server mode
|
if (m_ListenerModule!=null) m_ListenerModule.performedStop(); // is only needed in client server mode
|
||||||
if (m_ListenerModule!=null) m_ListenerModule.updateProgress(0, "Error in optimization: " + e.getMessage());
|
if (m_ListenerModule!=null) m_ListenerModule.updateProgress(0, "Error in optimization: " + e.getMessage());
|
||||||
}
|
}
|
||||||
|
return resPop;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Main optimization loop.
|
||||||
|
* Return a population containing the solutions of the last run if there were multiple.
|
||||||
*/
|
*/
|
||||||
public void optimize(String infoString) {
|
public Population optimize(String infoString) {
|
||||||
|
Population resPop = null;
|
||||||
|
|
||||||
if (!isOptRunning()) {
|
if (!isOptRunning()) {
|
||||||
System.err.println("warning, this shouldnt happen in processor! Was startOpt called?");
|
System.err.println("warning, this shouldnt happen in processor! Was startOpt called?");
|
||||||
setOptRunning(true);
|
setOptRunning(true);
|
||||||
@ -217,7 +211,8 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
|
|||||||
//////////////// Default stats
|
//////////////// Default stats
|
||||||
m_Statistics.stopOptPerformed(isOptRunning()); // stop is "normal" if opt wasnt set false by the user
|
m_Statistics.stopOptPerformed(isOptRunning()); // stop is "normal" if opt wasnt set false by the user
|
||||||
//////////////// PP
|
//////////////// PP
|
||||||
PostProcess.postProcess(goParams.getPostProcessParams(), goParams.getOptimizer().getAllSolutions(), (AbstractOptimizationProblem)goParams.getProblem(), (InterfaceTextListener)m_Statistics);
|
performNewPostProcessing((PostProcessParams)goParams.getPostProcessParams(), (InterfaceTextListener)m_Statistics);
|
||||||
|
|
||||||
// moved to PostProcess
|
// moved to PostProcess
|
||||||
// if ((goParams.getProblem() instanceof InterfaceMultimodalProblem)) {
|
// if ((goParams.getProblem() instanceof InterfaceMultimodalProblem)) {
|
||||||
// InterfaceMultimodalProblem mmProb = (InterfaceMultimodalProblem)goParams.getProblem();
|
// InterfaceMultimodalProblem mmProb = (InterfaceMultimodalProblem)goParams.getProblem();
|
||||||
@ -231,6 +226,7 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
|
|||||||
setOptRunning(false); // normal finish
|
setOptRunning(false); // normal finish
|
||||||
if (m_ListenerModule!=null) m_ListenerModule.performedStop(); // is only needed in client server mode
|
if (m_ListenerModule!=null) m_ListenerModule.performedStop(); // is only needed in client server mode
|
||||||
if (m_ListenerModule!=null) m_ListenerModule.updateProgress(0, null);
|
if (m_ListenerModule!=null) m_ListenerModule.updateProgress(0, null);
|
||||||
|
return resPop;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getStatusPercent(Population pop, int currentRun, int multiRuns) {
|
private int getStatusPercent(Population pop, int currentRun, int multiRuns) {
|
||||||
@ -303,13 +299,15 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
|
|||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method return the Statistics object.
|
/**
|
||||||
|
* This method return the Statistics object.
|
||||||
*/
|
*/
|
||||||
public InterfaceStatistics getStatistics() {
|
public InterfaceStatistics getStatistics() {
|
||||||
return m_Statistics;
|
return m_Statistics;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** These methods allow you to get and set the Modul Parameters.
|
/**
|
||||||
|
* These methods allow you to get and set the Module Parameters.
|
||||||
*/
|
*/
|
||||||
public InterfaceGOParameters getGOParams() {
|
public InterfaceGOParameters getGOParams() {
|
||||||
return goParams;
|
return goParams;
|
||||||
@ -317,4 +315,32 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
|
|||||||
public void setGOParams(InterfaceGOParameters x) {
|
public void setGOParams(InterfaceGOParameters x) {
|
||||||
goParams= x;
|
goParams= x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the last solution population or null if there is none available.
|
||||||
|
*
|
||||||
|
* @return the last solution population or null
|
||||||
|
*/
|
||||||
|
public Population getResultPopulation() {
|
||||||
|
return resPop;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Perform a post processing step with given parameters, based on all solutions found by the optimizer.
|
||||||
|
* Use getResultPopulation() to retrieve results.
|
||||||
|
*
|
||||||
|
* @param ppp
|
||||||
|
* @param listener
|
||||||
|
*/
|
||||||
|
public void performNewPostProcessing(PostProcessParams ppp, InterfaceTextListener listener) {
|
||||||
|
ppp.hideHideable(); // a bit mean: as we may have several instances of ppp in different states, make sure Bean-"hidden" state is consistent for output.
|
||||||
|
if (listener != null) listener.println("Starting post processing... " + BeanInspector.toString(ppp));
|
||||||
|
resPop = goParams.getOptimizer().getAllSolutions();
|
||||||
|
if (resPop.getFunctionCalls() != goParams.getOptimizer().getPopulation().getFunctionCalls()) {
|
||||||
|
// System.err.println("bad case in Processor::performNewPostProcessing ");
|
||||||
|
resPop.SetFunctionCalls(goParams.getOptimizer().getPopulation().getFunctionCalls());
|
||||||
|
}
|
||||||
|
if (!resPop.contains(m_Statistics.getBestSolution())) resPop.add(m_Statistics.getBestSolution()); // this is a minor cheat but guarantees that the best solution ever found is contained in the final results
|
||||||
|
resPop = PostProcess.postProcess(ppp, resPop, (AbstractOptimizationProblem)goParams.getProblem(), listener);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -228,14 +228,7 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter
|
|||||||
if (doTextOutput()) printToTextListener(getOutputHeader(informer, pop)+'\n');
|
if (doTextOutput()) printToTextListener(getOutputHeader(informer, pop)+'\n');
|
||||||
firstPlot = false;
|
firstPlot = false;
|
||||||
}
|
}
|
||||||
// System.out.println("pop fcalls: " + pop.getFunctionCalls());
|
|
||||||
// if ((pop.getFunctionCalls() % 100) != 0 ) {
|
|
||||||
// System.err.println("error: pop fcalls: " + pop.getFunctionCalls());
|
|
||||||
// double [] bla= new double[1];
|
|
||||||
// bla[10]=0;
|
|
||||||
// //TODO
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
if (pop.getSpecificData() != null) {
|
if (pop.getSpecificData() != null) {
|
||||||
plotSpecificData(pop, informer);
|
plotSpecificData(pop, informer);
|
||||||
return;
|
return;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user