Skip to content

Commit

Permalink
[issue1076] Replace OSI with our own interface to LP/MIP solvers
Browse files Browse the repository at this point in the history
For LP/MIP users: so far, we used the open solver interface OSI to communicate
with MIP and LP solvers. We now replaced this with our own interface to have
more direct control and fewer external dependencies. We now support CPLEX
22.11 and SoPlex from their current main branch (released versions <= 6.0.3 are
incompatible with C++-20). We dropped command line options for CLP and Gurobi
in the process: CLP has much worse performance than SoPlex which is also open
source, while Gurobi was never practically possible to compile with, as we did
not have a CMake find script for it. Performance with CPLEX increased in MIP
configurations and stayed roughly the same in LP configurations. Performance
with SoPlex increased for potential heuristics and decreased slightly in other
configurations.
  • Loading branch information
salome-eriksson authored Jul 20, 2023
1 parent 401a14b commit f32a201
Show file tree
Hide file tree
Showing 16 changed files with 1,352 additions and 920 deletions.
51 changes: 0 additions & 51 deletions src/cmake_modules/FindClp.cmake

This file was deleted.

68 changes: 35 additions & 33 deletions src/cmake_modules/FindCplex.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -136,44 +136,46 @@ find_library(CPLEX_LIBRARY_DEBUG
${CPLEX_LIBRARY_PATH_SUFFIX_DEBUG}
)

# Parse CPLEX version.
file(STRINGS ${CPLEX_INCLUDE_DIRS}/cpxconst.h CPLEX_VERSION_STR
REGEX "#define[ ]+CPX_VERSION[ ]+[0-9]+")
string(REGEX MATCH "[0-9]+" CPLEX_VERSION_STR ${CPLEX_VERSION_STR})
if(CPLEX_VERSION_STR)
math(EXPR CPLEX_VERSION_MAJOR "${CPLEX_VERSION_STR} / 1000000")
math(EXPR CPLEX_VERSION_MINOR "${CPLEX_VERSION_STR} / 10000 % 100")
math(EXPR CPLEX_VERSION_SUBMINOR "${CPLEX_VERSION_STR} / 100 % 100")
set(CPLEX_VERSION
"${CPLEX_VERSION_MAJOR}.${CPLEX_VERSION_MINOR}.${CPLEX_VERSION_SUBMINOR}")
endif()
if(CPLEX_INCLUDE_DIRS)
# Parse CPLEX version.
file(STRINGS ${CPLEX_INCLUDE_DIRS}/cpxconst.h CPLEX_VERSION_STR
REGEX "#define[ ]+CPX_VERSION[ ]+[0-9]+")
string(REGEX MATCH "[0-9]+" CPLEX_VERSION_STR ${CPLEX_VERSION_STR})
if(CPLEX_VERSION_STR)
math(EXPR CPLEX_VERSION_MAJOR "${CPLEX_VERSION_STR} / 1000000")
math(EXPR CPLEX_VERSION_MINOR "${CPLEX_VERSION_STR} / 10000 % 100")
math(EXPR CPLEX_VERSION_SUBMINOR "${CPLEX_VERSION_STR} / 100 % 100")
set(CPLEX_VERSION
"${CPLEX_VERSION_MAJOR}.${CPLEX_VERSION_MINOR}.${CPLEX_VERSION_SUBMINOR}")
endif()

if(CPLEX_LIBRARY_RELEASE OR CPLEX_LIBRARY_DEBUG)
find_package(Threads REQUIRED)

if(CPLEX_LIBRARY_RELEASE OR CPLEX_LIBRARY_DEBUG)
find_package(Threads REQUIRED)
set(CPLEX_LIBRARIES_COMMON ${CMAKE_THREAD_LIBS_INIT})
if(NOT (${CPLEX_VERSION} VERSION_LESS "12.8"))
set(CPLEX_LIBRARIES_COMMON ${CPLEX_LIBRARIES_COMMON} ${CMAKE_DL_LIBS})
endif()

set(CPLEX_LIBRARIES_COMMON ${CMAKE_THREAD_LIBS_INIT})
if(NOT (${CPLEX_VERSION} VERSION_LESS "12.8"))
set(CPLEX_LIBRARIES_COMMON ${CPLEX_LIBRARIES_COMMON} ${CMAKE_DL_LIBS})
set(CPLEX_LIBRARIES
optimized ${CPLEX_LIBRARY_RELEASE} ${CPLEX_LIBRARIES_COMMON}
debug ${CPLEX_LIBRARY_DEBUG} ${CPLEX_LIBRARIES_COMMON}
)
endif()

