QPSolverExample.cpp
Code presents how to solve quadratic programming problemThis example shows how to solve a quadratic programming problem formulted by equation:
Above problem can be rewritten:
Matrix form of QP problem allows us to use QuadraticProgrammingSolver to find the minimum.
#include <armadillo>
#include <juliant.hpp>
using namespace julian;
int main() {
arma::mat Q, C, A;
arma::mat a, b, c, d;
Q << 8.0 << 2.0 << arma::endr
<< 2.0 << 10.0 << arma::endr;
C << 1.5 << arma::endr
<< -2.0 << arma::endr;
A << 2.0 << 1.0 << arma::endr
<<-1.0 << 2.0 << arma::endr;
a << 2.0 << arma::endr
<< arma::datum::inf << arma::endr;
b << arma::datum::inf << arma::endr
<< 6.0 << arma::endr;
c << 0.0 << arma::endr
<< 0.0 << arma::endr;
d << 20.0 << arma::endr
<< arma::datum::inf << arma::endr;
/******** setting solver ************/
QuadraticProgrammingSolver qp_solver;
qp_solver.setQuadraticTerm(Q);
qp_solver.setLinearTerm(C);
qp_solver.setNonEqualityConstrainsMatrix(A);
qp_solver.setNonEqualityConstrainsLowerVector(a);
qp_solver.setNonEqualityConstrainsUpperVector(b);
qp_solver.setArgumentLowerConstrains(c);
qp_solver.setArgumentUpperConstrains(d);
/******** results ************/
SHOW(result);
return 0;
}