0

PuLP で 2 進整数計画問題を解こうとしていて、GLPK をソルバーとして使用しているときに、次のエラーが発生します。WindowsにGLPKをインストールし、パスも設定しました。pulp.pulpTestAll()ショーの結果Solver <class 'pulp.solvers.GLPK_CMD'> passed

Traceback (most recent call last):
  File "C:\Python34\Cloud 5.py", line 464, in <module>
    resource(request, pmachine, l, q)
  File "C:\Python34\Cloud 5.py", line 238, in resource
    status = prob.solve(pulp.GLPK())
  File "C:\Python34\lib\site-packages\pulp-1.6.1-py3.4.egg\pulp\pulp.py", line 1643, in solve
    status = solver.actualSolve(self, **kwargs)
  File "C:\Python34\lib\site-packages\pulp-1.6.1-py3.4.egg\pulp\solvers.py", line 346, in actualSolve
    raise PulpSolverError("PuLP: cannot execute "+self.path)
pulp.solvers.PulpSolverError: PuLP: cannot execute glpsol.exe

ただし、デフォルトの PuLP ソルバーを使用すると、問題なく動作します。私はstatus = prob.solve(pulp.GLPK())ソルバーを呼び出すために使用しています。完全な Python コードは非常に長いため、ここには掲載していません。PuLPの から得られる出力prob.writeLP('problem.txt')は次のとおりです。

\* Resource *\
Maximize
OBJ: 2 _y11 + 2 _y12 + 10 _y21 + 10 _y22
Subject To
_dummy: __dummy = 0
_C1: __dummy = 0
_C10: 100 _x121 + 200 _x221 <= 1024
_C11: _y11 + _y12 <= 1
_C12: _y21 + _y22 <= 1
_C13: _x111 - _y11 <= 0
_C14: _x112 - _y11 <= 0
_C15: _x121 - _y12 <= 0
_C16: _x211 - _y21 <= 0
_C17: _x212 - _y21 <= 0
_C18: _x221 - _y22 <= 0
_C19: _x111 + _x121 = 0
_dummy: __dummy = 0
_C2: __dummy = 0
_C20: _x211 + _x221 = 0
_C21: _x111 + _x121 = 0
_C22: _x211 + _x221 = 0
_C23: _x111 = 0
_C24: _x121 = 0
_C25: _x211 = 0
_C26: _x221 = 0
_C27: _x111 + _x112 + _x121 = 1
_C28: _x211 + _x212 + _x221 = 1
_dummy: __dummy = 0
_C3: __dummy = 0
_dummy: __dummy = 0
_C4: __dummy = 0
_C5: _x111 + 2 _x211 <= 4
_C6: _x112 + 2 _x212 <= 8
_C7: _x121 + 2 _x221 <= 4
_C8: 100 _x111 + 200 _x211 <= 1024
_C9: 100 _x112 + 200 _x212 <= 2000
Bounds
__dummy = 0
Binaries
_x111
_x112
_x121
_x211
_x212
_x221
_y11
_y12
_y21
_y22
End

GLPK でエラーが発生するのはなぜですか? デフォルトのソルバーを使用すると、次の出力が得られます。

Optimal
Objective value: 12.0

The values of the variables : 

__dummy = None
_x111 = 0.0
_x112 = 1.0
_x121 = 0.0
_x211 = 0.0
_x212 = 1.0
_x221 = 0.0
_y11 = 1.0
_y12 = 0.0
_y21 = 1.0
_y22 = 0.0
4

1 に答える 1

1

実際、これは答えではありません。これをコメントとして追加する予定でした。ただ、今は評判が50に達していないのでコメントは書けません。だから私はここで答えとしてそれを入れます。問題はあなたのプログラムにはないと思います。あなたのプログラムは問題ないはずです。ただし、環境変数または権限に問題がある可能性があります。pulp.pulpTestAll()うまく機能した場合、少なくともそのようなエラーは発生しないはずですcannot execute glpsol.exe。ただし、意図せずに一部の設定を変更して、この問題が発生する可能性があります。

だからここに役立つことがあります。プログラムが失敗した理由であるPuLPのこのコード ブロックを確認してください。

def executable(command):
    if os.path.isabs(command):
        if os.path.exists(command) and os.access(command, os.X_OK):
            return command
    for path in os.environ.get("PATH", []).split(os.pathsep):
        new_path = os.path.join(path, command)
        if os.path.exists(new_path) and os.access(new_path, os.X_OK):
            return os.path.join(path, command)
    return False
    executable = staticmethod(executable)

そのようなコマンドがファイルパスに存在するかどうか、アクセス許可があるかどうか、環境パスにあるかどうかなど、さまざまな理由があります。それぞれを手動で確認すると、プログラムが失敗した理由が確実にわかります。

于 2016-07-26T07:27:26.987 に答える