8 private readonly
double[] _productionQuantities;
9 private readonly
double[] _endingInventories;
10 private readonly
bool[] _setupDecisions;
22 ReadOnlySpan<double> productionQuantities,
23 ReadOnlySpan<double> endingInventories,
24 ReadOnlySpan<bool> setupDecisions,
26 double productionCost,
29 productionQuantities.ToArray(),
30 endingInventories.ToArray(),
31 setupDecisions.ToArray(),
40 double[] productionQuantities,
41 double[] endingInventories,
42 bool[] setupDecisions,
44 double productionCost,
48 ArgumentNullException.ThrowIfNull(productionQuantities);
49 ArgumentNullException.ThrowIfNull(endingInventories);
50 ArgumentNullException.ThrowIfNull(setupDecisions);
52 if (productionQuantities.Length == 0)
54 throw new ArgumentException(
55 "A ULS solution must contain at least one period.",
56 nameof(productionQuantities));
59 if (endingInventories.Length != productionQuantities.Length)
61 throw new ArgumentException(
62 "Ending-inventory and production vectors must have the same length.",
63 nameof(endingInventories));
66 if (setupDecisions.Length != productionQuantities.Length)
68 throw new ArgumentException(
69 "Setup-decision and production vectors must have the same length.",
70 nameof(setupDecisions));
73 ValidateNonNegativeFiniteVector(productionQuantities, nameof(productionQuantities));
74 ValidateNonNegativeFiniteVector(endingInventories, nameof(endingInventories));
75 ValidateCost(setupCost, nameof(setupCost));
76 ValidateCost(productionCost, nameof(productionCost));
77 ValidateCost(holdingCost, nameof(holdingCost));
79 _productionQuantities = takeOwnership
80 ? productionQuantities
81 : (
double[])productionQuantities.Clone();
83 _endingInventories = takeOwnership
85 : (
double[])endingInventories.Clone();
87 _setupDecisions = takeOwnership
89 : (
bool[])setupDecisions.Clone();
94 TotalCost = setupCost + productionCost + holdingCost;
100 public int Horizon => _productionQuantities.Length;
145 double[] productionQuantities,
146 double[] endingInventories,
147 bool[] setupDecisions,
149 double productionCost,
153 productionQuantities,
159 takeOwnership:
true);
162 private static void ValidateNonNegativeFiniteVector(
163 ReadOnlySpan<double> values,
164 string parameterName)
166 for (var period = 0; period < values.Length; period++)
168 var value = values[period];
170 if (!
double.IsFinite(value) || value < 0.0)
172 throw new ArgumentException(
173 $
"Vector '{parameterName}' contains an invalid value at period {period}: {value}.",
179 private static void ValidateCost(
double value,
string parameterName)
181 if (!
double.IsFinite(value) || value < 0.0)
183 throw new ArgumentOutOfRangeException(
186 "Solution cost components must be finite and non-negative.");
UlsSolution(ReadOnlySpan< double > productionQuantities, ReadOnlySpan< double > endingInventories, ReadOnlySpan< bool > setupDecisions, double setupCost, double productionCost, double holdingCost)
Initializes a solution by defensively copying all supplied decision vectors.
static UlsSolution FromOwnedBuffers(double[] productionQuantities, double[] endingInventories, bool[] setupDecisions, double setupCost, double productionCost, double holdingCost)
Creates a solution while transferring ownership of already allocated solver buffers.