Invoke algorithm directly from enum
This commit is contained in:
@@ -4,6 +4,7 @@ using Craftimizer.Solver.Crafty;
|
|||||||
using Dalamud.Configuration;
|
using Dalamud.Configuration;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
namespace Craftimizer.Plugin;
|
namespace Craftimizer.Plugin;
|
||||||
|
|
||||||
@@ -23,6 +24,33 @@ public enum SolverAlgorithm
|
|||||||
StepwiseFurcated,
|
StepwiseFurcated,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class AlgorithmUtils
|
||||||
|
{
|
||||||
|
public static void Invoke(this SolverAlgorithm me, SolverConfig config, SimulationState state, Action<ActionType>? actionCallback = null, CancellationToken token = default)
|
||||||
|
{
|
||||||
|
Func<SolverConfig, SimulationState, Action<ActionType>?, CancellationToken, SolverSolution> func = me switch
|
||||||
|
{
|
||||||
|
SolverAlgorithm.Oneshot => Solver.Crafty.Solver.SearchOneshot,
|
||||||
|
SolverAlgorithm.OneshotForked => Solver.Crafty.Solver.SearchOneshotForked,
|
||||||
|
SolverAlgorithm.Stepwise => Solver.Crafty.Solver.SearchStepwise,
|
||||||
|
SolverAlgorithm.StepwiseForked => Solver.Crafty.Solver.SearchStepwiseForked,
|
||||||
|
SolverAlgorithm.StepwiseFurcated or _ => Solver.Crafty.Solver.SearchStepwiseFurcated,
|
||||||
|
};
|
||||||
|
try
|
||||||
|
{
|
||||||
|
func(config, state, actionCallback, token);
|
||||||
|
}
|
||||||
|
catch (AggregateException e)
|
||||||
|
{
|
||||||
|
e.Handle(ex => ex is OperationCanceledException);
|
||||||
|
}
|
||||||
|
catch (OperationCanceledException)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public class Configuration : IPluginConfiguration
|
public class Configuration : IPluginConfiguration
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user