Compare commits
No commits in common. "0758ae1d8627f8b24b701dc3726fbea6b8327665" and "eabceed59d49dae21c968df4e3ae0c750c11371f" have entirely different histories.
0758ae1d86
...
eabceed59d
@ -2,7 +2,6 @@
|
||||
using Graph;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Graph.Utils;
|
||||
using OSM_Graph.Enums;
|
||||
using OSM_Regions;
|
||||
|
||||
namespace astar
|
||||
@ -14,13 +13,13 @@ namespace astar
|
||||
{
|
||||
RegionLoader rl = new(regionSize, importFolderPath, logger: logger);
|
||||
Graph graph = Spiral(rl, startLat, startLon, regionSize);
|
||||
Graph endRegion = Spiral(rl, endLat, endLon, regionSize);
|
||||
graph.ConcatGraph(endRegion);
|
||||
KeyValuePair<ulong, Node> startNode = graph.ClosestNodeToCoordinates(startLat, startLon, car);
|
||||
startNode.Value.PreviousIsFromStart = true;
|
||||
startNode.Value.PreviousNodeId = startNode.Key;
|
||||
startNode.Value.Distance = 0f;
|
||||
|
||||
Graph endRegion = Spiral(rl, endLat, endLon, regionSize);
|
||||
graph.ConcatGraph(endRegion);
|
||||
KeyValuePair<ulong, Node> endNode = graph.ClosestNodeToCoordinates(endLat, endLon, car);
|
||||
endNode.Value.PreviousIsFromStart = false;
|
||||
endNode.Value.PreviousNodeId = endNode.Key;
|
||||
@ -42,25 +41,20 @@ namespace astar
|
||||
{
|
||||
ulong currentNodeStartId = toVisitStart.Dequeue();
|
||||
Node currentNodeStart = graph.Nodes[currentNodeStartId];
|
||||
foreach ((ulong neighborId, KeyValuePair<ulong, bool> wayId) in currentNodeStart.Neighbors)
|
||||
foreach ((ulong neighborId, ulong wayId) in currentNodeStart.Neighbors)
|
||||
{
|
||||
if (!graph.ContainsNode(neighborId))
|
||||
graph.ConcatGraph(Graph.FromGraph(rl.LoadRegionFromNodeId(neighborId)));
|
||||
if (!graph.ContainsWay(wayId.Key))
|
||||
if (!graph.ContainsWay(wayId))
|
||||
{
|
||||
foreach (global::Graph.Graph? g in rl.LoadRegionsFromWayId(wayId.Key))
|
||||
foreach (global::Graph.Graph? g in rl.LoadRegionsFromWayId(wayId))
|
||||
graph.ConcatGraph(Graph.FromGraph(g));
|
||||
}
|
||||
|
||||
OSM_Graph.Way way = graph.Ways[wayId.Key];
|
||||
Way way = graph.Ways[wayId];
|
||||
byte speed = SpeedHelper.GetSpeed(way, car);
|
||||
if(speed < 1)
|
||||
continue;
|
||||
if(wayId.Value && way.GetDirection() == WayDirection.Forwards && car)
|
||||
continue;
|
||||
if(!wayId.Value && way.GetDirection() == WayDirection.Backwards && car)
|
||||
continue;
|
||||
|
||||
Node neighborNode = graph.Nodes[neighborId];
|
||||
|
||||
if (neighborNode.PreviousIsFromStart is false)//Check if we found the opposite End
|
||||
@ -79,26 +73,20 @@ namespace astar
|
||||
|
||||
ulong currentNodeEndId = toVisitEnd.Dequeue();
|
||||
Node currentNodeEnd = graph.Nodes[currentNodeEndId];
|
||||
foreach ((ulong neighborId, KeyValuePair<ulong, bool> wayId) in currentNodeEnd.Neighbors)
|
||||
foreach ((ulong neighborId, ulong wayId) in currentNodeEnd.Neighbors)
|
||||
{
|
||||
if (!graph.ContainsNode(neighborId))
|
||||
graph.ConcatGraph(Graph.FromGraph(rl.LoadRegionFromNodeId(neighborId)));
|
||||
if (!graph.ContainsWay(wayId.Key))
|
||||
if (!graph.ContainsWay(wayId))
|
||||
{
|
||||
foreach (global::Graph.Graph? g in rl.LoadRegionsFromWayId(wayId.Key))
|
||||
foreach (global::Graph.Graph? g in rl.LoadRegionsFromWayId(wayId))
|
||||
graph.ConcatGraph(Graph.FromGraph(g));
|
||||
}
|
||||
|
||||
OSM_Graph.Way way = graph.Ways[wayId.Key];
|
||||
Way way = graph.Ways[wayId];
|
||||
byte speed = SpeedHelper.GetSpeed(way, car);
|
||||
if(speed < 1)
|
||||
continue;
|
||||
|
||||
if(wayId.Value && way.GetDirection() == WayDirection.Backwards && car)
|
||||
continue;
|
||||
if(!wayId.Value && way.GetDirection() == WayDirection.Forwards && car)
|
||||
continue;
|
||||
|
||||
Node neighborNode = graph.Nodes[neighborId];
|
||||
|
||||
if (neighborNode.PreviousIsFromStart is true)//Check if we found the opposite End
|
||||
|
@ -6,7 +6,7 @@ namespace astar;
|
||||
public class Graph
|
||||
{
|
||||
public readonly Dictionary<ulong, Node> Nodes = new();
|
||||
public readonly Dictionary<ulong, OSM_Graph.Way> Ways = new ();
|
||||
public readonly Dictionary<ulong, Way> Ways = new ();
|
||||
|
||||
public static Graph? FromGraph(global::Graph.Graph? graph)
|
||||
{
|
||||
@ -16,7 +16,7 @@ public class Graph
|
||||
foreach ((ulong id, global::Graph.Node? node) in graph.Nodes)
|
||||
ret.Nodes.Add(id, Node.FromGraphNode(node));
|
||||
foreach ((ulong id, Way? way) in graph.Ways)
|
||||
ret.Ways.Add(id, new OSM_Graph.Way(id, way.Tags, new()));
|
||||
ret.Ways.Add(id, way);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -26,7 +26,7 @@ public class Graph
|
||||
return;
|
||||
foreach ((ulong id, Node n) in graph.Nodes)
|
||||
this.Nodes.TryAdd(id, n);
|
||||
foreach ((ulong id, OSM_Graph.Way w) in graph.Ways)
|
||||
foreach ((ulong id, Way w) in graph.Ways)
|
||||
this.Ways.TryAdd(id, w);
|
||||
}
|
||||
|
||||
@ -40,7 +40,7 @@ public class Graph
|
||||
return Nodes.ContainsKey(nodeId);
|
||||
}
|
||||
|
||||
public bool ContainsWay(OSM_Graph.Way way)
|
||||
public bool ContainsWay(Way way)
|
||||
{
|
||||
return Ways.ContainsValue(way);
|
||||
}
|
||||
@ -52,7 +52,7 @@ public class Graph
|
||||
|
||||
public KeyValuePair<ulong, Node> ClosestNodeToCoordinates(float lat, float lon, bool car = true)
|
||||
{
|
||||
return Nodes.Where(n => n.Value.Neighbors.Values.Any(way => SpeedHelper.GetSpeed(Ways[way.Key], car) > 0)).MinBy(n => n.Value.DistanceTo(lat, lon));
|
||||
return Nodes.Where(n => n.Value.Neighbors.Values.Any(wayId => SpeedHelper.GetSpeed(Ways[wayId], car) > 0)).MinBy(n => n.Value.DistanceTo(lat, lon));
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
|
@ -1,6 +1,6 @@
|
||||
namespace astar;
|
||||
|
||||
public class Node(float lat, float lon, Dictionary<ulong, KeyValuePair<ulong, bool>>? neighbors = null) : global::Graph.Node(lat, lon, neighbors)
|
||||
public class Node(float lat, float lon, Dictionary<ulong, ulong>? neighbors = null) : global::Graph.Node(lat, lon, neighbors)
|
||||
{
|
||||
public ulong? PreviousNodeId = null;
|
||||
public float? Distance = null;
|
||||
|
36
astar/PathingHelper/HighwayType.cs
Normal file
36
astar/PathingHelper/HighwayType.cs
Normal file
@ -0,0 +1,36 @@
|
||||
// ReSharper disable InconsistentNaming
|
||||
// ReSharper disable UnusedMember.Global
|
||||
namespace astar.PathingHelper;
|
||||
|
||||
public enum HighwayType
|
||||
{
|
||||
NONE,
|
||||
motorway,
|
||||
trunk,
|
||||
primary,
|
||||
secondary,
|
||||
tertiary,
|
||||
unclassified,
|
||||
residential,
|
||||
motorway_link,
|
||||
trunk_link,
|
||||
primary_link,
|
||||
secondary_link,
|
||||
tertiary_link,
|
||||
living_street,
|
||||
service,
|
||||
pedestrian,
|
||||
track,
|
||||
bus_guideway,
|
||||
escape,
|
||||
raceway,
|
||||
road,
|
||||
busway,
|
||||
footway,
|
||||
bridleway,
|
||||
steps,
|
||||
corridor,
|
||||
path,
|
||||
cycleway,
|
||||
construction
|
||||
}
|
@ -1,17 +1,23 @@
|
||||
using Graph;
|
||||
using OSM_Graph.Enums;
|
||||
|
||||
namespace astar.PathingHelper;
|
||||
|
||||
internal static class SpeedHelper
|
||||
{
|
||||
public static byte GetSpeed(OSM_Graph.Way way, bool car = true)
|
||||
public static byte GetSpeed(Way way, bool car = true)
|
||||
{
|
||||
byte maxspeed = way.GetMaxSpeed();
|
||||
if (maxspeed != 0)
|
||||
return maxspeed;
|
||||
HighwayType highwayType = way.GetHighwayType();
|
||||
return car ? SpeedCar[highwayType] : SpeedPedestrian[highwayType];
|
||||
if (!way.Tags.TryGetValue("highway", out string? highwayTypeStr))
|
||||
return 0;
|
||||
if (!Enum.TryParse(highwayTypeStr, out HighwayType highwayType))
|
||||
return 0;
|
||||
byte speed = car ? SpeedCar[highwayType] : SpeedPedestrian[highwayType];
|
||||
if (speed < 1)
|
||||
return speed;
|
||||
if(!way.Tags.TryGetValue("maxspeed", out string? maxSpeedStr))
|
||||
return speed;
|
||||
if (!byte.TryParse(maxSpeedStr, out speed))
|
||||
return speed;
|
||||
return speed;
|
||||
}
|
||||
|
||||
public static byte GetMaxSpeed(bool car = true)
|
||||
|
Loading…
Reference in New Issue
Block a user