Does Gurobi has something similar to the exists() function in Xpress/Morsel

24 views
Skip to first unread message

Jinxiang Gu

unread,
Feb 13, 2018, 4:22:55 PM2/13/18
to Gurobi Optimization
I am fairly new to the Gurobi/Python tool set and wandering if Gurobi has a function like the exists() function in Morsel. 

For example, I will get an error in using the following network flow conservation constraint because my supply and demand data does not exist for every enumeration of p and i. I can enumerate every possible combination of p and i, and set the supply/demand value to be zero but that does not seem very elegant. 

m.addConstrs(
(flow.sum(p,'*',i) + supply[p,i] == flow.sum(p,i,'*') + demand[p,i]
for p in product for i in loc), "flow_balance")

I would like to know if there is a convenient way to add the supply and demand terms to the constraint only if they exist in the data. 


Tobias Achterberg

unread,
Feb 15, 2018, 3:04:17 AM2/15/18
to gur...@googlegroups.com
This is more a Python than a Gurobi question. Shouldn't it be possible to just say
something like

for i in demand[p].keys()

instead of

for i in loc

?


Regards,

Tobias
Reply all
Reply to author
Forward
0 new messages