-
Notifications
You must be signed in to change notification settings - Fork 1
/
ants_pse.oms
104 lines (85 loc) · 3 KB
/
ants_pse.oms
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
val seed = Val[Int]
val population = Val[Double]
val diffusion = Val[Double]
val evaporation = Val[Double]
val maxsteps = Val[Int]
// Define the output variables
val food1 = Val[Double]
val food2 = Val[Double]
val food3 = Val[Double]
// Define the average output variables
val medFood1 = Val[Double]
val medFood2 = Val[Double]
val medFood3 = Val[Double]
// Define the NetlogoTask
val cmds = Seq("random-seed ${seed}", "run-to-grid")
val ants =
NetLogo5Task(workDirectory / "../ants.nlogo", cmds) set (
name := "ants",
// Map the OpenMOLE variables to NetLogo variables
netLogoInputs += (population, "gpopulation"),
netLogoInputs += (diffusion, "gdiffusion-rate"),
netLogoInputs += (evaporation, "gevaporation-rate"),
netLogoInputs += (maxsteps, "gmax-steps"),
netLogoOutputs += ("final-ticks-food1", food1),
netLogoOutputs += ("final-ticks-food2", food2),
netLogoOutputs += ("final-ticks-food3", food3),
// The seed is used to control the initialisation of the random number generator of NetLogo
inputs += seed,
// Define default values for inputs of the model
population := 125.0,
maxsteps := 2000
)
val medianSlot = Slot(Capsule(
ScalaTask("""
val medFood1 = food1.median
val medFood2 = food2.median
val medFood3 = food3.median
""") set (
name := "median",
inputs += (food1.toArray,food2.toArray, food3.toArray),
outputs += (medFood1, medFood2, medFood3)
)
))
val replicateCapsule = Capsule(
ExplorationTask(seed in (UniformDistribution[Int]() take 5)) set (
name := "Replicate ants",
inputs += (diffusion, evaporation),
outputs += (diffusion, evaporation)
)
)
val env = LocalEnvironment(50)
//val env = SSHEnvironment("cherel","zebulon.iscpif.fr", 20)
//val env = EGIEnvironment("vo.complex-systems.eu")
val replicateModel = (replicateCapsule -< (ants by 1 on env hook ToStringHook()) >- medianSlot)
val evolution =
BehaviourSearch (
termination = 1000000,
inputs =
Seq(
diffusion -> (0.0, 99.0),
evaporation -> (0.0, 99.0)),
observables =
Seq(
medFood1,
medFood3),
gridSize = Seq(50, 50),
reevaluate = 0.01
)
// Define a builder to use NSGA2 generational EA algorithm.
// replicateModel is the fitness function to optimise.
// lambda is the size of the offspring (and the parallelism level).
//val (puzzle, ga) =
// GenerationalGA(evolution)(
// replicateModel,
// lambda = 10
// )
// Define the island model with 2,000 concurrent islands. Each island gets 50 individuals sampled from the global
// population. The algorithm stops after 200,000 islands evaluations.
val (puzzle, ga) = SteadyGA(evolution)(replicateModel, 50)
// Define a hook to save the Pareto frontier
val savePopulationHook = SavePopulationHook(ga, workDirectory / "results")
// Define another hook to display the generation in the console
val display = DisplayHook("Generation ${" + ga.generation.name + "}")
// Plug everything together to create the workflow
(puzzle hook savePopulationHook hook display)