EdgeWeight rewrite

This commit is contained in:
glax 2023-04-09 17:00:28 +02:00
parent 05ae0bff6e
commit 5efec08bbc
3 changed files with 11 additions and 7 deletions

View File

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

View File

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

View File

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