Modifying quadratic coefficients (C++)
AnsweredI'd like to modify coefficients of quadratic terms in objectives and constraints. It looks like there aren't any functions to directly do this from C++.
With an objective, you can use gurobi methods to get the objective, remove a quadratic term, add a quadratic term and then re-add the objective.
It's not clear how you would do something similar for a constraint.
What is the best practice for modifying quadratic terms "in place"?
--Bill
-
The best way to modify a quadratic expression (GRBQuadExpr object) is to add the new terms. This is what you suggest for a quadratic objective. For a quadratic constraint, you can't edit it in place. Instead, do the following:
- Get the GRBQConstr object
- Call GRBModel::getQCRow() to get the GRBQuadExpr object
- Modify the GRBQuadExpr object
- Call GRBModel::remove() to remove the original GRBQConstr
- Call GRBModel::addQConstr()
This doesn't exactly modify the model in place. However, unlike LP, there is less benefit to warm start.
0
Please sign in to leave a comment.
Comments
1 comment