Compare commits

...

12 Commits

11 changed files with 99 additions and 25 deletions

View File

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

View File

@ -1,11 +1,49 @@
using Graph; using GeoGraph;
using Logging; using Logging;
using astar; using astar;
using OSM_XML_Importer; using OSM_XML_Importer;
Logger logger = new (LogType.CONSOLE, LogLevel.DEBUG); string[] confirmation = { "yes", "1", "true" };
Graph.Graph graph = Importer.Import(@"C:\Users\glax\Downloads\oberbayern-latest.osm", true, logger);
logger.level = LogLevel.DEBUG; Logger logger = new(LogType.CONSOLE, 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;

View File

@ -1,8 +1,11 @@
### astar # astar
Test of A* Algorithm Test of A* Algorithm on real-world road data
# Linked Repos ## Usage
`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

@ -0,0 +1,13 @@
# 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

@ -0,0 +1,4 @@
<?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

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

View File

@ -0,0 +1,7 @@
<?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 Graph; using GeoGraph;
using Graph.Utils; using GeoGraph.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 graph, Node start, Node goal, Logger? logger) public Route FindPath(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,10 +20,6 @@ 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
@ -34,7 +30,8 @@ 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);
toVisit.Add(e.neighbor); if (!toVisit.Contains(e.neighbor))
toVisit.Add(e.neighbor);
} }
} }
@ -53,14 +50,13 @@ 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();
@ -69,10 +65,8 @@ 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;
} }
@ -97,6 +91,7 @@ namespace astar
} }
return _route; return _route;
#pragma warning restore CS8604, CS8600
} }
/* /*

View File

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

View File

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

View File

@ -0,0 +1,2 @@
<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>