Try improving priority
This commit is contained in:
parent
c1557b7678
commit
874d60992e
@ -30,37 +30,24 @@ public static partial class Pathfinder
|
|||||||
return speed is 0 ? double.MaxValue : distance / speed;
|
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)
|
if (vehicle == Tag.SpeedType.any)
|
||||||
return 1;
|
return 1;
|
||||||
const double roadPriorityFactor = 1;
|
const double roadPriorityFactor = 1;
|
||||||
const double junctionFactor = 2;
|
const double roadSpeedFactor = 0.0001;
|
||||||
const double wayChangeFactor = 2;
|
|
||||||
Region r = regionManager.GetRegion(current.coordinates)!;
|
Region r = regionManager.GetRegion(current.coordinates)!;
|
||||||
|
|
||||||
double roadPriority = GetPriorityVehicleRoad(edge, vehicle, r) * 0.1 * roadPriorityFactor;
|
double roadPriority = GetPriorityVehicleRoad(edge, vehicle, r) * roadPriorityFactor;
|
||||||
double roadSpeed = regionManager.GetSpeedForEdge(current, edge.wayId, vehicle);
|
double roadSpeed = regionManager.GetSpeedForEdge(current, edge.wayId, vehicle) * roadSpeedFactor;
|
||||||
|
|
||||||
if (vehicle == Tag.SpeedType.pedestrian)
|
if (vehicle == Tag.SpeedType.pedestrian)
|
||||||
return (current.directDistanceToGoal / roadSpeed) * roadPriority;
|
return current.directDistanceToGoal / 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 junctionPriority = (current.edges.Count > 2 ? 1 : 0) * junctionFactor;
|
|
||||||
double wayChange = (previousWayId != edge.wayId ? 1 : 0) * wayChangeFactor;
|
|
||||||
|
|
||||||
if (vehicle == Tag.SpeedType.car)
|
if (vehicle == Tag.SpeedType.car)
|
||||||
return (current.directDistanceToGoal / roadSpeed) * roadPriority * ((junctionPriority + wayChange) / 2);
|
return current.directDistanceToGoal / roadPriority;
|
||||||
|
|
||||||
return double.MaxValue;
|
return double.MaxValue;
|
||||||
}
|
}
|
||||||
@ -83,23 +70,21 @@ public static partial class Pathfinder
|
|||||||
case WayType.trunk_link:
|
case WayType.trunk_link:
|
||||||
case WayType.primary:
|
case WayType.primary:
|
||||||
case WayType.primary_link:
|
case WayType.primary_link:
|
||||||
return 1;
|
return 7;
|
||||||
case WayType.secondary:
|
case WayType.secondary:
|
||||||
case WayType.secondary_link:
|
case WayType.secondary_link:
|
||||||
return 2;
|
|
||||||
case WayType.tertiary:
|
case WayType.tertiary:
|
||||||
case WayType.tertiary_link:
|
case WayType.tertiary_link:
|
||||||
return 3;
|
return 4;
|
||||||
case WayType.unclassified:
|
case WayType.unclassified:
|
||||||
case WayType.residential:
|
case WayType.residential:
|
||||||
case WayType.road:
|
case WayType.road:
|
||||||
return 4;
|
|
||||||
case WayType.living_street:
|
case WayType.living_street:
|
||||||
case WayType.service:
|
case WayType.service:
|
||||||
case WayType.track:
|
case WayType.track:
|
||||||
return 5;
|
return 2;
|
||||||
default:
|
default:
|
||||||
return 100;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (vehicle == Tag.SpeedType.pedestrian)
|
if (vehicle == Tag.SpeedType.pedestrian)
|
||||||
@ -113,20 +98,20 @@ public static partial class Pathfinder
|
|||||||
case WayType.steps:
|
case WayType.steps:
|
||||||
case WayType.residential:
|
case WayType.residential:
|
||||||
case WayType.living_street:
|
case WayType.living_street:
|
||||||
return 1;
|
return 10;
|
||||||
case WayType.service:
|
case WayType.service:
|
||||||
case WayType.cycleway:
|
case WayType.cycleway:
|
||||||
case WayType.bridleway:
|
case WayType.bridleway:
|
||||||
case WayType.road:
|
case WayType.road:
|
||||||
case WayType.track:
|
case WayType.track:
|
||||||
case WayType.unclassified:
|
case WayType.unclassified:
|
||||||
return 2;
|
return 5;
|
||||||
case WayType.tertiary:
|
case WayType.tertiary:
|
||||||
case WayType.tertiary_link:
|
case WayType.tertiary_link:
|
||||||
case WayType.escape:
|
case WayType.escape:
|
||||||
return 5;
|
return 2;
|
||||||
default:
|
default:
|
||||||
return 100;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ public static partial class Pathfinder
|
|||||||
while (toVisit.Count > 0)
|
while (toVisit.Count > 0)
|
||||||
{
|
{
|
||||||
OsmNode currentNode = toVisit.Dequeue();
|
OsmNode currentNode = toVisit.Dequeue();
|
||||||
|
Console.WriteLine($"{toVisit.Count} {currentNode.directDistanceToGoal}");
|
||||||
|
|
||||||
foreach (OsmEdge edge in currentNode.edges.Where(
|
foreach (OsmEdge edge in currentNode.edges.Where(
|
||||||
edge => regionManager.TestValidConnectionForType(currentNode, edge, vehicle)))
|
edge => regionManager.TestValidConnectionForType(currentNode, edge, vehicle)))
|
||||||
@ -52,8 +53,8 @@ public static partial class Pathfinder
|
|||||||
|
|
||||||
return GetRouteFromCalc(goalNode, regionManager);
|
return GetRouteFromCalc(goalNode, regionManager);
|
||||||
}
|
}
|
||||||
if (!toVisit.UnorderedItems.Any(item => item.Element.Equals(neighbor)))
|
//if (!toVisit.UnorderedItems.Any(item => item.Element.Equals(neighbor)))
|
||||||
toVisit.Enqueue(neighbor, GetPriority(currentNode, currentNode.previousPathNode, edge, vehicle, regionManager));
|
toVisit.Enqueue(neighbor, GetPriority(currentNode, edge, vehicle, regionManager));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user