From 7856f1c66c7f744b1aac6707d1d8455acb11a430 Mon Sep 17 00:00:00 2001 From: glax Date: Sun, 23 Apr 2023 13:42:46 +0200 Subject: [PATCH] Changed factors to globalfields to reduce parametersin methodcall --- Pathfinding/Pathfinder.cs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/Pathfinding/Pathfinder.cs b/Pathfinding/Pathfinder.cs index ccf0464..ec99238 100644 --- a/Pathfinding/Pathfinder.cs +++ b/Pathfinding/Pathfinder.cs @@ -13,22 +13,29 @@ public class Pathfinder public Dictionary? gScore; private Dictionary? _cameFromDict; private SpeedType _speedType; + private double roadPriorityFactor, junctionFactor, sameRoadFactor, nodeAngleFactor; - public Pathfinder(string workingDirectory) + public Pathfinder(string workingDirectory, double roadPriorityFactor, double junctionFactor, double sameRoadFactor, double nodeAngleFactor) { if (!Path.Exists(workingDirectory)) throw new DirectoryNotFoundException(workingDirectory); regionManager = new(workingDirectory); + this.roadPriorityFactor = roadPriorityFactor; + this.junctionFactor = junctionFactor; + this.sameRoadFactor = sameRoadFactor; + this.nodeAngleFactor = nodeAngleFactor; } - public Pathfinder(RegionManager regionManager) + public Pathfinder(RegionManager regionManager, double roadPriorityFactor, double junctionFactor, double sameRoadFactor, double nodeAngleFactor) { this.regionManager = regionManager; + this.roadPriorityFactor = roadPriorityFactor; + this.junctionFactor = junctionFactor; + this.sameRoadFactor = sameRoadFactor; + this.nodeAngleFactor = nodeAngleFactor; } - public Pathfinder AStar(Coordinates startCoordinates, Coordinates goalCoordinates, - SpeedType vehicle, double heuristicRoadLevelPriority, double heuristicSameRoadPriority, - double heuristicFewJunctionsPriority, double angleWeightFactor) + public Pathfinder AStar(Coordinates startCoordinates, Coordinates goalCoordinates, SpeedType vehicle) { DateTime startCalc = DateTime.Now; _speedType = vehicle; @@ -69,8 +76,7 @@ public class Pathfinder if(!_cameFromDict.TryAdd(neighbor, currentNode)) _cameFromDict[neighbor] = currentNode; gScore[neighbor] = tentativeGScore; - double h = Heuristic(currentNode, neighbor, goalNode, edge, - heuristicRoadLevelPriority, heuristicFewJunctionsPriority, heuristicSameRoadPriority, angleWeightFactor); + double h = Heuristic(currentNode, neighbor, goalNode, edge); openSetfScore.Enqueue(neighbor, tentativeGScore + h); //Currently set includes a lot of duplicates } } @@ -100,7 +106,7 @@ public class Pathfinder return distance / (speed * nodeAngle + prio + 1); } - private double Heuristic(OsmNode currentNode, OsmNode neighborNode, OsmNode goalNode, OsmEdge edge, double roadPriorityFactor, double junctionFactor, double sameRoadFactor, double nodeAngleFactor) + private double Heuristic(OsmNode currentNode, OsmNode neighborNode, OsmNode goalNode, OsmEdge edge) { double priority = regionManager.GetPriorityForVehicle(_speedType, edge, currentNode); if (priority == 0)