Getting TypeError: zip argument #1 must support iteration

1,241 views
Skip to first unread message

nooshin valibeig

unread,
Jul 8, 2014, 5:07:34 PM7/8/14
to gur...@googlegroups.com
Hi Everyone 

I have modeled an optimization problem in Gurobi-Python, for one of my constraints I have got the below error. How can resolve this error?

CONSTRAINT:
for p in person:
        m.addConstr(quicksum((regAssign[time[t],p]  + irregAssign[time[t],p]) for t in range(startTime[p]-1,startTime[p] + lengthOfTime[p] + 1)) <= lengthOfTime[p] + 1, 'not more than LOT+1 %s' % p)

ERROR:
Traceback (most recent call last):
  File "<string>", line 254, in run_nodebug
  File "C:\Working Project1\SimulatedDataForModel.py", line 102, in <module>
    ConnectingTwoFiles.solve(time, person, startTime, lengthOfTime, regular , irregular )
  File "C:\Working Project1\ConnectingTwoFiles.py", line 50, in solve
    m.addConstr(quicksum((regAssign[time[t],p]  + irregAssign[time[t],p]) for t in range(startTime[p]-1,startTime[p] + lengthOfTime[p] + 1)) <= lengthOfTime[p] + 1, 'not more than LOT+1 %s' % p)
  File "var.pxi", line 253, in gurobipy.Var.__radd__ (../../src/python/gurobipy.c:9499)
  File "exprutil.pxi", line 15, in gurobipy.__exprsum (../../src/python/gurobipy.c:27792)
  File "linexpr.pxi", line 37, in gurobipy.LinExpr.__init__ (../../src/python/gurobipy.c:16485)
TypeError: zip argument #1 must support iteration




Thanks,
Nooshin

Jakob Sch.

unread,
Jul 9, 2014, 8:46:37 AM7/9/14
to gur...@googlegroups.com
Hi Nooshin,

My first guess would be that you do not use quicksum() correctly. It should be called with a list of terms. Try
for p in person:
        m.addConstr(quicksum([regAssign[time[t],p]  + irregAssign[time[t],p] for t in range(startTime[p]-1,startTime[p] + lengthOfTime[p] + 1)]) <= lengthOfTime[p] + 1, 'not more than LOT+1 %s' % p)

Best regards,
Jakob
Reply all
Reply to author
Forward
0 new messages