|
1 | 1 | // |
2 | | -// Copyright (c) 2019 CNRS |
| 2 | +// Copyright (c) 2019,2022 CNRS INRIA |
3 | 3 | // |
4 | 4 | // This file is part of eiquadprog. |
5 | 5 | // |
|
21 | 21 |
|
22 | 22 | /* |
23 | 23 | FILE eiquadprog.hpp |
24 | | - NOTE: this is a modified of uQuadProg++ package, working with Eigen data structures. |
25 | | - uQuadProg++ is itself a port made by Angelo Furfaro of QuadProg++ originally developed by |
26 | | - Luca Di Gaspero, working with ublas data structures. |
| 24 | + NOTE: this is a modified of uQuadProg++ package, working with Eigen data |
| 25 | + structures. uQuadProg++ is itself a port made by Angelo Furfaro of QuadProg++ |
| 26 | + originally developed by Luca Di Gaspero, working with ublas data structures. |
27 | 27 | The quadprog_solve() function implements the algorithm of Goldfarb and Idnani |
28 | 28 | for the solution of a (convex) Quadratic Programming problem |
29 | 29 | by means of a dual method. |
|
41 | 41 | ci0: m |
42 | 42 | x: n |
43 | 43 | The function will return the cost of the solution written in the x vector or |
44 | | - std::numeric_limits::infinity() if the problem is infeasible. In the latter case |
45 | | - the value of the x vector is not correct. |
46 | | - References: D. Goldfarb, A. Idnani. A numerically stable dual method for solving |
47 | | - strictly convex quadratic programs. Mathematical Programming 27 (1983) pp. 1-33. |
48 | | - Notes: |
| 44 | + std::numeric_limits::infinity() if the problem is infeasible. In the latter |
| 45 | + case the value of the x vector is not correct. References: D. Goldfarb, A. |
| 46 | + Idnani. A numerically stable dual method for solving strictly convex quadratic |
| 47 | + programs. Mathematical Programming 27 (1983) pp. 1-33. Notes: |
49 | 48 | 1. pay attention in setting up the vectors ce0 and ci0. |
50 | 49 | If the constraints of your problem are specified in the form |
51 | 50 | A^T x = b and C^T x >= d, then you should set ce0 = -b and ci0 = -d. |
52 | 51 | 2. The matrix G is modified within the function since it is used to compute |
53 | | - the G = L^T L cholesky factorization for further computations inside the function. |
54 | | - If you need the original matrix G you should make a copy of it and pass the copy |
55 | | - to the function. |
56 | | - The author will be grateful if the researchers using this software will |
57 | | - acknowledge the contribution of this modified function and of Di Gaspero's |
58 | | - original version in their research papers. |
59 | | - LICENSE |
| 52 | + the G = L^T L cholesky factorization for further computations inside the |
| 53 | + function. If you need the original matrix G you should make a copy of it and |
| 54 | + pass the copy to the function. The author will be grateful if the researchers |
| 55 | + using this software will acknowledge the contribution of this modified function |
| 56 | + and of Di Gaspero's original version in their research papers. LICENSE |
60 | 57 | Copyright (2011) Benjamin Stephens |
61 | 58 | Copyright (2010) Gael Guennebaud |
62 | 59 | Copyright (2008) Angelo Furfaro |
|
79 | 76 |
|
80 | 77 | #include <Eigen/Cholesky> |
81 | 78 | #include <Eigen/Core> |
| 79 | + |
82 | 80 | #include <iostream> |
83 | 81 |
|
| 82 | +#include "eiquadprog/deprecated.hpp" |
84 | 83 | #include "eiquadprog/eiquadprog-utils.hxx" |
85 | 84 |
|
86 | 85 | // namespace internal { |
87 | 86 | namespace eiquadprog { |
88 | 87 | namespace solvers { |
89 | 88 |
|
90 | | -inline void compute_d(Eigen::VectorXd& d, const Eigen::MatrixXd& J, const Eigen::VectorXd& np) { |
91 | | - d = J.adjoint() * np; |
| 89 | +inline void compute_d(Eigen::VectorXd &d, const Eigen::MatrixXd &J, |
| 90 | + const Eigen::VectorXd &np) { |
| 91 | + d.noalias() = J.adjoint() * np; |
92 | 92 | } |
93 | 93 |
|
94 | | -inline void update_z(Eigen::VectorXd& z, const Eigen::MatrixXd& J, const Eigen::VectorXd& d, size_t iq) { |
95 | | - z = J.rightCols(z.size() - iq) * d.tail(d.size() - iq); |
| 94 | +inline void update_z(Eigen::VectorXd &z, const Eigen::MatrixXd &J, |
| 95 | + const Eigen::VectorXd &d, size_t iq) { |
| 96 | + z.noalias() = J.rightCols(z.size() - iq) * d.tail(d.size() - iq); |
96 | 97 | } |
97 | 98 |
|
98 | | -inline void update_r(const Eigen::MatrixXd& R, Eigen::VectorXd& r, const Eigen::VectorXd& d, size_t iq) { |
99 | | - r.head(iq) = R.topLeftCorner(iq, iq).triangularView<Eigen::Upper>().solve(d.head(iq)); |
| 99 | +inline void update_r(const Eigen::MatrixXd &R, Eigen::VectorXd &r, |
| 100 | + const Eigen::VectorXd &d, size_t iq) { |
| 101 | + r.head(iq) = d.head(iq); |
| 102 | + R.topLeftCorner(iq, iq).triangularView<Eigen::Upper>().solveInPlace( |
| 103 | + r.head(iq)); |
100 | 104 | } |
101 | 105 |
|
102 | | -bool add_constraint(Eigen::MatrixXd& R, Eigen::MatrixXd& J, Eigen::VectorXd& d, size_t& iq, double& R_norm); |
103 | | -void delete_constraint(Eigen::MatrixXd& R, Eigen::MatrixXd& J, Eigen::VectorXi& A, Eigen::VectorXd& u, size_t p, |
104 | | - size_t& iq, size_t l); |
| 106 | +bool add_constraint(Eigen::MatrixXd &R, Eigen::MatrixXd &J, Eigen::VectorXd &d, |
| 107 | + size_t &iq, double &R_norm); |
| 108 | +void delete_constraint(Eigen::MatrixXd &R, Eigen::MatrixXd &J, |
| 109 | + Eigen::VectorXi &A, Eigen::VectorXd &u, size_t p, |
| 110 | + size_t &iq, size_t l); |
| 111 | + |
| 112 | +double solve_quadprog(Eigen::LLT<Eigen::MatrixXd, Eigen::Lower> &chol, |
| 113 | + double c1, Eigen::VectorXd &g0, const Eigen::MatrixXd &CE, |
| 114 | + const Eigen::VectorXd &ce0, const Eigen::MatrixXd &CI, |
| 115 | + const Eigen::VectorXd &ci0, Eigen::VectorXd &x, |
| 116 | + Eigen::VectorXi &A, size_t &q); |
105 | 117 |
|
106 | | -/* solve_quadprog2 is used when the Cholesky decomposition of the G |
107 | | - matrix is precomputed */ |
108 | | -double solve_quadprog2(Eigen::LLT<Eigen::MatrixXd, Eigen::Lower>& chol, double c1, Eigen::VectorXd& g0, |
109 | | - const Eigen::MatrixXd& CE, const Eigen::VectorXd& ce0, const Eigen::MatrixXd& CI, |
110 | | - const Eigen::VectorXd& ci0, Eigen::VectorXd& x, Eigen::VectorXi& A, size_t& q); |
| 118 | +double solve_quadprog(Eigen::LLT<Eigen::MatrixXd, Eigen::Lower> &chol, |
| 119 | + double c1, Eigen::VectorXd &g0, const Eigen::MatrixXd &CE, |
| 120 | + const Eigen::VectorXd &ce0, const Eigen::MatrixXd &CI, |
| 121 | + const Eigen::VectorXd &ci0, Eigen::VectorXd &x, |
| 122 | + Eigen::VectorXd &y, Eigen::VectorXi &A, size_t &q); |
| 123 | + |
| 124 | +EIQUADPROG_DEPRECATED |
| 125 | +double solve_quadprog2(Eigen::LLT<Eigen::MatrixXd, Eigen::Lower> &chol, |
| 126 | + double c1, Eigen::VectorXd &g0, |
| 127 | + const Eigen::MatrixXd &CE, const Eigen::VectorXd &ce0, |
| 128 | + const Eigen::MatrixXd &CI, const Eigen::VectorXd &ci0, |
| 129 | + Eigen::VectorXd &x, Eigen::VectorXi &A, size_t &q) { |
| 130 | + return solve_quadprog(chol, c1, g0, CE, ce0, CI, ci0, x, A, q); |
| 131 | +} |
111 | 132 |
|
112 | 133 | /* solve_quadprog is used for on-demand QP solving */ |
113 | | -double solve_quadprog(Eigen::MatrixXd& G, Eigen::VectorXd& g0, const Eigen::MatrixXd& CE, const Eigen::VectorXd& ce0, |
114 | | - const Eigen::MatrixXd& CI, const Eigen::VectorXd& ci0, Eigen::VectorXd& x, |
115 | | - Eigen::VectorXi& activeSet, size_t& activeSetSize); |
| 134 | +double solve_quadprog(Eigen::MatrixXd &G, Eigen::VectorXd &g0, |
| 135 | + const Eigen::MatrixXd &CE, const Eigen::VectorXd &ce0, |
| 136 | + const Eigen::MatrixXd &CI, const Eigen::VectorXd &ci0, |
| 137 | + Eigen::VectorXd &x, Eigen::VectorXi &activeSet, |
| 138 | + size_t &activeSetSize); |
| 139 | + |
| 140 | +double solve_quadprog(Eigen::MatrixXd &G, Eigen::VectorXd &g0, |
| 141 | + const Eigen::MatrixXd &CE, const Eigen::VectorXd &ce0, |
| 142 | + const Eigen::MatrixXd &CI, const Eigen::VectorXd &ci0, |
| 143 | + Eigen::VectorXd &x, Eigen::VectorXd &y, |
| 144 | + Eigen::VectorXi &activeSet, size_t &activeSetSize); |
116 | 145 | // } |
117 | 146 |
|
118 | | -} // namespace solvers |
119 | | -} // namespace eiquadprog |
| 147 | +} // namespace solvers |
| 148 | +} // namespace eiquadprog |
120 | 149 |
|
121 | 150 | #endif |
0 commit comments