Invoke algorithm directly from enum

This commit is contained in:
Asriel Camora
2023-07-21 16:01:01 +04:00
parent 918252f9fe
commit 1e5cc96837
+28
View File
@@ -4,6 +4,7 @@ using Craftimizer.Solver.Crafty;
using Dalamud.Configuration;
using System;
using System.Collections.Generic;
using System.Threading;
namespace Craftimizer.Plugin;
@@ -23,6 +24,33 @@ public enum SolverAlgorithm
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]
public class Configuration : IPluginConfiguration
{