Fixed instant depletion of toVisit()
This commit is contained in:
parent
9444e2ac8e
commit
d7b084659a
@ -10,7 +10,6 @@ public class Pathfinder
|
||||
{
|
||||
RegionManager regionManager = new RegionManager(workingDir);
|
||||
Region startRegion, goalRegion;
|
||||
OsmNode? startNode, goalNode;
|
||||
try
|
||||
{
|
||||
startRegion = regionManager.GetRegion(start);
|
||||
@ -21,18 +20,18 @@ public class Pathfinder
|
||||
throw new Exception(string.Format("No region at coordinates {0}", e.FileName), e);
|
||||
}
|
||||
|
||||
startNode = ClosestNodeToCoordinates(start, startRegion);
|
||||
goalNode = ClosestNodeToCoordinates(goal, goalRegion);
|
||||
OsmNode? startNode = ClosestNodeToCoordinates(start, startRegion);
|
||||
OsmNode? goalNode = ClosestNodeToCoordinates(goal, goalRegion);
|
||||
if (startNode == null || goalNode == null)
|
||||
return new List<OsmNode>();
|
||||
|
||||
List<OsmNode> toVisit = new() { startNode };
|
||||
OsmNode closestNodeToGoal;
|
||||
OsmNode closestNodeToGoal = toVisit.First();
|
||||
closestNodeToGoal.currentPathWeight = 0;
|
||||
bool stop = false;
|
||||
|
||||
while (toVisit.Count > 0 && !stop)
|
||||
{
|
||||
Console.WriteLine("toVisit length: {0}", toVisit.Count.ToString());
|
||||
closestNodeToGoal = toVisit.First();
|
||||
foreach (OsmNode node in toVisit)
|
||||
{
|
||||
@ -46,11 +45,10 @@ public class Pathfinder
|
||||
}
|
||||
}
|
||||
|
||||
foreach (OsmEdge connection in closestNodeToGoal.edges)
|
||||
foreach (OsmEdge edge in closestNodeToGoal.edges)
|
||||
{
|
||||
OsmNode? neighbor = regionManager.GetNode(connection.neighborCoordinates);
|
||||
Console.WriteLine(neighbor);
|
||||
if (neighbor != null && neighbor.currentPathWeight < closestNodeToGoal.currentPathWeight + Utils.DistanceBetween(closestNodeToGoal, neighbor))
|
||||
OsmNode? neighbor = regionManager.GetNode(edge.neighborCoordinates);
|
||||
if (neighbor != null && neighbor.currentPathWeight > closestNodeToGoal.currentPathWeight + Utils.DistanceBetween(closestNodeToGoal, neighbor))
|
||||
{
|
||||
neighbor.previousPathNode = closestNodeToGoal;
|
||||
neighbor.currentPathWeight = closestNodeToGoal.currentPathWeight +
|
||||
|
Loading…
Reference in New Issue
Block a user