Skip to main content

gurobipy - add specific constraints as "Lazy"

Answered

Comments

8 comments

  • 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

Please sign in to leave a comment.