@@ -207,13 +207,15 @@ def get_max_indep_set(G):
207207 return 0
208208
209209 if nx .number_connected_components (G ) > 1 :
210+ # If G is disconnected, compute the size of a maximum independent set for each component separately
210211 res = 0
211212 for c in nx .connected_components (G ):
212213 res += get_max_indep_set (G .subgraph (c ))
213214
214215 return res
215216
216217 for u , v in itertools .combinations (sorted (G .nodes , key = sort_nodes ), 2 ):
218+ # If one node's neighborhood is a subset of the other's, we remove the node with the larger neighborhood
217219 nb_u = set (nx .neighbors (G , u ))
218220 nb_v = set (nx .neighbors (G , v ))
219221 if (nb_v | {v }).issubset (nb_u | {u }):
@@ -228,9 +230,12 @@ def get_max_indep_set(G):
228230 deg = comb [1 ]
229231 anti_edges = get_anti_edges (G , v )
230232 if (deg < 4 and is_foldable (G , v )) or (deg == 4 and len (anti_edges ) < 4 ):
233+ # Fold the graph at v
231234 return 1 + get_max_indep_set (fold_graph (G , v , anti_edges ))
232235
233236 v = max (node_degrees , key = lambda x : x [1 ])[0 ]
237+ # As a last resort, explore both subproblems of including and excluding v (having maximum degree)
238+ # from a maximum independent set
234239 return max (
235240 get_max_indep_set (nx .subgraph (G , G .nodes - {v } - get_mirrors (G , v ))),
236241 1 + get_max_indep_set (nx .subgraph (G , G .nodes - {v } - set (nx .neighbors (G , v )))),
@@ -298,7 +303,7 @@ def get_mif_len(G, F, active_v):
298303 new_G = G .copy ()
299304 new_F = set (F )
300305 for T in get_non_trivial_components (sg_F ):
301- # Get all neighbors of T in G and need to remove those with more than 1 connection to T
306+ # Get all neighbors of T in G. We need to remove those with more than 1 connection to T
302307 nb_T = set ()
303308 for v in T :
304309 nb_T .update (set (G .neighbors (v )))
0 commit comments