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>
246 void checkNaN(
Vector const& v)
const;
248 virtual void printMatrix(std::ostream& out)
const = 0;
267 template <
class R=
double>
293 void mv(
Vector const& x,
Vector& Ax)
const { A.mv(x,Ax); }
294 Real frobenius_norm()
const {
return A.frobenius_norm(); }
295 Vector solveSubmatrix(std::vector<int>
const& idx,
Vector const& b)
const;
297 virtual void printMatrix(std::ostream& out)
const override
299 out <<
"A = \n" << A;
302 virtual void updateWithColumn(
Real a,
int i,
Vector& s)
const override;
321 template <
class R=
double>
345 void mv(
Vector const&x,
Vector& Ax)
const { A.mv(x,Ax); }
346 Real frobenius_norm()
const;
348 Vector solveSubmatrix(std::vector<int>
const& idx,
Vector const& b)
const;
350 virtual void printMatrix(std::ostream& out)
const { out <<
"sparse matrix A in triplet format: \n" << A; }
376 template <QPStructure sparsity=QPStructure::DENSE,
class R=
double>
408 Real frobenius_norm()
const;
409 Vector solveSubmatrix(std::vector<int>
const& idx,
Vector const& b)
const;
411 virtual void printMatrix(std::ostream& out)
const
413 out <<
"A = \n" << A <<
"\nB = \n" << B <<
"\ngamma = " << gamma <<
"\n";
446 template <
int d,
class Real=
double>
513 std::unique_ptr<QPBoundSolver<Real>> dual;
548 template <
int d, QPStructure sparsity = QPStructure::DENSE,
class Real=
double>
683 int maxSteps = 10000;
685 std::vector<int> allCols;
722 template <
int d, QPStructure sparsity = QPStructure::DENSE,
class Real=
double>
823 int maxSteps = 10000;
A LAPACK-compatible dense matrix class with shape specified at runtime.
A NUMA-aware compressed row storage matrix adhering mostly to the Dune ISTL interface (to complete....
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.
std::conditional_t< sparsity==QPStructure::DENSE, DynamicMatrix< AEntry >, NumaBCRSMatrix< AEntry > > MatrixA
QPALSolver< d, sparsity, Real > & setPenalty(Real gamma)
Sets the penalty parameter .
std::conditional_t< sparsity==QPStructure::DENSE, DynamicMatrix< BEntry >, NumaBCRSMatrix< BEntry > > MatrixB
Dune::BlockVector< Dune::FieldVector< Real, 1 > > VectorB
QPALSolver< d, sparsity, Real > & setMinSteps(int i)
Sets the minimum number of augmented Lagrangian steps to perform.
Dune::BlockVector< Dune::FieldVector< Real, d > > VectorX
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.
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.
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.
Dune::BlockVector< Dune::FieldVector< Real, 1 > > Vector
DynamicMatrix< Dune::FieldMatrix< Real, 1, 1 > > Matrix
DynamicMatrix< Dune::FieldMatrix< Real, 1, 1 > > Matrix
QPBoundSolver(Matrix const &A, QPConvexificationStrategy convex=QPConvexificationStrategy::DONOTHING)
Constructs the solver, providing the matrix .
typename Base::Vector Vector
QPDirectSparse(SparseMatrix const &A, QPConvexificationStrategy convex=QPConvexificationStrategy::DONOTHING)
Constructs the solver, providing the matrix .
NumaBCRSMatrix< Dune::FieldMatrix< Real, 1, 1 > > SparseMatrix
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 .
std::conditional_t< sparsity==QPStructure::DENSE, DynamicMatrix< AEntry >, NumaBCRSMatrix< AEntry > > MatrixA
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
Dune::BlockVector< Dune::FieldVector< Real, d > > VectorX
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.
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 .
Dune::BlockVector< Dune::FieldVector< Real, 1 > > VectorB
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 .
typename Base::Vector Vector
std::conditional_t< sparsity==QPStructure::DENSE, DynamicMatrix< Entry >, NumaBCRSMatrix< Entry > > Matrix
QPSlackSolver(Matrix const &A, Matrix const &B, Real gamma, QPConvexificationStrategy convex=QPConvexificationStrategy::DONOTHING)
Constructs the solver, providing the matrix and .
Dune::BlockVector< Dune::FieldVector< Real, d > > VectorX
DynamicMatrix< Dune::FieldMatrix< Real, d, d > > MatrixA
DynamicMatrix< Dune::FieldMatrix< Real, 1, d > > MatrixB
static constexpr QPStructure sparse
Self & operator=(Self const &qp)
Dune::BlockVector< Dune::FieldVector< Real, 1 > > VectorB
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.