Added distance and duration to PathResult.
This commit is contained in:
parent
7d769a064f
commit
42e915ee05
@ -6,11 +6,15 @@ public class PathResult
|
|||||||
{
|
{
|
||||||
[JsonInclude]public TimeSpan calcTime;
|
[JsonInclude]public TimeSpan calcTime;
|
||||||
[JsonInclude]public List<PathNode> pathNodes;
|
[JsonInclude]public List<PathNode> pathNodes;
|
||||||
|
[JsonInclude]public double distance;
|
||||||
|
[JsonInclude]public double weight;
|
||||||
|
|
||||||
[JsonConstructor]
|
[JsonConstructor]
|
||||||
public PathResult(TimeSpan calcTime, List<PathNode> pathNodes)
|
public PathResult(TimeSpan calcTime, List<PathNode> pathNodes, double distance, double weight)
|
||||||
{
|
{
|
||||||
this.calcTime = calcTime;
|
this.calcTime = calcTime;
|
||||||
this.pathNodes = pathNodes;
|
this.pathNodes = pathNodes;
|
||||||
|
this.distance = distance;
|
||||||
|
this.weight = weight;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -36,7 +36,7 @@ public class Pathfinder
|
|||||||
OsmNode? goalNode = regionManager.ClosestNodeToCoordinates(goalCoordinates, _speedType);
|
OsmNode? goalNode = regionManager.ClosestNodeToCoordinates(goalCoordinates, _speedType);
|
||||||
if (startNode is null || goalNode is null)
|
if (startNode is null || goalNode is null)
|
||||||
{
|
{
|
||||||
pathResult = new(DateTime.Now - startCalc, new List<PathNode>());
|
pathResult = new(DateTime.Now - startCalc, new List<PathNode>(),0 ,0);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,7 +52,7 @@ public class Pathfinder
|
|||||||
{
|
{
|
||||||
TimeSpan calcTime = DateTime.Now - startCalc;
|
TimeSpan calcTime = DateTime.Now - startCalc;
|
||||||
pathResult = GetPath(goalNode, calcTime);
|
pathResult = GetPath(goalNode, calcTime);
|
||||||
Console.WriteLine($"Path found. {calcTime} PathLength {pathResult.pathNodes.Count} VisitedNodes {gScore.Count}");
|
Console.WriteLine($"Path found. {calcTime} PathLength {pathResult.pathNodes.Count} VisitedNodes {gScore.Count} Distance {pathResult.distance} Duration {pathResult.weight}");
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,7 +78,7 @@ public class Pathfinder
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pathResult = new(DateTime.Now - startCalc, new List<PathNode>());
|
pathResult = new(DateTime.Now - startCalc, new List<PathNode>(),0 ,0);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,6 +94,8 @@ public class Pathfinder
|
|||||||
{
|
{
|
||||||
List<PathNode> path = new();
|
List<PathNode> path = new();
|
||||||
OsmNode currentNode = goalNode;
|
OsmNode currentNode = goalNode;
|
||||||
|
double retDistance = 0;
|
||||||
|
double weight = 0;
|
||||||
while (_cameFromDict!.ContainsKey(_cameFromDict[currentNode]))
|
while (_cameFromDict!.ContainsKey(_cameFromDict[currentNode]))
|
||||||
{
|
{
|
||||||
OsmEdge? currentEdge = _cameFromDict[currentNode].edges.First(edge => edge.neighborId == currentNode.nodeId);
|
OsmEdge? currentEdge = _cameFromDict[currentNode].edges.First(edge => edge.neighborId == currentNode.nodeId);
|
||||||
@ -102,12 +104,17 @@ public class Pathfinder
|
|||||||
PathNode? newNode = PathNode.FromOsmNode(currentNode, tags);
|
PathNode? newNode = PathNode.FromOsmNode(currentNode, tags);
|
||||||
if(newNode is not null)
|
if(newNode is not null)
|
||||||
path.Add(newNode);
|
path.Add(newNode);
|
||||||
|
|
||||||
|
double distance = Utils.DistanceBetween(currentNode, _cameFromDict[currentNode]);
|
||||||
|
retDistance += distance;
|
||||||
|
weight += regionManager.GetSpeedForEdge(_cameFromDict[currentNode], currentEdge.wayId, _speedType);
|
||||||
|
|
||||||
currentNode = _cameFromDict[currentNode];
|
currentNode = _cameFromDict[currentNode];
|
||||||
}
|
}
|
||||||
|
|
||||||
path.Reverse();
|
path.Reverse();
|
||||||
|
|
||||||
return new PathResult(calcFinished, path);
|
return new PathResult(calcFinished, path, retDistance, retDistance / (weight / path.Count));
|
||||||
}
|
}
|
||||||
|
|
||||||
private double Weight(OsmNode currentNode, OsmNode neighborNode, OsmEdge edge, double angleWeightFactor)
|
private double Weight(OsmNode currentNode, OsmNode neighborNode, OsmEdge edge, double angleWeightFactor)
|
||||||
|
Reference in New Issue
Block a user