LotSizingDataModel.Core 2.0.1
Core domain model, shared abstractions and XML-serializable entities.
Loading...
Searching...
No Matches
SafetyStock.cs
Go to the documentation of this file.
1using System;
2using System.Xml.Serialization;
5
7
8/// <summary>
9/// Represents the required safety-stock level for each
10/// planning period.
11///
12/// Corresponds to the UML class "Stock Securite".
13/// Its values correspond to Isecu[t] in the source model.
14///
15/// When associated with an inventory, these values define
16/// the stock levels below which the inventory should not fall.
17/// </summary>
18[Serializable]
19[XmlType(TypeName = "safetyStock")]
20public sealed class SafetyStock :
22{
23 /// <summary>
24 /// Initializes an empty safety-stock constraint.
25 ///
26 /// This public parameterless constructor is required
27 /// by <see cref="XmlSerializer"/>.
28 /// </summary>
29 public SafetyStock()
30 {
31 }
32
33 /// <summary>
34 /// Initializes a safety-stock constraint for the specified
35 /// planning horizon.
36 ///
37 /// Every period is initially assigned a safety-stock level
38 /// of zero.
39 /// </summary>
40 /// <param name="planningHorizon">
41 /// Number of periods in the planning horizon.
42 /// </param>
43 public SafetyStock(int planningHorizon)
44 : base(
45 planningHorizon,
46 defaultValue: 0.0) // Initialize all periods with zero safety stock
47 {
48 }
49
50 /// <summary>
51 /// Initializes a safety-stock constraint and assigns
52 /// the same required level to every planning period.
53 /// </summary>
54 /// <param name="planningHorizon">
55 /// Number of periods in the planning horizon.
56 /// </param>
57 /// <param name="defaultSafetyStockLevel">
58 /// Safety-stock level initially assigned to every period.
59 /// </param>
61 int planningHorizon,
62 double defaultSafetyStockLevel)
63 : base(
64 planningHorizon,
65 defaultSafetyStockLevel) // Initialize all periods with the specified safety stock level
66 {
67 }
68
69 /// <summary>
70 /// Gets the complete safety-stock time series.
71 ///
72 /// This property is an alias for <see cref="LotSizingDataModel.Core.DecisionModel.DoubleTimeSeriesParameter.Values"/>
73 /// and is not serialized separately.
74 /// </summary>
75 [XmlIgnore]
77 Values;
78
79 /// <summary>
80 /// Gets the required safety-stock level for a planning period.
81 /// </summary>
82 /// <param name="period">
83 /// One-based planning-period number.
84 /// </param>
85 public double GetRequiredLevel(int period)
86 {
87 return GetValue(period);
88 }
89
90 /// <summary>
91 /// Sets the required safety-stock level for a planning period.
92 /// </summary>
93 /// <param name="period">
94 /// One-based planning-period number.
95 /// </param>
96 /// <param name="level">
97 /// Non-negative finite safety-stock level.
98 /// </param>
99 public void SetRequiredLevel(
100 int period,
101 double level)
102 {
103 SetValue(period, level);
104 }
105
106 /// <summary>
107 /// Validates a safety-stock level.
108 /// </summary>
109 protected override void ValidateValue(
110 double value,
111 string parameterName)
112 {
113 // First validate that the value is finite (base class validation)
114 base.ValidateValue(value, parameterName);
115
116 // Then validate that the safety stock level is non-negative
117 if (value < 0.0)
118 {
119 throw new ArgumentOutOfRangeException(
120 parameterName,
121 value,
122 "A safety-stock level cannot be negative.");
123 }
124 }
125}
Represents a sequence of finite double values indexed by planning period.
DoubleTimeSeries RequiredLevels
Gets the complete safety-stock time series.
void SetRequiredLevel(int period, double level)
Sets the required safety-stock level for a planning period.
SafetyStock()
Initializes an empty safety-stock constraint.
override void ValidateValue(double value, string parameterName)
Validates a safety-stock level.
SafetyStock(int planningHorizon)
Initializes a safety-stock constraint for the specified planning horizon.
SafetyStock(int planningHorizon, double defaultSafetyStockLevel)
Initializes a safety-stock constraint and assigns the same required level to every planning period.
double GetRequiredLevel(int period)
Gets the required safety-stock level for a planning period.
DoubleTimeSeriesParameter()
Initializes an empty period-dependent parameter.
double GetValue(int period)
Gets the parameter value for a planning period.
DoubleTimeSeries Values
Gets or sets the values of the parameter for all planning periods.
void SetValue(int period, double value)
Sets the parameter value for a planning period.