# File lib/rgl/condensation.rb, line 13
13:     def condensation_graph
14:       raise NotDirectedError,
15:         "condensation_graph only supported for directed graphs" unless directed?
16: 
17:       # Get the component map for the strongly connected components.
18:       comp_map = strongly_connected_components.comp_map
19:       # Invert the map such that for any number, n, in the component map a Set
20:       # instance is created containing all of the nodes which map to n.  The Set
21:       # instances will be used to map to the number, n, with which the elements
22:       # of the set are associated.
23:       inv_comp_map = {}
24:       comp_map.each { |v, n| (inv_comp_map[n] ||= Set.new) << v }
25: 
26:       # Create an ImplicitGraph where the nodes are the strongly connected
27:       # components of this graph and the edges are the edges of this graph which
28:       # cross between the strongly connected components.
29:       ImplicitGraph.new do |g|
30:         g.vertex_iterator do |b|
31:           inv_comp_map.each_value(&b)
32:         end
33:         g.adjacent_iterator do |scc, b|
34:           scc.each do |v|
35:             each_adjacent(v) do |w|
36:               # Do not make the cluster reference itself in the graph.
37:               if comp_map[v] != comp_map[w] then
38:                 b.call(inv_comp_map[comp_map[w]])
39:               end
40:             end
41:           end
42:         end
43:         g.directed = true
44:       end
45:     end