Skip to content

Commit

Permalink
adding MP readNL in this branch
Browse files Browse the repository at this point in the history
  • Loading branch information
hhijazi committed Apr 18, 2024
1 parent 65b735f commit adb7d6e
Show file tree
Hide file tree
Showing 13 changed files with 414 additions and 112 deletions.
20 changes: 6 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ option(Ipopt "Link to IPOPT libraries" ON)

option(MP "Link to AMPL MP libraries" OFF)

option(CoinUtils "Link to CoinUtils libraries" OFF)
option(CoinUtils "Link to CoinUtils libraries" ON)

# Find XLNT (optional)
option(Xlnt "Link to XLNT libraries" OFF)
Expand Down Expand Up @@ -196,6 +196,8 @@ set(THIRDPARTY_INSTALL_PATH ${THIRDPARTY_BASE_PATH})
if(NOT WIN32)
#CoinUtils
if (CoinUtils)
include(ExternalProject)
#CoinUtils
message(STATUS "Enable CoinUtils")
add_definitions(-DUSE_CoinUtils)
find_package(CoinUtils QUIET)
Expand All @@ -217,11 +219,13 @@ endif(CoinUtils)

#MP
if (MP)
#MP
message(STATUS "Enable AMPL MP")
add_definitions(-DUSE_MP)
find_package(MP QUIET)
if (MP_FOUND)
message("-- Found AMPL MP: ${MP_INCLUDE_DIRS}")
message("-- Found AMPL MP: ${CoinUtils_INCLUDE_DIRS}")
include_directories(${MP_INCLUDE_DIRS}/..)
set(LIBS ${LIBS} ${MP_LIBRARIES})
else(MP_FOUND)
Expand Down Expand Up @@ -258,19 +262,6 @@ endif(HiGHS)


if(Ipopt)
# Add Ipopt include dir and link to libraries
if(WIN32)
# include_directories("${PROJECT_SOURCE_DIR}/thirdparty/Ipopt")
include_directories("${PROJECT_SOURCE_DIR}/thirdparty/Ipopt/include/coin-or")
# add_subdirectory(thirdparty/Ipopt)
# find_library(IPOPT_LIBRARIES
# ipopt.dll
# HINTS /usr/local/lib
# HINTS ${PROJECT_SOURCE_DIR}/thirdparty/Ipopt
# HINTS ${IPOPT_ROOT_DIR}/lib
# )
endif(WIN32)

message(STATUS "Enable IPOPT")
add_definitions(-DUSE_IPOPT)
find_package(IPOPT QUIET)
Expand All @@ -288,6 +279,7 @@ elseif(WIN32)
set(IPOPT_LIBRARIES ${PROJECT_SOURCE_DIR}/thirdparty/Ipopt/libipopt-3.lib)
endif(APPLE)
include(ExternalIpopt)
set(IPOPT_LIBRARIES ${THIRDPARTY_INSTALL_PATH}/Install/ipopt/build/lib/libipopt.so)
endif (IPOPT_FOUND)
endif(Ipopt)

Expand Down
12 changes: 0 additions & 12 deletions cmake/ExternalCoinUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,6 @@ unset(CoinUtils_HOME)

