2using System.ComponentModel;
4using System.Xml.Serialization;
5using LotSizingDataModel.Core.Common;
6using LotSizingDataModel.Core.PhysicalModel;
23[XmlType(TypeName =
"transportDecision")]
29 private int _transportResourceId;
31 private WarehouseReference _origin =
34 private WarehouseReference _destination =
37 private DoubleTimeSeries _transportedQuantities =
40 private IntegerTimeSeries _setups =
43 private DoubleTimeSeries _additionalCapacityUsed =
55 SubscribeToObject(_origin);
56 SubscribeToObject(_destination);
57 SubscribeToObject(_transportedQuantities);
58 SubscribeToObject(_setups);
59 SubscribeToObject(_additionalCapacityUsed);
83 int transportResourceId,
84 WarehouseReference origin,
85 WarehouseReference destination,
91 throw new ArgumentOutOfRangeException(
94 "The item identifier must be strictly positive.");
97 if (transportResourceId <= 0)
99 throw new ArgumentOutOfRangeException(
100 nameof(transportResourceId),
102 "The transport-resource identifier must be " +
103 "strictly positive.");
106 ArgumentNullException.ThrowIfNull(origin);
107 ArgumentNullException.ThrowIfNull(destination);
113 throw new ArgumentException(
114 "The origin and destination warehouses " +
115 "must be different.",
116 nameof(destination));
119 if (planningHorizon <= 0)
121 throw new ArgumentOutOfRangeException(
122 nameof(planningHorizon),
124 "The planning horizon must be strictly positive.");
141 [XmlAttribute(
"itemId")]
154 throw new ArgumentOutOfRangeException(
157 "The item identifier cannot be negative.");
170 [XmlAttribute(
"transportResourceId")]
173 get => _transportResourceId;
181 throw new ArgumentOutOfRangeException(
184 "The transport-resource identifier " +
185 "cannot be negative.");
189 ref _transportResourceId,
197 [XmlElement(
"origin")]
203 ArgumentNullException.ThrowIfNull(value);
212 UnsubscribeFromObject(_origin);
218 SubscribeToObject(_origin);
220 NotifyDerivedProperties();
227 [XmlElement(
"destination")]
233 ArgumentNullException.ThrowIfNull(value);
242 UnsubscribeFromObject(_destination);
248 SubscribeToObject(_destination);
250 NotifyDerivedProperties();
261 [XmlElement(
"transportedQuantities")]
264 get => _transportedQuantities;
267 ArgumentNullException.ThrowIfNull(value);
270 _transportedQuantities,
276 UnsubscribeFromObject(
277 _transportedQuantities);
280 ref _transportedQuantities,
284 _transportedQuantities);
286 NotifyDerivedProperties();
297 [XmlElement(
"setups")]
303 ArgumentNullException.ThrowIfNull(value);
312 UnsubscribeFromObject(_setups);
318 SubscribeToObject(_setups);
320 NotifyDerivedProperties();
334 [XmlElement(
"additionalCapacityUsed")]
337 get => _additionalCapacityUsed;
340 ArgumentNullException.ThrowIfNull(value);
343 _additionalCapacityUsed,
349 UnsubscribeFromObject(
350 _additionalCapacityUsed);
353 ref _additionalCapacityUsed,
357 _additionalCapacityUsed);
359 NotifyDerivedProperties();
377 Setups.PeriodCount ==
379 AdditionalCapacityUsed.PeriodCount ==
390 double.IsFinite(quantity) &&
411 double.IsFinite(capacity) &&
420 Origin.ReferenceId > 0 &&
421 Destination.ReferenceId > 0 &&
473 ValidateNonNegativeFiniteValue(
493 return Setups[period] == 1;
544 ValidateNonNegativeFiniteValue(
573 int transportResourceId,
574 WarehouseReference origin,
575 WarehouseReference destination)
577 ArgumentNullException.ThrowIfNull(origin);
578 ArgumentNullException.ThrowIfNull(destination);
580 return ItemId == itemId &&
582 transportResourceId &&
606 throw new ArgumentOutOfRangeException(
609 "The period count cannot be negative.");
624 NotifyDerivedProperties();
636 NotifyDerivedProperties();
642 double totalQuantity =
646 $
"Item {ItemId}, transport resource " +
647 $
"{TransportResourceId}, " +
648 $
"{FormatWarehouse(Origin)} -> " +
649 $
"{FormatWarehouse(Destination)}: " +
650 $
"total quantity {totalQuantity}";
653 private void SubscribeToObject(
654 ModelObject modelObject)
656 modelObject.PropertyChanged +=
657 OnNestedPropertyChanged;
660 private void UnsubscribeFromObject(
661 ModelObject modelObject)
663 modelObject.PropertyChanged -=
664 OnNestedPropertyChanged;
667 private void OnNestedPropertyChanged(
669 PropertyChangedEventArgs eventArgs)
671 NotifyDerivedProperties();
674 private void NotifyDerivedProperties()
698 private static bool SameWarehouse(
699 WarehouseReference first,
700 WarehouseReference second)
708 private static string FormatWarehouse(
709 WarehouseReference warehouse)
712 $
"{warehouse.Kind}:{warehouse.ReferenceId}";
715 private static void ValidateNonNegativeFiniteValue(
717 string parameterName)
719 if (!
double.IsFinite(value) ||
722 throw new ArgumentOutOfRangeException(
725 "The value must be finite and non-negative.");
void SetSetupActivated(int period, bool isActivated)
Sets the item-specific transport activation for a planning period.
WarehouseReference Destination
Gets or sets the destination warehouse reference.
bool IsSetupActivated(int period)
Determines whether item-specific transport is activated during a planning period.
void SetTransportedQuantity(int period, double quantity)
Sets the transported quantity for a planning period.
bool IsInternallyValid
Gets a value indicating whether the transport decision is internally consistent.
override string ToString()
TransportDecision(int itemId, int transportResourceId, WarehouseReference origin, WarehouseReference destination, int planningHorizon)
Initializes a transport decision for an item, a transport resource and a directed warehouse lane.
TransportDecision()
Initializes an empty transport decision.
int TransportResourceId
Gets or sets the identifier of the transport resource used by the decision.
void ResizeTimeSeries(int periodCount)
Resizes every decision series to the specified planning horizon.
double GetAdditionalCapacityUsed(int period)
Gets the item-specific additional transport capacity used during a planning period.
double GetTransportedQuantity(int period)
Gets the transported quantity for a planning period.
DoubleTimeSeries AdditionalCapacityUsed
Gets or sets the item-specific additional transport capacity used during each planning period.
int PlanningHorizon
Gets the number of planning periods represented by the transported-quantity series.
DoubleTimeSeries TransportedQuantities
Gets or sets the quantities transported during each planning period.
void SetAdditionalCapacityUsed(int period, double capacity)
Sets the item-specific additional transport capacity used during a planning period.
void Clear()
Resets every transport decision value to zero.
bool HasValidAdditionalCapacityValues
Gets a value indicating whether every additional-capacity value is finite and non-negative.
bool HasConsistentPlanningHorizon
Gets a value indicating whether all decision series use the same planning horizon.
bool HasValidSetupValues
Gets a value indicating whether every setup value is equal to zero or one.
bool HasValidLane
Gets a value indicating whether the origin and destination identify different warehouses.
bool Matches(int itemId, int transportResourceId, WarehouseReference origin, WarehouseReference destination)
Determines whether this decision identifies the specified item, resource and directed warehouse lane.
WarehouseReference Origin
Gets or sets the origin warehouse reference.
IntegerTimeSeries Setups
Gets or sets the binary item-specific transport activation decisions.
bool HasValidTransportedQuantities
Gets a value indicating whether every transported quantity is finite and non-negative.
int ItemId
Gets or sets the identifier of the transported item.