All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
roboptim::Problem< T > Class Template Reference

#include <roboptim/core/problem.hh>

Public Types

typedef GenericFunction< T > function_t
 Function type. More...
 
typedef boost::mpl::vector
< function_t
constraintsList_t
 Constraints types list. More...
 
typedef boost::shared_ptr
< function_t
constraint_t
 Constraint's type. More...
 
typedef function_t::value_type value_type
 Import function's value_type type. More...
 
typedef function_t::vector_t vector_t
 Vector type. More...
 
typedef function_t::argument_t argument_t
 Argument type. More...
 
typedef function_t::result_t result_t
 Result type. More...
 
typedef function_t::size_type size_type
 Size type. More...
 
typedef std::vector< constraint_tconstraints_t
 Constraints are represented as a vector of constraints. More...
 
typedef boost::optional
< argument_t
startingPoint_t
 Optional vector defines a starting point. More...
 
typedef function_t::interval_t interval_t
 Interval type (e.g. for bounds). More...
 
typedef function_t::intervals_t intervals_t
 Intervals type. More...
 
typedef std::vector< value_typescaling_t
 Scaling vector. More...
 
typedef scaling_t scales_t
 Scaling vector (deprecated typedef) More...
 
typedef function_t::names_t names_t
 Vector of names (e.g. for arguments). More...
 
typedef std::vector< intervals_tintervalsVect_t
 Vector of interval vectors. More...
 
typedef std::vector< scaling_tscalingVect_t
 Vector of scaling vectors. More...
 
typedef scalingVect_t scalesVect_t
 Vector of scaling vectors (deprecated typedef). More...
 
typedef GenericFunctionTraits
< T >::jacobian_t 
jacobian_t
 Jacobian matrix type. More...
 
typedef GenericFunctionTraits
< T >::const_argument_ref 
const_argument_ref
 Constant reference to an argument vector. More...
 

Public Member Functions

std::ostream & print (std::ostream &o) const
 Display the problem on the specified output stream. More...
 
template<>
Problem< EigenMatrixSparse >
::jacobian_t 
jacobian (const_argument_ref x) const
 
template<int NORM>
Problem< T >::value_type constraintsViolation (const_argument_ref x) const
 
Constructors and destructors.
 Problem (const boost::shared_ptr< const function_t > &cost)
 Constructor taking a shared_ptr to a cost function. More...
 
 Problem (const function_t &cost)
 Deprecated constructor taking a reference to a cost function. More...
 
 Problem (const Problem< T > &pb)
 Copy constructor. More...
 
virtual ~Problem ()
 Virtual destructor. More...
 
Cost function.
const function_tfunction () const
 Retrieve cost function. More...
 
intervals_targumentBounds ()
 Retrieve arguments bounds. More...
 
const intervals_targumentBounds () const
 Retrieve arguments bounds. More...
 
scaling_tobjectiveScaling ()
 Retrieve objective scaling. More...
 
const scaling_tobjectiveScaling () const
 Retrieve objective scaling. More...
 
scaling_targumentScaling ()
 Retrieve arguments scaling. More...
 
const scaling_targumentScaling () const
 Retrieve arguments scaling. More...
 
scaling_targumentScales ()
 Retrieve arguments scaling (deprecated version). More...
 
const scaling_targumentScales () const
 Retrieve arguments scaling (deprecated version). More...
 
names_targumentNames ()
 Retrieve arguments names. More...
 
const names_targumentNames () const
 Retrieve arguments names. More...
 
Constraints.
const constraints_tconstraints () const
 Retrieve constraints. More...
 
void addConstraint (boost::shared_ptr< function_t > constraint, interval_t interval, value_type scale=1.)
 Add a constraint to the problem. More...
 
void addConstraint (boost::shared_ptr< function_t > constraint, intervals_t intervals, scaling_t scaling)
 Add a constraint to the problem. More...
 
const intervalsVect_tboundsVector () const
 Retrieve constraints bounds vector. More...
 
intervalsVect_tboundsVector ()
 Retrieve constraints bounds vector. More...
 
const scalingVect_tscalingVector () const
 Retrieve constraints scaling vector. More...
 
const scalingVect_tscalesVector () const
 Retrieve constraints scaling vector (deprecated version). More...
 
