Drake
Drake C++ Documentation
Loading...
Searching...
No Matches
ProjectedGradientDescentSolver Class Referencefinal

Detailed Description

Solves a nonlinear program via the projected gradient descent algorithm.

The gradient is determined by differentiation of the costs, or the user can supply a custom gradient function. The projection step is itself an optimization problem in general, but the user can supply a custom projection function. The user can also specify a specific solver interface to be used to solve the projection problem.

The solver terminates if

  • the projection step fails to find a feasible solution,
  • the 2-norm distance between subsequent iterates is less than the user-specified tolerance (see ConvergenceTolOptionName), or
  • a maximum number of iterations have been run (see MaxIterationsOptionName).
Warning
This feature is considered to be experimental and may change or be removed at any time, without any deprecation notice ahead of time.

#include <drake/solvers/projected_gradient_descent_solver.h>

Public Member Functions

 ProjectedGradientDescentSolver ()
 ~ProjectedGradientDescentSolver () final
void SetCustomGradientFunction (const std::function< Eigen::VectorXd(const Eigen::VectorXd &)> &custom_gradient_function)
 Specify a custom gradient function.
void SetCustomProjectionFunction (const std::function< bool(const Eigen::VectorXd &, Eigen::VectorXd *)> &custom_projection_function)
 Specify a custom projection function.
void SetProjectionSolverInterface (const SolverInterface *projection_solver_interface)
 Specify a solver interface to be used when solving the L2 projection onto the feasible set of the MathematicalProgram it's being used to solve.
Does not allow copy, move, or assignment
 ProjectedGradientDescentSolver (const ProjectedGradientDescentSolver &)=delete
ProjectedGradientDescentSolveroperator= (const ProjectedGradientDescentSolver &)=delete
 ProjectedGradientDescentSolver (ProjectedGradientDescentSolver &&)=delete
ProjectedGradientDescentSolveroperator= (ProjectedGradientDescentSolver &&)=delete
Public Member Functions inherited from SolverBase
 ~SolverBase () override
MathematicalProgramResult Solve (const MathematicalProgram &prog, const std::optional< Eigen::VectorXd > &initial_guess=std::nullopt, const std::optional< SolverOptions > &solver_options=std::nullopt) const
 Like SolverInterface::Solve(), but the result is a return value instead of an output argument.
void Solve (const MathematicalProgram &, const std::optional< Eigen::VectorXd > &, const std::optional< SolverOptions > &, MathematicalProgramResult *) const override
 Solves an optimization program with optional initial guess and solver options.
bool available () const override
 Returns true iff support for this solver has been compiled into Drake.
bool enabled () const override
 Returns true iff this solver is properly configured for use at runtime.
SolverId solver_id () const final
 Returns the identifier of this solver.
bool AreProgramAttributesSatisfied (const MathematicalProgram &) const override
 Returns true iff the program's attributes are compatible with this solver's capabilities.
std::string ExplainUnsatisfiedProgramAttributes (const MathematicalProgram &) const override
 Describes the reasons (if any) why the program is incompatible with this solver's capabilities.
 SolverBase (const SolverBase &)=delete
SolverBaseoperator= (const SolverBase &)=delete
 SolverBase (SolverBase &&)=delete
SolverBaseoperator= (SolverBase &&)=delete
Public Member Functions inherited from SolverInterface
virtual ~SolverInterface ()
 SolverInterface (const SolverInterface &)=delete
SolverInterfaceoperator= (const SolverInterface &)=delete
 SolverInterface (SolverInterface &&)=delete
SolverInterfaceoperator= (SolverInterface &&)=delete

Static Public Member Functions

static std::string ConvergenceTolOptionName ()
static std::string MaxIterationsOptionName ()
static std::string BacktrackingCOptionName ()
static std::string BacktrackingTauOptionName ()
static std::string BacktrackingAlpha0OptionName ()

Static versions of the instance methods with similar names.

static constexpr double kDefaultConvergenceTol = 1e-12
static constexpr int kDefaultMaxIterations = 1000
static constexpr double kDefaultBacktrackingC = 0.5
static constexpr double kDefaultBacktrackingTau = 0.5
static constexpr double kDefaultBacktrackingAlpha0 = 0.1
static constexpr int kDefaultMaxLineSearchSteps = 100
MathematicalProgramResult Solve (const MathematicalProgram &prog, const std::optional< Eigen::VectorXd > &initial_guess=std::nullopt, const std::optional< SolverOptions > &solver_options=std::nullopt) const
 Like SolverInterface::Solve(), but the result is a return value instead of an output argument.
void Solve (const MathematicalProgram &, const std::optional< Eigen::VectorXd > &, const std::optional< SolverOptions > &, MathematicalProgramResult *) const override
 Solves an optimization program with optional initial guess and solver options.
static SolverId id ()
static bool is_available ()
static bool is_enabled ()
static bool ProgramAttributesSatisfied (const MathematicalProgram &)

Additional Inherited Members

