Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.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)值错误:需要超过1个值才能解包_Python_Python 2.7_Pulp - Fatal编程技术网

纸浆(Python)值错误:需要超过1个值才能解包

纸浆(Python)值错误:需要超过1个值才能解包,python,python-2.7,pulp,Python,Python 2.7,Pulp,我试图在Python上使用纸浆解决这个问题 这是我的代码: from pulp import * # Create the 'prob' variable to contain the problem data prob = LpProblem("The Bus Problem",LpMinimize) # The variables are created with a lower limit of zero x0=LpVariable("Number of drivers at time

我试图在Python上使用纸浆解决这个问题

这是我的代码:

from pulp import *

# Create the 'prob' variable to contain the problem data
prob = LpProblem("The Bus Problem",LpMinimize)

# The variables are created with a lower limit of zero
x0=LpVariable("Number of drivers at time 0",0,None,LpInteger)
x4=LpVariable("Number of drivers at time 4",0)
x8=LpVariable("Number of drivers at time 8",0)
x12=LpVariable("Number of drivers at time 12",0)
x16=LpVariable("Number of drivers at time 16",0)
x20=LpVariable("Number of drivers at time 20",0)

# The objective function is added to 'prob' first
prob += x0 + x4 + x8 + x12 + x16 + x20, "drivers"

# The five constraints are entered
prob += x0 + x4 >= 8, 
prob += x4 + x8 >= 10, 
prob += x8 + x12 >= 7, 
prob += x12 + x16 >= 12,
prob += x16 + x20 >= 4,

# The problem data is written to an .lp file
prob.writeLP("BusModel.lp")

# The problem is solved using PuLP's choice of Solver
prob.solve()
但是,当我运行此命令时,会出现以下错误:

文件“C:\Users\uuuu\Anaconda2\lib\site packages\pulp\pulp.py”,第1337行,位于iadd other,name=other

ValueError:需要超过1个值才能解包

当我去看plup.py时,代码中是这样说的:

def __iadd__(self, other):
        if isinstance(other, tuple):
            other, name = other
        else:
            name = None
        if other is True:
            return self
        if isinstance(other, LpConstraintVar):
            self.addConstraint(other.constraint)
        elif isinstance(other, LpConstraint):
            self.addConstraint(other, name)
        elif isinstance(other, LpAffineExpression):
            if self.objective is not None:
                warnings.warn("Overwriting previously set objective.")
            self.objective = other
            self.objective.name = name
        elif isinstance(other, LpVariable) or isinstance(other, (int, float)):
            if self.objective is not None:
                warnings.warn("Overwriting previously set objective.")
            self.objective = LpAffineExpression(other)
            self.objective.name = name
        else:
            raise TypeError("Can only add LpConstraintVar, LpConstraint, LpAffineExpression or True objects")
        return self
有人能看到任何明显的问题吗?谢谢

您正在此处添加单元素元组:

逗号使每个表达式成为一个包含一个元素的元组。删除逗号(将其留给
\uuu iadd\uuuu
方法将名称设置为
None
),或者在每个逗号后提供一个name元素。

您正在此处添加单元素元组:


逗号使每个表达式成为一个包含一个元素的元组。删除逗号(将其留给
\uuu iadd\uuu
方法将名称设置为
None
),或者在每个逗号后提供一个name元素。

Wow,只需删除逗号即可。非常感谢!哇,就像去掉逗号一样简单。非常感谢!
prob += x0 + x4 >= 8, 
prob += x4 + x8 >= 10, 
prob += x8 + x12 >= 7, 
prob += x12 + x16 >= 12,
prob += x16 + x20 >= 4,