ULSAlgorithms 1.1.0-g3e5595996d
High-performance exact and heuristic algorithms for uncapacitated lot sizing
Loading...
Searching...
No Matches
UlsProblem.cs
Go to the documentation of this file.
2
3/// <summary>
4/// Represents a validated classical uncapacitated lot-sizing problem.
5/// </summary>
6/// <remarks>
7/// <para>
8/// Periods are zero-based in the API: <c>0, ..., Horizon - 1</c>.
9/// Demand must be satisfied without backlogging, capacity is unlimited, and
10/// initial inventory is zero.
11/// </para>
12/// <para>
13/// <see cref="HoldingCosts"/> contains the cost of holding one unit in
14/// end-of-period inventory. A standard zero-ending-inventory solution therefore
15/// does not use the last holding-cost entry.
16/// </para>
17/// <para>
18/// Input vectors are copied once at construction. Solvers then access contiguous
19/// read-only spans without per-period allocations.
20/// </para>
21/// </remarks>
22public sealed class UlsProblem
23{
24 private readonly double[] _demands;
25 private readonly double[] _setupCosts;
26 private readonly double[] _unitProductionCosts;
27 private readonly double[] _holdingCosts;
28
29 /// <summary>
30 /// Initializes a new validated ULS problem.
31 /// </summary>
32 /// <param name="demands">Demand in each period.</param>
33 /// <param name="setupCosts">Fixed setup cost in each period.</param>
34 /// <param name="unitProductionCosts">Unit production cost in each period.</param>
35 /// <param name="holdingCosts">
36 /// Unit cost of holding one unit of end-of-period inventory in each period.
37 /// </param>
38 public UlsProblem(
39 ReadOnlySpan<double> demands,
40 ReadOnlySpan<double> setupCosts,
41 ReadOnlySpan<double> unitProductionCosts,
42 ReadOnlySpan<double> holdingCosts)
43 {
45 demands,
46 setupCosts,
47 unitProductionCosts,
48 holdingCosts);
49
50 _demands = demands.ToArray();
51 _setupCosts = setupCosts.ToArray();
52 _unitProductionCosts = unitProductionCosts.ToArray();
53 _holdingCosts = holdingCosts.ToArray();
54
55 var totalDemand = 0.0;
56 var noSpeculativeMotive = true;
57
58 for (var period = 0; period < _demands.Length; period++)
59 {
60 totalDemand += _demands[period];
61
62 if (period < _demands.Length - 1)
63 {
64 var deliveredNextPeriod =
65 _unitProductionCosts[period] + _holdingCosts[period];
66
67 if (!double.IsFinite(deliveredNextPeriod) ||
68 deliveredNextPeriod < _unitProductionCosts[period + 1])
69 {
70 noSpeculativeMotive = false;
71 }
72 }
73 }
74
75 TotalDemand = totalDemand;
76 HasNoSpeculativeMotiveCosts = noSpeculativeMotive;
77 }
78
79 /// <summary>
80 /// Gets the number of planning periods.
81 /// </summary>
82 public int Horizon => _demands.Length;
83
84 /// <summary>
85 /// Gets the total demand over the complete planning horizon.
86 /// </summary>
87 public double TotalDemand { get; }
88
89 /// <summary>
90 /// Gets demand by period.
91 /// </summary>
92 public ReadOnlySpan<double> Demands => _demands;
93
94 /// <summary>
95 /// Gets fixed setup costs by period.
96 /// </summary>
97 public ReadOnlySpan<double> SetupCosts => _setupCosts;
98
99 /// <summary>
100 /// Gets unit production costs by period.
101 /// </summary>
102 public ReadOnlySpan<double> UnitProductionCosts => _unitProductionCosts;
103
104 /// <summary>
105 /// Gets end-of-period unit holding costs by period.
106 /// </summary>
107 public ReadOnlySpan<double> HoldingCosts => _holdingCosts;
108
109 /// <summary>
110 /// Gets whether the immutable problem satisfies the no-speculative-motive
111 /// cost condition used by the linear Wagner-Whitin specialization.
112 /// </summary>
113 /// <remarks>
114 /// This value is computed while the constructor already scans the copied
115 /// input arrays. Internal strategy selection can therefore reuse it without
116 /// performing another planning-horizon scan.
117 /// </remarks>
118 internal bool HasNoSpeculativeMotiveCosts { get; }
119}
double TotalDemand
Gets the total demand over the complete planning horizon.
Definition UlsProblem.cs:87
bool HasNoSpeculativeMotiveCosts
Gets whether the immutable problem satisfies the no-speculative-motive cost condition used by the lin...
UlsProblem(ReadOnlySpan< double > demands, ReadOnlySpan< double > setupCosts, ReadOnlySpan< double > unitProductionCosts, ReadOnlySpan< double > holdingCosts)
Initializes a new validated ULS problem.
Definition UlsProblem.cs:38
ReadOnlySpan< double > UnitProductionCosts
Gets unit production costs by period.
int Horizon
Gets the number of planning periods.
Definition UlsProblem.cs:82
ReadOnlySpan< double > HoldingCosts
Gets end-of-period unit holding costs by period.
ReadOnlySpan< double > Demands
Gets demand by period.
Definition UlsProblem.cs:92
ReadOnlySpan< double > SetupCosts
Gets fixed setup costs by period.
Definition UlsProblem.cs:97
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.