size_type constraintsOutputSize () const
 Return the output size of the problem's constraints. More...
 
size_type differentiableConstraintsOutputSize () const
 Return the output size of the problem's differentiable constraints. More...
 
void clearConstraints ()
 Clear the constraints from the problem. More...
 
Starting point (initial guess).
startingPoint_tstartingPoint ()
 Set the initial guess. More...
 
const startingPoint_tstartingPoint () const
 Get the initial guess. More...
 
Helper methods.
jacobian_t jacobian (const_argument_ref x) const
 Evaluate the Jacobian matrix of the problem for a given x. More...
 
jacobian_t scaledJacobian (const_argument_ref x) const
 Evaluate the scaled Jacobian matrix of the problem for a given x. More...
 
result_t constraintsViolationVector (const_argument_ref x) const
 Evaluate the vector of constraints violation for a given x. More...
 
template<int NORM>
value_type constraintsViolation (const_argument_ref x) const
 Evaluate the constraint violation for a given x. More...
 

Detailed Description

template<typename T>
class roboptim::Problem< T >

Examples:
problem-cc.cc.

Member Typedef Documentation

template<typename T>
typedef function_t::argument_t roboptim::Problem< T >::argument_t

Argument type.

Constant reference to an argument vector.

template<typename T>
typedef boost::shared_ptr<function_t> roboptim::Problem< T >::constraint_t

Constraint's type.

template<typename T>
typedef std::vector<constraint_t> roboptim::Problem< T >::constraints_t

Constraints are represented as a vector of constraints.

template<typename T>
typedef boost::mpl::vector<function_t> roboptim::Problem< T >::constraintsList_t

Constraints types list.

template<typename T>
typedef GenericFunction<T> roboptim::Problem< T >::function_t

Function type.

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

template<typename T>
typedef function_t::interval_t roboptim::Problem< T >::interval_t

Interval type (e.g. for bounds).

template<typename T>
typedef function_t::intervals_t roboptim::Problem< T >::intervals_t

Intervals type.

template<typename T>
typedef std::vector<intervals_t> roboptim::Problem< T >::intervalsVect_t

Vector of interval vectors.

This type is used to take into account the fact that constraints can have output values in \(\mathbb{C}^{m}\).

If \(m=1\), then the associated interval vector contains only one element of interval_t type.

template<typename T>
typedef GenericFunctionTraits<T>::jacobian_t roboptim::Problem< T >::jacobian_t

Jacobian matrix type.

template<typename T>
typedef function_t::names_t roboptim::Problem< T >::names_t

Vector of names (e.g. for arguments).

template<typename T>
typedef function_t::result_t roboptim::Problem< T >::result_t

Result type.

template<typename T>
typedef scaling_t roboptim::Problem< T >::scales_t

Scaling vector (deprecated typedef)

Deprecated:
Deprecated since version 3.1. Use Problem<T>::scaling_t instead.
template<typename T>
typedef scalingVect_t roboptim::Problem< T >::scalesVect_t

Vector of scaling vectors (deprecated typedef).

Deprecated:
Deprecated since version 3.1. Use Problem<T>::scalingVect_t instead.
template<typename T>
typedef std::vector<value_type> roboptim::Problem< T >::scaling_t

Scaling vector.

If \(g_u\) is the constraint as seen by the user, \(g_a\) the constraint as seen by the solver's algorithm, and \(s\) the scaling factor, then we have: \(g_a = s * g_u\)

template<typename T>
typedef std::vector<scaling_t> roboptim::Problem< T >::scalingVect_t

Vector of scaling vectors.

This type is used to take into account the fact that constraints can have output values in \(\mathbb{R}^m\).

If \(m=1\), then the associated scaling vector contains only one element of scaling_t type.

template<typename T>
typedef function_t::size_type roboptim::Problem< T >::size_type

Size type.

template<typename T>
typedef boost::optional<argument_t> roboptim::Problem< T >::startingPoint_t

Optional vector defines a starting point.

template<typename T>
typedef function_t::value_type roboptim::Problem< T >::value_type

Import function's value_type type.

template<typename T>
typedef function_t::vector_t roboptim::Problem< T >::vector_t

Vector type.

Constructor & Destructor Documentation

template<typename T >
roboptim::Problem< T >::Problem ( const boost::shared_ptr< const function_t > &  cost)
explicit

