LotSizingDataModel.Solver 2.0.1
Solver-independent modeling, execution, monitoring and adapter infrastructure.
Loading...
Searching...
No Matches
InventorySetupVariableFamilyBuilder.cs
Go to the documentation of this file.
1using System;
2using System.Linq;
3using System.Threading;
4using System.Threading.Tasks;
5using LotSizingDataModel.Core.Relationships;
6using LotSizingDataModel.Instance;
9
11
12/// <summary>
13/// Builds item-specific inventory setup variables.
14/// </summary>
17{
18 /// <summary>
19 /// Gets the inventory-setup variable-family identifier.
20 /// </summary>
21 public override string FamilyId =>
23
24 /// <summary>
25 /// Determines whether inventory setup variables are 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 instance.SupplyChain.Inventories.Any(
39 inventory =>
40 inventory.FixedSetupCost is not null ||
41 inventory.SetupTime is not null);
42 }
43
44 /// <summary>
45 /// Builds binary inventory setup variables.
46 /// </summary>
47 protected override ValueTask BuildFamilyAsync(
48 LotSizingInstance instance,
51 CancellationToken cancellationToken)
52 {
53 foreach (
54 Inventory inventory
55 in instance.SupplyChain.Inventories)
56 {
57 if (inventory.FixedSetupCost is null &&
58 inventory.SetupTime is null)
59 {
60 continue;
61 }
62
63 for (
64 int period = 1;
65 period <= instance.PlanningHorizon;
66 period++)
67 {
68 cancellationToken.ThrowIfCancellationRequested();
69
70 var keyBuilder =
73 .Add(
75 inventory.ItemId);
76
78 keyBuilder,
79 inventory.Warehouse);
80
81 string domainKey =
82 keyBuilder
83 .Add(
85 period)
86 .Build();
87
89 context,
90 $"YI_i{inventory.ItemId}_w" +
91 $"{inventory.Warehouse.ReferenceId}_t{period}",
92 domainKey,
93 $"Inventory setup for item {inventory.ItemId} " +
94 $"at warehouse " +
95 $"{inventory.Warehouse.ReferenceId}, " +
96 $"period {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.
override string FamilyId
Gets the inventory-setup variable-family identifier.
override ValueTask BuildFamilyAsync(LotSizingInstance instance, MathematicalModelBuildContext context, StandardLotSizingFormulationOptions options, CancellationToken cancellationToken)
Builds binary inventory setup variables.
override bool IsEnabled(LotSizingInstance instance, StandardLotSizingFormulationOptions options)
Determines whether inventory setup variables are enabled.
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 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 InventorySetup
Identifies inventory setup decision variables.
Provides the canonical mathematical domain-key segment names used by lot-sizing variables and constra...