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
-
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
Please sign in to leave a comment.
Comments
1 comment