LotSizingDataModel.Solver 2.0.1
Solver-independent modeling, execution, monitoring and adapter infrastructure.
Loading...
Searching...
No Matches
ProcurementCostObjectiveTermBuilder.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 supplier purchase 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 "procurementCost";
22
23 /// <summary>
24 /// Determines whether procurement 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.IncludeProcurement;
34 }
35
36 /// <summary>
37 /// Builds supplier purchase-cost terms.
38 /// </summary>
39 protected override ValueTask BuildTermsAsync(
40 LotSizingInstance instance,
42 LinearExpressionBuilder expressionBuilder,
44 CancellationToken cancellationToken)
45 {
46 foreach (
47 SupplierDelivery delivery
48 in instance.SupplyChain.SupplierDeliveries)
49 {
50 for (
51 int period = 1;
52 period <= instance.PlanningHorizon;
53 period++)
54 {
55 cancellationToken.ThrowIfCancellationRequested();
56
57 var keyBuilder =
60 .Add(
62 delivery.SupplierId)
63 .Add(
65 delivery.ItemId);
66
68 keyBuilder,
69 delivery.Warehouse);
70
72 context,
73 expressionBuilder,
74 keyBuilder
75 .Add(
77 period)
78 .Build(),
79 delivery.PurchasePrice?[period] ??
80 0.0);
81 }
82 }
83
84 return ValueTask.CompletedTask;
85 }
86}
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 bool IsEnabled(LotSizingInstance instance, StandardLotSizingFormulationOptions options)
Determines whether procurement costs are enabled.
override ValueTask BuildTermsAsync(LotSizingInstance instance, MathematicalModelBuildContext context, LinearExpressionBuilder expressionBuilder, StandardLotSizingFormulationOptions options, CancellationToken cancellationToken)
Builds supplier purchase-cost terms.
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 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 Procurement
Identifies supplier-procurement decision variables.
Provides the canonical mathematical domain-key segment names used by lot-sizing variables and constra...