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);
|
OsmNode? neighbor = regionManager.GetNode(edge.neighborId, edge.neighborRegion);
|
||||||
if (neighbor is not null)
|
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);
|
double newPotentialLength = currentNode.currentPathLength + Utils.DistanceBetween(currentNode, neighbor);
|
||||||
if (newPotentialLength < neighbor.currentPathLength)
|
if (newPotentialLength < neighbor.currentPathLength)
|
||||||
{
|
{
|
||||||
neighbor.previousPathNode = currentNode;
|
neighbor.previousPathNode = currentNode;
|
||||||
neighbor.currentPathLength = newPotentialLength;
|
neighbor.currentPathLength = newPotentialLength;
|
||||||
neighbor.directDistanceToGoal = Utils.DistanceBetween(neighbor, goalNode);
|
|
||||||
|
|
||||||
if (neighbor.Equals(goalNode))
|
if(neighbor.Equals(goalNode))
|
||||||
{
|
return GetRouteFromCalc(goalNode, regionManager);
|
||||||
stop = true;
|
//stop = true;
|
||||||
}
|
if (!toVisit.UnorderedItems.Any(item => item.Element.Equals(neighbor)) && !stop)
|
||||||
else if(!stop)
|
|
||||||
{
|
{
|
||||||
toVisit.Enqueue(neighbor, neighbor.directDistanceToGoal);
|
toVisit.Enqueue(neighbor, neighbor.directDistanceToGoal);
|
||||||
}
|
}
|
||||||
|
@ -29,22 +29,24 @@ public static partial class Pathfinder
|
|||||||
OsmNode? neighbor = regionManager.GetNode(edge.neighborId, edge.neighborRegion);
|
OsmNode? neighbor = regionManager.GetNode(edge.neighborId, edge.neighborRegion);
|
||||||
if (neighbor is not null)
|
if (neighbor is not null)
|
||||||
{
|
{
|
||||||
|
if (Math.Abs(neighbor.directDistanceToGoal - double.MaxValue) < 1)
|
||||||
|
neighbor.directDistanceToGoal = Utils.DistanceBetween(neighbor, goalNode);
|
||||||
|
|
||||||
double newPotentialWeight = currentNode.currentPathWeight +
|
double newPotentialWeight = currentNode.currentPathWeight +
|
||||||
EdgeWeight(currentNode, edge, vehicle, regionManager);
|
EdgeWeight(currentNode, edge, vehicle, regionManager);
|
||||||
|
|
||||||
if (newPotentialWeight < neighbor.currentPathWeight)
|
if (newPotentialWeight < neighbor.currentPathWeight)
|
||||||
{
|
{
|
||||||
neighbor.previousPathNode = currentNode;
|
neighbor.previousPathNode = currentNode;
|
||||||
neighbor.currentPathLength = currentNode.currentPathLength + Utils.DistanceBetween(currentNode, neighbor);
|
neighbor.currentPathLength = currentNode.currentPathLength + Utils.DistanceBetween(currentNode, neighbor);
|
||||||
neighbor.currentPathWeight = newPotentialWeight;
|
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;
|
toVisit.Enqueue(neighbor, neighbor.currentPathWeight + neighbor.directDistanceToGoal);
|
||||||
}
|
|
||||||
else if(!stop)
|
|
||||||
{
|
|
||||||
toVisit.Enqueue(neighbor, neighbor.directDistanceToGoal);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user