Skip to content

Commit ba8d8d5

Browse files
committed
Corrected determinism
1 parent a2ec123 commit ba8d8d5

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

exact_mif_v2.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def construct_H(G, F, nb):
2121

2222

2323
def is_foldable(G, v):
24-
nb = set(nx.neighbors(G, v))
24+
nb = sorted(nx.neighbors(G, v))
2525
for x, y, z in itertools.combinations(nb, 3):
2626
if not (G.has_edge(x, y) or G.has_edge(y, z) or G.has_edge(z, x)):
2727
# If no edges between x-y-z, there is an anti-triangle so not foldable
@@ -31,7 +31,7 @@ def is_foldable(G, v):
3131

3232

3333
def get_anti_edges(G, v):
34-
nb = set(nx.neighbors(G, v))
34+
nb = nx.neighbors(G, v)
3535
anti_edges = set()
3636
for x, y in itertools.combinations(nb, 2):
3737
if not G.has_edge(x, y):
@@ -97,7 +97,7 @@ def get_max_indep_set(G):
9797

9898
return res
9999

100-
for u, v in itertools.combinations(G.nodes, 2):
100+
for u, v in itertools.combinations(sorted(G.nodes), 2):
101101
nb_u = set(nx.neighbors(G, u))
102102
nb_v = set(nx.neighbors(G, v))
103103
if (nb_v | {v}).issubset(nb_u | {u}):
@@ -168,7 +168,7 @@ def get_mif_len(G, F, active_v):
168168
if connections > 1:
169169
vertices_to_remove.add(v)
170170

171-
v_T = next(iter(T))
171+
v_T = list(sorted(T))[0]
172172

173173
for n in T - {v_T}:
174174
new_G = nx.contracted_nodes(new_G, v_T, n, self_loops=False)
@@ -205,26 +205,26 @@ def main_procedure(G, F, active_v):
205205
)
206206

207207
if active_v is None:
208-
active_v = next(iter(F))
208+
active_v = list(sorted(F))[0]
209209

210210
nb = set(nx.neighbors(G, active_v))
211211
if set(G.nodes) - F == nb:
212212
return len(F) + get_max_indep_set(construct_H(G, F - {active_v}, nb))
213213

214-
for v in nb:
214+
for v in sorted(nb):
215215
gen_nb = get_generalized_neighbors(G, F, active_v, v)
216216
if len(gen_nb) < 2:
217217
return get_mif_len(G, F | {v}, active_v)
218218

219-
for v in nb:
219+
for v in sorted(nb):
220220
gen_nb = get_generalized_neighbors(G, F, active_v, v)
221221
if len(gen_nb) > 3:
222222
return max(
223223
get_mif_len(G, F | {v}, active_v),
224224
get_mif_len(nx.subgraph(G, G.nodes - {v}), F, active_v),
225225
)
226226

227-
for v in nb:
227+
for v in sorted(nb):
228228
gen_nb = get_generalized_neighbors(G, F, active_v, v)
229229
if len(gen_nb) == 2:
230230
return max(

0 commit comments

Comments
 (0)