ocra-recipes
Doxygen documentation for the ocra-recipes repository
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
ocra::OneLevelSolver Class Referenceabstract

A generic abstract class the solvers that can be used in the wOcra Controller. More...

#include <OneLevelSolver.h>

Inheritance diagram for ocra::OneLevelSolver:
[legend]
Collaboration diagram for ocra::OneLevelSolver:
[legend]

Public Types

using ObjectiveType = ocra::QuadraticObjective
 

Public Member Functions

 OneLevelSolver ()
 
virtual ~OneLevelSolver ()
 
virtual void printValuesAtSolution ()
 
void addObjective (ObjectiveType &obj)
 
void removeObjective (ObjectiveType &obj)
 
void addConstraint (ocra::LinearConstraint &constraint)
 
void removeConstraint (ocra::LinearConstraint &constraint)
 
void writePerformanceInStream (std::ostream &myOstream, bool addCommaAtEnd)
 
virtual void setObjectiveLevel (ocra::GenericObjective &obj, int level)
 
virtual std::string toString ()
 
virtual OneLevelSolver::Ptr clone () const =0
 
const std::vector< ObjectiveType * > & getObjectives ()
 
const Eigen::MatrixXd & getQuadraticMatrix ()
 
const Eigen::VectorXd & getQuadraticVector ()
 
- Public Member Functions inherited from ocra::Solver
const std::vector< int > & findMapping (Variable &var)
 
virtual ~Solver ()
 
const OptimizationResultsolve ()
 
const OptimizationResultgetLastResult () const
 
void printStatus (std::ostream &os)
 
virtual const std::string & getMoreInfo () const
 
void setMemoryLevel (int level)
 
void setAutoDumpFile (const std::string &file)
 
void activateAutoDump ()
 
void deactivateAutoDump ()
 
void dump (const std::string &file="") const
 
int n ()
 
VariablegetProblemVariable ()
 
void setVariableValue (const VectorXd &value)
 
- Public Member Functions inherited from ocra::ObserverSubject
 ObserverSubject ()
 
virtual ~ObserverSubject ()
 
- Public Member Functions inherited from ocra::Observer
virtual ~Observer ()
 
template<int EVT>
void bind (SubjectBase< EVT > &subject)
 Call this method to automatically propagate observed events to observers connected to the subject given in argument. More...
 
template<int EVT>
void stopPropagation ()
 
- Public Member Functions inherited from ocra::ObserverBase< EVT_RESIZE >
void bind (subject_type &subject)
 Call this method to automatically propagate observed events to observers connected to the subject given in argument. More...
 
- Public Member Functions inherited from ocra::ObserverBase< EVT_CHANGE_DEPENDENCIES >
void bind (subject_type &subject)
 Call this method to automatically propagate observed events to observers connected to the subject given in argument. More...
 
- Public Member Functions inherited from ocra::ObserverBase< EVT_CHANGE_VALUE >
void bind (subject_type &subject)
 Call this method to automatically propagate observed events to observers connected to the subject given in argument. More...
 
- Public Member Functions inherited from ocra::Subject
virtual ~Subject ()
 
template<int EVT, class Derived , class Base >
void connect (Derived &object, void(Base::*newCallback)(int)) const
 Call this method to register a non-static method as a callback. More...
 
template<int EVT>
void connect (void(*newCallback)(int)) const
 Call this method to register a free function as a callback. More...
 
template<int EVT, class Derived , class Base >
void disconnect (Derived &object, void(Base::*callbackToErase)(int)) const
 Disconnect non-static method. More...
 
template<int EVT>
void disconnect (void(*callbackToErase)(int)) const
 Disconnect free function. More...
 
template<int EVT>
void propagate () const
 
template<int EVT>
void propagate (int timestamp) const
 
- Public Member Functions inherited from ocra::SubjectBase< EVT_RESIZE >
void connect (T &object, typename SubjectBaseTraits< EVT, T >::callback_type newCallback) const
 Call this method to register a non-static method as a callback. More...
 
void connect (typename SubjectBaseTraits< EVT, void >::callback_type newCallback) const
 Call this method to register a free function as a callback. More...
 
void disconnect (T &object, typename SubjectBaseTraits< EVT, T >::callback_type callback) const
 Disconnect non-static method. More...
 
void disconnect (typename SubjectBaseTraits< EVT, void >::callback_type callbackToErase) const
 Disconnect free function. More...
 
