OR-Tools  9.6
g_gurobi.h
Go to the documentation of this file.
1 // Copyright 2010-2022 Google LLC
2 // Licensed under the Apache License, Version 2.0 (the "License");
3 // you may not use this file except in compliance with the License.
4 // You may obtain a copy of the License at
5 //
6 // http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13 
14 // Google C++ bindings for Gurobi C API.
15 //
16 // Attempts to be as close to the Gurobi C API as possible, with the following
17 // differences:
18 // * Use destructors to automatically clean up the environment and model.
19 // * Use absl::Status to propagate errors instead of int gurobi error codes.
20 // * Use absl::StatusOr instead of output arguments.
21 // * Use absl::Span<T> instead of T* and size for array args.
22 // * Use std::string instead of null terminated char* for string values (note
23 // that attribute names are still char*).
24 // * When setting array data, accept const data (absl::Span<const T>).
25 // * Callbacks are passed as an argument to optimize and then are cleared.
26 // * Callbacks propagate errors with status.
27 // * There is no distinction between a GRBmodel and the GRBenv created for a
28 // model, they are jointly captured by the newly defined Gurobi object.
29 // * Parameters are set on the Gurobi class rather than on a GRBenv. We do not
30 // provide an API fo setting parameters on the primary environment, only on
31 // the child environment created by GRBnewmodel (for details see
32 // https://www.gurobi.com/documentation/9.1/refman/c_newmodel.html ).
33 #ifndef OR_TOOLS_MATH_OPT_SOLVERS_GUROBI_G_GUROBI_H_
34 #define OR_TOOLS_MATH_OPT_SOLVERS_GUROBI_G_GUROBI_H_
35 
36 #include <cstdint>
37 #include <functional>
38 #include <memory>
39 #include <optional>
40 #include <string>
41 #include <vector>
42 
43 #include "absl/status/status.h"
44 #include "absl/status/statusor.h"
45 #include "absl/types/span.h"
48 
50 
51 // An ISV key for the Gurobi solver, an alternative to using a license file.
52 //
53 // See http://www.gurobi.com/products/licensing-pricing/isv-program.
54 struct GurobiIsvKey {
55  std::string name;
56  std::string application_name;
57  int32_t expiration = 0;
58  std::string key;
59 };
60 
61 // Functor to use as deleter for std::unique_ptr that stores a primary GRBenv,
62 // used by GRBenvUniquePtr. Most users will not use this directly.
63 struct GurobiFreeEnv {
64  void operator()(GRBenv* const env) const;
65 };
66 
67 // Unique pointer to a GRBenv. It destroys the environment on destruction
68 // calling GRBfreeenv. Most users will not use this directly.
69 using GRBenvUniquePtr = std::unique_ptr<GRBenv, GurobiFreeEnv>;
70 
71 // Returns a new primary Gurobi environment, using the ISV key if provided, or a
72 // regular license otherwise. Gurobi::New() creates an environment automatically
73 // if not provided, so most users will not use this directly.
74 //
75 absl::StatusOr<GRBenvUniquePtr> GurobiNewPrimaryEnv(
76  const std::optional<GurobiIsvKey>& isv_key = std::nullopt);
77 
78 // Models and solves optimization problems with Gurobi.
79 //
80 // This is a thin wrapper on the Gurobi C API, holding a GRBmodel,
81 // associated GRBenv that GRBnewmodel creates, and optionally the primary
82 // environment to clean up on deletion.
83 //
84 // Throughout, we refer to the child GRBenv created by GRBnewmodel as the
85 // "model environment" while the GRBenv that was used to create the model as
86 // the "primary environment", for details see:
87 // https://www.gurobi.com/documentation/9.1/refman/c_newmodel.html
88 //
90 // Attributes
92 //
93 // Most properties of a Gurobi optimization model are set and read with
94 // attributes, using the attribute names defined in the Gurobi C API. There are
95 // scalar attributes returning a single value of the following types:
96 // * int, e.g. GRB_INT_ATTR_MODELSENSE
97 // * double, e.g. GRB_DBL_ATTR_OBJVAL
98 // * string, e.g. GRB_STR_ATTR_MODELNAME
99 // and array attributes returning a list of values of the following types:
100 // * int array, e.g. GRB_INT_ATTR_BRANCHPRIORITY
101 // * double array, e.g. GRB_DBL_ATTR_LB
102 // * char array, e.g. GRB_CHAR_ATTR_VTYPE
103 //
104 // You set a scalar attribute with the methods SetXXXAttr, e.g.
105 // std::unique_ptr<Gurobi> gurobi = Gurobi::New().value();
106 // absl::Status s = gurobi->SetIntAttr(GRB_INT_ATTR_MODELSENSE, 1);
107 // Note that not all attributes can be set; consult the Gurobi attribute docs.
108 //
109 // Attributes can also be read. However, attributes can be unavailable depending
110 // on the context, e.g. the solution objective value is not available before
111 // solving. You can determine when an attribute is available either from the
112 // Gurobi documentation or by directly testing:
113 // std::unique_ptr<Gurobi> gurobi = Gurobi::New().value();
114 // bool is_avail = gurobi->IsAttrAvailable(GRB_DBL_ATTR_OBJVAL);
115 // To read an attribute:
116 // std::unique_ptr<Gurobi> gurobi = Gurobi::New().value();
117 // absl::StatusOr<double> obj = gurobi->GetDoubleAttr(GRB_DBL_ATTR_OBJVAL);
118 // (The method *should* succeed when IsAttrAvailable() is true and you have
119 // specified the type of attribute correctly.)
120 //
121 // Array attributes are similar, but the API differs slightly. E.g. to set the
122 // first three variable lower bounds to 1.0:
123 // std::unique_ptr<Gurobi> gurobi = Gurobi::New().value();
124 // absl::Status s = gurobi->SetDoubleAttrArray(GRB_DBL_ATTR_LB, {1, 1, 1});
125 // You can also set specific indices, see SetDoubleAttrList. To read, use:
126 // Gurobi* gurobi = ...;
127 // int num_vars = ...;
128 // absl::StatusOr<std::vector<double>> lbs =
129 // gurobi->GetDoubleAttrArray(GRB_DBL_ATTR_LB, num_vars);
130 // An overload to write the result into an absl::Span is also provided.
131 //
132 // WARNING: as with the Gurobi C API, attributes cannot be read immediately
133 // after they have been set. You need to call UpdateModel() (which is called by
134 // Optimize()) before reading the model back. E.g.
135 // std::unique_ptr<Gurobi> gurobi = Gurobi::New().value();
136 // CHECK_OK(gurobi->AddVars({1, 1}, {0, 0}, {1, 1},
137 // {GRB_INTEGER, GRB_INTEGER}, {"x", "y"}));
138 // int num_vars = gurobi->GetIntAttr(GRB_INT_ATTR_NUMVARS).value(); // Is 0.
139 // CHECK_OK(gurobi->UpdateModel());
140 // num_vars = gurobi->GetIntAttr(GRB_INT_ATTR_NUMVARS).value(); // Is now 2.
141 // Calls to UpdateModel() are expensive and should be minimized.
142 //
144 // Parameters
146 //
147 // Parameters are associated directly with Gurobi rather than a GRBenv as in the
148 // C API. Parameters have three types: int, double and string. You can get and
149 // set them by their C API names, e.g.
150 // std::unique_ptr<Gurobi> gurobi = Gurobi::New().value();
151 // gurobi->SetIntParam(GRB_INT_PAR_LOGTOCONSOLE, 1);
152 // gurobi->GetIntParam(GRB_INT_PAR_LOGTOCONSOLE); // Returns 1.
153 // Unlike attributes, values can be read immediately, no call to UpdateModel()
154 // is required.
155 class Gurobi {
156  public:
157  // A sparse matrix in compressed sparse column (CSC) format. E.g.
158  // [[2, 0, 4],
159  // [8, 6, 0]]
160  // Would be {.begins={0, 2, 3}, .inds={0, 1, 1, 0}, .vals={2, 8, 6, 4}}
161  struct SparseMat {
162  // Has size equal to the number of columns, the index in inds where this
163  // column begins.
164  std::vector<int> begins;
165 
166  // Has size equal to the number of nonzeros in the matrix, the row for this
167  // entry.
168  std::vector<int> inds;
169 
170  // Has size equal to the number of nonzeros in the matrix, the value for
171  // this entry.
172  std::vector<double> vals;
173  };
174 
175  // The argument of Gurobi callbacks, allows you to read callback specific
176  // data and send information back to the solver.
178  public:
179  // For internal use only.
180  CallbackContext(Gurobi* gurobi, void* cb_data, int where);
181 
182  // The current event of the callback, see Callback Codes in Gurobi docs.
183  int where() const { return where_; }
184  Gurobi* gurobi() const { return gurobi_; }
185 
186  // Calls GRBcbget() on "what" with result type int, see Callback Codes in
187  // Gurobi docs for values of "what".
188  absl::StatusOr<int> CbGetInt(int what) const;
189 
190  // Calls GRBcbget() on "what" with result type double, see Callback Codes in
191  // Gurobi docs for values of "what".
192  absl::StatusOr<double> CbGetDouble(int what) const;
193 
194  // Calls GRBcbget() on "what" with result type double*, see Callback Codes
195  // in Gurobi docs for values of "what".
196  //
197  // The user is responsible for ensuring that result is large enough to hold
198  // the result.
199  absl::Status CbGetDoubleArray(int what, absl::Span<double> result) const;
200 
201  // Calls GRBcbget() where what=MSG_STRING (call only at where=MESSAGE).
202  absl::StatusOr<std::string> CbGetMessage() const;
203 
204  // Calls GRBcbcut().
205  absl::Status CbCut(absl::Span<const int> cutind,
206  absl::Span<const double> cutval, char cutsense,
207  double cutrhs) const;
208 
209  // Calls GRBcblazy().
210  absl::Status CbLazy(absl::Span<const int> lazyind,
211  absl::Span<const double> lazyval, char lazysense,
212  double lazyrhs) const;
213 
214  // Calls GRBcbsolution().
215  absl::StatusOr<double> CbSolution(absl::Span<const double> solution) const;
216 
217  private:
218  Gurobi* const gurobi_;
219  void* const cb_data_;
220  const int where_;
221  };
222 
223  // Invoked regularly by Gurobi while solving if provided as an argument to
224  // Gurobi::Optimize(). If the user returns a status error in the callback:
225  // * Termination of the solve is requested.
226  // * The error is propagated to the return value of Gurobi::Optimize().
227  // * The callback will not be invoked again.
228  using Callback = std::function<absl::Status(const CallbackContext&)>;
229 
230  // Creates a new Gurobi, taking ownership of primary_env if provided (if no
231  // environment is given, a new one is created internally from the license
232  // file).
233  static absl::StatusOr<std::unique_ptr<Gurobi>> New(
234  GRBenvUniquePtr primary_env = nullptr);
235 
236  // Creates a new Gurobi using an existing GRBenv, where primary_env cannot be
237  // nullptr. Unlike Gurobi::New(), the returned Gurobi will not clean up the
238  // primary environment on destruction.
239  //
240  // A GurobiEnv can be shared between models with the following restrictions:
241  // - Environments are not thread-safe (so use one thread or mutual exclusion
242  // for Gurobi::New()).
243  // - The primary environment must outlive each Gurobi instance.
244  // - Every "primary" environment counts as a "use" of a Gurobi License.
245  // Depending on your license type, you may need to share to run concurrent
246  // solves in the same process.
247  static absl::StatusOr<std::unique_ptr<Gurobi>> NewWithSharedPrimaryEnv(
248  GRBenv* primary_env);
249 
250  ~Gurobi();
251 
253  // Model Building
255 
256  // Calls GRBaddvar() to add a variable to the model.
257  absl::Status AddVar(double obj, double lb, double ub, char vtype,
258  const std::string& name);
259 
260  // Calls GRBaddvar() to add a variable and linear constraint column to the
261  // model.
262  //
263  // The inputs `vind` and `vval` must have the same size. Both can be empty if
264  // you do not want to modify the constraint matrix, though this is equivalent
265  // to the simpler overload above.
266  absl::Status AddVar(absl::Span<const int> vind, absl::Span<const double> vval,
267  double obj, double lb, double ub, char vtype,
268  const std::string& name);
269 
270  // Calls GRBaddvars() to add variables to the model.
271  //
272  // Requirements:
273  // * lb, ub and vtype must have size equal to the number of new variables.
274  // * obj should either:
275  // - have size equal to the number of new variables,
276  // - be empty (all new variables have objective coefficient 0).
277  // * names should either:
278  // - have size equal to the number of new variables,
279  // - be empty (all new variables have name "").
280  absl::Status AddVars(absl::Span<const double> obj,
281  absl::Span<const double> lb, absl::Span<const double> ub,
282  absl::Span<const char> vtype,
283  absl::Span<const std::string> names);
284 
285  // Calls GRBaddvars() to add variables and linear constraint columns to the
286  // model.
287  //
288  // The new linear constraint matrix columns are given in CSC format (see
289  // SparseMat above for an example).
290  //
291  // Requirements:
292  // * lb, ub and vtype must have size equal to the number of new variables.
293  // * obj should either:
294  // - have size equal to the number of new variables,
295  // - be empty (all new variables have objective coefficient 0).
296  // * names should either:
297  // - have size equal to the number of new variables,
298  // - be empty (all new variables have name "").
299  // * vbegin should have size equal to the number of new variables.
300  // * vind and vsize should have size equal to the number of new nonzeros in
301  // the linear constraint matrix.
302  // Note: vbegin, vind and vval can all be empty if you do not want to modify
303  // the constraint matrix, this is equivalent to the simpler overload above.
304  absl::Status AddVars(absl::Span<const int> vbegin, absl::Span<const int> vind,
305  absl::Span<const double> vval,
306  absl::Span<const double> obj,
307  absl::Span<const double> lb, absl::Span<const double> ub,
308  absl::Span<const char> vtype,
309  absl::Span<const std::string> names);
310 
311  // Calls GRBdelvars().
312  absl::Status DelVars(absl::Span<const int> ind);
313 
314  // Calls GRBaddconstr() to add a constraint to the model.
315  //
316  // This overload does not add any variable coefficients to the constraint.
317  absl::Status AddConstr(char sense, double rhs, const std::string& name);
318 
319  // Calls GRBaddconstr() to add a constraint to the model.
320  //
321  // The inputs `cind` and `cval` must have the same size.
322  absl::Status AddConstr(absl::Span<const int> cind,
323  absl::Span<const double> cval, char sense, double rhs,
324  const std::string& name);
325 
326  // Calls GRBaddconstrs().
327  //
328  // Requirements:
329  // * sense and rhs must have size equal to the number of new constraints.
330  // * names should either:
331  // - have size equal to the number of new constraints,
332  // - be empty (all new constraints have name "").
333  absl::Status AddConstrs(absl::Span<const char> sense,
334  absl::Span<const double> rhs,
335  absl::Span<const std::string> names);
336 
337  // Calls GRBdelconstrs().
338  absl::Status DelConstrs(absl::Span<const int> ind);
339 
340  // Calls GRBchgcoeffs().
341  //
342  // Requirements:
343  // * cind, vind, and val have size equal to the number of changed constraint
344  // matrix entries.
345  absl::Status ChgCoeffs(absl::Span<const int> cind, absl::Span<const int> vind,
346  absl::Span<const double> val);
347 
348  // Calls GRBaddqpterms().
349  //
350  // Requirements:
351  // * qrow, qcol, and qval have size equal to the number of new quadratic
352  // objective terms.
353  absl::Status AddQpTerms(absl::Span<const int> qrow,
354  absl::Span<const int> qcol,
355  absl::Span<const double> qval);
356 
357  // Calls GRBdelq().
358  //
359  // Deletes all quadratic objective coefficients.
360  absl::Status DelQ();
361 
362  // Calls GRBsetobjectiven().
363  //
364  // Sets the n-th objective in a multi-objective model.
365  //
366  // Requirement:
367  // * lind and lval must be of equal length.
368  absl::Status SetNthObjective(int index, int priority, double weight,
369  double abs_tol, double rel_tol,
370  const std::string& name, double constant,
371  absl::Span<const int> lind,
372  absl::Span<const double> lval);
373 
374  // Calls GRBaddqconstr().
375  //
376  // Requirements:
377  // * lind and lval must be equal length.
378  // * qrow, qcol, and qval must be equal length.
379  absl::Status AddQConstr(absl::Span<const int> lind,
380  absl::Span<const double> lval,
381  absl::Span<const int> qrow,
382  absl::Span<const int> qcol,
383  absl::Span<const double> qval, char sense, double rhs,
384  const std::string& name);
385 
386  // Calls GRBdelqconstrs().
387  //
388  // Deletes the specified quadratic constraints.
389  absl::Status DelQConstrs(const absl::Span<const int> ind);
390 
391  // Calls GRBaddsos().
392  //
393  // This adds SOS constraints to the model. You may specify multiple SOS
394  // constraints at once, and may mix the types (SOS1 and SOS2) in a single
395  // call. The data is specified in CSR format, meaning that the entries of beg
396  // indicate the contiguous subranges of ind and weight associated with a
397  // particular SOS constraint. Please see the Gurobi documentation for more
398  // detail (https://www.gurobi.com/documentation/9.5/refman/c_addsos.html).
399  //
400  // Requirements:
401  // * types and beg must be of equal length.
402  // * ind and weight must be of equal length.
403  absl::Status AddSos(absl::Span<const int> types, absl::Span<const int> beg,
404  absl::Span<const int> ind,
405  absl::Span<const double> weight);
406 
407  // Calls GRBdelsos().
408  //
409  // Deletes the specified SOS constraints.
410  absl::Status DelSos(absl::Span<const int> ind);
411 
412  // Calls GRBaddgenconstrIndicator().
413  //
414  // `ind` and `val` must be of equal length.
415  absl::Status AddIndicator(const std::string& name, int binvar, int binval,
416  absl::Span<const int> ind,
417  absl::Span<const double> val, char sense,
418  double rhs);
419 
420  // Calls GRBdelgenconstrs().
421  //
422  // Deletes the specified general constraints.
423  absl::Status DelGenConstrs(absl::Span<const int> ind);
424 
426  // Linear constraint matrix queries.
428 
429  // Calls GRBgetvars().
430  //
431  // The number of nonzeros in the constraint matrix for the num_vars columns
432  // starting with first_var.
433  //
434  // Warning: will not reflect pending modifications, call UpdateModel() or
435  // Optimize() first.
436  absl::StatusOr<int> GetNnz(int first_var, int num_vars);
437 
438  // Calls GRBgetvars().
439  //
440  // Write the nonzeros of the constraint matrix for the num_vars columns
441  // starting with first_var out in CSC format to (vbegin, vind, vval).
442  //
443  // The user is responsible for ensuring that the output Spans are exactly
444  // the correct size. See the other GetVars() overload for a simpler version.
445  //
446  // Warning: will not reflect pending modifications, call UpdateModel() or
447  // Optimize() first.
448  absl::Status GetVars(absl::Span<int> vbegin, absl::Span<int> vind,
449  absl::Span<double> vval, int first_var, int num_vars);
450 
451  // Calls GRBgetvars().
452  //
453  // Returns the nonzeros of the constraint matrix for the num_vars columns
454  // starting with first_var out in CSC format.
455  //
456  // Warning: will not reflect pending modifications, call UpdateModel() or
457  // Optimize() first.
458  absl::StatusOr<SparseMat> GetVars(int first_var, int num_vars);
459 
461  // Solving
463 
464  // Calls GRBupdatemodel().
465  absl::Status UpdateModel();
466 
467  // Calls GRBoptimize().
468  //
469  // The callback, if specified, is set before solving and cleared after.
470  absl::Status Optimize(Callback cb = nullptr);
471 
472  // Calls GRBterminate().
473  void Terminate();
474 
476  // Attributes
478 
479  bool IsAttrAvailable(const char* name) const;
480 
481  absl::StatusOr<int> GetIntAttr(const char* name) const;
482  absl::Status SetIntAttr(const char* attr_name, int value);
483 
484  absl::StatusOr<double> GetDoubleAttr(const char* name) const;
485  absl::Status SetDoubleAttr(const char* attr_name, double value);
486 
487  absl::StatusOr<std::string> GetStringAttr(const char* name) const;
488  absl::Status SetStringAttr(const char* attr_name, const std::string& value);
489 
490  absl::Status GetIntAttrArray(const char* name,
491  absl::Span<int> attr_out) const;
492  absl::StatusOr<std::vector<int>> GetIntAttrArray(const char* name,
493  int len) const;
494  absl::Status SetIntAttrArray(const char* name,
495  absl::Span<const int> new_values);
496  absl::Status SetIntAttrList(const char* name, absl::Span<const int> ind,
497  absl::Span<const int> new_values);
498 
499  absl::Status GetDoubleAttrArray(const char* name,
500  absl::Span<double> attr_out) const;
501  absl::StatusOr<std::vector<double>> GetDoubleAttrArray(const char* name,
502  int len) const;
503  absl::Status SetDoubleAttrArray(const char* name,
504  absl::Span<const double> new_values);
505  absl::Status SetDoubleAttrList(const char* name, absl::Span<const int> ind,
506  absl::Span<const double> new_values);
507 
508  absl::Status GetCharAttrArray(const char* name,
509  absl::Span<char> attr_out) const;
510  absl::StatusOr<std::vector<char>> GetCharAttrArray(const char* name,
511  int len) const;
512  absl::Status SetCharAttrArray(const char* name,
513  absl::Span<const char> new_values);
514  absl::Status SetCharAttrList(const char* name, absl::Span<const int> ind,
515  absl::Span<const char> new_values);
516 
517  absl::StatusOr<double> GetDoubleAttrElement(const char* name,
518  int element) const;
519  absl::Status SetDoubleAttrElement(const char* name, int element,
520  double new_value);
521 
522  absl::StatusOr<char> GetCharAttrElement(const char* name, int element) const;
523  absl::Status SetCharAttrElement(const char* name, int element,
524  char new_value);
525 
527  // Parameters
529 
530  // Calls GRBsetparam().
531  //
532  // Prefer the typed versions (e.g. SetIntParam()) defined below.
533  absl::Status SetParam(const char* name, const std::string& value);
534 
535  // Calls GRBsetintparam().
536  absl::Status SetIntParam(const char* name, int value);
537 
538  // Calls GRBsetdblparam().
539  absl::Status SetDoubleParam(const char* name, double value);
540 
541  // Calls GRBsetstrparam().
542  absl::Status SetStringParam(const char* name, const std::string& value);
543 
544  // Calls GRBgetintparam().
545  absl::StatusOr<int> GetIntParam(const char* name);
546 
547  // Calls GRBgetdblparam().
548  absl::StatusOr<double> GetDoubleParam(const char* name);
549 
550  // Calls GRBgetstrparam().
551  absl::StatusOr<std::string> GetStringParam(const char* name);
552 
553  // Calls GRBresetparams().
554  absl::Status ResetParameters();
555 
556  // Typically not needed.
557  GRBmodel* model() const { return gurobi_model_; }
558 
559  private:
560  // optional_owned_primary_env can be null, model and model_env cannot.
561  Gurobi(GRBenvUniquePtr optional_owned_primary_env, GRBmodel* model,
562  GRBenv* model_env);
563  // optional_owned_primary_env can be null, primary_env cannot.
564  static absl::StatusOr<std::unique_ptr<Gurobi>> New(
565  GRBenvUniquePtr optional_owned_primary_env, GRBenv* primary_env);
566 
567  absl::Status ToStatus(
568  int grb_err, absl::StatusCode code = absl::StatusCode::kInvalidArgument,
570 
571  const GRBenvUniquePtr owned_primary_env_;
572  // Invariant: Not null.
573  GRBmodel* const gurobi_model_;
574  // Invariant: Not null. This is the environment created by GRBnewmodel(), not
575  // the primary environment used to create a GRBmodel, see class documentation.
576  GRBenv* const model_env_;
577 };
578 
579 } // namespace operations_research::math_opt
580 
581 #endif // OR_TOOLS_MATH_OPT_SOLVERS_GUROBI_G_GUROBI_H_
static constexpr SourceLocation current()
absl::StatusOr< double > CbGetDouble(int what) const
Definition: g_gurobi.cc:709
absl::StatusOr< double > CbSolution(absl::Span< const double > solution) const
Definition: g_gurobi.cc:753
CallbackContext(Gurobi *gurobi, void *cb_data, int where)
Definition: g_gurobi.cc:698
absl::Status CbGetDoubleArray(int what, absl::Span< double > result) const
Definition: g_gurobi.cc:717
absl::Status CbCut(absl::Span< const int > cutind, absl::Span< const double > cutval, char cutsense, double cutrhs) const
Definition: g_gurobi.cc:733
absl::StatusOr< std::string > CbGetMessage() const
Definition: g_gurobi.cc:723
absl::StatusOr< int > CbGetInt(int what) const
Definition: g_gurobi.cc:702
absl::Status CbLazy(absl::Span< const int > lazyind, absl::Span< const double > lazyval, char lazysense, double lazyrhs) const
Definition: g_gurobi.cc:743
absl::Status AddConstr(char sense, double rhs, const std::string &name)
Definition: g_gurobi.cc:247
absl::Status GetVars(absl::Span< int > vbegin, absl::Span< int > vind, absl::Span< double > vval, int first_var, int num_vars)
Definition: g_gurobi.cc:423
absl::Status AddVar(double obj, double lb, double ub, char vtype, const std::string &name)
Definition: g_gurobi.cc:172
absl::Status GetIntAttrArray(const char *name, absl::Span< int > attr_out) const
Definition: g_gurobi.cc:551
absl::Status SetCharAttrElement(const char *name, int element, char new_value)
Definition: g_gurobi.cc:648
absl::Status DelQConstrs(const absl::Span< const int > ind)
Definition: g_gurobi.cc:358
absl::Status AddConstrs(absl::Span< const char > sense, absl::Span< const double > rhs, absl::Span< const std::string > names)
Definition: g_gurobi.cc:267
absl::StatusOr< double > GetDoubleAttrElement(const char *name, int element) const
Definition: g_gurobi.cc:626
absl::StatusOr< double > GetDoubleParam(const char *name)
Definition: g_gurobi.cc:680
absl::Status Optimize(Callback cb=nullptr)
Definition: g_gurobi.cc:456
absl::Status ChgCoeffs(absl::Span< const int > cind, absl::Span< const int > vind, absl::Span< const double > val)
Definition: g_gurobi.cc:405
absl::Status DelGenConstrs(absl::Span< const int > ind)
Definition: g_gurobi.cc:400
absl::StatusOr< int > GetIntParam(const char *name)
Definition: g_gurobi.cc:674
absl::Status SetDoubleAttr(const char *attr_name, double value)
Definition: g_gurobi.cc:528
absl::Status AddQpTerms(absl::Span< const int > qrow, absl::Span< const int > qcol, absl::Span< const double > qval)
Definition: g_gurobi.cc:294
absl::StatusOr< int > GetNnz(int first_var, int num_vars)
Definition: g_gurobi.cc:416
absl::Status SetDoubleParam(const char *name, double value)
Definition: g_gurobi.cc:664
std::function< absl::Status(const CallbackContext &)> Callback
Definition: g_gurobi.h:228
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)
Definition: g_gurobi.cc:386
absl::Status SetIntAttr(const char *attr_name, int value)
Definition: g_gurobi.cc:524
static absl::StatusOr< std::unique_ptr< Gurobi > > NewWithSharedPrimaryEnv(GRBenv *primary_env)
Definition: g_gurobi.cc:103
absl::StatusOr< std::string > GetStringParam(const char *name)
Definition: g_gurobi.cc:686
absl::Status SetDoubleAttrElement(const char *name, int element, double new_value)
Definition: g_gurobi.cc:634
absl::Status GetCharAttrArray(const char *name, absl::Span< char > attr_out) const
Definition: g_gurobi.cc:581
absl::Status SetCharAttrArray(const char *name, absl::Span< const char > new_values)
Definition: g_gurobi.cc:545
absl::StatusOr< int > GetIntAttr(const char *name) const
Definition: g_gurobi.cc:492
static absl::StatusOr< std::unique_ptr< Gurobi > > New(GRBenvUniquePtr primary_env=nullptr)
Definition: g_gurobi.cc:109
absl::Status DelVars(absl::Span< const int > ind)
Definition: g_gurobi.cc:242
absl::StatusOr< std::string > GetStringAttr(const char *name) const
Definition: g_gurobi.cc:506
absl::Status SetIntAttrList(const char *name, absl::Span< const int > ind, absl::Span< const int > new_values)
Definition: g_gurobi.cc:596
absl::Status GetDoubleAttrArray(const char *name, absl::Span< double > attr_out) const
Definition: g_gurobi.cc:566
absl::Status DelSos(absl::Span< const int > ind)
Definition: g_gurobi.cc:381
absl::Status SetDoubleAttrArray(const char *name, absl::Span< const double > new_values)
Definition: g_gurobi.cc:539
absl::Status SetParam(const char *name, const std::string &value)
Definition: g_gurobi.cc:655
bool IsAttrAvailable(const char *name) const
Definition: g_gurobi.cc:488
absl::Status SetDoubleAttrList(const char *name, absl::Span< const int > ind, absl::Span< const double > new_values)
Definition: g_gurobi.cc:606
absl::StatusOr< double > GetDoubleAttr(const char *name) const
Definition: g_gurobi.cc:499
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)
Definition: g_gurobi.cc:307
absl::Status AddSos(absl::Span< const int > types, absl::Span< const int > beg, absl::Span< const int > ind, absl::Span< const double > weight)
Definition: g_gurobi.cc:363
absl::Status SetIntParam(const char *name, int value)
Definition: g_gurobi.cc:660
absl::Status SetIntAttrArray(const char *name, absl::Span< const int > new_values)
Definition: g_gurobi.cc:533
absl::Status SetStringParam(const char *name, const std::string &value)
Definition: g_gurobi.cc:669
absl::Status DelConstrs(absl::Span< const int > ind)
Definition: g_gurobi.cc:289
absl::Status SetStringAttr(const char *attr_name, const std::string &value)
Definition: g_gurobi.cc:519
absl::Status AddVars(absl::Span< const double > obj, absl::Span< const double > lb, absl::Span< const double > ub, absl::Span< const char > vtype, absl::Span< const std::string > names)
Definition: g_gurobi.cc:193
absl::StatusOr< char > GetCharAttrElement(const char *name, int element) const
Definition: g_gurobi.cc:640
absl::Status SetCharAttrList(const char *name, absl::Span< const int > ind, absl::Span< const char > new_values)
Definition: g_gurobi.cc:616
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)
Definition: g_gurobi.cc:330
const std::string name
int64_t value
struct _GRBenv GRBenv
Definition: environment.h:32
struct _GRBmodel GRBmodel
Definition: environment.h:31
int index
absl::StatusOr< GRBenvUniquePtr > GurobiNewPrimaryEnv(const std::optional< GurobiIsvKey > &isv_key)
Definition: g_gurobi.cc:72
std::unique_ptr< GRBenv, GurobiFreeEnv > GRBenvUniquePtr
Definition: g_gurobi.h:69
int64_t weight
Definition: pack.cc:510
void operator()(GRBenv *const env) const
Definition: g_gurobi.cc:66