GP area view should now work better

This commit is contained in:
Marcel Kronfeld 2009-05-08 13:06:21 +00:00
parent 12af483913
commit 4fbd2e3e08
10 changed files with 214 additions and 150 deletions

View File

@ -4,7 +4,7 @@ package eva2;
* Main product and version information strings. * Main product and version information strings.
* *
* --- Changelog * --- Changelog
* 2.035: Minor bugfix. * 2.035: Reactivated some of the model-based functionality within the GO framework. Minor bugfixes.
* 2.034: Adding a generic parameter control method for optimizers, currently used by PSO to adapt inertness depending * 2.034: Adding a generic parameter control method for optimizers, currently used by PSO to adapt inertness depending
* on EvaluationTerminator or GenerationTerminator instances defining the number of function evaluations. * on EvaluationTerminator or GenerationTerminator instances defining the number of function evaluations.
* The new package is eva2.server.go.operators.paramcontrol. * The new package is eva2.server.go.operators.paramcontrol.

View File

@ -7,6 +7,7 @@ import eva2.server.go.individuals.codings.gp.AbstractGPNode;
import eva2.server.go.individuals.codings.gp.GPArea; import eva2.server.go.individuals.codings.gp.GPArea;
import eva2.tools.EVAHELP; import eva2.tools.EVAHELP;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyEditorSupport; import java.beans.PropertyEditorSupport;
import java.beans.PropertyEditor; import java.beans.PropertyEditor;
import java.beans.PropertyChangeListener; import java.beans.PropertyChangeListener;
@ -24,7 +25,7 @@ import java.util.ArrayList;
* Time: 11:41:01 * Time: 11:41:01
* To change this template use Options | File Templates. * To change this template use Options | File Templates.
*/ */
public abstract class AbstractListSelectionEditor extends JPanel implements PropertyEditor { public abstract class AbstractListSelectionEditor extends JPanel implements PropertyEditor, PropertyChangeListener {
/** Handles property change notification */ /** Handles property change notification */
private PropertyChangeSupport m_Support = new PropertyChangeSupport(this); private PropertyChangeSupport m_Support = new PropertyChangeSupport(this);
@ -71,7 +72,8 @@ public abstract class AbstractListSelectionEditor extends JPanel implements Prop
*/ */
protected abstract boolean isElementAllowed(int i); protected abstract boolean isElementAllowed(int i);
/** The object may have changed update the editor. /**
* The object may have changed update the editor. This notifies change listeners automatically.
*/ */
private void updateEditor() { private void updateEditor() {
if (this.m_NodePanel != null) { if (this.m_NodePanel != null) {
@ -82,7 +84,7 @@ public abstract class AbstractListSelectionEditor extends JPanel implements Prop
this.m_BlackCheck[i] = new JCheckBox(getElementName(i), isElementAllowed(i)); this.m_BlackCheck[i] = new JCheckBox(getElementName(i), isElementAllowed(i));
this.m_BlackCheck[i].addActionListener(new ActionListener() { this.m_BlackCheck[i].addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ev) { public void actionPerformed(ActionEvent ev) {
performOnAction(); if (performOnAction()) m_Support.firePropertyChange("AbstractListSelectionEditor", null, this);
} }
}); });
this.m_NodePanel.add(this.m_BlackCheck[i]); this.m_NodePanel.add(this.m_BlackCheck[i]);
@ -91,12 +93,14 @@ public abstract class AbstractListSelectionEditor extends JPanel implements Prop
} }
/** /**
* Perform actions when the selection state changes. * Perform actions when the selection state changes. Return true if there was an actual change.
*/ */
protected abstract void performOnAction(); protected abstract boolean performOnAction();
/** /**
* Set the base object, return true on success. * Set the base object, return true on success. Make sure that the editor instance is
* added as a listener to the object (if supported).
*
* @param o * @param o
* @return * @return
*/ */
@ -180,4 +184,8 @@ public abstract class AbstractListSelectionEditor extends JPanel implements Prop
if (this.m_CustomEditor == null) this.initCustomEditor(); if (this.m_CustomEditor == null) this.initCustomEditor();
return m_CustomEditor; return m_CustomEditor;
} }
public void propertyChange(PropertyChangeEvent evt) {
m_Support.firePropertyChange("AbstractListSelectionEditor", null, this);
}
} }

