70 double integralityTolerance,
71 double nearIntegerTolerance)
75 nameof(zeroTolerance));
79 nameof(integralityTolerance));
83 nameof(nearIntegerTolerance));
128 ArgumentNullException.ThrowIfNull(
131 if (!
double.IsFinite(rawValue))
133 throw new ArgumentOutOfRangeException(
136 "A mathematical-variable value must be finite.");
144 return variable.VariableType
switch
152 NormalizeIntegerDomainValue(
157 NormalizeContinuousValue(
161 NormalizeContinuousValue(
173 ArgumentNullException.ThrowIfNull(
185 private double NormalizeBinary(
204 throw new InvalidOperationException(
205 $
"Binary solver value '{rawValue:G17}' is not within " +
206 $
"the configured integrality tolerance " +
207 $
"'{IntegralityTolerance:G17}' of 0 or 1.");
210 private double NormalizeIntegerDomainValue(
213 double nearestInteger =
216 MidpointRounding.AwayFromZero);
219 rawValue - nearestInteger) <=
222 return nearestInteger;
233 private double NormalizeContinuousValue(
236 double nearestInteger =
239 MidpointRounding.AwayFromZero);
242 rawValue - nearestInteger) <=
245 return nearestInteger;
251 private static void ValidateTolerance(
253 string parameterName)
255 if (!
double.IsFinite(tolerance) ||
258 throw new ArgumentOutOfRangeException(
261 "A numerical tolerance must be finite and " +
Stores the value returned by a solver for one mathematical decision variable.
int VariableId
Gets or sets the identifier of the mathematical variable.
string VariableName
Gets or sets the mathematical-variable name.
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.
const double DefaultNearIntegerTolerance
Gets the default tolerance used to clean continuous values that are numerically indistinguishable fro...
double Normalize(MathematicalVariable variable, double rawValue)
Normalizes one raw variable value.
MathematicalVariableValue Normalize(MathematicalVariable variable, MathematicalVariableValue rawValue)
Returns a normalized copy of one solver value.
double IntegralityTolerance
Gets the integrality tolerance.
const double DefaultZeroTolerance
Gets the default tolerance used to identify numerical zero.
const double DefaultIntegralityTolerance
Gets the default tolerance used for integer-domain values.
double ZeroTolerance
Gets the zero tolerance.
MathematicalVariableValueNormalizer(double zeroTolerance, double integralityTolerance, double nearIntegerTolerance)
Initializes a value normalizer.
double NearIntegerTolerance
Gets the near-integer cleanup tolerance for continuous variables.
MathematicalVariableValueNormalizer()
Initializes a value normalizer with default tolerances.
Represents one decision variable in a mathematical optimization model.
@ SemiContinuous
The variable is either zero or belongs to a continuous interval bounded away from zero.
@ Continuous
The variable may take any real value within its bounds.
@ SemiInteger
The variable is either zero or belongs to an integer interval bounded away from zero.
@ Binary
The variable may take only the values zero and one.
@ Integer
The variable may take only integer values within its bounds.