Compare commits

..

No commits in common. "db6d6ccaefeb9c4f2920cb7e23e58beac56f7ae5" and "f6d55c7f3e33e0234f16a4ba1115f5fa83f41013" have entirely different histories.

11 changed files with 25 additions and 99 deletions

View File

@ -2,10 +2,9 @@
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework> <TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<LangVersion>12</LangVersion>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@ -1,49 +1,11 @@
using GeoGraph; using Graph;
using Logging; using Logging;
using astar; using astar;
using OSM_XML_Importer; using OSM_XML_Importer;
string[] confirmation = { "yes", "1", "true" }; Logger logger = new (LogType.CONSOLE, LogLevel.DEBUG);
Graph.Graph graph = Importer.Import(@"C:\Users\glax\Downloads\oberbayern-latest.osm", true, logger);
Logger logger = new(LogType.CONSOLE, LogLevel.DEBUG); logger.level = LogLevel.DEBUG;
string xmlPath;
bool onlyJunctions;
switch (args.Length)
{
case 0:
xmlPath = @"";
onlyJunctions = true;
break;
case 1:
xmlPath = args[0];
onlyJunctions = true;
if (!File.Exists(xmlPath))
{
logger.Log(LogLevel.INFO, "File {0} does not exist.", xmlPath);
throw new FileNotFoundException(xmlPath);
}
break;
case 2:
xmlPath = args[0];
if (!File.Exists(xmlPath))
{
logger.Log(LogLevel.INFO, "File {0} does not exist.", xmlPath);
throw new FileNotFoundException(xmlPath);
}
if (confirmation.Contains(args[1].ToLower()))
onlyJunctions = true;
else
onlyJunctions = false;
break;
default:
logger.Log(LogLevel.INFO, "Invalid Arguments.");
logger.Log(LogLevel.INFO, "Arguments can be:");
logger.Log(LogLevel.INFO, "arg0 Path to file: string");
logger.Log(LogLevel.INFO, "arg1 onlyJunctions: 'yes', '1', 'true'");
return;
}
Graph graph = Importer.Import(xmlPath, onlyJunctions, logger);
Random r = new(); Random r = new();
Route _route; Route _route;
@ -57,4 +19,4 @@ do
_route = new Astar().FindPath(graph, n1, n2, logger); _route = new Astar().FindPath(graph, n1, n2, logger);
} while (!_route.routeFound); } while (!_route.routeFound);
logger.Log(LogLevel.INFO, "Press Enter to find new path."); logger.Log(LogLevel.INFO, "Press Enter to find new path.");
} while (Console.ReadKey().Key.Equals(ConsoleKey.Enter)); } while (Console.ReadKey().Key.Equals(ConsoleKey.Enter));

View File

