LotSizingDataModel.Solver 2.0.1
Solver-independent modeling, execution, monitoring and adapter infrastructure.
Loading...
Searching...
No Matches
GlspChangeoverDefinitionConstraintFamilyBuilder.cs
Go to the documentation of this file.
1using LotSizingDataModel.Core.Relationships;
2using LotSizingDataModel.Instance;
7{
8 public override string ConstraintFamilyId=>"glspChangeoverDefinition";
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);
15 if(fixedFrom>0){foreach(var to in routings){if(to.ItemId==fixedFrom)continue;var z=GetVariable(context,GlspFormulationVariableKeyFactory.CreateChangeoverKey(plantId,wc.Id,fixedFrom,to.ItemId,current));var y=GetVariable(context,GlspFormulationVariableKeyFactory.CreateMicroSetupStateKey(plantId,wc.Id,to.Id,to.ItemId,current));AddConstraint(context,$"glspInitialChangeover_i{fixedFrom}_j{to.ItemId}_t{current.MacroPeriod}_s{current.MicroPeriodIndex}",new LinearExpressionBuilder().Add(z).Subtract(y).Build(),MathematicalConstraintSense.Equal,0.0);}continue;}
16 if(i==0||GlspSequenceSemantics.IsResetBoundary(profile,ordered[i-1],current))continue;
17 foreach(var from in routings)foreach(var to in routings)
18 {
19 if(from.ItemId==to.ItemId)continue;var z=GetVariable(context,GlspFormulationVariableKeyFactory.CreateChangeoverKey(plantId,wc.Id,from.ItemId,to.ItemId,current));var yp=GetVariable(context,GlspFormulationVariableKeyFactory.CreateMicroSetupStateKey(plantId,wc.Id,from.Id,from.ItemId,ordered[i-1]));var yc=GetVariable(context,GlspFormulationVariableKeyFactory.CreateMicroSetupStateKey(plantId,wc.Id,to.Id,to.ItemId,current));string suffix=$"_i{from.ItemId}_j{to.ItemId}_t{current.MacroPeriod}_s{current.MicroPeriodIndex}";
20 AddConstraint(context,"glspChangeoverLower"+suffix,new LinearExpressionBuilder().Add(z).Subtract(yp).Subtract(yc).Build(),MathematicalConstraintSense.GreaterThanOrEqual,-1.0);
21 AddConstraint(context,"glspChangeoverUpperPrevious"+suffix,new LinearExpressionBuilder().Add(z).Subtract(yp).Build(),MathematicalConstraintSense.LessThanOrEqual,0.0);
22 AddConstraint(context,"glspChangeoverUpperCurrent"+suffix,new LinearExpressionBuilder().Add(z).Subtract(yc).Build(),MathematicalConstraintSense.LessThanOrEqual,0.0);
23 }
24 }
25 return ValueTask.CompletedTask;
26 }
27}
Provides a fluent builder for linear expressions.
Provides the shared state required while constructing a solver-independent mathematical model.
override ValueTask BuildConstraintsAsync(LotSizingInstance instance, MathematicalModelBuildContext context, StandardLotSizingFormulationOptions options, CancellationToken cancellationToken)
static string CreateChangeoverKey(int plantId, int workCenterId, int fromItemId, int toItemId, ProductionMicroPeriodReference microPeriod)
static string CreateMicroSetupStateKey(int plantId, int workCenterId, int routingId, int itemId, ProductionMicroPeriodReference microPeriod)
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)
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.