LotSizingDataModel.Solver 2.0.1
Solver-independent modeling, execution, monitoring and adapter infrastructure.
Loading...
Searching...
No Matches
BacklogCostObjectiveTermBuilder.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 backlog costs to the standard objective.
13/// </summary>
16{
17 /// <summary>
18 /// Gets the objective-term family identifier.
19 /// </summary>
20 public override string TermFamilyId =>
21 "backlogCost";
22
23 /// <summary>
24 /// Determines whether backlog costs are enabled.
25 /// </summary>
26 public override bool IsEnabled(
27 LotSizingInstance instance,
29 {
30 ArgumentNullException.ThrowIfNull(instance);
31 ArgumentNullException.ThrowIfNull(options);
32
33 return options.IncludeBacklog;
34 }
35
36 /// <summary>
37 /// Builds backlog cost terms.
38 /// </summary>
39 protected override ValueTask BuildTermsAsync(
40 LotSizingInstance instance,
42 LinearExpressionBuilder expressionBuilder,
44 CancellationToken cancellationToken)
45 {
46 foreach (
47 DistributionCenterSourcing sourcing
48 in instance.SupplyChain.DistributionCenterSourcings)
49 {
50 if (sourcing.BacklogConstraint is null)
51 {
52 continue;
53 }
54
55 for (
56 int period = 1;
57 period <= instance.PlanningHorizon;
58 period++)
59 {
60 cancellationToken.ThrowIfCancellationRequested();
61
62 double upperBound =
63 sourcing.BacklogConstraint[period];
64
65 if (options.RemoveStructurallyZeroVariables &&
66 double.IsFinite(upperBound) &&
67 upperBound <= options.StructuralZeroTolerance)
68 {
69 continue;
70 }
71
72 var keyBuilder =
75 .Add(
77 sourcing.DistributionCenterId)
78 .Add(
80 sourcing.ItemId);
81
83 keyBuilder,
84 sourcing.Warehouse);
85
87 context,
88 expressionBuilder,
89 keyBuilder
90 .Add(
92 period)
93 .Build(),
94 sourcing.BacklogCost?[period] ??
95 0.0);
96 }
97 }
98
99 return ValueTask.CompletedTask;
100 }
101}
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 string TermFamilyId
Gets the objective-term family identifier.
override bool IsEnabled(LotSizingInstance instance, StandardLotSizingFormulationOptions options)
Determines whether backlog costs are enabled.
override ValueTask BuildTermsAsync(LotSizingInstance instance, MathematicalModelBuildContext context, LinearExpressionBuilder expressionBuilder, StandardLotSizingFormulationOptions options, CancellationToken cancellationToken)
Builds backlog cost terms.
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 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...
const string Backlog
Identifies backlog-level decision variables.
Provides the canonical mathematical domain-key segment names used by lot-sizing variables and constra...
const string DistributionCenter
Distribution-center identifier segment.