Some wonders about the GRBModel::addRange()
AnsweredHi, everyone, I have some wonders about the GRBModel::addRange() API,
GRBConstr addRange ( const GRBLinExpr& expr,
double lower,
double upper,
string name="" )
I'm puzzled the argument lower and upper, for a linear expression, what's the meaning of the lower and upper? Such as
2 *x + y <= 10,
what's the lower and upper for this linear expression.
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?
Best Regards.
Thanks.
-
Official comment
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?. -
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 -
Thank you, Mr. Jaromił, I got it, you reply is very clearly and accurately.
0
Post is closed for comments.
Comments
3 comments