(Python, Gurobi) TypeError: expected string or Unicode object, list found
(Python, Gurobi) TypeError: expected string or Unicode object, list found
我正在使用来自 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 页。任何解释?谢谢!
["X"+str((l,i,j))]
是一个包含一个字符串元素的列表。可能你只想要 "X"+str((l,i,j))
我正在使用来自 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 页。任何解释?谢谢!
["X"+str((l,i,j))]
是一个包含一个字符串元素的列表。可能你只想要 "X"+str((l,i,j))