DART  6.10.1
dart::optimizer::NloptSolver Class Reference

NloptSolver is a nonlinear programming solver that provides many unlerlying algorithms through nlopt (an third-party library: https://nlopt.readthedocs.io/). More...

#include <NloptSolver.hpp>

Inheritance diagram for dart::optimizer::NloptSolver:
dart::optimizer::Solver

Public Types

enum  Algorithm {
  GN_DIRECT = 0 , GN_DIRECT_L , GN_DIRECT_L_RAND , GN_DIRECT_NOSCAL ,
  GN_DIRECT_L_NOSCAL , GN_DIRECT_L_RAND_NOSCAL , GN_ORIG_DIRECT , GN_ORIG_DIRECT_L ,
  GD_STOGO , GD_STOGO_RAND , LD_LBFGS_NOCEDAL , LD_LBFGS ,
  LN_PRAXIS , LD_VAR1 , LD_VAR2 , LD_TNEWTON ,
  LD_TNEWTON_RESTART , LD_TNEWTON_PRECOND , LD_TNEWTON_PRECOND_RESTART , GN_CRS2_LM ,
  GN_MLSL , GD_MLSL , GN_MLSL_LDS , GD_MLSL_LDS ,
  LD_MMA , LN_COBYLA , LN_NEWUOA , LN_NEWUOA_BOUND ,
  LN_NELDERMEAD , LN_SBPLX , LN_AUGLAG , LD_AUGLAG ,
  LN_AUGLAG_EQ , LD_AUGLAG_EQ , LN_BOBYQA , GN_ISRES ,
  AUGLAG , AUGLAG_EQ , G_MLSL , G_MLSL_LDS ,
  LD_SLSQP , LD_CCSAQ , GN_ESCH , NUM_ALGORITHMS
}
 

Public Member Functions

 NloptSolver (const Solver::Properties &properties, nlopt::algorithm alg)
 Default Constructor. More...
 
 NloptSolver (const Solver::Properties &properties=Solver::Properties(), Algorithm alg=LN_COBYLA)
 Default Constructor. More...
 
 NloptSolver (std::shared_ptr< Problem > problem, nlopt::algorithm alg)
 Alternative Constructor. More...
 
 NloptSolver (std::shared_ptr< Problem > problem, Algorithm alg=LN_COBYLA)
 Alternative Constructor. More...
 
 ~NloptSolver () override
 Destructor. More...
 
bool solve () override
 Solve optimization problem. More...
 
Eigen::VectorXd getLastConfiguration () const
 
std::string getType () const override
 Get the type (implementation) of this Solver. More...
 
std::shared_ptr< Solverclone () const override
 Create an identical clone of this Solver. More...
 
void copy (const NloptSolver &other)
 Copy the Properties of another NloptSolver. More...
 
NloptSolveroperator= (const NloptSolver &other)
 Copy the Properties of another NloptSolver. More...
 
void setAlgorithm (nlopt::algorithm alg)
 Set the algorithm that is to be used by the nlopt solver. More...
 
void setAlgorithm (Algorithm alg)
 Set the algorithm that is to be used by the nlopt solver. More...
 
nlopt::algorithm getAlgorithm () const
 Get the algorithm that is to be used by the nlopt solver. More...
 
Algorithm getAlgorithm2 () const
 Get the algorithm that is to be used by the nlopt solver. More...
 
void setProperties (const Properties &_properties)
 Set the generic Properties of this Solver. More...
 
const PropertiesgetSolverProperties () const
 Get the generic Properties of this Solver. More...
 
void copy (const Solver &_otherSolver)
 Copy the generic Properties of another Solver. More...
 
virtual void setProblem (std::shared_ptr< Problem > _newProblem)
 Set the nonlinear optimization problem. More...
 
std::shared_ptr< ProblemgetProblem () const
 Get nonlinear optimization problem. More...
 
virtual void setTolerance (double _newTolerance)
 Set the maximum step size allowed for the Problem to be considered converged. More...
 
double getTolerance () const
 Get the maximum step size allowed for the Problem to be considered converged. More...
 
virtual void setNumMaxIterations (std::size_t _newMax)
 Set the maximum number of iterations that the Solver should use. More...
 
std::size_t getNumMaxIterations () const
 Get the maximum number of iterations that the Solver should use. More...
 
virtual void setIterationsPerPrint (std::size_t _newRatio)
 Set the number of iterations that should pass between printing progress to the terminal. More...
 
std::size_t getIterationsPerPrint () const
 Get the number of iterations that should pass between printing progress to the terminal. More...
 
virtual void setOutStream (std::ostream *_os)
 Set the output stream that prints the Solver's progress. More...
 
std::ostream * getOutStream () const
 Get the output stream that prints the Solver's progress. More...
 
virtual void setPrintFinalResult (bool _print)
 Set to true if the final result should be printed to the terminal. More...
 
bool getPrintFinalResult () const
 Returns true if the final result should be printed to the terminal. More...
 
virtual void setResultFileName (const std::string &_resultFile)
 Set the name of the file that results should be printed to. More...
 
const std::string & getResultFileName () const
 Get the name of the file that results should be printed to. More...
 

Protected Attributes

Properties mProperties
 

Static Private Member Functions

static nlopt::algorithm convertAlgorithm (Algorithm algorithm)
 Converts nlopt::algorithm to NloptSolver::Algorithm. More...
 
static Algorithm convertAlgorithm (nlopt::algorithm algorithm)
 Converts NloptSolver::Algorithm to nlopt::algorithm. More...
 
static double _nlopt_func (unsigned n, const double *x, double *gradient, void *func_data)
 Wrapping function for nlopt callback function, nlopt_func. More...
 
static void _nlopt_mfunc (unsigned m, double *result, unsigned n, const double *x, double *gradient, void *func_data)
 Wrapping function for nlopt callback function, nlopt_mfunc. More...
 

Private Attributes

std::unique_ptr< nlopt::opt > mOpt
 NLOPT data structure. More...
 
nlopt::algorithm mAlg
 Algorithm to be used by the nlopt::opt. More...
 
std::vector< double > mX
 Optimization parameters. More...
 
double mMinF
 Optimum value of the objective function. More...
 

Detailed Description

NloptSolver is a nonlinear programming solver that provides many unlerlying algorithms through nlopt (an third-party library: https://nlopt.readthedocs.io/).

The algorithms falls into four categories: (1) Global derivative-free (2) Global gradient-based (3) Local derivative-free (4) Local gradient-based, which can be specified by NloptSolver::Algorithm. The element of NloptSolver are mostly of the form NLOPT_{G,L}{N,D}_xxxx, where G/L denotes global/local optimization and N/D denotes derivative-free/gradient-based algorithms, respectively. For the details, please see: https://nlopt.readthedocs.io/en/latest/NLopt_Algorithms/

Member Enumeration Documentation

◆ Algorithm

Enumerator
GN_DIRECT 
GN_DIRECT_L 
GN_DIRECT_L_RAND 
GN_DIRECT_NOSCAL 
GN_DIRECT_L_NOSCAL 
GN_DIRECT_L_RAND_NOSCAL 
GN_ORIG_DIRECT 
GN_ORIG_DIRECT_L 
GD_STOGO 
GD_STOGO_RAND 
LD_LBFGS_NOCEDAL 
LD_LBFGS 
LN_PRAXIS 
LD_VAR1 
LD_VAR2 
LD_TNEWTON 
LD_TNEWTON_RESTART 
LD_TNEWTON_PRECOND 
LD_TNEWTON_PRECOND_RESTART 
GN_CRS2_LM 
GN_MLSL 
GD_MLSL 
GN_MLSL_LDS 
GD_MLSL_LDS 
LD_MMA 
LN_COBYLA 
LN_NEWUOA 
LN_NEWUOA_BOUND 
LN_NELDERMEAD 
LN_SBPLX 
LN_AUGLAG 
LD_AUGLAG 
LN_AUGLAG_EQ 
LD_AUGLAG_EQ 
LN_BOBYQA 
GN_ISRES 
AUGLAG 
AUGLAG_EQ 
G_MLSL 
G_MLSL_LDS 
LD_SLSQP 
LD_CCSAQ 
GN_ESCH 
NUM_ALGORITHMS 

Not an algorithm, just the number of them.

Constructor & Destructor Documentation

◆ NloptSolver() [1/4]

dart::optimizer::NloptSolver::NloptSolver ( const Solver::Properties properties,
nlopt::algorithm  alg 
)

Default Constructor.

◆ NloptSolver() [2/4]

dart::optimizer::NloptSolver::NloptSolver ( const Solver::Properties properties = Solver::Properties(),
NloptSolver::Algorithm  alg = LN_COBYLA 
)

Default Constructor.

◆ NloptSolver() [3/4]

dart::optimizer::NloptSolver::NloptSolver ( std::shared_ptr< Problem problem,
nlopt::algorithm  alg 
)

Alternative Constructor.

◆ NloptSolver() [4/4]

dart::optimizer::NloptSolver::NloptSolver ( std::shared_ptr< Problem problem,
NloptSolver::Algorithm  alg = LN_COBYLA 
)

Alternative Constructor.

◆ ~NloptSolver()

dart::optimizer::NloptSolver::~NloptSolver ( )
override

Destructor.

Member Function Documentation

◆ _nlopt_func()

double dart::optimizer::NloptSolver::_nlopt_func ( unsigned  n,
const double *  x,
double *  gradient,
void *  func_data 
)
staticprivate

Wrapping function for nlopt callback function, nlopt_func.

◆ _nlopt_mfunc()

void dart::optimizer::NloptSolver::_nlopt_mfunc ( unsigned  m,
double *  result,
unsigned  n,
const double *  x,
double *  gradient,
void *  func_data 
)
staticprivate

Wrapping function for nlopt callback function, nlopt_mfunc.

◆ clone()

std::shared_ptr< Solver > dart::optimizer::NloptSolver::clone ( ) const
overridevirtual

Create an identical clone of this Solver.

Implements dart::optimizer::Solver.

◆ convertAlgorithm() [1/2]

nlopt::algorithm dart::optimizer::NloptSolver::convertAlgorithm ( NloptSolver::Algorithm  algorithm)
staticprivate

Converts nlopt::algorithm to NloptSolver::Algorithm.

◆ convertAlgorithm() [2/2]

NloptSolver::Algorithm dart::optimizer::NloptSolver::convertAlgorithm ( nlopt::algorithm  algorithm)
staticprivate

Converts NloptSolver::Algorithm to nlopt::algorithm.

◆ copy() [1/2]

void dart::optimizer::NloptSolver::copy ( const NloptSolver other)

Copy the Properties of another NloptSolver.

◆ copy() [2/2]

void dart::optimizer::Solver::copy ( const Solver _otherSolver)
inherited

Copy the generic Properties of another Solver.

◆ getAlgorithm()

nlopt::algorithm dart::optimizer::NloptSolver::getAlgorithm ( ) const

Get the algorithm that is to be used by the nlopt solver.

◆ getAlgorithm2()

NloptSolver::Algorithm dart::optimizer::NloptSolver::getAlgorithm2 ( ) const

Get the algorithm that is to be used by the nlopt solver.

◆ getIterationsPerPrint()

std::size_t dart::optimizer::Solver::getIterationsPerPrint ( ) const
inherited

Get the number of iterations that should pass between printing progress to the terminal.

A value of 0 means there will be no printing.

◆ getLastConfiguration()

Eigen::VectorXd dart::optimizer::NloptSolver::getLastConfiguration ( ) const

◆ getNumMaxIterations()

std::size_t dart::optimizer::Solver::getNumMaxIterations ( ) const
inherited

Get the maximum number of iterations that the Solver should use.

◆ getOutStream()

std::ostream * dart::optimizer::Solver::getOutStream ( ) const
inherited

Get the output stream that prints the Solver's progress.

◆ getPrintFinalResult()

bool dart::optimizer::Solver::getPrintFinalResult ( ) const
inherited

Returns true if the final result should be printed to the terminal.

◆ getProblem()

std::shared_ptr< Problem > dart::optimizer::Solver::getProblem ( ) const
inherited

Get nonlinear optimization problem.

◆ getResultFileName()

const std::string & dart::optimizer::Solver::getResultFileName ( ) const
inherited

Get the name of the file that results should be printed to.

An empty string indicates that results should not be printed to a file.

◆ getSolverProperties()

const Solver::Properties & dart::optimizer::Solver::getSolverProperties ( ) const
inherited

Get the generic Properties of this Solver.

◆ getTolerance()

double dart::optimizer::Solver::getTolerance ( ) const
inherited

Get the maximum step size allowed for the Problem to be considered converged.

◆ getType()

std::string dart::optimizer::NloptSolver::getType ( ) const
overridevirtual

Get the type (implementation) of this Solver.

Implements dart::optimizer::Solver.

◆ operator=()

NloptSolver & dart::optimizer::NloptSolver::operator= ( const NloptSolver other)

Copy the Properties of another NloptSolver.

◆ setAlgorithm() [1/2]

void dart::optimizer::NloptSolver::setAlgorithm ( NloptSolver::Algorithm  alg)

Set the algorithm that is to be used by the nlopt solver.

◆ setAlgorithm() [2/2]

void dart::optimizer::NloptSolver::setAlgorithm ( nlopt::algorithm  alg)

Set the algorithm that is to be used by the nlopt solver.

◆ setIterationsPerPrint()

void dart::optimizer::Solver::setIterationsPerPrint ( std::size_t  _newRatio)
virtualinherited

Set the number of iterations that should pass between printing progress to the terminal.

Use 0 for no printing.

◆ setNumMaxIterations()

void dart::optimizer::Solver::setNumMaxIterations ( std::size_t  _newMax)
virtualinherited

Set the maximum number of iterations that the Solver should use.

◆ setOutStream()

void dart::optimizer::Solver::setOutStream ( std::ostream *  _os)
virtualinherited

Set the output stream that prints the Solver's progress.

◆ setPrintFinalResult()

void dart::optimizer::Solver::setPrintFinalResult ( bool  _print)
virtualinherited

Set to true if the final result should be printed to the terminal.

◆ setProblem()

void dart::optimizer::Solver::setProblem ( std::shared_ptr< Problem _newProblem)
virtualinherited

Set the nonlinear optimization problem.

◆ setProperties()

void dart::optimizer::Solver::setProperties ( const Properties _properties)
inherited

Set the generic Properties of this Solver.

◆ setResultFileName()

void dart::optimizer::Solver::setResultFileName ( const std::string &  _resultFile)
virtualinherited

Set the name of the file that results should be printed to.

Use an empty string to indicate that results should not be printed to a file.

◆ setTolerance()

void dart::optimizer::Solver::setTolerance ( double  _newTolerance)
virtualinherited

Set the maximum step size allowed for the Problem to be considered converged.

◆ solve()

bool dart::optimizer::NloptSolver::solve ( )
overridevirtual

Solve optimization problem.

Implements dart::optimizer::Solver.

Member Data Documentation

◆ mAlg

nlopt::algorithm dart::optimizer::NloptSolver::mAlg
private

Algorithm to be used by the nlopt::opt.

◆ mMinF

double dart::optimizer::NloptSolver::mMinF
private

Optimum value of the objective function.

◆ mOpt

std::unique_ptr<nlopt::opt> dart::optimizer::NloptSolver::mOpt
private

NLOPT data structure.

◆ mProperties

Properties dart::optimizer::Solver::mProperties
protectedinherited

◆ mX

std::vector<double> dart::optimizer::NloptSolver::mX
private

Optimization parameters.