diff --git a/Server/Server.cs b/Server/Server.cs index dab519d..51ca258 100644 --- a/Server/Server.cs +++ b/Server/Server.cs @@ -26,7 +26,7 @@ public class Server Coordinates start = new (48.7933798f, 9.8275859f); Coordinates finish = new (48.795918f, 9.021618f); - TestVariables(workingDir, start, finish); + TestVariables(workingDir, start, finish, 4); string parentFolder = new DirectoryInfo(workingDir).Parent!.FullName; @@ -66,11 +66,11 @@ public class Server #pragma warning restore CA1416*/ } - private static void TestVariables(string workingDir, Coordinates start, Coordinates finish) + private static void TestVariables(string workingDir, Coordinates start, Coordinates finish, int threads) { string parentFolder = new DirectoryInfo(workingDir).Parent!.FullName; - Queue CalcThreads = new(); + Queue calcThreads = new(); for (double sameRoadPriority = 0.002; sameRoadPriority < 0.4; sameRoadPriority += 0.02) { @@ -81,7 +81,7 @@ public class Server double priority = roadLevelPriority; double roadPriority = sameRoadPriority; double factor = angleWeightFactor; - CalcThreads.Enqueue(new Thread(() => + calcThreads.Enqueue(new Thread(() => { Pathfinder testresult = new Pathfinder(workingDir).AStar(start, finish, Tag.SpeedType.car, priority, roadPriority, @@ -94,24 +94,27 @@ public class Server } } - int totalTasks = CalcThreads.Count; - int completed = 0; + int totalTasks = calcThreads.Count; + int completedTasks = 0; DateTime startTime = DateTime.Now; HashSet runningThreads = new(); - while (CalcThreads.Count > 0) + while (calcThreads.Count > 0) { - while (runningThreads.Count < 16 && CalcThreads.Count > 0) + while (runningThreads.Count < threads && calcThreads.Count > 0) { - Thread t = CalcThreads.Dequeue(); + Thread t = calcThreads.Dequeue(); runningThreads.Add(t); t.Start(); } - int newCompleted = runningThreads.RemoveWhere(thread => !thread.IsAlive); - completed += newCompleted; - if(newCompleted > 0) - Console.WriteLine($"To calculate: {CalcThreads.Count}/{totalTasks} Average Time: {(DateTime.Now - startTime)/(completed)} Elapsed: {DateTime.Now - startTime} Remaining: {(DateTime.Now - startTime)/(completed)*CalcThreads.Count}"); + 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}"); + } } } } \ No newline at end of file