File "E:\python\建模\.venv\Lib\site-packages\pulp\apis\coin_api.py", line 112, in actualSolve
return self.solve_CBC(lp, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\python\建模\.venv\Lib\site-packages\pulp\apis\coin_api.py", line 188, in solve_CBC
raise PulpSolverError("Pulp: Error while executing " + self.path)
pulp.apis.core.PulpSolverError: Pulp: Error while executing E:\python\建模\.venv\Lib\site-packages\pulp\solverdir\cbc\win\64\cbc.exe
咋一看好像是cbc解释器错误,所以可以重新安装看看是不是解释器的问题
pip install cbc
如果还不行,可以试试下述代码查看是哪个位置出了问题
pulpTestAll()
如果依旧不行,就回到源码中去,这里其实是float("inf")报错,推测原因是CBC解释器识别不了(个人推测),总之LpVariable上下限已经给出就是无穷,不必画蛇添足加这一步
import pulp as p
# pulpTestAll()
# pulp.CBC_PATH = "e:\python\建模\.venv\lib\site-packages"
LP = p.LpProblem("problem1", sense=p.LpMaximize)
x1 = p.LpVariable("x1", 0, float("inf"), cat="LpContinuous")
x2 = p.LpVariable("x2", 0, float("inf"), cat="LpContinuous")
x3 = p.LpVariable("x3", 0, float("inf"), cat="LpContinuous")
# 已找到问题,不能使用float("inf")这个正无穷,会报错, cat默认连续形
LP += 1000 * x1 + 2000 * x2 + 3000 * x3
LP += (x1 + x2 * 2 + x3 * 3 <= 10)
LP += (x2 + x3 * 2 <= 5)
LP.solve()
print("Status:", p.LpStatus[LP.status])
因为没有blog做过这个报错,所以我给一个补充嘞
标签:cbc,python,float,报错,inf,pulp From: https://blog.csdn.net/2302_79349465/article/details/139874384