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