File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import networkx as nx
2+ from collections import deque
23
34
45def 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+
3570def 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
You can’t perform that action at this time.
0 commit comments