Begin implementing async

This commit is contained in:
Asriel Camora
2023-07-04 07:41:37 +02:00
parent 4b90ded2bb
commit 76853e2f0d
4 changed files with 15 additions and 1 deletions
+11 -1
View File
@@ -213,7 +213,7 @@ public class Solver
}
}
public void Search(CancellationToken token)
public void SearchThread(CancellationToken token)
{
Simulator simulator = new(RootNode.State.State, Config.MaxStepCount);
for (var i = 0; i < Config.Iterations; i++)
@@ -228,6 +228,16 @@ public class Solver
}
}
public void Search(CancellationToken token)
{
var tasks = new Task[Config.ThreadCount];
for (var i = 0; i < Config.ThreadCount; ++i)
{
tasks[i] = Task.Run(() => SearchThread(token), token);
}
Task.WaitAll(tasks, token);
}
[Pure]
public (List<ActionType> Actions, SimulationNode Node) Solution()
{
+2
View File
@@ -10,6 +10,7 @@ public readonly record struct SolverConfig
public float MaxScoreWeightingConstant { get; init; }
public float ExplorationConstant { get; init; }
public int MaxStepCount { get; init; }
public int ThreadCount { get; init; }
public SolverConfig()
{
@@ -18,5 +19,6 @@ public readonly record struct SolverConfig
MaxScoreWeightingConstant = 0.1f;
ExplorationConstant = 4f;
MaxStepCount = 25;
ThreadCount = Environment.ProcessorCount;
}
}