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

if multi_constraints then

回答済み

コメント

1件のコメント

  • Riley Clement
    • Gurobi Staff

    Hi Carol,

    It will be easier to model this using contrapositive statements because we want the if-clause to be based on a binary variable.  This gives the following equivalent constraints:

    1. If P == 0 then a <= 0 or b <= 0 or c <= 0

    2. if N == 0 then a >= 0 or b >= 0 or c >= 0

    3. if Z == 0 then (a <= 0 or b <= 0 or c <= 0) and (a >= 0 or b >= 0 or c >= 0), or
        if Z == 0 then P == 0 or N == 0

    a_neg = m.addVar(vtype="B")
    b_neg = m.addVar(vtype="B")
    c_neg = m.addVar(vtype="B")
    a_pos = m.addVar(vtype="B")
    b_pos = m.addVar(vtype="B")
    c_pos = m.addVar(vtype="B")

    m.addConstr((a_neg=1) >> (a <= 0))
    m.addConstr((b_neg=1) >> (b <= 0))
    m.addConstr((c_neg=1) >> (c <= 0))
    m.addConstr((a_pos=1) >> (a >= 0))
    m.addConstr((b_pos=1) >> (b >= 0))
    m.addConstr((c_pos=1) >> (c >= 0))

    # condition 1
    m.addConstr((P == 0) >> (a_neg + b_neg + c_neg >= 1))

    # condition 2
    m.addConstr((N == 0) >> (a_pos + b_pos + c_pos >= 1))

    # condition 3
    m.addConstr((Z == 0) >> (P + N <= 1))

    Note that due to tolerances there are solutions where a, b, and c take on tiny non-zero values yet P = N = 0.

    Also, be careful not to assume that P == 1 implies a>0 and b>0 and c>0.  The above constraints do not model this.  P = 1, a = b = c = 0 is a valid solution.

    - Riley

     

    0

サインインしてコメントを残してください。