LotSizingDataModel.Solver 2.0.1
Solver-independent modeling, execution, monitoring and adapter infrastructure.
Loading...
Searching...
No Matches
GlspSetupStartDefinitionConstraintFamilyBuilder.cs
Go to the documentation of this file.
1using LotSizingDataModel.Core.Relationships;
2using LotSizingDataModel.Instance;
7{
8 public override string ConstraintFamilyId=>"glspSetupStartDefinition";
9 protected override ValueTask BuildConstraintsAsync(LotSizingInstance instance,MathematicalModelBuildContext context,StandardLotSizingFormulationOptions options,CancellationToken cancellationToken)
10 {
11 var (plantId,wc,profile)=GlspSchedulingData.GetSchedulingWorkCenter(instance);IReadOnlyList<ProductionRouting> routings=GlspSchedulingData.GetRoutings(instance,plantId,wc.Id);var ordered=profile.EnumerateMicroPeriods().ToArray();
12 for(int i=0;i<ordered.Length;i++)
13 {
14 var current=ordered[i];int fixedFrom=GlspSequenceSemantics.GetFixedPredecessorItemId(profile,i);bool reset=i>0&&GlspSequenceSemantics.IsResetBoundary(profile,ordered[i-1],current);
15 foreach(var routing in routings)
16 {
17 var y=GetVariable(context,GlspFormulationVariableKeyFactory.CreateMicroSetupStateKey(plantId,wc.Id,routing.Id,routing.ItemId,current));var u=GetVariable(context,GlspFormulationVariableKeyFactory.CreateMicroSetupStartKey(plantId,wc.Id,routing.Id,routing.ItemId,current,fixedFrom,reset));string suffix=$"_r{routing.Id}_t{current.MacroPeriod}_s{current.MicroPeriodIndex}";
18 if(fixedFrom>0){if(fixedFrom==routing.ItemId)AddConstraint(context,"glspSetupStartInitialSame"+suffix,new LinearExpressionBuilder().Add(u).Build(),MathematicalConstraintSense.Equal,0.0);else AddConstraint(context,"glspSetupStartInitial"+suffix,new LinearExpressionBuilder().Add(u).Subtract(y).Build(),MathematicalConstraintSense.Equal,0.0);continue;}
19 if(i==0||reset){AddConstraint(context,"glspSetupStartReset"+suffix,new LinearExpressionBuilder().Add(u).Subtract(y).Build(),MathematicalConstraintSense.Equal,0.0);continue;}
20 var prev=GetVariable(context,GlspFormulationVariableKeyFactory.CreateMicroSetupStateKey(plantId,wc.Id,routing.Id,routing.ItemId,ordered[i-1]));
21 AddConstraint(context,"glspSetupStartLower"+suffix,new LinearExpressionBuilder().Add(u).Subtract(y).Add(prev).Build(),MathematicalConstraintSense.GreaterThanOrEqual,0.0);
22 AddConstraint(context,"glspSetupStartUpperCurrent"+suffix,new LinearExpressionBuilder().Add(u).Subtract(y).Build(),MathematicalConstraintSense.LessThanOrEqual,0.0);
23 AddConstraint(context,"glspSetupStartUpperPrevious"+suffix,new LinearExpressionBuilder().Add(u).Add(prev).Build(),MathematicalConstraintSense.LessThanOrEqual,1.0);
24 }
25 }
26 return ValueTask.CompletedTask;
27 }
28}
Provides a fluent builder for linear expressions.
Provides the shared state required while constructing a solver-independent mathematical model.
static string CreateMicroSetupStateKey(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)
static int WorkCenter ProductionSchedulingProfile Profile GetSchedulingWorkCenter(LotSizingInstance instance)
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)
override ValueTask BuildConstraintsAsync(LotSizingInstance instance, MathematicalModelBuildContext context, StandardLotSizingFormulationOptions options, CancellationToken cancellationToken)
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.
MathematicalConstraintSense
Identifies the relational sense of a mathematical constraint.