LotSizingDataModel.Solver 2.0.1
Solver-independent modeling, execution, monitoring and adapter infrastructure.
Loading...
Searching...
No Matches
SolverSelectionResult.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.Xml.Serialization;
6
8
9/// <summary>
10/// Represents the result of selecting a solver adapter for a
11/// solve request.
12/// </summary>
13[Serializable]
14[XmlType(TypeName = "solverSelectionResult")]
15public sealed class SolverSelectionResult
16{
17 private readonly List<string> _diagnostics =
18 new();
19
20 /// <summary>
21 /// Initializes an empty solver-selection result.
22 /// </summary>
24 {
26 SolverKind.Unknown;
27
29 SolverKind.Unknown;
30
31 AdapterId =
32 string.Empty;
33
35 string.Empty;
36 }
37
38 /// <summary>
39 /// Gets or sets the solver requested by the caller.
40 /// </summary>
41 [XmlAttribute("requestedSolver")]
43 {
44 get;
45 set;
46 }
47
48 /// <summary>
49 /// Gets or sets the solver selected by the selection
50 /// service.
51 /// </summary>
52 [XmlAttribute("selectedSolver")]
54 {
55 get;
56 set;
57 }
58
59 /// <summary>
60 /// Gets or sets the identifier of the selected adapter.
61 /// </summary>
62 [XmlElement("adapterId")]
63 public string AdapterId
64 {
65 get;
66 set;
67 }
68
69 /// <summary>
70 /// Gets or sets the display name of the selected adapter.
71 /// </summary>
72 [XmlElement("adapterName")]
73 public string AdapterName
74 {
75 get;
76 set;
77 }
78
79 /// <summary>
80 /// Gets or sets the selected live adapter instance.
81 /// </summary>
82 /// <remarks>
83 /// The adapter is excluded from XML serialization because
84 /// it is a runtime object.
85 /// </remarks>
86 [XmlIgnore]
88 {
89 get;
90 set;
91 }
92
93 /// <summary>
94 /// Gets or sets the availability information associated
95 /// with the selected solver.
96 /// </summary>
97 [XmlElement("availability")]
99 {
100 get;
101 set;
102 }
103
104 /// <summary>
105 /// Gets the diagnostics produced during solver selection.
106 /// </summary>
107 [XmlArray("diagnostics")]
108 [XmlArrayItem("diagnostic")]
109 public List<string> Diagnostics =>
110 _diagnostics;
111
112 /// <summary>
113 /// Gets a value indicating whether a usable adapter was
114 /// selected.
115 /// </summary>
116 [XmlIgnore]
117 public bool IsSuccessful =>
118 Adapter is not null &&
119 SelectedSolver is not
120 SolverKind.Unknown and not
122 Availability is not null &&
123 Availability.IsUsable;
124
125 /// <summary>
126 /// Adds a diagnostic message.
127 /// </summary>
128 /// <param name="message">
129 /// Diagnostic message.
130 /// </param>
131 /// <exception cref="ArgumentException">
132 /// Thrown when <paramref name="message"/> is empty.
133 /// </exception>
134 public void AddDiagnostic(
135 string message)
136 {
137 if (string.IsNullOrWhiteSpace(
138 message))
139 {
140 throw new ArgumentException(
141 "A solver-selection diagnostic cannot be empty.",
142 nameof(message));
143 }
144
145 _diagnostics.Add(
146 message.Trim());
147 }
148
149 /// <summary>
150 /// Sets the selected adapter and copies its identity
151 /// information into this result.
152 /// </summary>
153 /// <param name="adapter">
154 /// Selected solver adapter.
155 /// </param>
156 /// <param name="availability">
157 /// Availability information associated with the adapter.
158 /// </param>
159 /// <exception cref="ArgumentNullException">
160 /// Thrown when <paramref name="adapter"/> or
161 /// <paramref name="availability"/> is
162 /// <see langword="null"/>.
163 /// </exception>
164 public void SetSelection(
165 ISolverAdapter adapter,
166 SolverAvailabilityInfo availability)
167 {
168 ArgumentNullException.ThrowIfNull(
169 adapter);
170
171 ArgumentNullException.ThrowIfNull(
172 availability);
173
174 Adapter =
175 adapter;
176
178 availability;
179
181 adapter.SolverKind;
182
183 AdapterId =
184 adapter.AdapterId;
185
187 adapter.AdapterName;
188 }
189}
Describes the availability and detected installation details of a mathematical optimization solver.
void SetSelection(ISolverAdapter adapter, SolverAvailabilityInfo availability)
Sets the selected adapter and copies its identity information into this result.
SolverSelectionResult()
Initializes an empty solver-selection result.
void AddDiagnostic(string message)
Adds a diagnostic message.
List< string > Diagnostics
Gets the diagnostics produced during solver selection.
SolverKind RequestedSolver
Gets or sets the solver requested by the caller.
string AdapterName
Gets or sets the display name of the selected adapter.
SolverKind SelectedSolver
Gets or sets the solver selected by the selection service.
string AdapterId
Gets or sets the identifier of the selected adapter.
ISolverAdapter? Adapter
Gets or sets the selected live adapter instance.
bool IsSuccessful
Gets a value indicating whether a usable adapter was selected.
SolverAvailabilityInfo? Availability
Gets or sets the availability information associated with the selected solver.
SolverKind SolverKind
Gets the solver kind implemented by this adapter.
Defines the metadata and capabilities exposed by a solver adapter plugin.
string AdapterId
Gets the unique adapter identifier.
string AdapterName
Gets the adapter display name.
SolverKind
Identifies a supported mathematical optimization solver.
Definition SolverKind.cs:12
@ Automatic
The solver is selected automatically from the adapters available on the current computer.
Definition SolverKind.cs:22
@ Unknown
No solver has been specified.
Definition SolverKind.cs:16