LotSizingDataModel.Solver 2.0.1
Solver-independent modeling, execution, monitoring and adapter infrastructure.
Loading...
Searching...
No Matches
ProductionDecisionMapper.cs
Go to the documentation of this file.
1using System;
2using System.Linq;
3using LotSizingDataModel.Solution;
4using LotSizingDataModel.Solution.Decisions;
6
8
9/// <summary>
10/// Maps mathematical production-variable values to production
11/// decisions in a lot-sizing solution.
12/// </summary>
13/// <remarks>
14/// Production decisions in <see cref="LotSizingSolution"/> are
15/// indexed by production-routing identifier and contain complete
16/// planning-horizon time series.
17///
18/// Expected canonical domain-key format:
19/// <code>
20/// production|routing=&lt;id&gt;|period=&lt;index&gt;
21/// </code>
22/// Period numbers are one-based.
23/// </remarks>
24public sealed class ProductionDecisionMapper :
26{
27 /// <summary>
28 /// Gets the mathematical domain-key category handled by this
29 /// mapper.
30 /// </summary>
31 public override string Category =>
33
34 /// <summary>
35 /// Maps one non-zero production quantity.
36 /// </summary>
37 /// <param name="context">
38 /// Mathematical-solution mapping context.
39 /// </param>
40 /// <param name="solution">
41 /// Target lot-sizing solution.
42 /// </param>
43 /// <param name="domainKey">
44 /// Parsed production domain key.
45 /// </param>
46 /// <param name="variableValue">
47 /// Production quantity returned by the solver.
48 /// </param>
49 protected override void MapValue(
51 LotSizingSolution solution,
52 MathematicalDomainKey domainKey,
53 MathematicalVariableValue variableValue)
54 {
55 ArgumentNullException.ThrowIfNull(
56 context);
57
58 ArgumentNullException.ThrowIfNull(
59 solution);
60
61 ArgumentNullException.ThrowIfNull(
62 domainKey);
63
64 ArgumentNullException.ThrowIfNull(
65 variableValue);
66
67 int routingId =
68 domainKey.GetRequiredInt32(
70
71 int period =
72 domainKey.GetRequiredInt32(
74
75 ProductionDecision? decision =
76 solution.ProductionDecisions
77 .FirstOrDefault(
78 existingDecision =>
79 existingDecision.RoutingId ==
80 routingId);
81
82 if (decision is null)
83 {
84 if (solution.PlanningHorizon <= 0)
85 {
86 throw new InvalidOperationException(
87 "The target lot-sizing solution must have a " +
88 "strictly positive planning horizon before " +
89 "production decisions are mapped.");
90 }
91
92 decision =
93 new ProductionDecision(
94 routingId,
95 solution.PlanningHorizon);
96
97 solution.AddProductionDecision(
98 decision);
99 }
100
101 decision.SetQuantity(
102 period,
103 variableValue.Value);
104 }
105}
Stores the value returned by a solver for one mathematical decision variable.
double Value
Gets or sets the value returned by the solver.
Provides the canonical mathematical domain-key categories used to identify lot-sizing decision famili...
const string Production
Identifies production-quantity decision variables.
Provides a reusable base implementation for mathematical decision mappers handling one domain-key cat...
Represents a parsed mathematical-model business-domain key.
int GetRequiredInt32(string name)
Gets a required integer segment.
Provides the canonical mathematical domain-key segment names used by lot-sizing variables and constra...
Provides the shared state and lookup services required while mapping a mathematical solver result bac...
Maps mathematical production-variable values to production decisions in a lot-sizing solution.
override void MapValue(MathematicalSolutionMappingContext context, LotSizingSolution solution, MathematicalDomainKey domainKey, MathematicalVariableValue variableValue)
Maps one non-zero production quantity.
override string Category
Gets the mathematical domain-key category handled by this mapper.