-
Notifications
You must be signed in to change notification settings - Fork 3
/
RunSim.py
75 lines (59 loc) · 1.87 KB
/
RunSim.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
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
# built-in
# third-party
# local
import Floorplan
import DotBot
import Orchestrator
import Wireless
import SimEngine
import SimUI
#============================ defines =========================================
SIMSETTINGS = [
{
'numDotBots': 50,
'floorplanDrawing': # 1m per character
'''
............###...
..................
....##.....##.....
....##............
..............##..
..............##..
''',
'initialPosition': (5,1),
}
]
#============================ helpers =========================================
def oneSim(simSetting):
'''
Run a single simulation.
'''
# create the wireless communication
wireless = Wireless.Wireless()
# create the SimEngine
simEngine = SimEngine.SimEngine()
# create the floorplan
floorplan = Floorplan.Floorplan(simSetting['floorplanDrawing'])
# create the DotBots
dotBots = []
for dotBotId in range(simSetting['numDotBots']):
dotBots += [DotBot.DotBot(dotBotId,floorplan)]
# drop the DotBots on the floorplan at their initial position
(x,y) = simSetting['initialPosition']
for dotBot in dotBots:
dotBot.setInitialPosition(x,y)
# create the orchestrator
orchestrator = Orchestrator.Orchestrator([simSetting['initialPosition']]*len(dotBots),floorplan)
# indicate the elements to the singletons
wireless.indicateElements(dotBots,orchestrator)
# start the UI (call last)
simUI = SimUI.SimUI(floorplan,dotBots,orchestrator)
# schedule the first event
simEngine.schedule(0,orchestrator.startExploration)
input('Press Enter to close simulation.')
#============================ main ============================================
def main():
for simSetting in SIMSETTINGS:
oneSim(simSetting)
if __name__=='__main__':
main()