示例#1
0
        public AcyclicShortestPath(EdgeWeightedDigraph g, int s)
        {
            edgeTo = new DirectedEdge[g.Vcount];
            distTo = new double[g.Vcount];
            for (int i = 0; i < g.Vcount; i++)
            {
                distTo[i] = double.PositiveInfinity;
            }
            distTo[s] = 0.0;
            var topo = new EdgeWeightedTopological(g);

            foreach (int v in topo.Order())
            {
                foreach (var e in g.Adj(v))
                {
                    Relax(e);
                }
            }
        }
        public AcyclicLongestPath(EdgeWeightedDigraph g, int s)
        {
            distTo = new double[g.Vcount];
            edgeTo = new DirectedEdge[g.Vcount];
            for (int i = 0; i < g.Vcount; i++)
            {
                distTo[i] = double.NegativeInfinity;
            }
            distTo[s] = 0.0;
            var topo = new EdgeWeightedTopological(g);

            if (!topo.IsDAG())
            {
                throw new ArgumentException("Digraph is not acyclic");
            }
            foreach (int i in topo.Order())
            {
                foreach (var e in g.Adj(i))
                {
                    Relax(e);
                }
            }
        }