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

How to handle absolute value in Gurobi constraints

進行中

コメント

4件のコメント

  • 正式なコメント
    Simranjit Kaur
    • Gurobi Staff 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 Gurobi Staff

    Hi Santanu,

    Did you write this LP file from scratch? If so, I don't recommend doing this; it's very error-prone, and the LP format isn't standardized. If you want to use algebraic modeling syntax to interact with Gurobi, you may want to look at AMPL or GAMS. Gurobi also supports APIs in several programming languages, so you can build this model in Python, C++, MATLAB, etc.

    One LP file that models this problem is below. We introduce auxiliary variables \( y_0 = v_0 - v_1 \) and \( y_1 = v_1 - v_2 \). Then, we use variables \( z_0 = |y_0| \) and \( z_1 = |y_1| \) to represent the corresponding absolute value terms.

    \ abc.lp
    Maximize
    v0 + v1 + v2
    Subject To
    R0: 3 v0 + v1 + v2 <= 72
    R1: 2 v0 + 3 v1 + 2 v2 <= 80
    R2: - v0 + v1 + y0 = 0
    R3: - v1 + v2 + y1 = 0
    R4: z0 + z1 >= 10
    Bounds
    Generals
    v0 v1 v2
    General Constraints
    GC0: z0 = ABS ( y0 )
    GC1: z1 = ABS ( y1 )
    End

    Thanks!

    Eli

    0
  • Santanu Sarkar
    • Gurobi-versary
    • First Question
    • First Comment

    Thank you so much for your help.

    0
  • Tripti Gangwar
    • Gurobi-versary
    • Conversationalist
    • First Question

    Hi,

    The absolute function in constraints works well in MATLAB +YALMIP. However, when I am trying to use the same constraint in PYOMO, Gurobi is not able to solve it. It shows non-linearity in the constraint.  Has anyone encountered the same problem?

    0

投稿コメントは受け付けていません。