ULSAlgorithms 1.1.0-g3e5595996d
High-performance exact and heuristic algorithms for uncapacitated lot sizing
Loading...
Searching...
No Matches
SegerstedtReformulatedSilverMealSolver.cs
Go to the documentation of this file.
1using System.Buffers;
6
8
9/// <summary>
10/// Implements the reformulated Silver-Meal (rSM, "Lägsta periodkostnad")
11/// heuristic of Segerstedt, Abdul-Jalbar and Samuelsson.
12/// </summary>
13/// <remarks>
14/// <para>
15/// Only periods with non-zero demand are candidate extension points. If
16/// non-zero demands X-hat_i occur at periods t_i and the current lot starts at
17/// t_0, the candidate average is
18///
19/// C_n = (A + h * sum(i=0..n) (t_i-t_0) X-hat_i)
20/// / (t_n-t_0+1).
21///
22/// The lot ends immediately before the first non-zero candidate for which this
23/// average increases.
24/// </para>
25/// <para>
26/// Reference: A. Segerstedt, B. Abdul-Jalbar and B. Samuelsson,
27/// "Reformulated Silver-Meal and Similar Lot Sizing Techniques",
28/// Axioms 12(7), 661, 2023, DOI 10.3390/axioms12070661.
29/// </para>
30/// </remarks>
32{
33 public string Name => "Segerstedt reformulated Silver-Meal";
34
35 public UlsSolverKind Kind => UlsSolverKind.Heuristic;
36
37 public static bool IsApplicable(UlsProblem problem) =>
39
41 UlsProblem problem,
42 CancellationToken cancellationToken = default)
43 {
44 ArgumentNullException.ThrowIfNull(problem);
45 cancellationToken.ThrowIfCancellationRequested();
47
48 var horizon = problem.Horizon;
49 var buffer = ArrayPool<int>.Shared.Rent(horizon);
50
51 try
52 {
53 var cycleEnds = buffer.AsSpan(0, horizon);
54 cycleEnds.Fill(-1);
55
56 var demands = problem.Demands;
57 var setupCost = problem.SetupCosts[0];
58 var holdingCost =
59 horizon > 1
60 ? problem.HoldingCosts[0]
61 : 0.0;
62
63 var start =
65 demands,
66 0);
67
68 while (start < horizon)
69 {
70 cancellationToken.ThrowIfCancellationRequested();
71
72 var bestEnd = start;
73 var accumulatedHolding = 0.0;
74 var previousAverage = setupCost;
75
76 var candidate =
78 demands,
79 start + 1);
80
81 while (candidate < horizon)
82 {
83 accumulatedHolding +=
84 holdingCost *
85 (candidate - start) *
86 demands[candidate];
87
88 if (!double.IsFinite(accumulatedHolding))
89 {
90 throw new ArithmeticException(
91 "Numerical overflow while evaluating reformulated Silver-Meal.");
92 }
93
94 var elapsedPeriods =
95 candidate - start + 1;
96
97 var average =
98 (setupCost + accumulatedHolding) /
99 elapsedPeriods;
100
101 if (average > previousAverage)
102 {
103 break;
104 }
105
106 previousAverage = average;
107 bestEnd = candidate;
108
109 candidate =
111 demands,
112 candidate + 1);
113 }
114
115 cycleEnds[start] = bestEnd;
116
117 start =
119 demands,
120 bestEnd + 1);
121 }
122
124 problem,
125 cycleEnds,
126 Name,
127 cancellationToken);
128 }
129 finally
130 {
131 ArrayPool<int>.Shared.Return(
132 buffer,
133 clearArray: false);
134 }
135 }
136}
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)
Implements the reformulated Silver-Meal (rSM, "Lägsta periodkostnad") heuristic of Segerstedt,...
UlsSolveResult Solve(UlsProblem problem, CancellationToken cancellationToken=default)
Solves an uncapacitated lot-sizing problem.
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.