Skip to main content

How to get absolute difference of 2 variable.

Answered

Comments

3 comments

  • Official comment
    Simranjit Kaur
    • Gurobi Staff
    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.
  • Mohd Munasib
    • Gurobi-versary
    • Curious
    • Conversationalist

    Hi Team,

    Hope you are doing good. 

    i am looking forward to your reply.

    Thanks

    Munasib

    0
  • Riley Clement
    • Gurobi Staff

    Hi Munasib,

    Noting that the API docs for abs_ indicate that the argument must be a variable, and not an expression, we know that we will need to create an auxiliary variable for each row, that will be equal to A-F.  You can add these variables to the dataframe, although you do not have to - you could create them on "the fly".

    In Advanced Patterns in the gurobipy-pandas docs we describe how to add SOS constraints, as there is no built-in method for this in gurobipy-pandas.  Likewise there is no built in method for abs_ so the approach will be very similar.  You will create a column of variables which will be equal to the desired result, and then iterate through the dataframe, row by row, using itertuples, and create the constraint inside the for loop (and possibly the auxiliary variable if you are creating it as you go and do not want to store it anywhere).

    - Riley

    0

Post is closed for comments.