LotSizingDataModel.Core 2.1.0
Core domain model, shared abstractions and XML-serializable entities.
Loading...
Searching...
No Matches
Warehouse.DecisionModel.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Xml.Serialization;
9
11
12/// <summary>
13/// Adds the global decision-model parameters associated
14/// with a warehouse.
15///
16/// These parameters concern the warehouse as a whole,
17/// independently of the items stored in it.
18/// </summary>
19public abstract partial class Warehouse :
20 IPlanningHorizonAware
21{
22 private CapacityConstraint? _capacityConstraint;
23 private AdditionalCapacity? _additionalCapacity;
24 private FixedUsageCost? _fixedUsageCost;
25 private AdditionalCapacityCost? _additionalCapacityCost;
26
27 /// <summary>
28 /// Gets or sets the maximum global storage capacity
29 /// of the warehouse during each planning period.
30 ///
31 /// Corresponds to CMax[v,t].
32 /// </summary>
33 [XmlIgnore]
35 {
36 get => _capacityConstraint;
37 set => SetDecisionParameter(ref _capacityConstraint, value, nameof(CapacityConstraint));
38 }
39
40 /// <summary>XML capacity series with INF for unbounded periods.</summary>
41 [XmlElement("capacityConstraint")]
47
48 /// <summary>Returns the maximum storage capacity, or null when the period is unbounded.</summary>
49 public double? GetStorageCapacity(int period) => CapacityConstraint?.GetFiniteMaximumCapacity(period);
50
51 /// <summary>
52 /// Gets or sets the maximum additional storage capacity
53 /// that may be allocated to the warehouse.
54 ///
55 /// Corresponds to CSuppl[v,t].
56 /// </summary>
57 [XmlElement("additionalCapacity")]
59 {
60 get => _additionalCapacity;
61 set => SetDecisionParameter(
62 ref _additionalCapacity,
63 value,
64 nameof(AdditionalCapacity));
65 }
66
67 /// <summary>
68 /// Gets or sets the fixed cost incurred when the warehouse
69 /// is used during a planning period.
70 ///
71 /// Corresponds to CFU[v,t].
72 /// </summary>
73 [XmlElement("fixedUsageCost")]
75 {
76 get => _fixedUsageCost;
77 set => SetDecisionParameter(
78 ref _fixedUsageCost,
79 value,
80 nameof(FixedUsageCost));
81 }
82
83 /// <summary>
84 /// Gets or sets the cost of using one unit of global
85 /// additional warehouse capacity.
86 ///
87 /// Corresponds to COV[v,t].
88 /// </summary>
89 [XmlElement("additionalCapacityCost")]
91 {
92 get => _additionalCapacityCost;
93 set => SetDecisionParameter(
94 ref _additionalCapacityCost,
95 value,
97 }
98
99 /// <summary>
100 /// Gets the planning horizon represented by the first
101 /// active period-dependent parameter.
102 ///
103 /// Returns zero when no decision parameter is active.
104 /// </summary>
105 [XmlIgnore]
107 {
108 get
109 {
110 // Return the first active parameter's horizon.
111 foreach (IPlanningHorizonAware parameter
112 in GetDecisionParameters())
113 {
114 return parameter.PlanningHorizon;
115 }
116
117 // No active parameter → horizon is zero.
118 return 0;
119 }
120 }
121
122 /// <summary>
123 /// Gets a value indicating whether the warehouse contains
124 /// at least one global decision-model parameter.
125 /// </summary>
126 [XmlIgnore]
128 CapacityConstraint is not null ||
129 AdditionalCapacity is not null ||
130 FixedUsageCost is not null ||
131 AdditionalCapacityCost is not null;
132
133 /// <summary>
134 /// Gets a value indicating whether all active parameters
135 /// use the same planning horizon.
136 /// </summary>
137 [XmlIgnore]
139 {
140 get
141 {
142 int? expectedHorizon = null;
143
144 // Compare each active parameter's horizon against the first.
145 foreach (IPlanningHorizonAware parameter
146 in GetDecisionParameters())
147 {
148 if (expectedHorizon is null)
149 {
150 expectedHorizon =
151 parameter.PlanningHorizon;
152
153 continue;
154 }
155
156 if (parameter.PlanningHorizon !=
157 expectedHorizon.Value)
158 {
159 return false;
160 }
161 }
162
163 return true;
164 }
165 }
166
167 /// <summary>
168 /// Gets a value indicating whether the dependencies between
169 /// the warehouse-capacity parameters are respected.
170 /// </summary>
171 [XmlIgnore]
173 (AdditionalCapacity is null ||
174 CapacityConstraint is not null) &&
175
176 (FixedUsageCost is null || CapacityConstraint is null || !System.Linq.Enumerable.Any(CapacityConstraint.Values, double.IsPositiveInfinity)) &&
177
178 (AdditionalCapacityCost is null ||
179 AdditionalCapacity is not null);
180
181 /// <summary>
182 /// Resizes every active period-dependent warehouse parameter.
183 ///
184 /// Existing values are preserved.
185 /// </summary>
186 /// <param name="periodCount">
187 /// New number of planning periods.
188 /// </param>
189 public void ResizeTimeSeries(int periodCount)
190 {
191 if (periodCount < 0)
192 {
193 throw new ArgumentOutOfRangeException(
194 nameof(periodCount),
195 periodCount,
196 "The planning horizon cannot be negative.");
197 }
198
199 int previousCapacityHorizon = CapacityConstraint?.PlanningHorizon ?? 0;
200
201 // Resize every active decision parameter.
202 foreach (IPlanningHorizonAware parameter
203 in GetDecisionParameters())
204 {
205 parameter.ResizeTimeSeries(periodCount);
206 }
207
208 if (CapacityConstraint is not null && FixedUsageCost is null)
209 {
210 for (int period = previousCapacityHorizon + 1; period <= periodCount; period++)
211 CapacityConstraint.Values.SetUnboundedCapacityPeriod(period);
212 }
213
214 // Notify dependent computed properties.
218 }
219
220 /// <summary>
221 /// Removes all global decision-model parameters
222 /// from the warehouse.
223 ///
224 /// Item-specific inventory parameters are not affected.
225 /// </summary>
227 {
228 CapacityConstraint = null;
229 AdditionalCapacity = null;
230 FixedUsageCost = null;
232 }
233
234 private void SetDecisionParameter<T>(
235 ref T? field,
236 T? value,
237 string propertyName)
239 {
240 if (ReferenceEquals(field, value))
241 {
242 return;
243 }
244
245 // Unsubscribe from old parameter.
246 if (field is not null)
247 {
248 field.PropertyChanged -=
249 OnDecisionParameterPropertyChanged;
250 }
251
252 field = value;
253
254 // Subscribe to new parameter.
255 if (field is not null)
256 {
257 field.PropertyChanged +=
258 OnDecisionParameterPropertyChanged;
259 }
260
261 // Notify the specific property plus all dependent ones.
262 OnPropertyChanged(propertyName);
269 }
270
271 private IEnumerable<IPlanningHorizonAware>
272 GetDecisionParameters()
273 {
274 if (CapacityConstraint is not null)
275 {
276 yield return CapacityConstraint;
277 }
278
279 if (AdditionalCapacity is not null)
280 {
281 yield return AdditionalCapacity;
282 }
283
284 if (FixedUsageCost is not null)
285 {
286 yield return FixedUsageCost;
287 }
288
289 if (AdditionalCapacityCost is not null)
290 {
291 yield return AdditionalCapacityCost;
292 }
293 }
294
295 private void OnDecisionParameterPropertyChanged(
296 object? sender,
297 PropertyChangedEventArgs e)
298 {
299 // Forward notification for the specific parameter that changed.
300 if (ReferenceEquals(sender, CapacityConstraint))
301 {
303 }
304 else if (ReferenceEquals(sender, AdditionalCapacity))
305 {
307 }
308 else if (ReferenceEquals(sender, FixedUsageCost))
309 {
311 }
312 else if (ReferenceEquals(
313 sender,
315 {
317 nameof(AdditionalCapacityCost));
318 }
319
320 // Update all computed properties that may be affected.
326 }
327}
Base class for model objects that notify listeners when one of their properties changes.
virtual void OnPropertyChanged([CallerMemberName] string? propertyName=null)
Raises the PropertyChanged event.
XML capacity series for work centers and warehouses, with INF for unbounded periods.
static ? ResourceCapacitySeries FromConstraint(CapacityConstraint? constraint)
Represents a warehouse in the supply chain.
Definition Warehouse.cs:19
AdditionalCapacity? AdditionalCapacity
Gets or sets the maximum additional storage capacity that may be allocated to the warehouse.
bool HasValidCapacityConfiguration
Gets a value indicating whether the dependencies between the warehouse-capacity parameters are respec...
FixedUsageCost? FixedUsageCost
Gets or sets the fixed cost incurred when the warehouse is used during a planning period.
ResourceCapacitySeries? SerializedCapacity
XML capacity series with INF for unbounded periods.
int PlanningHorizon
Gets the planning horizon represented by the first active period-dependent parameter.
bool HasDecisionParameters
Gets a value indicating whether the warehouse contains at least one global decision-model parameter.
CapacityConstraint? CapacityConstraint
Gets or sets the maximum global storage capacity of the warehouse during each planning period.
double? GetStorageCapacity(int period)
Returns the maximum storage capacity, or null when the period is unbounded.
void ClearDecisionParameters()
Removes all global decision-model parameters from the warehouse.
AdditionalCapacityCost? AdditionalCapacityCost
Gets or sets the cost of using one unit of global additional warehouse capacity.
void ResizeTimeSeries(int periodCount)
Resizes every active period-dependent warehouse parameter.
bool HasConsistentPlanningHorizon
Gets a value indicating whether all active parameters use the same planning horizon.
Defines a model object containing data indexed by planning period.
int PlanningHorizon
Gets the number of planning periods currently represented by the object's time-dependent data.
void ResizeTimeSeries(int periodCount)
Resizes every time-dependent series contained in the object.