Constructor taking a shared_ptr to a cost function.

Precondition
costfunction \(\mathbb{R}^n \rightarrow \mathbb{R}\)
Parameters
costcost function.
template<typename T >
roboptim::Problem< T >::Problem ( const function_t cost)
explicit

Deprecated constructor taking a reference to a cost function.

This legacy version meant that we simply kept a const reference to the cost function, which could reference stack variables... This prepares the transition to something safer (shared_ptr).

Parameters
costcost function.
Deprecated:
Deprecated since version 3.2. Use the shared_ptr constructor instead.
template<typename T>
roboptim::Problem< T >::Problem ( const Problem< T > &  pb)
explicit

Copy constructor.

Parameters
pbproblem to copy.
template<typename T >
roboptim::Problem< T >::~Problem ( )
virtual

Virtual destructor.

One may want to inherit from Problem to provide extra information to a solver plugin.

Member Function Documentation

template<typename T >
void roboptim::Problem< T >::addConstraint ( boost::shared_ptr< function_t constraint,
interval_t  interval,
value_type  scale = 1. 
)

Add a constraint to the problem.

Useful only when \(m=1\), use addConstraint (boost::shared_ptr<C> constraint, intervals_t intervals, scaling_t scaling) instead.

Parameters
constraintthe constraint that will be added
intervalinterval in which the constraint is satisfied
scaleconstraint scale
Exceptions
std::runtime_error
template<typename T >
void roboptim::Problem< T >::addConstraint ( boost::shared_ptr< function_t constraint,
intervals_t  intervals,
scaling_t  scaling 
)

Add a constraint to the problem.

The constraint can be multidimensional.

Parameters
constraintthe constraint that will be added
intervalsinterval vector in which the constraint is satisfied
scalingconstraint scaling
Exceptions
std::runtime_error

References ROBOPTIM_DEBUG_ONLY.

template<typename T >
Problem< T >::intervals_t & roboptim::Problem< T >::argumentBounds ( )

Retrieve arguments bounds.

Arguments bounds define in which interval each argument is valid.

Returns
arguments bounds
template<typename T >
const Problem< T >::intervals_t & roboptim::Problem< T >::argumentBounds ( ) const

Retrieve arguments bounds.

Arguments bounds define in which interval each argument is valid.

Returns
arguments bounds
template<typename T >
Problem< T >::names_t & roboptim::Problem< T >::argumentNames ( )

Retrieve arguments names.

Arguments names define a name for each argument. This is particularly useful when logging data.

Returns
arguments names
template<typename T >
const Problem< T >::names_t & roboptim::Problem< T >::argumentNames ( ) const

Retrieve arguments names.

Arguments names define a name for each argument. This is particularly useful when logging data.

Returns
arguments names
template<typename T >
Problem< T >::scaling_t & roboptim::Problem< T >::argumentScales ( )

Retrieve arguments scaling (deprecated version).

Deprecated:
Deprecated since version 3.1. Use argumentScaling() instead.
template<typename T >
const Problem< T >::scaling_t & roboptim::Problem< T >::argumentScales ( ) const

Retrieve arguments scaling (deprecated version).

Deprecated:
Deprecated since version 3.1. Use argumentScaling() instead.
template<typename T >
Problem< T >::scaling_t & roboptim::Problem< T >::argumentScaling ( )

Retrieve arguments scaling.

Arguments scaling define which scale factor is applied for each argument.

Returns
arguments scaling
template<typename T >
const Problem< T >::scaling_t & roboptim::Problem< T >::argumentScaling ( ) const

Retrieve arguments scaling.

Arguments scaling define which scale factor is applied for each argument.

Returns
arguments scaling
template<typename T >
const Problem< T >::intervalsVect_t & roboptim::Problem< T >::boundsVector ( ) const

Retrieve constraints bounds vector.

Returns
constraints bounds vector
template<typename T >
Problem< T >::intervalsVect_t & roboptim::Problem< T >::boundsVector ( )

Retrieve constraints bounds vector.

Returns
constraints bounds vector
template<typename T >
void roboptim::Problem< T >::clearConstraints ( )

Clear the constraints from the problem.

template<typename T >
const Problem< T >::constraints_t & roboptim::Problem< T >::constraints ( ) const