@ -1,11 +1,8 @@
# astar ### astar
Test of A* Algorithm on real-world road data Test of A* Algorithm
## Usage # Linked Repos
`Executable.exe <path to osm.xml> <junctions-only-mode 'yes','1','true'>`
### Linked Repos
- [Logging](https://github.com/C9Glax/Logging)
- [OSM-XML-Importer](https://github.com/C9Glax/OSM-XML-Importer) - [OSM-XML-Importer](https://github.com/C9Glax/OSM-XML-Importer)
- [Geo-Graph](https://github.com/C9Glax/Geo-Graph) - [Geo-Graph](https://github.com/C9Glax/Geo-Graph)
- [OSM-Landmarks](https://github.com/C9Glax/OSM-Landmarks)

View File

@ -1,13 +0,0 @@
# Default ignored files
/shelf/
/workspace.xml
# Rider ignored files
/projectSettingsUpdater.xml
/.idea.astar.iml
/contentModel.xml
/modules.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

View File

@ -1,4 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
</project>

View File

@ -1,10 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="UserContentModel">
<attachedFolders>
<Path>../../astar</Path>
</attachedFolders>
<explicitIncludes />
<explicitExcludes />
</component>
</project>

View File

@ -1,7 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>

View File

@ -1,6 +1,6 @@
using Logging; using Logging;
using GeoGraph; using Graph;
using GeoGraph.Utils; using Graph.Utils;
namespace astar namespace astar
{ {
@ -10,7 +10,7 @@ namespace astar
private Dictionary<Node, float> goalDistance = new(); private Dictionary<Node, float> goalDistance = new();
private Dictionary<Node, Node> previousNode = new(); private Dictionary<Node, Node> previousNode = new();
public Route FindPath(Graph graph, Node start, Node goal, Logger? logger) public Route FindPath(Graph.Graph graph, Node start, Node goal, Logger? logger)
{ {
logger?.Log(LogLevel.INFO, "From {0:000.00000}#{1:000.00000} to {2:000.00000}#{3:000.00000} Great-Circle {4:00000.00}km", start.lat, start.lon, goal.lat, goal.lon, Utils.DistanceBetweenNodes(start, goal)/1000); logger?.Log(LogLevel.INFO, "From {0:000.00000}#{1:000.00000} to {2:000.00000}#{3:000.00000} Great-Circle {4:00000.00}km", start.lat, start.lon, goal.lat, goal.lon, Utils.DistanceBetweenNodes(start, goal)/1000);
List<Node> toVisit = new(); List<Node> toVisit = new();
@ -20,6 +20,10 @@ namespace astar
SetDistanceToGoal(start, Convert.ToSingle(Utils.DistanceBetweenNodes(start, goal))); SetDistanceToGoal(start, Convert.ToSingle(Utils.DistanceBetweenNodes(start, goal)));
while (toVisit.Count > 0 && GetTimeRequiredToReach(toVisit[0]) < GetTimeRequiredToReach(goal)) while (toVisit.Count > 0 && GetTimeRequiredToReach(toVisit[0]) < GetTimeRequiredToReach(goal))
{ {
if(currentNode == goal)
{
logger?.Log(LogLevel.INFO, "Way found, checking for shorter option.");
}
currentNode = toVisit.First(); currentNode = toVisit.First();
logger?.Log(LogLevel.VERBOSE, "toVisit-length: {0} path-length: {1} goal-distance: {2}", toVisit.Count, timeRequired[currentNode], goalDistance[currentNode]); logger?.Log(LogLevel.VERBOSE, "toVisit-length: {0} path-length: {1} goal-distance: {2}", toVisit.Count, timeRequired[currentNode], goalDistance[currentNode]);
//Check all neighbors of current node //Check all neighbors of current node
@ -30,8 +34,7 @@ namespace astar
SetDistanceToGoal(e.neighbor, Convert.ToSingle(Utils.DistanceBetweenNodes(e.neighbor, goal))); SetDistanceToGoal(e.neighbor, Convert.ToSingle(Utils.DistanceBetweenNodes(e.neighbor, goal)));
SetTimeRequiredToReach(e.neighbor, GetTimeRequiredToReach(currentNode) + e.time); SetTimeRequiredToReach(e.neighbor, GetTimeRequiredToReach(currentNode) + e.time);
SetPreviousNodeOf(e.neighbor, currentNode); SetPreviousNodeOf(e.neighbor, currentNode);
if (!toVisit.Contains(e.neighbor)) toVisit.Add(e.neighbor);
toVisit.Add(e.neighbor);
} }
} }
@ -50,13 +53,14 @@ namespace astar
return new Route(new List<Step>(), false, float.MaxValue, float.MaxValue); return new Route(new List<Step>(), false, float.MaxValue, float.MaxValue);
} }
#pragma warning disable CS8604, CS8600 // Route was found, so has to have a previous node and edges
List<Node> tempNodes = new(); List<Node> tempNodes = new();
tempNodes.Add(goal); tempNodes.Add(goal);
while(currentNode != start) while(currentNode != start)
{ {
#pragma warning disable CS8604, CS8600 // Route was found, so has to have a previous node
tempNodes.Add(GetPreviousNodeOf(currentNode)); tempNodes.Add(GetPreviousNodeOf(currentNode));
currentNode = GetPreviousNodeOf(currentNode); currentNode = GetPreviousNodeOf(currentNode);
#pragma warning restore CS8604, CS8600
} }
tempNodes.Reverse(); tempNodes.Reverse();
@ -65,8 +69,10 @@ namespace astar
for(int i = 0; i < tempNodes.Count - 1; i++) for(int i = 0; i < tempNodes.Count - 1; i++)
{ {
#pragma warning disable CS8600, CS8604 // Route was found, so has to have an edge
Edge e = tempNodes[i].GetEdgeToNode(tempNodes[i + 1]); Edge e = tempNodes[i].GetEdgeToNode(tempNodes[i + 1]);
steps.Add(new Step(tempNodes[i], e, GetTimeRequiredToReach(tempNodes[i]), GetDistanceToGoal(tempNodes[i]))); steps.Add(new Step(tempNodes[i], e, GetTimeRequiredToReach(tempNodes[i]), GetDistanceToGoal(tempNodes[i])));
#pragma warning restore CS8600, CS8604
totalDistance += e.distance; totalDistance += e.distance;
} }
@ -91,9 +97,8 @@ namespace astar
} }
return _route; return _route;
#pragma warning restore CS8604, CS8600
} }
/* /*
* Compares two nodes and returns the node closer to the goal * Compares two nodes and returns the node closer to the goal
* -1 => n1 smaller n2 * -1 => n1 smaller n2

View File

@ -1,4 +1,4 @@
using GeoGraph; using Graph;
namespace astar namespace astar
{ {
public class Route public class Route

View File

@ -1,10 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net8.0</TargetFramework> <TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<LangVersion>12</LangVersion>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@ -1,2 +0,0 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/AddReferences/RecentPaths/=C_003A_005CUsers_005CGlax_005CRiderProjects_005CGeo_002DGraph_005CGeo_002DGraph_005Cbin_005CDebug_005Cnet6_002E0_005CGeo_002DGraph_002Edll/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>