diff --git a/resources/MatlabInterface/@JEInterface/JEInterface.m b/resources/MatlabInterface/@JEInterface/JEInterface.m index bd973e3c..d647155a 100644 --- a/resources/MatlabInterface/@JEInterface/JEInterface.m +++ b/resources/MatlabInterface/@JEInterface/JEInterface.m @@ -12,6 +12,18 @@ function int = JEInterface(interfaceName, fhandle, range, varargin) % JavaEvA default values. % defaultArgs: (optional) additional constant argument to the target % function, empty by default. +% Recognized options are: +% TolX: convergence criterion in the solution space +% TolFun: convergence criterion in the target space +% MaxFunEvals: maximum number of function evaluations +% Display: 'off'/'final'/'notify'/'iter', where 'notify' corresponds to +% displaying every k-th iteration, which k=10 as default. +% The termination criterion of a run is a combination of the TolX, TolFun and +% MaxFunEvals criteria. The run terminates if MaxFunEvals has been reached +% or the best solution changes both in domain and codomain less than TolX +% and TolFun for a certain time, e.g. 100 evaluations. +% To ignore a criterion, set it to 0. E.g. to perform 10^5 evaluations in +% any case, set TolX=TolFun=0 and MaxFunEvals=10^5. int.args = []; int.opts = optimset('MaxFunEvals', javaeva.OptimizerFactory.getDefaultFitCalls, 'TolX', 1e-4, 'TolFun', 1e-4); diff --git a/resources/MatlabInterface/@JEInterface/optimize.m b/resources/MatlabInterface/@JEInterface/optimize.m index effae025..f6e59dc9 100644 --- a/resources/MatlabInterface/@JEInterface/optimize.m +++ b/resources/MatlabInterface/@JEInterface/optimize.m @@ -1,18 +1,18 @@ function retInt = optimize(int, optType, varargin) % Start a JavaEvA optimization run. % optimize(interface, optType, [, outputFilePrefix ] ) -% where +% where % interface: instance of JEInterface % optType: integer indicating the type of the optimization strategy % to use. % resultFilePrefix: (optional) char prefix for an optional verbose % output file -if (int.finished == 0) +if (int.finished == 0) error('please wait for the current run to finish'); end if ((nargin == 2) || (nargin == 3)) - if (nargin == 3) + if (nargin == 3) outputFilePrefix = varargin{1}; else outputFilePrefix = 'none'; @@ -27,9 +27,9 @@ if ((nargin == 2) || (nargin == 3)) xTol = int.opts.TolX; maxEvals = int.opts.MaxFunEvals; fTol = int.opts.TolFun; - + import javaeva.server.go.operators.terminators.PhenotypeConvergenceTerminator; - import javaeva.server.go.operators.terminators.FitnessConvergenceTerminator; + import javaeva.server.go.operators.terminators.FitnessConvergenceTerminator; import javaeva.server.go.operators.terminators.CombinedTerminator; import javaeva.server.go.operators.terminators.EvaluationTerminator; import javaeva.OptimizerFactory; @@ -39,6 +39,7 @@ if ((nargin == 2) || (nargin == 3)) % values of 1e-4 in . Thats what we do as well if (isempty(int.opts.TolX)) ; xTol = 1e-4; end if (isempty(int.opts.TolFun)) ; fTol = 1e-4; end + % construct Terminators if ((xTol > 0) && (fTol > 0)) % both criteria are given, use combination @@ -48,12 +49,12 @@ if ((nargin == 2) || (nargin == 3)) else if (fTol > 0 ) % only fitness covnergence convTerm = FitnessConvergenceTerminator(fTol, 100, 1, 1); else - convTerm = 'undef'; % signal that there is no terminator yet + convTerm = 'undef'; % signal that there is no terminator yet end end end - if (ischar(convTerm)) % if no convergence terminator is defined so far, use fitness calls + if (ischar(convTerm)) % if no convergence terminator is defined so far, use fitness calls if (isempty(maxEvals)) error('Error: no termination criterion defined! Please check options.'); % int.opts.MaxFunEvals = OptimizerFactory.getDefaultFitCalls; @@ -61,9 +62,9 @@ if ((nargin == 2) || (nargin == 3)) end convTerm = EvaluationTerminator(maxEvals); javaeva.OptimizerFactory.setTerminator(convTerm); - else % there is a convergence terminator + else % there is a convergence terminator javaeva.OptimizerFactory.setTerminator(convTerm); % so set it - if (~isempty(maxEvals)) + if (~isempty(maxEvals) && (maxEvals > 0)) % if TolX/TolFun plus MaxFunEvals is defined additionally, combine an % EvaluationTerminator in disjunction, as Matlab does. javaeva.OptimizerFactory.addTerminator(EvaluationTerminator(maxEvals), 0); @@ -73,14 +74,21 @@ if ((nargin == 2) || (nargin == 3)) % set display if (strcmp(int.opts.Display,'off') || isempty(int.opts.Display)) int.mp.setStatsOutput(0); - elseif (strcmp(int.opts.Display, 'iter')) + elseif (strcmp(int.opts.Display, 'final')) int.mp.setStatsOutput(1); + elseif (strcmp(int.opts.Display, 'notify')) + % 'notify' is not the perfect notion for "show every k-th + % iteration", but optimset wont allow changing names. + int.mp.setStatsOutput(2); + elseif (strcmp(int.opts.Display, 'iter')) + % this should rather be 2 in JE slang, but in matlab slang its more like 3 + int.mp.setStatsOutput(3); else - error('invalid Display option, only off/iter are recognized'); + error('invalid Display option, only off/final/notify/iter are recognized'); end - + int=runEvalLoopJE(int, 1, optType, outputFilePrefix, -1, -1, -1); - + else error('Wrong number of arguments!') end diff --git a/resources/MatlabInterface/@JEInterface/runEvalLoopJE.m b/resources/MatlabInterface/@JEInterface/runEvalLoopJE.m index 1fae3eaf..cee8dc85 100644 --- a/resources/MatlabInterface/@JEInterface/runEvalLoopJE.m +++ b/resources/MatlabInterface/@JEInterface/runEvalLoopJE.m @@ -2,6 +2,10 @@ function int=runEvalLoopJE(int, optOrPostProc, optType, outputFilePrefix, steps, % Internal method starting a JavaEvA optimization loop. % Calling this directly may interfere with optimization. +% This function handles the communciation between JE and Matlab, main +% optimization configuration is done in the +% optimize/optimizeWith/postProcess functions from which this one should be +% called. % optOrPostProc: 1 for optimize, 2 for postProcess % optType, outputFilePrefix are parameters for optimize, dont care when % postprocessing. @@ -35,17 +39,19 @@ end % own stop button). we decide this by checking if the global variable % stopOptimization is empty. if it is then it is not the toolbox calling % and we create an own button to stop it. -if isempty(stopOptimization), - % create a cancel button box (case without SBtoolbox) - h=figure('Position',[100 600 250 80], 'MenuBar', 'none', 'Name', 'JavaEvA optimization running...', 'NumberTitle','off'); - uicontrol(h,'Style', 'pushbutton', 'String', 'Cancel', 'Position', [25 25 60 30], 'Callback', 'global stopOptimization; stopOptimization=1;'); - uicontrol(h,'Style', 'text', 'String', stopText, 'Position', [100 25 120 30]); - drawnow; - % set it to 0 now +if isempty(stopOptimization), + % set switch to 0 now stopOptimization = 0; + + % create a cancel button box (case without SBtoolbox) + boxHandle=figure('Position',[100 600 250 80], 'MenuBar', 'none', 'Name', 'JavaEvA optimization running...', 'NumberTitle','off'); + uicontrol(boxHandle,'Style', 'pushbutton', 'String', 'Cancel', 'Position', [25 25 60 30], 'Callback', 'global stopOptimization; stopOptimization=1;'); + uicontrol(boxHandle,'Style', 'text', 'String', stopText, 'Position', [100 25 120 30]); + drawnow; % set flag for non toolbox optimization nontoolboxopt = 1; else + % disp('seems like the toolbox is going on'); % its an estimation using the toolbox' parameter estimation thing nontoolboxopt = 0; end @@ -77,10 +83,12 @@ catch disp('Error in evaluate!'); %int.mediator.quit; % just in case %int.mediator=''; - if (nontoolboxopt == 1) - if (ishandle(h)) , close(h); end - clear global stopOptimization - end + + % why should this be done more than once in the end? + %if (nontoolboxopt == 1) + % if (ishandle(int.boxHandle)) , close(int.boxHandle); int.boxHandle=''; end + % clear global stopOptimization + %end end % write back results @@ -94,6 +102,6 @@ int.mediator=''; % and not from the toolboxes parameter estimation function (which has an % own stop button). we decide this by checking nontoolboxopt if nontoolboxopt == 1, - if (ishandle(h)) , close(h); end + if (ishandle(boxHandle)) , close(boxHandle); end clear global stopOptimization end diff --git a/resources/MatlabInterface/@JEInterface/stopOptimize.m b/resources/MatlabInterface/@JEInterface/stopOptimize.m index 5f99303b..19efcea4 100644 --- a/resources/MatlabInterface/@JEInterface/stopOptimize.m +++ b/resources/MatlabInterface/@JEInterface/stopOptimize.m @@ -16,6 +16,7 @@ if (nargin > 1) && (ischar(varargin{1}) && (strcmp(varargin{1},'kill')==1)) JEMediator.quit; % just in case JEMediator=''; clear global JEMediator; + clear global stopOptimization; else disp('no mediator to kill'); end diff --git a/resources/ParticleSwarmOptimization.html b/resources/ParticleSwarmOptimization.html index 66bf080e..826234d8 100644 --- a/resources/ParticleSwarmOptimization.html +++ b/resources/ParticleSwarmOptimization.html @@ -11,13 +11,31 @@ behaviour seen in animals like birds or ants. A swarm of particles is a set of i "flying" across the search space with individual velocity vectors. There is no selection as in classic Evolutionary Algorithms. Instead, the individuals exchange knowledge about the space they have come across. Each one is attracted to the best position the individual has seen so far (cognitive -component) and to the best position known by its neighbors (social component).
+component) and to the best position known by its neighbors (social component). +

