diff --git a/src/eva2/EvAInfo.java b/src/eva2/EvAInfo.java index 218097a8..e361adff 100644 --- a/src/eva2/EvAInfo.java +++ b/src/eva2/EvAInfo.java @@ -98,6 +98,8 @@ public class EvAInfo { public static final String splashLocation = "resources/images/splashScreen2.png"; public static final String infoTitle = productName+" Information"; public static final String copyrightYear = "2010-2012"; + + public static final String defaultLogger = "EvA2"; ////////////// Property handling... diff --git a/src/eva2/client/EvAClient.java b/src/eva2/client/EvAClient.java index 5c61cdf1..3b4601c5 100644 --- a/src/eva2/client/EvAClient.java +++ b/src/eva2/client/EvAClient.java @@ -442,8 +442,6 @@ public class EvAClient implements RemoteStateListener, Serializable { } }); - logger.info("EvAClient Loggin enabled"); - logger.warning("Logging could still die."); m_ProgressBar = new JProgressBar(); evaFrame.getContentPane().add(m_ProgressBar, BorderLayout.SOUTH); @@ -469,7 +467,7 @@ public class EvAClient implements RemoteStateListener, Serializable { evaFrame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { - System.out.println("Closing EvA2 Client. Bye!"); + logger.info("Closing EvA2 Client. Bye!"); evaFrame.dispose(); Set keys = System.getenv().keySet(); if (keys.contains("MATLAB")) { @@ -488,14 +486,14 @@ public class EvAClient implements RemoteStateListener, Serializable { selectHost(hostName); } m_ComAdapter.setLogPanel(logPanel); - logMessage("Selected Host: " + m_ComAdapter.getHostName()); + logger.log(Level.INFO, "Selected Host: {0}", m_ComAdapter.getHostName()); } // m_mnuModule.setText("Select module"); // m_mnuModule.repaint(); if (withGUI) { - logPanel.logMessage("Working directory is: " + System.getProperty("user.dir")); - logPanel.logMessage("Class path is: " + System.getProperty("java.class.path", ".")); + logger.log(Level.INFO, "Working directory is: {0}", System.getProperty("user.dir")); + logger.log(Level.INFO, "Class path is: {0}", System.getProperty("java.class.path", ".")); if (!(evaFrame.isVisible())) { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); @@ -503,7 +501,9 @@ public class EvAClient implements RemoteStateListener, Serializable { evaFrame.pack(); evaFrame.setVisible(true); } - logPanel.logMessage("EvA2 ready"); // if this message is omitted, the stupid scroll pane runs to the end of the last line which is ugly for a long class path + // if this message is omitted, the stupid scroll pane runs to + // the end of the last line which is ugly for a long class path + logger.info("EvA2 ready"); } } @@ -635,7 +635,7 @@ public class EvAClient implements RemoteStateListener, Serializable { @Override public void actionPerformed(ActionEvent e) { - logMessage(e.getActionCommand()); + logger.info(e.getActionCommand()); showAboutDialog(); } }; @@ -644,7 +644,7 @@ public class EvAClient implements RemoteStateListener, Serializable { @Override public void actionPerformed(ActionEvent e) { - logMessage(e.getActionCommand()); + logger.info(e.getActionCommand()); showLicense(); } }; @@ -653,7 +653,7 @@ public class EvAClient implements RemoteStateListener, Serializable { @Override public void actionPerformed(ActionEvent e) { - logMessage(e.getActionCommand()); + logger.info(e.getActionCommand()); selectAvailableHost(m_ComAdapter.getHostNameList()); } }; @@ -662,7 +662,7 @@ public class EvAClient implements RemoteStateListener, Serializable { @Override public void actionPerformed(ActionEvent e) { - logMessage(e.getActionCommand()); + logger.info(e.getActionCommand()); showPleaseWaitDialog(); Thread xx = new Thread() { @@ -679,7 +679,7 @@ public class EvAClient implements RemoteStateListener, Serializable { @Override public void actionPerformed(ActionEvent e) { - logMessage(e.getActionCommand()); + logger.info(e.getActionCommand()); showPleaseWaitDialog(); Thread xx = new Thread() { @@ -695,7 +695,7 @@ public class EvAClient implements RemoteStateListener, Serializable { @Override public void actionPerformed(ActionEvent e) { - logMessage(e.getActionCommand()); + logger.info(e.getActionCommand()); showPleaseWaitDialog(); Thread xx = new Thread() { @@ -835,10 +835,10 @@ public class EvAClient implements RemoteStateListener, Serializable { if (useLocalRMI) { EvAServer Server = new EvAServer(true, false); m_ComAdapter.setLocalRMIServer(Server.getRMIServer()); - logMessage("Local EvAServer started"); + logger.info("Local EvAServer started"); m_ComAdapter.setRunLocally(false); // this is not quite true but should have the desired effect } else { - logMessage("Working locally"); + logger.info("Working locally"); m_ComAdapter.setLocalRMIServer(null); m_ComAdapter.setRunLocally(true); } @@ -874,7 +874,7 @@ public class EvAClient implements RemoteStateListener, Serializable { m_actHost.setEnabled(true); m_actAvailableHost.setEnabled(true); } - logMessage("Selected Module: " + selectedModule); + logger.info("Selected Module: " + selectedModule); // m_LogPanel.statusMessage("Selected Module: " + selectedModule); } } @@ -921,8 +921,7 @@ public class EvAClient implements RemoteStateListener, Serializable { try { newModuleAdapter = m_ComAdapter.getModuleAdapter(selectedModule, goParams, withGUI ? null : "EvA2"); } catch (Exception e) { - logMessage("Error while m_ComAdapter.GetModuleAdapter Host: " + e.getMessage()); - e.printStackTrace(); + logger.log(Level.SEVERE, "Error while m_ComAdapter.GetModuleAdapter Host: " + e.getMessage(), e); EVAERROR.EXIT("Error while m_ComAdapter.GetModuleAdapter Host: " + e.getMessage()); } if (newModuleAdapter == null) { @@ -1044,9 +1043,9 @@ public class EvAClient implements RemoteStateListener, Serializable { private void selectHost(String hostName) { m_ComAdapter.setHostName(hostName); - logMessage("Selected Host: " + hostName); + logger.info("Selected Host: " + hostName); if (currentModule != null) { - logMessage("Reloading module from server..."); + logger.info("Reloading module from server..."); loadModuleFromServer(currentModule, null); } } @@ -1094,14 +1093,14 @@ public class EvAClient implements RemoteStateListener, Serializable { if (HostName == null) { return; } - logMessage("Kill host process on = " + HostName); + logger.info("Kill host process on = " + HostName); m_ComAdapter.killServer(HostName); // m_LogPanel.statusMessage(""); } - private void selectAllAvailableHostToKill(String[] HostNames) { + private void selectAllAvailableHostToKill(String[] hostNames) { System.out.println("SelectAllAvailableHostToKill"); - if (HostNames == null || HostNames.length == 0) { + if (hostNames == null || hostNames.length == 0) { System.out.println("no host is running"); return; } @@ -1114,7 +1113,7 @@ public class EvAClient implements RemoteStateListener, Serializable { l.performedRestart(infoString); } } - logMessage("Restarted processing " + infoString); + logger.log(Level.INFO, "Restarted processing {0}", infoString); startTime = System.currentTimeMillis(); } @@ -1124,7 +1123,7 @@ public class EvAClient implements RemoteStateListener, Serializable { l.performedStart(infoString); } } - logMessage("Started processing " + infoString); + logger.log(Level.INFO, "Started processing {0}", infoString); startTime = System.currentTimeMillis(); } @@ -1135,7 +1134,7 @@ public class EvAClient implements RemoteStateListener, Serializable { } } long t = (System.currentTimeMillis() - startTime); - logMessage(String.format("Stopped after %1$d.%2$tL s", (t / 1000), (t % 1000))); + logger.info(String.format("Stopped after %1$d.%2$tL s", (t / 1000), (t % 1000))); if (!withGUI) { System.exit(0); } @@ -1153,7 +1152,7 @@ public class EvAClient implements RemoteStateListener, Serializable { } } if (msg != null) { - logMessage(msg); + logger.info(msg); } if (this.m_ProgressBar != null) { Runnable doSetProgressBarValue = new Runnable() { diff --git a/src/eva2/server/modules/Processor.java b/src/eva2/server/modules/Processor.java index e412e59c..cb87fff0 100644 --- a/src/eva2/server/modules/Processor.java +++ b/src/eva2/server/modules/Processor.java @@ -1,5 +1,6 @@ package eva2.server.modules; +import eva2.EvAInfo; import java.util.List; import java.util.Vector; @@ -31,6 +32,8 @@ import eva2.tools.EVAHELP; import eva2.tools.StringTools; import eva2.tools.jproxy.RemoteStateListener; import eva2.tools.math.RNG; +import java.util.logging.Level; +import java.util.logging.Logger; /** * The Processor may run as a thread permanently (GenericModuleAdapter) and is then stopped and started @@ -47,28 +50,27 @@ import eva2.tools.math.RNG; */ public class Processor extends Thread implements InterfaceProcessor, InterfacePopulationChangedEventListener { - private static final boolean TRACE=false; - private volatile boolean m_optRunning; -// private volatile boolean m_doRunScript; - private InterfaceStatistics m_Statistics; - private InterfaceGOParameters goParams; - private boolean m_createInitialPopulations = true; - private boolean saveParams = true; - private RemoteStateListener m_ListenerModule; - private boolean wasRestarted = false; -// private int postProcessSteps = 0; - private int runCounter = 0; - private Population resPop = null; - private boolean userAborted = false; - -// transient private String m_OutputPath = ""; -// transient private BufferedWriter m_OutputFile = null; + private static final Logger logger = Logger.getLogger(EvAInfo.defaultLogger); + private volatile boolean m_optRunning; + private InterfaceStatistics m_Statistics; + private InterfaceGOParameters goParams; + private boolean m_createInitialPopulations = true; + private boolean saveParams = true; + private RemoteStateListener m_ListenerModule; + private boolean wasRestarted = false; + private int runCounter = 0; + private Population resPop = null; + private boolean userAborted = false; public void addListener(RemoteStateListener module) { - if (TRACE) System.out.println("Processor: setting module as listener: " + ((module==null) ? "null" : module.toString())); - m_ListenerModule = module; + logger.log( + Level.FINEST, + "Processor: setting module as listener: " + ((module == null) + ? "null" : module.toString())); + + m_ListenerModule = module; } - + /** * Construct a Processor instance and make statistics instance informable of the parameters, * such they can by dynamically show additional information. @@ -76,44 +78,43 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo * @see InterfaceNotifyOnInformers */ public Processor(InterfaceStatistics Stat, ModuleAdapter Adapter, InterfaceGOParameters params) { - goParams = params; - m_Statistics = Stat; - m_ListenerModule = Adapter; - + goParams = params; + m_Statistics = Stat; + m_ListenerModule = Adapter; + // the statistics want to be informed if the strategy or the optimizer (which provide statistical data as InterfaceAdditionalInformer) change. - if (Stat!=null && (params != null)) { - if (Stat.getStatisticsParameter() instanceof InterfaceNotifyOnInformers) { - // addition for the statistics revision with selectable strings - make sure the go parameters are represented within the statistics - params.addInformableInstance((InterfaceNotifyOnInformers)(Stat.getStatisticsParameter())); - } + if (Stat != null && (params != null)) { + if (Stat.getStatisticsParameter() instanceof InterfaceNotifyOnInformers) { + // addition for the statistics revision with selectable strings - make sure the go parameters are represented within the statistics + params.addInformableInstance((InterfaceNotifyOnInformers) (Stat.getStatisticsParameter())); + } } } - + public boolean isOptRunning() { - return m_optRunning; + return m_optRunning; } - + protected void setOptRunning(boolean bRun) { - m_optRunning = bRun; + m_optRunning = bRun; } - + /** * If set to true, before every run the parameters will be stored to a file. * * @param doSave */ public void setSaveParams(boolean doSave) { - saveParams = doSave; + saveParams = doSave; } /** * */ public void startOpt() { - m_createInitialPopulations = true; - if (TRACE) System.out.println("startOpt called:"); + m_createInitialPopulations = true; if (isOptRunning()) { - System.err.println("ERROR: Processor is already running !!"); + logger.log(Level.SEVERE, "Processor is already running."); return; } resPop = null; @@ -121,7 +122,7 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo wasRestarted = false; setOptRunning(true); } - + /** * Return true if the optimization was stopped by the user instead of * the termination criterion. @@ -129,17 +130,16 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo * @return */ public boolean wasAborted() { - return userAborted; + return userAborted; } /** * */ public void restartOpt() { - m_createInitialPopulations = false; - if (TRACE) System.out.println("restartOpt called:"); + m_createInitialPopulations = false; if (isOptRunning()) { - System.err.println("ERROR: Processor is already running !!"); + logger.log(Level.SEVERE, "Processor is already running."); return; } userAborted = false; @@ -151,58 +151,60 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo * */ public void stopOpt() { // this means user break - if (TRACE) System.out.println("called StopOpt"); setOptRunning(false); - if (TRACE) System.out.println("m_doRunScript = false "); } /** * */ public void run() { - setPriority(1); - while (true) { - try { - Thread.sleep(200); - } catch (Exception e) { - System.err.println ("There was an error in sleep Processor.run()" + e); - } - runOptOnce(); - } + setPriority(1); + while (true) { + try { + Thread.sleep(200); + } catch (Exception e) { + System.err.println("There was an error in sleep Processor.run()" + e); + } + runOptOnce(); + } } - + public Population runOptOnce() { - try { - EVAERROR.clearMsgCache(); - while (isOptRunning()) { - setPriority(3); - if (saveParams) { - try { - goParams.saveInstance(); - } catch(Exception e) { - System.err.println("Error on saveInstance!"); - } - } - resPop = optimize("Run"); - setPriority(1); - } - } catch (Exception e) { - String errMsg = e.toString(); - if ((errMsg == null) || (errMsg.length() == 0)) errMsg="check console output for error messages."; - errMsg = "Exception in Processor: "+errMsg; - System.err.println(errMsg); - e.printStackTrace(); - try { - JOptionPane.showMessageDialog(null, StringTools.wrapLine(errMsg, 60, 0.2), "Error in Optimization", JOptionPane.ERROR_MESSAGE); - } catch (Exception ex) {} catch(Error er) {}; - //m_Statistics.stopOptPerformed(false); - setOptRunning(false); // normal finish - if (m_ListenerModule!=null) { - m_ListenerModule.performedStop(); // is only needed in client server mode - m_ListenerModule.updateProgress(0, errMsg); - } - } - return resPop; + try { + EVAERROR.clearMsgCache(); + while (isOptRunning()) { + setPriority(3); + if (saveParams) { + try { + goParams.saveInstance(); + } catch (Exception e) { + System.err.println("Error on saveInstance!"); + } + } + resPop = optimize("Run"); + setPriority(1); + } + } catch (Exception e) { + String errMsg = e.toString(); + if ((errMsg == null) || (errMsg.length() == 0)) { + errMsg = "check console output for error messages."; + } + errMsg = "Exception in Processor: " + errMsg; + System.err.println(errMsg); + e.printStackTrace(); + try { + JOptionPane.showMessageDialog(null, StringTools.wrapLine(errMsg, 60, 0.2), "Error in Optimization", JOptionPane.ERROR_MESSAGE); + } catch (Exception ex) { + } catch (Error er) { + }; + //m_Statistics.stopOptPerformed(false); + setOptRunning(false); // normal finish + if (m_ListenerModule != null) { + m_ListenerModule.performedStop(); // is only needed in client server mode + m_ListenerModule.updateProgress(0, errMsg); + } + } + return resPop; } /** @@ -210,125 +212,146 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo * Return a population containing the solutions of the last run if there were multiple. */ protected Population optimize(String infoString) { - Population resultPop = null; + Population resultPop = null; - if (!isOptRunning()) { - System.err.println("warning, this shouldnt happen in processor! Was startOpt called?"); - setOptRunning(true); - } - - RNG.setRandomSeed(goParams.getSeed()); - - if (m_ListenerModule!=null) { - if (wasRestarted) m_ListenerModule.performedRestart(getInfoString()); - else m_ListenerModule.performedStart(getInfoString()); + if (!isOptRunning()) { + System.err.println("warning, this shouldnt happen in processor! Was startOpt called?"); + setOptRunning(true); } - - goParams.getOptimizer().addPopulationChangedEventListener(this); + + RNG.setRandomSeed(goParams.getSeed()); + + if (m_ListenerModule != null) { + if (wasRestarted) { + m_ListenerModule.performedRestart(getInfoString()); + } else { + m_ListenerModule.performedStart(getInfoString()); + } + } + + goParams.getOptimizer().addPopulationChangedEventListener(this); runCounter = 0; String popLog = null; //"populationLog.txt"; - while (isOptRunning() && (runCounter 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; + 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 */ @@ -395,20 +422,19 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo // System.err.println("Problems writing to output file!"); // } // } - public String getInfoString() { - //StringBuffer sb = new StringBuffer("processing "); - StringBuffer sb = new StringBuffer(this.goParams.getProblem().getName()); - 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) + //StringBuffer sb = new StringBuffer("processing "); + StringBuilder sb = new StringBuilder(this.goParams.getProblem().getName()); + 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) // sb.append(" for "); // sb.append(m_Statistics.getStatistisParameter().getMultiRuns()); // sb.append(" runs"); - return sb.toString(); + return sb.toString(); } - + /** * This method return the Statistics object. */ @@ -422,24 +448,28 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo public InterfaceGOParameters getGOParams() { return goParams; } + public void setGOParams(InterfaceGOParameters params) { - if (params!=null) goParams= params; - else System.err.println("Setting parameters failed (parameters were null) (Processor.setGOParams)"); + if (params != null) { + goParams = params; + } else { + System.err.println("Setting parameters failed (parameters were null) (Processor.setGOParams)"); + } } - + /** * Return the last solution population or null if there is none available. * * @return the last solution population or null */ public Population getResultPopulation() { - return resPop; + return resPop; } - + public Population performPostProcessing() { - return performPostProcessing((PostProcessParams)goParams.getPostProcessParams(), (InterfaceTextListener)m_Statistics); + return performPostProcessing((PostProcessParams) goParams.getPostProcessParams(), (InterfaceTextListener) m_Statistics); } - + /** * Perform a post processing step with given parameters, based on all solutions found by the optimizer. * Use getResultPopulation() to retrieve results. @@ -448,31 +478,35 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo * @param listener */ public Population performPostProcessing(PostProcessParams ppp, InterfaceTextListener listener) { - if (ppp.isDoPostProcessing()) { - 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 = (Population)(goParams.getOptimizer().getAllSolutions().getSolutions().clone()); - if (resultPop.getFunctionCalls() != goParams.getOptimizer().getPopulation().getFunctionCalls()) { - // System.err.println("bad case in Processor::performNewPostProcessing "); - resultPop.SetFunctionCalls(goParams.getOptimizer().getPopulation().getFunctionCalls()); - } + if (ppp.isDoPostProcessing()) { + 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 = (Population) (goParams.getOptimizer().getAllSolutions().getSolutions().clone()); + if (resultPop.getFunctionCalls() != goParams.getOptimizer().getPopulation().getFunctionCalls()) { + // System.err.println("bad case in Processor::performNewPostProcessing "); + resultPop.SetFunctionCalls(goParams.getOptimizer().getPopulation().getFunctionCalls()); + } // if (!resultPop.contains(m_Statistics.getBestSolution())) { // resultPop.add(m_Statistics.getBestSolution()); - // this is a minor cheat but guarantees that the best solution ever found is contained in the final results - // This was evil in case multiple runs were performed with PP, because the best of an earlier run is added which is confusing. - // the minor cheat should not be necessary anymore anyways, since the getAllSolutions() variant replaced the earlier getPopulation() call + // this is a minor cheat but guarantees that the best solution ever found is contained in the final results + // This was evil in case multiple runs were performed with PP, because the best of an earlier run is added which is confusing. + // the minor cheat should not be necessary anymore anyways, since the getAllSolutions() variant replaced the earlier getPopulation() call // resultPop.synchSize(); // } - - PostProcess.checkAccuracy((AbstractOptimizationProblem)goParams.getProblem(), resultPop, ppp.getAccuracies(), ppp.getAccAssumeConv(), - -1, ppp.getAccMaxEval(), (SolutionHistogram[]) null, true, listener); - - resultPop = PostProcess.postProcess(ppp, resultPop, (AbstractOptimizationProblem)goParams.getProblem(), listener); - resPop = resultPop; - return resultPop; - } else return null; + + PostProcess.checkAccuracy((AbstractOptimizationProblem) goParams.getProblem(), resultPop, ppp.getAccuracies(), ppp.getAccAssumeConv(), + -1, ppp.getAccMaxEval(), (SolutionHistogram[]) null, true, listener); + + resultPop = PostProcess.postProcess(ppp, resultPop, (AbstractOptimizationProblem) goParams.getProblem(), listener); + resPop = resultPop; + return resultPop; + } else { + return null; + } } } diff --git a/src/eva2/tools/EVAERROR.java b/src/eva2/tools/EVAERROR.java index 1ad2b3c6..3164ac1f 100644 --- a/src/eva2/tools/EVAERROR.java +++ b/src/eva2/tools/EVAERROR.java @@ -11,12 +11,7 @@ import java.util.HashMap; * $Date: 2007-11-08 17:24:53 +0100 (Thu, 08 Nov 2007) $ * $Author: mkron $ */ -/*==========================================================================* - * IMPORTS - *==========================================================================*/ -/*==========================================================================* - * CLASS DECLARATION - *==========================================================================*/ + /** * */ @@ -55,6 +50,7 @@ public class EVAERROR { static public void WARNING(String Message) { // if (MAIL_ON_WARNING) // EVAMail.SendMail("EvA EXIT on ERROR !! ",Message,"ulmerh@informatik.uni-tuebingen.de"); + System.err.println("WARNING: "+Message); System.out.flush(); System.err.flush(); @@ -71,7 +67,7 @@ public class EVAERROR { if (!errMap.containsKey(msg)) { System.err.println(msg); - errMap.put(msg, new Boolean(true)); + errMap.put(msg, true); } }