LotSizingDataModel.Solver 2.0.1
Solver-independent modeling, execution, monitoring and adapter infrastructure.
Loading...
Searching...
No Matches
InventoryVariableFamilyBuilder.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 inventory-level variables for every configured
13/// item-warehouse inventory relationship.
14/// </summary>
15public sealed class InventoryVariableFamilyBuilder :
17{
18 /// <summary>
19 /// Gets the inventory variable-family identifier.
20 /// </summary>
21 public override string FamilyId =>
23
24 /// <summary>
25 /// Determines whether inventory variables are required.
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 instance.SupplyChain.Inventories.Count > 0;
38 }
39
40 /// <summary>
41 /// Builds inventory-level variables.
42 /// </summary>
43 protected override ValueTask BuildFamilyAsync(
44 LotSizingInstance instance,
47 CancellationToken cancellationToken)
48 {
49 int planningHorizon =
50 instance.PlanningHorizon;
51
52 foreach (
53 Inventory inventory
54 in instance.SupplyChain.Inventories)
55 {
56 cancellationToken.ThrowIfCancellationRequested();
57
58 if (inventory.ItemId <= 0)
59 {
60 throw new InvalidOperationException(
61 "Every inventory relationship must identify " +
62 "a strictly positive item identifier.");
63 }
64
65 for (
66 int period = 1;
67 period <= planningHorizon;
68 period++)
69 {
70 cancellationToken.ThrowIfCancellationRequested();
71
72 var keyBuilder =
75 .Add(
77 inventory.ItemId);
78
80 keyBuilder,
81 inventory.Warehouse);
82
83 string domainKey =
84 keyBuilder
85 .Add(
87 period)
88 .Build();
89
91 context,
92 $"I_i{inventory.ItemId}_w" +
93 $"{inventory.Warehouse.ReferenceId}_t{period}",
94 domainKey,
95 double.PositiveInfinity,
96 $"Inventory level for item {inventory.ItemId} " +
97 $"at warehouse {inventory.Warehouse.ReferenceId} " +
98 $"in period {period}.");
99 }
100 }
101
102 return ValueTask.CompletedTask;
103 }
104}
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 inventory-level variables for every configured item-warehouse inventory relationship.
override string FamilyId
Gets the inventory variable-family identifier.
override bool IsEnabled(LotSizingInstance instance, StandardLotSizingFormulationOptions options)
Determines whether inventory variables are required.
override ValueTask BuildFamilyAsync(LotSizingInstance instance, MathematicalModelBuildContext context, StandardLotSizingFormulationOptions options, CancellationToken cancellationToken)
Builds inventory-level variables.
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.
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 Inventory
Identifies inventory-level decision variables.
Provides the canonical mathematical domain-key segment names used by lot-sizing variables and constra...