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

How to express if statement in constraints (Gurobi)

回答済み

コメント

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?.
  • Sonja Mars
    • Gurobi Staff

    Hi,

    There are different ways of doing this. It depends a bit on how you are creating the constraints and which programming language you use. For example, if you are using Python and you are adding them one by one and if I and J are lists of your indices, you can do something like this:

    for i in I:
      for j in J:
        if i != j: 
          add constraint

    In Python, there are definitely other more elegant ways, one example could be using tuplelists and only add those indices to the tuplelist that you really need in your constraints. We show an example of this in our netflow.py example.

    Best,

    Sonja

    1

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