2023-02-03 23:35:22 +01:00
|
|
|
|
using OSMDatastructure;
|
2023-03-14 17:00:59 +01:00
|
|
|
|
using OSMDatastructure.Graph;
|
2023-02-03 23:35:22 +01:00
|
|
|
|
|
|
|
|
|
namespace Pathfinding;
|
|
|
|
|
|
2023-04-09 16:17:15 +02:00
|
|
|
|
public static partial class Pathfinder
|
2023-02-03 23:35:22 +01:00
|
|
|
|
{
|
2023-04-06 02:23:12 +02:00
|
|
|
|
|
2023-04-09 16:17:15 +02:00
|
|
|
|
private static ValueTuple<OsmNode?, OsmNode?> SetupNodes(Coordinates startCoordinates, Coordinates goalCoordinates, RegionManager regionManager )
|
|
|
|
|
{
|
|
|
|
|
ValueTuple<OsmNode?, OsmNode?> retTuple = new();
|
2023-04-09 16:41:42 +02:00
|
|
|
|
retTuple.Item1 = regionManager.ClosestNodeToCoordinates(startCoordinates, Tag.SpeedType.road);
|
|
|
|
|
retTuple.Item2 = regionManager.ClosestNodeToCoordinates(goalCoordinates, Tag.SpeedType.road);
|
2023-04-09 16:17:15 +02:00
|
|
|
|
if (retTuple.Item1 is null || retTuple.Item2 is null)
|
|
|
|
|
return retTuple;
|
|
|
|
|
retTuple.Item1.currentPathWeight = 0;
|
|
|
|
|
retTuple.Item1.currentPathLength = 0;
|
|
|
|
|
retTuple.Item1.directDistanceToGoal = Utils.DistanceBetween(retTuple.Item1, retTuple.Item2);
|
|
|
|
|
return retTuple;
|
2023-02-03 23:35:22 +01:00
|
|
|
|
}
|
2023-04-09 16:17:15 +02:00
|
|
|
|
|
2023-04-06 02:23:12 +02:00
|
|
|
|
private static double EdgeWeight(OsmNode node1, OsmNode node2, ulong wayId, Tag.SpeedType vehicle, ref RegionManager regionManager)
|
|
|
|
|
{
|
|
|
|
|
double distance = Utils.DistanceBetween(node1, node2);
|
2023-04-09 16:41:42 +02:00
|
|
|
|
double speed = regionManager.GetSpeedForEdge(node1, wayId, vehicle);
|
2023-04-06 02:23:12 +02:00
|
|
|
|
if (speed is not 0)
|
|
|
|
|
return distance / speed;
|
2023-04-06 02:32:04 +02:00
|
|
|
|
return double.PositiveInfinity;
|
2023-04-06 02:23:12 +02:00
|
|
|
|
}
|
2023-02-03 23:35:22 +01:00
|
|
|
|
}
|