ULSAlgorithms 1.1.0-g3e5595996d
High-performance exact and heuristic algorithms for uncapacitated lot sizing
Loading...
Searching...
No Matches
UlsProblemValidator.cs
Go to the documentation of this file.
2
3/// <summary>
4/// Validates the numerical data of a classical finite-horizon ULS problem.
5/// </summary>
6public static class UlsProblemValidator
7{
8 /// <summary>
9 /// Validates all period-dependent ULS input vectors.
10 /// </summary>
11 /// <param name="demands">Demand in each period.</param>
12 /// <param name="setupCosts">Fixed setup cost in each period.</param>
13 /// <param name="unitProductionCosts">Unit production cost in each period.</param>
14 /// <param name="holdingCosts">
15 /// Unit cost of holding one unit of end-of-period inventory in each period.
16 /// </param>
17 /// <exception cref="ArgumentException">
18 /// Thrown when the horizon is empty, vector lengths differ, or a value is
19 /// negative, NaN, or infinite.
20 /// </exception>
21 public static void Validate(
22 ReadOnlySpan<double> demands,
23 ReadOnlySpan<double> setupCosts,
24 ReadOnlySpan<double> unitProductionCosts,
25 ReadOnlySpan<double> holdingCosts)
26 {
27 var horizon = demands.Length;
28
29 if (horizon == 0)
30 {
31 throw new ArgumentException(
32 "A ULS problem must contain at least one period.",
33 nameof(demands));
34 }
35
36 ValidateLength(setupCosts, horizon, nameof(setupCosts));
37 ValidateLength(unitProductionCosts, horizon, nameof(unitProductionCosts));
38 ValidateLength(holdingCosts, horizon, nameof(holdingCosts));
39
40 ValidateNonNegativeFiniteVector(demands, nameof(demands));
41 ValidateNonNegativeFiniteVector(setupCosts, nameof(setupCosts));
42 ValidateNonNegativeFiniteVector(unitProductionCosts, nameof(unitProductionCosts));
43 ValidateNonNegativeFiniteVector(holdingCosts, nameof(holdingCosts));
44 }
45
46 private static void ValidateLength(
47 ReadOnlySpan<double> values,
48 int expectedLength,
49 string parameterName)
50 {
51 if (values.Length != expectedLength)
52 {
53 throw new ArgumentException(
54 $"Vector '{parameterName}' must contain exactly {expectedLength} values, " +
55 $"but contains {values.Length}.",
56 parameterName);
57 }
58 }
59
60 private static void ValidateNonNegativeFiniteVector(
61 ReadOnlySpan<double> values,
62 string parameterName)
63 {
64 for (var period = 0; period < values.Length; period++)
65 {
66 var value = values[period];
67
68 if (!double.IsFinite(value) || value < 0.0)
69 {
70 throw new ArgumentException(
71 $"Vector '{parameterName}' contains an invalid value at period {period}: " +
72 $"{value}. ULS input values must be finite and non-negative.",
73 parameterName);
74 }
75 }
76 }
77}
Validates the numerical data of a classical finite-horizon ULS problem.
static void Validate(ReadOnlySpan< double > demands, ReadOnlySpan< double > setupCosts, ReadOnlySpan< double > unitProductionCosts, ReadOnlySpan< double > holdingCosts)
Validates all period-dependent ULS input vectors.