Prevent method from returning before all threads are finished.

Include calculating threads in output.
This commit is contained in:
glax 2023-04-23 16:03:39 +02:00
parent fea0ecf17b
commit 6b5dddb1e3

View File

@ -119,9 +119,9 @@ public class Server
Queue<Thread> calcThreads = new(); Queue<Thread> 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 priority = roadLevelPriority;
double angle = maxAngle; double angle = maxAngle;
@ -129,7 +129,7 @@ public class Server
{ {
Pathfinder testresult = new Pathfinder(rm, priority, angle).AStar(start, Pathfinder testresult = new Pathfinder(rm, priority, angle).AStar(start,
finish, Tag.SpeedType.car); 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)); testresult.SaveResult(Path.Join(parentFolder, fileName));
})); }));
} }
@ -140,7 +140,7 @@ public class Server
DateTime startTime = DateTime.Now; DateTime startTime = DateTime.Now;
HashSet<Thread> runningThreads = new(); HashSet<Thread> runningThreads = new();
while (calcThreads.Count > 0) while (calcThreads.Count > 0 || runningThreads.Count > 0)
{ {
while (runningThreads.Count < threads && calcThreads.Count > 0) while (runningThreads.Count < threads && calcThreads.Count > 0)
{ {
@ -154,7 +154,7 @@ public class Server
if (newCompletedTasks > 0) if (newCompletedTasks > 0)
{ {
TimeSpan elapsedTime = DateTime.Now - startTime; 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}");
} }
} }
} }