Archived
1
0

Fixed AStar Weight-assignment

OSMEdge.cs:
renamed speedped, speedcar
This commit is contained in:
2023-02-08 19:05:13 +01:00
parent d18e4f5abf
commit f15171a9f1
2 changed files with 38 additions and 30 deletions
OSMDatastructure
Pathfinding

@ -6,7 +6,7 @@ namespace Pathfinding;
public class Pathfinder
{
public static List<OsmNode> CustomAStar(string workingDir, Coordinates start, Coordinates goal)
public static List<OsmNode> CustomAStar(string workingDir, Coordinates start, Coordinates goal, OsmEdge.speedType vehicle)
{
RegionManager regionManager = new RegionManager(workingDir);
Region startRegion, goalRegion;
@ -32,6 +32,7 @@ public class Pathfinder
while (toVisit.Count > 0 && !stop)
{
Console.WriteLine("toVisit-length: {0}", toVisit.Count);
closestNodeToGoal = toVisit.First();
foreach (OsmNode node in toVisit)
{
@ -48,16 +49,20 @@ public class Pathfinder
foreach (OsmEdge edge in closestNodeToGoal.edges)
{
OsmNode? neighbor = regionManager.GetNode(edge.neighborCoordinates);
if (neighbor != null && neighbor.currentPathWeight > closestNodeToGoal.currentPathWeight + Utils.DistanceBetween(closestNodeToGoal, neighbor))
if (neighbor != null)
{
neighbor.previousPathNode = closestNodeToGoal;
neighbor.currentPathWeight = closestNodeToGoal.currentPathWeight +
Utils.DistanceBetween(closestNodeToGoal, neighbor);
double newPotentialWeight =
closestNodeToGoal.currentPathWeight + edge.GetWeight(closestNodeToGoal, vehicle);
if (neighbor.currentPathWeight > newPotentialWeight)
{
neighbor.previousPathNode = closestNodeToGoal;
neighbor.currentPathWeight = newPotentialWeight;
if (neighbor.Equals(goalNode))
stop = true;
else
toVisit.Add(neighbor);
if (neighbor.Equals(goalNode))
stop = true;
else
toVisit.Add(neighbor);
}
}
}
@ -72,7 +77,8 @@ public class Pathfinder
currentNode = currentNode.previousPathNode;
}
path.Add(startNode);
path.Reverse();
return path;
}