Further refactoring to clear up package structure.

This commit is contained in:
2013-07-19 16:44:59 +02:00
parent a4c45b6295
commit 85ec784da2
19 changed files with 1363 additions and 1694 deletions

View File

@@ -345,7 +345,7 @@
<jar jarfile="${bin.dist.dir}/${library.directory}/EvA2Base.jar" basedir="${build.directory}"> <jar jarfile="${bin.dist.dir}/${library.directory}/EvA2Base.jar" basedir="${build.directory}">
<!--<fileset dir="${classes.dir}" excludes="*test*"/>--> <!--<fileset dir="${classes.dir}" excludes="*test*"/>-->
<manifest> <attribute name="Main-Class" value="eva2.client.EvAClient"/> </manifest> <manifest> <attribute name="Main-Class" value="eva2.gui.Main"/> </manifest>
</jar> </jar>
</target> </target>
@@ -372,7 +372,7 @@
<!-- <fileset dir="${classes.dir}" excludes="*test*"/> <!-- <fileset dir="${classes.dir}" excludes="*test*"/>
--> -->
<manifest> <manifest>
<attribute name="Main-Class" value="eva2.client.EvAClient" /> <attribute name="Main-Class" value="eva2.gui.Main" />
</manifest> </manifest>
</jar> </jar>
</target> </target>
@@ -389,7 +389,7 @@
<jar jarfile="${bin.dist.dir}/${jar.name}.jar" basedir="${build.directory}" > <jar jarfile="${bin.dist.dir}/${jar.name}.jar" basedir="${build.directory}" >
<manifest> <manifest>
<attribute name="Main-Class" value="eva2.client.EvAClient"/> <attribute name="Main-Class" value="eva2.gui.Main"/>
<attribute name="Built-By" value="Center for Bioinformatics Tuebingen (ZBIT)"/> <attribute name="Built-By" value="Center for Bioinformatics Tuebingen (ZBIT)"/>
<!-- <!--
<attribute name="Xdock:name" value="EvA2"/> <attribute name="Xdock:name" value="EvA2"/>
@@ -662,7 +662,7 @@
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--> +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-->
<target name="run" description="Runs EvA2."> <target name="run" description="Runs EvA2.">
<java classname="eva2.client.EvAClient" fork="yes"> <java classname="eva2.gui.Main" fork="yes">
<jvmarg value="-Xmx512m"/> <jvmarg value="-Xmx512m"/>
<classpath> <classpath>
<pathelement path="${project.class.path}" /> <pathelement path="${project.class.path}" />

View File

@@ -255,7 +255,7 @@
</delete> </delete>
<jar jarfile="${bin.dist.dir}/${jar.name}.jar" basedir="${build.directory}" > <jar jarfile="${bin.dist.dir}/${jar.name}.jar" basedir="${build.directory}" >
<manifest> <attribute name="Main-Class" value="eva2.client.EvAClient"/> </manifest> <manifest> <attribute name="Main-Class" value="eva2.gui.Main"/> </manifest>
</jar> </jar>
<copy todir="${distribution.directory}"> <copy todir="${distribution.directory}">
@@ -333,7 +333,7 @@
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--> +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-->
<target name="run" description="Runs EvA2."> <target name="run" description="Runs EvA2.">
<java classname="eva2.client.EvAClient" fork="yes"> <java classname="eva2.gui.Main" fork="yes">
<jvmarg value="-Xmx512m"/> <jvmarg value="-Xmx512m"/>
<classpath> <classpath>
<pathelement path="${project.class.path}" /> <pathelement path="${project.class.path}" />

View File

@@ -68,7 +68,7 @@
<addMavenDescriptor>false</addMavenDescriptor> <addMavenDescriptor>false</addMavenDescriptor>
<manifest> <manifest>
<addClasspath>true</addClasspath> <addClasspath>true</addClasspath>
<mainClass>eva2.client.EvAClient</mainClass> <mainClass>eva2.gui.Main</mainClass>
</manifest> </manifest>
</archive> </archive>
</configuration> </configuration>
@@ -92,7 +92,7 @@
</descriptorRefs> </descriptorRefs>
<archive> <archive>
<manifest> <manifest>
<mainClass>eva2.client.EvAClient</mainClass> <mainClass>eva2.gui.Main</mainClass>
</manifest> </manifest>
</archive> </archive>
</configuration> </configuration>

View File

