1 year ago
#386459
noy medina
can't execute Pulp with GLPK solver
I'm trying tot solve a linear model with python for a class I take. but, when I try to use the GLPK solver I get an error: """ pulp.apis.core.PulpSolverError: PuLP: cannot execute glpsol.exe """
when I try using a different solver(cbc), it works.
this is my code:
"""
from pulp import *
# creating problem
lp = pulp.LpProblem("ordinal_problem", pulp.const.LpMaximize)
# Decision variable
u1 = pulp.LpVariable('U1', lowBound=0)
u2 = pulp.LpVariable('U2', lowBound=0)
u3 = pulp.LpVariable('U3', lowBound=0)
v1 = pulp.LpVariable('V1', lowBound=0)
v2 = pulp.LpVariable('V2', lowBound=0)
# objective function
lp += (5 * u1 + 7 * u2 + 10 * u3, "Obj")
# constraints
lp += (9 * u1 + 4 * u2 + 16 * u3 - 5 * v1 - 14 * v2 <= 0, "c_2")
lp += (5 * u1 + 7 * u2 + 10 * u3 - 8 * v1 - 15 * v2 <= 0, "c_3")
lp += (4 * u1 + 9 * u2 + 13 * u3 - 7 * v1 - 12 * v2 <= 0, "c_4")
# 8 * v1 + 15 * v2 = 1 --> the equal constraint became two constraints. >= and <=
lp += (8 * v1 + 15 * v2 >= 1, "c_11")
lp += (8 * v1 + 15 * v2 <= 1, "c_12")
# printing the model
print(lp)
lp.writeLP("ordinal_problem.lp") # saving the model to a document
# lp.solve(PULP_CBC_CMD(msg=False))
lp.solve(GLPK(options=["--ranges", "sensitivity_illustration.txt"]))
# the status of our solution (optimal, not feasible etc')
print("Status:", LpStatus[lp.status])
# printing the optimal solution
for v in lp.variables():
print(v.name, "=", v.varValue, '\t' "Reduce cost = ", v.dj)
"""
python
linear-programming
pulp
glpk
0 Answers
Your Answer