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
+16 -16
View File
@@ -534,6 +534,22 @@ public sealed class Settings : Window, IDisposable
disableOptimal ? [SolverAlgorithm.Raphael] : []
);
using (ImRaii.Disabled(config.Algorithm is not (SolverAlgorithm.OneshotForked or SolverAlgorithm.StepwiseForked or SolverAlgorithm.StepwiseGenetic or SolverAlgorithm.Raphael)))
DrawOption(
"Max Core Count",
"The number of cores to use when solving. You should use as many " +
"as you can. If it's too high, it will have an effect on your gameplay " +
$"experience. A good estimate would be 1 or 2 cores less than your " +
$"system (FYI, you have {Environment.ProcessorCount} cores), but make sure to accomodate " +
$"for any other tasks you have in the background, if you have any.\n" +
"(Only used in the Forked, Genetic, and Optimal algorithms)",
config.MaxThreadCount,
1,
Environment.ProcessorCount,
v => config = config with { MaxThreadCount = v },
ref isDirty
);
if (config.Algorithm != SolverAlgorithm.Raphael)
{
DrawOption(
@@ -602,22 +618,6 @@ public sealed class Settings : Window, IDisposable
ref isDirty
);
using (ImRaii.Disabled(config.Algorithm is not (SolverAlgorithm.OneshotForked or SolverAlgorithm.StepwiseForked or SolverAlgorithm.StepwiseGenetic)))
DrawOption(
"Max Core Count",
"The number of cores to use when solving. You should use as many " +
"as you can. If it's too high, it will have an effect on your gameplay " +
$"experience. A good estimate would be 1 or 2 cores less than your " +
$"system (FYI, you have {Environment.ProcessorCount} cores), but make sure to accomodate " +
$"for any other tasks you have in the background, if you have any.\n" +
"(Only used in the Forked and Genetic algorithms)",
config.MaxThreadCount,
1,
Environment.ProcessorCount,
v => config = config with { MaxThreadCount = v },
ref isDirty
);
using (ImRaii.Disabled(config.Algorithm is not (SolverAlgorithm.OneshotForked or SolverAlgorithm.StepwiseForked or SolverAlgorithm.StepwiseGenetic)))
DrawOption(
"Fork Count",
+5 -5
View File
@@ -36,8 +36,8 @@
},
"Raphael.Net": {
"type": "Transitive",
"resolved": "2.1.0",
"contentHash": "MDXWh/jSuwTctU3lMs76jC37KY6mERCBIip4+hl4aqvuyxNkX8WOKyrr0fP0EiV3QHFWoQCn7wxWA9U1or78IA=="
"resolved": "2.1.1",
"contentHash": "4+7HyDa7lVokXObqv8ADeTgi74Cz7W99N07DYtzuOXEt6tJtMlJt8RxLGoPtakVf1mURDMuD5kDKw0oz3EaoDA=="
},
"System.IO.Hashing": {
"type": "Transitive",
@@ -52,15 +52,15 @@
"dependencies": {
"Craftimizer.Simulator": "[1.0.0, )",
"DotNext": "[5.21.0, )",
"Raphael.Net": "[2.1.0, )"
"Raphael.Net": "[2.1.1, )"
}
}
},
"net9.0-windows7.0/win-x64": {
"Raphael.Net": {
"type": "Transitive",
"resolved": "2.1.0",
"contentHash": "MDXWh/jSuwTctU3lMs76jC37KY6mERCBIip4+hl4aqvuyxNkX8WOKyrr0fP0EiV3QHFWoQCn7wxWA9U1or78IA=="
"resolved": "2.1.1",
"contentHash": "4+7HyDa7lVokXObqv8ADeTgi74Cz7W99N07DYtzuOXEt6tJtMlJt8RxLGoPtakVf1mURDMuD5kDKw0oz3EaoDA=="
}
}
}
+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; }