Skip to main content

How to get absolute difference of 2 variable.

Answered

Comments

2 comments

  • 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 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

Please sign in to leave a comment.