def solve_pg_bdd_partial_debug(pg_path, timeout_value): """ Load and solve the parity game whose path is provided in parameter using the bdd implementation of the combination of the recursive algorithm and a partial solver. This is Clement's implementation. """ player0_won = "TIMEOUT" winning_0, winning_1 = None, None start_time = time.time() with timeout(timeout_value): manager = _bdd.BDD() arena, all_vertices = bdd_pg_loader.pg2bdd(pg_path, manager) winning_0, winning_1 = bdd_pg_recursive.recursive_with_buchi( 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 end_time = "%.5f" % (time.time() - start_time) if player0_won == "TIMEOUT": end_time = "TIMEOUT" return player0_won, end_time, winning_0, winning_1
def check_consistency_bdd(regions, realizability, is_pg, file_path): """ Checks the consistency of the winning regions computed by the bdd algorithms. """ # only keep the regions that were actually computed, meaning we exclude timeouts computed_regions = [region for region in regions if region[0] is not None] nbr_computed_regions = len(computed_regions) # same goes for the realizability computed_realizability = [ real for real in realizability if real != "TIMEOUT" ] manager = _bdd.BDD() if is_pg: arena_check, all_vertices = bdd_pg_loader.pg2bdd(file_path, manager) else: arena_check, all_vertices = bdd_gpg_loader.gpg2bdd(file_path, manager) all_vertices_in_arena = arena_check.player0_vertices | arena_check.player1_vertices # check that for each computed solution, intersection is empty and union is the set of vertices for region in computed_regions: pass #assert(((region[0] & region[1]) & all_vertices_in_arena) == manager.false) #assert(((region[0] | region[1]) & all_vertices_in_arena) == all_vertices_in_arena) # there has to be at least 2 to compare if nbr_computed_regions >= 2: for i in range(nbr_computed_regions - 1): compare_a = computed_regions[i] compare_b = computed_regions[i + 1] #assert set(compare_a[0]) == set(compare_b[0]) #assert set(compare_a[1]) == set(compare_b[1]) assert computed_realizability[i] == computed_realizability[i + 1]
def test_pg_arena_creation(self): """ Check if arenas are correctly loaded from files. """ for file in self.pg_test_files: file_path = self.pg_test_files_path + file manager = _bdd.BDD() # load arena and get number of vertices arena, vertices_bdd = pg2bdd(file_path, manager, is_gpg=False) nbr_vertices = len(vertices_bdd) print(file_path) expected_arena = retrieve_expected_pg_arena(file_path) self.assertEqual(arena.nbr_functions, 1) actual_player0 = set( bdd2int(arena.player0_vertices, arena.vars, manager, mapping=vertices_bdd)) expected_player0 = set(expected_arena[0]) self.assertEqual(expected_player0, actual_player0) actual_player1 = set( bdd2int(arena.player1_vertices, arena.vars, manager, mapping=vertices_bdd)) expected_player1 = set(expected_arena[1]) self.assertEqual(expected_player1, actual_player1) for priority, s in expected_arena[2].items(): actual_priority = set( bdd2int(arena.priorities[0][priority], arena.vars, manager, mapping=vertices_bdd)) expected_priority = set(s) self.assertEqual(expected_priority, actual_priority) for index in range(nbr_vertices): vertex_encoding = vertices_bdd[ index] # BDD encoding of the vertex edges_vertex = vertex_encoding & arena.edges edges_vertex = manager.exist(arena.vars, edges_vertex) edges_vertex = manager.let(arena.inv_mapping_bis, edges_vertex) actual_successors = set( bdd2int(edges_vertex, arena.vars, manager, mapping=vertices_bdd)) expected_successors = set(expected_arena[3][index]) self.assertEqual(expected_successors, actual_successors)