# Download and build the CoinUtils library and add its properties to the third party arguments.
set(CoinUtils_ROOT_DIR ${THIRDPARTY_INSTALL_PATH}/Install/CoinUtils/build CACHE INTERNAL "")
if(WIN32)
ExternalProject_Add(coinutils
DOWNLOAD_DIR ${THIRDPARTY_INSTALL_PATH}
DOWNLOAD_COMMAND git clone ${CoinUtils_DOWNLOAD_URL} && rmdir -fr ./Install/CoinUtils && move CoinUtils ./Install/CoinUtils && cd ./Install/CoinUtils && mkdir build && cd build && ../configure --prefix=${CoinUtils_ROOT_DIR} && make -j && make install
URL ${CoinUtils_DOWNLOAD_URL}
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CoinUtils_ROOT_DIR}
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
)
else()
ExternalProject_Add(coinutils
DOWNLOAD_DIR ${THIRDPARTY_INSTALL_PATH}
DOWNLOAD_COMMAND export HTTPS_PROXY=$ENV{HTTPS_PROXY} && git clone ${CoinUtils_DOWNLOAD_URL} && rm -fr ./Install/CoinUtils && mv CoinUtils ./Install/CoinUtils && cd ./Install/CoinUtils && mkdir build && cd build && ../configure --prefix=${CoinUtils_ROOT_DIR} && make -j24 && make install
Expand All @@ -24,7 +13,6 @@ ExternalProject_Add(coinutils
BUILD_COMMAND ""
INSTALL_COMMAND ""
)
endif()
list(APPEND GLOBAL_THIRDPARTY_LIB_ARGS "-DCoinUtils_ROOT_DIR:PATH=${CoinUtils_ROOT_DIR}")
set(CoinUtils_INCLUDE_DIRS ${THIRDPARTY_INSTALL_PATH}/Install/CoinUtils/build/include/coin-or)
include_directories(${CoinUtils_INCLUDE_DIRS})
Expand Down
14 changes: 1 addition & 13 deletions cmake/ExternalMP.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,15 @@ unset(MP_HOME)

# Download and build the MP library and add its properties to the third party arguments.
set(MP_ROOT_DIR ${THIRDPARTY_INSTALL_PATH}/Install/MP CACHE INTERNAL "")
if(WIN32)
ExternalProject_Add(mp
DOWNLOAD_DIR ${THIRDPARTY_INSTALL_PATH}
DOWNLOAD_COMMAND git clone ${MP_DOWNLOAD_URL} && rmdir -fr ./Install/MP && move mp ./Install/MP && cd ./Install/MP && mkdir build && cd build && cmake .. && make mp -j
DOWNLOAD_COMMAND export HTTPS_PROXY=$ENV{HTTPS_PROXY} && git clone ${MP_DOWNLOAD_URL} && rm -fr ./Install/MP && mv mp ./Install/MP && cd ./Install/MP && git submodule init && git submodule update && mkdir build && cd build && cmake -DBUILD=all .. && make -j24
URL ${MP_DOWNLOAD_URL}
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${MP_ROOT_DIR}
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
)
else()
ExternalProject_Add(mp
DOWNLOAD_DIR ${THIRDPARTY_INSTALL_PATH}
DOWNLOAD_COMMAND export HTTPS_PROXY=$ENV{HTTPS_PROXY} && git clone ${MP_DOWNLOAD_URL} && rm -fr ./Install/MP && mv mp ./Install/MP && cd ./Install/MP && mkdir build && cd build && cmake .. && make mp -j
URL ${MP_DOWNLOAD_URL}
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${MP_ROOT_DIR}
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
)
endif()

list(APPEND GLOBAL_THIRDPARTY_LIB_ARGS "-DMP_ROOT_DIR:PATH=${MP_ROOT_DIR}")
set(MP_INCLUDE_DIRS ${THIRDPARTY_INSTALL_PATH}/Install/MP/include)
Expand Down
18 changes: 8 additions & 10 deletions cmake/FindGUROBI.cmake
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
set(GUROBI_ROOT_DIR "$ENV{GUROBI_ROOT_DIR}" CACHE PATH "Gurobi root directory.")
set(GUROBI_VERSION_SHORT 119)
message("Gurobi root" ${GUROBI_ROOT_DIR})
if(APPLE)
file(GLOB dirs /Library/gurobi1*)
file(GLOB dirs /Library/gurobi*)
foreach(d in ${dirs})
string(REGEX MATCH "[0-9]+" GUROBI_VERSION "${d}")
endforeach(d)
elseif(UNIX)
file(GLOB dirs ${GUROBI_ROOT_DIR}/gurobi1*)
file(GLOB dirs ${GUROBI_ROOT_DIR}/gurobi*)
foreach(d in ${dirs})
string(REGEX MATCH "[0-9]+" GUROBI_VERSION "${d}")
endforeach(d)
Expand All @@ -20,25 +19,24 @@ elseif(UNIX)
string(CONCAT GUROBI_DIR ${GUROBI_ROOT_DIR};/gurobi;${GUROBI_VERSION};/linux64)
endif()
message("Looking for Gurobi in ${GUROBI_DIR}")
if(${GUROBI_DIR})

string(SUBSTRING ${GUROBI_VERSION} 0 3 GUROBI_VERSION_SHORT)
endif()

message("Gurobi version short ${GUROBI_VERSION_SHORT}")

find_path(GUROBI_INCLUDE_DIR gurobi_c++.h HINTS "${GUROBI_DIR}/include" "${GUROBI_ROOT_DIR}/include")
find_path(GUROBI_INCLUDE_DIR gurobi_c++.h HINTS "${GUROBI_DIR}/include")
if(APPLE)
find_library(GUROBI_LIBRARY libgurobi${GUROBI_VERSION_SHORT}.dylib HINTS ${GUROBI_DIR}/lib ${GUROBI_ROOT_DIR}/lib/macos_universal2)
find_library(GUROBI_LIBRARY libgurobi${GUROBI_VERSION_SHORT}.dylib HINTS ${GUROBI_DIR}/lib)
elseif(UNIX)
find_library(GUROBI_LIBRARY libgurobi${GUROBI_VERSION_SHORT}.so HINTS ${GUROBI_DIR}/lib)
endif()
message("GUROBI_DIR ${GUROBI_DIR}")
find_library(GUROBI_CPP_LIBRARY libgurobi_c++.a HINTS "${GUROBI_DIR}/lib" ${GUROBI_ROOT_DIR}/lib/macos_universal2)
find_library(GUROBI_CPP_LIBRARY libgurobi_c++.a HINTS "${GUROBI_DIR}/lib")
message("GUROBI_CPP_LIBRARY ${GUROBI_CPP_LIBRARY}")
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(GUROBI DEFAULT_MSG GUROBI_LIBRARY GUROBI_CPP_LIBRARY GUROBI_INCLUDE_DIR)

if(GUROBI_FOUND)
set(GRB_LICENSE_FILE "~/gurobi/gurobi.lic")
set(GRB_LICENSE_FILE "~/gurobi.research.lic")
set(GUROBI_INCLUDE_DIRS ${GUROBI_INCLUDE_DIR})
set(GUROBI_LIBRARIES ${GUROBI_CPP_LIBRARY} ${GUROBI_LIBRARY})
message("CMAKE_SYSTEM_NAME ${CMAKE_SYSTEM_NAME}")
Expand Down
3 changes: 2 additions & 1 deletion cmake/FindMP.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(MP DEFAULT_MSG MP_LIBRARY MP_INCLUDE_DIR)

if(MP_FOUND)
message("—- Found MP under ${MP_INCLUDE_DIR}")
message("—- Found MP include under ${MP_INCLUDE_DIR}")
message("—- Found MP lib under ${MP_LIBRARY}")
set(MP_INCLUDE_DIRS ${MP_INCLUDE_DIR})
set(MP_LIBRARIES ${MP_LIBRARY})
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
Expand Down
13 changes: 10 additions & 3 deletions examples/Gravity_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,17 @@
using namespace std;
using namespace gravity;

TEST_CASE("testing MISDP solvers"){
var<> x1("x1", -10, 150);


#ifdef USE_MP
TEST_CASE("testing readNL() function") {
Model<> M;
string NL_file = string(prj_dir)+"/data_sets/NL/ex4.nl";
int status = M.readNL(NL_file);
CHECK(status==0);
CHECK(M.get_nb_vars()==36);
CHECK(M.get_nb_cons()==30);
}
#endif

TEST_CASE("testing range update"){
var<> x1("x1", -10, 150);
Expand Down
4 changes: 2 additions & 2 deletions include/gravity/func.h
Original file line number Diff line number Diff line change
Expand Up @@ -9697,12 +9697,12 @@ namespace gravity {
else if(!f.is_constant()){
res._all_convexity = undet_;
}
res._range->first = log(f._range->first);
res._range->first = std::log(f._range->first);
if(f._range->second==numeric_limits<T1>::max()){
res._range->second = numeric_limits<T1>::max();
}
else {
res._range->second = log(f._range->second);
res._range->second = std::log(f._range->second);
}
res._expr->_range->first = res._range->first;
res._expr->_range->second = res._range->second;
Expand Down
Loading

0 comments on commit adb7d6e

Please sign in to comment.