LotSizingDataModel.Solver 2.0.1
Solver-independent modeling, execution, monitoring and adapter infrastructure.
Loading...
Searching...
No Matches
InventorySafetyStockViolationCostObjectiveTermBuilder.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/// Adds safety-stock violation penalties to the standard
13/// objective.
14/// </summary>
17{
18 /// <summary>
19 /// Gets the objective-term family identifier.
20 /// </summary>
21 public override string TermFamilyId =>
22 "inventorySafetyStockViolationCost";
23
24 /// <summary>
25 /// Determines whether safety-stock violation costs are
26 /// enabled.
27 /// </summary>
28 public override bool IsEnabled(
29 LotSizingInstance instance,
31 {
32 ArgumentNullException.ThrowIfNull(instance);
33 ArgumentNullException.ThrowIfNull(options);
34
35 return
36 options.IncludeSafetyStock &&
38 }
39
40 /// <summary>
41 /// Builds safety-stock violation penalty terms.
42 /// </summary>
43 protected override ValueTask BuildTermsAsync(
44 LotSizingInstance instance,
46 LinearExpressionBuilder expressionBuilder,
48 CancellationToken cancellationToken)
49 {
50 foreach (
51 Inventory inventory
52 in instance.SupplyChain.Inventories)
53 {
54 if (inventory.SafetyStock is null ||
55 inventory.SafetyStockViolationCost is null)
56 {
57 continue;
58 }
59
60 for (
61 int period = 1;
62 period <= instance.PlanningHorizon;
63 period++)
64 {
65 cancellationToken.ThrowIfCancellationRequested();
66
67 var keyBuilder =
70 .InventorySafetyStockViolation)
71 .Add(
73 inventory.ItemId);
74
76 keyBuilder,
77 inventory.Warehouse);
78
80 context,
81 expressionBuilder,
82 keyBuilder
83 .Add(
85 period)
86 .Build(),
87 inventory.SafetyStockViolationCost[period]);
88 }
89 }
90
91 return ValueTask.CompletedTask;
92 }
93}
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.
override ValueTask BuildTermsAsync(LotSizingInstance instance, MathematicalModelBuildContext context, LinearExpressionBuilder expressionBuilder, StandardLotSizingFormulationOptions options, CancellationToken cancellationToken)
Builds safety-stock violation penalty terms.
override bool IsEnabled(LotSizingInstance instance, StandardLotSizingFormulationOptions options)
Determines whether safety-stock violation costs 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.
bool IncludeSafetyStockViolation
Gets or sets whether safety-stock violations are allowed.
Provides common validation and helper methods for one objective-term family of the standard lot-sizin...
static void AddCostTerm(MathematicalModelBuildContext context, LinearExpressionBuilder expressionBuilder, string domainKey, double coefficient)
Adds one variable cost term to the shared objective.
Provides the canonical mathematical domain-key categories used to identify lot-sizing decision famili...
Provides the canonical mathematical domain-key segment names used by lot-sizing variables and constra...