Exemplo n.º 1
0
        public void Run()
        {
            IndexedPriorityQueue <double, int> pQ = new IndexedPriorityQueue <double, int>();

            for (int i = 0; i < vertexCount; ++i)
            {
                pQ.Insert(i, double.MaxValue);
            }

            pQ.Decrease_Key(source, 0);
            while (pQ.Count > 0)
            {
                KeyValuePair <double, int> kv = pQ.Extract_Minimum();
                vertexCost[kv.Value] = kv.Key;
                List <WeightedArc> edges = adjList.getEdges(kv.Value);
                foreach (WeightedArc e in edges)
                {
                    if (vertexCost[e.Vertex] > vertexCost[kv.Value] + e.Cost)
                    {
                        parent[e.Vertex] = kv.Value;
                        pQ.Decrease_Key(e.Vertex, vertexCost[kv.Value] + e.Cost);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void Run()
        {
            IndexedPriorityQueue<double, int> pQ = new IndexedPriorityQueue<double, int>();
            for(int i = 0; i < vertexCount; ++i)
                pQ.Insert(i, double.MaxValue);

            pQ.Decrease_Key(source, 0);
            while (pQ.Count > 0)
            {
                KeyValuePair<double, int> kv = pQ.Extract_Minimum();
                vertexCost[kv.Value] = kv.Key;
                List<WeightedArc> edges = adjList.getEdges(kv.Value);
                foreach (WeightedArc e in edges)
                {
                    if (vertexCost[e.Vertex] > vertexCost[kv.Value] + e.Cost)
                    {
                        parent[e.Vertex] = kv.Value;
                        pQ.Decrease_Key(e.Vertex, vertexCost[kv.Value] + e.Cost);
                    }
                }
            }
        }