From 874d60992eeef0183d3881321dff357ff05c5440 Mon Sep 17 00:00:00 2001 From: glax Date: Sun, 9 Apr 2023 22:10:58 +0200 Subject: [PATCH] Try improving priority --- Pathfinding/Pathfinder.cs | 55 +++++++++++++--------------------- Pathfinding/Pathfinder_Time.cs | 5 ++-- 2 files changed, 23 insertions(+), 37 deletions(-) diff --git a/Pathfinding/Pathfinder.cs b/Pathfinding/Pathfinder.cs index ed11327..80bdbc3 100644 --- a/Pathfinding/Pathfinder.cs +++ b/Pathfinding/Pathfinder.cs @@ -30,37 +30,24 @@ public static partial class Pathfinder return speed is 0 ? double.MaxValue : distance / speed; } - private static double GetPriority(OsmNode current, OsmNode? previous, OsmEdge edge, Tag.SpeedType vehicle, RegionManager regionManager) + //TODO when refs are imported use same road + private static double GetPriority(OsmNode current, OsmEdge edge, Tag.SpeedType vehicle, RegionManager regionManager) { if (vehicle == Tag.SpeedType.any) return 1; - const double roadPriorityFactor = 1; - const double junctionFactor = 2; - const double wayChangeFactor = 2; + const double roadPriorityFactor = 1; + const double roadSpeedFactor = 0.0001; Region r = regionManager.GetRegion(current.coordinates)!; - double roadPriority = GetPriorityVehicleRoad(edge, vehicle, r) * 0.1 * roadPriorityFactor; - double roadSpeed = regionManager.GetSpeedForEdge(current, edge.wayId, vehicle); - - if(vehicle == Tag.SpeedType.pedestrian) - return (current.directDistanceToGoal / roadSpeed) * roadPriority; - - ulong previousWayId = UInt64.MaxValue; - if (previous?.edges is not null) - { - foreach (OsmEdge e in previous.edges) - if (e.neighborId.Equals(current.nodeId)) - { - previousWayId = e.wayId; - break; - } - } + double roadPriority = GetPriorityVehicleRoad(edge, vehicle, r) * roadPriorityFactor; + double roadSpeed = regionManager.GetSpeedForEdge(current, edge.wayId, vehicle) * roadSpeedFactor; - double junctionPriority = (current.edges.Count > 2 ? 1 : 0) * junctionFactor; - double wayChange = (previousWayId != edge.wayId ? 1 : 0) * wayChangeFactor; - - if(vehicle == Tag.SpeedType.car) - return (current.directDistanceToGoal / roadSpeed) * roadPriority * ((junctionPriority + wayChange) / 2); + if (vehicle == Tag.SpeedType.pedestrian) + return current.directDistanceToGoal / roadPriority; + + + if (vehicle == Tag.SpeedType.car) + return current.directDistanceToGoal / roadPriority; return double.MaxValue; } @@ -83,23 +70,21 @@ public static partial class Pathfinder case WayType.trunk_link: case WayType.primary: case WayType.primary_link: - return 1; + return 7; case WayType.secondary: case WayType.secondary_link: - return 2; case WayType.tertiary: case WayType.tertiary_link: - return 3; + return 4; case WayType.unclassified: case WayType.residential: case WayType.road: - return 4; case WayType.living_street: case WayType.service: case WayType.track: - return 5; + return 2; default: - return 100; + return 1; } } if (vehicle == Tag.SpeedType.pedestrian) @@ -113,20 +98,20 @@ public static partial class Pathfinder case WayType.steps: case WayType.residential: case WayType.living_street: - return 1; + return 10; case WayType.service: case WayType.cycleway: case WayType.bridleway: case WayType.road: case WayType.track: case WayType.unclassified: - return 2; + return 5; case WayType.tertiary: case WayType.tertiary_link: case WayType.escape: - return 5; + return 2; default: - return 100; + return 1; } } diff --git a/Pathfinding/Pathfinder_Time.cs b/Pathfinding/Pathfinder_Time.cs index 65a4d7b..23f2144 100644 --- a/Pathfinding/Pathfinder_Time.cs +++ b/Pathfinding/Pathfinder_Time.cs @@ -21,6 +21,7 @@ public static partial class Pathfinder while (toVisit.Count > 0) { OsmNode currentNode = toVisit.Dequeue(); + Console.WriteLine($"{toVisit.Count} {currentNode.directDistanceToGoal}"); foreach (OsmEdge edge in currentNode.edges.Where( edge => regionManager.TestValidConnectionForType(currentNode, edge, vehicle))) @@ -52,8 +53,8 @@ public static partial class Pathfinder return GetRouteFromCalc(goalNode, regionManager); } - if (!toVisit.UnorderedItems.Any(item => item.Element.Equals(neighbor))) - toVisit.Enqueue(neighbor, GetPriority(currentNode, currentNode.previousPathNode, edge, vehicle, regionManager)); + //if (!toVisit.UnorderedItems.Any(item => item.Element.Equals(neighbor))) + toVisit.Enqueue(neighbor, GetPriority(currentNode, edge, vehicle, regionManager)); } } }