我正在pyomo中运行一个模型,该模型存在错误:
模型构造为:
from __future__ import division
from pyomo.environ import *
from sys import *
model = AbstractModel()
# Sets
model.Vo = Set() #
model.Vf = Set() #
model.Vc = Set() #
model.Vfc = model.Vf | model.Vc #
model.V = model.Vo | model.Vf | model.Vc # set of nodes
我想在这里用
创建一个布尔变量# Variables
model.x_ijl = Var(model.V, model.V, model.K, within=Boolean) # x_ijl= 1 iff l in K uses arc (i,j) in A #
.dat文件是:
set Vo := 0;
set Vf := 1 2;
set Vc := 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19;
但是它抱怨在使用x_ijl的目标和约束上都有错误:
对象错误:
ERROR: evaluating object as numeric value: ...
缺点:
ERROR: evaluating expression: No value for uninitialized NumericValue object
将x_ijl初始化为零或一,对我来说没有意义,因为它是一个布尔变量。
有人可以帮我找出最好的方法吗?
编辑:这是回溯:
Objectives:
obj : Size=1, Index=None, Active=True
ERROR: evaluating expression: No value for uninitialized NumericValue object
x_ijl[0,5,1]
(expression: 67*x_ijl[0,5,1] + 67*x_ijl[0,5,2] + 67*x_ijl[0,5,3] +
67*x_ijl[0,5,4] + 70*x_ijl[0,6,1] + 70*x_ijl[0,6,2] + 70*x_ijl[0,6,3]
+ 70*x_ijl[0,6,4] + 70*x_ijl[0,7,1] + 70*x_ijl[0,7,2] +
70*x_ijl[0,7,3] + 70*x_ijl[0,7,4] + 81*x_ijl[0,10,1] +
81*x_ijl[0,10,2] + 81*x_ijl[0,10,3] + 81*x_ijl[0,10,4] +
73*x_ijl[1,5,1] + 73*x_ijl[1,5,2] + 73*x_ijl[1,5,3] + 73*x_ijl[1,5,4]
+ 63*x_ijl[1,6,1] + 63*x_ijl[1,6,2] + 63*x_ijl[1,6,3] +
63*x_ijl[1,6,4] + 69*x_ijl[1,7,1] + 69*x_ijl[1,7,2] + 69*x_ijl[1,7,3]
+ 69*x_ijl[1,7,4] + 75*x_ijl[1,10,1] + 75*x_ijl[1,10,2] +
75*x_ijl[1,10,3] + 75*x_ijl[1,10,4] + 95*x_ijl[1,11,1] +
95*x_ijl[1,11,2] + 95*x_ijl[1,11,3] + 95*x_ijl[1,11,4] +
66*x_ijl[2,6,1] + 66*x_ijl[2,6,2] + 66*x_ijl[2,6,3] + 66*x_ijl[2,6,4]
+ 80*x_ijl[2,7,1] + 80*x_ijl[2,7,2] + 80*x_ijl[2,7,3] +
80*x_ijl[2,7,4] + 73*x_ijl[2,8,1] + 73*x_ijl[2,8,2] + 73*x_ijl[2,8,3]
+ 73*x_ijl[2,8,4] + 85*x_ijl[2,11,1] + 85*x_ijl[2,11,2] +
...
...
ERROR: evaluating expression: No value for uninitialized NumericValue object
x_ijl[0,8,4]
(expression: x_ijl[0,8,4] + x_ijl[1,8,4] + x_ijl[2,8,4] + x_ijl[3,8,4]
+ x_ijl[4,8,4] + x_ijl[5,8,4] + x_ijl[6,8,4] + x_ijl[7,8,4] +
x_ijl[8,8,4] + x_ijl[9,8,4] + x_ijl[10,8,4] + x_ijl[11,8,4] +
x_ijl[12,8,4] + x_ijl[13,8,4] + x_ijl[14,8,4] + x_ijl[15,8,4] +
x_ijl[16,8,4] + x_ijl[17,8,4] + x_ijl[18,8,4] + x_ijl[19,8,4] -
x_ijl[8,0,4] - x_ijl[8,1,4] - x_ijl[8,2,4] - x_ijl[8,3,4] -
x_ijl[8,4,4] - x_ijl[8,5,4] - x_ijl[8,6,4] - x_ijl[8,7,4] -
x_ijl[8,8,4] - x_ijl[8,9,4] - x_ijl[8,10,4] - x_ijl[8,11,4] -
x_ijl[8,12,4] - x_ijl[8,13,4] - x_ijl[8,14,4] - x_ijl[8,15,4] -
x_ijl[8,16,4] - x_ijl[8,17,4] - x_ijl[8,18,4] - x_ijl[8,19,4])
Key : Lower : Body : Upper
...
...
Traceback (most recent call last):
File "main.py", line 17, in <module>
instance.display()
File "/usr/local/lib/python2.7/dist-packages/pyomo/core/base/block.py", line 1890, in display
Block.display(self, filename, ostream, prefix)
File "/usr/local/lib/python2.7/dist-packages/pyomo/core/base/block.py", line 1870, in display
_BlockData.display(self[key], filename, ostream, prefix)
File "/usr/local/lib/python2.7/dist-packages/pyomo/core/base/block.py", line 1621, in display
obj.display(prefix=prefix + " ", ostream=ostream)
File "/usr/local/lib/python2.7/dist-packages/pyomo/core/base/constraint.py", line 843, in display
lambda k, v: [ value(v.lower),
File "/usr/local/lib/python2.7/dist-packages/pyomo/core/base/misc.py", line 245, in tabular_writer
+ "\n")
File "/usr/local/lib/python2.7/dist-packages/pyomo/core/base/misc.py", line 244, in <genexpr>
+ " : ".join( _width[i] % x for i,x in enumerate(_data) )
TypeError: not all arguments converted during string formatting