Exemplo n.º 1
0
def test_fundamental_cycle_basis_paton():
    g = create_graph(
        directed=False,
        allowing_self_loops=False,
        allowing_multiple_edges=False,
        weighted=True,
    )

    g.add_vertices_from([0, 1, 2, 3, 4, 5])
    g.add_edge(0, 1)
    g.add_edge(1, 2)
    g.add_edge(2, 3)
    g.add_edge(3, 0)
    g.add_edge(1, 4)
    g.add_edge(4, 5)
    g.add_edge(5, 2)

    fcb_weight, fcb_it = cycles.fundamental_cycle_basis_paton(g)

    assert fcb_weight == 8.0
    cycle1 = next(fcb_it)
    cycle2 = next(fcb_it)
    with pytest.raises(StopIteration):
        next(fcb_it)

    assert cycle1.edges == [1, 2, 3, 0]
    assert cycle2.edges == [4, 5, 6, 1]
Exemplo n.º 2
0
def is_bridge(e, g):
    if not (e in g.edges):
        return None
    w, c = fundamental_cycle_basis_paton(g)
    return all(not e in cycle for cycle in c)