Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
|
Public Member Functions | |
GurobiInterface (MPSolver *solver, bool mip) | |
Constructor that takes a name for the underlying GRB solver. | |
~GurobiInterface () override | |
void | SetOptimizationDirection (bool maximize) override |
Sets the optimization direction (min/max). | |
MPSolver::ResultStatus | Solve (const MPSolverParameters ¶m) override |
bool | SupportsDirectlySolveProto (std::atomic< bool > *interrupt) const override |
--— Directly solve proto is supported without interrupt — | |
MPSolutionResponse | DirectlySolveProto (LazyMutableCopy< MPModelRequest > request, std::atomic< bool > *interrupt) override |
void | Write (const std::string &filename) override |
Writes the model. | |
void | Reset () override |
---— Model modifications and extraction --— | |
void | SetVariableBounds (int var_index, double lb, double ub) override |
Modifies bounds. | |
void | SetVariableInteger (int var_index, bool integer) override |
Modifies integrality of an extracted variable. | |
void | SetConstraintBounds (int row_index, double lb, double ub) override |
Modify bounds of an extracted variable. | |
void | AddRowConstraint (MPConstraint *ct) override |
Adds Constraint incrementally. | |
bool | AddIndicatorConstraint (MPConstraint *ct) override |
void | AddVariable (MPVariable *var) override |
Adds variable incrementally. | |
void | SetCoefficient (MPConstraint *constraint, const MPVariable *variable, double new_value, double old_value) override |
Changes a coefficient in a constraint. | |
void | ClearConstraint (MPConstraint *constraint) override |
Clears a constraint from all its terms. | |
void | SetObjectiveCoefficient (const MPVariable *variable, double coefficient) override |
Changes a coefficient in the linear objective. | |
void | SetObjectiveOffset (double value) override |
Changes the constant term in the linear objective. | |
void | ClearObjective () override |
Clears the objective from all its terms. | |
void | BranchingPriorityChangedForVariable (int var_index) override |
int64_t | iterations () const override |
---— Query statistics on the solution and the solve ---— | |
int64_t | nodes () const override |
Number of branch-and-bound nodes. Only available for discrete problems. | |
MPSolver::BasisStatus | row_status (int constraint_index) const override |
Returns the basis status of a row. | |
MPSolver::BasisStatus | column_status (int variable_index) const override |
Returns the basis status of a column. | |
bool | IsContinuous () const override |
bool | IsLP () const override |
Returns true if the problem is continuous and linear. | |
bool | IsMIP () const override |
Returns true if the problem is discrete and linear. | |
void | ExtractNewVariables () override |
Extracts new variables. | |
void | ExtractNewConstraints () override |
Extracts the constraints that have not been extracted yet. | |
void | ExtractObjective () override |
Extracts the objective. | |
std::string | SolverVersion () const override |
Returns a string describing the underlying solver and its version. | |
bool | InterruptSolve () override |
void * | underlying_solver () override |
Returns the underlying solver. | |
double | ComputeExactConditionNumber () const override |
bool | NextSolution () override |
Iterates through the solutions in Gurobi's solution pool. | |
void | SetCallback (MPCallback *mp_callback) override |
See MPSolver::SetCallback() for details. | |
bool | SupportsCallbacks () const override |
Public Member Functions inherited from operations_research::MPSolverInterface | |
MPSolverInterface (MPSolver *solver) | |
virtual | ~MPSolverInterface () |
double | best_objective_bound () const |
double | objective_value () const |
Returns the objective value of the best solution found so far. | |
bool | CheckSolutionIsSynchronized () const |
virtual bool | CheckSolutionExists () const |
bool | CheckSolutionIsSynchronizedAndExists () const |
Handy shortcut to do both checks above (it is often used). | |
int | last_variable_index () const |
Returns the index of the last variable extracted. | |
bool | variable_is_extracted (int var_index) const |
void | set_variable_as_extracted (int var_index, bool extracted) |
bool | constraint_is_extracted (int ct_index) const |
void | set_constraint_as_extracted (int ct_index, bool extracted) |
bool | quiet () const |
Returns the boolean indicating the verbosity of the solver output. | |
void | set_quiet (bool quiet_value) |
Sets the boolean indicating the verbosity of the solver output. | |
MPSolver::ResultStatus | result_status () const |
Returns the result status of the last solve. | |
virtual void | SetStartingLpBasis (const std::vector< MPSolver::BasisStatus > &, const std::vector< MPSolver::BasisStatus > &) |
See MPSolver::SetStartingLpBasis(). | |
virtual double | infinity () |
Additional Inherited Members | |
Public Types inherited from operations_research::MPSolverInterface | |
enum | SynchronizationStatus { MUST_RELOAD , MODEL_SYNCHRONIZED , SOLUTION_SYNCHRONIZED } |
Static Public Attributes inherited from operations_research::MPSolverInterface | |
static constexpr int64_t | kUnknownNumberOfIterations = -1 |
static constexpr int64_t | kUnknownNumberOfNodes = -1 |
Protected Member Functions inherited from operations_research::MPSolverInterface | |
void | ExtractModel () |
Extracts model stored in MPSolver. | |
void | ResetExtractionInformation () |
Resets the extraction information. | |
void | InvalidateSolutionSynchronization () |
void | SetCommonParameters (const MPSolverParameters ¶m) |
Sets parameters common to LP and MIP in the underlying solver. | |
void | SetMIPParameters (const MPSolverParameters ¶m) |
Sets MIP specific parameters in the underlying solver. | |
void | SetUnsupportedDoubleParam (MPSolverParameters::DoubleParam param) |
Sets an unsupported double parameter. | |
virtual void | SetUnsupportedIntegerParam (MPSolverParameters::IntegerParam param) |
Sets an unsupported integer parameter. | |
void | SetDoubleParamToUnsupportedValue (MPSolverParameters::DoubleParam param, double value) |
Sets a supported double parameter to an unsupported value. | |
virtual void | SetIntegerParamToUnsupportedValue (MPSolverParameters::IntegerParam param, int value) |
Sets a supported integer parameter to an unsupported value. | |
virtual absl::Status | SetNumThreads (int num_threads) |
Sets the number of threads to be used by the solver. | |
Protected Attributes inherited from operations_research::MPSolverInterface | |
MPSolver *const | solver_ |
SynchronizationStatus | sync_status_ |
Indicates whether the model and the solution are synchronized. | |
MPSolver::ResultStatus | result_status_ |
bool | maximize_ |
Optimization direction. | |
int | last_constraint_index_ |
Index in MPSolver::variables_ of last constraint extracted. | |
int | last_variable_index_ |
Index in MPSolver::constraints_ of last variable extracted. | |
double | objective_value_ |
The value of the objective function. | |
double | best_objective_bound_ |
The value of the best objective bound. Used only for MIP solvers. | |
bool | quiet_ |
Boolean indicator for the verbosity of the solver output. | |
Static Protected Attributes inherited from operations_research::MPSolverInterface | |
static const int | kDummyVariableIndex = 0 |
-------— MPSolverInterface -------— | |
Definition at line 83 of file gurobi_interface.cc.
|
explicit |
Constructor that takes a name for the underlying GRB solver.
Creates a LP/MIP instance with the specified name and minimization objective.
Definition at line 629 of file gurobi_interface.cc.
|
override |
Definition at line 650 of file gurobi_interface.cc.
|
overridevirtual |
Adds an indicator constraint. Returns true if the feature is supported by the underlying solver.
Reimplemented from operations_research::MPSolverInterface.
Definition at line 746 of file gurobi_interface.cc.
|
overridevirtual |
Adds Constraint incrementally.
Implements operations_research::MPSolverInterface.
Definition at line 742 of file gurobi_interface.cc.
|
overridevirtual |
Adds variable incrementally.
Implements operations_research::MPSolverInterface.
Definition at line 752 of file gurobi_interface.cc.
|
overridevirtual |
Reimplemented from operations_research::MPSolverInterface.
Definition at line 819 of file gurobi_interface.cc.
|
overridevirtual |
Clears a constraint from all its terms.
Implements operations_research::MPSolverInterface.
Definition at line 778 of file gurobi_interface.cc.
|
overridevirtual |
Clears the objective from all its terms.
Implements operations_research::MPSolverInterface.
Definition at line 807 of file gurobi_interface.cc.
|
overridevirtual |
Returns the basis status of a column.
Implements operations_research::MPSolverInterface.
Definition at line 919 of file gurobi_interface.cc.
|
inlineoverridevirtual |
Computes exact condition number. Only available for continuous problems and only implemented in GLPK.
double cond = 0.0; const int status = GRBgetdblattr(model_, GRB_DBL_ATTR_KAPPA, &cond); if (0 == status) { return cond; } else { LOG(DFATAL) << "Condition number only available for " << "continuous problems"; return 0.0; }
Override this method in interfaces that actually support it.
Reimplemented from operations_research::MPSolverInterface.
Definition at line 178 of file gurobi_interface.cc.
|
inlineoverridevirtual |
Here we reuse the Gurobi environment to support single-use license that forbids creating a second environment if one already exists.
Reimplemented from operations_research::MPSolverInterface.
Definition at line 100 of file gurobi_interface.cc.
|
overridevirtual |
Extracts the constraints that have not been extracted yet.
Add each new constraint.
Using GRBaddrangeconstr for constraints that don't require it adds a slack which is not always removed by presolve.
NOTE(user): range constraints implicitly add an extra variable to the model.
Implements operations_research::MPSolverInterface.
Definition at line 988 of file gurobi_interface.cc.
|
overridevirtual |
Extracts new variables.
Define new variables.
Add new variables to existing constraints.
If there was a nonincremental change/the model is not incremental (e.g. there is an indicator constraint), we should never enter this loop, as last_variable_index_ will be reset to zero before ExtractNewVariables() is called.
Implements operations_research::MPSolverInterface.
Definition at line 937 of file gurobi_interface.cc.
|
overridevirtual |
Extracts the objective.
Implements operations_research::MPSolverInterface.
Definition at line 1055 of file gurobi_interface.cc.
|
inlineoverridevirtual |
Reimplemented from operations_research::MPSolverInterface.
Definition at line 170 of file gurobi_interface.cc.
|
inlineoverridevirtual |
--— Misc --— Queries problem type.
Implements operations_research::MPSolverInterface.
Definition at line 155 of file gurobi_interface.cc.
|
inlineoverridevirtual |
Returns true if the problem is continuous and linear.
Implements operations_research::MPSolverInterface.
Definition at line 156 of file gurobi_interface.cc.
|
inlineoverridevirtual |
Returns true if the problem is discrete and linear.
Implements operations_research::MPSolverInterface.
Definition at line 157 of file gurobi_interface.cc.
|
overridevirtual |
---— Query statistics on the solution and the solve ---—
---— Query statistics on the solution and the solve ---— Number of simplex or interior-point iterations
Implements operations_research::MPSolverInterface.
Definition at line 825 of file gurobi_interface.cc.
|
overridevirtual |
Iterates through the solutions in Gurobi's solution pool.
Next solution only supported for MIP
Make sure we have successfully solved the problem and not modified it.
Check if we are out of solutions.
Reimplemented from operations_research::MPSolverInterface.
Definition at line 1358 of file gurobi_interface.cc.
|
overridevirtual |
Number of branch-and-bound nodes. Only available for discrete problems.
Implements operations_research::MPSolverInterface.
Definition at line 832 of file gurobi_interface.cc.
|
overridevirtual |
---— Model modifications and extraction --—
--— Model modifications and extraction --— Resets extracted model
We hold calls to GRBterminate() until the new model_ is ready.
Copy all existing parameters from the previous model to the new one. This ensures that if a user calls multiple times SetSolverSpecificParametersAsString() and then Reset() is called, we still take into account all parameters.
The current code only reapplies the parameters stored in solver_specific_parameter_string_ at the start of the solve; other parameters set by previous calls are only kept in the Gurobi model.
Implements operations_research::MPSolverInterface.
Definition at line 657 of file gurobi_interface.cc.
|
overridevirtual |
Returns the basis status of a row.
Implements operations_research::MPSolverInterface.
Definition at line 896 of file gurobi_interface.cc.
|
overridevirtual |
See MPSolver::SetCallback() for details.
Reimplemented from operations_research::MPSolverInterface.
Definition at line 1407 of file gurobi_interface.cc.
|
overridevirtual |
Changes a coefficient in a constraint.
Cannot be const, GRBchgcoeffs needs non-const pointer.
Implements operations_research::MPSolverInterface.
Definition at line 756 of file gurobi_interface.cc.
|
overridevirtual |
Modify bounds of an extracted variable.
Implements operations_research::MPSolverInterface.
Definition at line 727 of file gurobi_interface.cc.
|
overridevirtual |
Changes a coefficient in the linear objective.
Implements operations_research::MPSolverInterface.
Definition at line 786 of file gurobi_interface.cc.
|
overridevirtual |
Changes the constant term in the linear objective.
Implements operations_research::MPSolverInterface.
Definition at line 798 of file gurobi_interface.cc.
|
overridevirtual |
Sets the optimization direction (min/max).
Implements operations_research::MPSolverInterface.
Definition at line 694 of file gurobi_interface.cc.
|
overridevirtual |
Modifies bounds.
Implements operations_research::MPSolverInterface.
Definition at line 699 of file gurobi_interface.cc.
|
overridevirtual |
Modifies integrality of an extracted variable.
Implements operations_research::MPSolverInterface.
Definition at line 711 of file gurobi_interface.cc.
|
overridevirtual |
--— Solve --— Solves the problem using the parameter values specified.
Set log level.
Sync solver.
Set solution hints if any.
Pass branching priority annotations if at least one has been updated.
Time limit.
We first set our internal MPSolverParameters from 'param' and then set any user-specified internal solver parameters via solver_specific_parameter_string_. Default MPSolverParameters can override custom parameters (for example for presolving) and therefore we apply MPSolverParameters first.
Logs all parameters not at default values in the model environment.
Solve
Get the status.
Get the results.
Implements operations_research::MPSolverInterface.
Definition at line 1178 of file gurobi_interface.cc.
|
inlineoverridevirtual |
Returns a string describing the underlying solver and its version.
Implements operations_research::MPSolverInterface.
Definition at line 163 of file gurobi_interface.cc.
|
inlineoverridevirtual |
Reimplemented from operations_research::MPSolverInterface.
Definition at line 205 of file gurobi_interface.cc.
|
inlineoverridevirtual |
--— Directly solve proto is supported without interrupt —
Reimplemented from operations_research::MPSolverInterface.
Definition at line 97 of file gurobi_interface.cc.
|
inlineoverridevirtual |
Returns the underlying solver.
Implements operations_research::MPSolverInterface.
Definition at line 176 of file gurobi_interface.cc.
|
overridevirtual |
Writes the model.
Sync solver.
Reimplemented from operations_research::MPSolverInterface.
Definition at line 1389 of file gurobi_interface.cc.