Skip to main content

How to properly write a constraint with the right hand side needs to choose among three possible numbers

Answered

Comments

4 comments

  • Official comment
    Simranjit Kaur
    • Gurobi Staff
    This post is more than three 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 why not try our AI Gurobot?.
  • Eli Towle
    • Gurobi Staff

    Hi Sabrin,

    Since \( f_i^r \) is indexed by both \( i \) and \( r \), you will need something like a dictionary or a function that maps the different values of \( i \) and \( r \) to their respective \( f \) values. E.g.:

    f = {(r, i) : 1 if i in P else -1 if i in D else 0 for r in R for i in Cr[r]}

    Then, you can use \( \texttt{f[r, i]} \) on the right-hand sides of the constraints.

    I see that \( y_{ij}^r \) is dependent on \( r \) in your mathematical formulation. However, in your code, you use \( \texttt{yr[i, j]} \), which has no dependency on \( \texttt{r} \). Is there a reason why the \( \texttt{y} \) variables in your code have no dependency on \( \texttt{r} \)?

    Thanks,

    Eli

    1
  • Sabrin Rashwan
    • Gurobi-versary
    • Conversationalist
    • Investigator

    Thanks a lot I was searching for something like that. 

    0
  • Sabrin Rashwan
    • Gurobi-versary
    • Conversationalist
    • Investigator

    With regard to the yr[i,j] I have corrected to yr[r,i,j]

    0

Post is closed for comments.