LotSizingDataModel.Solver 2.0.1
Solver-independent modeling, execution, monitoring and adapter infrastructure.
Loading...
Searching...
No Matches
GlspProducedItemCountConstraintFamilyBuilder.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=>"glspProducedItemCount";
10 public override bool IsEnabled(LotSizingInstance instance,StandardLotSizingFormulationOptions options){ArgumentNullException.ThrowIfNull(instance);ArgumentNullException.ThrowIfNull(options);return instance.SupplyChain.WorkCenters.Any(w=>w.SchedulingProfile?.MaximumProducedItemCount 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);MaximumProducedItemCount limit=profile.MaximumProducedItemCount??throw new InvalidOperationException("MaximumProducedItemCount required.");var routings=GlspSchedulingData.GetRoutings(instance,plantId,wc.Id);
14 for(int t=1;t<=instance.PlanningHorizon;t++){var count=new LinearExpressionBuilder();foreach(var r in routings){var c=GlspSchedulingData.GetCharacteristic(instance,r,plantId,wc.Id);double m=wc.CapacityConstraint![t]+(wc.AdditionalCapacity?[t]??0.0);var q=GetVariable(context,GlspFormulationVariableKeyFactory.CreateMacroProductionActivationKey(r.Id,t));AddConstraint(context,$"glspMacroProductionActivation_r{r.Id}_t{t}",new LinearExpressionBuilder().Add(GetVariable(context,StandardFormulationVariableKeyFactory.CreateProductionKey(r.Id,t)),c.UnitCapacityConsumption![t]).Subtract(q,m).Build(),MathematicalConstraintSense.LessThanOrEqual,0.0);count.Add(q);}AddConstraint(context,$"glspProducedItemCount_t{t}",count.Build(),MathematicalConstraintSense.LessThanOrEqual,limit.GetCount(t));}
15 return ValueTask.CompletedTask;
16 }
17}
Provides a fluent builder for linear expressions.
LinearExpressionBuilder Subtract(MathematicalVariable variable, double coefficient=1.0)
Subtracts a variable term from the expression.
LinearExpression Build(bool clone=true)
Builds and validates the linear expression.
Provides the shared state required while constructing a solver-independent mathematical model.
MathematicalModel Build(bool clone=true)
Builds and validates the mathematical model.
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)
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)
Creates canonical variable domain keys used by the standard formulation constraint builders.
static string CreateProductionKey(int routingId, int period)
Creates a production decision key.
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.