Further refactoring and removal of unused code. Documenting the Population class.

This commit is contained in:
Fabian Becker 2012-05-21 07:47:38 +00:00
parent c9f1fb4d75
commit 4cf0375f35
7 changed files with 2927 additions and 2615 deletions

View File

@ -498,8 +498,7 @@ public class EvAClient implements RemoteStateListener {
gbConstraints.fill = GridBagConstraints.HORIZONTAL;
gbConstraints.anchor = GridBagConstraints.PAGE_END;
mainFrame.add(statusBar, gbConstraints);
mainFrame.pack();
mainFrame.setVisible(true);
}
if (useDefaultModule != null) {

View File

@ -10,242 +10,231 @@ package eva2.gui;
* $Author: mkron $
*/
import eva2.EvAInfo;
import eva2.server.modules.ModuleAdapter;
import eva2.server.stat.EvAJob;
import eva2.tools.ToolBoxGui;
import eva2.tools.jproxy.RMIProxyLocal;
import eva2.tools.jproxy.RemoteStateListener;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.Serializable;
import java.net.InetAddress;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import eva2.server.modules.ModuleAdapter;
import eva2.server.stat.EvAJob;
import eva2.tools.BasicResourceLoader;
import eva2.tools.jproxy.RMIProxyLocal;
import eva2.tools.jproxy.RemoteStateListener;
import java.awt.Toolkit;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JToolBar;
/**
* Contains the GUI elements of start and stop buttons and optionally a help button.
* Contains the GUI elements of start and stop buttons and optionally a help
* button.
*/
public class EvAModuleButtonPanelMaker implements RemoteStateListener, Serializable, PanelMaker {
private static final Logger logger = Logger.getLogger(EvAInfo.defaultLogger);
private String m_Name = "undefined";
private ModuleAdapter moduleAdapter;
private boolean runningState;
private JButton runButton;
private JButton postProcessButton;
private JButton stopButton;
private JButton scheduleButton;
// private JButton m_actExitMod;
private JButton helpButton;
// private JButton m_ShowSolButton;
private JToolBar toolBar;
private String helpFileName;
public class EvAModuleButtonPanelMaker implements RemoteStateListener, Serializable, PanelMaker {
/**
*
*/
public EvAModuleButtonPanelMaker(ModuleAdapter adapter, boolean state) {
m_Name = "GENERAL";
runningState = state;
moduleAdapter = adapter;
}
private static final Logger LOGGER = Logger.getLogger(EvAInfo.defaultLogger);
private String m_Name = "undefined";
private ModuleAdapter moduleAdapter;
private boolean runningState;
private JButton runButton;
private JButton postProcessButton;
private JButton stopButton;
private JButton scheduleButton;
private JButton helpButton;
private JToolBar toolBar;
private String helpFileName;
public JToolBar makePanel() {
String myhostname = null;
/**
*
*/
public EvAModuleButtonPanelMaker(ModuleAdapter adapter, boolean state) {
m_Name = "GENERAL";
runningState = state;
moduleAdapter = adapter;
}
toolBar = new JToolBar();
toolBar.setFloatable(false);
if (moduleAdapter.hasConnection()) { // we might be in rmi mode
try {
myhostname = InetAddress.getLocalHost().getHostName();
} catch (Exception e) {
logger.log(Level.WARNING, "Could not get hostname", e);
}
}
if (!moduleAdapter.hasConnection()) {
moduleAdapter.addRemoteStateListener((RemoteStateListener)(this));
} else {// there is a network RMI connection
moduleAdapter.addRemoteStateListener((RemoteStateListener)RMIProxyLocal.newInstance(this));
}
public JToolBar makePanel() {
toolBar = new JToolBar();
toolBar.setFloatable(false);
//////////////////////////////////////////////////////////////
runButton = makeIconButton("resources/images/Play24.gif", "Start");
runButton.setToolTipText("Start the current optimization run.");
runButton.addActionListener(new ActionListener() {
/* ToDo: This is useless? */
if (moduleAdapter.hasConnection()) { // we might be in rmi mode
try {
String myhostname = InetAddress.getLocalHost().getHostName();
} catch (Exception e) {
LOGGER.log(Level.WARNING, "Could not get hostname", e);
}
}
if (!moduleAdapter.hasConnection()) {
moduleAdapter.addRemoteStateListener((RemoteStateListener) (this));
} else {// there is a network RMI connection
moduleAdapter.addRemoteStateListener((RemoteStateListener) RMIProxyLocal.newInstance(this));
}
public void actionPerformed(ActionEvent event) {
//Run Opt pressed !
onUserStart();
}
});
//////////////////////////////////////////////////////////////
runButton = ToolBoxGui.createIconifiedButton("resources/images/Play24.gif", "Start", true);
runButton.setToolTipText("Start the current optimization run.");
runButton.setEnabled(!runningState); // enabled if not running
runButton.addActionListener(new ActionListener() {
toolBar.add(runButton);
@Override
public void actionPerformed(ActionEvent event) {
//Run Opt pressed !
onUserStart();
}
});
stopButton = makeIconButton("resources/images/Stop24.gif", "Stop");
stopButton.setToolTipText("Stop the current optimization run.");
stopButton.addActionListener(new ActionListener() {
runButton.setEnabled(!runningState); // enabled if not running
public void actionPerformed(ActionEvent event) {
try {
// this means user break
moduleAdapter.stopOpt();
} catch (Exception ee) {
logger.log(Level.WARNING, "Error while stopping job.", ee);
}
}
});
toolBar.add(runButton);
stopButton.setEnabled(runningState);
toolBar.add(stopButton);
stopButton = ToolBoxGui.createIconifiedButton("resources/images/Stop24.gif", "Stop", true);
stopButton.setToolTipText("Stop the current optimization run.");
//stopButton.setBorderPainted(false);
stopButton.addActionListener(new ActionListener() {
postProcessButton = makeIconButton("resources/images/History24.gif", "Post Process");
postProcessButton.setToolTipText("Start post processing according to available parameters.");
postProcessButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
try {
// this means user break
moduleAdapter.stopOpt();
} catch (Exception ee) {
LOGGER.log(Level.WARNING, "Error while stopping job.", ee);
}
}
});
public void actionPerformed(ActionEvent e) {
try {
if (!moduleAdapter.startPostProcessing()) {
JOptionPane.showMessageDialog(null, "Post processing seems deactivated! Check the settings.", "Warning", JOptionPane.WARNING_MESSAGE);
}
} catch (Exception ee) {
logger.log(Level.WARNING, "Error in run", ee);
}
}
});
postProcessButton.setEnabled(runningState && moduleAdapter.hasPostProcessing());
toolBar.add(postProcessButton);
// //////////////////////////////////////////////////////////////
scheduleButton= makeIconButton("resources/images/Server24.gif", "Schedule");
scheduleButton.setToolTipText("Schedule the currently configured optimization as a job.");
scheduleButton.addActionListener(new ActionListener() {
stopButton.setEnabled(runningState);
toolBar.add(stopButton);
public void actionPerformed(ActionEvent e) {
EvAJob job = moduleAdapter.scheduleJob();
if (job == null) {
logger.log(Level.WARNING, "There was an error on scheduling your job");
}
}
});
scheduleButton.setEnabled(true);
toolBar.add(scheduleButton);
postProcessButton = ToolBoxGui.createIconifiedButton("resources/images/History24.gif", "Post Process", true);
postProcessButton.setToolTipText("Start post processing according to available parameters.");
//postProcessButton.setBorderPainted(false);
postProcessButton.addActionListener(new ActionListener() {
makeHelpButton();
@Override
public void actionPerformed(ActionEvent event) {
try {
if (!moduleAdapter.startPostProcessing()) {
JOptionPane.showMessageDialog(null, "Post processing seems deactivated! Check the settings.", "Warning", JOptionPane.WARNING_MESSAGE);
}
} catch (Exception ee) {
LOGGER.log(Level.WARNING, "Error in run", ee);
}
}
});
postProcessButton.setEnabled(runningState && moduleAdapter.hasPostProcessing());
toolBar.add(postProcessButton);
scheduleButton = ToolBoxGui.createIconifiedButton("resources/images/Server24.gif", "Schedule", true);
scheduleButton.setToolTipText("Schedule the currently configured optimization as a job.");
//scheduleButton.setBorderPainted(false);
scheduleButton.addActionListener(new ActionListener() {
return toolBar;
}
private JButton makeIconButton(final String iconSrc, final String title) {
JButton newButton;
byte[] bytes;
bytes = BasicResourceLoader.instance().getBytesFromResourceLocation(iconSrc, false);
if (bytes == null) {
newButton = new JButton(title);
} else {
newButton = new JButton(title, new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes)));
}
return newButton;
}
public void onUserStart() {
try {
moduleAdapter.startOpt();
stopButton.setEnabled(true);
runButton.setEnabled(false);
postProcessButton.setEnabled(false);
// m_RestartButton.setEnabled(false);
// m_JHelpButton.setEnabled(true);
} catch (Exception ee) {
ee.printStackTrace();
System.err.print ("Error in run: " +ee +" : " + ee.getMessage() );
}
}
private void makeHelpButton() {
///////////////////////////////////////////////////////////////
if (helpFileName != null && (!helpFileName.equals(""))) {
helpButton = new JButton("Description");
helpButton.setToolTipText("Description of the current optimization algorithm.");
helpButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
EvAJob job = moduleAdapter.scheduleJob();
if (job == null) {
LOGGER.log(Level.WARNING, "There was an error on scheduling your job");
}
}
});
scheduleButton.setEnabled(true);
toolBar.add(scheduleButton);
public void actionPerformed(ActionEvent e) {
//System.out.println("Run Opt pressed !!!!!!!!!!!!!!!!======================!!");
try {
if (helpFileName != null) {
HtmlDemo temp = new HtmlDemo(helpFileName);
temp.show();
}
helpButton.setEnabled(true);
} catch (Exception ee) {
ee.printStackTrace();
System.out.print("Error in run: " + ee + " : " + ee.getMessage());
}
}
});
toolBar.add(helpButton);
}
}
/**
*
*/
public void performedStop() {
runButton.setEnabled(true);
postProcessButton.setEnabled(true);
runButton.repaint();
stopButton.setEnabled(false);
toolBar.repaint();
}
makeHelpButton();
public void performedStart(String infoString) {
// m_ShowSolButton.setEnabled(true);
}
return toolBar;
}
public void onUserStart() {
try {
moduleAdapter.startOpt();
stopButton.setEnabled(true);
runButton.setEnabled(false);
postProcessButton.setEnabled(false);
} catch (Exception ex) {
ex.printStackTrace();
System.err.print("Error in run: " + ex + " : " + ex.getMessage());
}
}
public void performedRestart(String infoString) {
}
public void updateProgress(final int percent, String msg) {
}
/**
*
*/
public String getName() {
return m_Name;
}
/**
*
*/
public void setHelperFilename(String fileName) {
if ((fileName == null) && (fileName == helpFileName)) {
return; // both are null, do nothing
}
if (fileName != null) {
if (helpFileName == null) {
// only old is null, nothing to be removed
helpFileName = fileName;
makeHelpButton();
} else {
if (!helpFileName.equals(fileName)) {
toolBar.remove(helpButton);
helpFileName = fileName;
makeHelpButton();
} //else // both are equal, do nothing
}
} else { // s is null, so just remove
toolBar.remove(helpButton);
helpFileName = fileName;
}
}
private void makeHelpButton() {
///////////////////////////////////////////////////////////////
if (helpFileName != null && (!helpFileName.equals(""))) {
helpButton = new JButton("Description");
helpButton.setToolTipText("Description of the current optimization algorithm.");
helpButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//System.out.println("Run Opt pressed !!!!!!!!!!!!!!!!======================!!");
try {
if (helpFileName != null) {
HtmlDemo temp = new HtmlDemo(helpFileName);
temp.show();
}
helpButton.setEnabled(true);
} catch (Exception ee) {
ee.printStackTrace();
System.out.print("Error in run: " + ee + " : " + ee.getMessage());
}
}
});
toolBar.add(helpButton);
}
}
/**
*
*/
public void performedStop() {
runButton.setEnabled(true);
postProcessButton.setEnabled(true);
runButton.repaint();
stopButton.setEnabled(false);
toolBar.repaint();
}
@Override
public void performedStart(String infoString) {
}
@Override
public void performedRestart(String infoString) {
}
@Override
public void updateProgress(final int percent, String msg) {
}
/**
*
*/
public String getName() {
return m_Name;
}
/**
*
*/
public void setHelperFilename(String fileName) {
if ((fileName == null) && (fileName.equals(helpFileName))) {
return; // both are null, do nothing
}
if (fileName != null) {
if (helpFileName == null) {
// only old is null, nothing to be removed
helpFileName = fileName;
makeHelpButton();
} else {
if (!helpFileName.equals(fileName)) {
toolBar.remove(helpButton);
helpFileName = fileName;
makeHelpButton();
} //else // both are equal, do nothing
}
} else { // s is null, so just remove
toolBar.remove(helpButton);
helpFileName = fileName;
}
}
}

