Created
March 23, 2022 16:55
-
-
Save voglster/67990716d7e72612737e1a164b981faf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pulp import LpVariable, LpProblem, LpMaximize, LpStatus, value, LpInteger | |
# abstract simple problem | |
prob = LpProblem("Flow Model", LpMaximize) | |
# decision variables | |
buy_d1 = LpVariable("buy_d1", 0, 60_000) | |
buy_d2 = LpVariable("buy_d2", 0, 60_000) | |
store_d1_d2 = LpVariable("store_d1_d2", 0, 50_000) | |
store_d2_d3 = LpVariable("store_d2_d3", 0, 50_000) | |
sell_d2 = LpVariable("sell_d2", 0) | |
sell_d3 = LpVariable("sell_d3", 0) | |
prob += buy_d1 == store_d1_d2 | |
prob += buy_d2 + store_d1_d2 == sell_d2 + store_d2_d3 | |
prob += store_d2_d3 == sell_d3 | |
prob += buy_d1 + buy_d2 <= 90_000 | |
# sell_d2 mod 7000 == 0 | |
number_of_trucks_d2 = LpVariable("number_of_trucks_d2", 0, 100, cat=LpInteger) | |
number_of_trucks_d3 = LpVariable("number_of_trucks_d3", 0, 100, cat=LpInteger) | |
prob += number_of_trucks_d2 * 7_000 == sell_d2 | |
prob += number_of_trucks_d3 * 7_000 == sell_d3 | |
# Maximize | |
sales = sell_d2 * 0.51 + sell_d3 * 0.58 | |
storage_cost = (store_d2_d3 + store_d1_d2) * 0.01 | |
purchase_cost = buy_d1 * 0.50 + buy_d2 * 0.52 | |
prob += sales - purchase_cost - storage_cost | |
status = prob.solve() | |
print(LpStatus[status]) | |
for p in prob.variables(): | |
print(p.name, value(p)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment