Compare commits
No commits in common. "2f24a491b2b8c2eb281688fd361e0379dab38c40" and "956948d2d7f14e516e5e4082570e5a0fd2c6253d" have entirely different histories.
2f24a491b2
...
956948d2d7
@ -61,7 +61,7 @@ if (arguments.TryGetValue(pathArg, out string[]? pathValue))
|
|||||||
converter.SplitOsmExportIntoRegionFiles(pathValue[0]);
|
converter.SplitOsmExportIntoRegionFiles(pathValue[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
Route route = new Astar().FindPath(startLat, startLon, endLat, endLon, regionSize, true, importFolderPath: importPath, logger: logger);
|
Route route = Astar.FindPath(startLat, startLon, endLat, endLon, regionSize, true, importFolderPath: importPath, logger: logger);
|
||||||
if(route.RouteFound)
|
if(route.RouteFound)
|
||||||
Console.WriteLine(route);
|
Console.WriteLine(route);
|
||||||
else
|
else
|
||||||
|
@ -6,14 +6,11 @@ using OSM_Regions;
|
|||||||
|
|
||||||
namespace astar
|
namespace astar
|
||||||
{
|
{
|
||||||
public class Astar(ValueTuple<float, float, float, float>? optimizingWeights = null, int? explorationDistance = null, int? explorationMultiplier = null)
|
public class Astar
|
||||||
{
|
{
|
||||||
private static readonly ValueTuple<float, float, float, float> DefaultPriorityWeights = new(1, 1.4f, 0, 0);
|
private static readonly ValueTuple<float, float, float, float> DefaultPriorityWeights = new(1, 1.4f, 0, 0);
|
||||||
private readonly ValueTuple<float, float, float, float> OptimizingWeights = optimizingWeights ?? new(0, 0.07f, 0, 0);
|
private static readonly ValueTuple<float, float, float, float> OptimizingWeights = new(1, 0, 0, 0.5f);
|
||||||
private int ExplorationDistanceFromRoute = explorationDistance ?? 200;
|
public static 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)
|
||||||
private 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)
|
|
||||||
{
|
{
|
||||||
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);
|
||||||
@ -67,15 +64,9 @@ namespace astar
|
|||||||
if(meetingEnds is null)
|
if(meetingEnds is null)
|
||||||
return new Route(graph, Array.Empty<Step>().ToList(), false);
|
return new Route(graph, Array.Empty<Step>().ToList(), false);
|
||||||
|
|
||||||
List<Node> routeNodes = PathFound(graph, meetingEnds.Value.Item1, meetingEnds.Value.Item2, car).Steps.Select(s => s.Node1).ToList();
|
PriorityQueue<ulong, int> combinedQueue = toVisitStart;
|
||||||
Dictionary<ulong, int> routeQueue = toVisitStart.UnorderedItems.Select(l => l.Element).Union(toVisitEnd.UnorderedItems.Select(l => l.Element)).Where(id =>
|
while(toVisitEnd.TryDequeue(out ulong id, out int prio))
|
||||||
{
|
combinedQueue.Enqueue(id, prio);
|
||||||
Node p = graph.Nodes[id];
|
|
||||||
return routeNodes.Any(route => route.DistanceTo(p) < ExplorationDistanceFromRoute);
|
|
||||||
}).ToDictionary(id => id, _ => int.MinValue);
|
|
||||||
PriorityQueue<ulong, int> combinedQueue = new();
|
|
||||||
foreach ((ulong key, int value) in routeQueue)
|
|
||||||
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(additionalExploration, graph, combinedQueue, car, rl, priorityHelper, pathing, startNode.Value, endNode.Value, logger);
|
||||||
meetingEnds = newMeetingEnds ?? meetingEnds;
|
meetingEnds = newMeetingEnds ?? meetingEnds;
|
||||||
|
|
||||||
@ -132,10 +123,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 static 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)
|
||||||
{
|
{
|
||||||
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)(currentPathLength * additionalExploration); //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)
|
||||||
|
Loading…
Reference in New Issue
Block a user