LotSizingDataModel.Checker 2.0.1
Reusable validation engine for structural, mathematical and objective consistency checks.
Loading...
Searching...
No Matches
MathematicalSolutionProjectionResult.cs
Go to the documentation of this file.
2
3/// <summary>
4/// Contains mathematical-variable values projected from one
5/// normalized lot-sizing solution.
6/// </summary>
8{
9 private readonly Dictionary<int, double> _values =
10 new();
11
12 private readonly List<MathematicalSolutionProjectionIssue> _issues =
13 new();
14
15 /// <summary>
16 /// Gets the projected values indexed by mathematical variable
17 /// identifier.
18 /// </summary>
19 public IReadOnlyDictionary<int, double> Values =>
20 _values;
21
22 /// <summary>
23 /// Gets all projection diagnostics.
24 /// </summary>
25 public IReadOnlyList<MathematicalSolutionProjectionIssue> Issues =>
26 _issues;
27
28 /// <summary>
29 /// Gets whether every mathematical variable was projected
30 /// successfully.
31 /// </summary>
32 public bool IsSuccessful =>
33 _issues.Count == 0;
34
35 /// <summary>
36 /// Gets the number of projected variables.
37 /// </summary>
39 _values.Count;
40
41 /// <summary>
42 /// Adds one projected mathematical-variable value.
43 /// </summary>
44 /// <param name="variableId">Variable identifier.</param>
45 /// <param name="value">Projected value.</param>
46 public void AddValue(
47 int variableId,
48 double value)
49 {
50 if (variableId <= 0)
51 {
52 throw new ArgumentOutOfRangeException(
53 nameof(variableId),
54 variableId,
55 "A mathematical variable identifier must be positive.");
56 }
57
58 if (!double.IsFinite(value))
59 {
60 throw new ArgumentOutOfRangeException(
61 nameof(value),
62 value,
63 "A projected mathematical value must be finite.");
64 }
65
66 if (!_values.TryAdd(
67 variableId,
68 value))
69 {
70 throw new InvalidOperationException(
71 $"A projected value already exists for mathematical " +
72 $"variable '{variableId}'.");
73 }
74 }
75
76 /// <summary>
77 /// Adds one projection issue.
78 /// </summary>
79 /// <param name="issue">Issue to append.</param>
80 public void AddIssue(
82 {
83 ArgumentNullException.ThrowIfNull(issue);
84
85 _issues.Add(issue);
86 }
87
88 /// <summary>
89 /// Attempts to get the projected value of one mathematical
90 /// variable.
91 /// </summary>
92 public bool TryGetValue(
93 int variableId,
94 out double value)
95 {
96 return _values.TryGetValue(
97 variableId,
98 out value);
99 }
100}
Describes one issue encountered while projecting a business solution onto mathematical-model variable...
Contains mathematical-variable values projected from one normalized lot-sizing solution.
bool IsSuccessful
Gets whether every mathematical variable was projected successfully.
IReadOnlyList< MathematicalSolutionProjectionIssue > Issues
Gets all projection diagnostics.
void AddIssue(MathematicalSolutionProjectionIssue issue)
Adds one projection issue.
void AddValue(int variableId, double value)
Adds one projected mathematical-variable value.
IReadOnlyDictionary< int, double > Values
Gets the projected values indexed by mathematical variable identifier.
bool TryGetValue(int variableId, out double value)
Attempts to get the projected value of one mathematical variable.