Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
|
#include <gurobi_solver.h>
Public Member Functions | |
absl::StatusOr< SolveResultProto > | Solve (const SolveParametersProto ¶meters, const ModelSolveParametersProto &model_parameters, MessageCallback message_cb, const CallbackRegistrationProto &callback_registration, Callback cb, const SolveInterrupter *interrupter) override |
absl::StatusOr< bool > | Update (const ModelUpdateProto &model_update) override |
absl::StatusOr< ComputeInfeasibleSubsystemResultProto > | ComputeInfeasibleSubsystem (const SolveParametersProto ¶meters, MessageCallback message_cb, const SolveInterrupter *interrupter) override |
Public Member Functions inherited from operations_research::math_opt::SolverInterface | |
SolverInterface ()=default | |
SolverInterface (const SolverInterface &)=delete | |
SolverInterface & | operator= (const SolverInterface &)=delete |
virtual | ~SolverInterface ()=default |
Static Public Member Functions | |
static absl::StatusOr< std::unique_ptr< GurobiSolver > > | New (const ModelProto &input_model, const SolverInterface::InitArgs &init_args) |
Additional Inherited Members | |
Public Types inherited from operations_research::math_opt::SolverInterface | |
using | MessageCallback = std::function<void(const std::vector<std::string>&)> |
using | Callback |
using | Factory |
Definition at line 52 of file gurobi_solver.h.
|
overridevirtual |
Need to run GRBupdatemodel before:
Gurobi will silently impose that indicator variables are binary even if not so specified by the user in the model. We return an error here if this is the case to be consistent across solvers.
We must set the parameters before calling RegisterCallback since it changes some parameters depending on the callback registration.
We use a local interrupter that will triggers the calls to GRBterminate() when either the user interrupter is triggered or when a callback returns a true terminate
.
Make an immediate call to GRBterminate() as soon as this interrupter is triggered (which may immediately happen in the code below when it is chained with the optional user interrupter).
This call may happen too early. This is not an issue since we will repeat this call at each call of the Gurobi callback. See the comment in GurobiCallbackImpl() for details.
Chain the user interrupter to the local interrupter. If/when the user interrupter is triggered, this triggers the local interrupter. This may happen immediately if the user interrupter is already triggered.
The local interrupter can also be triggered by a callback returning a true terminate
.
Here we register the callback when we either have a message callback or a local interrupter. The rationale for doing so when we have only an interrupter is explained in GurobiCallbackImpl().
We flush message callbacks before testing for Gurobi error in case where the unfinished line of message would help with the error.
Reset Gurobi parameters.
Implements operations_research::math_opt::SolverInterface.
Definition at line 3037 of file gurobi_solver.cc.
|
static |
Definition at line 2715 of file gurobi_solver.cc.
|
overridevirtual |
Solves the current model (included all updates).
All input arguments are ensured (by solver.cc) to be valid. Furthermore, since all parameters are references or functions (which could be a lambda expression), the implementation should not keep a reference or copy of them, as they may become invalid reference after the invocation if this function.
Parameters message_cb
, cb
and interrupter
are optional. They are nullptr when not set.
When parameter message_cb
is not null the value of parameters.enable_output should be ignored the solver should behave as it is was false (i.e. not print anything).
When parameter message_cb
is not null and the underlying solver does not supports message callbacks, it should ignore it.
Solvers should return a InvalidArgumentError when called with events on callback_registration that are not supported by the solver for the type of model being solved (for example MIP events if the model is an LP, or events that are not emitted by the solver). Solvers should use CheckRegisteredCallbackEvents() to implement that.
Need to run GRBupdatemodel before:
Gurobi returns "infeasible" when bounds are inverted.
Gurobi will silently impose that indicator variables are binary even if not so specified by the user in the model. We return an error here if this is the case to be consistent across solvers.
We must set the parameters before calling RegisterCallback since it changes some parameters depending on the callback registration.
We use a local interrupter that will triggers the calls to GRBterminate() when either the user interrupter is triggered or when a callback returns a true terminate
.
Make an immediate call to GRBterminate() as soon as this interrupter is triggered (which may immediately happen in the code below when it is chained with the optional user interrupter).
This call may happen too early. This is not an issue since we will repeat this call at each call of the Gurobi callback. See the comment in GurobiCallbackImpl() for details.
Chain the user interrupter to the local interrupter. If/when the user interrupter is triggered, this triggers the local interrupter. This may happen immediately if the user interrupter is already triggered.
The local interrupter can also be triggered by a callback returning a true terminate
.
We select a value of "1" here, which means that the lazy constraints will be separated at feasible solutions, and that Gurobi has latitude to select which violated constraints to add to the model if multiple are violated. This seems like a reasonable default choice for us, but we may want to revisit later (or expose this choice to the user).
Here we register the callback when we either have a user callback or a local interrupter. The rationale for doing so when we have only an interrupter is explained in GurobiCallbackImpl().
We flush message callbacks before testing for Gurobi error in case where the unfinished line of message would help with the error.
Reset Gurobi parameters.
Implements operations_research::math_opt::SolverInterface.
Definition at line 2905 of file gurobi_solver.cc.
|
overridevirtual |
Updates the model to solve and returns true, or returns false if this update is not supported.
The implementation should assume the input ModelUpdate is valid and is free to assert if this is not the case.
As of 2022-12-06 we do not support incrementalism for multi-objective models: not adding/deleting/modifying the auxiliary objectives...
...or modifying the primary objective of a multi-objective model.
Now we update quadratic_objective_coefficients_, removing any terms where either one or both of the involved variables are about to be deleted.
We cache all Gurobi variables and constraint indices that must be deleted, and perform deletions at the end of the update call.
Otherwise the constraint is not actually registered with Gurobi.
If we are removing variables or constraints we remove them after adding any variable or constraint. This is to avoid problems with the numbering of possibly new variables and constraints. After that we must update the model so that sequence of updates don't interfere with one-another.
Synchronize all pending changes.
Implements operations_research::math_opt::SolverInterface.
Definition at line 2487 of file gurobi_solver.cc.