Public Types | Public Member Functions | Private Attributes | List of all members
ifopt::Composite Class Reference

A collection of components which is treated as another Component. More...

#include <composite.h>

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

Public Types

using ComponentVec = std::vector< Component::Ptr >
 
using Ptr = std::shared_ptr< Composite >
 
- Public Types inherited from ifopt::Component
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

void AddComponent (const Component::Ptr &)
 Adds a component to this composite. More...
 
void ClearComponents ()
 Removes all component from this composite. More...
 
 Composite (const std::string &name, bool is_cost)
 Creates a Composite holding either variables, costs or constraints. More...
 
VecBound GetBounds () const override
 Returns the "bounds" of this component. More...
 
const Component::Ptr GetComponent (std::string name) const
 Access generic component with the specified name. More...
 
template<typename T >
std::shared_ptr< T > GetComponent (const std::string &name) const
 Access type-casted component with the specified name. More...
 
const ComponentVec GetComponents () const
 Returns read access to the components. More...
 
Jacobian GetJacobian () const override
 Returns derivatives of each row w.r.t. the variables. More...
 
VectorXd GetValues () const override
 Returns the "values" of whatever this component represents. More...
 
void PrintAll () const
 
void SetVariables (const VectorXd &x) override
 Sets the optimization variables from an Eigen vector. More...
 
virtual ~Composite ()=default
 
- Public Member Functions inherited from ifopt::Component
 Component (int num_rows, const std::string &name)
 Creates a component. 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 void Print (double tolerance, int &index_start) 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 ~Component ()=default
 

Private Attributes

ComponentVec components_
 
bool is_cost_
 
size_t n_var = -1
 

Additional Inherited Members

- Static Public Attributes inherited from ifopt::Component
static const int kSpecifyLater = -1
 

Detailed Description

A collection of components which is treated as another Component.

This class follows the Component interface as well, but doesn't actually do any evaluation, but only stitches together the results of the components it is holding. This is where multiple sets of variables, constraints or costs are ordered and combined.

See Component and Composite Pattern for more information.

Definition at line 162 of file composite.h.

Member Typedef Documentation

◆ ComponentVec

Definition at line 165 of file composite.h.

◆ Ptr

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

Definition at line 164 of file composite.h.

Constructor & Destructor Documentation

◆ Composite()

ifopt::Composite::Composite ( const std::string &  name,
bool  is_cost 
)

Creates a Composite holding either variables, costs or constraints.

Parameters
is_costTrue if this class holds cost terms, false for all others.

Constraints and variables append individual constraint sets and Jacobian rows below one another, whereas costs terms are all accumulated to a scalar value/a single Jacobian row.

Definition at line 98 of file composite.cc.

◆ ~Composite()

virtual ifopt::Composite::~Composite ( )
virtualdefault

Member Function Documentation

◆ AddComponent()

void ifopt::Composite::AddComponent ( const Component::Ptr c)

Adds a component to this composite.

Definition at line 104 of file composite.cc.

◆ ClearComponents()

void ifopt::Composite::ClearComponents ( )

Removes all component from this composite.

Definition at line 118 of file composite.cc.

◆ GetBounds()

Composite::VecBound ifopt::Composite::GetBounds ( ) const
overridevirtual

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).

Implements ifopt::Component.

Definition at line 194 of file composite.cc.

◆ GetComponent() [1/2]

const Component::Ptr ifopt::Composite::GetComponent ( std::string  name) const

Access generic component with the specified name.

Parameters
nameThe name given to the component.
Returns
A generic pointer of that component.

Definition at line 125 of file composite.cc.

◆ GetComponent() [2/2]

template<typename T >
std::shared_ptr< T > ifopt::Composite::GetComponent ( const std::string &  name) const

Access type-casted component with the specified name.

Parameters
nameThe name given to the component.
Template Parameters
TType of component.
Returns
A type-casted pointer possibly providing addtional functionality.

Definition at line 227 of file composite.h.

◆ GetComponents()

const Composite::ComponentVec ifopt::Composite::GetComponents ( ) const

Returns read access to the components.

Definition at line 206 of file composite.cc.

◆ GetJacobian()

Composite::Jacobian ifopt::Composite::GetJacobian ( ) const
overridevirtual

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.

Implements ifopt::Component.

Definition at line 164 of file composite.cc.

◆ GetValues()

Composite::VectorXd ifopt::Composite::GetValues ( ) const
overridevirtual

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.

Implements ifopt::Component.

Definition at line 136 of file composite.cc.

◆ PrintAll()

void ifopt::Composite::PrintAll ( ) const

< tolerance when printing out constraint/bound violation.

Definition at line 212 of file composite.cc.

◆ SetVariables()

void ifopt::Composite::SetVariables ( const VectorXd x)
overridevirtual

Sets the optimization variables from an Eigen vector.

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

Implements ifopt::Component.

Definition at line 153 of file composite.cc.

Member Data Documentation

◆ components_

ComponentVec ifopt::Composite::components_
private

Definition at line 217 of file composite.h.

◆ is_cost_

bool ifopt::Composite::is_cost_
private

Definition at line 218 of file composite.h.

◆ n_var

size_t ifopt::Composite::n_var = -1
mutableprivate

Definition at line 221 of file composite.h.


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


ifopt
Author(s): Alexander W. Winkler
autogenerated on Fri Sep 16 2022 02:15:26