LotSizingDataModel.Solver 2.0.1
Solver-independent modeling, execution, monitoring and adapter infrastructure.
Loading...
Searching...
No Matches
ProductionVariableFamilyBuilder.cs
Go to the documentation of this file.
1using System;
2using System.Threading;
3using System.Threading.Tasks;
4using LotSizingDataModel.Core.Relationships;
5using LotSizingDataModel.Instance;
8
10
11/// <summary>
12/// Builds the production-quantity variable family of the
13/// standard lot-sizing formulation.
14/// </summary>
15/// <remarks>
16/// One non-negative continuous production variable is created
17/// for every production routing and planning period.
18/// The canonical domain key is:
19/// <code>
20/// production|routing=&lt;routingId&gt;|period=&lt;period&gt;
21/// </code>
22/// Period numbers are one-based.
23/// </remarks>
26{
27 /// <summary>
28 /// Gets the unique identifier of the production variable
29 /// family.
30 /// </summary>
31 public override string FamilyId =>
33
34 /// <summary>
35 /// Determines whether production variables are required for
36 /// the supplied instance.
37 /// </summary>
38 /// <param name="instance">
39 /// Source lot-sizing instance.
40 /// </param>
41 /// <param name="options">
42 /// Standard formulation options.
43 /// </param>
44 /// <returns>
45 /// <see langword="true"/> when at least one production
46 /// routing exists; otherwise, <see langword="false"/>.
47 /// </returns>
48 public override bool IsEnabled(
49 LotSizingInstance instance,
51 {
52 ArgumentNullException.ThrowIfNull(
53 instance);
54
55 ArgumentNullException.ThrowIfNull(
56 options);
57
58 return
59 instance.SupplyChain.ProductionRoutings.Count > 0;
60 }
61
62 /// <summary>
63 /// Builds the production-quantity variables.
64 /// </summary>
65 /// <param name="instance">
66 /// Source lot-sizing instance.
67 /// </param>
68 /// <param name="context">
69 /// Mathematical-model build context.
70 /// </param>
71 /// <param name="options">
72 /// Standard formulation options.
73 /// </param>
74 /// <param name="cancellationToken">
75 /// Token used to cancel variable construction.
76 /// </param>
77 /// <returns>
78 /// Task representing production-variable construction.
79 /// </returns>
80 protected override ValueTask BuildFamilyAsync(
81 LotSizingInstance instance,
84 CancellationToken cancellationToken)
85 {
86 int planningHorizon =
87 instance.PlanningHorizon;
88
89 if (planningHorizon <= 0)
90 {
91 throw new InvalidOperationException(
92 "Production variables cannot be built for an " +
93 "instance with a non-positive planning horizon.");
94 }
95
96 foreach (
97 ProductionRouting routing
98 in instance.SupplyChain.ProductionRoutings)
99 {
100 cancellationToken.ThrowIfCancellationRequested();
101
102 if (routing.Id <= 0)
103 {
104 throw new InvalidOperationException(
105 "Every production routing must have a " +
106 "strictly positive identifier before the " +
107 "mathematical formulation is built.");
108 }
109
110 for (
111 int period = 1;
112 period <= planningHorizon;
113 period++)
114 {
115 cancellationToken.ThrowIfCancellationRequested();
116
117 string domainKey =
120 .Add(
122 routing.Id)
123 .Add(
125 period)
126 .Build();
127
128 string variableName =
129 $"x_r{routing.Id}_t{period}";
130
132 context,
133 variableName,
134 domainKey,
135 double.PositiveInfinity,
136 $"Production quantity for routing " +
137 $"{routing.Id} in period {period}.");
138 }
139 }
140
141 return ValueTask.CompletedTask;
142 }
143}
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.
Builds the production-quantity variable family of the standard lot-sizing formulation.
override string FamilyId
Gets the unique identifier of the production variable family.
override ValueTask BuildFamilyAsync(LotSizingInstance instance, MathematicalModelBuildContext context, StandardLotSizingFormulationOptions options, CancellationToken cancellationToken)
Builds the production-quantity variables.
override bool IsEnabled(LotSizingInstance instance, StandardLotSizingFormulationOptions options)
Determines whether production variables are required for the supplied instance.
Configures the standard solver-independent mixed-integer lot-sizing formulation.
Provides common validation and variable-registration helpers for one variable family of the standard ...
static MathematicalVariable AddNonNegativeContinuousVariable(MathematicalModelBuildContext context, string name, string domainKey, double upperBound=double.PositiveInfinity, string description="")
Creates and registers one continuous non-negative variable.
Provides the canonical mathematical domain-key categories used to identify lot-sizing decision famili...
const string Production
Identifies production-quantity decision variables.
Provides the canonical mathematical domain-key segment names used by lot-sizing variables and constra...