ULSAlgorithms 1.1.0-g3e5595996d
High-performance exact and heuristic algorithms for uncapacitated lot sizing
Loading...
Searching...
No Matches
SolverSelectionOptions.cs
Go to the documentation of this file.
2
3/// <summary>
4/// Configures automatic or explicit optimization-solver selection.
5/// </summary>
6public sealed class SolverSelectionOptions
7{
8 private readonly List<SolverKind> _solverPriority =
9 [
10 SolverKind.Cplex,
11 SolverKind.Gurobi,
12 SolverKind.Xpress,
14 ];
15
16 private readonly List<SolverCapability> _requiredCapabilities = [];
17
18 /// <summary>
19 /// Gets the priority used for <see cref="SolverKind.Automatic"/>.
20 /// Earlier entries have higher priority.
21 /// </summary>
22 public List<SolverKind> SolverPriority => _solverPriority;
23
24 /// <summary>Gets capabilities that the selected adapter must support.</summary>
25 public List<SolverCapability> RequiredCapabilities => _requiredCapabilities;
26
27 /// <summary>
28 /// Gets or sets whether an adapter reported as available with limitations
29 /// can still be selected.
30 /// </summary>
31 public bool AllowLimitedAvailability { get; set; } = true;
32
33 /// <summary>
34 /// Gets or sets whether an explicitly requested solver forbids fallback.
35 /// </summary>
36 public bool RequireExactSolverKind { get; set; }
37
38 /// <summary>Validates this option set.</summary>
39 public void EnsureValid()
40 {
41 if (_solverPriority.Count == 0)
42 {
43 throw new InvalidOperationException(
44 "At least one concrete solver must be present in the priority.");
45 }
46
47 var seenKinds = new HashSet<SolverKind>();
48
49 foreach (SolverKind solverKind in _solverPriority)
50 {
51 if (solverKind is SolverKind.Unknown or SolverKind.Automatic)
52 {
53 throw new InvalidOperationException(
54 "The priority must contain only concrete solver kinds.");
55 }
56
57 if (!seenKinds.Add(solverKind))
58 {
59 throw new InvalidOperationException(
60 $"Solver '{solverKind}' appears more than once in the priority.");
61 }
62 }
63
64 var seenCapabilities = new HashSet<SolverCapability>();
65
66 foreach (SolverCapability capability in _requiredCapabilities)
67 {
68 if (capability == SolverCapability.Unknown)
69 {
70 throw new InvalidOperationException(
71 "Required capabilities cannot contain Unknown.");
72 }
73
74 if (!seenCapabilities.Add(capability))
75 {
76 throw new InvalidOperationException(
77 $"Capability '{capability}' appears more than once.");
78 }
79 }
80 }
81}
Configures automatic or explicit optimization-solver selection.
List< SolverCapability > RequiredCapabilities
Gets capabilities that the selected adapter must support.
bool AllowLimitedAvailability
Gets or sets whether an adapter reported as available with limitations can still be selected.
bool RequireExactSolverKind
Gets or sets whether an explicitly requested solver forbids fallback.
List< SolverKind > SolverPriority
Gets the priority used for SolverKind.Automatic. Earlier entries have higher priority.
SolverCapability
Identifies an optional capability exposed by an optimization-solver adapter.
SolverKind
Identifies a mathematical optimization solver that can be used by solver-backed ULS algorithms.
Definition SolverKind.cs:15
@ CoinOrCbc
COIN-OR CBC mixed-integer programming solver.
Definition SolverKind.cs:32