-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_for_benchmark.py
More file actions
208 lines (150 loc) · 8.23 KB
/
Copy pathrun_for_benchmark.py
File metadata and controls
208 lines (150 loc) · 8.23 KB
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
202
203
204
205
206
207
208
import sys
import dd.cudd as _bdd
import regular.gpg2arena as reg_gpg_loader
import regular.generalizedRecursive as reg_gpg_recursive
import bdd.gpg2bdd as bdd_gpg_loader
import bdd.generalizedRecursive as bdd_gpg_recursive
from bdd.dpa2bdd import get_product_automaton
from bdd.dpa2gpg import symb_dpa2gpg
from bdd.bdd_util import decomp_data_file
# Increase the recursion limit to avoid error when we read a long label with explicit2symbolic_path
sys.setrecursionlimit(50000)
def get_gpg_sizes_and_number_of_functions(gpg_path):
manager = _bdd.BDD()
arena, _ = bdd_gpg_loader.gpg2bdd(gpg_path, manager)
return len(manager), arena.nbr_vertices, arena.nbr_functions
def solve_gpg_regular(gpg_path):
"""
Load and solve the generalized parity game whose path is provided in parameter using the regular implementation of
the recursive algorithm.
"""
player0_won = "TIMEOUT"
winning_0, winning_1 = None, None
arena = reg_gpg_loader.gpg2arena(gpg_path)
winning_0, winning_1 = reg_gpg_recursive.generalized_recursive(arena)
player0_won = 0 in winning_0
return player0_won, winning_0, winning_1
def solve_gpg_regular_partial(gpg_path):
"""
Load and solve the generalized parity game whose path is provided in parameter using the regular implementation of
the combination of the recursive algorithm and a partial solver. This implementation performs a single call to the
partial solver before running the recursive algorithm.
"""
player0_won = "TIMEOUT"
winning_0, winning_1 = None, None
arena = reg_gpg_loader.gpg2arena(gpg_path)
winning_0, winning_1 = reg_gpg_recursive.generalized_recursive_with_buchi(arena)
player0_won = 0 in winning_0
return player0_won, winning_0, winning_1
def solve_gpg_regular_partial_multiple_calls(gpg_path):
"""
Load and solve the generalized parity game whose path is provided in parameter using the regular implementation of
the combination of the recursive algorithm and a partial solver. This implementation performs a call to the partial
solver in each recursive call.
"""
player0_won = "TIMEOUT"
winning_0, winning_1 = None, None
arena = reg_gpg_loader.gpg2arena(gpg_path)
winning_0, winning_1 = reg_gpg_recursive.generalized_recursive_with_buchi_multiple_calls(arena)
player0_won = 0 in winning_0
return player0_won, winning_0, winning_1
def solve_gpg_bdd(gpg_path):
"""
Load and solve the generalized parity game whose path is provided in parameter using the bdd implementation of the
recursive algorithm.
"""
player0_won = "TIMEOUT"
winning_0, winning_1 = None, None
manager = _bdd.BDD()
arena, all_vertices = bdd_gpg_loader.gpg2bdd(gpg_path, manager)
winning_0, winning_1 = bdd_gpg_recursive.generalized_recursive(arena, manager)
vertex_0_dict_rep = next(manager.pick_iter(all_vertices[0]))
player0_won = manager.let(vertex_0_dict_rep, winning_0) == manager.true
return player0_won, winning_0, winning_1
def solve_gpg_bdd_partial(gpg_path):
"""
Load and solve the generalized parity game whose path is provided in parameter using the bdd implementation of the
combination of the recursive algorithm and a partial solver. This implementation performs a single call to the
partial solver before running the recursive algorithm.
"""
manager = _bdd.BDD()
arena, all_vertices = bdd_gpg_loader.gpg2bdd(gpg_path, manager)
winning_0, winning_1 = bdd_gpg_recursive.generalized_recursive_with_psolver(arena, manager)
vertex_0_dict_rep = next(manager.pick_iter(all_vertices[0]))
player0_won = manager.let(vertex_0_dict_rep, winning_0) == manager.true
return player0_won, winning_0, winning_1
def solve_gpg_bdd_partial_multiple_calls(gpg_path):
"""
Load and solve the generalized parity game whose path is provided in parameter using the bdd implementation of the
combination of the recursive algorithm and a partial solver. This implementation performs a call to the partial
sover in each recursive call.
"""
manager = _bdd.BDD()
arena, all_vertices = bdd_gpg_loader.gpg2bdd(gpg_path, manager)
winning_0, winning_1 = bdd_gpg_recursive.generalized_recursive_with_psolver_multiple_calls(arena, manager)
vertex_0_dict_rep = next(manager.pick_iter(all_vertices[0]))
player0_won = manager.let(vertex_0_dict_rep, winning_0) == manager.true
return player0_won, winning_0, winning_1
def construct_full_bdd_arena(data_path, dynamic_reordering=True, arbitrary_reordering=True):
input_signals, output_signals, automata_paths = decomp_data_file(data_path)
manager = _bdd.BDD()
manager.declare(*input_signals, *output_signals)
manager.configure(reordering=dynamic_reordering)
product = get_product_automaton(automata_paths, manager, arbitrary_reordering=arbitrary_reordering,
aps=input_signals + output_signals)
arena, init = symb_dpa2gpg(product, input_signals, output_signals, manager)
return manager, arena, init
def get_gpg_full_bdd_sizes(data_path, dynamic_reordering=True, arbitrary_reordering=True):
manager, arena, _ = construct_full_bdd_arena(data_path, dynamic_reordering, arbitrary_reordering)
return len(manager), len(list(manager.pick_iter(arena.player0_vertices | arena.player1_vertices))), arena.nbr_functions
def solve_gpg_full_bdd(data_path, dynamic_reordering=True, arbitrary_reordering=True):
manager, arena, init = construct_full_bdd_arena(data_path, dynamic_reordering, arbitrary_reordering)
winning_0, winning_1 = bdd_gpg_recursive.generalized_recursive(arena, manager)
vertex_0_dict_rep = next(manager.pick_iter(init))
player0_won = manager.let(vertex_0_dict_rep, winning_0) == manager.true
return player0_won, winning_0, winning_1
def solve_gpg_full_bdd_partial(data_path, dynamic_reordering=True, arbitrary_reordering=True):
manager, arena, init = construct_full_bdd_arena(data_path, dynamic_reordering, arbitrary_reordering)
winning_0, winning_1 = bdd_gpg_recursive.generalized_recursive_with_psolver(arena, manager)
vertex_0_dict_rep = next(manager.pick_iter(init))
player0_won = manager.let(vertex_0_dict_rep, winning_0) == manager.true
return player0_won, winning_0, winning_1
def solve_gpg_full_bdd_partial_multiple_calls(data_path, dynamic_reordering=True, arbitrary_reordering=True):
manager, arena, init = construct_full_bdd_arena(data_path, dynamic_reordering, arbitrary_reordering)
winning_0, winning_1 = bdd_gpg_recursive.generalized_recursive_with_psolver_multiple_calls(arena, manager)
vertex_0_dict_rep = next(manager.pick_iter(init))
player0_won = manager.let(vertex_0_dict_rep, winning_0) == manager.true
return player0_won, winning_0, winning_1
if __name__ == "__main__":
mode = sys.argv[1]
path = sys.argv[2]
fbdd_dynamic_reordering = len(sys.argv) > 3 and sys.argv[3] == "True"
fbdd_arbitrary_reordering = len(sys.argv) > 4 and sys.argv[4] == "True"
if mode == "gpgSizeFunc":
bdd_size, game_size, n_func = get_gpg_sizes_and_number_of_functions(path)
with open("/tmp/out", "w") as f:
f.write(str(bdd_size) + "\n" + str(game_size) + "\n" + str(n_func) + "\n")
elif mode == "fbddSizes":
bdd_size, game_size, n_func = get_gpg_full_bdd_sizes(path, fbdd_dynamic_reordering, fbdd_arbitrary_reordering)
with open("/tmp/out", "w") as f:
f.write(str(bdd_size) + "\n" + str(game_size) + "\n" + str(n_func) + "\n")
elif mode == "reg":
solve_gpg_regular(path)
elif mode == "regPa":
solve_gpg_regular_partial(path)
elif mode == "regPaMu":
solve_gpg_regular_partial_multiple_calls(path)
elif mode == "bdd":
solve_gpg_bdd(path)
elif mode == "bddPa":
solve_gpg_bdd_partial(path)
elif mode == "bddPaMu":
solve_gpg_bdd_partial_multiple_calls(path)
elif mode == "fbdd":
solve_gpg_full_bdd(path, fbdd_dynamic_reordering, fbdd_arbitrary_reordering)
elif mode == "fbddPa":
solve_gpg_full_bdd_partial(path, fbdd_dynamic_reordering, fbdd_arbitrary_reordering)
elif mode == "fbddPaMu":
solve_gpg_full_bdd_partial_multiple_calls(path, fbdd_dynamic_reordering, fbdd_arbitrary_reordering)
else:
raise Exception("Invalid mode " + mode)