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

Conditional (piecewise) constraints modeling in Gurobi

回答済み

コメント

4件のコメント

  • 正式なコメント
    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 try Gurobot, our chatbot interface offering instant, expert-level support.
  • Jaromił Najman
    • Gurobi Staff

    Hi Jingfeng,

    To model the piecewise expression, you can first define auxiliary variable \(z_1 = y_1 + y_2, z_2 = |y_1-y_2|\) and thren follow the steps described in How do I model conditional statements in Gurobi? For the absolute value, you will need the addGenConstrAbs method. Once you have introduced two binary variables \(b_1,b_2\) for the first two conditions, you can check for the 3rd condition (the "otherwise" condition) by introducing a third binary variable and using Gurobi's or method to model \(b_3 = b_1 \lor b_2\).

    Then, there is the issue with all the nonlinear terms in your expressions. You will need to have a look at How do I divide by a variable in Gurobi? and How do I model multilinear terms in Gurobi?. Additionally, you will require the addGenConstrSin method to model the \(\sin\) term. Unfortunately, \(\arccos\) is not supported in Gurobi. Thus, you will need to construct a piecewise-linear approximation of this function by hand. You can use the addGenConstrPWL method for this.

    Given all the extra steps you have to make to model this highly nonlinear term in Gurobi, I would recommend to try a different solver, which is dedicated to such nonlinear expressions and possibly directly supports the \(\arccos\) function, multilinear terms, and variable division.

    Best regards, 
    Jaromił

    0
  • Purva Joshi
    • Gurobi-versary
    • First Comment

    Hi Jaromił,

    Thank you for your detailed explanation here as well on the post How do I model constraints in Gurobi? I found it to be very helpful to also implement some conditional constraints in my model. Perhaps it might be useful to briefly mention somewhere that when working exclusively with negative variables, the parameter M should take on a different value -- not the upper bound of x and y, but the lower bound instead. It took me some time to figure out that this was the root cause behind a TypeError that kept popping up.

    Thanks!

    Best regards,

    Purva

    0
  • Jaromił Najman
    • Gurobi Staff

    Hi Purva,

    Thanks you for the suggestion. We improved the Knowledge Base article.

    Best regards, 
    Jaromił

    0

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