From ec6725a5c513a9b52c881c8077a1a07a59a7eb3a Mon Sep 17 00:00:00 2001 From: glax Date: Sun, 23 Apr 2023 15:07:26 +0200 Subject: [PATCH] Removed unnecessary factors --- API/Program.cs | 8 +++----- Pathfinding/Pathfinder.cs | 30 ++++-------------------------- Server/Server.cs | 26 ++++++++++---------------- 3 files changed, 17 insertions(+), 47 deletions(-) diff --git a/API/Program.cs b/API/Program.cs index 6d3fec9..75841f3 100644 --- a/API/Program.cs +++ b/API/Program.cs @@ -13,10 +13,9 @@ builder.Services.AddSwaggerGen(); var app = builder.Build(); -app.MapGet("/getRoute", (float latStart, float lonStart, float latEnd, float lonEnd, Tag.SpeedType vehicle, double stayOnSameRoadPriority, double useHigherLevelRoadsPriority, double useRoadsWithLessJunctionsPriority, double angleFactor) => +app.MapGet("/getRoute", (float latStart, float lonStart, float latEnd, float lonEnd, Tag.SpeedType vehicle, double useHigherLevelRoadsPriority, double maxTurnAngle) => { - Pathfinder result = new Pathfinder("D:/stuttgart-regbez-latest", useHigherLevelRoadsPriority, stayOnSameRoadPriority, - useRoadsWithLessJunctionsPriority, 30).AStar(new Coordinates(latStart, lonStart), + Pathfinder result = new Pathfinder("D:/stuttgart-regbez-latest", useHigherLevelRoadsPriority, maxTurnAngle).AStar(new Coordinates(latStart, lonStart), new Coordinates(latEnd, lonEnd), vehicle); return result.pathResult; } @@ -24,8 +23,7 @@ app.MapGet("/getRoute", (float latStart, float lonStart, float latEnd, float lon app.MapGet("/getShortestRoute", (float latStart, float lonStart, float latEnd, float lonEnd) => { - Pathfinder result = new Pathfinder("D:/stuttgart-regbez-latest", 0, 0, - 0, 30).AStar(new Coordinates(latStart, lonStart), + Pathfinder result = new Pathfinder("D:/stuttgart-regbez-latest", 0, 30).AStar(new Coordinates(latStart, lonStart), new Coordinates(latEnd, lonEnd), Tag.SpeedType.any); return result.pathResult; } diff --git a/Pathfinding/Pathfinder.cs b/Pathfinding/Pathfinder.cs index 32de83f..4e86ecd 100644 --- a/Pathfinding/Pathfinder.cs +++ b/Pathfinding/Pathfinder.cs @@ -13,25 +13,21 @@ public class Pathfinder public Dictionary? gScore; private Dictionary? _cameFromDict; private SpeedType _speedType; - private double roadPriorityFactor, junctionFactor, sameRoadFactor, turnAngle; + private double roadPriorityFactor, turnAngle; - public Pathfinder(string workingDirectory, double roadPriorityFactor, double junctionFactor, double sameRoadFactor, double turnAngle) + public Pathfinder(string workingDirectory, double roadPriorityFactor, double turnAngle) { if (!Path.Exists(workingDirectory)) throw new DirectoryNotFoundException(workingDirectory); regionManager = new(workingDirectory); this.roadPriorityFactor = roadPriorityFactor; - this.junctionFactor = junctionFactor; - this.sameRoadFactor = sameRoadFactor; this.turnAngle = turnAngle; } - public Pathfinder(RegionManager regionManager, double roadPriorityFactor, double junctionFactor, double sameRoadFactor, double turnAngle) + public Pathfinder(RegionManager regionManager, double roadPriorityFactor, double turnAngle) { this.regionManager = regionManager; this.roadPriorityFactor = roadPriorityFactor; - this.junctionFactor = junctionFactor; - this.sameRoadFactor = sameRoadFactor; this.turnAngle = turnAngle; } @@ -154,27 +150,9 @@ public class Pathfinder else angle = nodeAngle / 180; } - - TagManager curTags = regionManager.GetRegion(currentNode.coordinates)!.tagManager; - TagManager nextTags = regionManager.GetRegion(neighborNode.coordinates)!.tagManager; - bool sameName = false; - string? curName = (string?)curTags.GetTag(edge.wayId, TagType.name); - bool sameRef = false; - string? curRef = (string?)curTags.GetTag(edge.wayId, TagType.tagref); - if(curName is not null) - foreach (OsmEdge pEdge in neighborNode.edges) - { - if ((string?)nextTags.GetTag(pEdge.wayId, TagType.name) == curName) - sameName = true; - if ((string?)nextTags.GetTag(pEdge.wayId, TagType.tagref) == curRef) - sameRef = true; - } - - double junctionCount = (neighborNode.edges.Count > 2 ? 0 : 1) * junctionFactor; double roadPriority = priority * roadPriorityFactor; - double sameRoadName = (sameRef || sameName ? 1 : 0) * sameRoadFactor; - return Utils.DistanceBetween(neighborNode, goalNode) / (speed * angle + 1); + return Utils.DistanceBetween(neighborNode, goalNode) / (speed * angle + roadPriority + 1); } public void SaveResult(string path) diff --git a/Server/Server.cs b/Server/Server.cs index 6d556a7..ea4cf9e 100644 --- a/Server/Server.cs +++ b/Server/Server.cs @@ -118,25 +118,19 @@ public class Server Queue calcThreads = new(); - for (double sameRoadPriority = 0; sameRoadPriority < 0.02; sameRoadPriority += 0.001) + for (double roadLevelPriority = 0.02; roadLevelPriority > 0; roadLevelPriority -= 0.001) { - for (double roadLevelPriority = 0.02; roadLevelPriority > 0; roadLevelPriority -= 0.001) + for (double maxAngle = 5; maxAngle < 45; maxAngle += 5) { - for (double maxAngle = 5; maxAngle < 45; maxAngle += 5) + double priority = roadLevelPriority; + double angle = maxAngle; + calcThreads.Enqueue(new Thread(() => { - double priority = roadLevelPriority; - double roadPriority = sameRoadPriority; - double angle = maxAngle; - calcThreads.Enqueue(new Thread(() => - { - Pathfinder testresult = new Pathfinder(rm, priority, roadPriority, - 0, angle).AStar(start, - finish, Tag.SpeedType.car); - string fileName = - $"angle{angle:0.000}_level{priority:0.000}_same{roadPriority:0.000}.result"; - testresult.SaveResult(Path.Join(parentFolder, fileName)); - })); - } + Pathfinder testresult = new Pathfinder(rm, priority, angle).AStar(start, + finish, Tag.SpeedType.car); + string fileName = $"angle{angle:0.000}_level{priority:0.000}.result"; + testresult.SaveResult(Path.Join(parentFolder, fileName)); + })); } }