3

PuLP通过 iPython notebook 和 Python 2.7 在 OS X 上运行。glpk使用安装brew install homebrew/science/glpk,PuLP 安装通过pip install pulp.

但是我在 Python 中遇到了错误:

---------------------------------------------------------------------------
PulpSolverError                           Traceback (most recent call last)
<ipython-input-15-689fef0dd94f> in <module>()
      1 # Solve the problem
----> 2 status = prob.solve(GLPK(msg=0))
      3 

/Users/x/anaconda/envs/data/lib/python2.7/site-packages/pulp/pulp.pyc in solve(self, solver, **kwargs)
   1641         #time it
   1642         self.solutionTime = -clock()
-> 1643         status = solver.actualSolve(self, **kwargs)
   1644         self.solutionTime += clock()
   1645         self.restoreObjective(wasNone, dummyVar)

/Users/x/anaconda/envs/data/lib/python2.7/site-packages/pulp/solvers.pyc in actualSolve(self, lp)
    364                              stderr = pipe)
    365             if rc:
--> 366                 raise PulpSolverError("PuLP: Error while trying to execute "+self.path)
    367         else:
    368             if os.name != 'nt':

PulpSolverError: PuLP: Error while trying to execute glpsol

这是触发此错误的代码:

from pulp import *

#Variables
x = LpVariable('x')
y = LpVariable('y')

# Problem
prob = LpProblem('problem', LpMinimize)

# Constraints
prob += x + y <= 1
prob += x <= 1
prob += -2 + y <= 4

# Objective function to minimize
prob += 

# Solve the problem
status = prob.solve(GLPK(msg=0))

导致错误的原因是什么,如何解决?

4

2 回答 2

2

如果你跑

pulp.pulpTestAll()

你可能会看到这样的一行:

Solver pulp.solvers.GLPK_CMD unavailable

如果是这样,您所要做的就是在您的 linux 上安装 glpk-utils 软件包。如果你成功了,你应该可以打电话

glpsol

也可以从命令行。

于 2016-08-18T14:15:59.830 回答
1

我在 Ubuntu 中遇到了同样的错误,这解决了它。

make install 后需要执行以下命令:

须藤 ldconfig

Ldconfig 创建到最新共享库的必要链接和缓存。

https://lists.gnu.org/archive/html/help-glpk/2013-09/msg00018.html

于 2015-10-08T15:08:07.713 回答