Exemple #1
0
        public DijkstraFindAllPathsResponse <TNode> FindAllPaths(TNode start)
        {
            InitSets(start);
            while (unexploredSet.Count > 0)
            {
                TNode  current          = unexploredSet.Pool();
                double distanceFromNode = distanceFromStartToNode.GetValueOrDefault(current);

                foreach (TNode neightboar in heuristicImpl.GetNeighboars(current))
                {
                    double distanceFromStart = distanceFromNode + heuristicImpl.VertexLength(current, neightboar);
                    double distanceToN       = distanceFromStartToNode.ContainsKey(neightboar) ? distanceFromStartToNode.GetValueOrDefault(neightboar) : double.MaxValue;
                    if (distanceFromStart < distanceToN)
                    {
                        ReplaceInDictionary(distanceFromStartToNode, neightboar, distanceFromStart);
                        ReplaceInDictionary(nodeToParent, neightboar, current);
                        if (!unexploredSet.Contains(neightboar))
                        {
                            unexploredSet.Add(neightboar, distanceFromStart);
                        }
                    }
                }
            }

            return(new DijkstraFindAllPathsResponse <TNode>
            {
                distances = distanceFromStartToNode,
                nodeToParent = nodeToParent
            });
        }
Exemple #2
0
 private void AddWithPriotiry(TNode node, IComparable priority)
 {
     if (!notEvaluatedNodes.Contains(node))
     {
         notEvaluatedNodes.Add(node, priority);
     }
 }