forked from RobotLocomotion/drake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mosek_solver.h
83 lines (68 loc) · 2.92 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
#pragma once
#include <memory>
#include <string>
#include <Eigen/Core>
#include "drake/common/drake_copyable.h"
#include "drake/solvers/mathematical_program_solver_interface.h"
namespace drake {
namespace solvers {
class MosekSolver : public MathematicalProgramSolverInterface {
public:
DRAKE_NO_COPY_NO_MOVE_NO_ASSIGN(MosekSolver)
MosekSolver() = default;
~MosekSolver() override = default;
/**
* Defined true if Mosek was included during compilation, false otherwise.
*/
bool available() const override;
SolutionResult Solve(MathematicalProgram& prog) const override;
SolverId solver_id() const override;
/// @return same as MathematicalProgramSolverInterface::solver_id()
static SolverId id();
/**
* Control stream logging. Refer to
* https://docs.mosek.com/8.1/capi/solver-io.html for more details.
* @param flag Set to true if the user want to turn on stream logging.
* @param log_file If the user wants to output the logging to a file, then
* set @p 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.
*/
void set_stream_logging(bool flag, const std::string& log_file) {
stream_logging_ = flag;
log_file_ = log_file;
}
/**
* 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::runtime_error if MOSEK is available but a license cannot be
* obtained.
*/
static std::shared_ptr<License> AcquireLicense();
private:
// 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_;
// Set to true if the user wants the solver to produce output to the console
// or a log file. Default to false, such that the solver runs silently.
// Check out https://docs.mosek.com/8.1/capi/solver-io.html for more info.
bool stream_logging_{false};
// set @p 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. Default to an
// empty string.
std::string log_file_{};
};
} // namespace solvers
} // namespace drake