LotSizingDataModel.Solver 2.0.1
Solver-independent modeling, execution, monitoring and adapter infrastructure.
Loading...
Searching...
No Matches
ProductionSetupLinkConstraintFamilyBuilder.cs
Go to the documentation of this file.
1using System;
2using System.Threading;
3using System.Threading.Tasks;
4using LotSizingDataModel.Core.Relationships;
5using LotSizingDataModel.Instance;
9
11
12/// <summary>
13/// Links production quantities to binary setup variables.
14/// </summary>
17{
18 private readonly IProductionSetupBigMEstimator
19 _bigMEstimator;
20
21 /// <summary>
22 /// Initializes the constraint-family builder with the default
23 /// generic Big-M estimator.
24 /// </summary>
29
30 /// <summary>
31 /// Initializes the constraint-family builder with an explicit
32 /// Big-M estimator.
33 /// </summary>
34 /// <param name="bigMEstimator">
35 /// Production/setup Big-M estimator.
36 /// </param>
39 {
40 ArgumentNullException.ThrowIfNull(bigMEstimator);
41 _bigMEstimator = bigMEstimator;
42 }
43
44 /// <summary>Gets the family identifier.</summary>
45 public override string ConstraintFamilyId =>
46 "productionSetupLink";
47
48 /// <summary>Determines whether the family is enabled.</summary>
49 public override bool IsEnabled(
50 LotSizingInstance instance,
52 {
53 ArgumentNullException.ThrowIfNull(instance);
54 ArgumentNullException.ThrowIfNull(options);
55
56 return options.IncludeProductionSetups &&
57 instance.SupplyChain.ProductionRoutings.Count > 0;
58 }
59
60 /// <summary>Builds production/setup linking constraints.</summary>
61 protected override ValueTask BuildConstraintsAsync(
62 LotSizingInstance instance,
65 CancellationToken cancellationToken)
66 {
67 foreach (
68 ProductionRouting routing
69 in instance.SupplyChain.ProductionRoutings)
70 {
71 for (int period = 1;
72 period <= instance.PlanningHorizon;
73 period++)
74 {
75 cancellationToken.ThrowIfCancellationRequested();
76
77 MathematicalVariable production =
78 context.GetVariable(
80 .CreateProductionKey(
81 routing.Id,
82 period));
83
85 context.GetVariable(
88 .Add(
90 routing.Id)
91 .Add(
93 period)
94 .Build());
95
97 _bigMEstimator.Estimate(
98 instance,
99 routing,
100 period,
101 options);
102
103 var expression =
105 .Add(production)
106 .Subtract(setup, estimate.Value);
107
109 context,
110 $"productionSetupLink_r{routing.Id}_t{period}",
111 expression.Build(),
112 MathematicalConstraintSense.LessThanOrEqual,
113 0.0,
114 description:
115 "Positive production requires an active " +
116 $"setup. Big-M={estimate.Value:G17}. " +
117 estimate.Source);
118 }
119 }
120
121 return ValueTask.CompletedTask;
122 }
123}
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.
Creates canonical variable domain keys used by the standard formulation constraint builders.
Provides common validation and helper methods for one constraint family of the standard lot-sizing fo...
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 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.
Estimates a valid finite upper bound for one production quantity used in a production/setup linking c...
MathematicalConstraintSense
Identifies the relational sense of a mathematical constraint.