Skip to main content

Branching priority to MVars

Answered

Comments

2 comments

  • Chung-Kyun Han
    • Gurobi Staff

    Hi Andrea,

    Thank you for reaching us.

    Suppose you don't call m.model(), you cannot check your modification on the variables' attributes directly.
    Try the below code.

    for v in y:
        v.setAttr('BranchPriority', 1)
    m.update()
    for v in y:
        print(v.getAttr('BranchPriority'))

    The Gurobi optimizer applies model modification in a lazy fashion, meaning that modifications don't affect the model immediately. The followings are the reasons why the Gurobi optimizer behave like that, and you can find other detail in 'Lazy Updates' section of Python API Overview.

    Why does the Gurobi interface behave in this manner? There are a few reasons. The first is that this approach makes it much easier to perform multiple modifications to a model, since the model remains unchanged between modifications. The second is that processing model modifications can be expensive, particularly in a Compute Server environment, where modifications require communication between machines. Thus, it is useful to have visibility into exactly when these modifications are applied. In general, if your program needs to make multiple modifications to the model, you should aim to make them in phases, where you make a set of modifications, then update, then make more modifications, then update again, etc. Updating after each individual modification can be extremely expensive.

    If you have further questions, feel free to reach us again.

     

    Best regards,
    Chung-Kyun Han

    0
  • Andrea Gasparin
    • Gurobi-versary
    • First Comment
    • First Question

    Fantastic!

     

    Thank you very much

    Andrea

    0

Please sign in to leave a comment.