Skip to main content

values of parameters dependant on decision variable




  • Jaromił Najman
    Gurobi Staff Gurobi Staff

    It is not directly possible to use a variable as an index of an expression or another variable. However, it is possible to formulate it in such a way as is discussed in the post use a decision variable as an index.

    In general if possible, I would try to avoid using optimization variables as indices. In your case, what exactly are you trying to achieve by accessing \(\texttt{D[i,j] for i in B}\)? Do you want to actually use the values of the binary variables to access either \(\texttt{D[0,j]}\) or \(\texttt{D[1,j]}\)? You can achieve this by formulating

    D_{0} \cdot (1-B) + D_{1} \cdot B

    with the appropriate indices for \(B\).

    Best regards, 

  • Leon Stefánsson
    First Comment
    First Question

    Thank you for the answear Jaromil,

    D is not binary, but a distance matrix.

    I found the post yesterday you referred to and after some pondering got around to using a dummy variable

    b \in R^{n x i} \\
    B_n = \sum_{i = 1}^{\I} n*b_{n,i}  \forall n \in N

    Then I set the objective function as:
    \sum_{i,j,n}^{} D_{i,j}R{j,n}b{n,i}

Please sign in to leave a comment.