LotSizingDataModel.Core 2.0.1
Core domain model, shared abstractions and XML-serializable entities.
Loading...
Searching...
No Matches
GroupingConstraint.cs
Go to the documentation of this file.
1using System;
2using System.Xml.Serialization;
5
7
8/// <summary>
9/// Represents a production-flow grouping rule defined
10/// for each planning period.
11///
12/// When this constraint is active, its value indicates the number
13/// of consecutive periods covered by the grouping window.
14///
15/// Corresponds to the UML class "Regroupement".
16/// Its values correspond to Regroup[t] in the source model.
17/// </summary>
18[Serializable]
19[XmlType(TypeName = "groupingConstraint")]
20public sealed class GroupingConstraint :
22{
23 /// <summary>
24 /// Initializes an empty grouping constraint.
25 ///
26 /// This public parameterless constructor is required
27 /// by <see cref="XmlSerializer"/>.
28 /// </summary>
30 {
31 }
32
33 /// <summary>
34 /// Initializes a grouping constraint for the specified
35 /// planning horizon.
36 ///
37 /// Every period is initially assigned a grouping window
38 /// of one period.
39 /// </summary>
40 /// <param name="planningHorizon">
41 /// Number of periods in the planning horizon.
42 /// </param>
43 public GroupingConstraint(int planningHorizon)
44 : base(
45 planningHorizon,
46 defaultValue: 1) // Initialize all periods with a grouping window of one period
47 {
48 }
49
50 /// <summary>
51 /// Initializes a grouping constraint and assigns the same
52 /// grouping-window length to every planning period.
53 /// </summary>
54 /// <param name="planningHorizon">
55 /// Number of periods in the planning horizon.
56 /// </param>
57 /// <param name="defaultGroupingPeriodCount">
58 /// Strictly positive number of periods initially assigned
59 /// to every planning period.
60 /// </param>
62 int planningHorizon,
63 int defaultGroupingPeriodCount)
64 : base(
65 planningHorizon,
66 defaultGroupingPeriodCount) // Initialize all periods with the specified grouping window
67 {
68 }
69
70 /// <summary>
71 /// Gets the complete grouping-window time series.
72 ///
73 /// This property is an alias for <see cref="LotSizingDataModel.Core.DecisionModel.IntegerTimeSeriesParameter.Values"/>
74 /// and is not serialized separately.
75 /// </summary>
76 [XmlIgnore]
78 Values;
79
80 /// <summary>
81 /// Gets the grouping-window length for a planning period.
82 /// </summary>
83 /// <param name="period">
84 /// One-based planning-period number.
85 /// </param>
86 /// <returns>
87 /// Strictly positive number of periods in the grouping window.
88 /// </returns>
89 public int GetGroupingPeriodCount(int period)
90 {
91 return GetValue(period);
92 }
93
94 /// <summary>
95 /// Sets the grouping-window length for a planning period.
96 /// </summary>
97 /// <param name="period">
98 /// One-based planning-period number.
99 /// </param>
100 /// <param name="groupingPeriodCount">
101 /// Strictly positive number of periods in the grouping window.
102 /// </param>
104 int period,
105 int groupingPeriodCount)
106 {
107 SetValue(period, groupingPeriodCount);
108 }
109
110 /// <summary>
111 /// Gets the value assigned to periods created when
112 /// the planning horizon grows.
113 ///
114 /// A value of one preserves a valid grouping constraint.
115 /// </summary>
116 [XmlIgnore]
117 protected override int DefaultValueForNewPeriods => 1;
118
119 /// <summary>
120 /// Validates a grouping-window length.
121 /// </summary>
122 protected override void ValidateValue(
123 int value,
124 string parameterName)
125 {
126 // Call base class validation (no-op for integer parameters)
127 base.ValidateValue(value, parameterName);
128
129 // Validate that the grouping period count is strictly positive
130 if (value <= 0)
131 {
132 throw new ArgumentOutOfRangeException(
133 parameterName,
134 value,
135 "A grouping-period count must be strictly positive.");
136 }
137 }
138}
Represents a sequence of integer values indexed by planning period.
override int DefaultValueForNewPeriods
Gets the value assigned to periods created when the planning horizon grows.
IntegerTimeSeries GroupingPeriodCountByPeriod
Gets the complete grouping-window time series.
int GetGroupingPeriodCount(int period)
Gets the grouping-window length for a planning period.
GroupingConstraint(int planningHorizon, int defaultGroupingPeriodCount)
Initializes a grouping constraint and assigns the same grouping-window length to every planning perio...
GroupingConstraint(int planningHorizon)
Initializes a grouping constraint for the specified planning horizon.
void SetGroupingPeriodCount(int period, int groupingPeriodCount)
Sets the grouping-window length for a planning period.
override void ValidateValue(int value, string parameterName)
Validates a grouping-window length.
int GetValue(int period)
Gets the parameter value for a planning period.
IntegerTimeSeriesParameter()
Initializes an empty period-dependent integer parameter.
void SetValue(int period, int value)
Sets the parameter value for a planning period.
IntegerTimeSeries Values
Gets or sets the parameter values for all planning periods.