roboptim::Problem< F, CLIST > Class Template Reference

Optimization problem. More...

#include <roboptim/core/problem.hh>

Public Types

typedef F function_t
 Function type. More...
 
typedef
boost::make_variant_over
< typename
detail::add_shared_ptr< CLIST >
::type >::type 
constraint_t
 Constraint's type. More...
 
typedef function_t::value_type value_type
 
typedef std::vector< constraint_tconstraints_t
 Constraints are represented as a vector of constraints. More...
 
typedef boost::optional
< Function::vector_t
startingPoint_t
 Optional vector defines a starting point. More...
 
typedef Function::interval_t interval_t
 
typedef Function::intervals_t intervals_t
 
typedef std::vector< value_typescales_t
 Scale vector. More...
 

Public Member Functions

std::ostream & print (std::ostream &o) const throw ()
 Display the problem on the specified output stream. More...
 
Constructors and destructors.
 Problem (const function_t &) throw ()
 
 Problem (const Problem< F, CLIST > &) throw ()
 Copy constructor. More...
 
template<typename F_ , typename CLIST_ >
 Problem (const Problem< F_, CLIST_ > &) throw ()
 Copy constructor (convert from another class of problem). More...
 
 ~Problem () throw ()
 
Cost function.
const function_tfunction () const throw ()
 Retrieve cost function. More...
 
intervals_targumentBounds () throw ()
 Retrieve arguments bounds. Arguments bounds define in which interval each argument is valid. More...
 
const intervals_targumentBounds () const throw ()
 Retrieve arguments bounds. Arguments bounds define in which interval each argument is valid. More...
 
scales_targumentScales () throw ()
 Retrieve arguments scales. Arguments scales define which scale is applied for each argument. More...
 
const scales_targumentScales () const throw ()
 Retrieve arguments scales. Arguments scales define which scale is applied for each argument. More...
 
Constraints.
const constraints_tconstraints () const throw ()
 Retrieve constraints. More...
 
template<typename C >
void addConstraint (boost::shared_ptr< C > constraint, interval_t interval, value_type scale=1.) throw (std::runtime_error)
 Add a constraint to the problem. More...
 
const intervals_tbounds () const throw ()
 Retrieve constraints bounds. More...
 
const scales_tscales () const throw ()
 Retrieve constraints scales. More...
 
Starting point (initial guess).
startingPoint_tstartingPoint () throw ()
 Set the initial guess. More...
 
const startingPoint_tstartingPoint () const throw ()
 Get the initial guess. More...
 

Friends

template<typename F_ , typename CLIST_ >
class Problem
 

Detailed Description

template<typename F, typename CLIST>
class roboptim::Problem< F, CLIST >

Optimization problem.

An optimization problem is defined as:

  • a cost function ( $\mathbb{R}^n \rightarrow \mathbb{R}$)
  • one or more constraints functions, ( $\mathbb{R}^n \rightarrow \mathbb{R}^m$) associated with an interval and a scale,
  • a set of intervals and scales for arguments.

The goal of the optimization process is finding a point which minimizes the cost function and which respects the constraints (i.e. the result of some functions is inside of specific interval).

To use the class, one has to instantiate a problem with a reference to a cost function. Then, constraints can be added through the addConstraint method: a reference to a function and an interval is needed.

The cost function is immutable.

Constraints are stored as a Boost.Variant of smart pointers (i.e. more precisely using a boost::shared_ptr) representing all the different possibles constraint types.

It is recommended to add a constraint using the following syntax:

problem.addConstraint<C> (boost::make_shared<MyFunction> (...), ...);

where C is the constraint type and MyFunction the function type.

Unlike other classes which just copy functions, pointers are used here in order to allow sub-classes of constraints to be inserted in the problem. For instance, a twice derivable function can be inserted in a problem which expects a derivable function.

Template Parameters
Ffunction type
CLISTtype list satisfying MPL's sequence concept
Examples:
problem-cc.cc.

Member Typedef Documentation

template<typename F, typename CLIST>
typedef boost::make_variant_over<typename detail::add_shared_ptr<CLIST>::type>::type roboptim::Problem< F, CLIST >::constraint_t

Constraint's type.

Generate a Boost.Variant of shared pointers tyle from the static constraints types list.

For instance, if one instantiates

Problem<QuadraticFunction, vector<LinearFunction, QuadraticFunction> >

then this type will be set to:

boost::variant<boost::shared_ptr<LinearFunction>,
boost::shared_ptr<QuadraticFunction> >

The meta-algorithm which add shared pointers is implemented in detail::add_shared_pointer.

template<typename F, typename CLIST>
typedef std::vector<constraint_t> roboptim::Problem< F, CLIST >::constraints_t

Constraints are represented as a vector of constraints.

template<typename F, typename CLIST>
typedef F roboptim::Problem< F, CLIST >::function_t

Function type.

This has to be either Function or one of its sub-classes.

