LotSizingDataModel.Solver 2.0.1
Solver-independent modeling, execution, monitoring and adapter infrastructure.
Loading...
Searching...
No Matches
MathematicalModelFormulationSelectionResult.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.Xml.Serialization;
4
6
7/// <summary>
8/// Describes the result of selecting a mathematical formulation
9/// for a lot-sizing instance.
10/// </summary>
11[Serializable]
12[XmlType(TypeName = "mathematicalModelFormulationSelectionResult")]
14{
15 private readonly List<string> _diagnostics =
16 new();
17
18 /// <summary>
19 /// Initializes an empty formulation-selection result.
20 /// </summary>
22 {
24 string.Empty;
25
27 string.Empty;
28
30 string.Empty;
31 }
32
33 /// <summary>
34 /// Gets or sets the requested formulation identifier.
35 /// </summary>
36 [XmlAttribute("requestedFormulationId")]
38 {
39 get;
40 set;
41 }
42
43 /// <summary>
44 /// Gets or sets the selected formulation identifier.
45 /// </summary>
46 [XmlAttribute("selectedFormulationId")]
48 {
49 get;
50 set;
51 }
52
53 /// <summary>
54 /// Gets or sets the selected formulation name.
55 /// </summary>
56 [XmlAttribute("selectedFormulationName")]
58 {
59 get;
60 set;
61 }
62
63 /// <summary>
64 /// Gets or sets a value indicating whether a compatible
65 /// formulation was selected.
66 /// </summary>
67 [XmlAttribute("isSuccessful")]
68 public bool IsSuccessful
69 {
70 get;
71 set;
72 }
73
74 /// <summary>
75 /// Gets or sets a value indicating whether the selected
76 /// formulation differs from the requested formulation.
77 /// </summary>
78 [XmlAttribute("usedFallback")]
79 public bool UsedFallback
80 {
81 get;
82 set;
83 }
84
85 /// <summary>
86 /// Gets diagnostic messages produced during formulation
87 /// selection.
88 /// </summary>
89 [XmlArray("diagnostics")]
90 [XmlArrayItem("diagnostic")]
91 public List<string> Diagnostics =>
92 _diagnostics;
93
94 /// <summary>
95 /// Gets or sets the selected formulation for the current
96 /// process.
97 /// </summary>
98 /// <remarks>
99 /// Interface instances are intentionally excluded from XML
100 /// serialization. The formulation can be resolved again from
101 /// <see cref="SelectedFormulationId"/>.
102 /// </remarks>
103 [XmlIgnore]
105 {
106 get;
107 set;
108 }
109
110 /// <summary>
111 /// Adds a non-empty diagnostic message.
112 /// </summary>
113 /// <param name="diagnostic">
114 /// Diagnostic message.
115 /// </param>
116 public void AddDiagnostic(
117 string diagnostic)
118 {
119 if (!string.IsNullOrWhiteSpace(
120 diagnostic))
121 {
122 _diagnostics.Add(
123 diagnostic.Trim());
124 }
125 }
126
127 /// <summary>
128 /// Creates a successful formulation-selection result.
129 /// </summary>
130 /// <param name="requestedFormulationId">
131 /// Requested formulation identifier.
132 /// </param>
133 /// <param name="formulation">
134 /// Selected formulation.
135 /// </param>
136 /// <param name="usedFallback">
137 /// Indicates whether fallback selection was used.
138 /// </param>
139 /// <returns>
140 /// Successful selection result.
141 /// </returns>
142 /// <exception cref="ArgumentNullException">
143 /// Thrown when <paramref name="formulation"/> is
144 /// <see langword="null"/>.
145 /// </exception>
148 string requestedFormulationId,
150 bool usedFallback)
151 {
152 ArgumentNullException.ThrowIfNull(
153 formulation);
154
156 {
158 requestedFormulationId?.Trim() ??
159 string.Empty,
160
162 formulation.FormulationId,
163
165 formulation.Name,
166
168 true,
169
171 usedFallback,
172
174 formulation
175 };
176 }
177
178 /// <summary>
179 /// Creates a failed formulation-selection result.
180 /// </summary>
181 /// <param name="requestedFormulationId">
182 /// Requested formulation identifier.
183 /// </param>
184 /// <param name="diagnostic">
185 /// Failure diagnostic.
186 /// </param>
187 /// <returns>
188 /// Failed selection result.
189 /// </returns>
192 string requestedFormulationId,
193 string diagnostic)
194 {
195 var result =
197 {
199 requestedFormulationId?.Trim() ??
200 string.Empty,
201
203 false
204 };
205
206 result.AddDiagnostic(
207 diagnostic);
208
209 return result;
210 }
211}
Describes the result of selecting a mathematical formulation for a lot-sizing instance.
static MathematicalModelFormulationSelectionResult Failure(string requestedFormulationId, string diagnostic)
Creates a failed formulation-selection result.
static MathematicalModelFormulationSelectionResult Success(string requestedFormulationId, IMathematicalModelFormulation formulation, bool usedFallback)
Creates a successful formulation-selection result.
IMathematicalModelFormulation? Formulation
Gets or sets the selected formulation for the current process.
bool IsSuccessful
Gets or sets a value indicating whether a compatible formulation was selected.
bool UsedFallback
Gets or sets a value indicating whether the selected formulation differs from the requested formulati...
List< string > Diagnostics
Gets diagnostic messages produced during formulation selection.
Defines a solver-independent mathematical formulation for a lot-sizing instance.