14 private const double DefaultAbsoluteObjectiveTolerance = 1.0e-8;
15 private const double DefaultRelativeObjectiveTolerance = 1.0e-9;
25 ArgumentNullException.ThrowIfNull(model);
26 ArgumentNullException.ThrowIfNull(solveResult);
27 ArgumentNullException.ThrowIfNull(mappingOptions);
36 SolverObjectiveValue =
65 throw new InvalidOperationException(
66 $
"Objective term references unknown variable " +
67 $
"identifier '{term.VariableId}'.");
76 throw new InvalidOperationException(
77 $
"No solver value is available for objective " +
78 $
"variable '{variable.Name}' " +
79 $
"(identifier {variable.Id}).");
82 double normalizedValue =
92 if (!
double.IsFinite(objective))
94 throw new InvalidOperationException(
95 "The recomputed objective value is not finite.");
98 result.RecomputedObjectiveValue =
106 result.Diagnostics.Add(
107 "The objective was recomputed successfully, " +
108 "but no solver-reported objective value was " +
109 "available for comparison.");
119 reported - objective);
126 Math.Abs(objective)));
130 DefaultAbsoluteObjectiveTolerance,
131 DefaultRelativeObjectiveTolerance * scale);
133 result.AbsoluteDifference =
136 result.ComparisonTolerance =
140 difference <= tolerance
144 result.Diagnostics.Add(
147 ? $
"Solver objective and recomputed objective " +
148 $
"are consistent. Absolute difference=" +
149 $
"{difference:G17}; tolerance={tolerance:G17}."
150 : $
"Solver objective and recomputed objective " +
151 $
"are inconsistent. Absolute difference=" +
152 $
"{difference:G17}; tolerance={tolerance:G17}.");
156 catch (Exception exception)
161 result.Diagnostics.Add(
162 "Objective-value post-processing failed: " +
Stores the result of objective-value post-processing.
Recomputes the objective from the exact normalized numerical representation used by the business solu...
static MathematicalObjectiveRecalculationResult Recalculate(MathematicalModel model, MathematicalModelSolveResult solveResult, MathematicalSolutionMappingOptions mappingOptions)
Recomputes and verifies the objective value.
Stores the solver result for a solver-independent mathematical model.
void EnsureValid()
Validates the mathematical-model solve result.
double? ObjectiveValue
Gets or sets the objective value.
MathematicalVariableValue? FindVariableValue(int variableId)
Finds a variable value by mathematical-variable identifier.
Stores the value returned by a solver for one mathematical decision variable.
double Value
Gets or sets the value returned by the solver.
Defines the options used when mapping a mathematical solver result back to a normalized lot-sizing so...
void EnsureValid()
Validates the mapping options.
double ZeroTolerance
Gets or sets the absolute tolerance below which a solver value is considered equal to zero.
Normalizes raw mathematical-variable values before they are exposed through domain decision objects o...
const double DefaultNearIntegerTolerance
Gets the default tolerance used to clean continuous values that are numerically indistinguishable fro...
const double DefaultIntegralityTolerance
Gets the default tolerance used for integer-domain values.
List< LinearTerm > Terms
Gets the linear terms of the expression.
double Constant
Gets or sets the constant value of the expression.
Represents one coefficient-variable term in a linear expression.
int VariableId
Gets or sets the identifier of the referenced mathematical variable.
Represents a solver-independent mathematical optimization model.
MathematicalObjective Objective
Gets or sets the mathematical objective.
MathematicalVariable? FindVariableById(int variableId)
Finds a mathematical variable by identifier.
void EnsureValid()
Validates the complete mathematical model.
LinearExpression Expression
Gets or sets the linear objective expression.
Represents one decision variable in a mathematical optimization model.
ObjectiveVerificationStatus
Indicates whether a solver-reported objective value is consistent with an objective value independent...
@ Consistent
The solver-reported and recomputed objective values agree within the configured tolerance.
@ NotChecked
No objective-value verification was performed.