Repository navigation
Expand file tree
/
Copy pathexample_netlogo.py
More file actions
60 lines (46 loc) · 1.52 KB
/
Copy pathexample_netlogo.py
File metadata and controls
60 lines (46 loc) · 1.52 KB
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
"""Illustration of using netlogo models with the workbench.
Note that this example uses the NetLogo 6 version of the predator prey model that
comes with NetLogo. This works fine also with NetLogo 7.
If you are using NetLogo 5, replace the model file with the one that comes with NetLogo.
"""
import numpy as np
from ema_workbench import (
MultiprocessingEvaluator,
RealParameter,
ScalarOutcome,
TimeSeriesOutcome,
ema_logging,
)
from ema_workbench.connectors.netlogo import NetLogoModel
# Created on 20 mrt. 2013
#
# .. codeauthor:: jhkwakkel
if __name__ == "__main__":
# turn on logging
ema_logging.log_to_stderr(ema_logging.INFO)
model = NetLogoModel(
"predprey",
wd="./models/predatorPreyNetlogo",
model_file="Wolf Sheep Predation.nlogo",
)
model.run_length = 100
model.replications = 10
model.uncertainties = [
RealParameter("grass-regrowth-time", 1, 99),
RealParameter("initial-number-sheep", 50, 100),
RealParameter("initial-number-wolves", 50, 100),
RealParameter("sheep-reproduce", 5, 10),
RealParameter("wolf-reproduce", 5, 10),
]
model.outcomes = [
ScalarOutcome("sheep", variable_name="count sheep", function=np.mean),
TimeSeriesOutcome("wolves"),
TimeSeriesOutcome("grass"),
]
# perform experiments
n = 10
with MultiprocessingEvaluator(
model, n_processes=-1, maxtasksperchild=4
) as evaluator:
results = evaluator.perform_experiments(n)
print()