LotSizingDataModel.Solver 2.0.1
Solver-independent modeling, execution, monitoring and adapter infrastructure.
Loading...
Searching...
No Matches
UlsAlgorithmsExactMathematicalResultProjector.cs
Go to the documentation of this file.
5
7
8/// <summary>
9/// Projects a validated ULSAlgorithms exact result onto the
10/// already-built canonical LotSizingDataModel mathematical model.
11/// </summary>
13{
17 UlsAlgorithmsExactBridgeResult externalResult,
18 string runName = "")
19 {
20 ArgumentNullException.ThrowIfNull(model);
21 ArgumentNullException.ThrowIfNull(problem);
22 ArgumentNullException.ThrowIfNull(externalResult);
23
24 if (externalResult.Horizon != problem.Horizon)
25 {
26 throw new InvalidOperationException(
27 "External exact result horizon does not match the extracted ULS problem.");
28 }
29
30 var result =
32 {
33 RunName =
34 runName ?? string.Empty,
35
36 FormulationId =
37 "ulsalgorithms-exact",
38
40 SolverKind.Unknown,
41
42 SolverName =
43 $"ULSAlgorithms/{externalResult.SolverId}",
44
45 SolverVersion =
46 externalResult.SolverVersion,
47
48 TerminationReason =
50
51 HasFeasibleSolution =
52 true,
53
54 IsOptimal =
55 true,
56
57 ObjectiveValue =
58 externalResult.ObjectiveValue,
59
60 BestBound =
61 externalResult.ObjectiveValue,
62
63 RelativeGap =
64 0.0,
65
66 AbsoluteGap =
67 0.0,
68
69 SolveDuration =
70 externalResult.SolveDuration
71 };
72
73 int projectedCount =
74 0;
75
76 foreach (MathematicalVariable variable
77 in model.Variables)
78 {
81 variable.DomainKey);
82
83 int period =
85 "period");
86
87 if (period < 1 ||
88 period > problem.Horizon)
89 {
90 throw new InvalidOperationException(
91 $"Variable '{variable.Name}' has period {period}, outside the exact ULS horizon.");
92 }
93
94 int index =
95 period - 1;
96
97 double value =
98 key.Category switch
99 {
101 externalResult.ProductionQuantities[index],
102
104 externalResult.SetupDecisions[index]
105 ? 1.0
106 : 0.0,
107
109 externalResult.EndingInventories[index],
110
112 problem.Demands[index],
113
114 _ =>
115 throw new NotSupportedException(
116 $"Cannot project external ULS result onto category '{key.Category}'.")
117 };
118
119 result.AddVariableValue(
121 variable.Id,
122 value,
123 variable.Name,
124 variable.DomainKey));
125
126 projectedCount++;
127 }
128
129 if (projectedCount !=
130 model.VariableCount)
131 {
132 throw new InvalidOperationException(
133 "External exact projection is incomplete.");
134 }
135
136 result.AddDiagnostic(
137 $"Exact external method={externalResult.SolverId}; ULSAlgorithms={externalResult.SolverVersion}; sourceCommit={UlsAlgorithmsExactMethodCatalog.SourceCommit}.");
138
139 result.EnsureValid();
140
141 return result;
142 }
143}
Immutable external exact-solve evidence retained before projection back into LotSizingDataModel.
Projects a validated ULSAlgorithms exact result onto the already-built canonical LotSizingDataModel m...
MathematicalModelSolveResult Project(MathematicalModel model, UlsAlgorithmsExactProblemData problem, UlsAlgorithmsExactBridgeResult externalResult, string runName="")
Normalized deterministic uncapacitated single-item problem passed to ULSAlgorithms.
Stores the solver result for a solver-independent mathematical model.
void AddDiagnostic(string diagnostic)
Adds a non-empty diagnostic message.
Stores the value returned by a solver for one mathematical decision variable.
const string Production
Identifies production-quantity decision variables.
const string Inventory
Identifies inventory-level decision variables.
const string Delivery
Identifies delivered-quantity decision variables.
const string Setup
Identifies production setup decision variables.
Represents a parsed mathematical-model business-domain key.
int GetRequiredInt32(string name)
Gets a required integer segment.
static MathematicalDomainKey Parse(string domainKey)
Parses a canonical mathematical domain key.
Represents a solver-independent mathematical optimization model.
Represents one decision variable in a mathematical optimization model.
string DomainKey
Gets or sets an optional domain key used to map the mathematical variable back to a lot-sizing decisi...
int Id
Gets or sets the unique variable identifier within the mathematical model.
SolverTerminationReason
Describes why a solver execution terminated.
SolverKind
Identifies a supported mathematical optimization solver.
Definition SolverKind.cs:12