An implementation of SolverInterface for the commercially-licensed Gurobi solver (https://www.gurobi.com/).
The default build of Drake is not configured to use Gurobi, so therefore SolverInterface::available() will return false. You must compile Drake from source in order to link against Gurobi. For details, refer to the documentation at https://drake-mit-edu.ezproxy.canberra.edu.au/bazel.html#proprietary-solvers.
The GRB_LICENSE_FILE environment variable controls whether or not SolverInterface::enabled() returns true. If it is set to any non-empty value, then the solver is enabled; otherwise, the solver is not enabled.
Gurobi solver supports options/parameters listed in https://www.gurobi.com/documentation/10.0/refman/parameters.html. On top of these options, we provide the following additional options
- "GRBwrite", set to a file name so that Gurobi solver will write the optimization model to this file, check https://www.gurobi.com/documentation/10.0/refman/py_model_write.html for more details, such as all supported file extensions. Set this option to "" if you don't want to write to file. Default is not to write to a file.
- "GRBcomputeIIS", set to 1 to compute an Irreducible Inconsistent Subsystem (IIS) when the problem is infeasible. Refer to https://www.gurobi.com/documentation/10.0/refman/py_model_computeiis.html for more details. Often this method is called together with setting GRBwrite to "FILENAME.ilp" to write IIS to a file with extension "ilp". Default is not to compute IIS.
GurobiSolver supports parallelization during Solve(). If both the "Threads" integer solver option and CommonSolverOption::kMaxThreads have been set by the user, then the value in "Threads" will be used as the number of threads.
If neither the "Threads" integer solver option nor CommonSolverOption::kMaxThreads has been set by the user, then GurobiSolver uses the environment variable GUROBI_NUM_THREADS (if set) as a default value for "Threads".
If none of "Threads", CommonSolverOption::kMaxThreads, or GUROBI_NUM_THREADS are set, then Drake's default maximum parallelism will be used.
|
| GurobiSolver () |
|
| ~GurobiSolver () final |
|
void | AddMipNodeCallback (const MipNodeCallbackFunction &callback) |
| Registers a callback to be called at intermediate solutions during the solve. More...
|
|
void | AddMipSolCallback (const MipSolCallbackFunction &callback) |
| Registers a callback to be called at feasible solutions during the solve. 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 |
|
|
| GurobiSolver (const GurobiSolver &)=delete |
|
GurobiSolver & | operator= (const GurobiSolver &)=delete |
|
| GurobiSolver (GurobiSolver &&)=delete |
|
GurobiSolver & | operator= (GurobiSolver &&)=delete |
|
| ~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...
|
|
| SolverBase (const SolverBase &)=delete |
|
SolverBase & | operator= (const SolverBase &)=delete |
|
| SolverBase (SolverBase &&)=delete |
|
SolverBase & | operator= (SolverBase &&)=delete |
|
virtual | ~SolverInterface () |
|
| SolverInterface (const SolverInterface &)=delete |
|
SolverInterface & | operator= (const SolverInterface &)=delete |
|
| SolverInterface (SolverInterface &&)=delete |
|
SolverInterface & | operator= (SolverInterface &&)=delete |
|
static std::shared_ptr<License> AcquireLicense |
( |
| ) |
|
|
static |
This acquires a Gurobi license environment shared among all GurobiSolver instances.
The environment will stay valid as long as at least one shared_ptr returned by this function is alive. GurobiSolver calls this method on each Solve().
If the license file contains the string HOSTID
, then we treat this as confirmation that the license is attached to the local host, and maintain an internal copy of the shared_ptr for the lifetime of the process. Otherwise the default behavior is to only hold the license while at least one GurobiSolver instance is alive.
Call this method directly and maintain the shared_ptr 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 Gurobi is not available in your build, this will return a null (empty) shared_ptr.
- Exceptions
-
std::exception | if Gurobi is available but a license cannot be obtained. |