def is_independent_set(G, nodes): """Return whether or not the *nodes* comprises an independent set. An set *S* of nodes in *G* is called an *independent set* if no two nodes in S are neighbors of one another. Parameters ---------- G : NetworkX graph An undirected graph. nodes : list, set An iterable container of nodes in G. Only nodes existing in G will be considered. Any other nodes will be ignored. Returns ------- bool True if the the nodes in *nodes* comprise an independent set, False otherwise. See Also -------- is_k_independent_set """ S = set(n for n in nodes if n in G) return set(set_neighborhood(G, S)).intersection(S) == set()
def is_total_dominating_set(G, nodes): """Return whether or not nodes comprises a total dominating set. A * total dominating set* is a set of nodes with the property that every node in the graph is adjacent to some node in the set. Parameters ---------- G : NetworkX graph An undirected graph. nodes : list, set An iterable container of nodes in G. Returns ------- boolean True if the nodes in nbunch comprise a k-dominating set, and False otherwise. """ # exclude any nodes that aren't in G S = set(n for n in nodes if n in G) return set(set_neighborhood(G, S)) == set(G.nodes())