ULSAlgorithms 1.1.0-g3e5595996d
High-performance exact and heuristic algorithms for uncapacitated lot sizing
Loading...
Searching...
No Matches
UlsFormulationMath.cs
Go to the documentation of this file.
2
4
5internal static class UlsFormulationMath
6{
7 internal static double[] BuildSuffixDemand(
8 UlsProblem problem)
9 {
10 var suffix =
11 new double[problem.Horizon + 1];
12
13 ReadOnlySpan<double> demand =
14 problem.Demands;
15
16 for (int period = problem.Horizon - 1;
17 period >= 0;
18 period--)
19 {
20 suffix[period] =
22 demand[period],
23 suffix[period + 1],
24 "suffix demand");
25 }
26
27 return suffix;
28 }
29
30 internal static double[] BuildCumulativeDemand(
31 UlsProblem problem)
32 {
33 var cumulative =
34 new double[problem.Horizon];
35
36 double running = 0.0;
37
38 for (int period = 0;
39 period < problem.Horizon;
40 period++)
41 {
42 running =
44 running,
45 problem.Demands[period],
46 "cumulative demand");
47
48 cumulative[period] =
49 running;
50 }
51
52 return cumulative;
53 }
54
55 internal static double DeliveredUnitCost(
56 UlsProblem problem,
57 int productionPeriod,
58 int demandPeriod)
59 {
60 if (productionPeriod < 0 ||
61 demandPeriod < productionPeriod ||
62 demandPeriod >= problem.Horizon)
63 {
64 throw new ArgumentOutOfRangeException();
65 }
66
67 double cost =
68 problem.UnitProductionCosts[productionPeriod];
69
70 for (int period = productionPeriod;
71 period < demandPeriod;
72 period++)
73 {
74 cost =
76 cost,
77 problem.HoldingCosts[period],
78 "delivered unit cost");
79 }
80
81 return cost;
82 }
83
84 internal static double RegenerationArcCost(
85 UlsProblem problem,
86 int start,
87 int endInclusive)
88 {
89 double quantity = 0.0;
90 double variableCost = 0.0;
91
92 for (int demandPeriod = start;
93 demandPeriod <= endInclusive;
94 demandPeriod++)
95 {
96 double demand =
97 problem.Demands[demandPeriod];
98
99 quantity =
100 AddFinite(
101 quantity,
102 demand,
103 "regeneration quantity");
104
105 variableCost =
106 AddFinite(
107 variableCost,
109 demand,
111 problem,
112 start,
113 demandPeriod),
114 "regeneration variable cost"),
115 "regeneration variable cost");
116 }
117
118 return quantity == 0.0
119 ? 0.0
120 : AddFinite(
121 problem.SetupCosts[start],
122 variableCost,
123 "regeneration arc cost");
124 }
125
126 internal static bool IsNoSpeculativeMotive(
127 UlsProblem problem)
128 {
129 for (int period = 0;
130 period < problem.Horizon - 1;
131 period++)
132 {
133 double deliveredNext =
134 problem.UnitProductionCosts[period] +
135 problem.HoldingCosts[period];
136
137 if (!double.IsFinite(deliveredNext) ||
138 deliveredNext <
139 problem.UnitProductionCosts[period + 1])
140 {
141 return false;
142 }
143 }
144
145 return true;
146 }
147
148 internal static double AddFinite(
149 double left,
150 double right,
151 string operation)
152 {
153 double value =
154 left + right;
155
156 if (!double.IsFinite(value))
157 {
158 throw new ArithmeticException(
159 $"Numerical overflow while computing {operation}.");
160 }
161
162 return value;
163 }
164
165 internal static double MultiplyFinite(
166 double left,
167 double right,
168 string operation)
169 {
170 double value =
171 left * right;
172
173 if (!double.IsFinite(value))
174 {
175 throw new ArithmeticException(
176 $"Numerical overflow while computing {operation}.");
177 }
178
179 return value;
180 }
181}
static double[] BuildCumulativeDemand(UlsProblem problem)
static double DeliveredUnitCost(UlsProblem problem, int productionPeriod, int demandPeriod)
static double RegenerationArcCost(UlsProblem problem, int start, int endInclusive)
static double AddFinite(double left, double right, string operation)
static double MultiplyFinite(double left, double right, string operation)
static double[] BuildSuffixDemand(UlsProblem problem)
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 > Demands
Gets demand by period.
Definition UlsProblem.cs:92
ReadOnlySpan< double > SetupCosts
Gets fixed setup costs by period.
Definition UlsProblem.cs:97