メインコンテンツへスキップ

Decision variable indices as a tuple or a list

回答済み

コメント

3件のコメント

  • Matthias Miltenberger
    • Gurobi Staff

    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,
    Matthias

    0
  • Maide Ceren Kaymaz
    • Gurobi-versary
    • First Comment
    • First Question

    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,
    Maide

    0
  • Matthias Miltenberger
    • Gurobi Staff

    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,
    Matthias

    0

サインインしてコメントを残してください。