Skip to content

Commit cb54bc8

Browse files
committed
Implemented the search for critical linkpoints
1 parent b637263 commit cb54bc8

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

bar_yehuda_fvs.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import networkx as nx
2+
from collections import deque
23

34

45
def dfs_remove_below_2(H, v):
@@ -32,11 +33,47 @@ def find_maximal_2_3_subgraph(G):
3233
return H
3334

3435

36+
def cycle_exists_with_node(G, n):
37+
queue = deque()
38+
queue.append((n, None))
39+
visited = set()
40+
visited.add(n)
41+
42+
while queue:
43+
current, parent = queue.popleft()
44+
for nb in G.neighbors(current):
45+
if nb == parent:
46+
continue
47+
48+
if nb == n:
49+
return True
50+
51+
if nb not in visited:
52+
visited.add(nb)
53+
queue.append((nb, current))
54+
55+
return False
56+
57+
58+
def get_critical_linkpoints(G, H):
59+
linkpoints = {n for n in H.nodes if H.degree(n) == 2}
60+
critical_linkpoints = set()
61+
62+
for n in linkpoints:
63+
sg = nx.subgraph(G, set(G.nodes) - (set(H.nodes) - {n}))
64+
if cycle_exists_with_node(sg, n):
65+
critical_linkpoints.add(n)
66+
67+
return critical_linkpoints
68+
69+
3570
def subG_2_3(G):
3671
if nx.is_forest(G):
3772
return set()
3873

3974
H = find_maximal_2_3_subgraph(G)
75+
X = get_critical_linkpoints(G, H)
76+
Y = {n for n in H.nodes if H.degree(n) > 2}
4077
pass
4178

4279

0 commit comments

Comments
 (0)