Пример #1
0
    def test_recursive_solved_worstcases(self):
        """
        Checks the solution of the recursive algorithm on worst case graphs for the recursive algorithm for regular
        parity games.
        """
        print("test recursive solved worstcases")
        g = io.load_generalized_from_file("examples/worstcase_1.txt")
        computed_winning_0, computed_winning_1 = recursive.generalized_parity_solver(
            g)
        self.assertTrue(set(computed_winning_0) == {1, 3, 4, 2, 0})
        self.assertTrue(set(computed_winning_1) == set())

        g = io.load_generalized_from_file("examples/worstcase_2.txt")
        computed_winning_0, computed_winning_1 = recursive.generalized_parity_solver(
            g)
        self.assertTrue(set(computed_winning_0) == set())
        self.assertTrue(
            set(computed_winning_1) == {6, 8, 9, 7, 5, 4, 0, 2, 1, 3})
        for element in fixpoint_1.incomparable_elements:
            winning_region_1.add(element[0])

        # check if the game is completely solved
        # TODO we need a stopping criterion when the theoretical maximal value that gives the equivalence is reached
        # TODO for testing purposes, stop at max_value = 100
        if len(winning_region_0) + len(
                winning_region_1) == nbr_nodes or max_value == 100:
            completely_solved = True

            # print("MAX VALUE "+str(max_value))
            # print("winning 0 " + str(winning_region_0))
            # print("winning 1 " + str(winning_region_1))

        # if it is not, increment the maximal value
        max_value += 1
        # print("value "+str(max_value)+" current fixpoint 0 : "+ str( fixpoint_0))
        # print("value "+str(max_value)+" current fixpoint 1 : "+ str( fixpoint_1))

    return list(winning_region_0), list(winning_region_1)


import file_handler as io
g = io.load_generalized_from_file("generalized_parity_game_example.txt")
fixpoint = compute_fixpoint_0(g, 4)
winning_region_0, winning_region_1 = get_winning_regions_incremental(g)
print("Fixpoint : " + str(fixpoint))
print("Winning region of player 0 : " + str(winning_region_0) +
      " Winning region of player 1 : " + str(winning_region_1))
# solution should be [1, 2] and [3,4,5]
Пример #3
0
def ltl2dpa_gpg(i):
    assert (i < len(_ltl2dpa_gpgs))
    return file_handler.load_generalized_from_file("examples/" +
                                                   _ltl2dpa_gpgs[i])
Пример #4
0
def all_generalized_examples(i):
    g = file_handler.load_generalized_from_file(
        os.path.join("examples", gen_sample_files[i]))
    g.name = gen_sample_files[i]
    assert (len(g.get_nbr_priorities()) > 1)
    return g
Пример #5
0
 def specific_generator(i):
     game = file_handler.load_generalized_from_file(specific_file_names[i])
     game.name = specific_file_names[i][11:]
     return game
