Pyomo: ValueError: Constraint 'VehicleNumCapRule' does not have a proper value. Found '<function vehicle_num_cap_rule at 0x7f0d6cfd4c80>'

Pyomo: ValueError: Constraint 'VehicleNumCapRule' does not have a proper value. Found '<function vehicle_num_cap_rule at 0x7f0d6cfd4c80>'

同样,作为一个 pyomo 爱好者和 python 的热心爱好者,我试图在 pyomo 中编写随时间 windows (vrptw) 的车辆路径问题。我将 time_window 参数创建为:

model.time_windows = Param(model.V)     # model.V is the set of nodes

在我的.dat文件中,我声明的参数如下:

param Time_windows: a b :=

0   1400 1500
1   0000 2400
2   0000 2400
3   0700 2400
4   0000 2400
5   0000 0700
6   0700 2400
7   0700 2400
8   0000 0700
9   0000 2400
10  0000 2400
11  0000 2400
12  0700 2400
13  0000 2400
14  0000 0700
15  0000 0800
16  0000 2400
17  0000 2400
18  0700 1200
19  0000 2400
;

但是,当我 运行 我的脚本时,我陷入了这个错误:

ERROR: Constructing component 'time_windows' from data={(9, 'a'): 0, (18,
'b'): 1200, (13, 'b'): 2400, (17, 'a'): 0, (6, 'a'): 700, (2, 'a'): 0,
(19, 'b'): 2400, (4, 'b'): 2400, (14, 'b'): 700, (10, 'a'): 0, (12, 'b'):
2400, (18, 'a'): 700, (1, 'b'): 2400, (3, 'a'): 700, (9, 'b'): 2400, (11,
'a'): 0, (17, 'b'): 2400, (14, 'a'): 0, (0, 'b'): 1500, (4, 'a'): 0, (12,
'a'): 700, (8, 'b'): 700, (3, 'b'): 2400, (7, 'b'): 2400, (16, 'b'): 2400,
(15, 'a'): 0, (11, 'b'): 2400, (6, 'b'): 2400, (5, 'a'): 0, (13, 'a'): 0,
(0, 'a'): 1400, (15, 'b'): 800, (8, 'a'): 0, (7, 'a'): 700, (16, 'a'): 0,
(2, 'b'): 2400, (19, 'a'): 0, (1, 'a'): 0, (10, 'b'): 2400, (5, 'b'): 700}
failed:
    RuntimeError: Failed to set value for param=time_windows, index=(9,
    'a'), value=0.
    source error message="Index '(9, 'a')' is not valid for indexed component
    'time_windows'"
Traceback (most recent call last):
  File "main.py", line 16, in <module>
instance = model.create_instance('data.dat')
  File "/usr/local/lib/python2.7/dist-packages/pyomo/core/base/PyomoModel.py", line 723, in create_instance
profile_memory=profile_memory )
  File "/usr/local/lib/python2.7/dist-packages/pyomo/core/base/PyomoModel.py", line 806, in load
profile_memory=profile_memory)
  File "/usr/local/lib/python2.7/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/python2.7/dist-packages/pyomo/core/base/PyomoModel.py", line 925, in _initialize_component
declaration.construct(data)
  File "/usr/local/lib/python2.7/dist-packages/pyomo/core/base/param.py", line 858, in construct
% (self.name, str(key), str(val), str(msg)) )
RuntimeError: Failed to set value for param=time_windows, index=(9, 'a'), value=0.
source error message="Index '(9, 'a')' is not valid for indexed component 'time_windows'"

谁能告诉我发生了什么事。提前致谢

编辑:这是包含 model.V

的部分
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

在 .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;

您的示例代码尝试使用二维数据初始化一维 model.time_windows 参数。

model.time_windows = Param(model.V, ['a', 'b']) 应该可以。