@@ -73,12 +73,10 @@ def minimum_multiway_cut(G, terminals, weight=None):
7373 raise nx .NetworkXError ("Expected non-empty NetworkX graph!" )
7474 if not nx .is_connected (G ):
7575 raise nx .NetworkXError ("Graph not connected." )
76- # convert to a set
77- terminals = set (terminals )
7876 # only consider the terminals in G
79- terminals = terminals & G .nodes ()
77+ terminals = set ( terminals ) & G .nodes ()
8078 # raise an error if less than two terminal have been provided
81- if len (terminals & G . nodes () ) < 2 :
79+ if len (terminals ) < 2 :
8280 raise nx .NetworkXError ("At least two terminals should be provided." )
8381
8482 # extract edges weight, and set edges weights with no attribute to 1
@@ -89,13 +87,13 @@ def minimum_multiway_cut(G, terminals, weight=None):
8987
9088 # take a non-existing node of G to be the sink
9189 sink = next (u for u in range (len (G ) + 1 ) if u not in G )
92- # add edges from the terminals to the sink node
90+ # add edges from the terminals to the sink node with infinite capacity
9391 G2 .add_edges_from ([(u , sink ) for u in terminals ], capacity = float ("inf" ))
9492
95- # compute the minimum weight cut for each terminal to all the others
9693 all_cuts = []
94+ # compute the minimum weight isolating cut for each terminal
9795 for u in terminals :
98- # remove the edge to the sink
96+ # remove the edge from u to the sink
9997 G2 .remove_edge (u , sink )
10098 # get the cut value and the 2 partitions of nodes
10199 value_cut , (p1 , p2 ) = nx .minimum_cut (G2 , u , sink )
0 commit comments