51 #include <visp3/core/vpConfig.h> 53 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11) && defined(VISP_HAVE_LAPACK) 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;
67 bool opt_click_allowed =
true;
70 for (
int i = 0; i < argc; i++) {
71 #ifdef VISP_HAVE_DISPLAY 72 if (std::string(argv[i]) ==
"-d")
74 else if (std::string(argv[i]) ==
"-c")
75 opt_click_allowed =
false;
78 if (std::string(argv[i]) ==
"-h") {
79 std::cout <<
"\nUsage: " << argv[0] <<
" [-d] [-c] [-h] [--help]" << std::endl;
80 std::cout <<
"\nOptions: \n" 81 #ifdef VISP_HAVE_DISPLAY 83 " Disable the image display. This can be useful \n" 84 " for automatic tests using crontab under Unix or \n" 85 " using the task manager under Windows.\n" 88 " Disable the mouse click. Useful to automate the \n" 89 " execution of this program without humain intervention.\n" 93 " Print the help.\n"<< std::endl;
112 for(
int i = 0; i < p; ++i)
113 d[i] += (5.*rand())/RAND_MAX;
124 double t_WS(0), t_noWS(0), t_ineq_WS(0), t_ineq_noWS(0);
125 const double eps = 1e-2;
127 #ifdef VISP_HAVE_DISPLAY 130 plot =
new QPlot(2, total, {
"only equalities",
"pre-solving",
"equalities + inequalities",
"pre-solving / warm start"});
133 for(
int k = 0; k < total; ++k)
136 Q += eps * randM(o,n);
138 C += eps * randM(p,n);
148 #ifdef VISP_HAVE_DISPLAY 150 plot->plot(0, 0, k, t);
159 #ifdef VISP_HAVE_DISPLAY 161 plot->plot(0, 1, k, t);
169 qp.
solveQP(Q, r, A, b, C, d, x);
172 #ifdef VISP_HAVE_DISPLAY 174 plot->plot(1, 0, k, t);
180 qp_ineq_WS.
solveQPi(Q, r, C, d, x,
true);
183 #ifdef VISP_HAVE_DISPLAY 185 plot->plot(1, 1, k, t);
189 std::cout.precision(3);
190 std::cout <<
"With only equality constraints\n";
191 std::cout <<
" pre-solving: t = " << t_WS <<
" ms (for 1 QP = " << t_WS/total <<
" ms)\n";
192 std::cout <<
" no pre-solving: t = " << t_noWS <<
" ms (for 1 QP = " << t_noWS/total <<
" ms)\n\n";
194 std::cout <<
"With inequality constraints\n";
195 std::cout <<
" Warm start: t = " << t_ineq_WS <<
" ms (for 1 QP = " << t_ineq_WS/total <<
" ms)\n";
196 std::cout <<
" No warm start: t = " << t_ineq_noWS <<
" ms (for 1 QP = " << t_ineq_noWS/total <<
" ms)" << std::endl;
198 #ifdef VISP_HAVE_DISPLAY 200 if (opt_click_allowed) {
201 std::cout <<
"Click in the graph to exit..." << std::endl;
208 #elif !(VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11) 211 std::cout <<
"You did not build ViSP with c++11 or higher compiler flag" << std::endl;
212 std::cout <<
"Tip:" << std::endl;
213 std::cout <<
"- Configure ViSP again using cmake -DUSE_CXX_STANDARD=11, and build again this example" << std::endl;
219 std::cout <<
"You did not build ViSP with Lapack support" << std::endl;
void solveBySVD(const vpColVector &B, vpColVector &x) const
Implementation of a matrix and operations on matrices.
bool solveQPe(const vpMatrix &Q, const vpColVector &r, vpColVector &x, const double &tol=1e-6) const
VISP_EXPORT double measureTimeMs()
This class provides a solver for Quadratic Programs.
bool setEqualityConstraint(const vpMatrix &A, const vpColVector &b, const double &tol=1e-6)
Implementation of column vector and the associated operations.
bool solveQPi(const vpMatrix &Q, const vpColVector &r, const vpMatrix &C, const vpColVector &d, vpColVector &x, 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)