GurobiError Invalid argument to linExpr multiplication

1,437 views
Skip to first unread message

Helen Gao

unread,
Mar 3, 2014, 2:50:04 PM3/3/14
to gur...@googlegroups.com
I use Gurobi and Python to make a optimization, but I have an error that Invalid argument to linExpr multiplication.

Here are constraints that I have. 

m.addConstr(quicksum (y for j in nodes if (j=='Detroit'or j== 'Denver'))<= (demand for  i in range(len(demand)) if (0<=i<=1)), "c0")

m.addConstr(-(quicksum(y for j in nodes if(j=='Boston' or j=='New York' or j=='Seattle'))) == (demand for j in range(len(demand)) if( j>3 and j<=6)), "c2")

m.addConstr(quicksum(y for i in nodes for j in nodes if( j!='Boston' and j!='New York' and j!='Seattle'))<=((1-a for i in range(len(a)) if i<=3)*(k for j in range(len(k)) if j<=3 )*( x for m in nods if(m!='Boston' and m!='New York' and m!='Seattle')) ), "c3" )

m.addConstr((y for i, j in nodes) >=0, "c5")

Jakob Sch.

unread,
Mar 3, 2014, 3:49:58 PM3/3/14
to gur...@googlegroups.com
Hi Helen,

Your code is a bit confusing. I think you are making a mistake with the statement "y for j in nodes" as python surely does not know what y is unless you specified it before. My guess is that you want something like "y[j]" or "j.y" depending on how you declared your stuff. Note that python is not a modeling language but a full programming language. If you are coming from a background with only modeling language experience (GAMS et al) you will have to do some extra work to get your models right (but it is just a bit of effort and python gets you a ton of third party libraries and out-of-the-box functionality that a modeling language can not offer).

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