Decision variable indices as a tuple or a list
AnsweredHello, how can I set an indices as a tuple or a list for a continuous variable in a constraint (in Python)?
Here Pr,l demonstrates a list with 2 dimensions
-
Official comment
This post is more than two 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 try Gurobot, our chatbot interface offering instant, expert-level support. -
Hi Maide,
You can pass multiple lists as indices to Model.addVars(). I suggest you try this with a smaller list to understand how the indexing works.
I hope that answers your question.
Cheers,
Matthias0 -
Hi Matthias, Matthias Miltenberger thank you for your answer. Is there a way to set tuple indices while adding in a constraint instead of defining as a variable? I'd like to define this variable as Zm,r,t,i but I'd like to use it as Zm,r,t,p(r,l) in the constraint like in the picture above.
Best,
Maide0 -
Hi Maide,
You can restrict the use of your variables in a conditional sense, by just querying your condition while formulating the constraint:
addConstrs(x[i] + y[k] = 1 for i in I for k in K if i==k)
Is this what you're after? Please consider that you cannot rely on (partly) solutions to your problem when formulating the model because this information will only be available after the solving process.
Cheers,
Matthias0
Post is closed for comments.
Comments
4 comments