LotSizingDataModel.Solver 2.0.1
Solver-independent modeling, execution, monitoring and adapter infrastructure.
Loading...
Searching...
No Matches
SmallBucketProductionStateConstraintFamilyBuilder.cs
Go to the documentation of this file.
1using LotSizingDataModel.Core.Relationships;
2using LotSizingDataModel.Instance;
6
8
10{
11 private readonly SmallBucketSchedulingFormulationKind _kind;
13 public override string ConstraintFamilyId => _kind switch
14 {
15 SmallBucketSchedulingFormulationKind.Dlsp=>"dlspProductionState",
16 SmallBucketSchedulingFormulationKind.Cslp=>"cslpProductionState",
17 SmallBucketSchedulingFormulationKind.Plsp=>"plspProductionState",
18 _=>throw new InvalidOperationException("Unknown small-bucket formulation kind.")
19 };
20 protected override ValueTask BuildConstraintsAsync(LotSizingInstance instance,MathematicalModelBuildContext context,StandardLotSizingFormulationOptions options,CancellationToken cancellationToken)
21 {
22 var wc=instance.SupplyChain.WorkCenters.Single(w=>w.SchedulingProfile is not null);
23 var profile=wc.SchedulingProfile!;
24 foreach(ProductionRouting routing in instance.SupplyChain.ProductionRoutings)
25 {
26 var reference=routing.WorkCenters.Single();
27 ProductionCharacteristic characteristic=instance.SupplyChain.ProductionCharacteristics.Single(candidate=>candidate.ItemId==routing.ItemId && candidate.WorkCenter.PlantId==reference.PlantId && candidate.WorkCenter.WorkCenterId==reference.WorkCenterId);
28 for(int period=1;period<=instance.PlanningHorizon;period++)
29 {
30 double regular=wc.CapacityConstraint![period];
31 double maxAdditional=wc.AdditionalCapacity?[period]??0.0;
32 double consumption=characteristic.UnitCapacityConsumption![period];
33 MathematicalVariable production=GetVariable(context,ProductionKey(routing.Id,period));
34 MathematicalVariable setup=GetVariable(context,SetupKey(routing.Id,period));
35 MathematicalVariable active=GetVariable(context,ActivationKey(routing.Id,period));
37 {
38 AddConstraint(context,$"dlspProductionFullBucket_r{routing.Id}_t{period}",new LinearExpressionBuilder().Add(production,consumption).Subtract(active,regular).Build(),MathematicalConstraintSense.Equal,0.0);
39 AddConstraint(context,$"dlspProductionRequiresSetup_r{routing.Id}_t{period}",new LinearExpressionBuilder().Add(active).Subtract(setup).Build(),MathematicalConstraintSense.LessThanOrEqual,0.0);
40 continue;
41 }
42 AddConstraint(context,$"{Prefix()}ProductionActivation_r{routing.Id}_t{period}",new LinearExpressionBuilder().Add(production,consumption).Subtract(active,regular+maxAdditional).Build(),MathematicalConstraintSense.LessThanOrEqual,0.0);
43 var state=new LinearExpressionBuilder().Add(active).Subtract(setup); double rhs=0.0;
45 {
46 if(period>1) state.Subtract(GetVariable(context,SetupKey(routing.Id,period-1)));
47 else if(profile.HasInitialSetupState && profile.InitialSetupItemId==routing.ItemId) rhs=1.0;
48 }
49 AddConstraint(context,$"{Prefix()}ProductionState_r{routing.Id}_t{period}",state.Build(),MathematicalConstraintSense.LessThanOrEqual,rhs);
50 }
51 }
52 return ValueTask.CompletedTask;
53 }
54 private string Prefix()=>_kind==SmallBucketSchedulingFormulationKind.Plsp?"plsp":"cslp";
58}
Provides a fluent builder for linear expressions.
LinearExpressionBuilder Subtract(MathematicalVariable variable, double coefficient=1.0)
Subtracts a variable term from the expression.
LinearExpressionBuilder Add(MathematicalVariable variable, double coefficient=1.0)
Adds a variable term to the expression.
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)
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 Production
Identifies production-quantity decision variables.
const string AuxiliarySmallBucketProductionActivation
Mathematical-only DLSP full-bucket production activation.
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.
SmallBucketSchedulingFormulationKind
Executable small-bucket scheduling formulation variants.
MathematicalConstraintSense
Identifies the relational sense of a mathematical constraint.