Compare commits
3 Commits
e6e0bc17ce
...
02e3b1e5a3
Author | SHA1 | Date | |
---|---|---|---|
02e3b1e5a3 | |||
d07deeccaf | |||
7bf94fa2fd |
28
Graph_Renderer/Benchmark.cs
Normal file
28
Graph_Renderer/Benchmark.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using astar;
|
||||
using astar.PathingHelper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Graph_Renderer;
|
||||
|
||||
public static class Benchmark
|
||||
{
|
||||
public static void Run(float startLat, float startLon, float endLat, float endLon, float regionSize, string importPath, string exportPath, ILogger? logger = null)
|
||||
{
|
||||
for (int explorationDistance = 1000; explorationDistance <= 1400; explorationDistance += 100)
|
||||
{
|
||||
for (int additionalExploration = 45; additionalExploration <= 80; additionalExploration += 5)
|
||||
{
|
||||
logger?.LogInformation($"Speed:{0:0.00} Angle:{0.07f:0.00} DistanceImproved:{0:0.00} DistanceSpeed:{0:0.00} ExplorationDistance:{explorationDistance:000} Additional:{additionalExploration:000}");
|
||||
string name = $"{0:0.00}${0.07f:0.00}${0:0.00}${0:0.00}${explorationDistance:000}${additionalExploration:000}";
|
||||
DateTime start = DateTime.Now;
|
||||
Route r = new Astar(new(0, 0.07f, 0, 0),explorationDistance).
|
||||
FindPath(startLat, startLon, endLat, endLon, regionSize, true, PathMeasure.Time, additionalExploration, importPath, logger);
|
||||
DateTime end = DateTime.Now;
|
||||
Directory.CreateDirectory(Path.Join(exportPath, "benchmark", name));
|
||||
File.WriteAllText(Path.Join(exportPath, "benchmark", name, "stats.txt"), $"{end - start:hh\\:mm\\:ss\\.fff}\n{r}");
|
||||
logger?.LogInformation($"Took {end-start:hh\\:mm\\:ss\\.fff}");
|
||||
Renderer.Render(r, 20000, Path.Join(exportPath, "benchmark", name, "render.png"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -16,33 +16,33 @@ public static class Coloring
|
||||
|
||||
private static readonly Dictionary<HighwayType, Pen> ColorDictionary = new() {
|
||||
{ HighwayType.NONE, DefaultPen },
|
||||
{ HighwayType.motorway, new Pen(BlueViolet, 4) },
|
||||
{ HighwayType.trunk, new Pen(Violet, 3) },
|
||||
{ HighwayType.primary, new Pen(Yellow , 3) },
|
||||
{ HighwayType.secondary, new Pen(Aqua ,2) },
|
||||
{ HighwayType.tertiary, new Pen(LightYellow ,2) },
|
||||
{ HighwayType.motorway, new Pen(OrangeRed, 4) },
|
||||
{ HighwayType.trunk, new Pen(Yellow, 3) },
|
||||
{ HighwayType.primary, new Pen(LightYellow , 3) },
|
||||
{ HighwayType.secondary, new Pen(White ,2) },
|
||||
{ HighwayType.tertiary, new Pen(White ,2) },
|
||||
{ HighwayType.unclassified, DefaultPen },
|
||||
{ HighwayType.residential, DefaultPen },
|
||||
{ HighwayType.motorway_link, new Pen(BlueViolet, 2) },
|
||||
{ HighwayType.trunk_link, new Pen(Violet, 2) },
|
||||
{ HighwayType.primary_link, new Pen(Yellow , 2) },
|
||||
{ HighwayType.secondary_link, new Pen(Aqua ,1) },
|
||||
{ HighwayType.tertiary_link, new Pen(LightYellow ,1) },
|
||||
{ HighwayType.motorway_link, new Pen(DarkOrange, 2) },
|
||||
{ HighwayType.trunk_link, new Pen(Yellow, 2) },
|
||||
{ HighwayType.primary_link, new Pen(LightYellow , 2) },
|
||||
{ HighwayType.secondary_link, new Pen(White ,1) },
|
||||
{ HighwayType.tertiary_link, new Pen(White ,1) },
|
||||
{ HighwayType.living_street, DefaultPen },
|
||||
{ HighwayType.service, DefaultPen },
|
||||
{ HighwayType.pedestrian, new Pen(ForestGreen, 1) },
|
||||
{ HighwayType.pedestrian, new Pen(Black, 1) },
|
||||
{ HighwayType.track, DefaultPen },
|
||||
{ HighwayType.bus_guideway, new Pen(Navy ,1) },
|
||||
{ HighwayType.bus_guideway, new Pen(Green ,1) },
|
||||
{ HighwayType.escape, DefaultPen },
|
||||
{ HighwayType.raceway, DefaultPen },
|
||||
{ HighwayType.road, DefaultPen },
|
||||
{ HighwayType.busway, new Pen(Navy, 1) },
|
||||
{ HighwayType.footway, new Pen(GreenYellow ,1) },
|
||||
{ HighwayType.busway, new Pen(Green, 1) },
|
||||
{ HighwayType.footway, new Pen(Black ,1) },
|
||||
{ HighwayType.bridleway, DefaultPen },
|
||||
{ HighwayType.steps, new Pen(PaleGreen, 1) },
|
||||
{ HighwayType.corridor, new Pen(Green, 1) },
|
||||
{ HighwayType.path, new Pen(Green, 1) },
|
||||
{ HighwayType.cycleway, new Pen(Salmon, 1) },
|
||||
{ HighwayType.steps, new Pen(LightSlateGray, 1) },
|
||||
{ HighwayType.corridor, new Pen(Black, 1) },
|
||||
{ HighwayType.path, new Pen(Black, 1) },
|
||||
{ HighwayType.cycleway, new Pen(Pink, 1) },
|
||||
{ HighwayType.construction, DefaultPen }
|
||||
};
|
||||
}
|
@ -18,14 +18,17 @@ if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
Argument regionArg = new (["-r", "--regionSize"], 1, "Region-Size");
|
||||
Argument importPathArg = new (["-i", "--importPath"], 1, "Region-Directory");
|
||||
Argument routeCoordinateArg = new(["-c", "--route", "--coordinates"], 4, "Start and end coordinates");
|
||||
Argument exportRenderPathArg = new(["-e", "--exportPath"], 1, "Export file path.");
|
||||
Argument benchmarkArg = new(["-b", "--benchmark"], 0, "Run tests");
|
||||
|
||||
ArgumentFetcher af = new ([regionArg, importPathArg, routeCoordinateArg]);
|
||||
ArgumentFetcher af = new ([regionArg, importPathArg, routeCoordinateArg, exportRenderPathArg, benchmarkArg]);
|
||||
|
||||
Dictionary<Argument, string[]> arguments = af.Fetch(args);
|
||||
|
||||
if (!arguments.TryGetValue(regionArg, out string[]? regionVal) ||
|
||||
!float.TryParse(regionVal[0], NumberFormatInfo.InvariantInfo, out float regionSize) ||
|
||||
!arguments.TryGetValue(importPathArg, out string[]? importPathVal) ||
|
||||
!arguments.TryGetValue(exportRenderPathArg, out string[]? exportRenderPath) ||
|
||||
!arguments.TryGetValue(routeCoordinateArg, out string[]? routeCoordinateVal) ||
|
||||
!float.TryParse(routeCoordinateVal[0], NumberFormatInfo.InvariantInfo, out float startLat) ||
|
||||
!float.TryParse(routeCoordinateVal[1], NumberFormatInfo.InvariantInfo, out float startLon) ||
|
||||
@ -37,8 +40,14 @@ if (!arguments.TryGetValue(regionArg, out string[]? regionVal) ||
|
||||
|
||||
Logger logger = new(LogLevel.Information, consoleOut: Console.Out);
|
||||
|
||||
Route r = Astar.FindPath(startLat, startLon, endLat, endLon, regionSize, true, PathMeasure.Time, importPathVal[0], logger);
|
||||
if (!arguments.ContainsKey(benchmarkArg))
|
||||
{
|
||||
Route r = new Astar().FindPath(startLat, startLon, endLat, endLon, regionSize, true, PathMeasure.Time, 300, importPathVal[0], logger);
|
||||
Renderer.Render(r, 20000, exportRenderPath[0]);
|
||||
}
|
||||
else
|
||||
Benchmark.Run(startLat, startLon, endLat, endLon, regionSize, importPathVal[0], Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Benchmark"), logger);
|
||||
|
||||
Renderer.Render(r, 30000, "render.png");
|
||||
logger.LogInformation("All done!");
|
||||
|
||||
return 0;
|
@ -16,11 +16,12 @@ public static class Renderer
|
||||
float deltaLat = maxCoordinates.Item1 - minCoordinates.Item1;
|
||||
float deltaLon = maxCoordinates.Item2 - minCoordinates.Item2;
|
||||
float multiplier = deltaLat > deltaLon ? longestEdge / deltaLat : longestEdge / deltaLon;
|
||||
int width = (int)(deltaLon * multiplier);
|
||||
int height = (int)(deltaLat * multiplier);
|
||||
|
||||
|
||||
Bitmap bitmap = new((int)(deltaLon * multiplier), (int)(deltaLat * multiplier), System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
|
||||
Bitmap bitmap = new(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
|
||||
Graphics graphics = Graphics.FromImage(bitmap);
|
||||
Pen previous = new (Color.White, 2);
|
||||
Pen previous = new (Color.LightSeaGreen, 2);
|
||||
using(GraphicsPath capPath = new ())
|
||||
{
|
||||
// A triangle
|
||||
@ -50,15 +51,27 @@ public static class Renderer
|
||||
|
||||
if (r.RouteFound)
|
||||
{
|
||||
Pen route = new(Color.Red, 2);
|
||||
Pen route = new(Color.Blue, 4);
|
||||
TimeSpan previousPrint = TimeSpan.Zero;
|
||||
float distance = 0;
|
||||
TimeSpan time = TimeSpan.Zero;
|
||||
foreach (Step step in r.Steps)
|
||||
{
|
||||
Point startCoordinates = PixelCoordinatesFromGeoCoordinates(step.Node1, minCoordinates, multiplier, bitmap.Height);
|
||||
Point endCoordinates = PixelCoordinatesFromGeoCoordinates(step.Node2, minCoordinates, multiplier, bitmap.Height);
|
||||
graphics.DrawLine(route, startCoordinates, endCoordinates);
|
||||
distance += step.Distance;
|
||||
time += TimeSpan.FromHours(step.Distance / 1000 / step.Speed);
|
||||
if (time - previousPrint > TimeSpan.FromSeconds(60))
|
||||
{
|
||||
previousPrint += TimeSpan.FromSeconds(60);
|
||||
Point printCoordinates = new(endCoordinates.X + 30, endCoordinates.Y + 30);
|
||||
graphics.DrawLine(route, endCoordinates, printCoordinates);
|
||||
graphics.DrawString($"{distance:000000}m\n{time:hh\\:mm\\:ss}", new Font(FontFamily.GenericMonospace, 8), new SolidBrush(Color.Blue), printCoordinates);
|
||||
}
|
||||
}
|
||||
|
||||
graphics.DrawString($"Distance: {r.Distance:000000.00}m\nTime: {r.Time:hh\\:mm\\:ss}", new Font(FontFamily.GenericMonospace, 18), new SolidBrush(Color.White), 2, 2);
|
||||
graphics.DrawString($"Distance: {r.Distance:000000.00}m\nTime: {r.Time:hh\\:mm\\:ss}", new Font(FontFamily.GenericMonospace, 24), new SolidBrush(Color.White), 2, 2);
|
||||
}
|
||||
|
||||
Directory.CreateDirectory(new FileInfo(outputPath).DirectoryName!);
|
||||
|
Loading…
Reference in New Issue
Block a user