Skip to content

Commit

Permalink
Remove score storage threshold
Browse files Browse the repository at this point in the history
  • Loading branch information
WorkingRobot committed Jul 1, 2024
1 parent a20b501 commit 480cc15
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 55 deletions.
14 changes: 1 addition & 13 deletions Craftimizer/Windows/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -538,18 +538,6 @@ ref isDirty

using (var panel = ImRaii2.GroupPanel("Advanced", -1, out _))
{
DrawOption(
"Score Storage Threshold",
"If a craft achieves this certain arbitrary score, the solver will " +
"throw away all other possible combinations in favor of that one. " +
"Only change this value if you absolutely know what you're doing.",
config.ScoreStorageThreshold,
0,
1,
v => config = config with { ScoreStorageThreshold = v },
ref isDirty
);

DrawOption(
"Max Rollout Step Count",
"The maximum number of crafting steps every iteration can consider. " +
Expand All @@ -575,7 +563,7 @@ ref isDirty

using (var panel = ImRaii2.GroupPanel("Score Weights (Advanced)", -1, out _))
{
ImGui.TextWrapped("All values should add up to 1. Otherwise, the Score Storage Threshold should be changed.");
ImGui.TextWrapped("All values should add up to 1.");
ImGuiHelpers.ScaledDummy(10);

DrawOption(
Expand Down
10 changes: 0 additions & 10 deletions Solver/MCTS.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Craftimizer.Simulator.Actions;
using Craftimizer.Simulator;
using System.Diagnostics.Contracts;
using System.Numerics;
using System.Runtime.CompilerServices;
using Node = Craftimizer.Solver.ArenaNode<Craftimizer.Solver.SimulationNode>;
using System.Runtime.Intrinsics;
Expand Down Expand Up @@ -206,16 +205,7 @@ private Node Select()
currentActions = simulator.AvailableActionsHeuristic(true);
}

// store the result if a max score was reached
var score = SimulationNode.CalculateScoreForState(currentState, currentCompletionState, config) ?? 0;
if (currentCompletionState == CompletionState.ProgressComplete)
{
if (score >= config.ScoreStorageThreshold && score >= MaxScore)
{
var terminalNode = ExecuteActions(simulator, expandedNode, actions[..actionCount], true);
return (terminalNode, score);
}
}
return (expandedNode, score);
}

Expand Down
2 changes: 0 additions & 2 deletions Solver/MCTSConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public readonly record struct MCTSConfig

public float MaxScoreWeightingConstant { get; init; }
public float ExplorationConstant { get; init; }
public float ScoreStorageThreshold { get; init; }

public float ScoreProgress { get; init; }
public float ScoreQuality { get; init; }
Expand All @@ -32,7 +31,6 @@ public MCTSConfig(in SolverConfig config)

MaxScoreWeightingConstant = config.MaxScoreWeightingConstant;
ExplorationConstant = config.ExplorationConstant;
ScoreStorageThreshold = config.ScoreStorageThreshold;

ScoreProgress = config.ScoreProgress;
ScoreQuality = config.ScoreQuality;
Expand Down
28 changes: 0 additions & 28 deletions Solver/Solver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,18 +188,6 @@ private async Task<SolverSolution> SearchStepwiseGenetic()

var bestActions = tasks.Select(t => t.Result).OrderByDescending(r => r.MaxScore).Take(Config.FurcatedActionCount).ToArray();

var bestAction = bestActions[0];
if (bestAction.MaxScore >= Config.ScoreStorageThreshold)
{
var (_, furcatedActionIdx, solution) = bestAction;
(IEnumerable<ActionType> activeActions, _) = activeStates[furcatedActionIdx];

activeActions = activeActions.Concat(solution.Actions);
foreach (var action in activeActions.Skip(definiteActionCount))
InvokeNewAction(action);
return solution with { ActionEnumerable = activeActions };
}

var newStates = new List<SolverSolution>(Config.FurcatedActionCount);
for (var i = 0; i < bestActions.Length; ++i)
{
Expand Down Expand Up @@ -312,14 +300,6 @@ private async Task<SolverSolution> SearchStepwiseForked()

var (maxScore, solution) = tasks.Select(t => t.Result).MaxBy(r => r.MaxScore);

if (maxScore >= Config.ScoreStorageThreshold)
{
actions.AddRange(solution.Actions);
foreach (var action in solution.Actions)
InvokeNewAction(action);
return solution with { Actions = actions };
}

var chosenAction = solution.Actions[0];
InvokeNewAction(chosenAction);

Expand Down Expand Up @@ -355,14 +335,6 @@ private Task<SolverSolution> SearchStepwise()

var solution = solver.Solution();

if (solver.MaxScore >= Config.ScoreStorageThreshold)
{
actions.AddRange(solution.Actions);
foreach (var action in solution.Actions)
InvokeNewAction(action);
return Task.FromResult(solution with { Actions = actions });
}

var chosenAction = solution.Actions[0];
InvokeNewAction(chosenAction);

Expand Down
2 changes: 0 additions & 2 deletions Solver/SolverConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public enum SolverAlgorithm
public readonly record struct SolverConfig
{
public int Iterations { get; init; }
public float ScoreStorageThreshold { get; init; }
public float MaxScoreWeightingConstant { get; init; }
public float ExplorationConstant { get; init; }
public int MaxStepCount { get; init; }
Expand All @@ -39,7 +38,6 @@ public readonly record struct SolverConfig
public SolverConfig()
{
Iterations = 100_000;
ScoreStorageThreshold = 1f;
MaxScoreWeightingConstant = 0.1f;
ExplorationConstant = 4;
MaxStepCount = 30;
Expand Down

0 comments on commit 480cc15

Please sign in to comment.