set(CPLEX_LIBRARIES
optimized ${CPLEX_LIBRARY_RELEASE} ${CPLEX_LIBRARIES_COMMON}
debug ${CPLEX_LIBRARY_DEBUG} ${CPLEX_LIBRARIES_COMMON}
# HACK: there must be a better way to find the dll file.
find_path(CPLEX_RUNTIME_LIBRARY_PATH
NAMES
cplex1262.dll
HINTS
${CPLEX_HINT_PATHS_RELEASE}
${CPLEX_HINT_PATHS_DEBUG}
PATH_SUFFIXES
${CPLEX_RUNTIME_LIBRARY_HINT}
)
endif()

# HACK: there must be a better way to find the dll file.
find_path(CPLEX_RUNTIME_LIBRARY_PATH
NAMES
cplex1262.dll
HINTS
${CPLEX_HINT_PATHS_RELEASE}
${CPLEX_HINT_PATHS_DEBUG}
PATH_SUFFIXES
${CPLEX_RUNTIME_LIBRARY_HINT}
)
if(CPLEX_RUNTIME_LIBRARY_PATH)
set(CPLEX_RUNTIME_LIBRARY "${CPLEX_RUNTIME_LIBRARY_PATH}/cplex1262.dll")
if(CPLEX_RUNTIME_LIBRARY_PATH)
set(CPLEX_RUNTIME_LIBRARY "${CPLEX_RUNTIME_LIBRARY_PATH}/cplex1262.dll")
endif()
endif()

# Check if everything was found and set CPLEX_FOUND.
Expand Down
154 changes: 0 additions & 154 deletions src/cmake_modules/FindOSI.cmake

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ endif()
# Check if everything was found and set SOPLEX_FOUND.
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
soplex
SoPlex
REQUIRED_VARS SOPLEX_INCLUDE_DIRS SOPLEX_LIBRARIES
)

Expand Down
58 changes: 31 additions & 27 deletions src/search/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,41 +57,45 @@ option(
TRUE)

if(PLUGIN_LP_SOLVER_ENABLED AND USE_LP)
find_package(OSI OPTIONAL_COMPONENTS Cpx Clp Grb Spx)
if(OSI_FOUND AND (OSI_Cpx_FOUND OR OSI_Clp_FOUND OR OSI_Grb_FOUND OR OSI_Spx_FOUND))
if(USE_GLIBCXX_DEBUG)
message(
FATAL_ERROR
"To prevent incompatibilities, the option USE_GLIBCXX_DEBUG is "
"not supported when an LP solver is used. See issue982 for details.")
add_definitions("-D USE_LP")

find_package(Cplex)
if(CPLEX_FOUND)
add_definitions("-D HAS_CPLEX")
include_directories(${CPLEX_INCLUDE_DIRS})
target_link_libraries(downward ${CPLEX_LIBRARIES})
if(CPLEX_RUNTIME_LIBRARY)
add_custom_command(TARGET downward POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CPLEX_RUNTIME_LIBRARY}
$<TARGET_FILE_DIR:downward>
)
endif()
foreach(SOLVER Cpx Clp Grb Spx)
if(OSI_${SOLVER}_FOUND)
string(TOUPPER ${SOLVER} TMP_SOLVER_UPPER_CASE)
mark_as_advanced(TMP_SOLVER_UPPER_CASE)
add_definitions("-D COIN_HAS_${TMP_SOLVER_UPPER_CASE}")
include_directories(${OSI_${SOLVER}_INCLUDE_DIRS})
target_link_libraries(downward ${OSI_${SOLVER}_LIBRARIES})
endif()
endforeach()

# Note that basic OSI libs must be added after (!) all OSI solver libs.
add_definitions("-D USE_LP")
include_directories(${OSI_INCLUDE_DIRS})
target_link_libraries(downward ${OSI_LIBRARIES})
endif()

find_package(SoPlex)
if (SOPLEX_FOUND)
add_definitions("-D HAS_SOPLEX")
include_directories(${SOPLEX_INCLUDE_DIRS})
target_link_libraries(downward ${SOPLEX_LIBRARIES})
find_package(ZLIB REQUIRED)
if(ZLIB_FOUND)
include_directories(${ZLIB_INCLUDE_DIRS})
target_link_libraries(downward ${ZLIB_LIBRARIES})
endif()
find_library(GMP_LIBRARY gmp REQUIRED)
if(GMP_LIBRARY)
target_link_libraries(downward ${GMP_LIBRARY})
endif()
endif()

if(OSI_Cpx_FOUND AND CPLEX_RUNTIME_LIBRARY)
add_custom_command(TARGET downward POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CPLEX_RUNTIME_LIBRARY}
$<TARGET_FILE_DIR:downward>
)
if(CPLEX_FOUND OR SOPLEX_FOUND)
if(USE_GLIBCXX_DEBUG)
message(
FATAL_ERROR
"To prevent incompatibilities, the option USE_GLIBCXX_DEBUG is "
"not supported when an LP solver is used. See issue982 for details.")
endif()
endif()

endif()
3 changes: 3 additions & 0 deletions src/search/DownwardFiles.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,11 @@ fast_downward_plugin(
NAME LP_SOLVER
HELP "Interface to an LP solver"
SOURCES
lp/cplex_solver_interface
lp/lp_internals
lp/lp_solver
lp/solver_interface
lp/soplex_solver_interface
DEPENDS NAMED_VECTOR
DEPENDENCY_ONLY
)
Expand Down
Loading

0 comments on commit f32a201

Please sign in to comment.