View File

@ -326,7 +326,8 @@ public class GOEPanel extends JPanel implements ItemListener {
for (String className : classesLongNames) {
classNameMap.put(EVAHELP.cutClassName(className), className);
}
objectChooser.setModel(new DefaultComboBoxModel(classNameMap.keySet().toArray()));
Vector<String> classesList = new Vector<String>(classesLongNames);
objectChooser.setModel(new DefaultComboBoxModel(classesList));
if (withComboBoxToolTips) {
objectChooser.setRenderer(new ToolTipComboBoxRenderer(collectComboToolTips(instances, tipMaxLen)));
}
@ -405,7 +406,7 @@ public class GOEPanel extends JPanel implements ItemListener {
if ((e.getSource() == objectChooser) && (e.getStateChange() == ItemEvent.SELECTED)) {
className = (String) objectChooser.getSelectedItem();
className = classNameMap.get(className);
//className = classNameMap.get(className);
try {
Object n = (Object) Class.forName(className).newInstance();
genericObjectEditor.setValue(n);

View File

@ -1,5 +1,4 @@
package eva2.server.go;
/*
* Title: EvA2
* Description:
@ -10,39 +9,73 @@ package eva2.server.go;
* $Date: 2007-12-04 14:22:52 +0100 (Tue, 04 Dec 2007) $
* $Author: mkron $
*/
/*==========================================================================*
* IMPORTS
*==========================================================================*/
/*==========================================================================*
* INTERFACE DECLARATION
*==========================================================================*/
/**
*
*/
public interface PopulationInterface {
public IndividualInterface getBestIndividual();
public IndividualInterface getWorstIndividual();
public double[] getBestFitness();
public double[] getWorstFitness();
public double[] getMeanFitness();
public double[] getPopulationMeasures();
public int getFunctionCalls();
public int getGeneration();
/** This method returns problem specific data
* @return double[]
*/
public double[] getSpecificData();
/** This method returns identifiers for the
* specific data
* Note: "Pareto-Front" is reserved for mulit-crit. Problems
* string[1] gives the dimension of the fitness values
* @return String[]
*/
public String[] getSpecificDataNames();
public Object get(int i);
public int size();
public void clear();
/**
* Returns the best individual of the population.
*
* @return The best individual
*/
IndividualInterface getBestIndividual();
/**
* Returns the worst individual of the population.
*
* @return The worst individual
*/
IndividualInterface getWorstIndividual();
double[] getBestFitness();
double[] getWorstFitness();
double[] getMeanFitness();
double[] getPopulationMeasures();
/**
* Returns the number of function calls.
* @return The number of function calls
*/
int getFunctionCalls();
/**
* The current generation count.
* @return int The current generation
*/
int getGeneration();
/**
* This method returns problem specific data
*
* @return double[]
*/
double[] getSpecificData();
/**
* This method returns identifiers for the specific data Note:
* "Pareto-Front" is reserved for multi-crit. Problems string[1] gives the
* dimension of the fitness values
*
* @return String[]
*/
String[] getSpecificDataNames();
Object get(int i);
/**
* Return the size of the population.
* @return int size of the population
*/
int size();
/**
* Clear the population.
*/
void clear();
}

File diff suppressed because it is too large Load Diff

View File

@ -1,13 +1,12 @@
package eva2.server.go.populations;
import java.util.BitSet;
import eva2.server.go.individuals.AbstractEAIndividual;
import eva2.server.go.individuals.InterfaceGAIndividual;
import eva2.tools.math.RNG;
import java.util.BitSet;
/** This implementation of Population Based Incremental Learning is only
/**
* This implementation of Population Based Incremental Learning is only
* suited for a BitString based genotype representation.
* Copyright: Copyright (c) 2003
* Company: University of Tuebingen, Computer Architecture
@ -45,8 +44,8 @@ public class PBILPopulation extends Population implements Cloneable, java.io.Ser
* have been inited by a problem
*/
public void init() {
this.m_Generation = 0;
this.m_FunctionCalls = 0;
this.generationCount = 0;
this.functionCallCount = 0;
if (!(this.get(0) instanceof InterfaceGAIndividual)) {
System.err.println("Members of the population are not instance of InterfaceGAIndividual!");
return;
@ -149,8 +148,8 @@ public class PBILPopulation extends Population implements Cloneable, java.io.Ser
}
result += "}\n";
result += "Population size: " + this.size() + "\n";
result += "Function calls : " + this.m_FunctionCalls + "\n";
result += "Generations : " + this.m_Generation;
result += "Function calls : " + this.functionCallCount + "\n";
result += "Generations : " + this.generationCount;
//for (int i = 0; i < this.size(); i++) {
//result += ((AbstractEAIndividual)this.get(i)).getSolutionRepresentationFor()+"\n";
//}

File diff suppressed because it is too large Load Diff