forked from RobotLocomotion/drake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmosek_solver.h
124 lines (110 loc) · 5.14 KB
/
mosek_solver.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#pragma once
#include <memory>
#include <string>
#include <Eigen/Core>
#include "drake/common/drake_copyable.h"
#include "drake/solvers/mathematical_program_result.h"
#include "drake/solvers/solver_base.h"
namespace drake {
namespace solvers {
/**
* The MOSEK™ solver details after calling Solve() function. The user can call
* MathematicalProgramResult::get_solver_details<MosekSolver>() to obtain the
* details.
*/
struct MosekSolverDetails {
/// The MOSEK™ optimization time. Please refer to MSK_DINF_OPTIMIZER_TIME in
/// https://docs.mosek.com/9.3/capi/constants.html?highlight=msk_dinf_optimizer_time
double optimizer_time{};
/// The response code returned from MOSEK™ solver. Check
/// https://docs.mosek.com/9.3/capi/response-codes.html for the meaning on the
/// response code.
int rescode{};
/// The solution status after solving the problem. Check
/// https://docs.mosek.com/9.3/capi/accessing-solution.html and
/// https://docs.mosek.com/9.3/capi/constants.html#mosek.solsta for the
/// meaning on the solution status.
int solution_status{};
};
/**
* 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.3/capi/tutorial-mio-shared.html?highlight=initial
*
* MOSEK™ supports many solver parameters. You can refer to the full list of
* parameters in
* https://docs.mosek.com/9.3/capi/param-groups.html#doc-param-groups. On top of
* these parameters, we also provide the following additional parameters
* 1. "writedata", set to a file name so that MOSEK™ solver will write the
* optimization model to this file. check
* https://docs.mosek.com/9.3/capi/solver-io.html#saving-a-problem-to-a-file
* for more details. The supported file extensions are listed in
* https://docs.mosek.com/9.3/capi/supported-file-formats.html#doc-shared-file-formats.
* Set this parameter to "" if you don't want to write to a file. Default is
* not to write to a file.
*/
class MosekSolver final : public SolverBase {
public:
DRAKE_NO_COPY_NO_MOVE_NO_ASSIGN(MosekSolver)
/// Type of details stored in MathematicalProgramResult.
using Details = MosekSolverDetails;
MosekSolver();
~MosekSolver() final;
/**
* This type contains a valid MOSEK license environment, and is only to be
* used from AcquireLicense().
*/
class License;
/**
* 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).
* @return 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.
* @throws std::exception if MOSEK™ is available but a license cannot be
* obtained.
*/
static std::shared_ptr<License> AcquireLicense();
/// @name Static versions of the instance methods with similar names.
//@{
static SolverId id();
static bool is_available();
/// Returns true iff the environment variable MOSEKLM_LICENSE_FILE has been
/// set to a non-empty value.
static bool is_enabled();
static bool ProgramAttributesSatisfied(const MathematicalProgram&);
static std::string UnsatisfiedProgramAttributes(const MathematicalProgram&);
//@}
// A using-declaration adds these methods into our class's Doxygen.
using SolverBase::Solve;
private:
void DoSolve(const MathematicalProgram&, const Eigen::VectorXd&,
const SolverOptions&, MathematicalProgramResult*) const final;
// Note that this is mutable to allow latching the allocation of mosek_env_
// during the first call of Solve() (which avoids grabbing a MOSEK™ license
// before we know that we actually want one).
mutable std::shared_ptr<License> license_;
};
} // namespace solvers
} // namespace drake