aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/gui/population/ChromosomePane.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/jcgp/gui/population/ChromosomePane.java')
-rw-r--r--src/jcgp/gui/population/ChromosomePane.java92
1 files changed, 75 insertions, 17 deletions
diff --git a/src/jcgp/gui/population/ChromosomePane.java b/src/jcgp/gui/population/ChromosomePane.java
index 1f67255..0279d09 100644
--- a/src/jcgp/gui/population/ChromosomePane.java
+++ b/src/jcgp/gui/population/ChromosomePane.java
@@ -10,7 +10,7 @@ import jcgp.backend.population.Connection;
import jcgp.backend.population.Input;
import jcgp.backend.population.Node;
import jcgp.backend.resources.Resources;
-
+import jcgp.gui.GUI;
public class ChromosomePane extends ScrollPane {
@@ -21,15 +21,23 @@ public class ChromosomePane extends ScrollPane {
private Pane content;
private ArrayList<Line> connectionLines;
-
private ArrayList<GUIOutput> relock = new ArrayList<GUIOutput>();
-
+
+ private int rows, columns;
+
private boolean target = false;
+ private boolean evaluating = false;
- public ChromosomePane(Chromosome chromosome, Resources resources) {
- super();
+ public ChromosomePane(Chromosome chromosome, GUI gui) {
+ super();
+
+ final Resources resources = gui.getExperiment().getResources();
+
+ rows = resources.rows();
+ columns = resources.columns();
+
connectionLines = new ArrayList<Line>();
-
+
content = new Pane();
content.setId("content pane for genes");
@@ -42,10 +50,10 @@ public class ChromosomePane extends ScrollPane {
content.getChildren().addAll(guiInputs[i]);
}
// nodes
- guiNodes = new GUINode[resources.rows()][resources.columns()];
+ guiNodes = new GUINode[rows][columns];
double angle, xPos, yPos;
- for (int r = 0; r < guiNodes.length; r++) {
- for (int c = 0; c < guiNodes[r].length; c++) {
+ for (int r = 0; r < rows; r++) {
+ for (int c = 0; c < columns; c++) {
// make the connection lines
Line lines[] = new Line[resources.arity()];
for (int l = 0; l < lines.length; l++) {
@@ -59,7 +67,7 @@ public class ChromosomePane extends ScrollPane {
connectionLines.add(lines[l]);
}
// make the GUI elements
- guiNodes[r][c] = new GUINode(this, chromosome.getNode(r, c), lines);
+ guiNodes[r][c] = new GUINode(this, chromosome.getNode(r, c), lines, gui);
}
content.getChildren().addAll(guiNodes[r]);
}
@@ -74,7 +82,7 @@ public class ChromosomePane extends ScrollPane {
line.setVisible(false);
connectionLines.add(line);
// make the GUI elements
- guiOutputs[i] = new GUIOutput(this, chromosome.getOutput(i), line);
+ guiOutputs[i] = new GUIOutput(this, chromosome.getOutput(i), line, gui);
content.getChildren().addAll(guiOutputs[i]);
}
@@ -83,7 +91,7 @@ public class ChromosomePane extends ScrollPane {
setContent(content);
}
- public GUIGene getGuiGene(Connection gene) {
+ protected GUIGene getGuiGene(Connection gene) {
if (gene instanceof Input) {
return guiInputs[((Input) gene).getIndex()];
} else if (gene instanceof Node) {
@@ -94,24 +102,28 @@ public class ChromosomePane extends ScrollPane {
}
}
- public boolean isTarget() {
+ protected boolean isTarget() {
return target;
}
- public void setTarget(boolean newValue) {
+ protected void setTarget(boolean newValue) {
target = newValue;
}
public void updateGenes() {
- for (int r = 0; r < guiNodes.length; r++) {
- for (int c = 0; c < guiNodes[r].length; c++) {
+ for (int r = 0; r < rows; r++) {
+ for (int c = 0; c < columns; c++) {
guiNodes[r][c].updateLines();
- guiNodes[r][c].updateFunction();
+ guiNodes[r][c].updateText();
}
}
for (int i = 0; i < guiOutputs.length; i++) {
guiOutputs[i].updateLines();
}
+ if (isEvaluating()) {
+ evaluate(0);
+ }
+
}
public void unlockOutputs() {
@@ -129,4 +141,50 @@ public class ChromosomePane extends ScrollPane {
relock.get(i).lock();
}
}
+
+ public void setInputs(Object[] values) {
+ evaluating = true;
+ for (int i = 0; i < guiInputs.length; i++) {
+ guiInputs[i].setValue(values[i]);
+ guiInputs[i].updateText();
+ }
+ evaluate(0);
+ }
+
+ public void evaluate(int start) {
+ if (start >= 0 || start < columns) {
+ for (int c = start; c < columns; c++) {
+ for (int r = 0; r < rows; r++) {
+ guiNodes[r][c].calculate();
+ guiNodes[r][c].updateText();
+ }
+ }
+ for (int o = 0; o < guiOutputs.length; o++) {
+ guiOutputs[o].calculate();
+ guiOutputs[o].updateText();
+ }
+ }
+ }
+
+ public void hideValues() {
+ evaluating = false;
+ for (int i = 0; i < guiInputs.length; i++) {
+ guiInputs[i].updateText();
+ }
+ for (int c = 0; c < columns; c++) {
+ for (int r = 0; r < rows; r++) {
+ guiNodes[r][c].updateText();
+ }
+ }
+ for (int o = 0; o < guiOutputs.length; o++) {
+ guiOutputs[o].updateText();
+ }
+ }
+
+ /**
+ * @return the evaluating
+ */
+ public boolean isEvaluating() {
+ return evaluating;
+ }
}