From de8244ac043192b7257d0ce56ffaea1124ff6c97 Mon Sep 17 00:00:00 2001 From: Joris Gillis Date: Mon, 27 Feb 2023 11:42:39 +0100 Subject: [PATCH] Adding Gurobi --- CMakeLists.txt | 1 + gurobi/CMakeLists.txt | 94 ++++++++++++++ gurobi/cmake/gurobi-config.cmake.in | 4 + gurobi/generate.py | 138 ++++++++++++++++++++ gurobi/include/gurobi.h.in | 48 +++++++ gurobi/include/gurobi_c.h | 91 +++++++++++++ gurobi/include/gurobi_core.h.in | 22 ++++ gurobi/src/gurobi.c | 190 ++++++++++++++++++++++++++++ 8 files changed, 588 insertions(+) create mode 100644 gurobi/CMakeLists.txt create mode 100644 gurobi/cmake/gurobi-config.cmake.in create mode 100644 gurobi/generate.py create mode 100644 gurobi/include/gurobi.h.in create mode 100644 gurobi/include/gurobi_c.h create mode 100644 gurobi/include/gurobi_core.h.in create mode 100644 gurobi/src/gurobi.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 08fac42..c5ee9b4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,3 +5,4 @@ add_subdirectory(matlab) add_subdirectory(octave) add_subdirectory(knitro) add_subdirectory(cplex) +add_subdirectory(gurobi) diff --git a/gurobi/CMakeLists.txt b/gurobi/CMakeLists.txt new file mode 100644 index 0000000..bebc69c --- /dev/null +++ b/gurobi/CMakeLists.txt @@ -0,0 +1,94 @@ +cmake_minimum_required(VERSION 3.10) + +project(gurobi + LANGUAGES C) + +set(INSTALL_PREFIX "") + +get_directory_property(hasParent PARENT_DIRECTORY) +if(hasParent) + set(INSTALL_PREFIX "${PROJECT_NAME}/") +endif() + + + +set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) + +set(LIBRARY_NAME gurobi_adaptor) + +add_library(${LIBRARY_NAME} SHARED src/gurobi.c include/gurobi.h) + +if(WIN32) + set_target_properties(${LIBRARY_NAME} PROPERTIES PREFIX "lib" IMPORT_PREFIX "lib") +endif() + +if(CMAKE_SIZEOF_VOID_P EQUAL 4) + set(NBITS_TWO "32") +elseif(CMAKE_SIZEOF_VOID_P EQUAL 8) + set(NBITS_TWO "64") +endif() + +set(ARCHIVE_DIR lib) +set(RUNTIME_DIR bin) + +if(${CMAKE_GENERATOR} MATCHES "Visual Studio*") + set(ARCHIVE_DIR extern/lib/win${NBITS_TWO}/microsoft) + set(RUNTIME_DIR bin/win${NBITS_TWO}) +elseif(${CMAKE_GENERATOR} MATCHES "MSYS Makefiles") + set(ARCHIVE_DIR extern/lib/win${NBITS_TWO}/mingw${NBITS_TWO}) + set(RUNTIME_DIR bin/win${NBITS_TWO}) +endif() + +install(TARGETS ${LIBRARY_NAME} EXPORT gurobiTargets + LIBRARY DESTINATION ${INSTALL_PREFIX}lib + ARCHIVE DESTINATION ${INSTALL_PREFIX}${ARCHIVE_DIR} + RUNTIME DESTINATION ${INSTALL_PREFIX}${RUNTIME_DIR}) + + +add_library(gurobi INTERFACE) + +target_link_libraries(gurobi INTERFACE ${LIBRARY_NAME}) + +install(TARGETS gurobi EXPORT gurobiTargets + LIBRARY DESTINATION ${INSTALL_PREFIX}lib + ARCHIVE DESTINATION ${INSTALL_PREFIX}lib + RUNTIME DESTINATION ${INSTALL_PREFIX}bin + INCLUDES DESTINATION ${INSTALL_PREFIX}include) + +target_include_directories(${LIBRARY_NAME} PUBLIC + $ + $ +) + +target_include_directories(gurobi INTERFACE + $ + $ +) + + + +install(DIRECTORY include/ DESTINATION ${INSTALL_PREFIX}include) + +install(EXPORT gurobiTargets + FILE gurobiTargets.cmake + NAMESPACE gurobi:: + DESTINATION cmake +) + +include(CMakePackageConfigHelpers) +write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/gurobiConfigVersion.cmake + VERSION 7.3 + COMPATIBILITY SameMajorVersion +) + +configure_package_config_file( + "${PROJECT_SOURCE_DIR}/cmake/${PROJECT_NAME}-config.cmake.in" + "${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config.cmake" + INSTALL_DESTINATION + cmake) + + + +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake" "${CMAKE_CURRENT_BINARY_DIR}/gurobiConfigVersion.cmake" + DESTINATION cmake +) diff --git a/gurobi/cmake/gurobi-config.cmake.in b/gurobi/cmake/gurobi-config.cmake.in new file mode 100644 index 0000000..9c15f36 --- /dev/null +++ b/gurobi/cmake/gurobi-config.cmake.in @@ -0,0 +1,4 @@ +@PACKAGE_INIT@ + +include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake") +check_required_components("@PROJECT_NAME@") diff --git a/gurobi/generate.py b/gurobi/generate.py new file mode 100644 index 0000000..a33c7e2 --- /dev/null +++ b/gurobi/generate.py @@ -0,0 +1,138 @@ + +method_declarations = [] + +import re + +with open("include/gurobi_core.h.in","r") as fin: + for line in fin.readlines(): + line = line.strip() + method_declarations.append(line) + +preamble = [] +postamble = [] + +with open("include/gurobi.h.in","r") as fin: + target = preamble + for line in fin.readlines(): + if "[gurobi_core.h]" in line: + target = postamble + continue + target.append(line) + + +def get_name(decl): + return decl.split("(")[0].split(" ")[-1] + +def function_ptr(decl): + return decl[:-1].replace(get_name(decl),"(*)") + +with open("include/gurobi_c.h","w") as fout: + fout.write("".join(preamble)) + for decl in method_declarations: + fout.write("#define %s adaptor_%s\n" % (get_name(decl),get_name(decl))) + fout.write("DLLSYMBOL " + decl.replace(get_name(decl),"(__stdcall *%s)" % get_name(decl))+"\n") + + fout.write("".join(postamble)) + +with open("src/gurobi.c","w") as fout: + + + fout.write(""" +#define DLL_IMPLEMENTATION +#include "gurobi_c.h" + +#include +#include +#ifdef _WIN32 +#include +#else // _WIN32 +#include +#include +#endif // _WIN32 + + +""") + for decl in method_declarations: + fout.write(decl.replace(get_name(decl),"(*%s)" % get_name(decl))[:-1]+" = NULL;\n") + + fout.write(""" + + #if defined(_WIN32) + static HINSTANCE h; + #else + void * h; + #endif + + void gurobi_adaptor_unload() { + if (h) { + #if defined(_WIN32) + FreeLibrary(h); + #elif defined(__APPLE__) + dlclose(h); + #endif + } + } + int gurobi_adaptor_load(char* err_msg, unsigned int err_msg_len) { + + const char* suffix = getenv("GUROBI_VERSION"); + + #if defined(_WIN32) + const char library_suffix[] = "dll"; + const char path_env[] = "PATH"; + #elif defined(__APPLE__) + const char library_suffix[] = "dylib"; + const char path_env[] = "DYLD_LIBRARY_PATH"; + #else + const char library_suffix[] = "so"; + const char path_env[] = "LD_LIBRARY_PATH"; + #endif + + + if (suffix==NULL) { + snprintf(err_msg, err_msg_len, "Gurobi load adaptor needs an environmental variable " + "such that libgurobi.%s can be found.", library_suffix); + return 1; + } + + char buffer[100]; + + snprintf(buffer, 100, "libgurobi%s.%s", suffix, library_suffix); + + #if defined(_WIN32) + h = LoadLibrary(TEXT(buffer)); + #elif defined(__APPLE__) + h = dlopen(buffer, RTLD_LAZY | RTLD_LOCAL); + #else + h = dlopen(buffer, RTLD_LAZY | RTLD_LOCAL | RTLD_DEEPBIND); + #endif + + if (h) { + #ifdef _WIN32 +""") + + for decl in method_declarations: + fout.write(""" %s = (%s) GetProcAddress(h, "%s");\n""" % (get_name(decl),function_ptr(decl),get_name(decl))) + fout.write(""" if (%s==NULL) { snprintf(err_msg, err_msg_len, "Could not find symbol '%s' in libgurobi%%s.%%s", suffix, library_suffix); return 2; };\n""" % (get_name(decl),get_name(decl).replace("CPXX","CPXL"))) + + fout.write(""" + #else // _WIN32 + """) + + for decl in method_declarations: + fout.write(""" %s = (%s) dlsym(h, "%s");\n""" % (get_name(decl),function_ptr(decl),get_name(decl))) + fout.write(""" if (%s==NULL) { snprintf(err_msg, err_msg_len, "Could not find symbol '%s' in libgurobi%%s.%%s", suffix, library_suffix); return 2; };\n""" % (get_name(decl),get_name(decl).replace("CPXX","CPXL"))) + + fout.write(""" + #endif // _WIN32 + + return 0; + } else { + snprintf(err_msg, err_msg_len, "Could not find library '%s'. " + "Consider adding the appropriate gurobi folder to environmental variable '%s'.", buffer, path_env); + return 1; + } + } + """) + + + diff --git a/gurobi/include/gurobi.h.in b/gurobi/include/gurobi.h.in new file mode 100644 index 0000000..9a1f1ca --- /dev/null +++ b/gurobi/include/gurobi.h.in @@ -0,0 +1,48 @@ +#ifndef GUROBI_H +#define GUROBI_H + +#ifdef __cplusplus +extern "C" { +#endif + + +#include + +typedef struct _GRBbatch GRBbatch; +typedef struct _GRBmodel GRBmodel; +typedef struct _GRBenv GRBenv; + +#if defined(_WIN64) && !defined(WIN64) +#define WIN64 +#endif + +#if defined(_WIN32) && !defined(_WIN64) && !defined(WIN32) +#define WIN32 +#endif + +#if !defined(WIN32) && !defined(WIN64) +#define __cdecl +#define __stdcall +#endif + +#ifdef _WIN32 + #ifdef DLL_IMPLEMENTATION + #define DLLSYMBOL __declspec( dllexport ) + #else + #define DLLSYMBOL __declspec( dllimport ) extern + #endif +#else + #ifdef DLL_IMPLEMENTATION + #define DLLSYMBOL + #else + #define DLLSYMBOL extern + #endif +#endif + +[gurobi_core.h] + +#ifdef __cplusplus +} +#endif + +#endif // GUROBI_H diff --git a/gurobi/include/gurobi_c.h b/gurobi/include/gurobi_c.h new file mode 100644 index 0000000..850b2a9 --- /dev/null +++ b/gurobi/include/gurobi_c.h @@ -0,0 +1,91 @@ +#ifndef GUROBI_H +#define GUROBI_H + +#ifdef __cplusplus +extern "C" { +#endif + + +#include + +typedef struct _GRBbatch GRBbatch; +typedef struct _GRBmodel GRBmodel; +typedef struct _GRBenv GRBenv; + +#if defined(_WIN64) && !defined(WIN64) +#define WIN64 +#endif + +#if defined(_WIN32) && !defined(_WIN64) && !defined(WIN32) +#define WIN32 +#endif + +#if !defined(WIN32) && !defined(WIN64) +#define __cdecl +#define __stdcall +#endif + +#ifdef _WIN32 + #ifdef DLL_IMPLEMENTATION + #define DLLSYMBOL __declspec( dllexport ) + #else + #define DLLSYMBOL __declspec( dllimport ) extern + #endif +#else + #ifdef DLL_IMPLEMENTATION + #define DLLSYMBOL + #else + #define DLLSYMBOL extern + #endif +#endif + +#define GRBaddconstr adaptor_GRBaddconstr +DLLSYMBOL int (__stdcall *GRBaddconstr)(GRBmodel *, int, int *, double *, char, double, const char *); +#define GRBaddqconstr adaptor_GRBaddqconstr +DLLSYMBOL int (__stdcall *GRBaddqconstr)(GRBmodel *, int, int *, double *, int, int *, int *, double *, char, double, const char *); +#define GRBaddqpterms adaptor_GRBaddqpterms +DLLSYMBOL int (__stdcall *GRBaddqpterms)(GRBmodel *, int, int *, int *, double *); +#define GRBaddrangeconstr adaptor_GRBaddrangeconstr +DLLSYMBOL int (__stdcall *GRBaddrangeconstr)(GRBmodel *, int, int *, double *, double, double, const char *); +#define GRBaddsos adaptor_GRBaddsos +DLLSYMBOL int (__stdcall *GRBaddsos)(GRBmodel *, int, int, int *, int *, int *, double *); +#define GRBaddvar adaptor_GRBaddvar +DLLSYMBOL int (__stdcall *GRBaddvar)(GRBmodel *, int, int *, double *, double, double, double, char, const char *); +#define GRBfreeenv adaptor_GRBfreeenv +DLLSYMBOL void (__stdcall *GRBfreeenv)(GRBenv *); +#define GRBfreemodel adaptor_GRBfreemodel +DLLSYMBOL int (__stdcall *GRBfreemodel)(GRBmodel *); +#define GRBgetdblattr adaptor_GRBgetdblattr +DLLSYMBOL int (__stdcall *GRBgetdblattr)(GRBmodel *, const char *, double *); +#define GRBgetdblattrarray adaptor_GRBgetdblattrarray +DLLSYMBOL int (__stdcall *GRBgetdblattrarray)(GRBmodel *, const char *, int, int, double *); +#define GRBgetenv adaptor_GRBgetenv +DLLSYMBOL GRBenv* (__stdcall *GRBgetenv)(GRBmodel *); +#define GRBgeterrormsg adaptor_GRBgeterrormsg +DLLSYMBOL const char* (__stdcall *GRBgeterrormsg)(GRBenv *); +#define GRBgetintattr adaptor_GRBgetintattr +DLLSYMBOL int (__stdcall *GRBgetintattr)(GRBmodel *, const char *, int *); +#define GRBgetparamtype adaptor_GRBgetparamtype +DLLSYMBOL int (__stdcall *GRBgetparamtype)(GRBenv *, const char *); +#define GRBloadenv adaptor_GRBloadenv +DLLSYMBOL int (__stdcall *GRBloadenv)(GRBenv **, const char *); +#define GRBnewmodel adaptor_GRBnewmodel +DLLSYMBOL int (__stdcall *GRBnewmodel)(GRBenv *, GRBmodel **, const char *, int, double *, double *, double *, char *, char **); +#define GRBoptimize adaptor_GRBoptimize +DLLSYMBOL int (__stdcall *GRBoptimize)(GRBmodel *); +#define GRBsetdblattrelement adaptor_GRBsetdblattrelement +DLLSYMBOL int (__stdcall *GRBsetdblattrelement)(GRBmodel *, const char *, int, double); +#define GRBsetdblparam adaptor_GRBsetdblparam +DLLSYMBOL int (__stdcall *GRBsetdblparam)(GRBenv *, const char *, double); +#define GRBsetintparam adaptor_GRBsetintparam +DLLSYMBOL int (__stdcall *GRBsetintparam)(GRBenv *, const char *, int); +#define GRBsetstrparam adaptor_GRBsetstrparam +DLLSYMBOL int (__stdcall *GRBsetstrparam)(GRBenv *, const char *, const char *); +#define GRBupdatemodel adaptor_GRBupdatemodel +DLLSYMBOL int (__stdcall *GRBupdatemodel)(GRBmodel *); + +#ifdef __cplusplus +} +#endif + +#endif // GUROBI_H diff --git a/gurobi/include/gurobi_core.h.in b/gurobi/include/gurobi_core.h.in new file mode 100644 index 0000000..6624ef0 --- /dev/null +++ b/gurobi/include/gurobi_core.h.in @@ -0,0 +1,22 @@ +int GRBaddconstr(GRBmodel *, int, int *, double *, char, double, const char *); +int GRBaddqconstr(GRBmodel *, int, int *, double *, int, int *, int *, double *, char, double, const char *); +int GRBaddqpterms(GRBmodel *, int, int *, int *, double *); +int GRBaddrangeconstr(GRBmodel *, int, int *, double *, double, double, const char *); +int GRBaddsos(GRBmodel *, int, int, int *, int *, int *, double *); +int GRBaddvar(GRBmodel *, int, int *, double *, double, double, double, char, const char *); +void GRBfreeenv(GRBenv *); +int GRBfreemodel(GRBmodel *); +int GRBgetdblattr(GRBmodel *, const char *, double *); +int GRBgetdblattrarray(GRBmodel *, const char *, int, int, double *); +GRBenv* GRBgetenv(GRBmodel *); +const char* GRBgeterrormsg(GRBenv *); +int GRBgetintattr(GRBmodel *, const char *, int *); +int GRBgetparamtype(GRBenv *, const char *); +int GRBloadenv(GRBenv **, const char *); +int GRBnewmodel(GRBenv *, GRBmodel **, const char *, int, double *, double *, double *, char *, char **); +int GRBoptimize(GRBmodel *); +int GRBsetdblattrelement(GRBmodel *, const char *, int, double); +int GRBsetdblparam(GRBenv *, const char *, double); +int GRBsetintparam(GRBenv *, const char *, int); +int GRBsetstrparam(GRBenv *, const char *, const char *); +int GRBupdatemodel(GRBmodel *); diff --git a/gurobi/src/gurobi.c b/gurobi/src/gurobi.c new file mode 100644 index 0000000..d800410 --- /dev/null +++ b/gurobi/src/gurobi.c @@ -0,0 +1,190 @@ + +#define DLL_IMPLEMENTATION +#include "gurobi_c.h" + +#include +#include +#ifdef _WIN32 +#include +#else // _WIN32 +#include +#include +#endif // _WIN32 + + +int (*GRBaddconstr)(GRBmodel *, int, int *, double *, char, double, const char *) = NULL; +int (*GRBaddqconstr)(GRBmodel *, int, int *, double *, int, int *, int *, double *, char, double, const char *) = NULL; +int (*GRBaddqpterms)(GRBmodel *, int, int *, int *, double *) = NULL; +int (*GRBaddrangeconstr)(GRBmodel *, int, int *, double *, double, double, const char *) = NULL; +int (*GRBaddsos)(GRBmodel *, int, int, int *, int *, int *, double *) = NULL; +int (*GRBaddvar)(GRBmodel *, int, int *, double *, double, double, double, char, const char *) = NULL; +void (*GRBfreeenv)(GRBenv *) = NULL; +int (*GRBfreemodel)(GRBmodel *) = NULL; +int (*GRBgetdblattr)(GRBmodel *, const char *, double *) = NULL; +int (*GRBgetdblattrarray)(GRBmodel *, const char *, int, int, double *) = NULL; +GRBenv* (*GRBgetenv)(GRBmodel *) = NULL; +const char* (*GRBgeterrormsg)(GRBenv *) = NULL; +int (*GRBgetintattr)(GRBmodel *, const char *, int *) = NULL; +int (*GRBgetparamtype)(GRBenv *, const char *) = NULL; +int (*GRBloadenv)(GRBenv **, const char *) = NULL; +int (*GRBnewmodel)(GRBenv *, GRBmodel **, const char *, int, double *, double *, double *, char *, char **) = NULL; +int (*GRBoptimize)(GRBmodel *) = NULL; +int (*GRBsetdblattrelement)(GRBmodel *, const char *, int, double) = NULL; +int (*GRBsetdblparam)(GRBenv *, const char *, double) = NULL; +int (*GRBsetintparam)(GRBenv *, const char *, int) = NULL; +int (*GRBsetstrparam)(GRBenv *, const char *, const char *) = NULL; +int (*GRBupdatemodel)(GRBmodel *) = NULL; + + + #if defined(_WIN32) + static HINSTANCE h; + #else + void * h; + #endif + + void gurobi_adaptor_unload() { + if (h) { + #if defined(_WIN32) + FreeLibrary(h); + #elif defined(__APPLE__) + dlclose(h); + #endif + } + } + int gurobi_adaptor_load(char* err_msg, unsigned int err_msg_len) { + + const char* suffix = getenv("GUROBI_VERSION"); + + #if defined(_WIN32) + const char library_suffix[] = "dll"; + const char path_env[] = "PATH"; + #elif defined(__APPLE__) + const char library_suffix[] = "dylib"; + const char path_env[] = "DYLD_LIBRARY_PATH"; + #else + const char library_suffix[] = "so"; + const char path_env[] = "LD_LIBRARY_PATH"; + #endif + + + if (suffix==NULL) { + snprintf(err_msg, err_msg_len, "Gurobi load adaptor needs an environmental variable " + "such that libgurobi.%s can be found.", library_suffix); + return 1; + } + + char buffer[100]; + + snprintf(buffer, 100, "libgurobi%s.%s", suffix, library_suffix); + + #if defined(_WIN32) + h = LoadLibrary(TEXT(buffer)); + #elif defined(__APPLE__) + h = dlopen(buffer, RTLD_LAZY | RTLD_LOCAL); + #else + h = dlopen(buffer, RTLD_LAZY | RTLD_LOCAL | RTLD_DEEPBIND); + #endif + + if (h) { + #ifdef _WIN32 + GRBaddconstr = (int (*)(GRBmodel *, int, int *, double *, char, double, const char *)) GetProcAddress(h, "GRBaddconstr"); + if (GRBaddconstr==NULL) { snprintf(err_msg, err_msg_len, "Could not find symbol 'GRBaddconstr' in libgurobi%s.%s", suffix, library_suffix); return 2; }; + GRBaddqconstr = (int (*)(GRBmodel *, int, int *, double *, int, int *, int *, double *, char, double, const char *)) GetProcAddress(h, "GRBaddqconstr"); + if (GRBaddqconstr==NULL) { snprintf(err_msg, err_msg_len, "Could not find symbol 'GRBaddqconstr' in libgurobi%s.%s", suffix, library_suffix); return 2; }; + GRBaddqpterms = (int (*)(GRBmodel *, int, int *, int *, double *)) GetProcAddress(h, "GRBaddqpterms"); + if (GRBaddqpterms==NULL) { snprintf(err_msg, err_msg_len, "Could not find symbol 'GRBaddqpterms' in libgurobi%s.%s", suffix, library_suffix); return 2; }; + GRBaddrangeconstr = (int (*)(GRBmodel *, int, int *, double *, double, double, const char *)) GetProcAddress(h, "GRBaddrangeconstr"); + if (GRBaddrangeconstr==NULL) { snprintf(err_msg, err_msg_len, "Could not find symbol 'GRBaddrangeconstr' in libgurobi%s.%s", suffix, library_suffix); return 2; }; + GRBaddsos = (int (*)(GRBmodel *, int, int, int *, int *, int *, double *)) GetProcAddress(h, "GRBaddsos"); + if (GRBaddsos==NULL) { snprintf(err_msg, err_msg_len, "Could not find symbol 'GRBaddsos' in libgurobi%s.%s", suffix, library_suffix); return 2; }; + GRBaddvar = (int (*)(GRBmodel *, int, int *, double *, double, double, double, char, const char *)) GetProcAddress(h, "GRBaddvar"); + if (GRBaddvar==NULL) { snprintf(err_msg, err_msg_len, "Could not find symbol 'GRBaddvar' in libgurobi%s.%s", suffix, library_suffix); return 2; }; + GRBfreeenv = (void (*)(GRBenv *)) GetProcAddress(h, "GRBfreeenv"); + if (GRBfreeenv==NULL) { snprintf(err_msg, err_msg_len, "Could not find symbol 'GRBfreeenv' in libgurobi%s.%s", suffix, library_suffix); return 2; }; + GRBfreemodel = (int (*)(GRBmodel *)) GetProcAddress(h, "GRBfreemodel"); + if (GRBfreemodel==NULL) { snprintf(err_msg, err_msg_len, "Could not find symbol 'GRBfreemodel' in libgurobi%s.%s", suffix, library_suffix); return 2; }; + GRBgetdblattr = (int (*)(GRBmodel *, const char *, double *)) GetProcAddress(h, "GRBgetdblattr"); + if (GRBgetdblattr==NULL) { snprintf(err_msg, err_msg_len, "Could not find symbol 'GRBgetdblattr' in libgurobi%s.%s", suffix, library_suffix); return 2; }; + GRBgetdblattrarray = (int (*)(GRBmodel *, const char *, int, int, double *)) GetProcAddress(h, "GRBgetdblattrarray"); + if (GRBgetdblattrarray==NULL) { snprintf(err_msg, err_msg_len, "Could not find symbol 'GRBgetdblattrarray' in libgurobi%s.%s", suffix, library_suffix); return 2; }; + GRBgetenv = (GRBenv* (*)(GRBmodel *)) GetProcAddress(h, "GRBgetenv"); + if (GRBgetenv==NULL) { snprintf(err_msg, err_msg_len, "Could not find symbol 'GRBgetenv' in libgurobi%s.%s", suffix, library_suffix); return 2; }; + GRBgeterrormsg = (const char* (*)(GRBenv *)) GetProcAddress(h, "GRBgeterrormsg"); + if (GRBgeterrormsg==NULL) { snprintf(err_msg, err_msg_len, "Could not find symbol 'GRBgeterrormsg' in libgurobi%s.%s", suffix, library_suffix); return 2; }; + GRBgetintattr = (int (*)(GRBmodel *, const char *, int *)) GetProcAddress(h, "GRBgetintattr"); + if (GRBgetintattr==NULL) { snprintf(err_msg, err_msg_len, "Could not find symbol 'GRBgetintattr' in libgurobi%s.%s", suffix, library_suffix); return 2; }; + GRBgetparamtype = (int (*)(GRBenv *, const char *)) GetProcAddress(h, "GRBgetparamtype"); + if (GRBgetparamtype==NULL) { snprintf(err_msg, err_msg_len, "Could not find symbol 'GRBgetparamtype' in libgurobi%s.%s", suffix, library_suffix); return 2; }; + GRBloadenv = (int (*)(GRBenv **, const char *)) GetProcAddress(h, "GRBloadenv"); + if (GRBloadenv==NULL) { snprintf(err_msg, err_msg_len, "Could not find symbol 'GRBloadenv' in libgurobi%s.%s", suffix, library_suffix); return 2; }; + GRBnewmodel = (int (*)(GRBenv *, GRBmodel **, const char *, int, double *, double *, double *, char *, char **)) GetProcAddress(h, "GRBnewmodel"); + if (GRBnewmodel==NULL) { snprintf(err_msg, err_msg_len, "Could not find symbol 'GRBnewmodel' in libgurobi%s.%s", suffix, library_suffix); return 2; }; + GRBoptimize = (int (*)(GRBmodel *)) GetProcAddress(h, "GRBoptimize"); + if (GRBoptimize==NULL) { snprintf(err_msg, err_msg_len, "Could not find symbol 'GRBoptimize' in libgurobi%s.%s", suffix, library_suffix); return 2; }; + GRBsetdblattrelement = (int (*)(GRBmodel *, const char *, int, double)) GetProcAddress(h, "GRBsetdblattrelement"); + if (GRBsetdblattrelement==NULL) { snprintf(err_msg, err_msg_len, "Could not find symbol 'GRBsetdblattrelement' in libgurobi%s.%s", suffix, library_suffix); return 2; }; + GRBsetdblparam = (int (*)(GRBenv *, const char *, double)) GetProcAddress(h, "GRBsetdblparam"); + if (GRBsetdblparam==NULL) { snprintf(err_msg, err_msg_len, "Could not find symbol 'GRBsetdblparam' in libgurobi%s.%s", suffix, library_suffix); return 2; }; + GRBsetintparam = (int (*)(GRBenv *, const char *, int)) GetProcAddress(h, "GRBsetintparam"); + if (GRBsetintparam==NULL) { snprintf(err_msg, err_msg_len, "Could not find symbol 'GRBsetintparam' in libgurobi%s.%s", suffix, library_suffix); return 2; }; + GRBsetstrparam = (int (*)(GRBenv *, const char *, const char *)) GetProcAddress(h, "GRBsetstrparam"); + if (GRBsetstrparam==NULL) { snprintf(err_msg, err_msg_len, "Could not find symbol 'GRBsetstrparam' in libgurobi%s.%s", suffix, library_suffix); return 2; }; + GRBupdatemodel = (int (*)(GRBmodel *)) GetProcAddress(h, "GRBupdatemodel"); + if (GRBupdatemodel==NULL) { snprintf(err_msg, err_msg_len, "Could not find symbol 'GRBupdatemodel' in libgurobi%s.%s", suffix, library_suffix); return 2; }; + + #else // _WIN32 + GRBaddconstr = (int (*)(GRBmodel *, int, int *, double *, char, double, const char *)) dlsym(h, "GRBaddconstr"); + if (GRBaddconstr==NULL) { snprintf(err_msg, err_msg_len, "Could not find symbol 'GRBaddconstr' in libgurobi%s.%s", suffix, library_suffix); return 2; }; + GRBaddqconstr = (int (*)(GRBmodel *, int, int *, double *, int, int *, int *, double *, char, double, const char *)) dlsym(h, "GRBaddqconstr"); + if (GRBaddqconstr==NULL) { snprintf(err_msg, err_msg_len, "Could not find symbol 'GRBaddqconstr' in libgurobi%s.%s", suffix, library_suffix); return 2; }; + GRBaddqpterms = (int (*)(GRBmodel *, int, int *, int *, double *)) dlsym(h, "GRBaddqpterms"); + if (GRBaddqpterms==NULL) { snprintf(err_msg, err_msg_len, "Could not find symbol 'GRBaddqpterms' in libgurobi%s.%s", suffix, library_suffix); return 2; }; + GRBaddrangeconstr = (int (*)(GRBmodel *, int, int *, double *, double, double, const char *)) dlsym(h, "GRBaddrangeconstr"); + if (GRBaddrangeconstr==NULL) { snprintf(err_msg, err_msg_len, "Could not find symbol 'GRBaddrangeconstr' in libgurobi%s.%s", suffix, library_suffix); return 2; }; + GRBaddsos = (int (*)(GRBmodel *, int, int, int *, int *, int *, double *)) dlsym(h, "GRBaddsos"); + if (GRBaddsos==NULL) { snprintf(err_msg, err_msg_len, "Could not find symbol 'GRBaddsos' in libgurobi%s.%s", suffix, library_suffix); return 2; }; + GRBaddvar = (int (*)(GRBmodel *, int, int *, double *, double, double, double, char, const char *)) dlsym(h, "GRBaddvar"); + if (GRBaddvar==NULL) { snprintf(err_msg, err_msg_len, "Could not find symbol 'GRBaddvar' in libgurobi%s.%s", suffix, library_suffix); return 2; }; + GRBfreeenv = (void (*)(GRBenv *)) dlsym(h, "GRBfreeenv"); + if (GRBfreeenv==NULL) { snprintf(err_msg, err_msg_len, "Could not find symbol 'GRBfreeenv' in libgurobi%s.%s", suffix, library_suffix); return 2; }; + GRBfreemodel = (int (*)(GRBmodel *)) dlsym(h, "GRBfreemodel"); + if (GRBfreemodel==NULL) { snprintf(err_msg, err_msg_len, "Could not find symbol 'GRBfreemodel' in libgurobi%s.%s", suffix, library_suffix); return 2; }; + GRBgetdblattr = (int (*)(GRBmodel *, const char *, double *)) dlsym(h, "GRBgetdblattr"); + if (GRBgetdblattr==NULL) { snprintf(err_msg, err_msg_len, "Could not find symbol 'GRBgetdblattr' in libgurobi%s.%s", suffix, library_suffix); return 2; }; + GRBgetdblattrarray = (int (*)(GRBmodel *, const char *, int, int, double *)) dlsym(h, "GRBgetdblattrarray"); + if (GRBgetdblattrarray==NULL) { snprintf(err_msg, err_msg_len, "Could not find symbol 'GRBgetdblattrarray' in libgurobi%s.%s", suffix, library_suffix); return 2; }; + GRBgetenv = (GRBenv* (*)(GRBmodel *)) dlsym(h, "GRBgetenv"); + if (GRBgetenv==NULL) { snprintf(err_msg, err_msg_len, "Could not find symbol 'GRBgetenv' in libgurobi%s.%s", suffix, library_suffix); return 2; }; + GRBgeterrormsg = (const char* (*)(GRBenv *)) dlsym(h, "GRBgeterrormsg"); + if (GRBgeterrormsg==NULL) { snprintf(err_msg, err_msg_len, "Could not find symbol 'GRBgeterrormsg' in libgurobi%s.%s", suffix, library_suffix); return 2; }; + GRBgetintattr = (int (*)(GRBmodel *, const char *, int *)) dlsym(h, "GRBgetintattr"); + if (GRBgetintattr==NULL) { snprintf(err_msg, err_msg_len, "Could not find symbol 'GRBgetintattr' in libgurobi%s.%s", suffix, library_suffix); return 2; }; + GRBgetparamtype = (int (*)(GRBenv *, const char *)) dlsym(h, "GRBgetparamtype"); + if (GRBgetparamtype==NULL) { snprintf(err_msg, err_msg_len, "Could not find symbol 'GRBgetparamtype' in libgurobi%s.%s", suffix, library_suffix); return 2; }; + GRBloadenv = (int (*)(GRBenv **, const char *)) dlsym(h, "GRBloadenv"); + if (GRBloadenv==NULL) { snprintf(err_msg, err_msg_len, "Could not find symbol 'GRBloadenv' in libgurobi%s.%s", suffix, library_suffix); return 2; }; + GRBnewmodel = (int (*)(GRBenv *, GRBmodel **, const char *, int, double *, double *, double *, char *, char **)) dlsym(h, "GRBnewmodel"); + if (GRBnewmodel==NULL) { snprintf(err_msg, err_msg_len, "Could not find symbol 'GRBnewmodel' in libgurobi%s.%s", suffix, library_suffix); return 2; }; + GRBoptimize = (int (*)(GRBmodel *)) dlsym(h, "GRBoptimize"); + if (GRBoptimize==NULL) { snprintf(err_msg, err_msg_len, "Could not find symbol 'GRBoptimize' in libgurobi%s.%s", suffix, library_suffix); return 2; }; + GRBsetdblattrelement = (int (*)(GRBmodel *, const char *, int, double)) dlsym(h, "GRBsetdblattrelement"); + if (GRBsetdblattrelement==NULL) { snprintf(err_msg, err_msg_len, "Could not find symbol 'GRBsetdblattrelement' in libgurobi%s.%s", suffix, library_suffix); return 2; }; + GRBsetdblparam = (int (*)(GRBenv *, const char *, double)) dlsym(h, "GRBsetdblparam"); + if (GRBsetdblparam==NULL) { snprintf(err_msg, err_msg_len, "Could not find symbol 'GRBsetdblparam' in libgurobi%s.%s", suffix, library_suffix); return 2; }; + GRBsetintparam = (int (*)(GRBenv *, const char *, int)) dlsym(h, "GRBsetintparam"); + if (GRBsetintparam==NULL) { snprintf(err_msg, err_msg_len, "Could not find symbol 'GRBsetintparam' in libgurobi%s.%s", suffix, library_suffix); return 2; }; + GRBsetstrparam = (int (*)(GRBenv *, const char *, const char *)) dlsym(h, "GRBsetstrparam"); + if (GRBsetstrparam==NULL) { snprintf(err_msg, err_msg_len, "Could not find symbol 'GRBsetstrparam' in libgurobi%s.%s", suffix, library_suffix); return 2; }; + GRBupdatemodel = (int (*)(GRBmodel *)) dlsym(h, "GRBupdatemodel"); + if (GRBupdatemodel==NULL) { snprintf(err_msg, err_msg_len, "Could not find symbol 'GRBupdatemodel' in libgurobi%s.%s", suffix, library_suffix); return 2; }; + + #endif // _WIN32 + + return 0; + } else { + snprintf(err_msg, err_msg_len, "Could not find library '%s'. " + "Consider adding the appropriate gurobi folder to environmental variable '%s'.", buffer, path_env); + return 1; + } + } + \ No newline at end of file