dart
|
DefaultSolver is a Solver extension which is native to DART (rather than relying on third-party libraries). More...
#include <GradientDescentSolver.hpp>
Classes | |
struct | Properties |
struct | UniqueProperties |
Public Member Functions | |
GradientDescentSolver (const Properties &_properties=Properties()) | |
Default constructor. | |
GradientDescentSolver (std::shared_ptr< Problem > _problem) | |
Alternative constructor. | |
virtual | ~GradientDescentSolver () |
Destructor. | |
bool | solve () override |
Solve optimization problem. | |
Eigen::VectorXd | getLastConfiguration () const |
Get the last configuration that was used by the Solver. | |
std::string | getType () const override |
Get the type (implementation) of this Solver. | |
std::shared_ptr< Solver > | clone () const override |
Create an identical clone of this Solver. | |
void | setProperties (const Properties &_properties) |
Set the Properties of this GradientDescentSolver. | |
void | setProperties (const UniqueProperties &_properties) |
Set the Properties of this GradientDescentSolver. | |
Properties | getGradientDescentProperties () const |
Get the Properties of this GradientDescentSolver. | |
void | copy (const GradientDescentSolver &_other) |
Copy the Properties of another GradientDescentSolver. | |
GradientDescentSolver & | operator= (const GradientDescentSolver &_other) |
Copy the Properties of another GradientDescentSolver. | |
void | setStepSize (double _newMultiplier) |
Set the multiplier for the step size. | |
double | getStepSize () const |
Get the multiplier for the step size. | |
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. | |
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. | |
void | setMaxPerturbationFactor (double _factor) |
Set UniqueProperties::mPerturbationFactor. | |
double | getMaxPerturbationFactor () const |
Get UniqueProperties::mPerturbationFactor. | |
void | setDefaultConstraintWeight (double _newDefault) |
Set UniqueProperties::mDefaultConstraintWeight. | |
double | getDefaultConstraintWeight () const |
Get UniqueProperties::mDefaultConstraintWeight. | |
Eigen::VectorXd & | getEqConstraintWeights () |
Set UniqueProperties::mEqConstraintWeights. | |
const Eigen::VectorXd & | getEqConstraintWeights () const |
Get UniqueProperties::mEqConstraintWeights. | |
Eigen::VectorXd & | getIneqConstraintWeights () |
Set UniqueProperties::mIneqConstraintWeights. | |
const Eigen::VectorXd & | getIneqConstraintWeights () const |
Get UniqueProperties::mIneqConstraintWeights. | |
void | randomizeConfiguration (Eigen::VectorXd &_x) |
Randomize the configuration based on this Solver's settings. | |
void | clampToBoundary (Eigen::VectorXd &_x) |
Clamp the configuration to the limits of the Problem. | |
std::size_t | getLastNumIterations () const |
Get the number of iterations used in the last attempt to solve the problem. | |
![]() | |
Solver (const Properties &_properties=Properties()) | |
Default Constructor. | |
Solver (std::shared_ptr< Problem > _problem) | |
Alternative Constructor. | |
virtual | ~Solver ()=default |
Destructor. | |
void | setProperties (const Properties &_properties) |
Set the generic Properties of this Solver. | |
const Properties & | getSolverProperties () const |
Get the generic Properties of this Solver. | |
void | copy (const Solver &_otherSolver) |
Copy the generic Properties of another Solver. | |
Solver & | operator= (const Solver &_otherSolver) |
Copy the generic Properties of another Solver. | |
virtual void | setProblem (std::shared_ptr< Problem > _newProblem) |
Set the nonlinear optimization problem. | |
std::shared_ptr< Problem > | getProblem () const |
Get nonlinear optimization problem. | |
virtual void | setTolerance (double _newTolerance) |
Set the maximum step size allowed for the Problem to be considered converged. | |
double | getTolerance () const |
Get the maximum step size allowed for the Problem to be considered converged. | |
virtual void | setNumMaxIterations (std::size_t _newMax) |
Set the maximum number of iterations that the Solver should use. | |
std::size_t | getNumMaxIterations () const |
Get the maximum number of iterations that the Solver should use. | |
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. | |
std::ostream * | getOutStream () const |
Get the output stream that prints the Solver's progress. | |
virtual void | setPrintFinalResult (bool _print) |
Set to true if the final result should be printed to the terminal. | |
bool | getPrintFinalResult () const |
Returns true if the final result should be printed to the terminal. | |
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. | |
std::size_t | mLastNumIterations |
The last number of iterations performed by this Solver. | |
std::random_device | mRD |
Randomization device. | |
std::mt19937 | mMT |
Mersenne twister method. | |
std::uniform_real_distribution< double > | mDistribution |
Distribution. | |
Eigen::VectorXd | mEqConstraintCostCache |
Cache to track the costs of equality constraints. | |
Eigen::VectorXd | mIneqConstraintCostCache |
Cache to track the costs of inequality constraints. | |
Eigen::VectorXd | mLastConfig |
The last config reached by this Solver. | |
![]() | |
Properties | mProperties |
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.
void dart::optimization::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.
void dart::optimization::GradientDescentSolver::setPerturbationStep | ( | std::size_t | _step | ) |
Set the number of steps that will be taken before applying a randomized perturbation.