コード例 #1
0
ファイル: AcyclicSP.cs プロジェクト: popomama/ALG2017
        public AcyclicSP(EdgeWeightedDiagraph ewg, int source)
        {
            edgeTo = new DirectedEdge[ewg.V()];
            distTo = new double[ewg.V()];
            for (int i = 0; i < ewg.V(); i++)
            {
                distTo[i] = double.PositiveInfinity;
            }
            distTo[source] = 0;
            TopologicalOrder tlOrder = new TopologicalOrder(ewg);

            foreach (int v in tlOrder.Order())
            {
                Relax(ewg, v);
            }
        }
コード例 #2
0
ファイル: BellmanFordSP.cs プロジェクト: popomama/ALG2017
        //Bellman Ford has the complexity of O(VE)
        public BellmanFordSP(EdgeWeightedDiagraph ewg, int source)
        {
            vertexNum = ewg.V();
            distTo    = new double[vertexNum];
            edgeTo    = new DirectedEdge[vertexNum];

            for (int i = 0; i < vertexNum; i++)
            {
                distTo[i] = double.PositiveInfinity;
            }
            distTo[source] = 0.0;
        }
コード例 #3
0
        public DijkstraSP(EdgeWeightedDiagraph g, int source)
        {
            vertexNumber = g.V();
            distTo       = new double[vertexNumber];
            for (int i = 0; i < vertexNumber; i++)
            {
                distTo[i] = double.PositiveInfinity;
            }
            distTo[source] = 0.0;

            edgeTo = new DirectedEdge[vertexNumber];

            pq = new IndexMinPQ <double>(vertexNumber);
            pq.Insert(source, 0.0);

            while (!pq.IsEmpty())
            {
                int current = pq.DelMin();
                Relax(g, current);
            }
        }