2using System.Xml.Serialization;
3using LotSizingDataModel.Core.Common;
19[XmlType(TypeName =
"solutionEvaluation")]
28 private DateTime _evaluatedAtUtc =
31 private string _evaluatorName =
34 private string _evaluatorVersion =
37 private string _objectiveValueSource =
40 private string _comment =
43 private double? _objectiveValue;
44 private double? _bestBound;
45 private double? _absoluteGap;
46 private double? _relativeGap;
48 private double? _maximumConstraintViolation;
49 private double? _totalConstraintViolation;
51 private int? _violatedConstraintCount;
87 [XmlAttribute(
"feasibilityStatus")]
90 get => _feasibilityStatus;
92 ref _feasibilityStatus,
100 [XmlAttribute(
"optimalityStatus")]
103 get => _optimalityStatus;
105 ref _optimalityStatus,
113 [XmlElement(
"evaluatedAtUtc")]
116 get => _evaluatedAtUtc;
125 DateTimeKind.Local =>
126 value.ToUniversalTime(),
129 DateTime.SpecifyKind(
148 [XmlAttribute(
"evaluatorName")]
151 get => _evaluatorName;
154 value?.Trim() ??
string.Empty);
161 [XmlAttribute(
"evaluatorVersion")]
164 get => _evaluatorVersion;
166 ref _evaluatorVersion,
167 value?.Trim() ??
string.Empty);
178 [XmlAttribute(
"objectiveValueSource")]
181 get => _objectiveValueSource;
183 ref _objectiveValueSource,
184 value?.Trim() ??
string.Empty);
194 [XmlElement(
"objectiveValue", IsNullable =
true)]
197 get => _objectiveValue;
200 ValidateNullableFiniteValue(
224 [XmlElement(
"bestBound", IsNullable =
true)]
230 ValidateNullableFiniteValue(
251 [XmlElement(
"absoluteGap", IsNullable =
true)]
257 ValidateNullableNonNegativeFiniteValue(
276 [XmlElement(
"relativeGap", IsNullable =
true)]
282 ValidateNullableNonNegativeFiniteValue(
301 "maximumConstraintViolation",
305 get => _maximumConstraintViolation;
308 ValidateNullableNonNegativeFiniteValue(
313 ref _maximumConstraintViolation,
331 "totalConstraintViolation",
335 get => _totalConstraintViolation;
338 ValidateNullableNonNegativeFiniteValue(
343 ref _totalConstraintViolation,
360 "violatedConstraintCount",
364 get => _violatedConstraintCount;
367 if (value.HasValue &&
370 throw new ArgumentOutOfRangeException(
373 "The violated-constraint count " +
374 "cannot be negative.");
378 ref _violatedConstraintCount,
391 [XmlElement(
"comment")]
397 value ??
string.Empty);
422 MaximumConstraintViolation.HasValue ||
423 TotalConstraintViolation.HasValue ||
436 double objectiveValue,
479 double maximumViolation,
480 double totalViolation,
481 int violatedConstraintCount)
483 if (maximumViolation > totalViolation)
485 throw new ArgumentException(
486 "The maximum constraint violation cannot " +
487 "exceed the total constraint violation.",
488 nameof(maximumViolation));
498 violatedConstraintCount;
525 string objectiveDescription =
526 ObjectiveValue.HasValue
528 System.Globalization.CultureInfo
533 $
"Feasibility: {FeasibilityStatus}; " +
534 $
"optimality: {OptimalityStatus}; " +
535 $
"objective: {objectiveDescription}";
538 private static void ValidateNullableFiniteValue(
540 string parameterName)
542 if (value.HasValue &&
543 !
double.IsFinite(value.Value))
545 throw new ArgumentOutOfRangeException(
548 "The value must be finite.");
553 ValidateNullableNonNegativeFiniteValue(
555 string parameterName)
557 if (value.HasValue &&
558 (!
double.IsFinite(value.Value) ||
561 throw new ArgumentOutOfRangeException(
564 "The value must be finite and non-negative.");
void SetConstraintViolationMetrics(double maximumViolation, double totalViolation, int violatedConstraintCount)
Records constraint-violation metrics.
double? AbsoluteGap
Gets or sets the absolute optimality gap.
string ObjectiveValueSource
Gets or sets a description of the source of the recorded objective value.
SolutionEvaluation(FeasibilityStatus feasibilityStatus, OptimalityStatus optimalityStatus)
Initializes a solution evaluation with feasibility and optimality information.
int? ViolatedConstraintCount
Gets or sets the number of violated constraints.
void ClearOptimalityInformation()
Removes all recorded quantitative optimality information.
double? BestBound
Gets or sets a valid bound on the optimal objective value.
double? MaximumConstraintViolation
Gets or sets the largest absolute constraint violation detected in the solution.
double? RelativeGap
Gets or sets the relative optimality gap.
string EvaluatorName
Gets or sets the name of the component that evaluated the solution.
OptimalityStatus OptimalityStatus
Gets or sets the available information about the optimality of the solution.
SolutionEvaluation()
Initializes an empty solution evaluation.
bool HasBestBound
Gets a value indicating whether a valid objective bound has been recorded.
DateTime EvaluatedAtUtc
Gets or sets the UTC date and time at which the evaluation was performed.
string Comment
Gets or sets an optional human-readable comment about the evaluation.
FeasibilityStatus FeasibilityStatus
Gets or sets the evaluated feasibility status of the solution.
double? TotalConstraintViolation
Gets or sets the sum of the absolute constraint violations detected in the solution.
void ClearConstraintViolationMetrics()
Removes all recorded constraint-violation metrics.
bool HasConstraintViolationMetrics
Gets a value indicating whether at least one constraint-violation metric has been recorded.
void SetObjectiveValue(double objectiveValue, string source="")
Records the objective value and its source.
override string ToString()
double? ObjectiveValue
Gets or sets the evaluated objective value.
bool HasObjectiveValue
Gets a value indicating whether an objective value has been recorded.
string EvaluatorVersion
Gets or sets the version of the component that evaluated the solution.
void SetOptimalityInformation(double bestBound, double absoluteGap, double relativeGap)
Records bound and optimality-gap information.