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