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