diff options
-rw-r--r-- | src/jcgp/JCGP.java | 5 | ||||
-rw-r--r-- | src/jcgp/backend/function/FunctionSet.java | 10 | ||||
-rw-r--r-- | src/jcgp/backend/function/SymbolicRegressionFunctions.java | 2 | ||||
-rw-r--r-- | src/jcgp/backend/parsers/ChromosomeParser.java | 2 | ||||
-rw-r--r-- | src/jcgp/gui/GUI.java | 4 | ||||
-rw-r--r-- | src/jcgp/gui/settings/SettingsPane.java | 35 |
6 files changed, 46 insertions, 12 deletions
diff --git a/src/jcgp/JCGP.java b/src/jcgp/JCGP.java index f36ac7c..4853ff7 100644 --- a/src/jcgp/JCGP.java +++ b/src/jcgp/JCGP.java @@ -245,6 +245,11 @@ public class JCGP { public void reset() { finished = false; + 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); resources.setCurrentGeneration(1); resources.setCurrentRun(1); diff --git a/src/jcgp/backend/function/FunctionSet.java b/src/jcgp/backend/function/FunctionSet.java index 926ed68..6a549cd 100644 --- a/src/jcgp/backend/function/FunctionSet.java +++ b/src/jcgp/backend/function/FunctionSet.java @@ -72,16 +72,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[function].getArity() > arity) { + arity = functionList[function].getArity(); } } return arity; diff --git a/src/jcgp/backend/function/SymbolicRegressionFunctions.java b/src/jcgp/backend/function/SymbolicRegressionFunctions.java index a35f258..cf5c33f 100644 --- a/src/jcgp/backend/function/SymbolicRegressionFunctions.java +++ b/src/jcgp/backend/function/SymbolicRegressionFunctions.java @@ -197,7 +197,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 91c72e6..27d01b3 100644 --- a/src/jcgp/gui/GUI.java +++ b/src/jcgp/gui/GUI.java @@ -245,4 +245,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 7fc5621..ba568a7 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); testCaseTable.close(); gui.setEvaluating(false); @@ -311,6 +316,7 @@ public class SettingsPane extends AnchorPane { gui.reDraw(); refreshFunctions(); } + gui.flushConsole(); } }); @@ -326,6 +332,7 @@ public class SettingsPane extends AnchorPane { gui.getExperiment().loadChromosome(chrFile, 0); gui.reDraw(); } + gui.flushConsole(); } }); saveChromosome.setOnAction(new EventHandler<ActionEvent>() { @@ -339,6 +346,7 @@ public class SettingsPane extends AnchorPane { if (chrFile != null) { gui.getExperiment().saveChromosome(chrFile, 0); } + gui.flushConsole(); } }); @@ -393,6 +401,7 @@ public class SettingsPane extends AnchorPane { fs.disableFunction(index); } gui.updateFunctionSelector(); + revalidateParameters(); } }); nodeFunctions.getChildren().add(cb); @@ -407,7 +416,7 @@ 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) { @@ -415,6 +424,9 @@ public class SettingsPane extends AnchorPane { return true; } } + if (arityChanged()) { + return true; + } return false; } @@ -436,15 +448,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); } /** @@ -455,6 +471,7 @@ public class SettingsPane extends AnchorPane { for (GUIParameter<?> parameter : parameters) { parameter.applyValue(); } + updateArity(); } /** @@ -498,4 +515,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(); + } } |