Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ jobs:
if: github.event_name != 'pull_request'
run: |
echo "PUSH_TO_BENCHMARKS=true" >> $GITHUB_ENV
echo "COMMENT_ALWAYS=false" >> $GITHUB_ENV

- name: Store Benchmark Result
uses: benchmark-action/github-action-benchmark@v1
Expand Down
28 changes: 28 additions & 0 deletions examples/lot_sizing/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Lot Sizing Example

You can find the source for the example
[here](https://github.com/cls-python/cls-luigi/tree/main/examples/lot_sizing/):

Here we utilized CLS-Luigi to construct demand prediction pipelines for
lot sizing. The example was built to present CLS-Luigi at the
[LION17](https://lion17.org/) conference.

# Requirements

The example contains a
[requirements.txt](https://github.com/cls-python/cls-luigi/tree/main/examples/ny_taxi/requirements.txt)
file. To experiment with the example, you can set up your environment by
executing the following command:

``` bash
# cd into the lot sizing example folder
pip install -r requirements.txt
```

# Static Visualization

![image](images/static.png)

# Dynamic Visualization

![image](images/dynamic.png)
Binary file added examples/lot_sizing/images/dynamic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/lot_sizing/images/static.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
81 changes: 81 additions & 0 deletions examples/lot_sizing/lot_optimizers/groff_heuristic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import numpy as np


class GroffHeuristic:
def __init__(self):
pass

def run(self, dict_in, demand):
# Füllen der Variablen aus Start_Dictionary
dem = demand
kf = dict_in["fixedCost"]
kv = dict_in["varCost"]
pp = len(dem)
orders = [0 for i in range(pp)]
cost_v = 0
j = 0
p = 0
criterion = (2 * kf) / kv

# testen ob "Null-Perioden am Anfang vorliegen
while dem[p] == 0:
orders[p] = 0
p = p + 1
if p == pp:
p = p - 1
break
i = p

while p < pp:
for i in range(p, pp):
crit_met = False
if dem[i] * j * ((i - p) + 1) <= criterion:
orders[p] += dem[i]
crit_met = True
cost = dem[i] * kv * (i - p)
j = j + 1
cost_v = cost + cost_v
else:
break
if (p == (pp - 1)) or (crit_met and i == (pp - 1)):
break
j = 0
p += i - p
x = orders.count(0)
fix = (pp - x) * kf
print(fix)
total_c = cost_v + fix
print("total cost: " + str(total_c))
print(sum(orders))
return np.array(orders)


if __name__ == "__main__":
# statisches Test dictionary
dict_in = {
"planningPeriod": 8, # Anzahl der Perioden
"fixedCost": 40, # Bestellkosten
"varCost": 1, # Lagerhaltungssatz
"roll": 4,
}

demand = [40, 50, 10, 20, 30, 40, 20, 25]
# demand = [0, 0, 0, 10, 0, 1]
# demand = [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0]
# demand = [20, 50, 10, 50, 50, 10, 20, 40, 20, 30]
# demand = [854, 1021, 984, 1030, 1240, 1178, 905, 1005, 958, 905, 966, 965, 1030, 1111, 1285, 1089, 959, 920]
# demand = [300, 5001, 6022, 6103, 3533, 4046, 3044, 3023, 4064, 9552, 3960, 5077, 4000, 4000, 3430, 300, 3400, 3440,
# 200, 3400, 9400, 4340, 3400, 300, 3040, 4000, 5000, 6500, 45454, 4443, 3244, 2334, 344, 3223, 2999, 4000, 4000,
# 4000, 3400, 0, 0, 0, 4500, 400, 4500, 3400, 5400, 3000, 600, 0, 4500, 0, 0, 555, 4540, 500, 800,
# 4555, 3000, 4555, 455, 3444, 4333, 2344, 4454, 4555, 3444]
# demand = [0, 0, 6022, 6103, 3533, 4046, 3044, 3023, 4064, 9552, 3960,
# 5077, 4000, 4000, 3430, 300, 3400, 3440, 200,
# 3400, 9400, 4340, 3400, 300, 3040, 4000, 5000, 6500, 45454,
# 4443, 3244, 2334, 344, 3223, 2999, 4000, 4000,
# 4000, 3400, 3400, 3444, 5006, 4500, 400, 4500, 3400, 5400, 0,
# 0, 0, 4500, 4500, 4400, 555, 4540, 0, 0,
# 4555, 3000, 4555, 455, 3444, 4333, 2344, 4454, 4555, 3444]

groff = GroffHeuristic()
output = groff.run(dict_in, demand)
print(output)
144 changes: 144 additions & 0 deletions examples/lot_sizing/lot_optimizers/least_unit_cost_method.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
import numpy as np


class LeastUnitCostMethod:
def __init__(self):
pass

def run(self, dict_in, demand):
# Füllen der Variablen aus Start_Dictionary
dem = demand
kf = dict_in["fixedCost"]
kv = dict_in["varCost"]
pp = len(dem)

p = 0
kpj = 0
kppj = 0
orders = [0 for i in range(pp)]
total_c = 0

# testen ob "Null-Perioden am Anfang vorliegen
while dem[p] == 0:
orders[p] = 0
p = p + 1
if p == pp:
p = p - 1
break

while p < pp:
j = p
lg1 = 0
lg2 = 0
kppj = (kf + (kv * dem[j] * (j - p))) / dem[j]
while j < pp:
last_c = kpj * lg2
lg1 += dem[j] * (j - p) # Aufsummierung der Nachfrage, in Abhängigkeit der Verzinsung
lg2 += dem[j] # Aufsummierung der Nachfrage
kpj = (kf + kv * lg1) / lg2
if kpj > kppj:
orders[p] = lg2 - dem[j]
total_c += last_c
break
j += 1
kppj = kpj
temp = p
p = j
total_c += kpj * lg2
orders[temp] = lg2
# print("Total Cost: " + str(total_c))
# print(sum(orders))
return np.array(orders)


if __name__ == "__main__":
# statisches Test dictionary
dict_in = {
"planningPeriod": 14, # Anzahl der Perioden
"fixedCost": 10000, # Bestellkosten
"varCost": 1, # Lagerhaltungssatz
"roll": 4,
}

# demand = [40, 50, 10, 20, 30, 40, 20, 25]
# demand = [0, 0, 0, 10, 0, 1]
# demand = [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0]
# demand = [20, 50, 10, 50, 50, 10, 20, 40, 20, 30]
# demand = [854, 1021, 984, 1030, 1240, 1178, 905, 1005, 958, 905, 966, 965, 1030, 1111, 1285, 1089, 959, 920]
# demand = [300, 5001, 6022, 6103, 3533, 4046, 3044, 3023, 4064, 9552, 3960, 5077, 4000, 4000, 3430, 300, 3400, 3440,
# 200, 3400, 9400, 4340, 3400, 300, 3040, 4000, 5000, 6500, 45454, 4443, 3244, 2334, 344, 3223, 2999, 4000, 4000,
# 4000, 3400, 0, 0, 0, 4500, 400, 4500, 3400, 5400, 3000, 600, 0, 4500, 0, 0, 555, 4540, 500, 800,
# 4555, 3000, 4555, 455, 3444, 4333, 2344, 4454, 4555, 3444]
demand = [
0,
0,
6022,
6103,
3533,
4046,
3044,
3023,
4064,
9552,
3960,
5077,
4000,
4000,
3430,
300,
3400,
3440,
200,
3400,
9400,
4340,
3400,
300,
3040,
4000,
5000,
6500,
45454,
4443,
3244,
2334,
344,
3223,
2999,
4000,
4000,
4000,
3400,
3400,
3444,
5006,
4500,
400,
4500,
3400,
5400,
0,
0,
0,
4500,
4500,
4400,
555,
4540,
0,
0,
4555,
3000,
4555,
455,
3444,
4333,
2344,
4454,
4555,
3444,
]

leastunitcostmethod = LeastUnitCostMethod()
output = leastunitcostmethod.run(dict_in, demand)
print(output)
Loading
Loading