Compare commits
No commits in common. "72b5511c2654ef2437ecb02ee7946e9b23b4a44a" and "e9f1ba2e73f1cb1b24720b86cac92adffdcfe5b2" have entirely different histories.
72b5511c26
...
e9f1ba2e73
@ -1,22 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<TargetFramework>net7.0</TargetFramework>
|
|
||||||
<Nullable>enable</Nullable>
|
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.4" />
|
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Folder Include="Controllers" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\Pathfinding\Pathfinding.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
@ -1,37 +0,0 @@
|
|||||||
using OSMDatastructure.Graph;
|
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
|
||||||
|
|
||||||
// Add services to the container.
|
|
||||||
|
|
||||||
builder.Services.AddControllers();
|
|
||||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
|
||||||
builder.Services.AddEndpointsApiExplorer();
|
|
||||||
builder.Services.AddSwaggerGen();
|
|
||||||
|
|
||||||
var app = builder.Build();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
app.MapGet("/getRoute", (float latStart, float lonStart, float latEnd, float lonEnd) =>
|
|
||||||
{
|
|
||||||
List<OsmNode> path = Pathfinding.Pathfinder.CustomAStar("D:/stuttgart-regbez-latest", new Coordinates(latStart, lonStart), new Coordinates(latEnd, lonEnd),
|
|
||||||
Tag.SpeedType.car);
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
// Configure the HTTP request pipeline.
|
|
||||||
if (app.Environment.IsDevelopment())
|
|
||||||
{
|
|
||||||
app.UseSwagger();
|
|
||||||
app.UseSwaggerUI();
|
|
||||||
}
|
|
||||||
|
|
||||||
app.UseHttpsRedirection();
|
|
||||||
|
|
||||||
app.UseAuthorization();
|
|
||||||
|
|
||||||
app.MapControllers();
|
|
||||||
|
|
||||||
app.Run();
|
|
@ -1,41 +0,0 @@
|
|||||||
{
|
|
||||||
"$schema": "https://json.schemastore.org/launchsettings.json",
|
|
||||||
"iisSettings": {
|
|
||||||
"windowsAuthentication": false,
|
|
||||||
"anonymousAuthentication": true,
|
|
||||||
"iisExpress": {
|
|
||||||
"applicationUrl": "http://localhost:39952",
|
|
||||||
"sslPort": 44326
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"profiles": {
|
|
||||||
"http": {
|
|
||||||
"commandName": "Project",
|
|
||||||
"dotnetRunMessages": true,
|
|
||||||
"launchBrowser": true,
|
|
||||||
"launchUrl": "swagger",
|
|
||||||
"applicationUrl": "http://localhost:5057",
|
|
||||||
"environmentVariables": {
|
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"https": {
|
|
||||||
"commandName": "Project",
|
|
||||||
"dotnetRunMessages": true,
|
|
||||||
"launchBrowser": true,
|
|
||||||
"launchUrl": "swagger",
|
|
||||||
"applicationUrl": "https://localhost:7095;http://localhost:5057",
|
|
||||||
"environmentVariables": {
|
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"IIS Express": {
|
|
||||||
"commandName": "IISExpress",
|
|
||||||
"launchBrowser": true,
|
|
||||||
"launchUrl": "swagger",
|
|
||||||
"environmentVariables": {
|
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,8 +0,0 @@
|
|||||||
{
|
|
||||||
"Logging": {
|
|
||||||
"LogLevel": {
|
|
||||||
"Default": "Information",
|
|
||||||
"Microsoft.AspNetCore": "Warning"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
{
|
|
||||||
"Logging": {
|
|
||||||
"LogLevel": {
|
|
||||||
"Default": "Information",
|
|
||||||
"Microsoft.AspNetCore": "Warning"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"AllowedHosts": "*"
|
|
||||||
}
|
|
@ -1,5 +1,4 @@
|
|||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Text.Json.Serialization;
|
|
||||||
|
|
||||||
namespace OSMDatastructure.Graph;
|
namespace OSMDatastructure.Graph;
|
||||||
|
|
||||||
@ -9,7 +8,6 @@ public class Coordinates
|
|||||||
public float latitude { get; }
|
public float latitude { get; }
|
||||||
public float longitude { get; }
|
public float longitude { get; }
|
||||||
|
|
||||||
[JsonConstructor]
|
|
||||||
public Coordinates(float latitude, float longitude)
|
public Coordinates(float latitude, float longitude)
|
||||||
{
|
{
|
||||||
this.latitude = latitude;
|
this.latitude = latitude;
|
||||||
|
@ -6,8 +6,4 @@
|
|||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="System.Runtime.Serialization.Json" Version="4.3.0" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
using System.Text.Json.Serialization;
|
|
||||||
|
|
||||||
namespace OSMDatastructure.Graph;
|
namespace OSMDatastructure.Graph;
|
||||||
|
|
||||||
[Serializable]
|
[Serializable]
|
||||||
@ -11,7 +9,6 @@ public class OsmEdge
|
|||||||
public ulong neighborRegion { get; }
|
public ulong neighborRegion { get; }
|
||||||
|
|
||||||
|
|
||||||
[JsonConstructor]
|
|
||||||
public OsmEdge(ulong wayId, ulong startId, ulong neighborId, ulong neighborRegion)
|
public OsmEdge(ulong wayId, ulong startId, ulong neighborId, ulong neighborRegion)
|
||||||
{
|
{
|
||||||
this.wayId = wayId;
|
this.wayId = wayId;
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
using System.Text.Json.Serialization;
|
|
||||||
|
|
||||||
namespace OSMDatastructure.Graph;
|
namespace OSMDatastructure.Graph;
|
||||||
|
|
||||||
@ -8,13 +7,13 @@ namespace OSMDatastructure.Graph;
|
|||||||
public class OsmNode
|
public class OsmNode
|
||||||
{
|
{
|
||||||
public ulong nodeId { get; }
|
public ulong nodeId { get; }
|
||||||
public HashSet<OsmEdge> edges { get; set; }
|
public HashSet<OsmEdge> edges { get; }
|
||||||
public Coordinates coordinates { get; }
|
public Coordinates coordinates { get; }
|
||||||
|
|
||||||
[JsonIgnore][NonSerialized]public OsmNode? previousPathNode = null;
|
[NonSerialized]public OsmNode? previousPathNode = null;
|
||||||
[JsonInclude][NonSerialized]public double currentPathWeight = double.MaxValue;
|
[NonSerialized]public double currentPathWeight = double.MaxValue;
|
||||||
[JsonInclude][NonSerialized]public double currentPathLength = double.MaxValue;
|
[NonSerialized]public double currentPathLength = double.MaxValue;
|
||||||
[JsonIgnore][NonSerialized]public double directDistanceToGoal = double.MaxValue;
|
[NonSerialized]public double directDistanceToGoal = double.MaxValue;
|
||||||
|
|
||||||
[OnDeserialized]
|
[OnDeserialized]
|
||||||
internal void SetDefaultValues(StreamingContext context)
|
internal void SetDefaultValues(StreamingContext context)
|
||||||
@ -31,7 +30,6 @@ public class OsmNode
|
|||||||
this.coordinates = new Coordinates(lat, lon);
|
this.coordinates = new Coordinates(lat, lon);
|
||||||
}
|
}
|
||||||
|
|
||||||
[JsonConstructor]
|
|
||||||
public OsmNode(ulong nodeId, Coordinates coordinates)
|
public OsmNode(ulong nodeId, Coordinates coordinates)
|
||||||
{
|
{
|
||||||
this.nodeId = nodeId;
|
this.nodeId = nodeId;
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
using System.Text.Json;
|
using System.Runtime.Serialization.Formatters.Binary;
|
||||||
using System.Text.Json.Serialization;
|
|
||||||
using OSMDatastructure.Graph;
|
using OSMDatastructure.Graph;
|
||||||
|
|
||||||
namespace OSMDatastructure;
|
namespace OSMDatastructure;
|
||||||
@ -7,32 +6,21 @@ namespace OSMDatastructure;
|
|||||||
[Serializable]
|
[Serializable]
|
||||||
public class Region
|
public class Region
|
||||||
{
|
{
|
||||||
[JsonIgnore]public const float RegionSize = 0.025f;
|
[NonSerialized]public const float RegionSize = 0.025f;
|
||||||
[JsonIgnore]public static readonly JsonSerializerOptions serializerOptions = new()
|
public readonly HashSet<OsmNode> nodes = new();
|
||||||
{
|
|
||||||
IncludeFields = true,
|
|
||||||
MaxDepth = 32,
|
|
||||||
IgnoreReadOnlyFields = false//,
|
|
||||||
//WriteIndented = true
|
|
||||||
};
|
|
||||||
|
|
||||||
[JsonRequired]public HashSet<OsmNode> nodes { get; set; }
|
|
||||||
public ulong regionHash { get; }
|
public ulong regionHash { get; }
|
||||||
[JsonRequired]public TagManager tagManager { get; set; }
|
public TagManager tagManager { get; }
|
||||||
|
|
||||||
[JsonConstructor]
|
|
||||||
public Region(ulong regionHash)
|
public Region(ulong regionHash)
|
||||||
{
|
{
|
||||||
this.regionHash = regionHash;
|
this.regionHash = regionHash;
|
||||||
tagManager = new TagManager();
|
tagManager = new TagManager();
|
||||||
nodes = new HashSet<OsmNode>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Region(Coordinates coordinates)
|
public Region(Coordinates coordinates)
|
||||||
{
|
{
|
||||||
regionHash = Coordinates.GetRegionHashCode(coordinates);
|
regionHash = Coordinates.GetRegionHashCode(coordinates);
|
||||||
tagManager = new TagManager();
|
tagManager = new TagManager();
|
||||||
nodes = new HashSet<OsmNode>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool ContainsNode(ulong id)
|
public bool ContainsNode(ulong id)
|
||||||
@ -61,8 +49,11 @@ public class Region
|
|||||||
|
|
||||||
public static Region? FromFile(string filePath)
|
public static Region? FromFile(string filePath)
|
||||||
{
|
{
|
||||||
|
BinaryFormatter bFormatter = new BinaryFormatter();
|
||||||
|
#pragma warning disable SYSLIB0011
|
||||||
if (File.Exists(filePath))
|
if (File.Exists(filePath))
|
||||||
return JsonSerializer.Deserialize<Region>(new FileStream(filePath, FileMode.Open), serializerOptions)!;
|
return (Region)bFormatter.Deserialize(new FileStream(filePath, FileMode.Open));
|
||||||
|
#pragma warning restore SYSLIB0011
|
||||||
else return null;
|
else return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,3 @@
|
|||||||
using System.Text.Json;
|
|
||||||
using System.Text.Json.Serialization;
|
|
||||||
|
|
||||||
namespace OSMDatastructure.Graph;
|
namespace OSMDatastructure.Graph;
|
||||||
|
|
||||||
[Serializable]
|
[Serializable]
|
||||||
@ -9,36 +6,11 @@ public class Tag
|
|||||||
public TagType key { get; }
|
public TagType key { get; }
|
||||||
public dynamic value { get; }
|
public dynamic value { get; }
|
||||||
|
|
||||||
[JsonConstructor]
|
|
||||||
public Tag(TagType key, dynamic value)
|
public Tag(TagType key, dynamic value)
|
||||||
{
|
{
|
||||||
this.key = key;
|
this.key = key;
|
||||||
if (value is JsonElement)
|
this.value = value;
|
||||||
{
|
|
||||||
switch (key)
|
|
||||||
{
|
|
||||||
case TagType.highway:
|
|
||||||
this.value = (WayType)value.GetByte();
|
|
||||||
break;
|
|
||||||
case TagType.maxspeed:
|
|
||||||
this.value = value.GetByte();
|
|
||||||
break;
|
|
||||||
case TagType.forward:
|
|
||||||
case TagType.oneway:
|
|
||||||
this.value = value.GetBoolean();
|
|
||||||
break;
|
|
||||||
case TagType.id:
|
|
||||||
this.value = value.GetUInt64();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
this.value = value;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Tag FromBytes(byte[] bytes)
|
public static Tag FromBytes(byte[] bytes)
|
||||||
|
@ -1,16 +1,11 @@
|
|||||||
using System.Text.Json.Serialization;
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
namespace OSMDatastructure.Graph;
|
namespace OSMDatastructure.Graph;
|
||||||
|
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public class TagManager
|
public class TagManager
|
||||||
{
|
{
|
||||||
[JsonRequired]public Dictionary<ulong, HashSet<Tag>> wayTagSets { get; set; }
|
public readonly Dictionary<ulong, HashSet<Tag>> wayTagSets = new();
|
||||||
|
|
||||||
public TagManager()
|
|
||||||
{
|
|
||||||
wayTagSets = new();
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool ContainsKey(ulong wayId, Tag.TagType key)
|
public bool ContainsKey(ulong wayId, Tag.TagType key)
|
||||||
{
|
{
|
||||||
|
@ -6,8 +6,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OSMDatastructure", "OSMData
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pathfinding", "Pathfinding\Pathfinding.csproj", "{D4AA1C47-98D4-415C-B026-3BC25B6B6F9D}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pathfinding", "Pathfinding\Pathfinding.csproj", "{D4AA1C47-98D4-415C-B026-3BC25B6B6F9D}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "API", "API\API.csproj", "{1D364F40-1681-4D36-A625-83B324F6AC89}"
|
|
||||||
EndProject
|
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@ -26,9 +24,5 @@ Global
|
|||||||
{D4AA1C47-98D4-415C-B026-3BC25B6B6F9D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{D4AA1C47-98D4-415C-B026-3BC25B6B6F9D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{D4AA1C47-98D4-415C-B026-3BC25B6B6F9D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{D4AA1C47-98D4-415C-B026-3BC25B6B6F9D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{D4AA1C47-98D4-415C-B026-3BC25B6B6F9D}.Release|Any CPU.Build.0 = Release|Any CPU
|
{D4AA1C47-98D4-415C-B026-3BC25B6B6F9D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{1D364F40-1681-4D36-A625-83B324F6AC89}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{1D364F40-1681-4D36-A625-83B324F6AC89}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{1D364F40-1681-4D36-A625-83B324F6AC89}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{1D364F40-1681-4D36-A625-83B324F6AC89}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
@ -4,7 +4,7 @@ using OSMImporter;
|
|||||||
|
|
||||||
namespace Pathfinding;
|
namespace Pathfinding;
|
||||||
|
|
||||||
public static class Pathfinder
|
public class Pathfinder
|
||||||
{
|
{
|
||||||
public static List<OsmNode> CustomAStar(string workingDir, Coordinates start, Coordinates goal, Tag.SpeedType vehicle)
|
public static List<OsmNode> CustomAStar(string workingDir, Coordinates start, Coordinates goal, Tag.SpeedType vehicle)
|
||||||
{
|
{
|
||||||
@ -14,8 +14,8 @@ public static class Pathfinder
|
|||||||
if (startRegion is null || goalRegion is null)
|
if (startRegion is null || goalRegion is null)
|
||||||
return new List<OsmNode>();
|
return new List<OsmNode>();
|
||||||
|
|
||||||
OsmNode? startNode = ClosestNodeToCoordinates(start, startRegion, vehicle, ref regionManager);
|
OsmNode? startNode = ClosestNodeToCoordinates(start, startRegion, vehicle);
|
||||||
OsmNode? goalNode = ClosestNodeToCoordinates(goal, goalRegion, vehicle, ref regionManager);
|
OsmNode? goalNode = ClosestNodeToCoordinates(goal, goalRegion, vehicle);
|
||||||
if (startNode == null || goalNode == null)
|
if (startNode == null || goalNode == null)
|
||||||
return new List<OsmNode>();
|
return new List<OsmNode>();
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ public static class Pathfinder
|
|||||||
OsmNode closestNodeToGoal = startNode;
|
OsmNode closestNodeToGoal = startNode;
|
||||||
bool stop = false;
|
bool stop = false;
|
||||||
|
|
||||||
while (toVisit.Count > 0)
|
while (toVisit.Count > 0 && !stop)
|
||||||
{
|
{
|
||||||
closestNodeToGoal = toVisit.Dequeue();
|
closestNodeToGoal = toVisit.Dequeue();
|
||||||
Console.WriteLine($"{toVisit.Count:000} {closestNodeToGoal.directDistanceToGoal:#.00} current:{closestNodeToGoal}");
|
Console.WriteLine($"{toVisit.Count:000} {closestNodeToGoal.directDistanceToGoal:#.00} current:{closestNodeToGoal}");
|
||||||
@ -39,18 +39,15 @@ public static class Pathfinder
|
|||||||
{
|
{
|
||||||
double newPotentialWeight =
|
double newPotentialWeight =
|
||||||
closestNodeToGoal.currentPathWeight + EdgeWeight(closestNodeToGoal, neighbor, edge.wayId, vehicle, ref regionManager);
|
closestNodeToGoal.currentPathWeight + EdgeWeight(closestNodeToGoal, neighbor, edge.wayId, vehicle, ref regionManager);
|
||||||
if (newPotentialWeight < neighbor.currentPathWeight)
|
if (neighbor.currentPathWeight > newPotentialWeight)
|
||||||
{
|
{
|
||||||
neighbor.previousPathNode = closestNodeToGoal;
|
neighbor.previousPathNode = closestNodeToGoal;
|
||||||
neighbor.currentPathWeight = newPotentialWeight;
|
neighbor.currentPathWeight = newPotentialWeight;
|
||||||
neighbor.currentPathLength = closestNodeToGoal.currentPathLength + Utils.DistanceBetween(closestNodeToGoal, neighbor);
|
neighbor.currentPathLength = closestNodeToGoal.currentPathLength + Utils.DistanceBetween(closestNodeToGoal, neighbor);
|
||||||
|
|
||||||
if (neighbor.Equals(goalNode) || closestNodeToGoal.directDistanceToGoal < 10)
|
if (neighbor.Equals(goalNode) || closestNodeToGoal.directDistanceToGoal < 10) //change for faster
|
||||||
{
|
|
||||||
stop = true;
|
stop = true;
|
||||||
goalNode = neighbor;
|
else
|
||||||
}
|
|
||||||
else if(!stop)
|
|
||||||
{
|
{
|
||||||
neighbor.directDistanceToGoal = Utils.DistanceBetween(neighbor, goalNode);
|
neighbor.directDistanceToGoal = Utils.DistanceBetween(neighbor, goalNode);
|
||||||
toVisit.Enqueue(neighbor, neighbor.directDistanceToGoal);
|
toVisit.Enqueue(neighbor, neighbor.directDistanceToGoal);
|
||||||
@ -61,7 +58,7 @@ public static class Pathfinder
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<OsmNode> path = new();
|
List<OsmNode> path = new();
|
||||||
OsmNode? currentNode = goalNode;
|
OsmNode? currentNode = closestNodeToGoal;
|
||||||
while (currentNode != null && !currentNode.Equals(startNode))
|
while (currentNode != null && !currentNode.Equals(startNode))
|
||||||
{
|
{
|
||||||
path.Add(currentNode);
|
path.Add(currentNode);
|
||||||
@ -73,21 +70,33 @@ public static class Pathfinder
|
|||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static OsmNode? ClosestNodeToCoordinates(Coordinates coordinates, Region region, Tag.SpeedType vehicle, ref RegionManager regionManager)
|
private static OsmNode? ClosestNodeToCoordinates(Coordinates coordinates, Region region, Tag.SpeedType vehicle)
|
||||||
{
|
{
|
||||||
OsmNode? closest = null;
|
OsmNode? closest = null;
|
||||||
double distance = double.MaxValue;
|
double distance = double.MaxValue;
|
||||||
foreach (OsmNode node in region.nodes)
|
foreach (OsmNode node in region.nodes)
|
||||||
{
|
{
|
||||||
bool hasConnectionUsingVehicle = false;
|
bool hasConnection = false;
|
||||||
foreach (OsmEdge edge in node.edges)
|
foreach (OsmEdge edge in node.edges)
|
||||||
{
|
{
|
||||||
double speed = GetSpeed(node, edge.wayId, vehicle, ref regionManager);
|
byte speed = 0;
|
||||||
|
switch (vehicle)
|
||||||
|
{
|
||||||
|
case Tag.SpeedType.road:
|
||||||
|
case Tag.SpeedType.car:
|
||||||
|
speed = Tag.defaultSpeedCar[(Tag.WayType)region.tagManager.GetTag(edge.wayId, Tag.TagType.highway)!];
|
||||||
|
break;
|
||||||
|
case Tag.SpeedType.pedestrian:
|
||||||
|
speed = Tag.defaultSpeedPedestrian[
|
||||||
|
(Tag.WayType)region.tagManager.GetTag(edge.wayId, Tag.TagType.highway)!];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (speed != 0)
|
if (speed != 0)
|
||||||
hasConnectionUsingVehicle = true;
|
hasConnection = true;
|
||||||
}
|
}
|
||||||
double nodeDistance = Utils.DistanceBetween(node, coordinates);
|
double nodeDistance = Utils.DistanceBetween(node, coordinates);
|
||||||
if (nodeDistance < distance && hasConnectionUsingVehicle)
|
if (nodeDistance < distance && hasConnection)
|
||||||
{
|
{
|
||||||
closest = node;
|
closest = node;
|
||||||
distance = nodeDistance;
|
distance = nodeDistance;
|
||||||
@ -97,37 +106,30 @@ public static class Pathfinder
|
|||||||
return closest;
|
return closest;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static double GetSpeed(OsmNode node1, ulong wayId, Tag.SpeedType vehicle, ref RegionManager regionManager)
|
private static double EdgeWeight(OsmNode node1, OsmNode node2, ulong wayId, Tag.SpeedType vehicle, ref RegionManager regionManager)
|
||||||
{
|
{
|
||||||
TagManager tags = regionManager.GetRegion(node1.coordinates)!.tagManager;
|
TagManager tags = regionManager.GetRegion(node1.coordinates)!.tagManager;
|
||||||
|
double distance = Utils.DistanceBetween(node1, node2);
|
||||||
Tag.WayType wayType = (Tag.WayType)tags.GetTag(wayId, Tag.TagType.highway)!;
|
Tag.WayType wayType = (Tag.WayType)tags.GetTag(wayId, Tag.TagType.highway)!;
|
||||||
switch (vehicle)
|
switch (vehicle)
|
||||||
{
|
{
|
||||||
case Tag.SpeedType.pedestrian:
|
case Tag.SpeedType.pedestrian:
|
||||||
byte speed = Tag.defaultSpeedPedestrian[wayType];
|
byte speed = Tag.defaultSpeedPedestrian[wayType];
|
||||||
if (speed is not 0)
|
if(speed is not 0)
|
||||||
return speed;
|
return distance / speed;
|
||||||
return 0;
|
else return Double.PositiveInfinity;
|
||||||
case Tag.SpeedType.car:
|
case Tag.SpeedType.car:
|
||||||
case Tag.SpeedType.road:
|
case Tag.SpeedType.road:
|
||||||
byte? maxSpeed = (byte?)tags.GetTag(wayId, Tag.TagType.maxspeed);
|
byte? maxspeed = (byte?)tags.GetTag(wayId, Tag.TagType.maxspeed);
|
||||||
if (maxSpeed is not null)
|
if (maxspeed is not null)
|
||||||
return (double)maxSpeed;
|
return distance / Convert.ToDouble(maxspeed);
|
||||||
maxSpeed = Tag.defaultSpeedCar[wayType];
|
else
|
||||||
if(maxSpeed is not 0)
|
maxspeed = Tag.defaultSpeedCar[wayType];
|
||||||
return (byte)maxSpeed;
|
if(maxspeed is not 0)
|
||||||
return 0;
|
return distance / Tag.defaultSpeedCar[wayType];
|
||||||
|
else return Double.PositiveInfinity;;
|
||||||
default:
|
default:
|
||||||
return 0;
|
return double.PositiveInfinity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static double EdgeWeight(OsmNode node1, OsmNode node2, ulong wayId, Tag.SpeedType vehicle, ref RegionManager regionManager)
|
|
||||||
{
|
|
||||||
double distance = Utils.DistanceBetween(node1, node2);
|
|
||||||
double speed = GetSpeed(node1, wayId, vehicle, ref regionManager);
|
|
||||||
if (speed is not 0)
|
|
||||||
return distance / speed;
|
|
||||||
return double.PositiveInfinity;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,6 +1,5 @@
|
|||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Runtime.Serialization.Formatters.Binary;
|
using System.Runtime.Serialization.Formatters.Binary;
|
||||||
using System.Text.Json;
|
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
using OSMDatastructure;
|
using OSMDatastructure;
|
||||||
using OSMDatastructure.Graph;
|
using OSMDatastructure.Graph;
|
||||||
@ -47,6 +46,7 @@ public class RegionConverter
|
|||||||
|
|
||||||
private static Dictionary<ulong, ulong> GetNodesAndRegions(XmlReader xmlReader, string outputPath)
|
private static Dictionary<ulong, ulong> GetNodesAndRegions(XmlReader xmlReader, string outputPath)
|
||||||
{
|
{
|
||||||
|
BinaryFormatter bFormatter = new BinaryFormatter();
|
||||||
Dictionary<ulong, ulong> nodeRegions = new();
|
Dictionary<ulong, ulong> nodeRegions = new();
|
||||||
Dictionary<ulong, FileStream> regionFileStreams = new();
|
Dictionary<ulong, FileStream> regionFileStreams = new();
|
||||||
Dictionary<ulong, OsmNode> tmpAllNodes = new();
|
Dictionary<ulong, OsmNode> tmpAllNodes = new();
|
||||||
@ -82,7 +82,6 @@ public class RegionConverter
|
|||||||
|
|
||||||
foreach (ulong nodeId in currentIds.Where(key => tmpAllNodes.ContainsKey(key)))
|
foreach (ulong nodeId in currentIds.Where(key => tmpAllNodes.ContainsKey(key)))
|
||||||
{
|
{
|
||||||
BinaryFormatter bFormatter = new BinaryFormatter();
|
|
||||||
if (isHighway)
|
if (isHighway)
|
||||||
{
|
{
|
||||||
ulong regionHash = Coordinates.GetRegionHashCode(tmpAllNodes[nodeId].coordinates);
|
ulong regionHash = Coordinates.GetRegionHashCode(tmpAllNodes[nodeId].coordinates);
|
||||||
@ -222,6 +221,7 @@ public class RegionConverter
|
|||||||
|
|
||||||
private static void CombineTmpFiles(string folderPath, HashSet<ulong> regionHashes)
|
private static void CombineTmpFiles(string folderPath, HashSet<ulong> regionHashes)
|
||||||
{
|
{
|
||||||
|
BinaryFormatter bFormatter = new BinaryFormatter();
|
||||||
foreach (ulong regionId in regionHashes)
|
foreach (ulong regionId in regionHashes)
|
||||||
{
|
{
|
||||||
ValueTuple<Region, HashSet<OsmEdge>> tmpRegion = LoadRegion(folderPath, regionId);
|
ValueTuple<Region, HashSet<OsmEdge>> tmpRegion = LoadRegion(folderPath, regionId);
|
||||||
@ -233,11 +233,11 @@ public class RegionConverter
|
|||||||
startNode.edges.Add(edge);
|
startNode.edges.Add(edge);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
FileStream tmpRegionFileStream = new FileStream(Path.Join(folderPath, $"{regionId}{RegionsFileName}"), FileMode.Create);
|
||||||
using (FileStream tmpRegionFileStream = new FileStream(Path.Join(folderPath, $"{regionId}{RegionsFileName}"), FileMode.Create))
|
#pragma warning disable SYSLIB0011
|
||||||
{
|
bFormatter.Serialize(tmpRegionFileStream, tmpRegion.Item1);
|
||||||
JsonSerializer.Serialize(tmpRegionFileStream, tmpRegion.Item1, typeof(Region), Region.serializerOptions);
|
#pragma warning restore SYSLIB0011
|
||||||
}
|
tmpRegionFileStream.Dispose();
|
||||||
Directory.Delete(Path.Join(folderPath, regionId.ToString()), true);
|
Directory.Delete(Path.Join(folderPath, regionId.ToString()), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,8 +11,4 @@
|
|||||||
<ProjectReference Include="..\Pathfinding\Pathfinding.csproj" />
|
<ProjectReference Include="..\Pathfinding\Pathfinding.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="System.Runtime.Serialization.Json" Version="4.3.0" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
Loading…
Reference in New Issue
Block a user