2using System.Collections.Generic;
5using System.Threading.Tasks;
71 ArgumentNullException.ThrowIfNull(
74 ArgumentNullException.ThrowIfNull(
97 public async ValueTask<SolverRuntimeBuildResult>
BuildAsync(
99 CancellationToken cancellationToken =
default)
101 ArgumentNullException.ThrowIfNull(
111 cancellationToken.ThrowIfCancellationRequested();
114 await _discoveryService.DiscoverAsync(
118 buildResult.DiscoveryResult =
121 buildResult.AddDiagnostics(
127 var validatedAvailability =
128 discoveryResult.AvailabilityInformation
137 in discoveryResult.AdapterDescriptors)
139 cancellationToken.ThrowIfCancellationRequested();
145 buildResult.AddAdapterLoadResult(
148 buildResult.AddDiagnostics(
154 buildResult.AddDiagnostic(
155 $
"Solver adapter '{descriptor.AdapterId}' " +
156 $
"was not loaded. Status: " +
157 $
"{loadResult.Status}.");
176 buildResult.AddDiagnostic(
177 $
"Adapter '{adapter.AdapterId}' returned " +
178 $
"availability for {availability.SolverKind} " +
179 $
"instead of {adapter.SolverKind}. The " +
180 "availability record was normalized.");
182 availability.SolverKind =
186 validatedAvailability[
190 buildResult.AddDiagnostics(
195 buildResult.AddDiagnostic(
196 $
"Solver adapter '{adapter.AdapterId}' was " +
197 $
"loaded, but native solver " +
198 $
"'{adapter.SolverName}' is not usable. " +
199 $
"Status: {availability.Status}.");
204 catch (OperationCanceledException)
208 catch (Exception exception)
219 adapter.SolverVersion
223 $
"Adapter-level availability validation " +
224 $
"failed: {exception.Message}");
226 validatedAvailability[
231 $
"Solver adapter '{adapter.AdapterId}' could " +
232 "not validate its native solver runtime.");
237 if (!registry.TryRegister(
240 buildResult.AddDiagnostic(
241 $
"Solver adapter '{adapter.AdapterId}' was " +
242 "loaded and validated but could not be " +
243 "registered, most likely because another " +
244 "adapter with the same identifier is already " +
250 buildResult.AddDiagnostic(
251 $
"Solver adapter '{adapter.AdapterId}' for " +
252 $
"{adapter.SolverKind} was loaded, validated, " +
253 "and registered successfully.");
257 GetConcreteSolverKinds()
260 validatedAvailability.TryGetValue(
269 buildResult.RuntimeContext =
274 if (registry.Count == 0)
276 buildResult.AddDiagnostic(
277 "No usable solver adapter was registered.");
280 if (!buildResult.RuntimeContext.CanSolve)
282 buildResult.AddDiagnostic(
283 "The current runtime cannot solve a model " +
284 "because no loaded and validated adapter " +
285 "matches a usable native solver.");
290 catch (OperationCanceledException)
292 buildResult.AddDiagnostic(
293 "Solver-runtime construction was cancelled.");
297 catch (Exception exception)
299 buildResult.AddDiagnostic(
300 $
"Solver-runtime construction failed: " +
301 $
"{exception.Message}");
303 buildResult.AddDiagnostic(
304 exception.ToString());
314 private static IReadOnlyList<SolverKind>
315 GetConcreteSolverKinds()
Describes a solver adapter without loading or executing its native optimization engine.
Represents the result of attempting to load a solver adapter plugin.
ISolverAdapter? Adapter
Gets or sets the loaded adapter instance.
List< string > Diagnostics
Gets the diagnostics produced during adapter loading.
bool IsLoaded
Gets a value indicating whether the adapter was loaded successfully.
Describes the availability and detected installation details of a mathematical optimization solver.
void AddDiagnostic(string message)
Adds a diagnostic message.
List< string > Diagnostics
Gets the diagnostic messages produced during solver discovery and validation.
bool IsUsable
Gets or sets a value indicating whether the solver can currently be used.
SolverKind SolverKind
Gets or sets the solver kind.
Provides the default solver discovery implementation used by the generic solver infrastructure.
Loads solver adapter plugins from managed assemblies.
Stores solver adapters that were loaded successfully and provides lookup services by adapter identifi...
Configures how solver adapter plugins and native solver installations are discovered on the current c...
void EnsureValid()
Validates the solver-discovery options.
Represents the complete result of solver and adapter discovery on the current computer.
List< string > Diagnostics
Gets the diagnostics produced during discovery.
Represents the result of building the solver runtime from discovery information and dynamically loade...
SolverRuntimeBuilder(ISolverDiscoveryService discoveryService, SolverAdapterLoader adapterLoader)
Initializes a solver-runtime builder with explicit dependencies.
async ValueTask< SolverRuntimeBuildResult > BuildAsync(SolverDiscoveryOptions options, CancellationToken cancellationToken=default)
Discovers solver infrastructure, loads adapters, and performs adapter-level native availability valid...
SolverRuntimeBuilder(ISolverDiscoveryService discoveryService)
Initializes a solver-runtime builder with the supplied discovery service and the default adapter load...
SolverRuntimeBuilder()
Initializes a solver-runtime builder with default discovery and adapter-loading services.
Represents the solver runtime infrastructure available to the application after adapter discovery and...
ValueTask< SolverAvailabilityInfo > CheckAvailabilityAsync(CancellationToken cancellationToken=default)
Checks whether the solver is installed, loadable, and licensed when a license is required.
string SolverName
Gets the display name of the solver.
SolverKind SolverKind
Gets the solver kind implemented by this adapter.
Defines the metadata and capabilities exposed by a solver adapter plugin.
Defines a service that discovers solver adapter plugins and native solver installations on the curren...
SolverKind
Identifies a supported mathematical optimization solver.
@ CoinOrCbc
COIN-OR CBC mixed-integer programming solver.
SolverAvailabilityStatus
Describes the availability state of a solver adapter on the current computer.