Ejemplo n.º 1
0
 public DijkstraSP(IEdgeWeightedDIgraph G, int s) : base(G, s)
 {
     pq = new IndexMinPQ <double>(G.V);
     pq.Insert(s, 0.0);
     while (!pq.IsEmpty)
     {
         Relax(G, pq.DeleteMin());
     }
 }
Ejemplo n.º 2
0
        private IndexMinPQ <double> pq; //有效的横切边

        public PrimeMST(IEdgeWeightGraph G)
        {
            edgeTo = new Edge[G.V];
            distTo = new double[G.V];
            marked = new bool[G.V];
            for (int v = 0; v < G.V; v++)
            {
                distTo[v] = Double.PositiveInfinity;
            }
            pq        = new IndexMinPQ <double>(G.V);
            distTo[0] = 0.0;
            pq.Insert(0, 0.0); //顶点0权重初始化
            while (!pq.IsEmpty)
            {
                Visit(G, pq.DeleteMin());
            }
        }
Ejemplo n.º 3
0
        public PrimMinSpanningTree(EdgeWeightedGraph g)
        {
            edgeTo     = new Edge[g.VertexCount];
            distanceTo = new double[g.VertexCount];
            marked     = new bool[g.VertexCount];
            pq         = new IndexMinPQ <double>(g.VertexCount);
            for (int i = 0; i < g.VertexCount; i++)
            {
                distanceTo[i] = double.MaxValue;
            }

            distanceTo[0] = 0;
            pq.Insert(0, 0);
            while (!pq.IsEmpty())
            {
                Visit(g, pq.DeleteMin());
            }
        }
Ejemplo n.º 4
0
        public DijkstraShortestPath(EdgeWeightedDirectedGraph graph, int start)
        {
            EdgeTo = new DirectedEdge[graph.VertexCount];
            DistTo = new double[graph.VertexCount];
            pq     = new IndexMinPQ <double>(graph.VertexCount);

            for (int i = 0; i < graph.VertexCount; i++)
            {
                DistTo[i]     = double.PositiveInfinity;
                DistTo[start] = 0;

                pq.Insert(start, 0);
                while (!pq.IsEmpty())
                {
                    Relax(graph, pq.DeleteMin());
                }
            }
        }