Exemple #1
0
def test_greedy_min():
    G = G1()
    B = branchings.greedy_branching(G, kind='min')

    edges = [(1, 0, 4), (0, 2, 12), (0, 4, 12), (2, 5, 12), (4, 7, 12),
             (5, 8, 12), (5, 6, 14), (7, 3, 19)]
    B_ = build_branching(edges)
    assert_equal_branchings(B, B_)
def test_greedy_max1():
    # Standard test.
    #
    G = G1()
    B = branchings.greedy_branching(G)
    # There are only two possible greedy branchings. The sorting is such
    # that it should equal the second suboptimal branching: 1b.
    B_ = build_branching(greedy_subopt_branching_1b)
    assert_equal_branchings(B, B_)
Exemple #3
0
def test_greedy_max1():
    # Standard test.
    #
    G = G1()
    B = branchings.greedy_branching(G)
    # There are only two possible greedy branchings. The sorting is such
    # that it should equal the second suboptimal branching: 1b.
    B_ = build_branching(greedy_subopt_branching_1b)
    assert_equal_branchings(B, B_)
Exemple #4
0
def test_greedy_min():
    G = G1()
    B = branchings.greedy_branching(G, kind='min')

    edges = [
        (1, 0, 4), (0, 2, 12), (0, 4, 12), (2, 5, 12),
        (4, 7, 12), (5, 8, 12), (5, 6, 14), (7, 3, 19)
    ]
    B_ = build_branching(edges)
    assert_equal_branchings(B, B_)
Exemple #5
0
def test_greedy_max3():
    # All equal weights.
    #
    G = G1()
    B = branchings.greedy_branching(G, attr=None)

    # This is mostly arbitrary...the output was generated by running the algo.
    edges = [
        (2, 1, 1), (3, 0, 1), (3, 4, 1), (5, 8, 1),
        (6, 2, 1), (7, 3, 1), (7, 6, 1), (8, 7, 1),
    ]
    B_ = build_branching(edges)
    assert_equal_branchings(B, B_, default=1)
Exemple #6
0
def test_greedy_max3():
    # All equal weights.
    #
    G = G1()
    B = branchings.greedy_branching(G, attr=None)

    # This is mostly arbitrary...the output was generated by running the algo.
    edges = [
        (2, 1, 1), (3, 0, 1), (3, 4, 1), (5, 8, 1),
        (6, 2, 1), (7, 3, 1), (7, 6, 1), (8, 7, 1),
    ]
    B_ = build_branching(edges)
    assert_equal_branchings(B, B_, default=1)
Exemple #7
0
def test_greedy_max2():
    # Different default weight.
    #
    G = G1()
    del G[1][0][0]['weight']
    B = branchings.greedy_branching(G, default=6)
    # Chosen so that edge (3,0,5) is not selected and (1,0,6) is instead.

    edges = [
        (1, 0, 6), (1, 5, 13), (7, 6, 15), (2, 1, 17),
        (3, 4, 17), (8, 7, 18), (2, 3, 21), (6, 2, 21),
    ]
    B_ = build_branching(edges)
    assert_equal_branchings(B, B_)
Exemple #8
0
def test_greedy_max2():
    # Different default weight.
    #
    G = G1()
    del G[1][0][0]['weight']
    B = branchings.greedy_branching(G, default=6)
    # Chosen so that edge (3,0,5) is not selected and (1,0,6) is instead.

    edges = [
        (1, 0, 6), (1, 5, 13), (7, 6, 15), (2, 1, 17),
        (3, 4, 17), (8, 7, 18), (2, 3, 21), (6, 2, 21),
    ]
    B_ = build_branching(edges)
    assert_equal_branchings(B, B_)