reorganize gurobi and xpress side loading

This commit is contained in:
Laurent Perron
2025-06-18 18:22:06 +02:00
parent c4b01c1294
commit b61ec9860c
9 changed files with 2643 additions and 1 deletions

View File

@@ -533,13 +533,13 @@ foreach(SUBPROJECT IN ITEMS
${GUROBI_DIR}
${PDLP_DIR}
sat
xpress
lp_data
packing
routing
scheduling
set_cover
port
third_party_solvers
util)
add_subdirectory(ortools/${SUBPROJECT})
#target_link_libraries(${PROJECT_NAME} PRIVATE ${PROJECT_NAME}_${SUBPROJECT})

View File

@@ -0,0 +1,88 @@
# Copyright 2010-2025 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
package(default_visibility = ["//visibility:public"])
config_setting(
name = "on_linux",
constraint_values = ["@platforms//os:linux"],
)
config_setting(
name = "on_macos",
constraint_values = ["@platforms//os:macos"],
)
config_setting(
name = "on_windows",
constraint_values = ["@platforms//os:windows"],
)
cc_library(
name = "dynamic_library",
hdrs = ["dynamic_library.h"],
linkopts = select({
"on_linux": ["-Wl,--no-as-needed -ldl"],
"on_macos": [],
"on_windows": [],
"//conditions:default": [],
}),
deps = [
"//ortools/base",
"//ortools/base:logging",
"@abseil-cpp//absl/strings",
],
)
cc_library(
name = "gurobi_environment",
srcs = [
"gurobi_environment.cc",
],
hdrs = [
"gurobi_environment.h",
],
deps = [
":dynamic_library",
"//ortools/base",
"//ortools/base:file",
"//ortools/base:status_macros",
"@abseil-cpp//absl/status",
"@abseil-cpp//absl/status:statusor",
"@abseil-cpp//absl/strings",
"@abseil-cpp//absl/synchronization",
"@abseil-cpp//absl/types:optional",
],
)
cc_library(
name = "xpress_environment",
srcs = [
"xpress_environment.cc",
],
hdrs = [
"xpress_environment.h",
],
deps = [
":dynamic_library",
"//ortools/base",
"//ortools/base:file",
"//ortools/base:status_macros",
"@abseil-cpp//absl/flags:flag",
"@abseil-cpp//absl/status",
"@abseil-cpp//absl/status:statusor",
"@abseil-cpp//absl/strings",
"@abseil-cpp//absl/synchronization",
"@abseil-cpp//absl/types:optional",
],
)

View File

@@ -0,0 +1,36 @@
# Copyright 2010-2025 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
file(GLOB _SRCS "*.h" "*.cc")
set(NAME ${PROJECT_NAME}_third_party_solvers)
add_library(${NAME} OBJECT ${_SRCS})
set_target_properties(${NAME} PROPERTIES
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS OFF
POSITION_INDEPENDENT_CODE ON
)
if(MSVC AND BUILD_SHARED_LIBS)
target_compile_definitions(${NAME} PUBLIC "OR_BUILD_DLL")
target_compile_definitions(${NAME} PRIVATE "OR_EXPORT")
endif()
target_include_directories(${NAME} PRIVATE
${PROJECT_SOURCE_DIR}
${PROJECT_BINARY_DIR})
target_link_libraries(${NAME} PRIVATE
absl::status
absl::strings
absl::str_format
absl::synchronization
)

View File

@@ -0,0 +1,120 @@
// Copyright 2010-2025 Google LLC
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef OR_TOOLS_BASE_DYNAMIC_LIBRARY_H_
#define OR_TOOLS_BASE_DYNAMIC_LIBRARY_H_
#include <functional>
#include <string>
#include "absl/strings/string_view.h"
#include "ortools/base/logging.h"
#if defined(_MSC_VER)
#define WIN32_LEAN_AND_MEAN // disables several conflicting macros
#include <windows.h>
#elif defined(__MINGW32__) || defined(__MINGW64__)
#include <windows.h>
#elif defined(__GNUC__)
#include <dlfcn.h>
#endif
class DynamicLibrary {
public:
DynamicLibrary() : library_handle_(nullptr) {}
~DynamicLibrary() {
if (library_handle_ == nullptr) {
return;
}
#if defined(_MSC_VER) || defined(__MINGW32__) || defined(__MINGW64__)
FreeLibrary(static_cast<HINSTANCE>(library_handle_));
#elif defined(__GNUC__)
dlclose(library_handle_);
#endif
}
bool TryToLoad(const absl::string_view library_name) {
library_name_ = library_name;
#if defined(_MSC_VER) || defined(__MINGW32__) || defined(__MINGW64__)
library_handle_ = static_cast<void*>(LoadLibraryA(library_name_.c_str()));
#elif defined(__GNUC__)
library_handle_ = dlopen(library_name_.c_str(), RTLD_NOW);
#endif
return library_handle_ != nullptr;
}
bool LibraryIsLoaded() const { return library_handle_ != nullptr; }
template <typename T>
std::function<T> GetFunction(const char* function_name) {
#if defined(_MSC_VER) || defined(__MINGW32__) || defined(__MINGW64__)
// On Windows, avoid casting to void*: not supported by MinGW.
FARPROC function_address =
GetProcAddress(static_cast<HINSTANCE>(library_handle_), function_name);
#else // Not Windows.
const void* function_address = dlsym(library_handle_, function_name);
#endif // MinGW.
CHECK(function_address)
<< "Error: could not find function " << std::string(function_name)
<< " in " << library_name_;
return TypeParser<T>::CreateFunction(function_address);
}
template <typename T>
std::function<T> GetFunction(const std::string& function_name) {
return GetFunction<T>(function_name.c_str());
}
template <typename T>
void GetFunction(std::function<T>* function, const char* function_name) {
*function = GetFunction<T>(function_name);
}
template <typename T>
void GetFunction(std::function<T>* function,
const std::string function_name) {
GetFunction<T>(function, function_name.c_str());
}
private:
void* library_handle_ = nullptr;
std::string library_name_;
template <typename T>
struct TypeParser {};
template <typename Ret, typename... Args>
struct TypeParser<Ret(Args...)> {
#if defined(_MSC_VER) || defined(__MINGW32__) || defined(__MINGW64__)
// Windows: take a FARPROC as argument.
static std::function<Ret(Args...)> CreateFunction(
const FARPROC function_address) {
return std::function<Ret(Args...)>(
reinterpret_cast<Ret (*)(Args...)>(function_address));
}
#else
// Not Windows: take a void* as argument.
static std::function<Ret(Args...)> CreateFunction(
const void* function_address) {
return std::function<Ret(Args...)>(reinterpret_cast<Ret (*)(Args...)>(
const_cast<void*>(function_address)));
}
#endif
};
};
#endif // OR_TOOLS_BASE_DYNAMIC_LIBRARY_H_

View File

