Skip to main content

Some wonders about the GRBModel::addRange()

Answered

Comments

3 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?.
  • Jaromił Najman
    Gurobi Staff Gurobi Staff

    Hi,

    The addRange function adds the constraints

    \[ \text{lower} \leq \text{expr} \leq \text{upper}\]

    to the model.

    The code

    model.addRange(2*x + y, 1.0, 10.0, "range_constraint");

    constructs the constraints

    \[ 1 \leq x + y \leq 10.\]

    AND another wonders is, could I switch to another constraint API, GRBModel::addConstrs(), this API is more convenient than GRBModel::addRange(), what's the difference between these two APIs?

    If you switch, e.g., to the Python API, you can use the overloaded form

    model.addConstr(2*x + y == [1.0, 10.0], name="range_constraint")

    There is no difference (other than the code itself) in using the overloaded \(\texttt{addConstr}\) form or the addRange function.

    Best regards,
    Jaromił

    0
  • dapei jiang
    Gurobi-versary
    First Comment
    First Question

    Thank you, Mr. Jaromił, I got it, you reply is very clearly and accurately.

    0

Post is closed for comments.