Moved algorithm into SolverConfig, multi configuration support
This commit is contained in:
@@ -570,4 +570,21 @@ public sealed class Solver
|
||||
|
||||
return solution;
|
||||
}
|
||||
|
||||
public static SolverSolution Search(SolverConfig config, SimulationInput input, Action<ActionType>? actionCallback = null, CancellationToken token = default) =>
|
||||
Search(config, new SimulationState(input), actionCallback, token);
|
||||
|
||||
public static SolverSolution Search(SolverConfig config, SimulationState state, Action<ActionType>? actionCallback = null, CancellationToken token = default)
|
||||
{
|
||||
Func<SolverConfig, SimulationState, Action<ActionType>?, CancellationToken, SolverSolution> func = config.Algorithm switch
|
||||
{
|
||||
SolverAlgorithm.Oneshot => SearchOneshot,
|
||||
SolverAlgorithm.OneshotForked => SearchOneshotForked,
|
||||
SolverAlgorithm.Stepwise => SearchStepwise,
|
||||
SolverAlgorithm.StepwiseForked => SearchStepwiseForked,
|
||||
SolverAlgorithm.StepwiseFurcated or _ => SearchStepwiseFurcated,
|
||||
};
|
||||
return func(config, state, actionCallback, token);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,15 @@ using System.Runtime.InteropServices;
|
||||
|
||||
namespace Craftimizer.Solver.Crafty;
|
||||
|
||||
public enum SolverAlgorithm
|
||||
{
|
||||
Oneshot,
|
||||
OneshotForked,
|
||||
Stepwise,
|
||||
StepwiseForked,
|
||||
StepwiseFurcated,
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Auto)]
|
||||
public readonly record struct SolverConfig
|
||||
{
|
||||
@@ -21,14 +30,16 @@ public readonly record struct SolverConfig
|
||||
public float ScoreCPBonus { get; init; }
|
||||
public float ScoreFewerStepsBonus { get; init; }
|
||||
|
||||
public SolverAlgorithm Algorithm { get; init; }
|
||||
|
||||
public SolverConfig()
|
||||
{
|
||||
Iterations = 100000;
|
||||
ScoreStorageThreshold = 1f;
|
||||
MaxScoreWeightingConstant = 0.1f;
|
||||
ExplorationConstant = 4;
|
||||
MaxStepCount = 25;
|
||||
MaxRolloutStepCount = MaxStepCount;
|
||||
MaxStepCount = 30;
|
||||
MaxRolloutStepCount = 99;
|
||||
ForkCount = Math.Max(Environment.ProcessorCount, 32);
|
||||
FurcatedActionCount = ForkCount / 2;
|
||||
StrictActions = true;
|
||||
@@ -38,5 +49,20 @@ public readonly record struct SolverConfig
|
||||
ScoreDurabilityBonus = .05f;
|
||||
ScoreCPBonus = .05f;
|
||||
ScoreFewerStepsBonus = .05f;
|
||||
|
||||
Algorithm = SolverAlgorithm.StepwiseFurcated;
|
||||
}
|
||||
|
||||
public static readonly SolverConfig SimulatorDefault = new SolverConfig() with
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
public static readonly SolverConfig SynthHelperDefault = new SolverConfig() with
|
||||
{
|
||||
Iterations = 300000,
|
||||
ForkCount = Environment.ProcessorCount - 1, // Keep one for the game thread
|
||||
FurcatedActionCount = Environment.ProcessorCount / 2,
|
||||
Algorithm = SolverAlgorithm.StepwiseForked
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user