@@ -0,0 +1,443 @@
// Copyright 2010-2025 Google LLC
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "ortools/third_party_solvers/gurobi_environment.h"
#include <functional>
#include <mutex>
#include <string>
#include <vector>
#include "absl/status/status.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_join.h"
#include "absl/strings/string_view.h"
#include "absl/synchronization/mutex.h"
#include "ortools/base/logging.h"
#include "ortools/third_party_solvers/dynamic_library.h"
namespace operations_research {
// This was generated with the parse_header.py script.
// See the comment at the top of the script.
// Let's not reformat the rest of the file.
// clang-format off
// This is the 'define' section.
std::function<int(GRBmodel* model, const char* attrname)> GRBisattravailable =
nullptr;
std::function<int(GRBmodel* model, const char* attrname, int* valueP)>
GRBgetintattr = nullptr;
std::function<int(GRBmodel* model, const char* attrname, int newvalue)>
GRBsetintattr = nullptr;
std::function<int(GRBmodel* model, const char* attrname, int element,
int* valueP)>
GRBgetintattrelement = nullptr;
std::function<int(GRBmodel* model, const char* attrname, int element,
int newvalue)>
GRBsetintattrelement = nullptr;
std::function<int(GRBmodel* model, const char* attrname, int first, int len,
int* values)>
GRBgetintattrarray = nullptr;
std::function<int(GRBmodel* model, const char* attrname, int first, int len,
int* newvalues)>
GRBsetintattrarray = nullptr;
std::function<int(GRBmodel* model, const char* attrname, int len, int* ind,
int* newvalues)>
GRBsetintattrlist = nullptr;
std::function<int(GRBmodel* model, const char* attrname, int element,
char* valueP)>
GRBgetcharattrelement = nullptr;
std::function<int(GRBmodel* model, const char* attrname, int element,
char newvalue)>
GRBsetcharattrelement = nullptr;
std::function<int(GRBmodel* model, const char* attrname, int first, int len,
char* values)>
GRBgetcharattrarray = nullptr;
std::function<int(GRBmodel* model, const char* attrname, int first, int len,
char* newvalues)>
GRBsetcharattrarray = nullptr;
std::function<int(GRBmodel* model, const char* attrname, int len, int* ind,
char* newvalues)>
GRBsetcharattrlist = nullptr;
std::function<int(GRBmodel* model, const char* attrname, double* valueP)>
GRBgetdblattr = nullptr;
std::function<int(GRBmodel* model, const char* attrname, double newvalue)>
GRBsetdblattr = nullptr;
std::function<int(GRBmodel* model, const char* attrname, int element,
double* valueP)>
GRBgetdblattrelement = nullptr;
std::function<int(GRBmodel* model, const char* attrname, int element,
double newvalue)>
GRBsetdblattrelement = nullptr;
std::function<int(GRBmodel* model, const char* attrname, int first, int len,
double* values)>
GRBgetdblattrarray = nullptr;
std::function<int(GRBmodel* model, const char* attrname, int first, int len,
double* newvalues)>
GRBsetdblattrarray = nullptr;
std::function<int(GRBmodel* model, const char* attrname, int len, int* ind,
double* newvalues)>
GRBsetdblattrlist = nullptr;
std::function<int(GRBmodel* model, const char* attrname, char** valueP)>
GRBgetstrattr = nullptr;
std::function<int(GRBmodel* model, const char* attrname, const char* newvalue)>
GRBsetstrattr = nullptr;
std::function<int(GRBmodel* model, int(GUROBI_STDCALL* cb)(CB_ARGS),
void* usrdata)>
GRBsetcallbackfunc = nullptr;
std::function<int(void* cbdata, int where, int what, void* resultP)> GRBcbget =
nullptr;
std::function<int(void* cbdata, const double* solution, double* objvalP)>
GRBcbsolution = nullptr;
std::function<int(void* cbdata, int cutlen, const int* cutind,
const double* cutval, char cutsense, double cutrhs)>
GRBcbcut = nullptr;
std::function<int(void* cbdata, int lazylen, const int* lazyind,
const double* lazyval, char lazysense, double lazyrhs)>
GRBcblazy = nullptr;
std::function<int(GRBmodel* model, int* numnzP, int* vbeg, int* vind,
double* vval, int start, int len)>
GRBgetvars = nullptr;
std::function<int(GRBmodel* model)> GRBoptimize = nullptr;
std::function<int(GRBmodel* model)> GRBcomputeIIS = nullptr;
std::function<int(GRBmodel* model, const char* filename)> GRBwrite = nullptr;
std::function<int(GRBenv* env, GRBmodel** modelP, const char* Pname,
int numvars, double* obj, double* lb, double* ub, char* vtype,
char** varnames)>
GRBnewmodel = nullptr;
std::function<int(GRBmodel* model, int numnz, int* vind, double* vval,
double obj, double lb, double ub, char vtype,
const char* varname)>
GRBaddvar = nullptr;
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 = nullptr;
std::function<int(GRBmodel* model, int numnz, int* cind, double* cval,
char sense, double rhs, const char* constrname)>
GRBaddconstr = nullptr;
std::function<int(GRBmodel* model, int numconstrs, int numnz, int* cbeg,
int* cind, double* cval, char* sense, double* rhs,
char** constrnames)>
GRBaddconstrs = nullptr;
std::function<int(GRBmodel* model, int numnz, int* cind, double* cval,
double lower, double upper, const char* constrname)>
GRBaddrangeconstr = nullptr;
std::function<int(GRBmodel* model, int numsos, int nummembers, int* types,
int* beg, int* ind, double* weight)>
GRBaddsos = nullptr;
std::function<int(GRBmodel* model, const char* name, int resvar, int nvars,
const int* vars, double constant)>
GRBaddgenconstrMax = nullptr;
std::function<int(GRBmodel* model, const char* name, int resvar, int nvars,
const int* vars, double constant)>
GRBaddgenconstrMin = nullptr;
std::function<int(GRBmodel* model, const char* name, int resvar, int argvar)>
GRBaddgenconstrAbs = nullptr;
std::function<int(GRBmodel* model, const char* name, int resvar, int nvars,
const int* vars)>
GRBaddgenconstrAnd = nullptr;
std::function<int(GRBmodel* model, const char* name, int resvar, int nvars,
const int* vars)>
GRBaddgenconstrOr = nullptr;
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 = nullptr;
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 = nullptr;
std::function<int(GRBmodel* model, int numqnz, int* qrow, int* qcol,
double* qval)>
GRBaddqpterms = nullptr;
std::function<int(GRBmodel* model, int len, int* ind)> GRBdelvars = nullptr;
std::function<int(GRBmodel* model, int len, int* ind)> GRBdelconstrs = nullptr;
std::function<int(GRBmodel* model, int len, int* ind)> GRBdelsos = nullptr;
std::function<int(GRBmodel* model, int len, int* ind)> GRBdelgenconstrs =
nullptr;
std::function<int(GRBmodel* model, int len, int* ind)> GRBdelqconstrs = nullptr;
std::function<int(GRBmodel* model)> GRBdelq = nullptr;
std::function<int(GRBmodel* model, int cnt, int* cind, int* vind, double* val)>
GRBchgcoeffs = nullptr;
std::function<int(GRBmodel* model)> GRBupdatemodel = nullptr;
std::function<int(GRBmodel* model)> GRBfreemodel = nullptr;
std::function<void(GRBmodel* model)> GRBterminate = nullptr;
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 = nullptr;
std::function<int(GRBenv* env, const char* paramname, int* valueP)>
GRBgetintparam = nullptr;
std::function<int(GRBenv* env, const char* paramname, double* valueP)>
GRBgetdblparam = nullptr;
std::function<int(GRBenv* env, const char* paramname, char* valueP)>
GRBgetstrparam = nullptr;
std::function<int(GRBenv* env, const char* paramname, int* valueP, int* minP,
int* maxP, int* defP)>
GRBgetintparaminfo = nullptr;
std::function<int(GRBenv* env, const char* paramname, double* valueP,
double* minP, double* maxP, double* defP)>
GRBgetdblparaminfo = nullptr;
std::function<int(GRBenv* env, const char* paramname, char* valueP, char* defP)>
GRBgetstrparaminfo = nullptr;
std::function<int(GRBenv* env, const char* paramname)> GRBgetparamtype =
nullptr;
std::function<int(GRBenv* env, int i, char** paramnameP)> GRBgetparamname =
nullptr;
std::function<int(GRBenv* env, const char* paramname, const char* value)>
GRBsetparam = nullptr;
std::function<int(GRBenv* env, const char* paramname, int value)>
GRBsetintparam = nullptr;
std::function<int(GRBenv* env, const char* paramname, double value)>
GRBsetdblparam = nullptr;
std::function<int(GRBenv* env, const char* paramname, const char* value)>
GRBsetstrparam = nullptr;
std::function<int(GRBenv* env)> GRBresetparams = nullptr;
std::function<int(GRBenv* dest, GRBenv* src)> GRBcopyparams = nullptr;
std::function<int(GRBenv* env)> GRBgetnumparams = nullptr;
std::function<int(GRBenv** envP)> GRBemptyenv = nullptr;
std::function<int(GRBenv** envP, const char* logfilename)> GRBloadenv = nullptr;
std::function<int(GRBenv* env)> GRBstartenv = nullptr;
std::function<GRBenv*(GRBmodel* model)> GRBgetenv = nullptr;
std::function<GRBenv*(GRBmodel* model, int num)> GRBgetmultiobjenv = nullptr;
std::function<GRBenv*(GRBmodel* model)> GRBdiscardmultiobjenvs = nullptr;
std::function<void(GRBenv* env)> GRBfreeenv = nullptr;
std::function<const char*(GRBenv* env)> GRBgeterrormsg = nullptr;
std::function<void(int* majorP, int* minorP, int* technicalP)> GRBversion =
nullptr;
std::function<char*(void)> GRBplatform = nullptr;
void LoadGurobiFunctions(DynamicLibrary* gurobi_dynamic_library) {
// This was generated with the parse_header.py script.
// See the comment at the top of the script.
// This is the 'assign' section.
gurobi_dynamic_library->GetFunction(&GRBisattravailable,
"GRBisattravailable");
gurobi_dynamic_library->GetFunction(&GRBgetintattr, "GRBgetintattr");
gurobi_dynamic_library->GetFunction(&GRBsetintattr, "GRBsetintattr");
gurobi_dynamic_library->GetFunction(&GRBgetintattrelement,
"GRBgetintattrelement");
gurobi_dynamic_library->GetFunction(&GRBsetintattrelement,
"GRBsetintattrelement");
gurobi_dynamic_library->GetFunction(&GRBgetintattrarray,
"GRBgetintattrarray");
gurobi_dynamic_library->GetFunction(&GRBsetintattrarray,
"GRBsetintattrarray");
gurobi_dynamic_library->GetFunction(&GRBsetintattrlist, "GRBsetintattrlist");
gurobi_dynamic_library->GetFunction(&GRBgetcharattrelement,
"GRBgetcharattrelement");
gurobi_dynamic_library->GetFunction(&GRBsetcharattrelement,
"GRBsetcharattrelement");
gurobi_dynamic_library->GetFunction(&GRBgetcharattrarray,
"GRBgetcharattrarray");
gurobi_dynamic_library->GetFunction(&GRBsetcharattrarray,
"GRBsetcharattrarray");
gurobi_dynamic_library->GetFunction(&GRBsetcharattrlist,
"GRBsetcharattrlist");
gurobi_dynamic_library->GetFunction(&GRBgetdblattr, "GRBgetdblattr");
gurobi_dynamic_library->GetFunction(&GRBsetdblattr, "GRBsetdblattr");
gurobi_dynamic_library->GetFunction(&GRBgetdblattrelement,
"GRBgetdblattrelement");
gurobi_dynamic_library->GetFunction(&GRBsetdblattrelement,
"GRBsetdblattrelement");
gurobi_dynamic_library->GetFunction(&GRBgetdblattrarray,
"GRBgetdblattrarray");
gurobi_dynamic_library->GetFunction(&GRBsetdblattrarray,
"GRBsetdblattrarray");
gurobi_dynamic_library->GetFunction(&GRBsetdblattrlist, "GRBsetdblattrlist");
gurobi_dynamic_library->GetFunction(&GRBgetstrattr, "GRBgetstrattr");
gurobi_dynamic_library->GetFunction(&GRBsetstrattr, "GRBsetstrattr");
gurobi_dynamic_library->GetFunction(&GRBsetcallbackfunc,
"GRBsetcallbackfunc");
gurobi_dynamic_library->GetFunction(&GRBcbget, "GRBcbget");
gurobi_dynamic_library->GetFunction(&GRBcbsolution, "GRBcbsolution");
gurobi_dynamic_library->GetFunction(&GRBcbcut, "GRBcbcut");
gurobi_dynamic_library->GetFunction(&GRBcblazy, "GRBcblazy");
gurobi_dynamic_library->GetFunction(&GRBgetvars, "GRBgetvars");
gurobi_dynamic_library->GetFunction(&GRBoptimize, "GRBoptimize");
gurobi_dynamic_library->GetFunction(&GRBcomputeIIS, "GRBcomputeIIS");
gurobi_dynamic_library->GetFunction(&GRBwrite, "GRBwrite");
gurobi_dynamic_library->GetFunction(&GRBnewmodel, "GRBnewmodel");
gurobi_dynamic_library->GetFunction(&GRBaddvar, "GRBaddvar");
gurobi_dynamic_library->GetFunction(&GRBaddvars, "GRBaddvars");
gurobi_dynamic_library->GetFunction(&GRBaddconstr, "GRBaddconstr");
gurobi_dynamic_library->GetFunction(&GRBaddconstrs, "GRBaddconstrs");
gurobi_dynamic_library->GetFunction(&GRBaddrangeconstr, "GRBaddrangeconstr");
gurobi_dynamic_library->GetFunction(&GRBaddsos, "GRBaddsos");
gurobi_dynamic_library->GetFunction(&GRBaddgenconstrMax,
"GRBaddgenconstrMax");
gurobi_dynamic_library->GetFunction(&GRBaddgenconstrMin,
"GRBaddgenconstrMin");
gurobi_dynamic_library->GetFunction(&GRBaddgenconstrAbs,
"GRBaddgenconstrAbs");
gurobi_dynamic_library->GetFunction(&GRBaddgenconstrAnd,
"GRBaddgenconstrAnd");
gurobi_dynamic_library->GetFunction(&GRBaddgenconstrOr, "GRBaddgenconstrOr");
gurobi_dynamic_library->GetFunction(&GRBaddgenconstrIndicator,
"GRBaddgenconstrIndicator");
gurobi_dynamic_library->GetFunction(&GRBaddqconstr, "GRBaddqconstr");
gurobi_dynamic_library->GetFunction(&GRBaddqpterms, "GRBaddqpterms");
gurobi_dynamic_library->GetFunction(&GRBdelvars, "GRBdelvars");
gurobi_dynamic_library->GetFunction(&GRBdelconstrs, "GRBdelconstrs");
gurobi_dynamic_library->GetFunction(&GRBdelsos, "GRBdelsos");
gurobi_dynamic_library->GetFunction(&GRBdelgenconstrs, "GRBdelgenconstrs");
gurobi_dynamic_library->GetFunction(&GRBdelqconstrs, "GRBdelqconstrs");
gurobi_dynamic_library->GetFunction(&GRBdelq, "GRBdelq");
gurobi_dynamic_library->GetFunction(&GRBchgcoeffs, "GRBchgcoeffs");
gurobi_dynamic_library->GetFunction(&GRBupdatemodel, "GRBupdatemodel");
gurobi_dynamic_library->GetFunction(&GRBfreemodel, "GRBfreemodel");
gurobi_dynamic_library->GetFunction(&GRBterminate, "GRBterminate");
gurobi_dynamic_library->GetFunction(&GRBsetobjectiven, "GRBsetobjectiven");
gurobi_dynamic_library->GetFunction(&GRBgetintparam, "GRBgetintparam");
gurobi_dynamic_library->GetFunction(&GRBgetdblparam, "GRBgetdblparam");
gurobi_dynamic_library->GetFunction(&GRBgetstrparam, "GRBgetstrparam");
gurobi_dynamic_library->GetFunction(&GRBsetparam, "GRBsetparam");
gurobi_dynamic_library->GetFunction(&GRBsetintparam, "GRBsetintparam");
gurobi_dynamic_library->GetFunction(&GRBsetdblparam, "GRBsetdblparam");
gurobi_dynamic_library->GetFunction(&GRBsetstrparam, "GRBsetstrparam");
gurobi_dynamic_library->GetFunction(&GRBresetparams, "GRBresetparams");
gurobi_dynamic_library->GetFunction(&GRBcopyparams, "GRBcopyparams");
gurobi_dynamic_library->GetFunction(&GRBloadenv, "GRBloadenv");
gurobi_dynamic_library->GetFunction(&GRBstartenv, "GRBstartenv");
gurobi_dynamic_library->GetFunction(&GRBemptyenv, "GRBemptyenv");
gurobi_dynamic_library->GetFunction(&GRBgetnumparams, "GRBgetnumparams");
gurobi_dynamic_library->GetFunction(&GRBgetparamname, "GRBgetparamname");
gurobi_dynamic_library->GetFunction(&GRBgetparamtype, "GRBgetparamtype");
gurobi_dynamic_library->GetFunction(&GRBgetintparaminfo,
"GRBgetintparaminfo");
gurobi_dynamic_library->GetFunction(&GRBgetdblparaminfo,
"GRBgetdblparaminfo");
gurobi_dynamic_library->GetFunction(&GRBgetstrparaminfo,
"GRBgetstrparaminfo");
gurobi_dynamic_library->GetFunction(&GRBgetenv, "GRBgetenv");
gurobi_dynamic_library->GetFunction(&GRBgetmultiobjenv, "GRBgetmultiobjenv");
gurobi_dynamic_library->GetFunction(&GRBdiscardmultiobjenvs,
"GRBdiscardmultiobjenvs");
gurobi_dynamic_library->GetFunction(&GRBfreeenv, "GRBfreeenv");
gurobi_dynamic_library->GetFunction(&GRBgeterrormsg, "GRBgeterrormsg");
gurobi_dynamic_library->GetFunction(&GRBversion, "GRBversion");
gurobi_dynamic_library->GetFunction(&GRBplatform, "GRBplatform");
}
std::vector<std::string> GurobiDynamicLibraryPotentialPaths() {
std::vector<std::string> potential_paths;
const std::vector<absl::string_view> kGurobiVersions = {
"1202", "1201", "1200", "1103", "1102", "1101", "1100", "1003",
"1002", "1001", "1000", "952", "951", "950", "911",
"910", "903", "902", "811", "801", "752"};
potential_paths.reserve(kGurobiVersions.size() * 3);
// Look for libraries pointed by GUROBI_HOME first.
const char* gurobi_home_from_env = getenv("GUROBI_HOME");
if (gurobi_home_from_env != nullptr) {
for (const absl::string_view version : kGurobiVersions) {
const absl::string_view lib = version.substr(0, version.size() - 1);
#if defined(_MSC_VER) // Windows
potential_paths.push_back(
absl::StrCat(gurobi_home_from_env, "\\bin\\gurobi", lib, ".dll"));
#elif defined(__APPLE__) // OS X
potential_paths.push_back(
absl::StrCat(gurobi_home_from_env, "/lib/libgurobi", lib, ".dylib"));
#elif defined(__GNUC__) // Linux
potential_paths.push_back(
absl::StrCat(gurobi_home_from_env, "/lib/libgurobi", lib, ".so"));
potential_paths.push_back(
absl::StrCat(gurobi_home_from_env, "/lib64/libgurobi", lib, ".so"));
#else
LOG(ERROR) << "OS Not recognized by gurobi_environment.cc."
<< " You won't be able to use Gurobi.";
#endif
}
}
// Search for canonical places.
for (const absl::string_view version : kGurobiVersions) {
const absl::string_view lib = version.substr(0, version.size() - 1);
#if defined(_MSC_VER) // Windows
potential_paths.push_back(absl::StrCat("C:\\Program Files\\gurobi", version,
"\\win64\\bin\\gurobi", lib,
".dll"));
potential_paths.push_back(absl::StrCat(
"C:\\gurobi", version, "\\win64\\bin\\gurobi", lib, ".dll"));
potential_paths.push_back(absl::StrCat("gurobi", lib, ".dll"));
#elif defined(__APPLE__) // OS X
potential_paths.push_back(absl::StrCat(
"/Library/gurobi", version, "/mac64/lib/libgurobi", lib, ".dylib"));
potential_paths.push_back(absl::StrCat("/Library/gurobi", version,
"/macos_universal2/lib/libgurobi",
lib, ".dylib"));
#elif defined(__GNUC__) // Linux
potential_paths.push_back(absl::StrCat(
"/opt/gurobi", version, "/linux64/lib/libgurobi", lib, ".so"));
potential_paths.push_back(absl::StrCat(
"/opt/gurobi", version, "/linux64/lib64/libgurobi", lib, ".so"));
potential_paths.push_back(
absl::StrCat("/opt/gurobi/linux64/lib/libgurobi", lib, ".so"));
potential_paths.push_back(
absl::StrCat("/opt/gurobi/linux64/lib64/libgurobi", lib, ".so"));
#else
LOG(ERROR) << "OS Not recognized by gurobi_environment.cc."
<< " You won't be able to use Gurobi.";
#endif
}
#if defined(__GNUC__) // path in linux64 gurobi/optimizer docker image.
for (const absl::string_view version :
{"12.0.2","12.0.1", "12.0.0", "11.0.3", "11.0.2", "11.0.1", "11.0.0",
"10.0.3", "10.0.2", "10.0.1", "10.0.0", "9.5.2", "9.5.1", "9.5.0"}) {
potential_paths.push_back(
absl::StrCat("/opt/gurobi/linux64/lib/libgurobi.so.", version));
}
#endif
return potential_paths;
}
absl::Status LoadGurobiDynamicLibrary(
std::vector<absl::string_view> potential_paths) {
static std::once_flag gurobi_loading_done;
static absl::Status gurobi_load_status;
static DynamicLibrary gurobi_library;
static absl::Mutex mutex;
absl::MutexLock lock(&mutex);
std::call_once(gurobi_loading_done, [&potential_paths]() {
const std::vector<std::string> canonical_paths =
GurobiDynamicLibraryPotentialPaths();
potential_paths.insert(potential_paths.end(), canonical_paths.begin(),
canonical_paths.end());
for (const absl::string_view path : potential_paths) {
if (gurobi_library.TryToLoad(path)) {
LOG(INFO) << "Found the Gurobi library in '" << path << ".";
break;
}
}
if (gurobi_library.LibraryIsLoaded()) {
LoadGurobiFunctions(&gurobi_library);
gurobi_load_status = absl::OkStatus();
} else {
gurobi_load_status = absl::NotFoundError(absl::StrCat(
"Could not find the Gurobi shared library. Looked in: [",
absl::StrJoin(potential_paths, "', '"),
"]. If you know where it"
" is, pass the full path to 'LoadGurobiDynamicLibrary()'."));
}
});
return gurobi_load_status;
}
} // namespace operations_research

View File

