DART  6.6.2
dart::optimizer::GradientDescentSolver Class Reference

DefaultSolver is a Solver extension which is native to DART (rather than relying on third-party libraries). More...

#include <GradientDescentSolver.hpp>

Inheritance diagram for dart::optimizer::GradientDescentSolver:
dart::optimizer::Solver

Classes

struct  Properties
 
struct  UniqueProperties
 

Public Member Functions

 GradientDescentSolver (const Properties &_properties=Properties())
 Default constructor. More...
 
 GradientDescentSolver (std::shared_ptr< Problem > _problem)
 Alternative constructor. More...
 
virtual ~GradientDescentSolver ()
 Destructor. More...
 
bool solve () override
 Solve optimization problem. More...
 
Eigen::VectorXd getLastConfiguration () const
 Get the last configuration that was used by the Solver. More...
 
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 setProperties (const Properties &_properties)
 Set the Properties of this GradientDescentSolver. More...
 
void setProperties (const UniqueProperties &_properties)
 Set the Properties of this GradientDescentSolver. More...
 
Properties getGradientDescentProperties () const
 Get the Properties of this GradientDescentSolver. More...
 
void copy (const GradientDescentSolver &_other)
 Copy the Properties of another GradientDescentSolver. More...
 
GradientDescentSolveroperator= (const GradientDescentSolver &_other)
 Copy the Properties of another GradientDescentSolver. More...
 
void setStepSize (double _newMultiplier)
 Set the multiplier for the step size. More...
 
double getStepSize () const
 Get the multiplier for the step size. More...
 
void setMaxAttempts (std::size_t _maxAttempts)
 Set the maximum number of solving attempts before quitting. More...
 
std::size_t getMaxAttempts () const
 Get the maximum number of solving attempts. More...
 
void setPerturbationStep (std::size_t _step)
 Set the number of steps that will be taken before applying a randomized perturbation. More...
 
std::size_t getPerturbationStep () const
 Get UniqueProperties::mPerturbationStep. More...
 
void setMaxPerturbationFactor (double _factor)
 Set UniqueProperties::mPerturbationFactor. More...
 
double getMaxPerturbationFactor () const
 Get UniqueProperties::mPerturbationFactor. More...
 
void setDefaultConstraintWeight (double _newDefault)
 Set UniqueProperties::mDefaultConstraintWeight. More...
 
double getDefaultConstraintWeight () const
 Get UniqueProperties::mDefaultConstraintWeight. More...
 
Eigen::VectorXd & getEqConstraintWeights ()
 Set UniqueProperties::mEqConstraintWeights. More...
 
const Eigen::VectorXd & getEqConstraintWeights () const
 Get UniqueProperties::mEqConstraintWeights. More...
 
Eigen::VectorXd & getIneqConstraintWeights ()
 Set UniqueProperties::mIneqConstraintWeights. More...
 
const Eigen::VectorXd & getIneqConstraintWeights () const
 Get UniqueProperties::mIneqConstraintWeights. More...
 
void randomizeConfiguration (Eigen::VectorXd &_x)
 Randomize the configuration based on this Solver's settings. More...
 
void clampToBoundary (Eigen::VectorXd &_x)
 Clamp the configuration to the limits of the Problem. More...
 
std::size_t getLastNumIterations () const
 Get the number of iterations used in the last attempt to solve the problem. 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...
 

Static Public Attributes

static const std::string Type = "GradientDescentSolver"
 

Protected Attributes

UniqueProperties mGradientP
 GradientDescentSolver properties. More...
 
std::size_t mLastNumIterations
 The last number of iterations performed by this Solver. More...
 
std::random_device mRD
 Randomization device. More...
 
std::mt19937 mMT
 Mersenne twister method. More...
 
std::uniform_real_distribution< double > mDistribution
 Distribution. More...
 
Eigen::VectorXd mEqConstraintCostCache
 Cache to track the costs of equality constraints. More...
 
Eigen::VectorXd mIneqConstraintCostCache
 Cache to track the costs of inequality constraints. More...
 
Eigen::VectorXd mLastConfig
 The last config reached by this Solver. More...
 
Properties mProperties
 

Detailed Description

DefaultSolver is a Solver extension which is native to DART (rather than relying on third-party libraries).

It uses randomized gradient descent and softened constraints (i.e. constraint functions are added into the objective function and assigned weights) to solve nonlinear problems. Note that this is not a good option for Problems with difficult constraint functions that need to be solved exactly.

Constructor & Destructor Documentation

◆ GradientDescentSolver() [1/2]

dart::optimizer::GradientDescentSolver::GradientDescentSolver ( const Properties _properties = Properties())
explicit

Default constructor.

◆ GradientDescentSolver() [2/2]

dart::optimizer::GradientDescentSolver::GradientDescentSolver ( std::shared_ptr< Problem _problem)
explicit

Alternative constructor.

◆ ~GradientDescentSolver()

dart::optimizer::GradientDescentSolver::~GradientDescentSolver ( )
virtual

Destructor.

Member Function Documentation

◆ clampToBoundary()

void dart::optimizer::GradientDescentSolver::clampToBoundary ( Eigen::VectorXd &  _x)

Clamp the configuration to the limits of the Problem.

◆ clone()

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

Create an identical clone of this Solver.

Implements dart::optimizer::Solver.

◆ copy() [1/2]

void dart::optimizer::GradientDescentSolver::copy ( const GradientDescentSolver _other)

