LotSizingDataModel.Solver 2.0.1
Solver-independent modeling, execution, monitoring and adapter infrastructure.
Loading...
Searching...
No Matches
GlspMacroCapacityConstraintFamilyBuilder.cs
Go to the documentation of this file.
1using LotSizingDataModel.Core.DecisionModel.Scheduling;
2using LotSizingDataModel.Core.Relationships;
3using LotSizingDataModel.Instance;
7
9
10/// <summary>
11/// Builds GLSP macro-period capacity including production, generic setup-start
12/// time, distinct start-up time, and sequence-dependent changeover time.
13/// </summary>
16{
17 public override string ConstraintFamilyId =>
18 "glspMacroCapacity";
19
20 protected override ValueTask BuildConstraintsAsync(
21 LotSizingInstance instance,
24 CancellationToken cancellationToken)
25 {
26 var (plantId,wc,profile) =
28
29 IReadOnlyList<ProductionRouting> routings =
31 instance,
32 plantId,
33 wc.Id);
34
35 var ordered =
36 profile.EnumerateMicroPeriods().ToArray();
37
38 for(int period=1;
39 period<=instance.PlanningHorizon;
40 period++)
41 {
42 var expression =
44
45 for(int index=0;
46 index<ordered.Length;
47 index++)
48 {
49 var micro =
50 ordered[index];
51
52 if(micro.MacroPeriod!=period)
53 {
54 continue;
55 }
56
57 int fixedFrom =
59 profile,
60 index);
61
62 bool reset =
63 index>0 &&
65 profile,
66 ordered[index-1],
67 micro);
68
69 foreach(ProductionRouting routing in routings)
70 {
71 ProductionCharacteristic characteristic =
73 instance,
74 routing,
75 plantId,
76 wc.Id);
77
78 expression.Add(
80 context,
82 plantId,
83 wc.Id,
84 routing.Id,
85 routing.ItemId,
86 micro)),
87 characteristic.UnitCapacityConsumption![period]);
88
89 double setupTime =
90 characteristic.SetupTime?[period] ?? 0.0;
91
92 if(setupTime>0.0)
93 {
94 expression.Add(
96 context,
98 plantId,
99 wc.Id,
100 routing.Id,
101 routing.ItemId,
102 micro,
103 fixedFrom,
104 reset)),
105 setupTime);
106 }
107
108 double startUpTime =
109 characteristic.StartUpTime?[period] ?? 0.0;
110
111 if(startUpTime>0.0)
112 {
113 expression.Add(
115 context,
117 plantId,
118 wc.Id,
119 routing.Id,
120 routing.ItemId,
121 micro,
122 fixedFrom,
123 reset)),
124 startUpTime);
125 }
126 }
127
128 foreach(ProductionRouting from in routings)
129 foreach(ProductionRouting to in routings)
130 {
131 if(from.ItemId==to.ItemId)
132 {
133 continue;
134 }
135
136 string key =
138 plantId,
139 wc.Id,
140 from.ItemId,
141 to.ItemId,
142 micro);
143
144 if(!context.VariableRegistry.TryGet(
145 key,
146 out MathematicalVariable? changeover) ||
147 changeover is null)
148 {
149 continue;
150 }
151
152 double changeoverTime =
154 profile,
155 from.ItemId,
156 to.ItemId)?.ChangeoverTime?[period] ?? 0.0;
157
158 if(changeoverTime>0.0)
159 {
160 expression.Add(
161 changeover,
162 changeoverTime);
163 }
164 }
165 }
166
167 string additionalKey =
173 .Build();
174
175 if(context.VariableRegistry.TryGet(
176 additionalKey,
177 out MathematicalVariable? additional) &&
178 additional is not null)
179 {
180 expression.Subtract(additional);
181 }
182
184 context,
185 $"glspMacroCapacity_p{plantId}_w{wc.Id}_t{period}",
186 expression.Build(),
187 MathematicalConstraintSense.LessThanOrEqual,
188 wc.CapacityConstraint![period]);
189 }
190
191 return ValueTask.CompletedTask;
192 }
193}
Provides a fluent builder for linear expressions.
Builds stable business-domain keys for mathematical variables and constraints.
MathematicalDomainKeyBuilder Add(string name, string value)
Adds a text segment.
Provides the shared state required while constructing a solver-independent mathematical model.
MathematicalModel Build(bool clone=true)
Builds and validates the mathematical model.
MathematicalVariableRegistry VariableRegistry
Gets the registry that maps business-domain keys to mathematical variables.
bool TryGet(string domainKey, out MathematicalVariable? variable)
Attempts to get the variable registered for a domain key.
static string CreateChangeoverKey(int plantId, int workCenterId, int fromItemId, int toItemId, ProductionMicroPeriodReference microPeriod)
static string CreateMicroProductionKey(int plantId, int workCenterId, int routingId, int itemId, ProductionMicroPeriodReference microPeriod)
static string CreateMicroSetupStartKey(int plantId, int workCenterId, int routingId, int itemId, ProductionMicroPeriodReference microPeriod, int fixedPredecessorItemId, bool resetBoundary)
Builds GLSP macro-period capacity including production, generic setup-start time, distinct start-up t...
override string ConstraintFamilyId
Gets the unique identifier of the constraint family.
override ValueTask BuildConstraintsAsync(LotSizingInstance instance, MathematicalModelBuildContext context, StandardLotSizingFormulationOptions options, CancellationToken cancellationToken)
static ? ProductionChangeover FindChangeover(ProductionSchedulingProfile profile, int fromItemId, int toItemId)
static int WorkCenter ProductionSchedulingProfile Profile GetSchedulingWorkCenter(LotSizingInstance instance)
static ProductionCharacteristic GetCharacteristic(LotSizingInstance instance, ProductionRouting routing, int plantId, int workCenterId)
static IReadOnlyList< ProductionRouting > GetRoutings(LotSizingInstance instance, int plantId, int workCenterId)
static bool IsResetBoundary(ProductionSchedulingProfile profile, ProductionMicroPeriodReference previous, ProductionMicroPeriodReference current)
static int GetFixedPredecessorItemId(ProductionSchedulingProfile profile, int index)
Builds canonical mathematical domain keys for production start-up events.
static string CreateGlspKey(int plantId, int workCenterId, int routingId, int itemId, ProductionMicroPeriodReference microPeriod, int fixedPredecessorItemId, bool resetBoundary)
Provides common validation and helper methods for one constraint family of the standard lot-sizing fo...
static MathematicalVariable GetVariable(MathematicalModelBuildContext context, string domainKey)
Resolves a required variable from its canonical domain key.
static void AddConstraint(MathematicalModelBuildContext context, string name, LinearExpression expression, MathematicalConstraintSense sense, double rightHandSide, string domainKey="", string description="")
Adds one linear constraint to the mathematical model.
Configures the standard solver-independent mixed-integer lot-sizing formulation.
Provides the canonical mathematical domain-key categories used to identify lot-sizing decision famili...
const string WorkCenterAdditionalCapacity
Identifies additional work-center-capacity decision variables.
Provides the canonical mathematical domain-key segment names used by lot-sizing variables and constra...
Represents one decision variable in a mathematical optimization model.
MathematicalConstraintSense
Identifies the relational sense of a mathematical constraint.