blob: ae72126d3a92fa006fff46b409b1d4aed087484a (
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
77
|
package jcgp.backend.parsers;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Scanner;
import jcgp.backend.resources.ModifiableResources;
public abstract class ParameterParser {
public static void parseParameters(File file, ModifiableResources resources) {
FileReader fr;
try {
fr = new FileReader(file);
} catch (FileNotFoundException e) {
resources.println("[Parser] Error: could not find " + file.getAbsolutePath() + ".");
return;
}
Scanner in = new Scanner(fr);
resources.println("[Parser] Parsing file: " + file.getAbsolutePath() + "...");
while (in.hasNextLine()) {
String[] splitString = in.nextLine().split("( |\t)+");
switch (splitString[1]) {
case "population_size":
resources.setPopulationSize(Integer.parseInt(splitString[0]));
resources.println("[Parser] Population size is now " + resources.populationSize() + ".");
break;
case "num_generations":
resources.setGenerations(Integer.parseInt(splitString[0]));
resources.println("[Parser] Total generations is now " + resources.generations() + ".");
break;
case "num_runs_total":
resources.setRuns(Integer.parseInt(splitString[0]));
resources.println("[Parser] Total runs is now " + resources.runs() + ".");
break;
case "num_rows":
resources.setRows(Integer.parseInt(splitString[0]));
resources.println("[Parser] Row number is now " + resources.rows() + ".");
break;
case "num_cols":
resources.setColumns(Integer.parseInt(splitString[0]));
resources.println("[Parser] Column number is now " + resources.columns() + ".");
break;
case "levels_back":
resources.setLevelsBack(Integer.parseInt(splitString[0]));
resources.println("[Parser] Levels back is now " + resources.levelsBack() + ".");
break;
case "report_interval":
resources.setReportInterval(Integer.parseInt(splitString[0]));
resources.println("[Parser] Report interval is now " + resources.levelsBack() + ".");
break;
case "global_seed":
resources.setSeed(Integer.parseInt(splitString[0]));
resources.println("[Parser] Seed is now " + resources.seed() + ".");
break;
default:
break;
}
}
in.close();
resources.println("[Parser] Finished parsing parameters.");
}
}
|