Changed factors to globalfields to reduce parametersin methodcall

This commit is contained in:
glax 2023-04-23 13:42:46 +02:00
parent 97a057a3d4
commit 7856f1c66c

View File

@ -13,22 +13,29 @@ public class Pathfinder
public Dictionary<OsmNode, double>? gScore; public Dictionary<OsmNode, double>? gScore;
private Dictionary<OsmNode, OsmNode>? _cameFromDict; private Dictionary<OsmNode, OsmNode>? _cameFromDict;
private SpeedType _speedType; 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)) if (!Path.Exists(workingDirectory))
throw new DirectoryNotFoundException(workingDirectory); throw new DirectoryNotFoundException(workingDirectory);
regionManager = new(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.regionManager = regionManager;
this.roadPriorityFactor = roadPriorityFactor;
this.junctionFactor = junctionFactor;
this.sameRoadFactor = sameRoadFactor;
this.nodeAngleFactor = nodeAngleFactor;
} }
public Pathfinder AStar(Coordinates startCoordinates, Coordinates goalCoordinates, public Pathfinder AStar(Coordinates startCoordinates, Coordinates goalCoordinates, SpeedType vehicle)
SpeedType vehicle, double heuristicRoadLevelPriority, double heuristicSameRoadPriority,
double heuristicFewJunctionsPriority, double angleWeightFactor)
{ {
DateTime startCalc = DateTime.Now; DateTime startCalc = DateTime.Now;
_speedType = vehicle; _speedType = vehicle;
@ -69,8 +76,7 @@ public class Pathfinder
if(!_cameFromDict.TryAdd(neighbor, currentNode)) if(!_cameFromDict.TryAdd(neighbor, currentNode))
_cameFromDict[neighbor] = currentNode; _cameFromDict[neighbor] = currentNode;
gScore[neighbor] = tentativeGScore; gScore[neighbor] = tentativeGScore;
double h = Heuristic(currentNode, neighbor, goalNode, edge, double h = Heuristic(currentNode, neighbor, goalNode, edge);
heuristicRoadLevelPriority, heuristicFewJunctionsPriority, heuristicSameRoadPriority, angleWeightFactor);
openSetfScore.Enqueue(neighbor, tentativeGScore + h); //Currently set includes a lot of duplicates 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); 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); double priority = regionManager.GetPriorityForVehicle(_speedType, edge, currentNode);
if (priority == 0) if (priority == 0)