LotSizingDataModel.Solver 2.0.1
Solver-independent modeling, execution, monitoring and adapter infrastructure.
Loading...
Searching...
No Matches
MathematicalModelSolverSelectionService.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.Threading;
4using System.Threading.Tasks;
7
9
10/// <summary>
11/// Selects a solver adapter that supports direct execution of
12/// solver-independent mathematical models.
13/// </summary>
15{
16 private readonly SolverSelectionService _solverSelectionService =
17 new();
18
19 /// <summary>
20 /// Selects a usable mathematical-model solver adapter.
21 /// </summary>
22 /// <param name="requestedSolver">
23 /// Solver requested by the caller.
24 /// </param>
25 /// <param name="registry">
26 /// Registry containing loaded solver adapters.
27 /// </param>
28 /// <param name="availabilityInformation">
29 /// Availability information associated with detected
30 /// solvers.
31 /// </param>
32 /// <param name="options">
33 /// Solver-selection options.
34 /// </param>
35 /// <param name="cancellationToken">
36 /// Token used to cancel adapter selection and availability
37 /// checks.
38 /// </param>
39 /// <returns>
40 /// Mathematical-model solver-selection result.
41 /// </returns>
42 /// <exception cref="ArgumentNullException">
43 /// Thrown when <paramref name="registry"/>,
44 /// <paramref name="availabilityInformation"/>, or
45 /// <paramref name="options"/> is
46 /// <see langword="null"/>.
47 /// </exception>
48 public async ValueTask<MathematicalModelSolverSelectionResult>
50 SolverKind requestedSolver,
51 SolverAdapterRegistry registry,
52 IEnumerable<SolverAvailabilityInfo>
53 availabilityInformation,
55 CancellationToken cancellationToken = default)
56 {
57 ArgumentNullException.ThrowIfNull(
58 registry);
59
60 ArgumentNullException.ThrowIfNull(
61 availabilityInformation);
62
63 ArgumentNullException.ThrowIfNull(
64 options);
65
66 SolverSelectionResult generalSelection =
67 await _solverSelectionService.SelectAsync(
68 requestedSolver,
69 registry,
70 availabilityInformation,
71 options,
72 cancellationToken);
73
76 generalSelection);
77
78 if (generalSelection.IsSuccessful &&
79 result.Adapter is null)
80 {
81 result.AddDiagnostic(
82 "The selected solver adapter cannot execute a " +
83 "solver-independent mathematical model.");
84
85 result.SelectedSolver =
86 SolverKind.Unknown;
87
88 result.Availability =
89 null;
90 }
91
92 return result;
93 }
94}
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.
Represents the result of selecting a solver adapter for a solve request.
bool IsSuccessful
Gets a value indicating whether a usable adapter was selected.
Selects a usable solver adapter according to the requested solver kind, adapter capabilities,...
Represents the result of selecting a solver adapter that can solve a solver-independent mathematical ...
static MathematicalModelSolverSelectionResult From(SolverSelectionResult selection)
Creates a mathematical-model solver-selection result from a general solver-selection result.
IMathematicalModelSolverAdapter? Adapter
Gets or sets the selected live mathematical-model solver adapter.
Selects a solver adapter that supports direct execution of solver-independent mathematical models.
async ValueTask< MathematicalModelSolverSelectionResult > SelectAsync(SolverKind requestedSolver, SolverAdapterRegistry registry, IEnumerable< SolverAvailabilityInfo > availabilityInformation, SolverSelectionOptions options, CancellationToken cancellationToken=default)
Selects a usable mathematical-model solver adapter.
SolverKind
Identifies a supported mathematical optimization solver.
Definition SolverKind.cs:12