admin管理员组文章数量:1287820
I am running an LP using pulp but getting the error AttributeError: 'NoneType' object has no attribute 'actualSolve'.
So I found this post on determining the solvers that are available. This directed me to try the code below.
import pulp
print(pulp.listSolvers())
print(pulp.listSolvers(onlyAvailable=True))
The first print statement gives me a list of solver, but the second statement gives me an empty list. []
I also uninstalled pulp with pip uninstall pulp
and then reinstalled it. Next I found this page and tried to install the solver directly with solver = pl.getSolver('CPLEX_CMD')
. I did this all in VS Code.
Then, just to see if I was just crazy I tried by LP in Google Colab and it worked no problem. What am I missing so that it works in one IDE but not in another?
Below is the code for my LP:
from pulp import LpProblem, LpMinimize, LpVariable, LpConstraint, lpSum, value
# Define the problem
prob = LpProblem("Minimize_Operating_Cost", LpMinimize)
# Define decision variables
x1 = LpVariable("Hours_Facility_1", lowBound=0)
x2 = LpVariable("Hours_Facility_2", lowBound=0)
# Objective function: Minimize cost
prob += 120 * x1 + 220 * x2, "Total_Cost"
# Constraints
prob += 300 * x1 + 350 * x2 >= 4500, "Regular_Detergent_Constraint"
prob += 220 * x1 + 450 * x2 >= 5200, "Concentrate_Detergent_Constraint"
# Solve the problem
prob.solve()
# Extract results
x1_opt = value(x1)
x2_opt = value(x2)
min_cost = value(prob.objective)
#
# Display results
x1_opt, x2_opt, min_cost
I am running an LP using pulp but getting the error AttributeError: 'NoneType' object has no attribute 'actualSolve'.
So I found this post on determining the solvers that are available. This directed me to try the code below.
import pulp
print(pulp.listSolvers())
print(pulp.listSolvers(onlyAvailable=True))
The first print statement gives me a list of solver, but the second statement gives me an empty list. []
I also uninstalled pulp with pip uninstall pulp
and then reinstalled it. Next I found this page and tried to install the solver directly with solver = pl.getSolver('CPLEX_CMD')
. I did this all in VS Code.
Then, just to see if I was just crazy I tried by LP in Google Colab and it worked no problem. What am I missing so that it works in one IDE but not in another?
Below is the code for my LP:
from pulp import LpProblem, LpMinimize, LpVariable, LpConstraint, lpSum, value
# Define the problem
prob = LpProblem("Minimize_Operating_Cost", LpMinimize)
# Define decision variables
x1 = LpVariable("Hours_Facility_1", lowBound=0)
x2 = LpVariable("Hours_Facility_2", lowBound=0)
# Objective function: Minimize cost
prob += 120 * x1 + 220 * x2, "Total_Cost"
# Constraints
prob += 300 * x1 + 350 * x2 >= 4500, "Regular_Detergent_Constraint"
prob += 220 * x1 + 450 * x2 >= 5200, "Concentrate_Detergent_Constraint"
# Solve the problem
prob.solve()
# Extract results
x1_opt = value(x1)
x2_opt = value(x2)
min_cost = value(prob.objective)
#
# Display results
x1_opt, x2_opt, min_cost
Share
Improve this question
asked Feb 23 at 7:17
gunsnfloydgunsnfloyd
716 bronze badges
1 Answer
Reset to default 0Your problem is most likely caused by missing solvers. Installing CBC and verifying that PuLP can detect it should resolve the issue. can verify by
which cbc # Linux/macOS
where cbc # Windows
Google Colab works because it comes pre-installed with solvers like CBC. on local you will need to install it first
You can download and install CBC manually from COIN-OR, or install it via conda:
conda install -c conda-fe coincbc
本文标签: pythonPuLP Solvers Not AvailableStack Overflow
版权声明:本文标题:python - PuLP Solvers Not Available - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741318646a2372073.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论