void propagate (int timestamp) const
 
void propagate () const
 
- Public Member Functions inherited from ocra::SubjectBase< EVT_CHANGE_DEPENDENCIES >
void connect (T &object, typename SubjectBaseTraits< EVT, T >::callback_type newCallback) const
 Call this method to register a non-static method as a callback. More...
 
void connect (typename SubjectBaseTraits< EVT, void >::callback_type newCallback) const
 Call this method to register a free function as a callback. More...
 
void disconnect (T &object, typename SubjectBaseTraits< EVT, T >::callback_type callback) const
 Disconnect non-static method. More...
 
void disconnect (typename SubjectBaseTraits< EVT, void >::callback_type callbackToErase) const
 Disconnect free function. More...
 
void propagate (int timestamp) const
 
void propagate () const
 
- Public Member Functions inherited from ocra::SubjectBase< EVT_CHANGE_VALUE >
void connect (T &object, typename SubjectBaseTraits< EVT, T >::callback_type newCallback) const
 Call this method to register a non-static method as a callback. More...
 
void connect (typename SubjectBaseTraits< EVT, void >::callback_type newCallback) const
 Call this method to register a free function as a callback. More...
 
void disconnect (T &object, typename SubjectBaseTraits< EVT, T >::callback_type callback) const
 Disconnect non-static method. More...
 
void disconnect (typename SubjectBaseTraits< EVT, void >::callback_type callbackToErase) const
 Disconnect free function. More...
 
void propagate (int timestamp) const
 
void propagate () const
 
- Public Member Functions inherited from ocra::NamedInstance
 NamedInstance (const std::string &name)
 
const std::string & getName () const
 
virtual ~NamedInstance ()
 

Protected Member Functions

virtual void doPrepare ()
 
virtual void doConclude ()
 
virtual void doSolve ()=0
 
virtual void prepareMatrices ()
 
virtual void updateObjectiveEquations ()=0
 
virtual void updateConstraintEquations ()=0
 
void reduceConstraints (const Eigen::MatrixXd &A, const Eigen::VectorXd &b, Eigen::MatrixXd &Ar, Eigen::VectorXd &br, double tolerance=1e-6)
 
- Protected Member Functions inherited from ocra::Solver
 Solver ()
 
void internalAddObjective (const GenericObjective &objective)
 
void internalAddConstraint (const GenericConstraint &constraint)
 
void internalRemoveObjective (const GenericObjective &objective)
 
void internalRemoveConstraint (const GenericConstraint &constraint)
 
virtual void onConstraintResize (int timestamp)
 
virtual void onObjectiveResize (int timestamp)
 
- Protected Member Functions inherited from ocra::ObserverBase< EVT_RESIZE >
void stopPropagation ()
 Call this method from your callbacks to avoid propagation to the bound subject (if any). More...
 
 ObserverBase ()
 
 ~ObserverBase ()
 
- Protected Member Functions inherited from ocra::ObserverBase< EVT_CHANGE_DEPENDENCIES >
void stopPropagation ()
 Call this method from your callbacks to avoid propagation to the bound subject (if any). More...
 
 ObserverBase ()
 
 ~ObserverBase ()
 
- Protected Member Functions inherited from ocra::ObserverBase< EVT_CHANGE_VALUE >
void stopPropagation ()
 Call this method from your callbacks to avoid propagation to the bound subject (if any). More...
 
 ObserverBase ()
 
 ~ObserverBase ()
 
- Protected Member Functions inherited from ocra::SubjectBase< EVT_RESIZE >
 SubjectBase ()
 
 ~SubjectBase ()
 
- Protected Member Functions inherited from ocra::SubjectBase< EVT_CHANGE_DEPENDENCIES >
 SubjectBase ()
 
 ~SubjectBase ()
 
- Protected Member Functions inherited from ocra::SubjectBase< EVT_CHANGE_VALUE >
 SubjectBase ()
 
 ~SubjectBase ()
 

Protected Attributes

std::vector< ObjectiveType * > _objectives
 
std::vector< ocra::LinearConstraint * > _equalityConstraints
 
Eigen::MatrixXd _A
 
Eigen::VectorXd _b
 
Eigen::MatrixXd _Atotal
 
Eigen::VectorXd _btotal
 
int ne
 
std::vector< ocra::LinearConstraint * > _inequalityConstraints
 
Eigen::MatrixXd _G
 
Eigen::VectorXd _h
 
