Last active
August 29, 2015 14:17
-
-
Save dragstar328/f4c751ff8373110b542c to your computer and use it in GitHub Desktop.
Pulp the LP solver
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
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