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