简体   繁体   中英

(Python, Gurobi) TypeError: expected string or Unicode object, list found

I'm using Gurobi from Python. For this segment of code:

    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))])

I'm getting this error:

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

Although the same syntax isused in Gurobi examples document page 475. Any explanation? Thanks!

["X"+str((l,i,j))]

is a list with one string element. Probably you want just "X"+str((l,i,j))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM