-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain_no_render.py
More file actions
128 lines (108 loc) · 3.39 KB
/
Copy pathmain_no_render.py
File metadata and controls
128 lines (108 loc) · 3.39 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
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
116
117
118
119
120
121
122
123
124
125
126
127
128
import sys
import os
import yaml
import argparse
# adds the root of the git dir to the import path
# FIXME: Directory shenanigans
root_dir = os.getcwd()
sys.path.append(root_dir)
import lib.Map.Map as mmap
from lib.Simulation.Simulator import Simulator
import lib.Renderer.debug as debug
configFileName = "config.yml"
requiredConfigs = [
"OSMfile",
"jobsFile",
"businessFile",
"numberOfAgents",
"buildingConfigPath",
"threadNumber",
"infectedAgent",
"vaccinationPercentage",
"windowWidth",
"windowHeight",
"reportDir",
"reportInterval",
"nr_step_size",
"nr_day_to_simulate",
]
optionalConfig = [
"buildConnFile",
"pathfindFileName",
"lockdownMethod",
"seed",
]
def read_validate_config(file_path):
config = None
with open(file_path, "r") as f:
config = yaml.safe_load(f)
err = False
errMessage = "Missing required attributes in config file: "
for c in requiredConfigs:
if c not in config:
err = True
errMessage += c + " "
if err:
raise NameError(errMessage)
for c in optionalConfig:
if c not in config:
config[c] = None
return config
def parseArgs():
global configFileName
parser = argparse.ArgumentParser()
parser.add_argument("-c", "--config_file", help="sets the config file")
parser.add_argument("-s", "--seed", type=int, help="sets the seed")
parser.add_argument("--no_infectious_stop", action="store_true", help="Interromps the execution if there are no more susceptible agents")
args = parser.parse_args()
if args.config_file:
configFileName = args.config_file
no_infectious_stop = False
if args.no_infectious_stop:
no_infectious_stop = True
seed = None
if args.seed:
seed = args.seed
return configFileName, no_infectious_stop, seed
def main():
configFileName, no_infectious_stop, seed = parseArgs()
c = read_validate_config(configFileName)
stepSize = c["nr_step_size"] #5 minutes
dayToSimulate = c["nr_day_to_simulate"]
if seed is None:
if c["seed"] is not None:
seed = c["seed"]
else:
seed = 100
# Load the data
gridSize = (c["gridHeight"], c["gridWidth"])
osmMap = mmap.readFile(
OSMfilePath = c["OSMfile"],
buildConnFile = c["buildConnFile"],
grid = gridSize,
buildingCSV = c["buildingConfigPath"])
# Start Simulator
sim = Simulator(
osmMap = osmMap,
jobCSVPath = c["jobsFile"],
businessCVSPath = c["businessFile"],
pathfindFileName = c["pathfindFileName"],
agentNum = c["numberOfAgents"],
threadNumber = c["threadNumber"],
infectedAgent = c["infectedAgent"],
vaccinationPercentage = c["vaccinationPercentage"],
reportPath = c["reportDir"],
reportInterval = c["reportInterval"],
lockdownMethod=c["lockdownMethod"],
delivery_type=c["delivery_type"],
seed=seed)
for x in range(0, dayToSimulate*24*3600, stepSize):
sim.step(stepSize = stepSize)
_, seirStatus = sim.getAgentStatus()
if no_infectious_stop and seirStatus["Infectious"] + seirStatus["Exposed"] == 0:
break
sim.extract()
sim.extractVisitLog()
debug._on_show_orders(model=sim, fnameout=configFileName)
if __name__ == "__main__":
main()