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;
private Dictionary<OsmNode, OsmNode>? _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)