LotSizingDataModel.Solver 2.0.1
Solver-independent modeling, execution, monitoring and adapter infrastructure.
Loading...
Searching...
No Matches
GlspSetupCountConstraintFamilyBuilder.cs
Go to the documentation of this file.
1using LotSizingDataModel.Core.DecisionModel.Scheduling;
2using LotSizingDataModel.Core.Relationships;
3using LotSizingDataModel.Instance;
8{
9 public override string ConstraintFamilyId=>"glspMaximumSetupCount";
10 public override bool IsEnabled(LotSizingInstance instance,StandardLotSizingFormulationOptions options){ArgumentNullException.ThrowIfNull(instance);ArgumentNullException.ThrowIfNull(options);return instance.SupplyChain.WorkCenters.Any(w=>w.SchedulingProfile?.MaximumSetupCount is not null);}
11 protected override ValueTask BuildConstraintsAsync(LotSizingInstance instance,MathematicalModelBuildContext context,StandardLotSizingFormulationOptions options,CancellationToken cancellationToken)
12 {
13 var (plantId,wc,profile)=GlspSchedulingData.GetSchedulingWorkCenter(instance);MaximumSetupCount limit=profile.MaximumSetupCount??throw new InvalidOperationException("MaximumSetupCount required.");IReadOnlyList<ProductionRouting> routings=GlspSchedulingData.GetRoutings(instance,plantId,wc.Id);var ordered=profile.EnumerateMicroPeriods().ToArray();
14 for(int t=1;t<=instance.PlanningHorizon;t++){var e=new LinearExpressionBuilder();for(int i=0;i<ordered.Length;i++){if(ordered[i].MacroPeriod!=t)continue;int from=GlspSequenceSemantics.GetFixedPredecessorItemId(profile,i);bool reset=i>0&&GlspSequenceSemantics.IsResetBoundary(profile,ordered[i-1],ordered[i]);foreach(var r in routings)e.Add(GetVariable(context,GlspFormulationVariableKeyFactory.CreateMicroSetupStartKey(plantId,wc.Id,r.Id,r.ItemId,ordered[i],from,reset)));}AddConstraint(context,$"glspMaximumSetupCount_t{t}",e.Build(),MathematicalConstraintSense.LessThanOrEqual,limit.GetCount(t));}
15 return ValueTask.CompletedTask;
16 }
17}
Provides a fluent builder for linear expressions.
Provides the shared state required while constructing a solver-independent mathematical model.
MathematicalModel Build(bool clone=true)
Builds and validates the 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 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 bool IsEnabled(LotSizingInstance instance, StandardLotSizingFormulationOptions options)
Determines whether this constraint family is enabled.
override ValueTask BuildConstraintsAsync(LotSizingInstance instance, MathematicalModelBuildContext context, StandardLotSizingFormulationOptions options, CancellationToken cancellationToken)
override string ConstraintFamilyId
Gets the unique identifier of the constraint family.
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.