From 6b5dddb1e3452ac2581f8d1b62d66a083ba59bbd Mon Sep 17 00:00:00 2001 From: glax Date: Sun, 23 Apr 2023 16:03:39 +0200 Subject: [PATCH] Prevent method from returning before all threads are finished. Include calculating threads in output. --- Server/Server.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Server/Server.cs b/Server/Server.cs index d612e74..85479af 100644 --- a/Server/Server.cs +++ b/Server/Server.cs @@ -119,9 +119,9 @@ public class Server Queue calcThreads = new(); - for (double roadLevelPriority = 0.02; roadLevelPriority > 0; roadLevelPriority -= 0.001) + for (double roadLevelPriority = 0.016; roadLevelPriority < 0.02; roadLevelPriority += 0.0002) { - for (double maxAngle = 5; maxAngle < 45; maxAngle += 5) + for (double maxAngle = 25; maxAngle < 35; maxAngle += 1) { double priority = roadLevelPriority; double angle = maxAngle; @@ -129,7 +129,7 @@ public class Server { Pathfinder testresult = new Pathfinder(rm, priority, angle).AStar(start, finish, Tag.SpeedType.car); - string fileName = $"angle{angle:00}_level{priority:0.000}.result"; + string fileName = $"angle{angle:00}_level{priority:0.0000}.result"; testresult.SaveResult(Path.Join(parentFolder, fileName)); })); } @@ -140,7 +140,7 @@ public class Server DateTime startTime = DateTime.Now; HashSet runningThreads = new(); - while (calcThreads.Count > 0) + while (calcThreads.Count > 0 || runningThreads.Count > 0) { while (runningThreads.Count < threads && calcThreads.Count > 0) { @@ -154,7 +154,7 @@ public class Server 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}"); + Console.WriteLine($"To calculate: {calcThreads.Count}(+{runningThreads.Count})/{totalTasks} Time Average: {(elapsedTime)/(completedTasks)} Elapsed: {elapsedTime} Remaining: {(elapsedTime)/(completedTasks)*calcThreads.Count}"); } } }