Skip to content

Commit

Permalink
Fix is_k_edge_connected for case of k=2 (#7024)
Browse files Browse the repository at this point in the history
* Fix is_k_edge_connected for case of k=2

Add call to is_connected in addition to has_bridges for k=2, to catch
multi-component graphs without bridges, which are not not 2-edge-connected.

Test case is a two-component graph without bridges, which should not be
2-edge-connected (or k-edge-connected for any value of k).
  • Loading branch information
kbvw committed Oct 18, 2023
1 parent 1ec6405 commit d8d398e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion networkx/algorithms/connectivity/edge_augmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def is_k_edge_connected(G, k):
if k == 1:
return nx.is_connected(G)
elif k == 2:
return not nx.has_bridges(G)
return nx.is_connected(G) and not nx.has_bridges(G)
else:
return nx.edge_connectivity(G, cutoff=k) >= k

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ def test_is_k_edge_connected():
assert is_k_edge_connected(G, k=3)
assert is_k_edge_connected(G, k=4)

G = nx.compose(nx.complete_graph([0, 1, 2]), nx.complete_graph([3, 4, 5]))
assert not is_k_edge_connected(G, k=1)
assert not is_k_edge_connected(G, k=2)
assert not is_k_edge_connected(G, k=3)


def test_is_k_edge_connected_exceptions():
pytest.raises(
Expand Down

0 comments on commit d8d398e

Please sign in to comment.