LotSizingDataModel.Solver 2.0.1
Solver-independent modeling, execution, monitoring and adapter infrastructure.
Loading...
Searching...
No Matches
ScientificFormulationCompatibilityService.cs
Go to the documentation of this file.
1using LotSizingDataModel.Core.DecisionModel.Objectives;
2using LotSizingDataModel.Instance.ProblemClasses;
3using LotSizingDataModel.Instance.Scientific;
4
6
7/// <summary>
8/// Evaluates whether one mathematical formulation has verified scientific
9/// coverage for a classified lot-sizing instance.
10/// </summary>
12{
14 ScientificClassificationResult classification,
15 string formulationId)
16 {
17 ArgumentNullException.ThrowIfNull(classification);
18
19 if (
21 formulationId,
23 {
25 formulationId?.Trim() ?? string.Empty,
26 profile: null,
28 problemClass: null,
29 verifiedSupportedExtensions:
30 Array.Empty<LotSizingProblemClassExtensionKind>(),
31 knownUnsupportedExtensions:
32 Array.Empty<LotSizingProblemClassExtensionKind>(),
33 undeterminedExtensions:
34 Array.Empty<LotSizingProblemClassExtensionKind>(),
35 diagnostics:
36 new[]
37 {
38 new ScientificFormulationDiagnostic(
39 "LSDM-FORM-001",
40 ScientificFormulationDiagnosticSeverity.Warning,
41 "formulation.profile",
42 "No scientific capability profile is registered " +
43 "for this formulation.")
44 });
45 }
46
47 return Assess(
48 classification,
49 profile!);
50 }
51
53 ScientificClassificationResult classification,
55 {
56 ArgumentNullException.ThrowIfNull(classification);
57 ArgumentNullException.ThrowIfNull(profile);
58
59 var diagnostics =
60 new List<ScientificFormulationDiagnostic>();
61
62 if (classification.IsBlocked)
63 {
64 diagnostics.Add(
66 "LSDM-FORM-002",
68 "classification",
69 "Scientific formulation compatibility is blocked " +
70 "because instance scientific classification is blocked."));
71
72 return Create(
73 profile,
75 problemClass: null,
76 Array.Empty<LotSizingProblemClassExtensionKind>(),
77 Array.Empty<LotSizingProblemClassExtensionKind>(),
78 Array.Empty<LotSizingProblemClassExtensionKind>(),
79 diagnostics);
80 }
81
82 LotSizingProblemClassMatchResult? primary =
83 classification.PrimaryProblemClass;
84
85 if (primary is null)
86 {
87 diagnostics.Add(
89 "LSDM-FORM-003",
91 "classification.problemClass",
92 "No unique canonical problem class is available for " +
93 "scientific formulation assessment."));
94
95 return Create(
96 profile,
98 problemClass: null,
99 Array.Empty<LotSizingProblemClassExtensionKind>(),
100 Array.Empty<LotSizingProblemClassExtensionKind>(),
101 Array.Empty<LotSizingProblemClassExtensionKind>(),
102 diagnostics);
103 }
104
105 CanonicalLotSizingProblemClassId problemClass =
106 primary.Definition.Id;
107
108 if (!profile.SupportsProblemClass(problemClass))
109 {
110 diagnostics.Add(
112 "LSDM-FORM-010",
114 "classification.problemClass",
115 $"Formulation '{profile.FormulationId}' has no " +
116 $"verified support for canonical class '{problemClass}'."));
117
118 return Create(
119 profile,
121 problemClass,
122 Array.Empty<LotSizingProblemClassExtensionKind>(),
123 Array.Empty<LotSizingProblemClassExtensionKind>(),
124 Array.Empty<LotSizingProblemClassExtensionKind>(),
125 diagnostics);
126 }
127
128 OptimizationObjectiveKind objectiveKind =
129 classification.Descriptor?.ObjectiveFinance
130 .PrimaryObjectiveKind ??
131 OptimizationObjectiveKind.Economic;
132
133 if (!profile.SupportsObjectiveKind(objectiveKind))
134 {
135 diagnostics.Add(
137 "LSDM-FORM-013",
139 "classification.objective",
140 $"Formulation '{profile.FormulationId}' has no verified " +
141 $"support for objective kind '{objectiveKind}'."));
142
143 return Create(
144 profile,
146 problemClass,
147 Array.Empty<LotSizingProblemClassExtensionKind>(),
148 Array.Empty<LotSizingProblemClassExtensionKind>(),
149 Array.Empty<LotSizingProblemClassExtensionKind>(),
150 diagnostics);
151 }
152
153 var supported =
154 new List<LotSizingProblemClassExtensionKind>();
155
156 var unsupported =
157 new List<LotSizingProblemClassExtensionKind>();
158
159 var undetermined =
160 new List<LotSizingProblemClassExtensionKind>();
161
162 foreach (
163 LotSizingProblemClassExtensionKind extension
164 in primary.Extensions)
165 {
166 if (profile.IsExtensionVerifiedSupported(extension))
167 {
168 supported.Add(extension);
169 }
170 else if (profile.IsExtensionKnownUnsupported(extension))
171 {
172 unsupported.Add(extension);
173 }
174 else
175 {
176 undetermined.Add(extension);
177 }
178 }
179
180 if (unsupported.Count > 0)
181 {
182 diagnostics.Add(
184 "LSDM-FORM-011",
186 "classification.extensions",
187 "Known unsupported formulation extensions: " +
188 string.Join(",", unsupported)));
189
190 return Create(
191 profile,
193 problemClass,
194 supported,
195 unsupported,
196 undetermined,
197 diagnostics);
198 }
199
200 if (undetermined.Count > 0)
201 {
202 diagnostics.Add(
204 "LSDM-FORM-012",
206 "classification.extensions",
207 "Formulation support has not yet been scientifically " +
208 "verified for extensions: " +
209 string.Join(",", undetermined)));
210
211 return Create(
212 profile,
214 problemClass,
215 supported,
216 unsupported,
217 undetermined,
218 diagnostics);
219 }
220
221 diagnostics.Add(
223 "LSDM-FORM-020",
225 "formulation",
226 $"Formulation '{profile.FormulationId}' has verified " +
227 "scientific coverage for the detected canonical core and " +
228 "all classified extensions."));
229
230 return Create(
231 profile,
233 problemClass,
234 supported,
235 unsupported,
236 undetermined,
237 diagnostics);
238 }
239
240 private static ScientificFormulationCompatibilityResult Create(
243 CanonicalLotSizingProblemClassId? problemClass,
244 IEnumerable<LotSizingProblemClassExtensionKind> supported,
245 IEnumerable<LotSizingProblemClassExtensionKind> unsupported,
246 IEnumerable<LotSizingProblemClassExtensionKind> undetermined,
247 IEnumerable<ScientificFormulationDiagnostic> diagnostics) =>
248 new(
249 profile.FormulationId,
250 profile,
251 kind,
252 problemClass,
253 supported,
254 unsupported,
255 undetermined,
256 diagnostics);
257}
static bool TryGet(string formulationId, out MathematicalFormulationScientificProfile? profile)
Evaluates whether one mathematical formulation has verified scientific coverage for a classified lot-...
ScientificFormulationCompatibilityResult Assess(ScientificClassificationResult classification, MathematicalFormulationScientificProfile profile)
ScientificFormulationCompatibilityResult Assess(ScientificClassificationResult classification, string formulationId)
ScientificFormulationCompatibilityKind
Scientific compatibility between one classification result and one mathematical-formulation capabilit...