@@ -22,7 +22,7 @@ def get_non_trivial_components(G):
2222
2323
2424def find_short_pair (G , F , active_v ):
25- for u , v in itertools .combinations (set (G .nodes ) - F , 2 ):
25+ for u , v in itertools .combinations (sorted ( set (G .nodes ) - F ) , 2 ):
2626 nb_u = set (nx .neighbors (G , u ))
2727 nb_v = set (nx .neighbors (G , v ))
2828 # If parallel edges between u and v (so u,v is a short-cycle) or they have a common neighbor in F (also short-cycle)
@@ -37,18 +37,18 @@ def find_short_pair(G, F, active_v):
3737
3838def is_trigger_vertex (G , F , active_v , v ):
3939 nb_active = set (nx .neighbors (G , active_v ))
40- for u in nb_active - F :
40+ for u in sorted ( nb_active - F ) :
4141 gen_nb = get_generalized_neighbors (G , F , active_v , u )
4242 if len (gen_nb - nb_active ) >= 3 and v in gen_nb :
4343 nb_v = set (nx .neighbors (G , v ))
4444 nb_u = set (nx .neighbors (G , u ))
4545 s_set = F - nb_v
4646 v_prime_set = F & nb_v
47- for s in s_set :
47+ for s in sorted ( s_set ) :
4848 if nb_u == {active_v , v , s }:
4949 return True
5050
51- for v_prime in v_prime_set :
51+ for v_prime in sorted ( v_prime_set ) :
5252 d_v_prime = G .degree (v_prime )
5353 if d_v_prime == 2 and (
5454 nb_u == {active_v , v_prime , s }
@@ -63,7 +63,7 @@ def find_optimal_v(G, F, active_v):
6363 nb_active = set (nx .neighbors (G , active_v ))
6464 G_not_F = set (G .nodes ) - F
6565 possible = set ()
66- for v in G_not_F :
66+ for v in sorted ( G_not_F ) :
6767 gen_nb = get_generalized_neighbors (G , F , active_v , v )
6868 if len (gen_nb ) < 3 :
6969 continue
@@ -101,7 +101,7 @@ def main_procedure(G, F, active_v):
101101
102102 cut_v = set (nx .articulation_points (G ))
103103 if len (cut_v ) > 0 :
104- v = next ( iter (cut_v ))
104+ v = list ( sorted (cut_v ))[ 0 ]
105105 components = list (nx .connected_components (nx .subgraph (G , set (G .nodes ) - {v })))
106106 H = min (components , key = lambda x : len (x ))
107107
@@ -143,10 +143,10 @@ def main_procedure(G, F, active_v):
143143 return max (get_mif_len (G , F | {v }, v ), get_mif_len (new_G , F , active_v ))
144144
145145 if active_v is None :
146- active_v = next ( iter (F ))
146+ active_v = list ( sorted (F ))[ 0 ]
147147
148148 nb_active = set (nx .neighbors (G , active_v ))
149- for v in nb_active :
149+ for v in sorted ( nb_active ) :
150150 gen_nb = get_generalized_neighbors (G , F , active_v , v )
151151 d_v = G .degree (v )
152152
@@ -156,7 +156,7 @@ def main_procedure(G, F, active_v):
156156 get_mif_len (nx .subgraph (G , set (G .nodes ) - {v }), F , active_v ),
157157 )
158158
159- for v in nb_active :
159+ for v in sorted ( nb_active ) :
160160 gen_nb = get_generalized_neighbors (G , F , active_v , v )
161161 if len (gen_nb ) == 2 :
162162 if not nx .is_forest (nx .subgraph (G , F | gen_nb )):
@@ -230,7 +230,7 @@ def get_mif_len(G, F, active_v):
230230 non_trivial_components = get_non_trivial_components (sg_F )
231231 if len (non_trivial_components ) > 0 :
232232 T = non_trivial_components [0 ]
233- v = next ( iter (T ))
233+ v = list ( sorted (T ))[ 0 ]
234234 if (active_v is not None ) and (active_v in T ):
235235 v = active_v
236236
@@ -244,9 +244,9 @@ def get_mif_len(G, F, active_v):
244244 # Step 2
245245 v = None
246246 # If we find a node v not in new_F that has 2 parallel edges to a node u in new_F, we remove it from new_G
247- for n in set (new_G .nodes ) - new_F :
247+ for n in sorted ( set (new_G .nodes ) - new_F ) :
248248 nb_in_F = set (new_G .neighbors (n )) & new_F
249- for u in nb_in_F :
249+ for u in sorted ( nb_in_F ) :
250250 if new_G .number_of_edges (u , n ) > 1 :
251251 v = n
252252 break
0 commit comments