LotSizingDataModel.Solver 2.0.1
Solver-independent modeling, execution, monitoring and adapter infrastructure.
Loading...
Searching...
No Matches
UlsAlgorithmsHeuristicMathematicalResultProjector.cs
Go to the documentation of this file.
5
7
8/// <summary>
9/// Projects a validated feasible ULSAlgorithms heuristic result
10/// onto a canonical LotSizingDataModel mathematical model.
11/// </summary>
13{
18 string runName = "")
19 {
20 ArgumentNullException.ThrowIfNull(
21 model);
22
23 ArgumentNullException.ThrowIfNull(
24 problem);
25
26 ArgumentNullException.ThrowIfNull(
27 heuristicResult);
28
29 if (heuristicResult.Horizon !=
30 problem.Horizon)
31 {
32 throw new InvalidOperationException(
33 "Heuristic result horizon does not match the canonical ULS problem.");
34 }
35
36 var result =
38 {
39 RunName =
40 runName ?? string.Empty,
41
42 FormulationId =
43 "ulsalgorithms-heuristic",
44
46 SolverKind.Unknown,
47
48 SolverName =
49 $"ULSAlgorithms/{heuristicResult.SolverId}",
50
51 SolverVersion =
52 heuristicResult.SolverVersion,
53
54 TerminationReason =
56
57 HasFeasibleSolution =
58 true,
59
60 IsOptimal =
61 false,
62
63 ObjectiveValue =
64 heuristicResult.ObjectiveValue,
65
66 BestBound =
67 null,
68
69 RelativeGap =
70 null,
71
72 AbsoluteGap =
73 null,
74
75 SolveDuration =
76 heuristicResult.SolveDuration
77 };
78
79 int projectedCount =
80 0;
81
82 foreach (MathematicalVariable variable
83 in model.Variables)
84 {
87 variable.DomainKey);
88
89 int period =
91 "period");
92
93 if (period < 1 ||
94 period > problem.Horizon)
95 {
96 throw new InvalidOperationException(
97 $"Variable '{variable.Name}' has period {period}, outside the heuristic ULS horizon.");
98 }
99
100 int index =
101 period - 1;
102
103 double value =
104 key.Category switch
105 {
107 heuristicResult.ProductionQuantities[index],
108
110 heuristicResult.SetupDecisions[index]
111 ? 1.0
112 : 0.0,
113
115 heuristicResult.EndingInventories[index],
116
118 problem.Demands[index],
119
120 _ =>
121 throw new NotSupportedException(
122 $"Cannot project a heuristic ULS result onto category '{key.Category}'.")
123 };
124
125 result.AddVariableValue(
127 variable.Id,
128 value,
129 variable.Name,
130 variable.DomainKey));
131
132 projectedCount++;
133 }
134
135 if (projectedCount !=
136 model.VariableCount)
137 {
138 throw new InvalidOperationException(
139 "Heuristic projection is incomplete.");
140 }
141
142 result.AddDiagnostic(
143 $"Heuristic method={heuristicResult.SolverId}; status=Feasible; optimalityClaim=false; ULSAlgorithms={heuristicResult.SolverVersion}.");
144
145 result.EnsureValid();
146
147 return result;
148 }
149}
Normalized deterministic uncapacitated single-item problem passed to ULSAlgorithms.
Validated feasible result returned by one pinned ULSAlgorithms heuristic.
Projects a validated feasible ULSAlgorithms heuristic result onto a canonical LotSizingDataModel math...
MathematicalModelSolveResult Project(MathematicalModel model, UlsAlgorithmsExactProblemData problem, UlsAlgorithmsHeuristicBridgeResult heuristicResult, string runName="")
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