int ni
 
Eigen::VectorXd Xsolution
 
Eigen::MatrixXd _C
 
Eigen::VectorXd _d
 
- Protected Attributes inherited from ocra::Solver
OptimizationResult _result
 

Additional Inherited Members

- Protected Types inherited from ocra::ObserverBase< EVT_RESIZE >
typedef SubjectBase< EVT > subject_type
 
typedef InvokerBase< EVT > invoker_type
 
- Protected Types inherited from ocra::ObserverBase< EVT_CHANGE_DEPENDENCIES >
typedef SubjectBase< EVT > subject_type
 
typedef InvokerBase< EVT > invoker_type
 
- Protected Types inherited from ocra::ObserverBase< EVT_CHANGE_VALUE >
typedef SubjectBase< EVT > subject_type
 
typedef InvokerBase< EVT > invoker_type
 

Detailed Description

A generic abstract class the solvers that can be used in the wOcra Controller.

It is based on quadratic solvers.

To get a concrete implementation of wOcra solvers, you should call:

 - OneLevelSolver if we consider that all the tasks registered have the same level of importance (but not necessarily the same weights)
 - HierarchySolver if we consider that tasks registered can have different level of importance

Definition at line 58 of file OneLevelSolver.h.

Member Typedef Documentation

Definition at line 61 of file OneLevelSolver.h.

Constructor & Destructor Documentation

OneLevelSolver::OneLevelSolver ( )

Initialize an abstract wOcra Solver.

Definition at line 11 of file OneLevelSolver.cpp.

OneLevelSolver::~OneLevelSolver ( )
virtual

Destructor

Definition at line 21 of file OneLevelSolver.cpp.

Member Function Documentation

void OneLevelSolver::addConstraint ( ocra::LinearConstraint constraint)

Add a quadratic objective to the controller.

Parameters
objThe quadratic objective to add

This objective is saved in an internal vector of objectives. Remove a quadratic objective to the controller.

Parameters
objThe quadratic objective to remove

This objective is removed from the internal vector of objectives. Add a linear constraint to the controller.

Parameters
constraintThe linear constraint to add

This constraint is saved in an internal vector of equality or inequality constraints, depending on the type of constraint.

Definition at line 65 of file OneLevelSolver.cpp.

void ocra::OneLevelSolver::addObjective ( ObjectiveType obj)
inline

Definition at line 72 of file OneLevelSolver.h.

virtual OneLevelSolver::Ptr ocra::OneLevelSolver::clone ( ) const
pure virtual

retuns a pointer to a new instance, very usefull in Hocra

Implemented in ocra::OneLevelSolverWithQLD, ocra::OneLevelSolverWithQPOASES, and ocra::OneLevelSolverWithQuadProg.

void OneLevelSolver::doConclude ( )
protectedvirtual

Do conclude, meaning what to do after solving.

Actually does nothing.

Implements ocra::Solver.

Definition at line 121 of file OneLevelSolver.cpp.

void OneLevelSolver::doPrepare ( void  )
protectedvirtual

Do prepare, meaning prepare matrices before solving.

It calls in this order:

 - #prepareMatrices()
 - #updateObjectiveEquations()
 - #updateConstraintEquations()

Implements ocra::Solver.

Definition at line 106 of file OneLevelSolver.cpp.

virtual void ocra::OneLevelSolver::doSolve ( )
protectedpure virtual
const std::vector<ObjectiveType*>& ocra::OneLevelSolver::getObjectives ( )
inline

Definition at line 92 of file OneLevelSolver.h.

const Eigen::MatrixXd& ocra::OneLevelSolver::getQuadraticMatrix ( )
inline

Definition at line 93 of file OneLevelSolver.h.

const Eigen::VectorXd& ocra::OneLevelSolver::getQuadraticVector ( )
inline

Definition at line 94 of file OneLevelSolver.h.

void OneLevelSolver::prepareMatrices ( )
protectedvirtual

Prepare the basic matrices, which can be considered as the task $ T_0 $ because it minimizes the whole problem vector with very low coefficient.

Definition at line 93 of file OneLevelSolver.cpp.

void OneLevelSolver::printValuesAtSolution ( void  )
virtual

I don't really know, I suppose to print internal values when solution is found.

Actually does nothing.

Implements ocra::Solver.

Definition at line 30 of file OneLevelSolver.cpp.

