-
Notifications
You must be signed in to change notification settings - Fork 1
/
benchmarks_statistics.py
252 lines (160 loc) · 9.56 KB
/
benchmarks_statistics.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
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
import time
from collections import deque, defaultdict
from verification_algorithms import smaller_than, generate_smaller_payoffs, counter_example_exists, \
get_payoff_of_accepting_run, counter_example_dominated, add_payoff_to_antichain
def antichain_optimization_algorithm_statistics(automaton, nbr_objectives, colors_map, realizable):
"""
The algorithm is as implemented in verification_algorithms, with new instructions to compute and return statistics.
Compute and return the following statistics on the algorithm: set of PO payoffs, number of calls to the realizable
function and their running time, number of calls to the realizable function when losing for Player 0 and their
running time.
:param automaton: the automaton.
:param nbr_objectives: the number t of objectives of Player 1.
:param colors_map: maps each parity objective to the set of SPOT acceptance sets used to represent its priorities.
:param realizable: function which decides if a (extended) payoff is realizable.
:return: whether the PRV problem is satisfied, the approximation of the set of PO payoffs, a pair [number of calls,
list of running time] for the realizable function, and a similar pair for the realizable function when losing for
Player 0.
"""
maximal_payoff = tuple([1] * nbr_objectives)
pareto_optimal_payoffs = []
queue = deque()
queue.append(maximal_payoff)
visited = defaultdict(int)
counter_realizable = 0
counter_realizable_losing = 0
realizable_times = []
realizable_losing_times = []
while queue:
p = queue.popleft()
if not any(smaller_than(p, p_prime) for p_prime in pareto_optimal_payoffs):
start_time_process = time.process_time()
is_realizable = realizable(p, automaton, colors_map)
end_time_process = time.process_time()
counter_realizable += 1
realizable_times.append(end_time_process - start_time_process)
if is_realizable:
pareto_optimal_payoffs.append(p)
start_time_process = time.process_time()
is_realizable_losing = realizable(p, automaton, colors_map, losing_for_0=True)
end_time_process = time.process_time()
counter_realizable_losing += 1
realizable_losing_times.append(end_time_process - start_time_process)
if is_realizable_losing:
return False, pareto_optimal_payoffs, [counter_realizable, realizable_times], \
[counter_realizable_losing, realizable_losing_times]
else:
for p_star in generate_smaller_payoffs(p):
if (not any(smaller_than(p_star, p_prime) for p_prime in pareto_optimal_payoffs)) and \
not visited[p_star]:
queue.append(p_star)
visited[p_star] = 1
return True, pareto_optimal_payoffs, [counter_realizable, realizable_times], \
[counter_realizable_losing, realizable_losing_times]
def counterexample_based_statistics(automaton, nbr_objectives, colors_map):
"""
The algorithm is as implemented in verification_algorithms, with new instructions to compute and return statistics.
Compute and return the following statistics on the algorithm: approximation of the set of PO payoffs computed by the
algorithm, number of calls to the function counter_example_exists and their running time, number of calls to the
counter_example_dominated function and their running time.
:param automaton: the automaton.
:param nbr_objectives: the number t of objectives of Player 1.
:param colors_map: maps each parity objective to the set of SPOT acceptance sets used to represent its priorities.
:return: whether the PRV problem is satisfied, the approximation of the set of PO payoffs, a pair [number of calls,
list of running time] for the counter_example_exists function, a similar pair for the counter_example_dominated
function, and the evolution of the size of the antichain at each iteration.
"""
pareto_optimal_payoffs = []
counter_exists = 0
counter_dominated = 0
exists_times = []
dominated_times = []
approximation_evolution = []
while True:
approximation_evolution.append(len(pareto_optimal_payoffs))
start_time_process = time.process_time()
a_counter_example_exists, accepting_run_counter_example = \
counter_example_exists(nbr_objectives, automaton, colors_map, pareto_optimal_payoffs)
end_time_process = time.process_time()
counter_exists += 1
exists_times.append(end_time_process - start_time_process)
if a_counter_example_exists:
counter_example_payoff = get_payoff_of_accepting_run(nbr_objectives, colors_map,
accepting_run_counter_example)
start_time_process = time.process_time()
is_counter_example_dominated, accepting_run_dominating = counter_example_dominated(nbr_objectives,
automaton, colors_map,
counter_example_payoff)
end_time_process = time.process_time()
counter_dominated += 1
dominated_times.append(end_time_process - start_time_process)
if is_counter_example_dominated:
dominating_payoff = get_payoff_of_accepting_run(nbr_objectives, colors_map,
accepting_run_dominating)
# update the set of PO payoffs with this new payoff
pareto_optimal_payoffs = add_payoff_to_antichain(pareto_optimal_payoffs, dominating_payoff)
else:
# a counter example is not dominated by another payoff, hence the instance is false
return False, pareto_optimal_payoffs, [counter_exists, exists_times], \
[counter_dominated, dominated_times], approximation_evolution
else:
# there are no counter examples, hence the instance is true
return True, pareto_optimal_payoffs, [counter_exists, exists_times], \
[counter_dominated, dominated_times], approximation_evolution
def compute_antichain(automaton, nbr_objectives, colors_map, realizable):
"""
Computes and returns the antichain of realizable payoffs in the automaton (that is the PO realizable payoffs). This
is done by going through the lattice of payoffs level-by-level as done in the antichain optimization algorithm.
:param automaton: the automaton.
:param nbr_objectives: the number t of objectives of Player 1.
:param colors_map: maps each parity objective to the set of SPOT acceptance sets used to represent its priorities.
:param realizable: function which decides if a (extended) payoff is realizable.
:return: the antichain of realizable payoffs in the automaton.
"""
maximal_payoff = tuple([1] * nbr_objectives)
pareto_optimal_payoffs = []
queue = deque()
queue.append(maximal_payoff)
visited = defaultdict(int)
while queue:
p = queue.popleft()
if not any(smaller_than(p, p_prime) for p_prime in pareto_optimal_payoffs):
if realizable(p, automaton, colors_map):
pareto_optimal_payoffs.append(p)
else:
for p_star in generate_smaller_payoffs(p):
if (not any(smaller_than(p_star, p_prime) for p_prime in pareto_optimal_payoffs)) and \
not visited[p_star]:
queue.append(p_star)
visited[p_star] = 1
return pareto_optimal_payoffs
def compute_losing_payoffs(automaton, nbr_objectives, colors_map, realizable):
"""
Computes and returns the set of all realizable payoffs in the automaton (that is all payoffs such that there exists
a play with that payoff, regardless of whether it is PO), as well as the set of payoffs p such that (0, p) is
realizable (which we call realizable losing payoffs). This function therefore requires to completely go through the
lattice of payoffs and may take time to terminate when nbr_objectives is large.
:param automaton: the automaton.
:param nbr_objectives: the number t of objectives of Player 1.
:param colors_map: maps each parity objective to the set of SPOT acceptance sets used to represent its priorities.
:param realizable: function which decides if a (extended) payoff is realizable.
:return: the set of all realizable payoffs and the set of all realizable losing payoffs in the automaton.
"""
maximal_payoff = tuple([1] * nbr_objectives)
all_realizable_payoffs = []
losing_payoffs = []
queue = deque()
queue.append(maximal_payoff)
visited = defaultdict(int)
while queue:
p = queue.popleft()
if realizable(p, automaton, colors_map, losing_for_0=True):
losing_payoffs.append(p)
all_realizable_payoffs.append(p)
elif realizable(p, automaton, colors_map):
all_realizable_payoffs.append(p)
for p_star in generate_smaller_payoffs(p):
if not visited[p_star]:
queue.append(p_star)
visited[p_star] = 1
return all_realizable_payoffs, losing_payoffs