LotSizingDataModel.Solver 2.0.1
Solver-independent modeling, execution, monitoring and adapter infrastructure.
Loading...
Searching...
No Matches
GlspStartUpDefinitionConstraintFamilyBuilder.cs
Go to the documentation of this file.
1using LotSizingDataModel.Core.Relationships;
2using LotSizingDataModel.Instance;
5
7
8/// <summary>
9/// Synchronizes the distinct GLSP start-up variable with the exact
10/// micro-period setup-start event.
11/// </summary>
14{
15 public override string ConstraintFamilyId =>
16 "glspProductionStartUpDefinition";
17
18 public override bool IsEnabled(
19 LotSizingInstance instance,
21 {
22 ArgumentNullException.ThrowIfNull(instance);
23 ArgumentNullException.ThrowIfNull(options);
24
25 return instance.SupplyChain.ProductionCharacteristics.Any(
26 characteristic =>
27 characteristic.StartUpCost is not null ||
28 characteristic.StartUpTime is not null);
29 }
30
31 protected override ValueTask BuildConstraintsAsync(
32 LotSizingInstance instance,
35 CancellationToken cancellationToken)
36 {
37 var (plantId, workCenter, profile) =
39
40 IReadOnlyList<ProductionRouting> routings =
42 instance,
43 plantId,
44 workCenter.Id);
45
46 var ordered =
47 profile.EnumerateMicroPeriods().ToArray();
48
49 for (int index = 0;
50 index < ordered.Length;
51 index++)
52 {
53 int fixedFrom =
55 profile,
56 index);
57
58 bool reset =
59 index > 0 &&
61 profile,
62 ordered[index - 1],
63 ordered[index]);
64
65 foreach (ProductionRouting routing
66 in routings)
67 {
68 ProductionCharacteristic characteristic =
70 instance,
71 routing,
72 plantId,
73 workCenter.Id);
74
75 if (characteristic.StartUpCost is null &&
76 characteristic.StartUpTime is null)
77 {
78 continue;
79 }
80
81 MathematicalVariable startUp =
83 context,
85 plantId,
86 workCenter.Id,
87 routing.Id,
88 routing.ItemId,
89 ordered[index],
90 fixedFrom,
91 reset));
92
93 MathematicalVariable setupStart =
95 context,
97 plantId,
98 workCenter.Id,
99 routing.Id,
100 routing.ItemId,
101 ordered[index],
102 fixedFrom,
103 reset));
104
106 context,
107 $"glspProductionStartUpDefinition_r{routing.Id}_t{ordered[index].MacroPeriod}_s{ordered[index].MicroPeriodIndex}",
109 .Add(startUp)
110 .Subtract(setupStart)
111 .Build(),
113 0.0);
114 }
115 }
116
117 return ValueTask.CompletedTask;
118 }
119}
Provides a fluent builder for linear expressions.
Provides the shared state required while constructing a solver-independent mathematical model.
static string CreateMicroSetupStartKey(int plantId, int workCenterId, int routingId, int itemId, ProductionMicroPeriodReference microPeriod, int fixedPredecessorItemId, bool resetBoundary)
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)
Synchronizes the distinct GLSP start-up variable with the exact micro-period setup-start event.
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.
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.
Represents one decision variable in a mathematical optimization model.
MathematicalConstraintSense
Identifies the relational sense of a mathematical constraint.