Retrieve constraints.

Returns
constraints

Referenced by roboptim::ResultAnalyzer< T >::checkNullGradient(), and roboptim::ScalingHelper< T >::ScalingHelper().

template<typename T >
Problem< T >::size_type roboptim::Problem< T >::constraintsOutputSize ( ) const

Return the output size of the problem's constraints.

template<typename T>
template<int NORM>
value_type roboptim::Problem< T >::constraintsViolation ( const_argument_ref  x) const

Evaluate the constraint violation for a given x.

This takes into account both argument bounds and constraint bounds.

Parameters
xevaluation point.
Returns
constraint violation at x.
Template Parameters
ALGEigen norm used for the reduction, e.g. 1 or Eigen::Infinity.
template<typename T>
template<int NORM>
Problem<T>::value_type roboptim::Problem< T >::constraintsViolation ( const_argument_ref  x) const
template<typename T >
Problem< T >::result_t roboptim::Problem< T >::constraintsViolationVector ( const_argument_ref  x) const

Evaluate the vector of constraints violation for a given x.

This takes into account both argument bounds and constraint bounds. If the output value is lower than the lower bound, the violation is negative. If the output value is higher than the upper bound, the violation is positive. If the output value is within the bounds, the violation is null.

Parameters
xevaluation point.
Returns
vector of constraint violation at x.

References roboptim::GenericFunction< T >::infinity().

Referenced by roboptim::ResultAnalyzer< T >::checkKKT().

template<typename T >
Problem< T >::size_type roboptim::Problem< T >::differentiableConstraintsOutputSize ( ) const

Return the output size of the problem's differentiable constraints.

template<typename T >
const Problem< T >::function_t & roboptim::Problem< T >::function ( ) const

Retrieve cost function.

Returns
cost function
template<typename T >
Problem< T >::jacobian_t roboptim::Problem< T >::jacobian ( const_argument_ref  x) const

Evaluate the Jacobian matrix of the problem for a given x.

Note: this is a helper method, and is not supposed to be used in any critical loop.

Parameters
xevaluation point.
Returns
Jacobian matrix evaluated at x.

References roboptim::GenericFunction< T >::inputSize().

template<typename T >
Problem< T >::scaling_t & roboptim::Problem< T >::objectiveScaling ( )

Retrieve objective scaling.

Objective scaling defines the scaling factors applied to the objective function.

Returns
objective scaling
template<typename T >
const Problem< T >::scaling_t & roboptim::Problem< T >::objectiveScaling ( ) const

Retrieve objective scaling.

Objective scaling defines the scaling factors applied to the objective function.

Returns
objective scaling
template<typename T >
std::ostream & roboptim::Problem< T >::print ( std::ostream &  o) const

Display the problem on the specified output stream.

Parameters
ooutput stream used for display
Returns
output stream

References roboptim::decindent(), roboptim::fg::fail(), roboptim::iendl(), roboptim::incendl(), roboptim::fg::ok(), roboptim::fg::reset(), and roboptim::fg::warn().

template<typename T >
Problem< T >::jacobian_t roboptim::Problem< T >::scaledJacobian ( const_argument_ref  x) const

Evaluate the scaled Jacobian matrix of the problem for a given x.

Note: this is a helper method, and is not supposed to be used in any critical loop. Both constraint and argument scaling parameters are applied.

Parameters
xevaluation point.
Returns
scaled Jacobian matrix evaluated at x.
template<typename T >
const Problem< T >::scalingVect_t & roboptim::Problem< T >::scalesVector ( ) const

Retrieve constraints scaling vector (deprecated version).

Deprecated:
Deprecated since version 3.1. Use scalingVector() instead.
template<typename T >
const Problem< T >::scalingVect_t & roboptim::Problem< T >::scalingVector ( ) const

Retrieve constraints scaling vector.

Returns
constraints scaling vector
template<typename T >
Problem< T >::startingPoint_t & roboptim::Problem< T >::startingPoint ( )

Set the initial guess.

Returns
reference on the initial guess
Exceptions
std::runtime_error
template<typename T >
const Problem< T >::startingPoint_t & roboptim::Problem< T >::startingPoint ( ) const

Get the initial guess.

Returns
reference on the initial guess
Exceptions
std::runtime_error