-
Notifications
You must be signed in to change notification settings - Fork 0
/
GenerateExample.java
115 lines (83 loc) · 3.39 KB
/
GenerateExample.java
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import org.nlogo.headless.HeadlessWorkspace;
import static java.lang.System.out;
import static java.lang.System.err;
import static java.lang.String.format;
public class GenerateExample {
// number of steps
static int steps = 250;
// global parameters
public static void main(String[] argv) {
int world_size = Integer.parseInt(argv[0]);
int init_life = Integer.parseInt(argv[1]);
boolean rand = Boolean.parseBoolean(argv[2]);
boolean sync = Boolean.parseBoolean(argv[3]);
int deterministic_period = Integer.parseInt(argv[4]);
double rule_switch_prob = Double.parseDouble(argv[5]);
int second_threshold = Integer.parseInt(argv[6]);
HeadlessWorkspace world = HeadlessWorkspace.newInstance();
try {
world.open("life-rule-switching.nlogo");
//for (int st = second_threshold; st<=9; st++) {
// for (double p = 0.0; p<1.0; p+=0.1) {
runWorld(world, world_size, init_life, rand, sync,
deterministic_period, rule_switch_prob, second_threshold);
// }
//}
world.dispose();
} catch (Exception ex) {
ex.printStackTrace();
}
}
private static void runWorld(
HeadlessWorkspace world,
int world_size, int init_life, boolean rand, boolean sync,
int deterministic_period, double rule_switch_prob, int second_threshold) {
err.println("[INFO] restarting simulation!");
// name is build from the parsed values
String world_name = new String();
try {
// load the model
// model specific setup
world.command(format("set world-size %d", world_size));
out.println(format("set world-size %d", world_size));
world.command(format("set init-life %d", init_life));
out.println(format("set init-life %d", init_life));
world_name += format("_size%d", world_size);
world_name += format("_init%d", init_life);
if (sync) {
world.command("set synchronous true");
world_name += "_sync";
} else {
world.command("set synchronous false");
world_name += "_async";
}
if (rand) {
world_name += "_rand";
world_name += format("_p%3.2f", rule_switch_prob);
world.command("set deterministic false");
err.println("set deterministic false");
world.command(format("set rule-switch-prob %3.2f", rule_switch_prob));
err.println(format("set rule-switch-prob %3.2f", rule_switch_prob));
} else {
world.command("set deterministic true");
err.println("set deterministic true");
world.command(format("set deterministic-period %d", deterministic_period));
err.println(format("set deterministic-period %d", deterministic_period));
world_name += "_detr";
world_name += format("_dp%d", deterministic_period);
}
world_name += format("_st%d", second_threshold);
world.command(format("set second-threshold %d", second_threshold));
err.println(format("set second-threshold %d", second_threshold));
// setup the world
world.command("setup");
world.command(String.format("repeat %d [go]", steps));
world.command("export-world \"world" + world_name + ".csv\"");
err.println("[INFO] Saving: " + "world" + world_name + ".csv");
world.command("clear-all");
world.command("reset-ticks");
} catch (Exception ex) {
ex.printStackTrace();
}
}
}