Compare commits

..

5 Commits

2 changed files with 21 additions and 15 deletions

View File

@ -30,7 +30,7 @@ namespace astar
endNode.Value.Metric = 0f; endNode.Value.Metric = 0f;
double totalDistance = NodeUtils.DistanceBetween(startNode.Value, endNode.Value); double totalDistance = NodeUtils.DistanceBetween(startNode.Value, endNode.Value);
PriorityHelper priorityHelper = new(totalDistance, SpeedHelper.GetMaxSpeed(car)); PriorityHelper priorityHelper = new(totalDistance, SpeedHelper.GetTheoreticalMaxSpeed(car));
logger?.Log(LogLevel.Information, logger?.Log(LogLevel.Information,
"From {0:00.00000}#{1:000.00000} to {2:00.00000}#{3:000.00000} Great-Circle {4:00000.00}km", "From {0:00.00000}#{1:000.00000} to {2:00.00000}#{3:000.00000} Great-Circle {4:00000.00}km",
@ -44,21 +44,27 @@ namespace astar
ValueTuple<Node, Node>? meetingEnds = null; ValueTuple<Node, Node>? meetingEnds = null;
while (toVisitStart.Count > 0 && toVisitEnd.Count > 0) while (toVisitStart.Count > 0 && toVisitEnd.Count > 0)
{ {
ulong closestEndNodeId = toVisitEnd.UnorderedItems
.MinBy(n => graph.Nodes[n.Element].DistanceTo(startNode.Value)).Element;
Node closestEndNode = graph.Nodes[closestEndNodeId];
if (toVisitStart.Count >= toVisitEnd.Count && meetingEnds is null) if (toVisitStart.Count >= toVisitEnd.Count && meetingEnds is null)
{ {
for(int i = 0; i < toVisitStart.Count / 10 && meetingEnds is null; i++) for(int i = 0; i < Math.Min(toVisitStart.Count * 0.5, 50) && meetingEnds is null; i++)
meetingEnds = ExploreSide(true, graph, toVisitStart, rl, priorityHelper, endNode.Value, car, DefaultPriorityWeights, pathing, logger); meetingEnds = ExploreSide(true, graph, toVisitStart, rl, priorityHelper, closestEndNode, car, DefaultPriorityWeights, pathing, logger);
} }
if(meetingEnds is null) if(meetingEnds is null)
meetingEnds = ExploreSide(true, graph, toVisitStart, rl, priorityHelper, endNode.Value, car, DefaultPriorityWeights, pathing, logger); meetingEnds = ExploreSide(true, graph, toVisitStart, rl, priorityHelper, closestEndNode, car, DefaultPriorityWeights, pathing, logger);
ulong closestStartNodeId = toVisitStart.UnorderedItems
.MinBy(n => graph.Nodes[n.Element].DistanceTo(endNode.Value)).Element;
Node closestStartNode = graph.Nodes[closestStartNodeId];
if (toVisitEnd.Count >= toVisitStart.Count && meetingEnds is null) if (toVisitEnd.Count >= toVisitStart.Count && meetingEnds is null)
{ {
for(int i = 0; i < toVisitEnd.Count / 10 && meetingEnds is null; i++) for(int i = 0; i < Math.Min(toVisitEnd.Count * 0.5, 50) && meetingEnds is null; i++)
meetingEnds = ExploreSide(false, graph, toVisitEnd, rl, priorityHelper, startNode.Value, car, DefaultPriorityWeights, pathing, logger); meetingEnds = ExploreSide(false, graph, toVisitEnd, rl, priorityHelper, closestStartNode, car, DefaultPriorityWeights, pathing, logger);
} }
if(meetingEnds is null) if(meetingEnds is null)
meetingEnds = ExploreSide(false, graph, toVisitEnd, rl, priorityHelper, startNode.Value, car, DefaultPriorityWeights, pathing, logger); meetingEnds = ExploreSide(false, graph, toVisitEnd, rl, priorityHelper, closestStartNode, car, DefaultPriorityWeights, pathing, logger);
if (meetingEnds is not null) if (meetingEnds is not null)
break; break;

View File

@ -8,12 +8,12 @@ internal static class SpeedHelper
{ {
byte maxspeed = way.GetMaxSpeed(); byte maxspeed = way.GetMaxSpeed();
if (maxspeed != 0) if (maxspeed != 0)
return maxspeed; return (byte)(maxspeed * 0.85);
HighwayType highwayType = way.GetHighwayType(); HighwayType highwayType = way.GetHighwayType();
return car ? SpeedCar[highwayType] : SpeedPedestrian[highwayType]; return car ? SpeedCar[highwayType] : SpeedPedestrian[highwayType];
} }
public static byte GetMaxSpeed(bool car = true) public static byte GetTheoreticalMaxSpeed(bool car = true)
{ {
return car ? SpeedCar.MaxBy(s => s.Value).Value : SpeedPedestrian.MaxBy(s => s.Value).Value; return car ? SpeedCar.MaxBy(s => s.Value).Value : SpeedPedestrian.MaxBy(s => s.Value).Value;
} }
@ -52,18 +52,18 @@ internal static class SpeedHelper
private static Dictionary<HighwayType, byte> SpeedCar = new() { private static Dictionary<HighwayType, byte> SpeedCar = new() {
{ HighwayType.NONE, 0 }, { HighwayType.NONE, 0 },
{ HighwayType.motorway, 110 }, { HighwayType.motorway, 120 },
{ HighwayType.trunk, 80 }, { HighwayType.trunk, 80 },
{ HighwayType.primary, 80 }, { HighwayType.primary, 70 },
{ HighwayType.secondary, 80 }, { HighwayType.secondary, 70 },
{ HighwayType.tertiary, 70 }, { HighwayType.tertiary, 70 },
{ HighwayType.unclassified, 30 }, { HighwayType.unclassified, 30 },
{ HighwayType.residential, 10 }, { HighwayType.residential, 10 },
{ HighwayType.motorway_link, 50 }, { HighwayType.motorway_link, 70 },
{ HighwayType.trunk_link, 50 }, { HighwayType.trunk_link, 50 },
{ HighwayType.primary_link, 50 }, { HighwayType.primary_link, 50 },
{ HighwayType.secondary_link, 30 }, { HighwayType.secondary_link, 50 },
{ HighwayType.tertiary_link, 25 }, { HighwayType.tertiary_link, 40 },
{ HighwayType.living_street, 5 }, { HighwayType.living_street, 5 },
{ HighwayType.service, 0 }, { HighwayType.service, 0 },
{ HighwayType.pedestrian, 0 }, { HighwayType.pedestrian, 0 },