Skip to content

Instantly share code, notes, and snippets.

@thomasnield
Created October 17, 2017 00:53
Show Gist options
  • Save thomasnield/bc4d44825e306f5c05dbdee2bf3da43d to your computer and use it in GitHub Desktop.
Save thomasnield/bc4d44825e306f5c05dbdee2bf3da43d to your computer and use it in GitHub Desktop.
Profit Maximization Problem with Pulp
import pulp
# Code for this walkthrough: http://benalexkeen.com/linear-programming-with-python-and-pulp-part-3/
model = pulp.LpProblem("Profit maximising problem", pulp.LpMaximize)
# Declare variables
A = pulp.LpVariable('A', lowBound=0, cat='Integer')
B = pulp.LpVariable('B', lowBound=0, cat='Integer')
# Objective function
model += 30000 * A + 45000 * B, "Profit"
# Constraints
model += 3 * A + 4 * B <= 30
model += 5 * A + 6 * B <= 60
model += 1.5 * A + 3 * B <= 21
# Solve our problem
model.solve()
print(pulp.LpStatus[model.status])
# Print our decision variable values
print("Production of Car A = {}".format(A.varValue))
print("Production of Car B = {}".format(B.varValue))
# Print our objective function value
print(pulp.value(model.objective))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment