diff --git a/src/eva2/client/EvAClient.java b/src/eva2/client/EvAClient.java index 129476da..61c6ad02 100644 --- a/src/eva2/client/EvAClient.java +++ b/src/eva2/client/EvAClient.java @@ -63,11 +63,11 @@ import eva2.gui.LogPanel; import eva2.server.EvAServer; import eva2.server.go.InterfaceGOParameters; import eva2.server.modules.AbstractModuleAdapter; +import eva2.server.modules.GOParameters; import eva2.server.modules.GenericModuleAdapter; import eva2.server.modules.ModuleAdapter; import eva2.server.stat.AbstractStatistics; import eva2.server.stat.InterfaceStatisticsParameter; -import eva2.server.stat.StatsParameter; import eva2.tools.BasicResourceLoader; import eva2.tools.EVAERROR; import eva2.tools.EVAHELP; @@ -86,6 +86,7 @@ public class EvAClient implements RemoteStateListener, Serializable { public static boolean TRACE = false; public JEFrame m_Frame; + Runnable initRnbl = null; private EvAComAdapter m_ComAdapter; private transient JMenuBar m_barMenu; @@ -148,7 +149,9 @@ public class EvAClient implements RemoteStateListener, Serializable { /** * Constructor of GUI of EvA2. * Works as client for the EvA2 server. - * + * Note that the EvAClient initialized multi-threaded for efficiency. Use {@link #awaitGuiInitialized()} + * to await full initialization if necessary. + * */ public EvAClient(final String hostName) { this(hostName, null, false, false); @@ -156,6 +159,8 @@ public class EvAClient implements RemoteStateListener, Serializable { /** * A constructor. Splash screen is optional, Gui is activated, no parent window. + * Note that the EvAClient initialized multi-threaded for efficiency. Use {@link #awaitGuiInitialized()} + * to await full initialization if necessary. * * @see #EvAClient(String, Window, String, boolean, boolean, boolean) * @param hostName @@ -164,11 +169,13 @@ public class EvAClient implements RemoteStateListener, Serializable { * @param nosplash */ public EvAClient(final String hostName, final String paramsFile, boolean autorun, boolean nosplash) { - this(hostName, null, paramsFile, autorun, nosplash, false); + this(hostName, null, paramsFile, null, autorun, nosplash, false); } /** * A constructor with optional spash screen. + * Note that the EvAClient initialized multi-threaded for efficiency. Use {@link #awaitGuiInitialized()} + * to await full initialization if necessary. * @see #EvAClient(String, String, boolean, boolean) * * @param hostName @@ -180,7 +187,26 @@ public class EvAClient implements RemoteStateListener, Serializable { } /** - * A constructor with optional spash screen. + * A constructor with optional splash screen. + * Note that the EvAClient initialized multi-threaded for efficiency. Use {@link #awaitGuiInitialized()} + * to await full initialization if necessary. + * + * @see #EvAClient(String, String, boolean, boolean) + * @param hostName + * @param paramsFile + * @param autorun + * @param noSplash + * @param noGui + */ + public EvAClient(final String hostName, String paramsFile, boolean autorun, boolean noSplash, boolean noGui) { + this(hostName, null, paramsFile, null, autorun, noSplash, noGui); + } + + /** + * A constructor with optional splash screen. + * Note that the EvAClient initialized multi-threaded for efficiency. Use {@link #awaitGuiInitialized()} + * to await full initialization if necessary. + * * @see #EvAClient(String, String, boolean, boolean) * * @param hostName @@ -189,11 +215,17 @@ public class EvAClient implements RemoteStateListener, Serializable { * @param noSplash * @param noGui */ - public EvAClient(final String hostName, String paramsFile, boolean autorun, boolean noSplash, boolean noGui) { - this(hostName, null, paramsFile, autorun, noSplash, noGui); + public EvAClient(final String hostName, InterfaceGOParameters goParams, boolean autorun, boolean noSplash, boolean noGui) { + this(hostName, null, null, goParams, autorun, noSplash, noGui); } + /** - * Constructor of GUI of EvA2. Works as client for the EvA2 server. + * Constructor of GUI of EvA2. Works as client for the EvA2 server. GO parameters may be + * loaded from a file (paramsFile) or given directly as a java instance. Both may be null + * to start with standard parameters. If both are non null, the java instance has the + * higher priority. + * Note that the EvAClient initialized multi-threaded for efficiency. Use {@link #awaitGuiInitialized()} + * to await full initialization if necessary. * * @param hostName * @param parent @@ -202,8 +234,7 @@ public class EvAClient implements RemoteStateListener, Serializable { * @param noSplash * @param noGui */ - - public EvAClient(final String hostName, final Window parent, final String paramsFile, final boolean autorun, final boolean noSplash, final boolean noGui) { + public EvAClient(final String hostName, final Window parent, final String paramsFile, final InterfaceGOParameters goParams, final boolean autorun, final boolean noSplash, final boolean noGui) { final SplashScreenShell fSplashScreen = new SplashScreenShell(EvAInfo.splashLocation); // preload some classes (into system cache) in a parallel thread @@ -224,31 +255,53 @@ public class EvAClient implements RemoteStateListener, Serializable { m_ComAdapter = EvAComAdapter.getInstance(); - SwingUtilities.invokeLater( new Runnable() { + SwingUtilities.invokeLater( initRnbl = new Runnable() { public void run(){ - long startTime = System.currentTimeMillis(); - init(hostName, paramsFile, parent); // this takes a bit - long wait = System.currentTimeMillis() - startTime; - if (!autorun) { - if (!noSplash) try { - // if splashScreenTime has not passed, sleep some more - if (wait < splashScreenTime) Thread.sleep(splashScreenTime - wait); - } catch (Exception e) {} - } else { - if (!withGUI && (currentModuleAdapter instanceof GenericModuleAdapter)) { - // do not save new parameters for an autorun without GUI - they werent changed manually anyways. - ((GenericModuleAdapter)currentModuleAdapter).getStatistics().setSaveParams(false); - System.out.println("Autorun without GUI - not saving statistics parameters..."); + synchronized (this) { + long startTime = System.currentTimeMillis(); + init(hostName, paramsFile, goParams, parent); // this takes a bit + + long wait = System.currentTimeMillis() - startTime; + if (!autorun) { + if (!noSplash) try { + // if splashScreenTime has not passed, sleep some more + if (wait < splashScreenTime) Thread.sleep(splashScreenTime - wait); + } catch (Exception e) {} + } else { + if (!withGUI && (currentModuleAdapter instanceof GenericModuleAdapter)) { + // do not save new parameters for an autorun without GUI - they werent changed manually anyways. + ((GenericModuleAdapter)currentModuleAdapter).getStatistics().setSaveParams(false); + System.out.println("Autorun without GUI - not saving statistics parameters..."); + } + if (withGUI) frmMkr.onUserStart(); + else currentModuleAdapter.startOpt(); } - if (withGUI) frmMkr.onUserStart(); - else currentModuleAdapter.startOpt(); + // close splash screen + if (!noSplash && withGUI) fSplashScreen.dispose(); + notify(); } - // close splash screen - if (!noSplash && withGUI) fSplashScreen.dispose(); - } + } }); } + /** + * Since the constructor runs multi-threaded for efficiency, this method + * may be called to await the full initialization of a client instance. + * As soon as it returns, the EvAClient GUI is fully initialized. + */ + public void awaitGuiInitialized() { + if (initRnbl!=null) { + synchronized (initRnbl) { + try { + initRnbl.wait(); + initRnbl=null; + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + } + private void preloadClasses() { ClassPreloader cp = new ClassPreloader( "eva2.server.go.strategies.InterfaceOptimizer", "eva2.server.go.problems.InterfaceOptimizationProblem", "eva2.server.go.InterfaceTerminator"); new Thread(cp).start(); @@ -270,7 +323,7 @@ public class EvAClient implements RemoteStateListener, Serializable { /** * Sets given hostname and tries to load GOParamsters from given file if non null. */ - private void init(String hostName, String paramsFile, final Window parent) { + private void init(String hostName, String paramsFile, InterfaceGOParameters goParams, final Window parent) { //EVA_EDITOR_PROPERTIES useDefaultModule = EvAInfo.propDefaultModule(); @@ -304,7 +357,10 @@ public class EvAClient implements RemoteStateListener, Serializable { createActions(); } if (useDefaultModule != null) { - loadModuleFromServer(useDefaultModule, paramsFile);//loadSpecificModule + // if goParams are not defined and a params file is defined + // try to load parameters from file + if (goParams==null && (paramsFile!=null && (paramsFile.length()>0))) goParams = GOParameters.getInstance(paramsFile, false); + loadModuleFromServer(useDefaultModule, goParams);//loadSpecificModule } if (withGUI) { @@ -649,7 +705,7 @@ public class EvAClient implements RemoteStateListener, Serializable { /** * */ - private void loadModuleFromServer(String selectedModule, String paramsFile) { + private void loadModuleFromServer(String selectedModule, InterfaceGOParameters goParams) { if (m_ComAdapter.getHostName() == null) { System.err.println("error in loadModuleFromServer!"); return; @@ -691,7 +747,7 @@ public class EvAClient implements RemoteStateListener, Serializable { } else { Serializer.storeString("lastmodule.ser", selectedModule); - loadSpecificModule(selectedModule, paramsFile); + loadSpecificModule(selectedModule, goParams); if (withGUI) { m_actHost.setEnabled(true); @@ -735,11 +791,11 @@ public class EvAClient implements RemoteStateListener, Serializable { } else return false; } - private void loadSpecificModule(String selectedModule, String paramsFile) { + private void loadSpecificModule(String selectedModule, InterfaceGOParameters goParams) { ModuleAdapter newModuleAdapter = null; // try { - newModuleAdapter = m_ComAdapter.getModuleAdapter(selectedModule, paramsFile, withGUI ? null : "EvA2"); + newModuleAdapter = m_ComAdapter.getModuleAdapter(selectedModule, goParams, withGUI ? null : "EvA2"); } catch (Exception e) { logMessage("Error while m_ComAdapter.GetModuleAdapter Host: " + e.getMessage()); e.printStackTrace(); @@ -755,7 +811,7 @@ public class EvAClient implements RemoteStateListener, Serializable { System.setProperty("java.class.path", cp + System.getProperty("path.separator") + baseDir.getPath()); ReflectPackage.resetDynCP(); m_ComAdapter.updateLocalMainAdapter(); - loadSpecificModule(selectedModule, paramsFile); // end recursive call! handle with care! + loadSpecificModule(selectedModule, goParams); // end recursive call! handle with care! return; } showLoadModules = true; diff --git a/src/eva2/client/EvAComAdapter.java b/src/eva2/client/EvAComAdapter.java index 551f42f2..3b9b7028 100644 --- a/src/eva2/client/EvAComAdapter.java +++ b/src/eva2/client/EvAComAdapter.java @@ -20,6 +20,7 @@ import eva2.EvAInfo; import eva2.gui.LogPanel; import eva2.server.EvAMainAdapter; import eva2.server.EvAMainAdapterImpl; +import eva2.server.go.InterfaceGOParameters; import eva2.server.modules.ModuleAdapter; import eva2.tools.jproxy.ComAdapter; import eva2.tools.jproxy.MainAdapter; @@ -59,11 +60,11 @@ public class EvAComAdapter extends ComAdapter { * Creates the ModulAdapters RMI Object on the server * @return */ - public ModuleAdapter getModuleAdapter(String selectedModuleName, String paramsFile, String noGuiStatsFile) { + public ModuleAdapter getModuleAdapter(String selectedModuleName, InterfaceGOParameters goParams, String noGuiStatsFile) { ModuleAdapter newModuleAdapter; if ((m_RMIServer == null) && isRunLocally()) { //ret = evaAdapter.getModuleAdapter(Modul, hostAdd, this.m_MainAdapterClient); - newModuleAdapter = getLocalMainAdapter().getModuleAdapter(selectedModuleName, true, getHostName(), paramsFile, noGuiStatsFile, null); + newModuleAdapter = getLocalMainAdapter().getModuleAdapter(selectedModuleName, true, getHostName(), goParams, noGuiStatsFile, null); } else { newModuleAdapter = ((RMIConnectionEvA)getConnection(getHostName())).getModuleAdapter(selectedModuleName); if (newModuleAdapter == null) System.err.println("RMI Error for getting ModuleAdapterObject : " + selectedModuleName); diff --git a/src/eva2/gui/GenericObjectEditor.java b/src/eva2/gui/GenericObjectEditor.java index 7c54b07d..9844c4c1 100644 --- a/src/eva2/gui/GenericObjectEditor.java +++ b/src/eva2/gui/GenericObjectEditor.java @@ -199,16 +199,42 @@ public class GenericObjectEditor implements PropertyEditor { * * @param cls * @param hide + * @return the original hidden states or null if an error occurred. */ - public static void setHideAllProperties(Class cls, boolean hide) { + public static boolean[] setHideAllProperties(Class cls, boolean hide) { try { BeanInfo bi = Introspector.getBeanInfo(cls); PropertyDescriptor[] props = bi.getPropertyDescriptors(); + boolean[] orig = new boolean[props.length]; for (int i=0; i cls, boolean[] hideStates) { + if (hideStates!=null) { + BeanInfo bi; + try { + bi = Introspector.getBeanInfo(cls); + } catch (IntrospectionException e) { + System.err.println("Error on introspection of " + cls.getName() + ", " + e.getMessage()); + e.printStackTrace(); + return; + } + PropertyDescriptor[] props = bi.getPropertyDescriptors(); + if (hideStates.length == props.length) { + for (int i=0; i[] constructorArr = module.getConstructors(); // create a module instance - if ((paramsFile==null && noGuiLogFile==null) || !module.equals(GOModuleAdapter.class)) { - if (paramsFile!=null) System.err.println("Cant load params - no matching constructor found for " + adapterName + " (ModuleServer)"); + if ((goParams==null && noGuiLogFile==null) || !module.equals(GOModuleAdapter.class)) { + if (goParams!=null) System.err.println("Cant set params - no matching constructor found for " + adapterName + " (ModuleServer)"); if (noGuiLogFile!=null) System.err.println("Cant deactivate GUI - no matching constructor found for " + adapterName + " (ModuleServer)"); Object[] Para = new Object[2]; Class paramTypes[] = (constructorArr[0]).getParameterTypes(); @@ -174,7 +175,7 @@ public class ModuleServer { } else { Object[] Para = new Object[4]; Para[0] = (String)adapterName; - Para[1] = (String)paramsFile; + Para[1] = (InterfaceGOParameters)goParams; Para[2] = (String)noGuiLogFile; Para[3] = (MainAdapterClient)Client; int constrIndex=0; diff --git a/src/eva2/server/go/CrossoverInterface.java b/src/eva2/server/go/CrossoverInterface.java deleted file mode 100644 index c1bdfa8f..00000000 --- a/src/eva2/server/go/CrossoverInterface.java +++ /dev/null @@ -1,24 +0,0 @@ -package eva2.server.go; -/* - * Title: EvA2 - * Description: - * Copyright: Copyright (c) 2003 - * Company: University of Tuebingen, Computer Architecture - * @author Holger Ulmer, Felix Streichert, Hannes Planatscher - * @version: $Revision: 306 $ - * $Date: 2007-12-04 14:22:52 +0100 (Tue, 04 Dec 2007) $ - * $Author: mkron $ - */ -/*==========================================================================* - * IMPORTS - *==========================================================================*/ -import eva2.server.stat.InterfaceStatistics; -/*==========================================================================* - * INTERFACE DECLARATION - *==========================================================================*/ -/** - * - */ -public interface CrossoverInterface { - public void addListener(InterfaceStatistics e); -} \ No newline at end of file diff --git a/src/eva2/server/go/GOStandaloneVersion.java b/src/eva2/server/go/GOStandaloneVersion.java index 8e0dd807..b0d4373b 100644 --- a/src/eva2/server/go/GOStandaloneVersion.java +++ b/src/eva2/server/go/GOStandaloneVersion.java @@ -411,7 +411,7 @@ public class GOStandaloneVersion implements InterfaceGOStandalone, InterfacePopu if (Thread.interrupted()) throw new InterruptedException(); // write header to file - this.writeToFile(" FitnessCalls\t Best\t Mean\t Worst \t" + BeanInspector.toString(this.m_GO.getProblem().getAdditionalFileStringHeader(this.m_GO.getOptimizer().getPopulation()), '\t', false)); + this.writeToFile(" FitnessCalls\t Best\t Mean\t Worst \t" + BeanInspector.toString(this.m_GO.getProblem().getAdditionalFileStringHeader(), '\t', false)); if ((this.m_ContinueFlag) && (this.m_Backup != null)) { this.m_RecentFC += this.m_Backup.getFunctionCalls(); this.m_GO.getOptimizer().getProblem().initProblem(); diff --git a/src/eva2/server/go/problems/AbstractMultiModalProblemKnown.java b/src/eva2/server/go/problems/AbstractMultiModalProblemKnown.java index 51d2659f..eab4ee33 100644 --- a/src/eva2/server/go/problems/AbstractMultiModalProblemKnown.java +++ b/src/eva2/server/go/problems/AbstractMultiModalProblemKnown.java @@ -122,8 +122,8 @@ public abstract class AbstractMultiModalProblemKnown extends AbstractProblemDoub public abstract double[] evalUnnormalized(double[] x); @Override - public String[] getAdditionalFileStringHeader(PopulationInterface pop) { - return ToolBox.appendArrays(new String[]{"numOptsFound", "maxPeakRatio"}, super.getAdditionalFileStringHeader(pop)); + public String[] getAdditionalFileStringHeader() { + return ToolBox.appendArrays(new String[]{"numOptsFound", "maxPeakRatio"}, super.getAdditionalFileStringHeader()); } @Override diff --git a/src/eva2/server/go/problems/AbstractMultiObjectiveOptimizationProblem.java b/src/eva2/server/go/problems/AbstractMultiObjectiveOptimizationProblem.java index 93972dfd..24b5edd5 100644 --- a/src/eva2/server/go/problems/AbstractMultiObjectiveOptimizationProblem.java +++ b/src/eva2/server/go/problems/AbstractMultiObjectiveOptimizationProblem.java @@ -489,8 +489,8 @@ public abstract class AbstractMultiObjectiveOptimizationProblem extends Abstract } @Override - public String[] getAdditionalFileStringHeader(PopulationInterface pop) { - String[] superHd = super.getAdditionalFileStringHeader(pop); + public String[] getAdditionalFileStringHeader() { + String[] superHd = super.getAdditionalFileStringHeader(); return ToolBox.appendArrays(new String[]{"paretoMetricCurrent","paretoMetricFront"}, superHd); } @@ -507,8 +507,8 @@ public abstract class AbstractMultiObjectiveOptimizationProblem extends Abstract * @see eva2.server.go.problems.AbstractOptimizationProblem#getAdditionalFileStringInfo(eva2.server.go.PopulationInterface) */ @Override - public String[] getAdditionalFileStringInfo(PopulationInterface pop) { - String[] superInfo = super.getAdditionalFileStringInfo(pop); + public String[] getAdditionalFileStringInfo() { + String[] superInfo = super.getAdditionalFileStringInfo(); return ToolBox.appendArrays(new String[]{"Pareto metric on the current population (per generation)", "Pareto metric on the collected pareto front"}, superInfo); } diff --git a/src/eva2/server/go/problems/AbstractOptimizationProblem.java b/src/eva2/server/go/problems/AbstractOptimizationProblem.java index 364917ee..df803253 100644 --- a/src/eva2/server/go/problems/AbstractOptimizationProblem.java +++ b/src/eva2/server/go/problems/AbstractOptimizationProblem.java @@ -241,7 +241,7 @@ implements InterfaceOptimizationProblem /*, InterfaceParamControllable*/, Serial * @param pop The population that is to be refined. * @return String */ - public String[] getAdditionalFileStringHeader(PopulationInterface pop) { + public String[] getAdditionalFileStringHeader() { if (this instanceof InterfaceInterestingHistogram) return new String[]{"solution","histogram","score"}; else return new String[]{"solution"}; } @@ -250,7 +250,7 @@ implements InterfaceOptimizationProblem /*, InterfaceParamControllable*/, Serial * @param pop The population that is to be refined. * @return String */ - public String[] getAdditionalFileStringInfo(PopulationInterface pop) { + public String[] getAdditionalFileStringInfo() { if (this instanceof InterfaceInterestingHistogram) return new String[]{"Representation of the current best individual", "Fitness histogram of the current population", diff --git a/src/eva2/server/go/problems/AbstractProblemDouble.java b/src/eva2/server/go/problems/AbstractProblemDouble.java index 82d0b28e..bab287ac 100644 --- a/src/eva2/server/go/problems/AbstractProblemDouble.java +++ b/src/eva2/server/go/problems/AbstractProblemDouble.java @@ -574,8 +574,8 @@ public abstract class AbstractProblemDouble extends AbstractOptimizationProblem } @Override - public String[] getAdditionalFileStringHeader(PopulationInterface pop) { - String[] superHeader = super.getAdditionalFileStringHeader(pop); + public String[] getAdditionalFileStringHeader() { + String[] superHeader = super.getAdditionalFileStringHeader(); if (isWithConstraints()) return ToolBox.appendArrays(superHeader, new String[] { "rawFit", "numViol", "sumViol" }); @@ -584,8 +584,8 @@ public abstract class AbstractProblemDouble extends AbstractOptimizationProblem } @Override - public String[] getAdditionalFileStringInfo(PopulationInterface pop) { - String[] superInfo = super.getAdditionalFileStringInfo(pop); + public String[] getAdditionalFileStringInfo() { + String[] superInfo = super.getAdditionalFileStringInfo(); if (isWithConstraints()) return ToolBox .appendArrays( diff --git a/src/eva2/server/go/problems/F8Problem.java b/src/eva2/server/go/problems/F8Problem.java index 858bd018..cabee42f 100644 --- a/src/eva2/server/go/problems/F8Problem.java +++ b/src/eva2/server/go/problems/F8Problem.java @@ -158,8 +158,8 @@ public class F8Problem extends AbstractProblemDoubleOffset } @Override - public String[] getAdditionalFileStringHeader(PopulationInterface pop) { - String[] superHd = super.getAdditionalFileStringHeader(pop); + public String[] getAdditionalFileStringHeader() { + String[] superHd = super.getAdditionalFileStringHeader(); return ToolBox.appendArrays(new String[]{"numOptimaFound","maxPeakRatio"}, superHd); // return "#Optima found \tMaximum Peak Ratio \t" + super.getAdditionalFileStringHeader(pop); } diff --git a/src/eva2/server/go/problems/FLensProblem.java b/src/eva2/server/go/problems/FLensProblem.java index 50d7b626..9d103199 100644 --- a/src/eva2/server/go/problems/FLensProblem.java +++ b/src/eva2/server/go/problems/FLensProblem.java @@ -344,19 +344,6 @@ public class FLensProblem extends AbstractOptimizationProblem implements Interfa result += "Y = " + individual.getFitness(0); return result; } - - @Override - public String[] getAdditionalFileStringHeader(PopulationInterface pop) { - return new String[]{"Solution"}; - } - @Override - public Object[] getAdditionalFileStringValue(PopulationInterface pop) { - String result ="{"; - double[] data = ((InterfaceDataTypeDouble) pop.getBestIndividual()).getDoubleData(); - for (int i = 0; i < data.length; i++) result += data[i] +"; "; - result += "}"; - return new Object[]{result}; - } /** This method allows you to output a string that describes a found solution * in a way that is most suiteable for a given problem. diff --git a/src/eva2/server/go/problems/InterfaceAdditionalPopulationInformer.java b/src/eva2/server/go/problems/InterfaceAdditionalPopulationInformer.java index 0900c411..a2a7de0e 100644 --- a/src/eva2/server/go/problems/InterfaceAdditionalPopulationInformer.java +++ b/src/eva2/server/go/problems/InterfaceAdditionalPopulationInformer.java @@ -17,7 +17,7 @@ public interface InterfaceAdditionalPopulationInformer { * @param pop The population of the optimization run. * @return String */ - public String[] getAdditionalFileStringHeader(PopulationInterface pop); + public String[] getAdditionalFileStringHeader(); /** * Optionally return informative descriptions of the data fields. @@ -25,7 +25,7 @@ public interface InterfaceAdditionalPopulationInformer { * @param pop * @return */ - public String[] getAdditionalFileStringInfo(PopulationInterface pop); + public String[] getAdditionalFileStringInfo(); /** * This method returns additional statistical data. diff --git a/src/eva2/server/go/problems/PSymbolicRegression.java b/src/eva2/server/go/problems/PSymbolicRegression.java index ab3d5774..04494c20 100644 --- a/src/eva2/server/go/problems/PSymbolicRegression.java +++ b/src/eva2/server/go/problems/PSymbolicRegression.java @@ -510,8 +510,8 @@ public class PSymbolicRegression extends AbstractOptimizationProblem implements } @Override - public String[] getAdditionalFileStringHeader(PopulationInterface pop) { - String[] superHd = super.getAdditionalFileStringHeader(pop); + public String[] getAdditionalFileStringHeader() { + String[] superHd = super.getAdditionalFileStringHeader(); return ToolBox.appendArrays(new String[]{"bestIndySize","avgIndySize","avgMaxIndyDepth"}, superHd); } diff --git a/src/eva2/server/go/strategies/ClusterBasedNichingEA.java b/src/eva2/server/go/strategies/ClusterBasedNichingEA.java index a6073720..878e4a0e 100644 --- a/src/eva2/server/go/strategies/ClusterBasedNichingEA.java +++ b/src/eva2/server/go/strategies/ClusterBasedNichingEA.java @@ -1142,14 +1142,14 @@ public class ClusterBasedNichingEA implements InterfacePopulationChangedEventLis return "If fitness improves less than this value within the halting window, convergence is assumed. May be set to zero."; } - public String[] getAdditionalFileStringHeader(PopulationInterface pop) { + public String[] getAdditionalFileStringHeader() { return new String[]{"numUndiff","numActSpec","avgSpecMeas","numArchived", "archivedMedCorr", "archivedMeanDist" // , "numCollisions", "clustSig" }; } - public String[] getAdditionalFileStringInfo(PopulationInterface pop) { // TODO use these as Tool Tip Texts??? + public String[] getAdditionalFileStringInfo() { return new String[] { "The number of exploring individuals in the main population", "The number of active species (sub-populations)", diff --git a/src/eva2/server/go/strategies/ClusteringHillClimbing.java b/src/eva2/server/go/strategies/ClusteringHillClimbing.java index 9df27eec..f4d8ef1c 100644 --- a/src/eva2/server/go/strategies/ClusteringHillClimbing.java +++ b/src/eva2/server/go/strategies/ClusteringHillClimbing.java @@ -418,11 +418,11 @@ public class ClusteringHillClimbing implements InterfacePopulationChangedEventLi return "Set the method to be used for the hill climbing as local search"; } - public String[] getAdditionalFileStringHeader(PopulationInterface pop) { + public String[] getAdditionalFileStringHeader() { return new String[]{"numIndies"}; } - public String[] getAdditionalFileStringInfo(PopulationInterface pop) { + public String[] getAdditionalFileStringInfo() { return new String[]{"The current population size"}; } diff --git a/src/eva2/server/go/strategies/ParticleSwarmOptimization.java b/src/eva2/server/go/strategies/ParticleSwarmOptimization.java index 0469166f..fa0d0727 100644 --- a/src/eva2/server/go/strategies/ParticleSwarmOptimization.java +++ b/src/eva2/server/go/strategies/ParticleSwarmOptimization.java @@ -2060,12 +2060,12 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se // public void setDoLocalSearch(boolean doLocalSearch) { // this.doLocalSearch = doLocalSearch; // } - public String[] getAdditionalFileStringHeader(PopulationInterface pop) { + public String[] getAdditionalFileStringHeader() { if (emaPeriods > 0) return new String[]{"meanEMASpeed", "meanCurSpeed"}; else return new String[]{"meanCurSpeed"}; } - public String[] getAdditionalFileStringInfo(PopulationInterface pop) { + public String[] getAdditionalFileStringInfo() { if (emaPeriods > 0) return new String[]{"Exponential moving average of the (range-relative) speed of all particles", "The mean (range-relative) current speed of all particles"}; else return new String[]{"The mean (range-relative) current speed of all particles"}; } diff --git a/src/eva2/server/modules/AbstractModuleAdapter.java b/src/eva2/server/modules/AbstractModuleAdapter.java index 09dceed5..e91e68c3 100644 --- a/src/eva2/server/modules/AbstractModuleAdapter.java +++ b/src/eva2/server/modules/AbstractModuleAdapter.java @@ -122,11 +122,11 @@ abstract public class AbstractModuleAdapter implements ModuleAdapter, Serializab } else return null; } -// public void setGOParameters(InterfaceGOParameters params) { -// if ((m_Processor != null) && (m_Processor instanceof Processor)) { -// ((Processor)m_Processor).setGOParams(params); -// } -// } + public void setGOParameters(InterfaceGOParameters goParams) { + if ((m_Processor != null) && (m_Processor instanceof Processor)) { + ((Processor)m_Processor).setGOParams(goParams); + } + } // public void loadGOParameters(String serParamsFile) { // if ((m_Processor != null) && (m_Processor instanceof Processor)) { diff --git a/src/eva2/server/modules/GOModuleAdapter.java b/src/eva2/server/modules/GOModuleAdapter.java index 7bd7d10f..f4c9873e 100644 --- a/src/eva2/server/modules/GOModuleAdapter.java +++ b/src/eva2/server/modules/GOModuleAdapter.java @@ -2,6 +2,7 @@ package eva2.server.modules; import java.io.Serializable; +import eva2.server.go.InterfaceGOParameters; import eva2.tools.jproxy.MainAdapterClient; @@ -39,8 +40,19 @@ public class GOModuleAdapter extends GenericModuleAdapter implements ModuleAdapt * @param AdapterName the title of the ModulAdapter * @param Client the client instance */ - public GOModuleAdapter(String adapterName, String serParamsFile, String noGuiLogFile, MainAdapterClient client) { + public GOModuleAdapter(String adapterName, InterfaceGOParameters goParams, String noGuiLogFile, MainAdapterClient client) { //super(adapterName, "", client, GOParameters.getInstance(serParamsFile, false), false); - super(adapterName, "", client, GOParameters.getInstance(serParamsFile, serParamsFile==null), false, noGuiLogFile); + super(adapterName, "", client, goParams, false, noGuiLogFile); } + +// /** +// * Starts a statistics GUI and the GOProcessor thread with a given GOParameters file. +// * +// * @param AdapterName the title of the ModulAdapter +// * @param Client the client instance +// */ +// public GOModuleAdapter(String adapterName, String serParamsFile, String noGuiLogFile, MainAdapterClient client) { +// //super(adapterName, "", client, GOParameters.getInstance(serParamsFile, false), false); +// super(adapterName, "", client, GOParameters.getInstance(serParamsFile, serParamsFile==null), false, noGuiLogFile); +// } } \ No newline at end of file diff --git a/src/eva2/server/modules/ModuleAdapter.java b/src/eva2/server/modules/ModuleAdapter.java index 38bf387b..dcef6375 100644 --- a/src/eva2/server/modules/ModuleAdapter.java +++ b/src/eva2/server/modules/ModuleAdapter.java @@ -13,9 +13,6 @@ package eva2.server.modules; * IMPORTS *==========================================================================*/ import eva2.gui.EvATabbedFrameMaker; -import eva2.gui.LogPanel; -import eva2.server.go.operators.postprocess.PostProcessParams; -import eva2.server.stat.InterfaceTextListener; import eva2.tools.jproxy.RemoteStateListener; /*==========================================================================* * INTERFACE DECLARATION diff --git a/src/eva2/server/modules/Processor.java b/src/eva2/server/modules/Processor.java index f76e641d..753330c2 100644 --- a/src/eva2/server/modules/Processor.java +++ b/src/eva2/server/modules/Processor.java @@ -1,5 +1,6 @@ package eva2.server.modules; +import java.util.List; import java.util.Vector; import javax.swing.JOptionPane; @@ -228,7 +229,7 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo String popLog = null; //"populationLog.txt"; while (isOptRunning() && (runCounter(2); - informerList.add(this.goParams.getProblem()); - if (this.goParams.getOptimizer() instanceof InterfaceAdditionalPopulationInformer) informerList.add(this.goParams.getOptimizer()); m_Statistics.createNextGenerationPerformed( (PopulationInterface)this.goParams.getOptimizer().getPopulation(), this.goParams.getOptimizer(), - informerList); + getInformerList()); if (m_ListenerModule != null) { m_ListenerModule.updateProgress( getStatusPercent( @@ -372,7 +370,14 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo } } } - + + protected List getInformerList() { + Vector informerList = new Vector(2); + informerList.add(this.goParams.getProblem()); + if (this.goParams.getOptimizer() instanceof InterfaceAdditionalPopulationInformer) informerList.add((InterfaceAdditionalPopulationInformer)this.goParams.getOptimizer()); + return informerList; + } + /** This method writes Data to file. * @param line The line that is to be added to the file */ diff --git a/src/eva2/server/stat/AbstractStatistics.java b/src/eva2/server/stat/AbstractStatistics.java index c1dd032d..4f3a4f72 100644 --- a/src/eva2/server/stat/AbstractStatistics.java +++ b/src/eva2/server/stat/AbstractStatistics.java @@ -65,7 +65,8 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter private ArrayList sumDataCollection; // collect summed-up data of multiple runs indexed per iteration protected Object[] currentStatObjectData = null; // the raw Object data collected in an iteration protected Double[] currentStatDoubleData = null; // the parsed doubles collected in an iteration (or null for complex data fields) - protected String[] currentHeaderData = null; // the header Strings of the currently provided data + protected String[] currentStatHeader = null; // the header Strings of the currently provided data + protected String[] currentStatMetaInfo = null; // meta information on the statistical data private Double[] statDataSumOverAll = null; // , lastAdditionalInfoSums=null; @@ -133,7 +134,7 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter private void fireDataListeners() { if (dataListeners!=null) for (InterfaceStatisticsListener l : dataListeners) { - l.notifyGenerationPerformed(currentHeaderData, currentStatObjectData, currentStatDoubleData); + l.notifyGenerationPerformed(currentStatHeader, currentStatObjectData, currentStatDoubleData); } } @@ -146,10 +147,10 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter */ private void fireDataListenersStartStop(int runNumber, boolean normal, boolean start) { if (dataListeners!=null) for (InterfaceStatisticsListener l : dataListeners) { - if (start) l.notifyRunStarted(runNumber, m_StatsParams.getMultiRuns()); + if (start) l.notifyRunStarted(runNumber, m_StatsParams.getMultiRuns(), currentStatHeader, currentStatMetaInfo); else { l.notifyRunStopped(optRunsPerformed, normal); - if (optRunsPerformed>1) l.finalMultiRunResults(currentHeaderData, finalObjectData); + if (optRunsPerformed>1) l.finalMultiRunResults(currentStatHeader, finalObjectData); } } } @@ -221,17 +222,24 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter saveParams = doSave; } - public void startOptPerformed(String infoString, int runNumber, Object params) { + public void startOptPerformed(String infoString, int runNumber, Object params, List informerList) { if (TRACE) { System.out.println("AbstractStatistics.startOptPerformed " + runNumber); System.out.println("Statsparams were " + BeanInspector.toString(m_StatsParams)); } if (runNumber == 0) { - currentHeaderData=null; + // store the intial graph selection state, so that modifications during runtime cannot cause inconsistencies + lastFieldSelection = (StringSelection)m_StatsParams.getFieldSelection().clone(); + lastIsShowFull = m_StatsParams.isOutputAllFieldsAsText(); + currentStatDoubleData=null; currentStatObjectData=null; + List headerFields=getOutputHeaderFieldNames(informerList); + currentStatHeader = headerFields.toArray(new String[headerFields.size()]); + currentStatMetaInfo = getOutputMetaInfoAsArray(informerList); + functionCallSum = 0; firstPlot = true; optRunsPerformed = 0; @@ -256,9 +264,6 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter feasibleFoundAfterSum=-1; numOfRunsFeasibleFound=0; - // store the intial graph selection state, so that modifications during runtime cannot cause inconsistencies - lastFieldSelection = (StringSelection)m_StatsParams.getFieldSelection().clone(); - lastIsShowFull = m_StatsParams.isOutputAllFieldsAsText(); } feasibleFoundAfter=-1; bestCurrentIndy = null; @@ -456,7 +461,7 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter private String getFinalAdditionalInfo() { PopulationInterface bestPop = makeStatsPop(); // List additionalFields = getAdditionalInfoHeader(lastInformerList, bestPop); - String additionalFields = getOutputHeaderString(lastInformerList, bestPop); + String additionalFields = getOutputHeaderFieldNamesAsString(lastInformerList); // String header = getOutputHeader(lastInformerList, bestPop); List vals = getOutputValues(lastInformerList, bestPop); @@ -502,7 +507,7 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter } public String refineToText(ArrayList data, int iterationsToShow) { - String hd = getOutputHeaderString(lastInformerList, null); + String hd = getOutputHeaderFieldNamesAsString(lastInformerList); StringBuffer sbuf = new StringBuffer("Iteration"); sbuf.append(textFieldDelimiter); sbuf.append(hd); @@ -591,11 +596,28 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter * @param pop * @return */ - protected String getOutputHeaderString(List informerList, PopulationInterface pop) { - List headlineFields = getOutputHeaderFieldNames(informerList, pop); + protected String getOutputHeaderFieldNamesAsString(List informerList) { + List headlineFields = getOutputHeaderFieldNames(informerList); return StringTools.concatFields(headlineFields, textFieldDelimiter); } + /** + * Collect meta information on both internal fields and fields of external informers. + * The length of this list depends on the field selection state. + * + * @param informerList + * @param pop + * @return + */ + protected List getOutputHeaderFieldNames(List informerList) { + ArrayList headlineFields = new ArrayList(5); + headlineFields.addAll(Arrays.asList(getSimpleOutputHeader())); + if (informerList != null) { + headlineFields.addAll(getAdditionalHeaderMetaInfo(informerList, null)); + } + return headlineFields; + } + /** * Collect all field names of both internal fields and fields of external informers. * The length of this list depends on the field selection state. @@ -604,14 +626,22 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter * @param pop * @return */ - protected List getOutputHeaderFieldNames(List informerList, PopulationInterface pop) { - ArrayList headlineFields = new ArrayList(5); - headlineFields.addAll(Arrays.asList(getSimpleOutputHeader())); + protected List getOutputMetaInfo(List informerList) { + ArrayList infoStrings = new ArrayList(5); + ArrayList addStrings = new ArrayList(5); + infoStrings.addAll(Arrays.asList(getSimpleOutputMetaInfo())); if (informerList != null) { - headlineFields.addAll(getAdditionalInfoHeader(informerList, pop)); + getAdditionalHeaderMetaInfo(informerList, addStrings); } - return headlineFields; + infoStrings.addAll(addStrings); + return infoStrings; } + + protected String[] getOutputMetaInfoAsArray(List informerList) { + List metaStrings = getOutputMetaInfo(informerList); + return metaStrings.toArray( new String[metaStrings.size()]); + } + /** * Collect the names of data fields which are collected internally.This must correspond to the @@ -632,6 +662,24 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter return headerEntries.toArray(new String[headerEntries.size()]); } + /** + * Collect the info strings of data fields collected internally. This must correspond to + * the method {@link #getSimpleOutputValues()}. + * + * @see #getSimpleOutputValues() + * @return + */ + protected String[] getSimpleOutputMetaInfo() { + GraphSelectionEnum[] vals = GraphSelectionEnum.values(); + ArrayList headerInfo = new ArrayList(); + headerInfo.add("The number of function evaluations"); + for (int i=0; i getAdditionalInfoHeader(List informerList, PopulationInterface pop) { - LinkedList additionals = new LinkedList(); + protected List getAdditionalHeaderMetaInfo(List informerList, List metaInfo) { + LinkedList headers = new LinkedList(); + if (metaInfo!=null && (metaInfo.size()>0)) System.err.println("Warning, metaInfo list should be empty in AbstractStatistics.getAdditionalInfoInfo"); for (InterfaceAdditionalPopulationInformer informer : informerList) { - additionals.addAll(Arrays.asList(informer.getAdditionalFileStringHeader(pop))); + headers.addAll(Arrays.asList(informer.getAdditionalFileStringHeader())); + if (metaInfo!=null) metaInfo.addAll(Arrays.asList(informer.getAdditionalFileStringInfo())); // hdr = hdr + "\t " + informer.getAdditionalFileStringHeader(pop); } - Iterator iter = additionals.iterator(); - if (!lastIsShowFull) while (iter.hasNext()) { - if (!isRequestedAdditionalField(iter.next())) iter.remove(); + Iterator hIter = headers.iterator(); + Iterator mIter = (metaInfo!=null) ? metaInfo.iterator() : null; + if (!lastIsShowFull) while (hIter.hasNext()) { + if (mIter!=null) mIter.next(); + if (!isRequestedAdditionalField(hIter.next())) { + hIter.remove(); + if (mIter!=null) mIter.remove(); + } } - return additionals; + return headers; } /** @@ -824,7 +881,7 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter // if (doTextOutput()) printToTextListener(getOutputHeader(null, null)+'\n'); firstPlot = false; } - if ((iterationCounter == 0) && printHeaderByVerbosity()) printToTextListener(getOutputHeaderString(null, null)+'\n'); + if ((iterationCounter == 0) && printHeaderByVerbosity()) printToTextListener(getOutputHeaderFieldNamesAsString(null)+'\n'); if (doTextOutput() && printLineByVerbosity(calls)) { Pair addInfo = getOutputData(null, null); @@ -943,7 +1000,7 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter } /** - * Do some data collection on the population. The informer parameter will not be handled by this method. + * Do some data collection on the population. * */ public synchronized void createNextGenerationPerformed(PopulationInterface @@ -964,9 +1021,7 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter collectPopData(pop); if (iterationCounter==0) { - List headerFields=getOutputHeaderFieldNames(informerList, pop); - currentHeaderData = headerFields.toArray(new String[headerFields.size()]); - String headerLine = StringTools.concatFields(headerFields, textFieldDelimiter); + String headerLine = StringTools.concatFields(currentStatHeader, textFieldDelimiter); if (printHeaderByVerbosity()) printToTextListener(headerLine+'\n'); } diff --git a/src/eva2/server/stat/InterfaceStatistics.java b/src/eva2/server/stat/InterfaceStatistics.java index 222dadc0..d9769631 100644 --- a/src/eva2/server/stat/InterfaceStatistics.java +++ b/src/eva2/server/stat/InterfaceStatistics.java @@ -28,7 +28,7 @@ public interface InterfaceStatistics { /** * Initialize statistics computations. */ - public void startOptPerformed(String InfoString,int runnumber, Object params); // called from processor + public void startOptPerformed(String InfoString,int runnumber, Object params, List informerList); // called from processor /** * Finalize statistics computations. */ diff --git a/src/eva2/server/stat/InterfaceStatisticsListener.java b/src/eva2/server/stat/InterfaceStatisticsListener.java index 025bf9c8..ad173ca0 100644 --- a/src/eva2/server/stat/InterfaceStatisticsListener.java +++ b/src/eva2/server/stat/InterfaceStatisticsListener.java @@ -26,8 +26,10 @@ public interface InterfaceStatisticsListener { * * @param runNumber the number of the new run, starting with 0 * @param plannedMultiRuns the number of planned multi-runs + * @param header field names of the data + * @param metaInfo additional meta information on the data fields */ - public void notifyRunStarted(int runNumber, int plannedMultiRuns); + public void notifyRunStarted(int runNumber, int plannedMultiRuns, String[] header, String[] metaInfo); /** * Method called at the end of a single run. diff --git a/src/eva2/server/stat/StatisticsDummy.java b/src/eva2/server/stat/StatisticsDummy.java index 52b03071..4d0da9cb 100644 --- a/src/eva2/server/stat/StatisticsDummy.java +++ b/src/eva2/server/stat/StatisticsDummy.java @@ -79,7 +79,7 @@ public class StatisticsDummy implements InterfaceStatistics, InterfaceTextListen } public void startOptPerformed(String InfoString, int runnumber, - Object params) { + Object params, List informerList) { if (runnumber==0) bestIndividualAllover = null; bestRunIndy = null; } diff --git a/src/eva2/server/stat/StatisticsStandalone.java b/src/eva2/server/stat/StatisticsStandalone.java index e34e167f..3bc64354 100644 --- a/src/eva2/server/stat/StatisticsStandalone.java +++ b/src/eva2/server/stat/StatisticsStandalone.java @@ -77,7 +77,7 @@ public class StatisticsStandalone extends AbstractStatistics implements Interfac protected void initPlots(PopulationInterface pop, List informerList) { if (collectData) { m_ResultData = new ArrayList>(m_StatsParams.getMultiRuns()); - List description = getOutputHeaderFieldNames(informerList, pop); + List description = getOutputHeaderFieldNames(informerList); m_ResultHeaderStrings = new ArrayList(); for (String str : description) m_ResultHeaderStrings.add(str); for (int i = 0; i < m_StatsParams.getMultiRuns(); i++) diff --git a/src/eva2/server/stat/StatisticsWithGUI.java b/src/eva2/server/stat/StatisticsWithGUI.java index 9439c99e..d8076d71 100644 --- a/src/eva2/server/stat/StatisticsWithGUI.java +++ b/src/eva2/server/stat/StatisticsWithGUI.java @@ -99,8 +99,8 @@ public class StatisticsWithGUI extends AbstractStatistics implements Serializabl /** * */ - public synchronized void startOptPerformed(String infoString, int runNumber, Object goParams) { - super.startOptPerformed(infoString, runNumber, goParams); + public synchronized void startOptPerformed(String infoString, int runNumber, Object goParams, List informerList) { + super.startOptPerformed(infoString, runNumber, goParams, informerList); m_GraphInfoString = infoString; // m_TextCounter = m_StatisticsParameter.GetTextoutput(); diff --git a/src/eva2/server/stat/StatsParameter.java b/src/eva2/server/stat/StatsParameter.java index 0f1f7c8c..f3da9941 100644 --- a/src/eva2/server/stat/StatsParameter.java +++ b/src/eva2/server/stat/StatsParameter.java @@ -384,9 +384,9 @@ public class StatsParameter implements InterfaceStatisticsParameter, InterfaceNo ArrayList infoFields = new ArrayList(); // parse list of header elements, show additional Strings according to names. for (InterfaceAdditionalPopulationInformer inf : informers) { - headerFields.addAll(Arrays.asList(inf.getAdditionalFileStringHeader(null))); + headerFields.addAll(Arrays.asList(inf.getAdditionalFileStringHeader())); if (infoFields.size()0) sb.append(delim); + sb.append(str); + cnt++; + } + return sb.toString(); + } }