0

我尝试使用 Pulp 和 CoinMP.dll 建立一个简单的环境来解决线性规划问题。我不能让它工作。任何人都可以帮忙吗?

当我尝试在这里运行测试时,第一件事就是我所拥有的

求解器纸浆.solvers.PULP_CBC_CMD 不可用。求解器纸浆.solvers.CPLEX_DLL 不可用。求解器纸浆.solvers.CPLEX_CMD 不可用。求解器纸浆.solvers.CPLEX_PY 不可用。

Solver pulp.solvers.COIN_CMD unavailable.
         Testing zero subtraction
         Testing continuous LP solution
         Testing maximize continuous LP solution
         Testing unbounded continuous LP solution
                 Error in CoinMP it reports Optimal
         Testing Long Names
         Testing repeated Names Traceback (most recent call last):   File "<stdin>", line 1, in <module>   File "D:\Portable Python
2.7.5.1\app\lib\site-packages\pulp-1.5.4-py2.7.egg\pulp\pulp.py", line 2235, in pulpTestAll
    pulpTestSolver(s)   File "D:\Portable Python 2.7.5.1\app\lib\site-packages\pulp-1.5.4-py2.7.egg\pulp\tests.py", line 560, in pulpTestSol r
    t(solver(msg=msg))   File "D:\Portable Python 2.7.5.1\app\lib\site-packages\pulp-1.5.4-py2.7.egg\pulp\tests.py", line 170, in pulpTest014
    pulpTestCheck(prob, solver, [LpStatusOptimal], {x:4, y:-1, z:6, w:0})   File "D:\Portable Python
2.7.5.1\app\lib\site-packages\pulp-1.5.4-py2.7.egg\pulp\tests.py", line 17, in pulpTestChec
    prob.writeLP("debug.lp")   File "D:\Portable Python 2.7.5.1\app\lib\site-packages\pulp-1.5.4-py2.7.egg\pulp\pulp.py", line 1502, in writeLP
    + str(repeated_names)) pulp.constants.PulpError: Repeated variable names in Lp format [('x', 2)]
4

1 回答 1

0

好的,找到了问题。PulpTest014 抛出此异常。要修复它,COINMP_DLL 应该放在包含所有抛出异常的求解器的数组中(因为 COIN_CMD 已经是)

if solver.__class__ in [COIN_CMD, COINMP_DLL, PULP_CBC_CMD, CPLEX_CMD, CPLEX_PY,
        GLPK_CMD, GUROBI_CMD]:
    try:
        pulpTestCheck(prob, solver, [LpStatusOptimal], {x:4, y:-1, z:6, w:0})
    except PulpError:
        #these solvers should raise an error'
        pass

有了 TestAll 通过。

于 2013-11-13T14:44:00.077 回答