Drake
SolverBase Class Referenceabstract

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 this solver was enabled at compile-time. More...
 
bool enabled () const override
 Returns true iff this solver is enabled at runtime. More...
 
SolverId solver_id () const override
 Returns the identifier of this solver. More...
 
bool AreProgramAttributesSatisfied (const MathematicalProgram &) const override
 Returns true if the program attributes are satisfied by the solver's capability. 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 (std::function< SolverId()> id, std::function< bool()> available, std::function< bool()> enabled, std::function< bool(const MathematicalProgram &)> satisfied)
 Constructs a SolverBase with the given default implementations of the solver_id(), available(), enabled(), and AreProgramAttributesSatisfied() methods. More...
 
virtual void DoSolve (const MathematicalProgram &prog, const Eigen::VectorXd &initial_guess, const SolverOptions &merged_options, MathematicalProgramResult *result) const =0
 Hook for subclasses to implement Solve. 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 ( std::function< SolverId()>  id,
std::function< bool()>  available,
std::function< bool()>  enabled,
std::function< bool(const MathematicalProgram &)>  satisfied 
)
protected

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

(Typically, the subclass will just pass the address of its static method, e.g. &id, for these functors.) Any of the functors can be nullptr, in which case the subclass should override the virtual method instead.

Member Function Documentation

◆ AreProgramAttributesSatisfied()

bool AreProgramAttributesSatisfied ( const MathematicalProgram prog) const
overridevirtual

Returns true if the program attributes are satisfied by the solver's capability.

Implements SolverInterface.

◆ available()

bool available ( ) const
overridevirtual

Returns true iff this solver was enabled at compile-time.

Certain solvers may be excluded at compile-time due to licensing or linking restrictions. When this method returns false, the Solve method will throw.

Implements SolverInterface.

◆ DoSolve()

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

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.

◆ enabled()

bool enabled ( ) const
overridevirtual

Returns true iff this solver is enabled at runtime.

The toggle mechanism is specific to the solver in question, but typically uses an environment variable. When this method returns false, the Solve method will throw.

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.

Implements SolverInterface.

◆ solver_id()

SolverId solver_id ( ) const
overridevirtual

Returns the identifier of this solver.

Implements SolverInterface.


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