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

Binary Variable to check if another variable is 0

回答済み

コメント

3件のコメント

  • 正式なコメント
    Juan Orozco
    • Gurobi Staff

    Dear Daniel,

    Let flag be a binary variable that takes on the value of one if and only if the general integer variable storage is strictly greater than zero (i.e. flag=0 when storage=0). Also, let BigM be an integer parameter that measures the biggest possible value for the variable storage. Then, you can enforce the desired behavior by adding the following auxiliary constraints:

    model.addConstr(storage >= flag, name="aux_1")

    model.addConstr(storage <= BigM*flag, name="aux_2")

    Remark1: If storage=0, then flag=0 to avoid violating constraint "aux_1".

    Remark2: If storage>=1, then flag=1 to avoid violating constraint "aux_2".

  • 正式なコメント
    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?.
  • Daniel Anderson
    • Gurobi-versary
    • First Question
    • First Comment

    Juan, thank you so much for your quick response. I implemented this and it worked pretty well.

    It led to two questions: 1) How do I implement BigM in Gurobi with Python? Do i have to import something? 2) The binary variable does not only take the value 0 and 1, but also -0. What does -0 mean?

    0

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