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

How to express two LinExpr in equivalence in one constraint

回答済み

コメント

2件のコメント

  • 正式なコメント
    Simranjit Kaur
    • Gurobi Staff
    This post is more than two 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

    I will omit the \(j\) indices for brevity. Please note that you define your cluster variables as semi-integer variables with a lower bound of \(0\). This means that your cluster variables are actually just integer variables and you can define their vtype as GRB.INTEGER.

    You are on the right track. You already modeled the first half of the equivalence relation, namely

    "if samec = 1 then cluster1 = cluster2"

    Now, you "only" have to model the second half

    "if cluster1 = cluster2 then samec1 = 1"

    This is discussed in the stackexchange post In an integer program, how can I foce a binary variable to equal 1 if some condition holds?

    You can introduce an auxiliary variable (and equality constraint) \(x = \text{cluster1} - \text{cluster2}\). Note that you have to explicitly define a negative lower bound for this variable \(\texttt{lb=-num_I+1}\). It's upper bound would be \(\texttt{ub = num_I -1}\).

    You can then proceed to formulate the condition

    "if x = 0 then samec = 1"

    Inspired by the mentioned stackexchange post, you can formulate this condition via

    \[\begin{align*}
    (-num_I+1) \cdot y^- + 0\cdot y + 0.5\cdot y^+ &\leq x \leq -0.5\cdot y^- + 0\cdot y + (num_I-1)*y^+\\
    y^- + y + y^+ &= 1\\
    y^-, y^+, y &\in \{0,1\}
    \end{align*}\]

    You can replace variable \(y\) by your samec variable in the above.

    Note that there might be an easier way of formulating this specific condition for your model.

    Best regards, 
    Jaromił

    0

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