LotSizingDataModel.Solver 2.0.1
Solver-independent modeling, execution, monitoring and adapter infrastructure.
Loading...
Searching...
No Matches
ProductionCostObjectiveTermBuilder.cs
Go to the documentation of this file.
1using System;
2using System.Threading;
3using System.Threading.Tasks;
4using LotSizingDataModel.Core.Querying;
5using LotSizingDataModel.Core.Relationships;
6using LotSizingDataModel.Instance;
9
11
12/// <summary>
13/// Adds variable production costs to the standard objective.
14/// </summary>
17{
18 /// <summary>
19 /// Gets the objective-term family identifier.
20 /// </summary>
21 public override string TermFamilyId =>
22 "productionCost";
23
24 /// <summary>
25 /// Builds variable production-cost terms.
26 /// </summary>
27 protected override ValueTask BuildTermsAsync(
28 LotSizingInstance instance,
30 LinearExpressionBuilder expressionBuilder,
32 CancellationToken cancellationToken)
33 {
34 var queries =
35 new SupplyChainQueries(
36 instance.SupplyChain);
37
38 foreach (
39 ProductionRouting routing
40 in instance.SupplyChain.ProductionRoutings)
41 {
42 for (
43 int period = 1;
44 period <= instance.PlanningHorizon;
45 period++)
46 {
47 cancellationToken.ThrowIfCancellationRequested();
48
49 double coefficient =
50 0.0;
51
52 foreach (
53 var workCenter
54 in routing.WorkCenters)
55 {
56 ProductionCharacteristic characteristic =
57 queries.GetRequiredProductionCharacteristic(
58 routing.ItemId,
59 workCenter);
60
61 coefficient +=
62 characteristic.UnitUsageCost?[period] ??
63 0.0;
64 }
65
66 string domainKey =
69 .Add(
71 routing.Id)
72 .Add(
74 period)
75 .Build();
76
78 context,
79 expressionBuilder,
80 domainKey,
81 coefficient);
82 }
83 }
84
85 return ValueTask.CompletedTask;
86 }
87}
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 variable production-cost terms.
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 Production
Identifies production-quantity decision variables.
Provides the canonical mathematical domain-key segment names used by lot-sizing variables and constra...