2using System.Collections.Generic;
5using System.Threading.Tasks;
56 IEnumerable<SolverAvailabilityInfo>
57 availabilityInformation,
59 CancellationToken cancellationToken =
default)
61 ArgumentNullException.ThrowIfNull(
64 ArgumentNullException.ThrowIfNull(
65 availabilityInformation);
67 ArgumentNullException.ThrowIfNull(
79 if (requestedSolver ==
83 "The requested solver cannot be Unknown.");
88 Dictionary<SolverKind, SolverAvailabilityInfo>
89 availabilityBySolver =
90 availabilityInformation
93 information is not
null)
96 information.SolverKind)
103 IReadOnlyList<SolverKind> solverOrder =
112 cancellationToken.ThrowIfCancellationRequested();
114 IReadOnlyList<ISolverAdapter> adapters =
115 registry.FindBySolverKind(
118 if (adapters.Count == 0)
120 result.AddDiagnostic(
121 $
"No loaded adapter is registered for " +
122 $
"solver '{solverKind}'.");
124 if (requestedSolver !=
126 options.RequireExactSolverKind)
135 availabilityBySolver.TryGetValue(
138 discoveredAvailability)
139 ? discoveredAvailability
146 cancellationToken.ThrowIfCancellationRequested();
148 if (!SupportsRequiredCapabilities(
150 options.RequiredCapabilities))
152 result.AddDiagnostic(
153 $
"Adapter '{adapter.AdapterName}' does " +
154 "not support all required " +
165 if (!IsAvailabilityAccepted(
166 effectiveAvailability,
169 result.AddDiagnostic(
170 $
"Adapter '{adapter.AdapterName}' is " +
171 $
"not usable. Availability status: " +
172 $
"'{effectiveAvailability.Status}'.");
179 effectiveAvailability);
181 result.AddDiagnostic(
182 $
"Adapter '{adapter.AdapterName}' was " +
183 $
"selected for solver '{solverKind}'.");
188 if (requestedSolver !=
190 options.RequireExactSolverKind)
196 result.AddDiagnostic(
197 "No suitable solver adapter could be selected.");
202 private static IReadOnlyList<SolverKind>
207 if (requestedSolver ==
231 if (!solverOrder.Contains(
242 private static bool SupportsRequiredCapabilities(
243 ISolverAdapter adapter,
244 IEnumerable<SolverCapability>
245 requiredCapabilities)
249 in requiredCapabilities)
261 private static bool IsAvailabilityAccepted(
262 SolverAvailabilityInfo availability,
263 SolverSelectionOptions options)
265 if (availability.
Status ==
272 options.AllowLimitedAvailability &&
273 availability.Status ==
275 .AvailableWithLimitations;
Describes the availability and detected installation details of a mathematical optimization solver.
SolverAvailabilityStatus Status
Gets or sets the detected availability status.
Stores solver adapters that were loaded successfully and provides lookup services by adapter identifi...
Configures how a solver adapter is selected when automatic solver selection is requested.
bool RequireExactSolverKind
Gets or sets whether a preferred concrete solver must be used without falling back to another solver.
void EnsureValid()
Validates the solver-selection options.
List< SolverKind > SolverPriority
Gets the solver priority used during automatic selection.
Represents the result of selecting a solver adapter for a solve request.
async ValueTask< SolverSelectionResult > SelectAsync(SolverKind requestedSolver, SolverAdapterRegistry registry, IEnumerable< SolverAvailabilityInfo > availabilityInformation, SolverSelectionOptions options, CancellationToken cancellationToken=default)
Selects a solver adapter.
SolverSelectionService()
Initializes a new solver-selection service.
ValueTask< SolverAvailabilityInfo > CheckAvailabilityAsync(CancellationToken cancellationToken=default)
Checks whether the solver is installed, loadable, and licensed when a license is required.
Defines the metadata and capabilities exposed by a solver adapter plugin.
bool SupportsCapability(SolverCapability capability)
Gets a value indicating whether this adapter supports the specified capability.
SolverKind
Identifies a supported mathematical optimization solver.
SolverCapability
Identifies an optional capability implemented by a solver adapter.
SolverAvailabilityStatus
Describes the availability state of a solver adapter on the current computer.