I don't know if someone can help here as the target community may not be so wide, but I will give it a try.
I'm practicing with the open-source C++ CasADi library for optimization and I'm struggling with the implementation of a quadratic programming (QP) problem with a linear constraint. Unfortunately, the official documentation regarding the proper syntax for C++ is only partial and deducing it from the other languages (Python, MATLAB) is not always that easy.
To make it short, inspired also by the example programs of the library, I wrote a minimal replicable code for a trivial QP problem such as:
casadi::SX xs = casadi::SX::sym("xs");
casadi::SX ys = casadi::SX::sym("ys");
casadi::SX fs = (xs) * (xs) + (ys) * (ys);
casadi::SX gs = xs - 3.0;
casadi::SXDict qp_problem = { {"x",casadi::SX::vertcat({xs,ys})}, {"f", fs}, {"g",gs}};
casadi::Function qp_solution = casadi::qpsol("QPproblem", "qrqp", qp_problem);
std::vector<double> x0 = { 10,10 };
casadi::DMDict arg = { {"x0",x0} };
std::cout << "Extracting the solution ... " << std::endl;
casadi::DMDict res = qp_solution(arg);
std::cout << "res[x] = " << res["x"] << std::endl;
According to the official documentation, the variable gs
specifies a linear inequality constraint as xs - 3.0 >= 0
, while fs
is the cost function to minimize.
As such, I would expect that the resulting minimum value for the x
(i.e., res[x]
) was (3,0)
in virtue of the constraint. Instead, the output of the above-reported code returns the pair (0,0)
, i.e., as if the constraint function gs
was not taken into account. I've also tried in changing the vertex of the paraboloid in fs
(i.e., by testing fs = (xs-x0) * (xs-x0) + (ys-y0) * (ys-y0)
), obtaining always the pair (x0,y0)
as minimum, independently on the expression of the constraint gs
.
Is there anything in the syntax that I'm possibly writing wrongly, or something in the discussion that I'm uncorrectly considering?
Thanks in advance for any help