Skip to content

Instantly share code, notes, and snippets.

@dragstar328
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dragstar328/f4c751ff8373110b542c to your computer and use it in GitHub Desktop.
Save dragstar328/f4c751ff8373110b542c to your computer and use it in GitHub Desktop.
Pulp the LP solver
import pulp
problem = pulp.LpProblem('hamburg and omelet', pulp.LpMaximize)
# create variables
x = pulp.LpVariable('x', cat = 'Integer')
y = pulp.LpVariable('y', cat = 'Integer')
# maximize
problem += 400 * x + 300 * y
# subjects
problem += 60 * x + 40 * y <= 3800
problem += 20 * x + 30 * y <= 2100
problem += 20 * x + 10 * y <= 1200
print problem
status = problem.solve()
print pulp.LpStatus[status]
print "Result"
print "x", x.value()
print "y", y.value()
max_value = 400 * x.value() + 300 * y.value()
print "MAX VALUE", "400 * %d + 300 * %d = %d" % (x.value(), y.value(), max_value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment