예제 #1
0
 private static void DuplicateGraph(DigraphBase g)
 {
     for (int i = 0; i < g.V; i++)
     {
         g.AddEdge(i, i);
         foreach (var v in g.Adj(i))
         {
             g.AddEdge(i, v);
         }
     }
 }
예제 #2
0
파일: SCC.cs 프로젝트: allanma88/SampleCode
 private void DfsVisit(DigraphBase g, int u)
 {
     _ids[u]            = _count;
     _vertices[u].Color = Color.Gray;
     foreach (var v in g.Adj(u))
     {
         if (_vertices[v].Color == Color.White)
         {
             DfsVisit(g, v);
         }
     }
     _vertices[u].Color = Color.Black;
 }
예제 #3
0
파일: SCC.cs 프로젝트: allanma88/SampleCode
 private void DfsOrderVisit(DigraphBase g, int u, Stack <int> stack)
 {
     _vertices[u].Color = Color.Gray;
     _vertices[u].D     = ++_time;
     foreach (var v in g.Adj(u))
     {
         if (_vertices[v].Color == Color.White)
         {
             DfsOrderVisit(g, v, stack);
         }
     }
     _vertices[u].F     = ++_time;
     _vertices[u].Color = Color.Black;
     stack.Push(u);
 }
예제 #4
0
파일: SCC.cs 프로젝트: allanma88/SampleCode
        private void Dfs(DigraphBase g, Stack <int> vertices)
        {
            foreach (var vertex in _vertices)
            {
                vertex.Color = Color.White;
            }

            foreach (int i in vertices)
            {
                if (_vertices[i].Color == Color.White)
                {
                    DfsVisit(g, i);
                    _count++;
                }
            }
        }
예제 #5
0
파일: SCC.cs 프로젝트: allanma88/SampleCode
        public SCC(DigraphBase g)
        {
            _ids      = new int[g.V];
            _vertices = new Vertex[g.V];
            for (int i = 0; i < g.V; i++)
            {
                _vertices[i] = new Vertex();
            }

            Stack <int> vertices = DfsOrder(g);
            DigraphBase gt       = g.Transpose();

            Dfs(gt, vertices);
            //call DFS.G/ to compute finishing times u:f for each vertex u
            //compute GT
            //call DFS.GT/, but in the main loop of DFS, consider the vertices in order of decreasing u:f (as computed in line 1)
            //output the vertices of each tree in the depth-first forest formed in line 3 as a separate strongly connected component
        }
예제 #6
0
파일: SCC.cs 프로젝트: allanma88/SampleCode
        private Stack <int> DfsOrder(DigraphBase g)
        {
            foreach (var vertex in _vertices)
            {
                vertex.Color = Color.White;
            }

            Stack <int> stack = new Stack <int>();

            _time = 0;
            for (int i = 0; i < g.V; i++)
            {
                if (_vertices[i].Color == Color.White)
                {
                    DfsOrderVisit(g, i, stack);
                }
            }

            return(stack);
        }