@@ -0,0 +1,736 @@
// Copyright 2010-2025 Google LLC
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef THIRD_PARTY_ORTOOLS_ORTOOLS_THIRD_PARTY_SOLVERS_GUROBI_ENVIRONMENT_H_
#define THIRD_PARTY_ORTOOLS_ORTOOLS_THIRD_PARTY_SOLVERS_GUROBI_ENVIRONMENT_H_
#include <functional>
#include <vector>
#include "absl/status/status.h"
#include "absl/strings/string_view.h"
#if defined(_MSC_VER)
#define GUROBI_STDCALL __stdcall
#else
#define GUROBI_STDCALL
#endif
extern "C" {
typedef struct _GRBmodel GRBmodel;
typedef struct _GRBenv GRBenv;
typedef struct _GRBsvec {
int len;
int* ind;
double* val;
} GRBsvec;
}
namespace operations_research {
// Force the loading of the gurobi dynamic library. It returns true if the
// library was successfully loaded. This method can only be called once.
// Successive calls are no-op.
//
// Note that it does not check if a token license can be grabbed.
absl::Status LoadGurobiDynamicLibrary(
std::vector<absl::string_view> potential_paths);
// clang-format off
// The list of #define and extern std::function<> below is generated directly
// from gurobi_c.h via parse_header.py
// See the top comment on the parse_header.py file.
// This is the header section
#define GRB_VERSION_MAJOR 10
#define GRB_VERSION_MINOR 0
#define GRB_VERSION_TECHNICAL 0
#define DEFAULT_CS_PRIORITY 0
#define MAX_CS_PRIORITY 100
#define DEFAULT_CS_PORT 61000
#define DEFAULT_CS_HANGUP 60
#define GRB_ERROR_OUT_OF_MEMORY 10001
#define GRB_ERROR_NULL_ARGUMENT 10002
#define GRB_ERROR_INVALID_ARGUMENT 10003
#define GRB_ERROR_UNKNOWN_ATTRIBUTE 10004
#define GRB_ERROR_DATA_NOT_AVAILABLE 10005
#define GRB_ERROR_INDEX_OUT_OF_RANGE 10006
#define GRB_ERROR_UNKNOWN_PARAMETER 10007
#define GRB_ERROR_VALUE_OUT_OF_RANGE 10008
#define GRB_ERROR_NO_LICENSE 10009
#define GRB_ERROR_SIZE_LIMIT_EXCEEDED 10010
#define GRB_ERROR_CALLBACK 10011
#define GRB_ERROR_FILE_READ 10012
#define GRB_ERROR_FILE_WRITE 10013
#define GRB_ERROR_NUMERIC 10014
#define GRB_ERROR_IIS_NOT_INFEASIBLE 10015
#define GRB_ERROR_NOT_FOR_MIP 10016
#define GRB_ERROR_OPTIMIZATION_IN_PROGRESS 10017
#define GRB_ERROR_DUPLICATES 10018
#define GRB_ERROR_NODEFILE 10019
#define GRB_ERROR_Q_NOT_PSD 10020
#define GRB_ERROR_QCP_EQUALITY_CONSTRAINT 10021
#define GRB_ERROR_NETWORK 10022
#define GRB_ERROR_JOB_REJECTED 10023
#define GRB_ERROR_NOT_SUPPORTED 10024
#define GRB_ERROR_EXCEED_2B_NONZEROS 10025
#define GRB_ERROR_INVALID_PIECEWISE_OBJ 10026
#define GRB_ERROR_UPDATEMODE_CHANGE 10027
#define GRB_ERROR_CLOUD 10028
#define GRB_ERROR_MODEL_MODIFICATION 10029
#define GRB_ERROR_CSWORKER 10030
#define GRB_ERROR_TUNE_MODEL_TYPES 10031
#define GRB_ERROR_SECURITY 10032
#define GRB_LESS_EQUAL '<'
#define GRB_GREATER_EQUAL '>'
#define GRB_EQUAL '='
#define GRB_CONTINUOUS 'C'
#define GRB_BINARY 'B'
#define GRB_INTEGER 'I'
#define GRB_SEMICONT 'S'
#define GRB_SEMIINT 'N'
#define GRB_MINIMIZE 1
#define GRB_MAXIMIZE -1
#define GRB_SOS_TYPE1 1
#define GRB_SOS_TYPE2 2
#define GRB_INFINITY 1e100
#define GRB_UNDEFINED 1e101
#define GRB_MAXINT 2000000000
#define GRB_MAX_NAMELEN 255
#define GRB_MAX_STRLEN 512
#define GRB_MAX_TAGLEN 10240
#define GRB_MAX_CONCURRENT 64
#define CB_ARGS GRBmodel *model, void *cbdata, int where, void *usrdata
#define LOGCB_ARGS char *msg, void *logdata
extern std::function<int(GRBmodel *model, const char *attrname)> GRBisattravailable;
extern std::function<int(GRBmodel *model, const char *attrname, int *valueP)> GRBgetintattr;
extern std::function<int(GRBmodel *model, const char *attrname, int newvalue)> GRBsetintattr;
extern std::function<int(GRBmodel *model, const char *attrname,int element, int *valueP)> GRBgetintattrelement;
extern std::function<int(GRBmodel *model, const char *attrname,int element, int newvalue)> GRBsetintattrelement;
extern std::function<int(GRBmodel *model, const char *attrname,int first, int len, int *values)> GRBgetintattrarray;
extern std::function<int(GRBmodel *model, const char *attrname,int first, int len, int *newvalues)> GRBsetintattrarray;
extern std::function<int(GRBmodel *model, const char *attrname,int len, int *ind, int *newvalues)> GRBsetintattrlist;
extern std::function<int(GRBmodel *model, const char *attrname,int element, char *valueP)> GRBgetcharattrelement;
extern std::function<int(GRBmodel *model, const char *attrname,int element, char newvalue)> GRBsetcharattrelement;
extern std::function<int(GRBmodel *model, const char *attrname,int first, int len, char *values)> GRBgetcharattrarray;
extern std::function<int(GRBmodel *model, const char *attrname,int first, int len, char *newvalues)> GRBsetcharattrarray;
extern std::function<int(GRBmodel *model, const char *attrname,int len, int *ind, char *newvalues)> GRBsetcharattrlist;
extern std::function<int(GRBmodel *model, const char *attrname, double *valueP)> GRBgetdblattr;
extern std::function<int(GRBmodel *model, const char *attrname, double newvalue)> GRBsetdblattr;
extern std::function<int(GRBmodel *model, const char *attrname,int element, double *valueP)> GRBgetdblattrelement;
extern std::function<int(GRBmodel *model, const char *attrname,int element, double newvalue)> GRBsetdblattrelement;
extern std::function<int(GRBmodel *model, const char *attrname,int first, int len, double *values)> GRBgetdblattrarray;
extern std::function<int(GRBmodel *model, const char *attrname,int first, int len, double *newvalues)> GRBsetdblattrarray;
extern std::function<int(GRBmodel *model, const char *attrname,int len, int *ind, double *newvalues)> GRBsetdblattrlist;
extern std::function<int(GRBmodel *model, const char *attrname, char **valueP)> GRBgetstrattr;
extern std::function<int(GRBmodel *model, const char *attrname, const char *newvalue)> GRBsetstrattr;
extern std::function<int(GRBmodel *model,int (GUROBI_STDCALL *cb)(CB_ARGS),void *usrdata)> GRBsetcallbackfunc;
extern std::function<int(void *cbdata, int where, int what, void *resultP)> GRBcbget;
extern std::function<int(void *cbdata, const double *solution, double *objvalP)> GRBcbsolution;
extern std::function<int(void *cbdata, int cutlen, const int *cutind, const double *cutval,char cutsense, double cutrhs)> GRBcbcut;
extern std::function<int(void *cbdata, int lazylen, const int *lazyind,const double *lazyval, char lazysense, double lazyrhs)> GRBcblazy;
#define GRB_INT_ATTR_NUMCONSTRS "NumConstrs"
#define GRB_INT_ATTR_NUMVARS "NumVars"
#define GRB_INT_ATTR_NUMSOS "NumSOS"
#define GRB_INT_ATTR_NUMQCONSTRS "NumQConstrs"
#define GRB_INT_ATTR_NUMGENCONSTRS "NumGenConstrs"
#define GRB_INT_ATTR_NUMNZS "NumNZs"
#define GRB_DBL_ATTR_DNUMNZS "DNumNZs"
#define GRB_INT_ATTR_NUMQNZS "NumQNZs"
#define GRB_INT_ATTR_NUMQCNZS "NumQCNZs"
#define GRB_INT_ATTR_NUMINTVARS "NumIntVars"
#define GRB_INT_ATTR_NUMBINVARS "NumBinVars"
#define GRB_INT_ATTR_NUMPWLOBJVARS "NumPWLObjVars"
#define GRB_STR_ATTR_MODELNAME "ModelName"
#define GRB_INT_ATTR_MODELSENSE "ModelSense"
#define GRB_DBL_ATTR_OBJCON "ObjCon"
#define GRB_INT_ATTR_IS_MIP "IsMIP"
#define GRB_INT_ATTR_IS_QP "IsQP"
#define GRB_INT_ATTR_IS_QCP "IsQCP"
#define GRB_INT_ATTR_IS_MULTIOBJ "IsMultiObj"
#define GRB_INT_ATTR_LICENSE_EXPIRATION "LicenseExpiration"
#define GRB_INT_ATTR_NUMTAGGED "NumTagged"
#define GRB_INT_ATTR_FINGERPRINT "Fingerprint"
#define GRB_INT_ATTR_BATCHERRORCODE "BatchErrorCode"
#define GRB_STR_ATTR_BATCHERRORMESSAGE "BatchErrorMessage"
#define GRB_STR_ATTR_BATCHID "BatchID"
#define GRB_INT_ATTR_BATCHSTATUS "BatchStatus"
#define GRB_DBL_ATTR_LB "LB"
#define GRB_DBL_ATTR_UB "UB"
#define GRB_DBL_ATTR_OBJ "Obj"
#define GRB_CHAR_ATTR_VTYPE "VType"
#define GRB_DBL_ATTR_START "Start"
#define GRB_DBL_ATTR_PSTART "PStart"
#define GRB_INT_ATTR_BRANCHPRIORITY "BranchPriority"
#define GRB_STR_ATTR_VARNAME "VarName"
#define GRB_INT_ATTR_PWLOBJCVX "PWLObjCvx"
#define GRB_DBL_ATTR_VARHINTVAL "VarHintVal"
#define GRB_INT_ATTR_VARHINTPRI "VarHintPri"
#define GRB_INT_ATTR_PARTITION "Partition"
#define GRB_INT_ATTR_POOLIGNORE "PoolIgnore"
#define GRB_STR_ATTR_VTAG "VTag"
#define GRB_STR_ATTR_CTAG "CTag"
#define GRB_DBL_ATTR_RHS "RHS"
#define GRB_DBL_ATTR_DSTART "DStart"
#define GRB_CHAR_ATTR_SENSE "Sense"
#define GRB_STR_ATTR_CONSTRNAME "ConstrName"
#define GRB_INT_ATTR_LAZY "Lazy"
#define GRB_STR_ATTR_QCTAG "QCTag"
#define GRB_DBL_ATTR_QCRHS "QCRHS"
#define GRB_CHAR_ATTR_QCSENSE "QCSense"
#define GRB_STR_ATTR_QCNAME "QCName"
#define GRB_INT_ATTR_GENCONSTRTYPE "GenConstrType"
#define GRB_STR_ATTR_GENCONSTRNAME "GenConstrName"
#define GRB_INT_ATTR_FUNCPIECES "FuncPieces"
#define GRB_DBL_ATTR_FUNCPIECEERROR "FuncPieceError"
#define GRB_DBL_ATTR_FUNCPIECELENGTH "FuncPieceLength"
#define GRB_DBL_ATTR_FUNCPIECERATIO "FuncPieceRatio"
#define GRB_DBL_ATTR_MAX_COEFF "MaxCoeff"
#define GRB_DBL_ATTR_MIN_COEFF "MinCoeff"
#define GRB_DBL_ATTR_MAX_BOUND "MaxBound"
#define GRB_DBL_ATTR_MIN_BOUND "MinBound"
#define GRB_DBL_ATTR_MAX_OBJ_COEFF "MaxObjCoeff"
#define GRB_DBL_ATTR_MIN_OBJ_COEFF "MinObjCoeff"
#define GRB_DBL_ATTR_MAX_RHS "MaxRHS"
#define GRB_DBL_ATTR_MIN_RHS "MinRHS"
#define GRB_DBL_ATTR_MAX_QCCOEFF "MaxQCCoeff"
#define GRB_DBL_ATTR_MIN_QCCOEFF "MinQCCoeff"
#define GRB_DBL_ATTR_MAX_QOBJ_COEFF "MaxQObjCoeff"
#define GRB_DBL_ATTR_MIN_QOBJ_COEFF "MinQObjCoeff"
#define GRB_DBL_ATTR_MAX_QCLCOEFF "MaxQCLCoeff"
#define GRB_DBL_ATTR_MIN_QCLCOEFF "MinQCLCoeff"
#define GRB_DBL_ATTR_MAX_QCRHS "MaxQCRHS"
#define GRB_DBL_ATTR_MIN_QCRHS "MinQCRHS"
#define GRB_DBL_ATTR_RUNTIME "Runtime"
#define GRB_DBL_ATTR_WORK "Work"
#define GRB_INT_ATTR_STATUS "Status"
#define GRB_DBL_ATTR_OBJVAL "ObjVal"
#define GRB_DBL_ATTR_OBJBOUND "ObjBound"
#define GRB_DBL_ATTR_OBJBOUNDC "ObjBoundC"
#define GRB_DBL_ATTR_POOLOBJBOUND "PoolObjBound"
#define GRB_DBL_ATTR_POOLOBJVAL "PoolObjVal"
#define GRB_DBL_ATTR_MIPGAP "MIPGap"
#define GRB_INT_ATTR_SOLCOUNT "SolCount"
#define GRB_DBL_ATTR_ITERCOUNT "IterCount"
#define GRB_INT_ATTR_BARITERCOUNT "BarIterCount"
#define GRB_DBL_ATTR_NODECOUNT "NodeCount"
#define GRB_DBL_ATTR_OPENNODECOUNT "OpenNodeCount"
#define GRB_INT_ATTR_HASDUALNORM "HasDualNorm"
#define GRB_INT_ATTR_CONCURRENTWINMETHOD "ConcurrentWinMethod"
#define GRB_DBL_ATTR_X "X"
#define GRB_DBL_ATTR_XN "Xn"
#define GRB_DBL_ATTR_BARX "BarX"
#define GRB_DBL_ATTR_RC "RC"
#define GRB_DBL_ATTR_VDUALNORM "VDualNorm"
#define GRB_INT_ATTR_VBASIS "VBasis"
#define GRB_DBL_ATTR_PI "Pi"
#define GRB_DBL_ATTR_QCPI "QCPi"
#define GRB_DBL_ATTR_SLACK "Slack"
#define GRB_DBL_ATTR_QCSLACK "QCSlack"
#define GRB_DBL_ATTR_CDUALNORM "CDualNorm"
#define GRB_INT_ATTR_CBASIS "CBasis"
#define GRB_DBL_ATTR_MAX_VIO "MaxVio"
#define GRB_DBL_ATTR_BOUND_VIO "BoundVio"
#define GRB_DBL_ATTR_BOUND_SVIO "BoundSVio"
#define GRB_INT_ATTR_BOUND_VIO_INDEX "BoundVioIndex"
#define GRB_INT_ATTR_BOUND_SVIO_INDEX "BoundSVioIndex"
#define GRB_DBL_ATTR_BOUND_VIO_SUM "BoundVioSum"
#define GRB_DBL_ATTR_BOUND_SVIO_SUM "BoundSVioSum"
#define GRB_DBL_ATTR_CONSTR_VIO "ConstrVio"
#define GRB_DBL_ATTR_CONSTR_SVIO "ConstrSVio"
#define GRB_INT_ATTR_CONSTR_VIO_INDEX "ConstrVioIndex"
#define GRB_INT_ATTR_CONSTR_SVIO_INDEX "ConstrSVioIndex"
#define GRB_DBL_ATTR_CONSTR_VIO_SUM "ConstrVioSum"
#define GRB_DBL_ATTR_CONSTR_SVIO_SUM "ConstrSVioSum"
#define GRB_DBL_ATTR_CONSTR_RESIDUAL "ConstrResidual"
#define GRB_DBL_ATTR_CONSTR_SRESIDUAL "ConstrSResidual"
#define GRB_INT_ATTR_CONSTR_RESIDUAL_INDEX "ConstrResidualIndex"
#define GRB_INT_ATTR_CONSTR_SRESIDUAL_INDEX "ConstrSResidualIndex"
#define GRB_DBL_ATTR_CONSTR_RESIDUAL_SUM "ConstrResidualSum"
#define GRB_DBL_ATTR_CONSTR_SRESIDUAL_SUM "ConstrSResidualSum"
#define GRB_DBL_ATTR_DUAL_VIO "DualVio"
#define GRB_DBL_ATTR_DUAL_SVIO "DualSVio"
#define GRB_INT_ATTR_DUAL_VIO_INDEX "DualVioIndex"
#define GRB_INT_ATTR_DUAL_SVIO_INDEX "DualSVioIndex"
#define GRB_DBL_ATTR_DUAL_VIO_SUM "DualVioSum"
#define GRB_DBL_ATTR_DUAL_SVIO_SUM "DualSVioSum"
#define GRB_DBL_ATTR_DUAL_RESIDUAL "DualResidual"
#define GRB_DBL_ATTR_DUAL_SRESIDUAL "DualSResidual"
#define GRB_INT_ATTR_DUAL_RESIDUAL_INDEX "DualResidualIndex"
#define GRB_INT_ATTR_DUAL_SRESIDUAL_INDEX "DualSResidualIndex"
#define GRB_DBL_ATTR_DUAL_RESIDUAL_SUM "DualResidualSum"
#define GRB_DBL_ATTR_DUAL_SRESIDUAL_SUM "DualSResidualSum"
#define GRB_DBL_ATTR_INT_VIO "IntVio"
#define GRB_INT_ATTR_INT_VIO_INDEX "IntVioIndex"
#define GRB_DBL_ATTR_INT_VIO_SUM "IntVioSum"
#define GRB_DBL_ATTR_COMPL_VIO "ComplVio"
#define GRB_INT_ATTR_COMPL_VIO_INDEX "ComplVioIndex"
#define GRB_DBL_ATTR_COMPL_VIO_SUM "ComplVioSum"
#define GRB_DBL_ATTR_KAPPA "Kappa"
#define GRB_DBL_ATTR_KAPPA_EXACT "KappaExact"
#define GRB_DBL_ATTR_N2KAPPA "N2Kappa"
#define GRB_DBL_ATTR_SA_OBJLOW "SAObjLow"
#define GRB_DBL_ATTR_SA_OBJUP "SAObjUp"
#define GRB_DBL_ATTR_SA_LBLOW "SALBLow"
#define GRB_DBL_ATTR_SA_LBUP "SALBUp"
#define GRB_DBL_ATTR_SA_UBLOW "SAUBLow"
#define GRB_DBL_ATTR_SA_UBUP "SAUBUp"
#define GRB_DBL_ATTR_SA_RHSLOW "SARHSLow"
#define GRB_DBL_ATTR_SA_RHSUP "SARHSUp"
#define GRB_INT_ATTR_IIS_MINIMAL "IISMinimal"
#define GRB_INT_ATTR_IIS_LB "IISLB"
#define GRB_INT_ATTR_IIS_UB "IISUB"
#define GRB_INT_ATTR_IIS_CONSTR "IISConstr"
#define GRB_INT_ATTR_IIS_SOS "IISSOS"
#define GRB_INT_ATTR_IIS_QCONSTR "IISQConstr"
#define GRB_INT_ATTR_IIS_GENCONSTR "IISGenConstr"
#define GRB_INT_ATTR_IIS_LBFORCE "IISLBForce"
#define GRB_INT_ATTR_IIS_UBFORCE "IISUBForce"
#define GRB_INT_ATTR_IIS_CONSTRFORCE "IISConstrForce"
#define GRB_INT_ATTR_IIS_SOSFORCE "IISSOSForce"
#define GRB_INT_ATTR_IIS_QCONSTRFORCE "IISQConstrForce"
#define GRB_INT_ATTR_IIS_GENCONSTRFORCE "IISGenConstrForce"
#define GRB_INT_ATTR_TUNE_RESULTCOUNT "TuneResultCount"
#define GRB_DBL_ATTR_FARKASDUAL "FarkasDual"
#define GRB_DBL_ATTR_FARKASPROOF "FarkasProof"
#define GRB_DBL_ATTR_UNBDRAY "UnbdRay"
#define GRB_INT_ATTR_INFEASVAR "InfeasVar"
#define GRB_INT_ATTR_UNBDVAR "UnbdVar"
#define GRB_INT_ATTR_VARPRESTAT "VarPreStat"
#define GRB_DBL_ATTR_PREFIXVAL "PreFixVal"
#define GRB_DBL_ATTR_OBJN "ObjN"
#define GRB_DBL_ATTR_OBJNVAL "ObjNVal"
#define GRB_DBL_ATTR_OBJNCON "ObjNCon"
#define GRB_DBL_ATTR_OBJNWEIGHT "ObjNWeight"
#define GRB_INT_ATTR_OBJNPRIORITY "ObjNPriority"
#define GRB_DBL_ATTR_OBJNRELTOL "ObjNRelTol"
#define GRB_DBL_ATTR_OBJNABSTOL "ObjNAbsTol"
#define GRB_STR_ATTR_OBJNNAME "ObjNName"
#define GRB_DBL_ATTR_SCENNLB "ScenNLB"
#define GRB_DBL_ATTR_SCENNUB "ScenNUB"
#define GRB_DBL_ATTR_SCENNOBJ "ScenNObj"
#define GRB_DBL_ATTR_SCENNRHS "ScenNRHS"
#define GRB_STR_ATTR_SCENNNAME "ScenNName"
#define GRB_DBL_ATTR_SCENNX "ScenNX"
#define GRB_DBL_ATTR_SCENNOBJBOUND "ScenNObjBound"
#define GRB_DBL_ATTR_SCENNOBJVAL "ScenNObjVal"
#define GRB_INT_ATTR_NUMOBJ "NumObj"
#define GRB_INT_ATTR_NUMSCENARIOS "NumScenarios"
#define GRB_INT_ATTR_NUMSTART "NumStart"
#define GRB_GENCONSTR_MAX 0
#define GRB_GENCONSTR_MIN 1
#define GRB_GENCONSTR_ABS 2
#define GRB_GENCONSTR_AND 3
#define GRB_GENCONSTR_OR 4
#define GRB_GENCONSTR_NORM 5
#define GRB_GENCONSTR_INDICATOR 6
#define GRB_GENCONSTR_PWL 7
#define GRB_GENCONSTR_POLY 8
#define GRB_GENCONSTR_EXP 9
#define GRB_GENCONSTR_EXPA 10
#define GRB_GENCONSTR_LOG 11
#define GRB_GENCONSTR_LOGA 12
#define GRB_GENCONSTR_POW 13
#define GRB_GENCONSTR_SIN 14
#define GRB_GENCONSTR_COS 15
#define GRB_GENCONSTR_TAN 16
#define GRB_GENCONSTR_LOGISTIC 17
#define GRB_CB_POLLING 0
#define GRB_CB_PRESOLVE 1
#define GRB_CB_SIMPLEX 2
#define GRB_CB_MIP 3
#define GRB_CB_MIPSOL 4
#define GRB_CB_MIPNODE 5
#define GRB_CB_MESSAGE 6
#define GRB_CB_BARRIER 7
#define GRB_CB_MULTIOBJ 8
#define GRB_CB_IIS 9
#define GRB_CB_PRE_COLDEL 1000
#define GRB_CB_PRE_ROWDEL 1001
#define GRB_CB_PRE_SENCHG 1002
#define GRB_CB_PRE_BNDCHG 1003
#define GRB_CB_PRE_COECHG 1004
#define GRB_CB_SPX_ITRCNT 2000
#define GRB_CB_SPX_OBJVAL 2001
#define GRB_CB_SPX_PRIMINF 2002
#define GRB_CB_SPX_DUALINF 2003
#define GRB_CB_SPX_ISPERT 2004
#define GRB_CB_MIP_OBJBST 3000
#define GRB_CB_MIP_OBJBND 3001
#define GRB_CB_MIP_NODCNT 3002
#define GRB_CB_MIP_SOLCNT 3003
#define GRB_CB_MIP_CUTCNT 3004
#define GRB_CB_MIP_NODLFT 3005
#define GRB_CB_MIP_ITRCNT 3006
#define GRB_CB_MIP_OPENSCENARIOS 3007
#define GRB_CB_MIP_PHASE 3008
#define GRB_CB_MIPSOL_SOL 4001
#define GRB_CB_MIPSOL_OBJ 4002
#define GRB_CB_MIPSOL_OBJBST 4003
#define GRB_CB_MIPSOL_OBJBND 4004
#define GRB_CB_MIPSOL_NODCNT 4005
#define GRB_CB_MIPSOL_SOLCNT 4006
#define GRB_CB_MIPSOL_OPENSCENARIOS 4007
#define GRB_CB_MIPSOL_PHASE 4008
#define GRB_CB_MIPNODE_STATUS 5001
#define GRB_CB_MIPNODE_REL 5002
#define GRB_CB_MIPNODE_OBJBST 5003
#define GRB_CB_MIPNODE_OBJBND 5004
#define GRB_CB_MIPNODE_NODCNT 5005
#define GRB_CB_MIPNODE_SOLCNT 5006
#define GRB_CB_MIPNODE_BRVAR 5007
#define GRB_CB_MIPNODE_OPENSCENARIOS 5008
#define GRB_CB_MIPNODE_PHASE 5009
#define GRB_CB_MSG_STRING 6001
#define GRB_CB_RUNTIME 6002
#define GRB_CB_WORK 6003
#define GRB_CB_BARRIER_ITRCNT 7001
#define GRB_CB_BARRIER_PRIMOBJ 7002
#define GRB_CB_BARRIER_DUALOBJ 7003
#define GRB_CB_BARRIER_PRIMINF 7004
#define GRB_CB_BARRIER_DUALINF 7005
#define GRB_CB_BARRIER_COMPL 7006
#define GRB_CB_MULTIOBJ_OBJCNT 8001
#define GRB_CB_MULTIOBJ_SOLCNT 8002
#define GRB_CB_MULTIOBJ_SOL 8003
#define GRB_CB_IIS_CONSTRMIN 9001
#define GRB_CB_IIS_CONSTRMAX 9002
#define GRB_CB_IIS_CONSTRGUESS 9003
#define GRB_CB_IIS_BOUNDMIN 9004
#define GRB_CB_IIS_BOUNDMAX 9005
#define GRB_CB_IIS_BOUNDGUESS 9006
#define GRB_FEASRELAX_LINEAR 0
#define GRB_FEASRELAX_QUADRATIC 1
#define GRB_FEASRELAX_CARDINALITY 2
extern std::function<int(GRBmodel *model, int *numnzP, int *vbeg, int *vind,double *vval, int start, int len)> GRBgetvars;
extern std::function<int(GRBmodel *model)> GRBoptimize;
extern std::function<int(GRBmodel *model)> GRBcomputeIIS;
#define MALLOCCB_ARGS size_t size, void *syscbusrdata
#define CALLOCCB_ARGS size_t nmemb, size_t size, void *syscbusrdata
#define REALLOCCB_ARGS void *ptr, size_t size, void *syscbusrdata
#define FREECB_ARGS void *ptr, void *syscbusrdata
#define THREADCREATECB_ARGS void **threadP, void (*start_routine)(void *), void *arg, void *syscbusrdata
#define THREADJOINCB_ARGS void *thread, void *syscbusrdata
extern std::function<int(GRBmodel *model, const char *filename)> GRBwrite;
extern std::function<int(GRBenv *env, GRBmodel **modelP, const char *Pname, int numvars,double *obj, double *lb, double *ub, char *vtype,char **varnames)> GRBnewmodel;
extern std::function<int(GRBmodel *model, int numnz, int *vind, double *vval,double obj, double lb, double ub, char vtype,const char *varname)> GRBaddvar;
extern 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;
extern std::function<int(GRBmodel *model, int numnz, int *cind, double *cval,char sense, double rhs, const char *constrname)> GRBaddconstr;
extern std::function<int(GRBmodel *model, int numconstrs, int numnz,int *cbeg, int *cind, double *cval,char *sense, double *rhs, char **constrnames)> GRBaddconstrs;
extern std::function<int(GRBmodel *model, int numnz, int *cind, double *cval,double lower, double upper, const char *constrname)> GRBaddrangeconstr;
extern std::function<int(GRBmodel *model, int numsos, int nummembers, int *types,int *beg, int *ind, double *weight)> GRBaddsos;
extern std::function<int(GRBmodel *model, const char *name,int resvar, int nvars, const int *vars,double constant)> GRBaddgenconstrMax;
extern std::function<int(GRBmodel *model, const char *name,int resvar, int nvars, const int *vars,double constant)> GRBaddgenconstrMin;
extern std::function<int(GRBmodel *model, const char *name,int resvar, int argvar)> GRBaddgenconstrAbs;
extern std::function<int(GRBmodel *model, const char *name,int resvar, int nvars, const int *vars)> GRBaddgenconstrAnd;
extern std::function<int(GRBmodel *model, const char *name,int resvar, int nvars, const int *vars)> GRBaddgenconstrOr;
extern 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;
extern 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;
extern std::function<int(GRBmodel *model, int numqnz, int *qrow, int *qcol,double *qval)> GRBaddqpterms;
extern std::function<int(GRBmodel *model, int len, int *ind)> GRBdelvars;
extern std::function<int(GRBmodel *model, int len, int *ind)> GRBdelconstrs;
extern std::function<int(GRBmodel *model, int len, int *ind)> GRBdelsos;
extern std::function<int(GRBmodel *model, int len, int *ind)> GRBdelgenconstrs;
extern std::function<int(GRBmodel *model, int len, int *ind)> GRBdelqconstrs;
extern std::function<int(GRBmodel *model)> GRBdelq;
extern std::function<int(GRBmodel *model, int cnt, int *cind, int *vind, double *val)> GRBchgcoeffs;
extern std::function<int(GRBmodel *model)> GRBupdatemodel;
extern std::function<int(GRBmodel *model)> GRBfreemodel;
#define GRB_LOADED 1
#define GRB_OPTIMAL 2
#define GRB_INFEASIBLE 3
#define GRB_INF_OR_UNBD 4
#define GRB_UNBOUNDED 5
#define GRB_CUTOFF 6
#define GRB_ITERATION_LIMIT 7
#define GRB_NODE_LIMIT 8
#define GRB_TIME_LIMIT 9
#define GRB_SOLUTION_LIMIT 10
#define GRB_INTERRUPTED 11
#define GRB_NUMERIC 12
#define GRB_SUBOPTIMAL 13
#define GRB_INPROGRESS 14
#define GRB_USER_OBJ_LIMIT 15
#define GRB_WORK_LIMIT 16
#define GRB_MEM_LIMIT 17
#define GRB_BASIC 0
#define GRB_NONBASIC_LOWER -1
#define GRB_NONBASIC_UPPER -2
#define GRB_SUPERBASIC -3
#define GRB_INT_PAR_BARITERLIMIT "BarIterLimit"
#define GRB_DBL_PAR_CUTOFF "Cutoff"
#define GRB_DBL_PAR_ITERATIONLIMIT "IterationLimit"
#define GRB_DBL_PAR_NODELIMIT "NodeLimit"
#define GRB_INT_PAR_SOLUTIONLIMIT "SolutionLimit"
#define GRB_DBL_PAR_TIMELIMIT "TimeLimit"
#define GRB_DBL_PAR_WORKLIMIT "WorkLimit"
#define GRB_DBL_PAR_MEMLIMIT "MemLimit"
#define GRB_DBL_PAR_SOFTMEMLIMIT "SoftMemLimit"
#define GRB_DBL_PAR_BESTOBJSTOP "BestObjStop"
#define GRB_DBL_PAR_BESTBDSTOP "BestBdStop"
#define GRB_DBL_PAR_FEASIBILITYTOL "FeasibilityTol"
#define GRB_DBL_PAR_INTFEASTOL "IntFeasTol"
#define GRB_DBL_PAR_MARKOWITZTOL "MarkowitzTol"
#define GRB_DBL_PAR_MIPGAP "MIPGap"
#define GRB_DBL_PAR_MIPGAPABS "MIPGapAbs"
#define GRB_DBL_PAR_OPTIMALITYTOL "OptimalityTol"
#define GRB_DBL_PAR_PSDTOL "PSDTol"
#define GRB_INT_PAR_METHOD "Method"
#define GRB_DBL_PAR_PERTURBVALUE "PerturbValue"
#define GRB_DBL_PAR_OBJSCALE "ObjScale"
#define GRB_INT_PAR_SCALEFLAG "ScaleFlag"
#define GRB_INT_PAR_SIMPLEXPRICING "SimplexPricing"
#define GRB_INT_PAR_QUAD "Quad"
#define GRB_INT_PAR_NORMADJUST "NormAdjust"
#define GRB_INT_PAR_SIFTING "Sifting"
#define GRB_INT_PAR_SIFTMETHOD "SiftMethod"
#define GRB_INT_PAR_LPWARMSTART "LPWarmStart"
#define GRB_INT_PAR_NETWORKALG "NetworkAlg"
#define GRB_DBL_PAR_BARCONVTOL "BarConvTol"
#define GRB_INT_PAR_BARCORRECTORS "BarCorrectors"
#define GRB_INT_PAR_BARHOMOGENEOUS "BarHomogeneous"
#define GRB_INT_PAR_BARORDER "BarOrder"
#define GRB_DBL_PAR_BARQCPCONVTOL "BarQCPConvTol"
#define GRB_INT_PAR_CROSSOVER "Crossover"
#define GRB_INT_PAR_CROSSOVERBASIS "CrossoverBasis"
#define GRB_INT_PAR_BRANCHDIR "BranchDir"
#define GRB_INT_PAR_DEGENMOVES "DegenMoves"
#define GRB_INT_PAR_DISCONNECTED "Disconnected"
#define GRB_DBL_PAR_HEURISTICS "Heuristics"
#define GRB_DBL_PAR_IMPROVESTARTGAP "ImproveStartGap"
#define GRB_DBL_PAR_IMPROVESTARTTIME "ImproveStartTime"
#define GRB_DBL_PAR_IMPROVESTARTNODES "ImproveStartNodes"
#define GRB_INT_PAR_INTEGRALITYFOCUS "IntegralityFocus"
#define GRB_INT_PAR_MINRELNODES "MinRelNodes"
#define GRB_INT_PAR_MIPFOCUS "MIPFocus"
#define GRB_INT_PAR_NLPHEUR "NLPHeur"
#define GRB_STR_PAR_NODEFILEDIR "NodefileDir"
#define GRB_DBL_PAR_NODEFILESTART "NodefileStart"
#define GRB_INT_PAR_NODEMETHOD "NodeMethod"
#define GRB_DBL_PAR_NORELHEURTIME "NoRelHeurTime"
#define GRB_DBL_PAR_NORELHEURWORK "NoRelHeurWork"
#define GRB_INT_PAR_OBBT "OBBT"
#define GRB_INT_PAR_PUMPPASSES "PumpPasses"
#define GRB_INT_PAR_RINS "RINS"
#define GRB_STR_PAR_SOLFILES "SolFiles"
#define GRB_INT_PAR_STARTNODELIMIT "StartNodeLimit"
#define GRB_INT_PAR_SUBMIPNODES "SubMIPNodes"
#define GRB_INT_PAR_SYMMETRY "Symmetry"
#define GRB_INT_PAR_VARBRANCH "VarBranch"
#define GRB_INT_PAR_SOLUTIONNUMBER "SolutionNumber"
#define GRB_INT_PAR_ZEROOBJNODES "ZeroObjNodes"
#define GRB_INT_PAR_CUTS "Cuts"
#define GRB_INT_PAR_CLIQUECUTS "CliqueCuts"
#define GRB_INT_PAR_COVERCUTS "CoverCuts"
#define GRB_INT_PAR_FLOWCOVERCUTS "FlowCoverCuts"
#define GRB_INT_PAR_FLOWPATHCUTS "FlowPathCuts"
#define GRB_INT_PAR_GUBCOVERCUTS "GUBCoverCuts"
#define GRB_INT_PAR_IMPLIEDCUTS "ImpliedCuts"
#define GRB_INT_PAR_PROJIMPLIEDCUTS "ProjImpliedCuts"
#define GRB_INT_PAR_MIPSEPCUTS "MIPSepCuts"
#define GRB_INT_PAR_MIRCUTS "MIRCuts"
#define GRB_INT_PAR_STRONGCGCUTS "StrongCGCuts"
#define GRB_INT_PAR_MODKCUTS "ModKCuts"
#define GRB_INT_PAR_ZEROHALFCUTS "ZeroHalfCuts"
#define GRB_INT_PAR_NETWORKCUTS "NetworkCuts"
#define GRB_INT_PAR_SUBMIPCUTS "SubMIPCuts"
#define GRB_INT_PAR_INFPROOFCUTS "InfProofCuts"
#define GRB_INT_PAR_RLTCUTS "RLTCuts"
#define GRB_INT_PAR_RELAXLIFTCUTS "RelaxLiftCuts"
#define GRB_INT_PAR_BQPCUTS "BQPCuts"
#define GRB_INT_PAR_PSDCUTS "PSDCuts"
#define GRB_INT_PAR_LIFTPROJECTCUTS "LiftProjectCuts"
#define GRB_INT_PAR_CUTAGGPASSES "CutAggPasses"
#define GRB_INT_PAR_CUTPASSES "CutPasses"
#define GRB_INT_PAR_GOMORYPASSES "GomoryPasses"
#define GRB_STR_PAR_WORKERPOOL "WorkerPool"
#define GRB_STR_PAR_WORKERPASSWORD "WorkerPassword"
#define GRB_STR_PAR_COMPUTESERVER "ComputeServer"
#define GRB_STR_PAR_TOKENSERVER "TokenServer"
#define GRB_STR_PAR_SERVERPASSWORD "ServerPassword"
#define GRB_INT_PAR_SERVERTIMEOUT "ServerTimeout"
#define GRB_STR_PAR_CSROUTER "CSRouter"
#define GRB_STR_PAR_CSGROUP "CSGroup"
#define GRB_DBL_PAR_CSQUEUETIMEOUT "CSQueueTimeout"
#define GRB_INT_PAR_CSPRIORITY "CSPriority"
#define GRB_INT_PAR_CSIDLETIMEOUT "CSIdleTimeout"
#define GRB_INT_PAR_CSTLSINSECURE "CSTLSInsecure"
#define GRB_INT_PAR_TSPORT "TSPort"
#define GRB_STR_PAR_CLOUDACCESSID "CloudAccessID"
#define GRB_STR_PAR_CLOUDSECRETKEY "CloudSecretKey"
#define GRB_STR_PAR_CLOUDPOOL "CloudPool"
#define GRB_STR_PAR_CLOUDHOST "CloudHost"
#define GRB_STR_PAR_CSMANAGER "CSManager"
#define GRB_STR_PAR_CSAUTHTOKEN "CSAuthToken"
#define GRB_STR_PAR_CSAPIACCESSID "CSAPIAccessID"
#define GRB_STR_PAR_CSAPISECRET "CSAPISecret"
#define GRB_INT_PAR_CSBATCHMODE "CSBatchMode"
#define GRB_STR_PAR_USERNAME "Username"
#define GRB_STR_PAR_CSAPPNAME "CSAppName"
#define GRB_INT_PAR_CSCLIENTLOG "CSClientLog"
#define GRB_STR_PAR_WLSACCESSID "WLSAccessID"
#define GRB_STR_PAR_WLSSECRET "WLSSecret"
#define GRB_INT_PAR_WLSTOKENDURATION "WLSTokenDuration"
#define GRB_DBL_PAR_WLSTOKENREFRESH "WLSTokenRefresh"
#define GRB_STR_PAR_WLSTOKEN "WLSToken"
#define GRB_INT_PAR_LICENSEID "LicenseID"
#define GRB_INT_PAR_AGGREGATE "Aggregate"
#define GRB_INT_PAR_AGGFILL "AggFill"
#define GRB_INT_PAR_CONCURRENTMIP "ConcurrentMIP"
#define GRB_INT_PAR_CONCURRENTJOBS "ConcurrentJobs"
#define GRB_INT_PAR_DISPLAYINTERVAL "DisplayInterval"
#define GRB_INT_PAR_DISTRIBUTEDMIPJOBS "DistributedMIPJobs"
#define GRB_INT_PAR_DUALREDUCTIONS "DualReductions"
#define GRB_DBL_PAR_FEASRELAXBIGM "FeasRelaxBigM"
#define GRB_INT_PAR_IISMETHOD "IISMethod"
#define GRB_INT_PAR_INFUNBDINFO "InfUnbdInfo"
#define GRB_INT_PAR_JSONSOLDETAIL "JSONSolDetail"
#define GRB_INT_PAR_LAZYCONSTRAINTS "LazyConstraints"
#define GRB_STR_PAR_LOGFILE "LogFile"
#define GRB_INT_PAR_LOGTOCONSOLE "LogToConsole"
#define GRB_INT_PAR_MIQCPMETHOD "MIQCPMethod"
#define GRB_INT_PAR_NONCONVEX "NonConvex"
#define GRB_INT_PAR_NUMERICFOCUS "NumericFocus"
#define GRB_INT_PAR_OUTPUTFLAG "OutputFlag"
#define GRB_INT_PAR_PRECRUSH "PreCrush"
#define GRB_INT_PAR_PREDEPROW "PreDepRow"
#define GRB_INT_PAR_PREDUAL "PreDual"
#define GRB_INT_PAR_PREPASSES "PrePasses"
#define GRB_INT_PAR_PREQLINEARIZE "PreQLinearize"
#define GRB_INT_PAR_PRESOLVE "Presolve"
#define GRB_DBL_PAR_PRESOS1BIGM "PreSOS1BigM"
#define GRB_DBL_PAR_PRESOS2BIGM "PreSOS2BigM"
#define GRB_INT_PAR_PRESOS1ENCODING "PreSOS1Encoding"
#define GRB_INT_PAR_PRESOS2ENCODING "PreSOS2Encoding"
#define GRB_INT_PAR_PRESPARSIFY "PreSparsify"
#define GRB_INT_PAR_PREMIQCPFORM "PreMIQCPForm"
#define GRB_INT_PAR_QCPDUAL "QCPDual"
#define GRB_INT_PAR_RECORD "Record"
#define GRB_STR_PAR_RESULTFILE "ResultFile"
#define GRB_INT_PAR_SEED "Seed"
#define GRB_INT_PAR_SOLUTIONTARGET "SolutionTarget"
#define GRB_INT_PAR_THREADS "Threads"
#define GRB_DBL_PAR_TUNETIMELIMIT "TuneTimeLimit"
#define GRB_INT_PAR_TUNERESULTS "TuneResults"
#define GRB_INT_PAR_TUNECRITERION "TuneCriterion"
#define GRB_INT_PAR_TUNETRIALS "TuneTrials"
#define GRB_INT_PAR_TUNEOUTPUT "TuneOutput"
#define GRB_INT_PAR_TUNEJOBS "TuneJobs"
#define GRB_DBL_PAR_TUNECLEANUP "TuneCleanup"
#define GRB_DBL_PAR_TUNETARGETMIPGAP "TuneTargetMIPGap"
#define GRB_DBL_PAR_TUNETARGETTIME "TuneTargetTime"
#define GRB_INT_PAR_TUNEMETRIC "TuneMetric"
#define GRB_INT_PAR_UPDATEMODE "UpdateMode"
#define GRB_INT_PAR_OBJNUMBER "ObjNumber"
#define GRB_INT_PAR_MULTIOBJMETHOD "MultiObjMethod"
#define GRB_INT_PAR_MULTIOBJPRE "MultiObjPre"
#define GRB_INT_PAR_SCENARIONUMBER "ScenarioNumber"
#define GRB_INT_PAR_POOLSOLUTIONS "PoolSolutions"
#define GRB_DBL_PAR_POOLGAP "PoolGap"
#define GRB_DBL_PAR_POOLGAPABS "PoolGapAbs"
#define GRB_INT_PAR_POOLSEARCHMODE "PoolSearchMode"
#define GRB_INT_PAR_IGNORENAMES "IgnoreNames"
#define GRB_INT_PAR_STARTNUMBER "StartNumber"
#define GRB_INT_PAR_PARTITIONPLACE "PartitionPlace"
#define GRB_INT_PAR_FUNCPIECES "FuncPieces"
#define GRB_DBL_PAR_FUNCPIECELENGTH "FuncPieceLength"
#define GRB_DBL_PAR_FUNCPIECEERROR "FuncPieceError"
#define GRB_DBL_PAR_FUNCPIECERATIO "FuncPieceRatio"
#define GRB_DBL_PAR_FUNCMAXVAL "FuncMaxVal"
#define GRB_STR_PAR_DUMMY "Dummy"
#define GRB_STR_PAR_JOBID "JobID"
#define GRB_CUTS_AUTO -1
#define GRB_CUTS_OFF 0
#define GRB_CUTS_CONSERVATIVE 1
#define GRB_CUTS_AGGRESSIVE 2
#define GRB_CUTS_VERYAGGRESSIVE 3
#define GRB_PRESOLVE_AUTO -1
#define GRB_PRESOLVE_OFF 0
#define GRB_PRESOLVE_CONSERVATIVE 1
#define GRB_PRESOLVE_AGGRESSIVE 2
#define GRB_METHOD_NONE -1
#define GRB_METHOD_AUTO -1
#define GRB_METHOD_PRIMAL 0
#define GRB_METHOD_DUAL 1
#define GRB_METHOD_BARRIER 2
#define GRB_METHOD_CONCURRENT 3
#define GRB_METHOD_DETERMINISTIC_CONCURRENT 4
#define GRB_METHOD_DETERMINISTIC_CONCURRENT_SIMPLEX 5
#define GRB_BARHOMOGENEOUS_AUTO -1
#define GRB_BARHOMOGENEOUS_OFF 0
#define GRB_BARHOMOGENEOUS_ON 1
#define GRB_MIPFOCUS_BALANCED 0
#define GRB_MIPFOCUS_FEASIBILITY 1
#define GRB_MIPFOCUS_OPTIMALITY 2
#define GRB_MIPFOCUS_BESTBOUND 3
#define GRB_BARORDER_AUTOMATIC -1
#define GRB_BARORDER_AMD 0
#define GRB_BARORDER_NESTEDDISSECTION 1
#define GRB_SIMPLEXPRICING_AUTO -1
#define GRB_SIMPLEXPRICING_PARTIAL 0
#define GRB_SIMPLEXPRICING_STEEPEST_EDGE 1
#define GRB_SIMPLEXPRICING_DEVEX 2
#define GRB_SIMPLEXPRICING_STEEPEST_QUICK 3
#define GRB_VARBRANCH_AUTO -1
#define GRB_VARBRANCH_PSEUDO_REDUCED 0
#define GRB_VARBRANCH_PSEUDO_SHADOW 1
#define GRB_VARBRANCH_MAX_INFEAS 2
#define GRB_VARBRANCH_STRONG 3
#define GRB_PARTITION_EARLY 16
#define GRB_PARTITION_ROOTSTART 8
#define GRB_PARTITION_ROOTEND 4
#define GRB_PARTITION_NODES 2
#define GRB_PARTITION_CLEANUP 1
#define GRB_PHASE_MIP_NOREL 0
#define GRB_PHASE_MIP_SEARCH 1
#define GRB_PHASE_MIP_IMPROVE 2
extern std::function<void(GRBmodel *model)> GRBterminate;
extern 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;
extern std::function<int(GRBenv *env, const char *paramname, int *valueP)> GRBgetintparam;
extern std::function<int(GRBenv *env, const char *paramname, double *valueP)> GRBgetdblparam;
extern std::function<int(GRBenv *env, const char *paramname, char *valueP)> GRBgetstrparam;
extern std::function<int(GRBenv *env, const char *paramname, const char *value)> GRBsetparam;
extern std::function<int(GRBenv *env, const char *paramname, int value)> GRBsetintparam;
extern std::function<int(GRBenv *env, const char *paramname, double value)> GRBsetdblparam;
extern std::function<int(GRBenv *env, const char *paramname, const char *value)> GRBsetstrparam;
extern std::function<int(GRBenv *env)> GRBresetparams;
extern std::function<int(GRBenv *dest, GRBenv *src)> GRBcopyparams;
extern std::function<int(GRBenv **envP, const char *logfilename)> GRBloadenv;
extern std::function<int(GRBenv *env)> GRBstartenv;
extern std::function<int(GRBenv **envP)> GRBemptyenv;
extern std::function<int(GRBenv *envP)> GRBgetnumparams;
extern std::function<int(GRBenv *envP, int i, char **paramnameP)> GRBgetparamname;
extern std::function<int(GRBenv *envP, const char *paramname)> GRBgetparamtype;
extern std::function<int(GRBenv *envP, const char *paramname, int *valueP, int *minP, int *maxP, int *defP)> GRBgetintparaminfo;
extern std::function<int(GRBenv *envP, const char *paramname, double *valueP, double *minP, double *maxP, double *defP)> GRBgetdblparaminfo;
extern std::function<int(GRBenv *envP, const char *paramname, char *valueP, char *defP)> GRBgetstrparaminfo;
extern std::function<GRBenv *(GRBmodel *model)> GRBgetenv;
extern std::function<GRBenv*(GRBmodel* model, int num)> GRBgetmultiobjenv;
extern std::function<GRBenv*(GRBmodel* model)> GRBdiscardmultiobjenvs;
extern std::function<void(GRBenv *env)> GRBfreeenv;
extern std::function<const char *(GRBenv *env)> GRBgeterrormsg;
extern std::function<void(int *majorP, int *minorP, int *technicalP)> GRBversion;
extern std::function<char *(void)> GRBplatform;
#define GRB_BATCH_STATUS_UNKNOWN 0
#define GRB_BATCH_CREATED 1
#define GRB_BATCH_SUBMITTED 2
#define GRB_BATCH_ABORTED 3
#define GRB_BATCH_FAILED 4
#define GRB_BATCH_COMPLETED 5
// clang-format on
} // namespace operations_research
#endif // THIRD_PARTY_ORTOOLS_ORTOOLS_THIRD_PARTY_SOLVERS_GUROBI_ENVIRONMENT_H_

