public List <INode> Execute(INode start, INode finish) { //vstupni na 0 foreach (string nulkey in g.Nodes.Keys) { INode nulled = g.FindNode(nulkey); nulled.SetPredchudce(null); nulled.SetRank(double.PositiveInfinity); } priority = new PriorityQueue <double, string>(); ShortestPathNodes = new List <INode>(); // marked = new Dictionary<string, string>(); start.SetRank(0.0); priority.Add(new KeyValuePair <double, string>(start.GetRank(), start.GetId())); //vložení poèáteèního vrcholu while (!priority.IsEmpty) { INode node = g.FindNode(priority.DequeueValue()); INode next; foreach (Follower f in node.GetFollowers()) // vsechny nasledniky { string key; double dist; if (f.GetFollowingNode(out key, out dist)) // je pruchozi { next = g.FindNode(key); if ((dist + node.GetRank()) < next.GetRank()) { priority.Remove(new KeyValuePair <double, string>(next.GetRank(), next.GetId())); next.SetRank(dist + node.GetRank()); // novej rank next.SetPredchudce(node); // marked.Add(next.GetId(),node.GetId()); // predchudce nexta je node (key, key) priority.Add(new KeyValuePair <double, string>(next.GetRank(), next.GetId())); } ; } } } /*Vypis*/ for (INode inode = finish; inode != null; inode = inode.GetPredchudce()) { ShortestPathNodes.Add(inode); } /* * for (INode inode = finish; !inode.Equals(start); inode = inode.GetPredchudce()) * { * ShortestPathNodes.Add(inode); * } * ShortestPathNodes.Add(start);*/ ShortestPathNodes.Reverse(); return(ShortestPathNodes); }