2using System.Collections.Generic;
4using System.Xml.Serialization;
14[XmlType(TypeName =
"mathematicalModelSolveResult")]
17 private readonly List<MathematicalVariableValue> _variableValues =
20 private readonly List<string> _diagnostics =
44 [XmlAttribute(
"runName")]
55 [XmlAttribute(
"formulationId")]
65 [XmlAttribute(
"solverKind")]
75 [XmlAttribute(
"solverName")]
85 [XmlAttribute(
"solverVersion")]
95 [XmlAttribute(
"terminationReason")]
106 [XmlAttribute(
"hasFeasibleSolution")]
117 [XmlAttribute(
"isOptimal")]
127 [XmlAttribute(
"objectiveValue")]
137 [XmlAttribute(
"bestBound")]
147 [XmlAttribute(
"relativeGap")]
157 [XmlAttribute(
"absoluteGap")]
178 [XmlAttribute(
"solveDurationMilliseconds")]
186 TimeSpan.FromMilliseconds(
194 [XmlAttribute(
"exploredNodeCount")]
205 [XmlAttribute(
"iterationCount")]
216 [XmlArray(
"variableValues")]
217 [XmlArrayItem(
"variableValue")]
224 [XmlArray(
"diagnostics")]
225 [XmlArrayItem(
"diagnostic")]
246 ArgumentNullException.ThrowIfNull(
251 if (_variableValues.Any(
253 existingValue.VariableId ==
256 throw new InvalidOperationException(
257 $
"A value for mathematical variable identifier " +
258 $
"'{variableValue.VariableId}' is already stored.");
274 if (!
string.IsNullOrWhiteSpace(
296 return _variableValues.FirstOrDefault(
298 variableValue.VariableId ==
311 EnsureFiniteNullable(
315 EnsureFiniteNullable(
319 EnsureFiniteNullable(
323 EnsureFiniteNullable(
329 throw new InvalidOperationException(
330 "Solver duration cannot be negative.");
336 throw new InvalidOperationException(
337 "A feasible solver result must provide an " +
344 throw new InvalidOperationException(
345 "An optimal solver result must contain a feasible " +
356 if (variableValue is
null)
358 throw new InvalidOperationException(
359 "The variable-value collection cannot contain " +
365 if (!variableIds.Add(
368 throw new InvalidOperationException(
369 $
"Mathematical variable identifier " +
370 $
"'{variableValue.VariableId}' appears more " +
371 "than once in the solve result.");
376 private static void EnsureFiniteNullable(
380 if (value.HasValue &&
386 throw new InvalidOperationException(
387 $
"{propertyName} must be finite when specified.");
double? RelativeGap
Gets or sets the relative optimality gap.
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.
SolverTerminationReason TerminationReason
Gets or sets the termination reason.
long? IterationCount
Gets or sets the number of simplex or barrier iterations, when available.
List< MathematicalVariableValue > VariableValues
Gets the mathematical-variable values returned by the solver.
double SolveDurationMilliseconds
Gets or sets the solver wall-clock duration in milliseconds for XML serialization.
bool IsOptimal
Gets or sets a value indicating whether optimality was proven.
MathematicalModelSolveResult()
Initializes an empty mathematical-model solve result.
long? ExploredNodeCount
Gets or sets the number of explored branch-and-bound nodes, when available.
string FormulationId
Gets or sets the identifier of the formulation that generated the mathematical model.
void AddVariableValue(MathematicalVariableValue variableValue)
Adds a variable value.
string SolverName
Gets or sets the solver name.
bool HasFeasibleSolution
Gets or sets a value indicating whether the solver produced at least one feasible solution.
List< string > Diagnostics
Gets diagnostic messages produced while solving.
string RunName
Gets or sets the solve-run name.
void AddDiagnostic(string diagnostic)
Adds a non-empty diagnostic message.
SolverKind SolverKind
Gets or sets the solver kind.
string SolverVersion
Gets or sets the solver version.
TimeSpan SolveDuration
Gets or sets the solver wall-clock duration.
double? BestBound
Gets or sets the best objective bound.
double? AbsoluteGap
Gets or sets the absolute optimality gap.
Stores the value returned by a solver for one mathematical decision variable.
void EnsureValid()
Validates the mathematical-variable value.
int VariableId
Gets or sets the identifier of the mathematical variable.
SolverTerminationReason
Describes why a solver execution terminated.