Skip to main content

gurobipy - add specific constraints as "Lazy"

Answered

Comments

9 comments

  • Official comment
    Simranjit Kaur
    Gurobi Staff 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?.
  • Daniel Espinoza

    addConstrs returns a tupledict of constraints that you can use latter on to set the lazy attribute

    0
  • Niccolò Bulgarini
    Gurobi-versary
    First Comment
    First Question

    Thank you! Can you link an example where constraints get the "Lazy" attribute set after they get created with ? I can't find any in the documentation and on Google

    0
  • Eli Towle
    Gurobi Staff Gurobi Staff

    Hi Niccolò,

    Here is a simple example showing how to set the Lazy attribute after creating the constraints.

    # addConstrs() returns tupledict of constraints
    myconstrs = m.addConstrs(x[i] + y[i] <= 1 for i in I)

    # Set Lazy attribute using returned tupledict
    for i in I:
        myconstrs[i].Lazy = 1

    I hope this helps!

    Eli

    1
  • Niccolò Bulgarini
    Gurobi-versary
    First Comment
    First Question

    awesome! exaclty what I was looking for. thanks!

    0
  • Julian Meffert
    Gurobi-versary
    First Comment

    how does this work in the c++ api? 

    0
  • Silke Horn
    Gurobi Staff Gurobi Staff

    Hi,

    You can find C++ attribute examples here. C++ is not as elegant as Python, and you need to include the type of the attribute in the identifier. The Lazy attribute is integer-valued, so you would set it on a constraint object like this:

    constraint.set(GRB_IntAttr_Lazy, 1);

    Silke

    0
  • Julian Meffert
    Gurobi-versary
    First Comment

    Hey, thanks a lot for your quick reply.

    And I get the constraint object by:

    auto constraint = model.addConstr(...);

    followed by 

    constraint.set(GRB_IntAttr_Lazy, 2);

    right? (just for completeness sake)

    Julian

    0
  • Silke Horn
    Gurobi Staff Gurobi Staff

    Yes, exactly!

    Of course, you can also iterate over an array of constraints (e.g. one returned by addConstrs) to set the Lazy attribute.

    Silke

    0

Post is closed for comments.