EigenOpt 1.0.0
Loading...
Searching...
No Matches
quadratic_programming.hpp
Go to the documentation of this file.
1#pragma once
2
4
5#include <Eigen/Dense>
6#include <vector>
7
8namespace EigenOpt {
9
10namespace quadratic_programming {
11
13
85template<class Scalar>
86class Solver {
87public:
89
91 Solver(int xdim, int rdim, const Scalar& tolerance);
92
94 template<class D1, class D2>
95 Solver(
96 const Eigen::EigenBase<D1>& Q,
97 const Eigen::EigenBase<D2>& r,
98 const Scalar& tolerance
99 );
100
102 template<class D1, class D2>
103 void updateObjective(
104 const Eigen::EigenBase<D1>& Q,
105 const Eigen::EigenBase<D2>& r
106 );
107
109 void resetActiveSet();
110
112 void clearConstraints();
113
115
125 template<class D1, class D2>
126 bool setConstraints(
127 const Eigen::EigenBase<D1>& C,
128 const Eigen::EigenBase<D2>& d
129 );
130
132
144 template<class D1, class D2, class D3, class D4>
145 bool setConstraints(
146 const Eigen::MatrixBase<D1>& A,
147 const Eigen::MatrixBase<D2>& b,
148 const Eigen::EigenBase<D3>& C,
149 const Eigen::EigenBase<D4>& d
150 );
151
153
164 template<class D1, class D2>
166 const Eigen::EigenBase<D1>& C,
167 const Eigen::EigenBase<D2>& d
168 );
169
171
175 template<class D>
176 bool solve(Eigen::MatrixBase<D>& x);
177
178private:
180
184 template<class D>
185 bool solveY(Eigen::MatrixBase<D>& y);
186
188
197 template<class D>
198 bool guess(Eigen::MatrixBase<D>& y);
199
201
207 bool initActiveSet();
208
209 const Scalar tol;
210 const int nx;
211 const int nr;
212 int ny;
213 int mi;
214 int me;
215
216 MatrixXs Q;
217 VectorXs r;
218
219 MatrixXs Z;
220 VectorXs xeq;
221
222 MatrixXs Qy;
223 VectorXs ry;
224 MatrixXs Cy;
225 VectorXs dy;
226 VectorXs yu;
227 VectorXs yk;
228
229 MatrixXs Ca;
230 VectorXs da;
231 std::vector<int> active;
232 std::vector<int> inactive;
233}; // class Solver
234
235} // namespace quadratic_programming
236
237} // namespace EigenOpt
238
239
Quadratic Programming solver using active set and null-space projections.
bool solve(Eigen::MatrixBase< D > &x)
Solve the optimization problem.
VectorXs da
Subset of dy, corresponding to active constraints.
MatrixXs Qy
Modified matrix of coefficients for the objective function.
bool guess(Eigen::MatrixBase< D > &y)
Find an initial solution to start the active-set algorithm.
const int nr
Number of rows in the objective.
VectorXs xeq
A particular solution to the equality constraints.
const Scalar tol
Small tolerance used in calculations.
int mi
Number of inequality constraints.
VectorXs ry
Modified vector of coefficients for the objective function.
VectorXs r
Vector of coefficients for the objective function.
VectorXs yu
Unconstrained minimum of the objective.
MatrixXs Cy
Modified inequality constraints matrix.
bool updateInequalities(const Eigen::EigenBase< D1 > &C, const Eigen::EigenBase< D2 > &d)
Update inequality constraints to the problem.
std::vector< int > active
List of constraints in the active set.
void resetActiveSet()
Clear the current active set, preventing warm starts.
VectorXs dy
Modified inequality constraints vector.
VectorXs yk
Current guess of the decision variables.
MatrixXs Z
Matrix that projects into the kernel of the equality constraints matrix.
int ny
Number of variables after removing the equality constraints.
const int nx
Number of decision variables.
void clearConstraints()
Removes constraints and clear the active set.
bool setConstraints(const Eigen::EigenBase< D1 > &C, const Eigen::EigenBase< D2 > &d)
Add inequality constraints to the problem.
int me
number of equality constraints.
bool solveY(Eigen::MatrixBase< D > &y)
Solve the problem in the y variable.
bool initActiveSet()
Initialize the active-set from the current solution.
MatrixXs Ca
Subset of Cy, corresponding to active constraints.
std::vector< int > inactive
List of constraints not in the active set.
void updateObjective(const Eigen::EigenBase< D1 > &Q, const Eigen::EigenBase< D2 > &r)
Updates the objective matrix.
MatrixXs Q
Matrix of coefficients for the objective function.
Main namespace of this project, containing all utilities.