aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/backend/parser
diff options
context:
space:
mode:
Diffstat (limited to 'src/jcgp/backend/parser')
-rw-r--r--src/jcgp/backend/parser/ChromosomeParser.java2
-rw-r--r--src/jcgp/backend/parser/FunctionParser.java7
-rw-r--r--src/jcgp/backend/parser/ParameterParser.java1
-rw-r--r--src/jcgp/backend/parser/TestCaseParser.java79
4 files changed, 80 insertions, 9 deletions
diff --git a/src/jcgp/backend/parser/ChromosomeParser.java b/src/jcgp/backend/parser/ChromosomeParser.java
index 74f638c..d5af1bd 100644
--- a/src/jcgp/backend/parser/ChromosomeParser.java
+++ b/src/jcgp/backend/parser/ChromosomeParser.java
@@ -17,7 +17,7 @@ import jcgp.backend.resources.Resources;
* @author Eduardo Pedroni
*
*/
-public class ChromosomeParser {
+public abstract class ChromosomeParser {
/**
* Use this method to parse .chr files into a given chromosome.
diff --git a/src/jcgp/backend/parser/FunctionParser.java b/src/jcgp/backend/parser/FunctionParser.java
index 64a095c..ab94899 100644
--- a/src/jcgp/backend/parser/FunctionParser.java
+++ b/src/jcgp/backend/parser/FunctionParser.java
@@ -40,17 +40,10 @@ private FunctionSet functionSet;
}
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);
}
diff --git a/src/jcgp/backend/parser/ParameterParser.java b/src/jcgp/backend/parser/ParameterParser.java
index 473b632..f96ebf9 100644
--- a/src/jcgp/backend/parser/ParameterParser.java
+++ b/src/jcgp/backend/parser/ParameterParser.java
@@ -4,6 +4,7 @@ import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Scanner;
+
import jcgp.backend.resources.ModifiableResources;
public class ParameterParser {
diff --git a/src/jcgp/backend/parser/TestCaseParser.java b/src/jcgp/backend/parser/TestCaseParser.java
index c997177..d47d663 100644
--- a/src/jcgp/backend/parser/TestCaseParser.java
+++ b/src/jcgp/backend/parser/TestCaseParser.java
@@ -1,13 +1,90 @@
package jcgp.backend.parser;
import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.util.Scanner;
import jcgp.backend.modules.problem.TestCaseProblem;
+import jcgp.backend.resources.ModifiableResources;
public class TestCaseParser {
- public static void parse(File file, TestCaseProblem<?> problem) {
+ private TestCaseProblem<?> problem;
+
+ public TestCaseParser(TestCaseProblem<?> problem) {
+ this.problem = problem;
+ }
+
+ public void parse(File file) {
+ FileReader fr;
+ try {
+ fr = new FileReader(file);
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ return;
+ }
+
+ Scanner in = new Scanner(fr);
+ boolean readingTestCases = false;
+ int inputs = 0, outputs = 0;
+
+ problem.clearTestCases();
+
+ while (in.hasNextLine()) {
+ String nextLine = in.nextLine();
+
+ if (nextLine.startsWith(".i")) {
+ String[] split = nextLine.split(" +");
+ inputs = Integer.parseInt(split[1]);
+ } else if (nextLine.startsWith(".o")) {
+ String[] split = nextLine.split(" +");
+ outputs = Integer.parseInt(split[1]);
+ } else if (nextLine.startsWith(".p") || nextLine.startsWith(".t")) {
+ readingTestCases = true;
+ } else if (nextLine.startsWith(".e")) {
+ readingTestCases = false;
+ // set test cases? not safe probably
+ } else if (readingTestCases) {
+ String[] split = nextLine.split("( |\t)+");
+ String[] inputCases = new String[inputs];
+ String[] outputCases = new String[outputs];
+ for (int i = 0; i < inputs; i++) {
+ inputCases[i] = split[i];
+ }
+ for (int o = 0; o < outputs; o++) {
+ outputCases[o] = split[o + inputs];
+ }
+
+ problem.addTestCase(inputCases, outputCases);
+ }
+ }
+ in.close();
}
+ public static void parseParameters(File file, ModifiableResources resources) {
+
+ FileReader fr;
+ try {
+ fr = new FileReader(file);
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ return;
+ }
+
+ Scanner in = new Scanner(fr);
+
+ while (in.hasNextLine()) {
+ String nextLine = in.nextLine();
+ if (nextLine.startsWith(".i")) {
+ String[] split = nextLine.split(" +");
+ resources.setInputs(Integer.parseInt(split[1]));
+ } else if (nextLine.startsWith(".o")) {
+ String[] split = nextLine.split(" +");
+ resources.setOutputs(Integer.parseInt(split[1]));
+ }
+ }
+ in.close();
+ }
}