Key
Key

Reputation: 45

PulpSolverError Pulp: Error while executing

I am trying to solve a Linear programming problem by using the PuLP library. After defining the problem correctly, when I run the solver (CBC) I get a very strange error.

PulpSolverError: Pulp: Error while executing c:\users\hp\appdata\local\programs\python\python38\lib\site-packages\pulp\apis..\solverdir\cbc\win\64\cbc.exe

I do not what is the issue, and I think I have hit the wall as I have tried several ways without any success. I also used the following link but it did not help me so I thought to pose it a question: - puLP solver error

The problem defined by me is as follows: -

prob = LpProblem('Diet_Problem', LpMinimize)

#Using only the first 17 rows in the data set

df = pd.read_excel('diet.xls',nrows=17)

food = list(df.Foods)

#Create a dictionary of calories for all items of food
calories = dict(zip(food,df['Calories']))

Similarly created dictionaries for Carbohydrates, proteins, vitamin_A and other components. Exact similar code was used in each case.

# A dictionary called 'food_vars' is created to contain the referenced Variables
food_vars = LpVariable.dicts("Food",food,lowBound=0,cat='Continuous')

#Defined the objective function in the problem
prob += lpSum([costs[i]*food_vars[i] for i in food])

#Defined the constraints and added to the problem
prob += lpSum([food_vars[x]*calories[x] for x in food]) >= 800, "CaloriesMinimum"
prob += lpSum([food_vars[x]*calories[x] for x in food]) <= 1300, "CaloriesMaximum"

After defining all this, when I run the solver I get following error: -

prob.solve()

enter image description here

A snapshot of the data set is here follows: -

enter image description here

Please let me know the solution for this. I have tried all my ways. Thanks in advance

Upvotes: 1

Views: 4974

Answers (1)

Elkary
Elkary

Reputation: 11

I had the same problem. First uninstall pulp and install it again using pip, to make sure it is installed correctly

Then, check your dataframes or data used for the model. In my case, the problem was due to some columns with 'None' or empty values. Removing them using dataframe.dropna() fixed it

Upvotes: 1

Related Questions