using System.Drawing; using System.Drawing.Imaging; using OSMDatastructure; using OSMDatastructure.Graph; using Pathfinding; using RenderPath; using Region = OSMDatastructure.Region; namespace Server; public class Server { public static void Main(string[] args) { ConsoleWriter newConsole = new(); Console.SetOut(newConsole); Console.SetError(newConsole); string workingDir = "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 (48.7933798f, 9.8275859f); Coordinates finish = new (48.795918f, 9.021618f); TestVariables(workingDir, start, finish, 16); /* string parentFolder = new DirectoryInfo(workingDir).Parent!.FullName; Pathfinder result = new Pathfinder(workingDir).AStar(start, finish, Tag.SpeedType.car, 0.034, 0.012, 0, 0.18); Console.WriteLine($"Calc-time {result.pathResult!.calcTime} Path-length: {result.pathResult.pathNodes.Count} Visited-nodes: {result.gScore!.Count}"); string fileName = DateTime.Now.ToFileTime().ToString(); string resultFileName = $"{new DirectoryInfo(workingDir).Name}-{fileName}.result"; result.SaveResult(Path.Join(parentFolder, resultFileName)); string renderFileName = $"{new DirectoryInfo(workingDir).Name}-{fileName}.render.png"; Image render = Renderer.DrawPathfinder(result); #pragma warning disable CA1416 render.Save(Path.Join(parentFolder, renderFileName), ImageFormat.Png); #pragma warning restore CA1416*/ } private static ValueTuple 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 baseRender = Renderer.DrawArea(allRegions); return baseRender; } private static void TestVariables(string workingDir, Coordinates start, Coordinates finish, int threads) { string parentFolder = new DirectoryInfo(workingDir).Parent!.FullName; Queue calcThreads = new(); for (double sameRoadPriority = 0.02; sameRoadPriority < 0.4; sameRoadPriority += 0.02) { 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; calcThreads.Enqueue(new Thread(() => { Pathfinder testresult = new Pathfinder(workingDir).AStar(start, 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)); })); } } } int totalTasks = calcThreads.Count; int completedTasks = 0; DateTime startTime = DateTime.Now; HashSet runningThreads = new(); while (calcThreads.Count > 0) { while (runningThreads.Count < threads && calcThreads.Count > 0) { Thread t = calcThreads.Dequeue(); runningThreads.Add(t); t.Start(); } 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}"); } } } }