LotSizingDataModel.Solver 2.0.1
Solver-independent modeling, execution, monitoring and adapter infrastructure.
Loading...
Searching...
No Matches
WorkCenterActivationDecisionMapper.cs
Go to the documentation of this file.
1using System;
2using System.Linq;
3using LotSizingDataModel.Core.PhysicalModel;
4using LotSizingDataModel.Solution;
5using LotSizingDataModel.Solution.Decisions;
7
9
10/// <summary>
11/// Maps mathematical work-center activation values to work-center
12/// capacity decisions in a lot-sizing solution.
13/// </summary>
14/// <remarks>
15/// Expected canonical domain-key format:
16/// <code>
17/// workCenterActivation|plant=&lt;id&gt;|workCenter=&lt;id&gt;|period=&lt;index&gt;
18/// </code>
19/// Period numbers are one-based.
20/// </remarks>
23{
24 /// <summary>
25 /// Gets the mathematical domain-key category handled by this
26 /// mapper.
27 /// </summary>
28 public override string Category =>
30
31 /// <summary>
32 /// Maps one non-zero work-center activation value.
33 /// </summary>
34 /// <param name="context">
35 /// Mathematical-solution mapping context.
36 /// </param>
37 /// <param name="solution">
38 /// Target lot-sizing solution.
39 /// </param>
40 /// <param name="domainKey">
41 /// Parsed work-center activation domain key.
42 /// </param>
43 /// <param name="variableValue">
44 /// Activation value returned by the solver.
45 /// </param>
46 protected override void MapValue(
48 LotSizingSolution solution,
49 MathematicalDomainKey domainKey,
50 MathematicalVariableValue variableValue)
51 {
52 ArgumentNullException.ThrowIfNull(
53 context);
54
55 ArgumentNullException.ThrowIfNull(
56 solution);
57
58 ArgumentNullException.ThrowIfNull(
59 domainKey);
60
61 ArgumentNullException.ThrowIfNull(
62 variableValue);
63
64 int plantId =
65 domainKey.GetRequiredInt32(
67
68 int workCenterId =
69 domainKey.GetRequiredInt32(
71
72 int period =
73 domainKey.GetRequiredInt32(
75
76 var workCenter =
77 new WorkCenterReference
78 {
79 PlantId =
80 plantId,
81
82 WorkCenterId =
83 workCenterId
84 };
85
86 WorkCenterCapacityDecision? decision =
87 solution.WorkCenterCapacityDecisions
88 .FirstOrDefault(
89 existing =>
90 existing.Matches(
91 workCenter));
92
93 if (decision is null)
94 {
95 if (solution.PlanningHorizon <= 0)
96 {
97 throw new InvalidOperationException(
98 "The target lot-sizing solution must have a " +
99 "strictly positive planning horizon before " +
100 "work-center capacity decisions are mapped.");
101 }
102
103 decision =
104 new WorkCenterCapacityDecision(
105 workCenter,
106 solution.PlanningHorizon);
107
108 solution.AddWorkCenterCapacityDecision(
109 decision);
110 }
111
112 decision.SetActivated(
113 period,
114 variableValue.Value >
116 }
117}
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 WorkCenterActivation
Identifies work-center activation 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 work-center activation values to work-center capacity decisions in a lot-sizing sol...
override void MapValue(MathematicalSolutionMappingContext context, LotSizingSolution solution, MathematicalDomainKey domainKey, MathematicalVariableValue variableValue)
Maps one non-zero work-center activation value.
override string Category
Gets the mathematical domain-key category handled by this mapper.