Fixed AStar Weight-assignment
OSMEdge.cs: renamed speedped, speedcar
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user