Compare commits
No commits in common. "0f53ae579ccf961986f50e7f52188b487a794cea" and "6eab23ff1653d17432e4e27b8a0aaa49b8ec7fde" have entirely different histories.
0f53ae579c
...
6eab23ff16
@ -37,7 +37,7 @@ app.MapGet("/getRouteTime", (float latStart, float lonStart, float latEnd, float
|
||||
app.MapGet("/getClosestNode", (float lat, float lon) =>
|
||||
{
|
||||
RegionManager regionManager = new RegionManager("D:/stuttgart-regbez-latest");
|
||||
return regionManager.ClosestNodeToCoordinates(new Coordinates(lat, lon), Tag.SpeedType.any);
|
||||
return regionManager.ClosestNodeToCoordinates(new Coordinates(lat, lon), Tag.SpeedType.road);
|
||||
});
|
||||
|
||||
// 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 }
|
||||
// ReSharper restore InconsistentNaming
|
||||
|
||||
public enum SpeedType { pedestrian, car, any }
|
||||
public enum SpeedType { pedestrian, car, road }
|
||||
}
|
@ -7,11 +7,10 @@ namespace Pathfinding;
|
||||
public class PathNode : OsmNode
|
||||
{
|
||||
[JsonInclude]public new double directDistanceToGoal = double.MaxValue;
|
||||
[JsonInclude]public double directDistanceDelta = double.MaxValue;
|
||||
[JsonInclude]public new double currentPathLength = double.MaxValue;
|
||||
[JsonInclude]public double pathDistanceDelta = double.MaxValue;
|
||||
[JsonInclude]public double distanceBetweenNodes = double.MaxValue;
|
||||
[JsonInclude]public new double currentPathWeight = double.MaxValue;
|
||||
[JsonInclude]public double pathWeightDelta = double.MaxValue;
|
||||
[JsonInclude]public double weightBetweenNodes = double.MaxValue;
|
||||
[JsonInclude]public Dictionary<string, string> tags = new();
|
||||
|
||||
public PathNode(ulong nodeId, float lat, float lon) : base(nodeId, lat, lon)
|
||||
@ -22,7 +21,7 @@ public class PathNode : OsmNode
|
||||
{
|
||||
}
|
||||
|
||||
public static PathNode? FromOsmNode(OsmNode? node, HashSet<Tag>? tags, double pathDistanceDelta, double pathWeightDelta, double directDistanceDelta)
|
||||
public static PathNode? FromOsmNode(OsmNode? node, HashSet<Tag>? tags, double distance, double weight)
|
||||
{
|
||||
if (node is null)
|
||||
return null;
|
||||
@ -31,9 +30,8 @@ public class PathNode : OsmNode
|
||||
currentPathLength = node.currentPathLength,
|
||||
currentPathWeight = double.IsPositiveInfinity(node.currentPathWeight) ? double.MaxValue : node.currentPathWeight,
|
||||
directDistanceToGoal = node.directDistanceToGoal,
|
||||
directDistanceDelta = directDistanceDelta,
|
||||
pathDistanceDelta = pathDistanceDelta,
|
||||
pathWeightDelta = pathWeightDelta
|
||||
distanceBetweenNodes = distance,
|
||||
weightBetweenNodes = weight
|
||||
};
|
||||
if (tags != null)
|
||||
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 )
|
||||
{
|
||||
ValueTuple<OsmNode?, OsmNode?> retTuple = new();
|
||||
retTuple.Item1 = regionManager.ClosestNodeToCoordinates(startCoordinates, Tag.SpeedType.any);
|
||||
retTuple.Item2 = regionManager.ClosestNodeToCoordinates(goalCoordinates, Tag.SpeedType.any);
|
||||
retTuple.Item1 = regionManager.ClosestNodeToCoordinates(startCoordinates, Tag.SpeedType.road);
|
||||
retTuple.Item2 = regionManager.ClosestNodeToCoordinates(goalCoordinates, Tag.SpeedType.road);
|
||||
if (retTuple.Item1 is null || retTuple.Item2 is null)
|
||||
return retTuple;
|
||||
retTuple.Item1.currentPathWeight = 0;
|
||||
@ -38,20 +38,17 @@ public static partial class Pathfinder
|
||||
while (currentNode is not null)
|
||||
{
|
||||
HashSet<Tag>? tags = null;
|
||||
double pathDistanceDelta = 0;
|
||||
double pathWeightDelta = 0;
|
||||
double directDistanceDelta = 0;
|
||||
double distance = 0;
|
||||
double weight = 0;
|
||||
if (currentNode.previousPathNode is not null)
|
||||
{
|
||||
OsmEdge edge = currentNode.previousPathNode!.edges.First(e => e.neighborId.Equals(currentNode.nodeId));
|
||||
tags = regionManager.GetRegion(currentNode.coordinates)!.tagManager.GetTagsForWayId(edge.wayId);
|
||||
pathDistanceDelta = currentNode.currentPathLength - currentNode.previousPathNode.currentPathLength;
|
||||
pathWeightDelta = currentNode.currentPathWeight - currentNode.previousPathNode.currentPathWeight;
|
||||
directDistanceDelta =
|
||||
currentNode.directDistanceToGoal - currentNode.previousPathNode.directDistanceToGoal;
|
||||
distance = currentNode.currentPathLength - currentNode.previousPathNode.currentPathLength;
|
||||
weight = currentNode.currentPathWeight - currentNode.previousPathNode.currentPathWeight;
|
||||
}
|
||||
|
||||
PathNode? pn = PathNode.FromOsmNode(currentNode, tags, pathDistanceDelta, pathWeightDelta, directDistanceDelta);
|
||||
PathNode? pn = PathNode.FromOsmNode(currentNode, tags, distance, weight);
|
||||
if(pn is not null)
|
||||
path.Add(pn!);
|
||||
currentNode = currentNode.previousPathNode;
|
||||
|
@ -74,8 +74,6 @@ namespace Pathfinding
|
||||
|
||||
public bool TestValidConnectionForType(OsmNode node1, OsmEdge edge, Tag.SpeedType type)
|
||||
{
|
||||
if (type == Tag.SpeedType.any)
|
||||
return true;
|
||||
double speed = GetSpeedForEdge(node1, edge.wayId, type);
|
||||
if (speed != 0)
|
||||
return true;
|
||||
@ -91,18 +89,13 @@ namespace Pathfinding
|
||||
return null;
|
||||
foreach (OsmNode node in region.nodes)
|
||||
{
|
||||
bool hasConnectionUsingVehicle = true;
|
||||
if (vehicle is not Tag.SpeedType.any)
|
||||
bool hasConnectionUsingVehicle = false;
|
||||
foreach (OsmEdge edge in node.edges)
|
||||
{
|
||||
hasConnectionUsingVehicle = false;
|
||||
foreach (OsmEdge edge in node.edges)
|
||||
{
|
||||
double speed = GetSpeedForEdge(node, edge.wayId, vehicle);
|
||||
if (speed != 0)
|
||||
hasConnectionUsingVehicle = true;
|
||||
}
|
||||
double speed = GetSpeedForEdge(node, edge.wayId, vehicle);
|
||||
if (speed != 0)
|
||||
hasConnectionUsingVehicle = true;
|
||||
}
|
||||
|
||||
double nodeDistance = Utils.DistanceBetween(node, coordinates);
|
||||
if (nodeDistance < distance && hasConnectionUsingVehicle)
|
||||
{
|
||||
@ -126,6 +119,7 @@ namespace Pathfinding
|
||||
return speed;
|
||||
return 0;
|
||||
case Tag.SpeedType.car:
|
||||
case Tag.SpeedType.road:
|
||||
byte? maxSpeed = (byte?)tags.GetTag(wayId, Tag.TagType.maxspeed);
|
||||
if (maxSpeed is not null)
|
||||
return (double)maxSpeed;
|
||||
@ -133,8 +127,6 @@ namespace Pathfinding
|
||||
if(maxSpeed is not 0)
|
||||
return (byte)maxSpeed;
|
||||
return 0;
|
||||
case Tag.SpeedType.any:
|
||||
return 1;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user