aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/backend/parser/FunctionParser.java
blob: 64a095ca4d26c01494698d1107dfeb7a7c029359 (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
52
53
54
55
56
57
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);
		}
		
	}	
}