LotSizingDataModel.Solver 2.0.1
Solver-independent modeling, execution, monitoring and adapter infrastructure.
Loading...
Searching...
No Matches
SetupDecisionMapper.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 setup-variable values to setup activation
11/// decisions associated with production routings.
12/// </summary>
13/// <remarks>
14/// Expected canonical domain-key format:
15/// <code>
16/// setup|routing=&lt;id&gt;|period=&lt;index&gt;
17/// </code>
18/// Period numbers are one-based.
19/// </remarks>
20public sealed class SetupDecisionMapper :
22{
23 /// <summary>
24 /// Gets the mathematical domain-key category handled by this
25 /// mapper.
26 /// </summary>
27 public override string Category =>
29
30 /// <summary>
31 /// Maps one non-zero setup value.
32 /// </summary>
33 /// <param name="context">
34 /// Mathematical-solution mapping context.
35 /// </param>
36 /// <param name="solution">
37 /// Target lot-sizing solution.
38 /// </param>
39 /// <param name="domainKey">
40 /// Parsed setup domain key.
41 /// </param>
42 /// <param name="variableValue">
43 /// Setup value returned by the solver.
44 /// </param>
45 protected override void MapValue(
47 LotSizingSolution solution,
48 MathematicalDomainKey domainKey,
49 MathematicalVariableValue variableValue)
50 {
51 ArgumentNullException.ThrowIfNull(
52 context);
53
54 ArgumentNullException.ThrowIfNull(
55 solution);
56
57 ArgumentNullException.ThrowIfNull(
58 domainKey);
59
60 ArgumentNullException.ThrowIfNull(
61 variableValue);
62
63 int routingId =
64 domainKey.GetRequiredInt32(
66
67 int period =
68 domainKey.GetRequiredInt32(
70
71 ProductionDecision? decision =
72 solution.ProductionDecisions
73 .FirstOrDefault(
74 existingDecision =>
75 existingDecision.RoutingId ==
76 routingId);
77
78 if (decision is null)
79 {
80 if (solution.PlanningHorizon <= 0)
81 {
82 throw new InvalidOperationException(
83 "The target lot-sizing solution must have a " +
84 "strictly positive planning horizon before " +
85 "setup decisions are mapped.");
86 }
87
88 decision =
89 new ProductionDecision(
90 routingId,
91 solution.PlanningHorizon);
92
93 solution.AddProductionDecision(
94 decision);
95 }
96
97 bool isActivated =
98 variableValue.Value >
100
101 decision.SetSetupActivated(
102 period,
103 isActivated);
104 }
105}
Stores the value returned by a solver for one mathematical decision variable.
Provides the canonical mathematical domain-key categories used to identify lot-sizing decision famili...
const string Setup
Identifies production setup decision variables.
Provides a reusable base implementation for mathematical decision mappers handling one domain-key cat...
virtual double ZeroTolerance
Gets the absolute tolerance below which a solver value is considered equal to zero.
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 setup-variable values to setup activation decisions associated with production rout...
override string Category
Gets the mathematical domain-key category handled by this mapper.
override void MapValue(MathematicalSolutionMappingContext context, LotSizingSolution solution, MathematicalDomainKey domainKey, MathematicalVariableValue variableValue)
Maps one non-zero setup value.