Drake
Drake C++ Documentation
SolverBase Class Reference

Detailed Description

Abstract base class used by implementations of individual solvers.

#include <drake/solvers/solver_base.h>

Public Member Functions

 ~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. More...
 
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. More...
 
bool available () const override
 Returns true iff support for this solver has been compiled into Drake. More...
 
bool enabled () const override
 Returns true iff this solver is properly configured for use at runtime. More...
 
SolverId solver_id () const final
 Returns the identifier of this solver. More...
 
bool AreProgramAttributesSatisfied (const MathematicalProgram &) const override
 Returns true iff the program's attributes are compatible with this solver's capabilities. More...
 
std::string ExplainUnsatisfiedProgramAttributes (const MathematicalProgram &) const override
 Describes the reasons (if any) why the program is incompatible with this solver's capabilities. More...
 
Does not allow copy, move, or assignment
 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
 

Protected Member Functions

 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. More...
 
virtual void DoSolve (const MathematicalProgram &prog, const Eigen::VectorXd &initial_guess, const SolverOptions &merged_options, MathematicalProgramResult *result) const
 Hook for subclasses to implement Solve. More...
 
virtual void DoSolve2 (const MathematicalProgram &prog, const Eigen::VectorXd &initial_guess, internal::SpecificOptions *options, MathematicalProgramResult *result) const
 (Internal use only) Like DoSolve() but using SpecificOptions instead of SolverOptions. More...
 
- Protected Member Functions inherited from SolverInterface
 SolverInterface ()
 

Constructor & Destructor Documentation

◆ SolverBase() [1/3]

SolverBase ( const SolverBase )
delete

◆ SolverBase() [2/3]

SolverBase ( SolverBase &&  )
delete

◆ ~SolverBase()

~SolverBase ( )
override

◆ SolverBase() [3/3]

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 
)
protected

Constructs a SolverBase with the given default implementations of the solver_id(), available(), enabled(), AreProgramAttributesSatisfied(), and ExplainUnsatisfiedProgramAttributes() methods.

Typically, the subclass will simply pass the address of its static method, e.g., &available, for these functors. Any of the functors can be nullptr, in which case the subclass must override the matching virtual method instead, except for explain_unsatisfied which already has a default implementation.

Member Function Documentation

◆ AreProgramAttributesSatisfied()

bool AreProgramAttributesSatisfied ( const MathematicalProgram prog) const
overridevirtual

Returns true iff the program's attributes are compatible with this solver's capabilities.

Implements SolverInterface.

◆ available()

bool available ( ) const
overridevirtual

Returns true iff support for this solver has been compiled into Drake.

When this method returns false, the Solve method will throw.

Most solver implementations will always return true, but certain solvers may have been excluded at compile-time due to licensing restrictions, or to narrow Drake's dependency footprint. In Drake's default build, only commercially-licensed solvers might return false.

Contrast this with enabled(), which reflects whether a solver has been configured for use at runtime (not compile-time).

For details on linking commercial solvers, refer to the solvers' class overview documentation, e.g., SnoptSolver, MosekSolver, GurobiSolver.

Implements SolverInterface.

◆ DoSolve()

virtual void DoSolve ( const MathematicalProgram prog,
const Eigen::VectorXd &  initial_guess,
const SolverOptions merged_options,
MathematicalProgramResult result 
) const
protectedvirtual

Hook for subclasses to implement Solve.

Prior to the SolverBase's call to this method, the solver's availability and capabilities vs the program attributes have already been checked, and the result's set_solver_id() and set_decision_variable_index() have already been set. The options and initial guess are already merged, i.e., the DoSolve implementation should ignore prog's solver options and prog's initial guess.

◆ DoSolve2()

virtual void DoSolve2 ( const MathematicalProgram prog,
const Eigen::VectorXd &  initial_guess,
internal::SpecificOptions *  options,
MathematicalProgramResult result 
) const
protectedvirtual

(Internal use only) Like DoSolve() but using SpecificOptions instead of SolverOptions.

The "2" here means "version 2", to help disabiguate various DoSolve overloads.

By default, DoSolve() will delegate to DoSolve2() and DoSolve2() will throw. Subclasses should override exactly one of the various DoSolver methods. Solvers wrapped inside Drake should override DoSolve2(); solvers wrapped in downstream projects must override DoSolve() since this function is marked as internal use only.

◆ enabled()

bool enabled ( ) const
overridevirtual

Returns true iff this solver is properly configured for use at runtime.

When this method returns false, the Solve method will throw.

Most solver implementation will always return true, but certain solvers require additional configuration before they may be used, e.g., setting an environment variable to specify a license file or license server. In Drake's default build, only commercially-licensed solvers might return false.

Contrast this with available(), which reflects whether a solver has been incorporated into Drake at compile-time (and has nothing to do with the runtime configuration). A solver where available() returns false may still return true for enabled() if it is properly configured.

The mechanism to configure a particular solver implementation is specific to the solver in question, but typically uses an environment variable. For details on configuring commercial solvers, refer to the solvers' class overview documentation, e.g., SnoptSolver, MosekSolver, GurobiSolver.

Implements SolverInterface.

◆ ExplainUnsatisfiedProgramAttributes()

std::string ExplainUnsatisfiedProgramAttributes ( const MathematicalProgram prog) const
overridevirtual

Describes the reasons (if any) why the program is incompatible with this solver's capabilities.

If AreProgramAttributesSatisfied would return true for the program, then this function returns the empty string.

Implements SolverInterface.

◆ operator=() [1/2]

SolverBase& operator= ( const SolverBase )
delete

◆ operator=() [2/2]

SolverBase& operator= ( SolverBase &&  )
delete

◆ Solve() [1/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.

◆ Solve() [2/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 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.

◆ solver_id()

SolverId solver_id ( ) const
finalvirtual

Returns the identifier of this solver.

Implements SolverInterface.


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