Added checks if item already in queue, only update direct-distance if it not already calculated.
This commit is contained in:
parent
2ca4207fd7
commit
9448187452
@ -27,18 +27,18 @@ public static partial class Pathfinder
|
||||
OsmNode? neighbor = regionManager.GetNode(edge.neighborId, edge.neighborRegion);
|
||||
if (neighbor is not null)
|
||||
{
|
||||
if (Math.Abs(neighbor.directDistanceToGoal - double.MaxValue) < 1)
|
||||
neighbor.directDistanceToGoal = Utils.DistanceBetween(neighbor, goalNode);
|
||||
double newPotentialLength = currentNode.currentPathLength + Utils.DistanceBetween(currentNode, neighbor);
|
||||
if (newPotentialLength < neighbor.currentPathLength)
|
||||
{
|
||||
neighbor.previousPathNode = currentNode;
|
||||
neighbor.currentPathLength = newPotentialLength;
|
||||
neighbor.directDistanceToGoal = Utils.DistanceBetween(neighbor, goalNode);
|
||||
|
||||
if (neighbor.Equals(goalNode))
|
||||
{
|
||||
stop = true;
|
||||
}
|
||||
else if(!stop)
|
||||
if(neighbor.Equals(goalNode))
|
||||
return GetRouteFromCalc(goalNode, regionManager);
|
||||
//stop = true;
|
||||
if (!toVisit.UnorderedItems.Any(item => item.Element.Equals(neighbor)) && !stop)
|
||||
{
|
||||
toVisit.Enqueue(neighbor, neighbor.directDistanceToGoal);
|
||||
}
|
||||
|
@ -29,22 +29,24 @@ public static partial class Pathfinder
|
||||
OsmNode? neighbor = regionManager.GetNode(edge.neighborId, edge.neighborRegion);
|
||||
if (neighbor is not null)
|
||||
{
|
||||
if (Math.Abs(neighbor.directDistanceToGoal - double.MaxValue) < 1)
|
||||
neighbor.directDistanceToGoal = Utils.DistanceBetween(neighbor, goalNode);
|
||||
|
||||
double newPotentialWeight = currentNode.currentPathWeight +
|
||||
EdgeWeight(currentNode, edge, vehicle, regionManager);
|
||||
|
||||
if (newPotentialWeight < neighbor.currentPathWeight)
|
||||
{
|
||||
neighbor.previousPathNode = currentNode;
|
||||
neighbor.currentPathLength = currentNode.currentPathLength + Utils.DistanceBetween(currentNode, neighbor);
|
||||
neighbor.currentPathWeight = newPotentialWeight;
|
||||
neighbor.directDistanceToGoal = Utils.DistanceBetween(neighbor, goalNode);
|
||||
|
||||
if (neighbor.Equals(goalNode))
|
||||
|
||||
if(neighbor.Equals(goalNode))
|
||||
return GetRouteFromCalc(goalNode, regionManager);
|
||||
//stop = true;
|
||||
if (!toVisit.UnorderedItems.Any(item => item.Element.Equals(neighbor)) && !stop)
|
||||
{
|
||||
stop = true;
|
||||
}
|
||||
else if(!stop)
|
||||
{
|
||||
toVisit.Enqueue(neighbor, neighbor.directDistanceToGoal);
|
||||
toVisit.Enqueue(neighbor, neighbor.currentPathWeight + neighbor.directDistanceToGoal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user