Use Contstructor exportationMultiplier, not method additonalExploration on optimize
This commit is contained in:
parent
be4f19c4bb
commit
31f4dfe096
@ -10,10 +10,10 @@ namespace astar
|
|||||||
{
|
{
|
||||||
private readonly ValueTuple<float, float, float, float> DefaultPriorityWeights = priorityWeights ?? new(0.75f, 1f, 0.1f, 0);
|
private readonly ValueTuple<float, float, float, float> DefaultPriorityWeights = priorityWeights ?? new(0.75f, 1f, 0.1f, 0);
|
||||||
private readonly ValueTuple<float, float, float, float> OptimizingWeights = optimizingWeights ?? new(0, 0.07f, 0, 0);
|
private readonly ValueTuple<float, float, float, float> OptimizingWeights = optimizingWeights ?? new(0, 0.07f, 0, 0);
|
||||||
private int ExplorationDistanceFromRoute = explorationDistance ?? 1200;
|
private readonly int _explorationDistanceFromRoute = explorationDistance ?? 1200;
|
||||||
private int ExplorationMultiplier = explorationMultiplier ?? 65;
|
private readonly int _explorationMultiplier = explorationMultiplier ?? 65;
|
||||||
|
|
||||||
public Route FindPath(float startLat, float startLon, float endLat, float endLon, float regionSize, bool car = true, PathMeasure pathing = PathMeasure.Distance, float additionalExploration = 3, string? importFolderPath = null, ILogger? logger = null)
|
public Route FindPath(float startLat, float startLon, float endLat, float endLon, float regionSize, bool car = true, PathMeasure pathing = PathMeasure.Distance, string? importFolderPath = null, ILogger? logger = null)
|
||||||
{
|
{
|
||||||
RegionLoader rl = new(regionSize, importFolderPath, logger: logger);
|
RegionLoader rl = new(regionSize, importFolderPath, logger: logger);
|
||||||
Graph graph = Spiral(rl, startLat, startLon, regionSize);
|
Graph graph = Spiral(rl, startLat, startLon, regionSize);
|
||||||
@ -77,12 +77,12 @@ namespace astar
|
|||||||
Dictionary<ulong, int> routeQueue = toVisitStart.UnorderedItems.Select(l => l.Element).Union(toVisitEnd.UnorderedItems.Select(l => l.Element)).Where(id =>
|
Dictionary<ulong, int> routeQueue = toVisitStart.UnorderedItems.Select(l => l.Element).Union(toVisitEnd.UnorderedItems.Select(l => l.Element)).Where(id =>
|
||||||
{
|
{
|
||||||
Node p = graph.Nodes[id];
|
Node p = graph.Nodes[id];
|
||||||
return routeNodes.Any(route => route.DistanceTo(p) < ExplorationDistanceFromRoute);
|
return routeNodes.Any(route => route.DistanceTo(p) < _explorationDistanceFromRoute);
|
||||||
}).ToDictionary(id => id, _ => int.MinValue);
|
}).ToDictionary(id => id, _ => int.MinValue);
|
||||||
PriorityQueue<ulong, int> combinedQueue = new();
|
PriorityQueue<ulong, int> combinedQueue = new();
|
||||||
foreach ((ulong key, int value) in routeQueue)
|
foreach ((ulong key, int value) in routeQueue)
|
||||||
combinedQueue.Enqueue(key, value);
|
combinedQueue.Enqueue(key, value);
|
||||||
ValueTuple<Node, Node>? newMeetingEnds = Optimize(additionalExploration, graph, combinedQueue, car, rl, priorityHelper, pathing, startNode.Value, endNode.Value, logger);
|
ValueTuple<Node, Node>? newMeetingEnds = Optimize(graph, combinedQueue, car, rl, priorityHelper, pathing, startNode.Value, endNode.Value, logger);
|
||||||
meetingEnds = newMeetingEnds ?? meetingEnds;
|
meetingEnds = newMeetingEnds ?? meetingEnds;
|
||||||
|
|
||||||
return PathFound(graph, meetingEnds!.Value.Item1, meetingEnds.Value.Item2, car, logger);
|
return PathFound(graph, meetingEnds!.Value.Item1, meetingEnds.Value.Item2, car, logger);
|
||||||
@ -140,10 +140,10 @@ namespace astar
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ValueTuple<Node, Node>? Optimize(float additionalExploration, Graph graph, PriorityQueue<ulong, int> combinedQueue, bool car, RegionLoader rl, PriorityHelper priorityHelper, PathMeasure pathing, Node startNode, Node goalNode, ILogger? logger = null)
|
private ValueTuple<Node, Node>? Optimize(Graph graph, PriorityQueue<ulong, int> combinedQueue, bool car, RegionLoader rl, PriorityHelper priorityHelper, PathMeasure pathing, Node startNode, Node goalNode, ILogger? logger = null)
|
||||||
{
|
{
|
||||||
int currentPathLength = graph.Nodes.Values.Count(node => node.PreviousNodeId is not null);
|
int currentPathLength = graph.Nodes.Values.Count(node => node.PreviousNodeId is not null);
|
||||||
int optimizeAfterFound = (int)(combinedQueue.Count * additionalExploration); //Check another x% of unexplored Paths.
|
int optimizeAfterFound = (int)(combinedQueue.Count * _explorationMultiplier); //Check another x% of unexplored Paths.
|
||||||
logger?.LogInformation($"Path found (explored {currentPathLength} Nodes). Optimizing route. (exploring {optimizeAfterFound} additional Nodes)");
|
logger?.LogInformation($"Path found (explored {currentPathLength} Nodes). Optimizing route. (exploring {optimizeAfterFound} additional Nodes)");
|
||||||
ValueTuple<Node, Node>? newMeetingEnds = null;
|
ValueTuple<Node, Node>? newMeetingEnds = null;
|
||||||
while (optimizeAfterFound-- > 0 && combinedQueue.Count > 0)
|
while (optimizeAfterFound-- > 0 && combinedQueue.Count > 0)
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
public class PriorityHelper(double totalDistance, byte maxSpeed)
|
public class PriorityHelper(double totalDistance, byte maxSpeed)
|
||||||
{
|
{
|
||||||
private readonly double _totalDistance = totalDistance;
|
|
||||||
private readonly byte _maxSpeed = maxSpeed;
|
|
||||||
public int CalculatePriority(Node current, Node neighbor, Node goal, byte speed, ValueTuple<float, float, float, float> ratingWeights)
|
public int CalculatePriority(Node current, Node neighbor, Node goal, byte speed, ValueTuple<float, float, float, float> ratingWeights)
|
||||||
{
|
{
|
||||||
double neighborDistanceToGoal = neighbor.DistanceTo(goal); //we want this to be small
|
double neighborDistanceToGoal = neighbor.DistanceTo(goal); //we want this to be small
|
||||||
@ -16,10 +14,10 @@ public class PriorityHelper(double totalDistance, byte maxSpeed)
|
|||||||
neighborDistanceToGoal * neighborDistanceToGoal) /
|
neighborDistanceToGoal * neighborDistanceToGoal) /
|
||||||
(2 * currentDistanceToGoal * currentDistanceToNeighbor)));
|
(2 * currentDistanceToGoal * currentDistanceToNeighbor)));
|
||||||
|
|
||||||
double speedRating = speed * 1.0 / _maxSpeed * 100;
|
double speedRating = speed * 1.0 / maxSpeed * 100;
|
||||||
double angleRating = 100 - (angle < 180 ? angle / 180 : (360 - angle) / 180) * 100;
|
double angleRating = 100 - (angle < 180 ? angle / 180 : (360 - angle) / 180) * 100;
|
||||||
double distanceImprovedRating = 100 - (neighborDistanceToGoal - currentDistanceToGoal ) / _totalDistance * 100;
|
double distanceImprovedRating = 100 - (neighborDistanceToGoal - currentDistanceToGoal ) / totalDistance * 100;
|
||||||
double distanceSpeedRating = ((_totalDistance / _maxSpeed) / (neighborDistanceToGoal / speed)) * 100;
|
double distanceSpeedRating = ((totalDistance / maxSpeed) / (neighborDistanceToGoal / speed)) * 100;
|
||||||
|
|
||||||
return (int)-(speedRating * ratingWeights.Item1 + angleRating * ratingWeights.Item2 + distanceImprovedRating * ratingWeights.Item3 + distanceSpeedRating * ratingWeights.Item4);
|
return (int)-(speedRating * ratingWeights.Item1 + angleRating * ratingWeights.Item2 + distanceImprovedRating * ratingWeights.Item3 + distanceSpeedRating * ratingWeights.Item4);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user