Compare commits
2 Commits
6eab23ff16
...
0f53ae579c
Author | SHA1 | Date | |
---|---|---|---|
0f53ae579c | |||
d8f8a41dcc |
@ -37,7 +37,7 @@ app.MapGet("/getRouteTime", (float latStart, float lonStart, float latEnd, float
|
|||||||
app.MapGet("/getClosestNode", (float lat, float lon) =>
|
app.MapGet("/getClosestNode", (float lat, float lon) =>
|
||||||
{
|
{
|
||||||
RegionManager regionManager = new RegionManager("D:/stuttgart-regbez-latest");
|
RegionManager regionManager = new RegionManager("D:/stuttgart-regbez-latest");
|
||||||
return regionManager.ClosestNodeToCoordinates(new Coordinates(lat, lon), Tag.SpeedType.road);
|
return regionManager.ClosestNodeToCoordinates(new Coordinates(lat, lon), Tag.SpeedType.any);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Configure the HTTP request pipeline.
|
// Configure the HTTP request pipeline.
|
||||||
|
@ -163,5 +163,5 @@ public class Tag
|
|||||||
public enum WayType : byte { NONE, motorway, trunk, primary, secondary, tertiary, unclassified, residential, motorway_link, trunk_link, primary_link, secondary_link, tertiary_link, living_street, service, pedestrian, track, bus_guideway, escape, raceway, road, busway, footway, bridleway, steps, corridor, path, cycleway, construction }
|
public enum WayType : byte { NONE, motorway, trunk, primary, secondary, tertiary, unclassified, residential, motorway_link, trunk_link, primary_link, secondary_link, tertiary_link, living_street, service, pedestrian, track, bus_guideway, escape, raceway, road, busway, footway, bridleway, steps, corridor, path, cycleway, construction }
|
||||||
// ReSharper restore InconsistentNaming
|
// ReSharper restore InconsistentNaming
|
||||||
|
|
||||||
public enum SpeedType { pedestrian, car, road }
|
public enum SpeedType { pedestrian, car, any }
|
||||||
}
|
}
|
@ -7,10 +7,11 @@ namespace Pathfinding;
|
|||||||
public class PathNode : OsmNode
|
public class PathNode : OsmNode
|
||||||
{
|
{
|
||||||
[JsonInclude]public new double directDistanceToGoal = double.MaxValue;
|
[JsonInclude]public new double directDistanceToGoal = double.MaxValue;
|
||||||
|
[JsonInclude]public double directDistanceDelta = double.MaxValue;
|
||||||
[JsonInclude]public new double currentPathLength = double.MaxValue;
|
[JsonInclude]public new double currentPathLength = double.MaxValue;
|
||||||
[JsonInclude]public double distanceBetweenNodes = double.MaxValue;
|
[JsonInclude]public double pathDistanceDelta = double.MaxValue;
|
||||||
[JsonInclude]public new double currentPathWeight = double.MaxValue;
|
[JsonInclude]public new double currentPathWeight = double.MaxValue;
|
||||||
[JsonInclude]public double weightBetweenNodes = double.MaxValue;
|
[JsonInclude]public double pathWeightDelta = double.MaxValue;
|
||||||
[JsonInclude]public Dictionary<string, string> tags = new();
|
[JsonInclude]public Dictionary<string, string> tags = new();
|
||||||
|
|
||||||
public PathNode(ulong nodeId, float lat, float lon) : base(nodeId, lat, lon)
|
public PathNode(ulong nodeId, float lat, float lon) : base(nodeId, lat, lon)
|
||||||
@ -21,7 +22,7 @@ public class PathNode : OsmNode
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PathNode? FromOsmNode(OsmNode? node, HashSet<Tag>? tags, double distance, double weight)
|
public static PathNode? FromOsmNode(OsmNode? node, HashSet<Tag>? tags, double pathDistanceDelta, double pathWeightDelta, double directDistanceDelta)
|
||||||
{
|
{
|
||||||
if (node is null)
|
if (node is null)
|
||||||
return null;
|
return null;
|
||||||
@ -30,8 +31,9 @@ public class PathNode : OsmNode
|
|||||||
currentPathLength = node.currentPathLength,
|
currentPathLength = node.currentPathLength,
|
||||||
currentPathWeight = double.IsPositiveInfinity(node.currentPathWeight) ? double.MaxValue : node.currentPathWeight,
|
currentPathWeight = double.IsPositiveInfinity(node.currentPathWeight) ? double.MaxValue : node.currentPathWeight,
|
||||||
directDistanceToGoal = node.directDistanceToGoal,
|
directDistanceToGoal = node.directDistanceToGoal,
|
||||||
distanceBetweenNodes = distance,
|
directDistanceDelta = directDistanceDelta,
|
||||||
weightBetweenNodes = weight
|
pathDistanceDelta = pathDistanceDelta,
|
||||||
|
pathWeightDelta = pathWeightDelta
|
||||||
};
|
};
|
||||||
if (tags != null)
|
if (tags != null)
|
||||||
foreach (Tag tag in tags)
|
foreach (Tag tag in tags)
|
||||||
|
@ -9,8 +9,8 @@ public static partial class Pathfinder
|
|||||||
private static ValueTuple<OsmNode?, OsmNode?> SetupNodes(Coordinates startCoordinates, Coordinates goalCoordinates, RegionManager regionManager )
|
private static ValueTuple<OsmNode?, OsmNode?> SetupNodes(Coordinates startCoordinates, Coordinates goalCoordinates, RegionManager regionManager )
|
||||||
{
|
{
|
||||||
ValueTuple<OsmNode?, OsmNode?> retTuple = new();
|
ValueTuple<OsmNode?, OsmNode?> retTuple = new();
|
||||||
retTuple.Item1 = regionManager.ClosestNodeToCoordinates(startCoordinates, Tag.SpeedType.road);
|
retTuple.Item1 = regionManager.ClosestNodeToCoordinates(startCoordinates, Tag.SpeedType.any);
|
||||||
retTuple.Item2 = regionManager.ClosestNodeToCoordinates(goalCoordinates, Tag.SpeedType.road);
|
retTuple.Item2 = regionManager.ClosestNodeToCoordinates(goalCoordinates, Tag.SpeedType.any);
|
||||||
if (retTuple.Item1 is null || retTuple.Item2 is null)
|
if (retTuple.Item1 is null || retTuple.Item2 is null)
|
||||||
return retTuple;
|
return retTuple;
|
||||||
retTuple.Item1.currentPathWeight = 0;
|
retTuple.Item1.currentPathWeight = 0;
|
||||||
@ -38,17 +38,20 @@ public static partial class Pathfinder
|
|||||||
while (currentNode is not null)
|
while (currentNode is not null)
|
||||||
{
|
{
|
||||||
HashSet<Tag>? tags = null;
|
HashSet<Tag>? tags = null;
|
||||||
double distance = 0;
|
double pathDistanceDelta = 0;
|
||||||
double weight = 0;
|
double pathWeightDelta = 0;
|
||||||
|
double directDistanceDelta = 0;
|
||||||
if (currentNode.previousPathNode is not null)
|
if (currentNode.previousPathNode is not null)
|
||||||
{
|
{
|
||||||
OsmEdge edge = currentNode.previousPathNode!.edges.First(e => e.neighborId.Equals(currentNode.nodeId));
|
OsmEdge edge = currentNode.previousPathNode!.edges.First(e => e.neighborId.Equals(currentNode.nodeId));
|
||||||
tags = regionManager.GetRegion(currentNode.coordinates)!.tagManager.GetTagsForWayId(edge.wayId);
|
tags = regionManager.GetRegion(currentNode.coordinates)!.tagManager.GetTagsForWayId(edge.wayId);
|
||||||
distance = currentNode.currentPathLength - currentNode.previousPathNode.currentPathLength;
|
pathDistanceDelta = currentNode.currentPathLength - currentNode.previousPathNode.currentPathLength;
|
||||||
weight = currentNode.currentPathWeight - currentNode.previousPathNode.currentPathWeight;
|
pathWeightDelta = currentNode.currentPathWeight - currentNode.previousPathNode.currentPathWeight;
|
||||||
|
directDistanceDelta =
|
||||||
|
currentNode.directDistanceToGoal - currentNode.previousPathNode.directDistanceToGoal;
|
||||||
}
|
}
|
||||||
|
|
||||||
PathNode? pn = PathNode.FromOsmNode(currentNode, tags, distance, weight);
|
PathNode? pn = PathNode.FromOsmNode(currentNode, tags, pathDistanceDelta, pathWeightDelta, directDistanceDelta);
|
||||||
if(pn is not null)
|
if(pn is not null)
|
||||||
path.Add(pn!);
|
path.Add(pn!);
|
||||||
currentNode = currentNode.previousPathNode;
|
currentNode = currentNode.previousPathNode;
|
||||||
|
@ -74,6 +74,8 @@ namespace Pathfinding
|
|||||||
|
|
||||||
public bool TestValidConnectionForType(OsmNode node1, OsmEdge edge, Tag.SpeedType type)
|
public bool TestValidConnectionForType(OsmNode node1, OsmEdge edge, Tag.SpeedType type)
|
||||||
{
|
{
|
||||||
|
if (type == Tag.SpeedType.any)
|
||||||
|
return true;
|
||||||
double speed = GetSpeedForEdge(node1, edge.wayId, type);
|
double speed = GetSpeedForEdge(node1, edge.wayId, type);
|
||||||
if (speed != 0)
|
if (speed != 0)
|
||||||
return true;
|
return true;
|
||||||
@ -89,13 +91,18 @@ namespace Pathfinding
|
|||||||
return null;
|
return null;
|
||||||
foreach (OsmNode node in region.nodes)
|
foreach (OsmNode node in region.nodes)
|
||||||
{
|
{
|
||||||
bool hasConnectionUsingVehicle = false;
|
bool hasConnectionUsingVehicle = true;
|
||||||
foreach (OsmEdge edge in node.edges)
|
if (vehicle is not Tag.SpeedType.any)
|
||||||
{
|
{
|
||||||
double speed = GetSpeedForEdge(node, edge.wayId, vehicle);
|
hasConnectionUsingVehicle = false;
|
||||||
if (speed != 0)
|
foreach (OsmEdge edge in node.edges)
|
||||||
hasConnectionUsingVehicle = true;
|
{
|
||||||
|
double speed = GetSpeedForEdge(node, edge.wayId, vehicle);
|
||||||
|
if (speed != 0)
|
||||||
|
hasConnectionUsingVehicle = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
double nodeDistance = Utils.DistanceBetween(node, coordinates);
|
double nodeDistance = Utils.DistanceBetween(node, coordinates);
|
||||||
if (nodeDistance < distance && hasConnectionUsingVehicle)
|
if (nodeDistance < distance && hasConnectionUsingVehicle)
|
||||||
{
|
{
|
||||||
@ -119,7 +126,6 @@ namespace Pathfinding
|
|||||||
return speed;
|
return speed;
|
||||||
return 0;
|
return 0;
|
||||||
case Tag.SpeedType.car:
|
case Tag.SpeedType.car:
|
||||||
case Tag.SpeedType.road:
|
|
||||||
byte? maxSpeed = (byte?)tags.GetTag(wayId, Tag.TagType.maxspeed);
|
byte? maxSpeed = (byte?)tags.GetTag(wayId, Tag.TagType.maxspeed);
|
||||||
if (maxSpeed is not null)
|
if (maxSpeed is not null)
|
||||||
return (double)maxSpeed;
|
return (double)maxSpeed;
|
||||||
@ -127,6 +133,8 @@ namespace Pathfinding
|
|||||||
if(maxSpeed is not 0)
|
if(maxSpeed is not 0)
|
||||||
return (byte)maxSpeed;
|
return (byte)maxSpeed;
|
||||||
return 0;
|
return 0;
|
||||||
|
case Tag.SpeedType.any:
|
||||||
|
return 1;
|
||||||
default:
|
default:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user