47 #include <visp3/core/vpConfig.h>
49 #if defined(VISP_HAVE_LAPACK) && (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
52 #include <visp3/core/vpQuadProg.h>
53 #include <visp3/core/vpTime.h>
55 int main(
int argc,
char **argv)
57 #ifdef ENABLE_VISP_NAMESPACE
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 human intervention.\n"
114 for (
int i = 0; i < p; ++i)
115 d[i] += (5. * rand()) / RAND_MAX;
126 double t_WS(0), t_noWS(0), t_ineq_WS(0), t_ineq_noWS(0);
127 const double eps = 1e-2;
129 #ifdef VISP_HAVE_DISPLAY
130 QPlot *plot =
nullptr;
132 plot =
new QPlot(2, total,
133 {
"only equalities",
"pre-solving",
"equalities + inequalities",
"pre-solving / warm start" });
136 for (
int k = 0; k < total; ++k) {
138 Q += eps * randM(o, n);
140 C += eps * randM(p, n);
150 #ifdef VISP_HAVE_DISPLAY
152 plot->plot(0, 0, k, t);
161 #ifdef VISP_HAVE_DISPLAY
163 plot->plot(0, 1, k, t);
171 qp.
solveQP(Q, r, A, b, C, d, x);
174 #ifdef VISP_HAVE_DISPLAY
176 plot->plot(1, 0, k, t);
182 qp_ineq_WS.
solveQPi(Q, r, C, d, x,
true);
185 #ifdef VISP_HAVE_DISPLAY
187 plot->plot(1, 1, k, t);
191 std::cout.precision(3);
192 std::cout <<
"With only equality constraints\n";
193 std::cout <<
" pre-solving: t = " << t_WS <<
" ms (for 1 QP = " << t_WS / total <<
" ms)\n";
194 std::cout <<
" no pre-solving: t = " << t_noWS <<
" ms (for 1 QP = " << t_noWS / total <<
" ms)\n\n";
196 std::cout <<
"With inequality constraints\n";
197 std::cout <<
" Warm start: t = " << t_ineq_WS <<
" ms (for 1 QP = " << t_ineq_WS / total <<
" ms)\n";
198 std::cout <<
" No warm start: t = " << t_ineq_noWS <<
" ms (for 1 QP = " << t_ineq_noWS / total <<
" ms)"
201 #ifdef VISP_HAVE_DISPLAY
203 if (opt_click_allowed) {
204 std::cout <<
"Click in the graph to exit..." << std::endl;
211 #elif !(VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
214 std::cout <<
"You did not build ViSP with c++11 or higher compiler flag" << std::endl;
215 std::cout <<
"Tip:" << std::endl;
216 std::cout <<
"- Configure ViSP again using cmake -DUSE_CXX_STANDARD=11, and build again this example" << std::endl;
222 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()