19#include "dune/istl/bvector.hh"
77 template <
class MatrixA,
class MatrixB,
class VectorX,
class VectorB>
78 std::array<typename ScalarTraits<typename MatrixA::field_type>::Real,4>
79 checkKKT(MatrixA
const& A, MatrixB
const& B,VectorX
const& c, VectorB
const& b,
80 VectorX
const& x, VectorB
const& lambda);
105 template <
class Real,
class Implementation>
229 void checkNaN(
Vector const& v)
const;
231 virtual void printMatrix(std::ostream& out)
const = 0;
250 template <
class R=
double>
277 Real frobenius_norm()
const {
return A.frobenius_norm(); }
278 Vector solveSubmatrix(std::vector<int>
const& idx,
Vector const& b)
const;
280 virtual void printMatrix(std::ostream& out)
const { out <<
"A = \n" << A; }
281 virtual void updateWithColumn(
Real a,
int i,
Vector& s)
const override;
300 template <
class R=
double>
325 Real frobenius_norm()
const;
327 Vector solveSubmatrix(std::vector<int>
const& idx,
Vector const& b)
const;
329 virtual void printMatrix(std::ostream& out)
const { out <<
"sparse matrix A in triplet format: \n" << A; }
355 template <QPStructure sparsity=QPStructure::DENSE,
class R=
double>
387 Real frobenius_norm()
const;
388 Vector solveSubmatrix(std::vector<int>
const& idx,
Vector const& b)
const;
390 virtual void printMatrix(std::ostream& out)
const { out <<
"A = \n" << A <<
"\nB = \n" << B <<
"\ngamma = " << gamma <<
"\n"; }
422 template <
int d,
class Real=
double>
488 std::unique_ptr<QPBoundSolver<Real>> dual;
523 template <
int d, QPStructure sparsity = QPStructure::DENSE,
class Real=
double>
658 int maxSteps = 10000;
660 std::vector<int> allCols;
697 template <
int d, QPStructure sparsity = QPStructure::DENSE,
class Real=
double>
798 int maxSteps = 10000;
void mv(const X &x, Y &y) const
matrix-vector product
field_type mv(X const &x, Y &y) const
Matrix-vector multiplication with computation of if A is square.
An augmented Lagrangian solver for small instances of a particular class of quadratic programs.
QPALSolver(MatrixA const &A, MatrixB const &B)
Constructs the solver, providing the matrices and .
std::tuple< VectorX, VectorB, int > solve(VectorX const &c, VectorB const &b, double tol) const
Solves the QP approximately for the given right hand side vectors.
QPALSolver< d, sparsity, Real > & setPenalty(Real gamma)
Sets the penalty parameter .
QPALSolver< d, sparsity, Real > & setMinSteps(int i)
Sets the minimum number of augmented Lagrangian steps to perform.
static constexpr QPStructure sparse
Given info on whether dense or sparse arithmetic is used (i.e. the choice of template parameter used ...
std::tuple< VectorX, VectorB, int > solve(VectorX const &c, VectorB const &b, double tol, VectorX x) const
Solves the QP approximately for the given right hand side vectors.
QPALSolver< d, sparsity, Real > & setMaxSteps(int i)
Sets the maximum number of projected gradient steps to perform.
std::conditional_t< sparsity==QPStructure::DENSE, DynamicMatrix< BEntry >, NumaBCRSMatrix< BEntry > > MatrixB
std::conditional_t< sparsity==QPStructure::DENSE, DynamicMatrix< AEntry >, NumaBCRSMatrix< AEntry > > MatrixA
An iterative solver for small instances of bound constrained quadratic programs.
Vector solveSubmatrix(std::vector< int > const &idx, Vector const &b) const
solves a subsystem .
virtual void updateWithColumn(Real a, int i, Vector &s) const
Performs the update , where is the i-th unit vector.
Dune::BlockVector< Dune::FieldVector< Real, 1 > > Vector
std::tuple< Vector, int > solve(Vector const &c, Vector const &b, double tol) const
Solves the QP for the given right hand side vectors.
Implementation & setMinSteps(int count)
defines the minimal number of steps to perform in solving.
void gradientStep(Vector const &c, Vector const &b, Vector &x) const
Performs a single projected gradient step.
Implementation & setMaxSteps(int count)
defines the maximum allowed number of steps to perform in solving.
virtual ~QPBoundSolverBase()
QPBoundSolverBase(int dim)
Constructor (to be used by derived classes only)
std::tuple< Vector, int > solve(Vector const &x, Vector const &c, Vector const &b, double tol) const
Solves the QP for the given right hand side vectors.
An iterative solver for small instances of bound constrained quadratic programs.
QPBoundSolver(Matrix const &A, QPConvexificationStrategy convex=QPConvexificationStrategy::DONOTHING)
Constructs the solver, providing the matrix .
typename Base::Vector Vector
A solver for sparse, medium-sized instances of bound constrained quadratic programs.
QPDirectSparse(SparseMatrix const &A, QPConvexificationStrategy convex=QPConvexificationStrategy::DONOTHING)
Constructs the solver, providing the matrix .
typename Base::Vector Vector
An iterative solver for small instances of a particular class of quadratic programs.
std::tuple< VectorX, VectorB, int > solve(VectorX const &c, VectorB const &b, VectorB const &lambda, double tol) const
Solves the QP approximately for the given right hand side vectors.
std::tuple< VectorX, int > solve(VectorX const &c, VectorB const &b, double tol, VectorX const &x) const
Real getPenalty() const
Returns the used penalty parameter .
QPPenalizedSolver< d, sparsity, Real > & setMaxSteps(int i)
Sets the maximum number of projected gradient steps to perform.
std::conditional_t< sparsity==QPStructure::DENSE, DynamicMatrix< BEntry >, NumaBCRSMatrix< BEntry > > MatrixB
QPPenalizedSolver< d, sparsity, Real > & setMinSteps(int i)
Sets the minimum number of projected gradient steps to perform.
std::tuple< VectorX, VectorB, int > solve(VectorX const &c, VectorB const &b, VectorB lambda, double tol, VectorX const &x) const
Solves the QP approximately for the given right hand side vectors.
std::conditional_t< sparsity==QPStructure::DENSE, DynamicMatrix< AEntry >, NumaBCRSMatrix< AEntry > > MatrixA
VectorB multiplierEstimate(VectorX const &x, VectorX c) const
Computes a least squares multiplier estimate.
QPPenalizedSolver(MatrixA const &A, MatrixB const &B)
Constructs the solver, providing the matrices and .
QPPenalizedSolver< d, sparsity, Real > & setPenalty(Real gamma)
Sets the penalty parameter .
std::tuple< VectorX, int > solve(VectorX const &c, VectorB const &b, double tol) const
static constexpr QPStructure sparse
Given info on whether dense or sparse arithmetic is used (i.e. the choice of template parameter used ...
QPPenalizedSolver(MatrixA const &A, MatrixB const &B, Real gamma)
Constructs the solver, providing the matrices and .
An iterative solver for particular instances of bound constrained quadratic programs.
std::conditional_t< sparsity==QPStructure::DENSE, DynamicMatrix< Entry >, NumaBCRSMatrix< Entry > > Matrix
typename Base::Vector Vector
QPSlackSolver(Matrix const &A, Matrix const &B, Real gamma, QPConvexificationStrategy convex=QPConvexificationStrategy::DONOTHING)
Constructs the solver, providing the matrix and .
An iterative solver for small instances of a particular class of quadratic programs.
static constexpr QPStructure sparse
Given info on whether dense or sparse arithmetic is used.
Self & operator=(Self const &qp)
QPSolver(MatrixA const &A, MatrixB const &B, QPConvexificationStrategy convex=QPConvexificationStrategy::DONOTHING)
Constructs the solver, providing the matrices and .
MatrixB const & matrixB() const
Provides access to the internal copy of .
std::tuple< VectorX, VectorB, int > solve(VectorX const &c, VectorB const &b, double tol) const
Solves the QP for the given right hand side vectors.
int count(Cell const &cell, int codim)
Computes the number of subentities of codimension c of a given entity.
std::array< typename ScalarTraits< typename MatrixA::field_type >::Real, 4 > checkKKT(MatrixA const &A, MatrixB const &B, VectorX const &c, VectorB const &b, VectorX const &x, VectorB const &lambda)
Computes the KKT residual for approximate solutions of certain QPs.
QPConvexificationStrategy
QPStructure
A flag that determines whether the QP solver shall work with dense or sparse linear algebra.