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

"All different" constraint

回答済み

コメント

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?.
  • Eli Towle
    • Gurobi Staff

    It looks like you're using integer variables \( x_i \in [1, 9] \) to represent the number assigned to location \( i = 1, \ldots, 9 \). The typical way to model this logic is to instead use binary variables \( x_{ik} \) for \( i = 1, \ldots 9 \), \(k = 1, \ldots 9 \), where \( x_{ik} = 1 \) if and only if number \( k \) is assigned to location \( i \). Then, you can model the "all different" condition with the following constraints:

    $$\sum_{i = 1}^{9} x_{ik} = 1 \quad k = 1, \ldots, 9.$$

    The full Gurobi installation includes a sudoku.py example that uses constraints of this form.

    0

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