Protected Member Functions inherited from SolverBase
 SolverBase (const SolverId &id, std::function< bool()> available, std::function< bool()> enabled, std::function< bool(const MathematicalProgram &)> are_satisfied, std::function< std::string(const MathematicalProgram &)> explain_unsatisfied=nullptr)
 Constructs a SolverBase with the given default implementations of the solver_id(), available(), enabled(), AreProgramAttributesSatisfied(), and ExplainUnsatisfiedProgramAttributes() methods.
virtual void DoSolve (const MathematicalProgram &prog, const Eigen::VectorXd &initial_guess, const SolverOptions &merged_options, MathematicalProgramResult *result) const
 Hook for subclasses to implement Solve.
Protected Member Functions inherited from SolverInterface
 SolverInterface ()

Constructor & Destructor Documentation

◆ ProjectedGradientDescentSolver() [1/3]

◆ ProjectedGradientDescentSolver() [2/3]

◆ ProjectedGradientDescentSolver() [3/3]

◆ ~ProjectedGradientDescentSolver()

Member Function Documentation

◆ BacktrackingAlpha0OptionName()

std::string BacktrackingAlpha0OptionName ( )
static
Returns
string key for SolverOptions to set the value of alpha_0 to use for the backtracking line search. Must be positive.

◆ BacktrackingCOptionName()

std::string BacktrackingCOptionName ( )
static
Returns
string key for SolverOptions to set the value of c to use for the backtracking line search. Must be between 0 and 1.

◆ BacktrackingTauOptionName()

std::string BacktrackingTauOptionName ( )
static
Returns
string key for SolverOptions to set the value of tau to use for the backtracking line search. Must be between 0 and 1.

◆ ConvergenceTolOptionName()

std::string ConvergenceTolOptionName ( )
static
Returns
string key for SolverOptions to set the threshold used to determine convergence. It must be positive.

◆ id()

SolverId id ( )
static

◆ is_available()

bool is_available ( )
static

◆ is_enabled()

bool is_enabled ( )
static

◆ MaxIterationsOptionName()

std::string MaxIterationsOptionName ( )
static
Returns
string key for SolverOptions to set the maximum number of iterations. It must be a positive integer.

◆ operator=() [1/2]

◆ operator=() [2/2]

◆ ProgramAttributesSatisfied()

bool ProgramAttributesSatisfied ( const MathematicalProgram & )
static

◆ SetCustomGradientFunction()

void SetCustomGradientFunction ( const std::function< Eigen::VectorXd(const Eigen::VectorXd &)> & custom_gradient_function)

Specify a custom gradient function.

Otherwise, this solver will differentiate through the costs in the MathematicalProgram it's used to solve.

◆ SetCustomProjectionFunction()

void SetCustomProjectionFunction ( const std::function< bool(const Eigen::VectorXd &, Eigen::VectorXd *)> & custom_projection_function)

Specify a custom projection function.

Otherwise, this solver will attempt to solve the L2 projection onto the feasible set of the MathematicalProgram it's used to solve. The projection function should return a boolean value indicating success or failure. It should take in two arguments: the point we are trying to stay close to, and an output argument where the projected value will be placed.

◆ SetProjectionSolverInterface()

void SetProjectionSolverInterface ( const SolverInterface * projection_solver_interface)

Specify a solver interface to be used when solving the L2 projection onto the feasible set of the MathematicalProgram it's being used to solve.

◆ Solve() [1/2]

void Solve ( const MathematicalProgram & prog,
const std::optional< Eigen::VectorXd > & initial_guess,
const std::optional< SolverOptions > & solver_options,
MathematicalProgramResult * result ) const
overridevirtual

Solves an optimization program with optional initial guess and solver options.

Note that these initial guess and solver options are not written to prog. If the prog has set an initial guess, and initial_guess is set, then initial_guess takes priority. If the prog has set an option for a solver, and solver_options contains a different value for the same option on the same solver, then solver_options takes priority. Derived implementations of this interface may elect to throw std::exception for badly formed programs.

Implements SolverInterface.

◆ Solve() [2/2]

MathematicalProgramResult Solve ( const MathematicalProgram & prog,
const std::optional< Eigen::VectorXd > & initial_guess = std::nullopt,
const std::optional< SolverOptions > & solver_options = std::nullopt ) const

Like SolverInterface::Solve(), but the result is a return value instead of an output argument.

Member Data Documentation

◆ kDefaultBacktrackingAlpha0

double kDefaultBacktrackingAlpha0 = 0.1
staticconstexpr

◆ kDefaultBacktrackingC

double kDefaultBacktrackingC = 0.5
staticconstexpr

◆ kDefaultBacktrackingTau

double kDefaultBacktrackingTau = 0.5
staticconstexpr

◆ kDefaultConvergenceTol

double kDefaultConvergenceTol = 1e-12
staticconstexpr

◆ kDefaultMaxIterations

int kDefaultMaxIterations = 1000
staticconstexpr

◆ kDefaultMaxLineSearchSteps

int kDefaultMaxLineSearchSteps = 100
staticconstexpr

The documentation for this class was generated from the following file: