aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp
diff options
context:
space:
mode:
Diffstat (limited to 'src/jcgp')
-rw-r--r--src/jcgp/JCGP.java5
-rw-r--r--src/jcgp/backend/function/FunctionSet.java10
-rw-r--r--src/jcgp/backend/function/SymbolicRegressionFunctions.java2
-rw-r--r--src/jcgp/backend/parsers/ChromosomeParser.java2
-rw-r--r--src/jcgp/gui/GUI.java4
-rw-r--r--src/jcgp/gui/settings/SettingsPane.java36
6 files changed, 47 insertions, 12 deletions
diff --git a/src/jcgp/JCGP.java b/src/jcgp/JCGP.java
index be09b4a..aa3b647 100644
--- a/src/jcgp/JCGP.java
+++ b/src/jcgp/JCGP.java
@@ -479,6 +479,11 @@ public class JCGP {
public void reset() {
finished = false;
statistics = new StatisticsLogger();
+ resources.setArity(problem.getFunctionSet().getMaxArity());
+ if (resources.arity() < 1) {
+ resources.println("[CGP] Error: arity is smaller than 1. Check that at least one function is enabled");
+ return;
+ }
population = new Population(resources);
resetStatisticsValues();
resources.setCurrentGeneration(1);
diff --git a/src/jcgp/backend/function/FunctionSet.java b/src/jcgp/backend/function/FunctionSet.java
index 052183a..abc9eb4 100644
--- a/src/jcgp/backend/function/FunctionSet.java
+++ b/src/jcgp/backend/function/FunctionSet.java
@@ -69,16 +69,16 @@ public abstract class FunctionSet {
/**
* Computes and returns the maximum arity out of
- * all the function, enabled or disabled.
+ * all enabled functions.
*
- * @return
+ * @return the problem's current maximum arity.
*/
public int getMaxArity(){
int arity = 0;
- for (Function function : functionList) {
+ for (Integer function : allowedFunctions) {
// if a higher arity is found, store it
- if (function.getArity() > arity) {
- arity = function.getArity();
+ if (functionList.get(function).getArity() > arity) {
+ arity = functionList.get(function).getArity();
}
}
return arity;
diff --git a/src/jcgp/backend/function/SymbolicRegressionFunctions.java b/src/jcgp/backend/function/SymbolicRegressionFunctions.java
index 6f72723..9c6a3b1 100644
--- a/src/jcgp/backend/function/SymbolicRegressionFunctions.java
+++ b/src/jcgp/backend/function/SymbolicRegressionFunctions.java
@@ -208,7 +208,7 @@ public class SymbolicRegressionFunctions extends FunctionSet {
}
/**
- * Exponential function. Returns the exponential of input 0.
+ * Exponential function. Returns e raised to input 0.
*
* @see Math
*/
diff --git a/src/jcgp/backend/parsers/ChromosomeParser.java b/src/jcgp/backend/parsers/ChromosomeParser.java
index 92568cc..c35b5b9 100644
--- a/src/jcgp/backend/parsers/ChromosomeParser.java
+++ b/src/jcgp/backend/parsers/ChromosomeParser.java
@@ -125,7 +125,7 @@ public abstract class ChromosomeParser {
resources.println("[Parser] File parsed successfully");
} else {
- resources.println("[Parser] Error: the topology of the chromosome in " + file.getName() + " does not match that of the experiment");
+ resources.println("[Parser] Error: the number of genes of the chromosome in " + file.getName() + " does not match that of the experiment");
}
}
diff --git a/src/jcgp/gui/GUI.java b/src/jcgp/gui/GUI.java
index 8056140..62a159c 100644
--- a/src/jcgp/gui/GUI.java
+++ b/src/jcgp/gui/GUI.java
@@ -246,4 +246,8 @@ public class GUI extends Application {
public Stage getStage() {
return stage;
}
+
+ public void flushConsole() {
+ console.flush();
+ }
}
diff --git a/src/jcgp/gui/settings/SettingsPane.java b/src/jcgp/gui/settings/SettingsPane.java
index b1322e4..e3d2096 100644
--- a/src/jcgp/gui/settings/SettingsPane.java
+++ b/src/jcgp/gui/settings/SettingsPane.java
@@ -43,6 +43,8 @@ public class SettingsPane extends AnchorPane {
private TestCaseTable testCaseTable;
private GUI gui;
+
+ private int currentArity;
public SettingsPane(GUI gui) {
super();
@@ -168,6 +170,8 @@ public class SettingsPane extends AnchorPane {
}
private void initialiseProblemTypeParameters(final JCGP jcgp, final GUI gui) {
+ updateArity();
+
problemPane= new VBox(2);
Text header = new Text("Problem Type");
@@ -207,6 +211,7 @@ public class SettingsPane extends AnchorPane {
@Override
public void handle(ActionEvent event) {
jcgp.setProblem(problemCBox.getSelectionModel().getSelectedIndex());
+ updateArity();
refreshParameters(jcgp.getProblem().getLocalParameters(), problemParameters);
if (testCaseTable != null) {
testCaseTable.close();
@@ -313,6 +318,7 @@ public class SettingsPane extends AnchorPane {
gui.reDraw();
refreshFunctions();
}
+ gui.flushConsole();
}
});
@@ -328,6 +334,7 @@ public class SettingsPane extends AnchorPane {
gui.getExperiment().loadChromosome(chrFile, 0);
gui.reDraw();
}
+ gui.flushConsole();
}
});
saveChromosome.setOnAction(new EventHandler<ActionEvent>() {
@@ -341,6 +348,7 @@ public class SettingsPane extends AnchorPane {
if (chrFile != null) {
gui.getExperiment().saveChromosome(chrFile, 0);
}
+ gui.flushConsole();
}
});
@@ -395,6 +403,7 @@ public class SettingsPane extends AnchorPane {
fs.disableFunction(index);
}
gui.updateFunctionSelector();
+ revalidateParameters();
}
});
nodeFunctions.getChildren().add(cb);
@@ -408,7 +417,8 @@ public class SettingsPane extends AnchorPane {
}
/**
- * @return true if the experiment needs to be reset, false otherwise.
+ *
+ * @return true if the experiment needs to be reset, false if otherwise.
*/
public boolean isResetRequired() {
for (GUIParameter<?> parameter : parameters) {
@@ -416,6 +426,9 @@ public class SettingsPane extends AnchorPane {
return true;
}
}
+ if (arityChanged()) {
+ return true;
+ }
return false;
}
@@ -437,15 +450,19 @@ public class SettingsPane extends AnchorPane {
* changed parameter.
*/
public void revalidateParameters() {
- runPause.setDisable(false);
- step.setDisable(false);
+ boolean disableControls = false;
for (GUIParameter<?> parameter : parameters) {
parameter.validate();
if (parameter.requiresReset()) {
- runPause.setDisable(true);
- step.setDisable(true);
+ disableControls = true;
}
}
+ if (arityChanged()) {
+ disableControls = true;
+ }
+
+ runPause.setDisable(disableControls);
+ step.setDisable(disableControls);
}
/**
@@ -456,6 +473,7 @@ public class SettingsPane extends AnchorPane {
for (GUIParameter<?> parameter : parameters) {
parameter.applyValue();
}
+ updateArity();
}
/**
@@ -499,4 +517,12 @@ public class SettingsPane extends AnchorPane {
public TestCaseTable getTestCaseTable() {
return testCaseTable;
}
+
+ private void updateArity() {
+ currentArity = gui.getExperiment().getProblem().getFunctionSet().getMaxArity();
+ }
+
+ private boolean arityChanged() {
+ return currentArity != gui.getExperiment().getProblem().getFunctionSet().getMaxArity();
+ }
}