Google OR-Tools v9.15
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
g_gurobi.h
Go to the documentation of this file.
1// Copyright 2010-2025 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 ORTOOLS_MATH_OPT_SOLVERS_GUROBI_G_GUROBI_H_
34#define ORTOOLS_MATH_OPT_SOLVERS_GUROBI_G_GUROBI_H_
35
36#include <functional>
37#include <memory>
38#include <optional>
39#include <string>
40#include <vector>
41
42#include "absl/status/status.h"
43#include "absl/status/statusor.h"
44#include "absl/types/span.h"
48
50
51// Functor to use as deleter for std::unique_ptr that stores a primary GRBenv,
52// used by GRBenvUniquePtr. Most users will not use this directly.
54 void operator()(GRBenv* env) const;
55};
56
57// Unique pointer to a GRBenv. It destroys the environment on destruction
58// calling GRBfreeenv. Most users will not use this directly.
59using GRBenvUniquePtr = std::unique_ptr<GRBenv, GurobiFreeEnv>;
60
61// Returns a new primary Gurobi environment, using the ISV key if provided, or a
62// regular license otherwise. Gurobi::New() creates an environment automatically
63// if not provided, so most users will not use this directly.
64//
65absl::StatusOr<GRBenvUniquePtr> GurobiNewPrimaryEnv(
66 const std::optional<GurobiIsvKey>& isv_key = std::nullopt);
67
68// Models and solves optimization problems with Gurobi.
69//
70// This is a thin wrapper on the Gurobi C API, holding a GRBmodel,
71// associated GRBenv that GRBnewmodel creates, and optionally the primary
72// environment to clean up on deletion.
73//
74// Throughout, we refer to the child GRBenv created by GRBnewmodel as the
75// "model environment" while the GRBenv that was used to create the model as
76// the "primary environment", for details see:
77// https://www.gurobi.com/documentation/9.1/refman/c_newmodel.html
78//
80// Attributes
82//
83// Most properties of a Gurobi optimization model are set and read with
84// attributes, using the attribute names defined in the Gurobi C API. There are
85// scalar attributes returning a single value of the following types:
86// * int, e.g. GRB_INT_ATTR_MODELSENSE
87// * double, e.g. GRB_DBL_ATTR_OBJVAL
88// * string, e.g. GRB_STR_ATTR_MODELNAME
89// and array attributes returning a list of values of the following types:
90// * int array, e.g. GRB_INT_ATTR_BRANCHPRIORITY
91// * double array, e.g. GRB_DBL_ATTR_LB
92// * char array, e.g. GRB_CHAR_ATTR_VTYPE
93//
94// You set a scalar attribute with the methods SetXXXAttr, e.g.
95// std::unique_ptr<Gurobi> gurobi = Gurobi::New().value();
96// absl::Status s = gurobi->SetIntAttr(GRB_INT_ATTR_MODELSENSE, 1);
97// Note that not all attributes can be set; consult the Gurobi attribute docs.
98//
99// Attributes can also be read. However, attributes can be unavailable depending
100// on the context, e.g. the solution objective value is not available before
101// solving. You can determine when an attribute is available either from the
102// Gurobi documentation or by directly testing:
103// std::unique_ptr<Gurobi> gurobi = Gurobi::New().value();
104// bool is_avail = gurobi->IsAttrAvailable(GRB_DBL_ATTR_OBJVAL);
105// To read an attribute:
106// std::unique_ptr<Gurobi> gurobi = Gurobi::New().value();
107// absl::StatusOr<double> obj = gurobi->GetDoubleAttr(GRB_DBL_ATTR_OBJVAL);
108// (The method *should* succeed when IsAttrAvailable() is true and you have
109// specified the type of attribute correctly.)
110//
111// Array attributes are similar, but the API differs slightly. E.g. to set the
112// first three variable lower bounds to 1.0:
113// std::unique_ptr<Gurobi> gurobi = Gurobi::New().value();
114// absl::Status s = gurobi->SetDoubleAttrArray(GRB_DBL_ATTR_LB, {1, 1, 1});
115// You can also set specific indices, see SetDoubleAttrList. To read, use:
116// Gurobi* gurobi = ...;
117// int num_vars = ...;
118// absl::StatusOr<std::vector<double>> lbs =
119// gurobi->GetDoubleAttrArray(GRB_DBL_ATTR_LB, num_vars);
120// An overload to write the result into an absl::Span is also provided.
121//
122// WARNING: as with the Gurobi C API, attributes cannot be read immediately
123// after they have been set. You need to call UpdateModel() (which is called by
124// Optimize()) before reading the model back. E.g.
125// std::unique_ptr<Gurobi> gurobi = Gurobi::New().value();
126// CHECK_OK(gurobi->AddVars({1, 1}, {0, 0}, {1, 1},
127// {GRB_INTEGER, GRB_INTEGER}, {"x", "y"}));
128// int num_vars = gurobi->GetIntAttr(GRB_INT_ATTR_NUMVARS).value(); // Is 0.
129// CHECK_OK(gurobi->UpdateModel());
130// num_vars = gurobi->GetIntAttr(GRB_INT_ATTR_NUMVARS).value(); // Is now 2.
131// Calls to UpdateModel() are expensive and should be minimized.
132//
134// Parameters
136//
137// Parameters are associated directly with Gurobi rather than a GRBenv as in the
138// C API. Parameters have three types: int, double and string. You can get and
139// set them by their C API names, e.g.
140// std::unique_ptr<Gurobi> gurobi = Gurobi::New().value();
141// gurobi->SetIntParam(GRB_INT_PAR_LOGTOCONSOLE, 1);
142// gurobi->GetIntParam(GRB_INT_PAR_LOGTOCONSOLE); // Returns 1.
143// Unlike attributes, values can be read immediately, no call to UpdateModel()
144// is required.
145class Gurobi {
146 public:
147 // A sparse matrix in compressed sparse column (CSC) format. E.g.
148 // [[2, 0, 4],
149 // [8, 6, 0]]
150 // Would be {.begins={0, 2, 3}, .inds={0, 1, 1, 0}, .vals={2, 8, 6, 4}}
151 struct SparseMat {
152 // Has size equal to the number of columns, the index in inds where this
153 // column begins.
154 std::vector<int> begins;
156 // Has size equal to the number of nonzeros in the matrix, the row for this
157 // entry.
158 std::vector<int> inds;
159
160 // Has size equal to the number of nonzeros in the matrix, the value for
161 // this entry.
162 std::vector<double> vals;
163 };
164
165 // The argument of Gurobi callbacks, allows you to read callback specific
166 // data and send information back to the solver.
167 class CallbackContext {
168 public:
169 // For internal use only.
170 CallbackContext(Gurobi* gurobi, void* cb_data, int where);
172 // The current event of the callback, see Callback Codes in Gurobi docs.
173 int where() const { return where_; }
174 Gurobi* gurobi() const { return gurobi_; }
175
176 // Calls GRBcbget() on "what" with result type int, see Callback Codes in
177 // Gurobi docs for values of "what".
178 absl::StatusOr<int> CbGetInt(int what) const;
179
180 // Calls GRBcbget() on "what" with result type double, see Callback Codes in
181 // Gurobi docs for values of "what".
182 absl::StatusOr<double> CbGetDouble(int what) const;
183
184 // Calls GRBcbget() on "what" with result type double*, see Callback Codes
185 // in Gurobi docs for values of "what".
186 //
187 // The user is responsible for ensuring that result is large enough to hold
188 // the result.
189 absl::Status CbGetDoubleArray(int what, absl::Span<double> result) const;
190
191 // Calls GRBcbget() where what=MSG_STRING (call only at where=MESSAGE).
192 absl::StatusOr<std::string> CbGetMessage() const;
193
194 // Calls GRBcbcut().
195 absl::Status CbCut(absl::Span<const int> cutind,
196 absl::Span<const double> cutval, char cutsense,
197 double cutrhs) const;
198
199 // Calls GRBcblazy().
200 absl::Status CbLazy(absl::Span<const int> lazyind,
201 absl::Span<const double> lazyval, char lazysense,
202 double lazyrhs) const;
203
204 // Calls GRBcbsolution().
205 absl::StatusOr<double> CbSolution(absl::Span<const double> solution) const;
206
207 private:
208 Gurobi* const gurobi_;
209 void* const cb_data_;
210 const int where_;
211 };
212
213 // Invoked regularly by Gurobi while solving if provided as an argument to
214 // Gurobi::Optimize(). If the user returns a status error in the callback:
215 // * Termination of the solve is requested.
216 // * The error is propagated to the return value of Gurobi::Optimize().
217 // * The callback will not be invoked again.
218 using Callback = std::function<absl::Status(const CallbackContext&)>;
219
220 // Creates a new Gurobi, taking ownership of primary_env if provided (if no
221 // environment is given, a new one is created internally from the license
222 // file).
223 static absl::StatusOr<std::unique_ptr<Gurobi>> New(
224 GRBenvUniquePtr primary_env = nullptr);
225
226 // Creates a new Gurobi using an existing GRBenv, where primary_env cannot be
227 // nullptr. Unlike Gurobi::New(), the returned Gurobi will not clean up the
228 // primary environment on destruction.
229 //
230 // A GurobiEnv can be shared between models with the following restrictions:
231 // - Environments are not thread-safe (so use one thread or mutual exclusion
232 // for Gurobi::New()).
233 // - The primary environment must outlive each Gurobi instance.
234 // - Every "primary" environment counts as a "use" of a Gurobi License.
235 // Depending on your license type, you may need to share to run concurrent
236 // solves in the same process.
237 static absl::StatusOr<std::unique_ptr<Gurobi>> NewWithSharedPrimaryEnv(
238 GRBenv* primary_env);
239
240 ~Gurobi();
241
243 // Model Building
245
246 // Calls GRBaddvar() to add a variable to the model.
247 absl::Status AddVar(double obj, double lb, double ub, char vtype,
248 const std::string& name);
249
250 // Calls GRBaddvar() to add a variable and linear constraint column to the
251 // model.
252 //
253 // The inputs `vind` and `vval` must have the same size. Both can be empty if
254 // you do not want to modify the constraint matrix, though this is equivalent
255 // to the simpler overload above.
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);
259
260 // Calls GRBaddvars() to add variables to the model.
261 //
262 // Requirements:
263 // * lb, ub and vtype must have size equal to the number of new variables.
264 // * obj should either:
265 // - have size equal to the number of new variables,
266 // - be empty (all new variables have objective coefficient 0).
267 // * names should either:
268 // - have size equal to the number of new variables,
269 // - be empty (all new variables have 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);
274
275 // Calls GRBaddvars() to add variables and linear constraint columns to the
276 // model.
277 //
278 // The new linear constraint matrix columns are given in CSC format (see
279 // SparseMat above for an example).
280 //
281 // Requirements:
282 // * lb, ub and vtype must have size equal to the number of new variables.
283 // * obj should either:
284 // - have size equal to the number of new variables,
285 // - be empty (all new variables have objective coefficient 0).
286 // * names should either:
287 // - have size equal to the number of new variables,
288 // - be empty (all new variables have name "").
289 // * vbegin should have size equal to the number of new variables.
290 // * vind and vsize should have size equal to the number of new nonzeros in
291 // the linear constraint matrix.
292 // Note: vbegin, vind and vval can all be empty if you do not want to modify
293 // the constraint matrix, this is equivalent to the simpler overload above.
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);
300
301 // Calls GRBdelvars().
302 absl::Status DelVars(absl::Span<const int> ind);
303
304 // Calls GRBaddconstr() to add a constraint to the model.
305 //
306 // This overload does not add any variable coefficients to the constraint.
307 absl::Status AddConstr(char sense, double rhs, const std::string& name);
308
309 // Calls GRBaddconstr() to add a constraint to the model.
310 //
311 // The inputs `cind` and `cval` must have the same size.
312 absl::Status AddConstr(absl::Span<const int> cind,
313 absl::Span<const double> cval, char sense, double rhs,
314 const std::string& name);
315
316 // Calls GRBaddconstrs().
317 //
318 // Requirements:
319 // * sense and rhs must have size equal to the number of new constraints.
320 // * names should either:
321 // - have size equal to the number of new constraints,
322 // - be empty (all new constraints have name "").
323 absl::Status AddConstrs(absl::Span<const char> sense,
324 absl::Span<const double> rhs,
325 absl::Span<const std::string> names);
326
327 // Calls GRBdelconstrs().
328 absl::Status DelConstrs(absl::Span<const int> ind);
329
330 // Calls GRBchgcoeffs().
331 //
332 // Requirements:
333 // * cind, vind, and val have size equal to the number of changed constraint
334 // matrix entries.
335 absl::Status ChgCoeffs(absl::Span<const int> cind, absl::Span<const int> vind,
336 absl::Span<const double> val);
337
338 // Calls GRBaddqpterms().
339 //
340 // Requirements:
341 // * qrow, qcol, and qval have size equal to the number of new quadratic
342 // objective terms.
343 absl::Status AddQpTerms(absl::Span<const int> qrow,
344 absl::Span<const int> qcol,
345 absl::Span<const double> qval);
346
347 // Calls GRBdelq().
348 //
349 // Deletes all quadratic objective coefficients.
350 absl::Status DelQ();
351
352 // Calls GRBsetobjectiven().
353 //
354 // Sets the n-th objective in a multi-objective model.
355 //
356 // Requirement:
357 // * lind and lval must be of equal length.
358 absl::Status SetNthObjective(int index, int priority, double weight,
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);
363
364 // Calls GRBaddqconstr().
365 //
366 // Requirements:
367 // * lind and lval must be equal length.
368 // * qrow, qcol, and qval must be equal length.
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);
375
376 // Calls GRBdelqconstrs().
377 //
378 // Deletes the specified quadratic constraints.
379 absl::Status DelQConstrs(absl::Span<const int> ind);
380
381 // Calls GRBaddsos().
382 //
383 // This adds SOS constraints to the model. You may specify multiple SOS
384 // constraints at once, and may mix the types (SOS1 and SOS2) in a single
385 // call. The data is specified in CSR format, meaning that the entries of beg
386 // indicate the contiguous subranges of ind and weight associated with a
387 // particular SOS constraint. Please see the Gurobi documentation for more
388 // detail (https://www.gurobi.com/documentation/9.5/refman/c_addsos.html).
389 //
390 // Requirements:
391 // * types and beg must be of equal length.
392 // * ind and weight must be of equal length.
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);
396
397 // Calls GRBdelsos().
398 //
399 // Deletes the specified SOS constraints.
400 absl::Status DelSos(absl::Span<const int> ind);
401
402 // Calls GRBaddgenconstrIndicator().
403 //
404 // `ind` and `val` must be of equal length.
405 absl::Status AddIndicator(const std::string& name, int binvar, int binval,
406 absl::Span<const int> ind,
407 absl::Span<const double> val, char sense,
408 double rhs);
409
410 // Calls GRBdelgenconstrs().
411 //
412 // Deletes the specified general constraints.
413 absl::Status DelGenConstrs(absl::Span<const int> ind);
414
416 // Linear constraint matrix queries.
418
419 // Calls GRBgetvars().
420 //
421 // The number of nonzeros in the constraint matrix for the num_vars columns
422 // starting with first_var.
423 //
424 // Warning: will not reflect pending modifications, call UpdateModel() or
425 // Optimize() first.
426 absl::StatusOr<int> GetNnz(int first_var, int num_vars);
427
428 // Calls GRBgetvars().
429 //
430 // Write the nonzeros of the constraint matrix for the num_vars columns
431 // starting with first_var out in CSC format to (vbegin, vind, vval).
432 //
433 // The user is responsible for ensuring that the output Spans are exactly
434 // the correct size. See the other GetVars() overload for a simpler version.
435 //
436 // Warning: will not reflect pending modifications, call UpdateModel() or
437 // Optimize() first.
438 absl::Status GetVars(absl::Span<int> vbegin, absl::Span<int> vind,
439 absl::Span<double> vval, int first_var, int num_vars);
440
441 // Calls GRBgetvars().
442 //
443 // Returns the nonzeros of the constraint matrix for the num_vars columns
444 // starting with first_var out in CSC format.
445 //
446 // Warning: will not reflect pending modifications, call UpdateModel() or
447 // Optimize() first.
448 absl::StatusOr<SparseMat> GetVars(int first_var, int num_vars);
449
451 // Solving
453
454 // Calls GRBupdatemodel().
455 absl::Status UpdateModel();
456
457 // Calls GRBoptimize().
458 //
459 // The callback, if specified, is set before solving and cleared after.
460 absl::Status Optimize(Callback cb = nullptr);
461
462 // Calls GRBterminate().
463 void Terminate();
464
465 // Calls GRBcomputeIIS().
466 //
467 // Returns:
468 // * a status if Gurobi errors,
469 // * true if Gurobi proves that the model is infeasible, or
470 // * false otherwise (e.g., feasibility is proven or a limit is reached).
471 //
472 // The callback, if specified, is set before solving and cleared after.
473 absl::StatusOr<bool> ComputeIIS(Callback cb = nullptr);
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<int> GetIntAttrElement(const char* name, int element) const;
518 absl::Status SetIntAttrElement(const char* name, int element, int new_value);
519
520 absl::StatusOr<double> GetDoubleAttrElement(const char* name,
521 int element) const;
522 absl::Status SetDoubleAttrElement(const char* name, int element,
523 double new_value);
524
525 absl::StatusOr<char> GetCharAttrElement(const char* name, int element) const;
526 absl::Status SetCharAttrElement(const char* name, int element,
527 char new_value);
528
530 // Parameters
532
533 // Calls GRBsetparam().
534 //
535 // Prefer the typed versions (e.g. SetIntParam()) defined below.
536 absl::Status SetParam(const char* name, const std::string& value);
537
538 // Calls GRBsetintparam().
539 absl::Status SetIntParam(const char* name, int value);
540
541 // Calls GRBsetdblparam().
542 absl::Status SetDoubleParam(const char* name, double value);
543
544 // Calls GRBsetstrparam().
545 absl::Status SetStringParam(const char* name, const std::string& value);
546
547 // Calls GRBgetintparam().
548 absl::StatusOr<int> GetIntParam(const char* name);
549
550 // Calls GRBgetdblparam().
551 absl::StatusOr<double> GetDoubleParam(const char* name);
552
553 // Calls GRBgetstrparam().
554 absl::StatusOr<std::string> GetStringParam(const char* name);
555
556 // Calls GRBresetparams().
557 absl::Status ResetParameters();
558
560 // Multi-objective Parameters
562
563 // Calls GRBsetdblparam() on the environment associated with the
564 // `obj_index`-th objective.
565 absl::Status SetMultiObjectiveDoubleParam(const char* name, int obj_index,
566 double value);
567
568 // Calls GRBgetdblparam() on the environment associated with the
569 // `obj_index`-th objective.
570 absl::StatusOr<double> GetMultiObjectiveDoubleParam(const char* name,
571 int obj_index);
572
573 // Typically not needed.
574 GRBmodel* model() const { return gurobi_model_; }
575
576 absl::Status ToStatus(
577 int grb_err, absl::StatusCode code = absl::StatusCode::kInvalidArgument,
579
580 private:
581 // optional_owned_primary_env can be null, model and model_env cannot.
582 Gurobi(GRBenvUniquePtr optional_owned_primary_env, GRBmodel* model,
583 GRBenv* model_env);
584 // optional_owned_primary_env can be null, primary_env cannot.
585 static absl::StatusOr<std::unique_ptr<Gurobi>> New(
586 GRBenvUniquePtr optional_owned_primary_env, GRBenv* primary_env);
587 absl::StatusOr<GRBenv*> GetMultiObjectiveEnv(int obj_index) const;
588
589 const GRBenvUniquePtr owned_primary_env_;
590 // Invariant: Not null.
591 GRBmodel* const gurobi_model_;
592 // Invariant: Not null. This is the environment created by GRBnewmodel(), not
593 // the primary environment used to create a GRBmodel, see class documentation.
594 GRBenv* const model_env_;
595};
596
597} // namespace operations_research::math_opt
598
599#endif // ORTOOLS_MATH_OPT_SOLVERS_GUROBI_G_GUROBI_H_
static constexpr SourceLocation current()
absl::StatusOr< std::string > CbGetMessage() const
Definition g_gurobi.cc:832
absl::Status CbLazy(absl::Span< const int > lazyind, absl::Span< const double > lazyval, char lazysense, double lazyrhs) const
Definition g_gurobi.cc:852
CallbackContext(Gurobi *gurobi, void *cb_data, int where)
Definition g_gurobi.cc:807
absl::StatusOr< double > CbGetDouble(int what) const
Definition g_gurobi.cc:818
absl::Status CbCut(absl::Span< const int > cutind, absl::Span< const double > cutval, char cutsense, double cutrhs) const
Definition g_gurobi.cc:842
absl::StatusOr< double > CbSolution(absl::Span< const double > solution) const
Definition g_gurobi.cc:862
absl::Status CbGetDoubleArray(int what, absl::Span< double > result) const
Definition g_gurobi.cc:826
absl::StatusOr< int > CbGetInt(int what) const
Definition g_gurobi.cc:811
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:466
absl::Status GetIntAttrArray(const char *name, absl::Span< int > attr_out) const
Definition g_gurobi.cc:629
absl::Status SetMultiObjectiveDoubleParam(const char *name, int obj_index, double value)
Definition g_gurobi.cc:788
absl::Status ToStatus(int grb_err, absl::StatusCode code=absl::StatusCode::kInvalidArgument, absl::SourceLocation loc=absl::SourceLocation::current()) const
Definition g_gurobi.cc:241
absl::Status DelGenConstrs(absl::Span< const int > ind)
Definition g_gurobi.cc:480
absl::Status SetDoubleAttrElement(const char *name, int element, double new_value)
Definition g_gurobi.cc:726
static absl::StatusOr< std::unique_ptr< Gurobi > > NewWithSharedPrimaryEnv(GRBenv *primary_env)
Definition g_gurobi.cc:183
absl::StatusOr< bool > ComputeIIS(Callback cb=nullptr)
Definition g_gurobi.cc:544
absl::Status AddVar(double obj, double lb, double ub, char vtype, const std::string &name)
Definition g_gurobi.cc:252
bool IsAttrAvailable(const char *name) const
Definition g_gurobi.cc:566
absl::StatusOr< char > GetCharAttrElement(const char *name, int element) const
Definition g_gurobi.cc:732
absl::Status SetIntAttrElement(const char *name, int element, int new_value)
Definition g_gurobi.cc:712
absl::Status SetCharAttrArray(const char *name, absl::Span< const char > new_values)
Definition g_gurobi.cc:623
absl::Status SetDoubleAttrArray(const char *name, absl::Span< const double > new_values)
Definition g_gurobi.cc:617
absl::StatusOr< int > GetIntAttr(const char *name) const
Definition g_gurobi.cc:570
absl::Status SetStringParam(const char *name, const std::string &value)
Definition g_gurobi.cc:761
absl::Status DelSos(absl::Span< const int > ind)
Definition g_gurobi.cc:461
absl::StatusOr< int > GetNnz(int first_var, int num_vars)
Definition g_gurobi.cc:496
absl::Status SetDoubleAttrList(const char *name, absl::Span< const int > ind, absl::Span< const double > new_values)
Definition g_gurobi.cc:684
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:443
absl::Status SetIntAttr(const char *attr_name, int value)
Definition g_gurobi.cc:602
absl::Status AddConstr(char sense, double rhs, const std::string &name)
Definition g_gurobi.cc:327
absl::Status SetParam(const char *name, const std::string &value)
Definition g_gurobi.cc:747
absl::Status SetStringAttr(const char *attr_name, const std::string &value)
Definition g_gurobi.cc:597
std::function< absl::Status(const CallbackContext &)> Callback
Definition g_gurobi.h:222
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:503
absl::Status ChgCoeffs(absl::Span< const int > cind, absl::Span< const int > vind, absl::Span< const double > val)
Definition g_gurobi.cc:485
static absl::StatusOr< std::unique_ptr< Gurobi > > New(GRBenvUniquePtr primary_env=nullptr)
Definition g_gurobi.cc:189
absl::Status Optimize(Callback cb=nullptr)
Definition g_gurobi.cc:536
absl::Status GetCharAttrArray(const char *name, absl::Span< char > attr_out) const
Definition g_gurobi.cc:659
absl::StatusOr< double > GetDoubleAttrElement(const char *name, int element) const
Definition g_gurobi.cc:718
absl::StatusOr< double > GetDoubleAttr(const char *name) const
Definition g_gurobi.cc:577
absl::Status SetCharAttrElement(const char *name, int element, char new_value)
Definition g_gurobi.cc:740
absl::Status SetIntParam(const char *name, int value)
Definition g_gurobi.cc:752
absl::StatusOr< std::string > GetStringAttr(const char *name) const
Definition g_gurobi.cc:584
absl::Status SetIntAttrArray(const char *name, absl::Span< const int > new_values)
Definition g_gurobi.cc:611
absl::StatusOr< int > GetIntParam(const char *name)
Definition g_gurobi.cc:766
absl::StatusOr< int > GetIntAttrElement(const char *name, int element) const
Definition g_gurobi.cc:704
absl::Status AddQpTerms(absl::Span< const int > qrow, absl::Span< const int > qcol, absl::Span< const double > qval)
Definition g_gurobi.cc:374
absl::Status SetDoubleParam(const char *name, double value)
Definition g_gurobi.cc:756
absl::StatusOr< double > GetDoubleParam(const char *name)
Definition g_gurobi.cc:772
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:387
absl::Status GetDoubleAttrArray(const char *name, absl::Span< double > attr_out) const
Definition g_gurobi.cc:644
absl::Status SetDoubleAttr(const char *attr_name, double value)
Definition g_gurobi.cc:606
absl::StatusOr< std::string > GetStringParam(const char *name)
Definition g_gurobi.cc:778
absl::Status DelQConstrs(absl::Span< const int > ind)
Definition g_gurobi.cc:438
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:410
have size equal to the number of new be empty(all new constraints have name ""). absl absl::Status DelConstrs(absl::Span< const int > ind)
Definition g_gurobi.cc:369
absl::Status SetIntAttrList(const char *name, absl::Span< const int > ind, absl::Span< const int > new_values)
Definition g_gurobi.cc:674
absl::StatusOr< double > GetMultiObjectiveDoubleParam(const char *name, int obj_index)
Definition g_gurobi.cc:796
absl::Status SetCharAttrList(const char *name, absl::Span< const int > ind, absl::Span< const char > new_values)
Definition g_gurobi.cc:694
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)
Definition g_gurobi.cc:322
struct _GRBenv GRBenv
struct _GRBmodel GRBmodel
absl::StatusOr< GRBenvUniquePtr > GurobiNewPrimaryEnv(const std::optional< GurobiIsvKey > &isv_key)
Definition g_gurobi.cc:162
std::unique_ptr< GRBenv, GurobiFreeEnv > GRBenvUniquePtr
Definition g_gurobi.h:59
Select next search node to expand Select next item_i to add this new search node to the search Generate a new search node where item_i is not in the knapsack Check validity of this new partial solution(using propagators) - If valid