Пример #6
0
    def test_recursive_solved_examples(self):
        """
        Checks the solution of the recursive algorithm on examples solved by hand.
        """
        print("test recursive solved examples")
        g = io.load_generalized_from_file("examples/example_0.txt")
        computed_winning_0, computed_winning_1 = recursive.generalized_parity_solver(
            g)
        self.assertTrue(set(computed_winning_0) == {2, 4, 1, 6})
        self.assertTrue(set(computed_winning_1) == {5, 3})

        g = io.load_generalized_from_file("examples/example_1.txt")
        computed_winning_0, computed_winning_1 = recursive.generalized_parity_solver(
            g)
        self.assertTrue(set(computed_winning_0) == {1, 3, 2})
        self.assertTrue(set(computed_winning_1) == set())

        g = io.load_generalized_from_file("examples/example_2.txt")
        computed_winning_0, computed_winning_1 = recursive.generalized_parity_solver(
            g)
        self.assertTrue(set(computed_winning_0) == {1, 3, 4, 2})
        self.assertTrue(set(computed_winning_1) == set())

        g = io.load_generalized_from_file("examples/example_3.txt")
        computed_winning_0, computed_winning_1 = recursive.generalized_parity_solver(
            g)
        self.assertTrue(set(computed_winning_0) == {2, 1, 3, 4})
        self.assertTrue(set(computed_winning_1) == {6, 7, 5})

        g = io.load_generalized_from_file("examples/example_4.txt")
        computed_winning_0, computed_winning_1 = recursive.generalized_parity_solver(
            g)
        self.assertTrue(set(computed_winning_0) == {2, 1, 5})
        self.assertTrue(set(computed_winning_1) == {6, 3, 4})

        g = io.load_generalized_from_file("examples/example_5.txt")
        computed_winning_0, computed_winning_1 = recursive.generalized_parity_solver(
            g)
        self.assertTrue(set(computed_winning_0) == {2, 1, 5})
        self.assertTrue(set(computed_winning_1) == {7, 6, 3, 4})

        # corresponds to counter_example in gamesolver
        g = io.load_generalized_from_file("examples/example_6.txt")
        computed_winning_0, computed_winning_1 = recursive.generalized_parity_solver(
            g)
        self.assertTrue(set(computed_winning_0) == set())
        self.assertTrue(set(computed_winning_1) == {1, 2, 3})

        # corresponds to simple_example in gamesolver
        g = io.load_generalized_from_file("examples/example_7.txt")
        computed_winning_0, computed_winning_1 = recursive.generalized_parity_solver(
            g)
        self.assertTrue(set(computed_winning_0) == {1, 2, 3})
        self.assertTrue(set(computed_winning_1) == set())

        # corresponds to simple_example2 in gamesolver
        g = io.load_generalized_from_file("examples/example_8.txt")
        computed_winning_0, computed_winning_1 = recursive.generalized_parity_solver(
            g)
        self.assertTrue(set(computed_winning_0) == {1, 2})
        self.assertTrue(set(computed_winning_1) == {3, 4, 5})

        # corresponds to simple_example3 in gamesolver
        g = io.load_generalized_from_file("examples/example_9.txt")
        computed_winning_0, computed_winning_1 = recursive.generalized_parity_solver(
            g)
        self.assertTrue(set(computed_winning_0) == {1, 2, 3, 5, 6})
        self.assertTrue(set(computed_winning_1) == {4})
Пример #7
0
    def test_recursive_solved_opposite_priority(self):
        """
        Checks the solution of the recursive algorithm on graphs in which the second priority function is the first
        priority function, but complemented. functions are twice the same.
        """
        print("test recursive solved opposite priority")
        g = gen.opposite_priorities(
            io.load_generalized_from_file("examples/example_0.txt"))
        computed_winning_0, computed_winning_1 = recursive.generalized_parity_solver(
            g)
        self.assertTrue(set(computed_winning_0) == set())
        self.assertTrue(set(computed_winning_1) == {2, 4, 1, 6, 5, 3})

        g = gen.opposite_priorities(
            io.load_generalized_from_file("examples/example_1.txt"))
        computed_winning_0, computed_winning_1 = recursive.generalized_parity_solver(
            g)
        self.assertTrue(set(computed_winning_0) == set())
        self.assertTrue(set(computed_winning_1) == {1, 3, 2})

        g = gen.opposite_priorities(
            io.load_generalized_from_file("examples/example_2.txt"))
        computed_winning_0, computed_winning_1 = recursive.generalized_parity_solver(
            g)
        self.assertTrue(set(computed_winning_0) == set())
        self.assertTrue(set(computed_winning_1) == {1, 3, 4, 2})

        g = gen.opposite_priorities(
            io.load_generalized_from_file("examples/example_3.txt"))
        computed_winning_0, computed_winning_1 = recursive.generalized_parity_solver(
            g)
        self.assertTrue(set(computed_winning_0) == set())
        self.assertTrue(set(computed_winning_1) == {2, 1, 3, 4, 6, 7, 5})

        g = gen.opposite_priorities(
            io.load_generalized_from_file("examples/example_4.txt"))
        computed_winning_0, computed_winning_1 = recursive.generalized_parity_solver(
            g)
        self.assertTrue(set(computed_winning_0) == set())
        self.assertTrue(set(computed_winning_1) == {2, 1, 5, 6, 3, 4})

        g = gen.opposite_priorities(
            io.load_generalized_from_file("examples/example_5.txt"))
        computed_winning_0, computed_winning_1 = recursive.generalized_parity_solver(
            g)
        self.assertTrue(set(computed_winning_0) == set())
        self.assertTrue(set(computed_winning_1) == {2, 1, 5, 7, 6, 3, 4})

        g = gen.opposite_priorities(
            io.load_generalized_from_file("examples/worstcase_1.txt"))
        computed_winning_0, computed_winning_1 = recursive.generalized_parity_solver(
            g)
        self.assertTrue(set(computed_winning_0) == set())
        self.assertTrue(set(computed_winning_1) == {1, 3, 4, 2, 0})

        g = gen.opposite_priorities(
            io.load_generalized_from_file("examples/worstcase_2.txt"))
        computed_winning_0, computed_winning_1 = recursive.generalized_parity_solver(
            g)
        self.assertTrue(set(computed_winning_0) == set())
        self.assertTrue(
            set(computed_winning_1) == {6, 8, 9, 7, 5, 4, 0, 2, 1, 3})
