LotSizingDataModel.Instance 2.0.1
Lot-sizing instance representation, descriptors and problem characterization.
Loading...
Searching...
No Matches
NonSpeculativeCostConditionAnalyzer.cs
Go to the documentation of this file.
3
5
6/// <summary>
7/// Tests the generic adjacent non-speculative cost condition
8/// h_t + p_t - p_(t+1) >= 0.
9/// </summary>
10/// <remarks>
11/// The caller supplies adjacent unit source/production costs p and holding
12/// costs h. There must be one more p value than h values.
13///
14/// This generic condition is the cost relation used by Wolsey's WW class, but
15/// the analyzer itself is independent from Wolsey.
16/// </remarks>
18{
20 IEnumerable<double> adjacentUnitCosts,
21 IEnumerable<double> holdingCosts,
22 TemporalPatternTolerance? tolerance = null)
23 {
24 ArgumentNullException.ThrowIfNull(adjacentUnitCosts);
25 ArgumentNullException.ThrowIfNull(holdingCosts);
26
27 double[] p = adjacentUnitCosts.ToArray();
28 double[] h = holdingCosts.ToArray();
29
30 if (h.Length == 0 || p.Length != h.Length + 1)
31 {
32 throw new ArgumentException(
33 "Non-speculative analysis requires at least one holding " +
34 "interval and exactly one more unit-cost value than holding " +
35 "cost values.");
36 }
37
38 ValidateFinite(p, nameof(adjacentUnitCosts));
39 ValidateFinite(h, nameof(holdingCosts));
40
42 tolerance ??
44
45 double scale =
46 p.Concat(h)
47 .Select(Math.Abs)
48 .DefaultIfEmpty(0.0)
49 .Max();
50
51 double effectiveTolerance =
52 policy.GetEffectiveTolerance(scale);
53
54 double[] margins =
55 new double[h.Length];
56
57 bool satisfied = true;
58
59 for (int index = 0; index < h.Length; index++)
60 {
61 margins[index] =
62 h[index] +
63 p[index] -
64 p[index + 1];
65
66 if (margins[index] < -effectiveTolerance)
67 {
68 satisfied = false;
69 }
70 }
71
73 satisfied
74 ? UniversalConditionState.Satisfied
75 : UniversalConditionState.NotSatisfied,
76 margins,
77 effectiveTolerance);
78 }
79
80 private static void ValidateFinite(
81 IEnumerable<double> values,
82 string parameterName)
83 {
84 if (values.Any(value => !double.IsFinite(value)))
85 {
86 throw new ArgumentException(
87 "Cost-condition inputs must contain only finite values.",
88 parameterName);
89 }
90 }
91}
Result of the generic adjacent non-speculative production/holding-cost condition analysis.
Tests the generic adjacent non-speculative cost condition h_t + p_t - p_(t+1) >= 0.
NonSpeculativeCostConditionAnalysis Analyze(IEnumerable< double > adjacentUnitCosts, IEnumerable< double > holdingCosts, TemporalPatternTolerance? tolerance=null)
Defines the numerical tolerance policy used for temporal-pattern analysis.
double GetEffectiveTolerance(double scale)
Computes the effective absolute tolerance for a given value scale.
static TemporalPatternTolerance Default
Gets the default conservative numerical tolerance.
UniversalConditionState
Three-valued state of a derived semantic condition.