-
Notifications
You must be signed in to change notification settings - Fork 8
/
summarize.py
83 lines (66 loc) · 2.13 KB
/
summarize.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
#
# This python scripts creates a text of HTML summary of the performance results in a
# directory.
#
# TODO: add command-line parser that can accept an option to specify the format.
#
import os.path
import sys
import glob
import pandas
import tabulate
import csv
problems = set()
sizes = set()
data = {}
for fname in glob.glob(os.path.join(".", sys.argv[1],"*.csv")):
with open(fname) as csvfile:
reader = csv.reader(csvfile)
first=True
for row in reader:
if first:
first=False
problems.add(row[1])
problem=row[1]
else:
size = int(row[0])
sizes.add(size)
data[problem, size] = round(float(row[1]),2) if (row[2] == "ok") else row[2]
results = {'Modeling': []}
for size in sorted(sizes):
results[str(size)] = []
for problem in sorted(problems):
results['Modeling'].append(problem)
for size in sizes:
results[str(size)].append( data.get((problem,size), "missing") )
print("-"*70)
print("Data Summary: "+sys.argv[1])
print("-"*70)
print("")
print("Runtime Performance (seconds)")
df = pandas.DataFrame(results)
print(tabulate.tabulate(df, headers='keys', tablefmt='psql', showindex="never"))
if "gurobi" in problems:
for size in sizes:
if ("gurobi", size) not in data:
print("Cannot normalize with Gurobi: missing data")
sys.exit(0)
try:
gval = float(data["gurobi",size])
except ValueError:
print("Cannot normalize with Gurobi: non-numeric value")
sys.exit(0)
size_str = str(size)
i=0
for problem in sorted(problems):
try:
pval = float(results[size_str][i])
results[size_str][i] = round(pval/gval,2)
except ValueError:
# We just skip data that isn't numeric
pass
i += 1
print("")
print("Normalized Performance (relative to Gurobi)")
df = pandas.DataFrame(results)
print(tabulate.tabulate(df, headers='keys', tablefmt='psql', showindex="never"))