Google OR-Tools v9.14
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
environment.cc
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
15
16#include <mutex>
17#include <string>
18
19#include "absl/flags/flag.h"
20#include "absl/status/status.h"
21#include "absl/status/statusor.h"
22#include "absl/strings/match.h"
23#include "absl/strings/str_cat.h"
24#include "absl/strings/str_format.h"
25#include "absl/strings/str_join.h"
26#include "absl/synchronization/mutex.h"
27#include "ortools/base/file.h"
30
31namespace operations_research {
32
34 absl::StatusOr<GRBenv*> status = GetGurobiEnv();
35 if (!status.ok() || status.value() == nullptr) {
36 LOG(WARNING) << status.status();
37 return false;
38 }
39
40 GRBfreeenv(status.value());
41
42 return true;
43}
44
45// This was generated with the parse_header.py script.
46// See the comment at the top of the script.
47
48// This is the 'define' section.
49std::function<int(GRBmodel* model, const char* attrname)> GRBisattravailable =
50 nullptr;
51std::function<int(GRBmodel* model, const char* attrname, int* valueP)>
52 GRBgetintattr = nullptr;
53std::function<int(GRBmodel* model, const char* attrname, int newvalue)>
54 GRBsetintattr = nullptr;
55std::function<int(GRBmodel* model, const char* attrname, int element,
56 int* valueP)>
58std::function<int(GRBmodel* model, const char* attrname, int element,
59 int newvalue)>
61std::function<int(GRBmodel* model, const char* attrname, int first, int len,
62 int* values)>
64std::function<int(GRBmodel* model, const char* attrname, int first, int len,
65 int* newvalues)>
67std::function<int(GRBmodel* model, const char* attrname, int len, int* ind,
68 int* newvalues)>
70std::function<int(GRBmodel* model, const char* attrname, int element,
71 char* valueP)>
73std::function<int(GRBmodel* model, const char* attrname, int element,
74 char newvalue)>
76std::function<int(GRBmodel* model, const char* attrname, int first, int len,
77 char* values)>
79std::function<int(GRBmodel* model, const char* attrname, int first, int len,
80 char* newvalues)>
82std::function<int(GRBmodel* model, const char* attrname, int len, int* ind,
83 char* newvalues)>
85std::function<int(GRBmodel* model, const char* attrname, double* valueP)>
86 GRBgetdblattr = nullptr;
87std::function<int(GRBmodel* model, const char* attrname, double newvalue)>
88 GRBsetdblattr = nullptr;
89std::function<int(GRBmodel* model, const char* attrname, int element,
90 double* valueP)>
92std::function<int(GRBmodel* model, const char* attrname, int element,
93 double newvalue)>
95std::function<int(GRBmodel* model, const char* attrname, int first, int len,
96 double* values)>
98std::function<int(GRBmodel* model, const char* attrname, int first, int len,
99 double* newvalues)>
101std::function<int(GRBmodel* model, const char* attrname, int len, int* ind,
102 double* newvalues)>
104std::function<int(GRBmodel* model, const char* attrname, char** valueP)>
105 GRBgetstrattr = nullptr;
106std::function<int(GRBmodel* model, const char* attrname, const char* newvalue)>
107 GRBsetstrattr = nullptr;
108std::function<int(GRBmodel* model, int(GUROBI_STDCALL* cb)(CB_ARGS),
109 void* usrdata)>
111std::function<int(void* cbdata, int where, int what, void* resultP)> GRBcbget =
112 nullptr;
113std::function<int(void* cbdata, const double* solution, double* objvalP)>
114 GRBcbsolution = nullptr;
115std::function<int(void* cbdata, int cutlen, const int* cutind,
116 const double* cutval, char cutsense, double cutrhs)>
117 GRBcbcut = nullptr;
118std::function<int(void* cbdata, int lazylen, const int* lazyind,
119 const double* lazyval, char lazysense, double lazyrhs)>
120 GRBcblazy = nullptr;
121std::function<int(GRBmodel* model, int* numnzP, int* vbeg, int* vind,
122 double* vval, int start, int len)>
123 GRBgetvars = nullptr;
124std::function<int(GRBmodel* model)> GRBoptimize = nullptr;
125std::function<int(GRBmodel* model)> GRBcomputeIIS = nullptr;
126std::function<int(GRBmodel* model, const char* filename)> GRBwrite = nullptr;
127std::function<int(GRBenv* env, GRBmodel** modelP, const char* Pname,
128 int numvars, double* obj, double* lb, double* ub, char* vtype,
129 char** varnames)>
130 GRBnewmodel = nullptr;
131std::function<int(GRBmodel* model, int numnz, int* vind, double* vval,
132 double obj, double lb, double ub, char vtype,
133 const char* varname)>
134 GRBaddvar = nullptr;
135std::function<int(GRBmodel* model, int numvars, int numnz, int* vbeg, int* vind,
136 double* vval, double* obj, double* lb, double* ub,
137 char* vtype, char** varnames)>
138 GRBaddvars = nullptr;
139std::function<int(GRBmodel* model, int numnz, int* cind, double* cval,
140 char sense, double rhs, const char* constrname)>
141 GRBaddconstr = nullptr;
142std::function<int(GRBmodel* model, int numconstrs, int numnz, int* cbeg,
143 int* cind, double* cval, char* sense, double* rhs,
144 char** constrnames)>
145 GRBaddconstrs = nullptr;
146std::function<int(GRBmodel* model, int numnz, int* cind, double* cval,
147 double lower, double upper, const char* constrname)>
149std::function<int(GRBmodel* model, int numsos, int nummembers, int* types,
150 int* beg, int* ind, double* weight)>
151 GRBaddsos = nullptr;
152std::function<int(GRBmodel* model, const char* name, int resvar, int nvars,
153 const int* vars, double constant)>
155std::function<int(GRBmodel* model, const char* name, int resvar, int nvars,
156 const int* vars, double constant)>
158std::function<int(GRBmodel* model, const char* name, int resvar, int argvar)>
160std::function<int(GRBmodel* model, const char* name, int resvar, int nvars,
161 const int* vars)>
163std::function<int(GRBmodel* model, const char* name, int resvar, int nvars,
164 const int* vars)>
166std::function<int(GRBmodel* model, const char* name, int binvar, int binval,
167 int nvars, const int* vars, const double* vals, char sense,
168 double rhs)>
170std::function<int(GRBmodel* model, int numlnz, int* lind, double* lval,
171 int numqnz, int* qrow, int* qcol, double* qval, char sense,
172 double rhs, const char* QCname)>
173 GRBaddqconstr = nullptr;
174std::function<int(GRBmodel* model, int numqnz, int* qrow, int* qcol,
175 double* qval)>
176 GRBaddqpterms = nullptr;
177std::function<int(GRBmodel* model, int len, int* ind)> GRBdelvars = nullptr;
178std::function<int(GRBmodel* model, int len, int* ind)> GRBdelconstrs = nullptr;
179std::function<int(GRBmodel* model, int len, int* ind)> GRBdelsos = nullptr;
180std::function<int(GRBmodel* model, int len, int* ind)> GRBdelgenconstrs =
181 nullptr;
182std::function<int(GRBmodel* model, int len, int* ind)> GRBdelqconstrs = nullptr;
183std::function<int(GRBmodel* model)> GRBdelq = nullptr;
184std::function<int(GRBmodel* model, int cnt, int* cind, int* vind, double* val)>
185 GRBchgcoeffs = nullptr;
186std::function<int(GRBmodel* model)> GRBupdatemodel = nullptr;
187std::function<int(GRBmodel* model)> GRBfreemodel = nullptr;
188std::function<void(GRBmodel* model)> GRBterminate = nullptr;
189std::function<int(GRBmodel* model, int index, int priority, double weight,
190 double abstol, double reltol, const char* name,
191 double constant, int lnz, int* lind, double* lval)>
193std::function<int(GRBenv* env, const char* paramname, int* valueP)>
194 GRBgetintparam = nullptr;
195std::function<int(GRBenv* env, const char* paramname, double* valueP)>
196 GRBgetdblparam = nullptr;
197std::function<int(GRBenv* env, const char* paramname, char* valueP)>
198 GRBgetstrparam = nullptr;
199std::function<int(GRBenv* env, const char* paramname, int* valueP, int* minP,
200 int* maxP, int* defP)>
202std::function<int(GRBenv* env, const char* paramname, double* valueP,
203 double* minP, double* maxP, double* defP)>
205std::function<int(GRBenv* env, const char* paramname, char* valueP, char* defP)>
207std::function<int(GRBenv* env, const char* paramname)> GRBgetparamtype =
208 nullptr;
209std::function<int(GRBenv* env, int i, char** paramnameP)> GRBgetparamname =
210 nullptr;
211std::function<int(GRBenv* env, const char* paramname, const char* value)>
212 GRBsetparam = nullptr;
213std::function<int(GRBenv* env, const char* paramname, int value)>
214 GRBsetintparam = nullptr;
215std::function<int(GRBenv* env, const char* paramname, double value)>
216 GRBsetdblparam = nullptr;
217std::function<int(GRBenv* env, const char* paramname, const char* value)>
218 GRBsetstrparam = nullptr;
219std::function<int(GRBenv* env)> GRBresetparams = nullptr;
220std::function<int(GRBenv* dest, GRBenv* src)> GRBcopyparams = nullptr;
221std::function<int(GRBenv* env)> GRBgetnumparams = nullptr;
222std::function<int(GRBenv** envP)> GRBemptyenv = nullptr;
223std::function<int(GRBenv** envP, const char* logfilename)> GRBloadenv = nullptr;
224std::function<int(GRBenv* env)> GRBstartenv = nullptr;
225std::function<GRBenv*(GRBmodel* model)> GRBgetenv = nullptr;
226std::function<GRBenv*(GRBmodel* model, int num)> GRBgetmultiobjenv = nullptr;
227std::function<GRBenv*(GRBmodel* model)> GRBdiscardmultiobjenvs = nullptr;
228std::function<void(GRBenv* env)> GRBfreeenv = nullptr;
229std::function<const char*(GRBenv* env)> GRBgeterrormsg = nullptr;
230std::function<void(int* majorP, int* minorP, int* technicalP)> GRBversion =
231 nullptr;
232std::function<char*(void)> GRBplatform = nullptr;
233
234void LoadGurobiFunctions(DynamicLibrary* gurobi_dynamic_library) {
235 // This was generated with the parse_header.py script.
236 // See the comment at the top of the script.
237
238 // This is the 'assign' section.
239 gurobi_dynamic_library->GetFunction(&GRBisattravailable,
240 "GRBisattravailable");
241 gurobi_dynamic_library->GetFunction(&GRBgetintattr, "GRBgetintattr");
242 gurobi_dynamic_library->GetFunction(&GRBsetintattr, "GRBsetintattr");
243 gurobi_dynamic_library->GetFunction(&GRBgetintattrelement,
244 "GRBgetintattrelement");
245 gurobi_dynamic_library->GetFunction(&GRBsetintattrelement,
246 "GRBsetintattrelement");
247 gurobi_dynamic_library->GetFunction(&GRBgetintattrarray,
248 "GRBgetintattrarray");
249 gurobi_dynamic_library->GetFunction(&GRBsetintattrarray,
250 "GRBsetintattrarray");
251 gurobi_dynamic_library->GetFunction(&GRBsetintattrlist, "GRBsetintattrlist");
252 gurobi_dynamic_library->GetFunction(&GRBgetcharattrelement,
253 "GRBgetcharattrelement");
254 gurobi_dynamic_library->GetFunction(&GRBsetcharattrelement,
255 "GRBsetcharattrelement");
256 gurobi_dynamic_library->GetFunction(&GRBgetcharattrarray,
257 "GRBgetcharattrarray");
258 gurobi_dynamic_library->GetFunction(&GRBsetcharattrarray,
259 "GRBsetcharattrarray");
260 gurobi_dynamic_library->GetFunction(&GRBsetcharattrlist,
261 "GRBsetcharattrlist");
262 gurobi_dynamic_library->GetFunction(&GRBgetdblattr, "GRBgetdblattr");
263 gurobi_dynamic_library->GetFunction(&GRBsetdblattr, "GRBsetdblattr");
264 gurobi_dynamic_library->GetFunction(&GRBgetdblattrelement,
265 "GRBgetdblattrelement");
266 gurobi_dynamic_library->GetFunction(&GRBsetdblattrelement,
267 "GRBsetdblattrelement");
268 gurobi_dynamic_library->GetFunction(&GRBgetdblattrarray,
269 "GRBgetdblattrarray");
270 gurobi_dynamic_library->GetFunction(&GRBsetdblattrarray,
271 "GRBsetdblattrarray");
272 gurobi_dynamic_library->GetFunction(&GRBsetdblattrlist, "GRBsetdblattrlist");
273 gurobi_dynamic_library->GetFunction(&GRBgetstrattr, "GRBgetstrattr");
274 gurobi_dynamic_library->GetFunction(&GRBsetstrattr, "GRBsetstrattr");
275 gurobi_dynamic_library->GetFunction(&GRBsetcallbackfunc,
276 "GRBsetcallbackfunc");
277 gurobi_dynamic_library->GetFunction(&GRBcbget, "GRBcbget");
278 gurobi_dynamic_library->GetFunction(&GRBcbsolution, "GRBcbsolution");
279 gurobi_dynamic_library->GetFunction(&GRBcbcut, "GRBcbcut");
280 gurobi_dynamic_library->GetFunction(&GRBcblazy, "GRBcblazy");
281 gurobi_dynamic_library->GetFunction(&GRBgetvars, "GRBgetvars");
282 gurobi_dynamic_library->GetFunction(&GRBoptimize, "GRBoptimize");
283 gurobi_dynamic_library->GetFunction(&GRBcomputeIIS, "GRBcomputeIIS");
284 gurobi_dynamic_library->GetFunction(&GRBwrite, "GRBwrite");
285 gurobi_dynamic_library->GetFunction(&GRBnewmodel, "GRBnewmodel");
286 gurobi_dynamic_library->GetFunction(&GRBaddvar, "GRBaddvar");
287 gurobi_dynamic_library->GetFunction(&GRBaddvars, "GRBaddvars");
288 gurobi_dynamic_library->GetFunction(&GRBaddconstr, "GRBaddconstr");
289 gurobi_dynamic_library->GetFunction(&GRBaddconstrs, "GRBaddconstrs");
290 gurobi_dynamic_library->GetFunction(&GRBaddrangeconstr, "GRBaddrangeconstr");
291 gurobi_dynamic_library->GetFunction(&GRBaddsos, "GRBaddsos");
292 gurobi_dynamic_library->GetFunction(&GRBaddgenconstrMax,
293 "GRBaddgenconstrMax");
294 gurobi_dynamic_library->GetFunction(&GRBaddgenconstrMin,
295 "GRBaddgenconstrMin");
296 gurobi_dynamic_library->GetFunction(&GRBaddgenconstrAbs,
297 "GRBaddgenconstrAbs");
298 gurobi_dynamic_library->GetFunction(&GRBaddgenconstrAnd,
299 "GRBaddgenconstrAnd");
300 gurobi_dynamic_library->GetFunction(&GRBaddgenconstrOr, "GRBaddgenconstrOr");
301 gurobi_dynamic_library->GetFunction(&GRBaddgenconstrIndicator,
302 "GRBaddgenconstrIndicator");
303 gurobi_dynamic_library->GetFunction(&GRBaddqconstr, "GRBaddqconstr");
304 gurobi_dynamic_library->GetFunction(&GRBaddqpterms, "GRBaddqpterms");
305 gurobi_dynamic_library->GetFunction(&GRBdelvars, "GRBdelvars");
306 gurobi_dynamic_library->GetFunction(&GRBdelconstrs, "GRBdelconstrs");
307 gurobi_dynamic_library->GetFunction(&GRBdelsos, "GRBdelsos");
308 gurobi_dynamic_library->GetFunction(&GRBdelgenconstrs, "GRBdelgenconstrs");
309 gurobi_dynamic_library->GetFunction(&GRBdelqconstrs, "GRBdelqconstrs");
310 gurobi_dynamic_library->GetFunction(&GRBdelq, "GRBdelq");
311 gurobi_dynamic_library->GetFunction(&GRBchgcoeffs, "GRBchgcoeffs");
312 gurobi_dynamic_library->GetFunction(&GRBupdatemodel, "GRBupdatemodel");
313 gurobi_dynamic_library->GetFunction(&GRBfreemodel, "GRBfreemodel");
314 gurobi_dynamic_library->GetFunction(&GRBterminate, "GRBterminate");
315 gurobi_dynamic_library->GetFunction(&GRBsetobjectiven, "GRBsetobjectiven");
316 gurobi_dynamic_library->GetFunction(&GRBgetintparam, "GRBgetintparam");
317 gurobi_dynamic_library->GetFunction(&GRBgetdblparam, "GRBgetdblparam");
318 gurobi_dynamic_library->GetFunction(&GRBgetstrparam, "GRBgetstrparam");
319 gurobi_dynamic_library->GetFunction(&GRBsetparam, "GRBsetparam");
320 gurobi_dynamic_library->GetFunction(&GRBsetintparam, "GRBsetintparam");
321 gurobi_dynamic_library->GetFunction(&GRBsetdblparam, "GRBsetdblparam");
322 gurobi_dynamic_library->GetFunction(&GRBsetstrparam, "GRBsetstrparam");
323 gurobi_dynamic_library->GetFunction(&GRBresetparams, "GRBresetparams");
324 gurobi_dynamic_library->GetFunction(&GRBcopyparams, "GRBcopyparams");
325 gurobi_dynamic_library->GetFunction(&GRBloadenv, "GRBloadenv");
326 gurobi_dynamic_library->GetFunction(&GRBstartenv, "GRBstartenv");
327 gurobi_dynamic_library->GetFunction(&GRBemptyenv, "GRBemptyenv");
328 gurobi_dynamic_library->GetFunction(&GRBgetnumparams, "GRBgetnumparams");
329 gurobi_dynamic_library->GetFunction(&GRBgetparamname, "GRBgetparamname");
330 gurobi_dynamic_library->GetFunction(&GRBgetparamtype, "GRBgetparamtype");
331 gurobi_dynamic_library->GetFunction(&GRBgetintparaminfo,
332 "GRBgetintparaminfo");
333 gurobi_dynamic_library->GetFunction(&GRBgetdblparaminfo,
334 "GRBgetdblparaminfo");
335 gurobi_dynamic_library->GetFunction(&GRBgetstrparaminfo,
336 "GRBgetstrparaminfo");
337 gurobi_dynamic_library->GetFunction(&GRBgetenv, "GRBgetenv");
338 gurobi_dynamic_library->GetFunction(&GRBgetmultiobjenv, "GRBgetmultiobjenv");
339 gurobi_dynamic_library->GetFunction(&GRBdiscardmultiobjenvs,
340 "GRBdiscardmultiobjenvs");
341 gurobi_dynamic_library->GetFunction(&GRBfreeenv, "GRBfreeenv");
342 gurobi_dynamic_library->GetFunction(&GRBgeterrormsg, "GRBgeterrormsg");
343 gurobi_dynamic_library->GetFunction(&GRBversion, "GRBversion");
344 gurobi_dynamic_library->GetFunction(&GRBplatform, "GRBplatform");
345}
346
347std::vector<std::string> GurobiDynamicLibraryPotentialPaths() {
348 std::vector<std::string> potential_paths;
349 const std::vector<absl::string_view> kGurobiVersions = {
350 "1202", "1201", "1200", "1103", "1102", "1101", "1100",
351 "1003", "1002", "1001", "1000", "952", "951", "950",
352 "911", "910", "903", "902", "811", "801", "752"};
353 potential_paths.reserve(kGurobiVersions.size() * 3);
354
355 // Look for libraries pointed by GUROBI_HOME first.
356 const char* gurobi_home_from_env = getenv("GUROBI_HOME");
357 if (gurobi_home_from_env != nullptr) {
358 for (const absl::string_view version : kGurobiVersions) {
359 const absl::string_view lib = version.substr(0, version.size() - 1);
360#if defined(_MSC_VER) // Windows
361 potential_paths.push_back(
362 absl::StrCat(gurobi_home_from_env, "\\bin\\gurobi", lib, ".dll"));
363#elif defined(__APPLE__) // OS X
364 potential_paths.push_back(
365 absl::StrCat(gurobi_home_from_env, "/lib/libgurobi", lib, ".dylib"));
366#elif defined(__GNUC__) // Linux
367 potential_paths.push_back(
368 absl::StrCat(gurobi_home_from_env, "/lib/libgurobi", lib, ".so"));
369 potential_paths.push_back(
370 absl::StrCat(gurobi_home_from_env, "/lib64/libgurobi", lib, ".so"));
371#else
372 LOG(ERROR) << "OS Not recognized by gurobi/environment.cc."
373 << " You won't be able to use Gurobi.";
374#endif
375 }
376 }
377
378 // Search for canonical places.
379 for (const absl::string_view version : kGurobiVersions) {
380 const absl::string_view lib = version.substr(0, version.size() - 1);
381#if defined(_MSC_VER) // Windows
382 potential_paths.push_back(absl::StrCat("C:\\Program Files\\gurobi", version,
383 "\\win64\\bin\\gurobi", lib,
384 ".dll"));
385 potential_paths.push_back(absl::StrCat(
386 "C:\\gurobi", version, "\\win64\\bin\\gurobi", lib, ".dll"));
387 potential_paths.push_back(absl::StrCat("gurobi", lib, ".dll"));
388#elif defined(__APPLE__) // OS X
389 potential_paths.push_back(absl::StrCat(
390 "/Library/gurobi", version, "/mac64/lib/libgurobi", lib, ".dylib"));
391 potential_paths.push_back(absl::StrCat("/Library/gurobi", version,
392 "/macos_universal2/lib/libgurobi",
393 lib, ".dylib"));
394#elif defined(__GNUC__) // Linux
395 potential_paths.push_back(absl::StrCat(
396 "/opt/gurobi", version, "/linux64/lib/libgurobi", lib, ".so"));
397 potential_paths.push_back(absl::StrCat(
398 "/opt/gurobi", version, "/linux64/lib64/libgurobi", lib, ".so"));
399 potential_paths.push_back(
400 absl::StrCat("/opt/gurobi/linux64/lib/libgurobi", lib, ".so"));
401 potential_paths.push_back(
402 absl::StrCat("/opt/gurobi/linux64/lib64/libgurobi", lib, ".so"));
403#else
404 LOG(ERROR) << "OS Not recognized by gurobi/environment.cc."
405 << " You won't be able to use Gurobi.";
406#endif
407 }
408
409#if defined(__GNUC__) // path in linux64 gurobi/optimizer docker image.
410 for (const absl::string_view version :
411 {"12.0.2", "12.0.1", "12.0.0", "11.0.3", "11.0.2", "11.0.1", "11.0.0",
412 "10.0.3", "10.0.2", "10.0.1", "10.0.0", "9.5.2", "9.5.1", "9.5.0"}) {
413 potential_paths.push_back(
414 absl::StrCat("/opt/gurobi/linux64/lib/libgurobi.so.", version));
415 }
416#endif
417 return potential_paths;
418}
419
421 std::vector<absl::string_view> potential_paths) {
422 static std::once_flag gurobi_loading_done;
423 static absl::Status gurobi_load_status;
424 static DynamicLibrary gurobi_library;
425 static absl::Mutex mutex;
426
427 absl::MutexLock lock(&mutex);
428
429 std::call_once(gurobi_loading_done, [&potential_paths]() {
430 const std::vector<std::string> canonical_paths =
432 potential_paths.insert(potential_paths.end(), canonical_paths.begin(),
433 canonical_paths.end());
434 for (const absl::string_view path : potential_paths) {
435 if (gurobi_library.TryToLoad(path)) {
436 LOG(INFO) << "Found the Gurobi library in '" << path << ".";
437 break;
438 }
439 }
440
441 if (gurobi_library.LibraryIsLoaded()) {
442 LoadGurobiFunctions(&gurobi_library);
443 gurobi_load_status = absl::OkStatus();
444 } else {
445 gurobi_load_status = absl::NotFoundError(absl::StrCat(
446 "Could not find the Gurobi shared library. Looked in: [",
447 absl::StrJoin(potential_paths, "', '"),
448 "]. If you know where it"
449 " is, pass the full path to 'LoadGurobiDynamicLibrary()'."));
450 }
451 });
452 return gurobi_load_status;
453}
454
455absl::StatusOr<GRBenv*> GetGurobiEnv() {
457
458 GRBenv* env = nullptr;
459
460 if (GRBloadenv(&env, nullptr) != 0 || env == nullptr) {
461 return absl::FailedPreconditionError(
462 absl::StrCat("Found the Gurobi shared library, but could not create "
463 "Gurobi environment: is Gurobi licensed on this machine?",
464 GRBgeterrormsg(env)));
465 }
466 return env;
467}
468
469} // namespace operations_research
#define RETURN_IF_ERROR(expr)
bool LibraryIsLoaded() const
std::function< T > GetFunction(const char *function_name)
bool TryToLoad(const absl::string_view library_name)
#define GUROBI_STDCALL
Definition environment.h:28
struct _GRBenv GRBenv
Definition environment.h:33
struct _GRBmodel GRBmodel
Definition environment.h:32
#define CB_ARGS
In SWIG mode, we don't want anything besides these top-level includes.
std::function< int(GRBmodel *model, int numnz, int *cind, double *cval, char sense, double rhs, const char *constrname)> GRBaddconstr
std::function< void(GRBenv *env)> GRBfreeenv
std::function< int(GRBmodel *model, const char *attrname, double *valueP)> GRBgetdblattr
std::function< int(GRBmodel *model, const char *attrname, int first, int len, double *values)> GRBgetdblattrarray
std::function< int(GRBmodel *model, const char *attrname, int first, int len, int *values)> GRBgetintattrarray
std::function< int(GRBmodel *model, const char *attrname, double newvalue)> GRBsetdblattr
std::function< int(GRBmodel *model, int len, int *ind)> GRBdelsos
std::function< int(GRBmodel *model, int numvars, int numnz, int *vbeg, int *vind, double *vval, double *obj, double *lb, double *ub, char *vtype, char **varnames)> GRBaddvars
std::function< int(GRBmodel *model, int(GUROBI_STDCALL *cb)(CB_ARGS), void *usrdata)> GRBsetcallbackfunc
std::function< int(GRBenv *dest, GRBenv *src)> GRBcopyparams
std::function< int(GRBmodel *model, int *numnzP, int *vbeg, int *vind, double *vval, int start, int len)> GRBgetvars
std::function< int(GRBmodel *model, const char *attrname, int len, int *ind, int *newvalues)> GRBsetintattrlist
std::function< int(GRBmodel *model, int cnt, int *cind, int *vind, double *val)> GRBchgcoeffs
std::function< int(GRBmodel *model, const char *attrname, int first, int len, char *values)> GRBgetcharattrarray
std::function< int(void *cbdata, int cutlen, const int *cutind, const double *cutval, char cutsense, double cutrhs)> GRBcbcut
std::function< int(GRBenv *env, const char *paramname, double *valueP)> GRBgetdblparam
std::function< int(GRBmodel *model, int numlnz, int *lind, double *lval, int numqnz, int *qrow, int *qcol, double *qval, char sense, double rhs, const char *QCname)> GRBaddqconstr
std::function< int(GRBmodel *model, int len, int *ind)> GRBdelvars
std::function< int(GRBmodel *model, const char *attrname, int newvalue)> GRBsetintattr
std::function< int(GRBenv *env, const char *paramname, const char *value)> GRBsetparam
std::function< int(GRBmodel *model, const char *attrname, int element, int *valueP)> GRBgetintattrelement
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
std::function< int(GRBenv *env, GRBmodel **modelP, const char *Pname, int numvars, double *obj, double *lb, double *ub, char *vtype, char **varnames)> GRBnewmodel
std::function< int(GRBmodel *model, int numnz, int *vind, double *vval, double obj, double lb, double ub, char vtype, const char *varname)> GRBaddvar
std::function< int(GRBmodel *model, const char *attrname, int first, int len, int *newvalues)> GRBsetintattrarray
std::function< int(GRBmodel *model)> GRBupdatemodel
std::function< void(int *majorP, int *minorP, int *technicalP)> GRBversion
std::function< GRBenv *(GRBmodel *model)> GRBgetenv
std::function< int(GRBmodel *model, const char *attrname, int len, int *ind, char *newvalues)> GRBsetcharattrlist
bool GurobiIsCorrectlyInstalled()
std::function< int(GRBenv *env, const char *paramname, char *valueP)> GRBgetstrparam
std::function< int(GRBmodel *model, const char *attrname, int element, double *valueP)> GRBgetdblattrelement
std::function< int(GRBmodel *model, const char *attrname, int first, int len, char *newvalues)> GRBsetcharattrarray
std::function< int(GRBmodel *model)> GRBfreemodel
std::function< int(GRBmodel *model, int len, int *ind)> GRBdelqconstrs
std::function< int(void *cbdata, int lazylen, const int *lazyind, const double *lazyval, char lazysense, double lazyrhs)> GRBcblazy
std::function< int(GRBmodel *model)> GRBcomputeIIS
void LoadGurobiFunctions(DynamicLibrary *gurobi_dynamic_library)
std::function< int(void *cbdata, int where, int what, void *resultP)> GRBcbget
std::function< int(GRBenv *env, const char *paramname, int value)> GRBsetintparam
std::function< int(GRBmodel *model, const char *attrname)> GRBisattravailable
This is the 'define' section.
std::function< int(GRBenv *env, const char *paramname, const char *value)> GRBsetstrparam
std::function< int(GRBenv *env, const char *paramname, char *valueP, char *defP)> GRBgetstrparaminfo
std::function< int(GRBmodel *model, const char *attrname, int first, int len, double *newvalues)> GRBsetdblattrarray
std::function< int(GRBmodel *model, const char *name, int resvar, int nvars, const int *vars, double constant)> GRBaddgenconstrMin
std::function< int(GRBmodel *model, int numnz, int *cind, double *cval, double lower, double upper, const char *constrname)> GRBaddrangeconstr
std::function< int(GRBmodel *model, const char *name, int binvar, int binval, int nvars, const int *vars, const double *vals, char sense, double rhs)> GRBaddgenconstrIndicator
std::function< int(GRBmodel *model, const char *attrname, int element, char newvalue)> GRBsetcharattrelement
std::function< int(GRBmodel *model, const char *attrname, int element, int newvalue)> GRBsetintattrelement
std::function< int(GRBenv *env)> GRBresetparams
std::function< int(GRBmodel *model, const char *attrname, const char *newvalue)> GRBsetstrattr
absl::Status LoadGurobiDynamicLibrary(std::vector< absl::string_view > potential_paths)
std::function< GRBenv *(GRBmodel *model)> GRBdiscardmultiobjenvs
std::function< int(GRBmodel *model)> GRBoptimize
std::function< int(GRBenv **envP, const char *logfilename)> GRBloadenv
std::function< int(GRBmodel *model, int numqnz, int *qrow, int *qcol, double *qval)> GRBaddqpterms
std::function< GRBenv *(GRBmodel *model, int num)> GRBgetmultiobjenv
std::function< int(GRBenv **envP)> GRBemptyenv
std::function< int(GRBenv *env, const char *paramname)> GRBgetparamtype
std::function< int(GRBmodel *model, int len, int *ind)> GRBdelconstrs
std::function< int(GRBmodel *model, const char *name, int resvar, int argvar)> GRBaddgenconstrAbs
std::vector< std::string > GurobiDynamicLibraryPotentialPaths()
std::function< int(GRBenv *env, int i, char **paramnameP)> GRBgetparamname
std::function< int(GRBmodel *model, const char *attrname, int *valueP)> GRBgetintattr
std::function< int(GRBmodel *model, int len, int *ind)> GRBdelgenconstrs
std::function< int(GRBmodel *model, int index, int priority, double weight, double abstol, double reltol, const char *name, double constant, int lnz, int *lind, double *lval)> GRBsetobjectiven
std::function< const char *(GRBenv *env)> GRBgeterrormsg
absl::StatusOr< GRBenv * > GetGurobiEnv()
std::function< int(GRBmodel *model, const char *filename)> GRBwrite
std::function< int(GRBenv *env, const char *paramname, double *valueP, double *minP, double *maxP, double *defP)> GRBgetdblparaminfo
std::function< int(GRBenv *env, const char *paramname, int *valueP)> GRBgetintparam
std::function< int(GRBmodel *model, const char *name, int resvar, int nvars, const int *vars)> GRBaddgenconstrAnd
std::function< int(GRBenv *env)> GRBstartenv
std::function< int(GRBmodel *model, const char *name, int resvar, int nvars, const int *vars)> GRBaddgenconstrOr
std::function< int(GRBmodel *model, int numconstrs, int numnz, int *cbeg, int *cind, double *cval, char *sense, double *rhs, char **constrnames)> GRBaddconstrs
std::function< int(GRBmodel *model, const char *attrname, int len, int *ind, double *newvalues)> GRBsetdblattrlist
std::function< int(GRBmodel *model, const char *name, int resvar, int nvars, const int *vars, double constant)> GRBaddgenconstrMax
std::function< char *(void)> GRBplatform
std::function< int(GRBenv *env, const char *paramname, int *valueP, int *minP, int *maxP, int *defP)> GRBgetintparaminfo
std::function< int(GRBmodel *model, int numsos, int nummembers, int *types, int *beg, int *ind, double *weight)> GRBaddsos
std::function< int(GRBenv *env)> GRBgetnumparams
std::function< int(GRBmodel *model, const char *attrname, int element, char *valueP)> GRBgetcharattrelement
std::function< int(GRBmodel *model, const char *attrname, char **valueP)> GRBgetstrattr
std::function< int(GRBmodel *model)> GRBdelq
std::function< int(void *cbdata, const double *solution, double *objvalP)> GRBcbsolution
std::function< void(GRBmodel *model)> GRBterminate
std::function< int(GRBenv *env, const char *paramname, double value)> GRBsetdblparam
std::function< int(GRBmodel *model, const char *attrname, int element, double newvalue)> GRBsetdblattrelement