LotSizingDataModel.Solver 2.0.1
Solver-independent modeling, execution, monitoring and adapter infrastructure.
Loading...
Searching...
No Matches
WarehouseActivationDecisionMapper.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 warehouse-activation values to warehouse
12/// capacity decisions in a lot-sizing solution.
13/// </summary>
14/// <remarks>
15/// Supported canonical domain-key formats are:
16/// <code>
17/// warehouseActivation|warehouse=&lt;id&gt;|period=&lt;index&gt;
18/// warehouseActivation|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 warehouse activation 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-activation domain key.
45 /// </param>
46 /// <param name="variableValue">
47 /// Activation 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.SetActivated(
102 period,
103 variableValue.Value >
105 }
106
107 private static WarehouseReference ResolveWarehouse(
108 MathematicalDomainKey domainKey)
109 {
110 bool hasStandaloneWarehouse =
111 domainKey.TryGetInt32(
113 out int warehouseId);
114
115 bool hasPlantWarehouse =
116 domainKey.TryGetInt32(
118 out int plantId);
119
120 if (hasStandaloneWarehouse ==
121 hasPlantWarehouse)
122 {
123 throw new InvalidOperationException(
124 "A warehouse-activation domain key must identify " +
125 "exactly one warehouse using either 'warehouse' " +
126 "or 'plant'.");
127 }
128
129 if (hasStandaloneWarehouse)
130 {
131 return WarehouseReference
132 .ForStandaloneWarehouse(
133 warehouseId);
134 }
135
136 return WarehouseReference
137 .ForPlantWarehouse(
138 plantId);
139 }
140}
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 WarehouseActivation
Identifies warehouse activation decision variables.
Provides a reusable base implementation for mathematical decision mappers handling one domain-key cat...
virtual double ZeroTolerance
Gets the absolute tolerance below which a solver value is considered equal to zero.
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 warehouse-activation values to warehouse capacity decisions in a lot-sizing solutio...
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 warehouse activation value.