View File

@@ -0,0 +1,280 @@
# Copyright 2010-2025 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
r"""Gurobi header parser script to generate code for the environment.{cc|h}.
To use, run the script
copy gurobi_c.h somewhere.
edit the file and add the signature for the GRBisqp:
int __stdcall
GRBisqp(GRBenv**, const char*, const char*, const char*, int, const char*);
blaze run \
ortools/third_party_solvers/gurobi_parse_header \
-- <path to gurobi_c.h>
It will output all methods defined in the EXPORTED_FUNCTIONS field, and all
defined symbols.
The list of symbols to export is found by the following command:
grep -oh -e "GRB[A-Za-z0-9_]*" <path_to>/gurobi_interface.cc \
<path_to>/gurobi_proto_solver.* <path_to>/math_opt/solvers/gurobi* \
<path_to>/math_opt/solvers/gurobi/g_gurobi* | sort -u
This will printout on the console 3 sections:
------------------- header -------------------
to copy paste in environment.h
------------------- define -------------------
to copy in the define part of environment.cc
------------------- assign -------------------
to copy in the assign part of environment.cc
"""
import re
from typing import Sequence
from absl import app
EXPORTED_FUNCTIONS = frozenset(
[
"GRBaddconstr",
"GRBaddconstrs",
"GRBaddgenconstrAbs",
"GRBaddgenconstrAnd",
"GRBaddgenconstrIndicator",
"GRBaddgenconstrMax",
"GRBaddgenconstrMin",
"GRBaddgenconstrOr",
"GRBaddqconstr",
"GRBaddqpterms",
"GRBaddrangeconstr",
"GRBaddsos",
"GRBaddvar",
"GRBaddvars",
"GRBcbcut",
"GRBcbget",
"GRBcblazy",
"GRBcbsolution",
"GRBchgcoeffs",
"GRBcopyparams",
"GRBdelconstrs",
"GRBdelgenconstrs",
"GRBdelq",
"GRBdelqconstrs",
"GRBdelsos",
"GRBdelvars",
"GRBenv",
"GRBenvUniquePtr",
"GRBemptyenv",
"GRBgetnumparams",
"GRBgetparamtype",
"GRBgetparamname",
"GRBgetintparaminfo",
"GRBgetdblparaminfo",
"GRBgetstrparaminfo",
"GRBfreeenv",
"GRBfreemodel",
"GRBgetcharattrarray",
"GRBgetcharattrelement",
"GRBgetdblattr",
"GRBgetdblattrarray",
"GRBgetdblattrelement",
"GRBgetdblparam",
"GRBgetenv",
"GRBgeterrormsg",
"GRBgetintattr",
"GRBgetintattrarray",
"GRBgetintattrelement",
"GRBgetintparam",
"GRBgetstrattr",
"GRBgetstrparam",
"GRBgetvars",
"GRBisattravailable",
"GRBisqp",
"GRBloadenv",
"GRBmodel",
"GRBnewmodel",
"GRBoptimize",
"GRBcomputeIIS",
"GRBplatform",
"GRBresetparams",
"GRBsetcallbackfunc",
"GRBsetcharattrarray",
"GRBsetcharattrelement",
"GRBsetcharattrlist",
"GRBsetdblattr",
"GRBsetdblattrarray",
"GRBsetdblattrelement",
"GRBsetdblattrlist",
"GRBsetdblparam",
"GRBsetintattr",
"GRBsetintattrarray",
"GRBsetintattrelement",
"GRBsetintattrlist",
"GRBsetintparam",
"GRBsetobjectiven",
"GRBsetparam",
"GRBsetstrattr",
"GRBsetstrparam",
"GRBterminate",
"GRBupdatemodel",
"GRBversion",
"GRBwrite",
]
)
# TODO(user): Filter #define too.
class GurobiHeaderParser:
"""Converts gurobi_c.h to something pastable in ./environment.h|.cc."""
def __init__(self):
self.__header = ""
self.__define = ""
self.__assign = ""
self.__state = 0
self.__return_type = ""
self.__args = ""
self.__fun_name = ""
def should_be_exported(self, name: str) -> bool:
return name in EXPORTED_FUNCTIONS
def write_define(self, symbol: str, value: str) -> None:
self.__header += f"#define {symbol} {value}\n"
def write_fun(self, name: str, return_type: str, args: str) -> None:
if not self.should_be_exported(name):
print("skipping " + name)
return
self.__header += f"extern std::function<{return_type}({args})> {name};\n"
self.__define += f"std::function<{return_type}({args})> {name} = nullptr;\n"
self.__assign += f" gurobi_dynamic_library->GetFunction(&{name}, "
self.__assign += f'"{name}");\n'
def parse(self, filepath: str) -> None:
"""Main method to parser the gurobi header."""
with open(filepath) as fp:
all_lines = fp.read()
for line in all_lines.splitlines():
if not line: # Ignore empty lines.
continue
if re.fullmatch(r"/\*", line, re.M): # Ignore comments.
continue
if self.__state == 0:
# Note: fullmatch does not work.
match_def = re.match(r"#define ([A-Z0-9_]*)\s+([^/]+)", line, re.M)
if match_def:
self.write_define(match_def.group(1), match_def.group(2))
continue
# Single line function definition.
match_fun = re.fullmatch(
r"([a-z]+) __stdcall (GRB[A-Za-z_]*)\(([^;]*)\);", line, re.M
)
if match_fun:
self.write_fun(
match_fun.group(1), match_fun.group(2), match_fun.group(3)
)
continue
# Simple type declaration (i.e. int __stdcall).
match_fun = re.fullmatch(r"([a-z]+) __stdcall\s*$", line, re.M)
if match_fun:
self.__return_type = match_fun.group(1)
self.__state = 1
continue
# Complex type declaration with pointer (i.e. GRBModel* __stdcall).
match_fun = re.fullmatch(r"([A-Za-z ]+)\*\s*__stdcall\s*$", line, re.M)
if match_fun:
self.__return_type = match_fun.group(1) + "*"
self.__state = 1
continue
elif self.__state == 1: # The return type was defined at the line before.
# Function definition terminates in this line.
match_fun = re.fullmatch(r"\s*(GRB[A-Za-z_]*)\(([^;]+)\);", line, re.M)
if match_fun:
self.write_fun(
match_fun.group(1), self.__return_type, match_fun.group(2)
)
self.__state = 0
self.__return_type = ""
continue
# Function definition does not terminate in this line.
match_fun = re.fullmatch(r"\s*(GRB[A-Za-z_]*)\(([^;]+)$", line, re.M)
if match_fun:
self.__fun_name = match_fun.group(1)
self.__args = match_fun.group(2)
self.__state = 2
continue
elif self.__state == 2: # Extra arguments.
# Arguments end in this line.
match_fun = re.fullmatch(r"\s*([^;]+)\);", line, re.M)
if match_fun:
self.__args += match_fun.group(1)
self.write_fun(self.__fun_name, self.__return_type, self.__args)
self.__args = ""
self.__fun_name = ""
self.__return_type = ""
self.__state = 0
continue
# Arguments do not end in this line.
match_fun = re.fullmatch(r"\s*([^;]+)$", line, re.M)
if match_fun:
self.__args += match_fun.group(1)
continue
def output(self) -> None:
"""Output the 3 generated code on standard out."""
# replace __stdcall by GUROBI_STDCALL.
self.__header = self.__header.replace("__stdcall", "GUROBI_STDCALL")
self.__define = self.__define.replace("__stdcall", "GUROBI_STDCALL")
print("------------------- header -------------------")
print(self.__header)
print("------------------- define -------------------")
print(self.__define)
print("------------------- assign -------------------")
print(self.__assign)
def main(argv: Sequence[str]) -> None:
if len(argv) > 2:
raise app.UsageError("Too many command-line arguments.")
if len(argv) == 1:
raise app.UsageError("Please supply path to gurobi_c.h on the command line.")
parser = GurobiHeaderParser()
parser.parse(argv[1])
parser.output()
if __name__ == "__main__":
app.run(main)

