Try improving priority

This commit is contained in:
glax 2023-04-09 22:10:58 +02:00
parent c1557b7678
commit 874d60992e
2 changed files with 23 additions and 37 deletions

View File

@ -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;
}
}

View File

@ -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));
}
}
}