Example #1
0
        private void BuildStrongConnectedComponents(DirectedGraph Graph)
        {
            TopologicalSorting topologicalSortedVertices = new TopologicalSorting(Graph);
            DirectedGraph      transposedGraph           = Graph.Transposition();

            int[] mark = new int[Graph.VerticesCount];
            for (int i = 0; i < Graph.VerticesCount; ++i)
            {
                mark[i] = -1;
            }

            for (int i = transposedGraph.VerticesCount - 1; i >= 0; --i)
            {
                if (mark[topologicalSortedVertices[i]] == -1)
                {
                    List <DirectedEdge> edges = new List <DirectedEdge>();
                    _strongConnectedComponentEdges.Add(edges);

                    List <int> vertices = new List <int>();
                    _strongConnectedComponentVertices.Add(vertices);

                    AddStrongConnectedComponent(topologicalSortedVertices[i], mark, transposedGraph);

                    _strongConnectedComponentVertices[StrongConnectedComponentCount].Sort();
                    ++StrongConnectedComponentCount;
                }
            }
        }
Example #2
0
        private void BuildStrongConnectedComponents(DirectedGraph Graph)
        {
            TopologicalSorting topologicalSortedVertices = new TopologicalSorting(Graph);
            DirectedGraph transposedGraph = Graph.Transposition();

            int[] mark = new int[Graph.VerticesCount];
            for (int i = 0; i < Graph.VerticesCount; ++i)
                mark[i] = -1;

            for (int i = transposedGraph.VerticesCount - 1; i >= 0; --i)
                if (mark[topologicalSortedVertices[i]] == -1)
                {
                    List<DirectedEdge> edges = new List<DirectedEdge>();
                    _strongConnectedComponentEdges.Add(edges);

                    List<int> vertices = new List<int>();
                    _strongConnectedComponentVertices.Add(vertices);

                    AddStrongConnectedComponent(topologicalSortedVertices[i], mark, transposedGraph);

                    _strongConnectedComponentVertices[StrongConnectedComponentCount].Sort();
                    ++StrongConnectedComponentCount;
                }
        }