LotSizingDataModel.Solver 2.0.1
Solver-independent modeling, execution, monitoring and adapter infrastructure.
Loading...
Searching...
No Matches
WorkCenterActivationVariableFamilyBuilder.cs
Go to the documentation of this file.
1using System;
2using System.Linq;
3using System.Threading;
4using System.Threading.Tasks;
5using LotSizingDataModel.Instance;
8
10
11/// <summary>
12/// Builds global work-center activation variables.
13/// </summary>
16{
17 /// <summary>
18 /// Gets the work-center activation variable-family
19 /// identifier.
20 /// </summary>
21 public override string FamilyId =>
23
24 /// <summary>
25 /// Determines whether work-center activation variables are
26 /// enabled.
27 /// </summary>
28 public override bool IsEnabled(
29 LotSizingInstance instance,
31 {
32 ArgumentNullException.ThrowIfNull(
33 instance);
34
35 ArgumentNullException.ThrowIfNull(
36 options);
37
38 return
39 options.IncludeResourceActivation &&
42 instance.SupplyChain)
43 .Any(
44 entry =>
45 entry.WorkCenter.FixedUsageCost is not null);
46 }
47
48 /// <summary>
49 /// Builds binary work-center activation variables.
50 /// </summary>
51 protected override ValueTask BuildFamilyAsync(
52 LotSizingInstance instance,
55 CancellationToken cancellationToken)
56 {
57 foreach (
58 var entry
60 .EnumerateWorkCenters(
61 instance.SupplyChain))
62 {
63 if (entry.WorkCenter.FixedUsageCost is null)
64 {
65 continue;
66 }
67
68 for (
69 int period = 1;
70 period <= instance.PlanningHorizon;
71 period++)
72 {
73 cancellationToken.ThrowIfCancellationRequested();
74
75 string domainKey =
78 .WorkCenterActivation)
79 .Add(
81 entry.PlantId)
82 .Add(
84 entry.WorkCenter.Id)
85 .Add(
87 period)
88 .Build();
89
91 context,
92 $"YW_p{entry.PlantId}_w" +
93 $"{entry.WorkCenter.Id}_t{period}",
94 domainKey,
95 $"Activation of work center " +
96 $"{entry.WorkCenter.Id} in plant " +
97 $"{entry.PlantId}, period {period}.");
98 }
99 }
100
101 return ValueTask.CompletedTask;
102 }
103}
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.
Enumerates physical resources together with the canonical references required by the mathematical for...
static IEnumerable<(int PlantId, WorkCenter WorkCenter)> EnumerateWorkCenters(SupplyChain supplyChain)
Enumerates every work center with its containing plant identifier.
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.
override string FamilyId
Gets the work-center activation variable-family identifier.
override bool IsEnabled(LotSizingInstance instance, StandardLotSizingFormulationOptions options)
Determines whether work-center activation variables are enabled.
override ValueTask BuildFamilyAsync(LotSizingInstance instance, MathematicalModelBuildContext context, StandardLotSizingFormulationOptions options, CancellationToken cancellationToken)
Builds binary work-center activation variables.
Provides the canonical mathematical domain-key categories used to identify lot-sizing decision famili...
const string WorkCenterActivation
Identifies work-center activation decision variables.
Provides the canonical mathematical domain-key segment names used by lot-sizing variables and constra...