Public Types | Public Member Functions | Static Public Attributes | Private Attributes | List of all members
ifopt::Component Class Referenceabstract

Interface representing either Variable, Cost or Constraint. More...

#include <composite.h>

Inheritance diagram for ifopt::Component:
Inheritance graph
[legend]

Public Types

using Jacobian = Eigen::SparseMatrix< double, Eigen::RowMajor >
 
using Ptr = std::shared_ptr< Component >
 
using VecBound = std::vector< Bounds >
 
using VectorXd = Eigen::VectorXd
 

Public Member Functions

 Component (int num_rows, const std::string &name)
 Creates a component. More...
 
virtual VecBound GetBounds () const =0
 Returns the "bounds" of this component. More...
 
virtual Jacobian GetJacobian () const =0
 Returns derivatives of each row w.r.t. the variables. More...
 
std::string GetName () const
 Returns the name (id) of this component. More...
 
int GetRows () const
 Returns the number of rows of this component. More...
 
virtual VectorXd GetValues () const =0
 Returns the "values" of whatever this component represents. More...
 
virtual void Print () const
 Prints the relevant information (name, rows, values) of this component. More...
 
void SetRows (int num_rows)
 Sets the number of rows of this component. More...
 
virtual void SetVariables (const VectorXd &x)=0
 Sets the optimization variables from an Eigen vector. More...
 
virtual ~Component ()=default
 

Static Public Attributes

static const int kSpecifyLater = -1
 

Private Attributes

std::string name_
 
int num_rows_ = kSpecifyLater
 

Detailed Description

Interface representing either Variable, Cost or Constraint.

This structure allows a user to define individual and independent variable sets, constraints and costs without having to worry about how to organize them with respect to each other.

The high-level idea is that variables, costs and constraints can all be fit into the same interface (Component). For example, each has a "value", which is either the actual value of the variables, the constraint value g or the cost. Additionally, a real-world optimization problem usually doesn't just contain one set of variables, but is comprised of multiple variable sets, constraints and cost terms (Composite). This representation provides one common interface ("smallest common denominator") that can be contain either individual variables/costs/constraints or a Composite of these. This pattern takes care of stacking variables, ordering Jacobians and providing bounds for the complete problem without duplicating code.

For more information on the composite pattern visit https://sourcemaking.com/design_patterns/composite

Definition at line 71 of file composite.h.

Member Typedef Documentation

using ifopt::Component::Jacobian = Eigen::SparseMatrix<double, Eigen::RowMajor>

Definition at line 75 of file composite.h.

using ifopt::Component::Ptr = std::shared_ptr<Component>

Definition at line 73 of file composite.h.

using ifopt::Component::VecBound = std::vector<Bounds>

Definition at line 77 of file composite.h.

using ifopt::Component::VectorXd = Eigen::VectorXd

Definition at line 76 of file composite.h.

Constructor & Destructor Documentation

ifopt::Component::Component ( int  num_rows,
const std::string &  name 
)

Creates a component.

Parameters
num_rowsThe number of rows of this components.
nameThe identifier for this component.

The number of rows num_rows can represent either

  • number of variables in this variables set
  • number of constraints in this constraint set
  • 1 if this component represents a Cost.

Definition at line 36 of file composite.cc.

virtual ifopt::Component::~Component ( )
virtualdefault

Member Function Documentation

virtual VecBound ifopt::Component::GetBounds ( ) const
pure virtual

Returns the "bounds" of this component.

  • For Variable these are the upper and lower variable bound.
  • For Constraint this represents the constraint bounds.
  • For Cost these done't exists (set to infinity).

Implemented in ifopt::Composite, ifopt::ExConstraint, ifopt::ExVariables, ifopt::CostTerm, and ifopt::ExComponent.

virtual Jacobian ifopt::Component::GetJacobian ( ) const
pure virtual

Returns derivatives of each row w.r.t. the variables.

  • For Constraint this is a matrix with one row per constraint.
  • For a Cost this is a row vector (gradient transpose).
  • Not sensible for Variable.

Implemented in ifopt::Composite, ifopt::ConstraintSet, ifopt::VariableSet, and ifopt::ExComponent.

std::string ifopt::Component::GetName ( ) const

Returns the name (id) of this component.

Definition at line 55 of file composite.cc.

int ifopt::Component::GetRows ( ) const

Returns the number of rows of this component.

Definition at line 43 of file composite.cc.

virtual VectorXd ifopt::Component::GetValues ( ) const
pure virtual

Returns the "values" of whatever this component represents.

  • For Variable this represents the actual optimization values.
  • For Constraint this represents the constraint value g.
  • For Cost this represents the cost value.

Implemented in ifopt::Composite, ifopt::ExConstraint, ifopt::ExVariables, ifopt::CostTerm, and ifopt::ExComponent.

void ifopt::Component::Print ( ) const
virtual

Prints the relevant information (name, rows, values) of this component.

Reimplemented in ifopt::Composite.

Definition at line 181 of file composite.cc.

void ifopt::Component::SetRows ( int  num_rows)

Sets the number of rows of this component.

Attention
This should correctly be done through constructor call, only delay this by using kSpecifyLater if you have good reason.

Definition at line 49 of file composite.cc.

virtual void ifopt::Component::SetVariables ( const VectorXd x)
pure virtual

Sets the optimization variables from an Eigen vector.

This is only done for Variable, where these are set from the current values of the NLP solvers.

Implemented in ifopt::Composite, ifopt::ConstraintSet, ifopt::ExVariables, and ifopt::ExComponent.

Member Data Documentation

const int ifopt::Component::kSpecifyLater = -1
static

Definition at line 149 of file composite.h.

std::string ifopt::Component::name_
private

Definition at line 153 of file composite.h.

int ifopt::Component::num_rows_ = kSpecifyLater
private

Definition at line 152 of file composite.h.


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


ifopt_core
Author(s): Alexander W. Winkler
autogenerated on Fri Apr 20 2018 02:27:34