aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEduardo Pedroni <ep625@york.ac.uk>2014-03-24 08:14:12 +0000
committerEduardo Pedroni <ep625@york.ac.uk>2014-03-24 08:14:12 +0000
commita09124d93c3e31d4e25ffe6c2f0a7663c02c35ed (patch)
treeffd47d8d16bbc20ac900db067f73146b66ae6e27
parent0c288cc1952809294c8d70d86b9f41b04878ac2e (diff)
Going further into active path locking
-rw-r--r--src/jcgp/CGP.java55
-rw-r--r--src/jcgp/GUI.java7
-rw-r--r--src/jcgp/gui/SettingsPane.java30
-rw-r--r--src/jcgp/gui/population/GUIGene.java8
-rw-r--r--src/jcgp/gui/population/GUIInput.java14
-rw-r--r--src/jcgp/gui/population/GUINode.java48
-rw-r--r--src/jcgp/gui/population/GUIOutput.java39
-rw-r--r--src/jcgp/gui/settings/GUIIntegerParameter.java23
-rw-r--r--src/jcgp/gui/settings/GUIParameter.java13
9 files changed, 195 insertions, 42 deletions
diff --git a/src/jcgp/CGP.java b/src/jcgp/CGP.java
index 6b68fd8..32fb1f0 100644
--- a/src/jcgp/CGP.java
+++ b/src/jcgp/CGP.java
@@ -5,6 +5,7 @@ import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Random;
+import java.util.Set;
import javafx.beans.property.Property;
import jcgp.function.Arithmetic;
@@ -107,7 +108,7 @@ public class CGP {
private void resetParameters(EvolutionaryAlgorithm ea, Mutator mu, FitnessFunction ff) {
Iterator<Entry<String, Parameter>> it = coreParameters.entrySet().iterator();
while (it.hasNext()) {
- ((Parameter) ((Map.Entry<String, Parameter>) it.next())).reset();
+ ((Parameter) ((Map.Entry<String, Parameter>) it.next()).getValue()).reset();
}
allParameters.clear();
@@ -124,6 +125,10 @@ public class CGP {
allParameters.putAll(moduleParameters);
}
+ public Set<Entry<String, Parameter>> getEntries() {
+ return allParameters.entrySet();
+ }
+
/*
* Utility functions
*/
@@ -230,5 +235,53 @@ public class CGP {
public Population getPopulation() {
return population;
}
+
+
+ /**
+ * @return the mutators
+ */
+ public Mutator[] getMutators() {
+ return mutators;
+ }
+
+
+ /**
+ * @return the mutator
+ */
+ public Mutator getMutator() {
+ return mutator;
+ }
+
+
+ /**
+ * @return the evolutionaryAlgorithms
+ */
+ public EvolutionaryAlgorithm[] getEvolutionaryAlgorithms() {
+ return evolutionaryAlgorithms;
+ }
+
+
+ /**
+ * @return the evolutionaryAlgorithm
+ */
+ public EvolutionaryAlgorithm getEvolutionaryAlgorithm() {
+ return evolutionaryAlgorithm;
+ }
+
+
+ /**
+ * @return the fitnessFunctions
+ */
+ public FitnessFunction[] getFitnessFunctions() {
+ return fitnessFunctions;
+ }
+
+
+ /**
+ * @return the fitnessFunction
+ */
+ public FitnessFunction getFitnessFunction() {
+ return fitnessFunction;
+ }
}
diff --git a/src/jcgp/GUI.java b/src/jcgp/GUI.java
index 1e1d4e4..284f9ae 100644
--- a/src/jcgp/GUI.java
+++ b/src/jcgp/GUI.java
@@ -68,12 +68,13 @@ public class GUI extends Application {
mainPane.getTabs().add(tab);
}
+ settings = new SettingsPane(cgp);
+
mainPane.setPrefHeight(500);
window = new BorderPane();
window.setCenter(mainPane);
-
- Scene scene = new Scene(window);
+ window.setRight(settings);
primaryStage.addEventFilter(MouseDragEvent.MOUSE_DRAG_RELEASED, new EventHandler<MouseDragEvent>() {
@Override
@@ -102,7 +103,7 @@ public class GUI extends Application {
primaryStage.setMinHeight(600);
primaryStage.setMinWidth(800);
- primaryStage.setScene(scene);
+ primaryStage.setScene(new Scene(window));
primaryStage.show();
diff --git a/src/jcgp/gui/SettingsPane.java b/src/jcgp/gui/SettingsPane.java
index 53056d3..06c35ec 100644
--- a/src/jcgp/gui/SettingsPane.java
+++ b/src/jcgp/gui/SettingsPane.java
@@ -1,11 +1,37 @@
package jcgp.gui;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+
import javafx.scene.layout.VBox;
+import javafx.scene.text.Text;
+import jcgp.CGP;
+import jcgp.gui.settings.GUIIntegerParameter;
+import jcgp.parameters.IntegerParameter;
+import jcgp.parameters.Parameter;
public class SettingsPane extends VBox {
-
- public SettingsPane() {
+
+ public SettingsPane(CGP cgp) {
super();
setPrefSize(180, 500);
+
+ Text parameters = new Text("Parameters");
+ getChildren().add(parameters);
+
+ Iterator<Entry<String, Parameter>> it = cgp.getResources().getEntries().iterator();
+ while (it.hasNext()) {
+ Parameter p = (Parameter) ((Map.Entry<String, Parameter>) it.next()).getValue();
+ if (p instanceof IntegerParameter) {
+ GUIIntegerParameter gip = new GUIIntegerParameter((IntegerParameter) p);
+ getChildren().add(gip);
+ }
+ }
+
}
+
+
+
+
}
diff --git a/src/jcgp/gui/population/GUIGene.java b/src/jcgp/gui/population/GUIGene.java
index ef44110..830192c 100644
--- a/src/jcgp/gui/population/GUIGene.java
+++ b/src/jcgp/gui/population/GUIGene.java
@@ -34,6 +34,8 @@ public abstract class GUIGene extends Group {
protected ChromosomePane parent;
+ protected int locked = 0;
+
public SimpleObjectProperty<GUIGeneState> stateProperty() {
return stateProperty;
}
@@ -46,6 +48,12 @@ public abstract class GUIGene extends Group {
text.setVisible(value);
}
+ public boolean isLocked() {
+ return locked > 0;
+ }
+
+ public abstract void setLocked(boolean value);
+
public abstract Gene getGene();
public abstract void setConnections(GUIGeneState newState);
diff --git a/src/jcgp/gui/population/GUIInput.java b/src/jcgp/gui/population/GUIInput.java
index 6f7a523..bf872dc 100644
--- a/src/jcgp/gui/population/GUIInput.java
+++ b/src/jcgp/gui/population/GUIInput.java
@@ -72,15 +72,6 @@ public class GUIInput extends GUIGene {
}
});
- addEventFilter(MouseDragEvent.MOUSE_DRAG_OVER, new EventHandler<MouseDragEvent>() {
- @Override
- public void handle(MouseDragEvent event) {
- // the user is dragging over this node, react appropriately
- // this happens even if we are the source of the drag
-
- }
- });
-
addEventFilter(MouseDragEvent.MOUSE_DRAG_EXITED, new EventHandler<MouseDragEvent>() {
@Override
public void handle(MouseDragEvent event) {
@@ -189,5 +180,10 @@ public class GUIInput extends GUIGene {
public void resetState() {
stateProperty.set(GUIGeneState.NEUTRAL);
+ }
+
+ @Override
+ public void setLocked(boolean value) {
+ locked += value ? 1 : -1;
}
}
diff --git a/src/jcgp/gui/population/GUINode.java b/src/jcgp/gui/population/GUINode.java
index 4350e52..c5ab43a 100644
--- a/src/jcgp/gui/population/GUINode.java
+++ b/src/jcgp/gui/population/GUINode.java
@@ -33,7 +33,7 @@ public class GUINode extends GUIGene {
private Node node;
private int connectionIndex;
-
+
public GUINode(ChromosomePane parentRef, final Node node, Resources resources, Line[] connectionLines) {
// store references
@@ -176,15 +176,6 @@ public class GUINode extends GUIGene {
}
});
- addEventFilter(MouseDragEvent.MOUSE_DRAG_OVER, new EventHandler<MouseDragEvent>() {
- @Override
- public void handle(MouseDragEvent event) {
- // the user is dragging over this node, react appropriately
- // this happens even if we are the source of the drag
-
- }
- });
-
addEventFilter(MouseDragEvent.MOUSE_DRAG_EXITED, new EventHandler<MouseDragEvent>() {
@Override
public void handle(MouseDragEvent event) {
@@ -244,8 +235,12 @@ public class GUINode extends GUIGene {
public void handle(MouseEvent event) {
// cursor has left this node without dragging, or it is dragging and this is the source
if (stateProperty.get() == GUIGeneState.HOVER) {
- stateProperty.set(GUIGeneState.NEUTRAL);
- setConnections(GUIGeneState.NEUTRAL);
+ if (isLocked()) {
+
+ } else {
+ stateProperty.set(GUIGeneState.NEUTRAL);
+ setConnections(GUIGeneState.NEUTRAL);
+ }
}
}
});
@@ -270,7 +265,10 @@ public class GUINode extends GUIGene {
case HOVER:
mainCircle.setFill(Paint.valueOf(GUI.HARD_HIGHLIGHT_COLOUR));
showLines(true);
- setConnections(GUIGeneState.INDIRECT_HOVER);
+ if (!isLocked()) {
+ setConnections(GUIGeneState.INDIRECT_HOVER);
+ }
+
break;
case INDIRECT_HOVER:
mainCircle.setFill(Paint.valueOf(GUI.SOFT_HIGHLIGHT_COLOUR));
@@ -392,9 +390,13 @@ public class GUINode extends GUIGene {
public void setConnections(GUIGeneState newState) {
for (int i = 0; i < lines.length; i++) {
if (node.getConnection(i) instanceof Node) {
- parent.getGuiNode(((Node) node.getConnection(i)).getRow(), ((Node) node.getConnection(i)).getColumn()).setState(newState);
+ if (!parent.getGuiNode(((Node) node.getConnection(i)).getRow(), ((Node) node.getConnection(i)).getColumn()).isLocked()) {
+ parent.getGuiNode(((Node) node.getConnection(i)).getRow(), ((Node) node.getConnection(i)).getColumn()).setState(newState);
+ }
} else if (node.getConnection(i) instanceof Input) {
- parent.getGuiInput(((Input) node.getConnection(i)).getIndex()).setState(newState);
+ if (!parent.getGuiInput(((Input) node.getConnection(i)).getIndex()).isLocked()) {
+ parent.getGuiInput(((Input) node.getConnection(i)).getIndex()).setState(newState);
+ }
}
}
}
@@ -413,5 +415,19 @@ public class GUINode extends GUIGene {
stateProperty.set(GUIGeneState.NEUTRAL);
setConnections(GUIGeneState.NEUTRAL);
}
-
+
+
+ @Override
+ public void setLocked(boolean value) {
+ locked += value ? 1 : -1;
+ stateProperty.set(locked > 0 ? GUIGeneState.HOVER : GUIGeneState.ACTIVE_HOVER);
+
+ for (int i = 0; i < lines.length; i++) {
+ if (node.getConnection(i) instanceof Node) {
+ parent.getGuiNode(((Node) node.getConnection(i)).getRow(), ((Node) node.getConnection(i)).getColumn()).setLocked(value);
+ } else if (node.getConnection(i) instanceof Input) {
+ parent.getGuiInput(((Input) node.getConnection(i)).getIndex()).setLocked(value);
+ }
+ }
+ }
}
diff --git a/src/jcgp/gui/population/GUIOutput.java b/src/jcgp/gui/population/GUIOutput.java
index 602a022..415d0fd 100644
--- a/src/jcgp/gui/population/GUIOutput.java
+++ b/src/jcgp/gui/population/GUIOutput.java
@@ -129,15 +129,6 @@ public class GUIOutput extends GUIGene {
}
});
- addEventFilter(MouseDragEvent.MOUSE_DRAG_OVER, new EventHandler<MouseDragEvent>() {
- @Override
- public void handle(MouseDragEvent event) {
- // the user is dragging over this node, react appropriately
- // this happens even if we are the source of the drag
-
- }
- });
-
addEventFilter(MouseDragEvent.MOUSE_DRAG_EXITED, new EventHandler<MouseDragEvent>() {
@Override
public void handle(MouseDragEvent event) {
@@ -179,13 +170,25 @@ public class GUIOutput extends GUIGene {
}
});
+ addEventFilter(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() {
+ @Override
+ public void handle(MouseEvent event) {
+ setLocked(!isLocked());
+ }
+ });
+
addEventFilter(MouseEvent.MOUSE_EXITED, new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
// cursor has left this node without dragging, or it is dragging and this is the source
if (stateProperty.get() == GUIGeneState.HOVER) {
- stateProperty.set(GUIGeneState.NEUTRAL);
- setConnections(GUIGeneState.NEUTRAL);
+ if (isLocked()) {
+
+ } else {
+ stateProperty.set(GUIGeneState.NEUTRAL);
+ setConnections(GUIGeneState.NEUTRAL);
+ }
+
}
}
});
@@ -274,4 +277,18 @@ public class GUIOutput extends GUIGene {
stateProperty.set(GUIGeneState.NEUTRAL);
setConnections(GUIGeneState.NEUTRAL);
}
+
+ @Override
+ public void setLocked(boolean value) {
+ //stateProperty.set(GUIGeneState.HOVER);
+ locked += value ? 1 : -1;
+ setConnections(value ? GUIGeneState.HOVER : GUIGeneState.ACTIVE_HOVER);
+
+ if (output.getSource() instanceof Node) {
+ parent.getGuiNode(((Node) output.getSource()).getRow(), ((Node) output.getSource()).getColumn()).setLocked(value);
+ } else if (output.getSource() instanceof Input) {
+ parent.getGuiInput(((Input) output.getSource()).getIndex()).setLocked(value);
+ }
+
+ }
}
diff --git a/src/jcgp/gui/settings/GUIIntegerParameter.java b/src/jcgp/gui/settings/GUIIntegerParameter.java
new file mode 100644
index 0000000..2bf5480
--- /dev/null
+++ b/src/jcgp/gui/settings/GUIIntegerParameter.java
@@ -0,0 +1,23 @@
+package jcgp.gui.settings;
+
+import javafx.scene.control.TextField;
+import javafx.scene.text.Text;
+import jcgp.parameters.IntegerParameter;
+
+public class GUIIntegerParameter extends GUIParameter {
+
+ private TextField value;
+
+ public GUIIntegerParameter(IntegerParameter parameter) {
+ this.parameter = parameter;
+
+ name = new Text(parameter.getName());
+ value = new TextField(String.valueOf((int) parameter.getValue()));
+
+ value.setDisable(parameter.isManaged());
+
+ getChildren().addAll(name, value);
+
+ }
+
+}
diff --git a/src/jcgp/gui/settings/GUIParameter.java b/src/jcgp/gui/settings/GUIParameter.java
new file mode 100644
index 0000000..d084060
--- /dev/null
+++ b/src/jcgp/gui/settings/GUIParameter.java
@@ -0,0 +1,13 @@
+package jcgp.gui.settings;
+
+import javafx.scene.layout.HBox;
+import javafx.scene.text.Text;
+import jcgp.parameters.Parameter;
+
+public abstract class GUIParameter extends HBox {
+
+ protected Parameter parameter;
+
+ protected Text name;
+
+}