def dominating_set(G, start_with=None):
 all_nodes = set(G)
 if (start_with is None):
  start_with = arbitrary_element(all_nodes)
 if (start_with not in G):
  raise nx.NetworkXError('node {} is not in G'.format(start_with))
 dominating_set = {start_with}
 dominated_nodes = set(G[start_with])
 remaining_nodes = ((all_nodes - dominated_nodes) - dominating_set)
 while remaining_nodes:
  v = remaining_nodes.pop()
  undominated_neighbors = (set(G[v]) - dominating_set)
  dominating_set.add(v)
  dominated_nodes |= undominated_neighbors
  remaining_nodes -= undominated_neighbors
 return dominating_set

def dominating_set ( G , start_with = None ) : all_nodes = set ( G ) if ( start_with is None ) : start_with = arbitrary_element ( all_nodes ) if ( start_with not in G ) : raise nx . NetworkXError ( 'node {} is not in G' . format ( start_with ) ) dominating_set = { start_with } dominated_nodes = set ( G [ start_with ] ) remaining_nodes = ( ( all_nodes - dominated_nodes ) - dominating_set ) while remaining_nodes : v = remaining_nodes . pop ( ) undominated_neighbors = ( set ( G [ v ] ) - dominating_set ) dominating_set . add ( v ) dominated_nodes |= undominated_neighbors remaining_nodes -= undominated_neighbors return dominating_set
finds a dominating set for the graph g .