Example #1
0
 public Topological(EdgeWeightedDigraph g)
 {
     //EdgeWeightedDirectedCycle cycleFinder = new EdgeWeightedDirectedCycle(g);
     //if (!cycleFinder.HasCycle())
     //{
     DepthFirstOrder dfs = new DepthFirstOrder(g);
     this.Order = dfs.ReversePost;
     //}
 }
Example #2
0
 public Topological(Digraph g)
 {
     DirectedCycle cycleFinder = new DirectedCycle(g);
     if (!cycleFinder.HasCycle())
     {
         DepthFirstOrder dfs = new DepthFirstOrder(g);
         this.Order = dfs.ReversePost;
     }
 }
Example #3
0
        /// <summary>
        /// Computes the connected components of the directed graph G.
        /// </summary>
        /// <param name="g"></param>
        public KosarajuSCC(Digraph g)
        {
            this.Marked = new bool[g.V];
            this.ID = new int[g.V];

            DepthFirstOrder order = new DepthFirstOrder(g.Reverse());
            foreach (int v in order.ReversePost)
                if (!this.Marked[v])
                {
                    this.dfs(g, v);
                    this.Count++;
                }
        }
Example #4
0
        public void TestKosarajuSCCHasNotCycle()
        {
            Digraph g = new Digraph(6);
            g.AddEdge(0, 1);
            g.AddEdge(1, 2);
            g.AddEdge(2, 3);
            g.AddEdge(0, 4);
            g.AddEdge(4, 5);
            Debug.WriteLine(g.ToString());

            DepthFirstOrder dfs = new DepthFirstOrder(g);
            StringBuilder sb = new StringBuilder();
            foreach (var item in dfs.ReversePost)
                sb.Append(item + " ");
            Debug.WriteLine(sb.ToString());

            KosarajuSCC scc = new KosarajuSCC(g);
            sb.Clear();
            for (int i = 0; i < scc.ID.Length; i++)
                sb.Append(i + " - " + scc.ID[i] + Environment.NewLine);
            Debug.WriteLine(sb.ToString());
        }