View File

@ -35,7 +35,7 @@ public class GenericAreaEditor extends AbstractListSelectionEditor {
} }
@Override @Override
protected void performOnAction() { protected boolean performOnAction() {
/** This method checks the current BlackList and compiles it /** This method checks the current BlackList and compiles it
* to a new ReducedList. * to a new ReducedList.
*/ */
@ -43,19 +43,19 @@ public class GenericAreaEditor extends AbstractListSelectionEditor {
this.m_AreaObject.setBlackListElement(i, this.m_BlackCheck[i].isSelected()); this.m_AreaObject.setBlackListElement(i, this.m_BlackCheck[i].isSelected());
} }
this.m_AreaObject.compileReducedList(); this.m_AreaObject.compileReducedList();
return true;
} }
@Override @Override
protected boolean setObject(Object o) { protected boolean setObject(Object o) {
if (o instanceof GPArea) { if (o instanceof GPArea) {
this.m_AreaObject = (GPArea) o; this.m_AreaObject = (GPArea) o;
m_AreaObject.addPropertyChangeListener(this);
return true; return true;
} else return false; } else return false;
} }
/** Retruns the current object. @Override
* @return the current object
*/
public Object getValue() { public Object getValue() {
return this.m_AreaObject; return this.m_AreaObject;
} }

View File

@ -27,16 +27,22 @@ public class GenericObjectListSelectionEditor extends AbstractListSelectionEdito
} }
@Override @Override
protected void performOnAction() { protected boolean performOnAction() {
boolean changed=false;
for (int i = 0; i < this.m_BlackCheck.length; i++) { for (int i = 0; i < this.m_BlackCheck.length; i++) {
objList.setSelectionForElement(i, this.m_BlackCheck[i].isSelected()); if (objList.isSelected(i)!=this.m_BlackCheck[i].isSelected()) {
objList.setSelectionForElement(i, this.m_BlackCheck[i].isSelected());
changed=true;
}
} }
return changed;
} }
@Override @Override
protected boolean setObject(Object o) { protected boolean setObject(Object o) {
if (o instanceof PropertySelectableList) { if (o instanceof PropertySelectableList) {
this.objList = (PropertySelectableList) o; this.objList = (PropertySelectableList) o;
objList.addPropertyChangeListener(this);
return true; return true;
} else return false; } else return false;
} }

View File

