PulpSolverError Pulp:执行时出错
我正在尝试使用 PuLP 库解决线性规划问题。正确定义问题后,当我运行求解器(CBC)时,我收到一个非常奇怪的错误。
PulpSolverError:Pulp:执行 c:\users\hp\appdata\local\programs\python\python38\lib\site-packages\pulp\apis..\solverdir\cbc\win\64\cbc.exe 时出错
我不问题是什么,我想我已经碰壁了,因为我尝试了多种方法但没有成功。我还使用了以下链接,但它对我没有帮助,所以我想提出一个问题:- puLP求解器错误
我定义的问题如下: -
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']))
类似地为碳水化合物、蛋白质、维生素A创建了字典和其他组件。在每种情况下都使用完全相同的代码。
# 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"
定义所有这些后,当我运行求解器时,出现以下错误: -
prob.solve()
数据集快照如下: -
请告诉我此问题的解决方案。我已经尝试了所有的方法。提前致谢
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()
A snapshot of the data set is here follows: -
Please let me know the solution for this. I have tried all my ways. Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我也有同样的问题。首先卸载pulp并使用pip再次安装,以确保其安装正确
然后,检查用于模型的数据框或数据。就我而言,问题是由于某些列具有“无”或空值造成的。使用 dataframe.dropna() 删除它们修复了它
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