LotSizingDataModel.Solver 2.0.1
Solver-independent modeling, execution, monitoring and adapter infrastructure.
Loading...
Searching...
No Matches
ProductionStartUpDefinitionConstraintFamilyBuilder.cs
Go to the documentation of this file.
1using LotSizingDataModel.Core.Relationships;
2using LotSizingDataModel.Instance;
6
8
9/// <summary>
10/// Defines standard start-up events as exact 0-to-1 setup transitions.
11/// </summary>
14{
15 public override string ConstraintFamilyId =>
16 "productionStartUpDefinition";
17
18 public override bool IsEnabled(
19 LotSizingInstance instance,
21 {
22 ArgumentNullException.ThrowIfNull(instance);
23 ArgumentNullException.ThrowIfNull(options);
24
25 return
26 options.IncludeProductionSetups &&
27 instance.SupplyChain.ProductionCharacteristics.Any(
28 characteristic =>
29 characteristic.StartUpCost is not null);
30 }
31
32 protected override ValueTask BuildConstraintsAsync(
33 LotSizingInstance instance,
36 CancellationToken cancellationToken)
37 {
38 foreach (ProductionRouting routing
39 in instance.SupplyChain.ProductionRoutings)
40 {
41 bool hasStartUpCost =
42 routing.WorkCenters.Any(
43 reference =>
44 instance.SupplyChain.ProductionCharacteristics.Any(
45 characteristic =>
46 characteristic.ItemId == routing.ItemId &&
47 characteristic.WorkCenter.PlantId == reference.PlantId &&
48 characteristic.WorkCenter.WorkCenterId == reference.WorkCenterId &&
49 characteristic.StartUpCost is not null));
50
51 if (!hasStartUpCost)
52 {
53 continue;
54 }
55
56 for (int period = 1;
57 period <= instance.PlanningHorizon;
58 period++)
59 {
60 cancellationToken.ThrowIfCancellationRequested();
61
62 MathematicalVariable startUp =
64 context,
66 routing.Id,
67 period));
68
71 context,
72 SetupKey(
73 routing.Id,
74 period));
75
76 string suffix =
77 $"_r{routing.Id}_t{period}";
78
79 if (period == 1)
80 {
82 context,
83 "productionStartUpInitial" + suffix,
85 .Add(startUp)
86 .Subtract(setup)
87 .Build(),
89 0.0);
90
91 continue;
92 }
93
94 MathematicalVariable previous =
96 context,
97 SetupKey(
98 routing.Id,
99 period - 1));
100
102 context,
103 "productionStartUpLower" + suffix,
105 .Add(startUp)
106 .Subtract(setup)
107 .Add(previous)
108 .Build(),
109 MathematicalConstraintSense.GreaterThanOrEqual,
110 0.0);
111
113 context,
114 "productionStartUpUpperCurrent" + suffix,
116 .Add(startUp)
117 .Subtract(setup)
118 .Build(),
119 MathematicalConstraintSense.LessThanOrEqual,
120 0.0);
121
123 context,
124 "productionStartUpUpperPrevious" + suffix,
126 .Add(startUp)
127 .Add(previous)
128 .Build(),
129 MathematicalConstraintSense.LessThanOrEqual,
130 1.0);
131 }
132 }
133
134 return ValueTask.CompletedTask;
135 }
136
137 private static string SetupKey(
138 int routingId,
139 int period) =>
144 .Build();
145}
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.
override ValueTask BuildConstraintsAsync(LotSizingInstance instance, MathematicalModelBuildContext context, StandardLotSizingFormulationOptions options, CancellationToken cancellationToken)
override bool IsEnabled(LotSizingInstance instance, StandardLotSizingFormulationOptions options)
Determines whether this constraint family is enabled.
Builds canonical mathematical domain keys for production start-up events.
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 Setup
Identifies production setup 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.