2023-04-19 22:55:49 +02:00
|
|
|
using System.Drawing;
|
2023-04-20 19:41:40 +02:00
|
|
|
using System.Drawing.Imaging;
|
2023-04-01 01:00:22 +02:00
|
|
|
using OSMDatastructure;
|
|
|
|
using OSMDatastructure.Graph;
|
2023-04-01 14:43:22 +02:00
|
|
|
using Pathfinding;
|
2023-04-13 19:18:25 +02:00
|
|
|
using RenderPath;
|
2023-04-21 00:43:58 +02:00
|
|
|
using Region = OSMDatastructure.Region;
|
2023-04-01 01:00:22 +02:00
|
|
|
|
2023-02-02 22:30:43 +01:00
|
|
|
namespace Server;
|
2023-02-02 19:03:00 +01:00
|
|
|
|
|
|
|
public class Server
|
|
|
|
{
|
2023-02-08 19:09:54 +01:00
|
|
|
|
2023-02-02 22:30:43 +01:00
|
|
|
public static void Main(string[] args)
|
2023-02-02 19:03:00 +01:00
|
|
|
{
|
2023-04-20 19:41:40 +02:00
|
|
|
ConsoleWriter newConsole = new();
|
2023-03-31 21:56:27 +02:00
|
|
|
Console.SetOut(newConsole);
|
|
|
|
Console.SetError(newConsole);
|
2023-04-20 19:41:40 +02:00
|
|
|
|
|
|
|
string workingDir = "D:/stuttgart-regbez-latest";
|
2023-03-31 21:56:27 +02:00
|
|
|
|
2023-04-13 00:24:33 +02:00
|
|
|
//RegionConverter.ConvertXMLToRegions("D:/stuttgart-regbez-latest.osm", "D:/stuttgart-regbez-latest");
|
2023-04-01 14:43:22 +02:00
|
|
|
//RegionConverter.ConvertXMLToRegions("D:/map.osm", "D:/map");
|
2023-04-06 14:46:19 +02:00
|
|
|
//RegionConverter.ConvertXMLToRegions("D:/germany-latest.osm", "D:/germany-latest");
|
2023-04-13 00:24:33 +02:00
|
|
|
|
2023-04-20 19:41:40 +02:00
|
|
|
Coordinates start = new (48.7933798f, 9.8275859f);
|
|
|
|
Coordinates finish = new (48.795918f, 9.021618f);
|
2023-04-21 00:43:58 +02:00
|
|
|
|
2023-04-21 15:14:02 +02:00
|
|
|
TestVariables(workingDir, start, finish, 32);
|
2023-04-21 00:43:58 +02:00
|
|
|
|
2023-04-21 14:44:50 +02:00
|
|
|
/*
|
2023-04-21 00:43:58 +02:00
|
|
|
string parentFolder = new DirectoryInfo(workingDir).Parent!.FullName;
|
|
|
|
|
2023-04-20 19:41:40 +02:00
|
|
|
Pathfinder result = new Pathfinder(workingDir).AStar(start,
|
2023-04-21 13:49:48 +02:00
|
|
|
finish, Tag.SpeedType.car, 0.034, 0.012,
|
|
|
|
0, 0.18);
|
2023-04-21 00:43:58 +02:00
|
|
|
|
|
|
|
Console.WriteLine($"Calc-time {result.pathResult!.calcTime} Path-length: {result.pathResult.pathNodes.Count} Visited-nodes: {result.gScore!.Count}");
|
|
|
|
|
|
|
|
string fileName = DateTime.Now.ToFileTime().ToString();
|
2023-04-19 22:55:49 +02:00
|
|
|
|
2023-04-21 00:43:58 +02:00
|
|
|
string resultFileName = $"{new DirectoryInfo(workingDir).Name}-{fileName}.result";
|
2023-04-20 19:41:40 +02:00
|
|
|
result.SaveResult(Path.Join(parentFolder, resultFileName));
|
|
|
|
|
2023-04-21 00:43:58 +02:00
|
|
|
string renderFileName = $"{new DirectoryInfo(workingDir).Name}-{fileName}.render.png";
|
2023-04-20 19:41:40 +02:00
|
|
|
Image render = Renderer.DrawPathfinder(result);
|
|
|
|
#pragma warning disable CA1416
|
|
|
|
render.Save(Path.Join(parentFolder, renderFileName), ImageFormat.Png);
|
2023-04-21 00:43:58 +02:00
|
|
|
#pragma warning restore CA1416*/
|
2023-02-02 19:03:00 +01:00
|
|
|
}
|
2023-04-21 13:49:48 +02:00
|
|
|
|
2023-04-21 14:44:50 +02:00
|
|
|
private static ValueTuple<Image, Renderer.Bounds> RenderAreaBaseImage(string workingDir, Coordinates c1, Coordinates c2)
|
|
|
|
{
|
|
|
|
float minLat = c1.latitude < c2.latitude ? c1.latitude : c2.latitude;
|
|
|
|
float minLon = c1.longitude < c2.longitude ? c1.longitude : c2.longitude;
|
|
|
|
float maxLat = c1.latitude > c2.latitude ? c1.latitude : c2.latitude;
|
|
|
|
float maxLon = c1.longitude > c2.longitude ? c1.longitude : c2.longitude;
|
|
|
|
|
|
|
|
RegionManager allRegions = new(workingDir);
|
|
|
|
for (float lat = minLat - Region.RegionSize; lat < maxLat + Region.RegionSize; lat += Region.RegionSize / 2)
|
|
|
|
{
|
|
|
|
for (float lon = minLon - Region.RegionSize; lon < maxLon + Region.RegionSize; lon += Region.RegionSize / 2)
|
|
|
|
{
|
|
|
|
allRegions.GetRegion(new Coordinates(lat, lon));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Console.WriteLine("Regions Loaded. Rendering.");
|
|
|
|
ValueTuple<Image, Renderer.Bounds> baseRender = Renderer.DrawArea(allRegions);
|
|
|
|
return baseRender;
|
|
|
|
}
|
|
|
|
|
2023-04-21 14:29:52 +02:00
|
|
|
private static void TestVariables(string workingDir, Coordinates start, Coordinates finish, int threads)
|
2023-04-21 13:49:48 +02:00
|
|
|
{
|
|
|
|
string parentFolder = new DirectoryInfo(workingDir).Parent!.FullName;
|
2023-04-21 15:14:02 +02:00
|
|
|
|
|
|
|
RegionManager rm = new (workingDir);
|
2023-04-21 13:49:48 +02:00
|
|
|
|
2023-04-21 14:29:52 +02:00
|
|
|
Queue<Thread> calcThreads = new();
|
2023-04-21 13:49:48 +02:00
|
|
|
|
2023-04-21 14:44:50 +02:00
|
|
|
for (double sameRoadPriority = 0.02; sameRoadPriority < 0.4; sameRoadPriority += 0.02)
|
2023-04-21 13:49:48 +02:00
|
|
|
{
|
|
|
|
for (double roadLevelPriority = 0.4; roadLevelPriority > 0; roadLevelPriority -= 0.02)
|
|
|
|
{
|
|
|
|
for (double angleWeightFactor = 0.01; angleWeightFactor < 0.25; angleWeightFactor += 0.01)
|
|
|
|
{
|
|
|
|
double priority = roadLevelPriority;
|
|
|
|
double roadPriority = sameRoadPriority;
|
|
|
|
double factor = angleWeightFactor;
|
2023-04-21 14:29:52 +02:00
|
|
|
calcThreads.Enqueue(new Thread(() =>
|
2023-04-21 13:49:48 +02:00
|
|
|
{
|
2023-04-21 15:14:02 +02:00
|
|
|
Pathfinder testresult = new Pathfinder(rm).AStar(start,
|
2023-04-21 13:49:48 +02:00
|
|
|
finish, Tag.SpeedType.car, priority, roadPriority,
|
|
|
|
0, factor);
|
|
|
|
string fileName =
|
|
|
|
$"angle{factor:0.000}_level{priority:0.000}_same{roadPriority:0.000}.result";
|
|
|
|
testresult.SaveResult(Path.Join(parentFolder, fileName));
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-21 14:29:52 +02:00
|
|
|
int totalTasks = calcThreads.Count;
|
|
|
|
int completedTasks = 0;
|
2023-04-21 13:49:48 +02:00
|
|
|
DateTime startTime = DateTime.Now;
|
|
|
|
|
|
|
|
HashSet<Thread> runningThreads = new();
|
2023-04-21 14:29:52 +02:00
|
|
|
while (calcThreads.Count > 0)
|
2023-04-21 13:49:48 +02:00
|
|
|
{
|
2023-04-21 14:29:52 +02:00
|
|
|
while (runningThreads.Count < threads && calcThreads.Count > 0)
|
2023-04-21 13:49:48 +02:00
|
|
|
{
|
2023-04-21 14:29:52 +02:00
|
|
|
Thread t = calcThreads.Dequeue();
|
2023-04-21 13:49:48 +02:00
|
|
|
runningThreads.Add(t);
|
|
|
|
t.Start();
|
|
|
|
}
|
|
|
|
|
2023-04-21 14:29:52 +02:00
|
|
|
int newCompletedTasks = runningThreads.RemoveWhere(thread => !thread.IsAlive);
|
|
|
|
completedTasks += newCompletedTasks;
|
|
|
|
if (newCompletedTasks > 0)
|
|
|
|
{
|
|
|
|
TimeSpan elapsedTime = DateTime.Now - startTime;
|
|
|
|
Console.WriteLine($"To calculate: {calcThreads.Count}/{totalTasks} Time Average: {(elapsedTime)/(completedTasks)} Elapsed: {elapsedTime} Remaining: {(elapsedTime)/(completedTasks)*calcThreads.Count}");
|
|
|
|
}
|
2023-04-21 13:49:48 +02:00
|
|
|
}
|
|
|
|
}
|
2023-02-02 19:03:00 +01:00
|
|
|
}
|