1

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

Key
  • 45
  • 1
  • 6
  • something is screwy with your installation of CBC. CBC is included in the `pulp` install. Why don't you try to re-install pulp, log out, log back in and try again. – AirSquid Feb 28 '22 at 21:49
  • What do you mean by logging out? I got the uninstall part "pip uninstall pulp" Is this the code right? – Key Mar 01 '22 at 05:25
  • I mean literally log out or restart your computer. :) Anytime you install something that might affect the environment variables (like the solver) sometimes a reset is needed to register the changed env. variables. – AirSquid Mar 01 '22 at 16:11
  • 1
    you seam to be using jupyter notebooks, did you take a look at this? https://coin-or.github.io/pulp/guides/how_to_debug.html#jupyter-notebooks-anaconda-conda-issues – pchtsp Mar 04 '22 at 22:49

0 Answers0