Пример #8
0
    def test_recursive_solved_double_priority(self):
        """
        Checks the solution of the recursive algorithm on graphs in which the priority functions are twice the same.
        """
        print("test recursive solved double priority")
        g = io.load_generalized_from_file("examples/double_priority.txt")
        computed_winning_0, computed_winning_1 = recursive.generalized_parity_solver(
            g)
        self.assertTrue(set(computed_winning_0) == set())
        self.assertTrue(set(computed_winning_1) == {4, 5, 6, 7, 3, 1, 2})

        g = gen.multiple_priorities(
            io.load_generalized_from_file("examples/example_0.txt"), 2)
        computed_winning_0, computed_winning_1 = recursive.generalized_parity_solver(
            g)
        self.assertTrue(set(computed_winning_0) == {2, 4, 1, 6})
        self.assertTrue(set(computed_winning_1) == {5, 3})

        g = gen.multiple_priorities(
            io.load_generalized_from_file("examples/example_1.txt"), 2)
        computed_winning_0, computed_winning_1 = recursive.generalized_parity_solver(
            g)
        self.assertTrue(set(computed_winning_0) == {1, 3, 2})
        self.assertTrue(set(computed_winning_1) == set())

        g = gen.multiple_priorities(
            io.load_generalized_from_file("examples/example_2.txt"), 2)
        computed_winning_0, computed_winning_1 = recursive.generalized_parity_solver(
            g)
        self.assertTrue(set(computed_winning_0) == {1, 3, 4, 2})
        self.assertTrue(set(computed_winning_1) == set())

        g = gen.multiple_priorities(
            io.load_generalized_from_file("examples/example_3.txt"), 2)
        computed_winning_0, computed_winning_1 = recursive.generalized_parity_solver(
            g)
        self.assertTrue(set(computed_winning_0) == {2, 1, 3, 4})
        self.assertTrue(set(computed_winning_1) == {6, 7, 5})

        g = gen.multiple_priorities(
            io.load_generalized_from_file("examples/example_4.txt"), 2)
        computed_winning_0, computed_winning_1 = recursive.generalized_parity_solver(
            g)
        self.assertTrue(set(computed_winning_0) == {2, 1, 5})
        self.assertTrue(set(computed_winning_1) == {6, 3, 4})

        g = gen.multiple_priorities(
            io.load_generalized_from_file("examples/example_5.txt"), 2)
        computed_winning_0, computed_winning_1 = recursive.generalized_parity_solver(
            g)
        self.assertTrue(set(computed_winning_0) == {2, 1, 5})
        self.assertTrue(set(computed_winning_1) == {7, 6, 3, 4})

        g = gen.multiple_priorities(
            io.load_generalized_from_file("examples/worstcase_1.txt"), 2)
        computed_winning_0, computed_winning_1 = recursive.generalized_parity_solver(
            g)
        self.assertTrue(set(computed_winning_0) == {1, 3, 4, 2, 0})
        self.assertTrue(set(computed_winning_1) == set())

        g = gen.multiple_priorities(
            io.load_generalized_from_file("examples/worstcase_2.txt"), 2)
        computed_winning_0, computed_winning_1 = recursive.generalized_parity_solver(
            g)
        self.assertTrue(set(computed_winning_0) == set())
        self.assertTrue(
            set(computed_winning_1) == {6, 8, 9, 7, 5, 4, 0, 2, 1, 3})