Open hongkai-dai opened 7 years ago
Looks like Mosek supports them, too. It seems that we have QuadraticConstraint and the solvers declare if they support quadratic constraints, but we just don't have AddQuadraticConstraint
nor AddConstraint<Binding<QuadraticConstraint>>
on MathematicalProgram
?
In the meantime, quadratic constraints can be written as Lorentz cone constraints.
Yes, and that is intentional. Mosek strongly suggests the users to reformulate the quadratic constraints as Lorentz cone constraints, mentioned here.
If it helps, I think we could provide this function
AddQuadraticConstraint(const Expression& quadratic_expr, double upper_bound, bool lorentz_cone=true);
which impose the constraint quadratic_expr <= upper_bound
. And by default we enforce this constraint as a Lorentz cone constraint (with lorentz_cone=true
).
That could be nice, but it's certainly not urgent.
Should we perhaps delete QuadraticConstraint and kQuadraticConstraint if they are unused and if we have no intention of using them?
Currently QuadraticConstraint and kQuadraticConstraint are used in nonlinear optimization, for example by SnoptSolver. So I think it is useful to keep it around?
How does a user create one of those constraints?
The user can do
prog.AddConstraint(std::make_shared<QuadraticConstraint>(...), vars)
as shown in snopt_solver_test.cc https://github.com/RobotLocomotion/drake/blob/6c5a106b1d3660a5e10c3667af4eddaf218a479c/solvers/test/snopt_solver_test.cc#L99-L102
Just curious, do you have a convex optimization problem with a convex quadratic constraint? I think that's a common use case, and I can add the function to parse the convex constraint to a lorentz cone constraint.
As mentioned in https://github.com/RobotLocomotion/drake/issues/18940#issuecomment-1455154129.
I think I should add an API
MathematicalProgram::AddQuadraticConstraint(...);
which adds Binding<QuadraticConstraint>
into MathematicalProgram. Then the solver will either treat it like a generic constraint (just compute the value and the gradient in SNOPT, IPOPT, etc), or a Lorentz cone constraint (by convex solvers like Mosek, Gurobi, SCS, etc).
This will involve quite some change in MathematicalProgram, as now we will add a new data member
std::vector<Binding<QuadraticConstraint>> quadratic_constraints_;
into MathematicalProgram. Also we need to mark each QuadraticConstraint whether it is convex or not.
Prioritizing this because we are solving QCQP.
Gurobi natively supports the convex quadratic constraint
x'*Q*x + q' * x <= b
, we should add that intoMathematicalProgram
andGurobiSolver
.