From 0f53ae579ccf961986f50e7f52188b487a794cea Mon Sep 17 00:00:00 2001 From: glax Date: Sun, 9 Apr 2023 18:27:53 +0200 Subject: [PATCH] Made speedtype any generic. Will use any connection (highway), and return the same speed for all highways. --- API/Program.cs | 2 +- OSMDatastructure/Tag.cs | 2 +- Pathfinding/Pathfinder.cs | 4 ++-- Pathfinding/RegionManager.cs | 20 ++++++++++++++------ 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/API/Program.cs b/API/Program.cs index 5a350d4..cf0ee76 100644 --- a/API/Program.cs +++ b/API/Program.cs @@ -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.road); + return regionManager.ClosestNodeToCoordinates(new Coordinates(lat, lon), Tag.SpeedType.any); }); // Configure the HTTP request pipeline. diff --git a/OSMDatastructure/Tag.cs b/OSMDatastructure/Tag.cs index 9985e14..ba912d8 100644 --- a/OSMDatastructure/Tag.cs +++ b/OSMDatastructure/Tag.cs @@ -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, road } + public enum SpeedType { pedestrian, car, any } } \ No newline at end of file diff --git a/Pathfinding/Pathfinder.cs b/Pathfinding/Pathfinder.cs index 6307b16..9f3ec2a 100644 --- a/Pathfinding/Pathfinder.cs +++ b/Pathfinding/Pathfinder.cs @@ -9,8 +9,8 @@ public static partial class Pathfinder private static ValueTuple SetupNodes(Coordinates startCoordinates, Coordinates goalCoordinates, RegionManager regionManager ) { ValueTuple retTuple = new(); - retTuple.Item1 = regionManager.ClosestNodeToCoordinates(startCoordinates, Tag.SpeedType.road); - retTuple.Item2 = regionManager.ClosestNodeToCoordinates(goalCoordinates, Tag.SpeedType.road); + retTuple.Item1 = regionManager.ClosestNodeToCoordinates(startCoordinates, Tag.SpeedType.any); + retTuple.Item2 = regionManager.ClosestNodeToCoordinates(goalCoordinates, Tag.SpeedType.any); if (retTuple.Item1 is null || retTuple.Item2 is null) return retTuple; retTuple.Item1.currentPathWeight = 0; diff --git a/Pathfinding/RegionManager.cs b/Pathfinding/RegionManager.cs index 08e34f4..a42692d 100644 --- a/Pathfinding/RegionManager.cs +++ b/Pathfinding/RegionManager.cs @@ -74,6 +74,8 @@ 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; @@ -89,13 +91,18 @@ namespace Pathfinding return null; foreach (OsmNode node in region.nodes) { - bool hasConnectionUsingVehicle = false; - foreach (OsmEdge edge in node.edges) + bool hasConnectionUsingVehicle = true; + if (vehicle is not Tag.SpeedType.any) { - double speed = GetSpeedForEdge(node, edge.wayId, vehicle); - if (speed != 0) - hasConnectionUsingVehicle = true; + hasConnectionUsingVehicle = false; + foreach (OsmEdge edge in node.edges) + { + double speed = GetSpeedForEdge(node, edge.wayId, vehicle); + if (speed != 0) + hasConnectionUsingVehicle = true; + } } + double nodeDistance = Utils.DistanceBetween(node, coordinates); if (nodeDistance < distance && hasConnectionUsingVehicle) { @@ -119,7 +126,6 @@ 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; @@ -127,6 +133,8 @@ namespace Pathfinding if(maxSpeed is not 0) return (byte)maxSpeed; return 0; + case Tag.SpeedType.any: + return 1; default: return 0; }