blob: ab94899606e82d028b4fefc450ecc1eaf9a1f763 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
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) {
int functionIndex = Integer.parseInt(splitString[splitString.length - 1]);
if (Integer.parseInt(splitString[0]) != 0) {
functionSet.enableFunction(functionIndex);
} else {
functionSet.disableFunction(functionIndex);
}
}
}
|