9 private readonly Dictionary<string, IOptimizationSolverAdapter> _byId =
10 new(StringComparer.OrdinalIgnoreCase);
12 private readonly Dictionary<SolverKind, List<IOptimizationSolverAdapter>> _byKind =
16 public IReadOnlyCollection<IOptimizationSolverAdapter>
Adapters =>
17 _byId.Values.ToArray();
20 public int Count => _byId.Count;
25 ArgumentNullException.ThrowIfNull(adapter);
27 if (
string.IsNullOrWhiteSpace(adapter.
AdapterId))
29 throw new InvalidOperationException(
30 "A solver adapter identifier is required.");
35 throw new InvalidOperationException(
36 "A solver adapter must target a concrete solver.");
39 string adapterId = adapter.
AdapterId.Trim();
41 if (_byId.ContainsKey(adapterId))
43 throw new InvalidOperationException(
44 $
"An adapter with identifier '{adapterId}' is already registered.");
47 _byId.Add(adapterId, adapter);
49 if (!_byKind.TryGetValue(
51 out List<IOptimizationSolverAdapter>? adapters))
57 adapters.Add(adapter);
64 return _byKind.TryGetValue(
66 out List<IOptimizationSolverAdapter>? adapters)
Stores optimization-solver adapters and provides deterministic lookup by adapter identifier and solve...
IReadOnlyList< IOptimizationSolverAdapter > FindBySolverKind(SolverKind solverKind)
Gets registered adapters targeting one solver kind.
void Register(IOptimizationSolverAdapter adapter)
Registers an adapter.
IReadOnlyCollection< IOptimizationSolverAdapter > Adapters
Gets all currently registered adapters.
void Clear()
Removes all adapters.
int Count
Gets the number of registered adapters.
Defines the common metadata and availability contract implemented by every optimization-solver adapte...
SolverKind SolverKind
Gets the concrete solver targeted by this adapter.
string AdapterId
Gets the stable adapter identifier.
SolverKind
Identifies a mathematical optimization solver that can be used by solver-backed ULS algorithms.