LotSizingDataModel.Solver 2.0.1
Solver-independent modeling, execution, monitoring and adapter infrastructure.
Loading...
Searching...
No Matches
SetupVariableFamilyBuilder.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-setup variable family of the standard
13/// lot-sizing formulation.
14/// </summary>
15/// <remarks>
16/// One binary setup variable is created for every production
17/// routing and planning period when production setups are
18/// enabled.
19/// The canonical domain key is:
20/// <code>
21/// setup|routing=&lt;routingId&gt;|period=&lt;period&gt;
22/// </code>
23/// Period numbers are one-based.
24/// </remarks>
25public sealed class SetupVariableFamilyBuilder :
27{
28 /// <summary>
29 /// Gets the unique identifier of the production-setup
30 /// variable family.
31 /// </summary>
32 public override string FamilyId =>
34
35 /// <summary>
36 /// Determines whether production-setup variables are enabled
37 /// for the supplied instance.
38 /// </summary>
39 /// <param name="instance">
40 /// Source lot-sizing instance.
41 /// </param>
42 /// <param name="options">
43 /// Standard formulation options.
44 /// </param>
45 /// <returns>
46 /// <see langword="true"/> when production setups are enabled
47 /// and at least one production routing exists; otherwise,
48 /// <see langword="false"/>.
49 /// </returns>
50 public override bool IsEnabled(
51 LotSizingInstance instance,
53 {
54 ArgumentNullException.ThrowIfNull(
55 instance);
56
57 ArgumentNullException.ThrowIfNull(
58 options);
59
60 return
61 options.IncludeProductionSetups &&
62 instance.SupplyChain.ProductionRoutings.Count > 0;
63 }
64
65 /// <summary>
66 /// Builds the production-setup variables.
67 /// </summary>
68 /// <param name="instance">
69 /// Source lot-sizing instance.
70 /// </param>
71 /// <param name="context">
72 /// Mathematical-model build context.
73 /// </param>
74 /// <param name="options">
75 /// Standard formulation options.
76 /// </param>
77 /// <param name="cancellationToken">
78 /// Token used to cancel variable construction.
79 /// </param>
80 /// <returns>
81 /// Task representing setup-variable construction.
82 /// </returns>
83 protected override ValueTask BuildFamilyAsync(
84 LotSizingInstance instance,
87 CancellationToken cancellationToken)
88 {
89 int planningHorizon =
90 instance.PlanningHorizon;
91
92 if (planningHorizon <= 0)
93 {
94 throw new InvalidOperationException(
95 "Production-setup variables cannot be built for " +
96 "an instance with a non-positive planning " +
97 "horizon.");
98 }
99
100 foreach (
101 ProductionRouting routing
102 in instance.SupplyChain.ProductionRoutings)
103 {
104 cancellationToken.ThrowIfCancellationRequested();
105
106 if (routing.Id <= 0)
107 {
108 throw new InvalidOperationException(
109 "Every production routing must have a " +
110 "strictly positive identifier before the " +
111 "mathematical formulation is built.");
112 }
113
114 for (
115 int period = 1;
116 period <= planningHorizon;
117 period++)
118 {
119 cancellationToken.ThrowIfCancellationRequested();
120
121 string domainKey =
124 .Add(
126 routing.Id)
127 .Add(
129 period)
130 .Build();
131
132 string variableName =
133 $"y_r{routing.Id}_t{period}";
134
136 context,
137 variableName,
138 domainKey,
139 $"Production setup activation for routing " +
140 $"{routing.Id} in period {period}.");
141 }
142 }
143
144 return ValueTask.CompletedTask;
145 }
146}
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-setup variable family of the standard lot-sizing formulation.
override ValueTask BuildFamilyAsync(LotSizingInstance instance, MathematicalModelBuildContext context, StandardLotSizingFormulationOptions options, CancellationToken cancellationToken)
Builds the production-setup variables.
override bool IsEnabled(LotSizingInstance instance, StandardLotSizingFormulationOptions options)
Determines whether production-setup variables are enabled for the supplied instance.
override string FamilyId
Gets the unique identifier of the production-setup variable family.
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 AddBinaryVariable(MathematicalModelBuildContext context, string name, string domainKey, string description="")
Creates and registers one binary variable.
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...