33#ifndef OR_TOOLS_MATH_OPT_SOLVERS_GUROBI_G_GUROBI_H_
34#define OR_TOOLS_MATH_OPT_SOLVERS_GUROBI_G_GUROBI_H_
42#include "absl/status/status.h"
43#include "absl/status/statusor.h"
44#include "absl/types/span.h"
66 const std::optional<GurobiIsvKey>& isv_key = std::nullopt);
173 int where()
const {
return where_; }
182 absl::StatusOr<double>
CbGetDouble(
int what)
const;
195 absl::Status
CbCut(absl::Span<const int> cutind,
196 absl::Span<const double> cutval,
char cutsense,
197 double cutrhs)
const;
200 absl::Status
CbLazy(absl::Span<const int> lazyind,
201 absl::Span<const double> lazyval,
char lazysense,
202 double lazyrhs)
const;
209 void*
const cb_data_;
223 static absl::StatusOr<std::unique_ptr<Gurobi>>
New(
247 absl::Status
AddVar(
double obj,
double lb,
double ub,
char vtype,
248 const std::string&
name);
256 absl::Status
AddVar(absl::Span<const int> vind, absl::Span<const double> vval,
257 double obj,
double lb,
double ub,
char vtype,
258 const std::string&
name);
270 absl::Status AddVars(absl::Span<const double> obj,
271 absl::Span<const double> lb, absl::Span<const double> ub,
272 absl::Span<const char> vtype,
273 absl::Span<const std::string> names);
294 absl::Status AddVars(absl::Span<const int> vbegin, absl::Span<const int> vind,
295 absl::Span<const double> vval,
296 absl::Span<const double> obj,
297 absl::Span<const double> lb, absl::Span<const double> ub,
298 absl::Span<const char> vtype,
299 absl::Span<const std::string> names);
302 absl::Status
DelVars(absl::Span<const int> ind);
307 absl::Status
AddConstr(
char sense,
double rhs,
const std::string&
name);
312 absl::Status
AddConstr(absl::Span<const int> cind,
313 absl::Span<const double> cval,
char sense,
double rhs,
314 const std::string&
name);
323 absl::Status AddConstrs(absl::Span<const char> sense,
324 absl::Span<const double> rhs,
325 absl::Span<const std::string> names);
328 absl::Status
DelConstrs(absl::Span<const int> ind);
335 absl::Status
ChgCoeffs(absl::Span<const int> cind, absl::Span<const int> vind,
336 absl::Span<const double> val);
343 absl::Status
AddQpTerms(absl::Span<const int> qrow,
344 absl::Span<const int> qcol,
345 absl::Span<const double> qval);
359 double abs_tol,
double rel_tol,
360 const std::string&
name,
double constant,
361 absl::Span<const int> lind,
362 absl::Span<const double> lval);
369 absl::Status
AddQConstr(absl::Span<const int> lind,
370 absl::Span<const double> lval,
371 absl::Span<const int> qrow,
372 absl::Span<const int> qcol,
373 absl::Span<const double> qval,
char sense,
double rhs,
374 const std::string&
name);
379 absl::Status
DelQConstrs(absl::Span<const int> ind);
393 absl::Status
AddSos(absl::Span<const int> types, absl::Span<const int> beg,
394 absl::Span<const int> ind,
395 absl::Span<const double>
weight);
400 absl::Status
DelSos(absl::Span<const int> ind);
406 absl::Span<const int> ind,
407 absl::Span<const double> val,
char sense,
426 absl::StatusOr<int>
GetNnz(
int first_var,
int num_vars);
438 absl::Status
GetVars(absl::Span<int> vbegin, absl::Span<int> vind,
439 absl::Span<double> vval,
int first_var,
int num_vars);
448 absl::StatusOr<SparseMat>
GetVars(
int first_var,
int num_vars);
491 absl::Span<int> attr_out)
const;
495 absl::Span<const int> new_values);
497 absl::Span<const int> new_values);
500 absl::Span<double> attr_out)
const;
504 absl::Span<const double> new_values);
506 absl::Span<const double> new_values);
509 absl::Span<char> attr_out)
const;
513 absl::Span<const char> new_values);
515 absl::Span<const char> new_values);
563 int grb_err, absl::StatusCode code = absl::StatusCode::kInvalidArgument,
571 static absl::StatusOr<std::unique_ptr<Gurobi>>
New(
static constexpr SourceLocation current()
absl::StatusOr< std::string > CbGetMessage() const
Calls GRBcbget() where what=MSG_STRING (call only at where=MESSAGE).
absl::Status CbLazy(absl::Span< const int > lazyind, absl::Span< const double > lazyval, char lazysense, double lazyrhs) const
Calls GRBcblazy().
int where() const
The current event of the callback, see Callback Codes in Gurobi docs.
CallbackContext(Gurobi *gurobi, void *cb_data, int where)
For internal use only.
absl::StatusOr< double > CbGetDouble(int what) const
absl::Status CbCut(absl::Span< const int > cutind, absl::Span< const double > cutval, char cutsense, double cutrhs) const
Calls GRBcbcut().
absl::StatusOr< double > CbSolution(absl::Span< const double > solution) const
Calls GRBcbsolution().
absl::Status CbGetDoubleArray(int what, absl::Span< double > result) const
absl::StatusOr< int > CbGetInt(int what) const
absl::Status AddIndicator(const std::string &name, int binvar, int binval, absl::Span< const int > ind, absl::Span< const double > val, char sense, double rhs)
absl::Status GetIntAttrArray(const char *name, absl::Span< int > attr_out) const
absl::Status ToStatus(int grb_err, absl::StatusCode code=absl::StatusCode::kInvalidArgument, absl::SourceLocation loc=absl::SourceLocation::current()) const
absl::Status DelGenConstrs(absl::Span< const int > ind)
absl::Status SetDoubleAttrElement(const char *name, int element, double new_value)
static absl::StatusOr< std::unique_ptr< Gurobi > > NewWithSharedPrimaryEnv(GRBenv *primary_env)
absl::StatusOr< bool > ComputeIIS(Callback cb=nullptr)
absl::Status AddVar(double obj, double lb, double ub, char vtype, const std::string &name)
Calls GRBaddvar() to add a variable to the model.
bool IsAttrAvailable(const char *name) const
absl::StatusOr< char > GetCharAttrElement(const char *name, int element) const
absl::Status SetIntAttrElement(const char *name, int element, int new_value)
absl::Status SetCharAttrArray(const char *name, absl::Span< const char > new_values)
absl::Status SetDoubleAttrArray(const char *name, absl::Span< const double > new_values)
absl::StatusOr< int > GetIntAttr(const char *name) const
absl::Status SetStringParam(const char *name, const std::string &value)
Calls GRBsetstrparam().
absl::Status DelSos(absl::Span< const int > ind)
absl::StatusOr< int > GetNnz(int first_var, int num_vars)
absl::Status SetDoubleAttrList(const char *name, absl::Span< const int > ind, absl::Span< const double > new_values)
absl::Status AddSos(absl::Span< const int > types, absl::Span< const int > beg, absl::Span< const int > ind, absl::Span< const double > weight)
absl::Status SetIntAttr(const char *attr_name, int value)
absl::Status AddConstr(char sense, double rhs, const std::string &name)
absl::Status SetParam(const char *name, const std::string &value)
absl::Status SetStringAttr(const char *attr_name, const std::string &value)
std::function< absl::Status(const CallbackContext &)> Callback
absl::Status GetVars(absl::Span< int > vbegin, absl::Span< int > vind, absl::Span< double > vval, int first_var, int num_vars)
absl::Status ChgCoeffs(absl::Span< const int > cind, absl::Span< const int > vind, absl::Span< const double > val)
void Terminate()
Calls GRBterminate().
static absl::StatusOr< std::unique_ptr< Gurobi > > New(GRBenvUniquePtr primary_env=nullptr)
GRBmodel * model() const
Typically not needed.
absl::Status Optimize(Callback cb=nullptr)
absl::Status GetCharAttrArray(const char *name, absl::Span< char > attr_out) const
absl::StatusOr< double > GetDoubleAttrElement(const char *name, int element) const
absl::StatusOr< double > GetDoubleAttr(const char *name) const
absl::Status SetCharAttrElement(const char *name, int element, char new_value)
absl::Status SetIntParam(const char *name, int value)
Calls GRBsetintparam().
absl::StatusOr< std::string > GetStringAttr(const char *name) const
absl::Status SetIntAttrArray(const char *name, absl::Span< const int > new_values)
absl::StatusOr< int > GetIntParam(const char *name)
Calls GRBgetintparam().
absl::StatusOr< int > GetIntAttrElement(const char *name, int element) const
absl::Status AddQpTerms(absl::Span< const int > qrow, absl::Span< const int > qcol, absl::Span< const double > qval)
absl::Status SetDoubleParam(const char *name, double value)
Calls GRBsetdblparam().
absl::StatusOr< double > GetDoubleParam(const char *name)
Calls GRBgetdblparam().
absl::Status SetNthObjective(int index, int priority, double weight, double abs_tol, double rel_tol, const std::string &name, double constant, absl::Span< const int > lind, absl::Span< const double > lval)
absl::Status GetDoubleAttrArray(const char *name, absl::Span< double > attr_out) const
absl::Status ResetParameters()
Calls GRBresetparams().
absl::Status UpdateModel()
Calls GRBupdatemodel().
absl::Status SetDoubleAttr(const char *attr_name, double value)
absl::StatusOr< std::string > GetStringParam(const char *name)
Calls GRBgetstrparam().
absl::Status DelQConstrs(absl::Span< const int > ind)
absl::Status AddQConstr(absl::Span< const int > lind, absl::Span< const double > lval, absl::Span< const int > qrow, absl::Span< const int > qcol, absl::Span< const double > qval, char sense, double rhs, const std::string &name)
have size equal to the number of new be empty(all new constraints have name ""). absl absl::Status DelConstrs(absl::Span< const int > ind)
Calls GRBdelconstrs().
absl::Status SetIntAttrList(const char *name, absl::Span< const int > ind, absl::Span< const int > new_values)
absl::Status SetCharAttrList(const char *name, absl::Span< const int > ind, absl::Span< const char > new_values)
have size equal to the number of new be be empty(all new variables have name ""). absl have size equal to the number of new be be empty(all new variables have name ""). absl absl::Status DelVars(absl::Span< const int > ind)
Calls GRBdelvars().
const std::string name
A name for logging purposes.
struct _GRBmodel GRBmodel
An object oriented wrapper for quadratic constraints in ModelStorage.
absl::StatusOr< GRBenvUniquePtr > GurobiNewPrimaryEnv(const std::optional< GurobiIsvKey > &isv_key)
std::unique_ptr< GRBenv, GurobiFreeEnv > GRBenvUniquePtr
void operator()(GRBenv *env) const
std::vector< double > vals
std::vector< int > begins