The neighborhood is defined by the swarm velocity, which may be a linear ordering, a grid and some others. The influence of the velocity of the last time-step is taken into account using an inertness/ constriction parameter, which controls the convergence behaviour of the swarm. +

The influence of social and cognitive attraction are weighed using the phi parameters. In the constriction variant there is a dependence enforced between constriction and the phi, making sure that -the swarm converges slowly but steadily, see the publications of Clerc, e.g.
+the swarm converges slowly but steadily, see the publications of M.Clerc, e.g. +Typical values for the attractor weights are phi1=phi2=2.05. +

+The topology defines the communication structure of the swarm. In linear topology, each particle has contact +to n others in two directions, so there is a linear overlay structure. The grid topology connects a particle +in 4 directions, while the star variant is completely connected. The random variant just connects each +particle to k others by random and anew in every generation cycle. +Basically, the more connections are available, the quicker will information about good areas spread through +the swarm and lead to quicker convergence, thereby increasing the risk of converging prematurely. +By default, the random (e.g. with range=4) or grid structure (e.g. with range=2) are good choices. +

+

+The multi-swarm approach splits the main swarm in sub-swarms defined by the distance to a local "leader", +as in the dynamic multi-swarm approaches by Shi and Branke, for example. The tree structure orders the +swarm to a tree of degree k, where the fittest individuals are on top and inform all their children nodes. +In this case, the higher the degree, the quicker will information spread. HPSO is a hierarchical tree variant +by Janson and Middendorf, 2005. \ No newline at end of file diff --git a/src/javaeva/OptimizerRunnable.java b/src/javaeva/OptimizerRunnable.java index a0dea86d..aad3606b 100644 --- a/src/javaeva/OptimizerRunnable.java +++ b/src/javaeva/OptimizerRunnable.java @@ -142,4 +142,14 @@ public class OptimizerRunnable implements Runnable { return ((InterfaceDataTypeInteger)indy).getIntegerData(); } else return null; } + + /** + * Set the verbosity level in the statistics module to the given value. See StatsParameter. + * @param vLev + */ + public void setVerbosityLevel(int vLev) { + if (vLev >= 0 && vLev < proc.getStatistics().getStatisticsParameter().getOutputVerbosity().getTags().length) { + proc.getStatistics().getStatisticsParameter().getOutputVerbosity().setSelectedTag(vLev); + } else System.err.println("Invalid verbosity leveln in OptimizerRunnable.setVerbosityLevel!"); + } } \ No newline at end of file diff --git a/src/javaeva/gui/JModuleGeneralPanel.java b/src/javaeva/gui/JModuleGeneralPanel.java index b6cd790f..d79cf26a 100644 --- a/src/javaeva/gui/JModuleGeneralPanel.java +++ b/src/javaeva/gui/JModuleGeneralPanel.java @@ -22,6 +22,7 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JComponent; +import javax.swing.JOptionPane; import javax.swing.JPanel; import wsi.ra.jproxy.RMIProxyLocal; @@ -86,6 +87,7 @@ public class JModuleGeneralPanel implements RemoteStateListener, Serializable { m_Adapter.startOpt(); m_actStop.setEnabled(true); m_RunButton.setEnabled(false); + m_PPButton.setEnabled(false); // m_RestartButton.setEnabled(false); m_JHelpButton.setEnabled(true); } catch (Exception ee) { @@ -124,7 +126,7 @@ public class JModuleGeneralPanel implements RemoteStateListener, Serializable { m_PPButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e){ try { - m_Adapter.startPostProcessing(); + if (!m_Adapter.startPostProcessing()) JOptionPane.showMessageDialog(null, "Post processing seems deactivated! Check the settings.", "Warning", JOptionPane.WARNING_MESSAGE); // m_actStop.setEnabled(true); // m_RunButton.setEnabled(false); } catch (Exception ee) { diff --git a/src/javaeva/server/go/problems/F14Problem.java b/src/javaeva/server/go/problems/F14Problem.java index 03c7ed57..8df4d81e 100644 --- a/src/javaeva/server/go/problems/F14Problem.java +++ b/src/javaeva/server/go/problems/F14Problem.java @@ -9,9 +9,10 @@ import javaeva.server.go.individuals.ESIndividualDoubleData; * Time: 19:15:03 * To change this template use File | Settings | File Templates. */ -public class F14Problem extends F1Problem implements java.io.Serializable { +public class F14Problem extends F1Problem implements InterfaceMultimodalProblem, java.io.Serializable { double rotation = 0.; - + double rotationDX = 2; + public F14Problem() { this.m_Template = new ESIndividualDoubleData(); this.m_ProblemDimension = 2; @@ -35,8 +36,8 @@ public class F14Problem extends F1Problem implements java.io.Serializable { */ public double[] eval(double[] x) { double[] result = new double[1]; - double x0 = x[0]-2; - double x1 = x[1]-2; + double x0 = x[0]-rotationDX; + double x1 = x[1]-rotationDX; if (rotation != 0.) { double cosw = Math.cos(rotation); double sinw = Math.sin(rotation); @@ -59,6 +60,10 @@ public class F14Problem extends F1Problem implements java.io.Serializable { public void setRotation(double rotation) { this.rotation = 2 * Math.PI * rotation / 360.0; } + + public String rotationTipText() { + return "The rotation angle in degrees."; + } /** This method returns a string describing the optimization problem. * @return The description. @@ -67,7 +72,7 @@ public class F14Problem extends F1Problem implements java.io.Serializable { String result = ""; result += "F14 function:\n"; - result += "Several local minima in a straight line\n"; + result += "Several local minima in linear order which may be rotated.\n"; //result += this.m_Template.getSolutionRepresentationFor(); return result; } @@ -80,13 +85,13 @@ public class F14Problem extends F1Problem implements java.io.Serializable { * @return The name. */ public String getName() { - return "F14 Problem"; + return "F14-Problem"; } /** This method returns a global info string * @return description */ public String globalInfo() { - return "F14 function."; + return "F14 function: numerous optima in linear order which may be rotated."; } } diff --git a/src/javaeva/server/go/problems/MatlabProblem.java b/src/javaeva/server/go/problems/MatlabProblem.java index e0a70857..a176a502 100644 --- a/src/javaeva/server/go/problems/MatlabProblem.java +++ b/src/javaeva/server/go/problems/MatlabProblem.java @@ -32,7 +32,7 @@ public class MatlabProblem extends AbstractProblemDouble implements InterfaceTex transient PrintStream dos = null; protected double[][] range = null; private static final String defTestOut = "matlabproblem-testout.dat"; - boolean forwardStatisticsOutput = false; + int verbosityLevel = 0; private MatlabEvalMediator handler = null; public static boolean hideFromGOE = true; @@ -133,8 +133,11 @@ public class MatlabProblem extends AbstractProblemDouble implements InterfaceTex // this.jmInterface = jmInterface; // } - public void setStatsOutput(boolean forwardStats) { - forwardStatisticsOutput = forwardStats; + public void setStatsOutput(int verboLevel) { + if ((verboLevel >= 0) && (verboLevel <= 3)) { + verbosityLevel = verboLevel; + } + else System.err.println("Error, invalid verbosity level for statistics output!"); } public String jmiInterfaceNameTipText() { @@ -225,6 +228,8 @@ public class MatlabProblem extends AbstractProblemDouble implements InterfaceTex runnable = OptimizerFactory.getOptRunnable(optType, (AbstractOptimizationProblem)this, outputFilePrefix); // runnable.getGOParams().setPostProcessParams(new PostProcessParams(0, 0.01, 5)); runnable.setTextListener(this); + runnable.setVerbosityLevel(verbosityLevel); + if ((specParams != null) && (specParams.length > 0)) { if ((specValues == null) || (specValues.length != specParams.length)) { System.err.println("mismatching value list for parameter arguments: " + specValues); @@ -388,7 +393,7 @@ public class MatlabProblem extends AbstractProblemDouble implements InterfaceTex } public void print(String str) { - if (forwardStatisticsOutput) { + if (verbosityLevel > 0) { // matlab displays sysout output in the command window, so we simply use this channel System.out.print(str); } diff --git a/src/javaeva/server/go/strategies/ParticleSwarmOptimization.java b/src/javaeva/server/go/strategies/ParticleSwarmOptimization.java index 24ee705f..a825ed35 100644 --- a/src/javaeva/server/go/strategies/ParticleSwarmOptimization.java +++ b/src/javaeva/server/go/strategies/ParticleSwarmOptimization.java @@ -56,8 +56,8 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se protected int m_TopologyRange = 2; protected double m_InitialVelocity = 0.2; protected double m_SpeedLimit = 0.1; - protected double m_Phi1 = 2.8; - protected double m_Phi2 = 1.3; + protected double m_Phi1 = 2.05; + protected double m_Phi2 = 2.05; // for multi-swarm topology: radius of the swarm relative to the range protected double m_swarmRadius = 0.2; // for multi-swarm: maximum sub swarm size. zero means unlimited @@ -105,7 +105,7 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se public ParticleSwarmOptimization() { this.m_Topology = new SelectedTag( "Linear", "Grid", "Star", "Multi-Swarm", "Tree", "HPSO", "Random" ); - m_Topology.setSelectedTag(2); + m_Topology.setSelectedTag(1); algType = new SelectedTag("Inertness", "Constriction"); algType.setSelectedTag(1); @@ -1680,7 +1680,7 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se setGOEShowProperties(getClass()); } - public void setGOEShowProperties(Class cls) { + public void setGOEShowProperties(Class cls) { GenericObjectEditor.setShowProperty(cls, "topologyRange", (m_Topology.getSelectedTag().getID() < 2) || (m_Topology.getSelectedTag().getID() == 6)); GenericObjectEditor.setShowProperty(cls, "subSwarmRadius", (m_Topology.getSelectedTag().getID() == 3)); GenericObjectEditor.setShowProperty(cls, "subSwarmSize", (m_Topology.getSelectedTag().getID() == 3)); @@ -1821,17 +1821,18 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se return treeStruct; } - public void setTreeStruct(int treeStruct) { + public void SetTreeStruct(int treeStruct) { this.treeStruct = treeStruct; } - - public boolean isUseAlternative() { - return useAlternative; - } - - public void setUseAlternative(boolean useAlternative) { - this.useAlternative = useAlternative; - } + +// This was for testing rotation operators +// public boolean isUseAlternative() { +// return useAlternative; +// } +// +// public void setUseAlternative(boolean useAlternative) { +// this.useAlternative = useAlternative; +// } public int getTreeBranchDegree() { return treeBranchDeg; diff --git a/src/javaeva/server/modules/AbstractModuleAdapter.java b/src/javaeva/server/modules/AbstractModuleAdapter.java index 69e6b683..e02fe802 100644 --- a/src/javaeva/server/modules/AbstractModuleAdapter.java +++ b/src/javaeva/server/modules/AbstractModuleAdapter.java @@ -19,9 +19,6 @@ import java.util.Vector; import javaeva.gui.JTabbedModuleFrame; import javaeva.gui.LogPanel; import javaeva.server.go.InterfaceProcessor; -import javaeva.server.go.operators.postprocess.PostProcessParams; -import javaeva.server.stat.InterfaceTextListener; - import wsi.ra.jproxy.MainAdapterClient; import wsi.ra.jproxy.RemoteStateListener; /*==========================================================================* @@ -112,11 +109,14 @@ abstract public class AbstractModuleAdapter implements ModuleAdapter, Serializab } public boolean hasPostProcessing() { - return (m_Processor instanceof Processor); + return ((m_Processor instanceof Processor) && ((Processor)m_Processor).getGOParams().getPostProcessParams().isDoPostProcessing()); } - public void startPostProcessing() { - if (hasPostProcessing()) ((Processor)m_Processor).performPostProcessing(); + public boolean startPostProcessing() { + if (hasPostProcessing() && ((Processor)m_Processor).getGOParams().getPostProcessParams().isDoPostProcessing()) { + ((Processor)m_Processor).performPostProcessing(); + return true; + } else return false; } /** diff --git a/src/javaeva/server/modules/ModuleAdapter.java b/src/javaeva/server/modules/ModuleAdapter.java index 1285b6ac..db34626c 100644 --- a/src/javaeva/server/modules/ModuleAdapter.java +++ b/src/javaeva/server/modules/ModuleAdapter.java @@ -29,8 +29,16 @@ public interface ModuleAdapter extends RemoteStateListener { public void restartOpt(); public void stopOpt(); public void runScript(); + /** + * Return true if post processing is available in principle, else false. + * @return true if post processing is available in principle, else false + */ public boolean hasPostProcessing(); - public void startPostProcessing(); + /** + * Return true if post processing was performed, else false. + * @return true if post processing was performed, else false + */ + public boolean startPostProcessing(); public void addRemoteStateListener(RemoteStateListener x); public String getAdapterName(); public void setConnection(boolean flag); diff --git a/src/javaeva/server/modules/Processor.java b/src/javaeva/server/modules/Processor.java index 92b85ba0..c820e1f8 100644 --- a/src/javaeva/server/modules/Processor.java +++ b/src/javaeva/server/modules/Processor.java @@ -14,6 +14,7 @@ import javaeva.server.go.problems.AbstractOptimizationProblem; import javaeva.server.go.tools.RandomNumberGenerator; import javaeva.server.stat.InterfaceStatistics; import javaeva.server.stat.InterfaceTextListener; +import javaeva.server.stat.StatisticsWithGUI; import wsi.ra.jproxy.RemoteStateListener; /** @@ -144,8 +145,12 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo e.printStackTrace(); //m_Statistics.stopOptPerformed(false); setOptRunning(false); // normal finish - 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.performedStop(); // is only needed in client server mode + String errMsg = e.getMessage(); + if ((errMsg == null) || (errMsg.length() == 0)) errMsg="check console output for error messages."; + m_ListenerModule.updateProgress(0, "Error in optimization: " + errMsg); + } } return resPop; } @@ -266,7 +271,7 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo public String getInfoString() { //StringBuffer sb = new StringBuffer("processing "); StringBuffer sb = new StringBuffer(this.goParams.getProblem().getName()); - sb.append("/"); + sb.append("+"); sb.append(this.goParams.getOptimizer().getName()); // commented out because the number of multi-runs can be changed after start // so it might create misinformation (would still be the user's fault, though) @@ -315,7 +320,11 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo */ public Population performPostProcessing(PostProcessParams ppp, InterfaceTextListener listener) { if (ppp.isDoPostProcessing()) { - if (listener != null) listener.println("Post processing params: " + BeanInspector.toString(ppp)); + if (listener != null) { + listener.println("Post processing params: " + BeanInspector.toString(ppp)); + // if textwindow was closed, check if it should be reopened for pp + if (m_Statistics instanceof StatisticsWithGUI) ((StatisticsWithGUI)m_Statistics).maybeShowProxyPrinter(); + } Population resultPop = goParams.getOptimizer().getAllSolutions(); if (resultPop.getFunctionCalls() != goParams.getOptimizer().getPopulation().getFunctionCalls()) { // System.err.println("bad case in Processor::performNewPostProcessing "); diff --git a/src/javaeva/server/stat/AbstractStatistics.java b/src/javaeva/server/stat/AbstractStatistics.java index 2ab23589..7e969ad5 100644 --- a/src/javaeva/server/stat/AbstractStatistics.java +++ b/src/javaeva/server/stat/AbstractStatistics.java @@ -18,8 +18,8 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter private PrintWriter resultOut; public final static boolean TRACE = false; protected InterfaceStatisticsParameter m_StatsParams; - protected String startDate; - protected long startTime; +// protected String startDate; +// protected long startTime; /** * Keep track of all intermediate fitness values, best, avg. and worst, averaging over all runs @@ -70,20 +70,22 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter return textListeners.remove(listener); } - protected void initOutput() { - SimpleDateFormat formatter = new SimpleDateFormat( - "E'_'yyyy.MM.dd'_at_'hh.mm.ss"); - startDate = formatter.format(new Date()); - startTime = System.currentTimeMillis(); + /** + * Collect start date and time of the run and if indicated, open a file output stream. + * + * @param infoString + */ + protected void initOutput(String infoString) { + SimpleDateFormat formatter = new SimpleDateFormat("E'_'yyyy.MM.dd'_at_'hh.mm.ss"); + String startDate = formatter.format(new Date()); // open the result file: - String resFName = m_StatsParams.getResultFileName(); if ((m_StatsParams.getOutputTo().getSelectedTagID()!=1) // not "text only" && (m_StatsParams.getOutputVerbosity().getSelectedTagID() > StatsParameter.VERBOSITY_NONE)) { // verbosity accordingly high //!resFName.equalsIgnoreCase("none") && !resFName.equals("")) { - String name = resFName + "_" + startDate + ".txt"; - if (TRACE) System.out.println("FileName =" + name); + String fname = makeOutputFileName(m_StatsParams.getResultFilePrefix(), infoString, startDate); + if (TRACE) System.out.println("FileName =" + fname); try { - resultOut = new PrintWriter(new FileOutputStream(name)); + resultOut = new PrintWriter(new FileOutputStream(fname)); } catch (Exception e) { e.printStackTrace(); System.out.println("Error: " + e); @@ -93,6 +95,9 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter } else resultOut = null; } + private String makeOutputFileName(String prefix, String infoString, String startDate) { + return (prefix + "_" + infoString).replace(' ', '_') + "_" + startDate + ".txt"; + } /** * If set to true, before every run the parameters will be stored to a file at the start * of each run. Default is true. @@ -111,7 +116,7 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter optRunsPerformed = 0; convergenceCnt = 0; if (saveParams) m_StatsParams.saveInstance(); - initOutput(); + initOutput(infoString); bestCurrentIndividual = null; bestIndivdualAllover = null; if (refineMultiRuns) meanCollection = new ArrayList(); diff --git a/src/javaeva/server/stat/InterfaceStatisticsParameter.java b/src/javaeva/server/stat/InterfaceStatisticsParameter.java index 247e4de5..a59596fb 100644 --- a/src/javaeva/server/stat/InterfaceStatisticsParameter.java +++ b/src/javaeva/server/stat/InterfaceStatisticsParameter.java @@ -46,8 +46,8 @@ public interface InterfaceStatisticsParameter { public SelectedTag getPlotFitness(); public void setPlotFitness(SelectedTag newMethod); - public String getResultFileName(); - public void SetResultFileName(String x); + public String getResultFilePrefix(); + public void SetResultFilePrefix(String x); public void setConvergenceRateThreshold(double x); public double getConvergenceRateThreshold(); diff --git a/src/javaeva/server/stat/StatisticsStandalone.java b/src/javaeva/server/stat/StatisticsStandalone.java index 3d91b78e..b33d49fc 100644 --- a/src/javaeva/server/stat/StatisticsStandalone.java +++ b/src/javaeva/server/stat/StatisticsStandalone.java @@ -70,7 +70,7 @@ public class StatisticsStandalone extends AbstractStatistics implements Interfac */ public StatisticsStandalone(String resultFileName) { this(new StatsParameter()); - m_StatsParams.SetResultFileName(resultFileName); + m_StatsParams.SetResultFilePrefix(resultFileName); } /** diff --git a/src/javaeva/server/stat/StatisticsWithGUI.java b/src/javaeva/server/stat/StatisticsWithGUI.java index d9ebd29e..dbee1b12 100644 --- a/src/javaeva/server/stat/StatisticsWithGUI.java +++ b/src/javaeva/server/stat/StatisticsWithGUI.java @@ -100,7 +100,6 @@ public class StatisticsWithGUI extends AbstractStatistics implements Serializabl */ public synchronized void startOptPerformed(String infoString, int runNumber, Object goParams) { super.startOptPerformed(infoString, runNumber, goParams); - m_GraphInfoString = infoString; // m_TextCounter = m_StatisticsParameter.GetTextoutput(); @@ -136,11 +135,15 @@ public class StatisticsWithGUI extends AbstractStatistics implements Serializabl // m_ConvergenceCnt = 0; // } } - + + public void maybeShowProxyPrinter() { + if (m_ProxyPrinter != null) m_ProxyPrinter.setShow((m_StatsParams).isShowTextOutput()); + } + protected void initPlots(List description) { if (TRACE) System.out.println("initPlots"); - if (m_ProxyPrinter != null) m_ProxyPrinter.setShow((m_StatsParams).isShowTextOutput()); + maybeShowProxyPrinter(); m_FitnessFrame = new GraphWindow[description.size()]; for (int i = 0; i < m_FitnessFrame.length; i++) { diff --git a/src/javaeva/server/stat/StatsParameter.java b/src/javaeva/server/stat/StatsParameter.java index ae9aa4cc..3b429fc6 100644 --- a/src/javaeva/server/stat/StatsParameter.java +++ b/src/javaeva/server/stat/StatsParameter.java @@ -41,7 +41,7 @@ public class StatsParameter implements InterfaceStatisticsParameter, Serializabl public final static int VERBOSITY_FINAL = 1; public final static int VERBOSITY_KTH_IT = 2; public final static int VERBOSITY_ALL = 3; - SelectedTag outputVerbosity = new SelectedTag("No output", "Results", "K-th iteration", "All iterations"); + SelectedTag outputVerbosity = new SelectedTag("No output", "Final results", "K-th iterations", "All iterations"); SelectedTag outputTo = new SelectedTag("File (current dir.)", "Text-window", "Both file and text-window"); private int verboK = 10; @@ -125,6 +125,7 @@ public class StatsParameter implements InterfaceStatisticsParameter, Serializabl m_PlotFitness = Source.m_PlotFitness; m_MultiRuns = Source.m_MultiRuns; m_ResultFilePrefix = Source.m_ResultFilePrefix; + verboK = Source.verboK; } /** @@ -268,7 +269,7 @@ public class StatsParameter implements InterfaceStatisticsParameter, Serializabl /** * */ - public void SetResultFileName(String x) { + public void SetResultFilePrefix(String x) { if (x==null) m_ResultFilePrefix = ""; else m_ResultFilePrefix = x; } @@ -276,7 +277,7 @@ public class StatsParameter implements InterfaceStatisticsParameter, Serializabl /** * */ - public String getResultFileName() { + public String getResultFilePrefix() { return m_ResultFilePrefix; }