template<typename F, typename CLIST>
typedef Function::interval_t roboptim::Problem< F, CLIST >::interval_t
template<typename F, typename CLIST>
typedef Function::intervals_t roboptim::Problem< F, CLIST >::intervals_t
template<typename F, typename CLIST>
typedef std::vector<value_type> roboptim::Problem< F, CLIST >::scales_t

Scale vector.

template<typename F, typename CLIST>
typedef boost::optional<Function::vector_t> roboptim::Problem< F, CLIST >::startingPoint_t

Optional vector defines a starting point.

template<typename F, typename CLIST>
typedef function_t::value_type roboptim::Problem< F, CLIST >::value_type

Constructor & Destructor Documentation

template<typename F , typename CLIST >
roboptim::Problem< F, CLIST >::Problem ( const function_t f)
throw (
)
explicit
Precondition
costfunction $\mathbb{R}^n \rightarrow \mathbb{R}$

References roboptim::Function::makeInfiniteInterval().

template<typename F , typename CLIST >
roboptim::Problem< F, CLIST >::Problem ( const Problem< F, CLIST > &  pb)
throw (
)
explicit

Copy constructor.

template<typename F , typename CLIST >
template<typename F_ , typename CLIST_ >
roboptim::Problem< F, CLIST >::Problem ( const Problem< F_, CLIST_ > &  pb)
throw (
)
explicit

Copy constructor (convert from another class of problem).

template<typename F , typename CLIST >
roboptim::Problem< F, CLIST >::~Problem ( )
throw (
)

Member Function Documentation

template<typename F , typename CLIST >
template<typename C >
void roboptim::Problem< F, CLIST >::addConstraint ( boost::shared_ptr< C >  constraint,
interval_t  interval,
value_type  scale = 1. 
)
throw (std::runtime_error
)

Add a constraint to the problem.

Parameters
constraintthe constraint that will be added
intervalinterval in which the constraint is satisfied
scaleconstraint scale
Template Parameters
Cconstraint type (has to be in CLIST)
template<typename F , typename CLIST >
Problem< F, CLIST >::intervals_t & roboptim::Problem< F, CLIST >::argumentBounds ( )
throw (
)

Retrieve arguments bounds. Arguments bounds define in which interval each argument is valid.

Returns
arguments bounds
template<typename F , typename CLIST >
const Problem< F, CLIST >::intervals_t & roboptim::Problem< F, CLIST >::argumentBounds ( ) const
throw (
)

Retrieve arguments bounds. Arguments bounds define in which interval each argument is valid.

Returns
arguments bounds
template<typename F , typename CLIST >
Problem< F, CLIST >::scales_t & roboptim::Problem< F, CLIST >::argumentScales ( )
throw (
)

Retrieve arguments scales. Arguments scales define which scale is applied for each argument.

Returns
arguments scales
template<typename F , typename CLIST >
const Problem< F, CLIST >::scales_t & roboptim::Problem< F, CLIST >::argumentScales ( ) const
throw (
)

Retrieve arguments scales. Arguments scales define which scale is applied for each argument.

Returns
arguments scales
template<typename F , typename CLIST >
const Problem< F, CLIST >::intervals_t & roboptim::Problem< F, CLIST >::bounds ( ) const
throw (
)

Retrieve constraints bounds.

Returns
constraints bounds
template<typename F , typename CLIST >
const Problem< F, CLIST >::constraints_t & roboptim::Problem< F, CLIST >::constraints ( ) const
throw (
)

Retrieve constraints.

Returns
constraints
template<typename F , typename CLIST >
const Problem< F, CLIST >::function_t & roboptim::Problem< F, CLIST >::function ( ) const
throw (
)

Retrieve cost function.

Returns
cost function
template<typename F , typename CLIST >
std::ostream & roboptim::Problem< F, CLIST >::print ( std::ostream &  o) const
throw (
)

Display the problem on the specified output stream.

Parameters
ooutput stream used for display
Returns
output stream

References roboptim::decindent(), roboptim::iendl(), roboptim::incendl(), and roboptim::Function::infinity().

template<typename F , typename CLIST >
const Problem< F, CLIST >::scales_t & roboptim::Problem< F, CLIST >::scales ( ) const
throw (
)

Retrieve constraints scales.

Returns
constraints scales
template<typename F , typename CLIST >
Problem< F, CLIST >::startingPoint_t & roboptim::Problem< F, CLIST >::startingPoint ( )
throw (
)

Set the initial guess.

Returns
reference on the initial guess
template<typename F , typename CLIST >
const Problem< F, CLIST >::startingPoint_t & roboptim::Problem< F, CLIST >::startingPoint ( ) const
throw (
)

Get the initial guess.

Returns
reference on the initial guess

Friends And Related Function Documentation

template<typename F, typename CLIST>
template<typename F_ , typename CLIST_ >
friend class Problem
friend