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
Add a comment  | 

1 Answer 1

Reset to default 0

Your 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