1 |
francois |
113 |
#include "gestionversion.h" |
2 |
francois |
481 |
#include "hypergraphlib_platform.h" |
3 |
francois |
283 |
|
4 |
francois |
481 |
#include "hypergraphlib_components.h" |
5 |
|
|
#include "hypergraphlib_dfs.h" |
6 |
|
|
#include "hypergraphlib_graph.h" |
7 |
|
|
#include "hypergraphlib_node.h" |
8 |
francois |
283 |
|
9 |
|
|
/** |
10 |
|
|
* Find the strongly connected components of a graph |
11 |
|
|
// http://en.wikipedia.org/wiki/Strongly_connected_component |
12 |
|
|
|
13 |
|
|
|
14 |
|
|
STRONGLY-CONNECTED COMPONENTS (G) |
15 |
|
|
1 call DFS(G) to compute finishing times f[u] for each vertex u |
16 |
|
|
2 compute GT |
17 |
|
|
3 call DFS(GT), but in the main loop of DFS, consider the vertices in order of decreasing f[u] |
18 |
|
|
4 produce as output the vertices of each tree in the DFS forest formed in point 3 as a separate SCC. |
19 |
|
|
|
20 |
|
|
*/ |
21 |
|
|
namespace HypergraphLib { |
22 |
|
|
|
23 |
|
|
void FindSCC(Graph * __G, std::set < std::set < Node * > > & __components) |
24 |
|
|
{ |
25 |
|
|
std::map < int, Node * > unvisitedNodes = __G->GetNodes(); |
26 |
|
|
|
27 |
|
|
while (unvisitedNodes.size()) |
28 |
|
|
{ |
29 |
|
|
std::set < Node * > depthFirstSearchNodes; |
30 |
|
|
dfs((unvisitedNodes.begin())->second, depthFirstSearchNodes); |
31 |
|
|
__components.insert ( depthFirstSearchNodes ); |
32 |
|
|
for ( std::set < Node * >::const_iterator it = depthFirstSearchNodes.begin(); |
33 |
|
|
it != depthFirstSearchNodes.end(); |
34 |
|
|
it++) |
35 |
|
|
unvisitedNodes.erase((*it)->Id()); |
36 |
|
|
} |
37 |
francois |
102 |
} |
38 |
foucault |
176 |
|
39 |
francois |
283 |
} |
40 |
|
|
|