Compare commits
No commits in common. "08ebc9a26be44ef946c0b0a54aecf27c84704a7c" and "308579279b292c4a227fdbf416d7dc0bb6db3509" have entirely different histories.
08ebc9a26b
...
308579279b
@ -17,7 +17,6 @@
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Pathfinding\Pathfinding.csproj" />
|
||||
<ProjectReference Include="..\RenderPath\RenderPath.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -14,6 +14,17 @@ builder.Services.AddSwaggerGen();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
app.MapGet("/getRouteBeta", (float latStart, float lonStart, float latEnd, float lonEnd, Tag.SpeedType vehicle, double stayOnSameRoadPriority, double useHigherLevelRoadsPriority, double useRoadsWithLessJunctionsPriority) =>
|
||||
{
|
||||
DateTime startCalc = DateTime.Now;
|
||||
List<PathNode> result = Pathfinder.AStar("D:/stuttgart-regbez-latest", new Coordinates(latStart, lonStart),
|
||||
new Coordinates(latEnd, lonEnd), vehicle, useHigherLevelRoadsPriority, stayOnSameRoadPriority,
|
||||
useRoadsWithLessJunctionsPriority);
|
||||
PathResult pathResult = new PathResult(DateTime.Now - startCalc, result);
|
||||
return RenderPath.Renderer.DrawFromPath(result);
|
||||
}
|
||||
);
|
||||
|
||||
app.MapGet("/getRoute", (float latStart, float lonStart, float latEnd, float lonEnd, Tag.SpeedType vehicle, double stayOnSameRoadPriority, double useHigherLevelRoadsPriority, double useRoadsWithLessJunctionsPriority) =>
|
||||
{
|
||||
DateTime startCalc = DateTime.Now;
|
||||
|
@ -118,16 +118,16 @@ public class Tag
|
||||
{ WayType.secondary, 60 },
|
||||
{ WayType.tertiary, 50 },
|
||||
{ WayType.unclassified, 30 },
|
||||
{ WayType.residential, 20 },
|
||||
{ WayType.residential, 15 },
|
||||
{ WayType.motorway_link, 60 },
|
||||
{ WayType.trunk_link, 50 },
|
||||
{ WayType.primary_link, 50 },
|
||||
{ WayType.secondary_link, 50 },
|
||||
{ WayType.tertiary_link, 30 },
|
||||
{ WayType.living_street, 10 },
|
||||
{ WayType.service, 0 },
|
||||
{ WayType.service, 1 },
|
||||
{ WayType.pedestrian, 0 },
|
||||
{ WayType.track, 0 },
|
||||
{ WayType.track, 1 },
|
||||
{ WayType.bus_guideway, 0 },
|
||||
{ WayType.escape, 0 },
|
||||
{ WayType.raceway, 0 },
|
||||
|
@ -8,8 +8,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pathfinding", "Pathfinding\
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "API", "API\API.csproj", "{1D364F40-1681-4D36-A625-83B324F6AC89}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RenderPath", "RenderPath\RenderPath.csproj", "{54CAC127-4EB6-4E06-A5C8-35343C5FF76A}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -32,9 +30,5 @@ Global
|
||||
{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
|
||||
{54CAC127-4EB6-4E06-A5C8-35343C5FF76A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{54CAC127-4EB6-4E06-A5C8-35343C5FF76A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{54CAC127-4EB6-4E06-A5C8-35343C5FF76A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{54CAC127-4EB6-4E06-A5C8-35343C5FF76A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
@ -1,6 +1,5 @@
|
||||
using OSMDatastructure;
|
||||
using OSMDatastructure.Graph;
|
||||
using RenderPath;
|
||||
using static OSMDatastructure.Tag;
|
||||
using WayType = OSMDatastructure.Tag.WayType;
|
||||
|
||||
@ -29,17 +28,7 @@ public static class Pathfinder
|
||||
{
|
||||
OsmNode currentNode = openSetfScore.Dequeue();
|
||||
if (currentNode.Equals(goalNode))
|
||||
{
|
||||
Console.WriteLine("Path found.");
|
||||
List<PathNode> path = GetPath(cameFromDict, goalNode, regionManager);
|
||||
Console.WriteLine("Rendering.");
|
||||
List<Coordinates> coords = new();
|
||||
foreach(PathNode pn in path)
|
||||
coords.Add(pn.coordinates);
|
||||
Renderer.DrawLoadedNodes(gScore, coords, workingDir);
|
||||
Console.WriteLine("Done.");
|
||||
return path;
|
||||
}
|
||||
return GetPath(cameFromDict, goalNode, regionManager);
|
||||
|
||||
foreach (OsmEdge edge in currentNode.edges)
|
||||
{
|
||||
@ -96,7 +85,7 @@ public static class Pathfinder
|
||||
double distance = Utils.DistanceBetween(fromNode, neighborNode);
|
||||
double speed = regionManager.GetSpeedForEdge(fromNode, edge.wayId, vehicle);
|
||||
double prio = GetPriorityVehicleRoad(edge, vehicle, regionManager.GetRegion(fromNode.coordinates)!);
|
||||
return distance / (speed + prio * 50);
|
||||
return distance / (speed + (prio * 10));
|
||||
}
|
||||
|
||||
private static double Heuristic(OsmNode fromNode, OsmNode neighborNode, OsmNode goalNode, OsmEdge edge, SpeedType vehicle, RegionManager regionManager, double roadPriorityFactor, double junctionFactor, double sameRoadFactor)
|
||||
@ -124,7 +113,7 @@ public static class Pathfinder
|
||||
|
||||
//Console.WriteLine($"{roadPriority:000.00} {sameRoadName:000.00} {junctionCount:000.00} {distanceImprovement:+000.00;-000.00;0000.00}");
|
||||
|
||||
return Utils.DistanceBetween(neighborNode, goalNode) - (roadPriority + sameRoadName + junctionCount) * 20;
|
||||
return Utils.DistanceBetween(neighborNode, goalNode) - (roadPriority + sameRoadName + junctionCount) * 100;
|
||||
}
|
||||
|
||||
private static double GetPriorityVehicleRoad(OsmEdge edge, SpeedType vehicle, Region region)
|
||||
|
@ -8,7 +8,6 @@
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OSMDatastructure\OSMDatastructure.csproj" />
|
||||
<ProjectReference Include="..\RenderPath\RenderPath.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -1,17 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OSMDatastructure\OSMDatastructure.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -1,79 +0,0 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using OSMDatastructure.Graph;
|
||||
|
||||
namespace RenderPath;
|
||||
|
||||
public class Renderer
|
||||
{
|
||||
[SuppressMessage("Interoperability", "CA1416:Plattformkompatibilität überprüfen")]
|
||||
|
||||
public static void DrawLoadedNodes(Dictionary<OsmNode, double> gScoreDict, List<Coordinates> pathCoordinates, string workingDir)
|
||||
{
|
||||
float minLat = gScoreDict.Min(kv => kv.Key.coordinates.latitude);
|
||||
float minLon = gScoreDict.Min(kv => kv.Key.coordinates.longitude);
|
||||
float maxLat = gScoreDict.Max(kv => kv.Key.coordinates.latitude);
|
||||
float maxLon = gScoreDict.Max(kv => kv.Key.coordinates.longitude);
|
||||
|
||||
double minWeight = gScoreDict.Min(kv => kv.Value);
|
||||
double maxWeight = gScoreDict.Max(kv => kv.Value);
|
||||
|
||||
float latDiff = maxLat - minLat;
|
||||
float lonDiff = maxLon - minLon;
|
||||
|
||||
const int imageMaxSize = 10000;
|
||||
float scaleFactor = latDiff > lonDiff ? imageMaxSize / latDiff : imageMaxSize / lonDiff;
|
||||
|
||||
int pixelsX = (int)(lonDiff * scaleFactor);
|
||||
int pixelsY = (int)(latDiff * scaleFactor);
|
||||
|
||||
Bitmap ret = new Bitmap(pixelsX, pixelsY, PixelFormat.Format32bppRgb);
|
||||
Graphics g = Graphics.FromImage(ret);
|
||||
g.Clear(Color.White);
|
||||
|
||||
Color start = Color.FromArgb(0, 0, 255);
|
||||
Color center = Color.FromArgb(255, 255, 0);
|
||||
Color end = Color.FromArgb(0, 255, 0);
|
||||
|
||||
foreach (KeyValuePair<OsmNode, double> kv in gScoreDict)
|
||||
{
|
||||
double percentage = (kv.Value - minWeight) / (maxWeight - minWeight);
|
||||
Brush b = new SolidBrush(GradientPick(percentage, start, center, end));
|
||||
float x = (kv.Key.coordinates.longitude - minLon) * scaleFactor;
|
||||
float y = (maxLat - kv.Key.coordinates.latitude) * scaleFactor;
|
||||
g.FillEllipse(b, x, y, 2, 2);
|
||||
}
|
||||
|
||||
Pen p = new Pen(Color.Red, 2);
|
||||
|
||||
for (int i = 0; i < pathCoordinates.Count - 1; i++)
|
||||
{
|
||||
Coordinates c1 = pathCoordinates[i];
|
||||
Coordinates c2 = pathCoordinates[i+1];
|
||||
Point p1 = new(Convert.ToInt32((c1.longitude - minLon) * scaleFactor), Convert.ToInt32((maxLat - c1.latitude) * scaleFactor));
|
||||
Point p2 = new(Convert.ToInt32((c2.longitude - minLon) * scaleFactor), Convert.ToInt32((maxLat - c2.latitude) * scaleFactor));
|
||||
g.DrawLine(p, p1, p2);
|
||||
}
|
||||
|
||||
ret.Save(Path.Join(Directory.GetParent(workingDir)!.FullName, "routing.png"), ImageFormat.Bmp);
|
||||
}
|
||||
|
||||
/*
|
||||
* https://stackoverflow.com/questions/55601338/get-a-color-value-within-a-gradient-based-on-a-value
|
||||
*/
|
||||
private static int LinearInterp(int start, int end, double percentage) => start + (int)Math.Round(percentage * (end - start));
|
||||
private static Color ColorInterp(Color start, Color end, double percentage) =>
|
||||
Color.FromArgb(LinearInterp(start.A, end.A, percentage),
|
||||
LinearInterp(start.R, end.R, percentage),
|
||||
LinearInterp(start.G, end.G, percentage),
|
||||
LinearInterp(start.B, end.B, percentage));
|
||||
private static Color GradientPick(double percentage, Color Start, Color Center, Color End) {
|
||||
if (percentage < 0.5)
|
||||
return ColorInterp(Start, Center, percentage / 0.5);
|
||||
else if (percentage == 0.5)
|
||||
return Center;
|
||||
else
|
||||
return ColorInterp(Center, End, (percentage - 0.5)/0.5);
|
||||
}
|
||||
}
|
@ -159,7 +159,7 @@ public class RegionConverter
|
||||
WriteTags(ref regionTagsFileStreams, ref writtenWayTagsInRegion, nodeRegions[node2Id],
|
||||
currentTags, outputPath);
|
||||
}
|
||||
else
|
||||
else if (currentTags.ContainsKey(Tag.TagType.forward) && (bool)currentTags[Tag.TagType.forward])
|
||||
{
|
||||
OsmEdge n12e = new OsmEdge(currentTags[Tag.TagType.id], node1Id, node2Id,
|
||||
nodeRegions[node2Id]);
|
||||
|
@ -13,14 +13,21 @@ public class Server
|
||||
Console.SetOut(newConsole);
|
||||
Console.SetError(newConsole);
|
||||
|
||||
//RegionConverter.ConvertXMLToRegions("D:/stuttgart-regbez-latest.osm", "D:/stuttgart-regbez-latest");
|
||||
RegionConverter.ConvertXMLToRegions("D:/stuttgart-regbez-latest.osm", "D:/stuttgart-regbez-latest");
|
||||
//RegionConverter.ConvertXMLToRegions("D:/map.osm", "D:/map");
|
||||
//RegionConverter.ConvertXMLToRegions("D:/germany-latest.osm", "D:/germany-latest");
|
||||
|
||||
Coordinates start = new Coordinates( 48.7933798f, 9.8275859f);
|
||||
Coordinates finish = new Coordinates( 48.8407632f, 10.0676979f);
|
||||
List<PathNode> result = Pathfinder.AStar("D:/stuttgart-regbez-latest", start,
|
||||
finish, Tag.SpeedType.car, 20, 2,
|
||||
0);
|
||||
|
||||
/*
|
||||
Coordinates start = new Coordinates(48.794567f, 9.820625f);
|
||||
Coordinates finish = new Coordinates(48.79593f, 9.824013f);
|
||||
DateTime startTime = DateTime.Now;
|
||||
OsmNode[] path = Pathfinder.CustomAStar("D:/map", start, finish, Tag.SpeedType.car).ToArray();
|
||||
TimeSpan duration = DateTime.Now - startTime;
|
||||
Console.WriteLine($"Took {duration.TotalMilliseconds}ms ({duration:g})");
|
||||
for (int i = 0; i < path.Length - 1; i++)
|
||||
{
|
||||
Console.WriteLine(path[i]);
|
||||
}
|
||||
Console.WriteLine();*/
|
||||
}
|
||||
}
|
@ -9,7 +9,6 @@
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Pathfinding\Pathfinding.csproj" />
|
||||
<ProjectReference Include="..\RenderPath\RenderPath.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
Loading…
Reference in New Issue
Block a user