纸浆求解器错误,无法使用.solve()
我在使用 .solve() 解决 PuLP 问题时遇到困难。我收到错误:
PulpSolverError:Pulp:尝试执行时出错,使用 msg=True 获取更多详细信息cbc
我不知道如何纠正它。任何建议表示赞赏。
import pulp
import pandas as pd
solver_list = pulp.listSolvers()
#read in excel file
df = pd.read_excel (r'/Users/***/Desktop/diet.xls', sheet_name='Sheet1')
print (df)
#nested list from values
diet_data = df.values.tolist()
#list of foods
foods = [x[0] for x in diet_data]
#meats =
# Make dictionaries (key / value pairs) from the lists
# Key = food name
# Value = value
price = {x[0]:x[1] for x in diet_data}
cals = {x[0]:x[3] for x in diet_data}
cholesterol = {x[0]:x[4] for x in diet_data}
fat = {x[0]:x[5] for x in diet_data}
sodium = {x[0]:x[6] for x in diet_data}
carbs = {x[0]:x[7] for x in diet_data}
fiber = {x[0]:x[8] for x in diet_data}
protein = {x[0]:x[9] for x in diet_data}
vitA = {x[0]:x[10] for x in diet_data}
vitC = {x[0]:x[11] for x in diet_data}
calcium= {x[0]:x[12] for x in diet_data}
iron = {x[0]:x[13] for x in diet_data}
#creating optimization problem
prob = pulp.LpProblem("DietProblem", pulp.LpMinimize)
# Creating the variables
lp_variables = pulp.LpVariable.dicts( "Amounts", foods, 0 )
# Creating objective function
# objective function
prob += pulp.lpSum(price[i] * lp_variables[i] for i in foods)
# min 1500 cals
prob += pulp.lpSum(cals[i] * lp_variables[i] for i in foods) >= 1500
# max 2500 cals
prob += pulp.lpSum(cals[i] * lp_variables[i] for i in foods) <= 2500
# min 30g chol
prob += pulp.lpSum(cholesterol[i] * lp_variables[i] for i in foods) >= 30
# max 240g chol
prob += pulp.lpSum(cholesterol[i] * lp_variables[i] for i in foods) <= 240
solution = prob.solve()
I'm having difficulty with .solve() for my PuLP problem. I'm receiving the error:
PulpSolverError: Pulp: Error while trying to execute, use msg=True for more detailscbc
I'm not sure how to correct it. Any advice is appreciated.
import pulp
import pandas as pd
solver_list = pulp.listSolvers()
#read in excel file
df = pd.read_excel (r'/Users/***/Desktop/diet.xls', sheet_name='Sheet1')
print (df)
#nested list from values
diet_data = df.values.tolist()
#list of foods
foods = [x[0] for x in diet_data]
#meats =
# Make dictionaries (key / value pairs) from the lists
# Key = food name
# Value = value
price = {x[0]:x[1] for x in diet_data}
cals = {x[0]:x[3] for x in diet_data}
cholesterol = {x[0]:x[4] for x in diet_data}
fat = {x[0]:x[5] for x in diet_data}
sodium = {x[0]:x[6] for x in diet_data}
carbs = {x[0]:x[7] for x in diet_data}
fiber = {x[0]:x[8] for x in diet_data}
protein = {x[0]:x[9] for x in diet_data}
vitA = {x[0]:x[10] for x in diet_data}
vitC = {x[0]:x[11] for x in diet_data}
calcium= {x[0]:x[12] for x in diet_data}
iron = {x[0]:x[13] for x in diet_data}
#creating optimization problem
prob = pulp.LpProblem("DietProblem", pulp.LpMinimize)
# Creating the variables
lp_variables = pulp.LpVariable.dicts( "Amounts", foods, 0 )
# Creating objective function
# objective function
prob += pulp.lpSum(price[i] * lp_variables[i] for i in foods)
# min 1500 cals
prob += pulp.lpSum(cals[i] * lp_variables[i] for i in foods) >= 1500
# max 2500 cals
prob += pulp.lpSum(cals[i] * lp_variables[i] for i in foods) <= 2500
# min 30g chol
prob += pulp.lpSum(cholesterol[i] * lp_variables[i] for i in foods) >= 30
# max 240g chol
prob += pulp.lpSum(cholesterol[i] * lp_variables[i] for i in foods) <= 240
solution = prob.solve()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论