LotSizingDataModel.Solver 2.0.1
Solver-independent modeling, execution, monitoring and adapter infrastructure.
Loading...
Searching...
No Matches
InventorySafetyStockViolationVariableFamilyBuilder.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 soft safety-stock violation variables.
14/// </summary>
17{
18 /// <summary>
19 /// Gets the safety-stock violation variable-family
20 /// identifier.
21 /// </summary>
22 public override string FamilyId =>
24
25 /// <summary>
26 /// Determines whether safety-stock violation variables are
27 /// enabled.
28 /// </summary>
29 public override bool IsEnabled(
30 LotSizingInstance instance,
32 {
33 ArgumentNullException.ThrowIfNull(
34 instance);
35
36 ArgumentNullException.ThrowIfNull(
37 options);
38
39 return
40 options.IncludeSafetyStock &&
41 options.IncludeSafetyStockViolation &&
42 instance.SupplyChain.Inventories.Any(
43 inventory =>
44 inventory.SafetyStock is not null &&
45 inventory.SafetyStockViolationCost is not null);
46 }
47
48 /// <summary>
49 /// Builds non-negative safety-stock violation variables.
50 /// </summary>
51 protected override ValueTask BuildFamilyAsync(
52 LotSizingInstance instance,
55 CancellationToken cancellationToken)
56 {
57 foreach (
58 Inventory inventory
59 in instance.SupplyChain.Inventories)
60 {
61 if (inventory.SafetyStock is null ||
62 inventory.SafetyStockViolationCost 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 .InventorySafetyStockViolation)
78 .Add(
80 inventory.ItemId);
81
83 keyBuilder,
84 inventory.Warehouse);
85
86 string domainKey =
87 keyBuilder
88 .Add(
90 period)
91 .Build();
92
94 context,
95 $"VSS_i{inventory.ItemId}_w" +
96 $"{inventory.Warehouse.ReferenceId}_t{period}",
97 domainKey,
98 double.PositiveInfinity,
99 $"Safety-stock violation for item " +
100 $"{inventory.ItemId} at warehouse " +
101 $"{inventory.Warehouse.ReferenceId}, " +
102 $"period {period}.");
103 }
104 }
105
106 return ValueTask.CompletedTask;
107 }
108}
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 ValueTask BuildFamilyAsync(LotSizingInstance instance, MathematicalModelBuildContext context, StandardLotSizingFormulationOptions options, CancellationToken cancellationToken)
Builds non-negative safety-stock violation variables.
override bool IsEnabled(LotSizingInstance instance, StandardLotSizingFormulationOptions options)
Determines whether safety-stock violation 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 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 InventorySafetyStockViolation
Identifies safety-stock violation decision variables.
Provides the canonical mathematical domain-key segment names used by lot-sizing variables and constra...