View File

@@ -0,0 +1,389 @@
// Copyright 2010-2025 Google LLC
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Initial version of this code was provided by RTE
#include "ortools/third_party_solvers/xpress_environment.h"
#include <cstdlib>
// NOLINTNEXTLINE(build/c++17)
#include <filesystem>
#include <functional>
#include <string>
#include <vector>
#include "absl/base/call_once.h"
#include "absl/base/const_init.h"
#include "absl/status/status.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_join.h"
#include "absl/synchronization/mutex.h"
#include "ortools/base/logging.h"
#include "ortools/third_party_solvers/dynamic_library.h"
namespace operations_research {
#define STRINGIFY2(X) #X
#define STRINGIFY(X) STRINGIFY2(X)
// Let's not reformat for rest of the file.
// This was generated with the parse_header_xpress.py script.
// See the comment at the top of the script.
// This is the 'define' section.
// NOLINTBEGIN(whitespace/line_length)
// NOLINTBEGIN(google3-runtime-global-variables)
// clang-format off
std::function<int(XPRSprob* p_prob)> XPRScreateprob = nullptr;
std::function<int(XPRSprob prob)> XPRSdestroyprob = nullptr;
std::function<int(const char* path)> XPRSinit = nullptr;
std::function<int(void)> XPRSfree = nullptr;
std::function<int(char* buffer, int maxbytes)> XPRSgetlicerrmsg = nullptr;
std::function<int(int* p_i, char* p_c)> XPRSlicense = nullptr;
std::function<int(char* banner)> XPRSgetbanner = nullptr;
std::function<int(char* version)> XPRSgetversion = nullptr;
std::function<int(XPRSprob prob, const char* probname)> XPRSsetprobname = nullptr;
std::function<int(XPRSprob prob, int control)> XPRSsetdefaultcontrol = nullptr;
std::function<int(XPRSprob prob, int reason)> XPRSinterrupt = nullptr;
std::function<int(XPRSprob prob, int control, int value)> XPRSsetintcontrol = nullptr;
std::function<int(XPRSprob prob, int control, XPRSint64 value)> XPRSsetintcontrol64 = nullptr;
std::function<int(XPRSprob prob, int control, double value)> XPRSsetdblcontrol = nullptr;
std::function<int(XPRSprob prob, int control, const char* value)> XPRSsetstrcontrol = nullptr;
std::function<int(XPRSprob prob, int control, int* p_value)> XPRSgetintcontrol = nullptr;
std::function<int(XPRSprob prob, int control, XPRSint64* p_value)> XPRSgetintcontrol64 = nullptr;
std::function<int(XPRSprob prob, int control, double* p_value)> XPRSgetdblcontrol = nullptr;
std::function<int(XPRSprob prob, int control, char* value, int maxbytes, int* p_nbytes)> XPRSgetstringcontrol = nullptr;
std::function<int(XPRSprob prob, int attrib, int* p_value)> XPRSgetintattrib = nullptr;
std::function<int(XPRSprob prob, int attrib, char* value, int maxbytes, int* p_nbytes)> XPRSgetstringattrib = nullptr;
std::function<int(XPRSprob prob, int attrib, double* p_value)> XPRSgetdblattrib = nullptr;
std::function<int(XPRSprob prob, const char* name, int* p_id, int* p_type)> XPRSgetcontrolinfo = nullptr;
std::function<int(XPRSprob prob, double objcoef[], int first, int last)> XPRSgetobj = nullptr;
std::function<int(XPRSprob prob, double rhs[], int first, int last)> XPRSgetrhs = nullptr;
std::function<int(XPRSprob prob, double rng[], int first, int last)> XPRSgetrhsrange = nullptr;
std::function<int(XPRSprob prob, double lb[], int first, int last)> XPRSgetlb = nullptr;
std::function<int(XPRSprob prob, double ub[], int first, int last)> XPRSgetub = nullptr;
std::function<int(XPRSprob prob, int row, int col, double* p_coef)> XPRSgetcoef = nullptr;
std::function<int(XPRSprob prob, int* status, double duals[], int first, int last)> XPRSgetduals = nullptr;
std::function<int(XPRSprob prob, int* status, double djs[], int first, int last)> XPRSgetredcosts = nullptr;
std::function<int(XPRSprob prob, int nrows, int ncoefs, const char rowtype[], const double rhs[], const double rng[], const int start[], const int colind[], const double rowcoef[])> XPRSaddrows = nullptr;
std::function<int(XPRSprob prob, int nrows, const int rowind[])> XPRSdelrows = nullptr;
std::function<int(XPRSprob prob, int ncols, int ncoefs, const double objcoef[], const int start[], const int rowind[], const double rowcoef[], const double lb[], const double ub[])> XPRSaddcols = nullptr;
std::function<int(XPRSprob prob, int type, const char names[], int first, int last)> XPRSaddnames = nullptr;
std::function<int(XPRSprob prob, int type, char names[], int first, int last)> XPRSgetnames = nullptr;
std::function<int(XPRSprob prob, int ncols, const int colind[])> XPRSdelcols = nullptr;
std::function<int(XPRSprob prob, int ncols, const int colind[], const char coltype[])> XPRSchgcoltype = nullptr;
std::function<int(XPRSprob prob, const int rowstat[], const int colstat[])> XPRSloadbasis = nullptr;
std::function<int(XPRSprob prob)> XPRSpostsolve = nullptr;
std::function<int(XPRSprob prob, int objsense)> XPRSchgobjsense = nullptr;
std::function<int(XPRSprob prob, char* errmsg)> XPRSgetlasterror = nullptr;
std::function<int(XPRSprob prob, int rowstat[], int colstat[])> XPRSgetbasis = nullptr;
std::function<int(XPRSprob prob, const char* filename, const char* flags)> XPRSwriteprob = nullptr;
std::function<int(XPRSprob prob, char rowtype[], int first, int last)> XPRSgetrowtype = nullptr;
std::function<int(XPRSprob prob, char coltype[], int first, int last)> XPRSgetcoltype = nullptr;
std::function<int(XPRSprob prob, int nbounds, const int colind[], const char bndtype[], const double bndval[])> XPRSchgbounds = nullptr;
std::function<int(XPRSprob prob, int length, const double solval[], const int colind[], const char* name)> XPRSaddmipsol = nullptr;
std::function<int(XPRSprob prob, double x[], double slack[], double duals[], double djs[])> XPRSgetlpsol = nullptr;
std::function<int(XPRSprob prob, double x[], double slack[])> XPRSgetmipsol = nullptr;
std::function<int(XPRSprob prob, int ncols, const int colind[], const double objcoef[])> XPRSchgobj = nullptr;
std::function<int(XPRSprob prob, int row, int col, double coef)> XPRSchgcoef = nullptr;
std::function<int(XPRSprob prob, int ncoefs, const int rowind[], const int colind[], const double rowcoef[])> XPRSchgmcoef = nullptr;
std::function<int(XPRSprob prob, XPRSint64 ncoefs, const int rowind[], const int colind[], const double rowcoef[])> XPRSchgmcoef64 = nullptr;
std::function<int(XPRSprob prob, int ncoefs, const int objqcol1[], const int objqcol2[], const double objqcoef[])> XPRSchgmqobj = nullptr;
std::function<int(XPRSprob prob, int nrows, const int rowind[], const double rhs[])> XPRSchgrhs = nullptr;
std::function<int(XPRSprob prob, int nrows, const int rowind[], const double rng[])> XPRSchgrhsrange = nullptr;
std::function<int(XPRSprob prob, int nrows, const int rowind[], const char rowtype[])> XPRSchgrowtype = nullptr;
std::function<int(XPRSprob prob, int objidx)> XPRSdelobj = nullptr;
std::function<int(XPRSprob prob, void (XPRS_CC *f_intsol)(XPRSprob cbprob, void* cbdata), void* p, int priority)> XPRSaddcbintsol = nullptr;
std::function<int(XPRSprob prob, void (XPRS_CC *f_intsol)(XPRSprob cbprob, void* cbdata), void* p)> XPRSremovecbintsol = nullptr;
std::function<int(XPRSprob prob, void (XPRS_CC *f_message)(XPRSprob cbprob, void* cbdata, const char* msg, int msglen, int msgtype), void* p, int priority)> XPRSaddcbmessage = nullptr;
std::function<int(XPRSprob prob, const char* flags)> XPRSlpoptimize = nullptr;
std::function<int(XPRSprob prob, const char* flags)> XPRSmipoptimize = nullptr;
std::function<int(XPRSprob prob, const char* flags, int* solvestatus, int* solstatus)> XPRSoptimize = nullptr;
// clang-format on
// NOLINTEND(google3-runtime-global-variables)
// NOLINTEND(whitespace/line_length)
void LoadXpressFunctions(DynamicLibrary* xpress_dynamic_library) {
// This was generated with the parse_header_xpress.py script.
// See the comment at the top of the script.
// This is the 'assign' section.
// NOLINTBEGIN(whitespace/line_length)
// clang-format off
xpress_dynamic_library->GetFunction(&XPRScreateprob, "XPRScreateprob");
xpress_dynamic_library->GetFunction(&XPRSdestroyprob, "XPRSdestroyprob");
xpress_dynamic_library->GetFunction(&XPRSinit, "XPRSinit");
xpress_dynamic_library->GetFunction(&XPRSfree, "XPRSfree");
xpress_dynamic_library->GetFunction(&XPRSgetlicerrmsg, "XPRSgetlicerrmsg");
xpress_dynamic_library->GetFunction(&XPRSlicense, "XPRSlicense");
xpress_dynamic_library->GetFunction(&XPRSgetbanner, "XPRSgetbanner");
xpress_dynamic_library->GetFunction(&XPRSgetversion, "XPRSgetversion");
xpress_dynamic_library->GetFunction(&XPRSsetprobname, "XPRSsetprobname");
xpress_dynamic_library->GetFunction(&XPRSsetdefaultcontrol, "XPRSsetdefaultcontrol");
xpress_dynamic_library->GetFunction(&XPRSinterrupt, "XPRSinterrupt");
xpress_dynamic_library->GetFunction(&XPRSsetintcontrol, "XPRSsetintcontrol");
xpress_dynamic_library->GetFunction(&XPRSsetintcontrol64, "XPRSsetintcontrol64");
xpress_dynamic_library->GetFunction(&XPRSsetdblcontrol, "XPRSsetdblcontrol");
xpress_dynamic_library->GetFunction(&XPRSsetstrcontrol, "XPRSsetstrcontrol");
xpress_dynamic_library->GetFunction(&XPRSgetintcontrol, "XPRSgetintcontrol");
xpress_dynamic_library->GetFunction(&XPRSgetintcontrol64, "XPRSgetintcontrol64");
xpress_dynamic_library->GetFunction(&XPRSgetdblcontrol, "XPRSgetdblcontrol");
xpress_dynamic_library->GetFunction(&XPRSgetstringcontrol, "XPRSgetstringcontrol");
xpress_dynamic_library->GetFunction(&XPRSgetintattrib, "XPRSgetintattrib");
xpress_dynamic_library->GetFunction(&XPRSgetstringattrib, "XPRSgetstringattrib");
xpress_dynamic_library->GetFunction(&XPRSgetdblattrib, "XPRSgetdblattrib");
xpress_dynamic_library->GetFunction(&XPRSgetobj, "XPRSgetobj");
xpress_dynamic_library->GetFunction(&XPRSgetrhs, "XPRSgetrhs");
xpress_dynamic_library->GetFunction(&XPRSgetrhsrange, "XPRSgetrhsrange");
xpress_dynamic_library->GetFunction(&XPRSgetlb, "XPRSgetlb");
xpress_dynamic_library->GetFunction(&XPRSgetub, "XPRSgetub");
xpress_dynamic_library->GetFunction(&XPRSgetcoef, "XPRSgetcoef");
xpress_dynamic_library->GetFunction(&XPRSgetduals, "XPRSgetduals");
xpress_dynamic_library->GetFunction(&XPRSgetredcosts, "XPRSgetredcosts");
xpress_dynamic_library->GetFunction(&XPRSaddrows, "XPRSaddrows");
xpress_dynamic_library->GetFunction(&XPRSdelrows, "XPRSdelrows");
xpress_dynamic_library->GetFunction(&XPRSaddcols, "XPRSaddcols");
xpress_dynamic_library->GetFunction(&XPRSaddnames, "XPRSaddnames");
xpress_dynamic_library->GetFunction(&XPRSgetnames, "XPRSgetnames");
xpress_dynamic_library->GetFunction(&XPRSdelcols, "XPRSdelcols");
xpress_dynamic_library->GetFunction(&XPRSchgcoltype, "XPRSchgcoltype");
xpress_dynamic_library->GetFunction(&XPRSloadbasis, "XPRSloadbasis");
xpress_dynamic_library->GetFunction(&XPRSpostsolve, "XPRSpostsolve");
xpress_dynamic_library->GetFunction(&XPRSchgobjsense, "XPRSchgobjsense");
xpress_dynamic_library->GetFunction(&XPRSgetlasterror, "XPRSgetlasterror");
xpress_dynamic_library->GetFunction(&XPRSgetbasis, "XPRSgetbasis");
xpress_dynamic_library->GetFunction(&XPRSwriteprob, "XPRSwriteprob");
xpress_dynamic_library->GetFunction(&XPRSgetrowtype, "XPRSgetrowtype");
xpress_dynamic_library->GetFunction(&XPRSgetcoltype, "XPRSgetcoltype");
xpress_dynamic_library->GetFunction(&XPRSchgbounds, "XPRSchgbounds");
xpress_dynamic_library->GetFunction(&XPRSaddmipsol, "XPRSaddmipsol");
xpress_dynamic_library->GetFunction(&XPRSgetlpsol, "XPRSgetlpsol");
xpress_dynamic_library->GetFunction(&XPRSgetmipsol, "XPRSgetmipsol");
xpress_dynamic_library->GetFunction(&XPRSchgobj, "XPRSchgobj");
xpress_dynamic_library->GetFunction(&XPRSchgcoef, "XPRSchgcoef");
xpress_dynamic_library->GetFunction(&XPRSchgmcoef, "XPRSchgmcoef");
xpress_dynamic_library->GetFunction(&XPRSchgmcoef64, "XPRSchgmcoef64");
xpress_dynamic_library->GetFunction(&XPRSchgmqobj, "XPRSchgmqobj");
xpress_dynamic_library->GetFunction(&XPRSchgrhs, "XPRSchgrhs");
xpress_dynamic_library->GetFunction(&XPRSchgrhsrange, "XPRSchgrhsrange");
xpress_dynamic_library->GetFunction(&XPRSchgrowtype, "XPRSchgrowtype");
xpress_dynamic_library->GetFunction(&XPRSdelobj, "XPRSdelobj");
xpress_dynamic_library->GetFunction(&XPRSaddcbintsol, "XPRSaddcbintsol");
xpress_dynamic_library->GetFunction(&XPRSremovecbintsol, "XPRSremovecbintsol");
xpress_dynamic_library->GetFunction(&XPRSaddcbmessage, "XPRSaddcbmessage");
xpress_dynamic_library->GetFunction(&XPRSlpoptimize, "XPRSlpoptimize");
xpress_dynamic_library->GetFunction(&XPRSmipoptimize, "XPRSmipoptimize");
xpress_dynamic_library->GetFunction(&XPRSoptimize, "XPRSoptimize");
// clang-format on
// NOLINTEND(whitespace/line_length)
}
void printXpressBanner(bool error) {
char banner[XPRS_MAXBANNERLENGTH];
XPRSgetbanner(banner);
if (error) {
LOG(ERROR) << "XpressInterface : Xpress banner :\n" << banner << "\n";
} else {
LOG(WARNING) << "XpressInterface : Xpress banner :\n" << banner << "\n";
}
}
std::vector<std::string> XpressDynamicLibraryPotentialPaths() {
std::vector<std::string> potential_paths;
// Look for libraries pointed by XPRESSDIR first.
const char* xpressdir_from_env = getenv("XPRESSDIR");
if (xpressdir_from_env != nullptr) {
LOG(INFO) << "Environment variable XPRESSDIR = " << xpressdir_from_env;
#if defined(_MSC_VER) // Windows
potential_paths.push_back(
absl::StrCat(xpressdir_from_env, "\\bin\\xprs.dll"));
#elif defined(__APPLE__) // macOS
potential_paths.push_back(
absl::StrCat(xpressdir_from_env, "/lib/libxprs.dylib"));
#elif defined(__GNUC__) // Linux
potential_paths.push_back(
absl::StrCat(xpressdir_from_env, "/lib/libxprs.so"));
#else
LOG(ERROR) << "OS Not recognized by xpress_environment.cc."
<< " You won't be able to use Xpress.";
#endif
} else {
LOG(WARNING) << "Environment variable XPRESSDIR undefined.";
}
// Search for canonical places.
#if defined(_MSC_VER) // Windows
potential_paths.push_back(absl::StrCat("C:\\xpressmp\\bin\\xprs.dll"));
potential_paths.push_back(
absl::StrCat("C:\\Program Files\\xpressmp\\bin\\xprs.dll"));
#elif defined(__APPLE__) // macOS
potential_paths.push_back(
absl::StrCat("/Library/xpressmp/lib/libxprs.dylib"));
#elif defined(__GNUC__) // Linux
potential_paths.push_back(absl::StrCat("/opt/xpressmp/lib/libxprs.so"));
#else
LOG(ERROR) << "OS Not recognized by xpress_environment.cc."
<< " You won't be able to use Xpress.";
#endif
return potential_paths;
}
absl::Status LoadXpressDynamicLibrary(std::string& xpresspath) {
static std::string* xpress_lib_path = new std::string;
static absl::once_flag xpress_loading_done;
static absl::Status* xpress_load_status = new absl::Status;
static DynamicLibrary* xpress_library = new DynamicLibrary;
static absl::Mutex mutex(absl::kConstInit);
absl::MutexLock lock(&mutex);
absl::call_once(xpress_loading_done, []() {
const std::vector<std::string> canonical_paths =
XpressDynamicLibraryPotentialPaths();
for (const std::string& path : canonical_paths) {
if (xpress_library->TryToLoad(path)) {
LOG(INFO) << "Found the Xpress library in " << path << ".";
xpress_lib_path->clear();
std::filesystem::path p(path);
p.remove_filename();
xpress_lib_path->append(p.string());
break;
}
}
if (xpress_library->LibraryIsLoaded()) {
LOG(INFO) << "Loading all Xpress functions";
LoadXpressFunctions(xpress_library);
*xpress_load_status = absl::OkStatus();
} else {
*xpress_load_status = absl::NotFoundError(
absl::StrCat("Could not find the Xpress shared library. Looked in: [",
absl::StrJoin(canonical_paths, "', '"),
"]. Please check environment variable XPRESSDIR"));
}
});
xpresspath.clear();
xpresspath.append(*xpress_lib_path);
return *xpress_load_status;
}
void log_message_about_XPRSinit_argument();
void log_full_license_error(int code, const std::string& xpress_lib_dir);
//! init XPRESS environment.
bool initXpressEnv(bool verbose, int xpress_oem_license_key) {
std::string xpress_lib_dir;
absl::Status status = LoadXpressDynamicLibrary(xpress_lib_dir);
if (!status.ok()) {
LOG(WARNING) << status << "\n";
return false;
}
int code;
// if not an OEM key
if (xpress_oem_license_key == 0) {
if (verbose) {
log_message_about_XPRSinit_argument();
}
code = XPRSinit(nullptr);
if (!code) {
// XPRSbanner informs about Xpress version, options and error messages
if (verbose) {
printXpressBanner(false);
char version[16];
XPRSgetversion(version);
LOG(WARNING) << "Optimizer version: " << version
<< " (OR-Tools was compiled with version " << XPVERSION
<< ").";
}
return true;
} else {
log_full_license_error(code, xpress_lib_dir);
return false;
}
} else {
// if OEM key
if (verbose) {
LOG(WARNING) << "XpressInterface : Initialising xpress-MP with OEM key "
<< xpress_oem_license_key;
}
int nvalue = 0;
int ierr;
char slicmsg[256] = "";
char errmsg[256];
XPRSlicense(&nvalue, slicmsg);
if (verbose) {
DLOG(INFO) << "XpressInterface : First message from XPRSLicense : "
<< slicmsg;
}
nvalue = xpress_oem_license_key - ((nvalue * nvalue) / 19);
ierr = XPRSlicense(&nvalue, slicmsg);
if (verbose) {
DLOG(INFO) << "XpressInterface : Second message from XPRSLicense : "
<< slicmsg;
}
if (ierr == 16) {
if (verbose) {
DLOG(INFO)
<< "XpressInterface : Optimizer development software detected";
}
} else if (ierr != 0) {
// get the license error message
XPRSgetlicerrmsg(errmsg, 256);
LOG(ERROR) << "XpressInterface : " << errmsg;
return false;
}
code = XPRSinit(nullptr);
if (!code) {
return true;
} else {
LOG(ERROR) << "XPRSinit returned code : " << code << "\n";
return false;
}
}
}
void log_full_license_error(int code, const std::string& xpress_lib_dir) {
LOG(WARNING) << "XpressInterface: Xpress found at " << xpress_lib_dir << "\n";
char errmsg[256];
XPRSgetlicerrmsg(errmsg, 256);
LOG(ERROR) << "XpressInterface : License error : " << errmsg
<< " (XPRSinit returned code " << code << "). \n";
LOG(ERROR)
<< "|_Your Xpress installation should have set the env var XPAUTH_PATH"
" to the full path of your licence file\n";
}
void log_message_about_XPRSinit_argument() {
LOG(WARNING)
<< "XpressInterface : Initialising xpress-MP with default parameters";
}
bool XpressIsCorrectlyInstalled() {
bool correctlyInstalled = initXpressEnv(false);
if (correctlyInstalled) {
XPRSfree();
}
return correctlyInstalled;
}
} // namespace operations_research

