Skip to content

Commit 597772e

Browse files
committed
core: expose dual variables to the user
1 parent f2113a7 commit 597772e

File tree

1 file changed

+64
-35
lines changed

1 file changed

+64
-35
lines changed

include/eiquadprog/eiquadprog.hpp

Lines changed: 64 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright (c) 2019 CNRS
2+
// Copyright (c) 2019,2022 CNRS INRIA
33
//
44
// This file is part of eiquadprog.
55
//
@@ -21,9 +21,9 @@
2121

2222
/*
2323
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.
2727
The quadprog_solve() function implements the algorithm of Goldfarb and Idnani
2828
for the solution of a (convex) Quadratic Programming problem
2929
by means of a dual method.
@@ -41,22 +41,19 @@
4141
ci0: m
4242
x: n
4343
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:
4948
1. pay attention in setting up the vectors ce0 and ci0.
5049
If the constraints of your problem are specified in the form
5150
A^T x = b and C^T x >= d, then you should set ce0 = -b and ci0 = -d.
5251
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
6057
Copyright (2011) Benjamin Stephens
6158
Copyright (2010) Gael Guennebaud
6259
Copyright (2008) Angelo Furfaro
@@ -79,43 +76,75 @@
7976

8077
#include <Eigen/Cholesky>
8178
#include <Eigen/Core>
79+
8280
#include <iostream>
8381

82+
#include "eiquadprog/deprecated.hpp"
8483
#include "eiquadprog/eiquadprog-utils.hxx"
8584

8685
// namespace internal {
8786
namespace eiquadprog {
8887
namespace solvers {
8988

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;
9292
}
9393

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);
9697
}
9798

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));
100104
}
101105

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);
105117

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+
}
111132

112133
/* 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);
116145
// }
117146

118-
} // namespace solvers
119-
} // namespace eiquadprog
147+
} // namespace solvers
148+
} // namespace eiquadprog
120149

121150
#endif

0 commit comments

Comments
 (0)