@ -1,65 +1,66 @@
package eva2.gui; //package eva2.gui;
//
//
import javax.swing.*; //import javax.swing.*;
//
import eva2.server.go.individuals.codings.gp.AbstractGPNode; //import eva2.server.go.individuals.codings.gp.AbstractGPNode;
import eva2.server.go.individuals.codings.gp.GPArea; //import eva2.server.go.individuals.codings.gp.GPArea;
//
import java.beans.PropertyEditor; //import java.beans.PropertyEditor;
import java.beans.PropertyChangeSupport; //import java.beans.PropertyChangeSupport;
import java.beans.PropertyChangeListener; //import java.beans.PropertyChangeListener;
import java.awt.*; //import java.awt.*;
import java.awt.event.ActionListener; //import java.awt.event.ActionListener;
import java.awt.event.ActionEvent; //import java.awt.event.ActionEvent;
import java.util.ArrayList; //import java.util.ArrayList;
//
/** ///**
* TODO this should be redundant with the new GenericObjectListEditor. // * TODO this should be redundant with the new GenericObjectListEditor.
* // *
* Created by IntelliJ IDEA. // * Created by IntelliJ IDEA.
* User: streiche // * User: streiche
* Date: 23.03.2004 // * Date: 23.03.2004
* Time: 15:03:29 // * Time: 15:03:29
* To change this template use File | Settings | File Templates. // * To change this template use File | Settings | File Templates.
*/ // */
public class GenericStringListSelectionEditor extends AbstractListSelectionEditor { //public class GenericStringListSelectionEditor extends AbstractListSelectionEditor {
private PropertyStringList m_List; // private PropertyStringList m_List;
//
@Override // @Override
protected int getElementCount() { // protected int getElementCount() {
return m_List.getStrings().length; // return m_List.getStrings().length;
} // }
//
@Override // @Override
protected String getElementName(int i) { // protected String getElementName(int i) {
return m_List.getStrings()[i]; // return m_List.getStrings()[i];
} // }
//
@Override // @Override
protected boolean isElementAllowed(int i) { // protected boolean isElementAllowed(int i) {
return this.m_List.getSelection()[i]; // return this.m_List.getSelection()[i];
} // }
//
@Override // @Override
protected void performOnAction() { // protected boolean performOnAction() {
for (int i = 0; i < this.m_BlackCheck.length; i++) { // for (int i = 0; i < this.m_BlackCheck.length; i++) {
this.m_List.setSelectionForElement(i, this.m_BlackCheck[i].isSelected()); // this.m_List.setSelectionForElement(i, this.m_BlackCheck[i].isSelected());
} // }
} // return true;
// }
@Override //
protected boolean setObject(Object o) { // @Override
if (o instanceof PropertyStringList) { // protected boolean setObject(Object o) {
this.m_List = (PropertyStringList) o; // if (o instanceof PropertyStringList) {
return true; // this.m_List = (PropertyStringList) o;
} else return false; // return true;
} // } else return false;
// }
/** Retruns the current object. //
* @return the current object // /** Retruns the current object.
*/ // * @return the current object
public Object getValue() { // */
return this.m_List; // public Object getValue() {
} // return this.m_List;
} // }
//}

View File

