Updates to the OptimizerFactory and the MatlabInterface. Better access to EvAClient.
This commit is contained in:
@@ -4,6 +4,8 @@ package eva2;
|
||||
* Main product and version information strings.
|
||||
*
|
||||
* --- Changelog
|
||||
* 2.031: Some updates to the OptimizerFactory. Review of the MatlabInterface with adding an own options structure.
|
||||
* Better access to the EvAClient, which now may have a RemoteStateListener added monitoring the optimization run.
|
||||
* 2.030: Added an EnumEditor to access enums easily through the GUI, which will replace SelectedTags sometimes.
|
||||
* IPOP-ES and RankMuCMA mutator have been added lately (wow!).
|
||||
* Cleaned up the IndividualInterface and reduced the usage of InterfaceESIndividual. This
|
||||
|
@@ -35,7 +35,6 @@ import eva2.server.go.operators.selection.InterfaceSelection;
|
||||
import eva2.server.go.operators.selection.SelectBestIndividuals;
|
||||
import eva2.server.go.operators.terminators.CombinedTerminator;
|
||||
import eva2.server.go.operators.terminators.EvaluationTerminator;
|
||||
import eva2.server.go.operators.terminators.FitnessConvergenceTerminator;
|
||||
import eva2.server.go.populations.Population;
|
||||
import eva2.server.go.problems.AbstractOptimizationProblem;
|
||||
import eva2.server.go.strategies.ClusterBasedNichingEA;
|
||||
@@ -67,9 +66,8 @@ import eva2.server.modules.GOParameters;
|
||||
* the methods initialize the respective optimization procedure. To perform an
|
||||
* optimization one has to do the following: <code>
|
||||
* InterfaceOptimizer optimizer = OptimizerFactory.createCertainOptimizer(arguments);
|
||||
* EvaluationTerminator terminator = new EvaluationTerminator();
|
||||
* terminator.setFitnessCalls(numOfFitnessCalls);
|
||||
* while (!terminator.isTerminated(mc.getPopulation())) mc.optimize();
|
||||
* EvaluationTerminator terminator = new EvaluationTerminator(numOfFitnessCalls);
|
||||
* while (!terminator.isTerminated(optimizer.getPopulation())) optimizer.optimize();
|
||||
* </code>
|
||||
* </p>
|
||||
*
|
||||
@@ -80,7 +78,7 @@ import eva2.server.modules.GOParameters;
|
||||
* @date 17.04.2007
|
||||
*/
|
||||
public class OptimizerFactory {
|
||||
private static InterfaceTerminator term = null;
|
||||
private static InterfaceTerminator userTerm = null;
|
||||
|
||||
public final static int STD_ES = 1;
|
||||
|
||||
@@ -110,24 +108,6 @@ public class OptimizerFactory {
|
||||
|
||||
private static OptimizerRunnable lastRunnable = null;
|
||||
|
||||
/**
|
||||
* Add an InterfaceTerminator to any new optimizer in a boolean combination.
|
||||
* The old and the given terminator will be combined as in (TOld && TNew) if
|
||||
* bAnd is true, and as in (TOld || TNew) if bAnd is false.
|
||||
*
|
||||
* @param newTerm
|
||||
* a new InterfaceTerminator instance
|
||||
* @param bAnd
|
||||
* indicate the boolean combination
|
||||
*/
|
||||
public static void addTerminator(InterfaceTerminator newTerm, boolean bAnd) {
|
||||
if (OptimizerFactory.term == null)
|
||||
OptimizerFactory.term = term;
|
||||
else
|
||||
setTerminator(new CombinedTerminator(OptimizerFactory.term,
|
||||
newTerm, bAnd));
|
||||
}
|
||||
|
||||
/**
|
||||
* This method optimizes the given problem using differential evolution.
|
||||
*
|
||||
@@ -501,10 +481,8 @@ public class OptimizerFactory {
|
||||
}
|
||||
|
||||
// /////////////////////////// Termination criteria
|
||||
public static InterfaceTerminator defaultTerminator() {
|
||||
if (term == null)
|
||||
term = new EvaluationTerminator(defaultFitCalls);
|
||||
return term;
|
||||
public static InterfaceTerminator makeDefaultTerminator() {
|
||||
return new EvaluationTerminator(defaultFitCalls);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -582,21 +560,38 @@ public class OptimizerFactory {
|
||||
public static OptimizerRunnable getOptRunnable(final int optType,
|
||||
AbstractOptimizationProblem problem, int fitCalls,
|
||||
String outputFilePrefix) {
|
||||
return getOptRunnable(optType, problem, new EvaluationTerminator(fitCalls), outputFilePrefix);
|
||||
}
|
||||
|
||||
/**
|
||||
* Produce a runnable optimizer from a strategy identifier, a problem instance and with a given
|
||||
* terminator. Output is written to a file if the prefix String is given. If the terminator is null
|
||||
* the current user-defined terminator will be used and if none is set, the default number of fitness
|
||||
* calls will be performed.
|
||||
*
|
||||
* @param optType
|
||||
* @param problem
|
||||
* @param terminator
|
||||
* @param outputFilePrefix
|
||||
* @return a runnable optimizer
|
||||
*/
|
||||
public static OptimizerRunnable getOptRunnable(final int optType,
|
||||
AbstractOptimizationProblem problem, InterfaceTerminator terminator,
|
||||
String outputFilePrefix) {
|
||||
OptimizerRunnable opt = null;
|
||||
GOParameters params = getParams(optType, problem);
|
||||
if (params != null) {
|
||||
opt = new OptimizerRunnable(params, outputFilePrefix);
|
||||
if (fitCalls != defaultFitCalls)
|
||||
opt.getGOParams().setTerminator(
|
||||
new EvaluationTerminator(fitCalls));
|
||||
if (terminator != null) opt.getGOParams().setTerminator(terminator);
|
||||
else opt.getGOParams().setTerminator(getTerminator());
|
||||
}
|
||||
return opt;
|
||||
}
|
||||
|
||||
|
||||
// /////////////////////////// constructing a default OptimizerRunnable
|
||||
/**
|
||||
* Produce a runnable optimizer from a strategy identifier, a problem instance and with the default
|
||||
* number of fitness calls to be performed. Output is written to a file if the prefix String is given.
|
||||
* Produce a runnable optimizer from a strategy identifier, a problem instance and with the current
|
||||
* static terminator in use. Output is written to a file if the prefix String is given.
|
||||
* @see #getOptRunnable(int, AbstractOptimizationProblem, int, String)
|
||||
* @param optType
|
||||
* @param problem
|
||||
@@ -605,17 +600,17 @@ public class OptimizerFactory {
|
||||
*/
|
||||
public static OptimizerRunnable getOptRunnable(final int optType,
|
||||
AbstractOptimizationProblem problem, String outputFilePrefix) {
|
||||
return getOptRunnable(optType, problem, defaultFitCalls,
|
||||
outputFilePrefix);
|
||||
return getOptRunnable(optType, problem, getTerminator(), outputFilePrefix);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the current default terminator.
|
||||
* Return the current user-defined or, if none was set, the default terminator.
|
||||
*
|
||||
* @return the current default terminator
|
||||
*/
|
||||
public static InterfaceTerminator getTerminator() {
|
||||
return OptimizerFactory.term;
|
||||
if (OptimizerFactory.userTerm != null) return OptimizerFactory.userTerm;
|
||||
else return makeDefaultTerminator();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -638,7 +633,7 @@ public class OptimizerFactory {
|
||||
*/
|
||||
public static GOParameters makeESParams(EvolutionStrategies es,
|
||||
AbstractOptimizationProblem problem) {
|
||||
return makeParams(es, es.getLambda(), problem, randSeed, defaultTerminator());
|
||||
return makeParams(es, es.getLambda(), problem, randSeed, makeDefaultTerminator());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -651,7 +646,7 @@ public class OptimizerFactory {
|
||||
* @return
|
||||
*/
|
||||
public static GOParameters makeParams(InterfaceOptimizer opt, int popSize, AbstractOptimizationProblem problem) {
|
||||
return makeParams(opt, popSize, problem, randSeed, defaultTerminator());
|
||||
return makeParams(opt, popSize, problem, randSeed, makeDefaultTerminator());
|
||||
}
|
||||
|
||||
public static GOParameters makeParams(InterfaceOptimizer opt,
|
||||
@@ -709,17 +704,39 @@ public class OptimizerFactory {
|
||||
* @param optType
|
||||
* @param problem
|
||||
* @param outputFilePrefix
|
||||
* @return
|
||||
* @return the OptimizerRunnable instance just started
|
||||
*/
|
||||
public static OptimizerRunnable optimizeInThread(final int optType,
|
||||
AbstractOptimizationProblem problem, String outputFilePrefix) {
|
||||
OptimizerRunnable runnable = getOptRunnable(optType, problem,
|
||||
outputFilePrefix);
|
||||
if (runnable != null)
|
||||
new Thread(runnable).start();
|
||||
return runnable;
|
||||
public static OptimizerRunnable optimizeInThread(final int optType, AbstractOptimizationProblem problem, String outputFilePrefix) {
|
||||
return optimizeInThread(getOptRunnable(optType, problem, outputFilePrefix));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a runnable optimization Runnable and directly start it in an own
|
||||
* thread. The Runnable will notify waiting threads and set the isFinished
|
||||
* flag when the optimization is complete. If the optType is invalid, null
|
||||
* will be returned.
|
||||
*
|
||||
* @param params
|
||||
* @param outputFilePrefix
|
||||
* @return the OptimizerRunnable instance just started
|
||||
*/
|
||||
public static OptimizerRunnable optimizeInThread(GOParameters params, String outputFilePrefix) {
|
||||
return optimizeInThread(new OptimizerRunnable(params, outputFilePrefix));
|
||||
}
|
||||
|
||||
/**
|
||||
* Start a runnable optimizer in a concurrent thread.
|
||||
* @param runnable
|
||||
* @return the started runnable
|
||||
*/
|
||||
public static OptimizerRunnable optimizeInThread(OptimizerRunnable runnable) {
|
||||
if (runnable != null) {
|
||||
new Thread(runnable).start();
|
||||
lastRunnable = runnable;
|
||||
}
|
||||
return runnable;
|
||||
}
|
||||
|
||||
// ///////////////////////////// Optimize a given parameter instance
|
||||
public static BitSet optimizeToBinary(GOParameters params,
|
||||
String outputFilePrefix) {
|
||||
@@ -810,12 +827,30 @@ public class OptimizerFactory {
|
||||
return (lastRunnable == null) ? null : postProcess(lastRunnable, ppp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Post process the given runnable with given parameters. The runnable will
|
||||
* not be stored.
|
||||
*
|
||||
* @param runnable
|
||||
* @param steps
|
||||
* @param sigma
|
||||
* @param nBest
|
||||
* @return
|
||||
*/
|
||||
public static Population postProcess(OptimizerRunnable runnable, int steps,
|
||||
double sigma, int nBest) {
|
||||
PostProcessParams ppp = new PostProcessParams(steps, sigma, nBest);
|
||||
return postProcess(runnable, ppp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Post process the given runnable with given parameters. The runnable will
|
||||
* not be stored.
|
||||
*
|
||||
* @param runnable
|
||||
* @param ppp
|
||||
* @return
|
||||
*/
|
||||
public static Population postProcess(OptimizerRunnable runnable,
|
||||
InterfacePostProcessParams ppp) {
|
||||
runnable.setDoRestart(true);
|
||||
@@ -845,6 +880,14 @@ public class OptimizerFactory {
|
||||
nBest));
|
||||
}
|
||||
|
||||
/**
|
||||
* Post process the given runnable with given parameters. Return the solution set
|
||||
* as a vector of BitSets. The runnable will not be stored.
|
||||
*
|
||||
* @param runnable
|
||||
* @param ppp
|
||||
* @return
|
||||
*/
|
||||
public static Vector<BitSet> postProcessBinVec(OptimizerRunnable runnable,
|
||||
InterfacePostProcessParams ppp) {
|
||||
Population resPop = postProcess(runnable, ppp);
|
||||
@@ -875,7 +918,15 @@ public class OptimizerFactory {
|
||||
return postProcessDblVec(runnable, new PostProcessParams(steps, sigma,
|
||||
nBest));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Post process the given runnable with given parameters. Return the solution set
|
||||
* as a vector of double arrays. The runnable will not be stored.
|
||||
*
|
||||
* @param runnable
|
||||
* @param ppp
|
||||
* @return
|
||||
*/
|
||||
public static Vector<double[]> postProcessDblVec(
|
||||
OptimizerRunnable runnable, InterfacePostProcessParams ppp) {
|
||||
Population resPop = postProcess(runnable, ppp);
|
||||
@@ -906,7 +957,15 @@ public class OptimizerFactory {
|
||||
return postProcessIndVec(runnable, new PostProcessParams(steps, sigma,
|
||||
nBest));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Post process the given runnable with given parameters. Return the solution set
|
||||
* as a vector of AbstractEAIndividuals. The runnable will not be stored.
|
||||
*
|
||||
* @param runnable
|
||||
* @param ppp
|
||||
* @return
|
||||
*/
|
||||
public static Vector<AbstractEAIndividual> postProcessIndVec(
|
||||
OptimizerRunnable runnable, InterfacePostProcessParams ppp) {
|
||||
Population resPop = postProcess(runnable, ppp);
|
||||
@@ -922,19 +981,48 @@ public class OptimizerFactory {
|
||||
}
|
||||
|
||||
///////////////////////////// termination management
|
||||
/**
|
||||
* Replace the current user-defined terminator by the given one.
|
||||
*
|
||||
* @param term
|
||||
*/
|
||||
public static void setTerminator(InterfaceTerminator term) {
|
||||
OptimizerFactory.userTerm = term;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new InterfaceTerminator to the current user-defined optimizer in a boolean combination.
|
||||
* The old and the given terminator will be combined as in (TOld && TNew) if
|
||||
* bAnd is true, and as in (TOld || TNew) if bAnd is false.
|
||||
* If there was no user-defined terminator (or it was set to null) the new one is used without conjunction.
|
||||
*
|
||||
* @param newTerm
|
||||
* a new InterfaceTerminator instance
|
||||
* @param bAnd
|
||||
* indicate the boolean combination
|
||||
*/
|
||||
public static void addTerminator(InterfaceTerminator newTerm, boolean bAnd) {
|
||||
if (OptimizerFactory.userTerm == null)
|
||||
OptimizerFactory.userTerm = newTerm;
|
||||
else
|
||||
setTerminator(new CombinedTerminator(OptimizerFactory.userTerm,
|
||||
newTerm, bAnd));
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method setting an EvaluationTerminator with the given
|
||||
* number of evaluations.
|
||||
*
|
||||
* @param maxEvals
|
||||
*/
|
||||
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) {
|
||||
OptimizerFactory.term = term;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the termination message of the last runnable, if available.
|
||||
* @return
|
||||
*/
|
||||
public static String terminatedBecause() {
|
||||
return (lastRunnable != null) ? lastRunnable.terminatedBecause() : null;
|
||||
}
|
||||
@@ -947,12 +1035,12 @@ public class OptimizerFactory {
|
||||
*/
|
||||
public static final GOParameters hillClimbing(
|
||||
AbstractOptimizationProblem problem) {
|
||||
return makeParams(new HillClimbing(), 50, problem, randSeed, defaultTerminator());
|
||||
return makeParams(new HillClimbing(), 50, problem, randSeed, makeDefaultTerminator());
|
||||
}
|
||||
|
||||
public static final GOParameters monteCarlo(
|
||||
AbstractOptimizationProblem problem) {
|
||||
return makeParams(new MonteCarloSearch(), 50, problem, randSeed, defaultTerminator());
|
||||
return makeParams(new MonteCarloSearch(), 50, problem, randSeed, makeDefaultTerminator());
|
||||
}
|
||||
|
||||
public static final GOParameters cbnES(AbstractOptimizationProblem problem) {
|
||||
@@ -967,7 +1055,7 @@ public class OptimizerFactory {
|
||||
cbn.setDifferentationCA(clustering);
|
||||
cbn.setShowCycle(0); // don't do graphical output
|
||||
|
||||
return makeParams(cbn, 100, problem, randSeed, defaultTerminator());
|
||||
return makeParams(cbn, 100, problem, randSeed, makeDefaultTerminator());
|
||||
}
|
||||
|
||||
public static final GOParameters clusteringHillClimbing(
|
||||
@@ -982,7 +1070,7 @@ public class OptimizerFactory {
|
||||
chc.setNotifyGuiEvery(0);
|
||||
chc.setStepSizeThreshold(0.000001);
|
||||
chc.setSigmaClust(0.05);
|
||||
return makeParams(chc, 100, problem, randSeed, defaultTerminator());
|
||||
return makeParams(chc, 100, problem, randSeed, makeDefaultTerminator());
|
||||
}
|
||||
|
||||
public static final GOParameters cmaES(AbstractOptimizationProblem problem) {
|
||||
@@ -1052,7 +1140,7 @@ public class OptimizerFactory {
|
||||
de.setK(0.6);
|
||||
de.setLambda(0.6);
|
||||
de.setMt(0.05);
|
||||
return makeParams(de, 50, problem, randSeed, defaultTerminator());
|
||||
return makeParams(de, 50, problem, randSeed, makeDefaultTerminator());
|
||||
}
|
||||
|
||||
public static final GOParameters standardES(
|
||||
@@ -1082,7 +1170,7 @@ public class OptimizerFactory {
|
||||
GeneticAlgorithm ga = new GeneticAlgorithm();
|
||||
ga.setElitism(true);
|
||||
|
||||
return makeParams(ga, 100, problem, randSeed, defaultTerminator());
|
||||
return makeParams(ga, 100, problem, randSeed, makeDefaultTerminator());
|
||||
}
|
||||
|
||||
public static final GOParameters standardPSO(
|
||||
@@ -1090,10 +1178,10 @@ public class OptimizerFactory {
|
||||
ParticleSwarmOptimization pso = new ParticleSwarmOptimization();
|
||||
pso.setPhiValues(2.05, 2.05);
|
||||
pso.getTopology().setSelectedTag("Grid");
|
||||
return makeParams(pso, 30, problem, randSeed, defaultTerminator());
|
||||
return makeParams(pso, 30, problem, randSeed, makeDefaultTerminator());
|
||||
}
|
||||
|
||||
public static final GOParameters tribes(AbstractOptimizationProblem problem) {
|
||||
return makeParams(new Tribes(), 1, problem, randSeed, defaultTerminator());
|
||||
return makeParams(new Tribes(), 1, problem, randSeed, makeDefaultTerminator());
|
||||
}
|
||||
}
|
||||
|
@@ -4,6 +4,8 @@ import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.util.BitSet;
|
||||
|
||||
import wsi.ra.jproxy.RemoteStateListener;
|
||||
|
||||
import eva2.server.go.IndividualInterface;
|
||||
import eva2.server.go.InterfaceGOParameters;
|
||||
import eva2.server.go.InterfaceTerminator;
|
||||
@@ -88,6 +90,10 @@ public class OptimizerRunnable implements Runnable {
|
||||
this.listener = lsnr;
|
||||
if (listener != null) proc.getStatistics().addTextListener(listener);
|
||||
}
|
||||
|
||||
public void addRemoteStateListener(RemoteStateListener rsl) {
|
||||
if (proc != null) proc.addListener(rsl);
|
||||
}
|
||||
|
||||
public void setDoRestart(boolean restart) {
|
||||
doRestart = restart;
|
||||
|
@@ -1,8 +1,5 @@
|
||||
package eva2.server.go.problems;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.BitSet;
|
||||
|
||||
import eva2.gui.BeanInspector;
|
||||
|
||||
/**
|
||||
@@ -34,7 +31,7 @@ public class MatlabEvalMediator implements Runnable {
|
||||
boolean quit = false;
|
||||
volatile Object optSolution = null;
|
||||
volatile Object[] optSolSet = null;
|
||||
// MatlabProblem mp = null;
|
||||
MatlabProblem mp = null;
|
||||
// no good: even when waiting for only 1 ms the Matlab execution time increases by a factor of 5-10
|
||||
final static int sleepTime = 0;
|
||||
|
||||
@@ -45,7 +42,7 @@ public class MatlabEvalMediator implements Runnable {
|
||||
* @return
|
||||
*/
|
||||
double[] requestEval(MatlabProblem mp, Object x) {
|
||||
// this.mp = mp;
|
||||
this.mp = mp;
|
||||
question = x;
|
||||
// System.err.println("IN REQUESTEVAL, x is " + BeanInspector.toString(x));
|
||||
if (question.getClass().isArray()) {
|
||||
@@ -54,11 +51,12 @@ public class MatlabEvalMediator implements Runnable {
|
||||
// BitSet b = (BitSet)x;
|
||||
// Integer.decode()
|
||||
//
|
||||
if (question == null) System.err.println("Error: requesting evaluation for null array!");
|
||||
} else System.err.println("Error, requesting evaluation for non array!");
|
||||
|
||||
requesting = true;
|
||||
// int k=0;
|
||||
// System.out.println("Requesting eval for " + BeanInspector.toString(x) + ", req state is " + requesting + "\n");
|
||||
mp.log("-- Requesting eval for " + BeanInspector.toString(x) + ", req state is " + requesting + "\n");
|
||||
while (requesting && !quit) {
|
||||
// wait for matlab to answer the question
|
||||
if (sleepTime > 0) try { Thread.sleep(sleepTime); } catch(Exception e) {};
|
||||
@@ -67,8 +65,9 @@ public class MatlabEvalMediator implements Runnable {
|
||||
// }
|
||||
// k++;
|
||||
}
|
||||
// System.out.println("Requesting done \n");
|
||||
mp.log("-- Requesting done\n");
|
||||
// matlab is finished, answer is here
|
||||
//return null;
|
||||
return getAnswer(); // return to JE with answer
|
||||
}
|
||||
|
||||
@@ -102,11 +101,12 @@ public class MatlabEvalMediator implements Runnable {
|
||||
* @return
|
||||
*/
|
||||
public Object getQuestion() {
|
||||
// mp.log("-- Question: " + BeanInspector.toString(question) + "\n");
|
||||
mp.log("-- Question: " + BeanInspector.toString(question) + "\n");
|
||||
return question;
|
||||
}
|
||||
|
||||
double[] getAnswer() {
|
||||
mp.log("-- mediator delivering " + BeanInspector.toString(answer) + "\n");
|
||||
return answer;
|
||||
}
|
||||
|
||||
@@ -116,10 +116,14 @@ public class MatlabEvalMediator implements Runnable {
|
||||
* @param y
|
||||
*/
|
||||
public void setAnswer(double[] y) {
|
||||
// mp.log("-- setAnswer: " + BeanInspector.toString(y) + "\n");
|
||||
// System.err.println("answer is " + BeanInspector.toString(y));
|
||||
if (y==null) {
|
||||
System.err.println("Error: Matlab function returned null array - this is bad.");
|
||||
System.err.println("X-value was " + BeanInspector.toString(getQuestion()));
|
||||
}
|
||||
answer = y;
|
||||
requesting = false; // answer is finished, break request loop
|
||||
mp.log("-- setAnswer: " + BeanInspector.toString(y) + ", req state is " + requesting + "\n");
|
||||
}
|
||||
|
||||
void setFinished(boolean val) {
|
||||
|
@@ -30,13 +30,13 @@ import eva2.server.stat.InterfaceTextListener;
|
||||
*/
|
||||
public class MatlabProblem extends AbstractOptimizationProblem implements InterfaceTextListener, Serializable {
|
||||
private static final long serialVersionUID = 4913310869887420815L;
|
||||
public static final boolean TRACE = true;
|
||||
public static boolean TRACE = false;
|
||||
transient OptimizerRunnable runnable = null;
|
||||
protected boolean allowSingleRunnable = true;
|
||||
protected int problemDimension = 10;
|
||||
transient PrintStream dos = null;
|
||||
private double range[][] = null;
|
||||
private static final String defTestOut = "matlabproblem-testout.dat";
|
||||
private static String defTestOut = "matlabproblem-debug.log";
|
||||
int verbosityLevel = 0;
|
||||
private MatlabEvalMediator handler = null;
|
||||
private boolean isDouble = true;
|
||||
@@ -123,18 +123,35 @@ public class MatlabProblem extends AbstractOptimizationProblem implements Interf
|
||||
// System.err.println("range: " + BeanInspector.toString(range));
|
||||
initTemplate();
|
||||
// res = new ResultArr();
|
||||
if ((dos == null) && TRACE) {
|
||||
try {
|
||||
dos = new PrintStream(new FileOutputStream(outFile));
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
setDebugOut(TRACE, defTestOut);
|
||||
|
||||
// log("range is " + BeanInspector.toString(range)+ "\n");
|
||||
// log("template len: " + ((ESIndividualDoubleData)m_Template).getDGenotype().length + "\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* If swtch is true and no output file is open yet, open a new one which will be used for debug output.
|
||||
* if fname is null, the default filename will be used.
|
||||
* if swtch is false, close the output file and deactivate debug output.
|
||||
*
|
||||
* @param swtch
|
||||
* @param fname
|
||||
*/
|
||||
public void setDebugOut(boolean swtch, String fname) {
|
||||
TRACE=swtch;
|
||||
if (!swtch && (dos != null)) {
|
||||
dos.close();
|
||||
dos = null;
|
||||
} else if ((dos == null) && swtch) {
|
||||
try {
|
||||
dos = new PrintStream(new FileOutputStream(fname==null ? defTestOut : fname));
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setStatsOutput(int verboLevel) {
|
||||
if ((verboLevel >= 0) && (verboLevel <= 3)) {
|
||||
verbosityLevel = verboLevel;
|
||||
@@ -386,10 +403,10 @@ public class MatlabProblem extends AbstractOptimizationProblem implements Interf
|
||||
|
||||
@Override
|
||||
public void evaluate(AbstractEAIndividual indy) {
|
||||
log("evaluating " + BeanInspector.toString(indy) + "\n");
|
||||
log("evaluating " + AbstractEAIndividual.getDefaultStringRepresentation(indy) + "\n");
|
||||
double[] res = handler.requestEval(this, AbstractEAIndividual.getIndyData(indy));
|
||||
log("evaluated to " + BeanInspector.toString(res) + "\n");
|
||||
indy.SetFitness(res);
|
||||
// System.err.println("evaluated to " + BeanInspector.toString(res));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -19,24 +19,23 @@ class WaitForEvARunnable implements Runnable {
|
||||
public void run() {
|
||||
if (runnable != null) {
|
||||
mp.log("\nStarting optimize runnable!\n");
|
||||
|
||||
synchronized (runnable) {
|
||||
try {
|
||||
// whole optimization thread goes in here
|
||||
new Thread(runnable).start();
|
||||
mp.log("Starting optimize thread done!\n");
|
||||
mp.log("Started optimize thread\n");
|
||||
runnable.wait();
|
||||
// wait for the runnable to finish
|
||||
mp.log("After wait!\n");
|
||||
mp.log("runnable continues...\n");
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
mp.log("WaitForEvARunnable was interrupted with " + e.getMessage());
|
||||
}
|
||||
}
|
||||
try {
|
||||
mp.log("runnable.getDoubleSolution: " + BeanInspector.toString(runnable.getDoubleSolution()));
|
||||
mp.log("runnable.getIntegerSolution: " + BeanInspector.toString(runnable.getIntegerSolution()));
|
||||
mp.log("\ngetAllSols best: " + AbstractEAIndividual.getDefaultDataString(runnable.getGOParams().getOptimizer().getAllSolutions().getSolutions().getBestEAIndividual()));
|
||||
mp.log("runnable.getDoubleSolution: " + BeanInspector.toString(runnable.getDoubleSolution()) + "\n");
|
||||
mp.log("runnable.getIntegerSolution: " + BeanInspector.toString(runnable.getIntegerSolution()) + "\n");
|
||||
mp.log("getAllSols best: " + AbstractEAIndividual.getDefaultDataString(runnable.getGOParams().getOptimizer().getAllSolutions().getSolutions().getBestEAIndividual()) + "\n");
|
||||
mp.log("\n");
|
||||
// write results back to matlab
|
||||
mp.exportResultToMatlab(runnable);
|
||||
|
@@ -150,13 +150,13 @@ public class ClusterBasedNichingEA implements InterfacePopulationChangedEventLis
|
||||
population.incrGeneration();
|
||||
}
|
||||
|
||||
private void plot() {
|
||||
private void plot(int gen) {
|
||||
double[] a = new double[2];
|
||||
a[0] = 0.0;
|
||||
a[1] = 0.0;
|
||||
if (this.m_Problem instanceof TF1Problem) {
|
||||
// now i need to plot the pareto fronts
|
||||
Plot plot = new Plot("TF3Problem", "y1", "y2", a, a);
|
||||
Plot plot = new Plot("TF3Problem at gen. "+gen, "y1", "y2", a, a);
|
||||
plot.setUnconnectedPoint(0,0,0);
|
||||
plot.setUnconnectedPoint(1,5,0);
|
||||
GraphPointSet mySet = new GraphPointSet(10, plot.getFunctionArea());
|
||||
@@ -191,7 +191,7 @@ public class ClusterBasedNichingEA implements InterfacePopulationChangedEventLis
|
||||
InterfaceDataTypeDouble tmpIndy1, best;
|
||||
Population pop;
|
||||
|
||||
this.m_Topology = new TopoPlot("CBN-Species","x","y",a,a);
|
||||
this.m_Topology = new TopoPlot("CBN-Species at gen. " + gen,"x","y",a,a);
|
||||
this.m_Topology.gridx = 60;
|
||||
this.m_Topology.gridy = 60;
|
||||
this.m_Topology.setTopology((Interface2DBorderProblem)this.m_Problem);
|
||||
@@ -358,9 +358,9 @@ public class ClusterBasedNichingEA implements InterfacePopulationChangedEventLis
|
||||
// plot the populations
|
||||
if (this.m_ShowCycle > 0) {
|
||||
if ((this.m_Undifferentiated.getGeneration() == 0) || (this.m_Undifferentiated.getGeneration() == 1) || (this.m_Undifferentiated.getGeneration() == 2)) {
|
||||
this.plot();
|
||||
this.plot(this.m_Undifferentiated.getGeneration());
|
||||
} else {
|
||||
if (this.m_Undifferentiated.getGeneration()%this.m_ShowCycle == 0) this.plot();
|
||||
if (this.m_Undifferentiated.getGeneration()%this.m_ShowCycle == 0) this.plot(this.m_Undifferentiated.getGeneration());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -706,7 +706,7 @@ public class ClusterBasedNichingEA implements InterfacePopulationChangedEventLis
|
||||
* @return description
|
||||
*/
|
||||
public String globalInfo() {
|
||||
return "This is a versatible species based niching EA method.";
|
||||
return "This is a versatile species based niching EA method.";
|
||||
}
|
||||
/** This method will return a naming String
|
||||
* @return The name of the algorithm
|
||||
|
Reference in New Issue
Block a user