我正在使用Python的Gurobi。对于这段代码:
Xlij = {}
for i in self.init.getNodes() - self.init.getActiveNodes():
for l in self.init.getL():
for j in self.init.getNeighbors(i, l):
Xlij[l,i,j] = model.addVar(vtype=GRB.BINARY, name=["X"+str((l,i,j))])
我收到此错误:
File "C:\Python27\My sim\Solutiongrb.py", line 34, in run
vars[l,i,j] = model.addVar(vtype=GRB.BINARY, name=["X"+str((l,i,j))])
File "model.pxi", line 2038, in gurobipy.Model.addVar (../../src/python/gurobipy.c:63880)
TypeError: expected string or Unicode object, list found
尽管在Gurobi示例document第475页中使用了相同的语法。任何解释?谢谢!
答案 0 :(得分:0)
["X"+str((l,i,j))]
是一个包含一个字符串元素的列表。可能你只想要"X"+str((l,i,j))