LotSizingDataModel.Checker 2.0.1
Reusable validation engine for structural, mathematical and objective consistency checks.
Loading...
Searching...
No Matches
SolutionCheckResultApplier.cs
Go to the documentation of this file.
5using LotSizingDataModel.Instance.Common;
6using LotSizingDataModel.Instance.Results;
7using LotSizingDataModel.Solution;
8using LotSizingDataModel.Solution.Common;
9
11
12/// <summary>
13/// Applies independent checker results back to the serializable solution
14/// evaluation and to an optional known-result record.
15/// </summary>
16/// <remarks>
17/// The applier deliberately does not change optimality information, solver
18/// bounds, or solver optimality gaps. The checker establishes feasibility and
19/// objective consistency, not optimality.
20/// </remarks>
21public sealed class SolutionCheckResultApplier :
23{
24 private const string ObjectiveValueSource =
25 "Recomputed by LotSizingSolutionChecker from candidate " +
26 "decision-variable values";
27
28 /// <inheritdoc/>
30 LotSizingSolution solution,
31 SolutionCheckResult checkResult,
33 DateTime evaluatedAtUtc,
34 KnownResult? knownResult = null)
35 {
36 ArgumentNullException.ThrowIfNull(solution);
37 ArgumentNullException.ThrowIfNull(checkResult);
38 ArgumentNullException.ThrowIfNull(options);
39
40 options.EnsureValid();
41
42 if (evaluatedAtUtc.Kind == DateTimeKind.Local)
43 {
44 evaluatedAtUtc = evaluatedAtUtc.ToUniversalTime();
45 }
46 else if (evaluatedAtUtc.Kind == DateTimeKind.Unspecified)
47 {
48 evaluatedAtUtc = DateTime.SpecifyKind(
49 evaluatedAtUtc,
50 DateTimeKind.Utc);
51 }
52
53 var applicationResult =
55
56 if (options.ApplyToSolutionEvaluation)
57 {
58 ApplyToSolutionEvaluation(
59 solution,
60 checkResult,
61 options,
62 evaluatedAtUtc);
63
64 applicationResult.SolutionEvaluationUpdated =
65 true;
66 }
67
68 if (knownResult is not null)
69 {
70 ApplyToKnownResult(
71 knownResult,
72 checkResult,
73 options,
74 applicationResult);
75 }
76
77 return applicationResult;
78 }
79
80 private static void ApplyToSolutionEvaluation(
81 LotSizingSolution solution,
84 DateTime evaluatedAtUtc)
85 {
86 solution.Evaluation.EvaluatedAtUtc =
87 evaluatedAtUtc;
88
89 solution.Evaluation.EvaluatorName =
90 options.EvaluatorName;
91
92 solution.Evaluation.EvaluatorVersion =
93 options.EvaluatorVersion;
94
95 if (CanPublishFeasibility(result))
96 {
97 bool feasible =
98 result.IsStructurallyValid &&
99 result.AreVariableDomainsValid &&
100 result.IsFeasible;
101
102 solution.Evaluation.FeasibilityStatus =
103 feasible
104 ? FeasibilityStatus.Feasible
105 : FeasibilityStatus.Infeasible;
106
107 solution.Evaluation.MaximumConstraintViolation =
109
110 solution.Evaluation.TotalConstraintViolation =
112
113 solution.Evaluation.ViolatedConstraintCount =
115 }
116 else
117 {
118 solution.Evaluation.FeasibilityStatus =
119 FeasibilityStatus.NotEvaluated;
120
121 solution.Evaluation.MaximumConstraintViolation =
122 null;
123
124 solution.Evaluation.TotalConstraintViolation =
125 null;
126
127 solution.Evaluation.ViolatedConstraintCount =
128 null;
129 }
130
131 if (result.ObjectiveCheckCompleted &&
132 result.RecomputedObjectiveValue.HasValue)
133 {
134 solution.Evaluation.ObjectiveValue =
135 result.RecomputedObjectiveValue.Value;
136
137 solution.Evaluation.ObjectiveValueSource =
138 ObjectiveValueSource;
139 }
140 else
141 {
142 solution.Evaluation.ObjectiveValue =
143 null;
144
145 solution.Evaluation.ObjectiveValueSource =
146 string.Empty;
147 }
148 }
149
150 private static void ApplyToKnownResult(
151 KnownResult knownResult,
152 SolutionCheckResult result,
153 SolutionVerificationOptions options,
154 SolutionCheckApplicationResult applicationResult)
155 {
156 if (options.UpdateKnownResultFeasibility &&
157 CanPublishFeasibility(result))
158 {
159 bool feasible =
160 result.IsStructurallyValid &&
161 result.AreVariableDomainsValid &&
162 result.IsFeasible;
163
164 knownResult.FeasibilityStatus =
165 feasible
166 ? FeasibilityStatus.Feasible
167 : FeasibilityStatus.Infeasible;
168
169 applicationResult.KnownResultFeasibilityUpdated =
170 true;
171 }
172
174 result.Level == SolutionCheckLevel.Full &&
176 result.IsValid)
177 {
178 knownResult.VerificationStatus =
179 KnownResultVerificationStatus.AutomaticallyVerified;
180
181 applicationResult.KnownResultPromoted =
182 true;
183 }
184 }
185
186 private static bool CanPublishFeasibility(
187 SolutionCheckResult result)
188 {
189 return
190 result.StructuralCheckCompleted &&
191 result.VariableDomainCheckCompleted &&
193 }
194}
Configures the high-level verification facade and the application of checker results back to domain o...
bool UpdateKnownResultFeasibility
Gets or sets whether an explicitly supplied known result receives the independently established feasi...
bool ApplyToSolutionEvaluation
Gets or sets whether the computed checker result is written to LotSizingSolution.Evaluation.
string EvaluatorVersion
Gets or sets the evaluator version written to the solution evaluation.
string EvaluatorName
Gets or sets the evaluator name written to the solution evaluation.
bool PromoteFullyVerifiedKnownResult
Gets or sets whether a known result is promoted to AutomaticallyVerified when a complete Full check s...
Describes which domain objects were changed while applying a checker result.
Applies independent checker results back to the serializable solution evaluation and to an optional k...
SolutionCheckApplicationResult Apply(LotSizingSolution solution, SolutionCheckResult checkResult, SolutionVerificationOptions options, DateTime evaluatedAtUtc, KnownResult? knownResult=null)
Applies one checker result.Information describing the domain-object mutations performed.
Contains the complete result of checking one lot-sizing solution.
bool FeasibilityCheckCompleted
Gets or sets whether mathematical feasibility checking completed.
double TotalConstraintViolation
Gets or sets the sum of mathematical-constraint violations.
SolutionCheckLevel Level
Gets or sets the checking level that was executed.
bool IsFeasible
Gets or sets whether all checked mathematical constraints are feasible.
double MaximumConstraintViolation
Gets or sets the maximum mathematical-constraint violation.
int ViolatedConstraintCount
Gets or sets the number of violated mathematical constraints.
bool IsValid
Gets whether the solution passed every check requested by Level.
bool ObjectiveCheckCompleted
Gets or sets whether objective checking completed.
double? RecomputedObjectiveValue
Gets or sets the objective value independently recomputed by the checker.
Applies a solver-independent checker result to the serializable solution evaluation and,...
SolutionCheckLevel
Defines how deeply a lot-sizing solution must be checked.