LotSizingDataModel.Solver 2.0.1
Solver-independent modeling, execution, monitoring and adapter infrastructure.
Loading...
Searching...
No Matches
WarehouseActivationLinkConstraintFamilyBuilder.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 aggregate warehouse inventory load to binary warehouse activation.
14/// </summary>
17{
18 /// <summary>Gets the family identifier.</summary>
19 public override string ConstraintFamilyId => "warehouseActivationLink";
20
21 /// <summary>Determines whether the family is enabled.</summary>
22 public override bool IsEnabled(
23 LotSizingInstance instance,
25 {
26 ArgumentNullException.ThrowIfNull(instance);
27 ArgumentNullException.ThrowIfNull(options);
28
29 if (!options.IncludeResourceActivation)
30 {
31 return false;
32 }
33
34 foreach (var entry in StandardFormulationResourceEnumerator
35 .EnumerateWarehouses(instance.SupplyChain))
36 {
37 if (entry.Warehouse.FixedUsageCost is not null &&
38 entry.Warehouse.CapacityConstraint is not null)
39 {
40 return true;
41 }
42 }
43
44 return false;
45 }
46
47 /// <summary>Builds warehouse activation-link constraints.</summary>
48 protected override ValueTask BuildConstraintsAsync(
49 LotSizingInstance instance,
52 CancellationToken cancellationToken)
53 {
54 foreach (var entry in StandardFormulationResourceEnumerator
55 .EnumerateWarehouses(instance.SupplyChain))
56 {
57 if (entry.Warehouse.FixedUsageCost is null ||
58 entry.Warehouse.CapacityConstraint is null)
59 {
60 continue;
61 }
62
63 for (int period = 1; period <= instance.PlanningHorizon; period++)
64 {
65 cancellationToken.ThrowIfCancellationRequested();
66
67 var expression = new LinearExpressionBuilder();
68
69 foreach (Inventory inventory in instance.SupplyChain.Inventories)
70 {
72 inventory.Warehouse,
73 entry.Reference))
74 {
75 continue;
76 }
77
78 expression.Add(
79 context.GetVariable(
83 inventory.ItemId,
84 inventory.Warehouse,
85 period)),
86 inventory.UnitCapacityConsumption?[period] ?? 1.0);
87 }
88
89 var activationKeyBuilder =
92
94 activationKeyBuilder,
95 entry.Reference);
96
97 string activationKey =
98 activationKeyBuilder
100 .Build();
101
102 expression.Subtract(
103 context.GetVariable(activationKey),
104 entry.Warehouse.CapacityConstraint[period]);
105
107 context,
108 $"warehouseActivationLink_w" +
109 $"{entry.Reference.ReferenceId}_t{period}",
110 expression.Build(),
111 MathematicalConstraintSense.LessThanOrEqual,
112 0.0,
113 description:
114 "Warehouse inventory load requires activation.");
115 }
116 }
117
118 return ValueTask.CompletedTask;
119 }
120}
Provides a fluent builder for linear expressions.
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 bool AreSameWarehouse(WarehouseReference left, WarehouseReference right)
Determines whether two warehouse references identify the same physical 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...
Creates canonical variable domain keys used by the standard formulation constraint builders.
static string CreateInventoryKey(string category, int itemId, WarehouseReference warehouse, int period)
Creates an inventory-like key for an item, warehouse, period, and decision category.
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.
bool IncludeResourceActivation
Gets or sets whether resource activations are included.
Provides the canonical mathematical domain-key categories used to identify lot-sizing decision famili...
const string WarehouseActivation
Identifies warehouse activation decision variables.
const string Inventory
Identifies inventory-level decision variables.
Provides the canonical mathematical domain-key segment names used by lot-sizing variables and constra...
MathematicalConstraintSense
Identifies the relational sense of a mathematical constraint.