Start of complete rethinking of Heuristic function and approach to get shortest path.
This commit is contained in:
parent
18822e2152
commit
bc39785f6f
@ -102,11 +102,24 @@ public class Pathfinder
|
|||||||
|
|
||||||
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 roadPriorityFactor, double junctionFactor, double sameRoadFactor, double nodeAngleFactor)
|
||||||
{
|
{
|
||||||
double roadPriority = regionManager.GetPriorityForVehicle(_speedType, edge, currentNode) * roadPriorityFactor;
|
double priority = regionManager.GetPriorityForVehicle(_speedType, edge, currentNode);
|
||||||
if (roadPriority == 0)
|
if (priority == 0)
|
||||||
return double.MaxValue;
|
return double.MaxValue;
|
||||||
|
|
||||||
double speed = regionManager.GetSpeedForEdge(currentNode, edge.wayId, _speedType) * 0.0003;
|
double speed = regionManager.GetSpeedForEdge(currentNode, edge.wayId, _speedType);
|
||||||
|
|
||||||
|
double angle = 0;
|
||||||
|
if (_cameFromDict!.ContainsKey(currentNode))
|
||||||
|
{
|
||||||
|
OsmNode previousNode = _cameFromDict[currentNode];
|
||||||
|
Vector v1 = new(currentNode, previousNode);
|
||||||
|
Vector v2 = new(currentNode, neighborNode);
|
||||||
|
double nodeAngle = v1.Angle(v2);
|
||||||
|
if (nodeAngle < 60)
|
||||||
|
angle = 0.001;
|
||||||
|
else
|
||||||
|
angle = (nodeAngle + 1) / (181);
|
||||||
|
}
|
||||||
|
|
||||||
TagManager curTags = regionManager.GetRegion(currentNode.coordinates)!.tagManager;
|
TagManager curTags = regionManager.GetRegion(currentNode.coordinates)!.tagManager;
|
||||||
TagManager nextTags = regionManager.GetRegion(neighborNode.coordinates)!.tagManager;
|
TagManager nextTags = regionManager.GetRegion(neighborNode.coordinates)!.tagManager;
|
||||||
@ -123,20 +136,11 @@ public class Pathfinder
|
|||||||
if ((string?)nextTags.GetTag(pEdge.wayId, TagType.tagref) == curRef)
|
if ((string?)nextTags.GetTag(pEdge.wayId, TagType.tagref) == curRef)
|
||||||
sameRef = true;
|
sameRef = true;
|
||||||
}
|
}
|
||||||
double sameRoadName = (sameRef || sameName ? 1 : 0) * sameRoadFactor;
|
|
||||||
|
|
||||||
double junctionCount = (neighborNode.edges.Count > 2 ? 0 : 1) * junctionFactor;
|
double junctionCount = (neighborNode.edges.Count > 2 ? 0 : 1) * junctionFactor;
|
||||||
|
double roadPriority = priority * roadPriorityFactor;
|
||||||
double angle = 0;
|
double sameRoadName = (sameRef || sameName ? 1 : 0) * sameRoadFactor;
|
||||||
if (_cameFromDict!.ContainsKey(currentNode))
|
return Utils.DistanceBetween(neighborNode, goalNode) / (speed * angle + 1);
|
||||||
{
|
|
||||||
OsmNode previousNode = _cameFromDict[currentNode];
|
|
||||||
Vector v1 = new(previousNode, currentNode);
|
|
||||||
Vector v2 = new(currentNode, neighborNode);
|
|
||||||
double nodeAngle = v1.Angle(v2);
|
|
||||||
angle = ((180 - nodeAngle) / 180) * nodeAngleFactor;
|
|
||||||
}
|
|
||||||
return Utils.DistanceBetween(neighborNode, goalNode) / (roadPriority + sameRoadName + junctionCount + angle);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SaveResult(string path)
|
public void SaveResult(string path)
|
||||||
|
Reference in New Issue
Block a user