【发布时间】:2017-04-09 04:31:34
【问题描述】:
我正在尝试使用pulp 库为python 中的线性规划问题添加一个约束。我尝试了下面的代码。
for week in range(14,52), i in I.index:
k = week
model += sum(x[(i, j, week, B)] for week in range(k, k+13),
j in J.index) <= 1
其中 I 和 J 具有以下索引
I.index = ['A','B','C']
J.index = [1,2,3]
我得到的错误是SyntaxError: Generator expression must be parenthesized if not sole argument。我研究了这个链接
Generator expression must be parenthesized if not sole argument
但是它似乎并没有解决我的问题。任何帮助表示赞赏。
【问题讨论】:
-
Idk 纸浆,但我认为即使你的第一行也是错误的,因为它编译为类似:
for week in (range(14,52), i in I.index),所以你的 for 循环只是迭代 2 个元素,第一个是 @ 987654327@ generator(也许这是问题所在),第二个是 bool 语句(如 [1,2,3]==True 中的 1)
标签: python pandas mathematical-optimization linear-programming pulp