예제 #1
0
def example_1():
    """
    Solves a simple example.
    """
    g = io.load_from_file("assets/strong parity/example_1.txt")
    (a, b), (c, d) = sp.strong_parity_solver(g)
    return (a == [1, 3, 2]) and b == {1: 1, 3: 3} and c == [] and d == {}
예제 #2
0
def fixwp_example8():
    #Figure 3.2.7
    g = io.load_from_file("assets/strong parity/example_8.txt")
    (w0, w1) = fixwp.partial_solver(
        g, 10
    )  #no solutions with any lambda because the winner is player 0 but player 1 can manage to loop to prevent window from closing
    return ops.are_lists_equal(w0, []) and ops.are_lists_equal(w1, [])
예제 #3
0
def example_2_antichain_algorithm():
    """
    Solves a simple example.
    """
    g = io.load_from_file("assets/strong parity/example_2.txt")
    (a, c) = sp.strong_parity_antichain_based(g, 1)
    return ops.are_lists_equal(a, [1, 3, 4, 2]) and ops.are_lists_equal(c, [])
예제 #4
0
def example_2_reduction_to_safety():
    """
    Solves a simple example.
    """
    g = io.load_from_file("assets/strong parity/example_2.txt")
    (a, c) = sp.reduction_to_safety_parity_solver(g)
    return ops.are_lists_equal(a, [1, 3, 4, 2]) and ops.are_lists_equal(c, [])
예제 #5
0
def dirfixwp_example3():
    g = io.load_from_file("assets/strong parity/example_3.txt")
    (w0, w1) = dirfixwp.partial_solver(g, 1)  #partial solve with lambda = 1
    (w0_2, w1_2) = dirfixwp.partial_solver(g, 2)  #full solve with lambda >= 2
    return ops.are_lists_equal(w0, [1, 2, 4]) and ops.are_lists_equal(
        w1, [5, 6, 7]) and ops.are_lists_equal(
            w0_2, [1, 2, 3, 4]) and ops.are_lists_equal(w1_2, [5, 6, 7])
예제 #6
0
def worstcase1():
    """
    Solves a worst case graph G_n for n = 1.
    """
    g = io.load_from_file("assets/strong parity/worstcase_1.txt")
    (a, b), (c, d) = sp.strong_parity_solver(g)
    return a == [1, 3, 4, 2, 0] and b == {1: 2, 3: 1} and c == [] and d == {}
예제 #7
0
def worstcase2_antichain_algorithm():
    """
    Solves a worst case graph G_n for n = 2.
    """
    g = io.load_from_file("assets/strong parity/worstcase_2.txt")
    (a, c) = sp.strong_parity_antichain_based(g, 0)
    return ops.are_lists_equal(a, []) and ops.are_lists_equal(
        c, [6, 8, 9, 7, 5, 4, 0, 2, 1, 3])
예제 #8
0
def worstcase1_antichain_algorithm():
    """
    Solves a worst case graph G_n for n = 1.
    """
    g = io.load_from_file("assets/strong parity/worstcase_1.txt")
    (a, c) = sp.strong_parity_antichain_based(g, 0)
    return ops.are_lists_equal(a, [1, 3, 4, 2, 0]) and ops.are_lists_equal(
        c, [])
예제 #9
0
def figure56_antichain_algorithm():
    """
    Solves the strong parity game from figure 5.6.
    """
    fig56_graph = io.load_from_file("assets/strong parity/figure56.txt")
    (a, c) = sp.strong_parity_antichain_based(fig56_graph, 1)
    return ops.are_lists_equal(a, [2, 4, 1, 6]) and ops.are_lists_equal(
        c, [5, 3])
예제 #10
0
def worstcase1_removed_optimization():
    """
    Solves a worst case graph G_n for n = 1.
    """
    g = io.load_from_file("assets/strong parity/worstcase_1.txt")
    removed = bitarray([False] + ([False] * len(g.nodes)))
    (a, b), (c, d) = sp.strong_parity_solver_non_removed(g, removed)
    return a == [1, 3, 4, 2, 0] and b == {1: 2, 3: 1} and c == [] and d == {}
예제 #11
0
def example_1_removed_optimization():
    """
    Solves a simple example.
    """
    g = io.load_from_file("assets/strong parity/example_1.txt")
    removed = bitarray([False] + ([False] * len(g.nodes)))
    (a, b), (c, d) = sp.strong_parity_solver_non_removed(g, removed)
    return (a == [1, 3, 2]) and b == {1: 1, 3: 3} and c == [] and d == {}
예제 #12
0
def figure56_reduction_to_safety():
    """
    Solves the strong parity game from figure 5.6.
    """
    fig56_graph = io.load_from_file("assets/strong parity/figure56.txt")
    (a, c) = sp.reduction_to_safety_parity_solver(fig56_graph)
    return ops.are_lists_equal(a, [2, 4, 1, 6]) and ops.are_lists_equal(
        c, [5, 3])
