LotSizingDataModel.Core 2.0.1
Core domain model, shared abstractions and XML-serializable entities.
Loading...
Searching...
No Matches
UnitUsageCost.cs
Go to the documentation of this file.
1using System;
2using System.Xml.Serialization;
5
7
8/// <summary>
9/// Represents the unit cost incurred when a resource is used
10/// to manufacture, store or transport one unit of an item
11/// during a planning period.
12///
13/// Corresponds to the UML class "Cout d'utilisation".
14/// Its values correspond to Cutil[t] in the source model.
15/// </summary>
16[Serializable]
17[XmlType(TypeName = "unitUsageCost")]
18public sealed class UnitUsageCost :
20{
21 /// <summary>
22 /// Initializes an empty unit-usage-cost parameter.
23 ///
24 /// This public parameterless constructor is required
25 /// by <see cref="XmlSerializer"/>.
26 /// </summary>
28 {
29 }
30
31 /// <summary>
32 /// Initializes a unit-usage-cost parameter for the specified
33 /// planning horizon.
34 ///
35 /// Every period is initially assigned a unit cost of zero.
36 /// </summary>
37 /// <param name="planningHorizon">
38 /// Number of periods in the planning horizon.
39 /// </param>
40 public UnitUsageCost(int planningHorizon)
41 : base(
42 planningHorizon,
43 defaultValue: 0.0) // Initialize all periods with zero unit usage cost
44 {
45 }
46
47 /// <summary>
48 /// Initializes a unit-usage-cost parameter and assigns
49 /// the same unit cost to every planning period.
50 /// </summary>
51 /// <param name="planningHorizon">
52 /// Number of periods in the planning horizon.
53 /// </param>
54 /// <param name="defaultUnitUsageCost">
55 /// Unit usage cost initially assigned to every period.
56 /// </param>
58 int planningHorizon,
59 double defaultUnitUsageCost)
60 : base(
61 planningHorizon,
62 defaultUnitUsageCost) // Initialize all periods with the specified unit usage cost
63 {
64 }
65
66 /// <summary>
67 /// Gets the complete unit-usage-cost time series.
68 ///
69 /// This property is an alias for <see cref="LotSizingDataModel.Core.DecisionModel.DoubleTimeSeriesParameter.Values"/>
70 /// and is not serialized separately.
71 /// </summary>
72 [XmlIgnore]
74 Values;
75
76 /// <summary>
77 /// Gets the unit usage cost for a planning period.
78 /// </summary>
79 /// <param name="period">
80 /// One-based planning-period number.
81 /// </param>
82 public double GetUnitUsageCost(int period)
83 {
84 return GetValue(period);
85 }
86
87 /// <summary>
88 /// Sets the unit usage cost for a planning period.
89 /// </summary>
90 /// <param name="period">
91 /// One-based planning-period number.
92 /// </param>
93 /// <param name="cost">
94 /// Non-negative finite cost per processed item unit.
95 /// </param>
96 public void SetUnitUsageCost(
97 int period,
98 double cost)
99 {
100 SetValue(period, cost);
101 }
102
103 /// <summary>
104 /// Validates a unit usage cost.
105 /// </summary>
106 protected override void ValidateValue(
107 double value,
108 string parameterName)
109 {
110 // First validate that the value is finite (base class validation)
111 base.ValidateValue(value, parameterName);
112
113 // Then validate that the unit usage cost is non-negative
114 if (value < 0.0)
115 {
116 throw new ArgumentOutOfRangeException(
117 parameterName,
118 value,
119 "A unit usage cost cannot be negative.");
120 }
121 }
122}
Represents a sequence of finite double values indexed by planning period.
double GetUnitUsageCost(int period)
Gets the unit usage cost for a planning period.
UnitUsageCost()
Initializes an empty unit-usage-cost parameter.
void SetUnitUsageCost(int period, double cost)
Sets the unit usage cost for a planning period.
UnitUsageCost(int planningHorizon)
Initializes a unit-usage-cost parameter for the specified planning horizon.
DoubleTimeSeries UnitUsageCostByPeriod
Gets the complete unit-usage-cost time series.
UnitUsageCost(int planningHorizon, double defaultUnitUsageCost)
Initializes a unit-usage-cost parameter and assigns the same unit cost to every planning period.
override void ValidateValue(double value, string parameterName)
Validates a unit usage cost.
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.