@ -169,7 +169,7 @@ public class PropertyEditorProvider {
PropertyEditorManager.registerEditor(PropertyEpsilonThreshold.class , GenericEpsilonThresholdEditor.class); PropertyEditorManager.registerEditor(PropertyEpsilonThreshold.class , GenericEpsilonThresholdEditor.class);
PropertyEditorManager.registerEditor(PropertyEpsilonConstraint.class , GenericEpsilonConstraintEditor.class); PropertyEditorManager.registerEditor(PropertyEpsilonConstraint.class , GenericEpsilonConstraintEditor.class);
PropertyEditorManager.registerEditor(PropertyWeightedLPTchebycheff.class, GenericWeigthedLPTchebycheffEditor.class); PropertyEditorManager.registerEditor(PropertyWeightedLPTchebycheff.class, GenericWeigthedLPTchebycheffEditor.class);
PropertyEditorManager.registerEditor(PropertyStringList.class , GenericStringListSelectionEditor.class); // PropertyEditorManager.registerEditor(PropertyStringList.class , GenericStringListSelectionEditor.class);
PropertyEditorManager.registerEditor(PropertyFilePath.class , GenericFilePathEditor.class); PropertyEditorManager.registerEditor(PropertyFilePath.class , GenericFilePathEditor.class);
PropertyEditorManager.registerEditor(PropertyRemoteServers.class , GenericRemoteServersEditor.class); PropertyEditorManager.registerEditor(PropertyRemoteServers.class , GenericRemoteServersEditor.class);
PropertyEditorManager.registerEditor(PropertyOptimizationObjectives.class , GenericOptimizationObjectivesEditor.class); PropertyEditorManager.registerEditor(PropertyOptimizationObjectives.class , GenericOptimizationObjectivesEditor.class);

View File

@ -1,5 +1,8 @@
package eva2.gui; package eva2.gui;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
/** /**
* Created by IntelliJ IDEA. * Created by IntelliJ IDEA.
* User: streiche * User: streiche
@ -11,6 +14,7 @@ public class PropertySelectableList implements java.io.Serializable {
private Object[] m_Objects; private Object[] m_Objects;
private boolean[] m_Selection; private boolean[] m_Selection;
private PropertyChangeSupport m_Support;
public PropertySelectableList() { public PropertySelectableList() {
} }
@ -33,6 +37,7 @@ public class PropertySelectableList implements java.io.Serializable {
public void setObjects(Object[] o) { public void setObjects(Object[] o) {
this.m_Objects = o; this.m_Objects = o;
this.m_Selection = new boolean[o.length]; this.m_Selection = new boolean[o.length];
m_Support.firePropertyChange("PropertySelectableList", null, this);
} }
public Object[] getStrings() { public Object[] getStrings() {
return this.m_Objects; return this.m_Objects;
@ -40,6 +45,7 @@ public class PropertySelectableList implements java.io.Serializable {
public void setSelection(boolean[] selection) { public void setSelection(boolean[] selection) {
this.m_Selection = selection; this.m_Selection = selection;
m_Support.firePropertyChange("PropertySelectableList", null, this);
} }
public boolean[] getSelection() { public boolean[] getSelection() {
@ -47,7 +53,10 @@ public class PropertySelectableList implements java.io.Serializable {
} }
public void setSelectionForElement(int index, boolean b) { public void setSelectionForElement(int index, boolean b) {
this.m_Selection[index] = b; if (m_Selection[index]!=b) {
this.m_Selection[index] = b;
m_Support.firePropertyChange("PropertySelectableList", null, this);
}
} }
public int size() { public int size() {
@ -66,5 +75,14 @@ public class PropertySelectableList implements java.io.Serializable {
public void clear() { public void clear() {
m_Objects=null; m_Objects=null;
m_Selection=null; m_Selection=null;
m_Support.firePropertyChange("PropertySelectableList", null, this);
} }
public void addPropertyChangeListener(PropertyChangeListener l) {
m_Support.addPropertyChangeListener(l);
}
public void removePropertyChangeListener(PropertyChangeListener l) {
m_Support.removePropertyChangeListener(l);
}
} }

View File

@ -1,49 +1,49 @@
package eva2.gui; //package eva2.gui;
//
/** ///**
* Created by IntelliJ IDEA. // * Created by IntelliJ IDEA.
* User: streiche // * User: streiche
* Date: 23.03.2004 // * Date: 23.03.2004
* Time: 15:04:05 // * Time: 15:04:05
* To change this template use File | Settings | File Templates. // * To change this template use File | Settings | File Templates.
*/ // */
public class PropertyStringList implements java.io.Serializable { //public class PropertyStringList implements java.io.Serializable {
//
public String[] m_Strings; // public String[] m_Strings;
public boolean[] m_Selection; // public boolean[] m_Selection;
//
public PropertyStringList() { // public PropertyStringList() {
//
} // }
public PropertyStringList(PropertyStringList b) { // public PropertyStringList(PropertyStringList b) {
if (b.m_Strings != null) { // if (b.m_Strings != null) {
this.m_Strings = new String[b.m_Strings.length]; // this.m_Strings = new String[b.m_Strings.length];
System.arraycopy(b.m_Strings, 0, this.m_Strings, 0, this.m_Strings.length); // System.arraycopy(b.m_Strings, 0, this.m_Strings, 0, this.m_Strings.length);
} // }
if (b.m_Selection != null) { // if (b.m_Selection != null) {
this.m_Selection = new boolean[b.m_Selection.length]; // this.m_Selection = new boolean[b.m_Selection.length];
System.arraycopy(b.m_Selection, 0, this.m_Selection, 0, this.m_Selection.length); // System.arraycopy(b.m_Selection, 0, this.m_Selection, 0, this.m_Selection.length);
} // }
} // }
public Object clone() { // public Object clone() {
return (Object) new PropertyStringList(this); // return (Object) new PropertyStringList(this);
} // }
public void setStrings(String[] strings) { // public void setStrings(String[] strings) {
this.m_Strings = strings; // this.m_Strings = strings;
this.m_Selection = new boolean[this.m_Strings.length]; // this.m_Selection = new boolean[this.m_Strings.length];
} // }
public String[] getStrings() { // public String[] getStrings() {
return this.m_Strings; // return this.m_Strings;
} // }
//
public void setSelection(boolean[] selection) { // public void setSelection(boolean[] selection) {
this.m_Selection = selection; // this.m_Selection = selection;
} // }
public boolean[] getSelection() { // public boolean[] getSelection() {
return this.m_Selection; // return this.m_Selection;
} // }
//
public void setSelectionForElement(int index, boolean b) { // public void setSelectionForElement(int index, boolean b) {
this.m_Selection[index] = b; // this.m_Selection[index] = b;
} // }
} //}

View File

@ -1,6 +1,8 @@
package eva2.server.go.individuals.codings.gp; package eva2.server.go.individuals.codings.gp;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.util.ArrayList; import java.util.ArrayList;
import wsi.ra.math.RNG; import wsi.ra.math.RNG;
@ -14,7 +16,9 @@ import wsi.ra.math.RNG;
* To change this template use Options | File Templates. * To change this template use Options | File Templates.
*/ */
public class GPArea implements java.io.Serializable { public class GPArea implements java.io.Serializable {
/** Handles property change notification */
private transient PropertyChangeSupport m_Support = new PropertyChangeSupport(this);
private ArrayList m_CompleteList = new ArrayList(); private ArrayList m_CompleteList = new ArrayList();
private ArrayList m_ReducedList = new ArrayList(); private ArrayList m_ReducedList = new ArrayList();
private ArrayList m_BlackList = new ArrayList(); private ArrayList m_BlackList = new ArrayList();
@ -92,6 +96,7 @@ public class GPArea implements java.io.Serializable {
*/ */
public void SetCompleteList(ArrayList a) { public void SetCompleteList(ArrayList a) {
this.m_CompleteList = a; this.m_CompleteList = a;
m_Support.firePropertyChange("GPArea", null, this);
} }
/** This method compiles the Complete List to the allowed list using the BlackList /** This method compiles the Complete List to the allowed list using the BlackList
@ -103,6 +108,7 @@ public class GPArea implements java.io.Serializable {
this.m_ReducedList.add(this.m_CompleteList.get(i)); this.m_ReducedList.add(this.m_CompleteList.get(i));
} }
} }
m_Support.firePropertyChange("GPArea", null, this);
} }
/** This method allows you to fetch a random node of a given arity /** This method allows you to fetch a random node of a given arity
@ -138,4 +144,21 @@ public class GPArea implements java.io.Serializable {
public boolean isEmpty() { public boolean isEmpty() {
return (m_CompleteList==null) || (m_CompleteList.size()==0); return (m_CompleteList==null) || (m_CompleteList.size()==0);
} }
public void clear() {
m_CompleteList = new ArrayList();
m_ReducedList = new ArrayList();
m_BlackList = new ArrayList();
m_Support.firePropertyChange("GPArea", null, this);
}
public void addPropertyChangeListener(PropertyChangeListener l) {
m_Support.addPropertyChangeListener(l);
}
/**
*
*/
public void removePropertyChangeListener(PropertyChangeListener l) {
m_Support.removePropertyChangeListener(l);
}
} }

View File

@ -96,30 +96,36 @@ public class PSymbolicRegression extends AbstractOptimizationProblem implements
/** This method inits the Problem to log multiruns /** This method inits the Problem to log multiruns
*/ */
public void initProblem() { public void initProblem() {
this.compileArea();
if (m_TargetFunction == null) m_TargetFunction = new RFKoza_GPI_10_2(); if (m_TargetFunction == null) m_TargetFunction = new RFKoza_GPI_10_2();
this.m_OverallBest = null; this.m_OverallBest = null;
this.m_C = new double[this.m_NumberOfConstants]; this.m_C = new double[this.m_NumberOfConstants];
for (int i = 0; i < this.m_C.length; i++) this.m_C[i] = RNG.randomDouble(-10, 10); for (int i = 0; i < this.m_C.length; i++) this.m_C[i] = RNG.randomDouble(-10, 10);
} this.compileArea();
}
/** This method compiles the area /**
* This method compiles the area
*/ */
private void compileArea() { private void compileArea() {
this.m_GPArea = new GPArea(); // unfortunately this must be cloned or the GUI wont update.
// if (m_GPArea==null)
this.m_GPArea.add2CompleteList(new GPNodeAdd()); m_GPArea = new GPArea();
this.m_GPArea.add2CompleteList(new GPNodeSub()); // else m_GPArea = (GPArea)m_GPArea.clone();
this.m_GPArea.add2CompleteList(new GPNodeDiv());
this.m_GPArea.add2CompleteList(new GPNodeMult()); if (m_GPArea.isEmpty()) {
this.m_GPArea.add2CompleteList(new GPNodeSin(), false); this.m_GPArea.add2CompleteList(new GPNodeAdd());
this.m_GPArea.add2CompleteList(new GPNodeCos(), false); this.m_GPArea.add2CompleteList(new GPNodeSub());
this.m_GPArea.add2CompleteList(new GPNodeExp(), false); this.m_GPArea.add2CompleteList(new GPNodeDiv());
this.m_GPArea.add2CompleteList(new GPNodePow2(), false); this.m_GPArea.add2CompleteList(new GPNodeMult());
this.m_GPArea.add2CompleteList(new GPNodePow3(), false); this.m_GPArea.add2CompleteList(new GPNodeSin(), false);
this.m_GPArea.add2CompleteList(new GPNodeSqrt(), false); this.m_GPArea.add2CompleteList(new GPNodeCos(), false);
for (int i = 0; i < this.m_X.length; i++) this.m_GPArea.add2CompleteList(new GPNodeInput("X"+i)); this.m_GPArea.add2CompleteList(new GPNodeExp(), false);
for (int i = 0; i < this.m_C.length; i++) this.m_GPArea.add2CompleteList(new GPNodeInput("C"+i)); this.m_GPArea.add2CompleteList(new GPNodePow2(), false);
this.m_GPArea.add2CompleteList(new GPNodePow3(), false);
this.m_GPArea.add2CompleteList(new GPNodeSqrt(), false);
for (int i = 0; i < this.m_X.length; i++) this.m_GPArea.add2CompleteList(new GPNodeInput("X"+i));
for (int i = 0; i < this.m_C.length; i++) this.m_GPArea.add2CompleteList(new GPNodeInput("C"+i));
}
this.m_GPArea.compileReducedList(); this.m_GPArea.compileReducedList();
} }
@ -192,7 +198,7 @@ public class PSymbolicRegression extends AbstractOptimizationProblem implements
/** /**
* This method evaluates a single individual and sets the fitness values * This method evaluates a single individual and sets the fitness values
* @param individual The individual that is to be evalutated * @param individual The individual that is to be evaluated
*/ */
public void evaluate(AbstractEAIndividual individual) { public void evaluate(AbstractEAIndividual individual) {
InterfaceProgram program; InterfaceProgram program;
@ -330,8 +336,8 @@ public class PSymbolicRegression extends AbstractOptimizationProblem implements
*/ */
public void setNumberOfConstants(int b) { public void setNumberOfConstants(int b) {
this.m_NumberOfConstants = b; this.m_NumberOfConstants = b;
m_GPArea.clear();
this.initProblem(); this.initProblem();
this.compileArea();
} }
public int getNumberOfConstants() { public int getNumberOfConstants() {
return this.m_NumberOfConstants; return this.m_NumberOfConstants;
@ -365,6 +371,7 @@ public class PSymbolicRegression extends AbstractOptimizationProblem implements
((InterfaceDataTypeProgram)this.m_Template).SetFunctionArea(tmpArea); ((InterfaceDataTypeProgram)this.m_Template).SetFunctionArea(tmpArea);
} }
public GPArea getArea() { public GPArea getArea() {
if (m_GPArea==null) initProblem();
return this.m_GPArea; return this.m_GPArea;
} }
public String areaTipText() { public String areaTipText() {
@ -396,6 +403,7 @@ public class PSymbolicRegression extends AbstractOptimizationProblem implements
this.m_TargetFunction = b; this.m_TargetFunction = b;
} }
public InterfaceRegressionFunction getTargetFunction() { public InterfaceRegressionFunction getTargetFunction() {
if (m_TargetFunction==null) initProblem();
return this.m_TargetFunction; return this.m_TargetFunction;
} }
public String targetFunctionTipText() { public String targetFunctionTipText() {