Gurobi for Python Declaring Variables Using Distinct Indices
AnsweredSuppose I have some binary variable X indexed by set S twice over where properly speaking X should only be indexed by distinct pairs.
I am familiar with AMPL where this declaration would be be:
var X{s in S, ss in S: s<>ss} binary;
I want to duplicate the bold part of the above declaration in my Python declaration below, so I would have to add on to or modify it in some way:
X = m.addVars(S, S, vtype=GRB.BINARY)
How do I do this?
0
-
Official comment
This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?. -
Try creating the index as a generator expression:
X = m.addVars(((s, ss) for s in S for ss in S if s != ss), vtype=GRB.BINARY)
1
Post is closed for comments.
Comments
2 comments