Last active
November 24, 2021 12:44
-
-
Save skipperkongen/0926ca685e9ccee5a4e65825ec86d3f3 to your computer and use it in GitHub Desktop.
Shadow prices in PuLP
This file contains hidden or 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
import pandas as pd | |
import pulp as P | |
# Define Constraints, Solve, Print Status, Variables, Objective | |
model = P.LpProblem("Maximize Bakery Profits", P.LpMaximize) | |
R = P.LpVariable('Regular_production', lowBound=0, cat='Continuous') | |
J = P.LpVariable('Jumbo_production', lowBound=0, cat='Continuous') | |
model += 5 * R + 10 * J, "Profit" | |
# Adjust the constraint | |
model += 0.5 * R + 1 * J <= ____ | |
model += 1 * R + 2.5 * J <= 65 | |
# Solve Model, Print Status, Variables, Objective, Shadow and Slack | |
model.solve() | |
print("Model Status: {}".format(P.LpStatus[model.status])) | |
for v in model.variables(): | |
print(v.name, "=", v.varValue) | |
print("Objective = $", value(model.objective)) | |
o = [{'name':name, 'shadow price':c.pi, 'slack': c.slack} | |
for name, c in model.constraints.items()] | |
print(pd.DataFrame(o)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment