2using System.ComponentModel;
4using System.Xml.Serialization;
5using LotSizingDataModel.Core.Common;
6using LotSizingDataModel.Core.PhysicalModel;
23[XmlType(TypeName =
"purchaseDecision")]
28 private int _supplierId;
31 private WarehouseReference _destinationWarehouse =
34 private DoubleTimeSeries _purchasedQuantities =
46 SubscribeToObject(_destinationWarehouse);
47 SubscribeToObject(_purchasedQuantities);
69 WarehouseReference destinationWarehouse,
75 throw new ArgumentOutOfRangeException(
78 "The supplier identifier must be strictly positive.");
83 throw new ArgumentOutOfRangeException(
86 "The item identifier must be strictly positive.");
89 ArgumentNullException.ThrowIfNull(
90 destinationWarehouse);
92 if (planningHorizon <= 0)
94 throw new ArgumentOutOfRangeException(
95 nameof(planningHorizon),
97 "The planning horizon must be strictly positive.");
104 destinationWarehouse;
113 [XmlAttribute(
"supplierId")]
126 throw new ArgumentOutOfRangeException(
129 "The supplier identifier cannot be negative.");
141 [XmlAttribute(
"itemId")]
152 throw new ArgumentOutOfRangeException(
155 "The item identifier cannot be negative.");
168 [XmlElement(
"destinationWarehouse")]
171 get => _destinationWarehouse;
174 ArgumentNullException.ThrowIfNull(value);
177 _destinationWarehouse,
183 UnsubscribeFromObject(
184 _destinationWarehouse);
187 ref _destinationWarehouse,
191 _destinationWarehouse);
193 NotifyDerivedProperties();
208 [XmlElement(
"purchasedQuantities")]
211 get => _purchasedQuantities;
214 ArgumentNullException.ThrowIfNull(value);
217 _purchasedQuantities,
223 UnsubscribeFromObject(
224 _purchasedQuantities);
227 ref _purchasedQuantities,
231 _purchasedQuantities);
233 NotifyDerivedProperties();
253 double.IsFinite(quantity) &&
262 DestinationWarehouse.ReferenceId > 0;
308 ValidateNonNegativeFiniteValue(
335 WarehouseReference destinationWarehouse)
337 ArgumentNullException.ThrowIfNull(
338 destinationWarehouse);
344 destinationWarehouse);
362 throw new ArgumentOutOfRangeException(
365 "The period count cannot be negative.");
372 NotifyDerivedProperties();
382 NotifyDerivedProperties();
388 double totalPurchasedQuantity =
392 $
"Supplier {SupplierId}, item {ItemId}, " +
394 $
"{FormatWarehouse(DestinationWarehouse)}: " +
395 $
"total purchased quantity " +
396 $
"{totalPurchasedQuantity}";
399 private void SubscribeToObject(
400 ModelObject modelObject)
402 modelObject.PropertyChanged +=
403 OnNestedPropertyChanged;
406 private void UnsubscribeFromObject(
407 ModelObject modelObject)
409 modelObject.PropertyChanged -=
410 OnNestedPropertyChanged;
413 private void OnNestedPropertyChanged(
415 PropertyChangedEventArgs eventArgs)
417 NotifyDerivedProperties();
420 private void NotifyDerivedProperties()
435 private static bool SameWarehouse(
436 WarehouseReference first,
437 WarehouseReference second)
445 private static string FormatWarehouse(
446 WarehouseReference warehouse)
449 $
"{warehouse.Kind}:{warehouse.ReferenceId}";
452 private static void ValidateNonNegativeFiniteValue(
454 string parameterName)
456 if (!
double.IsFinite(value) ||
459 throw new ArgumentOutOfRangeException(
462 "The value must be finite and non-negative.");
int PlanningHorizon
Gets the number of planning periods represented by the purchased-quantity series.
WarehouseReference DestinationWarehouse
Gets or sets the warehouse to which the purchased item is delivered.
PurchaseDecision()
Initializes an empty purchase decision.
int ItemId
Gets or sets the identifier of the purchased item.
DoubleTimeSeries PurchasedQuantities
Gets or sets the quantities purchased during each planning period.
override string ToString()
int SupplierId
Gets or sets the identifier of the supplier associated with the purchase decision.
bool HasValidDestinationWarehouse
Gets a value indicating whether the destination warehouse reference is initialized.
void ResizeTimeSeries(int periodCount)
Resizes the purchased-quantity series to the specified planning horizon.
double GetPurchasedQuantity(int period)
Gets the purchased quantity for a planning period.
void SetPurchasedQuantity(int period, double quantity)
Sets the purchased quantity for a planning period.
bool IsInternallyValid
Gets a value indicating whether the purchase decision is internally consistent.
void Clear()
Resets every purchased quantity to zero.
PurchaseDecision(int supplierId, int itemId, WarehouseReference destinationWarehouse, int planningHorizon)
Initializes a purchase decision for a supplier, an item, a destination warehouse and a planning horiz...
bool HasValidPurchasedQuantities
Gets a value indicating whether every purchased quantity is finite and non-negative.
bool Matches(int supplierId, int itemId, WarehouseReference destinationWarehouse)
Determines whether this decision identifies the specified supplier, item and destination warehouse.