LotSizingDataModel.Solver 2.0.1
Solver-independent modeling, execution, monitoring and adapter infrastructure.
Loading...
Searching...
No Matches
TransportResourceAdditionalCapacityDecisionMapper.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 additional transport-resource capacity values
11/// to transport-resource capacity decisions in a lot-sizing
12/// solution.
13/// </summary>
14/// <remarks>
15/// Expected canonical domain-key format:
16/// <code>
17/// transportResourceAdditionalCapacity|transportResource=&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 additional transport-resource capacity
33 /// value.
34 /// </summary>
35 /// <param name="context">
36 /// Mathematical-solution mapping context.
37 /// </param>
38 /// <param name="solution">
39 /// Target lot-sizing solution.
40 /// </param>
41 /// <param name="domainKey">
42 /// Parsed transport-resource additional-capacity domain key.
43 /// </param>
44 /// <param name="variableValue">
45 /// Additional-capacity value returned by the solver.
46 /// </param>
47 protected override void MapValue(
49 LotSizingSolution solution,
50 MathematicalDomainKey domainKey,
51 MathematicalVariableValue variableValue)
52 {
53 ArgumentNullException.ThrowIfNull(
54 context);
55
56 ArgumentNullException.ThrowIfNull(
57 solution);
58
59 ArgumentNullException.ThrowIfNull(
60 domainKey);
61
62 ArgumentNullException.ThrowIfNull(
63 variableValue);
64
65 int transportResourceId =
66 domainKey.GetRequiredInt32(
68
69 int period =
70 domainKey.GetRequiredInt32(
72
73 TransportResourceCapacityDecision? decision =
74 solution.TransportResourceCapacityDecisions
75 .FirstOrDefault(
76 existing =>
77 existing.Matches(
78 transportResourceId));
79
80 if (decision is null)
81 {
82 if (solution.PlanningHorizon <= 0)
83 {
84 throw new InvalidOperationException(
85 "The target lot-sizing solution must have a " +
86 "strictly positive planning horizon before " +
87 "transport-resource capacity decisions are " +
88 "mapped.");
89 }
90
91 decision =
92 new TransportResourceCapacityDecision(
93 transportResourceId,
94 solution.PlanningHorizon);
95
96 solution.AddTransportResourceCapacityDecision(
97 decision);
98 }
99
100 decision.SetAdditionalCapacityUsed(
101 period,
102 variableValue.Value);
103 }
104}
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 TransportResourceAdditionalCapacity
Identifies additional transport-resource-capacity 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...
const string TransportResource
Transport-resource identifier segment.
Provides the shared state and lookup services required while mapping a mathematical solver result bac...
Maps mathematical additional transport-resource capacity values to transport-resource capacity decisi...
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 additional transport-resource capacity value.