LotSizingDataModel.Solver 2.0.1
Solver-independent modeling, execution, monitoring and adapter infrastructure.
Loading...
Searching...
No Matches
BacklogVariableFamilyBuilder.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 backlog-level variables for sourcing relationships
13/// that explicitly define backlog constraints.
14/// </summary>
15public sealed class BacklogVariableFamilyBuilder :
17{
18 /// <summary>
19 /// Gets the backlog variable-family identifier.
20 /// </summary>
21 public override string FamilyId =>
23
24 /// <summary>
25 /// Determines whether backlog 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 if (!options.IncludeBacklog)
38 {
39 return false;
40 }
41
42 foreach (
43 DistributionCenterSourcing sourcing
44 in instance.SupplyChain.DistributionCenterSourcings)
45 {
46 if (sourcing.BacklogConstraint is not null)
47 {
48 return true;
49 }
50 }
51
52 return false;
53 }
54
55 /// <summary>
56 /// Builds backlog-level variables.
57 /// </summary>
58 protected override ValueTask BuildFamilyAsync(
59 LotSizingInstance instance,
62 CancellationToken cancellationToken)
63 {
64 int planningHorizon =
65 instance.PlanningHorizon;
66
67 foreach (
68 DistributionCenterSourcing sourcing
69 in instance.SupplyChain.DistributionCenterSourcings)
70 {
71 cancellationToken.ThrowIfCancellationRequested();
72
73 if (sourcing.BacklogConstraint is null)
74 {
75 continue;
76 }
77
78 for (
79 int period = 1;
80 period <= planningHorizon;
81 period++)
82 {
83 double upperBound =
84 sourcing.BacklogConstraint[period];
85
87 upperBound,
88 options))
89 {
90 continue;
91 }
92
93 var keyBuilder =
96 .Add(
98 sourcing.DistributionCenterId)
99 .Add(
101 sourcing.ItemId);
102
104 keyBuilder,
105 sourcing.Warehouse);
106
107 string domainKey =
108 keyBuilder
109 .Add(
111 period)
112 .Build();
113
115 context,
116 $"B_c{sourcing.DistributionCenterId}" +
117 $"_i{sourcing.ItemId}_w" +
118 $"{sourcing.Warehouse.ReferenceId}_t{period}",
119 domainKey,
120 upperBound,
121 $"Backlog level for distribution center " +
122 $"{sourcing.DistributionCenterId}, item " +
123 $"{sourcing.ItemId}, period {period}.");
124 }
125 }
126
127 return ValueTask.CompletedTask;
128 }
129}
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 backlog-level variables for sourcing relationships that explicitly define backlog constraints.
override ValueTask BuildFamilyAsync(LotSizingInstance instance, MathematicalModelBuildContext context, StandardLotSizingFormulationOptions options, CancellationToken cancellationToken)
Builds backlog-level variables.
override string FamilyId
Gets the backlog variable-family identifier.
override bool IsEnabled(LotSizingInstance instance, StandardLotSizingFormulationOptions options)
Determines whether backlog 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 bool IsStructurallyZero(double upperBound, StandardLotSizingFormulationOptions options)
Determines whether a finite non-negative upper bound is structurally equal to zero according to the f...
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 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.