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

QuadraticSolver class. More...

#include <QuadraticSolver.h>

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

Public Member Functions

void printValuesAtSolution ()
 
void addObjective (QuadraticObjective &obj)
 
void removeObjective (QuadraticFunction &obj)
 
void removeObjective (QuadraticObjective &obj)
 
void addConstraint (LinearConstraint &constraint)
 
void removeConstraint (LinearConstraint &constraint)
 
void addBounds (BoundConstraint &constraint)
 
void addBounds (IdentityConstraint &constraint)
 
void removeBounds (BoundConstraint &constraint)
 
void removeBounds (IdentityConstraint &constraint)
 
void clearObjectives ()
 
void clearConstraints ()
 
void clearEqualityConstraints ()
 
void clearInequalityConstraints ()
 
void clearBounds ()
 
std::string toString ()
 
virtual MatrixXd getP () const =0
 
virtual VectorXd getq () const =0
 
virtual MatrixXd getA () const =0
 
virtual VectorXd getb () const =0
 
virtual VectorXd getbp () const =0
 
virtual MatrixXd getC () const =0
 
virtual VectorXd getd () const =0
 
virtual VectorXd getl () const =0
 
virtual VectorXd getu () const =0
 
virtual VectorXd getxl () const =0
 
virtual VectorXd getxu () const =0
 
- 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

 QuadraticSolver (bool boundsAsConstraints=false)
 
void onConstraintResize (int timestamp)
 
void recomputeMP ()
 
- 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 onObjectiveResize (int timestamp)
 
virtual void doPrepare ()=0
 
virtual void doSolve ()=0
 
virtual void doConclude ()=0
 
- 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< LinearConstraint * > _equalityConstraints
 
std::vector< LinearConstraint * > _inequalityConstraints
 
std::vector< QuadraticObjective * > _objectives
 
std::vector< DiagonalLinearConstraint * > _bounds
 
size_t _m
 
size_t _p
 
size_t _ps
 
const bool _boundsAsConstraints
 
bool _invalidatedMP
 
- 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

QuadraticSolver class.

Warning
None

Base class for a quadratic solver Objective functions and constraints given as input assume the following form: Minimize 1/2 x^t P x + q^t x Subj. to Ax + b = b' l <= Cx + d <= u (xl <= x <= xu)

This class gives functionalities to maintain the right count in the number of equality or inequality constraints. Bounds can be either considered separatly as bounds or as 'normal' constraints, together with the other linear constraints.

Definition at line 46 of file QuadraticSolver.h.

Constructor & Destructor Documentation

ocra::QuadraticSolver::QuadraticSolver ( bool  boundsAsConstraints = false)
inlineprotected

Constructor to be used by derived class

Parameters
[in]boundsAsConstraints.If true, the bounds will be considered as normal constraints

Definition at line 59 of file QuadraticSolver.h.

Member Function Documentation

void ocra::QuadraticSolver::addBounds ( BoundConstraint constraint)

Add/remove a bound. Will throw a runtime_error for similar reasons as add/removeObjective.

Definition at line 64 of file QuadraticSolver.cpp.

void ocra::QuadraticSolver::addBounds ( IdentityConstraint constraint)

Definition at line 69 of file QuadraticSolver.cpp.

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

Add/remove a constraint. Will throw a runtime_error for similar reasons as add/removeObjective.

Definition at line 43 of file QuadraticSolver.cpp.

void ocra::QuadraticSolver::addObjective ( QuadraticObjective obj)

Add/remove an objective. Will throw a runtime_error in case obj already exist and is added again, or if one tries to remove obj and obj does not appear in the problem.

Definition at line 19 of file QuadraticSolver.cpp.

void ocra::QuadraticSolver::clearBounds ( )

Definition at line 131 of file QuadraticSolver.cpp.

void ocra::QuadraticSolver::clearConstraints ( )

Definition at line 115 of file QuadraticSolver.cpp.

void ocra::QuadraticSolver::clearEqualityConstraints ( )

Definition at line 121 of file QuadraticSolver.cpp.

void ocra::QuadraticSolver::clearInequalityConstraints ( )

Definition at line 126 of file QuadraticSolver.cpp.

