LotSizingDataModel.Solver 2.0.1
Solver-independent modeling, execution, monitoring and adapter infrastructure.
Loading...
Searching...
No Matches
TransportResourceActivationDecisionMapper.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 transport-resource activation values to
11/// transport-resource capacity decisions in a lot-sizing
12/// solution.
13/// </summary>
14/// <remarks>
15/// Expected canonical domain-key format:
16/// <code>
17/// transportResourceActivation|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 transport-resource 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 transport-resource 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 transportResourceId =
65 domainKey.GetRequiredInt32(
67
68 int period =
69 domainKey.GetRequiredInt32(
71
72 TransportResourceCapacityDecision? decision =
73 solution.TransportResourceCapacityDecisions
74 .FirstOrDefault(
75 existing =>
76 existing.Matches(
77 transportResourceId));
78
79 if (decision is null)
80 {
81 if (solution.PlanningHorizon <= 0)
82 {
83 throw new InvalidOperationException(
84 "The target lot-sizing solution must have a " +
85 "strictly positive planning horizon before " +
86 "transport-resource capacity decisions are " +
87 "mapped.");
88 }
89
90 decision =
91 new TransportResourceCapacityDecision(
92 transportResourceId,
93 solution.PlanningHorizon);
94
95 solution.AddTransportResourceCapacityDecision(
96 decision);
97 }
98
99 decision.SetActivated(
100 period,
101 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 TransportResourceActivation
Identifies transport-resource 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...
const string TransportResource
Transport-resource identifier segment.
Provides the shared state and lookup services required while mapping a mathematical solver result bac...
Maps mathematical transport-resource activation values to transport-resource capacity decisions in a ...
override void MapValue(MathematicalSolutionMappingContext context, LotSizingSolution solution, MathematicalDomainKey domainKey, MathematicalVariableValue variableValue)
Maps one non-zero transport-resource activation value.
override string Category
Gets the mathematical domain-key category handled by this mapper.