View File

@@ -0,0 +1,550 @@
// Copyright 2010-2025 Google LLC
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Initial version of this code was provided by RTE
#ifndef THIRD_PARTY_ORTOOLS_ORTOOLS_THIRD_PARTY_SOLVERS_XPRESS_ENVIRONMENT_H_
#define THIRD_PARTY_ORTOOLS_ORTOOLS_THIRD_PARTY_SOLVERS_XPRESS_ENVIRONMENT_H_
#include <functional>
#include <string>
#include "absl/status/status.h"
#include "ortools/base/base_export.h"
extern "C" {
typedef struct xo_prob_struct* XPRSprob;
}
namespace operations_research {
void printXpressBanner(bool error);
bool initXpressEnv(bool verbose = true, int xpress_oem_license_key = 0);
bool XpressIsCorrectlyInstalled();
// Force the loading of the xpress dynamic library. It returns true if the
// library was successfully loaded. This method can only be called once.
// Successive calls are no-op.
//
// Note that it does not check if a token license can be grabbed.
absl::Status LoadXpressDynamicLibrary(std::string& xpresspath);
// The list of #define and extern std::function<> below is generated directly
// from xprs.h via parse_header_xpress.py
// See the top comment on the parse_header_xpress.py file.
// This is the header section
// NOLINTBEGIN(runtime/int)
#if defined(_WIN32)
#define XPRSint64 __int64
#elif defined(__LP64__) || defined(_LP64) || defined(__ILP64__) || \
defined(_ILP64)
#define XPRSint64 long
#else
#define XPRSint64 long long
#endif
// NOLINTEND(runtime/int)
#if defined(_MSC_VER)
#define XPRS_CC __stdcall
#else
#define XPRS_CC
#endif
// ***************************************************************************
// * values related to XPRSinterrupt *
// ***************************************************************************
#define XPRS_STOP_NONE 0
#define XPRS_STOP_TIMELIMIT 1
#define XPRS_STOP_CTRLC 2
#define XPRS_STOP_NODELIMIT 3
#define XPRS_STOP_ITERLIMIT 4
#define XPRS_STOP_MIPGAP 5
#define XPRS_STOP_SOLLIMIT 6
#define XPRS_STOP_GENERICERROR 7
#define XPRS_STOP_MEMORYERROR 8
#define XPRS_STOP_USER 9
#define XPRS_STOP_SOLVECOMPLETE 10
#define XPRS_STOP_LICENSELOST 11
#define XPRS_STOP_NUMERICALERROR 13
// ***************************************************************************
// * values related to Set/GetControl/Attribinfo *
// ***************************************************************************
#define XPRS_TYPE_NOTDEFINED 0
#define XPRS_TYPE_INT 1
#define XPRS_TYPE_INT64 2
#define XPRS_TYPE_DOUBLE 3
#define XPRS_TYPE_STRING 4
// ***************************************************************************
// * values related to NAMESPACES *
// ***************************************************************************
#define XPRS_NAMES_ROW 1
#define XPRS_NAMES_COLUMN 2
#define XPRS_PLUSINFINITY 1.0e+20
#define XPRS_MINUSINFINITY -1.0e+20
#define XPRS_MAXBANNERLENGTH 512
#define XPVERSION 41
#define XPRS_MPSRHSNAME 6001
#define XPRS_MPSOBJNAME 6002
#define XPRS_MPSRANGENAME 6003
#define XPRS_MPSBOUNDNAME 6004
#define XPRS_OUTPUTMASK 6005
#define XPRS_TUNERMETHODFILE 6017
#define XPRS_TUNEROUTPUTPATH 6018
#define XPRS_TUNERSESSIONNAME 6019
#define XPRS_COMPUTEEXECSERVICE 6022
#define XPRS_MAXCUTTIME 8149
#define XPRS_MAXSTALLTIME 8443
#define XPRS_TUNERMAXTIME 8364
#define XPRS_MATRIXTOL 7001
#define XPRS_PIVOTTOL 7002
#define XPRS_FEASTOL 7003
#define XPRS_OUTPUTTOL 7004
#define XPRS_SOSREFTOL 7005
#define XPRS_OPTIMALITYTOL 7006
#define XPRS_ETATOL 7007
#define XPRS_RELPIVOTTOL 7008
#define XPRS_MIPTOL 7009
#define XPRS_MIPTOLTARGET 7010
#define XPRS_BARPERTURB 7011
#define XPRS_MIPADDCUTOFF 7012
#define XPRS_MIPABSCUTOFF 7013
#define XPRS_MIPRELCUTOFF 7014
#define XPRS_PSEUDOCOST 7015
#define XPRS_PENALTY 7016
#define XPRS_BIGM 7018
#define XPRS_MIPABSSTOP 7019
#define XPRS_MIPRELSTOP 7020
#define XPRS_CROSSOVERACCURACYTOL 7023
#define XPRS_PRIMALPERTURB 7024
#define XPRS_DUALPERTURB 7025
#define XPRS_BAROBJSCALE 7026
#define XPRS_BARRHSSCALE 7027
#define XPRS_CHOLESKYTOL 7032
#define XPRS_BARGAPSTOP 7033
#define XPRS_BARDUALSTOP 7034
#define XPRS_BARPRIMALSTOP 7035
#define XPRS_BARSTEPSTOP 7036
#define XPRS_ELIMTOL 7042
#define XPRS_MARKOWITZTOL 7047
#define XPRS_MIPABSGAPNOTIFY 7064
#define XPRS_MIPRELGAPNOTIFY 7065
#define XPRS_BARLARGEBOUND 7067
#define XPRS_PPFACTOR 7069
#define XPRS_REPAIRINDEFINITEQMAX 7071
#define XPRS_BARGAPTARGET 7073
#define XPRS_DUMMYCONTROL 7075
#define XPRS_BARSTARTWEIGHT 7076
#define XPRS_BARFREESCALE 7077
#define XPRS_SBEFFORT 7086
#define XPRS_HEURDIVERANDOMIZE 7089
#define XPRS_HEURSEARCHEFFORT 7090
#define XPRS_CUTFACTOR 7091
#define XPRS_EIGENVALUETOL 7097
#define XPRS_INDLINBIGM 7099
#define XPRS_TREEMEMORYSAVINGTARGET 7100
#define XPRS_INDPRELINBIGM 7102
#define XPRS_RELAXTREEMEMORYLIMIT 7105
#define XPRS_MIPABSGAPNOTIFYOBJ 7108
#define XPRS_MIPABSGAPNOTIFYBOUND 7109
#define XPRS_PRESOLVEMAXGROW 7110
#define XPRS_HEURSEARCHTARGETSIZE 7112
#define XPRS_CROSSOVERRELPIVOTTOL 7113
#define XPRS_CROSSOVERRELPIVOTTOLSAFE 7114
#define XPRS_DETLOGFREQ 7116
#define XPRS_MAXIMPLIEDBOUND 7120
#define XPRS_FEASTOLTARGET 7121
#define XPRS_OPTIMALITYTOLTARGET 7122
#define XPRS_PRECOMPONENTSEFFORT 7124
#define XPRS_LPLOGDELAY 7127
#define XPRS_HEURDIVEITERLIMIT 7128
#define XPRS_BARKERNEL 7130
#define XPRS_FEASTOLPERTURB 7132
#define XPRS_CROSSOVERFEASWEIGHT 7133
#define XPRS_LUPIVOTTOL 7139
#define XPRS_MIPRESTARTGAPTHRESHOLD 7140
#define XPRS_NODEPROBINGEFFORT 7141
#define XPRS_INPUTTOL 7143
#define XPRS_MIPRESTARTFACTOR 7145
#define XPRS_BAROBJPERTURB 7146
#define XPRS_CPIALPHA 7149
#define XPRS_GLOBALBOUNDINGBOX 7154
#define XPRS_TIMELIMIT 7158
#define XPRS_SOLTIMELIMIT 7159
#define XPRS_REPAIRINFEASTIMELIMIT 7160
#define XPRS_EXTRAROWS 8004
#define XPRS_EXTRACOLS 8005
#define XPRS_LPITERLIMIT 8007
#define XPRS_LPLOG 8009
#define XPRS_SCALING 8010
#define XPRS_PRESOLVE 8011
#define XPRS_CRASH 8012
#define XPRS_PRICINGALG 8013
#define XPRS_INVERTFREQ 8014
#define XPRS_INVERTMIN 8015
#define XPRS_MAXNODE 8018
#define XPRS_MAXTIME 8020
#define XPRS_MAXMIPSOL 8021
#define XPRS_SIFTPASSES 8022
#define XPRS_DEFAULTALG 8023
#define XPRS_VARSELECTION 8025
#define XPRS_NODESELECTION 8026
#define XPRS_BACKTRACK 8027
#define XPRS_MIPLOG 8028
#define XPRS_KEEPNROWS 8030
#define XPRS_MPSECHO 8032
#define XPRS_MAXPAGELINES 8034
#define XPRS_OUTPUTLOG 8035
#define XPRS_BARSOLUTION 8038
#define XPRS_CACHESIZE 8043
#define XPRS_CROSSOVER 8044
#define XPRS_BARITERLIMIT 8045
#define XPRS_CHOLESKYALG 8046
#define XPRS_BAROUTPUT 8047
#define XPRS_EXTRAMIPENTS 8051
#define XPRS_REFACTOR 8052
#define XPRS_BARTHREADS 8053
#define XPRS_KEEPBASIS 8054
#define XPRS_CROSSOVEROPS 8060
#define XPRS_VERSION 8061
#define XPRS_CROSSOVERTHREADS 8065
#define XPRS_BIGMMETHOD 8068
#define XPRS_MPSNAMELENGTH 8071
#define XPRS_ELIMFILLIN 8073
#define XPRS_PRESOLVEOPS 8077
#define XPRS_MIPPRESOLVE 8078
#define XPRS_MIPTHREADS 8079
#define XPRS_BARORDER 8080
#define XPRS_BREADTHFIRST 8082
#define XPRS_AUTOPERTURB 8084
#define XPRS_DENSECOLLIMIT 8086
#define XPRS_CALLBACKFROMMASTERTHREAD 8090
#define XPRS_MAXMCOEFFBUFFERELEMS 8091
#define XPRS_REFINEOPS 8093
#define XPRS_LPREFINEITERLIMIT 8094
#define XPRS_MIPREFINEITERLIMIT 8095
#define XPRS_DUALIZEOPS 8097
#define XPRS_CROSSOVERITERLIMIT 8104
#define XPRS_PREBASISRED 8106
#define XPRS_PRESORT 8107
#define XPRS_PREPERMUTE 8108
#define XPRS_PREPERMUTESEED 8109
#define XPRS_MAXMEMORYSOFT 8112
#define XPRS_CUTFREQ 8116
#define XPRS_SYMSELECT 8117
#define XPRS_SYMMETRY 8118
#define XPRS_MAXMEMORYHARD 8119
#define XPRS_MIQCPALG 8125
#define XPRS_QCCUTS 8126
#define XPRS_QCROOTALG 8127
#define XPRS_PRECONVERTSEPARABLE 8128
#define XPRS_ALGAFTERNETWORK 8129
#define XPRS_TRACE 8130
#define XPRS_MAXIIS 8131
#define XPRS_CPUTIME 8133
#define XPRS_COVERCUTS 8134
#define XPRS_GOMCUTS 8135
#define XPRS_LPFOLDING 8136
#define XPRS_MPSFORMAT 8137
#define XPRS_CUTSTRATEGY 8138
#define XPRS_CUTDEPTH 8139
#define XPRS_TREECOVERCUTS 8140
#define XPRS_TREEGOMCUTS 8141
#define XPRS_CUTSELECT 8142
#define XPRS_TREECUTSELECT 8143
#define XPRS_DUALIZE 8144
#define XPRS_DUALGRADIENT 8145
#define XPRS_SBITERLIMIT 8146
#define XPRS_SBBEST 8147
#define XPRS_BARINDEFLIMIT 8153
#define XPRS_HEURFREQ 8155
#define XPRS_HEURDEPTH 8156
#define XPRS_HEURMAXSOL 8157
#define XPRS_HEURNODES 8158
#define XPRS_LNPBEST 8160
#define XPRS_LNPITERLIMIT 8161
#define XPRS_BRANCHCHOICE 8162
#define XPRS_BARREGULARIZE 8163
#define XPRS_SBSELECT 8164
#define XPRS_LOCALCHOICE 8170
#define XPRS_LOCALBACKTRACK 8171
#define XPRS_DUALSTRATEGY 8174
#define XPRS_L1CACHE 8175
#define XPRS_HEURDIVESTRATEGY 8177
#define XPRS_HEURSELECT 8178
#define XPRS_BARSTART 8180
#define XPRS_PRESOLVEPASSES 8183
#define XPRS_BARNUMSTABILITY 8186
#define XPRS_BARORDERTHREADS 8187
#define XPRS_EXTRASETS 8190
#define XPRS_FEASIBILITYPUMP 8193
#define XPRS_PRECOEFELIM 8194
#define XPRS_PREDOMCOL 8195
#define XPRS_HEURSEARCHFREQ 8196
#define XPRS_HEURDIVESPEEDUP 8197
#define XPRS_SBESTIMATE 8198
#define XPRS_BARCORES 8202
#define XPRS_MAXCHECKSONMAXTIME 8203
#define XPRS_MAXCHECKSONMAXCUTTIME 8204
#define XPRS_HISTORYCOSTS 8206
#define XPRS_ALGAFTERCROSSOVER 8208
#define XPRS_MUTEXCALLBACKS 8210
#define XPRS_BARCRASH 8211
#define XPRS_HEURDIVESOFTROUNDING 8215
#define XPRS_HEURSEARCHROOTSELECT 8216
#define XPRS_HEURSEARCHTREESELECT 8217
#define XPRS_MPS18COMPATIBLE 8223
#define XPRS_ROOTPRESOLVE 8224
#define XPRS_CROSSOVERDRP 8227
#define XPRS_FORCEOUTPUT 8229
#define XPRS_PRIMALOPS 8231
#define XPRS_DETERMINISTIC 8232
#define XPRS_PREPROBING 8238
#define XPRS_TREEMEMORYLIMIT 8242
#define XPRS_TREECOMPRESSION 8243
#define XPRS_TREEDIAGNOSTICS 8244
#define XPRS_MAXTREEFILESIZE 8245
#define XPRS_PRECLIQUESTRATEGY 8247
#define XPRS_REPAIRINFEASMAXTIME 8250
#define XPRS_IFCHECKCONVEXITY 8251
#define XPRS_PRIMALUNSHIFT 8252
#define XPRS_REPAIRINDEFINITEQ 8254
#define XPRS_MIPRAMPUP 8255
#define XPRS_MAXLOCALBACKTRACK 8257
#define XPRS_USERSOLHEURISTIC 8258
#define XPRS_FORCEPARALLELDUAL 8265
#define XPRS_BACKTRACKTIE 8266
#define XPRS_BRANCHDISJ 8267
#define XPRS_MIPFRACREDUCE 8270
#define XPRS_CONCURRENTTHREADS 8274
#define XPRS_MAXSCALEFACTOR 8275
#define XPRS_HEURTHREADS 8276
#define XPRS_THREADS 8278
#define XPRS_HEURBEFORELP 8280
#define XPRS_PREDOMROW 8281
#define XPRS_BRANCHSTRUCTURAL 8282
#define XPRS_QUADRATICUNSHIFT 8284
#define XPRS_BARPRESOLVEOPS 8286
#define XPRS_QSIMPLEXOPS 8288
#define XPRS_MIPRESTART 8290
#define XPRS_CONFLICTCUTS 8292
#define XPRS_PREPROTECTDUAL 8293
#define XPRS_CORESPERCPU 8296
#define XPRS_RESOURCESTRATEGY 8297
#define XPRS_CLAMPING 8301
#define XPRS_SLEEPONTHREADWAIT 8302
#define XPRS_PREDUPROW 8307
#define XPRS_CPUPLATFORM 8312
#define XPRS_BARALG 8315
#define XPRS_SIFTING 8319
#define XPRS_LPLOGSTYLE 8326
#define XPRS_RANDOMSEED 8328
#define XPRS_TREEQCCUTS 8331
#define XPRS_PRELINDEP 8333
#define XPRS_DUALTHREADS 8334
#define XPRS_PREOBJCUTDETECT 8336
#define XPRS_PREBNDREDQUAD 8337
#define XPRS_PREBNDREDCONE 8338
#define XPRS_PRECOMPONENTS 8339
#define XPRS_MAXMIPTASKS 8347
#define XPRS_MIPTERMINATIONMETHOD 8348
#define XPRS_PRECONEDECOMP 8349
#define XPRS_HEURFORCESPECIALOBJ 8350
#define XPRS_HEURSEARCHROOTCUTFREQ 8351
#define XPRS_PREELIMQUAD 8353
#define XPRS_PREIMPLICATIONS 8356
#define XPRS_TUNERMODE 8359
#define XPRS_TUNERMETHOD 8360
#define XPRS_TUNERTARGET 8362
#define XPRS_TUNERTHREADS 8363
#define XPRS_TUNERHISTORY 8365
#define XPRS_TUNERPERMUTE 8366
#define XPRS_TUNERVERBOSE 8370
#define XPRS_TUNEROUTPUT 8372
#define XPRS_PREANALYTICCENTER 8374
#define XPRS_NETCUTS 8382
#define XPRS_LPFLAGS 8385
#define XPRS_MIPKAPPAFREQ 8386
#define XPRS_OBJSCALEFACTOR 8387
#define XPRS_TREEFILELOGINTERVAL 8389
#define XPRS_IGNORECONTAINERCPULIMIT 8390
#define XPRS_IGNORECONTAINERMEMORYLIMIT 8391
#define XPRS_MIPDUALREDUCTIONS 8392
#define XPRS_GENCONSDUALREDUCTIONS 8395
#define XPRS_PWLDUALREDUCTIONS 8396
#define XPRS_BARFAILITERLIMIT 8398
#define XPRS_AUTOSCALING 8406
#define XPRS_GENCONSABSTRANSFORMATION 8408
#define XPRS_COMPUTEJOBPRIORITY 8409
#define XPRS_PREFOLDING 8410
#define XPRS_NETSTALLLIMIT 8412
#define XPRS_SERIALIZEPREINTSOL 8413
#define XPRS_NUMERICALEMPHASIS 8416
#define XPRS_PWLNONCONVEXTRANSFORMATION 8420
#define XPRS_MIPCOMPONENTS 8421
#define XPRS_MIPCONCURRENTNODES 8422
#define XPRS_MIPCONCURRENTSOLVES 8423
#define XPRS_OUTPUTCONTROLS 8424
#define XPRS_SIFTSWITCH 8425
#define XPRS_HEUREMPHASIS 8427
#define XPRS_COMPUTEMATX 8428
#define XPRS_COMPUTEMATX_IIS 8429
#define XPRS_COMPUTEMATX_IISMAXTIME 8430
#define XPRS_BARREFITER 8431
#define XPRS_COMPUTELOG 8434
#define XPRS_SIFTPRESOLVEOPS 8435
#define XPRS_CHECKINPUTDATA 8436
#define XPRS_ESCAPENAMES 8440
#define XPRS_IOTIMEOUT 8442
#define XPRS_AUTOCUTTING 8446
#define XPRS_CALLBACKCHECKTIMEDELAY 8451
#define XPRS_MULTIOBJOPS 8457
#define XPRS_MULTIOBJLOG 8458
#define XPRS_GLOBALSPATIALBRANCHIFPREFERORIG 8465
#define XPRS_PRECONFIGURATION 8470
#define XPRS_FEASIBILITYJUMP 8471
#define XPRS_EXTRAELEMS 8006
#define XPRS_EXTRASETELEMS 8191
#define XPRS_LPOBJVAL 2001
#define XPRS_MIPOBJVAL 2003
#define XPRS_BESTBOUND 2004
#define XPRS_OBJRHS 2005
#define XPRS_OBJSENSE 2008
#define XPRS_ROWS 1001
#define XPRS_SIMPLEXITER 1009
#define XPRS_BARITER 5001
#define XPRS_SOLSTATUS_NOTFOUND 0
#define XPRS_SOLSTATUS_OPTIMAL 1
#define XPRS_SOLSTATUS_FEASIBLE 2
#define XPRS_SOLSTATUS_INFEASIBLE 3
#define XPRS_SOLSTATUS_UNBOUNDED 4
#define XPRS_LPSTATUS 1010
#define XPRS_MIPSTATUS 1011
#define XPRS_NODES 1013
#define XPRS_COLS 1018
#define XPRS_MAXPROBNAMELENGTH 1158
#define XPRS_LP_UNSTARTED 0
#define XPRS_LP_OPTIMAL 1
#define XPRS_LP_INFEAS 2
#define XPRS_LP_CUTOFF 3
#define XPRS_LP_UNFINISHED 4
#define XPRS_LP_UNBOUNDED 5
#define XPRS_LP_CUTOFF_IN_DUAL 6
#define XPRS_LP_UNSOLVED 7
#define XPRS_LP_NONCONVEX 8
#define XPRS_MIP_SOLUTION 4
#define XPRS_MIP_INFEAS 5
#define XPRS_MIP_OPTIMAL 6
#define XPRS_MIP_UNBOUNDED 7
#define XPRS_ALG_DUAL 2
#define XPRS_ALG_PRIMAL 3
#define XPRS_ALG_BARRIER 4
#define XPRS_OBJ_MINIMIZE 1
#define XPRS_OBJ_MAXIMIZE -1
#define XPRS_UUID 3011
// ***************************************************************************
// * variable types *
// ***************************************************************************
#define XPRS_INTEGER 'I'
#define XPRS_CONTINUOUS 'C'
// ***************************************************************************
// * constraint types *
// ***************************************************************************
#define XPRS_LESS_EQUAL 'L'
#define XPRS_GREATER_EQUAL 'G'
#define XPRS_EQUAL 'E'
#define XPRS_RANGE 'R'
#define XPRS_NONBINDING 'N'
// ***************************************************************************
// * basis status *
// ***************************************************************************
#define XPRS_AT_LOWER 0
#define XPRS_BASIC 1
#define XPRS_AT_UPPER 2
#define XPRS_FREE_SUPER 3
// Let's not reformat for rest of the file.
// NOLINTBEGIN(whitespace/line_length)
// clang-format off
extern std::function<int(XPRSprob* p_prob)> XPRScreateprob;
extern std::function<int(XPRSprob prob)> XPRSdestroyprob;
extern std::function<int(const char* path)> XPRSinit;
extern std::function<int(void)> XPRSfree;
extern std::function<int(char* buffer, int maxbytes)> XPRSgetlicerrmsg;
extern std::function<int(int* p_i, char* p_c)> XPRSlicense;
extern std::function<int(char* banner)> XPRSgetbanner;
extern std::function<int(char* version)> XPRSgetversion;
extern std::function<int(XPRSprob prob, const char* probname)> XPRSsetprobname;
extern std::function<int(XPRSprob prob, int control)> XPRSsetdefaultcontrol;
extern std::function<int(XPRSprob prob, int reason)> XPRSinterrupt;
extern std::function<int(XPRSprob prob, int control, int value)> XPRSsetintcontrol;
extern std::function<int(XPRSprob prob, int control, XPRSint64 value)> XPRSsetintcontrol64;
extern std::function<int(XPRSprob prob, int control, double value)> XPRSsetdblcontrol;
extern std::function<int(XPRSprob prob, int control, const char* value)> XPRSsetstrcontrol;
OR_DLL extern std::function<int(XPRSprob prob, int control, int* p_value)> XPRSgetintcontrol;
OR_DLL extern std::function<int(XPRSprob prob, int control, XPRSint64* p_value)> XPRSgetintcontrol64;
OR_DLL extern std::function<int(XPRSprob prob, int control, double* p_value)> XPRSgetdblcontrol;
OR_DLL extern std::function<int(XPRSprob prob, int control, char* value, int maxbytes, int* p_nbytes)> XPRSgetstringcontrol;
OR_DLL extern std::function<int(XPRSprob prob, int attrib, int* p_value)> XPRSgetintattrib;
OR_DLL extern std::function<int(XPRSprob prob, int attrib, char* value, int maxbytes, int* p_nbytes)> XPRSgetstringattrib;
OR_DLL extern std::function<int(XPRSprob prob, int attrib, double* p_value)> XPRSgetdblattrib;
extern std::function<int(XPRSprob prob, const char* name, int* p_id, int* p_type)> XPRSgetcontrolinfo;
OR_DLL extern std::function<int(XPRSprob prob, double objcoef[], int first, int last)> XPRSgetobj;
OR_DLL extern std::function<int(XPRSprob prob, double rhs[], int first, int last)> XPRSgetrhs;
OR_DLL extern std::function<int(XPRSprob prob, double rng[], int first, int last)> XPRSgetrhsrange;
OR_DLL extern std::function<int(XPRSprob prob, double lb[], int first, int last)> XPRSgetlb;
OR_DLL extern std::function<int(XPRSprob prob, double ub[], int first, int last)> XPRSgetub;
OR_DLL extern std::function<int(XPRSprob prob, int row, int col, double* p_coef)> XPRSgetcoef;
extern std::function<int(XPRSprob prob, int* status, double duals[], int first, int last)> XPRSgetduals;
extern std::function<int(XPRSprob prob, int* status, double djs[], int first, int last)> XPRSgetredcosts;
extern std::function<int(XPRSprob prob, int nrows, int ncoefs, const char rowtype[], const double rhs[], const double rng[], const int start[], const int colind[], const double rowcoef[])> XPRSaddrows;
extern std::function<int(XPRSprob prob, int nrows, const int rowind[])> XPRSdelrows;
extern std::function<int(XPRSprob prob, int ncols, int ncoefs, const double objcoef[], const int start[], const int rowind[], const double rowcoef[], const double lb[], const double ub[])> XPRSaddcols;
extern std::function<int(XPRSprob prob, int type, const char names[], int first, int last)> XPRSaddnames;
extern std::function<int(XPRSprob prob, int type, char names[], int first, int last)> XPRSgetnames;
extern std::function<int(XPRSprob prob, int ncols, const int colind[])> XPRSdelcols;
extern std::function<int(XPRSprob prob, int ncols, const int colind[], const char coltype[])> XPRSchgcoltype;
extern std::function<int(XPRSprob prob, const int rowstat[], const int colstat[])> XPRSloadbasis;
extern std::function<int(XPRSprob prob)> XPRSpostsolve;
extern std::function<int(XPRSprob prob, int objsense)> XPRSchgobjsense;
extern std::function<int(XPRSprob prob, char* errmsg)> XPRSgetlasterror;
extern std::function<int(XPRSprob prob, int rowstat[], int colstat[])> XPRSgetbasis;
extern std::function<int(XPRSprob prob, const char* filename, const char* flags)> XPRSwriteprob;
OR_DLL extern std::function<int(XPRSprob prob, char rowtype[], int first, int last)> XPRSgetrowtype;
OR_DLL extern std::function<int(XPRSprob prob, char coltype[], int first, int last)> XPRSgetcoltype;
extern std::function<int(XPRSprob prob, int nbounds, const int colind[], const char bndtype[], const double bndval[])> XPRSchgbounds;
extern std::function<int(XPRSprob prob, int length, const double solval[], const int colind[], const char* name)> XPRSaddmipsol;
extern std::function<int(XPRSprob prob, double x[], double slack[], double duals[], double djs[])> XPRSgetlpsol;
extern std::function<int(XPRSprob prob, double x[], double slack[])> XPRSgetmipsol;
extern std::function<int(XPRSprob prob, int ncols, const int colind[], const double objcoef[])> XPRSchgobj;
extern std::function<int(XPRSprob prob, int row, int col, double coef)> XPRSchgcoef;
extern std::function<int(XPRSprob prob, int ncoefs, const int rowind[], const int colind[], const double rowcoef[])> XPRSchgmcoef;
extern std::function<int(XPRSprob prob, XPRSint64 ncoefs, const int rowind[], const int colind[], const double rowcoef[])> XPRSchgmcoef64;
extern std::function<int(XPRSprob prob, int ncoefs, const int objqcol1[], const int objqcol2[], const double objqcoef[])> XPRSchgmqobj;
extern std::function<int(XPRSprob prob, int nrows, const int rowind[], const double rhs[])> XPRSchgrhs;
extern std::function<int(XPRSprob prob, int nrows, const int rowind[], const double rng[])> XPRSchgrhsrange;
extern std::function<int(XPRSprob prob, int nrows, const int rowind[], const char rowtype[])> XPRSchgrowtype;
extern std::function<int(XPRSprob prob, int objidx)> XPRSdelobj;
extern std::function<int(XPRSprob prob, void (XPRS_CC *f_intsol)(XPRSprob cbprob, void* cbdata), void* p, int priority)> XPRSaddcbintsol;
extern std::function<int(XPRSprob prob, void (XPRS_CC *f_intsol)(XPRSprob cbprob, void* cbdata), void* p)> XPRSremovecbintsol;
extern std::function<int(XPRSprob prob, void (XPRS_CC *f_message)(XPRSprob cbprob, void* cbdata, const char* msg, int msglen, int msgtype), void* p, int priority)> XPRSaddcbmessage;
extern std::function<int(XPRSprob prob, const char* flags)> XPRSlpoptimize;
extern std::function<int(XPRSprob prob, const char* flags)> XPRSmipoptimize;
extern std::function<int(XPRSprob prob, const char* flags, int* solvestatus, int* solstatus)> XPRSoptimize;
// clang-format on
// NOLINTEND(whitespace/line_length)
} // namespace operations_research
#endif // THIRD_PARTY_ORTOOLS_ORTOOLS_THIRD_PARTY_SOLVERS_XPRESS_ENVIRONMENT_H_