Skip to content

Commit b96a389

Browse files
committed
Changed generalized neighbor computation in exact_mif_v3 to fully correspond to the definition
1 parent 402ec56 commit b96a389

1 file changed

Lines changed: 24 additions & 5 deletions

File tree

exact_mif_v3.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
def get_generalized_neighbors(G, F, active_v, v):
66
gen_nb = set(nx.neighbors(G, v)) - F
7-
ens = set(nx.neighbors(G, v)) & (F - {active_v})
7+
excl = {active_v} if active_v is not None else set()
8+
ens = set(nx.neighbors(G, v)) & (F - excl)
89
for s in ens:
910
gen_nb.update(set(nx.neighbors(G, s)) - F)
1011

@@ -274,10 +275,7 @@ def get_mif_len(G, F, active_v):
274275
for n, deg in new_G.degree():
275276
if n not in new_F and (
276277
deg == 2
277-
or (
278-
active_v is not None
279-
and len(get_generalized_neighbors(new_G, new_F, active_v, n)) <= 1
280-
)
278+
or len(get_generalized_neighbors(new_G, new_F, active_v, n)) <= 1
281279
):
282280
v = n
283281
break
@@ -304,3 +302,24 @@ def get_decycling_number_mif_v3(G):
304302
return 0
305303

306304
return len(G.nodes) - get_mif_len(G, set(), None)
305+
306+
307+
if __name__ == "__main__":
308+
nt = nx.Graph()
309+
nt.add_nodes_from(["V1", "V2", "V3", "V4", "V5", "V6", "V7", "V8"])
310+
nt.add_edges_from(
311+
[
312+
("V1", "V2"),
313+
("V1", "V3"),
314+
("V2", "V4"),
315+
("V4", "V5"),
316+
("V3", "V5"),
317+
("V4", "V6"),
318+
("V6", "V7"),
319+
("V5", "V7"),
320+
("V7", "V8"),
321+
("V6", "V8"),
322+
]
323+
)
324+
325+
print(get_decycling_number_mif_v3(nt))

0 commit comments

Comments
 (0)