make_table.py 5.74 KB
Newer Older
Stefan Jaax's avatar
Stefan Jaax committed
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
import sys
import pandas as pd

benchmark_dir='.'
results_dir='results'

properties = [ 'termination', 'consensus' ]
prop_steps = [ '$|\mathcal{P}|$', '$|R|$' ]

max_params = 2

long_table = True
short_table = True
if len(sys.argv) >= 2:
    long_table = False
    short_table = False
    for arg in sys.argv[1:]:
        if arg == '-s':
            short_table = True
        elif arg == '-l':
            long_table = True
        else:
            print("unknown argument: %s" % arg, file=sys.stderr)
            sys.exit(-1)

# long table

if long_table:
    results_file='results.csv'

    results = pd.read_csv(benchmark_dir + '/' + results_dir + '/' + results_file)

    alignrow = "\\begin{longtable}{l"
    for i in range(max_params):
        alignrow += 'l'
    alignrow += 'rr'
    for prop in properties:
        alignrow += 'rr'
    alignrow += 'r}'
    print(alignrow)
    print("\\toprule")

    headerrow = "protocol & \\multicolumn{%d}{c}{params} & $|Q|$ & $|T|$" % max_params
    for prop, prop_step in zip(properties, prop_steps):
        headerrow +=  " & %s & %s" % (prop, prop_step)
    headerrow += " & total \\\\"
    print(headerrow)

    last_protocol = ''
    last_params = []
    for i in range(max_params):
        last_params.append('')

    for result in results.iterrows():
        row = result[1]
        row_string = ''

        protocol = row['protocol']
        filename = row['file']

        protocol_changed = False
        if protocol != last_protocol:
            protocol_changed = True
            print("\\midrule")
            row_string = "%s" % protocol
            last_protocol = protocol
            for i in range(max_params):
                last_params[i] = ''
        else:
            row_string = ""

        params = [ p for p in filename[len(protocol):][:-5].split('_') if len(p) >= 2 ]

        for i in range(len(params)):
            var = params[i][0]
            val = params[i][1:]
            param_string = "$%s = %s$" % (var, val)
            if last_params[i] != param_string:
                #if i == 0 and len(params) > 1 and not protocol_changed:
                #    print("\\cline{2-%d}" % (4 + max_params + 2*len(properties)))
                last_params[i] = param_string
                row_string += " & %s" % param_string
                for j in range(i+1, max_params):
                    last_params[j] = ''
            else:
                row_string += " &"
        for i in range(len(params), max_params):
            row_string += " &"

        n_places = row['places']
        n_transitions = row['transitions']
        row_string += ' & %d & %d' % (n_places, n_transitions)

        total_time = 0.0
        total_timeout = False

        for prop in properties:
            prop_result = row[prop + '_result']
            prop_time = row[prop + '_time'] / 10**9
            prop_refinements = row[prop + '_refinements']
            prop_string = ''
            if prop_result == 'positive':
                prop_string = "%.2f" % prop_time
            elif prop_result == 'dontknow':
                prop_string = "%.2f (?)" % prop_time
            elif prop_result == 'timeout':
                prop_string = 'timeout'
                total_timeout = True
            else:
                prop_string = 'error'
            try:
                refinement_string = str(int(prop_refinements))
            except ValueError:
                refinement_string ='-'
            row_string += " & %s & %s" % (prop_string, refinement_string)
            total_time += prop_time

        row_string += " & "
        if total_timeout:
            row_string += "timeout"
        else:
            row_string += "%.2f" % total_time
        row_string += " \\\\"

        print(row_string)

    print("\\bottomrule")
    print("\\end{longtable}")

# short table

if short_table:
    results_file='results-short.csv'

    results = pd.read_csv(benchmark_dir + '/' + results_dir + '/' + results_file)

    last_protocol = ''
    last_params = []
    for i in range(max_params):
        last_params.append('')

    for result in results.iterrows():
        row = result[1]
        row_string = ''

        protocol = row['protocol']
        filename = row['file']

        protocol_changed = False
        if protocol != last_protocol:
            protocol_changed = True
            if last_protocol != '':
                print("\\bottomrule")
                print("\\end{tabular}")
            last_protocol = protocol
            print("\\begin{tabular}{rrrr}")
            print("\\toprule")
            print("\multicolumn{3}{c}{%s} \\\\" % protocol)
            print("\\midrule")
            print("$m$ & $|Q|$ & $|T|$ & Time\,(s) \\\\")
            print("\\midrule")

        params = [ p for p in filename[len(protocol):][:-5].split('_') if len(p) >= 2 ]

        if len(params) > 0:
            val = params[0][1:]
            row_string += "%s " % val

        n_places = row['places']
        n_transitions = row['transitions']
        row_string += ' & %d & %d' % (n_places, n_transitions)

        total_time = 0.0
        total_timeout = False
        total_error = False

        for prop in properties:
            prop_result = row[prop + '_result']
            if prop_result == 'positive':
                prop_time = row[prop + '_time'] / 10**9
                total_time += prop_time
            elif prop_result == 'timeout':
                total_timeout = True
            else:
                total_error = True

        row_string += " & "
        if total_timeout:
            row_string += "timeout"
        elif total_error:
            row_string += "error"
        else:
            row_string += "%.1f" % total_time
        row_string += " \\\\"

        print(row_string)

    if last_protocol != '':
        print("\\bottomrule")
        print("\\end{tabular}")