Drake
MosekSolver Class Referencefinal

Detailed Description

An implementation of SolverInterface for the commercially-licensed MOSEK solver (https://www.mosek.com/).

The default build of Drake is not configured to use MOSEK, so therefore SolverInterface::available() will return false. You must compile Drake from source in order to link against MOSEK. For details, refer to the documentation at https://drake.mit.edu/bazel.html#mosek.

The MOSEKLM_LICENSE_FILE environment variable controls whether or not SolverInterface::enabled() returns true. Iff it is set to any non-empty value, then the solver is enabled; otherwise, the solver is not enabled.

Note
Mosek only cares about the initial guess of integer variables. The initial guess of continuous variables are not passed to MOSEK. If all the integer variables are set to some integer values, then MOSEK will be forced to compute the remaining continuous variable values as the initial guess. (Mosek might change the values of the integer/binary variables in the subsequent iterations.) If the specified integer solution is infeasible or incomplete, MOSEK will simply ignore it. For more details, check https://docs.mosek.com/9.2/capi/tutorial-mio-shared.html?highlight=initial

#include <drake/solvers/mosek_solver.h>

Public Types

using Details = MosekSolverDetails
 Type of details stored in MathematicalProgramResult. More...
 

Public Member Functions

 MosekSolver ()
 
 ~MosekSolver () final
 
void set_stream_logging (bool flag, const std::string &log_file)
 Control stream logging. More...
 
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
 
Does not allow copy, move, or assignment
 MosekSolver (const MosekSolver &)=delete
 
MosekSolveroperator= (const MosekSolver &)=delete
 
 MosekSolver (MosekSolver &&)=delete
 
MosekSolveroperator= (MosekSolver &&)=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. 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...
 
 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::shared_ptr< License > AcquireLicense ()
 This acquires a MOSEK license environment shared among all MosekSolver instances; the environment will stay valid as long as at least one shared_ptr returned by this function is alive. More...
 
Static versions of the instance methods with similar names.
static SolverId id ()
 
static bool is_available ()
 
static bool is_enabled ()
 Returns true iff the environment variable MOSEKLM_LICENSE_FILE has been set to a non-empty value. More...
 
static bool ProgramAttributesSatisfied (const MathematicalProgram &)
 
static std::string UnsatisfiedProgramAttributes (const MathematicalProgram &)
 

Additional Inherited Members

- Protected Member Functions inherited from SolverBase
 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...
 
- Protected Member Functions inherited from SolverInterface
 SolverInterface ()
 

Member Typedef Documentation

◆ Details

Type of details stored in MathematicalProgramResult.

Constructor & Destructor Documentation

◆ MosekSolver() [1/3]

MosekSolver ( const MosekSolver )
delete

◆ MosekSolver() [2/3]

MosekSolver ( MosekSolver &&  )
delete

◆ MosekSolver() [3/3]

◆ ~MosekSolver()

~MosekSolver ( )
final

Member Function Documentation

◆ AcquireLicense()

static std::shared_ptr<License> AcquireLicense ( )
static

This acquires a MOSEK license environment shared among all MosekSolver instances; the environment will stay valid as long as at least one shared_ptr returned by this function is alive.

Call this ONLY if you must use different MathematicalProgram instances at different instances in time, and repeatedly acquiring the license is costly (e.g., requires contacting a license server).

Returns
A shared pointer to a license environment that will stay valid as long as any shared_ptr returned by this function is alive. If MOSEK is not available in your build, this will return a null (empty) shared_ptr.
Exceptions
std::runtime_errorif MOSEK is available but a license cannot be obtained.

◆ id()

static SolverId id ( )
static

◆ is_available()

static bool is_available ( )
static

◆ is_enabled()

static bool is_enabled ( )
static

Returns true iff the environment variable MOSEKLM_LICENSE_FILE has been set to a non-empty value.

◆ operator=() [1/2]

MosekSolver& operator= ( MosekSolver &&  )
delete

◆ operator=() [2/2]

MosekSolver& operator= ( const MosekSolver )
delete

◆ ProgramAttributesSatisfied()

static bool ProgramAttributesSatisfied ( const MathematicalProgram )
static

◆ set_stream_logging()

void set_stream_logging ( bool  flag,
const std::string &  log_file 
)

Control stream logging.

Refer to https://docs.mosek.com/9.2/capi/solver-io.html for more details.

Parameters
flagSet to true if the user want to turn on stream logging.
log_fileIf the user wants to output the logging to a file, then set log_file to the name of that file. If the user wants to output the logging to the console, then set log_file to empty string.

◆ Solve() [1/2]

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

◆ Solve() [2/2]

void Solve
override

◆ UnsatisfiedProgramAttributes()

static std::string UnsatisfiedProgramAttributes ( const MathematicalProgram )
static

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