LotSizingDataModel.Solver 2.0.1
Solver-independent modeling, execution, monitoring and adapter infrastructure.
Loading...
Searching...
No Matches
MetaheuristicsPlatformMathematicalResultProjector.cs
Go to the documentation of this file.
4
6
8{
11 DebConstraintGaBridgeResult bridgeResult,
12 string runName = "")
13 {
14 ArgumentNullException.ThrowIfNull(
15 model);
16
17 ArgumentNullException.ThrowIfNull(
18 bridgeResult);
19
20 if (!bridgeResult.IsFeasible)
21 {
22 throw new InvalidOperationException(
23 "Only a feasible metaheuristic incumbent can be projected.");
24 }
25
26 MathematicalVariable[] variables =
27 model.Variables
28 .OrderBy(
29 variable =>
30 variable.Id)
31 .ToArray();
32
33 if (variables.Length !=
34 bridgeResult.ModelVariableValues.Length)
35 {
36 throw new InvalidOperationException(
37 "Metaheuristic incumbent dimension does not match the mathematical model.");
38 }
39
40 var result =
42 {
43 RunName =
44 runName ?? string.Empty,
45
46 FormulationId =
47 "metaheuristics-platform",
48
50 SolverKind.Unknown,
51
52 SolverName =
53 $"MetaheuristicsPlatform/{bridgeResult.AlgorithmId}",
54
55 SolverVersion =
57
58 TerminationReason =
60
61 HasFeasibleSolution =
62 true,
63
64 IsOptimal =
65 false,
66
67 ObjectiveValue =
68 bridgeResult.ObjectiveValue,
69
70 BestBound =
71 null,
72
73 RelativeGap =
74 null,
75
76 AbsoluteGap =
77 null,
78
79 SolveDuration =
80 bridgeResult.Duration
81 };
82
83 for (int index = 0;
84 index < variables.Length;
85 index++)
86 {
87 MathematicalVariable variable =
88 variables[index];
89
90 result.AddVariableValue(
92 variable.Id,
93 bridgeResult.ModelVariableValues[index],
94 variable.Name,
95 variable.DomainKey));
96 }
97
98 result.AddDiagnostic(
99 $"MetaheuristicsPlatform algorithm={bridgeResult.AlgorithmId}; feasible={bridgeResult.IsFeasible}; optimalityClaim=false; seed={bridgeResult.Seed}.");
100
101 result.EnsureValid();
102
103 return result;
104 }
105}
MathematicalModelSolveResult Project(MathematicalModel model, DebConstraintGaBridgeResult bridgeResult, 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.
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