| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /////////////////////////////////////////////////////////////////////////////// | ||
| 2 | // BSD 3-Clause License | ||
| 3 | // | ||
| 4 | // Copyright (C) 2019-2020, University of Edinburgh | ||
| 5 | // Copyright note valid unless otherwise stated in individual files. | ||
| 6 | // All rights reserved. | ||
| 7 | /////////////////////////////////////////////////////////////////////////////// | ||
| 8 | |||
| 9 | #include <iostream> | ||
| 10 | |||
| 11 | #include "crocoddyl/core/solvers/box-qp.hpp" | ||
| 12 | #include "crocoddyl/core/utils/timer.hpp" | ||
| 13 | |||
| 14 | ✗ | int main(int argc, char* argv[]) { | |
| 15 | ✗ | unsigned int NX = 36; // dimension of the decision vector | |
| 16 | ✗ | unsigned int T = 5e3; // number of trials | |
| 17 | ✗ | if (argc > 1) { | |
| 18 | ✗ | T = atoi(argv[1]); | |
| 19 | } | ||
| 20 | |||
| 21 | // Solving the bounded QP problem | ||
| 22 | ✗ | crocoddyl::BoxQP boxqp(NX); | |
| 23 | ✗ | Eigen::ArrayXd duration(T); | |
| 24 | ✗ | for (unsigned int i = 0; i < T; ++i) { | |
| 25 | // Creating a new random problem | ||
| 26 | ✗ | Eigen::MatrixXd H = Eigen::MatrixXd::Random(NX, NX); | |
| 27 | ✗ | Eigen::MatrixXd hessian = H.transpose() * H; | |
| 28 | ✗ | hessian = 0.5 * (hessian + hessian.transpose()).eval(); | |
| 29 | ✗ | Eigen::VectorXd gradient = Eigen::VectorXd::Random(NX); | |
| 30 | ✗ | Eigen::VectorXd lb = Eigen::VectorXd::Zero(NX); | |
| 31 | ✗ | Eigen::VectorXd ub = Eigen::VectorXd::Ones(NX); | |
| 32 | ✗ | Eigen::VectorXd xinit(NX); | |
| 33 | |||
| 34 | ✗ | crocoddyl::Timer timer; | |
| 35 | ✗ | boxqp.solve(hessian, gradient, lb, ub, xinit); | |
| 36 | ✗ | duration[i] = timer.get_duration(); | |
| 37 | ✗ | } | |
| 38 | |||
| 39 | ✗ | double avrg_duration = duration.sum() / T; | |
| 40 | ✗ | double min_duration = duration.minCoeff(); | |
| 41 | ✗ | double max_duration = duration.maxCoeff(); | |
| 42 | ✗ | std::cout << " BoxQP.solve (36) [ms]: " << avrg_duration << " (" | |
| 43 | ✗ | << min_duration << "-" << max_duration << ")" << std::endl; | |
| 44 | |||
| 45 | ✗ | NX = 76; | |
| 46 | ✗ | boxqp.set_nx(NX); | |
| 47 | ✗ | for (unsigned int i = 0; i < T; ++i) { | |
| 48 | // Creating a new random problem | ||
| 49 | ✗ | Eigen::MatrixXd H = Eigen::MatrixXd::Random(NX, NX); | |
| 50 | ✗ | Eigen::MatrixXd hessian = H.transpose() * H; | |
| 51 | ✗ | hessian = 0.5 * (hessian + hessian.transpose()).eval(); | |
| 52 | ✗ | Eigen::VectorXd gradient = Eigen::VectorXd::Random(NX); | |
| 53 | ✗ | Eigen::VectorXd lb = Eigen::VectorXd::Zero(NX); | |
| 54 | ✗ | Eigen::VectorXd ub = Eigen::VectorXd::Ones(NX); | |
| 55 | ✗ | Eigen::VectorXd xinit(NX); | |
| 56 | |||
| 57 | ✗ | crocoddyl::Timer timer; | |
| 58 | ✗ | boxqp.solve(hessian, gradient, lb, ub, xinit); | |
| 59 | ✗ | duration[i] = timer.get_duration(); | |
| 60 | ✗ | } | |
| 61 | |||
| 62 | ✗ | avrg_duration = duration.sum() / T; | |
| 63 | ✗ | min_duration = duration.minCoeff(); | |
| 64 | ✗ | max_duration = duration.maxCoeff(); | |
| 65 | ✗ | std::cout << " BoxQP.solve (76) [ms]: " << avrg_duration << " (" | |
| 66 | ✗ | << min_duration << "-" << max_duration << ")" << std::endl; | |
| 67 | ✗ | } | |
| 68 |