Drake

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 override 
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  
SolverBase &  operator= (const SolverBase &)=delete 
SolverBase (SolverBase &&)=delete  
SolverBase &  operator= (SolverBase &&)=delete 
Public Member Functions inherited from SolverInterface  
virtual  ~SolverInterface () 
SolverInterface (const SolverInterface &)=delete  
SolverInterface &  operator= (const SolverInterface &)=delete 
SolverInterface (SolverInterface &&)=delete  
SolverInterface &  operator= (SolverInterface &&)=delete 
Protected Member Functions  
SolverBase (std::function< 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 =0 
Hook for subclasses to implement Solve. More...  
Protected Member Functions inherited from SolverInterface  
SolverInterface ()  

delete 

delete 

override 

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. &id
, 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.

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

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 compiletime due to licensing restrictions, or to narrow Drake's dependency footprint. In Drake's default build, only commerciallylicensed solvers might return false.
Contrast this with enabled(), which reflects whether a solver has been configured for use at runtime (not compiletime).
For details on linking commercial solvers, refer to the solvers' class overview documentation, e.g., SnoptSolver, MosekSolver, GurobiSolver.
Implements SolverInterface.

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.

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 commerciallylicensed solvers might return false.
Contrast this with available(), which reflects whether a solver has been incorporated into Drake at compiletime (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.

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.

delete 

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

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.

overridevirtual 
Returns the identifier of this solver.
Implements SolverInterface.