LotSizingDataModel.Solver 2.0.1
Solver-independent modeling, execution, monitoring and adapter infrastructure.
Loading...
Searching...
No Matches
ClosedLoopDecisionProjector.cs
Go to the documentation of this file.
1using LotSizingDataModel.Instance.ClosedLoop;
5
7
8public sealed class ClosedLoopDecisionProjector
9{
10 public IReadOnlyList<ClosedLoopDecisionSnapshot> Project(
11 IReadOnlyList<ClosedLoopReturnStream> streams,
14 {
15 ArgumentNullException.ThrowIfNull(
16 streams);
17
18 ArgumentNullException.ThrowIfNull(
19 model);
20
21 ArgumentNullException.ThrowIfNull(
22 solveResult);
23
24 var snapshots =
25 new List<ClosedLoopDecisionSnapshot>();
26
27 foreach (ClosedLoopReturnStream stream
28 in streams.OrderBy(
29 candidate =>
30 candidate.Id))
31 {
32 stream.EnsureValid();
33
34 for (int period = 1;
35 period <= stream.PlanningHorizon;
36 period++)
37 {
38 MathematicalVariable recoveryVariable =
39 GetRequiredVariable(
40 model,
42 .CreateRecoveryKey(
43 stream.Id,
44 stream.ItemId,
45 stream.DistributionCenterId,
46 period));
47
48 MathematicalVariable disposalVariable =
49 GetRequiredVariable(
50 model,
52 .CreateDisposalKey(
53 stream.Id,
54 stream.ItemId,
55 stream.DistributionCenterId,
56 period));
57
58 MathematicalVariableValue recoveryValue =
59 solveResult.FindVariableValue(
60 recoveryVariable.Id) ??
61 throw new InvalidOperationException(
62 $"Closed-loop recovery value for stream '{stream.Id}', period {period}, is missing.");
63
64 MathematicalVariableValue disposalValue =
65 solveResult.FindVariableValue(
66 disposalVariable.Id) ??
67 throw new InvalidOperationException(
68 $"Closed-loop disposal value for stream '{stream.Id}', period {period}, is missing.");
69
70 snapshots.Add(
72 stream.Id,
73 period,
74 recoveryValue.Value,
75 disposalValue.Value,
76 stream.RecoveryYield *
77 recoveryValue.Value));
78 }
79 }
80
81 return snapshots;
82 }
83
84 private static MathematicalVariable GetRequiredVariable(
86 string domainKey)
87 {
88 MathematicalVariable[] matches =
89 model.Variables
90 .Where(
91 variable =>
92 string.Equals(
93 variable.DomainKey,
94 domainKey,
95 StringComparison.Ordinal))
96 .ToArray();
97
98 if (matches.Length != 1)
99 {
100 throw new InvalidOperationException(
101 $"Expected exactly one closed-loop variable with domain key '{domainKey}'; found {matches.Length}.");
102 }
103
104 return matches[0];
105 }
106}
Stores the solver result for a solver-independent mathematical model.
Stores the value returned by a solver for one mathematical decision variable.
double Value
Gets or sets the value returned by the solver.
IReadOnlyList< ClosedLoopDecisionSnapshot > Project(IReadOnlyList< ClosedLoopReturnStream > streams, MathematicalModel model, MathematicalModelSolveResult solveResult)
Represents a solver-independent mathematical optimization model.
Represents one decision variable in a mathematical optimization model.
int Id
Gets or sets the unique variable identifier within the mathematical model.