[Python] PuLP Solvers Not Available

Discussão em 'Python' iniciado por Stack, Fevereiro 23, 2025.

  1. Stack

    Stack Membro Participativo

    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

    Continue reading...

Compartilhe esta Página