summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Schult <dschult@colgate.edu>2016-01-07 12:41:43 -0500
committerDan Schult <dschult@colgate.edu>2016-01-07 12:41:43 -0500
commit1aee422ce836d4253401145026fcd3628cee3ad5 (patch)
tree95b5ab446fa6b6fa732193f4e72a71c03bfef38d
parent399fec8b80bf49e2ea90126b8598863897c01570 (diff)
parentd4947aa7c9f14251959abea47f2e0691c89fcdd0 (diff)
downloadnetworkx-1aee422ce836d4253401145026fcd3628cee3ad5.tar.gz
Merge pull request #1914 from Arafatk/patch-5
minimum_st_node_cut incorrect if source and target are connected
-rw-r--r--networkx/algorithms/connectivity/cuts.py3
-rw-r--r--networkx/algorithms/connectivity/tests/test_cuts.py7
2 files changed, 9 insertions, 1 deletions
diff --git a/networkx/algorithms/connectivity/cuts.py b/networkx/algorithms/connectivity/cuts.py
index 763a8e4a..0288f5e2 100644
--- a/networkx/algorithms/connectivity/cuts.py
+++ b/networkx/algorithms/connectivity/cuts.py
@@ -285,7 +285,8 @@ def minimum_st_node_cut(G, s, t, flow_func=None, auxiliary=None, residual=None):
mapping = H.graph.get('mapping', None)
if mapping is None:
raise nx.NetworkXError('Invalid auxiliary digraph.')
-
+ if G.has_edge(s, t) or G.has_edge(t, s):
+ return []
kwargs = dict(flow_func=flow_func, residual=residual, auxiliary=H)
# The edge cut in the auxiliary digraph corresponds to the node cut in the
diff --git a/networkx/algorithms/connectivity/tests/test_cuts.py b/networkx/algorithms/connectivity/tests/test_cuts.py
index 1086cf9c..264bc4af 100644
--- a/networkx/algorithms/connectivity/tests/test_cuts.py
+++ b/networkx/algorithms/connectivity/tests/test_cuts.py
@@ -238,6 +238,13 @@ def tests_min_cut_complete_directed():
for flow_func in flow_funcs:
assert_equal(4, len(interface_func(G, flow_func=flow_func)))
+def tests_minimum_st_node_cut():
+ G = nx.Graph()
+ G.add_nodes_from([0, 1, 2, 3, 7, 8, 11, 12])
+ G.add_edges_from([(7, 11), (1, 11), (1, 12), (12, 8), (0, 1)])
+ nodelist = minimum_st_node_cut(G, 7, 11)
+ assert(nodelist == [])
+
def test_invalid_auxiliary():
G = nx.complete_graph(5)
assert_raises(nx.NetworkXError, minimum_st_node_cut, G, 0, 3,