48 #include <visp3/core/vpConfig.h>
50 #if defined(VISP_HAVE_LAPACK) && (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
53 #include <visp3/core/vpQuadProg.h>
54 #include <visp3/core/vpTime.h>
56 int main(
int argc,
char **argv)
62 #ifdef VISP_HAVE_DISPLAY
63 bool opt_display =
true;
64 bool opt_click_allowed =
true;
67 for (
int i = 0; i < argc; i++) {
68 #ifdef VISP_HAVE_DISPLAY
69 if (std::string(argv[i]) ==
"-d")
71 else if (std::string(argv[i]) ==
"-c")
72 opt_click_allowed =
false;
75 if (std::string(argv[i]) ==
"-h") {
76 std::cout <<
"\nUsage: " << argv[0] <<
" [-d] [-c] [-h] [--help]" << 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"
85 " Disable the mouse click. Useful to automate the \n"
86 " execution of this program without human intervention.\n"
111 for (
int i = 0; i < p; ++i)
112 d[i] += (5. * rand()) / RAND_MAX;
123 double t_WS(0), t_noWS(0), t_ineq_WS(0), t_ineq_noWS(0);
124 const double eps = 1e-2;
126 #ifdef VISP_HAVE_DISPLAY
127 QPlot *plot =
nullptr;
129 plot =
new QPlot(2, total,
130 {
"only equalities",
"pre-solving",
"equalities + inequalities",
"pre-solving / warm start" });
133 for (
int k = 0; k < total; ++k) {
135 Q += eps * randM(o, n);
137 C += eps * randM(p, n);
147 #ifdef VISP_HAVE_DISPLAY
149 plot->plot(0, 0, k, t);
158 #ifdef VISP_HAVE_DISPLAY
160 plot->plot(0, 1, k, t);
168 qp.
solveQP(Q, r, A, b, C, d, x);
171 #ifdef VISP_HAVE_DISPLAY
173 plot->plot(1, 0, k, t);
179 qp_ineq_WS.
solveQPi(Q, r, C, d, x,
true);
182 #ifdef VISP_HAVE_DISPLAY
184 plot->plot(1, 1, k, t);
188 std::cout.precision(3);
189 std::cout <<
"With only equality constraints\n";
190 std::cout <<
" pre-solving: t = " << t_WS <<
" ms (for 1 QP = " << t_WS / total <<
" ms)\n";
191 std::cout <<
" no pre-solving: t = " << t_noWS <<
" ms (for 1 QP = " << t_noWS / total <<
" ms)\n\n";
193 std::cout <<
"With inequality constraints\n";
194 std::cout <<
" Warm start: t = " << t_ineq_WS <<
" ms (for 1 QP = " << t_ineq_WS / total <<
" ms)\n";
195 std::cout <<
" No warm start: t = " << t_ineq_noWS <<
" ms (for 1 QP = " << t_ineq_noWS / total <<
" ms)"
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;
Implementation of column vector and the associated operations.
Implementation of a matrix and operations on matrices.
void solveBySVD(const vpColVector &B, vpColVector &x) const
This class provides a solver for Quadratic Programs.
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)
bool solveQPe(const vpMatrix &Q, const vpColVector &r, vpColVector &x, const double &tol=1e-6) const
bool setEqualityConstraint(const vpMatrix &A, const vpColVector &b, const double &tol=1e-6)
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)
VISP_EXPORT double measureTimeMs()