diff --git a/src/eva2/gui/GenericRemoteServersEditor.java b/src/eva2/gui/GenericRemoteServersEditor.java index 997e3710..3ed3bfd3 100644 --- a/src/eva2/gui/GenericRemoteServersEditor.java +++ b/src/eva2/gui/GenericRemoteServersEditor.java @@ -43,6 +43,7 @@ public class GenericRemoteServersEditor extends JPanel implements PropertyEditor private JTextField[] m_Names; private JComboBox[] m_CPUs; private JButton[] m_Delete; + private int prefEditorHeight = 200; public GenericRemoteServersEditor() { @@ -51,149 +52,79 @@ public class GenericRemoteServersEditor extends JPanel implements PropertyEditor /** This method will init the CustomEditor Panel */ private void initCustomEditor() { - this.m_Editor = new JPanel(); - // This is the upper panel - this.m_ParameterPanel = new JPanel(); - GridBagConstraints gbc = new GridBagConstraints(); - gbc.anchor = GridBagConstraints.WEST; - gbc.fill = GridBagConstraints.HORIZONTAL; - gbc.gridwidth = 1; - gbc.gridx = 0; - gbc.gridy = 0; - gbc.weightx = 1; - this.m_ParameterPanel.setLayout(new GridBagLayout()); - this.m_ParameterPanel.add(new JLabel("Login: "), gbc); - this.m_Login = new JTextField(""+this.m_RemoteServers.getLogin()); - this.m_Login.addKeyListener(loginListener); - gbc.anchor = GridBagConstraints.WEST; - gbc.fill = GridBagConstraints.HORIZONTAL; - gbc.gridwidth = 2; - gbc.gridx = 1; - gbc.gridy = 0; - gbc.weightx = 100; - this.m_ParameterPanel.add(this.m_Login, gbc); - gbc.anchor = GridBagConstraints.WEST; - gbc.fill = GridBagConstraints.HORIZONTAL; - gbc.gridwidth = 1; - gbc.gridx = 3; - gbc.gridy = 0; - gbc.weightx = 1; - this.m_ParameterPanel.add(new JLabel("Password: "), gbc); - this.m_Password = new JPasswordField(""+this.m_RemoteServers.getPassword()); - this.m_Password.addKeyListener(passwordListener); - gbc.anchor = GridBagConstraints.WEST; - gbc.fill = GridBagConstraints.HORIZONTAL; - gbc.gridwidth = 2; - gbc.gridx = 4; - gbc.gridy = 0; - gbc.weightx = 100; - this.m_ParameterPanel.add(this.m_Password, gbc); + this.m_Editor = new JPanel(); + // This is the upper panel + this.m_ParameterPanel = new JPanel(); + GridBagConstraints gbc = new GridBagConstraints(); + setGBC(gbc, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, 1, 0, 0, 1); + this.m_ParameterPanel.setLayout(new GridBagLayout()); + this.m_ParameterPanel.add(new JLabel("Login: "), gbc); + this.m_Login = new JTextField(""+this.m_RemoteServers.getLogin()); + this.m_Login.addKeyListener(loginListener); + setGBC(gbc, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, 2, 1, 0, 100); + this.m_ParameterPanel.add(this.m_Login, gbc); + setGBC(gbc, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, 1, 3, 0, 1); + this.m_ParameterPanel.add(new JLabel("Password: "), gbc); + this.m_Password = new JPasswordField(""+this.m_RemoteServers.getPassword()); + this.m_Password.addKeyListener(passwordListener); + setGBC(gbc, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, 2, 4, 0, 100); + this.m_ParameterPanel.add(this.m_Password, gbc); - JButton tmpB; - BasicResourceLoader loader = BasicResourceLoader.instance(); - byte[] bytes; - bytes = loader.getBytesFromResourceLocation("resources/images/Add24.gif"); - try { - tmpB = new JButton("", new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes))); - } catch (java.lang.NullPointerException e) { - System.out.println("Could not find Add24 icon, please move resources folder to working directory!"); - tmpB = new JButton("Add"); - } - tmpB.addActionListener(addServer); - gbc.anchor = GridBagConstraints.WEST; - gbc.fill = GridBagConstraints.HORIZONTAL; - gbc.gridwidth = 1; - gbc.gridx = 0; - gbc.gridy = 1; - gbc.weightx = 1; - this.m_ParameterPanel.add(tmpB, gbc); - bytes = loader.getBytesFromResourceLocation("resources/images/Export24.gif"); - try { - tmpB = new JButton("Load", new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes))); - } catch (java.lang.NullPointerException e) { - System.out.println("Could not find Export24 icon, please move resources folder to working directory!"); - tmpB = new JButton("Load"); - } - tmpB.addActionListener(loadServers); - gbc.anchor = GridBagConstraints.WEST; - gbc.fill = GridBagConstraints.HORIZONTAL; - gbc.gridx = 1; - gbc.gridy = 1; - gbc.weightx = 1; - this.m_ParameterPanel.add(tmpB, gbc); - bytes = loader.getBytesFromResourceLocation("resources/images/Import24.gif"); - try { - tmpB = new JButton("Save", new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes))); - } catch (java.lang.NullPointerException e) { - System.out.println("Could not find Import24 icon, please move resources folder to working directory!"); - tmpB = new JButton("Save"); - } - tmpB.addActionListener(saveServers); - gbc.anchor = GridBagConstraints.WEST; - gbc.fill = GridBagConstraints.HORIZONTAL; - gbc.gridx = 2; - gbc.gridy = 1; - gbc.weightx = 1; - this.m_ParameterPanel.add(tmpB, gbc); - bytes = loader.getBytesFromResourceLocation("resources/images/Refresh24.gif"); - try { - tmpB = new JButton("Update Status", new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes))); - } catch (java.lang.NullPointerException e) { - System.out.println("Could not find Refresh24 icon, please move resources folder to working directory!"); - tmpB = new JButton("Update Status"); - } - tmpB.addActionListener(updateServers); - gbc.anchor = GridBagConstraints.WEST; - gbc.fill = GridBagConstraints.HORIZONTAL; - gbc.gridx = 3; - gbc.gridy = 1; - gbc.weightx = 1; - this.m_ParameterPanel.add(tmpB, gbc); - bytes = loader.getBytesFromResourceLocation("resources/images/Play24.gif"); - try { - tmpB = new JButton("Start Server", new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes))); - } catch (java.lang.NullPointerException e) { - System.out.println("Could not find Play24 icon, please move resources folder to working directory!"); - tmpB = new JButton("Start Server"); - } - tmpB.addActionListener(startServers); - gbc.anchor = GridBagConstraints.WEST; - gbc.fill = GridBagConstraints.HORIZONTAL; - gbc.gridx = 4; - gbc.gridy = 1; - gbc.weightx = 1; - this.m_ParameterPanel.add(tmpB, gbc); - bytes = loader.getBytesFromResourceLocation("resources/images/Stop24.gif"); - try { - tmpB = new JButton("Stop Server", new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes))); - } catch (java.lang.NullPointerException e) { - System.out.println("Could not find Stop24 icon, please move resources folder to working directory!"); - tmpB = new JButton("Stop Server"); - } - tmpB.addActionListener(killServers); - gbc.anchor = GridBagConstraints.WEST; - gbc.fill = GridBagConstraints.HORIZONTAL; - gbc.gridx = 5; - gbc.gridy = 1; - gbc.weightx = 1; - this.m_ParameterPanel.add(tmpB, gbc); + JButton tmpB; + tmpB = makeButtonWith("resources/images/Add24.gif", "add"); + tmpB.addActionListener(addServer); + setGBC(gbc, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, 1, 0, 1, 1); + this.m_ParameterPanel.add(tmpB, gbc); + tmpB = makeButtonWith("resources/images/Export24.gif", "Load"); + tmpB.addActionListener(loadServers); + setGBC(gbc, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, 1, 1, 1, 1); + this.m_ParameterPanel.add(tmpB, gbc); + tmpB = makeButtonWith("resources/images/Import24.gif", "Save"); + tmpB.addActionListener(saveServers); + setGBC(gbc, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, 1, 2, 1, 1); + this.m_ParameterPanel.add(tmpB, gbc); + tmpB = makeButtonWith("resources/images/Refresh24.gif", "Update Status"); + tmpB.addActionListener(updateServers); + setGBC(gbc, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, 1, 3, 1, 1); + this.m_ParameterPanel.add(tmpB, gbc); + tmpB = makeButtonWith("resources/images/Play24.gif", "Start Server"); + tmpB.addActionListener(startServers); + setGBC(gbc, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, 1, 4, 1, 1); + this.m_ParameterPanel.add(tmpB, gbc); + tmpB = makeButtonWith("resources/images/Stop24.gif", "Stop Server"); + tmpB.addActionListener(killServers); + setGBC(gbc, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, 1, 5, 1, 1); + this.m_ParameterPanel.add(tmpB, gbc); - this.m_ServerList = new JPanel(); - this.updateServerList(); - JScrollPane scrollServer = new JScrollPane(this.m_ServerList); - - this.m_Editor.setLayout(new BorderLayout()); - this.m_Editor.add(this.m_ParameterPanel, BorderLayout.NORTH); - this.m_Editor.add(scrollServer, BorderLayout.CENTER); - - this.updateEditor(); + this.m_ServerList = new JPanel(); + this.updateServerList(); + JScrollPane scrollServer = new JScrollPane(this.m_ServerList); + scrollServer.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); + scrollServer.setPreferredSize(new Dimension(200,prefEditorHeight)); + + this.m_Editor.setLayout(new BorderLayout()); + this.m_Editor.add(this.m_ParameterPanel, BorderLayout.NORTH); + this.m_Editor.add(scrollServer, BorderLayout.CENTER); + this.updateEditor(); } + private JButton makeButtonWith(String iconSrc, String title) { + JButton tmpB; + byte[] bytes; + bytes = BasicResourceLoader.instance().getBytesFromResourceLocation(iconSrc); + try { + tmpB = new JButton(title, new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes))); + } catch (java.lang.NullPointerException e) { + System.err.println("Could not find icon " + iconSrc + ", please move resources folder to working directory!"); + tmpB = new JButton(title); + } + return tmpB; + } + /** This method updates the server list * */ private void updateServerList() { - BasicResourceLoader loader = BasicResourceLoader.instance(); byte[] bytes; ServerNode t; this.m_ServerList.removeAll(); @@ -206,33 +137,22 @@ public class GenericRemoteServersEditor extends JPanel implements PropertyEditor String[] cups = new String[8]; for (int i = 0; i < cups.length; i++) cups[i] = ""+(i+1); // The head title - gbc.anchor = GridBagConstraints.WEST; - gbc.fill = GridBagConstraints.BOTH; - gbc.gridx = 0; - gbc.weightx = 1; + setGBC(gbc, GridBagConstraints.WEST, GridBagConstraints.BOTH, 0, 1); this.m_ServerList.add(new JLabel("Status"), gbc); - gbc.anchor = GridBagConstraints.WEST; - gbc.fill = GridBagConstraints.BOTH; - gbc.gridx = 1; - gbc.weightx = 80; + + setGBC(gbc, GridBagConstraints.WEST, GridBagConstraints.BOTH, 1, 80); this.m_ServerList.add(new JLabel("Server Name"), gbc); - gbc.anchor = GridBagConstraints.WEST; - gbc.fill = GridBagConstraints.BOTH; - gbc.gridx = 2; - gbc.weightx = 10; + + setGBC(gbc, GridBagConstraints.WEST, GridBagConstraints.BOTH, 2, 10); this.m_ServerList.add(new JLabel("CPUs"), gbc); - gbc.anchor = GridBagConstraints.WEST; - gbc.fill = GridBagConstraints.REMAINDER; - gbc.gridx = 3; - gbc.weightx = 10; + + setGBC(gbc, GridBagConstraints.WEST, GridBagConstraints.REMAINDER, 3, 10); this.m_ServerList.add(new JLabel("Remove"), gbc); + for (int i = 0; i < this.m_RemoteServers.size(); i++) { t = this.m_RemoteServers.get(i); // the status indicator - gbc.anchor = GridBagConstraints.WEST; - gbc.fill = GridBagConstraints.BOTH; - gbc.gridx = 0; - gbc.weightx = 1; + setGBC(gbc, GridBagConstraints.WEST, GridBagConstraints.BOTH, 0, 1); this.m_Status[i] = new JButton(" "); this.m_Status[i].setEnabled(false); if (this.m_RemoteServers.isServerOnline(t.m_ServerName)) this.m_Status[i].setBackground(Color.GREEN); @@ -240,42 +160,46 @@ public class GenericRemoteServersEditor extends JPanel implements PropertyEditor this.m_ServerList.add(this.m_Status[i], gbc); // the server name gbc = new GridBagConstraints(); - gbc.anchor = GridBagConstraints.WEST; - gbc.fill = GridBagConstraints.BOTH; - gbc.gridx = 1; - gbc.weightx = 80; + setGBC(gbc, GridBagConstraints.WEST, GridBagConstraints.BOTH, 1, 80); this.m_Names[i] = new JTextField(""+t.m_ServerName); this.m_Names[i].addKeyListener(serverNameListener); this.m_ServerList.add(this.m_Names[i], gbc); // the number of CPUs - gbc.anchor = GridBagConstraints.WEST; - gbc.fill = GridBagConstraints.BOTH; - gbc.gridx = 2; - gbc.weightx = 10; + setGBC(gbc, GridBagConstraints.WEST, GridBagConstraints.BOTH, 2, 10); this.m_CPUs[i] = new JComboBox(cups); this.m_CPUs[i].setSelectedIndex(t.m_CPUs-1); this.m_CPUs[i].addItemListener(cpuStateListener); this.m_ServerList.add(this.m_CPUs[i], gbc); // The delete button - gbc.anchor = GridBagConstraints.WEST; - gbc.fill = GridBagConstraints.REMAINDER; - gbc.gridx = 3; - gbc.weightx = 10; - bytes = loader.getBytesFromResourceLocation("resources/images/Sub24.gif"); + setGBC(gbc, GridBagConstraints.WEST, GridBagConstraints.REMAINDER, 3, 10); + bytes = BasicResourceLoader.instance().getBytesFromResourceLocation("resources/images/Sub24.gif"); this.m_Delete[i] = new JButton("", new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes))); this.m_Delete[i].addActionListener(deleteServer); this.m_ServerList.add(this.m_Delete[i], gbc); } String[] h = this.m_RemoteServers.getCheckedServerNodes(); - System.out.println("My active nodes: "); - for (int i = 0; i < h.length; i++) { - System.out.println(""+h[i]); - } +// System.out.println("My active nodes: "); +// for (int i = 0; i < h.length; i++) { +// System.out.println(""+h[i]); +// } this.m_ServerList.repaint(); this.m_ServerList.validate(); } - /** This action listener,... + private void setGBC(GridBagConstraints gbc, int anchor, int fill, int gridx, int weightx) { + gbc.anchor = anchor; + gbc.fill = fill; + gbc.gridx = gridx; + gbc.weightx = weightx; + } + + private void setGBC(GridBagConstraints gbc, int anchor, int fill, int gridwidth, int gridx, int gridy, int weightx) { + setGBC(gbc, anchor, fill, gridx, weightx); + gbc.gridwidth = gridwidth; + gbc.gridy = gridy; + } + + /** This action listener,... */ ActionListener saveServers = new ActionListener() { public void actionPerformed(ActionEvent event) { @@ -290,9 +214,9 @@ public class GenericRemoteServersEditor extends JPanel implements PropertyEditor OutputFile.write(text); OutputFile.close(); } catch (FileNotFoundException t) { - System.out.println("Could not open output file! Filename: " + file.getName()); + System.err.println("Could not open output file! Filename: " + file.getName()); } catch (java.io.IOException t) { - System.out.println("Could not write to output file! Filename: " + file.getName()); + System.err.println("Could not write to output file! Filename: " + file.getName()); } } } @@ -329,8 +253,9 @@ public class GenericRemoteServersEditor extends JPanel implements PropertyEditor */ ActionListener addServer = new ActionListener() { public void actionPerformed(ActionEvent event) { - m_RemoteServers.addServerNode("none", 1); + m_RemoteServers.addServerNode("noname-"+m_RemoteServers.size(), 1); updateServerList(); + updateEditor(); } }; @@ -342,6 +267,7 @@ public class GenericRemoteServersEditor extends JPanel implements PropertyEditor if (event.getSource().equals(m_Delete[i])) m_RemoteServers.removeServerNode(m_RemoteServers.get(i).m_ServerName); } updateServerList(); + updateEditor(); } }; diff --git a/src/eva2/gui/PropertyRemoteServers.java b/src/eva2/gui/PropertyRemoteServers.java index c97f4a04..ca5d407c 100644 --- a/src/eva2/gui/PropertyRemoteServers.java +++ b/src/eva2/gui/PropertyRemoteServers.java @@ -33,7 +33,7 @@ class ServerNode implements java.io.Serializable { public class PropertyRemoteServers implements java.io.Serializable { - private ServerNode[] m_AvailableNodes; + private ServerNode[] m_AvailableNodes=null; // private String m_ClassToStart = "eva2.tools.jproxy.RMIServer"; private transient String m_password = ""; private String m_Login = ""; @@ -48,6 +48,7 @@ public class PropertyRemoteServers implements java.io.Serializable { } public PropertyRemoteServers(PropertyRemoteServers e) { + this(); if (e.m_AvailableNodes != null) { this.m_AvailableNodes = new ServerNode[e.m_AvailableNodes.length]; for (int i = 0; i < e.m_AvailableNodes.length; i++) { diff --git a/src/eva2/server/go/individuals/AbstractEAIndividual.java b/src/eva2/server/go/individuals/AbstractEAIndividual.java index eee2d6c8..6e0144c8 100644 --- a/src/eva2/server/go/individuals/AbstractEAIndividual.java +++ b/src/eva2/server/go/individuals/AbstractEAIndividual.java @@ -181,7 +181,7 @@ public abstract class AbstractEAIndividual implements IndividualInterface, java. // checking in mutation/crossover operators if (!this.m_MutationOperator.equals(indy.m_MutationOperator)) return false; if (!this.m_CrossoverOperator.equals(indy.m_CrossoverOperator)) return false; - System.err.println("Check whether this is semantically meant by equality!!! (AbstractEAIndividual.equals())"); +// System.err.println("Check whether this is semantically meant by equality!!! (AbstractEAIndividual.equals())"); return true; } else { return false; diff --git a/src/eva2/server/go/mocco/MOCCOParameterizeRefPoint.java b/src/eva2/server/go/mocco/MOCCOParameterizeRefPoint.java index 80e127b2..169e0e4c 100644 --- a/src/eva2/server/go/mocco/MOCCOParameterizeRefPoint.java +++ b/src/eva2/server/go/mocco/MOCCOParameterizeRefPoint.java @@ -133,7 +133,7 @@ public class MOCCOParameterizeRefPoint extends MOCCOPhase implements InterfacePr this.m_EIMEA = new GeneralGOEProperty(); this.m_Island = new IslandModelEA(); this.m_Island.setHeterogenuousProblems(true); - this.m_Island.setParallelize(false); + this.m_Island.setLocalOnly(true); this.m_Island.setMigrationRate(2); this.m_Island.setMigrationStrategy(new SOBestMigration()); this.m_Island.setNumberLocalCPUs(this.m_Perturbations); @@ -223,16 +223,16 @@ public class MOCCOParameterizeRefPoint extends MOCCOPhase implements InterfacePr System.out.println("The selected MOSO conversion is not suited for the reference point approach!"); } // then set the values - if (m_Island.getParallelize()) { +// if (!m_Island.getLocalOnly()) { PropertyRemoteServers t = m_Island.getServers(); String[] servers = t.getServerNodes(); if (servers.length != m_Perturbations) { System.out.println("Warning: Number of servers overrides number of perturbations!"); m_Perturbations = servers.length; } - } else { - m_Island.setNumberLocalCPUs(m_Perturbations); - } +// } else { +// m_Island.setNumberLocalCPUs(m_Perturbations); +// } m_Mocco.m_State.m_Optimizer = m_Island; m_Mocco.m_State.m_Optimizer.SetProblem(m_Mocco.m_State.m_CurrentProblem); m_Island.init(); diff --git a/src/eva2/server/go/mocco/MOCCOParameterizeTchebycheff.java b/src/eva2/server/go/mocco/MOCCOParameterizeTchebycheff.java index 1e56c5e1..6e0ec110 100644 --- a/src/eva2/server/go/mocco/MOCCOParameterizeTchebycheff.java +++ b/src/eva2/server/go/mocco/MOCCOParameterizeTchebycheff.java @@ -110,7 +110,7 @@ public class MOCCOParameterizeTchebycheff extends MOCCOPhase implements Interfac this.m_EIMEA = new GeneralGOEProperty(); this.m_Island = new IslandModelEA(); this.m_Island.setHeterogenuousProblems(true); - this.m_Island.setParallelize(false); + this.m_Island.setLocalOnly(true); this.m_Island.setMigrationRate(2); this.m_Island.setMigrationStrategy(new SOBestMigration()); this.m_Island.setNumberLocalCPUs(this.m_Perturbations); @@ -230,16 +230,16 @@ public class MOCCOParameterizeTchebycheff extends MOCCOPhase implements Interfac System.out.println("The selected optimizer does not allow heterogenuous multi-starts!"); } // then set the values - if (m_Island.getParallelize()) { - PropertyRemoteServers t = m_Island.getServers(); - String[] servers = t.getServerNodes(); +// if (!m_Island.getLocalOnly()) { + PropertyRemoteServers servs = m_Island.getServers(); + String[] servers = servs.getServerNodes(); if (servers.length != m_Perturbations) { System.out.println("Warning: Number of servers overrides number of perturbations!"); m_Perturbations = servers.length; } - } else { - m_Island.setNumberLocalCPUs(m_Perturbations); - } +// } else { +// m_Island.setNumberLocalCPUs(m_Perturbations); +// } m_Mocco.m_State.m_Optimizer = m_Island; m_Mocco.m_State.m_Optimizer.SetProblem(m_Mocco.m_State.m_CurrentProblem); m_Island.init(); diff --git a/src/eva2/server/go/problems/AbstractProblemDouble.java b/src/eva2/server/go/problems/AbstractProblemDouble.java index 4189c52c..0cc6427a 100644 --- a/src/eva2/server/go/problems/AbstractProblemDouble.java +++ b/src/eva2/server/go/problems/AbstractProblemDouble.java @@ -82,7 +82,7 @@ public abstract class AbstractProblemDouble extends AbstractOptimizationProblem } this.withConstraints=o.withConstraints; this.doRotation = o.doRotation; - this.rotation = (Matrix)o.rotation.clone(); + this.rotation = (o.rotation==null) ? null : (Matrix)o.rotation.clone(); this.rotAngle = o.rotAngle; } diff --git a/src/eva2/server/go/strategies/IslandModelEA.java b/src/eva2/server/go/strategies/IslandModelEA.java index 4618bd4b..a85214e3 100644 --- a/src/eva2/server/go/strategies/IslandModelEA.java +++ b/src/eva2/server/go/strategies/IslandModelEA.java @@ -1,5 +1,6 @@ package eva2.server.go.strategies; +import eva2.gui.BeanInspector; import eva2.gui.Plot; import eva2.gui.PropertyRemoteServers; import eva2.server.go.InterfacePopulationChangedEventListener; @@ -52,9 +53,9 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I private PropertyRemoteServers m_Servers = new PropertyRemoteServers(); // These are the processor to run on - private int m_LocalCPUs = 4; - private boolean m_Parallelize = false; - private InterfaceOptimizer[] m_Islands; + private int m_numLocalCPUs = 1; + private boolean m_localOnly = false; + transient private InterfaceOptimizer[] m_Islands; transient private RMIServer m_LocalServer = null; // This is for debugging @@ -64,6 +65,7 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I transient private String m_Identifier = ""; transient private InterfacePopulationChangedEventListener m_Listener; + transient private final boolean TRACE = false; public IslandModelEA() { @@ -75,8 +77,10 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I this.m_Optimizer = (InterfaceOptimizer)a.m_Optimizer.clone(); this.m_Migration = (InterfaceMigration)a.m_Migration.clone(); this.m_Servers = (PropertyRemoteServers)a.m_Servers.clone(); - this.m_LocalCPUs = a.m_LocalCPUs; - this.m_Parallelize = a.m_Parallelize; + this.m_MigrationRate = a.m_MigrationRate; + this.m_HeterogenuousProblems = a.m_HeterogenuousProblems; + this.m_numLocalCPUs = a.m_numLocalCPUs; + this.m_localOnly = a.m_localOnly; } public Object clone() { @@ -93,21 +97,35 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I } } - this.m_Population = new Population(); - this.m_Population.incrGeneration(); +// this.m_Population = new Population(); + this.m_Population.clear(); + this.m_Population.init(); this.m_Optimizer.init(); this.m_Optimizer.SetProblem(this.m_Problem); + this.m_Optimizer.setPopulation((Population)m_Population.clone()); InterfacePopulationChangedEventListener myLocal = null; - if (this.m_Parallelize) { + if (this.m_localOnly) { + // this is running on the local machine + this.m_Islands = new InterfaceOptimizer[this.m_numLocalCPUs]; + for (int i = 0; i < this.m_numLocalCPUs; i++) { + this.m_Islands[i] = (InterfaceOptimizer) this.m_Optimizer.clone(); + this.m_Islands[i].SetIdentifier(""+i); + this.m_Islands[i].init(); + if (this.m_LogLocalChanges) + this.m_Islands[i].addPopulationChangedEventListener(this); + } + } else { // this is running on remote machines if (this.m_LocalServer == null) this.m_LocalServer = RMIServer.getInstance(); try { myLocal = (InterfacePopulationChangedEventListener) RMIProxyLocal.newInstance(this); } catch(Exception e) { - System.out.println("Island Model EA warning on local RMIServer... but i'll start anyway!"); + System.err.println("Island Model EA warning on local RMIServer... but i'll start anyway!"); } String[] nodesList = this.m_Servers.getCheckedServerNodes(); - if ((nodesList == null) || (nodesList.length == 0)) return; + if ((nodesList == null) || (nodesList.length == 0)) { + throw new RuntimeException("Error, no active remote servers available! Activate servers or use localOnly mode."); + } this.m_Islands = new InterfaceOptimizer[nodesList.length]; for (int i = 0; i < nodesList.length; i++) { this.m_Islands[i] = (InterfaceOptimizer) RMIProxyRemoteThread.newInstance(this.m_Optimizer, nodesList[i]); @@ -116,24 +134,19 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I if (this.m_LogLocalChanges) this.m_Islands[i].addPopulationChangedEventListener(myLocal); } - } else { - // this is running on the local machine - this.m_Islands = new InterfaceOptimizer[this.m_LocalCPUs]; - for (int i = 0; i < this.m_LocalCPUs; i++) { - this.m_Islands[i] = (InterfaceOptimizer) this.m_Optimizer.clone(); - this.m_Islands[i].SetIdentifier(""+i); - this.m_Islands[i].init(); - if (this.m_LogLocalChanges) - this.m_Islands[i].addPopulationChangedEventListener(this); - } } this.m_Migration.initMigration(this.m_Islands); Population pop; + this.m_Population.incrGeneration(); // the island-initialization has increased the island-pop generations. + for (int i = 0; i < this.m_Islands.length; i++) { pop = (Population)this.m_Islands[i].getPopulation().clone(); this.m_Population.addPopulation(pop); this.m_Population.incrFunctionCallsBy(pop.getFunctionCalls()); + if (m_Islands[i].getPopulation().getGeneration()!=m_Population.getGeneration()) { + System.err.println("Error, inconsistent generations!"); + } } this.firePropertyChangedEvent(Population.nextGenerationPerformed, this.m_Optimizer.getPopulation()); } @@ -160,13 +173,23 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I this.m_Optimizer.init(); this.m_Optimizer.SetProblem(this.m_Problem); InterfacePopulationChangedEventListener myLocal = null; - if (this.m_Parallelize) { + if (this.m_localOnly) { + // this is running on the local machine + this.m_Islands = new InterfaceOptimizer[this.m_numLocalCPUs]; + for (int i = 0; i < this.m_numLocalCPUs; i++) { + this.m_Islands[i] = (InterfaceOptimizer) this.m_Optimizer.clone(); + this.m_Islands[i].SetIdentifier(""+i); + this.m_Islands[i].init(); + if (this.m_LogLocalChanges) + this.m_Islands[i].addPopulationChangedEventListener(this); + } + } else { // this is running on remote machines if (this.m_LocalServer == null) this.m_LocalServer = RMIServer.getInstance(); try { myLocal = (InterfacePopulationChangedEventListener) RMIProxyLocal.newInstance(this); } catch(Exception e) { - System.out.println("Island Model EA warning on local RMIServer... but i'll start anyway!"); + System.err.println("Island Model EA warning on local RMIServer... but i'll try to start anyway!"); } String[] nodesList = this.m_Servers.getCheckedServerNodes(); if ((nodesList == null) || (nodesList.length == 0)) return; @@ -178,16 +201,6 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I if (this.m_LogLocalChanges) this.m_Islands[i].addPopulationChangedEventListener(myLocal); } - } else { - // this is running on the local machine - this.m_Islands = new InterfaceOptimizer[this.m_LocalCPUs]; - for (int i = 0; i < this.m_LocalCPUs; i++) { - this.m_Islands[i] = (InterfaceOptimizer) this.m_Optimizer.clone(); - this.m_Islands[i].SetIdentifier(""+i); - this.m_Islands[i].init(); - if (this.m_LogLocalChanges) - this.m_Islands[i].addPopulationChangedEventListener(this); - } } this.m_Migration.initMigration(this.m_Islands); @@ -204,14 +217,17 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I */ public void optimize() { for (int i = 0; i < this.m_Islands.length; i++) { - if (this.m_Islands[i].getPopulation().size() > 0) this.m_Islands[i].optimize(); - else this.m_Islands[i].getPopulation().incrGeneration(); + if (this.m_Islands[i].getPopulation().size() > 0) { + this.m_Islands[i].optimize(); + if (TRACE ) System.out.println(BeanInspector.toString(m_Islands[i].getPopulation())); + } else this.m_Islands[i].getPopulation().incrGeneration(); + if (TRACE) System.out.println("----"); } this.m_Population.incrGeneration(); if ((this.m_Population.getGeneration() % this.m_MigrationRate) == 0) { this.communicate(); } - // this is necessary for heterogeneuous islands + // this is necessary for heterogeneous islands if (this.m_HeterogenuousProblems) { for (int i = 0; i < this.m_Islands.length; i++) { this.m_Islands[i].getProblem().evaluate(this.m_Islands[i].getPopulation()); @@ -220,7 +236,7 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I System.gc(); } - /** This method will manage comunication between the + /** This method will manage communication between the * islands */ private void communicate() { @@ -299,7 +315,7 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I result += "Using:\n"; result += " Migration Strategy = " + this.m_Migration.getClass().toString() + "\n"; result += " Migration rate = " + this.m_MigrationRate + "\n"; - result += " Truely Parallel = " + this.m_Parallelize + "\n"; + result += " Local only = " + this.m_localOnly + "\n"; result += " Het. Problems = " + this.m_HeterogenuousProblems + "\n"; if (this.m_HeterogenuousProblems) { result += " Heterogenuous Optimizers: \n"; @@ -331,7 +347,7 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I s.startServers(); IslandModelEA imea = new IslandModelEA(); imea.m_Show = true; - imea.m_Parallelize = true; + imea.m_localOnly = false; imea.setServers(s); if (false) { imea.m_Optimizer = new MultiObjectiveEA(); @@ -431,27 +447,29 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I * @return description */ public String globalInfo() { - return "This is general Evolutionary Multi-Criteria Optimization Framework."; + return "This is an island model EA distributing the individuals across several (remote) CPUs for optimization."; } /** This method will return a naming String * @return The name of the algorithm */ public String getName() { - return "Island EA"; + return "IslandEA"; } /** This method allows you to toggle between a truly parallel * and a serial implementation. - * @return The current optimzation mode + * @return The current optimization mode */ - public boolean getParallelize() { - return this.m_Parallelize; + // TODO Deactivated from GUI because the current implementation does not really parallelize on a multicore. + // Instead, the new direct problem parallelization can be used. +// public boolean isLocalOnly() { +// return this.m_localOnly; +// } + public void setLocalOnly(boolean b){ + this.m_localOnly = b; } - public void setParallelize(boolean b){ - this.m_Parallelize = b; - } - public String parallelizeTipText() { - return "Toggle between parallel and serial implementation."; + public String localOnlyTipText() { + return "Toggle between usage of local CPUs and remote servers."; } /** This will show the local performance @@ -543,12 +561,15 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I * @param n Number of processors. */ public void setNumberLocalCPUs(int n) { - this.m_LocalCPUs = n; - } - public int getNumberLocalCPUs() { - return this.m_LocalCPUs; + if (n>=1) this.m_numLocalCPUs = n; + else System.err.println("Number of CPUs must be at least 1!"); } + // TODO Deactivated from GUI because the current implementation does not really parallelize on a multicore. + // Instead, the new direct problem parallelization can be used. +// public int getNumberLocalCPUs() { +// return this.m_LocalCPUs; +// } public String numberLocalCPUsTipText() { - return "Set the number of local CPUS (only active in non-parallelized mode)."; + return "Set the number of local CPUS (>=1, only used in local mode)."; } } \ No newline at end of file