2using System.ComponentModel;
4using System.Xml.Serialization;
18[XmlType(TypeName =
"demand")]
24 private int _distributionCenterId;
36 SubscribeToQuantities(_quantities);
53 int distributionCenterId,
68 [XmlAttribute(
"itemId")]
77 throw new ArgumentOutOfRangeException(
80 "The item identifier cannot be negative.");
84 SetProperty(ref _itemId, value);
94 [XmlAttribute(
"distributionCenterId")]
97 get => _distributionCenterId;
103 throw new ArgumentOutOfRangeException(
106 "The distribution-center identifier cannot be negative.");
111 ref _distributionCenterId,
122 [XmlElement(
"quantities")]
133 if (ReferenceEquals(_quantities, newValue))
139 UnsubscribeFromQuantities(_quantities);
141 _quantities = newValue;
144 SubscribeToQuantities(_quantities);
187 ValidateQuantity(quantity, nameof(quantity));
195 public void Fill(
double quantity)
198 ValidateQuantity(quantity, nameof(quantity));
214 throw new ArgumentOutOfRangeException(
217 "The planning horizon cannot be negative.");
233 return other is not
null
252 int distributionCenterId)
256 distributionCenterId;
267 !
double.IsNaN(quantity)
268 && !
double.IsInfinity(quantity)
274 private void SubscribeToQuantities(
278 quantities.PropertyChanged +=
279 OnQuantitiesPropertyChanged;
285 private void UnsubscribeFromQuantities(
289 quantities.PropertyChanged -=
290 OnQuantitiesPropertyChanged;
297 private void OnQuantitiesPropertyChanged(
299 PropertyChangedEventArgs e)
305 if (e.PropertyName ==
323 private static void ValidateQuantity(
325 string parameterName)
328 if (
double.IsNaN(quantity) ||
329 double.IsInfinity(quantity))
331 throw new ArgumentOutOfRangeException(
334 "A demand quantity must be a finite number.");
340 throw new ArgumentOutOfRangeException(
343 "A demand quantity cannot be negative.");
Represents a sequence of finite double values indexed by planning period.
double[] Values
Gets or replaces all values of the time series.
int PeriodCount
Gets the number of periods currently represented.
Base class for model objects that notify listeners when one of their properties changes.
virtual void OnPropertyChanged([CallerMemberName] string? propertyName=null)
Raises the PropertyChanged event.
Demand()
Initializes an empty demand.
bool ConcernsItem(int itemId)
Determines whether this demand concerns the specified item.
bool ConcernsDistributionCenter(int distributionCenterId)
Determines whether this demand concerns the specified distribution center.
int ItemId
Gets or sets the identifier of the requested item.
void SetQuantity(int period, double quantity)
Sets the demand quantity for a planning period.
int PlanningHorizon
Gets the number of periods represented by the demand.
Demand(int itemId, int distributionCenterId, int planningHorizon)
Initializes a demand for an item and a distribution center.
int DistributionCenterId
Gets or sets the identifier of the distribution center issuing the demand.
bool HasValidQuantities
Checks whether all currently stored demand quantities are finite and non-negative.
DoubleTimeSeries Quantities
Gets or sets the quantities requested for each planning period.
void ResizeTimeSeries(int periodCount)
Resizes the period-dependent demand data.
bool RefersToSameDemand(Demand? other)
Determines whether this object represents the same item/distribution-center association as another de...
void Fill(double quantity)
Assigns the same demand quantity to every period.
double GetQuantity(int period)
Gets the demand quantity for a planning period.
Defines a model object containing data indexed by planning period.