Added currentPathLength to OsmNode

This commit is contained in:
C9Glax 2023-02-08 19:09:46 +01:00
parent 55b9e87b7e
commit d3680565fc
2 changed files with 7 additions and 4 deletions

View File

@ -7,6 +7,7 @@ public class OsmNode
public OsmNode? previousPathNode = null; public OsmNode? previousPathNode = null;
public double currentPathWeight = double.MaxValue; public double currentPathWeight = double.MaxValue;
public double currentPathLength = double.MaxValue;
public double directDistanceToGoal = double.MaxValue; public double directDistanceToGoal = double.MaxValue;
public OsmNode(float lat, float lon) public OsmNode(float lat, float lon)
@ -43,13 +44,13 @@ public class OsmNode
{ {
if(this.previousPathNode != null) if(this.previousPathNode != null)
return string.Format( return string.Format(
"NODE {0} Edges-Count: {1} previousPathNode: {2} currentPathWeight: {3} directDistanceToGoal: {4}", "NODE {0} Edges-Count: {1} previousPathNode: {2} currentPathWeight: {3} currentPathLength: {4} directDistanceToGoal: {5}",
this.coordinates.ToString(), this.edges.Count, this.previousPathNode.coordinates.ToString(), this.coordinates.ToString(), this.edges.Count, this.previousPathNode.coordinates.ToString(),
this.currentPathWeight, this.directDistanceToGoal); this.currentPathWeight, this.currentPathLength, this.directDistanceToGoal);
else else
return string.Format( return string.Format(
"NODE {0} Edges-Count: {1} previousPathNode: NO PREVIOUS NODE currentPathWeight: {2} directDistanceToGoal: {3}", "NODE {0} Edges-Count: {1} previousPathNode: NO PREVIOUS NODE currentPathWeight: {2} currentPathLength: {3} directDistanceToGoal: {4}",
this.coordinates.ToString(), this.edges.Count, this.coordinates.ToString(), this.edges.Count,
this.currentPathWeight, this.directDistanceToGoal); this.currentPathWeight, this.currentPathLength, this.directDistanceToGoal);
} }
} }

View File

@ -28,6 +28,7 @@ public class Pathfinder
List<OsmNode> toVisit = new() { startNode }; List<OsmNode> toVisit = new() { startNode };
OsmNode closestNodeToGoal = toVisit.First(); OsmNode closestNodeToGoal = toVisit.First();
closestNodeToGoal.currentPathWeight = 0; closestNodeToGoal.currentPathWeight = 0;
closestNodeToGoal.currentPathLength = 0;
bool stop = false; bool stop = false;
while (toVisit.Count > 0 && !stop) while (toVisit.Count > 0 && !stop)
@ -57,6 +58,7 @@ public class Pathfinder
{ {
neighbor.previousPathNode = closestNodeToGoal; neighbor.previousPathNode = closestNodeToGoal;
neighbor.currentPathWeight = newPotentialWeight; neighbor.currentPathWeight = newPotentialWeight;
neighbor.currentPathLength = closestNodeToGoal.currentPathLength + Utils.DistanceBetween(closestNodeToGoal, neighbor);
if (neighbor.Equals(goalNode)) if (neighbor.Equals(goalNode))
stop = true; stop = true;