ULSAlgorithms 1.1.0-g3e5595996d
High-performance exact and heuristic algorithms for uncapacitated lot sizing
Loading...
Searching...
No Matches
UlsSolveResult.cs
Go to the documentation of this file.
2
3/// <summary>
4/// Represents the outcome returned by a ULS solution strategy.
5/// </summary>
6/// <remarks>
7/// The class is intentionally extensible so solver-backed strategies can expose
8/// additional execution provenance while remaining assignable to the common
9/// <see cref="UlsSolveResult"/> contract.
10/// </remarks>
11public class UlsSolveResult
12{
13 /// <summary>
14 /// Initializes a solve result.
15 /// </summary>
16 /// <param name="solverName">Stable human-readable solver name.</param>
17 /// <param name="status">Mathematical solve status.</param>
18 /// <param name="solution">Optional feasible solution.</param>
19 /// <param name="message">Optional diagnostic message.</param>
21 string solverName,
22 UlsSolveStatus status,
23 UlsSolution? solution = null,
24 string? message = null)
25 {
26 if (string.IsNullOrWhiteSpace(solverName))
27 {
28 throw new ArgumentException(
29 "A solve result must identify its solver.",
30 nameof(solverName));
31 }
32
33 ValidateStatusAndSolution(
34 status,
35 solution);
36
37 SolverName = solverName;
38 Status = status;
39 Solution = solution;
40 Message = message;
41 }
42
43 /// <summary>Gets the solver that produced the result.</summary>
44 public string SolverName { get; }
45
46 /// <summary>Gets the mathematical solve status.</summary>
47 public UlsSolveStatus Status { get; }
48
49 /// <summary>Gets the feasible solution, when one is available.</summary>
50 public UlsSolution? Solution { get; }
51
52 /// <summary>Gets an optional diagnostic message.</summary>
53 public string? Message { get; }
54
55 /// <summary>Gets whether the result contains a feasible solution.</summary>
56 public bool HasSolution => Solution is not null;
57
58 /// <summary>Gets the objective value when a solution is available.</summary>
59 public double? ObjectiveValue => Solution?.TotalCost;
60
61 private static void ValidateStatusAndSolution(
62 UlsSolveStatus status,
63 UlsSolution? solution)
64 {
65 if ((status is UlsSolveStatus.Optimal or
66 UlsSolveStatus.Feasible) &&
67 solution is null)
68 {
69 throw new ArgumentException(
70 $"Status '{status}' requires a feasible solution.",
71 nameof(solution));
72 }
73
74 if ((status is UlsSolveStatus.Infeasible or
75 UlsSolveStatus.NotSolved or
76 UlsSolveStatus.Failed) &&
77 solution is not null)
78 {
79 throw new ArgumentException(
80 $"Status '{status}' cannot contain a feasible solution.",
81 nameof(solution));
82 }
83 }
84}
Represents a feasible production plan for a ULS problem.
Definition UlsSolution.cs:7
string? Message
Gets an optional diagnostic message.
double? ObjectiveValue
Gets the objective value when a solution is available.
UlsSolveStatus Status
Gets the mathematical solve status.
UlsSolution? Solution
Gets the feasible solution, when one is available.
bool HasSolution
Gets whether the result contains a feasible solution.
UlsSolveResult(string solverName, UlsSolveStatus status, UlsSolution? solution=null, string? message=null)
Initializes a solve result.
string SolverName
Gets the solver that produced the result.
UlsSolveStatus
Describes the mathematical status of a ULS solve.