예제 #13
0
def worstcase2_reduction_to_safety():
    """
    Solves a worst case graph G_n for n = 2.
    """
    g = io.load_from_file("assets/strong parity/worstcase_2.txt")
    (a, c) = sp.reduction_to_safety_parity_solver(g)
    return ops.are_lists_equal(a, []) and ops.are_lists_equal(
        c, [6, 8, 9, 7, 5, 4, 0, 2, 1, 3])
예제 #14
0
def dirfixwp_example5():
    g = io.load_from_file("assets/strong parity/example_5.txt")
    (w0, w1) = dirfixwp.partial_solver(g, 1)  #partial solve with lambda = 1
    (w0_2, w1_2) = dirfixwp.partial_solver(
        g, 100)  #not able to solve more even with a greater lambda
    return ops.are_lists_equal(w0, [1, 2, 5]) and ops.are_lists_equal(
        w1, [3, 6]) and ops.are_lists_equal(
            w0_2, [1, 2, 5]) and ops.are_lists_equal(w1_2, [3, 6])
예제 #15
0
def worstcase1_reduction_to_safety():
    """
    Solves a worst case graph G_n for n = 1.
    """
    g = io.load_from_file("assets/strong parity/worstcase_1.txt")
    (a, c) = sp.reduction_to_safety_parity_solver(g)
    return ops.are_lists_equal(a, [1, 3, 4, 2, 0]) and ops.are_lists_equal(
        c, [])
예제 #16
0
def wp_2_example9():
    g = io.load_from_file("assets/strong parity/example_9.txt")
    (dir_w0, dir_w1) = dirfixwp.partial_solver2(g, 1)
    (ndir_w0, ndir_w1) = fixwp.partial_solver2(g, 1)
    (w0, w1) = sp(g)
    dir_inc_0 = all(s in w0 for s in dir_w0)
    dir_inc_1 = all(s in w1 for s in dir_w1)
    ndir_inc_0 = all(s in w0 for s in ndir_w0)
    ndir_inc_1 = all(s in w1 for s in ndir_w1)
    return dir_inc_0 and dir_inc_1 and ndir_inc_0 and ndir_inc_1
예제 #17
0
def wp_2_example6():
    g = io.load_from_file("assets/strong parity/example_6.txt")
    #only winnable with lambda >=4
    (dir_w0, dir_w1) = dirfixwp.partial_solver2(g, 4)
    (ndir_w0, ndir_w1) = fixwp.partial_solver2(g, 4)
    (w0, w1) = sp(g)
    dir_inc_0 = all(s in w0 for s in dir_w0)
    dir_inc_1 = all(s in w1 for s in dir_w1)
    ndir_inc_0 = all(s in w0 for s in ndir_w0)
    ndir_inc_1 = all(s in w1 for s in ndir_w1)
    return dir_inc_0 and dir_inc_1 and ndir_inc_0 and ndir_inc_1
예제 #18
0
def wp_2_example3():
    g = io.load_from_file("assets/strong parity/example_3.txt")
    #better results with lambda = 2 on the basic algorithm
    (dir_w0, dir_w1) = dirfixwp.partial_solver2(g, 2)
    (ndir_w0, ndir_w1) = fixwp.partial_solver2(g, 2)
    (w0, w1) = sp(g)
    dir_inc_0 = all(s in w0 for s in dir_w0)
    dir_inc_1 = all(s in w1 for s in dir_w1)
    ndir_inc_0 = all(s in w0 for s in ndir_w0)
    ndir_inc_1 = all(s in w1 for s in ndir_w1)
    return dir_inc_0 and dir_inc_1 and ndir_inc_0 and ndir_inc_1
예제 #19
0
def wp_2_example1():
    g = io.load_from_file("assets/strong parity/example_1.txt")
    (dir_w0, dir_w1) = dirfixwp.partial_solver2(g, 1)
    (ndir_w0, ndir_w1) = fixwp.partial_solver2(g, 1)
    (w0, w1) = sp(g)
    #checking if the partial solutions are included in the true solutions
    dir_inc_0 = all(s in w0 for s in dir_w0)
    dir_inc_1 = all(s in w1 for s in dir_w1)
    ndir_inc_0 = all(s in w0 for s in ndir_w0)
    ndir_inc_1 = all(s in w1 for s in ndir_w1)
    return dir_inc_0 and dir_inc_1 and ndir_inc_0 and ndir_inc_1
예제 #20
0
def figure56():
    """
    Solves the strong parity game from figure 5.6.
    """
    fig56_graph = io.load_from_file("assets/strong parity/figure56.txt")
    (a, b), (c, d) = sp.strong_parity_solver(fig56_graph)
    return (a == [2, 4, 1, 6]) and b == {
        2: 2,
        4: 1
    } and c == [5, 3] and d == {
        5: 5
    }
예제 #21
0
def example_1():
    g = io.load_from_file("assets/weak parity/example_1.txt")
    (a, b), (c, d) = wp.weak_parity_solver(g)
    return a == [3, 6, 2] and b == {
        1: 5,
        3: 3,
        6: 1
    } and c == [8, 7, 4, 5, 1] and d == {
        8: 3,
        5: 1,
        7: 8
    }
