LotSizingDataModel.Checker 2.0.1
Reusable validation engine for structural, mathematical and objective consistency checks.
Loading...
Searching...
No Matches
SolutionVerificationBatchCandidate.cs
Go to the documentation of this file.
1using LotSizingDataModel.Instance;
2using LotSizingDataModel.Instance.Results;
3using LotSizingDataModel.Solution;
4
6
7/// <summary>
8/// Describes one candidate to verify in a batch campaign.
9/// </summary>
10/// <remarks>
11/// A candidate represents either a standalone solution or the detailed
12/// solution of a known result. Factory methods guarantee that the two forms
13/// cannot be mixed accidentally.
14/// </remarks>
15public sealed class SolutionVerificationBatchCandidate
16{
17 private SolutionVerificationBatchCandidate(
18 string candidateKey,
19 string? candidateName,
20 LotSizingInstance instance,
21 LotSizingSolution? solution,
22 KnownResult? knownResult,
24 {
26 ValidateCandidateKey(candidateKey);
27
29 string.IsNullOrWhiteSpace(candidateName)
30 ? null
31 : candidateName;
32
33 Instance =
34 instance ??
35 throw new ArgumentNullException(nameof(instance));
36
37 Solution =
38 solution;
39
41 knownResult;
42
43 Kind =
44 kind;
45 }
46
47 /// <summary>
48 /// Gets the stable caller-defined identifier used to correlate results
49 /// with the input candidate.
50 /// </summary>
51 public string CandidateKey
52 {
53 get;
54 }
55
56 /// <summary>
57 /// Gets an optional human-readable candidate name.
58 /// </summary>
59 public string? CandidateName
60 {
61 get;
62 }
63
64 /// <summary>
65 /// Gets the lot-sizing instance against which the candidate is checked.
66 /// </summary>
67 public LotSizingInstance Instance
68 {
69 get;
70 }
71
72 /// <summary>
73 /// Gets the standalone solution when <see cref="Kind"/> is
74 /// <see cref="SolutionVerificationBatchCandidateKind.StandaloneSolution"/>.
75 /// </summary>
76 public LotSizingSolution? Solution
77 {
78 get;
79 }
80
81 /// <summary>
82 /// Gets the known result when <see cref="Kind"/> is
83 /// <see cref="SolutionVerificationBatchCandidateKind.KnownResult"/>.
84 /// </summary>
86 {
87 get;
88 }
89
90 /// <summary>
91 /// Gets the candidate representation kind.
92 /// </summary>
97
98 /// <summary>
99 /// Creates a candidate from a standalone solution.
100 /// </summary>
101 /// <param name="candidateKey">Stable caller-defined candidate identifier.</param>
102 /// <param name="instance">Instance defining the problem.</param>
103 /// <param name="solution">Standalone candidate solution.</param>
104 /// <param name="candidateName">Optional human-readable candidate name.</param>
105 /// <returns>A validated standalone-solution candidate.</returns>
106 public static SolutionVerificationBatchCandidate ForSolution(
107 string candidateKey,
108 LotSizingInstance instance,
109 LotSizingSolution solution,
110 string? candidateName = null)
111 {
112 ArgumentNullException.ThrowIfNull(solution);
113
114 return new SolutionVerificationBatchCandidate(
115 candidateKey,
116 candidateName,
117 instance,
118 solution,
119 knownResult: null,
120 SolutionVerificationBatchCandidateKind.StandaloneSolution);
121 }
122
123 /// <summary>
124 /// Creates a candidate from a known result containing a detailed solution.
125 /// </summary>
126 /// <param name="candidateKey">Stable caller-defined candidate identifier.</param>
127 /// <param name="instance">Instance defining the problem.</param>
128 /// <param name="knownResult">Known result to verify.</param>
129 /// <param name="candidateName">Optional human-readable candidate name.</param>
130 /// <returns>A validated known-result candidate.</returns>
131 /// <exception cref="InvalidOperationException">
132 /// Thrown when the known result has no detailed solution.
133 /// </exception>
134 public static SolutionVerificationBatchCandidate ForKnownResult(
135 string candidateKey,
136 LotSizingInstance instance,
137 KnownResult knownResult,
138 string? candidateName = null)
139 {
140 ArgumentNullException.ThrowIfNull(knownResult);
141
142 if (knownResult.DetailedSolution is null)
143 {
144 throw new InvalidOperationException(
145 "The known result does not contain a detailed solution " +
146 "that can be independently checked.");
147 }
148
149 return new SolutionVerificationBatchCandidate(
150 candidateKey,
151 candidateName,
152 instance,
153 solution: null,
154 knownResult,
156 }
157
158 private static string ValidateCandidateKey(
159 string candidateKey)
160 {
161 if (string.IsNullOrWhiteSpace(candidateKey))
162 {
163 throw new ArgumentException(
164 "The candidate key cannot be empty.",
165 nameof(candidateKey));
166 }
167
168 return candidateKey;
169 }
170}
SolutionVerificationBatchCandidateKind Kind
Gets the candidate representation kind.
LotSizingInstance Instance
Gets the lot-sizing instance against which the candidate is checked.
KnownResult? KnownResult
Gets the known result when Kind is SolutionVerificationBatchCandidateKind.KnownResult.
static SolutionVerificationBatchCandidate ForKnownResult(string candidateKey, LotSizingInstance instance, KnownResult knownResult, string? candidateName=null)
Creates a candidate from a known result containing a detailed solution.
LotSizingSolution? Solution
Gets the standalone solution when Kind is SolutionVerificationBatchCandidateKind.StandaloneSolution.
static SolutionVerificationBatchCandidate ForSolution(string candidateKey, LotSizingInstance instance, LotSizingSolution solution, string? candidateName=null)
Creates a candidate from a standalone solution.
string CandidateKey
Gets the stable caller-defined identifier used to correlate results with the input candidate.
SolutionVerificationBatchCandidateKind
Identifies the domain object represented by a batch-verification candidate.