LotSizingDataModel.Solver 2.0.1
Solver-independent modeling, execution, monitoring and adapter infrastructure.
Loading...
Searching...
No Matches
MathematicalVariableValue.cs
Go to the documentation of this file.
1using System;
2using System.Xml.Serialization;
3
5
6/// <summary>
7/// Stores the value returned by a solver for one mathematical
8/// decision variable.
9/// </summary>
10/// <remarks>
11/// The variable identifier is the primary link to the
12/// solver-independent mathematical model. The optional variable
13/// name and domain key are copied for diagnostics, exports, and
14/// later mapping back to lot-sizing decisions.
15/// </remarks>
16[Serializable]
17[XmlType(TypeName = "mathematicalVariableValue")]
18public sealed class MathematicalVariableValue
19{
20 /// <summary>
21 /// Initializes an empty mathematical-variable value.
22 /// </summary>
24 {
26 string.Empty;
27
28 DomainKey =
29 string.Empty;
30 }
31
32 /// <summary>
33 /// Initializes a mathematical-variable value.
34 /// </summary>
35 /// <param name="variableId">
36 /// Identifier of the mathematical variable.
37 /// </param>
38 /// <param name="value">
39 /// Value returned by the solver.
40 /// </param>
41 /// <param name="variableName">
42 /// Optional mathematical-variable name.
43 /// </param>
44 /// <param name="domainKey">
45 /// Optional business-domain key.
46 /// </param>
48 int variableId,
49 double value,
50 string variableName = "",
51 string domainKey = "")
52 : this()
53 {
55 variableId;
56
57 Value =
58 value;
59
61 variableName?.Trim() ??
62 string.Empty;
63
64 DomainKey =
65 domainKey?.Trim() ??
66 string.Empty;
67
69 }
70
71 /// <summary>
72 /// Gets or sets the identifier of the mathematical
73 /// variable.
74 /// </summary>
75 [XmlAttribute("variableId")]
76 public int VariableId
77 {
78 get;
79 set;
80 }
81
82 /// <summary>
83 /// Gets or sets the mathematical-variable name.
84 /// </summary>
85 [XmlAttribute("variableName")]
86 public string VariableName
87 {
88 get;
89 set;
90 }
91
92 /// <summary>
93 /// Gets or sets the business-domain key associated with the
94 /// mathematical variable.
95 /// </summary>
96 [XmlElement("domainKey")]
97 public string DomainKey
98 {
99 get;
100 set;
101 }
102
103 /// <summary>
104 /// Gets or sets the value returned by the solver.
105 /// </summary>
106 [XmlAttribute("value")]
107 public double Value
108 {
109 get;
110 set;
111 }
112
113 /// <summary>
114 /// Validates the mathematical-variable value.
115 /// </summary>
116 /// <exception cref="InvalidOperationException">
117 /// Thrown when the variable identifier or returned value is
118 /// invalid.
119 /// </exception>
120 public void EnsureValid()
121 {
122 if (VariableId <= 0)
123 {
124 throw new InvalidOperationException(
125 "A mathematical-variable value must reference a " +
126 "strictly positive variable identifier.");
127 }
128
129 if (double.IsNaN(
130 Value) ||
131 double.IsInfinity(
132 Value))
133 {
134 throw new InvalidOperationException(
135 "A mathematical-variable value must be finite.");
136 }
137
139 VariableName?.Trim() ??
140 string.Empty;
141
142 DomainKey =
143 DomainKey?.Trim() ??
144 string.Empty;
145 }
146}
void EnsureValid()
Validates the mathematical-variable value.
int VariableId
Gets or sets the identifier of the mathematical variable.
string VariableName
Gets or sets the mathematical-variable name.
MathematicalVariableValue()
Initializes an empty mathematical-variable value.
MathematicalVariableValue(int variableId, double value, string variableName="", string domainKey="")
Initializes a mathematical-variable value.
double Value
Gets or sets the value returned by the solver.
string DomainKey
Gets or sets the business-domain key associated with the mathematical variable.