-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemo2.py
49 lines (41 loc) · 1.22 KB
/
demo2.py
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
# demo_2.py
import mosaik
import mosaik.util
# Sim config
# this_folder = __file__.rsplit("/", 1)[0]
SIM_CONFIG = {
"ExampleSim": {
"cmd": "cargo run --example example_sim -- -a=%(addr)s",
},
"ExampleCtrl": {
"connect": "127.0.0.1:5678",
},
"Collector": {
"cmd": "cargo run --example collector -- -a=%(addr)s",
},
}
END = 10 # 10 seconds
# Create World
world = mosaik.World(SIM_CONFIG)
# End: Create World
# Start simulators
with world.group():
examplesim = world.start("ExampleSim", eid_prefix="Model_")
examplectrl = world.start("ExampleCtrl")
collector = world.start("Collector")
# End: Start simulators
# Instantiate models
models = [examplesim.ExampleModel(init_val=i) for i in range(-2, 3, 2)]
agents = examplectrl.Agent.create(len(models))
monitor = collector.Monitor()
# End: Instantiate models
# Connect entities
for model, agent in zip(models, agents):
world.connect(model, agent, ("val", "val_in"))
world.connect(agent, model, "delta", weak=True)
# End: Connect entities
# Connect to monitor
mosaik.util.connect_many_to_one(world, models, monitor, "val", "delta")
mosaik.util.connect_many_to_one(world, agents, monitor, "delta")
# Run simulation
world.run(until=END)