LotSizingDataModel.Core 2.0.1
Core domain model, shared abstractions and XML-serializable entities.
Loading...
Searching...
No Matches
SupplierDelivery.DecisionModel.cs
Go to the documentation of this file.
5using System;
6using System.ComponentModel;
7using System.Xml.Serialization;
8
10
11/// <summary>
12/// Adds the optional purchase-price parameter associated
13/// with the delivery of an item from a supplier to a warehouse.
14/// </summary>
15public sealed partial class SupplierDelivery :
16 IPlanningHorizonAware
17{
18 private PurchasePrice? _purchasePrice;
19 private CapacityConstraint? _capacityConstraint;
20
21 /// <summary>
22 /// Gets or sets the unit purchase price of the item
23 /// for each planning period.
24 ///
25 /// A null value means that no purchase price is defined
26 /// for this supplier-item-warehouse relationship.
27 /// </summary>
28 [XmlElement("purchasePrice")]
30 {
31 get => _purchasePrice;
32 set
33 {
34 if (ReferenceEquals(_purchasePrice, value))
35 {
36 return;
37 }
38
39 // Unsubscribe from old parameter.
40 if (_purchasePrice is not null)
41 {
42 _purchasePrice.PropertyChanged -=
43 OnPurchasePricePropertyChanged;
44 }
45
46 _purchasePrice = value;
47
48 // Subscribe to new parameter.
49 if (_purchasePrice is not null)
50 {
51 _purchasePrice.PropertyChanged +=
52 OnPurchasePricePropertyChanged;
53 }
54
55 // Notify the specific property plus all dependent ones.
59 }
60 }
61
62 /// <summary>
63 /// Gets or sets the maximum procurement quantity available
64 /// from this supplier for this item and destination.
65 /// </summary>
66 [XmlElement("capacityConstraint")]
68 {
69 get => _capacityConstraint;
70 set
71 {
72 if (ReferenceEquals(_capacityConstraint, value))
73 {
74 return;
75 }
76
77 if (_capacityConstraint is not null)
78 {
79 _capacityConstraint.PropertyChanged -=
80 OnCapacityConstraintPropertyChanged;
81 }
82
83 _capacityConstraint = value;
84
85 if (_capacityConstraint is not null)
86 {
87 _capacityConstraint.PropertyChanged +=
88 OnCapacityConstraintPropertyChanged;
89 }
90
95 }
96 }
97
98 /// <summary>
99 /// Gets the planning horizon represented by the
100 /// purchase-price time series.
101 ///
102 /// Returns zero when no purchase price is defined.
103 /// </summary>
104 [XmlIgnore]
105 public int PlanningHorizon =>
106 PurchasePrice?.PlanningHorizon ??
107 CapacityConstraint?.PlanningHorizon ??
108 0;
109
110 /// <summary>
111 /// Gets a value indicating whether this delivery
112 /// contains at least one decision-model parameter.
113 /// </summary>
114 [XmlIgnore]
116 PurchasePrice is not null ||
117 CapacityConstraint is not null;
118
119 [XmlIgnore]
121 PurchasePrice is null ||
122 CapacityConstraint is null ||
124 CapacityConstraint.PlanningHorizon;
125
126 /// <summary>
127 /// Resizes the purchase-price time series.
128 ///
129 /// Existing values are preserved and newly created
130 /// periods are initialized according to PurchasePrice.
131 /// </summary>
132 /// <param name="periodCount">
133 /// New number of planning periods.
134 /// </param>
135 public void ResizeTimeSeries(int periodCount)
136 {
137 if (periodCount < 0)
138 {
139 throw new ArgumentOutOfRangeException(
140 nameof(periodCount),
141 periodCount,
142 "The planning horizon cannot be negative.");
143 }
144
145 // Resize active period-dependent parameters.
146 PurchasePrice?.ResizeTimeSeries(periodCount);
147 CapacityConstraint?.ResizeTimeSeries(periodCount);
148
149 // Notify dependent computed property.
151 }
152
153 /// <summary>
154 /// Removes the purchase-price parameter from
155 /// this supplier delivery.
156 /// </summary>
158 {
159 PurchasePrice = null;
160 CapacityConstraint = null;
161 }
162
163 private void OnCapacityConstraintPropertyChanged(
164 object? sender,
165 PropertyChangedEventArgs e)
166 {
170 }
171
172 private void OnPurchasePricePropertyChanged(
173 object? sender,
174 PropertyChangedEventArgs e)
175 {
176 // Forward notification and update dependent computed property.
179 }
180}
virtual void OnPropertyChanged([CallerMemberName] string? propertyName=null)
Raises the PropertyChanged event.
Represents a maximum-capacity constraint defined for each planning period.
Represents the unit purchase price of an item bought from a supplier during each planning period.
Represents the ability of a supplier to deliver a given item to a given warehouse inventory.
int PlanningHorizon
Gets the planning horizon represented by the purchase-price time series.
PurchasePrice? PurchasePrice
Gets or sets the unit purchase price of the item for each planning period.
bool HasDecisionParameters
Gets a value indicating whether this delivery contains at least one decision-model parameter.
CapacityConstraint? CapacityConstraint
Gets or sets the maximum procurement quantity available from this supplier for this item and destinat...
void ResizeTimeSeries(int periodCount)
Resizes the purchase-price time series.
void ClearDecisionParameters()
Removes the purchase-price parameter from this supplier delivery.
int PlanningHorizon
Gets the number of planning periods currently represented by the object's time-dependent data.