Update raphael (now threaded and loggable)

This commit is contained in:
Asriel Camora
2025-04-29 14:28:50 -07:00
parent fb959e07fc
commit 9d8e29f069
5 changed files with 37 additions and 28 deletions
+2 -2
View File
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
@@ -15,7 +15,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Raphael.Net" Version="1.1.0" />
<PackageReference Include="Raphael.Net" Version="2.1.0" />
</ItemGroup>
<ItemGroup>
+13 -4
View File
@@ -160,8 +160,8 @@ public sealed class Solver : IDisposable
var pool = RaphaelUtils.ConvertToRawActions(Config.ActionPool.Where(a => a.Base().IsPossible(s)).ToArray());
var input = new Raphael.SolverInput()
{
CP = checked((short)State.Input.Stats.CP),
Durability = checked((sbyte)State.Input.Recipe.MaxDurability),
CP = checked((ushort)State.Input.Stats.CP),
Durability = checked((ushort)State.Input.Recipe.MaxDurability),
Progress = checked((ushort)State.Input.Recipe.MaxProgress),
Quality = checked((ushort)(State.Input.Recipe.MaxQuality - State.Input.StartingQuality)),
BaseProgressGain = checked((ushort)State.Input.BaseProgressGain),
@@ -202,13 +202,18 @@ public sealed class Solver : IDisposable
progress = prog % maxProgress;
}
void Log(string s) =>
OnLog?.Invoke(s);
if (!Config.MinimizeSteps)
{
Raphael.SolverConfig config = new()
{
Adversarial = Config.Adversarial,
BackloadProgress = true,
UnsoundBranchPruning = true
UnsoundBranchPruning = true,
LogLevel = Raphael.LevelFilter.Debug,
ThreadCount = Config.MaxThreadCount,
};
using var solver = new Raphael.Solver(in config, in input, pool);
@@ -216,6 +221,7 @@ public sealed class Solver : IDisposable
solver.OnFinish += OnFinish;
solver.OnSuggestSolution += OnSuggestSolution;
solver.OnProgress += OnProgress;
solver.OnLog += Log;
progressStage = 0;
progress = 0;
@@ -231,7 +237,9 @@ public sealed class Solver : IDisposable
{
Adversarial = Config.Adversarial,
BackloadProgress = Config.BackloadProgress,
UnsoundBranchPruning = false
UnsoundBranchPruning = false,
LogLevel = Raphael.LevelFilter.Debug,
ThreadCount = Config.MaxThreadCount,
};
using var solver = new Raphael.Solver(in config, in input, pool);
@@ -239,6 +247,7 @@ public sealed class Solver : IDisposable
solver.OnFinish += OnFinish;
solver.OnSuggestSolution += OnSuggestSolution;
solver.OnProgress += OnProgress;
solver.OnLog += Log;
progressStage = 0;
progress = 0;
+1 -1
View File
@@ -24,7 +24,6 @@ public readonly record struct SolverConfig
public float ExplorationConstant { get; init; }
public int MaxStepCount { get; init; }
public int MaxRolloutStepCount { get; init; }
public int MaxThreadCount { get; init; }
public int ForkCount { get; init; }
public int FurcatedActionCount { get; init; }
public bool StrictActions { get; init; }
@@ -41,6 +40,7 @@ public readonly record struct SolverConfig
public bool BackloadProgress { get; init; }
public bool MinimizeSteps { get; init; }
public int MaxThreadCount { get; init; }
public ActionType[] ActionPool { get; init; }
public SolverAlgorithm Algorithm { get; init; }