@not_implemented_for('undirected')
def condensation(G, scc=None):
 if (scc is None):
  scc = nx.strongly_connected_components(G)
 mapping = {}
 members = {}
 C = nx.DiGraph()
 i = 0
 for (i, component) in enumerate(scc):
  members[i] = component
  mapping.update(((n, i) for n in component))
 number_of_components = (i + 1)
 C.add_nodes_from(range(number_of_components))
 C.add_edges_from(((mapping[u], mapping[v]) for (u, v) in G.edges() if (mapping[u] != mapping[v])))
 nx.set_node_attributes(C, 'members', members)
 C.graph['mapping'] = mapping
 return C

@ not_implemented_for ( 'undirected' ) def condensation ( G , scc = None ) : if ( scc is None ) : scc = nx . strongly_connected_components ( G ) mapping = { } members = { } C = nx . DiGraph ( ) i = 0 for ( i , component ) in enumerate ( scc ) : members [ i ] = component mapping . update ( ( ( n , i ) for n in component ) ) number_of_components = ( i + 1 ) C . add_nodes_from ( range ( number_of_components ) ) C . add_edges_from ( ( ( mapping [ u ] , mapping [ v ] ) for ( u , v ) in G . edges ( ) if ( mapping [ u ] != mapping [ v ] ) ) ) nx . set_node_attributes ( C , 'members' , members ) C . graph [ 'mapping' ] = mapping return C
returns the condensation of g .