aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/backend/parser/ParameterParser.java
blob: 473b632ee10818e4bd0013cb28b529cbffef1f48 (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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package jcgp.backend.parser;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Scanner;
import jcgp.backend.resources.ModifiableResources;

public class ParameterParser {
	
	private ModifiableResources resources;
	
	private ParameterParser(ModifiableResources resources) {
		this.resources = resources;
	}

	public static void parseParameters(File file, ModifiableResources resources) {
		ParameterParser pp = new ParameterParser(resources);
		
		FileReader fr;
		try {
			fr = new FileReader(file);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
			return;
		}
		
		Scanner in = new Scanner(fr);
		
		while (in.hasNextLine()) {
			pp.parseAndSet(in.nextLine().split("( |\t)+"));
		}
		
		in.close();
	}
	
	private void parseAndSet(String[] splitString) {
		switch (splitString[1]) {
		
		case "population_size":
			resources.setPopulationSize(Integer.parseInt(splitString[0]));
			break;
			
		case "num_generations":
			resources.setGenerations(Integer.parseInt(splitString[0]));
			break;
			
		case "num_runs_total":
			resources.setRuns(Integer.parseInt(splitString[0]));
			break;
			
		case "num_rows":
			resources.setRows(Integer.parseInt(splitString[0]));
			break;
			
		case "num_cols":
			resources.setColumns(Integer.parseInt(splitString[0]));
			break;

		case "levels_back":
			resources.setLevelsBack(Integer.parseInt(splitString[0]));
			break;
		
		case "report_interval":
			resources.setReportInterval(Integer.parseInt(splitString[0]));
			break;
		
		case "global_seed":
			resources.setSeed(Integer.parseInt(splitString[0]));
			break;

		default:
			break;
		}
	}
}