cmake/FindGLPK.cmake
author Peter Kovacs <kpeter@inf.elte.hu>
Thu, 12 Nov 2009 23:26:13 +0100
changeset 806 fa6f37d7a25b
parent 637 4faa0c763906
child 1062 caf16813b1e8
permissions -rw-r--r--
Entirely rework CapacityScaling (#180)

- Use the new interface similarly to NetworkSimplex.
- Rework the implementation using an efficient internal structure
for handling the residual network. This improvement made the
code much faster (up to 2-5 times faster on large graphs).
- Handle GEQ supply type (LEQ is not supported).
- Handle negative costs for arcs of finite capacity.
(Note that this algorithm cannot handle arcs of negative cost
and infinite upper bound, thus it returns UNBOUNDED if such
an arc exists.)
- Extend the documentation.
     1 SET(GLPK_ROOT_DIR "" CACHE PATH "GLPK root directory")
     2 
     3 SET(GLPK_REGKEY "[HKEY_LOCAL_MACHINE\\SOFTWARE\\GnuWin32\\Glpk;InstallPath]")
     4 GET_FILENAME_COMPONENT(GLPK_ROOT_PATH ${GLPK_REGKEY} ABSOLUTE)
     5 
     6 FIND_PATH(GLPK_INCLUDE_DIR
     7   glpk.h
     8   PATHS ${GLPK_REGKEY}/include
     9   HINTS ${GLPK_ROOT_DIR}/include
    10 )
    11 FIND_LIBRARY(GLPK_LIBRARY
    12   glpk
    13   PATHS ${GLPK_REGKEY}/lib
    14   HINTS ${GLPK_ROOT_DIR}/lib
    15 )
    16 
    17 IF(GLPK_INCLUDE_DIR AND GLPK_LIBRARY)
    18   FILE(READ ${GLPK_INCLUDE_DIR}/glpk.h GLPK_GLPK_H)
    19 
    20   STRING(REGEX MATCH "define[ ]+GLP_MAJOR_VERSION[ ]+[0-9]+" GLPK_MAJOR_VERSION_LINE "${GLPK_GLPK_H}")
    21   STRING(REGEX REPLACE "define[ ]+GLP_MAJOR_VERSION[ ]+([0-9]+)" "\\1" GLPK_VERSION_MAJOR "${GLPK_MAJOR_VERSION_LINE}")
    22 
    23   STRING(REGEX MATCH "define[ ]+GLP_MINOR_VERSION[ ]+[0-9]+" GLPK_MINOR_VERSION_LINE "${GLPK_GLPK_H}")
    24   STRING(REGEX REPLACE "define[ ]+GLP_MINOR_VERSION[ ]+([0-9]+)" "\\1" GLPK_VERSION_MINOR "${GLPK_MINOR_VERSION_LINE}")
    25 
    26   SET(GLPK_VERSION_STRING "${GLPK_VERSION_MAJOR}.${GLPK_VERSION_MINOR}")
    27 
    28   IF(GLPK_FIND_VERSION)
    29     IF(GLPK_FIND_VERSION_COUNT GREATER 2)
    30       MESSAGE(SEND_ERROR "unexpected version string")
    31     ENDIF(GLPK_FIND_VERSION_COUNT GREATER 2)
    32 
    33     MATH(EXPR GLPK_REQUESTED_VERSION "${GLPK_FIND_VERSION_MAJOR}*100 + ${GLPK_FIND_VERSION_MINOR}")
    34     MATH(EXPR GLPK_FOUND_VERSION "${GLPK_VERSION_MAJOR}*100 + ${GLPK_VERSION_MINOR}")
    35 
    36     IF(GLPK_FOUND_VERSION LESS GLPK_REQUESTED_VERSION)
    37       SET(GLPK_PROPER_VERSION_FOUND FALSE)
    38     ELSE(GLPK_FOUND_VERSION LESS GLPK_REQUESTED_VERSION)
    39       SET(GLPK_PROPER_VERSION_FOUND TRUE)
    40     ENDIF(GLPK_FOUND_VERSION LESS GLPK_REQUESTED_VERSION)
    41   ELSE(GLPK_FIND_VERSION)
    42     SET(GLPK_PROPER_VERSION_FOUND TRUE)
    43   ENDIF(GLPK_FIND_VERSION)
    44 ENDIF(GLPK_INCLUDE_DIR AND GLPK_LIBRARY)
    45 
    46 INCLUDE(FindPackageHandleStandardArgs)
    47 FIND_PACKAGE_HANDLE_STANDARD_ARGS(GLPK DEFAULT_MSG GLPK_LIBRARY GLPK_INCLUDE_DIR GLPK_PROPER_VERSION_FOUND)
    48 
    49 IF(GLPK_FOUND)
    50   SET(GLPK_INCLUDE_DIRS ${GLPK_INCLUDE_DIR})
    51   SET(GLPK_LIBRARIES ${GLPK_LIBRARY})
    52   SET(GLPK_BIN_DIR ${GLPK_ROOT_PATH}/bin)
    53 ENDIF(GLPK_FOUND)
    54 
    55 MARK_AS_ADVANCED(GLPK_LIBRARY GLPK_INCLUDE_DIR GLPK_BIN_DIR)
    56 
    57 IF(GLPK_FOUND)
    58   SET(LEMON_HAVE_LP TRUE)
    59   SET(LEMON_HAVE_MIP TRUE)
    60   SET(LEMON_HAVE_GLPK TRUE)
    61 ENDIF(GLPK_FOUND)