ULSAlgorithms 1.1.0-g3e5595996d
High-performance exact and heuristic algorithms for uncapacitated lot sizing
Loading...
Searching...
No Matches
ChiuModifiedLeastUnitCostSolver.cs
Go to the documentation of this file.
1using System.Buffers;
6
8
9/// <summary>
10/// Implements Chiu's modified Least Unit Cost heuristic.
11/// </summary>
12/// <remarks>
13/// <para>
14/// The ordinary LUC plan is first constructed. A final post-processing test
15/// then removes the last replenishment lot when combining it with the preceding
16/// lot strictly lowers total relevant cost.
17/// </para>
18/// <para>
19/// Reference: Y. P. Chiu,
20/// "A modification of the least unit cost lot-sizing heuristic",
21/// Journal of Statistics and Management Systems 7(1), 197-207, 2004,
22/// DOI 10.1080/09720510.2004.10701115.
23/// </para>
24/// </remarks>
26{
27 public string Name => "Chiu modified Least Unit Cost";
28
29 public UlsSolverKind Kind => UlsSolverKind.Heuristic;
30
31 public static bool IsApplicable(UlsProblem problem) =>
33
35 UlsProblem problem,
36 CancellationToken cancellationToken = default)
37 {
38 ArgumentNullException.ThrowIfNull(problem);
39 cancellationToken.ThrowIfCancellationRequested();
41
42 var horizon = problem.Horizon;
43 var buffer = ArrayPool<int>.Shared.Rent(horizon);
44
45 try
46 {
47 var cycleEnds = buffer.AsSpan(0, horizon);
48 cycleEnds.Fill(-1);
49
50 var demands = problem.Demands;
51 var setupCost = problem.SetupCosts[0];
52 var holdingCost =
53 horizon > 1
54 ? problem.HoldingCosts[0]
55 : 0.0;
56
57 var start =
59 demands,
60 0);
61
62 while (start < horizon)
63 {
64 cancellationToken.ThrowIfCancellationRequested();
65
66 var bestEnd = start;
67 var quantity = demands[start];
68 var accumulatedHolding = 0.0;
69 var previousUnitCost = setupCost / quantity;
70
71 for (var end = start + 1; end < horizon; end++)
72 {
73 accumulatedHolding +=
74 holdingCost *
75 (end - start) *
76 demands[end];
77
78 quantity += demands[end];
79
80 if (!double.IsFinite(accumulatedHolding) ||
81 !double.IsFinite(quantity))
82 {
83 throw new ArithmeticException(
84 "Numerical overflow while evaluating modified LUC.");
85 }
86
87 var unitCost =
88 (setupCost + accumulatedHolding) /
89 quantity;
90
91 if (unitCost > previousUnitCost)
92 {
93 break;
94 }
95
96 previousUnitCost = unitCost;
97 bestEnd = end;
98 }
99
100 cycleEnds[start] = bestEnd;
101
102 start =
104 demands,
105 bestEnd + 1);
106 }
107
108 cancellationToken.ThrowIfCancellationRequested();
109
111 problem,
112 cycleEnds);
113
115 problem,
116 cycleEnds,
117 Name,
118 cancellationToken);
119 }
120 finally
121 {
122 ArrayPool<int>.Shared.Return(
123 buffer,
124 clearArray: false);
125 }
126 }
127}
Implements Chiu's modified Least Unit Cost heuristic.
string Name
Gets the stable human-readable name of the solver.
UlsSolveResult Solve(UlsProblem problem, CancellationToken cancellationToken=default)
Solves an uncapacitated lot-sizing problem.
Shared applicability checks for classical stationary-cost lot-sizing heuristics.
static void ThrowIfNotStationary(UlsProblem problem, string solverName)
static int FindNextPositiveDemand(ReadOnlySpan< double > demands, int start)
Builds and validates a zero-backlogging heuristic solution from a set of replenishment cycles.
static UlsSolveResult Build(UlsProblem problem, ReadOnlySpan< int > cycleEnds, string solverName, CancellationToken cancellationToken)
Applies the published final-lot merge test used by the modified LUC and modified PPB heuristics.
static bool TryMergeLastLot(UlsProblem problem, Span< int > cycleEnds)
Eliminates the final replenishment lot when moving its complete demand to the preceding replenishment...
Represents a validated classical uncapacitated lot-sizing problem.
Definition UlsProblem.cs:23
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
Represents the outcome returned by a ULS solution strategy.
Defines the common strategy contract implemented by every ULS solver.
Definition IUlsSolver.cs:14
UlsSolverKind
Identifies the broad family of a ULS solution strategy.