51 #include <visp3/core/vpConfig.h> 53 #ifdef VISP_HAVE_CPP11_COMPATIBILITY 55 #include <visp3/core/vpQuadProg.h> 56 #include <visp3/core/vpTime.h> 59 int main (
int argc,
char **argv)
65 #ifdef VISP_HAVE_DISPLAY 66 bool opt_display =
true;
69 for (
int i = 0; i < argc; i++) {
70 #ifdef VISP_HAVE_DISPLAY 71 if (std::string(argv[i]) ==
"-d")
75 if (std::string(argv[i]) ==
"-h") {
76 std::cout <<
"\nUsage: " << argv[0] <<
" [-d] [-h]" << std::endl;
77 std::cout <<
"\nOptions: \n" 78 #ifdef VISP_HAVE_DISPLAY 80 " Disable the image display. This can be useful \n" 81 " for automatic tests using crontab under Unix or \n" 82 " using the task manager under Windows.\n" 86 " Print the help.\n"<< std::endl;
105 for(
int i = 0; i < p; ++i)
106 d[i] += (5.*rand())/RAND_MAX;
117 double t_WS(0), t_noWS(0), t_ineq_WS(0), t_ineq_noWS(0);
118 const double eps = 1e-2;
120 #ifdef VISP_HAVE_DISPLAY 123 plot =
new QPlot(2, total, {
"only equalities",
"pre-solving",
"equalities + inequalities",
"pre-solving / warm start"});
126 for(
int k = 0; k < total; ++k)
129 Q += eps * randM(o,n);
131 C += eps * randM(p,n);
141 #ifdef VISP_HAVE_DISPLAY 143 plot->
plot(0, 0, k, t);
152 #ifdef VISP_HAVE_DISPLAY 154 plot->
plot(0, 1, k, t);
162 qp.
solveQP(Q, r, A, b, C, d, x);
165 #ifdef VISP_HAVE_DISPLAY 167 plot->
plot(1, 0, k, t);
173 qp_ineq_WS.
solveQPi(Q, r, C, d, x,
true);
176 #ifdef VISP_HAVE_DISPLAY 178 plot->
plot(1, 1, k, t);
182 std::cout.precision(3);
183 std::cout <<
"With only equality constraints\n";
184 std::cout <<
" pre-solving: t = " << t_WS <<
" ms (for 1 QP = " << t_WS/total <<
" ms)\n";
185 std::cout <<
" no pre-solving: t = " << t_noWS <<
" ms (for 1 QP = " << t_noWS/total <<
" ms)\n\n";
187 std::cout <<
"With inequality constraints\n";
188 std::cout <<
" Warm start: t = " << t_ineq_WS <<
" ms (for 1 QP = " << t_ineq_WS/total <<
" ms)\n";
189 std::cout <<
" No warm start: t = " << t_ineq_noWS <<
" ms (for 1 QP = " << t_ineq_noWS/total <<
" ms)" << std::endl;
191 #ifdef VISP_HAVE_DISPLAY 201 std::cout <<
"You did not build ViSP with C++11 compiler flag" << std::endl;
202 std::cout <<
"Tip:" << std::endl;
203 std::cout <<
"- Configure ViSP again using cmake -DUSE_CPP11=ON, and build again this example" << std::endl;
Implementation of a matrix and operations on matrices.
VISP_EXPORT double measureTimeMs()
void solveBySVD(const vpColVector &B, vpColVector &x) const
This class provides a solver for Quadratic Programs.
void plot(int g, int c, int i, double t)
bool setEqualityConstraint(const vpMatrix &A, const vpColVector &b, const double &tol=1e-6)
Implementation of column vector and the associated operations.
bool solveQPe(const vpMatrix &Q, const vpColVector &r, vpColVector &x, const double &tol=1e-6) const
bool solveQPi(const vpMatrix &Q, const vpColVector &r, const vpMatrix &C, const vpColVector &d, vpColVector &x, const bool use_equality=false, const double &tol=1e-6)
bool solveQP(const vpMatrix &Q, const vpColVector &r, vpMatrix A, vpColVector b, const vpMatrix &C, const vpColVector &d, vpColVector &x, const double &tol=1e-6)