LotSizingDataModel.Solver 2.0.1
Solver-independent modeling, execution, monitoring and adapter infrastructure.
Loading...
Searching...
No Matches
ProductionSetupCostObjectiveTermBuilder.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 fixed production setup 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 "productionSetupCost";
23
24 /// <summary>
25 /// Determines whether production setup costs are enabled.
26 /// </summary>
27 public override bool IsEnabled(
28 LotSizingInstance instance,
30 {
31 ArgumentNullException.ThrowIfNull(instance);
32 ArgumentNullException.ThrowIfNull(options);
33
34 return options.IncludeProductionSetups;
35 }
36
37 /// <summary>
38 /// Builds fixed production setup-cost terms.
39 /// </summary>
40 protected override ValueTask BuildTermsAsync(
41 LotSizingInstance instance,
43 LinearExpressionBuilder expressionBuilder,
45 CancellationToken cancellationToken)
46 {
47 var queries =
48 new SupplyChainQueries(
49 instance.SupplyChain);
50
51 foreach (
52 ProductionRouting routing
53 in instance.SupplyChain.ProductionRoutings)
54 {
55 for (
56 int period = 1;
57 period <= instance.PlanningHorizon;
58 period++)
59 {
60 cancellationToken.ThrowIfCancellationRequested();
61
62 double coefficient =
63 0.0;
64
65 foreach (
66 var workCenter
67 in routing.WorkCenters)
68 {
69 ProductionCharacteristic characteristic =
70 queries.GetRequiredProductionCharacteristic(
71 routing.ItemId,
72 workCenter);
73
74 coefficient +=
75 characteristic.FixedSetupCost?[period] ??
76 0.0;
77 }
78
79 string domainKey =
82 .Add(
84 routing.Id)
85 .Add(
87 period)
88 .Build();
89
91 context,
92 expressionBuilder,
93 domainKey,
94 coefficient);
95 }
96 }
97
98 return ValueTask.CompletedTask;
99 }
100}
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 fixed production setup-cost terms.
override bool IsEnabled(LotSizingInstance instance, StandardLotSizingFormulationOptions options)
Determines whether production setup costs are enabled.
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 Setup
Identifies production setup decision variables.
Provides the canonical mathematical domain-key segment names used by lot-sizing variables and constra...