LotSizingDataModel.Solver 2.0.1
Solver-independent modeling, execution, monitoring and adapter infrastructure.
Loading...
Searching...
No Matches
WarehouseAdditionalCapacityDecisionMapper.cs
Go to the documentation of this file.
1using System;
2using System.Linq;
3using LotSizingDataModel.Core.PhysicalModel;
4using LotSizingDataModel.Solution;
5using LotSizingDataModel.Solution.Decisions;
7
9
10/// <summary>
11/// Maps mathematical additional warehouse-capacity values to
12/// warehouse capacity decisions in a lot-sizing solution.
13/// </summary>
14/// <remarks>
15/// Supported canonical domain-key formats are:
16/// <code>
17/// warehouseAdditionalCapacity|warehouse=&lt;id&gt;|period=&lt;index&gt;
18/// warehouseAdditionalCapacity|plant=&lt;id&gt;|period=&lt;index&gt;
19/// </code>
20/// The first format identifies a standalone warehouse. The
21/// second identifies the warehouse attached to a plant.
22/// Period numbers are one-based.
23/// </remarks>
26{
27 /// <summary>
28 /// Gets the mathematical domain-key category handled by this
29 /// mapper.
30 /// </summary>
31 public override string Category =>
33
34 /// <summary>
35 /// Maps one non-zero additional warehouse-capacity value.
36 /// </summary>
37 /// <param name="context">
38 /// Mathematical-solution mapping context.
39 /// </param>
40 /// <param name="solution">
41 /// Target lot-sizing solution.
42 /// </param>
43 /// <param name="domainKey">
44 /// Parsed warehouse additional-capacity domain key.
45 /// </param>
46 /// <param name="variableValue">
47 /// Additional-capacity value returned by the solver.
48 /// </param>
49 protected override void MapValue(
51 LotSizingSolution solution,
52 MathematicalDomainKey domainKey,
53 MathematicalVariableValue variableValue)
54 {
55 ArgumentNullException.ThrowIfNull(
56 context);
57
58 ArgumentNullException.ThrowIfNull(
59 solution);
60
61 ArgumentNullException.ThrowIfNull(
62 domainKey);
63
64 ArgumentNullException.ThrowIfNull(
65 variableValue);
66
67 int period =
68 domainKey.GetRequiredInt32(
70
71 WarehouseReference warehouse =
72 ResolveWarehouse(
73 domainKey);
74
75 WarehouseCapacityDecision? decision =
76 solution.WarehouseCapacityDecisions
77 .FirstOrDefault(
78 existing =>
79 existing.Matches(
80 warehouse));
81
82 if (decision is null)
83 {
84 if (solution.PlanningHorizon <= 0)
85 {
86 throw new InvalidOperationException(
87 "The target lot-sizing solution must have a " +
88 "strictly positive planning horizon before " +
89 "warehouse capacity decisions are mapped.");
90 }
91
92 decision =
93 new WarehouseCapacityDecision(
94 warehouse,
95 solution.PlanningHorizon);
96
97 solution.AddWarehouseCapacityDecision(
98 decision);
99 }
100
101 decision.SetAdditionalCapacityUsed(
102 period,
103 variableValue.Value);
104 }
105
106 private static WarehouseReference ResolveWarehouse(
107 MathematicalDomainKey domainKey)
108 {
109 bool hasStandaloneWarehouse =
110 domainKey.TryGetInt32(
112 out int warehouseId);
113
114 bool hasPlantWarehouse =
115 domainKey.TryGetInt32(
117 out int plantId);
118
119 if (hasStandaloneWarehouse ==
120 hasPlantWarehouse)
121 {
122 throw new InvalidOperationException(
123 "A warehouse additional-capacity domain key must " +
124 "identify exactly one warehouse using either " +
125 "'warehouse' or 'plant'.");
126 }
127
128 if (hasStandaloneWarehouse)
129 {
130 return WarehouseReference
131 .ForStandaloneWarehouse(
132 warehouseId);
133 }
134
135 return WarehouseReference
136 .ForPlantWarehouse(
137 plantId);
138 }
139}
Stores the value returned by a solver for one mathematical decision variable.
double Value
Gets or sets the value returned by the solver.
Provides the canonical mathematical domain-key categories used to identify lot-sizing decision famili...
const string WarehouseAdditionalCapacity
Identifies additional warehouse-capacity decision variables.
Provides a reusable base implementation for mathematical decision mappers handling one domain-key cat...
Represents a parsed mathematical-model business-domain key.
int GetRequiredInt32(string name)
Gets a required integer segment.
bool TryGetInt32(string name, out int value)
Attempts to get an integer segment.
Provides the canonical mathematical domain-key segment names used by lot-sizing variables and constra...
Provides the shared state and lookup services required while mapping a mathematical solver result bac...
Maps mathematical additional warehouse-capacity values to warehouse capacity decisions in a lot-sizin...
override string Category
Gets the mathematical domain-key category handled by this mapper.
override void MapValue(MathematicalSolutionMappingContext context, LotSizingSolution solution, MathematicalDomainKey domainKey, MathematicalVariableValue variableValue)
Maps one non-zero additional warehouse-capacity value.