CustomAStar now returns ValueTuple with calctime and path as result
This commit is contained in:
@ -6,13 +6,18 @@ namespace Pathfinding;
|
||||
|
||||
public static class Pathfinder
|
||||
{
|
||||
public static List<PathNode> CustomAStar(string workingDir, Coordinates start, Coordinates goal, Tag.SpeedType vehicle)
|
||||
public static ValueTuple<TimeSpan, List<PathNode>> CustomAStar(string workingDir, Coordinates start, Coordinates goal, Tag.SpeedType vehicle)
|
||||
{
|
||||
DateTime startTime = DateTime.Now;
|
||||
TimeSpan calcTime;
|
||||
RegionManager regionManager = new (workingDir);
|
||||
OsmNode? startNode = ClosestNodeToCoordinates(start, vehicle, ref regionManager);
|
||||
OsmNode? goalNode = ClosestNodeToCoordinates(goal, vehicle, ref regionManager);
|
||||
if (startNode == null || goalNode == null)
|
||||
return new List<PathNode>();
|
||||
{
|
||||
calcTime = DateTime.Now - startTime;
|
||||
return new ValueTuple<TimeSpan, List<PathNode>>(calcTime, new List<PathNode>());
|
||||
}
|
||||
|
||||
PriorityQueue<OsmNode, double> toVisit = new();
|
||||
toVisit.Enqueue(startNode, 0);
|
||||
@ -24,7 +29,7 @@ public static class Pathfinder
|
||||
while (toVisit.Count > 0)
|
||||
{
|
||||
OsmNode closestNodeToGoal = toVisit.Dequeue();
|
||||
Console.WriteLine($"{toVisit.Count:000} {closestNodeToGoal.directDistanceToGoal:#.00} current:{closestNodeToGoal}");
|
||||
//Console.WriteLine($"{toVisit.Count:000} {closestNodeToGoal.directDistanceToGoal:#.00} current:{closestNodeToGoal}");
|
||||
|
||||
foreach (OsmEdge edge in closestNodeToGoal.edges)
|
||||
{
|
||||
@ -62,8 +67,9 @@ public static class Pathfinder
|
||||
currentNode = currentNode.previousPathNode;
|
||||
}
|
||||
path.Reverse();
|
||||
|
||||
return path;
|
||||
|
||||
calcTime = DateTime.Now - startTime;
|
||||
return new ValueTuple<TimeSpan, List<PathNode>>(calcTime, path);
|
||||
}
|
||||
|
||||
public static OsmNode? ClosestNodeToCoordinates(Coordinates coordinates, Tag.SpeedType vehicle, ref RegionManager regionManager)
|
||||
|
Reference in New Issue
Block a user