LotSizingDataModel.Solver 2.0.1
Solver-independent modeling, execution, monitoring and adapter infrastructure.
Loading...
Searching...
No Matches
ProcurementVariableFamilyBuilder.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 supplier-procurement quantity variables.
13/// </summary>
16{
17 /// <summary>
18 /// Gets the procurement variable-family identifier.
19 /// </summary>
20 public override string FamilyId =>
22
23 /// <summary>
24 /// Determines whether procurement variables are enabled.
25 /// </summary>
26 public override bool IsEnabled(
27 LotSizingInstance instance,
29 {
30 ArgumentNullException.ThrowIfNull(instance);
31 ArgumentNullException.ThrowIfNull(options);
32
33 return
34 options.IncludeProcurement &&
35 instance.SupplyChain.SupplierDeliveries.Count > 0;
36 }
37
38 /// <summary>
39 /// Builds procurement variables for each supplier delivery
40 /// relationship and period.
41 /// </summary>
42 protected override ValueTask BuildFamilyAsync(
43 LotSizingInstance instance,
46 CancellationToken cancellationToken)
47 {
48 int planningHorizon =
49 instance.PlanningHorizon;
50
51 foreach (
52 SupplierDelivery delivery
53 in instance.SupplyChain.SupplierDeliveries)
54 {
55 cancellationToken.ThrowIfCancellationRequested();
56
57 if (delivery.SupplierId <= 0 ||
58 delivery.ItemId <= 0)
59 {
60 throw new InvalidOperationException(
61 "Supplier deliveries must identify strictly " +
62 "positive supplier and item identifiers.");
63 }
64
65 for (
66 int period = 1;
67 period <= planningHorizon;
68 period++)
69 {
70 cancellationToken.ThrowIfCancellationRequested();
71
72 var keyBuilder =
75 .Add(
77 delivery.SupplierId)
78 .Add(
80 delivery.ItemId);
81
84 keyBuilder,
85 delivery.Warehouse);
86
87 string domainKey =
88 keyBuilder
89 .Add(
91 period)
92 .Build();
93
95 context,
96 $"P_f{delivery.SupplierId}_i{delivery.ItemId}" +
97 $"_w{delivery.Warehouse.ReferenceId}_t{period}",
98 domainKey,
99 double.PositiveInfinity,
100 $"Purchased quantity from supplier " +
101 $"{delivery.SupplierId} for item " +
102 $"{delivery.ItemId} in 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 bool IsEnabled(LotSizingInstance instance, StandardLotSizingFormulationOptions options)
Determines whether procurement variables are enabled.
override string FamilyId
Gets the procurement variable-family identifier.
override ValueTask BuildFamilyAsync(LotSizingInstance instance, MathematicalModelBuildContext context, StandardLotSizingFormulationOptions options, CancellationToken cancellationToken)
Builds procurement variables for each supplier delivery relationship and period.
Creates canonical domain-key fragments shared by standard formulation builders and provides warehouse...
static MathematicalDomainKeyBuilder AddDestinationWarehouse(MathematicalDomainKeyBuilder builder, WarehouseReference warehouse)
Adds a destination warehouse reference.
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 Procurement
Identifies supplier-procurement decision variables.
Provides the canonical mathematical domain-key segment names used by lot-sizing variables and constra...