예제 #22
0
def fixwp_example6():
    g = io.load_from_file("assets/strong parity/example_6.txt")
    (w0, w1) = fixwp.partial_solver(g, 1)  #no solutions with lambda = 1
    (w0_2, w1_2) = fixwp.partial_solver(g, 2)  #no solutions with lambda = 2
    (w0_3, w1_3) = fixwp.partial_solver(g, 3)  #no solutions with lambda = 3
    (w0_4, w1_4) = fixwp.partial_solver(g, 4)  #full solve with lambda >= 4
    return ops.are_lists_equal(w0, []) and ops.are_lists_equal(
        w1, []) and ops.are_lists_equal(w0_2, []) and ops.are_lists_equal(
            w1_2,
            []) and ops.are_lists_equal(w0_3, []) and ops.are_lists_equal(
                w1_3, []) and ops.are_lists_equal(
                    w0_4, []) and ops.are_lists_equal(w1_4, [1, 2, 3, 4, 5])
예제 #23
0
def figure56_removed_optimization():
    """
    Solves the strong parity game from figure 5.6.
    """
    fig56_graph = io.load_from_file("assets/strong parity/figure56.txt")
    removed = bitarray([False] + ([False] * len(fig56_graph.nodes)))
    (a, b), (c, d) = sp.strong_parity_solver_non_removed(fig56_graph, removed)
    return (a == [2, 4, 1, 6]) and b == {
        2: 2,
        4: 1
    } and c == [5, 3] and d == {
        5: 5
    }
예제 #24
0
def figure32():
    """
    Solves the reachability game from figure 3.2.
    """
    fig32_graph = io.load_from_file("assets/reachability/figure32.txt")
    (W0, sig0), (W1, sig1) = rs.reachability_solver(fig32_graph, [1], 0)
    return W0 == [1, 2, 3, 5] and sig0 == {
        1: 1,
        2: 1,
        5: 2
    } and W1 == [4, 6] and sig1 == {
        4: 6,
        6: 4
    }
예제 #25
0
def example_1():
    """
    Solves a simple example.
    """
    fig51_graph = io.load_from_file("assets/reachability/fig51.txt")
    (W1, sig1), (W0, sig0) = rs.reachability_solver(fig51_graph, [8], 1)
    return W1 == [8, 7, 4] and sig1 == {
        8: 3,
        7: 8
    } and W0 == [1, 2, 3, 5, 6] and sig0 == {
        1: 5,
        3: 3,
        6: 5
    }
예제 #26
0
def worstcase2():
    """
    Solves a worst case graph G_n for n = 2.
    """
    g = io.load_from_file("assets/strong parity/worstcase_2.txt")
    (a, b), (c, d) = sp.strong_parity_solver(g)
    return a == [] and b == {} and c == [6, 8, 9, 7, 5, 4, 0, 2, 1, 3
                                         ] and d == {
                                             0: 4,
                                             2: 4,
                                             4: 5,
                                             6: 7,
                                             8: 6
                                         }
예제 #27
0
def figure41():
    """
    Solves the weak parity game from figure 4.1.
    """
    g = io.load_from_file("assets/weak parity/figure41.txt")
    (a, b), (c, d) = wp.weak_parity_solver(g)
    return a == [3] and b == {
        1: 2,
        5: 5
    } and c == [4, 5, 1, 2] and d == {
        4: 4,
        2: 1,
        3: 3
    }
예제 #28
0
def example_3():
    """
    Solves a simple example.
    """
    g = io.load_from_file("assets/strong parity/example_3.txt")
    (a, b), (c, d) = sp.strong_parity_solver(g)
    return (a == [2, 1, 3, 4]) and b == {
        4: 4,
        2: 4,
        1: 2
    } and c == [6, 7, 5] and d == {
        7: 6,
        6: 6,
        5: 6
    }
예제 #29
0
def worstcase2_removed_optimization():
    """
    Solves a worst case graph G_n for n = 2.
    """
    g = io.load_from_file("assets/strong parity/worstcase_2.txt")
    removed = bitarray([False] + ([False] * len(g.nodes)))
    (a, b), (c, d) = sp.strong_parity_solver_non_removed(g, removed)
    return a == [] and b == {} and c == [6, 8, 9, 7, 5, 4, 0, 2, 1, 3
                                         ] and d == {
                                             0: 4,
                                             2: 4,
                                             4: 5,
                                             6: 7,
                                             8: 6
                                         }
예제 #30
0
def example_5():
    """
    Solves a simple example.
    """
    g = io.load_from_file("assets/strong parity/example_5.txt")
    (a, b), (c, d) = sp.strong_parity_solver(g)
    return a == [2, 1, 5] and b == {
        1: 2,
        2: 2,
        5: 5
    } and c == [7, 6, 3, 4] and d == {
        3: 6,
        4: 3,
        6: 6
    }