-
Notifications
You must be signed in to change notification settings - Fork 30
/
record.py
141 lines (122 loc) · 3.58 KB
/
record.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
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
129
130
131
132
133
134
135
136
137
138
139
140
141
import re
import datetime
import subprocess
optimal_solvers = [
'CBS',
'ICBS',
]
suboptimal_solvers = [
'PIBT',
'winPIBT',
'PushAndSwap',
'HCA',
'WHCA',
'RevisitPP',
'ECBS',
'PIBT_COMPLETE',
]
suboptimal_solvers_option = [
'', # PIBT
'', # winPIBT
'-c', # PushAndSwap
'', # HCA
'', # WHCA
'', # RevisitPP
'', # ECBS
'', # PIBT_COMPLETE
]
anytime_solvers = [
'IR',
'IR_SINGLE_PATHS',
'IR_FIX_AT_GOALS',
'IR_FOCUS_GOALS',
'IR_MDD',
'IR_BOTTLENECK',
'IR_HYBRID',
]
anytime_solvers_option = '-t 500 -n 10000'
output_file = './result.txt'
cmd_app = '../build/app'
cmd_output = '-o ' + output_file
optimal_ins = './benchrmark/optimal_random-32-32-20_30agents.txt'
suboptimal_ins = './benchrmark/suboptimal_den520d_300agents.txt'
anytime_ins = './benchrmark/anytime_arena_300agents.txt'
def read_data(filename):
r_solved = re.compile(r"solved=(\d)")
r_makespan = re.compile(r"makespan=(\d+)")
r_soc = re.compile(r"soc=(\d+)")
r_comp_time = re.compile(r"comp_time=(\d+)")
result = {}
with open(output_file, 'r') as f:
for row in f:
m_solved = re.match(r_solved, row)
if m_solved:
result['solved'] = int(m_solved.group(1))
continue
m_comp_time = re.match(r_comp_time, row)
if m_comp_time:
result['comp_time'] = int(m_comp_time.group(1))
continue
m_soc = re.match(r_soc, row)
if m_soc:
result['sum-of-costs'] = int(m_soc.group(1))
continue
m_makespan = re.match(r_makespan, row)
if m_makespan:
result['makespan'] = int(m_makespan.group(1))
continue
return result
def run(ins, solver, option=''):
cmd_ins = '-i ' + ins
cmd_solver = '-s ' + solver + ' ' + option
cmd = '{} {} {} {}'.format(cmd_app, cmd_output, cmd_ins, cmd_solver)
print(cmd)
subprocess.run(cmd, shell=True, encoding='utf-8', stdout=subprocess.PIPE)
return read_data(output_file)
def get_run_result(ins, solvers, options=[]):
table_header = """|solver | solved | comp_time(ms) | sum-of-costs | makespan |
| ---: | ---: | ---: | ---: | ---: |
"""
result_str = table_header
for i, solver in enumerate(solvers):
option = options[i] if i < len(options) else ''
res = run(ins, solver, option)
result_str += "| {} | {} | {} | {} | {} |\n".format(
solver, res['solved'], res['comp_time'], res['sum-of-costs'], res['makespan'])
return result_str
if __name__ == '__main__':
date_str = datetime.datetime.now().strftime('%Y-%m-%d-%H-%M-%S')
cp = subprocess.run('git --no-pager log -n 1 --no-decorate',
shell=True, encoding='utf-8', stdout=subprocess.PIPE)
git_log = cp.stdout
suboptimal_res = get_run_result(suboptimal_ins, suboptimal_solvers, suboptimal_solvers_option)
optimal_res = get_run_result(optimal_ins, optimal_solvers)
anytime_res = get_run_result(anytime_ins, anytime_solvers,
[anytime_solvers_option]*len(anytime_solvers))
md_str = """auto record by github actions
===
date: {}
commit
```
{}
```
## sub-optimal solvers
benchmark: {}
{}
## optimal solvers
benchmark: {}
{}
## anytime solvers
benchmark: {}
{}""".format(
date_str,
git_log,
suboptimal_ins,
suboptimal_res,
optimal_ins,
optimal_res,
anytime_ins,
anytime_res)
record_file = './readme.md'
with open(record_file, 'w') as f:
f.write(md_str)