Use TPL when solving with all algorithms
This commit is contained in:
@@ -215,7 +215,8 @@ public sealed unsafe partial class Craft : Window, IDisposable
|
||||
public void Dispose()
|
||||
{
|
||||
StopSolve();
|
||||
SolverTask?.Wait();
|
||||
SolverTaskToken?.Cancel();
|
||||
SolverTask?.TryWait();
|
||||
SolverTask?.Dispose();
|
||||
SolverTaskToken?.Dispose();
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Craftimizer.Simulator;
|
||||
using Craftimizer.Simulator.Actions;
|
||||
using Dalamud.Interface.Windowing;
|
||||
using Dalamud.Logging;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
@@ -12,7 +13,7 @@ namespace Craftimizer.Plugin.Windows;
|
||||
public sealed unsafe partial class Craft : Window, IDisposable
|
||||
{
|
||||
private SimulationState? SolverState { get; set; }
|
||||
private Task? SolverTask { get; set; }
|
||||
private Solver.Solver? SolverTask { get; set; }
|
||||
private CancellationTokenSource? SolverTaskToken { get; set; }
|
||||
private ConcurrentQueue<ActionType> SolverActionQueue { get; } = new();
|
||||
|
||||
@@ -48,7 +49,10 @@ public sealed unsafe partial class Craft : Window, IDisposable
|
||||
SolverSim = new(state);
|
||||
|
||||
SolverTaskToken = new();
|
||||
SolverTask = Task.Run(() => Config.SynthHelperSolverConfig.Invoke(state, SolverActionQueue.Enqueue, SolverTaskToken.Token));
|
||||
SolverTask = new(Config.SynthHelperSolverConfig, state) { Token = SolverTaskToken.Token };
|
||||
SolverTask.OnLog += s => PluginLog.Debug(s);
|
||||
SolverTask.OnNewAction += SolverActionQueue.Enqueue;
|
||||
SolverTask.Start();
|
||||
}
|
||||
|
||||
private void SolveTick()
|
||||
|
||||
@@ -312,32 +312,32 @@ public class Settings : Window
|
||||
DrawOption(
|
||||
"Progress",
|
||||
"Amount of weight to give to the craft's progress.",
|
||||
config.ScoreProgressBonus,
|
||||
v => config = config with { ScoreProgressBonus = v },
|
||||
config.ScoreProgress,
|
||||
v => config = config with { ScoreProgress = v },
|
||||
ref isDirty
|
||||
);
|
||||
|
||||
DrawOption(
|
||||
"Quality",
|
||||
"Amount of weight to give to the craft's quality.",
|
||||
config.ScoreQualityBonus,
|
||||
v => config = config with { ScoreQualityBonus = v },
|
||||
config.ScoreQuality,
|
||||
v => config = config with { ScoreQuality = v },
|
||||
ref isDirty
|
||||
);
|
||||
|
||||
DrawOption(
|
||||
"Durability",
|
||||
"Amount of weight to give to the craft's remaining durability.",
|
||||
config.ScoreDurabilityBonus,
|
||||
v => config = config with { ScoreDurabilityBonus = v },
|
||||
config.ScoreDurability,
|
||||
v => config = config with { ScoreDurability = v },
|
||||
ref isDirty
|
||||
);
|
||||
|
||||
DrawOption(
|
||||
"CP",
|
||||
"Amount of weight to give to the craft's remaining CP.",
|
||||
config.ScoreCPBonus,
|
||||
v => config = config with { ScoreCPBonus = v },
|
||||
config.ScoreCP,
|
||||
v => config = config with { ScoreCP = v },
|
||||
ref isDirty
|
||||
);
|
||||
|
||||
@@ -345,25 +345,25 @@ public class Settings : Window
|
||||
"Steps",
|
||||
"Amount of weight to give to the craft's number of steps. The lower\n" +
|
||||
"the step count, the higher the score.",
|
||||
config.ScoreFewerStepsBonus,
|
||||
v => config = config with { ScoreFewerStepsBonus = v },
|
||||
config.ScoreSteps,
|
||||
v => config = config with { ScoreSteps = v },
|
||||
ref isDirty
|
||||
);
|
||||
|
||||
if (ImGui.Button("Normalize Weights", OptionButtonSize))
|
||||
{
|
||||
var total = config.ScoreProgressBonus +
|
||||
config.ScoreQualityBonus +
|
||||
config.ScoreDurabilityBonus +
|
||||
config.ScoreCPBonus +
|
||||
config.ScoreFewerStepsBonus;
|
||||
var total = config.ScoreProgress +
|
||||
config.ScoreQuality +
|
||||
config.ScoreDurability +
|
||||
config.ScoreCP +
|
||||
config.ScoreSteps;
|
||||
config = config with
|
||||
{
|
||||
ScoreProgressBonus = config.ScoreProgressBonus / total,
|
||||
ScoreQualityBonus = config.ScoreQualityBonus / total,
|
||||
ScoreDurabilityBonus = config.ScoreDurabilityBonus / total,
|
||||
ScoreCPBonus = config.ScoreCPBonus / total,
|
||||
ScoreFewerStepsBonus = config.ScoreFewerStepsBonus / total
|
||||
ScoreProgress = config.ScoreProgress / total,
|
||||
ScoreQuality = config.ScoreQuality / total,
|
||||
ScoreDurability = config.ScoreDurability / total,
|
||||
ScoreCP = config.ScoreCP / total,
|
||||
ScoreSteps = config.ScoreSteps / total
|
||||
};
|
||||
isDirty = true;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Craftimizer.Simulator;
|
||||
using Craftimizer.Simulator.Actions;
|
||||
using Dalamud.Interface.Windowing;
|
||||
using Dalamud.Logging;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Threading;
|
||||
@@ -10,7 +11,7 @@ namespace Craftimizer.Plugin.Windows;
|
||||
|
||||
public sealed partial class Simulator : Window, IDisposable
|
||||
{
|
||||
private Task? SolverTask { get; set; }
|
||||
private Solver.Solver? SolverTask { get; set; }
|
||||
private CancellationTokenSource? SolverTaskToken { get; set; }
|
||||
private ConcurrentQueue<ActionType> SolverActionQueue { get; } = new();
|
||||
private int SolverInitialActionCount { get; set; }
|
||||
@@ -83,13 +84,17 @@ public sealed partial class Simulator : Window, IDisposable
|
||||
|
||||
SolverInitialActionCount = Actions.Count;
|
||||
SolverTaskToken = new();
|
||||
SolverTask = Task.Run(() => Config.SimulatorSolverConfig.Invoke(solverState, SolverActionQueue.Enqueue, SolverTaskToken.Token));
|
||||
SolverTask = new(Config.SimulatorSolverConfig, solverState) { Token = SolverTaskToken.Token };
|
||||
SolverTask.OnLog += s => PluginLog.Debug(s);
|
||||
SolverTask.OnNewAction += SolverActionQueue.Enqueue;
|
||||
SolverTask.Start();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
StopSolveMacro();
|
||||
SolverTask?.Wait();
|
||||
SolverTaskToken?.Cancel();
|
||||
SolverTask?.TryWait();
|
||||
SolverTask?.Dispose();
|
||||
SolverTaskToken?.Dispose();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user