@@ -1,24 +1,13 @@
package eva2.client; package eva2.gui;
/*
* Title: EvA2
* Description: The main client class of the EvA framework.
* Copyright: Copyright (c) 2008
* Company: University of Tuebingen, Computer
* Architecture
*
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
* @version: $Revision: 322 $ $Date: 2007-12-11 17:24:07 +0100 (Tue, 11 Dec 2007)$
* $Author: mkron $
*/
import eva2.EvAInfo; import eva2.EvAInfo;
import eva2.gui.*; import eva2.client.*;
import eva2.optimization.OptimizationStateListener; import eva2.optimization.OptimizationStateListener;
import eva2.optimization.go.InterfaceOptimizationParameters; import eva2.optimization.go.InterfaceOptimizationParameters;
import eva2.optimization.modules.AbstractModuleAdapter; import eva2.optimization.modules.AbstractModuleAdapter;
import eva2.optimization.modules.OptimizationParameters;
import eva2.optimization.modules.GenericModuleAdapter; import eva2.optimization.modules.GenericModuleAdapter;
import eva2.optimization.modules.ModuleAdapter; import eva2.optimization.modules.ModuleAdapter;
import eva2.optimization.modules.OptimizationParameters;
import eva2.optimization.stat.AbstractStatistics; import eva2.optimization.stat.AbstractStatistics;
import eva2.optimization.stat.InterfaceStatisticsListener; import eva2.optimization.stat.InterfaceStatisticsListener;
import eva2.optimization.stat.InterfaceStatisticsParameter; import eva2.optimization.stat.InterfaceStatisticsParameter;
@@ -26,22 +15,22 @@ import eva2.tools.BasicResourceLoader;
import eva2.tools.EVAERROR; import eva2.tools.EVAERROR;
import eva2.tools.ReflectPackage; import eva2.tools.ReflectPackage;
import eva2.tools.StringTools; import eva2.tools.StringTools;
import javax.help.HelpSet;
import javax.help.JHelpContentViewer;
import javax.help.JHelpNavigator;
import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.awt.event.*; import java.awt.event.*;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.*;
import java.util.List;
import java.util.Set;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.help.*;
import javax.swing.*;
/** /**
* *
*/ */
public class EvAClient extends JFrame implements OptimizationStateListener { public class Main extends JFrame implements OptimizationStateListener {
/** /**
* Generated serial version identifier. * Generated serial version identifier.
@@ -70,7 +59,7 @@ public class EvAClient extends JFrame implements OptimizationStateListener {
// LogPanel // LogPanel
private LoggingPanel logPanel; private LoggingPanel logPanel;
private static final Logger LOGGER = Logger.getLogger(EvAClient.class.getName()); private static final Logger LOGGER = Logger.getLogger(Main.class.getName());
// Module: // Module:
private ExtAction actModuleLoad; private ExtAction actModuleLoad;
@@ -101,7 +90,7 @@ public class EvAClient extends JFrame implements OptimizationStateListener {
private EvATabbedFrameMaker frameMaker = null; private EvATabbedFrameMaker frameMaker = null;
private Window parentWindow; private Window parentWindow;
private List<OptimizationStateListener> superListenerList = null; private java.util.List<OptimizationStateListener> superListenerList = null;
private EvAComAdapter comAdapter; private EvAComAdapter comAdapter;
@@ -123,67 +112,67 @@ public class EvAClient extends JFrame implements OptimizationStateListener {
/** /**
* Constructor of GUI of EvA2. Works as client for the EvA2 server. Note * Constructor of GUI of EvA2. Works as client for the EvA2 server. Note
* that the EvAClient initialized multi-threaded for efficiency. Use {@link #awaitGuiInitialized()} * that the Main initialized multi-threaded for efficiency. Use {@link #awaitGuiInitialized()}
* to await full initialization if necessary. * to await full initialization if necessary.
* *
*/ */
public EvAClient(final String hostName) { public Main(final String hostName) {
this(hostName, null, false, false); this(hostName, null, false, false);
} }
/** /**
* A constructor. Splash screen is optional, Gui is activated, no parent * A constructor. Splash screen is optional, Gui is activated, no parent
* window. Note that the EvAClient initialized multi-threaded for * window. Note that the Main initialized multi-threaded for
* efficiency. Use {@link #awaitGuiInitialized()} to await full * efficiency. Use {@link #awaitGuiInitialized()} to await full
* initialization if necessary. * initialization if necessary.
* *
* @see #EvAClient(String, Window, String, boolean, boolean, boolean) * @see #EvAClient(String, java.awt.Window, String, boolean, boolean, boolean)
* @param hostName * @param hostName
* @param paramsFile * @param paramsFile
* @param autorun * @param autorun
* @param nosplash * @param nosplash
*/ */
public EvAClient(final String hostName, final String paramsFile, boolean autorun, boolean nosplash) { public Main(final String hostName, final String paramsFile, boolean autorun, boolean nosplash) {
this(hostName, null, paramsFile, null, autorun, nosplash, false, false); this(hostName, null, paramsFile, null, autorun, nosplash, false, false);
} }
/** /**
* A constructor with optional spash screen. Note that the EvAClient is * A constructor with optional spash screen. Note that the Main is
* initialized multi-threaded for efficiency. Use {@link #awaitGuiInitialized()} * initialized multi-threaded for efficiency. Use {@link #awaitGuiInitialized()}
* to await full initialization if necessary. * to await full initialization if necessary.
* *
* @see #EvAClient(String, String, boolean, boolean) * @see #Main(String, String, boolean, boolean)
* *
* @param hostName * @param hostName
* @param autorun * @param autorun
* @param nosplash * @param nosplash
*/ */
public EvAClient(final String hostName, boolean autorun, boolean nosplash) { public Main(final String hostName, boolean autorun, boolean nosplash) {
this(hostName, null, autorun, nosplash); this(hostName, null, autorun, nosplash);
} }
/** /**
* A constructor with optional splash screen. Note that the EvAClient * A constructor with optional splash screen. Note that the Main
* initialized multi-threaded for efficiency. Use {@link #awaitGuiInitialized()} * initialized multi-threaded for efficiency. Use {@link #awaitGuiInitialized()}
* to await full initialization if necessary. * to await full initialization if necessary.
* *
* @see #EvAClient(String, String, boolean, boolean) * @see #Main(String, String, boolean, boolean)
* @param hostName * @param hostName
* @param paramsFile * @param paramsFile
* @param autorun * @param autorun
* @param noSplash * @param noSplash
* @param noGui * @param noGui
*/ */
public EvAClient(final String hostName, String paramsFile, boolean autorun, boolean noSplash, boolean noGui, boolean withTreeView) { public Main(final String hostName, String paramsFile, boolean autorun, boolean noSplash, boolean noGui, boolean withTreeView) {
this(hostName, null, paramsFile, null, autorun, noSplash, noGui, withTreeView); this(hostName, null, paramsFile, null, autorun, noSplash, noGui, withTreeView);
} }
/** /**
* A constructor with optional splash screen. Note that the EvAClient * A constructor with optional splash screen. Note that the Main
* initialized multi-threaded for efficiency. Use {@link #awaitGuiInitialized()} * initialized multi-threaded for efficiency. Use {@link #awaitGuiInitialized()}
* to await full initialization if necessary. * to await full initialization if necessary.
* *
* @see #EvAClient(String, String, boolean, boolean) * @see #Main(String, String, boolean, boolean)
* *
* @param hostName * @param hostName
* @param paramsFile * @param paramsFile
@@ -191,7 +180,7 @@ public class EvAClient extends JFrame implements OptimizationStateListener {
* @param noSplash * @param noSplash
* @param noGui * @param noGui
*/ */
public EvAClient(final String hostName, InterfaceOptimizationParameters goParams, boolean autorun, boolean noSplash, boolean noGui) { public Main(final String hostName, InterfaceOptimizationParameters goParams, boolean autorun, boolean noSplash, boolean noGui) {
this(hostName, null, null, goParams, autorun, noSplash, noGui, false); this(hostName, null, null, goParams, autorun, noSplash, noGui, false);
} }
@@ -206,7 +195,7 @@ public class EvAClient extends JFrame implements OptimizationStateListener {
* @param noSplash * @param noSplash
* @param noGui * @param noGui
*/ */
public EvAClient(final String hostName, final Window parent, final String paramsFile, final InterfaceOptimizationParameters goParams, final boolean autorun, final boolean noSplash, final boolean noGui) { public Main(final String hostName, final Window parent, final String paramsFile, final InterfaceOptimizationParameters goParams, final boolean autorun, final boolean noSplash, final boolean noGui) {
this(hostName, parent, paramsFile, goParams, autorun, noSplash, noGui, false); this(hostName, parent, paramsFile, goParams, autorun, noSplash, noGui, false);
} }
@@ -215,7 +204,7 @@ public class EvAClient extends JFrame implements OptimizationStateListener {
* locally or as client for the EvA2 server. GO parameters may be loaded * locally or as client for the EvA2 server. GO parameters may be loaded
* from a file (paramsFile) or given directly as a java instance. Both may * 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 * be null to start with standard parameters. If both are non null, the java
* instance has the higher priority. Note that the EvAClient initialized * instance has the higher priority. Note that the Main initialized
* multi-threaded for efficiency. Use {@link #awaitGuiInitialized()} to * multi-threaded for efficiency. Use {@link #awaitGuiInitialized()} to
* await full initialization if necessary. * await full initialization if necessary.
* *
@@ -226,9 +215,9 @@ public class EvAClient extends JFrame implements OptimizationStateListener {
* @param noSplash * @param noSplash
* @param noGui * @param noGui
*/ */
public EvAClient(final String hostName, final Window parent, final String paramsFile, final InterfaceOptimizationParameters goParams, final boolean autorun, final boolean noSplash, final boolean noGui, final boolean showTreeView) { public Main(final String hostName, final Window parent, final String paramsFile, final InterfaceOptimizationParameters goParams, final boolean autorun, final boolean noSplash, final boolean noGui, final boolean showTreeView) {
clientInited = false; clientInited = false;
final SplashScreen splashScreen = new SplashScreen(EvAInfo.splashLocation); final eva2.gui.SplashScreen splashScreen = new eva2.gui.SplashScreen(EvAInfo.splashLocation);
// preload some classes (into system cache) in a parallel thread // preload some classes (into system cache) in a parallel thread
preloadClasses(); preloadClasses();
@@ -294,7 +283,7 @@ public class EvAClient extends JFrame implements OptimizationStateListener {
/** /**
* Since the constructor runs multi-threaded for efficiency, this method may * Since the constructor runs multi-threaded for efficiency, this method may
* be called to await the full initialization of a client instance. As soon * be called to await the full initialization of a client instance. As soon
* as it returns, the EvAClient GUI is fully initialized. * as it returns, the Main GUI is fully initialized.
*/ */
public void awaitClientInitialized() { public void awaitClientInitialized() {
if (initRnbl != null) { if (initRnbl != null) {
@@ -338,7 +327,7 @@ public class EvAClient extends JFrame implements OptimizationStateListener {
* @param fontResource The FontUIResource for the controls * @param fontResource The FontUIResource for the controls
*/ */
private static void setUIFont(javax.swing.plaf.FontUIResource fontResource) { private static void setUIFont(javax.swing.plaf.FontUIResource fontResource) {
java.util.Enumeration keys = UIManager.getDefaults().keys(); Enumeration keys = UIManager.getDefaults().keys();
while (keys.hasMoreElements()) { while (keys.hasMoreElements()) {
Object key = keys.nextElement(); Object key = keys.nextElement();
Object value = UIManager.get(key); Object value = UIManager.get(key);
@@ -509,12 +498,12 @@ public class EvAClient extends JFrame implements OptimizationStateListener {
@Override @Override
public void windowClosing(final WindowEvent event) { public void windowClosing(final WindowEvent event) {
int result = JOptionPane.showConfirmDialog( int result = JOptionPane.showConfirmDialog(
EvAClient.this, Main.this,
"Do you really want to exit EvA2?", "Do you really want to exit EvA2?",
"Exit Application", "Exit Application",
JOptionPane.YES_NO_OPTION); JOptionPane.YES_NO_OPTION);
if (result == JOptionPane.YES_OPTION) { if (result == JOptionPane.YES_OPTION) {
EvAClient.this.close(); Main.this.close();
} }
} }
}); });
@@ -572,7 +561,7 @@ public class EvAClient extends JFrame implements OptimizationStateListener {
* The one and only main of the client program. Possible arguments: * The one and only main of the client program. Possible arguments:
* --autorun immediately starts the optimization (with parameters loaded * --autorun immediately starts the optimization (with parameters loaded
* from current directory if available. --hostname HOST: sets the hostname * from current directory if available. --hostname HOST: sets the hostname
* for the EvAClient to HOST --nosplash: skip the splash screen. --params * for the Main to HOST --nosplash: skip the splash screen. --params
* PFILE: load the optimization parameter from the serialized file PFILE * PFILE: load the optimization parameter from the serialized file PFILE
* *
* @param args command line parameters * @param args command line parameters
@@ -630,7 +619,7 @@ public class EvAClient extends JFrame implements OptimizationStateListener {
String hostName = StringTools.checkSingleStringArg(keys[4], values[4], arities[4] - 1); String hostName = StringTools.checkSingleStringArg(keys[4], values[4], arities[4] - 1);
String paramsFile = StringTools.checkSingleStringArg(keys[5], values[5], arities[5] - 1); String paramsFile = StringTools.checkSingleStringArg(keys[5], values[5], arities[5] - 1);
new EvAClient(hostName, paramsFile, autorun, nosplash, nogui, treeView); new Main(hostName, paramsFile, autorun, nosplash, nogui, treeView);
} }
} }
@@ -643,12 +632,12 @@ public class EvAClient extends JFrame implements OptimizationStateListener {
* optimization * optimization
* @param windowListener additional window listener for client frame * @param windowListener additional window listener for client frame
*/ */
public static EvAClient initClientGUI(OptimizationParameters goParams, public static Main initClientGUI(OptimizationParameters goParams,
InterfaceStatisticsListener statisticsListener, InterfaceStatisticsListener statisticsListener,
WindowListener windowListener, final Window parent) { WindowListener windowListener, final Window parent) {
EvAClient evaClient; Main evaClient;
evaClient = new EvAClient(null, parent, null, goParams, evaClient = new Main(null, parent, null, goParams,
false, true, false, false); // initializes GUI in the background false, true, false, false); // initializes GUI in the background
// important: wait for GUI initialization before accessing any internal // important: wait for GUI initialization before accessing any internal
// settings: // settings:
@@ -724,7 +713,7 @@ public class EvAClient extends JFrame implements OptimizationStateListener {
@Override @Override
public void actionPerformed(final ActionEvent event) { public void actionPerformed(final ActionEvent event) {
EvAClient.this.close(); Main.this.close();
} }
}; };
@@ -744,7 +733,7 @@ public class EvAClient extends JFrame implements OptimizationStateListener {
public void actionPerformed(final ActionEvent event) { public void actionPerformed(final ActionEvent event) {
// ToDo // ToDo
String helpHS = "EvA2Help/EvA2Help.hs"; String helpHS = "EvA2Help/EvA2Help.hs";
ClassLoader cl = EvAClient.class.getClassLoader(); ClassLoader cl = Main.class.getClassLoader();
JHelpContentViewer helpPane; JHelpContentViewer helpPane;
try { try {
URL hsURL = HelpSet.findHelpSet(cl, helpHS); URL hsURL = HelpSet.findHelpSet(cl, helpHS);
@@ -942,7 +931,7 @@ public class EvAClient extends JFrame implements OptimizationStateListener {
* Create a tree view of an object based on EvATreeNode. It is encapsulated * Create a tree view of an object based on EvATreeNode. It is encapsulated
* in a JScrollPane. * in a JScrollPane.
* *
* @see EvATreeNode * @see eva2.gui.EvATreeNode
* @param title * @param title
* @param object * @param object
* @return * @return
@@ -1036,35 +1025,3 @@ public class EvAClient extends JFrame implements OptimizationStateListener {
} }
} }
} }
final class SplashScreen extends Frame {
private static final long serialVersionUID = 1281793825850423095L;
private String imgLocation;
public SplashScreen(String imgLoc) {
imgLocation = imgLoc;
}
/**
* Show the splash screen to the end user.
*
* <P>Once this method returns, the splash screen is realized, which means
* that almost all work on the splash screen should proceed through the
* event dispatch thread. In particular, any call to
* <code>dispose</code> for the splash screen must be performed in the event
* dispatch thread.
*/
public void splash() {
JWindow splashWindow = new JWindow(this);
BasicResourceLoader loader = BasicResourceLoader.instance();
byte[] bytes = loader.getBytesFromResourceLocation(imgLocation, true);
ImageIcon ii = new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes));
JLabel splashLabel = new JLabel(ii);
splashWindow.add(splashLabel);
splashWindow.pack();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
splashWindow.setLocation(screenSize.width / 2 - splashWindow.getSize().width / 2, screenSize.height / 2 - splashWindow.getSize().height / 2);
splashWindow.setVisible(true);
}
}

View File

@@ -0,0 +1,51 @@
package eva2.gui;
/*
* Title: EvA2
* Description: The main client class of the EvA framework.
* Copyright: Copyright (c) 2008
* Company: University of Tuebingen, Computer
* Architecture
*
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
* @version: $Revision: 322 $ $Date: 2007-12-11 17:24:07 +0100 (Tue, 11 Dec 2007)$
* $Author: mkron $
*/
import eva2.tools.BasicResourceLoader;
import java.awt.*;
import javax.swing.*;
class SplashScreen extends Frame {
private static final long serialVersionUID = 1281793825850423095L;
private String imgLocation;
public SplashScreen(String imgLoc) {
imgLocation = imgLoc;
}
/**
* Show the splash screen to the end user.
*
* <P>Once this method returns, the splash screen is realized, which means
* that almost all work on the splash screen should proceed through the
* event dispatch thread. In particular, any call to
* <code>dispose</code> for the splash screen must be performed in the event
* dispatch thread.
*/
public void splash() {
JWindow splashWindow = new JWindow(this);
BasicResourceLoader loader = BasicResourceLoader.instance();
byte[] bytes = loader.getBytesFromResourceLocation(imgLocation, true);
ImageIcon ii = new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes));
JLabel splashLabel = new JLabel(ii);
splashWindow.add(splashLabel);
splashWindow.pack();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
splashWindow.setLocation(screenSize.width / 2 - splashWindow.getSize().width / 2, screenSize.height / 2 - splashWindow.getSize().height / 2);
splashWindow.setVisible(true);
}
}

View File

@@ -166,7 +166,7 @@ public class GOStandaloneVersion implements InterfaceGOStandalone, InterfacePopu
} }
this.m_O1 = (paraPanel.makePanel()); this.m_O1 = (paraPanel.makePanel());
// TODO this is defunct anyways... (MK, 2010-03) // TODO this is defunct anyways... (MK, 2010-03)
// EvAClient.setProperty("eva2.server.oa.go.Tools.InterfaceTest", "eva2.server.oa.go.Tools.Test1,eva2.server.oa.go.Tools.Test2"); // Main.setProperty("eva2.server.oa.go.Tools.InterfaceTest", "eva2.server.oa.go.Tools.Test1,eva2.server.oa.go.Tools.Test2");
this.m_OptionsPanel = new JTabbedPane(); this.m_OptionsPanel = new JTabbedPane();
JParaPanel paraPanel2 = new JParaPanel(this.m_GO, "MyGUI"); JParaPanel paraPanel2 = new JParaPanel(this.m_GO, "MyGUI");
this.m_O2 = (paraPanel2.makePanel()); this.m_O2 = (paraPanel2.makePanel());

View File

@@ -39,25 +39,6 @@ public class ArchivingNSGAII extends ArchivingNSGA implements java.io.Serializab
pop.SetArchive(new Population()); pop.SetArchive(new Population());
} }
//////////////////////////////////////////////////////////////////////////////////////////////
if (this.m_Debug && false) {
// plot the complete population
double[] tmpD = new double[2];
tmpD[0] = 0;
tmpD[1] = 0;
this.m_Plot = new eva2.gui.Plot("Debug NSGAII", "Y1", "Y2", tmpD, tmpD);
System.out.println("Population size: " + pop.size());
// plot the population
this.m_Plot.setUnconnectedPoint(0, 0, 11);
this.m_Plot.setUnconnectedPoint(1.05, 2.5, 11);
double[][] trueFitness = new double[pop.size()][];
for (int i = 0; i < pop.size(); i++) {
trueFitness[i] = ((AbstractEAIndividual)pop.get(i)).getFitness();
this.m_Plot.setUnconnectedPoint(trueFitness[i][0], trueFitness[i][1], 11);
}
}
//////////////////////////////////////////////////////////////////////////////////////////////
// First merge the current population and the archive // First merge the current population and the archive
Population tmpPop = new Population(); Population tmpPop = new Population();
tmpPop.addPopulation((Population)pop.getClone()); tmpPop.addPopulation((Population)pop.getClone());

View File

@@ -48,36 +48,6 @@ public class ArchivingPESAII extends AbstractArchiving implements java.io.Serial
} }
Population archive = pop.getArchive(); Population archive = pop.getArchive();
////////////////////////////////////////////////////////////////////////////////////
if (this.m_Debug) {
this.m_Plot = new eva2.gui.Plot("Debug SPEAII", "Y1", "Y2", true);
System.out.println("Population size: " + pop.size());
// plot the population
this.m_Plot.setUnconnectedPoint(0, 0, 11);
this.m_Plot.setUnconnectedPoint(1.2, 2.0, 11);
Population tmpPop = new Population();
tmpPop.addPopulation(pop);
tmpPop.addPopulation(pop.getArchive());
double[][] trueFitness;
GraphPointSet mySet = new GraphPointSet(10, this.m_Plot.getFunctionArea());
DPoint myPoint;
Chart2DDPointIconText tmp;
trueFitness = new double[archive.size()][];
for (int i = 0; i < archive.size(); i++) {
trueFitness[i] = ((AbstractEAIndividual)archive.get(i)).getFitness();
}
mySet.setConnectedMode(false);
for (int i = 0; i < trueFitness.length; i++) {
myPoint = new DPoint(trueFitness[i][0], trueFitness[i][1]);
tmp = new Chart2DDPointIconText("");
tmp.setIcon(new Chart2DDPointIconCircle());
myPoint.setIcon(tmp);
mySet.addDPoint(myPoint);
}
}
////////////////////////////////////////////////////////////////////////////////////
// test for each element in population if it // test for each element in population if it
// is dominating a element in the archive // is dominating a element in the archive
for (int i = 0; i < pop.size(); i++) { for (int i = 0; i < pop.size(); i++) {
@@ -87,57 +57,7 @@ public class ArchivingPESAII extends AbstractArchiving implements java.io.Serial
} }
//////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////
if (this.m_Debug) {
// first plot the grid
double[][] bounds;
double[][] trueFitness = new double[archive.size()][];
// first calculate the bounds of the search space
bounds = new double[((AbstractEAIndividual)archive.get(0)).getFitness().length][2];
for (int i = 0; i < bounds.length; i++) {
bounds[i][0] = Double.POSITIVE_INFINITY;
bounds[i][1] = Double.NEGATIVE_INFINITY;
}
for (int i = 0; i < archive.size(); i++) {
trueFitness[i] = ((AbstractEAIndividual)archive.get(i)).getFitness();
for (int j = 0; j < trueFitness[i].length; j++) {
if (trueFitness[i][j] < bounds[j][0]) {
bounds[j][0] = trueFitness[i][j];
}
if (trueFitness[i][j] > bounds[j][1]) {
bounds[j][1] = trueFitness[i][j];
}
}
}
double gridx, gridy;
DLine line;
gridx = (bounds[0][1] - bounds[0][0])/this.m_GridSize;
gridy = (bounds[1][1] - bounds[1][0])/this.m_GridSize;
for (int i = 0; i <= this.m_GridSize; i++) {
line = new DLine(bounds[0][0]+gridx*i, bounds[1][0], bounds[0][0]+gridx*i, bounds[1][1], Color.BLUE);
this.m_Plot.getFunctionArea().addDElement(line);
line = new DLine(bounds[0][0], bounds[1][0]+gridy*i, bounds[0][1], bounds[1][0]+gridy*i, Color.BLUE);
this.m_Plot.getFunctionArea().addDElement(line);
}
// now plot the archive with squeezing factor
int[] sqFactor = this.calculateSqueezeFactor(archive);
GraphPointSet mySet = new GraphPointSet(10, this.m_Plot.getFunctionArea());
DPoint myPoint;
Chart2DDPointIconText tmp;
Chart2DDPointIconCircle tmp2;
mySet.setConnectedMode(false);
for (int i = 0; i < trueFitness.length; i++) {
myPoint = new DPoint(trueFitness[i][0], trueFitness[i][1]);
tmp = new Chart2DDPointIconText("SF:"+sqFactor[i]);
tmp2 = new Chart2DDPointIconCircle();
tmp2.setFillColor(Color.GREEN);
tmp.setIcon(tmp2);
myPoint.setIcon(tmp);
mySet.addDPoint(myPoint);
}
}
////////////////////////////////////////////////////////////////////////////////////
// Now check whether there are individuals to remove // Now check whether there are individuals to remove
int bigSqueeze, index; int bigSqueeze, index;
@@ -157,27 +77,6 @@ public class ArchivingPESAII extends AbstractArchiving implements java.io.Serial
} }
archive.remove(index); archive.remove(index);
} }
////////////////////////////////////////////////////////////////////////////////////
if (this.m_Debug) {
double[][] trueFitness;
GraphPointSet mySet = new GraphPointSet(10, this.m_Plot.getFunctionArea());
DPoint myPoint;
Chart2DDPointIconCircle tmp;
trueFitness = new double[archive.size()][];
for (int i = 0; i < archive.size(); i++) {
trueFitness[i] = ((AbstractEAIndividual)archive.get(i)).getFitness();
}
mySet.setConnectedMode(false);
for (int i = 0; i < trueFitness.length; i++) {
myPoint = new DPoint(trueFitness[i][0], trueFitness[i][1]);
tmp = new Chart2DDPointIconCircle();
tmp.setFillColor(Color.RED);
myPoint.setIcon(tmp);
mySet.addDPoint(myPoint);
}
}
////////////////////////////////////////////////////////////////////////////////////
} }
/** This method will calculate the squeeze factor for a population /** This method will calculate the squeeze factor for a population

View File

@@ -48,16 +48,6 @@ public class ArchivingSPEAII extends AbstractArchiving implements java.io.Serial
pop.SetArchive(new Population()); pop.SetArchive(new Population());
} }
////////////////////////////////////////////////////////////////////////////////////
if (this.m_Debug) {
this.m_Plot = new eva2.gui.Plot("Debug SPEAII", "Y1", "Y2", true);
System.out.println("Population size: " + pop.size());
// plot the population
this.m_Plot.setUnconnectedPoint(0, 0, 11);
this.m_Plot.setUnconnectedPoint(1.2, 2.0, 11);
}
////////////////////////////////////////////////////////////////////////////////////
// First merge the current population and the archive // First merge the current population and the archive
Population tmpPop = new Population(); Population tmpPop = new Population();
tmpPop.addPopulation((Population)pop.getClone()); tmpPop.addPopulation((Population)pop.getClone());
@@ -73,30 +63,6 @@ public class ArchivingSPEAII extends AbstractArchiving implements java.io.Serial
// ((AbstractEAIndividual)tmpPop.get(i)).SetData("kthDistance", new Double(kthDistance[i])); // ((AbstractEAIndividual)tmpPop.get(i)).SetData("kthDistance", new Double(kthDistance[i]));
// } // }
////////////////////////////////////////////////////////////////////////////////////
if (this.m_Debug) {
double[][] trueFitness;
GraphPointSet mySet = new GraphPointSet(10, this.m_Plot.getFunctionArea());
DPoint myPoint;
double tmp1, tmp2;
Chart2DDPointIconText tmp;
trueFitness = new double[tmpPop.size()][];
for (int i = 0; i < tmpPop.size(); i++) {
trueFitness[i] = ((AbstractEAIndividual)tmpPop.get(i)).getFitness();
}
mySet.setConnectedMode(false);
for (int i = 0; i < trueFitness.length; i++) {
myPoint = new DPoint(trueFitness[i][0], trueFitness[i][1]);
tmp1 = Math.round(RawFitness[i]*100)/(double)100;
tmp2 = Math.round(kthDistance[i]*100)/(double)100;
tmp = new Chart2DDPointIconText("RF:"+RawFitness[i]+"/ KD:"+tmp2);
tmp.setIcon(new Chart2DDPointIconCircle());
myPoint.setIcon(tmp);
mySet.addDPoint(myPoint);
}
}
////////////////////////////////////////////////////////////////////////////////////
// Now init the new archive // Now init the new archive
Population archive = new Population(); Population archive = new Population();
archive.setTargetSize(pop.getArchive().getTargetSize()); archive.setTargetSize(pop.getArchive().getTargetSize());
@@ -110,54 +76,6 @@ public class ArchivingSPEAII extends AbstractArchiving implements java.io.Serial
archive.add(tmpPop.get(i)); archive.add(tmpPop.get(i));
} }
} }
///////////////////////////////////////////////////////////////////////////////
// double[][] p = this.showMay(archive);
// if ((true) && ((p[0][0] > d[0][0]) || (p[1][1] > d[1][1]))) {
// this.tz = true;
// this.calculateRawFitness(tmpPop);
// this.tz = false;
// this.m_Plot = new eva2.gui.Plot("Debug SPEAII", "Y1", "Y2");
// // plot the population
// this.m_Plot.setUnconnectedPoint(0, 0, 11);
// this.m_Plot.setUnconnectedPoint(1.2, 2.0, 11);
// System.out.println("------------------Alert max!");
// double[][] trueFitness;
// GraphPointSet mySet = new GraphPointSet(10, this.m_Plot.getFunctionArea());
// DPoint myPoint;
// double tmp1, tmp2;
// Chart2DDPointIconText tmp;
// trueFitness = new double[tmpPop.size()][];
// for (int i = 0; i < tmpPop.size(); i++) {
// trueFitness[i] = ((AbstractEAIndividual)tmpPop.get(i)).getFitness();
// }
// mySet.setConnectedMode(false);
// for (int i = 0; i < trueFitness.length; i++) {
// myPoint = new DPoint(trueFitness[i][0], trueFitness[i][1]);
// tmp1 = Math.round(RawFitness[i]*100)/(double)100;
// tmp2 = Math.round(kthDistance[i]*100)/(double)100;
// tmp = new Chart2DDPointIconText(""+RawFitness[i]+"/"+tmp2);
// tmp.setIcon(new Chart2DDPointIconCircle());
// myPoint.setIcon(tmp);
// mySet.addDPoint(myPoint);
// }
//
// mySet = new GraphPointSet(10, this.m_Plot.getFunctionArea());
// Chart2DDPointIconCircle tmpC;
// trueFitness = new double[archive.size()][];
// for (int i = 0; i < archive.size(); i++) {
// trueFitness[i] = ((AbstractEAIndividual)archive.get(i)).getFitness();
// }
// mySet.setConnectedMode(false);
// for (int i = 0; i < trueFitness.length; i++) {
// myPoint = new DPoint(trueFitness[i][0], trueFitness[i][1]);
// tmpC = new Chart2DDPointIconCircle();
// tmpC.setFillColor(Color.GREEN);
// myPoint.setIcon(tmpC);
// mySet.addDPoint(myPoint);
// }
// }
/////////////////////////////////////////////////////////////////////////////////////
// if there is some place left let's add some more // if there is some place left let's add some more
int currentLevel = 0; int currentLevel = 0;
@@ -169,26 +87,6 @@ public class ArchivingSPEAII extends AbstractArchiving implements java.io.Serial
} }
} }
} }
////////////////////////////////////////////////////////////////////////////////////
if (this.m_Debug) {
double[][] trueFitness;
GraphPointSet mySet = new GraphPointSet(10, this.m_Plot.getFunctionArea());
DPoint myPoint;
Chart2DDPointIconCircle tmp;
trueFitness = new double[archive.size()][];
for (int i = 0; i < archive.size(); i++) {
trueFitness[i] = ((AbstractEAIndividual)archive.get(i)).getFitness();
}
mySet.setConnectedMode(false);
for (int i = 0; i < trueFitness.length; i++) {
myPoint = new DPoint(trueFitness[i][0], trueFitness[i][1]);
tmp = new Chart2DDPointIconCircle();
tmp.setFillColor(Color.GREEN);
myPoint.setIcon(tmp);
mySet.addDPoint(myPoint);
}
}
////////////////////////////////////////////////////////////////////////////////////
// Here i want to remove surplus individuals *pff* // Here i want to remove surplus individuals *pff*
// So the basic idea is to search on the highes level of // So the basic idea is to search on the highes level of
@@ -215,72 +113,8 @@ public class ArchivingSPEAII extends AbstractArchiving implements java.io.Serial
archive.remove(ICurSma); archive.remove(ICurSma);
} }
////////////////////////////////////////////////////////////////////////////////////
if (this.m_Debug) {
double[][] trueFitness;
GraphPointSet mySet = new GraphPointSet(10, this.m_Plot.getFunctionArea());
DPoint myPoint;
Chart2DDPointIconCircle tmp;
trueFitness = new double[archive.size()][];
for (int i = 0; i < archive.size(); i++) {
trueFitness[i] = ((AbstractEAIndividual)archive.get(i)).getFitness();
}
mySet.setConnectedMode(false);
for (int i = 0; i < trueFitness.length; i++) {
myPoint = new DPoint(trueFitness[i][0], trueFitness[i][1]);
tmp = new Chart2DDPointIconCircle();
tmp.setFillColor(Color.RED);
myPoint.setIcon(tmp);
mySet.addDPoint(myPoint);
}
}
////////////////////////////////////////////////////////////////////////////////////
pop.SetArchive(archive); pop.SetArchive(archive);
// if there are too many let's remove the surplus
// i could simply remove the individuals with the
// smallest distance to a neighbor selecting from
// all individuals or just selecting from the ones
// in the range of currentLevel to currentLevel+1
// while (archive.size() > archive.getPopulationSize()) {
// // now it's time to use the <=d operator e.g.
// // remove the individuals that are to close
// // to thier neighbours
// double[][] dist
//
// }
//
// // might sound stuid but as far as i understood this
// // i'll simply select the n best ones regarding SPEAFit
// Population archive = (Population)pop.getArchive().clone();
// archive.clear();
// double smallest;
// int index;
// for (int i = 0; i < archive.getPopulationSize(); i++) {
// // find the smallest one
// index = -1;
// smallest = Double.POSITIVE_INFINITY;
// for (int j = 0; j < SPEAFit.length; j++) {
// if (smallest > SPEAFit[j]) {
// smallest = SPEAFit[j];
// index = j;
// }
// }
//
// if (index > -1) {
// SPEAFit[index] = Double.POSITIVE_INFINITY;
// archive.add(tmpPop.get(index));
// }
// }
// if (this.m_Debug) {
// // plot the archive
// double[] tmpD;
// for (int i = 0; i < archive.size(); i++) {
// tmpD = ((AbstractEAIndividual)archive.get(i)).getFitness();
// this.m_Plot.setUnconnectedPoint(tmpD[0], tmpD[1], 12);
// }
// }
} }
private double[][] showMay(Population pop) { private double[][] showMay(Population pop) {
@@ -539,26 +373,6 @@ public class ArchivingSPEAII extends AbstractArchiving implements java.io.Serial
((AbstractEAIndividual)pop.get(i)).putData("SPEAFit", new Double(SPEAResult[i])); ((AbstractEAIndividual)pop.get(i)).putData("SPEAFit", new Double(SPEAResult[i]));
} }
if (this.m_Debug && this.m_Plot != null) {
//System.out.println("k: " + k);
GraphPointSet mySet = new GraphPointSet(10, this.m_Plot.getFunctionArea());
DPoint myPoint;
double tmp1, tmp2;
Chart2DDPointIconText tmp;
mySet.setConnectedMode(false);
for (int i = 0; i < trueFitness.length; i++) {
myPoint = new DPoint(trueFitness[i][0], trueFitness[i][1]);
tmp1 = Math.round(SPEAResult[i]*100)/(double)100;
tmp2 = Math.round(D[i]*100)/(double)100;
tmp = new Chart2DDPointIconText(""+SPEAStrength[i]+"/"+SPEAFitness[i]);
tmp.setIcon(new Chart2DDPointIconCircle());
myPoint.setIcon(tmp);
mySet.addDPoint(myPoint);
}
}
// Puh! // Puh!
return SPEAResult; return SPEAResult;
} }

View File

@@ -2,7 +2,7 @@ package eva2.optimization.problems;
import eva2.OptimizerFactory; import eva2.OptimizerFactory;
import eva2.OptimizerRunnable; import eva2.OptimizerRunnable;
import eva2.client.EvAClient; import eva2.gui.Main;
import eva2.gui.BeanInspector; import eva2.gui.BeanInspector;
import eva2.optimization.individuals.AbstractEAIndividual; import eva2.optimization.individuals.AbstractEAIndividual;
import eva2.optimization.modules.OptimizationParameters; import eva2.optimization.modules.OptimizationParameters;
@@ -85,7 +85,7 @@ public class ERPStarter {
// Instantiate optimization // Instantiate optimization
OptimizationParameters params = new OptimizationParameters(opt, erp, new EvaluationTerminator(maxEvals)); OptimizationParameters params = new OptimizationParameters(opt, erp, new EvaluationTerminator(maxEvals));
if (startGUI) { if (startGUI) {
EvAClient.initClientGUI(params, null, null, null); Main.initClientGUI(params, null, null, null);
} else { } else {
OptimizerRunnable rnbl = new OptimizerRunnable(params, new StatisticsStandalone(outputFilePrefix, 1, 3, true), false); OptimizerRunnable rnbl = new OptimizerRunnable(params, new StatisticsStandalone(outputFilePrefix, 1, 3, true), false);
// actually start the optimization // actually start the optimization

View File

@@ -13,6 +13,7 @@ import eva2.tools.StringSelection;
import eva2.tools.StringTools; import eva2.tools.StringTools;
import eva2.tools.ToolBox; import eva2.tools.ToolBox;
import eva2.tools.math.Mathematics; import eva2.tools.math.Mathematics;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.PrintWriter; import java.io.PrintWriter;
@@ -25,27 +26,25 @@ import java.util.*;
* updated per iteration in createNextGenerationPerformed and reported to listeners in stopOptPerformed. * updated per iteration in createNextGenerationPerformed and reported to listeners in stopOptPerformed.
* Several different verbosity levels are regarded. * Several different verbosity levels are regarded.
* The method plotCurrentResults should be implemented to plot further results per iteration. * The method plotCurrentResults should be implemented to plot further results per iteration.
* * <p/>
* All displayable data is now routed through a single pipeline, which consists in a * All displayable data is now routed through a single pipeline, which consists in a
* list of Objects assembled in the getOutputValues method. This allows all simple data types which are * list of Objects assembled in the getOutputValues method. This allows all simple data types which are
* provided by the external informer instances to be handled uniformly to the internally collected data, and * provided by the external informer instances to be handled uniformly to the internally collected data, and
* thus they can be plotted and text-dumped in the same manner. * thus they can be plotted and text-dumped in the same manner.
* Basic fields are identified by the enum GraphSelectionEnum and are available independently of additional * Basic fields are identified by the enum GraphSelectionEnum and are available independently of additional
* informer instances. * informer instances.
* * <p/>
* Depending on the field selection state and the informers, the list of data fields is dynamically altered, * Depending on the field selection state and the informers, the list of data fields is dynamically altered,
* however changes during a multi-run are ignored, since the potential of inconsistencies is too high. * however changes during a multi-run are ignored, since the potential of inconsistencies is too high.
* * <p/>
* Listeners implementing InterfaceTextListener receive String output (human readable). * Listeners implementing InterfaceTextListener receive String output (human readable).
* Listeners implementing InterfaceStatisticsListener receive the raw data per iteration. * Listeners implementing InterfaceStatisticsListener receive the raw data per iteration.
* *
* @see StatsParameter
* @author mkron * @author mkron
* * @see StatsParameter
*/ */
public abstract class AbstractStatistics implements InterfaceTextListener, InterfaceStatistics { public abstract class AbstractStatistics implements InterfaceTextListener, InterfaceStatistics {
private transient PrintWriter resultOut; private transient PrintWriter resultOut;
public final static boolean TRACE = false;
protected InterfaceStatisticsParameter m_StatsParams; protected InterfaceStatisticsParameter m_StatsParams;
/** /**
@@ -57,7 +56,7 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter
* by dynamic population optimizers, also due to the graph output. * by dynamic population optimizers, also due to the graph output.
*/ */
private boolean refineMultiRuns = true; private boolean refineMultiRuns = true;
// private ArrayList<double[][]> meanCollection; // private ArrayList<double[][]> meanCollection;
private ArrayList<Object[]> finalObjectData; private ArrayList<Object[]> finalObjectData;
private ArrayList<Double[]> sumDataCollection; // collect summed-up data of multiple runs indexed per iteration private ArrayList<Double[]> sumDataCollection; // collect summed-up data of multiple runs indexed per iteration
protected Object[] currentStatObjectData = null; // the raw Object data collected in an iteration protected Object[] currentStatObjectData = null; // the raw Object data collected in an iteration
@@ -84,10 +83,10 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter
protected int optRunsPerformed; protected int optRunsPerformed;
protected double[] currentBestFit; protected double[] currentBestFit;
protected double[] currentBestFeasibleFit; protected double[] currentBestFeasibleFit;
// protected double[] meanBestFeasibleFit; // protected double[] meanBestFeasibleFit;
protected double[] currentMeanFit; protected double[] currentMeanFit;
protected double[] currentWorstFit; protected double[] currentWorstFit;
// protected double[] meanBestOfRunFitness; // protected double[] meanBestOfRunFitness;
protected double currentAvgEucDistInPop, currentMaxEucDistInPop; protected double currentAvgEucDistInPop, currentMaxEucDistInPop;
protected double currentAvgPopDistMetric, currentMaxPopDistMetric; protected double currentAvgPopDistMetric, currentMaxPopDistMetric;
protected IndividualInterface bestCurrentIndy, bestOfRunIndy, bestOfRunFeasibleIndy, bestFeasibleAllRuns, bestIndyAllRuns; protected IndividualInterface bestCurrentIndy, bestOfRunIndy, bestOfRunFeasibleIndy, bestFeasibleAllRuns, bestIndyAllRuns;
@@ -119,33 +118,33 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter
@Override @Override
public void addDataListener(InterfaceStatisticsListener l) { public void addDataListener(InterfaceStatisticsListener l) {
if (dataListeners==null) { if (dataListeners == null) {
dataListeners=new LinkedList<InterfaceStatisticsListener>(); dataListeners = new LinkedList<InterfaceStatisticsListener>();
} }
if (l!=null && !dataListeners.contains(l)) { if (l != null && !dataListeners.contains(l)) {
dataListeners.add(l); dataListeners.add(l);
} }
} }
@Override @Override
public boolean removeDataListener(InterfaceStatisticsListener l) { public boolean removeDataListener(InterfaceStatisticsListener l) {
if (dataListeners==null) { if (dataListeners == null) {
return false; return false;
} } else {
else {
return dataListeners.remove(l); return dataListeners.remove(l);
} }
} }
private void fireDataListeners() { private void fireDataListeners() {
if (dataListeners!=null) { if (dataListeners != null) {
for (InterfaceStatisticsListener l : dataListeners) { for (InterfaceStatisticsListener l : dataListeners) {
l.notifyGenerationPerformed(currentStatHeader, currentStatObjectData, currentStatDoubleData); l.notifyGenerationPerformed(currentStatHeader, currentStatObjectData, currentStatDoubleData);
} } }
}
} }
private void fireDataListenersFinalize() { private void fireDataListenersFinalize() {
if (dataListeners!=null) { if (dataListeners != null) {
LinkedList<InterfaceStatisticsListener> toRemove = new LinkedList<InterfaceStatisticsListener>(); LinkedList<InterfaceStatisticsListener> toRemove = new LinkedList<InterfaceStatisticsListener>();
for (InterfaceStatisticsListener l : dataListeners) { for (InterfaceStatisticsListener l : dataListeners) {
boolean rm = l.notifyMultiRunFinished(currentStatHeader, finalObjectData); boolean rm = l.notifyMultiRunFinished(currentStatHeader, finalObjectData);
@@ -167,7 +166,7 @@ l.notifyGenerationPerformed(currentStatHeader, currentStatObjectData, currentSta
* @param start if true, give the start signal, otherwise the stop signal * @param start if true, give the start signal, otherwise the stop signal
*/ */
private void fireDataListenersStartStop(int runNumber, boolean normal, boolean start) { private void fireDataListenersStartStop(int runNumber, boolean normal, boolean start) {
if (dataListeners!=null) { if (dataListeners != null) {
for (InterfaceStatisticsListener l : dataListeners) { for (InterfaceStatisticsListener l : dataListeners) {
if (start) { if (start) {
l.notifyRunStarted(runNumber, m_StatsParams.getMultiRuns(), l.notifyRunStarted(runNumber, m_StatsParams.getMultiRuns(),
@@ -178,8 +177,9 @@ l.notifyGenerationPerformed(currentStatHeader, currentStatObjectData, currentSta
l.finalMultiRunResults(currentStatHeader, l.finalMultiRunResults(currentStatHeader,
finalObjectData); finalObjectData);
// } // }
} }
} } }
}
} }
@Override @Override
@@ -206,14 +206,11 @@ l.notifyGenerationPerformed(currentStatHeader, currentStatObjectData, currentSta
&& (m_StatsParams.getOutputVerbosity().getSelectedTagID() > StatisticsParameter.VERBOSITY_NONE)) { // verbosity accordingly high && (m_StatsParams.getOutputVerbosity().getSelectedTagID() > StatisticsParameter.VERBOSITY_NONE)) { // verbosity accordingly high
//!resFName.equalsIgnoreCase("none") && !resFName.equals("")) { //!resFName.equalsIgnoreCase("none") && !resFName.equals("")) {
String fnameBase = makeOutputFileName(m_StatsParams.getResultFilePrefix(), infoString, startDate); String fnameBase = makeOutputFileName(m_StatsParams.getResultFilePrefix(), infoString, startDate);
int cnt=0; int cnt = 0;
String fname = fnameBase; String fname = fnameBase;
while (new File(fname).exists()) { while (new File(fname).exists()) {
cnt++; cnt++;
fname=fnameBase+"."+cnt; fname = fnameBase + "." + cnt;
}
if (TRACE) {
System.out.println("FileName =" + fname);
} }
try { try {
resultOut = new PrintWriter(new FileOutputStream(fname)); resultOut = new PrintWriter(new FileOutputStream(fname));
@@ -230,6 +227,7 @@ l.notifyGenerationPerformed(currentStatHeader, currentStatObjectData, currentSta
/** /**
* Return a simple String describing the current date and time. * Return a simple String describing the current date and time.
*
* @return * @return
*/ */
public static String getDateString() { public static String getDateString() {
@@ -239,12 +237,13 @@ l.notifyGenerationPerformed(currentStatHeader, currentStatObjectData, currentSta
} }
protected boolean doFileOutput() { protected boolean doFileOutput() {
return (m_StatsParams.getOutputTo().getSelectedTagID()!=1); // not "text-window only" return (m_StatsParams.getOutputTo().getSelectedTagID() != 1); // not "text-window only"
} }
private String makeOutputFileName(String prefix, String infoString, String startDate) { private String makeOutputFileName(String prefix, String infoString, String startDate) {
return (prefix + "_" + infoString).replace(' ', '_') + "_" + startDate + ".txt"; return (prefix + "_" + infoString).replace(' ', '_') + "_" + startDate + ".txt";
} }
/** /**
* If set to true, before every run the parameters will be stored to a file at the start * If set to true, before every run the parameters will be stored to a file at the start
* of each run. Default is true. * of each run. Default is true.
@@ -257,20 +256,16 @@ l.notifyGenerationPerformed(currentStatHeader, currentStatObjectData, currentSta
@Override @Override
public void startOptPerformed(String infoString, int runNumber, Object params, List<InterfaceAdditionalPopulationInformer> informerList) { public void startOptPerformed(String infoString, int runNumber, Object params, List<InterfaceAdditionalPopulationInformer> informerList) {
if (TRACE) {
System.out.println("AbstractStatistics.startOptPerformed " + runNumber);
System.out.println("Statsparams were " + BeanInspector.toString(m_StatsParams));
}
if (runNumber == 0) { if (runNumber == 0) {
// store the intial graph selection state, so that modifications during runtime cannot cause inconsistencies // store the intial graph selection state, so that modifications during runtime cannot cause inconsistencies
lastFieldSelection = (StringSelection)m_StatsParams.getFieldSelection().clone(); lastFieldSelection = (StringSelection) m_StatsParams.getFieldSelection().clone();
lastIsShowFull = m_StatsParams.isOutputAllFieldsAsText(); lastIsShowFull = m_StatsParams.isOutputAllFieldsAsText();
currentStatDoubleData=null; currentStatDoubleData = null;
currentStatObjectData=null; currentStatObjectData = null;
List<String> headerFields=getOutputHeaderFieldNames(informerList); List<String> headerFields = getOutputHeaderFieldNames(informerList);
currentStatHeader = headerFields.toArray(new String[headerFields.size()]); currentStatHeader = headerFields.toArray(new String[headerFields.size()]);
currentStatMetaInfo = getOutputMetaInfoAsArray(informerList); currentStatMetaInfo = getOutputMetaInfoAsArray(informerList);
@@ -292,8 +287,7 @@ l.notifyGenerationPerformed(currentStatHeader, currentStatObjectData, currentSta
// else meanCollection = null; // else meanCollection = null;
if (refineMultiRuns) { if (refineMultiRuns) {
sumDataCollection = new ArrayList<Double[]>(); sumDataCollection = new ArrayList<Double[]>();
} } else {
else {
sumDataCollection = null; sumDataCollection = null;
} }
@@ -301,20 +295,20 @@ l.notifyGenerationPerformed(currentStatHeader, currentStatObjectData, currentSta
statDataSumOverAll = null; statDataSumOverAll = null;
// lastAdditionalInfoSums = null; // lastAdditionalInfoSums = null;
feasibleFoundAfterSum=-1; feasibleFoundAfterSum = -1;
numOfRunsFeasibleFound=0; numOfRunsFeasibleFound = 0;
} }
feasibleFoundAfter=-1; feasibleFoundAfter = -1;
bestCurrentIndy = null; bestCurrentIndy = null;
bestOfRunIndy = null; bestOfRunIndy = null;
currentBestFeasibleFit=null; currentBestFeasibleFit = null;
bestOfRunFeasibleIndy = null; bestOfRunFeasibleIndy = null;
lastInformerList = null; lastInformerList = null;
lastSols = null; lastSols = null;
iterationCounter = 0; iterationCounter = 0;
if (printRunIntroVerbosity()) { if (printRunIntroVerbosity()) {
printToTextListener("\n****** Multirun "+runNumber); printToTextListener("\n****** Multirun " + runNumber);
} }
if (params != null) { if (params != null) {
if (printRunIntroVerbosity()) { if (printRunIntroVerbosity()) {
@@ -336,19 +330,13 @@ l.notifyGenerationPerformed(currentStatHeader, currentStatObjectData, currentSta
@Override @Override
public void stopOptPerformed(boolean normal, String stopMessage) { public void stopOptPerformed(boolean normal, String stopMessage) {
if (TRACE) { if (lastSols == null) {
System.out.println("AbstractStatistics.stopOptPerformed");
}
if (lastSols==null) {
System.err.println("WARNING, possibly there was no call to createNextGenerationPerformed before calling stopOptPerformed (AnstractStatistics)."); System.err.println("WARNING, possibly there was no call to createNextGenerationPerformed before calling stopOptPerformed (AnstractStatistics).");
} }
if (iterationCounter < sumDataCollection.size()) { if (iterationCounter < sumDataCollection.size()) {
// no good: later run was shorter than the first one. What to do? Discard the longer one: // no good: later run was shorter than the first one. What to do? Discard the longer one:
if (TRACE) { for (int i = sumDataCollection.size() - 1; i >= iterationCounter; i--) {
System.err.println("Error in AbstractStatistics: later run was shorter than earlier one... discarding rest...");
}
for (int i=sumDataCollection.size()-1; i>=iterationCounter; i--) {
sumDataCollection.remove(i); sumDataCollection.remove(i);
} }
} }
@@ -378,7 +366,7 @@ l.notifyGenerationPerformed(currentStatHeader, currentStatObjectData, currentSta
// meanBestOfRunFitness=bestRunIndividual.getFitness().clone(); // meanBestOfRunFitness=bestRunIndividual.getFitness().clone();
// } else addSecond(meanBestOfRunFitness, bestRunIndividual.getFitness()); // } else addSecond(meanBestOfRunFitness, bestRunIndividual.getFitness());
} }
if (feasibleFoundAfter>0) { if (feasibleFoundAfter > 0) {
if (printRunStoppedVerbosity()) { if (printRunStoppedVerbosity()) {
printToTextListener(" Feasible ind. found after " + feasibleFoundAfter + " evaluations.\n"); printToTextListener(" Feasible ind. found after " + feasibleFoundAfter + " evaluations.\n");
} }
@@ -388,7 +376,7 @@ l.notifyGenerationPerformed(currentStatHeader, currentStatObjectData, currentSta
} }
} }
if (printRunStoppedVerbosity()) { if (printRunStoppedVerbosity()) {
printToTextListener(" Solution correlations (min,max,avg,med,var): " + BeanInspector.toString(((Population)lastSols).getCorrelations((Population)lastSols)) + "\n"); printToTextListener(" Solution correlations (min,max,avg,med,var): " + BeanInspector.toString(((Population) lastSols).getCorrelations((Population) lastSols)) + "\n");
} }
if (bestOfRunFeasibleIndy != null) { if (bestOfRunFeasibleIndy != null) {
runBestFeasibleList.add(bestOfRunFeasibleIndy); runBestFeasibleList.add(bestOfRunFeasibleIndy);
@@ -396,14 +384,14 @@ l.notifyGenerationPerformed(currentStatHeader, currentStatObjectData, currentSta
// meanBestFeasibleFit=bestRunFeasibleIndy.getFitness().clone(); // meanBestFeasibleFit=bestRunFeasibleIndy.getFitness().clone();
// } else addSecond(meanBestFeasibleFit, bestRunFeasibleIndy.getFitness()); // } else addSecond(meanBestFeasibleFit, bestRunFeasibleIndy.getFitness());
if (printRunStoppedVerbosity()) { if (printRunStoppedVerbosity()) {
if ((bestOfRunFeasibleIndy instanceof AbstractEAIndividual) && ((AbstractEAIndividual)bestOfRunFeasibleIndy).equalGenotypes((AbstractEAIndividual)bestOfRunIndy)) { if ((bestOfRunFeasibleIndy instanceof AbstractEAIndividual) && ((AbstractEAIndividual) bestOfRunFeasibleIndy).equalGenotypes((AbstractEAIndividual) bestOfRunIndy)) {
printToTextListener("* Run best feasible individual equals best individual.\n"); printToTextListener("* Run best feasible individual equals best individual.\n");
} else { } else {
if (bestOfRunIndy instanceof AbstractEAIndividual) { if (bestOfRunIndy instanceof AbstractEAIndividual) {
if (((AbstractEAIndividual)bestOfRunIndy).violatesConstraint()) { if (((AbstractEAIndividual) bestOfRunIndy).violatesConstraint()) {
printToTextListener(" Run best individual violates constraints by " + ((AbstractEAIndividual)bestOfRunIndy).getConstraintViolation() + "\n"); printToTextListener(" Run best individual violates constraints by " + ((AbstractEAIndividual) bestOfRunIndy).getConstraintViolation() + "\n");
} }
if (((AbstractEAIndividual)bestOfRunIndy).isMarkedPenalized()) { if (((AbstractEAIndividual) bestOfRunIndy).isMarkedPenalized()) {
printToTextListener(" Run best individual is penalized.\n"); printToTextListener(" Run best individual is penalized.\n");
} }
} }
@@ -411,7 +399,7 @@ l.notifyGenerationPerformed(currentStatHeader, currentStatObjectData, currentSta
} }
} }
} }
if (finalObjectData==null) { if (finalObjectData == null) {
finalObjectData = new ArrayList<Object[]>(); finalObjectData = new ArrayList<Object[]>();
} }
finalObjectData.add(currentStatObjectData); finalObjectData.add(currentStatObjectData);
@@ -431,9 +419,9 @@ l.notifyGenerationPerformed(currentStatHeader, currentStatObjectData, currentSta
printToTextListener("\n"); printToTextListener("\n");
} }
if (printRunStoppedVerbosity()) { if (printRunStoppedVerbosity()) {
if (resultPop!=null && (resultPop.size()>0)) { if (resultPop != null && (resultPop.size() > 0)) {
printToTextListener("Resulting population: \n"); printToTextListener("Resulting population: \n");
for (int i=0; i<resultPop.size(); i++) { for (int i = 0; i < resultPop.size(); i++) {
printToTextListener(AbstractEAIndividual.getDefaultStringRepresentation(resultPop.getEAIndividual(i))); printToTextListener(AbstractEAIndividual.getDefaultStringRepresentation(resultPop.getEAIndividual(i)));
printToTextListener("\n"); printToTextListener("\n");
} }
@@ -451,7 +439,7 @@ l.notifyGenerationPerformed(currentStatHeader, currentStatObjectData, currentSta
// if (bestCurrentIndy!=null) pop.add(bestCurrentIndy); // if (bestCurrentIndy!=null) pop.add(bestCurrentIndy);
// if (bestOfRunIndy!=null) pop.add(bestOfRunIndy); // if (bestOfRunIndy!=null) pop.add(bestOfRunIndy);
// if (bestOfRunFeasibleIndy!=null) pop.add(bestOfRunFeasibleIndy); // if (bestOfRunFeasibleIndy!=null) pop.add(bestOfRunFeasibleIndy);
if (bestIndyAllRuns!=null) { if (bestIndyAllRuns != null) {
pop.add(bestIndyAllRuns); pop.add(bestIndyAllRuns);
} }
return pop; return pop;
@@ -463,12 +451,10 @@ l.notifyGenerationPerformed(currentStatHeader, currentStatObjectData, currentSta
printToTextListener(" solution fit : " + BeanInspector.toString(indy.getFitness())); printToTextListener(" solution fit : " + BeanInspector.toString(indy.getFitness()));
if (!(indy instanceof AbstractEAIndividual)) { if (!(indy instanceof AbstractEAIndividual)) {
printToTextListener(" - feasibility unknown\n"); printToTextListener(" - feasibility unknown\n");
} } else {
else { if (((AbstractEAIndividual) indy).isMarkedPenalized() || ((AbstractEAIndividual) indy).violatesConstraint()) {
if (((AbstractEAIndividual)indy).isMarkedPenalized() || ((AbstractEAIndividual)indy).violatesConstraint()) {
printToTextListener(" - infeasible\n"); printToTextListener(" - infeasible\n");
} } else {
else {
printToTextListener("\n"); printToTextListener("\n");
} }
} }
@@ -495,29 +481,29 @@ l.notifyGenerationPerformed(currentStatHeader, currentStatObjectData, currentSta
protected void finalizeOutput() { protected void finalizeOutput() {
if (printFinalVerbosity()) { if (printFinalVerbosity()) {
printToTextListener("*******\n Runs performed: " + optRunsPerformed + ", reached target " + convergenceCnt + " times with threshold " + m_StatsParams.getConvergenceRateThreshold() + ", rate " + convergenceCnt/(double)m_StatsParams.getMultiRuns() + '\n'); printToTextListener("*******\n Runs performed: " + optRunsPerformed + ", reached target " + convergenceCnt + " times with threshold " + m_StatsParams.getConvergenceRateThreshold() + ", rate " + convergenceCnt / (double) m_StatsParams.getMultiRuns() + '\n');
} }
if (printFinalVerbosity()) { if (printFinalVerbosity()) {
printToTextListener(" Average function calls: " + (functionCallSum/optRunsPerformed) + "\n"); printToTextListener(" Average function calls: " + (functionCallSum / optRunsPerformed) + "\n");
} }
if (printFinalVerbosity() && (feasibleFoundAfterSum>=0.)) { if (printFinalVerbosity() && (feasibleFoundAfterSum >= 0.)) {
printToTextListener(" Feasible solution found in " + numOfRunsFeasibleFound + " of " + optRunsPerformed + " runs \n"); printToTextListener(" Feasible solution found in " + numOfRunsFeasibleFound + " of " + optRunsPerformed + " runs \n");
printToTextListener(" Average evaluations until feasible ind. was found in " + numOfRunsFeasibleFound + " runs: " + feasibleFoundAfterSum/numOfRunsFeasibleFound + " evaluations\n"); printToTextListener(" Average evaluations until feasible ind. was found in " + numOfRunsFeasibleFound + " runs: " + feasibleFoundAfterSum / numOfRunsFeasibleFound + " evaluations\n");
} }
if (printFinalVerbosity() && (statDataSumOverAll != null)) { if (printFinalVerbosity() && (statDataSumOverAll != null)) {
printToTextListener(" Averaged sum of run statistical data: (" + optRunsPerformed + " runs):"); printToTextListener(" Averaged sum of run statistical data: (" + optRunsPerformed + " runs):");
for (int i=0; i<statDataSumOverAll.length; i++) { for (int i = 0; i < statDataSumOverAll.length; i++) {
if (statDataSumOverAll[i]!=null) { if (statDataSumOverAll[i] != null) {
printToTextListener(textFieldDelimiter+(statDataSumOverAll[i]/optRunsPerformed)); printToTextListener(textFieldDelimiter + (statDataSumOverAll[i] / optRunsPerformed));
} }
} }
printToTextListener("\n Averaged last statistical data (" + optRunsPerformed + " runs):"); printToTextListener("\n Averaged last statistical data (" + optRunsPerformed + " runs):");
Double[] lastSum = sumDataCollection.get(sumDataCollection.size()-1); Double[] lastSum = sumDataCollection.get(sumDataCollection.size() - 1);
for (int i=0; i<lastSum.length; i++) { for (int i = 0; i < lastSum.length; i++) {
if (lastSum[i]!=null) { if (lastSum[i] != null) {
printToTextListener(textFieldDelimiter+(lastSum[i]/optRunsPerformed)); printToTextListener(textFieldDelimiter + (lastSum[i] / optRunsPerformed));
} }
} }
// for (int i=0; i<lastAdditionalInfoSums.length; i++) if (lastAdditionalInfoSums[i]!=null) printToTextListener(" \t"+(lastAdditionalInfoSums[i]/optRunsPerformed)); // for (int i=0; i<lastAdditionalInfoSums.length; i++) if (lastAdditionalInfoSums[i]!=null) printToTextListener(" \t"+(lastAdditionalInfoSums[i]/optRunsPerformed));
@@ -528,33 +514,33 @@ l.notifyGenerationPerformed(currentStatHeader, currentStatObjectData, currentSta
printIndy("Overall best", bestIndyAllRuns); printIndy("Overall best", bestIndyAllRuns);
} }
if (printFinalVerbosity()) { if (printFinalVerbosity()) {
printToTextListener(getFinalAdditionalInfo()+'\n'); printToTextListener(getFinalAdditionalInfo() + '\n');
} }
if (optRunsPerformed>1) { if (optRunsPerformed > 1) {
if (runBestFitList.size()>0) { if (runBestFitList.size() > 0) {
// Mathematics.svDiv((double)optRunsPerformed, meanBestOfRunFitness, meanBestOfRunFitness); // Mathematics.svDiv((double)optRunsPerformed, meanBestOfRunFitness, meanBestOfRunFitness);
if (printFinalVerbosity()) { if (printFinalVerbosity()) {
double[] meanBestFit=getMeanBestFit(false); double[] meanBestFit = getMeanBestFit(false);
printToTextListener(" MultiRun stats: Mean best fitness: " + BeanInspector.toString(meanBestFit)+"\n"); printToTextListener(" MultiRun stats: Mean best fitness: " + BeanInspector.toString(meanBestFit) + "\n");
if (meanBestFit.length==1) { if (meanBestFit.length == 1) {
printToTextListener(" MultiRun stats: Variance/Std.Dev.: " + BeanInspector.toString(calcStdDevVar(runBestFitList, meanBestFit[0])) + "\n"); printToTextListener(" MultiRun stats: Variance/Std.Dev.: " + BeanInspector.toString(calcStdDevVar(runBestFitList, meanBestFit[0])) + "\n");
} }
printToTextListener(" MultiRun stats: Median best fitn.: " + BeanInspector.toString(getMedianBestFit(false))+"\n"); printToTextListener(" MultiRun stats: Median best fitn.: " + BeanInspector.toString(getMedianBestFit(false)) + "\n");
} }
} }
if (printFinalVerbosity() && (bestFeasibleAllRuns != null)) { if (printFinalVerbosity() && (bestFeasibleAllRuns != null)) {
printIndy("Overall best feasible", bestFeasibleAllRuns); printIndy("Overall best feasible", bestFeasibleAllRuns);
} }
// if ((runBestFeasibleList.size()>0) && (!equalLists(runBestFeasibleList, runBestFitList))) { // is there a difference between best feasibles and best fit? // if ((runBestFeasibleList.size()>0) && (!equalLists(runBestFeasibleList, runBestFitList))) { // is there a difference between best feasibles and best fit?
if (runBestFeasibleList.size()>0) { // always output feasible stats even if theyre equal if (runBestFeasibleList.size() > 0) { // always output feasible stats even if theyre equal
if (printFinalVerbosity()) { if (printFinalVerbosity()) {
double[] meanBestFeasibleFit=getMeanBestFit(true); double[] meanBestFeasibleFit = getMeanBestFit(true);
printToTextListener(" MultiRun stats: Mean best feasible fitness (" + numOfRunsFeasibleFound + " runs): " + BeanInspector.toString(meanBestFeasibleFit)+"\n"); printToTextListener(" MultiRun stats: Mean best feasible fitness (" + numOfRunsFeasibleFound + " runs): " + BeanInspector.toString(meanBestFeasibleFit) + "\n");
if (meanBestFeasibleFit.length==1) { if (meanBestFeasibleFit.length == 1) {
printToTextListener(" MultiRun stats: Variance/Std.Dev.: " + BeanInspector.toString(calcStdDevVar(runBestFeasibleList, meanBestFeasibleFit[0])) + "\n"); printToTextListener(" MultiRun stats: Variance/Std.Dev.: " + BeanInspector.toString(calcStdDevVar(runBestFeasibleList, meanBestFeasibleFit[0])) + "\n");
} }
printToTextListener(" MultiRun stats: Median best feasible fitn. (: " + numOfRunsFeasibleFound + " runs): " + BeanInspector.toString(getMedianBestFit(true))+"\n"); printToTextListener(" MultiRun stats: Median best feasible fitn. (: " + numOfRunsFeasibleFound + " runs): " + BeanInspector.toString(getMedianBestFit(true)) + "\n");
} }
} }
if (refineMultiRuns && (sumDataCollection != null)) { if (refineMultiRuns && (sumDataCollection != null)) {
@@ -562,25 +548,22 @@ l.notifyGenerationPerformed(currentStatHeader, currentStatObjectData, currentSta
printToTextListener(" Averaged performance:\n"); printToTextListener(" Averaged performance:\n");
} }
// the summed-up values of the mean collection is divided by the number of runs // the summed-up values of the mean collection is divided by the number of runs
for (int i=0; i<sumDataCollection.size(); i++) { for (int i = 0; i < sumDataCollection.size(); i++) {
divideMean(sumDataCollection.get(i), optRunsPerformed); divideMean(sumDataCollection.get(i), optRunsPerformed);
} }
if (printFinalVerbosity()) { if (printFinalVerbosity()) {
printToTextListener(refineToText(sumDataCollection, showAvgIntervals)); printToTextListener(refineToText(sumDataCollection, showAvgIntervals));
} }
} }
if (printFinalVerbosity() && (finalObjectData!=null)) { if (printFinalVerbosity() && (finalObjectData != null)) {
printToTextListener(" Last data line of " + finalObjectData.size() + " multi-runs:\n" ); printToTextListener(" Last data line of " + finalObjectData.size() + " multi-runs:\n");
for (int i=0; i<finalObjectData.size(); i++) { for (int i = 0; i < finalObjectData.size(); i++) {
printToTextListener(BeanInspector.toString(finalObjectData.get(i))); printToTextListener(BeanInspector.toString(finalObjectData.get(i)));
printToTextListener("\n"); printToTextListener("\n");
} }
} }
} }
if (TRACE) {
System.out.println("End of run");
}
if (resultOut != null) { if (resultOut != null) {
String StopDate = getDateString(); String StopDate = getDateString();
resultOut.println("StopDate:" + StopDate); resultOut.println("StopDate:" + StopDate);
@@ -605,26 +588,27 @@ l.notifyGenerationPerformed(currentStatHeader, currentStatObjectData, currentSta
} }
private double[] calcStdDevVar(ArrayList<IndividualInterface> list, double meanFit) { private double[] calcStdDevVar(ArrayList<IndividualInterface> list, double meanFit) {
double tmp=0, sum=0; double tmp = 0, sum = 0;
for (Iterator<IndividualInterface> iter = list.iterator(); iter.hasNext();) { for (Iterator<IndividualInterface> iter = list.iterator(); iter.hasNext(); ) {
IndividualInterface indy = iter.next(); IndividualInterface indy = iter.next();
tmp=indy.getFitness()[0]-meanFit; tmp = indy.getFitness()[0] - meanFit;
sum+=(tmp*tmp); sum += (tmp * tmp);
} }
double[] res = new double[2]; double[] res = new double[2];
res[0]=sum/list.size(); res[0] = sum / list.size();
res[1]=Math.sqrt(res[0]); res[1] = Math.sqrt(res[0]);
return res; return res;
} }
/** /**
* Calculate the mean fitness of a list of individuals. * Calculate the mean fitness of a list of individuals.
*
* @param list * @param list
* @return * @return
*/ */
public static double[] calcMeanFit(List<IndividualInterface> list) { public static double[] calcMeanFit(List<IndividualInterface> list) {
double[] sumFit = list.get(0).getFitness().clone(); double[] sumFit = list.get(0).getFitness().clone();
for (int i=1; i<list.size(); i++) { for (int i = 1; i < list.size(); i++) {
Mathematics.vvAdd(sumFit, list.get(i).getFitness(), sumFit); Mathematics.vvAdd(sumFit, list.get(i).getFitness(), sumFit);
} }
Mathematics.svDiv(list.size(), sumFit, sumFit); Mathematics.svDiv(list.size(), sumFit, sumFit);
@@ -634,7 +618,7 @@ l.notifyGenerationPerformed(currentStatHeader, currentStatObjectData, currentSta
public static double[] calcMedianFit(List<IndividualInterface> list) { public static double[] calcMedianFit(List<IndividualInterface> list) {
ArrayList<double[]> dblAList = new ArrayList<double[]>(list.size()); ArrayList<double[]> dblAList = new ArrayList<double[]>(list.size());
for (int i=0; i<list.size(); i++) { for (int i = 0; i < list.size(); i++) {
dblAList.add(list.get(i).getFitness()); dblAList.add(list.get(i).getFitness());
} }
return Mathematics.median(dblAList, false); return Mathematics.median(dblAList, false);
@@ -651,17 +635,17 @@ l.notifyGenerationPerformed(currentStatHeader, currentStatObjectData, currentSta
} }
public static void refineToText(ArrayList<Double[]> data, int iterationsToShow, StringBuffer sbuf, String delim) { public static void refineToText(ArrayList<Double[]> data, int iterationsToShow, StringBuffer sbuf, String delim) {
double step = data.size()/(iterationsToShow-1.); double step = data.size() / (iterationsToShow - 1.);
int printedIteration=0; int printedIteration = 0;
Double[] meanData; Double[] meanData;
for(int i = 1; i < data.size()+1; i++) { for (int i = 1; i < data.size() + 1; i++) {
// print the first, last and intermediate iterations requested by the integer parameter // print the first, last and intermediate iterations requested by the integer parameter
// first one is printed always, as printedIteration=0 // first one is printed always, as printedIteration=0
if ((i==data.size()) || ((i-1)==Math.round(printedIteration*step))) { if ((i == data.size()) || ((i - 1) == Math.round(printedIteration * step))) {
printedIteration++; printedIteration++;
meanData = data.get(i-1); meanData = data.get(i - 1);
sbuf.append(i); sbuf.append(i);
for (int k=0; k<meanData.length; k++) { for (int k = 0; k < meanData.length; k++) {
sbuf.append(delim); sbuf.append(delim);
sbuf.append(BeanInspector.toString(meanData[k])); sbuf.append(BeanInspector.toString(meanData[k]));
} }
@@ -714,6 +698,7 @@ l.notifyGenerationPerformed(currentStatHeader, currentStatObjectData, currentSta
public void print(String str) { public void print(String str) {
printToTextListener(str); printToTextListener(str);
} }
////////////// InterfaceTextListener ////////////// InterfaceTextListener
@Override @Override
public void println(String str) { public void println(String str) {
@@ -727,7 +712,7 @@ l.notifyGenerationPerformed(currentStatHeader, currentStatObjectData, currentSta
} }
protected boolean doTextOutput() { protected boolean doTextOutput() {
return (resultOut != null) || (textListeners.size()>0); return (resultOut != null) || (textListeners.size() > 0);
} }
/** /**
@@ -781,7 +766,7 @@ l.notifyGenerationPerformed(currentStatHeader, currentStatObjectData, currentSta
protected String[] getOutputMetaInfoAsArray(List<InterfaceAdditionalPopulationInformer> informerList) { protected String[] getOutputMetaInfoAsArray(List<InterfaceAdditionalPopulationInformer> informerList) {
List<String> metaStrings = getOutputMetaInfo(informerList); List<String> metaStrings = getOutputMetaInfo(informerList);
return metaStrings.toArray( new String[metaStrings.size()]); return metaStrings.toArray(new String[metaStrings.size()]);
} }
/** /**
@@ -789,15 +774,16 @@ l.notifyGenerationPerformed(currentStatHeader, currentStatObjectData, currentSta
* method {@link #getSimpleOutputValues()}. * method {@link #getSimpleOutputValues()}.
* Basic fields are identified by the enum GraphSelectionEnum and are available independently of additional * Basic fields are identified by the enum GraphSelectionEnum and are available independently of additional
* informer instances. * informer instances.
* @see #getSimpleOutputValues() *
* @return * @return
* @see #getSimpleOutputValues()
*/ */
protected String[] getSimpleOutputHeader() { protected String[] getSimpleOutputHeader() {
// collect the full header by using the entries of the GraphSelectionEnum // collect the full header by using the entries of the GraphSelectionEnum
GraphSelectionEnum[] vals = GraphSelectionEnum.values(); GraphSelectionEnum[] vals = GraphSelectionEnum.values();
ArrayList<String>headerEntries = new ArrayList<String>(); ArrayList<String> headerEntries = new ArrayList<String>();
headerEntries.add("FunctionCalls"); headerEntries.add("FunctionCalls");
for (int i=0; i<vals.length; i++) { for (int i = 0; i < vals.length; i++) {
if (isRequestedField(vals[i])) { if (isRequestedField(vals[i])) {
headerEntries.add(vals[i].toString()); headerEntries.add(vals[i].toString());
} }
@@ -811,14 +797,14 @@ l.notifyGenerationPerformed(currentStatHeader, currentStatObjectData, currentSta
* the method {@link #getSimpleOutputValues()}. * the method {@link #getSimpleOutputValues()}.
* Basic meta info is defined by the enum GraphSelectionEnum. * Basic meta info is defined by the enum GraphSelectionEnum.
* *
* @see #getSimpleOutputValues()
* @return * @return
* @see #getSimpleOutputValues()
*/ */
protected String[] getSimpleOutputMetaInfo() { protected String[] getSimpleOutputMetaInfo() {
GraphSelectionEnum[] vals = GraphSelectionEnum.values(); GraphSelectionEnum[] vals = GraphSelectionEnum.values();
ArrayList<String> headerInfo = new ArrayList<String>(); ArrayList<String> headerInfo = new ArrayList<String>();
headerInfo.add("The number of function evaluations"); headerInfo.add("The number of function evaluations");
for (int i=0; i<vals.length; i++) { for (int i = 0; i < vals.length; i++) {
if (isRequestedField(vals[i])) { if (isRequestedField(vals[i])) {
headerInfo.add(GraphSelectionEnum.getInfoStrings()[i]); headerInfo.add(GraphSelectionEnum.getInfoStrings()[i]);
} }
@@ -864,28 +850,48 @@ l.notifyGenerationPerformed(currentStatHeader, currentStatObjectData, currentSta
* Return all simple data fields collected internally. This must correspond to the * Return all simple data fields collected internally. This must correspond to the
* method {@link #getSimpleOutputHeader()}. * method {@link #getSimpleOutputHeader()}.
* *
* @see #getSimpleOutputHeader()
* @return * @return
* @see #getSimpleOutputHeader()
*/ */
protected Object[] getSimpleOutputValues() { protected Object[] getSimpleOutputValues() {
GraphSelectionEnum[] selEnumVals=null; GraphSelectionEnum[] selEnumVals = null;
selEnumVals = GraphSelectionEnum.values(); selEnumVals = GraphSelectionEnum.values();
// else selEnumVals = (GraphSelectionEnum[]) (m_StatsParams.getGraphSelection().getSelectedEnum(GraphSelectionEnum.values())); // else selEnumVals = (GraphSelectionEnum[]) (m_StatsParams.getGraphSelection().getSelectedEnum(GraphSelectionEnum.values()));
Object[] ret = new Object[1+selEnumVals.length]; Object[] ret = new Object[1 + selEnumVals.length];
ret[0]=functionCalls; ret[0] = functionCalls;
for (int i=1; i<=selEnumVals.length; i++) { for (int i = 1; i <= selEnumVals.length; i++) {
switch (selEnumVals[i-1]) { // the field i+1 contains enum value i, because field 0 is reserved for the number of function calls switch (selEnumVals[i - 1]) { // the field i+1 contains enum value i, because field 0 is reserved for the number of function calls
// currentBest, currentWorst, runBest, currentBestFeasible, runBestFeasible, avgPopDistance, maxPopDistance; // currentBest, currentWorst, runBest, currentBestFeasible, runBestFeasible, avgPopDistance, maxPopDistance;
case currentBest: ret[i]=currentBestFit[defaultFitCriterion ]; break; case currentBest:
case meanFit: ret[i] = (currentMeanFit==null) ? Double.NaN : currentMeanFit[defaultFitCriterion]; break; ret[i] = currentBestFit[defaultFitCriterion];
case currentWorst: ret[i] = (currentWorstFit==null) ? Double.NaN : currentWorstFit[defaultFitCriterion]; break; break;
case runBest: ret[i] = bestOfRunIndy.getFitness()[defaultFitCriterion]; break; case meanFit:
case currentBestFeasible: ret[i] = (currentBestFeasibleFit==null) ? Double.NaN : currentBestFeasibleFit[defaultFitCriterion]; break; ret[i] = (currentMeanFit == null) ? Double.NaN : currentMeanFit[defaultFitCriterion];
case runBestFeasible: ret[i] = (bestOfRunFeasibleIndy==null) ? Double.NaN : bestOfRunFeasibleIndy.getFitness()[defaultFitCriterion]; break; break;
case avgEucPopDistance: ret[i] = currentAvgEucDistInPop; break; case currentWorst:
case maxEucPopDistance: ret[i] = currentMaxEucDistInPop; break; ret[i] = (currentWorstFit == null) ? Double.NaN : currentWorstFit[defaultFitCriterion];
case avgPopMetricDist: ret[i] = currentAvgPopDistMetric; break; break;
case maxPopMetricDist: ret[i] = currentMaxPopDistMetric; break; case runBest:
ret[i] = bestOfRunIndy.getFitness()[defaultFitCriterion];
break;
case currentBestFeasible:
ret[i] = (currentBestFeasibleFit == null) ? Double.NaN : currentBestFeasibleFit[defaultFitCriterion];
break;
case runBestFeasible:
ret[i] = (bestOfRunFeasibleIndy == null) ? Double.NaN : bestOfRunFeasibleIndy.getFitness()[defaultFitCriterion];
break;
case avgEucPopDistance:
ret[i] = currentAvgEucDistInPop;
break;
case maxEucPopDistance:
ret[i] = currentMaxEucDistInPop;
break;
case avgPopMetricDist:
ret[i] = currentAvgPopDistMetric;
break;
case maxPopMetricDist:
ret[i] = currentMaxPopDistMetric;
break;
} }
} }
// all standard fields should be filled now // all standard fields should be filled now
@@ -908,10 +914,10 @@ l.notifyGenerationPerformed(currentStatHeader, currentStatObjectData, currentSta
* names of the corresponding fields in the same order. * names of the corresponding fields in the same order.
* The length of this list depends on the field selection state. * The length of this list depends on the field selection state.
* *
* @see #getOutputHeader(List, PopulationInterface)
* @param informerList * @param informerList
* @param pop * @param pop
* @return * @return
* @see #getOutputHeader(List, PopulationInterface)
*/ */
protected List<Object> getOutputValues(List<InterfaceAdditionalPopulationInformer> informerList, PopulationInterface pop) { protected List<Object> getOutputValues(List<InterfaceAdditionalPopulationInformer> informerList, PopulationInterface pop) {
LinkedList<Object> values = new LinkedList<Object>(); LinkedList<Object> values = new LinkedList<Object>();
@@ -924,7 +930,7 @@ l.notifyGenerationPerformed(currentStatHeader, currentStatObjectData, currentSta
} }
// remove those which are not requested // remove those which are not requested
Iterator<Object> iter = values.iterator(); Iterator<Object> iter = values.iterator();
int cnt=0; int cnt = 0;
iter.next(); // skip the first field (function calls) which is not regarded here iter.next(); // skip the first field (function calls) which is not regarded here
if (!lastIsShowFull) { if (!lastIsShowFull) {
while (iter.hasNext()) { while (iter.hasNext()) {
@@ -949,26 +955,26 @@ l.notifyGenerationPerformed(currentStatHeader, currentStatObjectData, currentSta
*/ */
protected List<String> getAdditionalHeaderMetaInfo(List<InterfaceAdditionalPopulationInformer> informerList, List<String> metaInfo) { protected List<String> getAdditionalHeaderMetaInfo(List<InterfaceAdditionalPopulationInformer> informerList, List<String> metaInfo) {
LinkedList<String> headers = new LinkedList<String>(); LinkedList<String> headers = new LinkedList<String>();
if (metaInfo!=null && (metaInfo.size()>0)) { if (metaInfo != null && (metaInfo.size() > 0)) {
System.err.println("Warning, metaInfo list should be empty in AbstractStatistics.getAdditionalHeaderMetaInfo"); System.err.println("Warning, metaInfo list should be empty in AbstractStatistics.getAdditionalHeaderMetaInfo");
} }
for (InterfaceAdditionalPopulationInformer informer : informerList) { for (InterfaceAdditionalPopulationInformer informer : informerList) {
headers.addAll(Arrays.asList(informer.getAdditionalDataHeader())); headers.addAll(Arrays.asList(informer.getAdditionalDataHeader()));
if (metaInfo!=null) { if (metaInfo != null) {
metaInfo.addAll(Arrays.asList(informer.getAdditionalDataInfo())); metaInfo.addAll(Arrays.asList(informer.getAdditionalDataInfo()));
} }
// hdr = hdr + "\t " + informer.getAdditionalDataHeader(pop); // hdr = hdr + "\t " + informer.getAdditionalDataHeader(pop);
} }
Iterator<String> hIter = headers.iterator(); Iterator<String> hIter = headers.iterator();
Iterator<String> mIter = (metaInfo!=null) ? metaInfo.iterator() : null; Iterator<String> mIter = (metaInfo != null) ? metaInfo.iterator() : null;
if (!lastIsShowFull) { if (!lastIsShowFull) {
while (hIter.hasNext()) { while (hIter.hasNext()) {
if (mIter!=null && mIter.hasNext()) { if (mIter != null && mIter.hasNext()) {
mIter.next(); mIter.next();
} }
if (!isRequestedAdditionalField(hIter.next())) { if (!isRequestedAdditionalField(hIter.next())) {
hIter.remove(); hIter.remove();
if (mIter!=null && mIter.hasNext()) { if (mIter != null && mIter.hasNext()) {
mIter.remove(); mIter.remove();
} }
} }
@@ -987,11 +993,11 @@ l.notifyGenerationPerformed(currentStatHeader, currentStatObjectData, currentSta
* @param pop * @param pop
* @return * @return
*/ */
protected Pair<String,Object[]> getOutputData(List<InterfaceAdditionalPopulationInformer> informerList, PopulationInterface pop) { protected Pair<String, Object[]> getOutputData(List<InterfaceAdditionalPopulationInformer> informerList, PopulationInterface pop) {
List<Object> statValues = getOutputValues(informerList, pop); List<Object> statValues = getOutputValues(informerList, pop);
String statValuesString = StringTools.concatValues(statValues, textFieldDelimiter); String statValuesString = StringTools.concatValues(statValues, textFieldDelimiter);
return new Pair<String,Object[]>(statValuesString, statValues.toArray(new Object[statValues.size()])); return new Pair<String, Object[]>(statValuesString, statValues.toArray(new Object[statValues.size()]));
} }
// /** // /**
@@ -1045,13 +1051,13 @@ l.notifyGenerationPerformed(currentStatHeader, currentStatObjectData, currentSta
firstPlot = false; firstPlot = false;
} }
if ((iterationCounter == 0) && printHeaderByVerbosity()) { if ((iterationCounter == 0) && printHeaderByVerbosity()) {
printToTextListener(getOutputHeaderFieldNamesAsString(null)+'\n'); printToTextListener(getOutputHeaderFieldNamesAsString(null) + '\n');
} }
if (doTextOutput() && printLineByVerbosity(calls)) { if (doTextOutput() && printLineByVerbosity(calls)) {
Pair<String,Object[]> addInfo = getOutputData(null, null); Pair<String, Object[]> addInfo = getOutputData(null, null);
printToTextListener(addInfo.head()+'\n'); printToTextListener(addInfo.head() + '\n');
if (addInfo.tail()!=null) { if (addInfo.tail() != null) {
statDataSumOverAll = updateSum(statDataSumOverAll, ToolBox.parseDoubles(addInfo.tail())); statDataSumOverAll = updateSum(statDataSumOverAll, ToolBox.parseDoubles(addInfo.tail()));
} }
} }
@@ -1067,18 +1073,17 @@ l.notifyGenerationPerformed(currentStatHeader, currentStatObjectData, currentSta
* @param curInfo * @param curInfo
*/ */
private static Double[] updateSum(Double[] resultSum, Double[] curInfo) { private static Double[] updateSum(Double[] resultSum, Double[] curInfo) {
if (resultSum==null) { if (resultSum == null) {
resultSum = curInfo.clone(); resultSum = curInfo.clone();
} else { } else {
if (curInfo.length != resultSum.length) { if (curInfo.length != resultSum.length) {
System.err.println("Error in AbstractStatistics.updateAdditionalInfo: mismatching info arrays!"); System.err.println("Error in AbstractStatistics.updateAdditionalInfo: mismatching info arrays!");
} else { } else {
for (int i=0; i<curInfo.length; i++) { for (int i = 0; i < curInfo.length; i++) {
if (resultSum[i]==null || (curInfo[i]==null)) { if (resultSum[i] == null || (curInfo[i] == null)) {
resultSum[i]=null; resultSum[i] = null;
} } else {
else { resultSum[i] += curInfo[i];
resultSum[i]+=curInfo[i];
} }
} }
} }
@@ -1088,6 +1093,7 @@ l.notifyGenerationPerformed(currentStatHeader, currentStatObjectData, currentSta
/** /**
* If the population returns a specific data array, this method is called instead of doing standard output * If the population returns a specific data array, this method is called instead of doing standard output
*
* @param pop * @param pop
* @param informer * @param informer
*/ */
@@ -1102,6 +1108,7 @@ l.notifyGenerationPerformed(currentStatHeader, currentStatObjectData, currentSta
/** /**
* To set a list of informers (even before the actual run is started). * To set a list of informers (even before the actual run is started).
*
* @param informerList * @param informerList
*/ */
public void setInitialInformerList(List<InterfaceAdditionalPopulationInformer> informerList) { public void setInitialInformerList(List<InterfaceAdditionalPopulationInformer> informerList) {
@@ -1120,8 +1127,8 @@ l.notifyGenerationPerformed(currentStatHeader, currentStatObjectData, currentSta
if ((bestIndyAllRuns == null) || (secondIsBetter(bestIndyAllRuns, bestCurrentIndy))) { if ((bestIndyAllRuns == null) || (secondIsBetter(bestIndyAllRuns, bestCurrentIndy))) {
bestIndyAllRuns = bestCurrentIndy; bestIndyAllRuns = bestCurrentIndy;
} }
if ((bestOfRunIndy==null) || (secondIsBetter(bestOfRunIndy, bestCurrentIndy))) { if ((bestOfRunIndy == null) || (secondIsBetter(bestOfRunIndy, bestCurrentIndy))) {
bestOfRunIndy=bestCurrentIndy; bestOfRunIndy = bestCurrentIndy;
} }
if (bestCurrentIndy == null) { if (bestCurrentIndy == null) {
System.err.println("createNextGenerationPerformed BestInd==null"); System.err.println("createNextGenerationPerformed BestInd==null");
@@ -1131,19 +1138,19 @@ l.notifyGenerationPerformed(currentStatHeader, currentStatObjectData, currentSta
System.err.println("BestFitness==null !"); System.err.println("BestFitness==null !");
} }
if (pop instanceof Population) { if (pop instanceof Population) {
AbstractEAIndividual curBestFeasible = ((Population)pop).getBestFeasibleIndividual(-1); AbstractEAIndividual curBestFeasible = ((Population) pop).getBestFeasibleIndividual(-1);
if (curBestFeasible!=null) { // a feasible ind. was found! if (curBestFeasible != null) { // a feasible ind. was found!
if (currentBestFeasibleFit==null) { // feasible indy found for the first time if (currentBestFeasibleFit == null) { // feasible indy found for the first time
numOfRunsFeasibleFound++; numOfRunsFeasibleFound++;
feasibleFoundAfter=((Population)pop).getFunctionCalls(); feasibleFoundAfter = ((Population) pop).getFunctionCalls();
if (feasibleFoundAfterSum<0) { if (feasibleFoundAfterSum < 0) {
feasibleFoundAfterSum=0.; feasibleFoundAfterSum = 0.;
} // initial signaling value was -1. } // initial signaling value was -1.
feasibleFoundAfterSum+=feasibleFoundAfter; feasibleFoundAfterSum += feasibleFoundAfter;
} }
currentBestFeasibleFit = curBestFeasible.getFitness().clone(); currentBestFeasibleFit = curBestFeasible.getFitness().clone();
if ((bestOfRunFeasibleIndy==null) || (secondIsBetter(bestOfRunFeasibleIndy, curBestFeasible))) { if ((bestOfRunFeasibleIndy == null) || (secondIsBetter(bestOfRunFeasibleIndy, curBestFeasible))) {
bestOfRunFeasibleIndy=(AbstractEAIndividual)curBestFeasible.clone(); bestOfRunFeasibleIndy = (AbstractEAIndividual) curBestFeasible.clone();
// System.out.println("New best feasible: " + AbstractEAIndividual.getDefaultStringRepresentation((AbstractEAIndividual)bestRunFeasibleIndy)); // System.out.println("New best feasible: " + AbstractEAIndividual.getDefaultStringRepresentation((AbstractEAIndividual)bestRunFeasibleIndy));
} }
if ((bestFeasibleAllRuns == null) || (secondIsBetter(bestFeasibleAllRuns, bestOfRunFeasibleIndy))) { if ((bestFeasibleAllRuns == null) || (secondIsBetter(bestFeasibleAllRuns, bestOfRunFeasibleIndy))) {
@@ -1157,14 +1164,12 @@ l.notifyGenerationPerformed(currentStatHeader, currentStatObjectData, currentSta
// collect these data fields only if requested by the user // collect these data fields only if requested by the user
if (lastIsShowFull || GraphSelectionEnum.doPlotMean(lastFieldSelection)) { if (lastIsShowFull || GraphSelectionEnum.doPlotMean(lastFieldSelection)) {
currentMeanFit = pop.getMeanFitness().clone(); currentMeanFit = pop.getMeanFitness().clone();
} } else {
else {
currentMeanFit = null; currentMeanFit = null;
} }
if (lastIsShowFull || GraphSelectionEnum.doPlotWorst(lastFieldSelection)) { if (lastIsShowFull || GraphSelectionEnum.doPlotWorst(lastFieldSelection)) {
currentWorstFit = pop.getWorstIndividual().getFitness().clone(); currentWorstFit = pop.getWorstIndividual().getFitness().clone();
} } else {
else {
currentWorstFit = null; currentWorstFit = null;
} }
@@ -1172,7 +1177,7 @@ l.notifyGenerationPerformed(currentStatHeader, currentStatObjectData, currentSta
if (lastIsShowFull || GraphSelectionEnum.doPlotAvgEucDist(lastFieldSelection) if (lastIsShowFull || GraphSelectionEnum.doPlotAvgEucDist(lastFieldSelection)
|| GraphSelectionEnum.doPlotMaxEucDist(lastFieldSelection)) { || GraphSelectionEnum.doPlotMaxEucDist(lastFieldSelection)) {
double[] measures = ((Population)pop).getPopulationMeasures((InterfaceDistanceMetric)null); double[] measures = ((Population) pop).getPopulationMeasures((InterfaceDistanceMetric) null);
if (measures != null) { if (measures != null) {
currentAvgEucDistInPop = measures[0]; currentAvgEucDistInPop = measures[0];
currentMaxEucDistInPop = measures[2]; currentMaxEucDistInPop = measures[2];
@@ -1181,7 +1186,7 @@ l.notifyGenerationPerformed(currentStatHeader, currentStatObjectData, currentSta
if (lastIsShowFull || GraphSelectionEnum.doPlotAvgPopMetricDist(lastFieldSelection) if (lastIsShowFull || GraphSelectionEnum.doPlotAvgPopMetricDist(lastFieldSelection)
|| GraphSelectionEnum.doPlotMaxPopMetricDist(lastFieldSelection)) { || GraphSelectionEnum.doPlotMaxPopMetricDist(lastFieldSelection)) {
double[] measures = ((Population)pop).getPopulationMeasures(); double[] measures = ((Population) pop).getPopulationMeasures();
if (measures != null) { if (measures != null) {
currentAvgPopDistMetric = measures[0]; currentAvgPopDistMetric = measures[0];
currentMaxPopDistMetric = measures[2]; currentMaxPopDistMetric = measures[2];
@@ -1196,15 +1201,12 @@ l.notifyGenerationPerformed(currentStatHeader, currentStatObjectData, currentSta
/** /**
* Do some data collection on the population. * Do some data collection on the population.
*
*/ */
@Override @Override
public synchronized void createNextGenerationPerformed(PopulationInterface public synchronized void createNextGenerationPerformed(PopulationInterface
pop, InterfaceOptimizer opt, List<InterfaceAdditionalPopulationInformer> informerList) { pop, InterfaceOptimizer opt, List<InterfaceAdditionalPopulationInformer> informerList) {
lastInformerList = informerList; lastInformerList = informerList;
if (TRACE) {
printToTextListener(".. in createNextGenPerformed after " + pop.getFunctionCalls() + " evals.\n");
}
if (resultOut != null) { if (resultOut != null) {
resultOut.flush(); resultOut.flush();
} }
@@ -1212,7 +1214,7 @@ l.notifyGenerationPerformed(currentStatHeader, currentStatObjectData, currentSta
initPlots(pop, informerList); initPlots(pop, informerList);
// if (doTextOutput()) printToTextListener(getOutputHeader(informer, pop)+'\n'); // if (doTextOutput()) printToTextListener(getOutputHeader(informer, pop)+'\n');
firstPlot = false; firstPlot = false;
currentBestFeasibleFit=null; currentBestFeasibleFit = null;
} }
if (pop.getSpecificData() != null) { // this is more or less deprecated. the standard population implementation will always return null. However the ES module wont if (pop.getSpecificData() != null) { // this is more or less deprecated. the standard population implementation will always return null. However the ES module wont
@@ -1222,27 +1224,27 @@ l.notifyGenerationPerformed(currentStatHeader, currentStatObjectData, currentSta
collectPopData(pop); collectPopData(pop);
if (iterationCounter==0) { if (iterationCounter == 0) {
String headerLine = StringTools.concatFields(currentStatHeader, textFieldDelimiter); String headerLine = StringTools.concatFields(currentStatHeader, textFieldDelimiter);
if (printHeaderByVerbosity()) { if (printHeaderByVerbosity()) {
printToTextListener(headerLine+'\n'); printToTextListener(headerLine + '\n');
} }
} }
lastSols = (opt!=null) ? new Population(opt.getAllSolutions().getSolutions()) : pop; lastSols = (opt != null) ? new Population(opt.getAllSolutions().getSolutions()) : pop;
// Pair<String,Double[]> addData = getOutputData(informerList, lastSols); // Pair<String,Double[]> addData = getOutputData(informerList, lastSols);
// System.out.println("lastSols size: " + 500*PSymbolicRegression.getAvgIndySize(lastSols)); // System.out.println("lastSols size: " + 500*PSymbolicRegression.getAvgIndySize(lastSols));
// System.out.println("Mem use: " + getMemoryUse()); // System.out.println("Mem use: " + getMemoryUse());
Pair<String,Object[]> addData = getOutputData(informerList, lastSols); Pair<String, Object[]> addData = getOutputData(informerList, lastSols);
if (doTextOutput()) { // this is where the text output is actually written if (doTextOutput()) { // this is where the text output is actually written
if (printLineByVerbosity(iterationCounter)) { if (printLineByVerbosity(iterationCounter)) {
// printToTextListener(functionCalls + textFieldDelimiter); // printToTextListener(functionCalls + textFieldDelimiter);
printToTextListener(addData.head()+'\n'); printToTextListener(addData.head() + '\n');
} }
} }
currentStatObjectData = addData.tail(); currentStatObjectData = addData.tail();
currentStatDoubleData = ToolBox.parseDoubles(currentStatObjectData); currentStatDoubleData = ToolBox.parseDoubles(currentStatObjectData);
if (currentStatObjectData!=null) { if (currentStatObjectData != null) {
statDataSumOverAll = updateSum(statDataSumOverAll, currentStatDoubleData); // this adds up all data of a single run statDataSumOverAll = updateSum(statDataSumOverAll, currentStatDoubleData); // this adds up all data of a single run
} else { } else {
System.err.println("Warning in AbstractStatistics!"); System.err.println("Warning in AbstractStatistics!");
@@ -1251,14 +1253,14 @@ l.notifyGenerationPerformed(currentStatHeader, currentStatObjectData, currentSta
if (sumDataCollection != null) { if (sumDataCollection != null) {
// Collect average data // Collect average data
Double[] sumDataEntry = null; Double[] sumDataEntry = null;
if ((optRunsPerformed==0) && (sumDataCollection.size()<=iterationCounter)) { if ((optRunsPerformed == 0) && (sumDataCollection.size() <= iterationCounter)) {
// in the first run, newly allocate the arrays // in the first run, newly allocate the arrays
// assume that all later data sets will have the same format // assume that all later data sets will have the same format
// means = new double[4][currentBestFit.length]; // this only fits fitness vectors! of course this is sensible for multi-crit fitnesses... // means = new double[4][currentBestFit.length]; // this only fits fitness vectors! of course this is sensible for multi-crit fitnesses...
sumDataEntry = currentStatDoubleData.clone(); sumDataEntry = currentStatDoubleData.clone();
sumDataCollection.add(sumDataEntry); sumDataCollection.add(sumDataEntry);
} else { } else {
if (sumDataCollection.size()<=iterationCounter) {// bad case! if (sumDataCollection.size() <= iterationCounter) {// bad case!
// may happen for dynamic pop-sizes, e.g. in Tribes, when runs do not necessarily send the // may happen for dynamic pop-sizes, e.g. in Tribes, when runs do not necessarily send the
// "generation performed" event the same number of times. // "generation performed" event the same number of times.
// thus: dont do an update for events that are "too late" // thus: dont do an update for events that are "too late"
@@ -1285,9 +1287,6 @@ l.notifyGenerationPerformed(currentStatHeader, currentStatObjectData, currentSta
// } // }
plotCurrentResults(); plotCurrentResults();
fireDataListeners(); fireDataListeners();
if (TRACE) {
printToTextListener(".. done createNextGenPerformed after " + pop.getFunctionCalls() + " evals.\n");
}
if (resultOut != null) { if (resultOut != null) {
resultOut.flush(); resultOut.flush();
} }
@@ -1309,7 +1308,7 @@ l.notifyGenerationPerformed(currentStatHeader, currentStatObjectData, currentSta
private boolean printRunIntroVerbosity() { private boolean printRunIntroVerbosity() {
return (m_StatsParams.getOutputVerbosity().getSelectedTagID() >= StatisticsParameter.VERBOSITY_KTH_IT) return (m_StatsParams.getOutputVerbosity().getSelectedTagID() >= StatisticsParameter.VERBOSITY_KTH_IT)
|| (optRunsPerformed==0 && (m_StatsParams.getOutputVerbosity().getSelectedTagID() >= StatisticsParameter.VERBOSITY_FINAL)); || (optRunsPerformed == 0 && (m_StatsParams.getOutputVerbosity().getSelectedTagID() >= StatisticsParameter.VERBOSITY_FINAL));
} }
private boolean printRunStoppedVerbosity() { private boolean printRunStoppedVerbosity() {
@@ -1324,15 +1323,14 @@ l.notifyGenerationPerformed(currentStatHeader, currentStatObjectData, currentSta
// ingeniously shifting i by two since the stats counter starts at 0 // ingeniously shifting i by two since the stats counter starts at 0
// after two evaluations have already happened: initialization and first optimization // after two evaluations have already happened: initialization and first optimization
// this allows the last iteration to be within the displayed set if k is a divisor of whole iterations as expected // this allows the last iteration to be within the displayed set if k is a divisor of whole iterations as expected
if ((i==0) || (k==0)) { if ((i == 0) || (k == 0)) {
return true; return true;
} } else {
else { if (i <= 2) {
if (i<=2) {
return (i % k) == 0; return (i % k) == 0;
} // show more at the beginning (always first time) } // show more at the beginning (always first time)
else { else {
return ((i+2) % k) == 0; return ((i + 2) % k) == 0;
} }
} }
} }
@@ -1342,8 +1340,8 @@ l.notifyGenerationPerformed(currentStatHeader, currentStatObjectData, currentSta
} }
private static void divideMean(Double[] mean, double d) { private static void divideMean(Double[] mean, double d) {
for (int j=0; j<mean.length; j++) { for (int j = 0; j < mean.length; j++) {
if (mean[j]!=null) { if (mean[j] != null) {
mean[j] /= d; mean[j] /= d;
} }
} }
@@ -1367,7 +1365,7 @@ l.notifyGenerationPerformed(currentStatHeader, currentStatObjectData, currentSta
return false; return false;
} }
if (indy1 instanceof AbstractEAIndividual) { if (indy1 instanceof AbstractEAIndividual) {
return ((AbstractEAIndividual)indy2).isDominatingDebConstraints((AbstractEAIndividual)indy1); return ((AbstractEAIndividual) indy2).isDominatingDebConstraints((AbstractEAIndividual) indy1);
} }
return (indy2.isDominant(indy1)); return (indy2.isDominant(indy1));
} }

View File

@@ -1,26 +1,12 @@
package eva2.optimization.stat; package eva2.optimization.stat;
/*
* 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.optimization.go.IndividualInterface; import eva2.optimization.go.IndividualInterface;
import eva2.optimization.population.PopulationInterface; import eva2.optimization.population.PopulationInterface;
import eva2.optimization.population.Population; import eva2.optimization.population.Population;
import eva2.optimization.problems.InterfaceAdditionalPopulationInformer; import eva2.optimization.problems.InterfaceAdditionalPopulationInformer;
import eva2.optimization.strategies.InterfaceOptimizer; import eva2.optimization.strategies.InterfaceOptimizer;
import java.util.List; import java.util.List;
/*==========================================================================*
* INTERFACE DECLARATION
*==========================================================================*/
/** /**
* *
*/ */
@@ -28,21 +14,21 @@ public interface InterfaceStatistics {
/** /**
* Initialize statistics computations. * Initialize statistics computations.
*/ */
public void startOptPerformed(String InfoString,int runnumber, Object params, List<InterfaceAdditionalPopulationInformer> informerList); // called from processor void startOptPerformed(String InfoString,int runnumber, Object params, List<InterfaceAdditionalPopulationInformer> informerList); // called from processor
/** /**
* Finalize statistics computations. * Finalize statistics computations.
*/ */
public void stopOptPerformed(boolean normal, String stopMessage); // called from processor void stopOptPerformed(boolean normal, String stopMessage); // called from processor
public void addDataListener(InterfaceStatisticsListener listener); void addDataListener(InterfaceStatisticsListener listener);
public boolean removeDataListener(InterfaceStatisticsListener listener); boolean removeDataListener(InterfaceStatisticsListener listener);
public void addTextListener(InterfaceTextListener listener); void addTextListener(InterfaceTextListener listener);
public boolean removeTextListener(InterfaceTextListener listener); boolean removeTextListener(InterfaceTextListener listener);
public void printToTextListener(String s); void printToTextListener(String s);
public void createNextGenerationPerformed(PopulationInterface Pop, InterfaceOptimizer opt, List<InterfaceAdditionalPopulationInformer> informerList); void createNextGenerationPerformed(PopulationInterface Pop, InterfaceOptimizer opt, List<InterfaceAdditionalPopulationInformer> informerList);
public void createNextGenerationPerformed(double[] bestfit,double[] worstfit,int calls); void createNextGenerationPerformed(double[] bestfit,double[] worstfit,int calls);
public InterfaceStatisticsParameter getStatisticsParameter(); // called from moduleadapter InterfaceStatisticsParameter getStatisticsParameter(); // called from moduleadapter
public IndividualInterface getRunBestSolution(); // return the best fitness of the last run (may not be equal to the last population) IndividualInterface getRunBestSolution(); // return the best fitness of the last run (may not be equal to the last population)
public IndividualInterface getBestSolution(); // returns the best overall solution IndividualInterface getBestSolution(); // returns the best overall solution
public double[] getBestFitness(); // returns the best overall fitness double[] getBestFitness(); // returns the best overall fitness
public void postProcessingPerformed(Population resultPop); // called from processor void postProcessingPerformed(Population resultPop); // called from processor
} }

View File

@@ -1,20 +1,6 @@
package eva2.optimization.stat; package eva2.optimization.stat;
/*
* Title: EvA2
* Description:
* Copyright: Copyright (c) 2003
* Company: University of Tuebingen, Computer Architecture
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
* @version: $Revision: 16 $
* $Date: 2006-12-20 10:42:57 +0100 (Wed, 20 Dec 2006) $
* $Author: marcekro $
*/
/*==========================================================================*
* IMPORTS
*==========================================================================*/
/*==========================================================================*
* INTERFACE DECLARATION
*==========================================================================*/
/** /**
* *
*/ */

View File

@@ -105,9 +105,6 @@ public class StatisticsStandalone extends AbstractStatistics implements Interfac
@Override @Override
public void plotSpecificData(PopulationInterface pop, List<InterfaceAdditionalPopulationInformer> informerList) { public void plotSpecificData(PopulationInterface pop, List<InterfaceAdditionalPopulationInformer> informerList) {
if (TRACE) {
System.out.println(" m_SpecificData !!");
}
double[] specificData = pop.getSpecificData(); double[] specificData = pop.getSpecificData();
if (specificData != null) { if (specificData != null) {
for (int i = 0; i < specificData.length; i++) { for (int i = 0; i < specificData.length; i++) {

View File

@@ -71,7 +71,7 @@ public class GeneralGEOFaker extends JPanel {
// edit.setEnabled(false); // edit.setEnabled(false);
// m_SourceCodeEditor = new SourceCodeEditor(); // m_SourceCodeEditor = new SourceCodeEditor();
// String className = m_Editor.getValue().getClass().getName(); // String className = m_Editor.getValue().getClass().getName();
// m_SourceCodeEditor.editSource(EvAClient.DYNAMICCLASSES_PROPERTIES.getProperty(className)); // m_SourceCodeEditor.editSource(Main.DYNAMICCLASSES_PROPERTIES.getProperty(className));
// m_SourceCodeEditorFrame = new PropertyDialog(m_SourceCodeEditor, "test", 50, 50); // m_SourceCodeEditorFrame = new PropertyDialog(m_SourceCodeEditor, "test", 50, 50);
// m_SourceCodeEditorFrame.pack(); // m_SourceCodeEditorFrame.pack();
// m_SourceCodeEditorFrame.addWindowListener(new WindowAdapter() { // m_SourceCodeEditorFrame.addWindowListener(new WindowAdapter() {

View File

@@ -99,7 +99,7 @@ public class GeneralGenericObjectEditorPanel extends JPanel implements ItemListe
// m_editSourceBut.setEnabled(false); // m_editSourceBut.setEnabled(false);
// m_SourceCodeEditor = new SourceCodeEditor(); // m_SourceCodeEditor = new SourceCodeEditor();
// String className = m_ObjectEditor.getValue().getClass().getName(); // String className = m_ObjectEditor.getValue().getClass().getName();
// m_SourceCodeEditor.editSource(EvAClient.DYNAMICCLASSES_PROPERTIES.getProperty(className)); // m_SourceCodeEditor.editSource(Main.DYNAMICCLASSES_PROPERTIES.getProperty(className));
// m_SourceCodeEditorFrame = new PropertyDialog(m_SourceCodeEditor, "test", 50, 50); // m_SourceCodeEditorFrame = new PropertyDialog(m_SourceCodeEditor, "test", 50, 50);
// m_SourceCodeEditorFrame.pack(); // m_SourceCodeEditorFrame.pack();
// m_SourceCodeEditorFrame.addWindowListener(new WindowAdapter() { // m_SourceCodeEditorFrame.addWindowListener(new WindowAdapter() {

View File

@@ -47,7 +47,7 @@ public class EVAERROR {
* Send a message only once to System.err. Once means that the msg is stored for the lifetime of * Send a message only once to System.err. Once means that the msg is stored for the lifetime of
* the VM or until clearMsgCache() is called. * the VM or until clearMsgCache() is called.
* *
* @param msg * @param message
*/ */
public static void errorMsgOnce(String message) { public static void errorMsgOnce(String message) {
if (errorMap == null) { if (errorMap == null) {

View File

@@ -464,7 +464,7 @@ public class ReflectPackage {
// BasicResourceLoader rld = BasicResourceLoader.instance(); // BasicResourceLoader rld = BasicResourceLoader.instance();
// byte[] b = rld.getBytesFromResourceLocation("images/Sub24.gif"); // byte[] b = rld.getBytesFromResourceLocation("images/Sub24.gif");
// System.out.println((b == null) ? "null" : b.toString()); // System.out.println((b == null) ? "null" : b.toString());
// b = rld.getBytesFromResourceLocation("src/eva2/client/EvAClient.java"); // b = rld.getBytesFromResourceLocation("src/eva2/client/SplashScreen.java");
// System.out.println((b == null) ? "null" : b.toString()); // System.out.println((b == null) ? "null" : b.toString());
HashSet<String> h = new HashSet<String> (20); HashSet<String> h = new HashSet<String> (20);

View File

@@ -19,7 +19,7 @@ public final class StringTools {
private StringTools() { } private StringTools() { }
/** /**
* Returns a HTML formated String, in which each line is at most lineBreak * Returns a HTML formatted String, in which each line is at most lineBreak
* symbols long. * symbols long.
* *
* @param string * @param string