void ocra::QuadraticSolver::clearObjectives ( )

Clear all the corresponding data of the problem. Equivalent to call remove() one by one for each of them

Definition at line 110 of file QuadraticSolver.cpp.

virtual MatrixXd ocra::QuadraticSolver::getA ( ) const
pure virtual
virtual VectorXd ocra::QuadraticSolver::getb ( ) const
pure virtual
virtual VectorXd ocra::QuadraticSolver::getbp ( ) const
pure virtual

Implemented in ocra::QLDSolver.

virtual MatrixXd ocra::QuadraticSolver::getC ( ) const
pure virtual
virtual VectorXd ocra::QuadraticSolver::getd ( ) const
pure virtual
virtual VectorXd ocra::QuadraticSolver::getl ( ) const
pure virtual
virtual MatrixXd ocra::QuadraticSolver::getP ( ) const
pure virtual
virtual VectorXd ocra::QuadraticSolver::getq ( ) const
pure virtual
virtual VectorXd ocra::QuadraticSolver::getu ( ) const
pure virtual
virtual VectorXd ocra::QuadraticSolver::getxl ( ) const
pure virtual

Implemented in ocra::QLDSolver.

virtual VectorXd ocra::QuadraticSolver::getxu ( ) const
pure virtual

Implemented in ocra::QLDSolver.

void ocra::QuadraticSolver::onConstraintResize ( int  timestamp)
protectedvirtual

Overload of the callback defined in Solver.

Reimplemented from ocra::Solver.

Definition at line 150 of file QuadraticSolver.cpp.

void ocra::QuadraticSolver::printValuesAtSolution ( void  )
virtual

Print the value of each objective and constraint at the previously found solution

Warning
This assumes the value of the problem variable is still the value of the solution. It does not set the value of the variable to the solution again. Thus, if the variable's value has been changed (directly or through one of its sub-variable) between the last call to solve() and the call to this methods, values displayed will not be the value at the solution.

Implements ocra::Solver.

Definition at line 137 of file QuadraticSolver.cpp.

void ocra::QuadraticSolver::recomputeMP ( )
protected

Compute the value of _m, _p and _ps for the actual set of constraints (and bounds if _boundsAsConstraints is true), and put back _invalidatedMP to false.

Definition at line 155 of file QuadraticSolver.cpp.

void ocra::QuadraticSolver::removeBounds ( BoundConstraint constraint)

Definition at line 87 of file QuadraticSolver.cpp.

void ocra::QuadraticSolver::removeBounds ( IdentityConstraint constraint)

Definition at line 92 of file QuadraticSolver.cpp.

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

Definition at line 53 of file QuadraticSolver.cpp.

void ocra::QuadraticSolver::removeObjective ( QuadraticFunction obj)

Definition at line 25 of file QuadraticSolver.cpp.

void ocra::QuadraticSolver::removeObjective ( QuadraticObjective obj)

Definition at line 37 of file QuadraticSolver.cpp.

std::string ocra::QuadraticSolver::toString ( )
virtual

Get debug info. Don't use these functions in critical loops.

Implements ocra::Solver.

Definition at line 175 of file QuadraticSolver.cpp.

Member Data Documentation

std::vector<DiagonalLinearConstraint*> ocra::QuadraticSolver::_bounds
protected

Definition at line 153 of file QuadraticSolver.h.

const bool ocra::QuadraticSolver::_boundsAsConstraints
protected

Definition at line 159 of file QuadraticSolver.h.

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

Definition at line 150 of file QuadraticSolver.h.

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

Definition at line 151 of file QuadraticSolver.h.

bool ocra::QuadraticSolver::_invalidatedMP
protected

Definition at line 160 of file QuadraticSolver.h.

size_t ocra::QuadraticSolver::_m
protected

Definition at line 155 of file QuadraticSolver.h.

std::vector<QuadraticObjective*> ocra::QuadraticSolver::_objectives
protected

Definition at line 152 of file QuadraticSolver.h.

size_t ocra::QuadraticSolver::_p
protected

Definition at line 156 of file QuadraticSolver.h.

size_t ocra::QuadraticSolver::_ps
protected

Definition at line 157 of file QuadraticSolver.h.


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