-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
65 lines (51 loc) · 2.12 KB
/
main.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
import argparse
from pathlib import Path
import time
import yaml
from logger import Logger
from network import Network
import pandas as pd
from runner import Runner
CONFIG_PATH = Path("./config/")
def load_config(filename):
"""Load yaml configuration file.
Args:
filename (str): config file name (including extension).
Returns:
dict: configuration dictionary.
"""
with open(Path(CONFIG_PATH / filename)) as f:
config = yaml.safe_load(f)
return config
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Transport network and School Choice")
parser.add_argument('--config', default='default.yaml', type=str)
parser.add_argument('--no_log', action='store_true', default=False)
args = parser.parse_args()
config = load_config(args.config)
sim_start = time.time()
if not args.no_log:
logger = Logger(config)
print(f'Running {args.config} configuration - results saved in {logger.results_path}')
else:
logger = None
print(f'Running {args.config} configuration - no results saved')
# TODO: probably want to move calc_tt_mx flag to config file (maybe want to set to False for large networks.)
network = Network(config['network_file'], calc_tt_mx=True)
population = pd.read_csv(config['population_file'])
facilities = pd.read_csv(config['facilities_file'])
runner = Runner(network, population, facilities, logger)
runner.run_simulation(
config['simulation_rounds'],
config['allocation_rounds'],
config['intervention_rounds'],
config['intervention_budget'],
config['preferences_model'],
config['allocation_model'],
config['intervention_model'],
preference_model_params=config.get('preference_model_params', None),
update_preference_params=config['update_preference_params'])
sim_time = time.time() - sim_start
print(f"All is said and done in {sim_time} seconds, which is {sim_time / 60} minutes.")
if logger:
logger.append_to_output_file(f"sim_time: {sim_time}")