void OneLevelSolver::reduceConstraints ( const Eigen::MatrixXd &  A,
const Eigen::VectorXd &  b,
Eigen::MatrixXd &  Ar,
Eigen::VectorXd &  br,
double  tolerance = 1e-6 
)
protected

Reduce the set of equality constraints if it is not full rank.

Parameters
AThe matrix associated to the set of equality constraints
bThe vector associated to the set of equality constraints
ArThe matrix instance where will be saved the reduced version of A
brThe vector instance where will be saved the reduced version of b
toleranceThe tolerance of reduction

To reduce the set of equality constraints, we make a SVD decomposition $ \A = U . S . V\tp $. Then we check the dimension (denoted by $ r $) of the diagonal $ S $ where value are greater than the tolerance.

The reduced set of task is then (noted in a python way):

\begin{align*} \A_r &= S[0:r, :] V[:, 0:r] \tp & & & \b_r &= U[:, 0:r] \tp \b \end{align*}

Definition at line 168 of file OneLevelSolver.cpp.

void OneLevelSolver::removeConstraint ( ocra::LinearConstraint constraint)

Removea linear constraint to the controller.

Parameters
constraintThe linear constraint to remove

Definition at line 78 of file OneLevelSolver.cpp.

void ocra::OneLevelSolver::removeObjective ( ObjectiveType obj)
inline

Definition at line 77 of file OneLevelSolver.h.

virtual void ocra::OneLevelSolver::setObjectiveLevel ( ocra::GenericObjective obj,
int  level 
)
inlinevirtual

Definition at line 87 of file OneLevelSolver.h.

std::string OneLevelSolver::toString ( )
virtual

I don't really know, I support to write the problem as a string.

Actually does nothing.

Implements ocra::Solver.

Definition at line 205 of file OneLevelSolver.cpp.

virtual void ocra::OneLevelSolver::updateConstraintEquations ( )
protectedpure virtual
virtual void ocra::OneLevelSolver::updateObjectiveEquations ( )
protectedpure virtual
void OneLevelSolver::writePerformanceInStream ( std::ostream &  outstream,
bool  addCommaAtEnd 
)

Write information about solver performances in a string stream.

Parameters
outstreamthe output stream where to write the performances information
addCommaAtEndIf true, add a comma at the end of the stream. If false, it means that this is the end of the json file, nothing will be added after that, no comma is added.

See Orocos_wOcraController::getPerformances() to know more. Here it saves:

  • solver_prepare
  • solver_solve

Definition at line 137 of file OneLevelSolver.cpp.

Member Data Documentation

Eigen::MatrixXd ocra::OneLevelSolver::_A
protected

Definition at line 115 of file OneLevelSolver.h.

Eigen::MatrixXd ocra::OneLevelSolver::_Atotal
protected

Definition at line 118 of file OneLevelSolver.h.

Eigen::VectorXd ocra::OneLevelSolver::_b
protected

Definition at line 116 of file OneLevelSolver.h.

Eigen::VectorXd ocra::OneLevelSolver::_btotal
protected

Definition at line 119 of file OneLevelSolver.h.

Eigen::MatrixXd ocra::OneLevelSolver::_C
protected

Definition at line 131 of file OneLevelSolver.h.

Eigen::VectorXd ocra::OneLevelSolver::_d
protected

Definition at line 132 of file OneLevelSolver.h.

std::vector<ocra::LinearConstraint*> ocra::OneLevelSolver::_equalityConstraints
protected

Definition at line 114 of file OneLevelSolver.h.

Eigen::MatrixXd ocra::OneLevelSolver::_G
protected

Definition at line 123 of file OneLevelSolver.h.

Eigen::VectorXd ocra::OneLevelSolver::_h
protected

Definition at line 124 of file OneLevelSolver.h.

std::vector<ocra::LinearConstraint*> ocra::OneLevelSolver::_inequalityConstraints
protected

Definition at line 122 of file OneLevelSolver.h.

std::vector<ObjectiveType*> ocra::OneLevelSolver::_objectives
protected

Definition at line 111 of file OneLevelSolver.h.

int ocra::OneLevelSolver::ne
protected

Definition at line 120 of file OneLevelSolver.h.

int ocra::OneLevelSolver::ni
protected

Definition at line 125 of file OneLevelSolver.h.

Eigen::VectorXd ocra::OneLevelSolver::Xsolution
protected

Definition at line 127 of file OneLevelSolver.h.


The documentation for this class was generated from the following files: