aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/backend/parser/FunctionParser.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/jcgp/backend/parser/FunctionParser.java')
-rw-r--r--src/jcgp/backend/parser/FunctionParser.java58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/jcgp/backend/parser/FunctionParser.java b/src/jcgp/backend/parser/FunctionParser.java
new file mode 100644
index 0000000..64a095c
--- /dev/null
+++ b/src/jcgp/backend/parser/FunctionParser.java
@@ -0,0 +1,58 @@
+package jcgp.backend.parser;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.util.Scanner;
+
+import jcgp.backend.function.FunctionSet;
+import jcgp.backend.modules.problem.Problem;
+
+public class FunctionParser {
+
+private FunctionSet functionSet;
+
+ private FunctionParser(Problem problem) {
+ this.functionSet = problem.getFunctionSet();
+ }
+
+ public static void parseFunctions(File file, Problem problem) {
+ FunctionParser pp = new FunctionParser(problem);
+
+ FileReader fr;
+ try {
+ fr = new FileReader(file);
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ return;
+ }
+
+ Scanner in = new Scanner(fr);
+
+ while (in.hasNextLine()) {
+ String line = in.nextLine();
+ if (line.substring(line.length() - 1).matches("[0-9]")) {
+ pp.parseAndSet(line.split("[^0-9]+"));
+ }
+ }
+
+ in.close();
+ }
+
+ private void parseAndSet(String[] splitString) {
+// System.out.println("new line");
+// for (int i= 0; i < splitString.length; i++) {
+// System.out.println(i + ": " + splitString[i]);
+// }
+ int functionIndex = Integer.parseInt(splitString[splitString.length - 1]);
+ System.out.println("index: " + functionIndex);
+ if (Integer.parseInt(splitString[0]) != 0) {
+ System.out.println("enabling: " + functionSet.getFunction(functionIndex).getName());
+ functionSet.enableFunction(functionIndex);
+ } else {
+ System.out.println("disabling: " + functionSet.getFunction(functionIndex).getName());
+ functionSet.disableFunction(functionIndex);
+ }
+
+ }
+}