From 3519bf7986e4ab3f95709423802726d99f22cc4b Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Wed, 18 Oct 2023 09:15:16 -0700 Subject: [PATCH 01/39] start --- CMakeLists.txt | 6 +- src/cpp/multisolver_interface/CMakeLists.txt | 16 +- .../multisolver_interface/SolverFactory.cpp | 20 +- .../multisolver_interface/SolverXpress.cpp | 2 + src/cpp/multisolver_interface/SolverXpress.h | 2 +- src/cpp/multisolver_interface/environment.cc | 423 ++++++++++++++++ src/cpp/multisolver_interface/environment.h | 450 ++++++++++++++++++ .../multisolver_interface/SolverFactory.h | 1 + 8 files changed, 897 insertions(+), 23 deletions(-) create mode 100644 src/cpp/multisolver_interface/environment.cc create mode 100644 src/cpp/multisolver_interface/environment.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 4c2f72d2e..2e7a80084 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -243,11 +243,11 @@ if(XPRESS) message("XPRESS is ${XPRESS}") #Default xpress install dir - if (NOT XPRESS_ROOT) + if (NOT XPRESSDIR) if (MSVC) - set(XPRESS_ROOT "C:/xpressmp") + set(XPRESSDIR "C:/xpressmp") elseif(UNIX) - set(XPRESS_ROOT "/opt/xpressmp") + set(XPRESSDIR "/opt/xpressmp") endif() endif() diff --git a/src/cpp/multisolver_interface/CMakeLists.txt b/src/cpp/multisolver_interface/CMakeLists.txt index 4a02be465..f23d54313 100644 --- a/src/cpp/multisolver_interface/CMakeLists.txt +++ b/src/cpp/multisolver_interface/CMakeLists.txt @@ -18,11 +18,11 @@ list(APPEND Solver_sources ) # XPRESS -IF( XPRESS ) +#IF( XPRESS ) list(APPEND Solver_sources ${CMAKE_CURRENT_LIST_DIR}/SolverXpress.cpp ) -ENDIF( XPRESS ) +#ENDIF( XPRESS ) #Clp - CBc IF(COIN_OR) @@ -52,12 +52,12 @@ target_include_directories (solvers # XPRESS -if(XPRESS) - target_link_libraries (solvers - PUBLIC - XPRESS::XPRESS - ) -endif() +#if(XPRESS) + # target_link_libraries (solvers + # PUBLIC + # XPRESS::XPRESS + # ) +#endif() #CLP-CBC if(COIN_OR) diff --git a/src/cpp/multisolver_interface/SolverFactory.cpp b/src/cpp/multisolver_interface/SolverFactory.cpp index 62be10ca0..7aae17a7c 100644 --- a/src/cpp/multisolver_interface/SolverFactory.cpp +++ b/src/cpp/multisolver_interface/SolverFactory.cpp @@ -1,6 +1,7 @@ -#ifdef XPRESS +// #ifdef XPRESS #include "SolverXpress.h" -#endif +#include "environment.h" +// #endif #ifdef COIN_OR #include "SolverCbc.h" #include "SolverClp.h" @@ -10,9 +11,10 @@ SolverFactory::SolverFactory() { _available_solvers.clear(); -#ifdef XPRESS - _available_solvers.push_back(XPRESS_STR); -#endif + if (isXpress_available_ = + operations_research_Xpansion::XpressIsCorrectlyInstalled()) { + _available_solvers.push_back(XPRESS_STR); + } #ifdef COIN_OR _available_solvers.push_back(CLP_STR); _available_solvers.push_back(CBC_STR); @@ -45,11 +47,9 @@ SolverAbstract::Ptr SolverFactory::create_solver( if (solver_name == "") { throw InvalidSolverNameException(solver_name, LOGLOCATION); } -#ifdef XPRESS - else if (solver_name == XPRESS_STR) { + if (isXpress_available_ && solver_name == XPRESS_STR) { return std::make_shared(log_name); } -#endif #ifdef COIN_OR else if (solver_name == CLP_STR) { return std::make_shared(log_name); @@ -69,11 +69,9 @@ SolverAbstract::Ptr SolverFactory::copy_solver( if (solver_name == "") { throw InvalidSolverNameException(solver_name, LOGLOCATION); } -#ifdef XPRESS - else if (solver_name == XPRESS_STR) { + if (isXpress_available_ && solver_name == XPRESS_STR) { return std::make_shared(to_copy); } -#endif #ifdef COIN_OR else if (solver_name == CLP_STR) { return std::make_shared(to_copy); diff --git a/src/cpp/multisolver_interface/SolverXpress.cpp b/src/cpp/multisolver_interface/SolverXpress.cpp index 49e88e4a4..9cae961a4 100644 --- a/src/cpp/multisolver_interface/SolverXpress.cpp +++ b/src/cpp/multisolver_interface/SolverXpress.cpp @@ -6,6 +6,8 @@ #include "StringManip.h" +using namespace operations_research_Xpansion; + /************************************************************************************************* ----------------------------------- Constructor/Desctructor -------------------------------- diff --git a/src/cpp/multisolver_interface/SolverXpress.h b/src/cpp/multisolver_interface/SolverXpress.h index fbe6d3613..91429f0ce 100644 --- a/src/cpp/multisolver_interface/SolverXpress.h +++ b/src/cpp/multisolver_interface/SolverXpress.h @@ -3,8 +3,8 @@ #include #include +#include "environment.h" #include "multisolver_interface/SolverAbstract.h" -#include "xprs.h" /*! * \class class SolverXpress diff --git a/src/cpp/multisolver_interface/environment.cc b/src/cpp/multisolver_interface/environment.cc new file mode 100644 index 000000000..f74dd5471 --- /dev/null +++ b/src/cpp/multisolver_interface/environment.cc @@ -0,0 +1,423 @@ +// Copyright 2010-2021 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 "environment.h" + +#include +#include +#include + +namespace operations_research_Xpansion { + +#define STRINGIFY2(X) #X +#define STRINGIFY(X) STRINGIFY2(X) + +// This was generated with the parse_header_xpress.py script. +// See the comment at the top of the script. + +// This is the 'define' section. +std::function XPRScreateprob = nullptr; +std::function XPRSdestroyprob = nullptr; +std::function XPRSinit = nullptr; +std::function XPRSfree = nullptr; +std::function XPRSgetlicerrmsg = nullptr; +std::function XPRSlicense = nullptr; +std::function XPRSgetbanner = nullptr; +std::function XPRSgetversion = nullptr; +std::function XPRSsetdefaultcontrol = nullptr; +std::function XPRSsetintcontrol = + nullptr; +std::function + XPRSsetintcontrol64 = nullptr; +std::function XPRSsetdblcontrol = + nullptr; +std::function + XPRSsetstrcontrol = nullptr; +std::function XPRSgetintcontrol = + nullptr; +std::function + XPRSgetintcontrol64 = nullptr; +std::function + XPRSgetdblcontrol = nullptr; +std::function + XPRSgetstringcontrol = nullptr; +std::function XPRSgetintattrib = + nullptr; +std::function + XPRSgetdblattrib = nullptr; +std::function + XPRSloadlp = nullptr; +std::function + XPRSloadlp64 = nullptr; +std::function + XPRSgetobj = nullptr; +std::function + XPRSgetrhs = nullptr; +std::function + XPRSgetrhsrange = nullptr; +std::function XPRSgetlb = + nullptr; +std::function XPRSgetub = + nullptr; +std::function + XPRSgetcoef = nullptr; +std::function + XPRSaddrows = nullptr; +std::function XPRSdelrows = + nullptr; +std::function + XPRSaddcols = nullptr; +std::function XPRSdelcols = + nullptr; +std::function + XPRSchgcoltype = nullptr; +std::function + XPRSloadbasis = nullptr; +std::function XPRSpostsolve = nullptr; +std::function XPRSchgobjsense = nullptr; +std::function XPRSgetlasterror = nullptr; +std::function XPRSgetbasis = + nullptr; +std::function + XPRSwriteprob = nullptr; +std::function + XPRSgetrowtype = nullptr; +std::function + XPRSgetcoltype = nullptr; +std::function + XPRSchgbounds = nullptr; +std::function + XPRSgetlpsol = nullptr; +std::function XPRSgetmipsol = + nullptr; +std::function + XPRSchgobj = nullptr; +std::function XPRSchgcoef = + nullptr; +std::function + XPRSchgmcoef = nullptr; +std::function + XPRSchgrhs = nullptr; +std::function + XPRSchgrhsrange = nullptr; +std::function + XPRSchgrowtype = nullptr; +std::function + XPRSsetcbmessage = nullptr; +std::function XPRSminim = nullptr; +std::function XPRSmaxim = nullptr; + +bool 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. + 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(&XPRSsetdefaultcontrol, + "XPRSsetdefaultcontrol"); + 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(&XPRSgetdblattrib, "XPRSgetdblattrib"); + xpress_dynamic_library->GetFunction(&XPRSloadlp, "XPRSloadlp"); + xpress_dynamic_library->GetFunction(&XPRSloadlp64, "XPRSloadlp64"); + 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(&XPRSaddrows, "XPRSaddrows"); + xpress_dynamic_library->GetFunction(&XPRSdelrows, "XPRSdelrows"); + xpress_dynamic_library->GetFunction(&XPRSaddcols, "XPRSaddcols"); + 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(&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(&XPRSchgrhs, "XPRSchgrhs"); + xpress_dynamic_library->GetFunction(&XPRSchgrhsrange, "XPRSchgrhsrange"); + xpress_dynamic_library->GetFunction(&XPRSchgrowtype, "XPRSchgrowtype"); + xpress_dynamic_library->GetFunction(&XPRSsetcbmessage, "XPRSsetcbmessage"); + xpress_dynamic_library->GetFunction(&XPRSminim, "XPRSminim"); + xpress_dynamic_library->GetFunction(&XPRSmaxim, "XPRSmaxim"); + + auto notFound = xpress_dynamic_library->FunctionsNotFound(); + if (!notFound.empty()) { + std::string msg( + "Could not find the following functions (list may not be " + "exhaustive). [" + + StringJoin(notFound) + + "]. Please make sure that your XPRESS install is " + "up-to-date (>= 8.13.0)."); + std::cout << msg << std::endl; + return false; + } + return true; +} + +std::string StringJoin(const std::vector& vec) { + std::string ret; + for (const auto& str : vec) ret += str + "', '"; + return ret; +} +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 XpressDynamicLibraryPotentialPaths() { + std::vector potential_paths; + + // Look for libraries pointed by XPRESSDIR first. + const char* xpress_home_from_env = getenv("XPRESSDIR"); + if (xpress_home_from_env != nullptr) { + std::filesystem::path prefix(xpress_home_from_env); +#if defined(_MSC_VER) // Windows + potential_paths.push_back(prefix / "\\bin\\xprs.dll"); +#elif defined(__APPLE__) // OS X + potential_paths.push_back(prefix / "/lib/libxprs.dylib"); +#elif defined(__GNUC__) // Linux + potential_paths.push_back(prefix / "/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.\n"; + } + + // Search for canonical places. +#if defined(_MSC_VER) // Windows + potential_paths.push_back("C:\\xpressmp\\bin\\xprs.dll"); + potential_paths.push_back("C:\\Program Files\\xpressmp\\bin\\xprs.dll"); +#elif defined(__APPLE__) // OS X + potential_paths.push_back("/Library/xpressmp/lib/libxprs.dylib"); +#elif defined(__GNUC__) // Linux + potential_paths.push_back("/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; +} + +bool LoadXpressDynamicLibrary(std::string& xpresspath) { + static std::string xpress_lib_path; + static std::once_flag xpress_loading_done; + static bool ret; + static DynamicLibrary xpress_library; + static absl::Mutex mutex; + + absl::MutexLock lock(&mutex); + + std::call_once(xpress_loading_done, []() { + const std::vector 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()) { + ret = LoadXpressFunctions(&xpress_library); + } else { + std::string msg("Could not find the Xpress shared library. Looked in: [" + + StringJoin(canonical_paths) + + "]. Please check environment variable XPRESSDIR"); + std::cout << msg << std::endl; + ret = false; + } + }); + xpresspath.clear(); + xpresspath.append(xpress_lib_path); + return ret; +} + +/** init XPRESS environment */ +bool initXpressEnv(bool verbose, int xpress_oem_license_key) { + std::string xpresspath; + bool status = LoadXpressDynamicLibrary(xpresspath); + if (!status) { + LOG(WARNING) << status << "\n"; + return false; + } + + const char* xpress_from_env = getenv("XPRESS"); + if (xpress_from_env == nullptr) { + if (verbose) { + LOG(WARNING) + << "XpressInterface Error : Environment variable XPRESS undefined.\n"; + } + if (xpresspath.empty()) { + return false; + } + } else { + xpresspath = xpress_from_env; + } + + int code; + + // if not an OEM key + if (xpress_oem_license_key == 0) { + if (verbose) { + LOG(WARNING) << "XpressInterface : Initialising xpress-MP with parameter " + << xpresspath << "\n"; + } + + code = XPRSinit(xpresspath.c_str()); + + 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 + << ").\n"; + } + return true; + } else { + LOG(ERROR) << "XpressInterface: Xpress found at " << xpresspath << "\n"; + char errmsg[256]; + XPRSgetlicerrmsg(errmsg, 256); + + LOG(ERROR) << "XpressInterface : License error : " << errmsg + << " (XPRSinit returned code " << code << "). Please check" + << " environment variable XPRESS.\n"; + + return false; + } + } else { + // if OEM key + if (verbose) { + LOG(WARNING) << "XpressInterface : Initialising xpress-MP with OEM key " + << xpress_oem_license_key << "\n"; + } + + int nvalue = 0; + int ierr; + char slicmsg[256] = ""; + char errmsg[256]; + + XPRSlicense(&nvalue, slicmsg); + if (verbose) { + VLOG(0) << "XpressInterface : First message from XPRSLicense : " + << slicmsg << "\n"; + } + + nvalue = xpress_oem_license_key - ((nvalue * nvalue) / 19); + ierr = XPRSlicense(&nvalue, slicmsg); + + if (verbose) { + VLOG(0) << "XpressInterface : Second message from XPRSLicense : " + << slicmsg << "\n"; + } + if (ierr == 16) { + if (verbose) { + VLOG(0) + << "XpressInterface : Optimizer development software detected\n"; + } + } else if (ierr != 0) { + // get the license error message + XPRSgetlicerrmsg(errmsg, 256); + + LOG(ERROR) << "XpressInterface : " << errmsg << "\n"; + return false; + } + + code = XPRSinit(NULL); + + if (!code) { + return true; + } else { + LOG(ERROR) << "XPRSinit returned code : " << code << "\n"; + return false; + } + } +} + +bool XpressIsCorrectlyInstalled() { + bool correctlyInstalled = initXpressEnv(false); + if (correctlyInstalled) { + XPRSfree(); + } + return correctlyInstalled; +} + +} // namespace operations_research_Xpansion diff --git a/src/cpp/multisolver_interface/environment.h b/src/cpp/multisolver_interface/environment.h new file mode 100644 index 000000000..b011b1a49 --- /dev/null +++ b/src/cpp/multisolver_interface/environment.h @@ -0,0 +1,450 @@ +// Copyright 2010-2021 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. +#pragma once +#include +extern "C" { +typedef struct xo_prob_struct* XPRSprob; +} + +namespace operations_research_Xpansion { + +void printXpressBanner(bool error); + +bool initXpressEnv(bool verbose = true, int xpress_oem_license_key = 0); + +bool XpressIsCorrectlyInstalled(); +// clang-format off +// 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. +bool 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 +#if defined(_WIN32) +#define XPRSint64 __int64 +#elif defined(__LP64__) || defined(_LP64) || defined(__ILP64__) || defined(_ILP64) +#define XPRSint64 long +#else +#define XPRSint64 long long +#endif + +#if defined(_MSC_VER) +#define XPRS_CC __stdcall +#else +#define XPRS_CC +#endif +#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_LPSTATUS 1010 +#define XPRS_MIPSTATUS 1011 +#define XPRS_NODES 1013 +#define XPRS_COLS 1018 +#define XPRS_LP_OPTIMAL 1 +#define XPRS_LP_INFEAS 2 +#define XPRS_LP_UNBOUNDED 5 +#define XPRS_MIP_SOLUTION 4 +#define XPRS_MIP_INFEAS 5 +#define XPRS_MIP_OPTIMAL 6 +#define XPRS_MIP_UNBOUNDED 7 +#define XPRS_OBJ_MINIMIZE 1 +#define XPRS_OBJ_MAXIMIZE -1 +extern std::function XPRScreateprob; +extern std::function XPRSdestroyprob; +extern std::function XPRSinit; +extern std::function XPRSfree; +extern std::function XPRSgetlicerrmsg; +extern std::function XPRSlicense; +extern std::function XPRSgetbanner; +extern std::function XPRSgetversion; +extern std::function XPRSsetdefaultcontrol; +extern std::function XPRSsetintcontrol; +extern std::function XPRSsetintcontrol64; +extern std::function XPRSsetdblcontrol; +extern std::function XPRSsetstrcontrol; +extern std::function XPRSgetintcontrol; +extern std::function XPRSgetintcontrol64; +extern std::function XPRSgetdblcontrol; +extern std::function XPRSgetstringcontrol; +extern std::function XPRSgetintattrib; +extern std::function XPRSgetdblattrib; +extern std::function XPRSloadlp; +extern std::function XPRSloadlp64; +extern std::function XPRSgetobj; +extern std::function XPRSgetrhs; +extern std::function XPRSgetrhsrange; +extern std::function XPRSgetlb; +extern std::function XPRSgetub; +extern std::function XPRSgetcoef; +extern std::function XPRSaddrows; +extern std::function XPRSdelrows; +extern std::function XPRSaddcols; +extern std::function XPRSdelcols; +extern std::function XPRSchgcoltype; +extern std::function XPRSloadbasis; +extern std::function XPRSpostsolve; +extern std::function XPRSchgobjsense; +extern std::function XPRSgetlasterror; +extern std::function XPRSgetbasis; +extern std::function XPRSwriteprob; +extern std::function XPRSgetrowtype; +extern std::function XPRSgetcoltype; +extern std::function XPRSchgbounds; +extern std::function XPRSgetlpsol; +extern std::function XPRSgetmipsol; +extern std::function XPRSchgobj; +extern std::function XPRSchgcoef; +extern std::function XPRSchgmcoef; +extern std::function XPRSchgrhs; +extern std::function XPRSchgrhsrange; +extern std::function XPRSchgrowtype; +extern std::function XPRSsetcbmessage; +extern std::function XPRSminim; +extern std::function XPRSmaxim; + +} // namespace operations_research_Xpansion + diff --git a/src/cpp/multisolver_interface/include/multisolver_interface/SolverFactory.h b/src/cpp/multisolver_interface/include/multisolver_interface/SolverFactory.h index 91594b58d..d97ba383c 100644 --- a/src/cpp/multisolver_interface/include/multisolver_interface/SolverFactory.h +++ b/src/cpp/multisolver_interface/include/multisolver_interface/SolverFactory.h @@ -62,4 +62,5 @@ class SolverFactory { * @brief Returns a reference to the list of available solvers */ const std::vector &get_solvers_list() const; + bool isXpress_available = false; }; From 1cd9fa25c5832ccab3a653b565f95480a996b9f6 Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Wed, 18 Oct 2023 09:22:09 -0700 Subject: [PATCH 02/39] start --- .../include/multisolver_interface/SolverFactory.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cpp/multisolver_interface/include/multisolver_interface/SolverFactory.h b/src/cpp/multisolver_interface/include/multisolver_interface/SolverFactory.h index d97ba383c..89e2f05a0 100644 --- a/src/cpp/multisolver_interface/include/multisolver_interface/SolverFactory.h +++ b/src/cpp/multisolver_interface/include/multisolver_interface/SolverFactory.h @@ -62,5 +62,6 @@ class SolverFactory { * @brief Returns a reference to the list of available solvers */ const std::vector &get_solvers_list() const; - bool isXpress_available = false; + + bool isXpress_available_ = false; }; From d9f7126863e977f71a9aafdcb2e13a3a1eddc63c Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Thu, 19 Oct 2023 02:30:15 -0700 Subject: [PATCH 03/39] add more function --- src/cpp/multisolver_interface/CMakeLists.txt | 3 + .../multisolver_interface/dynamic_library.h | 115 ++++++++++++++++++ src/cpp/multisolver_interface/environment.cc | 111 +++++++++++------ src/cpp/multisolver_interface/environment.h | 22 ++++ 4 files changed, 216 insertions(+), 35 deletions(-) create mode 100644 src/cpp/multisolver_interface/dynamic_library.h diff --git a/src/cpp/multisolver_interface/CMakeLists.txt b/src/cpp/multisolver_interface/CMakeLists.txt index f23d54313..36b8de6ad 100644 --- a/src/cpp/multisolver_interface/CMakeLists.txt +++ b/src/cpp/multisolver_interface/CMakeLists.txt @@ -21,6 +21,8 @@ list(APPEND Solver_sources #IF( XPRESS ) list(APPEND Solver_sources ${CMAKE_CURRENT_LIST_DIR}/SolverXpress.cpp + ${CMAKE_CURRENT_LIST_DIR}/environment.h + ${CMAKE_CURRENT_LIST_DIR}/environment.cc ) #ENDIF( XPRESS ) @@ -68,5 +70,6 @@ if(COIN_OR) Coin::CoinUtils Coin::Osi Coin::Cbc + ${CMAKE_DL_LIBS} ) endif() diff --git a/src/cpp/multisolver_interface/dynamic_library.h b/src/cpp/multisolver_interface/dynamic_library.h new file mode 100644 index 000000000..fd5909995 --- /dev/null +++ b/src/cpp/multisolver_interface/dynamic_library.h @@ -0,0 +1,115 @@ +// Copyright 2010-2022 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 +#include +#include +#include + +#if defined(_MSC_VER) +#define WIN32_LEAN_AND_MEAN // disables several conflicting macros +#include +#elif defined(__GNUC__) +#include +#endif + +class DynamicLibrary { + static constexpr size_t kMaxFunctionsNotFound = 10; + + public: + DynamicLibrary() : library_handle_(nullptr) {} + + ~DynamicLibrary() { + if (library_handle_ == nullptr) { + return; + } + +#if defined(_MSC_VER) + FreeLibrary(static_cast(library_handle_)); +#elif defined(__GNUC__) + dlclose(library_handle_); +#endif + } + + bool TryToLoad(const std::string& library_name) { + library_name_ = std::string(library_name); +#if defined(_MSC_VER) + library_handle_ = static_cast(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; } + + const std::vector& FunctionsNotFound() const { + return functions_not_found_; + } + + template + std::function GetFunction(const char* function_name) { + const void* function_address = +#if defined(_MSC_VER) + static_cast(GetProcAddress( + static_cast(library_handle_), function_name)); +#else + dlsym(library_handle_, function_name); +#endif + // We don't really need the full list of missing functions, + // just a few are enough. + if (!function_address && + functions_not_found_.size() < kMaxFunctionsNotFound) + functions_not_found_.push_back(function_name); + + return TypeParser::CreateFunction(function_address); + } + + template + std::function GetFunction(const std::string& function_name) { + return GetFunction(function_name.c_str()); + } + + template + void GetFunction(std::function* function, const char* function_name) { + *function = GetFunction(function_name); + } + + template + void GetFunction(std::function* function, + const std::string function_name) { + GetFunction(function, function_name.c_str()); + } + + private: + void* library_handle_ = nullptr; + std::string library_name_; + std::vector functions_not_found_; + + template + struct TypeParser {}; + + template + struct TypeParser { + static std::function CreateFunction( + const void* function_address) { + return std::function(reinterpret_cast( + const_cast(function_address))); + } + }; +}; + +#endif // OR_TOOLS_BASE_DYNAMIC_LIBRARY_H_ diff --git a/src/cpp/multisolver_interface/environment.cc b/src/cpp/multisolver_interface/environment.cc index f74dd5471..c23323b6d 100644 --- a/src/cpp/multisolver_interface/environment.cc +++ b/src/cpp/multisolver_interface/environment.cc @@ -14,6 +14,7 @@ #include "environment.h" #include +#include #include #include @@ -25,7 +26,33 @@ namespace operations_research_Xpansion { // This was generated with the parse_header_xpress.py script. // See the comment at the top of the script. +std::string StringJoin(const std::vector& vec) { + std::string ret; + for (const auto& str : vec) ret += str + "', '"; + return ret; +} // This is the 'define' section. +std::function XPRScopyprob = + nullptr; +std::function + XPRSwritebasis = nullptr; +std::function + XPRSreadprob = nullptr; +std::function + XPRSreadbasis = nullptr; +std::function + XPRSgetrows = nullptr; +std::function + XPRSgetindex = nullptr; +std::function + XPRSgetnames = nullptr; +std::function + XPRSaddnames = nullptr; +std::function XPRSlpoptimize = nullptr; +std::function XPRSmipoptimize = nullptr; + std::function XPRScreateprob = nullptr; std::function XPRSdestroyprob = nullptr; std::function XPRSinit = nullptr; @@ -147,6 +174,17 @@ bool LoadXpressFunctions(DynamicLibrary* xpress_dynamic_library) { // See the comment at the top of the script. // This is the 'assign' section. + xpress_dynamic_library->GetFunction(&XPRScopyprob, "XPRScopyprob"); + xpress_dynamic_library->GetFunction(&XPRSwritebasis, "XPRSwritebasis"); + xpress_dynamic_library->GetFunction(&XPRSreadprob, "XPRSreadprob"); + xpress_dynamic_library->GetFunction(&XPRSreadbasis, "XPRSreadbasis"); + xpress_dynamic_library->GetFunction(&XPRSgetrows, "XPRSgetrows"); + xpress_dynamic_library->GetFunction(&XPRSgetindex, "XPRSgetindex"); + xpress_dynamic_library->GetFunction(&XPRSgetnames, "XPRSgetnames"); + xpress_dynamic_library->GetFunction(&XPRSaddnames, "XPRSaddnames"); + xpress_dynamic_library->GetFunction(&XPRSlpoptimize, "XPRSlpoptimize"); + xpress_dynamic_library->GetFunction(&XPRSmipoptimize, "XPRSmipoptimize"); + xpress_dynamic_library->GetFunction(&XPRScreateprob, "XPRScreateprob"); xpress_dynamic_library->GetFunction(&XPRSdestroyprob, "XPRSdestroyprob"); xpress_dynamic_library->GetFunction(&XPRSinit, "XPRSinit"); @@ -218,19 +256,16 @@ bool LoadXpressFunctions(DynamicLibrary* xpress_dynamic_library) { return true; } -std::string StringJoin(const std::vector& vec) { - std::string ret; - for (const auto& str : vec) ret += str + "', '"; - return ret; -} void printXpressBanner(bool error) { char banner[XPRS_MAXBANNERLENGTH]; XPRSgetbanner(banner); if (error) { - LOG(ERROR) << "XpressInterface : Xpress banner :\n" << banner << "\n"; + std::cerr << "XpressInterface : Xpress banner :\n" << banner << "\n"; } else { - LOG(WARNING) << "XpressInterface : Xpress banner :\n" << banner << "\n"; + std::cout << "Warning: " + << "XpressInterface : Xpress banner :\n" + << banner << "\n"; } } @@ -248,11 +283,12 @@ std::vector XpressDynamicLibraryPotentialPaths() { #elif defined(__GNUC__) // Linux potential_paths.push_back(prefix / "/lib/libxprs.so"); #else - LOG(ERROR) << "OS Not recognized by xpress/environment.cc." - << " You won't be able to use Xpress."; + std::cerr << "OS Not recognized by xpress/environment.cc." + << " You won't be able to use Xpress."; #endif } else { - LOG(WARNING) << "Environment variable XPRESSDIR undefined.\n"; + std::cout << "Warning: " + << "Environment variable XPRESSDIR undefined.\n"; } // Search for canonical places. @@ -264,8 +300,8 @@ std::vector XpressDynamicLibraryPotentialPaths() { #elif defined(__GNUC__) // Linux potential_paths.push_back("/opt/xpressmp/lib/libxprs.so"); #else - LOG(ERROR) << "OS Not recognized by xpress/environment.cc." - << " You won't be able to use Xpress."; + std::cerr << "OS Not recognized by xpress/environment.cc." + << " You won't be able to use Xpress."; #endif return potential_paths; } @@ -275,16 +311,17 @@ bool LoadXpressDynamicLibrary(std::string& xpresspath) { static std::once_flag xpress_loading_done; static bool ret; static DynamicLibrary xpress_library; - static absl::Mutex mutex; + static std::mutex mutex; - absl::MutexLock lock(&mutex); + mutex.lock(); std::call_once(xpress_loading_done, []() { const std::vector canonical_paths = XpressDynamicLibraryPotentialPaths(); for (const std::string& path : canonical_paths) { if (xpress_library.TryToLoad(path)) { - LOG(INFO) << "Found the Xpress library in " << path << "."; + std::cout << "Info: " + << "Found the Xpress library in " << path << "."; xpress_lib_path.clear(); std::filesystem::path p(path); p.remove_filename(); @@ -313,14 +350,15 @@ bool initXpressEnv(bool verbose, int xpress_oem_license_key) { std::string xpresspath; bool status = LoadXpressDynamicLibrary(xpresspath); if (!status) { - LOG(WARNING) << status << "\n"; + std::cout << "Warning: " << status << "\n"; return false; } const char* xpress_from_env = getenv("XPRESS"); if (xpress_from_env == nullptr) { if (verbose) { - LOG(WARNING) + std::cout + << "Warning: " << "XpressInterface Error : Environment variable XPRESS undefined.\n"; } if (xpresspath.empty()) { @@ -335,8 +373,9 @@ bool initXpressEnv(bool verbose, int xpress_oem_license_key) { // if not an OEM key if (xpress_oem_license_key == 0) { if (verbose) { - LOG(WARNING) << "XpressInterface : Initialising xpress-MP with parameter " - << xpresspath << "\n"; + std::cout << "Warning: " + << "XpressInterface : Initialising xpress-MP with parameter " + << xpresspath << "\n"; } code = XPRSinit(xpresspath.c_str()); @@ -347,27 +386,29 @@ bool initXpressEnv(bool verbose, int xpress_oem_license_key) { printXpressBanner(false); char version[16]; XPRSgetversion(version); - LOG(WARNING) << "Optimizer version: " << version - << " (OR-Tools was compiled with version " << XPVERSION - << ").\n"; + std::cout << "Warning: " + << "Optimizer version: " << version + << " (OR-Tools was compiled with version " << XPVERSION + << ").\n"; } return true; } else { - LOG(ERROR) << "XpressInterface: Xpress found at " << xpresspath << "\n"; + std::cerr << "XpressInterface: Xpress found at " << xpresspath << "\n"; char errmsg[256]; XPRSgetlicerrmsg(errmsg, 256); - LOG(ERROR) << "XpressInterface : License error : " << errmsg - << " (XPRSinit returned code " << code << "). Please check" - << " environment variable XPRESS.\n"; + std::cerr << "XpressInterface : License error : " << errmsg + << " (XPRSinit returned code " << code << "). Please check" + << " environment variable XPRESS.\n"; return false; } } else { // if OEM key if (verbose) { - LOG(WARNING) << "XpressInterface : Initialising xpress-MP with OEM key " - << xpress_oem_license_key << "\n"; + std::cout << "Warning: " + << "XpressInterface : Initialising xpress-MP with OEM key " + << xpress_oem_license_key << "\n"; } int nvalue = 0; @@ -377,27 +418,27 @@ bool initXpressEnv(bool verbose, int xpress_oem_license_key) { XPRSlicense(&nvalue, slicmsg); if (verbose) { - VLOG(0) << "XpressInterface : First message from XPRSLicense : " - << slicmsg << "\n"; + std::cout << "XpressInterface : First message from XPRSLicense : " + << slicmsg << "\n"; } nvalue = xpress_oem_license_key - ((nvalue * nvalue) / 19); ierr = XPRSlicense(&nvalue, slicmsg); if (verbose) { - VLOG(0) << "XpressInterface : Second message from XPRSLicense : " - << slicmsg << "\n"; + std::cout << "XpressInterface : Second message from XPRSLicense : " + << slicmsg << "\n"; } if (ierr == 16) { if (verbose) { - VLOG(0) + std::cout << "XpressInterface : Optimizer development software detected\n"; } } else if (ierr != 0) { // get the license error message XPRSgetlicerrmsg(errmsg, 256); - LOG(ERROR) << "XpressInterface : " << errmsg << "\n"; + std::cerr << "XpressInterface : " << errmsg << "\n"; return false; } @@ -406,7 +447,7 @@ bool initXpressEnv(bool verbose, int xpress_oem_license_key) { if (!code) { return true; } else { - LOG(ERROR) << "XPRSinit returned code : " << code << "\n"; + std::cerr << "XPRSinit returned code : " << code << "\n"; return false; } } diff --git a/src/cpp/multisolver_interface/environment.h b/src/cpp/multisolver_interface/environment.h index b011b1a49..4bc20c0ed 100644 --- a/src/cpp/multisolver_interface/environment.h +++ b/src/cpp/multisolver_interface/environment.h @@ -12,6 +12,8 @@ // limitations under the License. #pragma once #include + +#include "dynamic_library.h" extern "C" { typedef struct xo_prob_struct* XPRSprob; } @@ -393,7 +395,27 @@ bool LoadXpressDynamicLibrary(std::string &xpresspath); #define XPRS_MIP_UNBOUNDED 7 #define XPRS_OBJ_MINIMIZE 1 #define XPRS_OBJ_MAXIMIZE -1 + +#define XPRS_ELEMS 1006 +#define XPRS_MIPENTS 1032 +#define XPRS_NAMELENGTH 1028 +#define XPRS_OUTPUTLOG_FULL_OUTPUT 1 +#define XPRS_ERRORCODE 1023 +#define XPRS_OUTPUTLOG_NO_OUTPUT 0 + extern std::function XPRScreateprob; +extern std::function XPRScopyprob; +extern std::function XPRSwritebasis; +extern std::function XPRSreadprob; +extern std::function XPRSreadbasis; +extern std::function XPRSgetrows; +extern std::function XPRSgetindex; +extern std::function XPRSgetnames; +extern std::function XPRSaddnames; +extern std::function XPRSlpoptimize; +extern std::function XPRSmipoptimize; + + extern std::function XPRSdestroyprob; extern std::function XPRSinit; extern std::function XPRSfree; From 39639040d720b39ff9919bedb775508f214d691c Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Thu, 19 Oct 2023 02:45:56 -0700 Subject: [PATCH 04/39] by default add Xpress in available solvers list --- src/CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d6e783575..903eeb892 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -6,9 +6,7 @@ if (COIN_OR) SET(AVAILABLE_SOLVER_YML_LIST "${AVAILABLE_SOLVER_YML_LIST}- Cbc\n") SET(AVAILABLE_SOLVER_YML_LIST "${AVAILABLE_SOLVER_YML_LIST}- Coin\n") endif() -if (XPRESS) SET(AVAILABLE_SOLVER_YML_LIST "${AVAILABLE_SOLVER_YML_LIST}- Xpress\n") -endif() #configure file to define antares-solver executable From 45f1a0ba9fa479b0bbc92807a2b77e3b044fa486 Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Thu, 19 Oct 2023 08:19:33 -0700 Subject: [PATCH 05/39] it works! --- src/cpp/lpnamer/main/RunProblemGeneration.cpp | 12 +++++++----- .../ZipProblemsProviderAdapter.cpp | 18 +++++++++--------- src/cpp/multisolver_interface/environment.cc | 4 ++-- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/cpp/lpnamer/main/RunProblemGeneration.cpp b/src/cpp/lpnamer/main/RunProblemGeneration.cpp index c6cbf682f..e7bf4af45 100644 --- a/src/cpp/lpnamer/main/RunProblemGeneration.cpp +++ b/src/cpp/lpnamer/main/RunProblemGeneration.cpp @@ -193,7 +193,7 @@ void RunProblemGeneration( } auto mps_file_writer = std::make_shared(lpDir_); std::for_each( - std::execution::par, problems_and_data.begin(), problems_and_data.end(), + problems_and_data.begin(), problems_and_data.end(), [&](const auto& problem_and_data) { const auto& [problem, data] = problem_and_data; std::shared_ptr variables_provider; @@ -205,8 +205,9 @@ void RunProblemGeneration( std::make_shared( problem, links, logger); } - linkProblemsGenerator.treat(data._problem_mps, couplings, problem.get(), - variables_provider.get(), mps_file_writer.get()); + linkProblemsGenerator.treat(data._problem_mps, couplings, + problem.get(), variables_provider.get(), + mps_file_writer.get()); }); reader->Close(); @@ -254,8 +255,9 @@ void RunProblemGeneration( std::make_shared( problem, links, logger); } - linkProblemsGenerator.treat(data._problem_mps, couplings, problem.get(), - variables_provider.get(), mps_file_writer.get()); + linkProblemsGenerator.treat(data._problem_mps, couplings, + problem.get(), variables_provider.get(), + mps_file_writer.get()); }); } diff --git a/src/cpp/lpnamer/problem_modifier/ZipProblemsProviderAdapter.cpp b/src/cpp/lpnamer/problem_modifier/ZipProblemsProviderAdapter.cpp index bf8aeae6f..e0a4176da 100644 --- a/src/cpp/lpnamer/problem_modifier/ZipProblemsProviderAdapter.cpp +++ b/src/cpp/lpnamer/problem_modifier/ZipProblemsProviderAdapter.cpp @@ -16,15 +16,15 @@ ZipProblemsProviderAdapter::provideProblems( SolverLogManager& solver_log_manager) const { std::vector> problems(problem_names_.size()); // Order is important. Problems need to be in the same order as names - std::transform(std::execution::par, - /*std::transform preserves order of element*/ - problem_names_.begin(), problem_names_.end(), problems.begin(), - [&](auto name) { - ZipProblemProviderAdapter problem_provider(lp_dir_, name, - archive_reader_); - return problem_provider.provide_problem(solver_name, - solver_log_manager); - }); + std::transform( + /*std::transform preserves order of element*/ + problem_names_.begin(), problem_names_.end(), problems.begin(), + [&](auto name) { + ZipProblemProviderAdapter problem_provider(lp_dir_, name, + archive_reader_); + return problem_provider.provide_problem(solver_name, + solver_log_manager); + }); return problems; } ZipProblemsProviderAdapter::ZipProblemsProviderAdapter( diff --git a/src/cpp/multisolver_interface/environment.cc b/src/cpp/multisolver_interface/environment.cc index c23323b6d..51eb02b2d 100644 --- a/src/cpp/multisolver_interface/environment.cc +++ b/src/cpp/multisolver_interface/environment.cc @@ -311,9 +311,9 @@ bool LoadXpressDynamicLibrary(std::string& xpresspath) { static std::once_flag xpress_loading_done; static bool ret; static DynamicLibrary xpress_library; - static std::mutex mutex; + // static std::mutex mutex; - mutex.lock(); + // mutex.lock(); std::call_once(xpress_loading_done, []() { const std::vector canonical_paths = From 2e0b58ff85d5ac62a54e38f9eb3657cc9cb117bb Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Thu, 19 Oct 2023 08:23:48 -0700 Subject: [PATCH 06/39] it works 2 --- src/cpp/lpnamer/main/RunProblemGeneration.cpp | 2 +- .../ZipProblemsProviderAdapter.cpp | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/cpp/lpnamer/main/RunProblemGeneration.cpp b/src/cpp/lpnamer/main/RunProblemGeneration.cpp index e7bf4af45..c022816b6 100644 --- a/src/cpp/lpnamer/main/RunProblemGeneration.cpp +++ b/src/cpp/lpnamer/main/RunProblemGeneration.cpp @@ -193,7 +193,7 @@ void RunProblemGeneration( } auto mps_file_writer = std::make_shared(lpDir_); std::for_each( - problems_and_data.begin(), problems_and_data.end(), + std::execution::par, problems_and_data.begin(), problems_and_data.end(), [&](const auto& problem_and_data) { const auto& [problem, data] = problem_and_data; std::shared_ptr variables_provider; diff --git a/src/cpp/lpnamer/problem_modifier/ZipProblemsProviderAdapter.cpp b/src/cpp/lpnamer/problem_modifier/ZipProblemsProviderAdapter.cpp index e0a4176da..bf8aeae6f 100644 --- a/src/cpp/lpnamer/problem_modifier/ZipProblemsProviderAdapter.cpp +++ b/src/cpp/lpnamer/problem_modifier/ZipProblemsProviderAdapter.cpp @@ -16,15 +16,15 @@ ZipProblemsProviderAdapter::provideProblems( SolverLogManager& solver_log_manager) const { std::vector> problems(problem_names_.size()); // Order is important. Problems need to be in the same order as names - std::transform( - /*std::transform preserves order of element*/ - problem_names_.begin(), problem_names_.end(), problems.begin(), - [&](auto name) { - ZipProblemProviderAdapter problem_provider(lp_dir_, name, - archive_reader_); - return problem_provider.provide_problem(solver_name, - solver_log_manager); - }); + std::transform(std::execution::par, + /*std::transform preserves order of element*/ + problem_names_.begin(), problem_names_.end(), problems.begin(), + [&](auto name) { + ZipProblemProviderAdapter problem_provider(lp_dir_, name, + archive_reader_); + return problem_provider.provide_problem(solver_name, + solver_log_manager); + }); return problems; } ZipProblemsProviderAdapter::ZipProblemsProviderAdapter( From 57461f65a129e2eb1e8e7690dcad87ea36228e64 Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Fri, 20 Oct 2023 02:38:40 -0700 Subject: [PATCH 07/39] tidy --- src/cpp/multisolver_interface/environment.cc | 83 ++++++++++---------- src/cpp/multisolver_interface/environment.h | 29 ++++--- 2 files changed, 55 insertions(+), 57 deletions(-) diff --git a/src/cpp/multisolver_interface/environment.cc b/src/cpp/multisolver_interface/environment.cc index 51eb02b2d..e97b24e2d 100644 --- a/src/cpp/multisolver_interface/environment.cc +++ b/src/cpp/multisolver_interface/environment.cc @@ -32,6 +32,7 @@ std::string StringJoin(const std::vector& vec) { return ret; } // This is the 'define' section. +std::function XPRSinit = nullptr; std::function XPRScopyprob = nullptr; std::function @@ -52,11 +53,34 @@ std::function XPRSlpoptimize = nullptr; std::function XPRSmipoptimize = nullptr; - +std::function XPRSfree = nullptr; std::function XPRScreateprob = nullptr; +std::function + XPRSloadlp = nullptr; std::function XPRSdestroyprob = nullptr; -std::function XPRSinit = nullptr; -std::function XPRSfree = nullptr; + +std::function + XPRSwriteprob = nullptr; +std::function XPRSgetintcontrol = + nullptr; +std::function + XPRSgetobj = nullptr; +std::function + XPRSgetrowtype = nullptr; +std::function + XPRSgetrhs = nullptr; +std::function + XPRSgetrhsrange = nullptr; +std::function + XPRSgetcoltype = nullptr; +std::function XPRSgetlb = + nullptr; +/*----*/ + std::function XPRSgetlicerrmsg = nullptr; std::function XPRSlicense = nullptr; std::function XPRSgetbanner = nullptr; @@ -70,8 +94,6 @@ std::function XPRSsetdblcontrol = nullptr; std::function XPRSsetstrcontrol = nullptr; -std::function XPRSgetintcontrol = - nullptr; std::function XPRSgetintcontrol64 = nullptr; std::function @@ -83,26 +105,12 @@ std::function XPRSgetintattrib = nullptr; std::function XPRSgetdblattrib = nullptr; -std::function - XPRSloadlp = nullptr; std::function XPRSloadlp64 = nullptr; -std::function - XPRSgetobj = nullptr; -std::function - XPRSgetrhs = nullptr; -std::function - XPRSgetrhsrange = nullptr; -std::function XPRSgetlb = - nullptr; std::function XPRSgetub = nullptr; std::function @@ -129,12 +137,6 @@ std::function XPRSchgobjsense = nullptr; std::function XPRSgetlasterror = nullptr; std::function XPRSgetbasis = nullptr; -std::function - XPRSwriteprob = nullptr; -std::function - XPRSgetrowtype = nullptr; -std::function - XPRSgetcoltype = nullptr; std::function XPRSchgbounds = nullptr; @@ -166,14 +168,13 @@ std::function XPRSsetcbmessage = nullptr; -std::function XPRSminim = nullptr; -std::function XPRSmaxim = nullptr; bool 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. + xpress_dynamic_library->GetFunction(&XPRSinit, "XPRSinit"); xpress_dynamic_library->GetFunction(&XPRScopyprob, "XPRScopyprob"); xpress_dynamic_library->GetFunction(&XPRSwritebasis, "XPRSwritebasis"); xpress_dynamic_library->GetFunction(&XPRSreadprob, "XPRSreadprob"); @@ -184,11 +185,21 @@ bool LoadXpressFunctions(DynamicLibrary* xpress_dynamic_library) { xpress_dynamic_library->GetFunction(&XPRSaddnames, "XPRSaddnames"); xpress_dynamic_library->GetFunction(&XPRSlpoptimize, "XPRSlpoptimize"); xpress_dynamic_library->GetFunction(&XPRSmipoptimize, "XPRSmipoptimize"); - + xpress_dynamic_library->GetFunction(&XPRSfree, "XPRSfree"); + xpress_dynamic_library->GetFunction(&XPRSloadlp, "XPRSloadlp"); 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(&XPRSwriteprob, "XPRSwriteprob"); + xpress_dynamic_library->GetFunction(&XPRSgetintcontrol, "XPRSgetintcontrol"); + xpress_dynamic_library->GetFunction(&XPRSgetintattrib, "XPRSgetintattrib"); + xpress_dynamic_library->GetFunction(&XPRSgetobj, "XPRSgetobj"); + xpress_dynamic_library->GetFunction(&XPRSgetrowtype, "XPRSgetrowtype"); + xpress_dynamic_library->GetFunction(&XPRSgetrhsrange, "XPRSgetrhsrange"); + xpress_dynamic_library->GetFunction(&XPRSgetrhs, "XPRSgetrhs"); + xpress_dynamic_library->GetFunction(&XPRSgetcoltype, "XPRSgetcoltype"); + xpress_dynamic_library->GetFunction(&XPRSgetlb, "XPRSgetlb"); + + /**/ xpress_dynamic_library->GetFunction(&XPRSgetlicerrmsg, "XPRSgetlicerrmsg"); xpress_dynamic_library->GetFunction(&XPRSlicense, "XPRSlicense"); xpress_dynamic_library->GetFunction(&XPRSgetbanner, "XPRSgetbanner"); @@ -200,20 +211,13 @@ bool LoadXpressFunctions(DynamicLibrary* xpress_dynamic_library) { "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(&XPRSgetdblattrib, "XPRSgetdblattrib"); - xpress_dynamic_library->GetFunction(&XPRSloadlp, "XPRSloadlp"); xpress_dynamic_library->GetFunction(&XPRSloadlp64, "XPRSloadlp64"); - 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(&XPRSaddrows, "XPRSaddrows"); @@ -226,9 +230,6 @@ bool LoadXpressFunctions(DynamicLibrary* xpress_dynamic_library) { 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(&XPRSgetlpsol, "XPRSgetlpsol"); xpress_dynamic_library->GetFunction(&XPRSgetmipsol, "XPRSgetmipsol"); @@ -239,8 +240,6 @@ bool LoadXpressFunctions(DynamicLibrary* xpress_dynamic_library) { xpress_dynamic_library->GetFunction(&XPRSchgrhsrange, "XPRSchgrhsrange"); xpress_dynamic_library->GetFunction(&XPRSchgrowtype, "XPRSchgrowtype"); xpress_dynamic_library->GetFunction(&XPRSsetcbmessage, "XPRSsetcbmessage"); - xpress_dynamic_library->GetFunction(&XPRSminim, "XPRSminim"); - xpress_dynamic_library->GetFunction(&XPRSmaxim, "XPRSmaxim"); auto notFound = xpress_dynamic_library->FunctionsNotFound(); if (!notFound.empty()) { diff --git a/src/cpp/multisolver_interface/environment.h b/src/cpp/multisolver_interface/environment.h index 4bc20c0ed..d576e10e4 100644 --- a/src/cpp/multisolver_interface/environment.h +++ b/src/cpp/multisolver_interface/environment.h @@ -403,6 +403,7 @@ bool LoadXpressDynamicLibrary(std::string &xpresspath); #define XPRS_ERRORCODE 1023 #define XPRS_OUTPUTLOG_NO_OUTPUT 0 +extern std::function XPRSinit; extern std::function XPRScreateprob; extern std::function XPRScopyprob; extern std::function XPRSwritebasis; @@ -414,11 +415,21 @@ extern std::function XPRSaddnames; extern std::function XPRSlpoptimize; extern std::function XPRSmipoptimize; +extern std::function XPRSfree; +extern std::function XPRSloadlp; +extern std::function XPRSdestroyprob; +extern std::function XPRSwriteprob; +extern std::function XPRSgetintcontrol; +extern std::function XPRSgetintattrib; +extern std::function XPRSgetobj; +extern std::function XPRSgetrowtype; +extern std::function XPRSgetrhs; +extern std::function XPRSgetrhsrange; +extern std::function XPRSgetcoltype; +extern std::function XPRSgetlb; -extern std::function XPRSdestroyprob; -extern std::function XPRSinit; -extern std::function XPRSfree; +/***/ extern std::function XPRSgetlicerrmsg; extern std::function XPRSlicense; extern std::function XPRSgetbanner; @@ -428,18 +439,11 @@ extern std::function XPRSsetintcontr extern std::function XPRSsetintcontrol64; extern std::function XPRSsetdblcontrol; extern std::function XPRSsetstrcontrol; -extern std::function XPRSgetintcontrol; extern std::function XPRSgetintcontrol64; extern std::function XPRSgetdblcontrol; extern std::function XPRSgetstringcontrol; -extern std::function XPRSgetintattrib; extern std::function XPRSgetdblattrib; -extern std::function XPRSloadlp; extern std::function XPRSloadlp64; -extern std::function XPRSgetobj; -extern std::function XPRSgetrhs; -extern std::function XPRSgetrhsrange; -extern std::function XPRSgetlb; extern std::function XPRSgetub; extern std::function XPRSgetcoef; extern std::function XPRSaddrows; @@ -452,9 +456,6 @@ extern std::function XPRSpostsolve; extern std::function XPRSchgobjsense; extern std::function XPRSgetlasterror; extern std::function XPRSgetbasis; -extern std::function XPRSwriteprob; -extern std::function XPRSgetrowtype; -extern std::function XPRSgetcoltype; extern std::function XPRSchgbounds; extern std::function XPRSgetlpsol; extern std::function XPRSgetmipsol; @@ -465,8 +466,6 @@ extern std::function XPRSchgrhsrange; extern std::function XPRSchgrowtype; extern std::function XPRSsetcbmessage; -extern std::function XPRSminim; -extern std::function XPRSmaxim; } // namespace operations_research_Xpansion From 1c884379e01784908b1f0bfb2eb4ad03ec5f9ba8 Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Fri, 20 Oct 2023 03:11:24 -0700 Subject: [PATCH 08/39] unload unused function --- src/cpp/multisolver_interface/environment.cc | 201 ++++++++++--------- src/cpp/multisolver_interface/environment.h | 62 +++--- 2 files changed, 135 insertions(+), 128 deletions(-) diff --git a/src/cpp/multisolver_interface/environment.cc b/src/cpp/multisolver_interface/environment.cc index e97b24e2d..c70426598 100644 --- a/src/cpp/multisolver_interface/environment.cc +++ b/src/cpp/multisolver_interface/environment.cc @@ -79,95 +79,100 @@ std::function XPRSgetcoltype = nullptr; std::function XPRSgetlb = nullptr; -/*----*/ - -std::function XPRSgetlicerrmsg = nullptr; -std::function XPRSlicense = nullptr; -std::function XPRSgetbanner = nullptr; -std::function XPRSgetversion = nullptr; -std::function XPRSsetdefaultcontrol = nullptr; -std::function XPRSsetintcontrol = - nullptr; -std::function - XPRSsetintcontrol64 = nullptr; -std::function XPRSsetdblcontrol = - nullptr; -std::function - XPRSsetstrcontrol = nullptr; -std::function - XPRSgetintcontrol64 = nullptr; -std::function - XPRSgetdblcontrol = nullptr; -std::function - XPRSgetstringcontrol = nullptr; -std::function XPRSgetintattrib = - nullptr; -std::function - XPRSgetdblattrib = nullptr; -std::function - XPRSloadlp64 = nullptr; std::function XPRSgetub = nullptr; -std::function - XPRSgetcoef = nullptr; +std::function XPRSdelrows = + nullptr; std::function XPRSaddrows = nullptr; -std::function XPRSdelrows = - nullptr; std::function XPRSaddcols = nullptr; -std::function XPRSdelcols = - nullptr; + std::function - XPRSchgcoltype = nullptr; -std::function - XPRSloadbasis = nullptr; -std::function XPRSpostsolve = nullptr; + const double objcoef[])> + XPRSchgobj = nullptr; std::function XPRSchgobjsense = nullptr; -std::function XPRSgetlasterror = nullptr; -std::function XPRSgetbasis = - nullptr; std::function XPRSchgbounds = nullptr; +std::function + XPRSchgcoltype = nullptr; +std::function + XPRSchgrhs = nullptr; + +std::function XPRSchgcoef = + nullptr; +std::function XPRSgetbasis = + nullptr; +std::function + XPRSgetdblattrib = nullptr; std::function XPRSgetlpsol = nullptr; std::function XPRSgetmipsol = nullptr; -std::function - XPRSchgobj = nullptr; -std::function XPRSchgcoef = - nullptr; -std::function - XPRSchgmcoef = nullptr; -std::function - XPRSchgrhs = nullptr; -std::function - XPRSchgrhsrange = nullptr; -std::function - XPRSchgrowtype = nullptr; std::function XPRSsetcbmessage = nullptr; +std::function XPRSsetintcontrol = + nullptr; +std::function XPRSsetdblcontrol = + nullptr; +std::function XPRSgetbanner = nullptr; + +std::function XPRSgetlicerrmsg = nullptr; +std::function XPRSlicense = nullptr; +std::function XPRSgetversion = nullptr; +std::function XPRSgetintattrib = + nullptr; +/*----*/ + +// std::function XPRSsetdefaultcontrol = +// nullptr; std::function +// XPRSsetintcontrol64 = nullptr; +// std::function +// XPRSsetstrcontrol = nullptr; +// std::function +// XPRSgetintcontrol64 = nullptr; +// std::function +// XPRSgetdblcontrol = nullptr; +// std::function +// XPRSgetstringcontrol = nullptr; +// std::function +// XPRSloadlp64 = nullptr; +// std::function +// XPRSgetcoef = nullptr; +// std::function XPRSdelcols +// = +// nullptr; +// std::function +// XPRSloadbasis = nullptr; +// std::function XPRSpostsolve = nullptr; +// std::function XPRSgetlasterror = nullptr; +// std::function +// XPRSchgmcoef = nullptr; +// std::function +// XPRSchgrhsrange = nullptr; +// std::function +// XPRSchgrowtype = nullptr; bool LoadXpressFunctions(DynamicLibrary* xpress_dynamic_library) { // This was generated with the parse_header_xpress.py script. @@ -198,48 +203,50 @@ bool LoadXpressFunctions(DynamicLibrary* xpress_dynamic_library) { xpress_dynamic_library->GetFunction(&XPRSgetrhs, "XPRSgetrhs"); xpress_dynamic_library->GetFunction(&XPRSgetcoltype, "XPRSgetcoltype"); xpress_dynamic_library->GetFunction(&XPRSgetlb, "XPRSgetlb"); - - /**/ - 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(&XPRSsetdefaultcontrol, - "XPRSsetdefaultcontrol"); - 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(&XPRSgetintcontrol64, - "XPRSgetintcontrol64"); - xpress_dynamic_library->GetFunction(&XPRSgetdblcontrol, "XPRSgetdblcontrol"); - xpress_dynamic_library->GetFunction(&XPRSgetstringcontrol, - "XPRSgetstringcontrol"); - xpress_dynamic_library->GetFunction(&XPRSgetdblattrib, "XPRSgetdblattrib"); - xpress_dynamic_library->GetFunction(&XPRSloadlp64, "XPRSloadlp64"); xpress_dynamic_library->GetFunction(&XPRSgetub, "XPRSgetub"); - xpress_dynamic_library->GetFunction(&XPRSgetcoef, "XPRSgetcoef"); - xpress_dynamic_library->GetFunction(&XPRSaddrows, "XPRSaddrows"); xpress_dynamic_library->GetFunction(&XPRSdelrows, "XPRSdelrows"); + xpress_dynamic_library->GetFunction(&XPRSaddrows, "XPRSaddrows"); + xpress_dynamic_library->GetFunction(&XPRSchgobj, "XPRSchgobj"); xpress_dynamic_library->GetFunction(&XPRSaddcols, "XPRSaddcols"); - 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(&XPRSchgbounds, "XPRSchgbounds"); + xpress_dynamic_library->GetFunction(&XPRSchgcoltype, "XPRSchgcoltype"); + xpress_dynamic_library->GetFunction(&XPRSchgrhs, "XPRSchgrhs"); + xpress_dynamic_library->GetFunction(&XPRSchgcoef, "XPRSchgcoef"); + xpress_dynamic_library->GetFunction(&XPRSgetbasis, "XPRSgetbasis"); xpress_dynamic_library->GetFunction(&XPRSgetlpsol, "XPRSgetlpsol"); + xpress_dynamic_library->GetFunction(&XPRSgetdblattrib, "XPRSgetdblattrib"); 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(&XPRSchgrhs, "XPRSchgrhs"); - xpress_dynamic_library->GetFunction(&XPRSchgrhsrange, "XPRSchgrhsrange"); - xpress_dynamic_library->GetFunction(&XPRSchgrowtype, "XPRSchgrowtype"); xpress_dynamic_library->GetFunction(&XPRSsetcbmessage, "XPRSsetcbmessage"); + xpress_dynamic_library->GetFunction(&XPRSsetintcontrol, "XPRSsetintcontrol"); + xpress_dynamic_library->GetFunction(&XPRSsetdblcontrol, "XPRSsetdblcontrol"); + xpress_dynamic_library->GetFunction(&XPRSgetbanner, "XPRSgetbanner"); + xpress_dynamic_library->GetFunction(&XPRSgetlicerrmsg, "XPRSgetlicerrmsg"); + xpress_dynamic_library->GetFunction(&XPRSlicense, "XPRSlicense"); + xpress_dynamic_library->GetFunction(&XPRSgetversion, "XPRSgetversion"); + + /**/ + // xpress_dynamic_library->GetFunction(&XPRSsetdefaultcontrol, + // "XPRSsetdefaultcontrol"); + // xpress_dynamic_library->GetFunction(&XPRSsetintcontrol64, + // "XPRSsetintcontrol64"); + // xpress_dynamic_library->GetFunction(&XPRSsetstrcontrol, + // "XPRSsetstrcontrol"); + // xpress_dynamic_library->GetFunction(&XPRSgetintcontrol64, + // "XPRSgetintcontrol64"); + // xpress_dynamic_library->GetFunction(&XPRSgetdblcontrol, + // "XPRSgetdblcontrol"); + // xpress_dynamic_library->GetFunction(&XPRSgetstringcontrol, + // "XPRSgetstringcontrol"); + // xpress_dynamic_library->GetFunction(&XPRSloadlp64, "XPRSloadlp64"); + // xpress_dynamic_library->GetFunction(&XPRSgetcoef, "XPRSgetcoef"); + // xpress_dynamic_library->GetFunction(&XPRSdelcols, "XPRSdelcols"); + // xpress_dynamic_library->GetFunction(&XPRSloadbasis, "XPRSloadbasis"); + // xpress_dynamic_library->GetFunction(&XPRSpostsolve, "XPRSpostsolve"); + // xpress_dynamic_library->GetFunction(&XPRSgetlasterror, "XPRSgetlasterror"); + // xpress_dynamic_library->GetFunction(&XPRSchgmcoef, "XPRSchgmcoef"); + // xpress_dynamic_library->GetFunction(&XPRSchgrhsrange, "XPRSchgrhsrange"); + // xpress_dynamic_library->GetFunction(&XPRSchgrowtype, "XPRSchgrowtype"); auto notFound = xpress_dynamic_library->FunctionsNotFound(); if (!notFound.empty()) { diff --git a/src/cpp/multisolver_interface/environment.h b/src/cpp/multisolver_interface/environment.h index d576e10e4..86bc23a53 100644 --- a/src/cpp/multisolver_interface/environment.h +++ b/src/cpp/multisolver_interface/environment.h @@ -427,45 +427,45 @@ extern std::function XPRS extern std::function XPRSgetrhsrange; extern std::function XPRSgetcoltype; extern std::function XPRSgetlb; - - -/***/ -extern std::function XPRSgetlicerrmsg; -extern std::function XPRSlicense; -extern std::function XPRSgetbanner; -extern std::function XPRSgetversion; -extern std::function XPRSsetdefaultcontrol; -extern std::function XPRSsetintcontrol; -extern std::function XPRSsetintcontrol64; -extern std::function XPRSsetdblcontrol; -extern std::function XPRSsetstrcontrol; -extern std::function XPRSgetintcontrol64; -extern std::function XPRSgetdblcontrol; -extern std::function XPRSgetstringcontrol; -extern std::function XPRSgetdblattrib; -extern std::function XPRSloadlp64; extern std::function XPRSgetub; -extern std::function XPRSgetcoef; -extern std::function XPRSaddrows; extern std::function XPRSdelrows; +extern std::function XPRSaddrows; extern std::function XPRSaddcols; -extern std::function XPRSdelcols; -extern std::function XPRSchgcoltype; -extern std::function XPRSloadbasis; -extern std::function XPRSpostsolve; +extern std::function XPRSchgobj; extern std::function XPRSchgobjsense; -extern std::function XPRSgetlasterror; -extern std::function XPRSgetbasis; extern std::function XPRSchgbounds; +extern std::function XPRSchgcoltype; +extern std::function XPRSchgrhs; +extern std::function XPRSchgcoef; +extern std::function XPRSgetbasis; +extern std::function XPRSgetdblattrib; extern std::function XPRSgetlpsol; extern std::function XPRSgetmipsol; -extern std::function XPRSchgobj; -extern std::function XPRSchgcoef; -extern std::function XPRSchgmcoef; -extern std::function XPRSchgrhs; -extern std::function XPRSchgrhsrange; -extern std::function XPRSchgrowtype; extern std::function XPRSsetcbmessage; +extern std::function XPRSsetintcontrol; +extern std::function XPRSsetdblcontrol; +extern std::function XPRSgetbanner; + +extern std::function XPRSgetlicerrmsg; +extern std::function XPRSlicense; +extern std::function XPRSgetversion; + +/***/ +// extern std::function XPRSsetdefaultcontrol; +// extern std::function XPRSsetintcontrol64; +// extern std::function XPRSsetstrcontrol; +// extern std::function XPRSgetintcontrol64; +// extern std::function XPRSgetdblcontrol; +// extern std::function XPRSgetstringcontrol; +// extern std::function XPRSloadlp64; +// extern std::function XPRSgetcoef; +// extern std::function XPRSdelcols; +// extern std::function XPRSloadbasis; +// extern std::function XPRSpostsolve; +// extern std::function XPRSgetlasterror; +// extern std::function XPRSchgmcoef; +// extern std::function XPRSchgrhsrange; +// extern std::function XPRSchgrowtype; } // namespace operations_research_Xpansion From de57ad538e8b9470ff7545e7f6a5d2f525da83c0 Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Fri, 20 Oct 2023 03:18:14 -0700 Subject: [PATCH 09/39] fix conversion path->string --- src/cpp/multisolver_interface/environment.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cpp/multisolver_interface/environment.cc b/src/cpp/multisolver_interface/environment.cc index c70426598..69625b406 100644 --- a/src/cpp/multisolver_interface/environment.cc +++ b/src/cpp/multisolver_interface/environment.cc @@ -283,11 +283,11 @@ std::vector XpressDynamicLibraryPotentialPaths() { if (xpress_home_from_env != nullptr) { std::filesystem::path prefix(xpress_home_from_env); #if defined(_MSC_VER) // Windows - potential_paths.push_back(prefix / "\\bin\\xprs.dll"); + potential_paths.push_back((prefix / "\\bin\\xprs.dll").string()); #elif defined(__APPLE__) // OS X - potential_paths.push_back(prefix / "/lib/libxprs.dylib"); + potential_paths.push_back((prefix / "/lib/libxprs.dylib").string()); #elif defined(__GNUC__) // Linux - potential_paths.push_back(prefix / "/lib/libxprs.so"); + potential_paths.push_back((prefix / "/lib/libxprs.so").string()); #else std::cerr << "OS Not recognized by xpress/environment.cc." << " You won't be able to use Xpress."; From 0450e4c3ecb10e9296f640b3a1b27926a6c4c098 Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Fri, 20 Oct 2023 07:06:59 -0700 Subject: [PATCH 10/39] add newline after msf --- src/cpp/multisolver_interface/environment.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cpp/multisolver_interface/environment.cc b/src/cpp/multisolver_interface/environment.cc index 69625b406..6bcfde96b 100644 --- a/src/cpp/multisolver_interface/environment.cc +++ b/src/cpp/multisolver_interface/environment.cc @@ -341,7 +341,7 @@ bool LoadXpressDynamicLibrary(std::string& xpresspath) { } else { std::string msg("Could not find the Xpress shared library. Looked in: [" + StringJoin(canonical_paths) + - "]. Please check environment variable XPRESSDIR"); + "]. Please check environment variable XPRESSDIR\n"); std::cout << msg << std::endl; ret = false; } From 2393fdda5b4262f263cd65660f020e01c4bf9302 Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Fri, 20 Oct 2023 07:15:16 -0700 Subject: [PATCH 11/39] set xpress dir env var --- .github/workflows/build_windows.yml | 1 + .github/workflows/windows-vcpkg.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/build_windows.yml b/.github/workflows/build_windows.yml index 5f8c59407..9de6780a6 100644 --- a/.github/workflows/build_windows.yml +++ b/.github/workflows/build_windows.yml @@ -141,5 +141,6 @@ jobs: run: | set PATH=%PATH%;C:\Program Files\Microsoft MPI\Bin set PATH=%PATH%;${{ env.XPRESS }} + set PATH=%PATH%;${{ env.XPRESSDIR }} cd _build ctest -C Release --output-on-failure -L "medium|unit|benders|lpnamer" \ No newline at end of file diff --git a/.github/workflows/windows-vcpkg.yml b/.github/workflows/windows-vcpkg.yml index 063bdab22..c8c8074c6 100644 --- a/.github/workflows/windows-vcpkg.yml +++ b/.github/workflows/windows-vcpkg.yml @@ -193,6 +193,7 @@ jobs: run: | set PATH=%PATH%;C:\Program Files\Microsoft MPI\Bin\ set PATH=%PATH%;${{ env.XPRESS }} + set PATH=%PATH%;${{ env.XPRESSDIR }} cd _build ctest -C Release --output-on-failure -L "medium|unit|benders|lpnamer" From 88ba8c7dafa9f287f12a0eaa2c0577c5c5a94df9 Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Fri, 20 Oct 2023 08:13:59 -0700 Subject: [PATCH 12/39] windows set env var XPRESSDIR --- .github/workflows/build_windows.yml | 3 ++- .github/workflows/windows-vcpkg.yml | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_windows.yml b/.github/workflows/build_windows.yml index 9de6780a6..de503d196 100644 --- a/.github/workflows/build_windows.yml +++ b/.github/workflows/build_windows.yml @@ -141,6 +141,7 @@ jobs: run: | set PATH=%PATH%;C:\Program Files\Microsoft MPI\Bin set PATH=%PATH%;${{ env.XPRESS }} - set PATH=%PATH%;${{ env.XPRESSDIR }} + set XPRESSDIR=${{ env.XPRESSDIR }} + cd _build ctest -C Release --output-on-failure -L "medium|unit|benders|lpnamer" \ No newline at end of file diff --git a/.github/workflows/windows-vcpkg.yml b/.github/workflows/windows-vcpkg.yml index c8c8074c6..2a3478883 100644 --- a/.github/workflows/windows-vcpkg.yml +++ b/.github/workflows/windows-vcpkg.yml @@ -193,7 +193,7 @@ jobs: run: | set PATH=%PATH%;C:\Program Files\Microsoft MPI\Bin\ set PATH=%PATH%;${{ env.XPRESS }} - set PATH=%PATH%;${{ env.XPRESSDIR }} + set XPRESSDIR=${{ env.XPRESSDIR }} cd _build ctest -C Release --output-on-failure -L "medium|unit|benders|lpnamer" From d7840549bb6305ccfc527e07d63cbf1130474224 Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Mon, 23 Oct 2023 11:26:28 +0200 Subject: [PATCH 13/39] update windows getenv method --- src/cpp/multisolver_interface/environment.cc | 24 +++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/cpp/multisolver_interface/environment.cc b/src/cpp/multisolver_interface/environment.cc index 6bcfde96b..9a7cccc5f 100644 --- a/src/cpp/multisolver_interface/environment.cc +++ b/src/cpp/multisolver_interface/environment.cc @@ -279,8 +279,26 @@ std::vector XpressDynamicLibraryPotentialPaths() { std::vector potential_paths; // Look for libraries pointed by XPRESSDIR first. - const char* xpress_home_from_env = getenv("XPRESSDIR"); - if (xpress_home_from_env != nullptr) { + const char* XPRESSDIR = "XPRESSDIR"; + std::string xpress_home_from_env = ""; +#ifdef _MSC_VER + size_t requiredSize; + + getenv_s(&requiredSize, NULL, 0, XPRESSDIR); + if (requiredSize == 0) { + std::cout << "XPRESS doesn't exist!\n"; + } + + xpress_home_from_env.resize(requiredSize); + + // Get the value of the LIB environment variable. + getenv_s(&requiredSize, xpress_home_from_env.data(), requiredSize, XPRESSDIR); + +#else + xpress_home_from_env = getenv("XPRESSDIR"); +#endif + + if (xpress_home_from_env != "") { std::filesystem::path prefix(xpress_home_from_env); #if defined(_MSC_VER) // Windows potential_paths.push_back((prefix / "\\bin\\xprs.dll").string()); @@ -306,7 +324,7 @@ std::vector XpressDynamicLibraryPotentialPaths() { #elif defined(__GNUC__) // Linux potential_paths.push_back("/opt/xpressmp/lib/libxprs.so"); #else - std::cerr << "OS Not recognized by xpress/environment.cc." + std::cerr << "OS Not recognized by environment.cc." << " You won't be able to use Xpress."; #endif return potential_paths; From ca3b2266742409742af694bc5f904e81c2286038 Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Mon, 23 Oct 2023 11:59:16 +0200 Subject: [PATCH 14/39] update getenv --- src/cpp/multisolver_interface/environment.cc | 29 ++++++++++++-------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/cpp/multisolver_interface/environment.cc b/src/cpp/multisolver_interface/environment.cc index 9a7cccc5f..e4dda494a 100644 --- a/src/cpp/multisolver_interface/environment.cc +++ b/src/cpp/multisolver_interface/environment.cc @@ -275,28 +275,35 @@ void printXpressBanner(bool error) { } } -std::vector XpressDynamicLibraryPotentialPaths() { - std::vector potential_paths; - +std::string GetXpressVarFromEnvironmentVariables(const char* XPRESS_var) { // Look for libraries pointed by XPRESSDIR first. - const char* XPRESSDIR = "XPRESSDIR"; std::string xpress_home_from_env = ""; #ifdef _MSC_VER size_t requiredSize; - getenv_s(&requiredSize, NULL, 0, XPRESSDIR); + getenv_s(&requiredSize, NULL, 0, XPRESS_var); if (requiredSize == 0) { - std::cout << "XPRESS doesn't exist!\n"; + std::cout << XPRESS_var << " doesn't exist!\n"; } xpress_home_from_env.resize(requiredSize); // Get the value of the LIB environment variable. - getenv_s(&requiredSize, xpress_home_from_env.data(), requiredSize, XPRESSDIR); + getenv_s(&requiredSize, xpress_home_from_env.data(), requiredSize, + XPRESS_var); #else - xpress_home_from_env = getenv("XPRESSDIR"); + xpress_home_from_env = getenv(XPRESS_var); #endif + return xpress_home_from_env; +} + +std::vector XpressDynamicLibraryPotentialPaths() { + std::vector potential_paths; + + const char* XPRESSDIR = "XPRESSDIR"; + std::string xpress_home_from_env = + GetXpressVarFromEnvironmentVariables(XPRESSDIR); if (xpress_home_from_env != "") { std::filesystem::path prefix(xpress_home_from_env); @@ -312,7 +319,7 @@ std::vector XpressDynamicLibraryPotentialPaths() { #endif } else { std::cout << "Warning: " - << "Environment variable XPRESSDIR undefined.\n"; + << "Environment variable " << XPRESSDIR << " undefined.\n"; } // Search for canonical places. @@ -378,8 +385,8 @@ bool initXpressEnv(bool verbose, int xpress_oem_license_key) { return false; } - const char* xpress_from_env = getenv("XPRESS"); - if (xpress_from_env == nullptr) { + std::string xpress_from_env = GetXpressVarFromEnvironmentVariables("XPRESS"); + if (xpress_from_env == "") { if (verbose) { std::cout << "Warning: " From 5b8710c982b0b8b9744df0a17fc8b2b14a9668a7 Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Mon, 23 Oct 2023 14:49:41 +0200 Subject: [PATCH 15/39] write err in stderr --- src/cpp/multisolver_interface/environment.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cpp/multisolver_interface/environment.cc b/src/cpp/multisolver_interface/environment.cc index e4dda494a..48544035f 100644 --- a/src/cpp/multisolver_interface/environment.cc +++ b/src/cpp/multisolver_interface/environment.cc @@ -318,7 +318,7 @@ std::vector XpressDynamicLibraryPotentialPaths() { << " You won't be able to use Xpress."; #endif } else { - std::cout << "Warning: " + std::cerr << "Warning: " << "Environment variable " << XPRESSDIR << " undefined.\n"; } From 239c78f00beb8bb6b0dce4ccf9e47c5e81db66d9 Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Mon, 23 Oct 2023 14:52:40 +0200 Subject: [PATCH 16/39] build clean path --- src/cpp/multisolver_interface/environment.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cpp/multisolver_interface/environment.cc b/src/cpp/multisolver_interface/environment.cc index 48544035f..6a58c9358 100644 --- a/src/cpp/multisolver_interface/environment.cc +++ b/src/cpp/multisolver_interface/environment.cc @@ -308,7 +308,7 @@ std::vector XpressDynamicLibraryPotentialPaths() { if (xpress_home_from_env != "") { std::filesystem::path prefix(xpress_home_from_env); #if defined(_MSC_VER) // Windows - potential_paths.push_back((prefix / "\\bin\\xprs.dll").string()); + potential_paths.push_back((prefix / "bin" / "xprs.dll").string()); #elif defined(__APPLE__) // OS X potential_paths.push_back((prefix / "/lib/libxprs.dylib").string()); #elif defined(__GNUC__) // Linux From f46956a482eaa90e55a68a8fa8b5228f11a26226 Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Mon, 23 Oct 2023 14:54:43 +0200 Subject: [PATCH 17/39] print clearer err message --- src/cpp/multisolver_interface/environment.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cpp/multisolver_interface/environment.cc b/src/cpp/multisolver_interface/environment.cc index 6a58c9358..cdec34c8e 100644 --- a/src/cpp/multisolver_interface/environment.cc +++ b/src/cpp/multisolver_interface/environment.cc @@ -283,7 +283,8 @@ std::string GetXpressVarFromEnvironmentVariables(const char* XPRESS_var) { getenv_s(&requiredSize, NULL, 0, XPRESS_var); if (requiredSize == 0) { - std::cout << XPRESS_var << " doesn't exist!\n"; + std::cerr << "[Windows getenv_s function]: " << XPRESS_var + << " doesn't exist!\n"; } xpress_home_from_env.resize(requiredSize); From d30bdf385af6b2138771cc7151f298f64a89f12e Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Mon, 23 Oct 2023 15:55:18 +0200 Subject: [PATCH 18/39] list xpress dir --- .github/workflows/build_windows.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.github/workflows/build_windows.yml b/.github/workflows/build_windows.yml index de503d196..be308343b 100644 --- a/.github/workflows/build_windows.yml +++ b/.github/workflows/build_windows.yml @@ -43,6 +43,17 @@ jobs: ref: 8.13a token: ${{ secrets.AS_TOKEN }} + - name: list xpress dir + if: matrix.xprs == 'XPRESS-ON' + shell: bash + run: | + ls ${{ env.XPRESSDIR }} + echo "************************" + ls ${{ env.XPRESSDIR }}\xpress\bin + echo "************************" + ls ${{ env.XPRESSDIR }}\xpress\lib + echo "************************" + - name: Get release if: github.event_name == 'release' && github.event.action == 'created' id: get_release From ea1c4f04eb244dff09343670fd33935efa82b9f4 Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Mon, 23 Oct 2023 15:59:05 +0200 Subject: [PATCH 19/39] list xpress dir 2 --- .github/workflows/build_windows.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build_windows.yml b/.github/workflows/build_windows.yml index be308343b..aeba902a1 100644 --- a/.github/workflows/build_windows.yml +++ b/.github/workflows/build_windows.yml @@ -47,11 +47,11 @@ jobs: if: matrix.xprs == 'XPRESS-ON' shell: bash run: | - ls ${{ env.XPRESSDIR }} + ls "${{ env.XPRESSDIR }}" echo "************************" - ls ${{ env.XPRESSDIR }}\xpress\bin + ls "${{ env.XPRESSDIR }}\xpress\bin" echo "************************" - ls ${{ env.XPRESSDIR }}\xpress\lib + ls "${{ env.XPRESSDIR }}\xpress\lib" echo "************************" - name: Get release From fbd3fda1601be884c0af4611f59b1c53f51492e9 Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Mon, 23 Oct 2023 16:05:25 +0200 Subject: [PATCH 20/39] list xpress dir 3 --- .github/workflows/build_windows.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build_windows.yml b/.github/workflows/build_windows.yml index aeba902a1..3d285aaa2 100644 --- a/.github/workflows/build_windows.yml +++ b/.github/workflows/build_windows.yml @@ -24,7 +24,7 @@ jobs: xprs: [ XPRESS-ON, XPRESS-OFF ] env: XPRESSDIR: ${{ github.workspace }}\xpress - XPRESS: ${{ github.workspace }}\xpress\bin + XPRESS: ${{ github.workspace }}\bin XPRS_LIB_Path: ${{ github.workspace }}\xpress\lib # Indicates the location of the vcpkg as a Git submodule of the project repository. VCPKG_ROOT: ${{ github.workspace }}/vcpkg @@ -49,9 +49,9 @@ jobs: run: | ls "${{ env.XPRESSDIR }}" echo "************************" - ls "${{ env.XPRESSDIR }}\xpress\bin" + ls "${{ env.XPRESSDIR }}\bin" echo "************************" - ls "${{ env.XPRESSDIR }}\xpress\lib" + ls "${{ env.XPRESSDIR }}\lib" echo "************************" - name: Get release From 80a7815f47278db39069113e5d4727c4ce94ad5d Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Mon, 23 Oct 2023 16:26:05 +0200 Subject: [PATCH 21/39] list xpress dir 4 --- .github/workflows/build_windows.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_windows.yml b/.github/workflows/build_windows.yml index 3d285aaa2..9d77c4921 100644 --- a/.github/workflows/build_windows.yml +++ b/.github/workflows/build_windows.yml @@ -24,7 +24,7 @@ jobs: xprs: [ XPRESS-ON, XPRESS-OFF ] env: XPRESSDIR: ${{ github.workspace }}\xpress - XPRESS: ${{ github.workspace }}\bin + XPRESS: ${{ github.workspace }}\xpress\bin XPRS_LIB_Path: ${{ github.workspace }}\xpress\lib # Indicates the location of the vcpkg as a Git submodule of the project repository. VCPKG_ROOT: ${{ github.workspace }}/vcpkg @@ -153,6 +153,9 @@ jobs: set PATH=%PATH%;C:\Program Files\Microsoft MPI\Bin set PATH=%PATH%;${{ env.XPRESS }} set XPRESSDIR=${{ env.XPRESSDIR }} + DIR "${{ env.XPRESSDIR }}" + DIR "${{ env.XPRESSDIR }}\bin" + DIR "${{ env.XPRESSDIR }}\lib" cd _build - ctest -C Release --output-on-failure -L "medium|unit|benders|lpnamer" \ No newline at end of file + ctest -C Release --output-on-failure -L "unit" \ No newline at end of file From 65f0ec1fb74b656d0de574ddf3e90c7cad0b2943 Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Mon, 23 Oct 2023 16:30:41 +0200 Subject: [PATCH 22/39] list xpress dir 5 --- .github/workflows/build_windows.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build_windows.yml b/.github/workflows/build_windows.yml index 9d77c4921..e8b697088 100644 --- a/.github/workflows/build_windows.yml +++ b/.github/workflows/build_windows.yml @@ -47,6 +47,7 @@ jobs: if: matrix.xprs == 'XPRESS-ON' shell: bash run: | + cat "${{ env.XPRESSDIR }}\bin\xpauth.xpr" ls "${{ env.XPRESSDIR }}" echo "************************" ls "${{ env.XPRESSDIR }}\bin" From ccbdf1309a31eaab757c3c8d7884ce0b63bf8ef6 Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Tue, 24 Oct 2023 12:09:47 +0200 Subject: [PATCH 23/39] remove prepos --- src/cpp/multisolver_interface/CMakeLists.txt | 5 +++++ src/cpp/multisolver_interface/SolverFactory.cpp | 14 +++++--------- tests/cpp/sensitivity/SensitivityStudyTest.cpp | 8 +++++--- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/cpp/multisolver_interface/CMakeLists.txt b/src/cpp/multisolver_interface/CMakeLists.txt index 36b8de6ad..d9486232b 100644 --- a/src/cpp/multisolver_interface/CMakeLists.txt +++ b/src/cpp/multisolver_interface/CMakeLists.txt @@ -16,6 +16,10 @@ list(APPEND Solver_sources ${CMAKE_CURRENT_LIST_DIR}/SolverFactory.cpp ) +list(APPEND XPRESS_LOAD + ${CMAKE_CURRENT_LIST_DIR}/environment.cc + ${CMAKE_CURRENT_LIST_DIR}/environment.h +) # XPRESS #IF( XPRESS ) @@ -41,6 +45,7 @@ ENDIF(COIN_OR) # --------------------------------------------------------------------------- add_library (solvers STATIC ${Solver_sources} + ${XPRESS_LOAD} ) get_target_property(xpansion_interfaces_path xpansion_interfaces INTERFACE_INCLUDE_DIRECTORIES) target_include_directories (solvers diff --git a/src/cpp/multisolver_interface/SolverFactory.cpp b/src/cpp/multisolver_interface/SolverFactory.cpp index a8c227bf7..16fdc2b7a 100644 --- a/src/cpp/multisolver_interface/SolverFactory.cpp +++ b/src/cpp/multisolver_interface/SolverFactory.cpp @@ -1,7 +1,7 @@ -// #ifdef XPRESS + #include "SolverXpress.h" #include "environment.h" -// #endif + #ifdef COIN_OR #include "SolverCbc.h" #include "SolverClp.h" @@ -26,11 +26,10 @@ SolverAbstract::Ptr SolverFactory::create_solver( if (solver_name == "") { throw InvalidSolverNameException(solver_name, LOGLOCATION); } -#ifdef XPRESS - else if (solver_name == XPRESS_STR) { + + else if (isXpress_available_ && solver_name == XPRESS_STR) { return std::make_shared(); } -#endif #ifdef COIN_OR if (solver_name == COIN_STR && solver_type == SOLVER_TYPE::CONTINUOUS) { return std::make_shared(); @@ -60,12 +59,9 @@ SolverAbstract::Ptr SolverFactory::create_solver( const std::string &solver_name) const { if (solver_name == "") { throw InvalidSolverNameException(solver_name, LOGLOCATION); - } -#ifdef XPRESS - else if (solver_name == XPRESS_STR) { + } else if (isXpress_available_ && solver_name == XPRESS_STR) { return std::make_shared(); } -#endif #ifdef COIN_OR else if (solver_name == CLP_STR) { return std::make_shared(); diff --git a/tests/cpp/sensitivity/SensitivityStudyTest.cpp b/tests/cpp/sensitivity/SensitivityStudyTest.cpp index 6559f5b9b..1ca263921 100644 --- a/tests/cpp/sensitivity/SensitivityStudyTest.cpp +++ b/tests/cpp/sensitivity/SensitivityStudyTest.cpp @@ -1,5 +1,6 @@ #include "SensitivityFileLogger.h" #include "SensitivityStudy.h" +#include "environment.h" #include "gtest/gtest.h" #include "multisolver_interface/SolverFactory.h" @@ -106,9 +107,10 @@ class SensitivityStudyTest : public ::testing::Test { std::string mps_path, std::map> expec_output_data_map) { std::vector solvers_name = {coin_name}; -#ifdef XPRESS - solvers_name.push_back(xpress_name); -#endif + if (operations_research_Xpansion::XpressIsCorrectlyInstalled()) { + solvers_name.push_back(xpress_name); + } + for (auto solver_name : solvers_name) { init_solver(solver_name, mps_path); input_data.last_master = math_problem; From 682bd836e2e0af6f29279a1a39dd91911f5f495e Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Tue, 24 Oct 2023 12:17:15 +0200 Subject: [PATCH 24/39] some move --- CMakeLists.txt | 25 ------------------- src/cpp/multisolver_interface/CMakeLists.txt | 4 +-- .../multisolver_interface/SolverFactory.cpp | 2 +- src/cpp/multisolver_interface/SolverXpress.h | 2 +- src/cpp/multisolver_interface/environment.cc | 2 +- .../multisolver_interface}/environment.h | 0 .../cpp/sensitivity/SensitivityStudyTest.cpp | 2 +- 7 files changed, 5 insertions(+), 32 deletions(-) rename src/cpp/multisolver_interface/{ => include/multisolver_interface}/environment.h (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 50349849e..412f7fcba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -237,31 +237,6 @@ endif() find_package(jsoncpp CONFIG REQUIRED) -# Third-party solver -## Xpress -if(XPRESS) - message("XPRESS is ${XPRESS}") - - #Default xpress install dir - if (NOT XPRESSDIR) - if (MSVC) - set(XPRESSDIR "C:/xpressmp") - elseif(UNIX) - set(XPRESSDIR "/opt/xpressmp") - endif() - endif() - - find_package(XPRESS REQUIRED) - - # Add solver variables for usage in C++ source code - # There are already some variables defined by SOLVER, -DUSE_XPRESS, -DUSE_CBC - # But they are exclusive, only one can be set to True - # We need to keep COIN-OR at least COIN-OR to True while it is required in lpnamer - # and we want to allow compilation with several solvers so that the user can switch - # the solver without any compilation phase. - # @TODO : I think those parameters should be merged in a future version - add_definitions( -DXPRESS=true ) -endif(XPRESS) ## Coin-OR (Clp and CBC solvers) diff --git a/src/cpp/multisolver_interface/CMakeLists.txt b/src/cpp/multisolver_interface/CMakeLists.txt index d9486232b..dae17ecfb 100644 --- a/src/cpp/multisolver_interface/CMakeLists.txt +++ b/src/cpp/multisolver_interface/CMakeLists.txt @@ -16,17 +16,15 @@ list(APPEND Solver_sources ${CMAKE_CURRENT_LIST_DIR}/SolverFactory.cpp ) + list(APPEND XPRESS_LOAD ${CMAKE_CURRENT_LIST_DIR}/environment.cc - ${CMAKE_CURRENT_LIST_DIR}/environment.h ) # XPRESS #IF( XPRESS ) list(APPEND Solver_sources ${CMAKE_CURRENT_LIST_DIR}/SolverXpress.cpp - ${CMAKE_CURRENT_LIST_DIR}/environment.h - ${CMAKE_CURRENT_LIST_DIR}/environment.cc ) #ENDIF( XPRESS ) diff --git a/src/cpp/multisolver_interface/SolverFactory.cpp b/src/cpp/multisolver_interface/SolverFactory.cpp index 16fdc2b7a..4e321b0ec 100644 --- a/src/cpp/multisolver_interface/SolverFactory.cpp +++ b/src/cpp/multisolver_interface/SolverFactory.cpp @@ -1,6 +1,6 @@ #include "SolverXpress.h" -#include "environment.h" +#include "multisolver_interface/environment.h" #ifdef COIN_OR #include "SolverCbc.h" diff --git a/src/cpp/multisolver_interface/SolverXpress.h b/src/cpp/multisolver_interface/SolverXpress.h index 82f3d4baa..432936690 100644 --- a/src/cpp/multisolver_interface/SolverXpress.h +++ b/src/cpp/multisolver_interface/SolverXpress.h @@ -3,8 +3,8 @@ #include #include -#include "environment.h" #include "multisolver_interface/SolverAbstract.h" +#include "multisolver_interface/environment.h" /*! * \class class SolverXpress diff --git a/src/cpp/multisolver_interface/environment.cc b/src/cpp/multisolver_interface/environment.cc index cdec34c8e..be595b4b8 100644 --- a/src/cpp/multisolver_interface/environment.cc +++ b/src/cpp/multisolver_interface/environment.cc @@ -11,7 +11,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "environment.h" +#include "multisolver_interface/environment.h" #include #include diff --git a/src/cpp/multisolver_interface/environment.h b/src/cpp/multisolver_interface/include/multisolver_interface/environment.h similarity index 100% rename from src/cpp/multisolver_interface/environment.h rename to src/cpp/multisolver_interface/include/multisolver_interface/environment.h diff --git a/tests/cpp/sensitivity/SensitivityStudyTest.cpp b/tests/cpp/sensitivity/SensitivityStudyTest.cpp index 1ca263921..35eaadf9d 100644 --- a/tests/cpp/sensitivity/SensitivityStudyTest.cpp +++ b/tests/cpp/sensitivity/SensitivityStudyTest.cpp @@ -1,8 +1,8 @@ #include "SensitivityFileLogger.h" #include "SensitivityStudy.h" -#include "environment.h" #include "gtest/gtest.h" #include "multisolver_interface/SolverFactory.h" +#include "multisolver_interface/environment.h" class SensitivityStudyTest : public ::testing::Test { public: From 925a4a75159b49e32db3de220d1a9565c07c7efc Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Tue, 24 Oct 2023 12:18:45 +0200 Subject: [PATCH 25/39] move header file --- .../{ => include/multisolver_interface}/dynamic_library.h | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/cpp/multisolver_interface/{ => include/multisolver_interface}/dynamic_library.h (100%) diff --git a/src/cpp/multisolver_interface/dynamic_library.h b/src/cpp/multisolver_interface/include/multisolver_interface/dynamic_library.h similarity index 100% rename from src/cpp/multisolver_interface/dynamic_library.h rename to src/cpp/multisolver_interface/include/multisolver_interface/dynamic_library.h From 9aa3c50edb27a3799fee10bbc3d8a4b44006a84d Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Tue, 24 Oct 2023 12:28:31 +0200 Subject: [PATCH 26/39] treat warning --- src/cpp/multisolver_interface/SolverFactory.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cpp/multisolver_interface/SolverFactory.cpp b/src/cpp/multisolver_interface/SolverFactory.cpp index 4e321b0ec..d575a0972 100644 --- a/src/cpp/multisolver_interface/SolverFactory.cpp +++ b/src/cpp/multisolver_interface/SolverFactory.cpp @@ -11,8 +11,8 @@ SolverFactory::SolverFactory() { _available_solvers.clear(); - if (isXpress_available_ = - operations_research_Xpansion::XpressIsCorrectlyInstalled()) { + if ((isXpress_available_ = + operations_research_Xpansion::XpressIsCorrectlyInstalled())) { _available_solvers.push_back(XPRESS_STR); } #ifdef COIN_OR From b5d1f37645e6463f2f9ee044ff56daf586f6995a Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Tue, 24 Oct 2023 14:22:36 +0200 Subject: [PATCH 27/39] remove prints --- .github/workflows/build_windows.yml | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/.github/workflows/build_windows.yml b/.github/workflows/build_windows.yml index e8b697088..9ebf684a0 100644 --- a/.github/workflows/build_windows.yml +++ b/.github/workflows/build_windows.yml @@ -43,18 +43,6 @@ jobs: ref: 8.13a token: ${{ secrets.AS_TOKEN }} - - name: list xpress dir - if: matrix.xprs == 'XPRESS-ON' - shell: bash - run: | - cat "${{ env.XPRESSDIR }}\bin\xpauth.xpr" - ls "${{ env.XPRESSDIR }}" - echo "************************" - ls "${{ env.XPRESSDIR }}\bin" - echo "************************" - ls "${{ env.XPRESSDIR }}\lib" - echo "************************" - - name: Get release if: github.event_name == 'release' && github.event.action == 'created' id: get_release @@ -154,9 +142,5 @@ jobs: set PATH=%PATH%;C:\Program Files\Microsoft MPI\Bin set PATH=%PATH%;${{ env.XPRESS }} set XPRESSDIR=${{ env.XPRESSDIR }} - DIR "${{ env.XPRESSDIR }}" - DIR "${{ env.XPRESSDIR }}\bin" - DIR "${{ env.XPRESSDIR }}\lib" - cd _build - ctest -C Release --output-on-failure -L "unit" \ No newline at end of file + ctest -C Release --output-on-failure -L "medium|unit|benders|lpnamer" \ No newline at end of file From d5c55f7839feddcdbb3c155ca4ecb1f54263cac0 Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Tue, 24 Oct 2023 15:46:20 +0200 Subject: [PATCH 28/39] do right --- src/cpp/multisolver_interface/environment.cc | 2 ++ .../multisolver_interface/environment.h | 23 +++++++++++-------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/cpp/multisolver_interface/environment.cc b/src/cpp/multisolver_interface/environment.cc index be595b4b8..445934928 100644 --- a/src/cpp/multisolver_interface/environment.cc +++ b/src/cpp/multisolver_interface/environment.cc @@ -1,3 +1,5 @@ +// This this file is an adaptation for Antares-Xpansion needs +// see orginal at https://github.com/rte-france/or-tools // Copyright 2010-2021 Google LLC // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/src/cpp/multisolver_interface/include/multisolver_interface/environment.h b/src/cpp/multisolver_interface/include/multisolver_interface/environment.h index 86bc23a53..45fe608d9 100644 --- a/src/cpp/multisolver_interface/include/multisolver_interface/environment.h +++ b/src/cpp/multisolver_interface/include/multisolver_interface/environment.h @@ -1,15 +1,18 @@ -// Copyright 2010-2021 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 + +// This this file is an adaptation for Antares-Xpansion needs +// see orginal at https://github.com/rte-france/or-tools +// Copyright 2010-2021 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 +// 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. +// 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. #pragma once #include From 0c9c969b6a44842fdd1f01d24e36faa0977151d7 Mon Sep 17 00:00:00 2001 From: abdoulbari zakir <32519851+a-zakir@users.noreply.github.com> Date: Fri, 10 Nov 2023 14:53:10 +0100 Subject: [PATCH 29/39] suggestion by @flomnes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Florian Omnès --- src/cpp/multisolver_interface/environment.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cpp/multisolver_interface/environment.cc b/src/cpp/multisolver_interface/environment.cc index 445934928..f8105c889 100644 --- a/src/cpp/multisolver_interface/environment.cc +++ b/src/cpp/multisolver_interface/environment.cc @@ -1,4 +1,4 @@ -// This this file is an adaptation for Antares-Xpansion needs +// This this file is an adaptation of OR-Tools for Antares-Xpansion needs // see orginal at https://github.com/rte-france/or-tools // Copyright 2010-2021 Google LLC // Licensed under the Apache License, Version 2.0 (the "License"); From daa0971222d7eab97dfebf56dda9718aca9e00d8 Mon Sep 17 00:00:00 2001 From: abdoulbari zakir <32519851+a-zakir@users.noreply.github.com> Date: Fri, 10 Nov 2023 14:54:05 +0100 Subject: [PATCH 30/39] suggestion by @flomnes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Florian Omnès --- src/cpp/multisolver_interface/environment.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cpp/multisolver_interface/environment.cc b/src/cpp/multisolver_interface/environment.cc index f8105c889..a5497b5e7 100644 --- a/src/cpp/multisolver_interface/environment.cc +++ b/src/cpp/multisolver_interface/environment.cc @@ -1,5 +1,5 @@ // This this file is an adaptation of OR-Tools for Antares-Xpansion needs -// see orginal at https://github.com/rte-france/or-tools +// see orginal at https://github.com/google/or-tools // Copyright 2010-2021 Google LLC // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. From 06ed31a28f29945fbc4d77de313e2a93d78a913f Mon Sep 17 00:00:00 2001 From: abdoulbari zakir <32519851+a-zakir@users.noreply.github.com> Date: Fri, 10 Nov 2023 14:58:02 +0100 Subject: [PATCH 31/39] suggestion by @florian --- .../include/multisolver_interface/environment.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cpp/multisolver_interface/include/multisolver_interface/environment.h b/src/cpp/multisolver_interface/include/multisolver_interface/environment.h index 45fe608d9..a7e0b4c18 100644 --- a/src/cpp/multisolver_interface/include/multisolver_interface/environment.h +++ b/src/cpp/multisolver_interface/include/multisolver_interface/environment.h @@ -1,6 +1,6 @@ -// This this file is an adaptation for Antares-Xpansion needs -// see orginal at https://github.com/rte-france/or-tools +// This this file is an adaptation of OR-Tools for Antares-Xpansion needs +// see orginal at https://github.com/google/or-tools // Copyright 2010-2021 Google LLC // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. From 9da5a5ad49e49646ba440a8e1460408cb5fcaa26 Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Fri, 10 Nov 2023 15:09:53 +0100 Subject: [PATCH 32/39] rename namespace --- src/cpp/multisolver_interface/SolverFactory.cpp | 3 +-- src/cpp/multisolver_interface/SolverXpress.cpp | 2 +- src/cpp/multisolver_interface/environment.cc | 4 ++-- .../include/multisolver_interface/environment.h | 4 ++-- tests/cpp/sensitivity/SensitivityStudyTest.cpp | 2 +- 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/cpp/multisolver_interface/SolverFactory.cpp b/src/cpp/multisolver_interface/SolverFactory.cpp index d575a0972..ef50caa3d 100644 --- a/src/cpp/multisolver_interface/SolverFactory.cpp +++ b/src/cpp/multisolver_interface/SolverFactory.cpp @@ -11,8 +11,7 @@ SolverFactory::SolverFactory() { _available_solvers.clear(); - if ((isXpress_available_ = - operations_research_Xpansion::XpressIsCorrectlyInstalled())) { + if ((isXpress_available_ = LoadXpress::XpressIsCorrectlyInstalled())) { _available_solvers.push_back(XPRESS_STR); } #ifdef COIN_OR diff --git a/src/cpp/multisolver_interface/SolverXpress.cpp b/src/cpp/multisolver_interface/SolverXpress.cpp index d749f8fe6..bff9f2c19 100644 --- a/src/cpp/multisolver_interface/SolverXpress.cpp +++ b/src/cpp/multisolver_interface/SolverXpress.cpp @@ -6,7 +6,7 @@ #include "StringManip.h" -using namespace operations_research_Xpansion; +using namespace LoadXpress; /************************************************************************************************* ----------------------------------- Constructor/Desctructor diff --git a/src/cpp/multisolver_interface/environment.cc b/src/cpp/multisolver_interface/environment.cc index a5497b5e7..ca0863b3d 100644 --- a/src/cpp/multisolver_interface/environment.cc +++ b/src/cpp/multisolver_interface/environment.cc @@ -20,7 +20,7 @@ #include #include -namespace operations_research_Xpansion { +namespace LoadXpress { #define STRINGIFY2(X) #X #define STRINGIFY(X) STRINGIFY2(X) @@ -495,4 +495,4 @@ bool XpressIsCorrectlyInstalled() { return correctlyInstalled; } -} // namespace operations_research_Xpansion +} // namespace LoadXpress diff --git a/src/cpp/multisolver_interface/include/multisolver_interface/environment.h b/src/cpp/multisolver_interface/include/multisolver_interface/environment.h index a7e0b4c18..9c79e7018 100644 --- a/src/cpp/multisolver_interface/include/multisolver_interface/environment.h +++ b/src/cpp/multisolver_interface/include/multisolver_interface/environment.h @@ -21,7 +21,7 @@ extern "C" { typedef struct xo_prob_struct* XPRSprob; } -namespace operations_research_Xpansion { +namespace LoadXpress { void printXpressBanner(bool error); @@ -470,5 +470,5 @@ extern std::function XPRSgetversion; // extern std::function XPRSchgrhsrange; // extern std::function XPRSchgrowtype; -} // namespace operations_research_Xpansion +} // namespace LoadXpress diff --git a/tests/cpp/sensitivity/SensitivityStudyTest.cpp b/tests/cpp/sensitivity/SensitivityStudyTest.cpp index 35eaadf9d..e19758083 100644 --- a/tests/cpp/sensitivity/SensitivityStudyTest.cpp +++ b/tests/cpp/sensitivity/SensitivityStudyTest.cpp @@ -107,7 +107,7 @@ class SensitivityStudyTest : public ::testing::Test { std::string mps_path, std::map> expec_output_data_map) { std::vector solvers_name = {coin_name}; - if (operations_research_Xpansion::XpressIsCorrectlyInstalled()) { + if (LoadXpress::XpressIsCorrectlyInstalled()) { solvers_name.push_back(xpress_name); } From 2ce15ba5a39ddc5f14cc9d3fcac448a08db1f377 Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Fri, 10 Nov 2023 15:19:18 +0100 Subject: [PATCH 33/39] remove commented code --- src/cpp/multisolver_interface/CMakeLists.txt | 2 - src/cpp/multisolver_interface/environment.cc | 62 ------------------- .../multisolver_interface/environment.h | 16 ----- 3 files changed, 80 deletions(-) diff --git a/src/cpp/multisolver_interface/CMakeLists.txt b/src/cpp/multisolver_interface/CMakeLists.txt index dae17ecfb..b03d8800a 100644 --- a/src/cpp/multisolver_interface/CMakeLists.txt +++ b/src/cpp/multisolver_interface/CMakeLists.txt @@ -22,11 +22,9 @@ list(APPEND XPRESS_LOAD ) # XPRESS -#IF( XPRESS ) list(APPEND Solver_sources ${CMAKE_CURRENT_LIST_DIR}/SolverXpress.cpp ) -#ENDIF( XPRESS ) #Clp - CBc IF(COIN_OR) diff --git a/src/cpp/multisolver_interface/environment.cc b/src/cpp/multisolver_interface/environment.cc index ca0863b3d..8240d30bd 100644 --- a/src/cpp/multisolver_interface/environment.cc +++ b/src/cpp/multisolver_interface/environment.cc @@ -136,45 +136,6 @@ std::function XPRSlicense = nullptr; std::function XPRSgetversion = nullptr; std::function XPRSgetintattrib = nullptr; -/*----*/ - -// std::function XPRSsetdefaultcontrol = -// nullptr; std::function -// XPRSsetintcontrol64 = nullptr; -// std::function -// XPRSsetstrcontrol = nullptr; -// std::function -// XPRSgetintcontrol64 = nullptr; -// std::function -// XPRSgetdblcontrol = nullptr; -// std::function -// XPRSgetstringcontrol = nullptr; -// std::function -// XPRSloadlp64 = nullptr; -// std::function -// XPRSgetcoef = nullptr; -// std::function XPRSdelcols -// = -// nullptr; -// std::function -// XPRSloadbasis = nullptr; -// std::function XPRSpostsolve = nullptr; -// std::function XPRSgetlasterror = nullptr; -// std::function -// XPRSchgmcoef = nullptr; -// std::function -// XPRSchgrhsrange = nullptr; -// std::function -// XPRSchgrowtype = nullptr; bool LoadXpressFunctions(DynamicLibrary* xpress_dynamic_library) { // This was generated with the parse_header_xpress.py script. @@ -227,29 +188,6 @@ bool LoadXpressFunctions(DynamicLibrary* xpress_dynamic_library) { xpress_dynamic_library->GetFunction(&XPRSlicense, "XPRSlicense"); xpress_dynamic_library->GetFunction(&XPRSgetversion, "XPRSgetversion"); - /**/ - // xpress_dynamic_library->GetFunction(&XPRSsetdefaultcontrol, - // "XPRSsetdefaultcontrol"); - // xpress_dynamic_library->GetFunction(&XPRSsetintcontrol64, - // "XPRSsetintcontrol64"); - // xpress_dynamic_library->GetFunction(&XPRSsetstrcontrol, - // "XPRSsetstrcontrol"); - // xpress_dynamic_library->GetFunction(&XPRSgetintcontrol64, - // "XPRSgetintcontrol64"); - // xpress_dynamic_library->GetFunction(&XPRSgetdblcontrol, - // "XPRSgetdblcontrol"); - // xpress_dynamic_library->GetFunction(&XPRSgetstringcontrol, - // "XPRSgetstringcontrol"); - // xpress_dynamic_library->GetFunction(&XPRSloadlp64, "XPRSloadlp64"); - // xpress_dynamic_library->GetFunction(&XPRSgetcoef, "XPRSgetcoef"); - // xpress_dynamic_library->GetFunction(&XPRSdelcols, "XPRSdelcols"); - // xpress_dynamic_library->GetFunction(&XPRSloadbasis, "XPRSloadbasis"); - // xpress_dynamic_library->GetFunction(&XPRSpostsolve, "XPRSpostsolve"); - // xpress_dynamic_library->GetFunction(&XPRSgetlasterror, "XPRSgetlasterror"); - // xpress_dynamic_library->GetFunction(&XPRSchgmcoef, "XPRSchgmcoef"); - // xpress_dynamic_library->GetFunction(&XPRSchgrhsrange, "XPRSchgrhsrange"); - // xpress_dynamic_library->GetFunction(&XPRSchgrowtype, "XPRSchgrowtype"); - auto notFound = xpress_dynamic_library->FunctionsNotFound(); if (!notFound.empty()) { std::string msg( diff --git a/src/cpp/multisolver_interface/include/multisolver_interface/environment.h b/src/cpp/multisolver_interface/include/multisolver_interface/environment.h index 9c79e7018..003130ee9 100644 --- a/src/cpp/multisolver_interface/include/multisolver_interface/environment.h +++ b/src/cpp/multisolver_interface/include/multisolver_interface/environment.h @@ -453,22 +453,6 @@ extern std::function XPRSgetlicerrmsg; extern std::function XPRSlicense; extern std::function XPRSgetversion; -/***/ -// extern std::function XPRSsetdefaultcontrol; -// extern std::function XPRSsetintcontrol64; -// extern std::function XPRSsetstrcontrol; -// extern std::function XPRSgetintcontrol64; -// extern std::function XPRSgetdblcontrol; -// extern std::function XPRSgetstringcontrol; -// extern std::function XPRSloadlp64; -// extern std::function XPRSgetcoef; -// extern std::function XPRSdelcols; -// extern std::function XPRSloadbasis; -// extern std::function XPRSpostsolve; -// extern std::function XPRSgetlasterror; -// extern std::function XPRSchgmcoef; -// extern std::function XPRSchgrhsrange; -// extern std::function XPRSchgrowtype; } // namespace LoadXpress From 562aa15bfca37de32cda2cc320e5fe7c0fbd83bf Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Fri, 10 Nov 2023 15:20:59 +0100 Subject: [PATCH 34/39] resolve conflicts --- src/cpp/lpnamer/main/RunProblemGeneration.cpp | 108 +++++------------- 1 file changed, 27 insertions(+), 81 deletions(-) diff --git a/src/cpp/lpnamer/main/RunProblemGeneration.cpp b/src/cpp/lpnamer/main/RunProblemGeneration.cpp index c022816b6..527075c13 100644 --- a/src/cpp/lpnamer/main/RunProblemGeneration.cpp +++ b/src/cpp/lpnamer/main/RunProblemGeneration.cpp @@ -1,13 +1,11 @@ #include "RunProblemGeneration.h" -#include #include #include #include "ActiveLinks.h" #include "AdditionalConstraints.h" -#include "Clock.h" #include "GeneralDataReader.h" #include "LauncherHelpers.h" #include "LinkProblemsGenerator.h" @@ -17,14 +15,12 @@ #include "MasterGeneration.h" #include "MasterProblemBuilder.h" #include "MpsTxtWriter.h" -#include "ProblemGenerationExeOptions.h" #include "ProblemVariablesFromProblemAdapter.h" #include "ProblemVariablesZipAdapter.h" #include "StringManip.h" #include "Timer.h" #include "WeightsFileReader.h" #include "WeightsFileWriter.h" -#include "XpansionProblemsFromAntaresProvider.h" #include "ZipProblemsProviderAdapter.h" #include "config.h" @@ -59,6 +55,7 @@ struct Version { int major; int minor; }; + std::shared_ptr InstantiateZipReader( const std::filesystem::path& antares_archive_path); void ProcessWeights( @@ -128,6 +125,7 @@ std::vector> getXpansionProblems( problem_names); return adapter->provideProblems(solver_name, solver_log_manager); } + void RunProblemGeneration( const std::filesystem::path& xpansion_output_dir, const std::string& master_formulation, @@ -169,14 +167,10 @@ void RunProblemGeneration( auto files_mapper = FilesMapper(antares_archive_path); auto mpsList = files_mapper.MpsAndVariablesFilesVect(); - bool use_zip_implementation = true; - bool use_file_implementation = false; - auto solver_log_manager = SolverLogManager(log_file_path); Couplings couplings; LinkProblemsGenerator linkProblemsGenerator( lpDir_, links, solver_name, logger, solver_log_manager, rename_problems); - if (use_zip_implementation) { std::shared_ptr reader = InstantiateZipReader(antares_archive_path); @@ -185,81 +179,33 @@ void RunProblemGeneration( getXpansionProblems(solver_log_manager, solver_name, mpsList, lpDir_, reader); - std::vector, ProblemData>> - problems_and_data; - for (int i = 0; i < xpansion_problems.size(); ++i) { - xpansion_problems.at(i)->_name = mpsList.at(i)._problem_mps; - problems_and_data.emplace_back(xpansion_problems.at(i), mpsList.at(i)); - } - auto mps_file_writer = std::make_shared(lpDir_); - std::for_each( - std::execution::par, problems_and_data.begin(), problems_and_data.end(), - [&](const auto& problem_and_data) { - const auto& [problem, data] = problem_and_data; - std::shared_ptr variables_provider; - if (rename_problems) { - variables_provider = std::make_shared( - reader, data, links, logger); - } else { - variables_provider = - std::make_shared( - problem, links, logger); - } - linkProblemsGenerator.treat(data._problem_mps, couplings, - problem.get(), variables_provider.get(), - mps_file_writer.get()); - }); - - reader->Close(); - reader->Delete(); - } else if (use_file_implementation) { - /* Main stuff */ - auto mps_file_writer = std::make_shared(lpDir_); - linkProblemsGenerator.treatloop(xpansion_output_dir, couplings, mpsList, + std::vector, ProblemData>> + problems_and_data; + for (int i = 0; i < xpansion_problems.size(); ++i) { + xpansion_problems.at(i)->_name = mpsList.at(i)._problem_mps; + problems_and_data.emplace_back(xpansion_problems.at(i), mpsList.at(i)); + } + auto mps_file_writer = std::make_shared(lpDir_); + std::for_each( + std::execution::par, problems_and_data.begin(), problems_and_data.end(), + [&](const auto& problem_and_data) { + const auto& [problem, data] = problem_and_data; + std::shared_ptr variables_provider; + if (rename_problems) { + variables_provider = std::make_shared( + reader, data, links, logger); + } else { + variables_provider = + std::make_shared( + problem, links, logger); + } + linkProblemsGenerator.treat(data._problem_mps, couplings, problem.get(), + variables_provider.get(), mps_file_writer.get()); - } else { - std::filesystem::path path = - xpansion_output_dir.parent_path().parent_path() / - "fichierDeSerialisation"; - std::ifstream ifs(xpansion_output_dir.parent_path().parent_path() / - "fichierDeSerialisation"); - boost::archive::text_iarchive ia(ifs); - - LpsFromAntares lps; - ia >> lps; - lps._constant->Mdeb.push_back(lps._constant->NombreDeCoefficients); - - XpansionProblemsFromAntaresProvider adapter(lps); - auto xpansion_problems = - adapter.provideProblems(solver_name, solver_log_manager); - std::vector, ProblemData>> - problems_and_data; - for (int i = 0; i < xpansion_problems.size(); ++i) { - xpansion_problems.at(i)->_name = mpsList.at(i)._problem_mps; - problems_and_data.emplace_back(xpansion_problems.at(i), mpsList.at(i)); - } - - auto reader = InstantiateZipReader(antares_archive_path); - auto mps_file_writer = std::make_shared(lpDir_); + }); - std::for_each( - std::execution::par, problems_and_data.begin(), problems_and_data.end(), - [&](const auto& problem_and_data) { - const auto& [problem, data] = problem_and_data; - std::shared_ptr variables_provider; - if (rename_problems) { - variables_provider = std::make_shared( - reader, data, links, logger); - } else { - variables_provider = - std::make_shared( - problem, links, logger); - } - linkProblemsGenerator.treat(data._problem_mps, couplings, - problem.get(), variables_provider.get(), - mps_file_writer.get()); - }); - } + reader->Close(); + reader->Delete(); MasterGeneration master_generation( xpansion_output_dir, links, additionalConstraints, couplings, From 5731bce63b72e14c1d4122efe5e07413c698d0b0 Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Wed, 15 Nov 2023 07:35:42 -0800 Subject: [PATCH 35/39] init Xpress env if needed --- src/cpp/multisolver_interface/SolverXpress.cpp | 1 + src/cpp/multisolver_interface/environment.cc | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/cpp/multisolver_interface/SolverXpress.cpp b/src/cpp/multisolver_interface/SolverXpress.cpp index bff9f2c19..e7df31e5c 100644 --- a/src/cpp/multisolver_interface/SolverXpress.cpp +++ b/src/cpp/multisolver_interface/SolverXpress.cpp @@ -27,6 +27,7 @@ SolverXpress::SolverXpress() { std::lock_guard guard(license_guard); int status = 0; if (_NumberOfProblems == 0) { + initXpressEnv(); status = XPRSinit(NULL); zero_status_check(status, "initialize XPRESS environment", LOGLOCATION); } diff --git a/src/cpp/multisolver_interface/environment.cc b/src/cpp/multisolver_interface/environment.cc index 8240d30bd..f64d6a5ce 100644 --- a/src/cpp/multisolver_interface/environment.cc +++ b/src/cpp/multisolver_interface/environment.cc @@ -234,7 +234,11 @@ std::string GetXpressVarFromEnvironmentVariables(const char* XPRESS_var) { XPRESS_var); #else - xpress_home_from_env = getenv(XPRESS_var); + char* path = nullptr; + path = getenv(XPRESS_var); + if (path) { + xpress_home_from_env = path; + } #endif return xpress_home_from_env; } From dd28db3ab46471a295546160f25f8a921b940cb1 Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Wed, 15 Nov 2023 08:32:47 -0800 Subject: [PATCH 36/39] check available Solvers once per program --- .../multisolver_interface/SolverFactory.cpp | 20 +++++++++++------ .../multisolver_interface/SolverFactory.h | 22 +++++++++++++------ 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/cpp/multisolver_interface/SolverFactory.cpp b/src/cpp/multisolver_interface/SolverFactory.cpp index ef50caa3d..f0b6932ee 100644 --- a/src/cpp/multisolver_interface/SolverFactory.cpp +++ b/src/cpp/multisolver_interface/SolverFactory.cpp @@ -8,18 +8,24 @@ #endif #include "LogUtils.h" #include "multisolver_interface/SolverFactory.h" +std::vector tmp; -SolverFactory::SolverFactory() { - _available_solvers.clear(); - if ((isXpress_available_ = LoadXpress::XpressIsCorrectlyInstalled())) { - _available_solvers.push_back(XPRESS_STR); - } +std::vector SolverLoader::GetAvailableSolvers() { + if (tmp.empty()) { + if (LoadXpress::XpressIsCorrectlyInstalled()) { + tmp.push_back(XPRESS_STR); + } #ifdef COIN_OR - _available_solvers.push_back(CLP_STR); - _available_solvers.push_back(CBC_STR); + tmp.push_back(CLP_STR); + tmp.push_back(CBC_STR); #endif + } + return tmp; } +SolverFactory::SolverFactory() + : _available_solvers(SolverLoader::GetAvailableSolvers()) {} + SolverAbstract::Ptr SolverFactory::create_solver( const std::string &solver_name, const SOLVER_TYPE solver_type) const { if (solver_name == "") { diff --git a/src/cpp/multisolver_interface/include/multisolver_interface/SolverFactory.h b/src/cpp/multisolver_interface/include/multisolver_interface/SolverFactory.h index 36949841d..332eedb71 100644 --- a/src/cpp/multisolver_interface/include/multisolver_interface/SolverFactory.h +++ b/src/cpp/multisolver_interface/include/multisolver_interface/SolverFactory.h @@ -8,6 +8,15 @@ enum class SOLVER_TYPE { INTEGER, CONTINUOUS }; const std::string UNKNOWN_STR("UNKNOWN"), COIN_STR("COIN"), CBC_STR("CBC"), CLP_STR("CLP"), XPRESS_STR("XPRESS"); +/*! + * \class class SolverLoader + * \brief Class to check if supported solvers are available + */ +class SolverLoader { + public: + static std::vector GetAvailableSolvers(); +}; + /*! * \class class SolverFactory * \brief Class to manage the creation of solvers from the different @@ -31,9 +40,8 @@ class SolverFactory { * @param solver_name : Name of the solver to use */ SolverAbstract::Ptr create_solver(const std::string &solver_name) const; - SolverAbstract::Ptr create_solver( - const std::string &solver_name, - SolverLogManager&log_manager) const; + SolverAbstract::Ptr create_solver(const std::string &solver_name, + SolverLogManager &log_manager) const; /** * @brief Creates and returns to an object solver from the wanted @@ -44,9 +52,9 @@ class SolverFactory { */ SolverAbstract::Ptr create_solver(const std::string &solver_name, const SOLVER_TYPE solver_type) const; - SolverAbstract::Ptr create_solver( - const std::string &solver_name, const SOLVER_TYPE solver_type, - SolverLogManager&log_manager) const; + SolverAbstract::Ptr create_solver(const std::string &solver_name, + const SOLVER_TYPE solver_type, + SolverLogManager &log_manager) const; /** * @brief Copy constructor : Creates and returns to an object solver from the @@ -63,5 +71,5 @@ class SolverFactory { */ const std::vector &get_solvers_list() const; - bool isXpress_available_ = false; + bool isXpress_available_ = false; }; From 6340cb22dfe77c6f2807eed3e99b6bbd12b8f8bb Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Wed, 15 Nov 2023 08:46:01 -0800 Subject: [PATCH 37/39] set Xpress bool check --- src/cpp/multisolver_interface/SolverFactory.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/cpp/multisolver_interface/SolverFactory.cpp b/src/cpp/multisolver_interface/SolverFactory.cpp index f0b6932ee..c4cdce683 100644 --- a/src/cpp/multisolver_interface/SolverFactory.cpp +++ b/src/cpp/multisolver_interface/SolverFactory.cpp @@ -24,7 +24,10 @@ std::vector SolverLoader::GetAvailableSolvers() { } SolverFactory::SolverFactory() - : _available_solvers(SolverLoader::GetAvailableSolvers()) {} + : _available_solvers(SolverLoader::GetAvailableSolvers()) { + isXpress_available_ = + std::find(tmp.cbegin(), tmp.cend(), XPRESS_STR) != tmp.cend(); +} SolverAbstract::Ptr SolverFactory::create_solver( const std::string &solver_name, const SOLVER_TYPE solver_type) const { From fa6cbf6fc345a0ac27a681cee577f77020c70e5b Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Wed, 15 Nov 2023 09:02:02 -0800 Subject: [PATCH 38/39] print the right log messages --- src/cpp/multisolver_interface/environment.cc | 34 ++++++++------------ 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/src/cpp/multisolver_interface/environment.cc b/src/cpp/multisolver_interface/environment.cc index f64d6a5ce..e4f77ca5a 100644 --- a/src/cpp/multisolver_interface/environment.cc +++ b/src/cpp/multisolver_interface/environment.cc @@ -207,11 +207,9 @@ void printXpressBanner(bool error) { XPRSgetbanner(banner); if (error) { - std::cerr << "XpressInterface : Xpress banner :\n" << banner << "\n"; + std::cerr << "Xpress banner :\n" << banner << "\n"; } else { - std::cout << "Warning: " - << "XpressInterface : Xpress banner :\n" - << banner << "\n"; + std::cout << "Xpress banner :\n" << banner << "\n"; } } @@ -333,9 +331,7 @@ bool initXpressEnv(bool verbose, int xpress_oem_license_key) { std::string xpress_from_env = GetXpressVarFromEnvironmentVariables("XPRESS"); if (xpress_from_env == "") { if (verbose) { - std::cout - << "Warning: " - << "XpressInterface Error : Environment variable XPRESS undefined.\n"; + std::cout << "Warning: Environment variable XPRESS undefined.\n"; } if (xpresspath.empty()) { return false; @@ -349,9 +345,8 @@ bool initXpressEnv(bool verbose, int xpress_oem_license_key) { // if not an OEM key if (xpress_oem_license_key == 0) { if (verbose) { - std::cout << "Warning: " - << "XpressInterface : Initialising xpress-MP with parameter " - << xpresspath << "\n"; + std::cout << "Initialising xpress-MP with parameter " << xpresspath + << "\n"; } code = XPRSinit(xpresspath.c_str()); @@ -364,8 +359,8 @@ bool initXpressEnv(bool verbose, int xpress_oem_license_key) { XPRSgetversion(version); std::cout << "Warning: " << "Optimizer version: " << version - << " (OR-Tools was compiled with version " << XPVERSION - << ").\n"; + << " (Antares-Xpansion was compiled with version " + << XPVERSION << ").\n"; } return true; } else { @@ -373,7 +368,7 @@ bool initXpressEnv(bool verbose, int xpress_oem_license_key) { char errmsg[256]; XPRSgetlicerrmsg(errmsg, 256); - std::cerr << "XpressInterface : License error : " << errmsg + std::cerr << "Xpress License error : " << errmsg << " (XPRSinit returned code " << code << "). Please check" << " environment variable XPRESS.\n"; @@ -383,7 +378,7 @@ bool initXpressEnv(bool verbose, int xpress_oem_license_key) { // if OEM key if (verbose) { std::cout << "Warning: " - << "XpressInterface : Initialising xpress-MP with OEM key " + << "Initialising xpress-MP with OEM key " << xpress_oem_license_key << "\n"; } @@ -394,27 +389,24 @@ bool initXpressEnv(bool verbose, int xpress_oem_license_key) { XPRSlicense(&nvalue, slicmsg); if (verbose) { - std::cout << "XpressInterface : First message from XPRSLicense : " - << slicmsg << "\n"; + std::cout << "First message from XPRSLicense : " << slicmsg << "\n"; } nvalue = xpress_oem_license_key - ((nvalue * nvalue) / 19); ierr = XPRSlicense(&nvalue, slicmsg); if (verbose) { - std::cout << "XpressInterface : Second message from XPRSLicense : " - << slicmsg << "\n"; + std::cout << "Second message from XPRSLicense : " << slicmsg << "\n"; } if (ierr == 16) { if (verbose) { - std::cout - << "XpressInterface : Optimizer development software detected\n"; + std::cout << "Optimizer development software detected\n"; } } else if (ierr != 0) { // get the license error message XPRSgetlicerrmsg(errmsg, 256); - std::cerr << "XpressInterface : " << errmsg << "\n"; + std::cerr << "Xpress Error Message: " << errmsg << "\n"; return false; } From 6aa147d1d0a2fd307fd1701ca3e6ee4f66233cb8 Mon Sep 17 00:00:00 2001 From: Abdoulbari ZAKIR Date: Thu, 16 Nov 2023 17:58:48 +0100 Subject: [PATCH 39/39] rename compile unit variable --- src/cpp/multisolver_interface/SolverFactory.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/cpp/multisolver_interface/SolverFactory.cpp b/src/cpp/multisolver_interface/SolverFactory.cpp index c4cdce683..fb38d45b1 100644 --- a/src/cpp/multisolver_interface/SolverFactory.cpp +++ b/src/cpp/multisolver_interface/SolverFactory.cpp @@ -8,25 +8,26 @@ #endif #include "LogUtils.h" #include "multisolver_interface/SolverFactory.h" -std::vector tmp; +std::vector available_solvers; std::vector SolverLoader::GetAvailableSolvers() { - if (tmp.empty()) { + if (available_solvers.empty()) { if (LoadXpress::XpressIsCorrectlyInstalled()) { - tmp.push_back(XPRESS_STR); + available_solvers.push_back(XPRESS_STR); } #ifdef COIN_OR - tmp.push_back(CLP_STR); - tmp.push_back(CBC_STR); + available_solvers.push_back(CLP_STR); + available_solvers.push_back(CBC_STR); #endif } - return tmp; + return available_solvers; } SolverFactory::SolverFactory() : _available_solvers(SolverLoader::GetAvailableSolvers()) { isXpress_available_ = - std::find(tmp.cbegin(), tmp.cend(), XPRESS_STR) != tmp.cend(); + std::find(available_solvers.cbegin(), available_solvers.cend(), + XPRESS_STR) != available_solvers.cend(); } SolverAbstract::Ptr SolverFactory::create_solver(