ULSAlgorithms 1.1.0-g3e5595996d
High-performance exact and heuristic algorithms for uncapacitated lot sizing
Loading...
Searching...
No Matches
ClassicHeuristicGuard.cs
Go to the documentation of this file.
2
4
5/// <summary>
6/// Shared applicability checks for classical stationary-cost lot-sizing
7/// heuristics.
8/// </summary>
9internal static class ClassicHeuristicGuard
10{
11 public static bool HasStationaryRelevantCosts(UlsProblem problem)
12 {
13 ArgumentNullException.ThrowIfNull(problem);
14
15 var horizon = problem.Horizon;
16 var setupCosts = problem.SetupCosts;
17 var productionCosts = problem.UnitProductionCosts;
18 var holdingCosts = problem.HoldingCosts;
19
20 var setupCost = setupCosts[0];
21 var productionCost = productionCosts[0];
22
23 for (var period = 1; period < horizon; period++)
24 {
25 if (setupCosts[period] != setupCost ||
26 productionCosts[period] != productionCost)
27 {
28 return false;
29 }
30 }
31
32 if (horizon > 1)
33 {
34 var holdingCost = holdingCosts[0];
35
36 for (var period = 1; period < horizon - 1; period++)
37 {
38 if (holdingCosts[period] != holdingCost)
39 {
40 return false;
41 }
42 }
43 }
44
45 return true;
46 }
47
48 public static void ThrowIfNotStationary(
49 UlsProblem problem,
50 string solverName)
51 {
52 if (!HasStationaryRelevantCosts(problem))
53 {
54 throw new NotSupportedException(
55 $"{solverName} requires constant setup costs, constant unit " +
56 "production costs and constant economically relevant holding costs.");
57 }
58 }
59
60 public static int FindNextPositiveDemand(
61 ReadOnlySpan<double> demands,
62 int start)
63 {
64 for (var period = start; period < demands.Length; period++)
65 {
66 if (demands[period] > 0.0)
67 {
68 return period;
69 }
70 }
71
72 return demands.Length;
73 }
74}
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)
Represents a validated classical uncapacitated lot-sizing problem.
Definition UlsProblem.cs:23
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 > SetupCosts
Gets fixed setup costs by period.
Definition UlsProblem.cs:97