Begin implementing async
This commit is contained in:
@@ -48,6 +48,7 @@ internal static class Program
|
||||
var config = new SolverConfig()
|
||||
{
|
||||
Iterations = 30_000,//1_000_000
|
||||
ThreadCount = 2,
|
||||
};
|
||||
|
||||
var s = Stopwatch.StartNew();
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
+11
-1
@@ -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()
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user