32 std::cout<<
"TODO: 'printValuesAtSolution' method not implemented yet!"<<std::endl;
68 if(constraint.isEquality())
81 if(constraint.isEquality())
172 Eigen::JacobiSVD<Eigen::MatrixXd> svdOfMat(A, Eigen::ComputeThinU | Eigen::ComputeThinV);
173 Eigen::VectorXd S = svdOfMat.singularValues();
174 Eigen::MatrixXd Ur = svdOfMat.matrixU();
175 Eigen::MatrixXd Vr = svdOfMat.matrixV();
178 for (r = 0; r<S.size(); r++)
180 if (S[r] <= tolerance)
184 Eigen::VectorXd Sr = S.segment(0,r);
185 Ur.conservativeResize(Eigen::NoChange, r);
186 Vr.conservativeResize(Eigen::NoChange, r);
188 Ar = Sr.asDiagonal() * Vr.transpose();
189 br = Ur.transpose() * b;
207 std::stringstream ss;
208 ss<<
"-----------------------------------------------\n";
211 ss<<
"C:\n"<<
_C<<
"\n";
212 ss<<
"d:\n"<<-
_d.transpose()<<
"\n";
215 ss<<
"b:\n"<<-
_btotal.transpose()<<
"\n";
217 ss<<
"G:\n"<<
_G<<
"\n";
218 ss<<
"h:\n"<<-
_h.transpose()<<
"\n";
240 std::cout <<
"-- " <<
getName() <<
" --" << std::endl;
257 _C.setZero(
n(),
n());
263 auto& f = obj->getFunction();
264 double weight = obj->getWeight();
266 const std::vector<int>& objMap =
findMapping(f.getVariable());
289 _A.resize(
ne,
n());
_A.setZero();
290 _b.resize(
ne);
_b.setZero();
292 int initialRows =
ne;
303 int dim = cstr->getDimension();
308 OCRA_ERROR(
"The size of equality constraints changed after _A had been resized.");
309 std::cout <<
"Initial number of equality constraints was: " << initialSize << std::endl;
310 std::cout <<
"New size of equality constraints is: " <<
_equalityConstraints.size() << std::endl;
311 std::cout <<
"Resizing A accordingly... " << std::endl;
313 Eigen::MatrixXd Atmp(initialRows,
n());
314 Atmp =
_A.block(0,0,initialRows,
n());
321 _A.block(0,0,initialRows,
n()) = Atmp;
325 Eigen::Block<Eigen::MatrixXd> _A_block =
_A.block(idx, 0, dim,
n());
326 Eigen::VectorBlock<Eigen::VectorXd> _b_segment =
_b.segment(idx, dim);
342 this->
mutex.unlock();
360 int dim = cstr->getDimension();
364 Eigen::Block<Eigen::MatrixXd > _G_block =
_G.block(idx, 0, dim,
n());
365 Eigen::VectorBlock<Eigen::VectorXd> _h_segment =
_h.segment(idx, dim);
398 , _nWSR_every_run(200)
400 std::cout <<
"-- " <<
getName() <<
" -- "<<
this<< std::endl;
402 sqp_options.enableRegularisation = qpOASES::BT_TRUE;
420 int dim = cstr->getDimension();
424 Eigen::Block<Eigen::MatrixXd> _A_block =
_A.block(idx, 0, dim,
n());
425 Eigen::VectorBlock<Eigen::VectorXd> _ubA_segment =
_ubA.segment(idx, dim);
448 int dim = cstr->getDimension();
452 Eigen::Block<Eigen::MatrixXd > _G_block =
_G.block(idx, 0, dim,
n());
454 Eigen::VectorBlock<Eigen::VectorXd> _lbG_segment =
_lbG.segment(idx, dim);
455 Eigen::VectorBlock<Eigen::VectorXd> _ubG_segment =
_ubG.segment(idx, dim);
466 for(
int i=0;i<
_lbG.size();i++)
471 std::cout <<
"[ERROR] Lower bound "<<i<<
"("<<
_lbG[i]<<
") higher than upper ("<<
_ubG[i]<<
")"<<std::endl;
472 double tmp =
_lbG[i];
496 if (
_xl.size() !=
n())
498 _xl = - 1e6 * Eigen::VectorXd::Ones(
n());
499 _xu = 1e6 * Eigen::VectorXd::Ones(
n());
521 _C.setZero(
n(),
n());
537 if(
H.size() !=
_C.rows()*
_C.cols())
538 H.resize(
_C.rows()*
_C.cols());
541 _RegTerm = 1.e-8*Eigen::MatrixXd::Identity(
_C.rows(),
_C.cols());
543 Eigen::Map<MatrixXdRm>(
H.data(),
_C.rows(),
_C.cols()) =
_C ;
551 case qpOASES::SUCCESSFUL_RETURN:
553 case qpOASES::RET_QP_INFEASIBLE:
562 static bool first_time;
566 std::cout <<
"Creating "<<
getName()<<
" Solver with params : n:"<<
n()<<
" ni:"<<
ni<<
" ne:"<<
ne<<std::endl;
567 sqp_prob.reset(
new qpOASES::SQProblem(
n(),
ni+
ne,qpOASES::HST_POSDEF));
569 sqp_prob->setPrintLevel(qpOASES::PL_NONE);
575 qpOASES::returnValue ret;
579 if(ret == qpOASES::SUCCESSFUL_RETURN)
584 if(ret == qpOASES::SUCCESSFUL_RETURN)
612 std::cout <<
"-- " <<
getName() <<
" --" << std::endl;
631 _C.setZero(
n(),
n());
634 if (
MapP.size() !=
_C.size())
673 int dim = cstr->getDimension();
677 Eigen::Block<Eigen::MatrixXd> _A_block =
_A.block(idx, 0, dim,
n());
678 Eigen::VectorBlock<Eigen::VectorXd> _b_segment =
_b.segment(idx, dim);
706 int dim = cstr->getDimension();
710 Eigen::Block<Eigen::MatrixXd > _G_block =
_G.block(idx, 0, dim,
n());
711 Eigen::VectorBlock<Eigen::VectorXd> _h_segment =
_h.segment(idx, dim);
732 if (
_xl.size() !=
n())
734 _xl = - 1e10 * Eigen::VectorXd::Ones(
n());
735 _xu = 1e10 * Eigen::VectorXd::Ones(
n());
virtual void updateObjectiveEquations()
const Variable & getVariable() const
void internalAddConstraint(const GenericConstraint &constraint)
Eigen::Map< Eigen::VectorXd > VectorMap
Eigen::VectorXd Xsolution
OneLevelSolverWithQPOASES()
virtual void updateConstraintEquations()
void internalRemoveConstraint(const GenericConstraint &constraint)
void addCompressed2d(const MatrixBase< Derived1 > &in, MatrixBase< Derived2 > const &_out, const std::vector< int > &mapping, double scale, bool reverseMapping)
virtual ~OneLevelSolverWithQuadProg()
Define the internal solver class that can be used in the wOcra controller.
int solve(Map< MatrixXd > &C, const Map< VectorXd > &d, const Map< MatrixXd > &A, const Map< VectorXd > &b, int me, Map< VectorXd > &x, const Map< VectorXd > &xl, const Map< VectorXd > &xu, bool factorizedC=false)
OptimizationResult _result
const std::string & getName() const
const std::vector< int > & findMapping(Variable &var)
virtual void prepareMatrices()
ocra::ObjQLD * _QLDsolver
std::vector< ocra::LinearConstraint * > _inequalityConstraints
Eigen::Map< Eigen::MatrixXd > MatrixMap
virtual void updateObjectiveEquations()
void writePerformanceInStream(std::ostream &myOstream, bool addCommaAtEnd)
Optimization-based Robot Controller namespace. a library of classes to write and solve optimization p...
OneLevelSolverWithQuadProg()
double solve_quadprog(const Eigen::MatrixXd &_G, const Eigen::VectorXd &g0, const Eigen::MatrixXd &_CE, const Eigen::VectorXd &ce0, const Eigen::MatrixXd &_CI, const Eigen::VectorXd &ci0, Eigen::VectorXd &x)
virtual void updateObjectiveEquations()=0
Variable & getProblemVariable()
virtual std::string toString()
void convert(const LinearConstraint &cstr, const std::vector< int > &mapping, eConstraintOutput type, MatrixBase< Derived > &A, VectorBase1 &b, VectorBase2 &l, double infinity=0.)
const VectorXd & getqi(int index=0) const
virtual void doConclude()
void reduceConstraints(const Eigen::MatrixXd &A, const Eigen::VectorXd &b, Eigen::MatrixXd &Ar, Eigen::VectorXd &br, double tolerance=1e-6)
virtual void updateConstraintEquations()
void removeConstraint(ocra::LinearConstraint &constraint)
void addConstraint(ocra::LinearConstraint &constraint)
void addCompressedByRow(const MatrixBase< Derived1 > &in, MatrixBase< Derived2 > const &_out, const std::vector< int > &mapping, double scale, bool reverseMapping)
const MatrixXd & getPi(int index=0) const
virtual void updateConstraintEquations()=0
virtual ~OneLevelSolver()
virtual void updateConstraintEquations()
A generic abstract class the solvers that can be used in the wOcra Controller.
virtual void printValuesAtSolution()
qpOASES::Options sqp_options
std::vector< qpOASES::real_t > H
std::unique_ptr< qpOASES::SQProblem > sqp_prob
virtual void printSubTree(int depth, std::ostream &os) const =0
Overload in ComponentDerived and CompositeDerived to simply call printTree_impl().
virtual ~OneLevelSolverWithQLD()
virtual void updateObjectiveEquations()
std::vector< ObjectiveType * > _objectives
std::vector< ocra::LinearConstraint * > _equalityConstraints
static ocra::eReturnInfo toOcraRetValue(const qpOASES::returnValue &ret)