public Topological(EdgeWeightedDigraph G)
        {
            DirectedCycle cycleFinder = new DirectedCycle(G);

            if (!cycleFinder.HasCycle())
            {
                DepthFirstOrder dfs = new DepthFirstOrder(G);
                order = dfs.ReversePost();
            }
        }
        private Stack <int> order;  //顶点的拓扑排序
        public Topological(Digraph G)
        {
            DirectedCycle cycleFinder = new DirectedCycle(G);//用于判断有向图G是否有环

            if (!cycleFinder.HasCycle())
            {
                DepthFirstOrder dfs = new DepthFirstOrder(G);
                order = dfs.ReversePost();
            }
        }
예제 #3
0
        private void FindNegativeCycle()
        {
            int V = edgeTo.Length;
            EdgeWeightedDigraph spt = new EdgeWeightedDigraph(V);

            for (int v = 0; v < V; v++)
            {
                if (edgeTo[v] != null)
                {
                    spt.AddEdge(edgeTo[v]);
                }
            }
            DirectedCycle cf = new DirectedCycle(spt);

            cycle = cf.Cycle();
        }