Skip to content

Commit

Permalink
Merge 293fd05 into 61f41d4
Browse files Browse the repository at this point in the history
  • Loading branch information
jtorrents committed May 5, 2014
2 parents 61f41d4 + 293fd05 commit 65938ab
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion networkx/algorithms/components/strongly_connected.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,9 @@ def condensation(G, scc=None):
C : NetworkX DiGraph
The condensation of G. The node labels are integers corresponding
to the index of the component in the list of strongly connected
components.
components. It has a graph attribute named 'mapping' with a
dictionary mapping the original nodes to the nodes in the
condensation graph (ie SCC) to which they belong.
Raises
------
Expand All @@ -334,4 +336,6 @@ def condensation(G, scc=None):
for u,v in G.edges():
if mapping[u] != mapping[v]:
C.add_edge(mapping[u],mapping[v])
# Add mapping dict as graph attribute
C.graph['mapping'] = mapping
return C
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@ def test_contract_scc_edge(self):
edge = (1,0)
assert_equal(cG.edges(),[edge])

def test_condensation_mapping(self):
G, C = self.gc[1]
cG = nx.condensation(G)
mapping = cG.graph['mapping']
assert_true(all(n in G for n in mapping))
assert_true(all(0 == cN for n, cN in mapping.items() if n in C[0]))
assert_true(all(1 == cN for n, cN in mapping.items() if n in C[1]))

def test_connected_raise(self):
G=nx.Graph()
assert_raises(NetworkXNotImplemented,nx.strongly_connected_components,G)
Expand Down

0 comments on commit 65938ab

Please sign in to comment.