Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.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 3.x 索引器:约束';Rest1';:无法使用单个表达式初始化约束的多个索引_Python 3.x_Constraints_Pyomo - Fatal编程技术网

Python 3.x 索引器:约束';Rest1';:无法使用单个表达式初始化约束的多个索引

Python 3.x 索引器:约束';Rest1';:无法使用单个表达式初始化约束的多个索引,python-3.x,constraints,pyomo,Python 3.x,Constraints,Pyomo,请我需要帮助的手来解决上述错误,我作为我的标题张贴。我是pyomo的新手。我最近在关注这个链接: . 在MadridALNS.py中,所有操作都完全符合创建约束的位置: #2 // arrival flow to each destination "wd" equal to demand of the destination origin pair "w" def resd1_rule(model,w): wo=model.tabla[w,'wo'] e

请我需要帮助的手来解决上述错误,我作为我的标题张贴。我是pyomo的新手。我最近在关注这个链接: . 在MadridALNS.py中,所有操作都完全符合创建约束的位置:

#2 // arrival flow to each destination "wd" equal to demand of the destination origin pair "w"

    def resd1_rule(model,w):
        wo=model.tabla[w,'wo']
        expr=0
        for l in model.L:
            if model.b[wo,l]==1:
                expr += model.fo[w,l]
        if expr!=0:
                return (expr + model.h[w]==model.tabla[w,'g']*model.factorg)
        else:
                return Constraint.Skip
    model.restr1 = Constraint(model.W,expr=resd1_rule)
这是我运行代码时遇到的错误:

ERROR: Constructing component 'restr1' from data=None failed:
    IndexError: Constraint 'restr1': Cannot initialize multiple indices of
    a constraint with a single expression
Traceback (most recent call last):
   File "ALNS.py", line 16, in <module>
   instance = model.create_instance('madridALNS.dat')
   File "/usr/local/lib/python3.5/dist-packages/pyomo/core/base/PyomoModel.py", line 723, in create_instance
   profile_memory=profile_memory )
   File "/usr/local/lib/python3.5/dist-packages/pyomo/core/base/PyomoModel.py", line 806, in load
   profile_memory=profile_memory)
   File "/usr/local/lib/python3.5/dist-packages/pyomo/core/base/PyomoModel.py", line 870, in _load_model_data
   self._initialize_component(modeldata, namespaces, component_name, profile_memory)
  File "/usr/local/lib/python3.5/dist-packages/pyomo/core/base/PyomoModel.py", line 925, in _initialize_component
  declaration.construct(data)
   File "/usr/local/lib/python3.5/dist-packages/pyomo/core/base/constraint.py", line 786, in construct
   (self.name,) )
  IndexError: Constraint 'restr1': Cannot initialize multiple indices of a constraint with a single expression
错误:从数据构建组件“rest1”=None失败:
索引器错误:约束“rest1”:无法初始化的多个索引
具有单个表达式的约束
回溯(最近一次呼叫最后一次):
文件“ALNS.py”,第16行,在
instance=model.create_实例('madridALNS.dat')
文件“/usr/local/lib/python3.5/dist packages/pyomo/core/base/pyomodel.py”,第723行,在create_实例中
配置文件\内存=配置文件\内存)
加载文件“/usr/local/lib/python3.5/dist-packages/pyomo/core/base/pyomodel.py”,第806行
配置文件\内存=配置文件\内存)
文件“/usr/local/lib/python3.5/dist packages/pyomo/core/base/pyomodel.py”,第870行,在加载模型数据中
self.\初始化\组件(模型数据、名称空间、组件\名称、配置文件\内存)
文件“/usr/local/lib/python3.5/dist packages/pyomo/core/base/pyomodel.py”,第925行,在初始化组件中
声明.构造(数据)
文件“/usr/local/lib/python3.5/dist-packages/pyomo/core/base/constraint.py”,第786行,在构造中
(self.name,))
索引器错误:约束“rest1”:无法使用单个表达式初始化约束的多个索引

文件可以在这里找到参数
expr=
用于单个非索引表达式。你应该试试
rule=resid1\u rule

我很荣幸得到你的回复。当我改用“rule=resid1_rule”时,我立即遇到以下错误消息:“ValueError:No value for uninitialized NumericValue object fo[1,1_C1]”。我不明白我为什么会犯那个错误。提前感谢您在这里遇到了一个不同的问题,但这意味着出于某种原因,当程序的值为
None
时,程序试图访问
值(fo[1,1\u C1])
。我必须查看堆栈跟踪才能说得更多。根据您的回复,我越来越接近于理解错误,但我的问题是如何修复它。我将通过添加第二个错误的堆栈跟踪来编辑问题,以便您可以查看它。再次感谢您的回复!您也可以简单地打开一个新的StackOverflow问题。我不认为回答你的问题就是为了这个目的。我刚刚提出了一个新的问题。你可以看看。提前谢谢