From 5efec08bbc1530d493ac3297cf1af99d4f8c8527 Mon Sep 17 00:00:00 2001 From: glax Date: Sun, 9 Apr 2023 17:00:28 +0200 Subject: [PATCH] EdgeWeight rewrite --- Pathfinding/Pathfinder.cs | 13 ++++++++----- Pathfinding/Pathfinder_Distance.cs | 2 ++ Pathfinding/Pathfinder_Time.cs | 3 +-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Pathfinding/Pathfinder.cs b/Pathfinding/Pathfinder.cs index 66b2bea..7350f1b 100644 --- a/Pathfinding/Pathfinder.cs +++ b/Pathfinding/Pathfinder.cs @@ -19,12 +19,15 @@ public static partial class Pathfinder return retTuple; } - private static double EdgeWeight(OsmNode node1, OsmNode node2, ulong wayId, Tag.SpeedType vehicle, ref RegionManager regionManager) + private static double EdgeWeight(OsmNode node1, OsmEdge edge, Tag.SpeedType vehicle, RegionManager regionManager) { + OsmNode? node2 = regionManager.GetNode(edge.neighborId, edge.neighborRegion); + if (node2 is null) + return double.MaxValue; double distance = Utils.DistanceBetween(node1, node2); - double speed = regionManager.GetSpeedForEdge(node1, wayId, vehicle); - if (speed is not 0) - return distance / speed; - return double.PositiveInfinity; + double speed = regionManager.GetSpeedForEdge(node1, edge.wayId, vehicle); + if (speed is 0) + return double.MaxValue; + return distance / speed; } } \ No newline at end of file diff --git a/Pathfinding/Pathfinder_Distance.cs b/Pathfinding/Pathfinder_Distance.cs index 485dfeb..3e66471 100644 --- a/Pathfinding/Pathfinder_Distance.cs +++ b/Pathfinding/Pathfinder_Distance.cs @@ -32,6 +32,8 @@ public static partial class Pathfinder { neighbor.previousPathNode = closestNodeToGoal; neighbor.currentPathLength = newPotentialLength; + neighbor.currentPathWeight = closestNodeToGoal.currentPathWeight + + EdgeWeight(closestNodeToGoal, edge, Tag.SpeedType.road, regionManager); neighbor.directDistanceToGoal = Utils.DistanceBetween(neighbor, goalNode); if (neighbor.Equals(goalNode)) diff --git a/Pathfinding/Pathfinder_Time.cs b/Pathfinding/Pathfinder_Time.cs index bea0adb..a3bba80 100644 --- a/Pathfinding/Pathfinder_Time.cs +++ b/Pathfinding/Pathfinder_Time.cs @@ -29,8 +29,7 @@ public static partial class Pathfinder if (neighbor is not null) { double newPotentialWeight = closestNodeToGoal.currentPathLength + - EdgeWeight(closestNodeToGoal, neighbor, edge.wayId, vehicle, - ref regionManager); + EdgeWeight(closestNodeToGoal, edge, vehicle, regionManager); if (newPotentialWeight < neighbor.currentPathWeight) { neighbor.previousPathNode = closestNodeToGoal;