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 | |
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 (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 () | |
|
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., &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.
|
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 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.
|
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.
|
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.
|
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.
|
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. Derived implementations of this interface may elect to throw std::exception for badly formed programs.
Implements SolverInterface.
|
finalvirtual |
Returns the identifier of this solver.
Implements SolverInterface.