Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/343.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在python中求解LPP时出错_Python_Pulp - Fatal编程技术网

在python中求解LPP时出错

在python中求解LPP时出错,python,pulp,Python,Pulp,我用于求解LPP的脚本如下: 脚本: # Import PuLP modeler functions from pulp import * # Create the 'prob' variable to contain the problem data prob = LpProblem("The Whiskas Problem",LpMinimize) LpVariable("example", None, 100) # The 2 variables Beef and Chicken are

我用于求解
LPP
的脚本如下:

脚本:

# Import PuLP modeler functions
from pulp import *
# Create the 'prob' variable to contain the problem data
prob = LpProblem("The Whiskas Problem",LpMinimize)
LpVariable("example", None, 100)
# The 2 variables Beef and Chicken are created with a lower limit of zero
x1=LpVariable("ChickenPercent",0,None,LpInteger)
x2=LpVariable("BeefPercent",0)
# The objective function is added to 'prob' first
prob += 0.013*x1 + 0.008*x2, "Total Cost of Ingredients per can"
# The five constraints are entered
prob += x1 + x2 == 100, "PercentagesSum"
prob += 0.100*x1 + 0.200*x2 >= 8.0, "ProteinRequirement"
prob += 0.080*x1 + 0.100*x2 >= 6.0, "FatRequirement"
prob += 0.001*x1 + 0.005*x2 <= 2.0, "FibreRequirement"
prob += 0.002*x1 + 0.005*x2 <= 0.4, "SaltRequirement"
# The problem data is written to an .lp file
prob.writeLP("WhiskasModel.lp")
# The problem is solved using PuLP's choice of Solver
prob.solve()
# The status of the solution is printed to the screen
print( "\n", "Status:", LpStatus[prob.status],"\n")
# Each of the variables is printed with it's resolved optimum value
for v in prob.variables():
print( v.name, "=", v.varValue)
# The optimised objective function value is printed to the screen
print ("Total Cost of Ingredients per can = ", value(prob.objective))

您尚未安装
纸浆

确保您已运行以下任一操作:

pip install pulp

基于您在Jupyter或iPython笔记本中运行的任何Python内核版本。如果已设置虚拟环境,请确保已在虚拟环境中运行Jupyter安装

此外,您的系统中可能缺少一些基本依赖项。要检查是否已正确设置所有内容,请运行:

>>> import pulp
>>> pulp.pulpTestAll()

您应该看到缺失的依赖项(如果有)列表,这些依赖项可能会阻止模块的安装/导入

呃。。。请确保使用
pip install-pulp
安装此模块,例如。。。(可以在python安装中找到pip)错误非常明显。需要给朱皮特吗?
pip3 install pulp 
>>> import pulp
>>> pulp.pulpTestAll()