Copy the Properties of another GradientDescentSolver.

◆ copy() [2/2]

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

Copy the generic Properties of another Solver.

◆ getDefaultConstraintWeight()

double dart::optimizer::GradientDescentSolver::getDefaultConstraintWeight ( ) const

◆ getEqConstraintWeights() [1/2]

Eigen::VectorXd & dart::optimizer::GradientDescentSolver::getEqConstraintWeights ( )

◆ getEqConstraintWeights() [2/2]

const Eigen::VectorXd & dart::optimizer::GradientDescentSolver::getEqConstraintWeights ( ) const

◆ getGradientDescentProperties()

GradientDescentSolver::Properties dart::optimizer::GradientDescentSolver::getGradientDescentProperties ( ) const

◆ getIneqConstraintWeights() [1/2]

Eigen::VectorXd & dart::optimizer::GradientDescentSolver::getIneqConstraintWeights ( )

◆ getIneqConstraintWeights() [2/2]

const Eigen::VectorXd & dart::optimizer::GradientDescentSolver::getIneqConstraintWeights ( ) const

◆ 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::GradientDescentSolver::getLastConfiguration ( ) const

Get the last configuration that was used by the Solver.

◆ getLastNumIterations()

std::size_t dart::optimizer::GradientDescentSolver::getLastNumIterations ( ) const

Get the number of iterations used in the last attempt to solve the problem.

◆ getMaxAttempts()

std::size_t dart::optimizer::GradientDescentSolver::getMaxAttempts ( ) const

Get the maximum number of solving attempts.

◆ getMaxPerturbationFactor()

double dart::optimizer::GradientDescentSolver::getMaxPerturbationFactor ( ) const

Get UniqueProperties::mPerturbationFactor.

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

◆ getPerturbationStep()

std::size_t dart::optimizer::GradientDescentSolver::getPerturbationStep ( ) const

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

◆ getStepSize()

double dart::optimizer::GradientDescentSolver::getStepSize ( ) const

Get the multiplier for the step size.

◆ 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::GradientDescentSolver::getType ( ) const
overridevirtual

Get the type (implementation) of this Solver.

Implements dart::optimizer::Solver.

◆ operator=()

GradientDescentSolver & dart::optimizer::GradientDescentSolver::operator= ( const GradientDescentSolver _other)

Copy the Properties of another GradientDescentSolver.

◆ randomizeConfiguration()

void dart::optimizer::GradientDescentSolver::randomizeConfiguration ( Eigen::VectorXd &  _x)

Randomize the configuration based on this Solver's settings.

◆ setDefaultConstraintWeight()

void dart::optimizer::GradientDescentSolver::setDefaultConstraintWeight ( double  _newDefault)

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

◆ setMaxAttempts()

void dart::optimizer::GradientDescentSolver::setMaxAttempts ( std::size_t  _maxAttempts)

Set the maximum number of solving attempts before quitting.

Each attempt will use getNumMaxIterations() steps. When a new attempt is started, it will use the next seed in the list of seeds. If we've reached the end of the list of seeds, the attempt will start from a randomized configuration.

◆ setMaxPerturbationFactor()

void dart::optimizer::GradientDescentSolver::setMaxPerturbationFactor ( double  _factor)

Set UniqueProperties::mPerturbationFactor.

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

◆ setPerturbationStep()

void dart::optimizer::GradientDescentSolver::setPerturbationStep ( std::size_t  _step)

Set the number of steps that will be taken before applying a randomized perturbation.

◆ 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() [1/3]

void dart::optimizer::GradientDescentSolver::setProperties ( const Properties _properties)

◆ setProperties() [2/3]

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

Set the generic Properties of this Solver.

◆ setProperties() [3/3]

void dart::optimizer::GradientDescentSolver::setProperties ( const UniqueProperties _properties)

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

◆ setStepSize()

void dart::optimizer::GradientDescentSolver::setStepSize ( double  _newMultiplier)

Set the multiplier for the step size.

◆ 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::GradientDescentSolver::solve ( )
overridevirtual

Solve optimization problem.

Implements dart::optimizer::Solver.

Member Data Documentation

◆ mDistribution

std::uniform_real_distribution<double> dart::optimizer::GradientDescentSolver::mDistribution
protected

Distribution.

◆ mEqConstraintCostCache

Eigen::VectorXd dart::optimizer::GradientDescentSolver::mEqConstraintCostCache
protected

Cache to track the costs of equality constraints.

◆ mGradientP

UniqueProperties dart::optimizer::GradientDescentSolver::mGradientP
protected

GradientDescentSolver properties.

◆ mIneqConstraintCostCache

Eigen::VectorXd dart::optimizer::GradientDescentSolver::mIneqConstraintCostCache
protected

Cache to track the costs of inequality constraints.

◆ mLastConfig

Eigen::VectorXd dart::optimizer::GradientDescentSolver::mLastConfig
protected

The last config reached by this Solver.

◆ mLastNumIterations

std::size_t dart::optimizer::GradientDescentSolver::mLastNumIterations
protected

The last number of iterations performed by this Solver.

◆ mMT

std::mt19937 dart::optimizer::GradientDescentSolver::mMT
protected

Mersenne twister method.

◆ mProperties

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

◆ mRD

std::random_device dart::optimizer::GradientDescentSolver::mRD
protected

Randomization device.

◆ Type

const std::string dart::optimizer::GradientDescentSolver::Type = "GradientDescentSolver"
static