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

add a constrain for two related variables

回答済み

コメント

6件のコメント

  • 正式なコメント
    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?.
  • Matthias Miltenberger
    • Gurobi Staff

    Hi!

    This sounds like Indicator constraints might be helpful here. These allow modeling such variable relations.

    Cheers,
    Matthias

    0
  • Mohammad Albarazi
    • Gurobi-versary
    • First Comment
    • First Question

    thank you so much, but I did not recognize well how to use it. How to give the indicator a value. Can you give me a simple example, please?

    0
  • Alison Cozad
    • Gurobi Staff

    To help give an example, could you tell us a bit more about your variables? What variable type are they (integer, binary, continuous)? Do they have bounds?

    0
  • Mohammad Albarazi
    • Gurobi-versary
    • First Comment
    • First Question

    I have two continuous variables, I want one of them to be 0 when the other takes a value more than 0. such as battery charging/discharging variables. they cannot have values more than 0 at the same time.

    0
  • Jaromił Najman
    • Gurobi Staff

    For 2 continuous variables, one way to formulate what you want would be

    \[\begin{align}
    x_1 &\leq \delta_1 x_1^U\\
    x_2 &\leq \delta_2 x_2^U\\
    \delta_1 + \delta_2 &= 1\\
    \delta_1 &, \delta_2 \in \{0,1\}\\
    x_1 &\in [0,x_1^U], x_2 \in [0, x_2^U]
    \end{align}\]

    This way, when \(x_1 > 0\), then \(\delta_1 = 1\) and thus \(\delta_2=0\) and \(x_2=0\). An analogous statement holds when \(x_2 > 0\). Please note that it is possible that \(x_1=x_2=0\).

    0

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