Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

linear integer optimization in pulp

I was trying to do the following simple example optimization problem before starting a bigger problem. The code:

from pulp import *
x = LpVariable("x", 0, 3)
y = LpVariable("y", 0, 1)
prob = LpProblem("myProblem", LpMinimize)

prob += x + y <= 2
#objective function
prob += -4*x + y

status = prob.solve(GLPK(msg = 0))
#results
value(x)

I am getting the following error:

Traceback (most recent call last):
  File "C:\Users\mahabubalam\Desktop\Works\GUI\whiskas.py", line 85, in <module>
    status = prob.solve(GLPK(msg = 0))
  File "C:\Python34\lib\site-packages\pulp-1.5.6-py3.4.egg\pulp\pulp.py", line 1619, in solve
    status = solver.actualSolve(self, **kwargs)
  File "C:\Python34\lib\site-packages\pulp-1.5.6-py3.4.egg\pulp\solvers.py", line 335, in actualSolve
    raise PulpSolverError("PuLP: cannot execute "+self.path)
pulp.solvers.PulpSolverError: PuLP: cannot execute glpsol.exe

Can anyone please help me to understand why is that?

like image 838
Dubar Alam Avatar asked Aug 04 '26 23:08

Dubar Alam


1 Answers

I have successfully run your code after doing the following two steps:

  1. Download GLPK from

    http://sourceforge.net/projects/winglpk/files/latest/download (as mentioned by oyvind)

  2. Unzip it into (for example) : C:\glpk_is_here\
  3. Add GLPK binaries to your system path before running python C:\>set PATH=%PATH%;C:\glpk_is_here\glpk-4.55\w64

  4. Using the same cmd window from (3), use python/ipython to run your code:
    C:\>ipython your_code.py

  5. See the results Out[4]: 2.0

Good luck.

like image 73
MZHm Avatar answered Aug 07 '26 13:08

MZHm