LotSizingDataModel.Solver 2.0.1
Solver-independent modeling, execution, monitoring and adapter infrastructure.
Loading...
Searching...
No Matches
WarehouseActivationVariableFamilyBuilder.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 warehouse activation variables.
13/// </summary>
16{
17 /// <summary>
18 /// Gets the warehouse activation variable-family identifier.
19 /// </summary>
20 public override string FamilyId =>
22
23 /// <summary>
24 /// Determines whether warehouse activation variables are
25 /// enabled.
26 /// </summary>
27 public override bool IsEnabled(
28 LotSizingInstance instance,
30 {
31 ArgumentNullException.ThrowIfNull(
32 instance);
33
34 ArgumentNullException.ThrowIfNull(
35 options);
36
37 return
38 options.IncludeResourceActivation &&
41 instance.SupplyChain)
42 .Any(
43 entry =>
44 entry.Warehouse.FixedUsageCost is not null);
45 }
46
47 /// <summary>
48 /// Builds binary warehouse activation variables.
49 /// </summary>
50 protected override ValueTask BuildFamilyAsync(
51 LotSizingInstance instance,
54 CancellationToken cancellationToken)
55 {
56 foreach (
57 var entry
59 .EnumerateWarehouses(
60 instance.SupplyChain))
61 {
62 if (entry.Warehouse.FixedUsageCost is null)
63 {
64 continue;
65 }
66
67 for (
68 int period = 1;
69 period <= instance.PlanningHorizon;
70 period++)
71 {
72 cancellationToken.ThrowIfCancellationRequested();
73
74 var keyBuilder =
77 .WarehouseActivation);
78
80 keyBuilder,
81 entry.Reference);
82
83 string domainKey =
84 keyBuilder
85 .Add(
87 period)
88 .Build();
89
91 context,
92 $"YH_w{entry.Reference.ReferenceId}_t{period}",
93 domainKey,
94 $"Activation of warehouse " +
95 $"{entry.Reference.ReferenceId} in period " +
96 $"{period}.");
97 }
98 }
99
100 return ValueTask.CompletedTask;
101 }
102}
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 domain-key fragments shared by standard formulation builders and provides warehouse...
static MathematicalDomainKeyBuilder AddWarehouse(MathematicalDomainKeyBuilder builder, WarehouseReference warehouse)
Adds a warehouse reference using the generic warehouse or plant segment.
Enumerates physical resources together with the canonical references required by the mathematical for...
static IEnumerable<(WarehouseReference Reference, Warehouse Warehouse)> EnumerateWarehouses(SupplyChain supplyChain)
Enumerates every standalone and plant warehouse.
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 ValueTask BuildFamilyAsync(LotSizingInstance instance, MathematicalModelBuildContext context, StandardLotSizingFormulationOptions options, CancellationToken cancellationToken)
Builds binary warehouse activation variables.
override string FamilyId
Gets the warehouse activation variable-family identifier.
override bool IsEnabled(LotSizingInstance instance, StandardLotSizingFormulationOptions options)
Determines whether warehouse activation variables are enabled.
Provides the canonical mathematical domain-key categories used to identify lot-sizing decision famili...
const string WarehouseActivation
Identifies warehouse activation decision variables.
Provides the canonical mathematical domain-key segment names used by lot-sizing variables and constra...