-
Notifications
You must be signed in to change notification settings - Fork 1
/
flexibility.py
62 lines (49 loc) · 1.78 KB
/
flexibility.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
import yaml
import subprocess
import pandas as pd
import time
# Load all routes from allRoutes.xlsx
df = pd.read_excel('allRoutes.xlsx')
df = df[df.incompatible == False]
# Modify the config file each time and run main.py with the new config
for i in range(40):
#############
# first run
#############
# Load the initial configuration
with open('config.yml', 'r') as f:
config = yaml.safe_load(f)
# Change the filename being saved
config['filename'] = f'flex_test {i}'
# Randomly sample 10 routes without repeats
print(df['routeNum'].sample(10).to_list())
config['routes'] = df['routeNum'].sample(10).to_list()
# Make the first run dynamic
config['runType'] = 'dynamic'
# Save the modified configuration
with open('config.yml', 'w') as f:
yaml.safe_dump(config, f)
# Call main.py with a timeout of 3 minutes
start_time = time.time()
proc = subprocess.Popen(['python3', 'main.py'], stdout=subprocess.PIPE)
try:
outs, errs = proc.communicate(timeout=180)
except subprocess.TimeoutExpired:
print(f"First run of main.py for iteration {i} timed out after 3 minutes")
continue
results = pd.read_csv('results.csv')
# only run the second run if the first was successful
if not results[results['case_name'] == f'flex_test {i}'].empty:
#############
# second run
#############
# Load the initial configuration
with open('config.yml', 'r') as f:
config = yaml.safe_load(f)
# Make the second run static
config['runType'] = 'static'
# Save the modified configuration
with open('config.yml', 'w') as f:
yaml.safe_dump(config, f)
# Call main.py
subprocess.call(['python3', 'main.py'])