COIN-OR::LEMON - Graph Library

Changes in / [1037:d3dcc49e6403:1038:a2d142bb5d3c] in lemon-main


Ignore:
Files:
8 added
18 deleted
96 edited

Legend:

Unmodified
Added
Removed
  • AUTHORS

    r320 r992  
    1 The authors of the 1.x series are
     1The main developers of release series 1.x are
    22
    33 * Balazs Dezso <deba@inf.elte.hu>
     
    66 * Akos Ladanyi <ladanyi@tmit.bme.hu>
    77
    8 For more details on the actual contribution, please visit the history
    9 of the main LEMON source repository: http://lemon.cs.elte.hu/hg/lemon
     8For more complete list of contributors, please visit the history of
     9the LEMON source code repository: http://lemon.cs.elte.hu/hg/lemon
    1010
    11 Moreover, this version is heavily based on the 0.x series of
    12 LEMON. Here is the list of people who contributed to those versions.
     11Moreover, this version is heavily based on version 0.x of LEMON. Here
     12is the list of people who contributed to those versions.
    1313
    1414 * Mihaly Barasz <klao@cs.elte.hu>
     
    2424
    2525Again, please visit the history of the old LEMON repository for more
    26 details: http://lemon.cs.elte.hu/svn/lemon/trunk
     26details: http://lemon.cs.elte.hu/hg/lemon-0.x
  • CMakeLists.txt

    r912 r1017  
    1313ELSE()
    1414  EXECUTE_PROCESS(
    15     COMMAND ${PYTHON_EXECUTABLE} ./scripts/chg-len.py
     15    COMMAND
     16    hg log -r. --template "{latesttag}"
    1617    WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
    17     OUTPUT_VARIABLE HG_REVISION_PATH
     18    OUTPUT_VARIABLE HG_REVISION_TAG
    1819    ERROR_QUIET
    1920    OUTPUT_STRIP_TRAILING_WHITESPACE
    2021  )
    2122  EXECUTE_PROCESS(
    22     COMMAND hg id -i
     23    COMMAND
     24    hg log -r. --template "{latesttagdistance}"
    2325    WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
    24     OUTPUT_VARIABLE HG_REVISION
     26    OUTPUT_VARIABLE HG_REVISION_DIST
    2527    ERROR_QUIET
    2628    OUTPUT_STRIP_TRAILING_WHITESPACE
    2729  )
    28   IF(HG_REVISION STREQUAL "")
     30  EXECUTE_PROCESS(
     31    COMMAND
     32    hg log -r. --template "{node|short}"
     33    WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
     34    OUTPUT_VARIABLE HG_REVISION_ID
     35    ERROR_QUIET
     36    OUTPUT_STRIP_TRAILING_WHITESPACE
     37  )
     38
     39  IF(HG_REVISION_TAG STREQUAL "")
    2940    SET(HG_REVISION_ID "hg-tip")
    3041  ELSE()
    31     IF(HG_REVISION_PATH STREQUAL "")
    32       SET(HG_REVISION_ID ${HG_REVISION})
     42    IF(HG_REVISION_TAG STREQUAL "null")
     43      SET(HG_REVISION_TAG "trunk")
     44    ELSEIF(HG_REVISION_TAG MATCHES "^r")
     45      STRING(SUBSTRING ${HG_REVISION_TAG} 1 -1 HG_REVISION_TAG)
     46    ENDIF()
     47    IF(HG_REVISION_DIST STREQUAL "0")
     48      SET(HG_REVISION ${HG_REVISION_TAG})
    3349    ELSE()
    34       SET(HG_REVISION_ID ${HG_REVISION_PATH}.${HG_REVISION})
     50      SET(HG_REVISION
     51        "${HG_REVISION_TAG}+${HG_REVISION_DIST}-${HG_REVISION_ID}")
    3552    ENDIF()
    3653  ENDIF()
    37   SET(LEMON_VERSION ${HG_REVISION_ID} CACHE STRING "LEMON version string.")
     54
     55  SET(LEMON_VERSION ${HG_REVISION} CACHE STRING "LEMON version string.")
    3856ENDIF()
    3957
     
    5270ELSE()
    5371  IF(CMAKE_COMPILER_IS_GNUCXX)
    54     SET(CXX_WARNING "-Wall -W -Wunused -Wformat=2 -Wctor-dtor-privacy -Wnon-virtual-dtor -Wno-char-subscripts -Wwrite-strings -Wno-char-subscripts -Wreturn-type -Wcast-qual -Wcast-align -Wsign-promo -Woverloaded-virtual -ansi -fno-strict-aliasing -Wold-style-cast -Wno-unknown-pragmas")
     72    SET(CXX_WARNING "-Wall -W -Wunused -Wformat=2 -Wctor-dtor-privacy -Wnon-virtual-dtor -Wno-char-subscripts -Wwrite-strings -Wno-char-subscripts -Wreturn-type -Wcast-qual -Wcast-align -Wsign-promo -Woverloaded-virtual -fno-strict-aliasing -Wold-style-cast -Wno-unknown-pragmas")
    5573    SET(CMAKE_CXX_FLAGS_DEBUG CACHE STRING "-ggdb")
    5674    SET(CMAKE_C_FLAGS_DEBUG CACHE STRING "-ggdb")
     
    6785    # C4996: 'function': was declared deprecated
    6886  ELSE()
    69     SET(CXX_WARNING "-Wall -W")
     87    SET(CXX_WARNING "-Wall")
    7088  ENDIF()
    7189ENDIF()
     
    7492SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LEMON_CXX_WARNING_FLAGS}")
    7593
    76 SET( CMAKE_CXX_FLAGS_MAINTAINER "-Werror -ggdb" CACHE STRING
     94IF(MSVC)
     95  SET( CMAKE_CXX_FLAGS_MAINTAINER "/WX ${CMAKE_CXX_FLAGS_DEBUG}" CACHE STRING
    7796    "Flags used by the C++ compiler during maintainer builds."
    78     FORCE )
    79 SET( CMAKE_C_FLAGS_MAINTAINER "-Werror" CACHE STRING
     97    )
     98  SET( CMAKE_C_FLAGS_MAINTAINER "/WX ${CMAKE_CXX_FLAGS_DEBUG}" CACHE STRING
    8099    "Flags used by the C compiler during maintainer builds."
    81     FORCE )
    82 SET( CMAKE_EXE_LINKER_FLAGS_MAINTAINER
     100    )
     101  SET( CMAKE_EXE_LINKER_FLAGS_MAINTAINER
     102    "${CMAKE_EXE_LINKER_FLAGS_DEBUG}" CACHE STRING
     103    "Flags used for linking binaries during maintainer builds."
     104    )
     105  SET( CMAKE_SHARED_LINKER_FLAGS_MAINTAINER
     106    "${CMAKE_SHARED_LINKER_FLAGS_DEBUG}" CACHE STRING
     107    "Flags used by the shared libraries linker during maintainer builds."
     108    )
     109ELSE()
     110  SET( CMAKE_CXX_FLAGS_MAINTAINER "-Werror -ggdb -O0" CACHE STRING
     111    "Flags used by the C++ compiler during maintainer builds."
     112    )
     113  SET( CMAKE_C_FLAGS_MAINTAINER "-Werror -O0" CACHE STRING
     114    "Flags used by the C compiler during maintainer builds."
     115    )
     116  SET( CMAKE_EXE_LINKER_FLAGS_MAINTAINER
    83117    "-Wl,--warn-unresolved-symbols,--warn-once" CACHE STRING
    84118    "Flags used for linking binaries during maintainer builds."
    85     FORCE )
    86 SET( CMAKE_SHARED_LINKER_FLAGS_MAINTAINER
     119    )
     120  SET( CMAKE_SHARED_LINKER_FLAGS_MAINTAINER
    87121    "-Wl,--warn-unresolved-symbols,--warn-once" CACHE STRING
    88122    "Flags used by the shared libraries linker during maintainer builds."
    89     FORCE )
     123    )
     124ENDIF()
     125
    90126MARK_AS_ADVANCED(
    91127    CMAKE_CXX_FLAGS_MAINTAINER
     
    115151SET(LEMON_HAVE_LONG_LONG ${HAVE_LONG_LONG})
    116152
     153INCLUDE(FindThreads)
     154
     155IF(NOT LEMON_THREADING)
     156  IF(CMAKE_USE_PTHREADS_INIT)
     157    SET(LEMON_THREADING "Pthread")
     158  ELSEIF(CMAKE_USE_WIN32_THREADS_INIT)
     159    SET(LEMON_THREADING "Win32")
     160  ELSE()
     161    SET(LEMON_THREADING "None")
     162  ENDIF()
     163ENDIF()
     164
     165SET( LEMON_THREADING "${LEMON_THREADING}" CACHE STRING
     166  "Choose the threading library, options are: Pthread Win32 None."
     167  FORCE )
     168
     169IF(LEMON_THREADING STREQUAL "Pthread")
     170  SET(LEMON_USE_PTHREAD TRUE)
     171ELSEIF(LEMON_THREADING STREQUAL "Win32")
     172  SET(LEMON_USE_WIN32_THREADS TRUE)
     173ENDIF()
     174
    117175ENABLE_TESTING()
    118176
     
    125183ADD_SUBDIRECTORY(lemon)
    126184IF(${CMAKE_SOURCE_DIR} STREQUAL ${PROJECT_SOURCE_DIR})
     185  ADD_SUBDIRECTORY(contrib)
    127186  ADD_SUBDIRECTORY(demo)
    128187  ADD_SUBDIRECTORY(tools)
     
    148207ENDIF()
    149208
     209CONFIGURE_FILE(
     210  ${PROJECT_SOURCE_DIR}/cmake/version.cmake.in
     211  ${PROJECT_BINARY_DIR}/cmake/version.cmake
     212  @ONLY
     213)
     214
     215SET(ARCHIVE_BASE_NAME ${CMAKE_PROJECT_NAME})
     216STRING(TOLOWER ${ARCHIVE_BASE_NAME} ARCHIVE_BASE_NAME)
     217SET(ARCHIVE_NAME ${ARCHIVE_BASE_NAME}-${PROJECT_VERSION})
     218ADD_CUSTOM_TARGET(dist
     219  COMMAND cmake -E remove_directory ${ARCHIVE_NAME}
     220  COMMAND hg archive ${ARCHIVE_NAME}
     221  COMMAND cmake -E copy cmake/version.cmake ${ARCHIVE_NAME}/cmake/version.cmake
     222  COMMAND tar -czf ${ARCHIVE_BASE_NAME}-nodoc-${PROJECT_VERSION}.tar.gz ${ARCHIVE_NAME}
     223  COMMAND zip -r ${ARCHIVE_BASE_NAME}-nodoc-${PROJECT_VERSION}.zip ${ARCHIVE_NAME}
     224  COMMAND cmake -E copy_directory doc/html ${ARCHIVE_NAME}/doc/html
     225  COMMAND tar -czf ${ARCHIVE_NAME}.tar.gz ${ARCHIVE_NAME}
     226  COMMAND zip -r ${ARCHIVE_NAME}.zip ${ARCHIVE_NAME}
     227  COMMAND cmake -E copy_directory doc/html ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION}
     228  COMMAND tar -czf ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION}.tar.gz ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION}
     229  COMMAND zip -r ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION}.zip ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION}
     230  COMMAND cmake -E remove_directory ${ARCHIVE_NAME}
     231  COMMAND cmake -E remove_directory ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION}
     232  DEPENDS html
     233  WORKING_DIRECTORY ${PROJECT_BINARY_DIR})
     234
     235# CPACK config (Basically for NSIS)
    150236IF(${CMAKE_SOURCE_DIR} STREQUAL ${PROJECT_SOURCE_DIR})
    151237  SET(CPACK_PACKAGE_NAME ${PROJECT_NAME})
  • INSTALL

    r824 r992  
    22=========================
    33
    4 Since you are reading this I assume you already obtained one of the release
    5 tarballs and successfully extracted it. The latest version of LEMON is
    6 available at our web page (http://lemon.cs.elte.hu/).
     4This file contains instructions for building and installing LEMON from
     5source on Linux. The process on Windows is similar.
    76
    8 LEMON provides two different build environments, one is based on "autotool",
    9 while the other is based on "cmake". This file contains instructions only for
    10 the former one, which is the recommended build environment on Linux, Mac OSX
    11 and other unices or if you use Cygwin on Windows. For cmake installation
    12 instructions visit http://lemon.cs.elte.hu.
     7Note that it is not necessary to install LEMON in order to use
     8it. Instead, you can easily integrate it with your own code
     9directly. For instructions, see
     10https://lemon.cs.elte.hu/trac/lemon/wiki/HowToCompile
     11
    1312
    1413In order to install LEMON from the extracted source tarball you have to
    1514issue the following commands:
    1615
    17    1. `cd lemon-x.y.z'
     16   1. Step into the root of the source directory.
    1817
    19       This command changes to the directory which was created when you
    20       extracted the sources. The x.y.z part is a version number.
     18      $ cd lemon-x.y.z
    2119
    22    2. `./configure'
     20   2. Create a build subdirectory and step into it.
    2321
    24       This command runs the configure shell script, which does some checks and
    25       creates the makefiles.
     22      $ mkdir build
     23      $ cd build
    2624
    27    3. `make'
     25   3. Perform system checks and create the makefiles.
    2826
    29       This command compiles the non-template part of LEMON into libemon.a
    30       file. It also compiles the programs in the tools subdirectory by
    31       default.
     27      $ cmake ..
    3228
    33    4. `make check'
     29   4. Build LEMON.
    3430
    35       This step is optional, but recommended. It runs the test programs that
    36       we developed for LEMON to check whether the library works properly on
    37       your platform.
     31      $ make
    3832
    39    5. `make install'
     33      This command compiles the non-template part of LEMON into
     34      libemon.a file. It also compiles the programs in the 'tools' and
     35      'demo' subdirectories.
     36
     37   5. [Optional] Compile and run the self-tests.
     38
     39      $ make check
     40
     41   5. [Optional] Generate the user documentation.
     42
     43      $ make html
     44
     45      The release tarballs already include the documentation.
     46
     47      Note that for this step you need to have the following tools
     48      installed: Python, Doxygen, Graphviz, Ghostscript, LaTeX.
     49
     50   6. [Optional] Install LEMON
     51
     52      $ make install
    4053
    4154      This command installs LEMON under /usr/local (you will need root
    42       privileges to be able to do that). If you want to install it to some
    43       other location, then pass the --prefix=DIRECTORY flag to configure in
    44       step 2. For example: `./configure --prefix=/home/username/lemon'.
    45 
    46    6. `make install-html'
    47 
    48       This command installs the documentation under share/doc/lemon/docs. The
    49       generated documentation is included in the tarball. If you want to
    50       generate it yourself, then run `make html'. Note that for this you need
    51       to have the following programs installed: Doxygen, Graphviz, Ghostscript,
    52       Latex.
    53 
     55      privileges to be able to do that). If you want to install it to
     56      some other location, then pass the
     57      -DCMAKE_INSTALL_PREFIX=DIRECTORY flag to cmake in Step 3.
     58      For example:
     59     
     60      $ cmake -DCMAKE_INSTALL_PREFIX=/home/username/lemon'
    5461
    5562Configure Options and Variables
    5663===============================
    5764
    58 In step 2 you can customize the actions of configure by setting variables
    59 and passing options to it. This can be done like this:
    60 `./configure [OPTION]... [VARIABLE=VALUE]...'
     65In Step 3, you can customize the build process by passing options to CMAKE.
    6166
    62 Below you will find some useful variables and options (see `./configure --help'
    63 for more):
     67$ cmake [OPTIONS] ..
    6468
    65 CXX='comp'
     69You find a list of the most useful options below.
    6670
    67   Change the C++ compiler to 'comp'.
    68 
    69 CXXFLAGS='flags'
    70 
    71   Pass the 'flags' to the compiler. For example CXXFLAGS='-O3 -march=pentium-m'
    72   turns on generation of aggressively optimized Pentium-M specific code.
    73 
    74 --prefix=PREFIX
     71-DCMAKE_INSTALL_PREFIX=PREFIX
    7572
    7673  Set the installation prefix to PREFIX. By default it is /usr/local.
    7774
    78 --enable-tools
     75-DCMAKE_BUILD_TYPE=[Release|Debug|Maintainer|...]
    7976
    80    Build the programs in the tools subdirectory (default).
     77  This sets the compiler options. The choices are the following
    8178
    82 --disable-tools
     79  'Release': A strong optimization is turned on (-O3 with gcc). This
     80    is the default setting and we strongly recommend using this for
     81    the final compilation.
    8382
    84    Do not build the programs in the tools subdirectory.
     83  'Debug': Optimization is turned off and debug info is added (-O0
     84    -ggdb with gcc). If is recommended during the development.
    8585
    86 --with-glpk[=PREFIX]
     86  'Maintainer': The same as 'Debug' but the compiler warnings are
     87    converted to errors (-Werror with gcc). In addition, 'make' will
     88    also automatically compile and execute the test codes. It is the
     89    best way of ensuring that LEMON codebase is clean and safe.
    8790
    88    Enable GLPK support (default). You should specify the prefix too if
    89    you installed GLPK to some non-standard location (e.g. your home
    90    directory). If it is not found, GLPK support will be disabled.
     91  'RelWithDebInfo': Optimized build with debug info.
    9192
    92 --with-glpk-includedir=DIR
     93  'MinSizeRel': Size optimized build (-Os with gcc)
    9394
    94    The directory where the GLPK header files are located. This is only
    95    useful when the GLPK headers and libraries are not under the same
    96    prefix (which is unlikely).
     95-DTEST_WITH_VALGRIND=YES
    9796
    98 --with-glpk-libdir=DIR
     97  Using this, the test codes will be executed using valgrind. It is a
     98  very effective way of identifying indexing problems and memory leaks.
    9999
    100    The directory where the GLPK libraries are located. This is only
    101    useful when the GLPK headers and libraries are not under the same
    102    prefix (which is unlikely).
     100-DCMAKE_CXX_COMPILER=path-to-compiler
    103101
    104 --without-glpk
     102  Change the compiler to be used.
    105103
    106    Disable GLPK support.
     104-DBUILD_SHARED_LIBS=TRUE
    107105
    108 --with-cplex[=PREFIX]
     106  Build shared library instead of static one. Think twice if you
     107  really want to use this option.
    109108
    110    Enable CPLEX support (default). You should specify the prefix too
    111    if you installed CPLEX to some non-standard location
    112    (e.g. /opt/ilog/cplex75). If it is not found, CPLEX support will be
    113    disabled.
     109-DGLPK_ROOT_DIR=DIRECTORY
     110-DCOIN_ROOT_DIR=DIRECTORY
     111-DCPLEX_ROOT_DIR=DIRECTORY
    114112
    115 --with-cplex-includedir=DIR
    116 
    117    The directory where the CPLEX header files are located. This is
    118    only useful when the CPLEX headers and libraries are not under the
    119    same prefix (e.g.  /usr/local/cplex/cplex75/include).
    120 
    121 --with-cplex-libdir=DIR
    122 
    123    The directory where the CPLEX libraries are located. This is only
    124    useful when the CPLEX headers and libraries are not under the same
    125    prefix (e.g.
    126    /usr/local/cplex/cplex75/lib/i86_linux2_glibc2.2_gcc3.0/static_pic_mt).
    127 
    128 --without-cplex
    129 
    130    Disable CPLEX support.
    131 
    132 --with-soplex[=PREFIX]
    133 
    134    Enable SoPlex support (default). You should specify the prefix too if
    135    you installed SoPlex to some non-standard location (e.g. your home
    136    directory). If it is not found, SoPlex support will be disabled.
    137 
    138 --with-soplex-includedir=DIR
    139 
    140    The directory where the SoPlex header files are located. This is only
    141    useful when the SoPlex headers and libraries are not under the same
    142    prefix (which is unlikely).
    143 
    144 --with-soplex-libdir=DIR
    145 
    146    The directory where the SoPlex libraries are located. This is only
    147    useful when the SoPlex headers and libraries are not under the same
    148    prefix (which is unlikely).
    149 
    150 --without-soplex
    151 
    152    Disable SoPlex support.
    153 
    154 --with-coin[=PREFIX]
    155 
    156    Enable support for COIN-OR solvers (CLP and CBC). You should
    157    specify the prefix too. (by default, COIN-OR tools install
    158    themselves to the source code directory). This command enables the
    159    solvers that are actually found.
    160 
    161 --with-coin-includedir=DIR
    162 
    163    The directory where the COIN-OR header files are located. This is
    164    only useful when the COIN-OR headers and libraries are not under
    165    the same prefix (which is unlikely).
    166 
    167 --with-coin-libdir=DIR
    168 
    169    The directory where the COIN-OR libraries are located. This is only
    170    useful when the COIN-OR headers and libraries are not under the
    171    same prefix (which is unlikely).
    172 
    173 --without-coin
    174 
    175    Disable COIN-OR support.
    176 
     113  Install root directory prefixes of optional third party libraries.
    177114
    178115Makefile Variables
    179116==================
    180117
    181 Some Makefile variables are reserved by the GNU Coding Standards for
    182 the use of the "user" - the person building the package. For instance,
    183 CXX and CXXFLAGS are such variables, and have the same meaning as
    184 explained in the previous section. These variables can be set on the
    185 command line when invoking `make' like this:
    186 `make [VARIABLE=VALUE]...'
     118make VERBOSE=1
    187119
    188 WARNINGCXXFLAGS is a non-standard Makefile variable introduced by us
    189 to hold several compiler flags related to warnings. Its default value
    190 can be overridden when invoking `make'. For example to disable all
    191 warning flags use `make WARNINGCXXFLAGS='.
    192 
    193 In order to turn off a single flag from the default set of warning
    194 flags, you can use the CXXFLAGS variable, since this is passed after
    195 WARNINGCXXFLAGS. For example to turn off `-Wold-style-cast' (which is
    196 used by default when g++ is detected) you can use
    197 `make CXXFLAGS="-g -O2 -Wno-old-style-cast"'.
     120   This results in a more verbose output by showing the full
     121   compiler and linker commands.
  • LICENSE

    r879 r992  
    22copyright/license.
    33
    4 Copyright (C) 2003-2010 Egervary Jeno Kombinatorikus Optimalizalasi
     4Copyright (C) 2003-2012 Egervary Jeno Kombinatorikus Optimalizalasi
    55Kutatocsoport (Egervary Combinatorial Optimization Research Group,
    66EGRES).
  • cmake/FindCOIN.cmake

    r634 r973  
    66FIND_LIBRARY(COIN_CBC_LIBRARY
    77  NAMES Cbc libCbc
     8  HINTS ${COIN_ROOT_DIR}/lib/coin
    89  HINTS ${COIN_ROOT_DIR}/lib
    910)
    1011FIND_LIBRARY(COIN_CBC_SOLVER_LIBRARY
    1112  NAMES CbcSolver libCbcSolver
     13  HINTS ${COIN_ROOT_DIR}/lib/coin
    1214  HINTS ${COIN_ROOT_DIR}/lib
    1315)
    1416FIND_LIBRARY(COIN_CGL_LIBRARY
    1517  NAMES Cgl libCgl
     18  HINTS ${COIN_ROOT_DIR}/lib/coin
    1619  HINTS ${COIN_ROOT_DIR}/lib
    1720)
    1821FIND_LIBRARY(COIN_CLP_LIBRARY
    1922  NAMES Clp libClp
     23  HINTS ${COIN_ROOT_DIR}/lib/coin
    2024  HINTS ${COIN_ROOT_DIR}/lib
    2125)
    2226FIND_LIBRARY(COIN_COIN_UTILS_LIBRARY
    2327  NAMES CoinUtils libCoinUtils
     28  HINTS ${COIN_ROOT_DIR}/lib/coin
    2429  HINTS ${COIN_ROOT_DIR}/lib
    2530)
    2631FIND_LIBRARY(COIN_OSI_LIBRARY
    2732  NAMES Osi libOsi
     33  HINTS ${COIN_ROOT_DIR}/lib/coin
    2834  HINTS ${COIN_ROOT_DIR}/lib
    2935)
    3036FIND_LIBRARY(COIN_OSI_CBC_LIBRARY
    3137  NAMES OsiCbc libOsiCbc
     38  HINTS ${COIN_ROOT_DIR}/lib/coin
    3239  HINTS ${COIN_ROOT_DIR}/lib
    3340)
    3441FIND_LIBRARY(COIN_OSI_CLP_LIBRARY
    3542  NAMES OsiClp libOsiClp
     43  HINTS ${COIN_ROOT_DIR}/lib/coin
    3644  HINTS ${COIN_ROOT_DIR}/lib
    3745)
    3846FIND_LIBRARY(COIN_OSI_VOL_LIBRARY
    3947  NAMES OsiVol libOsiVol
     48  HINTS ${COIN_ROOT_DIR}/lib/coin
    4049  HINTS ${COIN_ROOT_DIR}/lib
    4150)
    4251FIND_LIBRARY(COIN_VOL_LIBRARY
    4352  NAMES Vol libVol
     53  HINTS ${COIN_ROOT_DIR}/lib/coin
     54  HINTS ${COIN_ROOT_DIR}/lib
     55)
     56
     57FIND_LIBRARY(COIN_ZLIB_LIBRARY
     58  NAMES z libz
     59  HINTS ${COIN_ROOT_DIR}/lib/coin
     60  HINTS ${COIN_ROOT_DIR}/lib
     61)
     62FIND_LIBRARY(COIN_BZ2_LIBRARY
     63  NAMES bz2 libbz2
     64  HINTS ${COIN_ROOT_DIR}/lib/coin
    4465  HINTS ${COIN_ROOT_DIR}/lib
    4566)
     
    5677  COIN_OSI_CBC_LIBRARY
    5778  COIN_OSI_CLP_LIBRARY
    58   COIN_OSI_VOL_LIBRARY
    59   COIN_VOL_LIBRARY
     79  # COIN_OSI_VOL_LIBRARY
     80  # COIN_VOL_LIBRARY
    6081)
    6182
    6283IF(COIN_FOUND)
    6384  SET(COIN_INCLUDE_DIRS ${COIN_INCLUDE_DIR})
    64   SET(COIN_LIBRARIES "${COIN_CBC_LIBRARY};${COIN_CBC_SOLVER_LIBRARY};${COIN_CGL_LIBRARY};${COIN_CLP_LIBRARY};${COIN_COIN_UTILS_LIBRARY};${COIN_OSI_LIBRARY};${COIN_OSI_CBC_LIBRARY};${COIN_OSI_CLP_LIBRARY};${COIN_OSI_VOL_LIBRARY};${COIN_VOL_LIBRARY}")
    65   SET(COIN_CLP_LIBRARIES "${COIN_CLP_LIBRARY};${COIN_COIN_UTILS_LIBRARY}")
    66   SET(COIN_CBC_LIBRARIES ${COIN_LIBRARIES})
     85  SET(COIN_CLP_LIBRARIES "${COIN_CLP_LIBRARY};${COIN_COIN_UTILS_LIBRARY};${COIN_ZLIB_LIBRARY};${COIN_BZ2_LIBRARY}")
     86  IF(COIN_ZLIB_LIBRARY)
     87    SET(COIN_CLP_LIBRARIES "${COIN_CLP_LIBRARIES};${COIN_ZLIB_LIBRARY}")
     88  ENDIF(COIN_ZLIB_LIBRARY)
     89   IF(COIN_BZ2_LIBRARY)
     90    SET(COIN_CLP_LIBRARIES "${COIN_CLP_LIBRARIES};${COIN_BZ2_LIBRARY}")
     91  ENDIF(COIN_BZ2_LIBRARY)
     92  SET(COIN_CBC_LIBRARIES "${COIN_CBC_LIBRARY};${COIN_CBC_SOLVER_LIBRARY};${COIN_CGL_LIBRARY};${COIN_OSI_LIBRARY};${COIN_OSI_CBC_LIBRARY};${COIN_OSI_CLP_LIBRARY};${COIN_ZLIB_LIBRARY};${COIN_BZ2_LIBRARY};${COIN_CLP_LIBRARIES}")
     93  SET(COIN_LIBRARIES ${COIN_CBC_LIBRARIES})
    6794ENDIF(COIN_FOUND)
    6895
     
    79106  COIN_OSI_VOL_LIBRARY
    80107  COIN_VOL_LIBRARY
     108  COIN_ZLIB_LIBRARY
     109  COIN_BZ2_LIBRARY
    81110)
    82111
  • cmake/FindCPLEX.cmake

    r636 r972  
    33FIND_PATH(CPLEX_INCLUDE_DIR
    44  ilcplex/cplex.h
    5   PATHS "C:/ILOG/CPLEX91/include"
    6   PATHS "/opt/ilog/cplex91/include"
     5  PATHS "C:/ILOG/CPLEX/include"
     6  PATHS "/opt/ilog/cplex/include"
    77  HINTS ${CPLEX_ROOT_DIR}/include
    88)
    99FIND_LIBRARY(CPLEX_LIBRARY
    10   cplex91
    11   PATHS "C:/ILOG/CPLEX91/lib/msvc7/stat_mda"
    12   PATHS "/opt/ilog/cplex91/bin"
     10  cplex
     11  PATHS "C:/ILOG/CPLEX/lib/msvc7/stat_mda"
     12  PATHS "/opt/ilog/cplex/bin"
    1313  HINTS ${CPLEX_ROOT_DIR}/bin
     14  HINTS ${CPLEX_ROOT_DIR}/lib
    1415)
    1516
     
    1819
    1920FIND_PATH(CPLEX_BIN_DIR
    20   cplex91.dll
    21   PATHS "C:/ILOG/CPLEX91/bin/x86_win32"
     21  cplex.dll
     22  PATHS "C:/ILOG/CPLEX/bin/x86_win32"
     23  HINTS ${CPLEX_ROOT_DIR}/bin
    2224)
    2325
  • cmake/version.cmake.in

    r678 r983  
    1 SET(LEMON_VERSION "@PACKAGE_VERSION@" CACHE STRING "LEMON version string.")
     1SET(LEMON_VERSION "@LEMON_VERSION@" CACHE STRING "LEMON version string.")
  • doc/CMakeLists.txt

    r1032 r1038  
    1111  @ONLY
    1212)
     13
     14CONFIGURE_FILE(
     15  ${PROJECT_SOURCE_DIR}/doc/mainpage.dox.in
     16  ${PROJECT_BINARY_DIR}/doc/mainpage.dox
     17  @ONLY
     18)
     19
     20# Copy doc from source (if exists)
     21IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/html AND
     22    NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/html/index.html)
     23  MESSAGE(STATUS "Copy doc from source tree")
     24  EXECUTE_PROCESS(
     25    COMMAND cmake -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/html ${CMAKE_CURRENT_BINARY_DIR}/html
     26    )
     27ENDIF()
    1328
    1429IF(DOXYGEN_EXECUTABLE AND PYTHONINTERP_FOUND AND GHOSTSCRIPT_EXECUTABLE)
  • doc/Doxyfile.in

    r912 r966  
    1 # Doxyfile 1.5.9
     1# Doxyfile 1.7.3
    22
    33#---------------------------------------------------------------------------
     
    55#---------------------------------------------------------------------------
    66DOXYFILE_ENCODING      = UTF-8
    7 PROJECT_NAME           = @PACKAGE_NAME@
    8 PROJECT_NUMBER         = @PACKAGE_VERSION@
     7PROJECT_NAME           =
     8PROJECT_NUMBER         =
     9PROJECT_BRIEF          =
     10PROJECT_LOGO           =
    911OUTPUT_DIRECTORY       =
    1012CREATE_SUBDIRS         = NO
     
    3032OPTIMIZE_FOR_FORTRAN   = NO
    3133OPTIMIZE_OUTPUT_VHDL   = NO
     34EXTENSION_MAPPING      =
    3235BUILTIN_STL_SUPPORT    = YES
    3336CPP_CLI_SUPPORT        = NO
     
    5558HIDE_SCOPE_NAMES       = YES
    5659SHOW_INCLUDE_FILES     = YES
     60FORCE_LOCAL_INCLUDES   = NO
    5761INLINE_INFO            = YES
    5862SORT_MEMBER_DOCS       = NO
    5963SORT_BRIEF_DOCS        = NO
     64SORT_MEMBERS_CTORS_1ST = NO
    6065SORT_GROUP_NAMES       = NO
    6166SORT_BY_SCOPE_NAME     = NO
     67STRICT_PROTO_MATCHING  = NO
    6268GENERATE_TODOLIST      = YES
    6369GENERATE_TESTLIST      = YES
     
    9096                         "@abs_top_srcdir@/lemon/concepts" \
    9197                         "@abs_top_srcdir@/demo" \
     98                         "@abs_top_srcdir@/contrib" \
    9299                         "@abs_top_srcdir@/tools" \
    93100                         "@abs_top_srcdir@/test/test_tools.h" \
     101                         "@abs_top_builddir@/doc/mainpage.dox" \
    94102                         "@abs_top_builddir@/doc/references.dox"
    95103INPUT_ENCODING         = UTF-8
     
    112120FILTER_PATTERNS        =
    113121FILTER_SOURCE_FILES    = NO
     122FILTER_SOURCE_PATTERNS =
    114123#---------------------------------------------------------------------------
    115124# configuration options related to source browsing
     
    138147HTML_FOOTER            =
    139148HTML_STYLESHEET        =
     149HTML_COLORSTYLE_HUE    = 220
     150HTML_COLORSTYLE_SAT    = 100
     151HTML_COLORSTYLE_GAMMA  = 80
     152HTML_TIMESTAMP         = YES
    140153HTML_ALIGN_MEMBERS     = YES
    141 HTML_DYNAMIC_SECTIONS  = NO
     154HTML_DYNAMIC_SECTIONS  = YES
    142155GENERATE_DOCSET        = NO
    143156DOCSET_FEEDNAME        = "Doxygen generated docs"
    144157DOCSET_BUNDLE_ID       = org.doxygen.Project
     158DOCSET_PUBLISHER_ID    = org.doxygen.Publisher
     159DOCSET_PUBLISHER_NAME  = Publisher
    145160GENERATE_HTMLHELP      = NO
    146161CHM_FILE               =
     
    154169QHP_NAMESPACE          = org.doxygen.Project
    155170QHP_VIRTUAL_FOLDER     = doc
     171QHP_CUST_FILTER_NAME   =
     172QHP_CUST_FILTER_ATTRS  =
     173QHP_SECT_FILTER_ATTRS  =
    156174QHG_LOCATION           =
     175GENERATE_ECLIPSEHELP   = NO
     176ECLIPSE_DOC_ID         = org.doxygen.Project
    157177DISABLE_INDEX          = NO
    158178ENUM_VALUES_PER_LINE   = 4
    159179GENERATE_TREEVIEW      = NO
     180USE_INLINE_TREES       = NO
    160181TREEVIEW_WIDTH         = 250
     182EXT_LINKS_IN_WINDOW    = NO
    161183FORMULA_FONTSIZE       = 10
     184FORMULA_TRANSPARENT    = YES
     185USE_MATHJAX            = NO
     186MATHJAX_RELPATH        = http://www.mathjax.org/mathjax
     187SEARCHENGINE           = YES
     188SERVER_BASED_SEARCH    = NO
    162189#---------------------------------------------------------------------------
    163190# configuration options related to the LaTeX output
     
    176203LATEX_BATCHMODE        = NO
    177204LATEX_HIDE_INDICES     = NO
     205LATEX_SOURCE_CODE      = NO
    178206#---------------------------------------------------------------------------
    179207# configuration options related to the RTF output
     
    224252SKIP_FUNCTION_MACROS   = YES
    225253#---------------------------------------------------------------------------
    226 # Options related to the search engine   
     254# Configuration::additions related to external references
    227255#---------------------------------------------------------------------------
    228256TAGFILES               = "@abs_top_builddir@/doc/libstdc++.tag = http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/  "
     
    238266HIDE_UNDOC_RELATIONS   = YES
    239267HAVE_DOT               = YES
     268DOT_NUM_THREADS        = 0
    240269DOT_FONTNAME           = FreeSans
    241270DOT_FONTSIZE           = 10
     
    255284DOT_PATH               =
    256285DOTFILE_DIRS           =
     286MSCFILE_DIRS           =
    257287DOT_GRAPH_MAX_NODES    = 50
    258288MAX_DOT_GRAPH_DEPTH    = 0
     
    261291GENERATE_LEGEND        = YES
    262292DOT_CLEANUP            = YES
    263 #---------------------------------------------------------------------------
    264 # Configuration::additions related to the search engine   
    265 #---------------------------------------------------------------------------
    266 SEARCHENGINE           = NO
  • doc/DoxygenLayout.xml

    r316 r928  
    33  <navindex>
    44    <tab type="mainpage" visible="yes" title=""/>
    5     <tab type="modules" visible="yes" title=""/>
     5    <tab type="modules" visible="yes" title="" intro=""/>
    66    <tab type="classes" visible="yes" title="">
    7       <tab type="classes" visible="yes" title=""/>
    8       <tab type="classindex" visible="$ALPHABETICAL_INDEX" title=""/> 
    9       <tab type="hierarchy" visible="yes" title=""/>
    10       <tab type="classmembers" visible="yes" title=""/>
     7      <tab type="classes" visible="yes" title="" intro=""/>
     8      <tab type="classindex" visible="$ALPHABETICAL_INDEX" title=""/>
     9      <tab type="hierarchy" visible="yes" title="" intro=""/>
     10      <tab type="classmembers" visible="yes" title="" intro=""/>
    1111    </tab>
    1212    <tab type="namespaces" visible="yes" title="">
    13       <tab type="namespaces" visible="yes" title=""/>
    14       <tab type="namespacemembers" visible="yes" title=""/>
     13      <tab type="namespaces" visible="yes" title="" intro=""/>
     14      <tab type="namespacemembers" visible="yes" title="" intro=""/>
    1515    </tab>
    1616    <tab type="files" visible="yes" title="">
    17       <tab type="files" visible="yes" title=""/>
    18       <tab type="globals" visible="yes" title=""/>
     17      <tab type="files" visible="yes" title="" intro=""/>
     18      <tab type="globals" visible="yes" title="" intro=""/>
    1919    </tab>
    20     <tab type="dirs" visible="yes" title=""/>
    21     <tab type="examples" visible="yes" title=""/> 
    22     <tab type="pages" visible="yes" title=""/>
     20    <tab type="dirs" visible="yes" title="" intro=""/>
     21    <tab type="examples" visible="yes" title="" intro=""/>
     22    <tab type="pages" visible="yes" title="" intro=""/>
    2323  </navindex>
    2424
  • doc/coding_style.dox

    r440 r919  
    9999\subsection pri-loc-var Private member variables
    100100
    101 Private member variables should start with underscore
     101Private member variables should start with underscore.
    102102
    103103\code
    104 _start_with_underscores
     104_start_with_underscore
    105105\endcode
    106106
  • doc/dirs.dox

    r440 r925  
    3232documentation.
    3333*/
     34
     35/**
     36\dir contrib
     37\brief Directory for user contributed source codes.
     38
     39You can place your own C++ code using LEMON into this directory, which
     40will compile to an executable along with LEMON when you build the
     41library. This is probably the easiest way of compiling short to medium
     42codes, for this does require neither a LEMON installed system-wide nor
     43adding several paths to the compiler.
     44
     45Please have a look at <tt>contrib/CMakeLists.txt</tt> for
     46instruction on how to add your own files into the build process.  */
    3447
    3548/**
  • doc/groups.dox

    r1036 r1038  
    407407   strongly polynomial \ref klein67primal, \ref goldberg89cyclecanceling.
    408408
    409 In general NetworkSimplex is the most efficient implementation,
    410 but in special cases other algorithms could be faster.
     409In general, \ref NetworkSimplex and \ref CostScaling are the most efficient
     410implementations.
     411\ref NetworkSimplex is usually the fastest on relatively small graphs (up to
     412several thousands of nodes) and on dense graphs, while \ref CostScaling is
     413typically more efficient on large graphs (e.g. hundreds of thousands of
     414nodes or above), especially if they are sparse.
     415However, other algorithms could be faster in special cases.
    411416For example, if the total supply and/or capacities are rather small,
    412 CapacityScaling is usually the fastest algorithm (without effective scaling).
     417\ref CapacityScaling is usually the fastest algorithm (without effective scaling).
     418
     419These classes are intended to be used with integer-valued input data
     420(capacities, supply values, and costs), except for \ref CapacityScaling,
     421which is capable of handling real-valued arc costs (other numerical
     422data are required to be integer).
    413423*/
    414424
     
    449459
    450460This group contains the algorithms for finding minimum mean cycles
    451 \ref clrs01algorithms, \ref amo93networkflows.
     461\ref amo93networkflows, \ref karp78characterization.
    452462
    453463The \e minimum \e mean \e cycle \e problem is to find a directed cycle
     
    465475
    466476LEMON contains three algorithms for solving the minimum mean cycle problem:
    467 - \ref KarpMmc Karp's original algorithm \ref amo93networkflows,
    468   \ref dasdan98minmeancycle.
     477- \ref KarpMmc Karp's original algorithm \ref karp78characterization.
    469478- \ref HartmannOrlinMmc Hartmann-Orlin's algorithm, which is an improved
    470   version of Karp's algorithm \ref dasdan98minmeancycle.
     479  version of Karp's algorithm \ref hartmann93finding.
    471480- \ref HowardMmc Howard's policy iteration algorithm
    472   \ref dasdan98minmeancycle.
    473 
    474 In practice, the \ref HowardMmc "Howard" algorithm proved to be by far the
     481  \ref dasdan98minmeancycle, \ref dasdan04experimental.
     482
     483In practice, the \ref HowardMmc "Howard" algorithm turned out to be by far the
    475484most efficient one, though the best known theoretical bound on its running
    476485time is exponential.
     
    540549
    541550/**
    542 @defgroup planar Planarity Embedding and Drawing
     551@defgroup planar Planar Embedding and Drawing
    543552@ingroup algs
    544553\brief Algorithms for planarity checking, embedding and drawing
  • doc/lgf.dox

    r440 r1024  
    6464\endcode
    6565
     66The \e LGF files can also contain bipartite graphs, in this case a
     67\c @red_nodes and a \c @blue_nodes sections describe the node set of the
     68graph. If a map is in both of these sections, then it can be used as a
     69regular node map.
     70
     71\code
     72 @red_nodes
     73 label  only_red_map   name
     74 1      "cherry"       "John"
     75 2      "Santa Claus"  "Jack"
     76 3      "blood"        "Jason"
     77 @blue_nodes
     78 label  name
     79 4      "Elisabeth"
     80 5      "Eve"
     81\endcode
     82
    6683The \c \@arcs section is very similar to the \c \@nodes section,
    6784it again starts with a header line describing the names of the maps,
     
    7996\endcode
    8097
     98If there is no map in the \c \@arcs section at all, then it must be
     99indicated by a sole '-' sign in the first line.
     100
     101\code
     102 @arcs
     103         -
     104 1   2
     105 1   3
     106 2   3
     107\endcode
     108
    81109The \c \@edges is just a synonym of \c \@arcs. The \@arcs section can
    82110also store the edge set of an undirected graph. In such case there is
    83111a conventional method for store arc maps in the file, if two columns
    84 has the same caption with \c '+' and \c '-' prefix, then these columns
     112have the same caption with \c '+' and \c '-' prefix, then these columns
    85113can be regarded as the values of an arc map.
    86114
  • doc/min_cost_flow.dox

    r877 r1002  
    102102\f[ lower(uv) \leq f(uv) \leq upper(uv) \quad \forall uv\in A \f]
    103103
    104 However if the sum of the supply values is zero, then these two problems
     104However, if the sum of the supply values is zero, then these two problems
    105105are equivalent.
    106106The \ref min_cost_flow_algs "algorithms" in LEMON support the general
  • doc/references.bib

    r904 r1002  
    55  title =        {{LEMON} -- {L}ibrary for {E}fficient {M}odeling and
    66                  {O}ptimization in {N}etworks},
    7   howpublished = {\url{http://lemon.cs.elte.hu/}},
    8   year =         2009
     7  howpublished = {\url{http://lemon.cs.elte.hu/}}
    98}
    109
     
    212211  volume =       23,
    213212  pages =        {309-311}
     213}
     214
     215@article{hartmann93finding,
     216  author =       {Mark Hartmann and James B. Orlin},
     217  title =        {Finding minimum cost to time ratio cycles with small
     218                  integral transit times},
     219  journal =      {Networks},
     220  year =         1993,
     221  volume =       23,
     222  pages =        {567-574}
    214223}
    215224
     
    226235}
    227236
     237@article{dasdan04experimental,
     238  author =       {Ali Dasdan},
     239  title =        {Experimental analysis of the fastest optimum cycle
     240                  ratio and mean algorithms},
     241  journal =      {ACM Trans. Des. Autom. Electron. Syst.},
     242  year =         2004,
     243  volume =       9,
     244  issue =        4,
     245  pages =        {385-418}
     246}
     247
    228248
    229249%%%%% Minimum cost flow algorithms %%%%%
  • lemon/CMakeLists.txt

    r908 r981  
    55
    66CONFIGURE_FILE(
    7   ${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake
     7  ${CMAKE_CURRENT_SOURCE_DIR}/config.h.in
    88  ${CMAKE_CURRENT_BINARY_DIR}/config.h
    99)
    1010
    1111CONFIGURE_FILE(
    12   ${CMAKE_CURRENT_SOURCE_DIR}/lemon.pc.cmake
     12  ${CMAKE_CURRENT_SOURCE_DIR}/lemon.pc.in
    1313  ${CMAKE_CURRENT_BINARY_DIR}/lemon.pc
    1414  @ONLY
     
    5858  TARGETS lemon
    5959  ARCHIVE DESTINATION lib
     60  LIBRARY DESTINATION lib
    6061  COMPONENT library
    6162)
  • lemon/adaptors.h

    r877 r998  
    13721372    /// and edge filter maps.
    13731373    SubGraph(GR& graph, NF& node_filter, EF& edge_filter) {
    1374       initialize(graph, node_filter, edge_filter);
     1374      this->initialize(graph, node_filter, edge_filter);
    13751375    }
    13761376
     
    22782278    /// Creates an undirected graph from the given digraph.
    22792279    Undirector(DGR& digraph) {
    2280       initialize(digraph);
     2280      this->initialize(digraph);
    22812281    }
    22822282
  • lemon/bfs.h

    r877 r976  
    12521252      }
    12531253      _Visitor& visitor;
     1254      Constraints() {}
    12541255    };
    12551256  };
  • lemon/bits/alteration_notifier.h

    r440 r979  
    2424
    2525#include <lemon/core.h>
     26#include <lemon/bits/lock.h>
    2627
    2728//\ingroup graphbits
     
    252253    typedef std::list<ObserverBase*> Observers;
    253254    Observers _observers;
    254 
     255    lemon::bits::Lock _lock;
    255256
    256257  public:
     
    333334
    334335    void attach(ObserverBase& observer) {
     336      _lock.lock();
    335337      observer._index = _observers.insert(_observers.begin(), &observer);
    336338      observer._notifier = this;
     339      _lock.unlock();
    337340    }
    338341
    339342    void detach(ObserverBase& observer) {
     343      _lock.lock();
    340344      _observers.erase(observer._index);
    341345      observer._index = _observers.end();
    342346      observer._notifier = 0;
     347      _lock.unlock();
    343348    }
    344349
  • lemon/bits/bezier.h

    r440 r997  
    160160    const Point d=(a+b)/2;
    161161    const Point e=(b+c)/2;
    162     const Point f=(d+e)/2;
     162    // const Point f=(d+e)/2;
    163163    R f1=_f(Bezier3(p1,a,d,e),_d);
    164164    R f2=_f(Bezier3(e,d,c,p4),_d);
  • lemon/bits/edge_set_extender.h

    r884 r1000  
    524524    // Returns the base node of the iterator
    525525    Node baseNode(const IncEdgeIt &e) const {
    526       return e.direction ? u(e) : v(e);
     526      return e.direction ? this->u(e) : this->v(e);
    527527    }
    528528    // Running node of the iterator
     
    530530    // Returns the running node of the iterator
    531531    Node runningNode(const IncEdgeIt &e) const {
    532       return e.direction ? v(e) : u(e);
     532      return e.direction ? this->v(e) : this->u(e);
    533533    }
    534534
  • lemon/bits/graph_extender.h

    r778 r1027  
    588588    // Returns the base node of the iterator
    589589    Node baseNode(const IncEdgeIt &edge) const {
    590       return edge._direction ? u(edge) : v(edge);
     590      return edge._direction ? this->u(edge) : this->v(edge);
    591591    }
    592592    // Running node of the iterator
     
    594594    // Returns the running node of the iterator
    595595    Node runningNode(const IncEdgeIt &edge) const {
    596       return edge._direction ? v(edge) : u(edge);
     596      return edge._direction ? this->v(edge) : this->u(edge);
    597597    }
    598598
     
    747747  };
    748748
     749  // \ingroup _graphbits
     750  //
     751  // \brief Extender for the BpGraphs
     752  template <typename Base>
     753  class BpGraphExtender : public Base {
     754    typedef Base Parent;
     755
     756  public:
     757
     758    typedef BpGraphExtender BpGraph;
     759
     760    typedef True UndirectedTag;
     761
     762    typedef typename Parent::Node Node;
     763    typedef typename Parent::RedNode RedNode;
     764    typedef typename Parent::BlueNode BlueNode;
     765    typedef typename Parent::Arc Arc;
     766    typedef typename Parent::Edge Edge;
     767
     768    // BpGraph extension
     769
     770    using Parent::first;
     771    using Parent::next;
     772    using Parent::id;
     773
     774    int maxId(Node) const {
     775      return Parent::maxNodeId();
     776    }
     777
     778    int maxId(RedNode) const {
     779      return Parent::maxRedId();
     780    }
     781
     782    int maxId(BlueNode) const {
     783      return Parent::maxBlueId();
     784    }
     785
     786    int maxId(Arc) const {
     787      return Parent::maxArcId();
     788    }
     789
     790    int maxId(Edge) const {
     791      return Parent::maxEdgeId();
     792    }
     793
     794    static Node fromId(int id, Node) {
     795      return Parent::nodeFromId(id);
     796    }
     797
     798    static Arc fromId(int id, Arc) {
     799      return Parent::arcFromId(id);
     800    }
     801
     802    static Edge fromId(int id, Edge) {
     803      return Parent::edgeFromId(id);
     804    }
     805
     806    Node u(Edge e) const { return this->redNode(e); }
     807    Node v(Edge e) const { return this->blueNode(e); }
     808
     809    Node oppositeNode(const Node &n, const Edge &e) const {
     810      if( n == u(e))
     811        return v(e);
     812      else if( n == v(e))
     813        return u(e);
     814      else
     815        return INVALID;
     816    }
     817
     818    Arc oppositeArc(const Arc &arc) const {
     819      return Parent::direct(arc, !Parent::direction(arc));
     820    }
     821
     822    using Parent::direct;
     823    Arc direct(const Edge &edge, const Node &node) const {
     824      return Parent::direct(edge, Parent::redNode(edge) == node);
     825    }
     826
     827    RedNode asRedNode(const Node& node) const {
     828      if (node == INVALID || Parent::blue(node)) {
     829        return INVALID;
     830      } else {
     831        return Parent::asRedNodeUnsafe(node);
     832      }
     833    }
     834
     835    BlueNode asBlueNode(const Node& node) const {
     836      if (node == INVALID || Parent::red(node)) {
     837        return INVALID;
     838      } else {
     839        return Parent::asBlueNodeUnsafe(node);
     840      }
     841    }
     842
     843    // Alterable extension
     844
     845    typedef AlterationNotifier<BpGraphExtender, Node> NodeNotifier;
     846    typedef AlterationNotifier<BpGraphExtender, RedNode> RedNodeNotifier;
     847    typedef AlterationNotifier<BpGraphExtender, BlueNode> BlueNodeNotifier;
     848    typedef AlterationNotifier<BpGraphExtender, Arc> ArcNotifier;
     849    typedef AlterationNotifier<BpGraphExtender, Edge> EdgeNotifier;
     850
     851
     852  protected:
     853
     854    mutable NodeNotifier node_notifier;
     855    mutable RedNodeNotifier red_node_notifier;
     856    mutable BlueNodeNotifier blue_node_notifier;
     857    mutable ArcNotifier arc_notifier;
     858    mutable EdgeNotifier edge_notifier;
     859
     860  public:
     861
     862    NodeNotifier& notifier(Node) const {
     863      return node_notifier;
     864    }
     865
     866    RedNodeNotifier& notifier(RedNode) const {
     867      return red_node_notifier;
     868    }
     869
     870    BlueNodeNotifier& notifier(BlueNode) const {
     871      return blue_node_notifier;
     872    }
     873
     874    ArcNotifier& notifier(Arc) const {
     875      return arc_notifier;
     876    }
     877
     878    EdgeNotifier& notifier(Edge) const {
     879      return edge_notifier;
     880    }
     881
     882
     883
     884    class NodeIt : public Node {
     885      const BpGraph* _graph;
     886    public:
     887
     888      NodeIt() {}
     889
     890      NodeIt(Invalid i) : Node(i) { }
     891
     892      explicit NodeIt(const BpGraph& graph) : _graph(&graph) {
     893        _graph->first(static_cast<Node&>(*this));
     894      }
     895
     896      NodeIt(const BpGraph& graph, const Node& node)
     897        : Node(node), _graph(&graph) {}
     898
     899      NodeIt& operator++() {
     900        _graph->next(*this);
     901        return *this;
     902      }
     903
     904    };
     905
     906    class RedNodeIt : public RedNode {
     907      const BpGraph* _graph;
     908    public:
     909
     910      RedNodeIt() {}
     911
     912      RedNodeIt(Invalid i) : RedNode(i) { }
     913
     914      explicit RedNodeIt(const BpGraph& graph) : _graph(&graph) {
     915        _graph->first(static_cast<RedNode&>(*this));
     916      }
     917
     918      RedNodeIt(const BpGraph& graph, const RedNode& node)
     919        : RedNode(node), _graph(&graph) {}
     920
     921      RedNodeIt& operator++() {
     922        _graph->next(static_cast<RedNode&>(*this));
     923        return *this;
     924      }
     925
     926    };
     927
     928    class BlueNodeIt : public BlueNode {
     929      const BpGraph* _graph;
     930    public:
     931
     932      BlueNodeIt() {}
     933
     934      BlueNodeIt(Invalid i) : BlueNode(i) { }
     935
     936      explicit BlueNodeIt(const BpGraph& graph) : _graph(&graph) {
     937        _graph->first(static_cast<BlueNode&>(*this));
     938      }
     939
     940      BlueNodeIt(const BpGraph& graph, const BlueNode& node)
     941        : BlueNode(node), _graph(&graph) {}
     942
     943      BlueNodeIt& operator++() {
     944        _graph->next(static_cast<BlueNode&>(*this));
     945        return *this;
     946      }
     947
     948    };
     949
     950
     951    class ArcIt : public Arc {
     952      const BpGraph* _graph;
     953    public:
     954
     955      ArcIt() { }
     956
     957      ArcIt(Invalid i) : Arc(i) { }
     958
     959      explicit ArcIt(const BpGraph& graph) : _graph(&graph) {
     960        _graph->first(static_cast<Arc&>(*this));
     961      }
     962
     963      ArcIt(const BpGraph& graph, const Arc& arc) :
     964        Arc(arc), _graph(&graph) { }
     965
     966      ArcIt& operator++() {
     967        _graph->next(*this);
     968        return *this;
     969      }
     970
     971    };
     972
     973
     974    class OutArcIt : public Arc {
     975      const BpGraph* _graph;
     976    public:
     977
     978      OutArcIt() { }
     979
     980      OutArcIt(Invalid i) : Arc(i) { }
     981
     982      OutArcIt(const BpGraph& graph, const Node& node)
     983        : _graph(&graph) {
     984        _graph->firstOut(*this, node);
     985      }
     986
     987      OutArcIt(const BpGraph& graph, const Arc& arc)
     988        : Arc(arc), _graph(&graph) {}
     989
     990      OutArcIt& operator++() {
     991        _graph->nextOut(*this);
     992        return *this;
     993      }
     994
     995    };
     996
     997
     998    class InArcIt : public Arc {
     999      const BpGraph* _graph;
     1000    public:
     1001
     1002      InArcIt() { }
     1003
     1004      InArcIt(Invalid i) : Arc(i) { }
     1005
     1006      InArcIt(const BpGraph& graph, const Node& node)
     1007        : _graph(&graph) {
     1008        _graph->firstIn(*this, node);
     1009      }
     1010
     1011      InArcIt(const BpGraph& graph, const Arc& arc) :
     1012        Arc(arc), _graph(&graph) {}
     1013
     1014      InArcIt& operator++() {
     1015        _graph->nextIn(*this);
     1016        return *this;
     1017      }
     1018
     1019    };
     1020
     1021
     1022    class EdgeIt : public Parent::Edge {
     1023      const BpGraph* _graph;
     1024    public:
     1025
     1026      EdgeIt() { }
     1027
     1028      EdgeIt(Invalid i) : Edge(i) { }
     1029
     1030      explicit EdgeIt(const BpGraph& graph) : _graph(&graph) {
     1031        _graph->first(static_cast<Edge&>(*this));
     1032      }
     1033
     1034      EdgeIt(const BpGraph& graph, const Edge& edge) :
     1035        Edge(edge), _graph(&graph) { }
     1036
     1037      EdgeIt& operator++() {
     1038        _graph->next(*this);
     1039        return *this;
     1040      }
     1041
     1042    };
     1043
     1044    class IncEdgeIt : public Parent::Edge {
     1045      friend class BpGraphExtender;
     1046      const BpGraph* _graph;
     1047      bool _direction;
     1048    public:
     1049
     1050      IncEdgeIt() { }
     1051
     1052      IncEdgeIt(Invalid i) : Edge(i), _direction(false) { }
     1053
     1054      IncEdgeIt(const BpGraph& graph, const Node &node) : _graph(&graph) {
     1055        _graph->firstInc(*this, _direction, node);
     1056      }
     1057
     1058      IncEdgeIt(const BpGraph& graph, const Edge &edge, const Node &node)
     1059        : _graph(&graph), Edge(edge) {
     1060        _direction = (_graph->source(edge) == node);
     1061      }
     1062
     1063      IncEdgeIt& operator++() {
     1064        _graph->nextInc(*this, _direction);
     1065        return *this;
     1066      }
     1067    };
     1068
     1069    // \brief Base node of the iterator
     1070    //
     1071    // Returns the base node (ie. the source in this case) of the iterator
     1072    Node baseNode(const OutArcIt &arc) const {
     1073      return Parent::source(static_cast<const Arc&>(arc));
     1074    }
     1075    // \brief Running node of the iterator
     1076    //
     1077    // Returns the running node (ie. the target in this case) of the
     1078    // iterator
     1079    Node runningNode(const OutArcIt &arc) const {
     1080      return Parent::target(static_cast<const Arc&>(arc));
     1081    }
     1082
     1083    // \brief Base node of the iterator
     1084    //
     1085    // Returns the base node (ie. the target in this case) of the iterator
     1086    Node baseNode(const InArcIt &arc) const {
     1087      return Parent::target(static_cast<const Arc&>(arc));
     1088    }
     1089    // \brief Running node of the iterator
     1090    //
     1091    // Returns the running node (ie. the source in this case) of the
     1092    // iterator
     1093    Node runningNode(const InArcIt &arc) const {
     1094      return Parent::source(static_cast<const Arc&>(arc));
     1095    }
     1096
     1097    // Base node of the iterator
     1098    //
     1099    // Returns the base node of the iterator
     1100    Node baseNode(const IncEdgeIt &edge) const {
     1101      return edge._direction ? this->u(edge) : this->v(edge);
     1102    }
     1103    // Running node of the iterator
     1104    //
     1105    // Returns the running node of the iterator
     1106    Node runningNode(const IncEdgeIt &edge) const {
     1107      return edge._direction ? this->v(edge) : this->u(edge);
     1108    }
     1109
     1110    // Mappable extension
     1111
     1112    template <typename _Value>
     1113    class NodeMap
     1114      : public MapExtender<DefaultMap<BpGraph, Node, _Value> > {
     1115      typedef MapExtender<DefaultMap<BpGraph, Node, _Value> > Parent;
     1116
     1117    public:
     1118      explicit NodeMap(const BpGraph& bpgraph)
     1119        : Parent(bpgraph) {}
     1120      NodeMap(const BpGraph& bpgraph, const _Value& value)
     1121        : Parent(bpgraph, value) {}
     1122
     1123    private:
     1124      NodeMap& operator=(const NodeMap& cmap) {
     1125        return operator=<NodeMap>(cmap);
     1126      }
     1127
     1128      template <typename CMap>
     1129      NodeMap& operator=(const CMap& cmap) {
     1130        Parent::operator=(cmap);
     1131        return *this;
     1132      }
     1133
     1134    };
     1135
     1136    template <typename _Value>
     1137    class RedNodeMap
     1138      : public MapExtender<DefaultMap<BpGraph, RedNode, _Value> > {
     1139      typedef MapExtender<DefaultMap<BpGraph, RedNode, _Value> > Parent;
     1140
     1141    public:
     1142      explicit RedNodeMap(const BpGraph& bpgraph)
     1143        : Parent(bpgraph) {}
     1144      RedNodeMap(const BpGraph& bpgraph, const _Value& value)
     1145        : Parent(bpgraph, value) {}
     1146
     1147    private:
     1148      RedNodeMap& operator=(const RedNodeMap& cmap) {
     1149        return operator=<RedNodeMap>(cmap);
     1150      }
     1151
     1152      template <typename CMap>
     1153      RedNodeMap& operator=(const CMap& cmap) {
     1154        Parent::operator=(cmap);
     1155        return *this;
     1156      }
     1157
     1158    };
     1159
     1160    template <typename _Value>
     1161    class BlueNodeMap
     1162      : public MapExtender<DefaultMap<BpGraph, BlueNode, _Value> > {
     1163      typedef MapExtender<DefaultMap<BpGraph, BlueNode, _Value> > Parent;
     1164
     1165    public:
     1166      explicit BlueNodeMap(const BpGraph& bpgraph)
     1167        : Parent(bpgraph) {}
     1168      BlueNodeMap(const BpGraph& bpgraph, const _Value& value)
     1169        : Parent(bpgraph, value) {}
     1170
     1171    private:
     1172      BlueNodeMap& operator=(const BlueNodeMap& cmap) {
     1173        return operator=<BlueNodeMap>(cmap);
     1174      }
     1175
     1176      template <typename CMap>
     1177      BlueNodeMap& operator=(const CMap& cmap) {
     1178        Parent::operator=(cmap);
     1179        return *this;
     1180      }
     1181
     1182    };
     1183
     1184    template <typename _Value>
     1185    class ArcMap
     1186      : public MapExtender<DefaultMap<BpGraph, Arc, _Value> > {
     1187      typedef MapExtender<DefaultMap<BpGraph, Arc, _Value> > Parent;
     1188
     1189    public:
     1190      explicit ArcMap(const BpGraph& graph)
     1191        : Parent(graph) {}
     1192      ArcMap(const BpGraph& graph, const _Value& value)
     1193        : Parent(graph, value) {}
     1194
     1195    private:
     1196      ArcMap& operator=(const ArcMap& cmap) {
     1197        return operator=<ArcMap>(cmap);
     1198      }
     1199
     1200      template <typename CMap>
     1201      ArcMap& operator=(const CMap& cmap) {
     1202        Parent::operator=(cmap);
     1203        return *this;
     1204      }
     1205    };
     1206
     1207
     1208    template <typename _Value>
     1209    class EdgeMap
     1210      : public MapExtender<DefaultMap<BpGraph, Edge, _Value> > {
     1211      typedef MapExtender<DefaultMap<BpGraph, Edge, _Value> > Parent;
     1212
     1213    public:
     1214      explicit EdgeMap(const BpGraph& graph)
     1215        : Parent(graph) {}
     1216
     1217      EdgeMap(const BpGraph& graph, const _Value& value)
     1218        : Parent(graph, value) {}
     1219
     1220    private:
     1221      EdgeMap& operator=(const EdgeMap& cmap) {
     1222        return operator=<EdgeMap>(cmap);
     1223      }
     1224
     1225      template <typename CMap>
     1226      EdgeMap& operator=(const CMap& cmap) {
     1227        Parent::operator=(cmap);
     1228        return *this;
     1229      }
     1230
     1231    };
     1232
     1233    // Alteration extension
     1234
     1235    RedNode addRedNode() {
     1236      RedNode node = Parent::addRedNode();
     1237      notifier(RedNode()).add(node);
     1238      notifier(Node()).add(node);
     1239      return node;
     1240    }
     1241
     1242    BlueNode addBlueNode() {
     1243      BlueNode node = Parent::addBlueNode();
     1244      notifier(BlueNode()).add(node);
     1245      notifier(Node()).add(node);
     1246      return node;
     1247    }
     1248
     1249    Edge addEdge(const RedNode& from, const BlueNode& to) {
     1250      Edge edge = Parent::addEdge(from, to);
     1251      notifier(Edge()).add(edge);
     1252      std::vector<Arc> av;
     1253      av.push_back(Parent::direct(edge, true));
     1254      av.push_back(Parent::direct(edge, false));
     1255      notifier(Arc()).add(av);
     1256      return edge;
     1257    }
     1258
     1259    void clear() {
     1260      notifier(Arc()).clear();
     1261      notifier(Edge()).clear();
     1262      notifier(Node()).clear();
     1263      notifier(BlueNode()).clear();
     1264      notifier(RedNode()).clear();
     1265      Parent::clear();
     1266    }
     1267
     1268    template <typename BpGraph, typename NodeRefMap, typename EdgeRefMap>
     1269    void build(const BpGraph& graph, NodeRefMap& nodeRef,
     1270               EdgeRefMap& edgeRef) {
     1271      Parent::build(graph, nodeRef, edgeRef);
     1272      notifier(RedNode()).build();
     1273      notifier(BlueNode()).build();
     1274      notifier(Node()).build();
     1275      notifier(Edge()).build();
     1276      notifier(Arc()).build();
     1277    }
     1278
     1279    void erase(const Node& node) {
     1280      Arc arc;
     1281      Parent::firstOut(arc, node);
     1282      while (arc != INVALID ) {
     1283        erase(arc);
     1284        Parent::firstOut(arc, node);
     1285      }
     1286
     1287      Parent::firstIn(arc, node);
     1288      while (arc != INVALID ) {
     1289        erase(arc);
     1290        Parent::firstIn(arc, node);
     1291      }
     1292
     1293      if (Parent::red(node)) {
     1294        notifier(RedNode()).erase(this->asRedNodeUnsafe(node));
     1295      } else {
     1296        notifier(BlueNode()).erase(this->asBlueNodeUnsafe(node));
     1297      }
     1298
     1299      notifier(Node()).erase(node);
     1300      Parent::erase(node);
     1301    }
     1302
     1303    void erase(const Edge& edge) {
     1304      std::vector<Arc> av;
     1305      av.push_back(Parent::direct(edge, true));
     1306      av.push_back(Parent::direct(edge, false));
     1307      notifier(Arc()).erase(av);
     1308      notifier(Edge()).erase(edge);
     1309      Parent::erase(edge);
     1310    }
     1311
     1312    BpGraphExtender() {
     1313      red_node_notifier.setContainer(*this);
     1314      blue_node_notifier.setContainer(*this);
     1315      node_notifier.setContainer(*this);
     1316      arc_notifier.setContainer(*this);
     1317      edge_notifier.setContainer(*this);
     1318    }
     1319
     1320    ~BpGraphExtender() {
     1321      edge_notifier.clear();
     1322      arc_notifier.clear();
     1323      node_notifier.clear();
     1324      blue_node_notifier.clear();
     1325      red_node_notifier.clear();
     1326    }
     1327
     1328  };
     1329
    7491330}
    7501331
  • lemon/bits/solver_bits.h

    r877 r989  
    4545      void clear() {
    4646        first_item = -1;
     47        last_item = -1;
    4748        first_free_item = -1;
    4849        items.clear();
  • lemon/bits/traits.h

    r616 r1026  
    149149        : Parent(_digraph, _value) {}
    150150    };
     151
     152  };
     153
     154  template <typename GR, typename Enable = void>
     155  struct RedNodeNotifierIndicator {
     156    typedef InvalidType Type;
     157  };
     158  template <typename GR>
     159  struct RedNodeNotifierIndicator<
     160    GR,
     161    typename enable_if<typename GR::RedNodeNotifier::Notifier, void>::type
     162  > {
     163    typedef typename GR::RedNodeNotifier Type;
     164  };
     165
     166  template <typename GR>
     167  class ItemSetTraits<GR, typename GR::RedNode> {
     168  public:
     169
     170    typedef GR BpGraph;
     171    typedef GR Graph;
     172    typedef GR Digraph;
     173
     174    typedef typename GR::RedNode Item;
     175    typedef typename GR::RedNodeIt ItemIt;
     176
     177    typedef typename RedNodeNotifierIndicator<GR>::Type ItemNotifier;
     178
     179    template <typename V>
     180    class Map : public GR::template RedNodeMap<V> {
     181      typedef typename GR::template RedNodeMap<V> Parent;
     182
     183    public:
     184      typedef typename GR::template RedNodeMap<V> Type;
     185      typedef typename Parent::Value Value;
     186
     187      Map(const GR& _bpgraph) : Parent(_bpgraph) {}
     188      Map(const GR& _bpgraph, const Value& _value)
     189        : Parent(_bpgraph, _value) {}
     190
     191     };
     192
     193  };
     194
     195  template <typename GR, typename Enable = void>
     196  struct BlueNodeNotifierIndicator {
     197    typedef InvalidType Type;
     198  };
     199  template <typename GR>
     200  struct BlueNodeNotifierIndicator<
     201    GR,
     202    typename enable_if<typename GR::BlueNodeNotifier::Notifier, void>::type
     203  > {
     204    typedef typename GR::BlueNodeNotifier Type;
     205  };
     206
     207  template <typename GR>
     208  class ItemSetTraits<GR, typename GR::BlueNode> {
     209  public:
     210
     211    typedef GR BpGraph;
     212    typedef GR Graph;
     213    typedef GR Digraph;
     214
     215    typedef typename GR::BlueNode Item;
     216    typedef typename GR::BlueNodeIt ItemIt;
     217
     218    typedef typename BlueNodeNotifierIndicator<GR>::Type ItemNotifier;
     219
     220    template <typename V>
     221    class Map : public GR::template BlueNodeMap<V> {
     222      typedef typename GR::template BlueNodeMap<V> Parent;
     223
     224    public:
     225      typedef typename GR::template BlueNodeMap<V> Type;
     226      typedef typename Parent::Value Value;
     227
     228      Map(const GR& _bpgraph) : Parent(_bpgraph) {}
     229      Map(const GR& _bpgraph, const Value& _value)
     230        : Parent(_bpgraph, _value) {}
     231
     232     };
    151233
    152234  };
  • lemon/bits/windows.cc

    r877 r1001  
    4141#include <unistd.h>
    4242#include <ctime>
     43#ifndef WIN32
    4344#include <sys/times.h>
     45#endif
    4446#include <sys/time.h>
    4547#endif
     
    129131#endif
    130132    }
     133
     134    WinLock::WinLock() {
     135#ifdef WIN32
     136      CRITICAL_SECTION *lock = new CRITICAL_SECTION;
     137      InitializeCriticalSection(lock);
     138      _repr = lock;
     139#else
     140      _repr = 0; //Just to avoid 'unused variable' warning with clang
     141#endif
     142    }
     143   
     144    WinLock::~WinLock() {
     145#ifdef WIN32
     146      CRITICAL_SECTION *lock = static_cast<CRITICAL_SECTION*>(_repr);
     147      DeleteCriticalSection(lock);
     148      delete lock;
     149#endif
     150    }
     151
     152    void WinLock::lock() {
     153#ifdef WIN32
     154      CRITICAL_SECTION *lock = static_cast<CRITICAL_SECTION*>(_repr);
     155      EnterCriticalSection(lock);
     156#endif
     157    }
     158
     159    void WinLock::unlock() {
     160#ifdef WIN32
     161      CRITICAL_SECTION *lock = static_cast<CRITICAL_SECTION*>(_repr);
     162      LeaveCriticalSection(lock);
     163#endif
     164    }
    131165  }
    132166}
  • lemon/bits/windows.h

    r529 r979  
    2929    std::string getWinFormattedDate();
    3030    int getWinRndSeed();
     31
     32    class WinLock {
     33    public:
     34      WinLock();
     35      ~WinLock();
     36      void lock();
     37      void unlock();
     38    private:
     39      void *_repr;
     40    };
    3141  }
    3242}
  • lemon/capacity_scaling.h

    r877 r1004  
    7171  /// solution method.
    7272  ///
     73  /// This algorithm is typically slower than \ref CostScaling and
     74  /// \ref NetworkSimplex, but in special cases, it can be more
     75  /// efficient than them.
     76  /// (For more information, see \ref min_cost_flow_algs "the module page".)
     77  ///
    7378  /// Most of the parameters of the problem (except for the digraph)
    7479  /// can be given using separate functions, and the algorithm can be
     
    8792  /// consider to use the named template parameters instead.
    8893  ///
    89   /// \warning Both number types must be signed and all input data must
    90   /// be integer.
    91   /// \warning This algorithm does not support negative costs for such
    92   /// arcs that have infinite upper bound.
     94  /// \warning Both \c V and \c C must be signed number types.
     95  /// \warning Capacity bounds and supply values must be integer, but
     96  /// arc costs can be arbitrary real numbers.
     97  /// \warning This algorithm does not support negative costs for
     98  /// arcs having infinite upper bound.
    9399#ifdef DOXYGEN
    94100  template <typename GR, typename V, typename C, typename TR>
     
    423429    ///
    424430    /// Using this function has the same effect as using \ref supplyMap()
    425     /// with such a map in which \c k is assigned to \c s, \c -k is
     431    /// with a map in which \c k is assigned to \c s, \c -k is
    426432    /// assigned to \c t and all other nodes have zero supply value.
    427433    ///
     
    676682    }
    677683
    678     /// \brief Return the flow map (the primal solution).
     684    /// \brief Copy the flow values (the primal solution) into the
     685    /// given map.
    679686    ///
    680687    /// This function copies the flow value on each arc into the given
     
    700707    }
    701708
    702     /// \brief Return the potential map (the dual solution).
     709    /// \brief Copy the potential values (the dual solution) into the
     710    /// given map.
    703711    ///
    704712    /// This function copies the potential (dual value) of each node
  • lemon/cbc.cc

    r746 r1000  
    2626#include <coin/OsiSolverInterface.hpp>
    2727
    28 #ifdef COIN_HAS_CLP
    2928#include "coin/OsiClpSolverInterface.hpp"
    30 #endif
    31 #ifdef COIN_HAS_OSL
    32 #include "coin/OsiOslSolverInterface.hpp"
    33 #endif
    3429
    3530#include "coin/CbcCutGenerator.hpp"
     
    271266      delete _osi_solver;
    272267    }
    273 #ifdef COIN_HAS_CLP
    274268    _osi_solver = new OsiClpSolverInterface();
    275 #elif COIN_HAS_OSL
    276     _osi_solver = new OsiOslSolverInterface();
    277 #else
    278 #error Cannot instantiate Osi solver
    279 #endif
    280269
    281270    _osi_solver->loadFromCoinModel(*_prob);
     
    329318      _cbc_model->addCutGenerator(&flowGen, -1, "FlowCover");
    330319
    331 #ifdef COIN_HAS_CLP
    332320      OsiClpSolverInterface* osiclp =
    333321        dynamic_cast<OsiClpSolverInterface*>(_cbc_model->solver());
     
    335323        osiclp->setupForRepeatedUse(2, 0);
    336324      }
    337 #endif
    338325
    339326      CbcRounding heuristic1(*_cbc_model);
     
    449436
    450437    _prob = new CoinModel();
    451     rows.clear();
    452     cols.clear();
    453438  }
    454439
  • lemon/circulation.h

    r877 r998  
    573573
    574574      Node act;
    575       Node bact=INVALID;
    576       Node last_activated=INVALID;
    577575      while((act=_level->highestActive())!=INVALID) {
    578576        int actlevel=(*_level)[act];
  • lemon/clp.cc

    r877 r989  
    438438    delete _prob;
    439439    _prob = new ClpSimplex();
    440     rows.clear();
    441     cols.clear();
    442440    _col_names_ref.clear();
    443441    _clear_temporals();
  • lemon/concept_check.h

    r440 r997  
    3636
    3737  template <class T> inline void ignore_unused_variable_warning(const T&) { }
     38  template <class T1, class T2>
     39  inline void ignore_unused_variable_warning(const T1&, const T2&) { }
     40  template <class T1, class T2, class T3>
     41  inline void ignore_unused_variable_warning(const T1&, const T2&,
     42                                             const T3&) { }
     43  template <class T1, class T2, class T3, class T4>
     44  inline void ignore_unused_variable_warning(const T1&, const T2&,
     45                                             const T3&, const T4&) { }
     46  template <class T1, class T2, class T3, class T4, class T5>
     47  inline void ignore_unused_variable_warning(const T1&, const T2&,
     48                                             const T3&, const T4&,
     49                                             const T5&) { }
     50  template <class T1, class T2, class T3, class T4, class T5, class T6>
     51  inline void ignore_unused_variable_warning(const T1&, const T2&,
     52                                             const T3&, const T4&,
     53                                             const T5&, const T6&) { }
    3854
    3955  ///\e
  • lemon/concepts/graph.h

    r877 r1018  
    7373    class Graph {
    7474    private:
    75       /// Graphs are \e not copy constructible. Use DigraphCopy instead.
     75      /// Graphs are \e not copy constructible. Use GraphCopy instead.
    7676      Graph(const Graph&) {}
    7777      /// \brief Assignment of a graph to another one is \e not allowed.
    78       /// Use DigraphCopy instead.
     78      /// Use GraphCopy instead.
    7979      void operator=(const Graph&) {}
    8080
  • lemon/concepts/graph_components.h

    r877 r1028  
    109109
    110110          bool b;
     111          ignore_unused_variable_warning(b);
     112
    111113          b = (ia == ib) && (ia != ib);
    112114          b = (ia == INVALID) && (ib != INVALID);
     
    116118        const _GraphItem &ia;
    117119        const _GraphItem &ib;
     120        Constraints() {}
    118121      };
    119122    };
     
    175178
    176179        const _Digraph& digraph;
     180        Constraints() {}
    177181      };
    178182    };
     
    291295
    292296        const _Graph& graph;
     297      Constraints() {}
     298      };
     299
     300    };
     301
     302    /// \brief Base skeleton class for undirected bipartite graphs.
     303    ///
     304    /// This class describes the base interface of undirected
     305    /// bipartite graph types.  All bipartite graph %concepts have to
     306    /// conform to this class.  It extends the interface of \ref
     307    /// BaseGraphComponent with an \c Edge type and functions to get
     308    /// the end nodes of edges, to convert from arcs to edges and to
     309    /// get both direction of edges.
     310    class BaseBpGraphComponent : public BaseGraphComponent {
     311    public:
     312
     313      typedef BaseBpGraphComponent BpGraph;
     314
     315      typedef BaseDigraphComponent::Node Node;
     316      typedef BaseDigraphComponent::Arc Arc;
     317
     318      /// \brief Class to represent red nodes.
     319      ///
     320      /// This class represents the red nodes of the graph. The red
     321      /// nodes can also be used as normal nodes.
     322      class RedNode : public Node {
     323        typedef Node Parent;
     324
     325      public:
     326        /// \brief Default constructor.
     327        ///
     328        /// Default constructor.
     329        /// \warning The default constructor is not required to set
     330        /// the item to some well-defined value. So you should consider it
     331        /// as uninitialized.
     332        RedNode() {}
     333
     334        /// \brief Copy constructor.
     335        ///
     336        /// Copy constructor.
     337        RedNode(const RedNode &) : Parent() {}
     338
     339        /// \brief Constructor for conversion from \c INVALID.
     340        ///
     341        /// Constructor for conversion from \c INVALID.
     342        /// It initializes the item to be invalid.
     343        /// \sa Invalid for more details.
     344        RedNode(Invalid) {}
     345      };
     346
     347      /// \brief Class to represent blue nodes.
     348      ///
     349      /// This class represents the blue nodes of the graph. The blue
     350      /// nodes can also be used as normal nodes.
     351      class BlueNode : public Node {
     352        typedef Node Parent;
     353
     354      public:
     355        /// \brief Default constructor.
     356        ///
     357        /// Default constructor.
     358        /// \warning The default constructor is not required to set
     359        /// the item to some well-defined value. So you should consider it
     360        /// as uninitialized.
     361        BlueNode() {}
     362
     363        /// \brief Copy constructor.
     364        ///
     365        /// Copy constructor.
     366        BlueNode(const BlueNode &) : Parent() {}
     367
     368        /// \brief Constructor for conversion from \c INVALID.
     369        ///
     370        /// Constructor for conversion from \c INVALID.
     371        /// It initializes the item to be invalid.
     372        /// \sa Invalid for more details.
     373        BlueNode(Invalid) {}
     374
     375        /// \brief Constructor for conversion from a node.
     376        ///
     377        /// Constructor for conversion from a node. The conversion can
     378        /// be invalid, since the Node can be member of the red
     379        /// set.
     380        BlueNode(const Node&) {}
     381      };
     382
     383      /// \brief Gives back %true for red nodes.
     384      ///
     385      /// Gives back %true for red nodes.
     386      bool red(const Node&) const { return true; }
     387
     388      /// \brief Gives back %true for blue nodes.
     389      ///
     390      /// Gives back %true for blue nodes.
     391      bool blue(const Node&) const { return true; }
     392
     393      /// \brief Gives back the red end node of the edge.
     394      ///
     395      /// Gives back the red end node of the edge.
     396      RedNode redNode(const Edge&) const { return RedNode(); }
     397
     398      /// \brief Gives back the blue end node of the edge.
     399      ///
     400      /// Gives back the blue end node of the edge.
     401      BlueNode blueNode(const Edge&) const { return BlueNode(); }
     402
     403      /// \brief Converts the node to red node object.
     404      ///
     405      /// This function converts unsafely the node to red node
     406      /// object. It should be called only if the node is from the red
     407      /// partition or INVALID.
     408      RedNode asRedNodeUnsafe(const Node&) const { return RedNode(); }
     409
     410      /// \brief Converts the node to blue node object.
     411      ///
     412      /// This function converts unsafely the node to blue node
     413      /// object. It should be called only if the node is from the red
     414      /// partition or INVALID.
     415      BlueNode asBlueNodeUnsafe(const Node&) const { return BlueNode(); }
     416
     417      /// \brief Converts the node to red node object.
     418      ///
     419      /// This function converts safely the node to red node
     420      /// object. If the node is not from the red partition, then it
     421      /// returns INVALID.
     422      RedNode asRedNode(const Node&) const { return RedNode(); }
     423
     424      /// \brief Converts the node to blue node object.
     425      ///
     426      /// This function converts unsafely the node to blue node
     427      /// object. If the node is not from the blue partition, then it
     428      /// returns INVALID.
     429      BlueNode asBlueNode(const Node&) const { return BlueNode(); }
     430
     431      template <typename _BpGraph>
     432      struct Constraints {
     433        typedef typename _BpGraph::Node Node;
     434        typedef typename _BpGraph::RedNode RedNode;
     435        typedef typename _BpGraph::BlueNode BlueNode;
     436        typedef typename _BpGraph::Arc Arc;
     437        typedef typename _BpGraph::Edge Edge;
     438
     439        void constraints() {
     440          checkConcept<BaseGraphComponent, _BpGraph>();
     441          checkConcept<GraphItem<'n'>, RedNode>();
     442          checkConcept<GraphItem<'n'>, BlueNode>();
     443          {
     444            Node n;
     445            RedNode rn;
     446            BlueNode bn;
     447            Node rnan = rn;
     448            Node bnan = bn;
     449            Edge e;
     450            bool b;
     451            b = bpgraph.red(rnan);
     452            b = bpgraph.blue(bnan);
     453            rn = bpgraph.redNode(e);
     454            bn = bpgraph.blueNode(e);
     455            rn = bpgraph.asRedNodeUnsafe(rnan);
     456            bn = bpgraph.asBlueNodeUnsafe(bnan);
     457            rn = bpgraph.asRedNode(rnan);
     458            bn = bpgraph.asBlueNode(bnan);
     459            ignore_unused_variable_warning(b);
     460          }
     461        }
     462
     463        const _BpGraph& bpgraph;
    293464      };
    294465
     
    370541
    371542        const _Digraph& digraph;
     543        Constraints() {}
    372544      };
    373545    };
     
    422594
    423595        const _Graph& graph;
     596        Constraints() {}
     597      };
     598    };
     599
     600    /// \brief Skeleton class for \e idable undirected bipartite graphs.
     601    ///
     602    /// This class describes the interface of \e idable undirected
     603    /// bipartite graphs. It extends \ref IDableGraphComponent with
     604    /// the core ID functions of undirected bipartite graphs. Beside
     605    /// the regular node ids, this class also provides ids within the
     606    /// the red and blue sets of the nodes. This concept is part of
     607    /// the BpGraph concept.
     608    template <typename BAS = BaseBpGraphComponent>
     609    class IDableBpGraphComponent : public IDableGraphComponent<BAS> {
     610    public:
     611
     612      typedef BAS Base;
     613      typedef IDableGraphComponent<BAS> Parent;
     614      typedef typename Base::Node Node;
     615      typedef typename Base::RedNode RedNode;
     616      typedef typename Base::BlueNode BlueNode;
     617
     618      using Parent::id;
     619
     620      /// \brief Return a unique integer id for the given node in the red set.
     621      ///
     622      /// Return a unique integer id for the given node in the red set.
     623      int id(const RedNode&) const { return -1; }
     624
     625      /// \brief Return a unique integer id for the given node in the blue set.
     626      ///
     627      /// Return a unique integer id for the given node in the blue set.
     628      int id(const BlueNode&) const { return -1; }
     629
     630      /// \brief Return an integer greater or equal to the maximum
     631      /// node id in the red set.
     632      ///
     633      /// Return an integer greater or equal to the maximum
     634      /// node id in the red set.
     635      int maxRedId() const { return -1; }
     636
     637      /// \brief Return an integer greater or equal to the maximum
     638      /// node id in the blue set.
     639      ///
     640      /// Return an integer greater or equal to the maximum
     641      /// node id in the blue set.
     642      int maxBlueId() const { return -1; }
     643
     644      template <typename _BpGraph>
     645      struct Constraints {
     646
     647        void constraints() {
     648          checkConcept<IDableGraphComponent<Base>, _BpGraph>();
     649          typename _BpGraph::Node node;
     650          typename _BpGraph::RedNode red;
     651          typename _BpGraph::BlueNode blue;
     652          int rid = bpgraph.id(red);
     653          int bid = bpgraph.id(blue);
     654          rid = bpgraph.maxRedId();
     655          bid = bpgraph.maxBlueId();
     656          ignore_unused_variable_warning(rid);
     657          ignore_unused_variable_warning(bid);
     658        }
     659
     660        const _BpGraph& bpgraph;
    424661      };
    425662    };
     
    490727          _GraphItemIt it3 = it1;
    491728          _GraphItemIt it4 = INVALID;
     729          ignore_unused_variable_warning(it3);
     730          ignore_unused_variable_warning(it4);
    492731
    493732          it2 = ++it1;
     
    499738        }
    500739        const GR& g;
     740        Constraints() {}
    501741      };
    502742    };
     
    578818          _GraphIncIt it3 = it1;
    579819          _GraphIncIt it4 = INVALID;
     820          ignore_unused_variable_warning(it3);
     821          ignore_unused_variable_warning(it4);
    580822
    581823          it2 = ++it1;
     
    587829        const Base& node;
    588830        const GR& graph;
     831        Constraints() {}
    589832      };
    590833    };
     
    7631006
    7641007        const _Digraph& digraph;
     1008        Constraints() {}
    7651009      };
    7661010    };
     
    8871131
    8881132        const _Graph& graph;
     1133        Constraints() {}
     1134      };
     1135    };
     1136
     1137    /// \brief Skeleton class for iterable undirected bipartite graphs.
     1138    ///
     1139    /// This class describes the interface of iterable undirected
     1140    /// bipartite graphs. It extends \ref IterableGraphComponent with
     1141    /// the core iterable interface of undirected bipartite graphs.
     1142    /// This concept is part of the BpGraph concept.
     1143    template <typename BAS = BaseBpGraphComponent>
     1144    class IterableBpGraphComponent : public IterableGraphComponent<BAS> {
     1145    public:
     1146
     1147      typedef BAS Base;
     1148      typedef typename Base::Node Node;
     1149      typedef typename Base::RedNode RedNode;
     1150      typedef typename Base::BlueNode BlueNode;
     1151      typedef typename Base::Arc Arc;
     1152      typedef typename Base::Edge Edge;
     1153     
     1154      typedef IterableBpGraphComponent BpGraph;
     1155
     1156      using IterableGraphComponent<BAS>::first;
     1157      using IterableGraphComponent<BAS>::next;
     1158
     1159      /// \name Base Iteration
     1160      ///
     1161      /// This interface provides functions for iteration on red and blue nodes.
     1162      ///
     1163      /// @{
     1164
     1165      /// \brief Return the first red node.
     1166      ///
     1167      /// This function gives back the first red node in the iteration order.
     1168      void first(RedNode&) const {}
     1169
     1170      /// \brief Return the next red node.
     1171      ///
     1172      /// This function gives back the next red node in the iteration order.
     1173      void next(RedNode&) const {}
     1174
     1175      /// \brief Return the first blue node.
     1176      ///
     1177      /// This function gives back the first blue node in the iteration order.
     1178      void first(BlueNode&) const {}
     1179
     1180      /// \brief Return the next blue node.
     1181      ///
     1182      /// This function gives back the next blue node in the iteration order.
     1183      void next(BlueNode&) const {}
     1184
     1185
     1186      /// @}
     1187
     1188      /// \name Class Based Iteration
     1189      ///
     1190      /// This interface provides iterator classes for red and blue nodes.
     1191      ///
     1192      /// @{
     1193
     1194      /// \brief This iterator goes through each red node.
     1195      ///
     1196      /// This iterator goes through each red node.
     1197      typedef GraphItemIt<BpGraph, RedNode> RedNodeIt;
     1198
     1199      /// \brief This iterator goes through each blue node.
     1200      ///
     1201      /// This iterator goes through each blue node.
     1202      typedef GraphItemIt<BpGraph, BlueNode> BlueNodeIt;
     1203
     1204      /// @}
     1205
     1206      template <typename _BpGraph>
     1207      struct Constraints {
     1208        void constraints() {
     1209          checkConcept<IterableGraphComponent<Base>, _BpGraph>();
     1210
     1211          typename _BpGraph::RedNode rn(INVALID);
     1212          bpgraph.first(rn);
     1213          bpgraph.next(rn);
     1214          typename _BpGraph::BlueNode bn(INVALID);
     1215          bpgraph.first(bn);
     1216          bpgraph.next(bn);
     1217
     1218          checkConcept<GraphItemIt<_BpGraph, typename _BpGraph::RedNode>,
     1219            typename _BpGraph::RedNodeIt>();
     1220          checkConcept<GraphItemIt<_BpGraph, typename _BpGraph::BlueNode>,
     1221            typename _BpGraph::BlueNodeIt>();
     1222        }
     1223
     1224        const _BpGraph& bpgraph;
    8891225      };
    8901226    };
     
    9151251      ArcNotifier;
    9161252
     1253      mutable NodeNotifier node_notifier;
     1254      mutable ArcNotifier arc_notifier;
     1255
    9171256      /// \brief Return the node alteration notifier.
    9181257      ///
    9191258      /// This function gives back the node alteration notifier.
    9201259      NodeNotifier& notifier(Node) const {
    921          return NodeNotifier();
     1260        return node_notifier;
    9221261      }
    9231262
     
    9261265      /// This function gives back the arc alteration notifier.
    9271266      ArcNotifier& notifier(Arc) const {
    928         return ArcNotifier();
     1267        return arc_notifier;
    9291268      }
    9301269
     
    9441283
    9451284        const _Digraph& digraph;
     1285        Constraints() {}
    9461286      };
    9471287    };
     
    9611301
    9621302      typedef BAS Base;
     1303      typedef AlterableDigraphComponent<Base> Parent;
    9631304      typedef typename Base::Edge Edge;
    9641305
     
    9681309      EdgeNotifier;
    9691310
     1311      mutable EdgeNotifier edge_notifier;
     1312
     1313      using Parent::notifier;
     1314
    9701315      /// \brief Return the edge alteration notifier.
    9711316      ///
    9721317      /// This function gives back the edge alteration notifier.
    9731318      EdgeNotifier& notifier(Edge) const {
    974         return EdgeNotifier();
     1319        return edge_notifier;
    9751320      }
    9761321
     
    9851330
    9861331        const _Graph& graph;
     1332        Constraints() {}
     1333      };
     1334    };
     1335
     1336    /// \brief Skeleton class for alterable undirected bipartite graphs.
     1337    ///
     1338    /// This class describes the interface of alterable undirected
     1339    /// bipartite graphs. It extends \ref AlterableGraphComponent with
     1340    /// the alteration notifier interface of bipartite graphs. It
     1341    /// implements an observer-notifier pattern for the red and blue
     1342    /// nodes. More obsevers can be registered into the notifier and
     1343    /// whenever an alteration occured in the graph all the observers
     1344    /// will be notified about it.
     1345    template <typename BAS = BaseBpGraphComponent>
     1346    class AlterableBpGraphComponent : public AlterableGraphComponent<BAS> {
     1347    public:
     1348
     1349      typedef BAS Base;
     1350      typedef AlterableGraphComponent<Base> Parent;
     1351      typedef typename Base::RedNode RedNode;
     1352      typedef typename Base::BlueNode BlueNode;
     1353
     1354
     1355      /// Red node alteration notifier class.
     1356      typedef AlterationNotifier<AlterableBpGraphComponent, RedNode>
     1357      RedNodeNotifier;
     1358
     1359      /// Blue node alteration notifier class.
     1360      typedef AlterationNotifier<AlterableBpGraphComponent, BlueNode>
     1361      BlueNodeNotifier;
     1362
     1363      mutable RedNodeNotifier red_node_notifier;
     1364      mutable BlueNodeNotifier blue_node_notifier;
     1365
     1366      using Parent::notifier;
     1367
     1368      /// \brief Return the red node alteration notifier.
     1369      ///
     1370      /// This function gives back the red node alteration notifier.
     1371      RedNodeNotifier& notifier(RedNode) const {
     1372        return red_node_notifier;
     1373      }
     1374
     1375      /// \brief Return the blue node alteration notifier.
     1376      ///
     1377      /// This function gives back the blue node alteration notifier.
     1378      BlueNodeNotifier& notifier(BlueNode) const {
     1379        return blue_node_notifier;
     1380      }
     1381
     1382      template <typename _BpGraph>
     1383      struct Constraints {
     1384        void constraints() {
     1385          checkConcept<AlterableGraphComponent<Base>, _BpGraph>();
     1386          typename _BpGraph::RedNodeNotifier& rnn
     1387            = bpgraph.notifier(typename _BpGraph::RedNode());
     1388          typename _BpGraph::BlueNodeNotifier& bnn
     1389            = bpgraph.notifier(typename _BpGraph::BlueNode());
     1390          ignore_unused_variable_warning(rnn);
     1391          ignore_unused_variable_warning(bnn);
     1392        }
     1393
     1394        const _BpGraph& bpgraph;
    9871395      };
    9881396    };
     
    10621470        const GR &g;
    10631471        const typename GraphMap::Value &t;
     1472        Constraints() {}
    10641473      };
    10651474
     
    12001609
    12011610        const _Digraph& digraph;
     1611        Constraints() {}
    12021612      };
    12031613    };
     
    12851695
    12861696        const _Graph& graph;
     1697        Constraints() {}
     1698      };
     1699    };
     1700
     1701    /// \brief Skeleton class for mappable undirected bipartite graphs.
     1702    ///
     1703    /// This class describes the interface of mappable undirected
     1704    /// bipartite graphs.  It extends \ref MappableGraphComponent with
     1705    /// the standard graph map class for red and blue nodes (\c
     1706    /// RedNodeMap and BlueNodeMap). This concept is part of the
     1707    /// BpGraph concept.
     1708    template <typename BAS = BaseBpGraphComponent>
     1709    class MappableBpGraphComponent : public MappableGraphComponent<BAS>  {
     1710    public:
     1711
     1712      typedef BAS Base;
     1713      typedef typename Base::Node Node;
     1714
     1715      typedef MappableBpGraphComponent BpGraph;
     1716
     1717      /// \brief Standard graph map for the red nodes.
     1718      ///
     1719      /// Standard graph map for the red nodes.
     1720      /// It conforms to the ReferenceMap concept.
     1721      template <typename V>
     1722      class RedNodeMap : public GraphMap<MappableBpGraphComponent, Node, V> {
     1723        typedef GraphMap<MappableBpGraphComponent, Node, V> Parent;
     1724
     1725      public:
     1726        /// \brief Construct a new map.
     1727        ///
     1728        /// Construct a new map for the graph.
     1729        explicit RedNodeMap(const MappableBpGraphComponent& graph)
     1730          : Parent(graph) {}
     1731
     1732        /// \brief Construct a new map with default value.
     1733        ///
     1734        /// Construct a new map for the graph and initalize the values.
     1735        RedNodeMap(const MappableBpGraphComponent& graph, const V& value)
     1736          : Parent(graph, value) {}
     1737
     1738      private:
     1739        /// \brief Copy constructor.
     1740        ///
     1741        /// Copy Constructor.
     1742        RedNodeMap(const RedNodeMap& nm) : Parent(nm) {}
     1743
     1744        /// \brief Assignment operator.
     1745        ///
     1746        /// Assignment operator.
     1747        template <typename CMap>
     1748        RedNodeMap& operator=(const CMap&) {
     1749          checkConcept<ReadMap<Node, V>, CMap>();
     1750          return *this;
     1751        }
     1752
     1753      };
     1754
     1755      /// \brief Standard graph map for the blue nodes.
     1756      ///
     1757      /// Standard graph map for the blue nodes.
     1758      /// It conforms to the ReferenceMap concept.
     1759      template <typename V>
     1760      class BlueNodeMap : public GraphMap<MappableBpGraphComponent, Node, V> {
     1761        typedef GraphMap<MappableBpGraphComponent, Node, V> Parent;
     1762
     1763      public:
     1764        /// \brief Construct a new map.
     1765        ///
     1766        /// Construct a new map for the graph.
     1767        explicit BlueNodeMap(const MappableBpGraphComponent& graph)
     1768          : Parent(graph) {}
     1769
     1770        /// \brief Construct a new map with default value.
     1771        ///
     1772        /// Construct a new map for the graph and initalize the values.
     1773        BlueNodeMap(const MappableBpGraphComponent& graph, const V& value)
     1774          : Parent(graph, value) {}
     1775
     1776      private:
     1777        /// \brief Copy constructor.
     1778        ///
     1779        /// Copy Constructor.
     1780        BlueNodeMap(const BlueNodeMap& nm) : Parent(nm) {}
     1781
     1782        /// \brief Assignment operator.
     1783        ///
     1784        /// Assignment operator.
     1785        template <typename CMap>
     1786        BlueNodeMap& operator=(const CMap&) {
     1787          checkConcept<ReadMap<Node, V>, CMap>();
     1788          return *this;
     1789        }
     1790
     1791      };
     1792
     1793
     1794      template <typename _BpGraph>
     1795      struct Constraints {
     1796
     1797        struct Dummy {
     1798          int value;
     1799          Dummy() : value(0) {}
     1800          Dummy(int _v) : value(_v) {}
     1801        };
     1802
     1803        void constraints() {
     1804          checkConcept<MappableGraphComponent<Base>, _BpGraph>();
     1805
     1806          { // int map test
     1807            typedef typename _BpGraph::template RedNodeMap<int>
     1808              IntRedNodeMap;
     1809            checkConcept<GraphMap<_BpGraph, typename _BpGraph::RedNode, int>,
     1810              IntRedNodeMap >();
     1811          } { // bool map test
     1812            typedef typename _BpGraph::template RedNodeMap<bool>
     1813              BoolRedNodeMap;
     1814            checkConcept<GraphMap<_BpGraph, typename _BpGraph::RedNode, bool>,
     1815              BoolRedNodeMap >();
     1816          } { // Dummy map test
     1817            typedef typename _BpGraph::template RedNodeMap<Dummy>
     1818              DummyRedNodeMap;
     1819            checkConcept<GraphMap<_BpGraph, typename _BpGraph::RedNode, Dummy>,
     1820              DummyRedNodeMap >();
     1821          }
     1822
     1823          { // int map test
     1824            typedef typename _BpGraph::template BlueNodeMap<int>
     1825              IntBlueNodeMap;
     1826            checkConcept<GraphMap<_BpGraph, typename _BpGraph::BlueNode, int>,
     1827              IntBlueNodeMap >();
     1828          } { // bool map test
     1829            typedef typename _BpGraph::template BlueNodeMap<bool>
     1830              BoolBlueNodeMap;
     1831            checkConcept<GraphMap<_BpGraph, typename _BpGraph::BlueNode, bool>,
     1832              BoolBlueNodeMap >();
     1833          } { // Dummy map test
     1834            typedef typename _BpGraph::template BlueNodeMap<Dummy>
     1835              DummyBlueNodeMap;
     1836            checkConcept<GraphMap<_BpGraph, typename _BpGraph::BlueNode, Dummy>,
     1837              DummyBlueNodeMap >();
     1838          }
     1839        }
     1840
     1841        const _BpGraph& bpgraph;
    12871842      };
    12881843    };
     
    13291884
    13301885        _Digraph& digraph;
     1886        Constraints() {}
    13311887      };
    13321888    };
     
    13731929
    13741930        _Graph& graph;
     1931        Constraints() {}
     1932      };
     1933    };
     1934
     1935    /// \brief Skeleton class for extendable undirected bipartite graphs.
     1936    ///
     1937    /// This class describes the interface of extendable undirected
     1938    /// bipartite graphs. It extends \ref BaseGraphComponent with
     1939    /// functions for adding nodes and edges to the graph. This
     1940    /// concept requires \ref AlterableBpGraphComponent.
     1941    template <typename BAS = BaseBpGraphComponent>
     1942    class ExtendableBpGraphComponent : public BAS {
     1943    public:
     1944
     1945      typedef BAS Base;
     1946      typedef typename Base::Node Node;
     1947      typedef typename Base::RedNode RedNode;
     1948      typedef typename Base::BlueNode BlueNode;
     1949      typedef typename Base::Edge Edge;
     1950
     1951      /// \brief Add a new red node to the digraph.
     1952      ///
     1953      /// This function adds a red new node to the digraph.
     1954      RedNode addRedNode() {
     1955        return INVALID;
     1956      }
     1957
     1958      /// \brief Add a new blue node to the digraph.
     1959      ///
     1960      /// This function adds a blue new node to the digraph.
     1961      BlueNode addBlueNode() {
     1962        return INVALID;
     1963      }
     1964
     1965      /// \brief Add a new edge connecting the given two nodes.
     1966      ///
     1967      /// This function adds a new edge connecting the given two nodes
     1968      /// of the graph. The first node has to be a red node, and the
     1969      /// second one a blue node.
     1970      Edge addEdge(const RedNode&, const BlueNode&) {
     1971        return INVALID;
     1972      }
     1973      Edge addEdge(const BlueNode&, const RedNode&) {
     1974        return INVALID;
     1975      }
     1976
     1977      template <typename _BpGraph>
     1978      struct Constraints {
     1979        void constraints() {
     1980          checkConcept<Base, _BpGraph>();
     1981          typename _BpGraph::RedNode red_node;
     1982          typename _BpGraph::BlueNode blue_node;
     1983          red_node = bpgraph.addRedNode();
     1984          blue_node = bpgraph.addBlueNode();
     1985          typename _BpGraph::Edge edge;
     1986          edge = bpgraph.addEdge(red_node, blue_node);
     1987          edge = bpgraph.addEdge(blue_node, red_node);
     1988        }
     1989
     1990        _BpGraph& bpgraph;
    13751991      };
    13761992    };
     
    14122028
    14132029        _Digraph& digraph;
     2030        Constraints() {}
    14142031      };
    14152032    };
     
    14512068
    14522069        _Graph& graph;
    1453       };
    1454     };
     2070        Constraints() {}
     2071      };
     2072    };
     2073
     2074    /// \brief Skeleton class for erasable undirected graphs.
     2075    ///
     2076    /// This class describes the interface of erasable undirected
     2077    /// bipartite graphs. It extends \ref BaseBpGraphComponent with
     2078    /// functions for removing nodes and edges from the graph. This
     2079    /// concept requires \ref AlterableBpGraphComponent.
     2080    template <typename BAS = BaseBpGraphComponent>
     2081    class ErasableBpGraphComponent : public ErasableGraphComponent<BAS> {};
    14552082
    14562083    /// \brief Skeleton class for clearable directed graphs.
     
    14792106
    14802107        _Digraph& digraph;
     2108        Constraints() {}
    14812109      };
    14822110    };
     
    14892117    /// This concept requires \ref AlterableGraphComponent.
    14902118    template <typename BAS = BaseGraphComponent>
    1491     class ClearableGraphComponent : public ClearableDigraphComponent<BAS> {
    1492     public:
    1493 
    1494       typedef BAS Base;
    1495 
    1496       /// \brief Erase all nodes and edges from the graph.
    1497       ///
    1498       /// This function erases all nodes and edges from the graph.
    1499       void clear() {}
    1500 
    1501       template <typename _Graph>
    1502       struct Constraints {
    1503         void constraints() {
    1504           checkConcept<Base, _Graph>();
    1505           graph.clear();
    1506         }
    1507 
    1508         _Graph& graph;
    1509       };
    1510     };
     2119    class ClearableGraphComponent : public ClearableDigraphComponent<BAS> {};
     2120
     2121    /// \brief Skeleton class for clearable undirected biparite graphs.
     2122    ///
     2123    /// This class describes the interface of clearable undirected
     2124    /// bipartite graphs. It extends \ref BaseBpGraphComponent with a
     2125    /// function for clearing the graph.  This concept requires \ref
     2126    /// AlterableBpGraphComponent.
     2127    template <typename BAS = BaseBpGraphComponent>
     2128    class ClearableBpGraphComponent : public ClearableGraphComponent<BAS> {};
    15112129
    15122130  }
  • lemon/concepts/heap.h

    r877 r976  
    315315        _Heap& heap;
    316316        ItemIntMap& map;
     317        Constraints() {}
    317318      };
    318319    };
  • lemon/concepts/maps.h

    r718 r997  
    5050      /// Returns the value associated with the given key.
    5151      Value operator[](const Key &) const {
    52         return *static_cast<Value *>(0);
     52        return *(static_cast<Value *>(0)+1);
    5353      }
    5454
     
    6969        const typename _ReadMap::Key& own_key;
    7070        const _ReadMap& m;
     71        Constraints() {}
    7172      };
    7273
     
    110111        const typename _WriteMap::Value& own_val;
    111112        _WriteMap& m;
     113        Constraints() {}
    112114      };
    113115    };
     
    130132      /// Returns the value associated with the given key.
    131133      Value operator[](const Key &) const {
    132         return *static_cast<Value *>(0);
     134        Value *r = 0;
     135        return *r;
    133136      }
    134137
     
    170173      /// Returns a reference to the value associated with the given key.
    171174      Reference operator[](const Key &) {
    172         return *static_cast<Value *>(0);
     175        Value *r = 0;
     176        return *r;
    173177      }
    174178
    175179      /// Returns a const reference to the value associated with the given key.
    176180      ConstReference operator[](const Key &) const {
    177         return *static_cast<Value *>(0);
     181        Value *r = 0;
     182        return *r;
    178183      }
    179184
     
    206211        typename _ReferenceMap::ConstReference own_cref;
    207212        _ReferenceMap& m;
     213        Constraints() {}
    208214      };
    209215    };
  • lemon/concepts/path.h

    r785 r976  
    169169        }
    170170        _Path& p;
     171        PathDumperConstraints() {}
    171172      };
    172173
     
    194195        }
    195196        _Path& p;
     197        PathDumperConstraints() {}
    196198      };
    197199
  • lemon/config.h.in

    r678 r981  
    1 /* The version string */
    2 #undef LEMON_VERSION
    3 
    4 /* Define to 1 if you have long long */
    5 #undef LEMON_HAVE_LONG_LONG
    6 
    7 /* Define to 1 if you have any LP solver. */
    8 #undef LEMON_HAVE_LP
    9 
    10 /* Define to 1 if you have any MIP solver. */
    11 #undef LEMON_HAVE_MIP
    12 
    13 /* Define to 1 if you have CPLEX. */
    14 #undef LEMON_HAVE_CPLEX
    15 
    16 /* Define to 1 if you have GLPK. */
    17 #undef LEMON_HAVE_GLPK
    18 
    19 /* Define to 1 if you have SOPLEX */
    20 #undef LEMON_HAVE_SOPLEX
    21 
    22 /* Define to 1 if you have CLP */
    23 #undef LEMON_HAVE_CLP
    24 
    25 /* Define to 1 if you have CBC */
    26 #undef LEMON_HAVE_CBC
     1#define LEMON_VERSION "@PROJECT_VERSION@"
     2#cmakedefine LEMON_HAVE_LONG_LONG 1
     3#cmakedefine LEMON_HAVE_LP 1
     4#cmakedefine LEMON_HAVE_MIP 1
     5#cmakedefine LEMON_HAVE_GLPK 1
     6#cmakedefine LEMON_HAVE_CPLEX 1
     7#cmakedefine LEMON_HAVE_CLP 1
     8#cmakedefine LEMON_HAVE_CBC 1
     9#cmakedefine LEMON_USE_PTHREAD 1
     10#cmakedefine LEMON_USE_WIN32_THREADS 1
  • lemon/core.h

    r893 r1027  
    149149  typedef typename Graph::template EdgeMap<double> DoubleEdgeMap
    150150
     151  ///Create convenience typedefs for the bipartite graph types and iterators
     152
     153  ///This \c \#define creates the same convenient type definitions as
     154  ///defined by \ref GRAPH_TYPEDEFS(BpGraph) and ten more, namely it
     155  ///creates \c RedNode, \c RedNodeIt, \c BoolRedNodeMap,
     156  ///\c IntRedNodeMap, \c DoubleRedNodeMap, \c BlueNode, \c BlueNodeIt,
     157  ///\c BoolBlueNodeMap, \c IntBlueNodeMap, \c DoubleBlueNodeMap.
     158  ///
     159  ///\note If the graph type is a dependent type, ie. the graph type depend
     160  ///on a template parameter, then use \c TEMPLATE_BPGRAPH_TYPEDEFS()
     161  ///macro.
     162#define BPGRAPH_TYPEDEFS(BpGraph)                                       \
     163  GRAPH_TYPEDEFS(BpGraph);                                              \
     164  typedef BpGraph::RedNode RedNode;                                     \
     165  typedef BpGraph::RedNodeIt RedNodeIt;                                 \
     166  typedef BpGraph::RedNodeMap<bool> BoolRedNodeMap;                     \
     167  typedef BpGraph::RedNodeMap<int> IntRedNodeMap;                       \
     168  typedef BpGraph::RedNodeMap<double> DoubleRedNodeMap;                 \
     169  typedef BpGraph::BlueNode BlueNode;                                   \
     170  typedef BpGraph::BlueNodeIt BlueNodeIt;                               \
     171  typedef BpGraph::BlueNodeMap<bool> BoolBlueNodeMap;                   \
     172  typedef BpGraph::BlueNodeMap<int> IntBlueNodeMap;                     \
     173  typedef BpGraph::BlueNodeMap<double> DoubleBlueNodeMap
     174
     175  ///Create convenience typedefs for the bipartite graph types and iterators
     176
     177  ///\see BPGRAPH_TYPEDEFS
     178  ///
     179  ///\note Use this macro, if the graph type is a dependent type,
     180  ///ie. the graph type depend on a template parameter.
     181#define TEMPLATE_BPGRAPH_TYPEDEFS(BpGraph)                                  \
     182  TEMPLATE_GRAPH_TYPEDEFS(BpGraph);                                         \
     183  typedef typename BpGraph::RedNode RedNode;                                \
     184  typedef typename BpGraph::RedNodeIt RedNodeIt;                            \
     185  typedef typename BpGraph::template RedNodeMap<bool> BoolRedNodeMap;       \
     186  typedef typename BpGraph::template RedNodeMap<int> IntRedNodeMap;         \
     187  typedef typename BpGraph::template RedNodeMap<double> DoubleRedNodeMap;   \
     188  typedef typename BpGraph::BlueNode BlueNode;                              \
     189  typedef typename BpGraph::BlueNodeIt BlueNodeIt;                          \
     190  typedef typename BpGraph::template BlueNodeMap<bool> BoolBlueNodeMap;     \
     191  typedef typename BpGraph::template BlueNodeMap<int> IntBlueNodeMap;       \
     192  typedef typename BpGraph::template BlueNodeMap<double> DoubleBlueNodeMap
     193
    151194  /// \brief Function to count the items in a graph.
    152195  ///
     
    200243  }
    201244
     245  namespace _graph_utils_bits {
     246   
     247    template <typename Graph, typename Enable = void>
     248    struct CountRedNodesSelector {
     249      static int count(const Graph &g) {
     250        return countItems<Graph, typename Graph::RedNode>(g);
     251      }
     252    };
     253
     254    template <typename Graph>
     255    struct CountRedNodesSelector<
     256      Graph, typename
     257      enable_if<typename Graph::NodeNumTag, void>::type>
     258    {
     259      static int count(const Graph &g) {
     260        return g.redNum();
     261      }
     262    };   
     263  }
     264
     265  /// \brief Function to count the red nodes in the graph.
     266  ///
     267  /// This function counts the red nodes in the graph.
     268  /// The complexity of the function is O(n) but for some
     269  /// graph structures it is specialized to run in O(1).
     270  ///
     271  /// If the graph contains a \e redNum() member function and a
     272  /// \e NodeNumTag tag then this function calls directly the member
     273  /// function to query the cardinality of the node set.
     274  template <typename Graph>
     275  inline int countRedNodes(const Graph& g) {
     276    return _graph_utils_bits::CountRedNodesSelector<Graph>::count(g);
     277  }
     278
     279  namespace _graph_utils_bits {
     280   
     281    template <typename Graph, typename Enable = void>
     282    struct CountBlueNodesSelector {
     283      static int count(const Graph &g) {
     284        return countItems<Graph, typename Graph::BlueNode>(g);
     285      }
     286    };
     287
     288    template <typename Graph>
     289    struct CountBlueNodesSelector<
     290      Graph, typename
     291      enable_if<typename Graph::NodeNumTag, void>::type>
     292    {
     293      static int count(const Graph &g) {
     294        return g.blueNum();
     295      }
     296    };   
     297  }
     298
     299  /// \brief Function to count the blue nodes in the graph.
     300  ///
     301  /// This function counts the blue nodes in the graph.
     302  /// The complexity of the function is O(n) but for some
     303  /// graph structures it is specialized to run in O(1).
     304  ///
     305  /// If the graph contains a \e blueNum() member function and a
     306  /// \e NodeNumTag tag then this function calls directly the member
     307  /// function to query the cardinality of the node set.
     308  template <typename Graph>
     309  inline int countBlueNodes(const Graph& g) {
     310    return _graph_utils_bits::CountBlueNodesSelector<Graph>::count(g);
     311  }
     312
    202313  // Arc counting:
    203314
     
    441552      template <typename From, typename NodeRefMap, typename EdgeRefMap>
    442553      static void copy(const From& from, Graph &to,
    443                        NodeRefMap& nodeRefMap, EdgeRefMap& edgeRefMap) {
     554                       NodeRefMap& nodeRefMap,
     555                       EdgeRefMap& edgeRefMap) {
    444556        to.build(from, nodeRefMap, edgeRefMap);
    445557      }
    446558    };
    447559
     560    template <typename BpGraph, typename Enable = void>
     561    struct BpGraphCopySelector {
     562      template <typename From, typename RedNodeRefMap,
     563                typename BlueNodeRefMap, typename EdgeRefMap>
     564      static void copy(const From& from, BpGraph &to,
     565                       RedNodeRefMap& redNodeRefMap,
     566                       BlueNodeRefMap& blueNodeRefMap,
     567                       EdgeRefMap& edgeRefMap) {
     568        to.clear();
     569        for (typename From::RedNodeIt it(from); it != INVALID; ++it) {
     570          redNodeRefMap[it] = to.addRedNode();
     571        }
     572        for (typename From::BlueNodeIt it(from); it != INVALID; ++it) {
     573          blueNodeRefMap[it] = to.addBlueNode();
     574        }
     575        for (typename From::EdgeIt it(from); it != INVALID; ++it) {
     576          edgeRefMap[it] = to.addEdge(redNodeRefMap[from.redNode(it)],
     577                                      blueNodeRefMap[from.blueNode(it)]);
     578        }
     579      }
     580    };
     581
     582    template <typename BpGraph>
     583    struct BpGraphCopySelector<
     584      BpGraph,
     585      typename enable_if<typename BpGraph::BuildTag, void>::type>
     586    {
     587      template <typename From, typename RedNodeRefMap,
     588                typename BlueNodeRefMap, typename EdgeRefMap>
     589      static void copy(const From& from, BpGraph &to,
     590                       RedNodeRefMap& redNodeRefMap,
     591                       BlueNodeRefMap& blueNodeRefMap,
     592                       EdgeRefMap& edgeRefMap) {
     593        to.build(from, redNodeRefMap, blueNodeRefMap, edgeRefMap);
     594      }
     595    };
     596
    448597  }
    449598
    450   /// Check whether a graph is undirected.
     599  /// \brief Check whether a graph is undirected.
    451600  ///
    452601  /// This function returns \c true if the given graph is undirected.
     
    9901139  graphCopy(const From& from, To& to) {
    9911140    return GraphCopy<From, To>(from, to);
     1141  }
     1142
     1143  /// \brief Class to copy a bipartite graph.
     1144  ///
     1145  /// Class to copy a bipartite graph to another graph (duplicate a
     1146  /// graph). The simplest way of using it is through the
     1147  /// \c bpGraphCopy() function.
     1148  ///
     1149  /// This class not only make a copy of a bipartite graph, but it can
     1150  /// create references and cross references between the nodes, edges
     1151  /// and arcs of the two graphs, and it can copy maps for using with
     1152  /// the newly created graph.
     1153  ///
     1154  /// To make a copy from a graph, first an instance of BpGraphCopy
     1155  /// should be created, then the data belongs to the graph should
     1156  /// assigned to copy. In the end, the \c run() member should be
     1157  /// called.
     1158  ///
     1159  /// The next code copies a graph with several data:
     1160  ///\code
     1161  ///  BpGraphCopy<OrigBpGraph, NewBpGraph> cg(orig_graph, new_graph);
     1162  ///  // Create references for the nodes
     1163  ///  OrigBpGraph::NodeMap<NewBpGraph::Node> nr(orig_graph);
     1164  ///  cg.nodeRef(nr);
     1165  ///  // Create cross references (inverse) for the edges
     1166  ///  NewBpGraph::EdgeMap<OrigBpGraph::Edge> ecr(new_graph);
     1167  ///  cg.edgeCrossRef(ecr);
     1168  ///  // Copy a red node map
     1169  ///  OrigBpGraph::RedNodeMap<double> ormap(orig_graph);
     1170  ///  NewBpGraph::RedNodeMap<double> nrmap(new_graph);
     1171  ///  cg.redNodeMap(ormap, nrmap);
     1172  ///  // Copy a node
     1173  ///  OrigBpGraph::Node on;
     1174  ///  NewBpGraph::Node nn;
     1175  ///  cg.node(on, nn);
     1176  ///  // Execute copying
     1177  ///  cg.run();
     1178  ///\endcode
     1179  template <typename From, typename To>
     1180  class BpGraphCopy {
     1181  private:
     1182
     1183    typedef typename From::Node Node;
     1184    typedef typename From::RedNode RedNode;
     1185    typedef typename From::BlueNode BlueNode;
     1186    typedef typename From::NodeIt NodeIt;
     1187    typedef typename From::Arc Arc;
     1188    typedef typename From::ArcIt ArcIt;
     1189    typedef typename From::Edge Edge;
     1190    typedef typename From::EdgeIt EdgeIt;
     1191
     1192    typedef typename To::Node TNode;
     1193    typedef typename To::RedNode TRedNode;
     1194    typedef typename To::BlueNode TBlueNode;
     1195    typedef typename To::Arc TArc;
     1196    typedef typename To::Edge TEdge;
     1197
     1198    typedef typename From::template RedNodeMap<TRedNode> RedNodeRefMap;
     1199    typedef typename From::template BlueNodeMap<TBlueNode> BlueNodeRefMap;
     1200    typedef typename From::template EdgeMap<TEdge> EdgeRefMap;
     1201
     1202    struct NodeRefMap {
     1203      NodeRefMap(const From& from, const RedNodeRefMap& red_node_ref,
     1204                 const BlueNodeRefMap& blue_node_ref)
     1205        : _from(from), _red_node_ref(red_node_ref),
     1206          _blue_node_ref(blue_node_ref) {}
     1207
     1208      typedef typename From::Node Key;
     1209      typedef typename To::Node Value;
     1210
     1211      Value operator[](const Key& key) const {
     1212        if (_from.red(key)) {
     1213          return _red_node_ref[_from.asRedNodeUnsafe(key)];
     1214        } else {
     1215          return _blue_node_ref[_from.asBlueNodeUnsafe(key)];
     1216        }
     1217      }
     1218
     1219      const From& _from;
     1220      const RedNodeRefMap& _red_node_ref;
     1221      const BlueNodeRefMap& _blue_node_ref;
     1222    };
     1223
     1224    struct ArcRefMap {
     1225      ArcRefMap(const From& from, const To& to, const EdgeRefMap& edge_ref)
     1226        : _from(from), _to(to), _edge_ref(edge_ref) {}
     1227
     1228      typedef typename From::Arc Key;
     1229      typedef typename To::Arc Value;
     1230
     1231      Value operator[](const Key& key) const {
     1232        return _to.direct(_edge_ref[key], _from.direction(key));
     1233      }
     1234
     1235      const From& _from;
     1236      const To& _to;
     1237      const EdgeRefMap& _edge_ref;
     1238    };
     1239
     1240  public:
     1241
     1242    /// \brief Constructor of BpGraphCopy.
     1243    ///
     1244    /// Constructor of BpGraphCopy for copying the content of the
     1245    /// \c from graph into the \c to graph.
     1246    BpGraphCopy(const From& from, To& to)
     1247      : _from(from), _to(to) {}
     1248
     1249    /// \brief Destructor of BpGraphCopy
     1250    ///
     1251    /// Destructor of BpGraphCopy.
     1252    ~BpGraphCopy() {
     1253      for (int i = 0; i < int(_node_maps.size()); ++i) {
     1254        delete _node_maps[i];
     1255      }
     1256      for (int i = 0; i < int(_red_maps.size()); ++i) {
     1257        delete _red_maps[i];
     1258      }
     1259      for (int i = 0; i < int(_blue_maps.size()); ++i) {
     1260        delete _blue_maps[i];
     1261      }
     1262      for (int i = 0; i < int(_arc_maps.size()); ++i) {
     1263        delete _arc_maps[i];
     1264      }
     1265      for (int i = 0; i < int(_edge_maps.size()); ++i) {
     1266        delete _edge_maps[i];
     1267      }
     1268    }
     1269
     1270    /// \brief Copy the node references into the given map.
     1271    ///
     1272    /// This function copies the node references into the given map.
     1273    /// The parameter should be a map, whose key type is the Node type of
     1274    /// the source graph, while the value type is the Node type of the
     1275    /// destination graph.
     1276    template <typename NodeRef>
     1277    BpGraphCopy& nodeRef(NodeRef& map) {
     1278      _node_maps.push_back(new _core_bits::RefCopy<From, Node,
     1279                           NodeRefMap, NodeRef>(map));
     1280      return *this;
     1281    }
     1282
     1283    /// \brief Copy the node cross references into the given map.
     1284    ///
     1285    /// This function copies the node cross references (reverse references)
     1286    /// into the given map. The parameter should be a map, whose key type
     1287    /// is the Node type of the destination graph, while the value type is
     1288    /// the Node type of the source graph.
     1289    template <typename NodeCrossRef>
     1290    BpGraphCopy& nodeCrossRef(NodeCrossRef& map) {
     1291      _node_maps.push_back(new _core_bits::CrossRefCopy<From, Node,
     1292                           NodeRefMap, NodeCrossRef>(map));
     1293      return *this;
     1294    }
     1295
     1296    /// \brief Make a copy of the given node map.
     1297    ///
     1298    /// This function makes a copy of the given node map for the newly
     1299    /// created graph.
     1300    /// The key type of the new map \c tmap should be the Node type of the
     1301    /// destination graph, and the key type of the original map \c map
     1302    /// should be the Node type of the source graph.
     1303    template <typename FromMap, typename ToMap>
     1304    BpGraphCopy& nodeMap(const FromMap& map, ToMap& tmap) {
     1305      _node_maps.push_back(new _core_bits::MapCopy<From, Node,
     1306                           NodeRefMap, FromMap, ToMap>(map, tmap));
     1307      return *this;
     1308    }
     1309
     1310    /// \brief Make a copy of the given node.
     1311    ///
     1312    /// This function makes a copy of the given node.
     1313    BpGraphCopy& node(const Node& node, TNode& tnode) {
     1314      _node_maps.push_back(new _core_bits::ItemCopy<From, Node,
     1315                           NodeRefMap, TNode>(node, tnode));
     1316      return *this;
     1317    }
     1318
     1319    /// \brief Copy the red node references into the given map.
     1320    ///
     1321    /// This function copies the red node references into the given
     1322    /// map.  The parameter should be a map, whose key type is the
     1323    /// Node type of the source graph with the red item set, while the
     1324    /// value type is the Node type of the destination graph.
     1325    template <typename RedRef>
     1326    BpGraphCopy& redRef(RedRef& map) {
     1327      _red_maps.push_back(new _core_bits::RefCopy<From, RedNode,
     1328                          RedNodeRefMap, RedRef>(map));
     1329      return *this;
     1330    }
     1331
     1332    /// \brief Copy the red node cross references into the given map.
     1333    ///
     1334    /// This function copies the red node cross references (reverse
     1335    /// references) into the given map. The parameter should be a map,
     1336    /// whose key type is the Node type of the destination graph with
     1337    /// the red item set, while the value type is the Node type of the
     1338    /// source graph.
     1339    template <typename RedCrossRef>
     1340    BpGraphCopy& redCrossRef(RedCrossRef& map) {
     1341      _red_maps.push_back(new _core_bits::CrossRefCopy<From, RedNode,
     1342                          RedNodeRefMap, RedCrossRef>(map));
     1343      return *this;
     1344    }
     1345
     1346    /// \brief Make a copy of the given red node map.
     1347    ///
     1348    /// This function makes a copy of the given red node map for the newly
     1349    /// created graph.
     1350    /// The key type of the new map \c tmap should be the Node type of
     1351    /// the destination graph with the red items, and the key type of
     1352    /// the original map \c map should be the Node type of the source
     1353    /// graph.
     1354    template <typename FromMap, typename ToMap>
     1355    BpGraphCopy& redNodeMap(const FromMap& map, ToMap& tmap) {
     1356      _red_maps.push_back(new _core_bits::MapCopy<From, RedNode,
     1357                          RedNodeRefMap, FromMap, ToMap>(map, tmap));
     1358      return *this;
     1359    }
     1360
     1361    /// \brief Make a copy of the given red node.
     1362    ///
     1363    /// This function makes a copy of the given red node.
     1364    BpGraphCopy& redNode(const RedNode& node, TRedNode& tnode) {
     1365      _red_maps.push_back(new _core_bits::ItemCopy<From, RedNode,
     1366                          RedNodeRefMap, TRedNode>(node, tnode));
     1367      return *this;
     1368    }
     1369
     1370    /// \brief Copy the blue node references into the given map.
     1371    ///
     1372    /// This function copies the blue node references into the given
     1373    /// map.  The parameter should be a map, whose key type is the
     1374    /// Node type of the source graph with the blue item set, while the
     1375    /// value type is the Node type of the destination graph.
     1376    template <typename BlueRef>
     1377    BpGraphCopy& blueRef(BlueRef& map) {
     1378      _blue_maps.push_back(new _core_bits::RefCopy<From, BlueNode,
     1379                           BlueNodeRefMap, BlueRef>(map));
     1380      return *this;
     1381    }
     1382
     1383    /// \brief Copy the blue node cross references into the given map.
     1384    ///
     1385    /// This function copies the blue node cross references (reverse
     1386    /// references) into the given map. The parameter should be a map,
     1387    /// whose key type is the Node type of the destination graph with
     1388    /// the blue item set, while the value type is the Node type of the
     1389    /// source graph.
     1390    template <typename BlueCrossRef>
     1391    BpGraphCopy& blueCrossRef(BlueCrossRef& map) {
     1392      _blue_maps.push_back(new _core_bits::CrossRefCopy<From, BlueNode,
     1393                           BlueNodeRefMap, BlueCrossRef>(map));
     1394      return *this;
     1395    }
     1396
     1397    /// \brief Make a copy of the given blue node map.
     1398    ///
     1399    /// This function makes a copy of the given blue node map for the newly
     1400    /// created graph.
     1401    /// The key type of the new map \c tmap should be the Node type of
     1402    /// the destination graph with the blue items, and the key type of
     1403    /// the original map \c map should be the Node type of the source
     1404    /// graph.
     1405    template <typename FromMap, typename ToMap>
     1406    BpGraphCopy& blueNodeMap(const FromMap& map, ToMap& tmap) {
     1407      _blue_maps.push_back(new _core_bits::MapCopy<From, BlueNode,
     1408                           BlueNodeRefMap, FromMap, ToMap>(map, tmap));
     1409      return *this;
     1410    }
     1411
     1412    /// \brief Make a copy of the given blue node.
     1413    ///
     1414    /// This function makes a copy of the given blue node.
     1415    BpGraphCopy& blueNode(const BlueNode& node, TBlueNode& tnode) {
     1416      _blue_maps.push_back(new _core_bits::ItemCopy<From, BlueNode,
     1417                           BlueNodeRefMap, TBlueNode>(node, tnode));
     1418      return *this;
     1419    }
     1420
     1421    /// \brief Copy the arc references into the given map.
     1422    ///
     1423    /// This function copies the arc references into the given map.
     1424    /// The parameter should be a map, whose key type is the Arc type of
     1425    /// the source graph, while the value type is the Arc type of the
     1426    /// destination graph.
     1427    template <typename ArcRef>
     1428    BpGraphCopy& arcRef(ArcRef& map) {
     1429      _arc_maps.push_back(new _core_bits::RefCopy<From, Arc,
     1430                          ArcRefMap, ArcRef>(map));
     1431      return *this;
     1432    }
     1433
     1434    /// \brief Copy the arc cross references into the given map.
     1435    ///
     1436    /// This function copies the arc cross references (reverse references)
     1437    /// into the given map. The parameter should be a map, whose key type
     1438    /// is the Arc type of the destination graph, while the value type is
     1439    /// the Arc type of the source graph.
     1440    template <typename ArcCrossRef>
     1441    BpGraphCopy& arcCrossRef(ArcCrossRef& map) {
     1442      _arc_maps.push_back(new _core_bits::CrossRefCopy<From, Arc,
     1443                          ArcRefMap, ArcCrossRef>(map));
     1444      return *this;
     1445    }
     1446
     1447    /// \brief Make a copy of the given arc map.
     1448    ///
     1449    /// This function makes a copy of the given arc map for the newly
     1450    /// created graph.
     1451    /// The key type of the new map \c tmap should be the Arc type of the
     1452    /// destination graph, and the key type of the original map \c map
     1453    /// should be the Arc type of the source graph.
     1454    template <typename FromMap, typename ToMap>
     1455    BpGraphCopy& arcMap(const FromMap& map, ToMap& tmap) {
     1456      _arc_maps.push_back(new _core_bits::MapCopy<From, Arc,
     1457                          ArcRefMap, FromMap, ToMap>(map, tmap));
     1458      return *this;
     1459    }
     1460
     1461    /// \brief Make a copy of the given arc.
     1462    ///
     1463    /// This function makes a copy of the given arc.
     1464    BpGraphCopy& arc(const Arc& arc, TArc& tarc) {
     1465      _arc_maps.push_back(new _core_bits::ItemCopy<From, Arc,
     1466                          ArcRefMap, TArc>(arc, tarc));
     1467      return *this;
     1468    }
     1469
     1470    /// \brief Copy the edge references into the given map.
     1471    ///
     1472    /// This function copies the edge references into the given map.
     1473    /// The parameter should be a map, whose key type is the Edge type of
     1474    /// the source graph, while the value type is the Edge type of the
     1475    /// destination graph.
     1476    template <typename EdgeRef>
     1477    BpGraphCopy& edgeRef(EdgeRef& map) {
     1478      _edge_maps.push_back(new _core_bits::RefCopy<From, Edge,
     1479                           EdgeRefMap, EdgeRef>(map));
     1480      return *this;
     1481    }
     1482
     1483    /// \brief Copy the edge cross references into the given map.
     1484    ///
     1485    /// This function copies the edge cross references (reverse references)
     1486    /// into the given map. The parameter should be a map, whose key type
     1487    /// is the Edge type of the destination graph, while the value type is
     1488    /// the Edge type of the source graph.
     1489    template <typename EdgeCrossRef>
     1490    BpGraphCopy& edgeCrossRef(EdgeCrossRef& map) {
     1491      _edge_maps.push_back(new _core_bits::CrossRefCopy<From,
     1492                           Edge, EdgeRefMap, EdgeCrossRef>(map));
     1493      return *this;
     1494    }
     1495
     1496    /// \brief Make a copy of the given edge map.
     1497    ///
     1498    /// This function makes a copy of the given edge map for the newly
     1499    /// created graph.
     1500    /// The key type of the new map \c tmap should be the Edge type of the
     1501    /// destination graph, and the key type of the original map \c map
     1502    /// should be the Edge type of the source graph.
     1503    template <typename FromMap, typename ToMap>
     1504    BpGraphCopy& edgeMap(const FromMap& map, ToMap& tmap) {
     1505      _edge_maps.push_back(new _core_bits::MapCopy<From, Edge,
     1506                           EdgeRefMap, FromMap, ToMap>(map, tmap));
     1507      return *this;
     1508    }
     1509
     1510    /// \brief Make a copy of the given edge.
     1511    ///
     1512    /// This function makes a copy of the given edge.
     1513    BpGraphCopy& edge(const Edge& edge, TEdge& tedge) {
     1514      _edge_maps.push_back(new _core_bits::ItemCopy<From, Edge,
     1515                           EdgeRefMap, TEdge>(edge, tedge));
     1516      return *this;
     1517    }
     1518
     1519    /// \brief Execute copying.
     1520    ///
     1521    /// This function executes the copying of the graph along with the
     1522    /// copying of the assigned data.
     1523    void run() {
     1524      RedNodeRefMap redNodeRefMap(_from);
     1525      BlueNodeRefMap blueNodeRefMap(_from);
     1526      NodeRefMap nodeRefMap(_from, redNodeRefMap, blueNodeRefMap);
     1527      EdgeRefMap edgeRefMap(_from);
     1528      ArcRefMap arcRefMap(_from, _to, edgeRefMap);
     1529      _core_bits::BpGraphCopySelector<To>::
     1530        copy(_from, _to, redNodeRefMap, blueNodeRefMap, edgeRefMap);
     1531      for (int i = 0; i < int(_node_maps.size()); ++i) {
     1532        _node_maps[i]->copy(_from, nodeRefMap);
     1533      }
     1534      for (int i = 0; i < int(_red_maps.size()); ++i) {
     1535        _red_maps[i]->copy(_from, redNodeRefMap);
     1536      }
     1537      for (int i = 0; i < int(_blue_maps.size()); ++i) {
     1538        _blue_maps[i]->copy(_from, blueNodeRefMap);
     1539      }
     1540      for (int i = 0; i < int(_edge_maps.size()); ++i) {
     1541        _edge_maps[i]->copy(_from, edgeRefMap);
     1542      }
     1543      for (int i = 0; i < int(_arc_maps.size()); ++i) {
     1544        _arc_maps[i]->copy(_from, arcRefMap);
     1545      }
     1546    }
     1547
     1548  private:
     1549
     1550    const From& _from;
     1551    To& _to;
     1552
     1553    std::vector<_core_bits::MapCopyBase<From, Node, NodeRefMap>* >
     1554      _node_maps;
     1555
     1556    std::vector<_core_bits::MapCopyBase<From, RedNode, RedNodeRefMap>* >
     1557      _red_maps;
     1558
     1559    std::vector<_core_bits::MapCopyBase<From, BlueNode, BlueNodeRefMap>* >
     1560      _blue_maps;
     1561
     1562    std::vector<_core_bits::MapCopyBase<From, Arc, ArcRefMap>* >
     1563      _arc_maps;
     1564
     1565    std::vector<_core_bits::MapCopyBase<From, Edge, EdgeRefMap>* >
     1566      _edge_maps;
     1567
     1568  };
     1569
     1570  /// \brief Copy a graph to another graph.
     1571  ///
     1572  /// This function copies a graph to another graph.
     1573  /// The complete usage of it is detailed in the BpGraphCopy class,
     1574  /// but a short example shows a basic work:
     1575  ///\code
     1576  /// graphCopy(src, trg).nodeRef(nr).edgeCrossRef(ecr).run();
     1577  ///\endcode
     1578  ///
     1579  /// After the copy the \c nr map will contain the mapping from the
     1580  /// nodes of the \c from graph to the nodes of the \c to graph and
     1581  /// \c ecr will contain the mapping from the edges of the \c to graph
     1582  /// to the edges of the \c from graph.
     1583  ///
     1584  /// \see BpGraphCopy
     1585  template <typename From, typename To>
     1586  BpGraphCopy<From, To>
     1587  bpGraphCopy(const From& from, To& to) {
     1588    return BpGraphCopy<From, To>(from, to);
    9921589  }
    9931590
     
    12581855    /// The Digraph type
    12591856    typedef GR Digraph;
    1260 
     1857   
    12611858  protected:
    12621859
     
    18692466    ///a single node \c n, then \ref refresh(Node) "refresh(n)" is enough.
    18702467    ///
    1871 #ifdef DOXYGEN
    1872     Arc operator()(Node s, Node t, Arc prev=INVALID) const {}
    1873 #else
    1874     using ArcLookUp<GR>::operator() ;
    1875     Arc operator()(Node s, Node t, Arc prev) const
     2468    Arc operator()(Node s, Node t, Arc prev=INVALID) const
    18762469    {
    1877       return prev==INVALID?(*this)(s,t):_next[prev];
    1878     }
     2470      if(prev==INVALID)
     2471        {
     2472          Arc f=INVALID;
     2473          Arc e;
     2474          for(e=_head[s];
     2475              e!=INVALID&&_g.target(e)!=t;
     2476              e = t < _g.target(e)?_left[e]:_right[e]) ;
     2477          while(e!=INVALID)
     2478            if(_g.target(e)==t)
     2479              {
     2480                f = e;
     2481                e = _left[e];
     2482              }
     2483            else e = _right[e];
     2484          return f;
     2485        }
     2486      else return _next[prev];
     2487    }
     2488
     2489  };
     2490
     2491  /// @}
     2492
     2493} //namespace lemon
     2494
    18792495#endif
    1880 
    1881   };
    1882 
    1883   /// @}
    1884 
    1885 } //namespace lemon
    1886 
    1887 #endif
  • lemon/cost_scaling.h

    r877 r1003  
    9898  /// "preflow push-relabel" algorithm for the maximum flow problem.
    9999  ///
     100  /// In general, \ref NetworkSimplex and \ref CostScaling are the fastest
     101  /// implementations available in LEMON for solving this problem.
     102  /// (For more information, see \ref min_cost_flow_algs "the module page".)
     103  ///
    100104  /// Most of the parameters of the problem (except for the digraph)
    101105  /// can be given using separate functions, and the algorithm can be
     
    114118  /// consider to use the named template parameters instead.
    115119  ///
    116   /// \warning Both number types must be signed and all input data must
     120  /// \warning Both \c V and \c C must be signed number types.
     121  /// \warning All input data (capacities, supply values, and costs) must
    117122  /// be integer.
    118   /// \warning This algorithm does not support negative costs for such
    119   /// arcs that have infinite upper bound.
     123  /// \warning This algorithm does not support negative costs for
     124  /// arcs having infinite upper bound.
    120125  ///
    121126  /// \note %CostScaling provides three different internal methods,
     
    179184    /// relabel operation.
    180185    /// By default, the so called \ref PARTIAL_AUGMENT
    181     /// "Partial Augment-Relabel" method is used, which proved to be
     186    /// "Partial Augment-Relabel" method is used, which turned out to be
    182187    /// the most efficient and the most robust on various test inputs.
    183188    /// However, the other methods can be selected using the \ref run()
     
    234239    };
    235240
    236     typedef StaticVectorMap<StaticDigraph::Node, LargeCost> LargeCostNodeMap;
    237241    typedef StaticVectorMap<StaticDigraph::Arc, LargeCost> LargeCostArcMap;
    238242
     
    285289    int _max_rank;
    286290
    287     // Data for a StaticDigraph structure
    288     typedef std::pair<int, int> IntPair;
    289     StaticDigraph _sgr;
    290     std::vector<IntPair> _arc_vec;
    291     std::vector<LargeCost> _cost_vec;
    292     LargeCostArcMap _cost_map;
    293     LargeCostNodeMap _pi_map;
    294 
    295291  public:
    296292
     
    339335    CostScaling(const GR& graph) :
    340336      _graph(graph), _node_id(graph), _arc_idf(graph), _arc_idb(graph),
    341       _cost_map(_cost_vec), _pi_map(_pi),
    342337      INF(std::numeric_limits<Value>::has_infinity ?
    343338          std::numeric_limits<Value>::infinity() :
     
    448443    ///
    449444    /// Using this function has the same effect as using \ref supplyMap()
    450     /// with such a map in which \c k is assigned to \c s, \c -k is
     445    /// with a map in which \c k is assigned to \c s, \c -k is
    451446    /// assigned to \c t and all other nodes have zero supply value.
    452447    ///
     
    494489    /// \param method The internal method that will be used in the
    495490    /// algorithm. For more information, see \ref Method.
    496     /// \param factor The cost scaling factor. It must be larger than one.
     491    /// \param factor The cost scaling factor. It must be at least two.
    497492    ///
    498493    /// \return \c INFEASIBLE if no feasible flow exists,
     
    508503    /// \see ProblemType, Method
    509504    /// \see resetParams(), reset()
    510     ProblemType run(Method method = PARTIAL_AUGMENT, int factor = 8) {
     505    ProblemType run(Method method = PARTIAL_AUGMENT, int factor = 16) {
     506      LEMON_ASSERT(factor >= 2, "The scaling factor must be at least 2");
    511507      _alpha = factor;
    512508      ProblemType pt = init();
     
    572568    }
    573569
    574     /// \brief Reset all the parameters that have been given before.
    575     ///
    576     /// This function resets all the paramaters that have been given
    577     /// before using functions \ref lowerMap(), \ref upperMap(),
    578     /// \ref costMap(), \ref supplyMap(), \ref stSupply().
    579     ///
    580     /// It is useful for multiple run() calls. If this function is not
    581     /// used, all the parameters given before are kept for the next
    582     /// \ref run() call.
    583     /// However, the underlying digraph must not be modified after this
    584     /// class have been constructed, since it copies and extends the graph.
     570    /// \brief Reset the internal data structures and all the parameters
     571    /// that have been given before.
     572    ///
     573    /// This function resets the internal data structures and all the
     574    /// paramaters that have been given before using functions \ref lowerMap(),
     575    /// \ref upperMap(), \ref costMap(), \ref supplyMap(), \ref stSupply().
     576    ///
     577    /// It is useful for multiple \ref run() calls. By default, all the given
     578    /// parameters are kept for the next \ref run() call, unless
     579    /// \ref resetParams() or \ref reset() is used.
     580    /// If the underlying digraph was also modified after the construction
     581    /// of the class or the last \ref reset() call, then the \ref reset()
     582    /// function must be used, otherwise \ref resetParams() is sufficient.
     583    ///
     584    /// See \ref resetParams() for examples.
     585    ///
    585586    /// \return <tt>(*this)</tt>
     587    ///
     588    /// \see resetParams(), run()
    586589    CostScaling& reset() {
    587590      // Resize vectors
     
    608611      _excess.resize(_res_node_num);
    609612      _next_out.resize(_res_node_num);
    610 
    611       _arc_vec.reserve(_res_arc_num);
    612       _cost_vec.reserve(_res_arc_num);
    613613
    614614      // Copy the graph
     
    706706    }
    707707
    708     /// \brief Return the flow map (the primal solution).
     708    /// \brief Copy the flow values (the primal solution) into the
     709    /// given map.
    709710    ///
    710711    /// This function copies the flow value on each arc into the given
     
    730731    }
    731732
    732     /// \brief Return the potential map (the dual solution).
     733    /// \brief Copy the potential values (the dual solution) into the
     734    /// given map.
    733735    ///
    734736    /// This function copies the potential (dual value) of each node
     
    887889      }
    888890
    889       return OPTIMAL;
    890     }
    891 
    892     // Execute the algorithm and transform the results
    893     void start(Method method) {
    894       // Maximum path length for partial augment
    895       const int MAX_PATH_LENGTH = 4;
    896 
    897891      // Initialize data structures for buckets
    898892      _max_rank = _alpha * _res_node_num;
     
    902896      _rank.resize(_res_node_num + 1);
    903897
    904       // Execute the algorithm
     898      return OPTIMAL;
     899    }
     900
     901    // Execute the algorithm and transform the results
     902    void start(Method method) {
     903      const int MAX_PARTIAL_PATH_LENGTH = 4;
     904
    905905      switch (method) {
    906906        case PUSH:
     
    908908          break;
    909909        case AUGMENT:
    910           startAugment();
     910          startAugment(_res_node_num - 1);
    911911          break;
    912912        case PARTIAL_AUGMENT:
    913           startAugment(MAX_PATH_LENGTH);
     913          startAugment(MAX_PARTIAL_PATH_LENGTH);
    914914          break;
    915915      }
    916916
    917       // Compute node potentials for the original costs
    918       _arc_vec.clear();
    919       _cost_vec.clear();
    920       for (int j = 0; j != _res_arc_num; ++j) {
    921         if (_res_cap[j] > 0) {
    922           _arc_vec.push_back(IntPair(_source[j], _target[j]));
    923           _cost_vec.push_back(_scost[j]);
    924         }
    925       }
    926       _sgr.build(_res_node_num, _arc_vec.begin(), _arc_vec.end());
    927 
    928       typename BellmanFord<StaticDigraph, LargeCostArcMap>
    929         ::template SetDistMap<LargeCostNodeMap>::Create bf(_sgr, _cost_map);
    930       bf.distMap(_pi_map);
    931       bf.init(0);
    932       bf.start();
     917      // Compute node potentials (dual solution)
     918      for (int i = 0; i != _res_node_num; ++i) {
     919        _pi[i] = static_cast<Cost>(_pi[i] / (_res_node_num * _alpha));
     920      }
     921      bool optimal = true;
     922      for (int i = 0; optimal && i != _res_node_num; ++i) {
     923        LargeCost pi_i = _pi[i];
     924        int last_out = _first_out[i+1];
     925        for (int j = _first_out[i]; j != last_out; ++j) {
     926          if (_res_cap[j] > 0 && _scost[j] + pi_i - _pi[_target[j]] < 0) {
     927            optimal = false;
     928            break;
     929          }
     930        }
     931      }
     932
     933      if (!optimal) {
     934        // Compute node potentials for the original costs with BellmanFord
     935        // (if it is necessary)
     936        typedef std::pair<int, int> IntPair;
     937        StaticDigraph sgr;
     938        std::vector<IntPair> arc_vec;
     939        std::vector<LargeCost> cost_vec;
     940        LargeCostArcMap cost_map(cost_vec);
     941
     942        arc_vec.clear();
     943        cost_vec.clear();
     944        for (int j = 0; j != _res_arc_num; ++j) {
     945          if (_res_cap[j] > 0) {
     946            int u = _source[j], v = _target[j];
     947            arc_vec.push_back(IntPair(u, v));
     948            cost_vec.push_back(_scost[j] + _pi[u] - _pi[v]);
     949          }
     950        }
     951        sgr.build(_res_node_num, arc_vec.begin(), arc_vec.end());
     952
     953        typename BellmanFord<StaticDigraph, LargeCostArcMap>::Create
     954          bf(sgr, cost_map);
     955        bf.init(0);
     956        bf.start();
     957
     958        for (int i = 0; i != _res_node_num; ++i) {
     959          _pi[i] += bf.dist(sgr.node(i));
     960        }
     961      }
     962
     963      // Shift potentials to meet the requirements of the GEQ type
     964      // optimality conditions
     965      LargeCost max_pot = _pi[_root];
     966      for (int i = 0; i != _res_node_num; ++i) {
     967        if (_pi[i] > max_pot) max_pot = _pi[i];
     968      }
     969      if (max_pot != 0) {
     970        for (int i = 0; i != _res_node_num; ++i) {
     971          _pi[i] -= max_pot;
     972        }
     973      }
    933974
    934975      // Handle non-zero lower bounds
     
    948989        LargeCost pi_u = _pi[u];
    949990        for (int a = _first_out[u]; a != last_out; ++a) {
    950           int v = _target[a];
    951           if (_res_cap[a] > 0 && _cost[a] + pi_u - _pi[v] < 0) {
    952             Value delta = _res_cap[a];
    953             _excess[u] -= delta;
    954             _excess[v] += delta;
    955             _res_cap[a] = 0;
    956             _res_cap[_reverse[a]] += delta;
     991          Value delta = _res_cap[a];
     992          if (delta > 0) {
     993            int v = _target[a];
     994            if (_cost[a] + pi_u - _pi[v] < 0) {
     995              _excess[u] -= delta;
     996              _excess[v] += delta;
     997              _res_cap[a] = 0;
     998              _res_cap[_reverse[a]] += delta;
     999            }
    9571000          }
    9581001        }
     
    9701013    }
    9711014
    972     // Early termination heuristic
    973     bool earlyTermination() {
    974       const double EARLY_TERM_FACTOR = 3.0;
    975 
    976       // Build a static residual graph
    977       _arc_vec.clear();
    978       _cost_vec.clear();
    979       for (int j = 0; j != _res_arc_num; ++j) {
    980         if (_res_cap[j] > 0) {
    981           _arc_vec.push_back(IntPair(_source[j], _target[j]));
    982           _cost_vec.push_back(_cost[j] + 1);
    983         }
    984       }
    985       _sgr.build(_res_node_num, _arc_vec.begin(), _arc_vec.end());
    986 
    987       // Run Bellman-Ford algorithm to check if the current flow is optimal
    988       BellmanFord<StaticDigraph, LargeCostArcMap> bf(_sgr, _cost_map);
    989       bf.init(0);
    990       bool done = false;
    991       int K = int(EARLY_TERM_FACTOR * std::sqrt(double(_res_node_num)));
    992       for (int i = 0; i < K && !done; ++i) {
    993         done = bf.processNextWeakRound();
    994       }
    995       return done;
     1015    // Price (potential) refinement heuristic
     1016    bool priceRefinement() {
     1017
     1018      // Stack for stroing the topological order
     1019      IntVector stack(_res_node_num);
     1020      int stack_top;
     1021
     1022      // Perform phases
     1023      while (topologicalSort(stack, stack_top)) {
     1024
     1025        // Compute node ranks in the acyclic admissible network and
     1026        // store the nodes in buckets
     1027        for (int i = 0; i != _res_node_num; ++i) {
     1028          _rank[i] = 0;
     1029        }
     1030        const int bucket_end = _root + 1;
     1031        for (int r = 0; r != _max_rank; ++r) {
     1032          _buckets[r] = bucket_end;
     1033        }
     1034        int top_rank = 0;
     1035        for ( ; stack_top >= 0; --stack_top) {
     1036          int u = stack[stack_top], v;
     1037          int rank_u = _rank[u];
     1038
     1039          LargeCost rc, pi_u = _pi[u];
     1040          int last_out = _first_out[u+1];
     1041          for (int a = _first_out[u]; a != last_out; ++a) {
     1042            if (_res_cap[a] > 0) {
     1043              v = _target[a];
     1044              rc = _cost[a] + pi_u - _pi[v];
     1045              if (rc < 0) {
     1046                LargeCost nrc = static_cast<LargeCost>((-rc - 0.5) / _epsilon);
     1047                if (nrc < LargeCost(_max_rank)) {
     1048                  int new_rank_v = rank_u + static_cast<int>(nrc);
     1049                  if (new_rank_v > _rank[v]) {
     1050                    _rank[v] = new_rank_v;
     1051                  }
     1052                }
     1053              }
     1054            }
     1055          }
     1056
     1057          if (rank_u > 0) {
     1058            top_rank = std::max(top_rank, rank_u);
     1059            int bfirst = _buckets[rank_u];
     1060            _bucket_next[u] = bfirst;
     1061            _bucket_prev[bfirst] = u;
     1062            _buckets[rank_u] = u;
     1063          }
     1064        }
     1065
     1066        // Check if the current flow is epsilon-optimal
     1067        if (top_rank == 0) {
     1068          return true;
     1069        }
     1070
     1071        // Process buckets in top-down order
     1072        for (int rank = top_rank; rank > 0; --rank) {
     1073          while (_buckets[rank] != bucket_end) {
     1074            // Remove the first node from the current bucket
     1075            int u = _buckets[rank];
     1076            _buckets[rank] = _bucket_next[u];
     1077
     1078            // Search the outgoing arcs of u
     1079            LargeCost rc, pi_u = _pi[u];
     1080            int last_out = _first_out[u+1];
     1081            int v, old_rank_v, new_rank_v;
     1082            for (int a = _first_out[u]; a != last_out; ++a) {
     1083              if (_res_cap[a] > 0) {
     1084                v = _target[a];
     1085                old_rank_v = _rank[v];
     1086
     1087                if (old_rank_v < rank) {
     1088
     1089                  // Compute the new rank of node v
     1090                  rc = _cost[a] + pi_u - _pi[v];
     1091                  if (rc < 0) {
     1092                    new_rank_v = rank;
     1093                  } else {
     1094                    LargeCost nrc = rc / _epsilon;
     1095                    new_rank_v = 0;
     1096                    if (nrc < LargeCost(_max_rank)) {
     1097                      new_rank_v = rank - 1 - static_cast<int>(nrc);
     1098                    }
     1099                  }
     1100
     1101                  // Change the rank of node v
     1102                  if (new_rank_v > old_rank_v) {
     1103                    _rank[v] = new_rank_v;
     1104
     1105                    // Remove v from its old bucket
     1106                    if (old_rank_v > 0) {
     1107                      if (_buckets[old_rank_v] == v) {
     1108                        _buckets[old_rank_v] = _bucket_next[v];
     1109                      } else {
     1110                        int pv = _bucket_prev[v], nv = _bucket_next[v];
     1111                        _bucket_next[pv] = nv;
     1112                        _bucket_prev[nv] = pv;
     1113                      }
     1114                    }
     1115
     1116                    // Insert v into its new bucket
     1117                    int nv = _buckets[new_rank_v];
     1118                    _bucket_next[v] = nv;
     1119                    _bucket_prev[nv] = v;
     1120                    _buckets[new_rank_v] = v;
     1121                  }
     1122                }
     1123              }
     1124            }
     1125
     1126            // Refine potential of node u
     1127            _pi[u] -= rank * _epsilon;
     1128          }
     1129        }
     1130
     1131      }
     1132
     1133      return false;
     1134    }
     1135
     1136    // Find and cancel cycles in the admissible network and
     1137    // determine topological order using DFS
     1138    bool topologicalSort(IntVector &stack, int &stack_top) {
     1139      const int MAX_CYCLE_CANCEL = 1;
     1140
     1141      BoolVector reached(_res_node_num, false);
     1142      BoolVector processed(_res_node_num, false);
     1143      IntVector pred(_res_node_num);
     1144      for (int i = 0; i != _res_node_num; ++i) {
     1145        _next_out[i] = _first_out[i];
     1146      }
     1147      stack_top = -1;
     1148
     1149      int cycle_cnt = 0;
     1150      for (int start = 0; start != _res_node_num; ++start) {
     1151        if (reached[start]) continue;
     1152
     1153        // Start DFS search from this start node
     1154        pred[start] = -1;
     1155        int tip = start, v;
     1156        while (true) {
     1157          // Check the outgoing arcs of the current tip node
     1158          reached[tip] = true;
     1159          LargeCost pi_tip = _pi[tip];
     1160          int a, last_out = _first_out[tip+1];
     1161          for (a = _next_out[tip]; a != last_out; ++a) {
     1162            if (_res_cap[a] > 0) {
     1163              v = _target[a];
     1164              if (_cost[a] + pi_tip - _pi[v] < 0) {
     1165                if (!reached[v]) {
     1166                  // A new node is reached
     1167                  reached[v] = true;
     1168                  pred[v] = tip;
     1169                  _next_out[tip] = a;
     1170                  tip = v;
     1171                  a = _next_out[tip];
     1172                  last_out = _first_out[tip+1];
     1173                  break;
     1174                }
     1175                else if (!processed[v]) {
     1176                  // A cycle is found
     1177                  ++cycle_cnt;
     1178                  _next_out[tip] = a;
     1179
     1180                  // Find the minimum residual capacity along the cycle
     1181                  Value d, delta = _res_cap[a];
     1182                  int u, delta_node = tip;
     1183                  for (u = tip; u != v; ) {
     1184                    u = pred[u];
     1185                    d = _res_cap[_next_out[u]];
     1186                    if (d <= delta) {
     1187                      delta = d;
     1188                      delta_node = u;
     1189                    }
     1190                  }
     1191
     1192                  // Augment along the cycle
     1193                  _res_cap[a] -= delta;
     1194                  _res_cap[_reverse[a]] += delta;
     1195                  for (u = tip; u != v; ) {
     1196                    u = pred[u];
     1197                    int ca = _next_out[u];
     1198                    _res_cap[ca] -= delta;
     1199                    _res_cap[_reverse[ca]] += delta;
     1200                  }
     1201
     1202                  // Check the maximum number of cycle canceling
     1203                  if (cycle_cnt >= MAX_CYCLE_CANCEL) {
     1204                    return false;
     1205                  }
     1206
     1207                  // Roll back search to delta_node
     1208                  if (delta_node != tip) {
     1209                    for (u = tip; u != delta_node; u = pred[u]) {
     1210                      reached[u] = false;
     1211                    }
     1212                    tip = delta_node;
     1213                    a = _next_out[tip] + 1;
     1214                    last_out = _first_out[tip+1];
     1215                    break;
     1216                  }
     1217                }
     1218              }
     1219            }
     1220          }
     1221
     1222          // Step back to the previous node
     1223          if (a == last_out) {
     1224            processed[tip] = true;
     1225            stack[++stack_top] = tip;
     1226            tip = pred[tip];
     1227            if (tip < 0) {
     1228              // Finish DFS from the current start node
     1229              break;
     1230            }
     1231            ++_next_out[tip];
     1232          }
     1233        }
     1234
     1235      }
     1236
     1237      return (cycle_cnt == 0);
    9961238    }
    9971239
    9981240    // Global potential update heuristic
    9991241    void globalUpdate() {
    1000       int bucket_end = _root + 1;
     1242      const int bucket_end = _root + 1;
    10011243
    10021244      // Initialize buckets
     
    10051247      }
    10061248      Value total_excess = 0;
     1249      int b0 = bucket_end;
    10071250      for (int i = 0; i != _res_node_num; ++i) {
    10081251        if (_excess[i] < 0) {
    10091252          _rank[i] = 0;
    1010           _bucket_next[i] = _buckets[0];
    1011           _bucket_prev[_buckets[0]] = i;
    1012           _buckets[0] = i;
     1253          _bucket_next[i] = b0;
     1254          _bucket_prev[b0] = i;
     1255          b0 = i;
    10131256        } else {
    10141257          total_excess += _excess[i];
     
    10171260      }
    10181261      if (total_excess == 0) return;
     1262      _buckets[0] = b0;
    10191263
    10201264      // Search the buckets
     
    10381282                LargeCost nrc = (_cost[ra] + _pi[v] - pi_u) / _epsilon;
    10391283                int new_rank_v = old_rank_v;
    1040                 if (nrc < LargeCost(_max_rank))
    1041                   new_rank_v = r + 1 + int(nrc);
     1284                if (nrc < LargeCost(_max_rank)) {
     1285                  new_rank_v = r + 1 + static_cast<int>(nrc);
     1286                }
    10421287
    10431288                // Change the rank of v
     
    10511296                      _buckets[old_rank_v] = _bucket_next[v];
    10521297                    } else {
    1053                       _bucket_next[_bucket_prev[v]] = _bucket_next[v];
    1054                       _bucket_prev[_bucket_next[v]] = _bucket_prev[v];
     1298                      int pv = _bucket_prev[v], nv = _bucket_next[v];
     1299                      _bucket_next[pv] = nv;
     1300                      _bucket_prev[nv] = pv;
    10551301                    }
    10561302                  }
    10571303
    1058                   // Insert v to its new bucket
    1059                   _bucket_next[v] = _buckets[new_rank_v];
    1060                   _bucket_prev[_buckets[new_rank_v]] = v;
     1304                  // Insert v into its new bucket
     1305                  int nv = _buckets[new_rank_v];
     1306                  _bucket_next[v] = nv;
     1307                  _bucket_prev[nv] = v;
    10611308                  _buckets[new_rank_v] = v;
    10621309                }
     
    10851332
    10861333    /// Execute the algorithm performing augment and relabel operations
    1087     void startAugment(int max_length = std::numeric_limits<int>::max()) {
     1334    void startAugment(int max_length) {
    10881335      // Paramters for heuristics
    1089       const int EARLY_TERM_EPSILON_LIMIT = 1000;
    1090       const double GLOBAL_UPDATE_FACTOR = 3.0;
    1091 
    1092       const int global_update_freq = int(GLOBAL_UPDATE_FACTOR *
     1336      const int PRICE_REFINEMENT_LIMIT = 2;
     1337      const double GLOBAL_UPDATE_FACTOR = 1.0;
     1338      const int global_update_skip = static_cast<int>(GLOBAL_UPDATE_FACTOR *
    10931339        (_res_node_num + _sup_node_num * _sup_node_num));
    1094       int next_update_limit = global_update_freq;
    1095 
     1340      int next_global_update_limit = global_update_skip;
     1341
     1342      // Perform cost scaling phases
     1343      IntVector path;
     1344      BoolVector path_arc(_res_arc_num, false);
    10961345      int relabel_cnt = 0;
    1097 
    1098       // Perform cost scaling phases
    1099       std::vector<int> path;
     1346      int eps_phase_cnt = 0;
    11001347      for ( ; _epsilon >= 1; _epsilon = _epsilon < _alpha && _epsilon > 1 ?
    11011348                                        1 : _epsilon / _alpha )
    11021349      {
    1103         // Early termination heuristic
    1104         if (_epsilon <= EARLY_TERM_EPSILON_LIMIT) {
    1105           if (earlyTermination()) break;
     1350        ++eps_phase_cnt;
     1351
     1352        // Price refinement heuristic
     1353        if (eps_phase_cnt >= PRICE_REFINEMENT_LIMIT) {
     1354          if (priceRefinement()) continue;
    11061355        }
    11071356
     
    11201369
    11211370          // Find an augmenting path from the start node
    1122           path.clear();
    11231371          int tip = start;
    1124           while (_excess[tip] >= 0 && int(path.size()) < max_length) {
     1372          while (int(path.size()) < max_length && _excess[tip] >= 0) {
    11251373            int u;
    1126             LargeCost min_red_cost, rc, pi_tip = _pi[tip];
     1374            LargeCost rc, min_red_cost = std::numeric_limits<LargeCost>::max();
     1375            LargeCost pi_tip = _pi[tip];
    11271376            int last_out = _first_out[tip+1];
    11281377            for (int a = _next_out[tip]; a != last_out; ++a) {
    1129               u = _target[a];
    1130               if (_res_cap[a] > 0 && _cost[a] + pi_tip - _pi[u] < 0) {
    1131                 path.push_back(a);
    1132                 _next_out[tip] = a;
    1133                 tip = u;
    1134                 goto next_step;
     1378              if (_res_cap[a] > 0) {
     1379                u = _target[a];
     1380                rc = _cost[a] + pi_tip - _pi[u];
     1381                if (rc < 0) {
     1382                  path.push_back(a);
     1383                  _next_out[tip] = a;
     1384                  if (path_arc[a]) {
     1385                    goto augment;   // a cycle is found, stop path search
     1386                  }
     1387                  tip = u;
     1388                  path_arc[a] = true;
     1389                  goto next_step;
     1390                }
     1391                else if (rc < min_red_cost) {
     1392                  min_red_cost = rc;
     1393                }
    11351394              }
    11361395            }
    11371396
    11381397            // Relabel tip node
    1139             min_red_cost = std::numeric_limits<LargeCost>::max();
    11401398            if (tip != start) {
    11411399              int ra = _reverse[path.back()];
    1142               min_red_cost = _cost[ra] + pi_tip - _pi[_target[ra]];
     1400              min_red_cost =
     1401                std::min(min_red_cost, _cost[ra] + pi_tip - _pi[_target[ra]]);
    11431402            }
     1403            last_out = _next_out[tip];
    11441404            for (int a = _first_out[tip]; a != last_out; ++a) {
    1145               rc = _cost[a] + pi_tip - _pi[_target[a]];
    1146               if (_res_cap[a] > 0 && rc < min_red_cost) {
    1147                 min_red_cost = rc;
     1405              if (_res_cap[a] > 0) {
     1406                rc = _cost[a] + pi_tip - _pi[_target[a]];
     1407                if (rc < min_red_cost) {
     1408                  min_red_cost = rc;
     1409                }
    11481410              }
    11491411            }
     
    11541416            // Step back
    11551417            if (tip != start) {
    1156               tip = _source[path.back()];
     1418              int pa = path.back();
     1419              path_arc[pa] = false;
     1420              tip = _source[pa];
    11571421              path.pop_back();
    11581422            }
     
    11621426
    11631427          // Augment along the found path (as much flow as possible)
     1428        augment:
    11641429          Value delta;
    11651430          int pa, u, v = start;
     
    11681433            u = v;
    11691434            v = _target[pa];
     1435            path_arc[pa] = false;
    11701436            delta = std::min(_res_cap[pa], _excess[u]);
    11711437            _res_cap[pa] -= delta;
     
    11731439            _excess[u] -= delta;
    11741440            _excess[v] += delta;
    1175             if (_excess[v] > 0 && _excess[v] <= delta)
     1441            if (_excess[v] > 0 && _excess[v] <= delta) {
    11761442              _active_nodes.push_back(v);
    1177           }
     1443            }
     1444          }
     1445          path.clear();
    11781446
    11791447          // Global update heuristic
    1180           if (relabel_cnt >= next_update_limit) {
     1448          if (relabel_cnt >= next_global_update_limit) {
    11811449            globalUpdate();
    1182             next_update_limit += global_update_freq;
    1183           }
    1184         }
    1185       }
     1450            next_global_update_limit += global_update_skip;
     1451          }
     1452        }
     1453
     1454      }
     1455
    11861456    }
    11871457
     
    11891459    void startPush() {
    11901460      // Paramters for heuristics
    1191       const int EARLY_TERM_EPSILON_LIMIT = 1000;
     1461      const int PRICE_REFINEMENT_LIMIT = 2;
    11921462      const double GLOBAL_UPDATE_FACTOR = 2.0;
    11931463
    1194       const int global_update_freq = int(GLOBAL_UPDATE_FACTOR *
     1464      const int global_update_skip = static_cast<int>(GLOBAL_UPDATE_FACTOR *
    11951465        (_res_node_num + _sup_node_num * _sup_node_num));
    1196       int next_update_limit = global_update_freq;
    1197 
    1198       int relabel_cnt = 0;
     1466      int next_global_update_limit = global_update_skip;
    11991467
    12001468      // Perform cost scaling phases
    12011469      BoolVector hyper(_res_node_num, false);
    12021470      LargeCostVector hyper_cost(_res_node_num);
     1471      int relabel_cnt = 0;
     1472      int eps_phase_cnt = 0;
    12031473      for ( ; _epsilon >= 1; _epsilon = _epsilon < _alpha && _epsilon > 1 ?
    12041474                                        1 : _epsilon / _alpha )
    12051475      {
    1206         // Early termination heuristic
    1207         if (_epsilon <= EARLY_TERM_EPSILON_LIMIT) {
    1208           if (earlyTermination()) break;
     1476        ++eps_phase_cnt;
     1477
     1478        // Price refinement heuristic
     1479        if (eps_phase_cnt >= PRICE_REFINEMENT_LIMIT) {
     1480          if (priceRefinement()) continue;
    12091481        }
    12101482
     
    12781550               std::numeric_limits<LargeCost>::max();
    12791551            for (int a = _first_out[n]; a != last_out; ++a) {
    1280               rc = _cost[a] + pi_n - _pi[_target[a]];
    1281               if (_res_cap[a] > 0 && rc < min_red_cost) {
    1282                 min_red_cost = rc;
     1552              if (_res_cap[a] > 0) {
     1553                rc = _cost[a] + pi_n - _pi[_target[a]];
     1554                if (rc < min_red_cost) {
     1555                  min_red_cost = rc;
     1556                }
    12831557              }
    12841558            }
     
    12981572
    12991573          // Global update heuristic
    1300           if (relabel_cnt >= next_update_limit) {
     1574          if (relabel_cnt >= next_global_update_limit) {
    13011575            globalUpdate();
    13021576            for (int u = 0; u != _res_node_num; ++u)
    13031577              hyper[u] = false;
    1304             next_update_limit += global_update_freq;
     1578            next_global_update_limit += global_update_skip;
    13051579          }
    13061580        }
  • lemon/cplex.cc

    r877 r1016  
    4141    int status;
    4242    _cnt = new int;
     43    (*_cnt) = 1;
    4344    _env = CPXopenCPLEX(&status);
    4445    if (_env == 0) {
     
    471472    int status;
    472473    _prob = CPXcreateprob(cplexEnv(), &status, "Cplex problem");
    473     rows.clear();
    474     cols.clear();
    475474  }
    476475
  • lemon/cycle_canceling.h

    r877 r1013  
    3636#include <lemon/bellman_ford.h>
    3737#include <lemon/howard_mmc.h>
     38#include <lemon/hartmann_orlin_mmc.h>
    3839
    3940namespace lemon {
     
    4950  /// \ref amo93networkflows, \ref klein67primal,
    5051  /// \ref goldberg89cyclecanceling.
    51   /// The most efficent one (both theoretically and practically)
    52   /// is the \ref CANCEL_AND_TIGHTEN "Cancel and Tighten" algorithm,
    53   /// thus it is the default method.
    54   /// It is strongly polynomial, but in practice, it is typically much
    55   /// slower than the scaling algorithms and NetworkSimplex.
     52  /// The most efficent one is the \ref CANCEL_AND_TIGHTEN
     53  /// "Cancel-and-Tighten" algorithm, thus it is the default method.
     54  /// It runs in strongly polynomial time, but in practice, it is typically
     55  /// orders of magnitude slower than the scaling algorithms and
     56  /// \ref NetworkSimplex.
     57  /// (For more information, see \ref min_cost_flow_algs "the module page".)
    5658  ///
    5759  /// Most of the parameters of the problem (except for the digraph)
     
    6668  /// algorithm. By default, it is the same as \c V.
    6769  ///
    68   /// \warning Both number types must be signed and all input data must
     70  /// \warning Both \c V and \c C must be signed number types.
     71  /// \warning All input data (capacities, supply values, and costs) must
    6972  /// be integer.
    70   /// \warning This algorithm does not support negative costs for such
    71   /// arcs that have infinite upper bound.
     73  /// \warning This algorithm does not support negative costs for
     74  /// arcs having infinite upper bound.
    7275  ///
    7376  /// \note For more information about the three available methods,
     
    116119    ///
    117120    /// \ref CycleCanceling provides three different cycle-canceling
    118     /// methods. By default, \ref CANCEL_AND_TIGHTEN "Cancel and Tighten"
    119     /// is used, which proved to be the most efficient and the most robust
    120     /// on various test inputs.
     121    /// methods. By default, \ref CANCEL_AND_TIGHTEN "Cancel-and-Tighten"
     122    /// is used, which is by far the most efficient and the most robust.
    121123    /// However, the other methods can be selected using the \ref run()
    122124    /// function with the proper parameter.
    123125    enum Method {
    124126      /// A simple cycle-canceling method, which uses the
    125       /// \ref BellmanFord "Bellman-Ford" algorithm with limited iteration
    126       /// number for detecting negative cycles in the residual network.
     127      /// \ref BellmanFord "Bellman-Ford" algorithm for detecting negative
     128      /// cycles in the residual network.
     129      /// The number of Bellman-Ford iterations is bounded by a successively
     130      /// increased limit.
    127131      SIMPLE_CYCLE_CANCELING,
    128132      /// The "Minimum Mean Cycle-Canceling" algorithm, which is a
     
    130134      /// \ref goldberg89cyclecanceling. It improves along a
    131135      /// \ref min_mean_cycle "minimum mean cycle" in each iteration.
    132       /// Its running time complexity is O(n<sup>2</sup>m<sup>3</sup>log(n)).
     136      /// Its running time complexity is O(n<sup>2</sup>e<sup>3</sup>log(n)).
    133137      MINIMUM_MEAN_CYCLE_CANCELING,
    134       /// The "Cancel And Tighten" algorithm, which can be viewed as an
     138      /// The "Cancel-and-Tighten" algorithm, which can be viewed as an
    135139      /// improved version of the previous method
    136140      /// \ref goldberg89cyclecanceling.
    137141      /// It is faster both in theory and in practice, its running time
    138       /// complexity is O(n<sup>2</sup>m<sup>2</sup>log(n)).
     142      /// complexity is O(n<sup>2</sup>e<sup>2</sup>log(n)).
    139143      CANCEL_AND_TIGHTEN
    140144    };
     
    350354    ///
    351355    /// Using this function has the same effect as using \ref supplyMap()
    352     /// with such a map in which \c k is assigned to \c s, \c -k is
     356    /// with a map in which \c k is assigned to \c s, \c -k is
    353357    /// assigned to \c t and all other nodes have zero supply value.
    354358    ///
     
    611615    }
    612616
    613     /// \brief Return the flow map (the primal solution).
     617    /// \brief Copy the flow values (the primal solution) into the
     618    /// given map.
    614619    ///
    615620    /// This function copies the flow value on each arc into the given
     
    635640    }
    636641
    637     /// \brief Return the potential map (the dual solution).
     642    /// \brief Copy the potential values (the dual solution) into the
     643    /// given map.
    638644    ///
    639645    /// This function copies the potential (dual value) of each node
     
    923929    // Execute the "Minimum Mean Cycle Canceling" method
    924930    void startMinMeanCycleCanceling() {
    925       typedef SimplePath<StaticDigraph> SPath;
     931      typedef Path<StaticDigraph> SPath;
    926932      typedef typename SPath::ArcIt SPathArcIt;
    927933      typedef typename HowardMmc<StaticDigraph, CostArcMap>
    928         ::template SetPath<SPath>::Create MMC;
     934        ::template SetPath<SPath>::Create HwMmc;
     935      typedef typename HartmannOrlinMmc<StaticDigraph, CostArcMap>
     936        ::template SetPath<SPath>::Create HoMmc;
     937
     938      const double HW_ITER_LIMIT_FACTOR = 1.0;
     939      const int HW_ITER_LIMIT_MIN_VALUE = 5;
     940
     941      const int hw_iter_limit =
     942          std::max(static_cast<int>(HW_ITER_LIMIT_FACTOR * _node_num),
     943                   HW_ITER_LIMIT_MIN_VALUE);
    929944
    930945      SPath cycle;
    931       MMC mmc(_sgr, _cost_map);
    932       mmc.cycle(cycle);
     946      HwMmc hw_mmc(_sgr, _cost_map);
     947      hw_mmc.cycle(cycle);
    933948      buildResidualNetwork();
    934       while (mmc.findCycleMean() && mmc.cycleCost() < 0) {
    935         // Find the cycle
    936         mmc.findCycle();
    937 
     949      while (true) {
     950       
     951        typename HwMmc::TerminationCause hw_tc =
     952            hw_mmc.findCycleMean(hw_iter_limit);
     953        if (hw_tc == HwMmc::ITERATION_LIMIT) {
     954          // Howard's algorithm reached the iteration limit, start a
     955          // strongly polynomial algorithm instead
     956          HoMmc ho_mmc(_sgr, _cost_map);
     957          ho_mmc.cycle(cycle);
     958          // Find a minimum mean cycle (Hartmann-Orlin algorithm)
     959          if (!(ho_mmc.findCycleMean() && ho_mmc.cycleCost() < 0)) break;
     960          ho_mmc.findCycle();
     961        } else {
     962          // Find a minimum mean cycle (Howard algorithm)
     963          if (!(hw_tc == HwMmc::OPTIMAL && hw_mmc.cycleCost() < 0)) break;
     964          hw_mmc.findCycle();
     965        }
     966       
    938967        // Compute delta value
    939968        Value delta = INF;
     
    955984    }
    956985
    957     // Execute the "Cancel And Tighten" method
     986    // Execute the "Cancel-and-Tighten" method
    958987    void startCancelAndTighten() {
    959988      // Constants for the min mean cycle computations
    960989      const double LIMIT_FACTOR = 1.0;
    961990      const int MIN_LIMIT = 5;
     991      const double HW_ITER_LIMIT_FACTOR = 1.0;
     992      const int HW_ITER_LIMIT_MIN_VALUE = 5;
     993
     994      const int hw_iter_limit =
     995          std::max(static_cast<int>(HW_ITER_LIMIT_FACTOR * _node_num),
     996                   HW_ITER_LIMIT_MIN_VALUE);
    962997
    963998      // Contruct auxiliary data vectors
     
    11331168          }
    11341169        } else {
    1135           typedef HowardMmc<StaticDigraph, CostArcMap> MMC;
     1170          typedef HowardMmc<StaticDigraph, CostArcMap> HwMmc;
     1171          typedef HartmannOrlinMmc<StaticDigraph, CostArcMap> HoMmc;
    11361172          typedef typename BellmanFord<StaticDigraph, CostArcMap>
    11371173            ::template SetDistMap<CostNodeMap>::Create BF;
    11381174
    11391175          // Set epsilon to the minimum cycle mean
     1176          Cost cycle_cost = 0;
     1177          int cycle_size = 1;
    11401178          buildResidualNetwork();
    1141           MMC mmc(_sgr, _cost_map);
    1142           mmc.findCycleMean();
    1143           epsilon = -mmc.cycleMean();
    1144           Cost cycle_cost = mmc.cycleCost();
    1145           int cycle_size = mmc.cycleSize();
     1179          HwMmc hw_mmc(_sgr, _cost_map);
     1180          if (hw_mmc.findCycleMean(hw_iter_limit) == HwMmc::ITERATION_LIMIT) {
     1181            // Howard's algorithm reached the iteration limit, start a
     1182            // strongly polynomial algorithm instead
     1183            HoMmc ho_mmc(_sgr, _cost_map);
     1184            ho_mmc.findCycleMean();
     1185            epsilon = -ho_mmc.cycleMean();
     1186            cycle_cost = ho_mmc.cycleCost();
     1187            cycle_size = ho_mmc.cycleSize();
     1188          } else {
     1189            // Set epsilon
     1190            epsilon = -hw_mmc.cycleMean();
     1191            cycle_cost = hw_mmc.cycleCost();
     1192            cycle_size = hw_mmc.cycleSize();
     1193          }
    11461194
    11471195          // Compute feasible potentials for the current epsilon
  • lemon/dfs.h

    r907 r1000  
    11941194      }
    11951195      _Visitor& visitor;
     1196      Constraints() {}
    11961197    };
    11971198  };
  • lemon/euler.h

    r877 r919  
    3737  ///Euler tour iterator for digraphs.
    3838
    39   /// \ingroup graph_prop
     39  /// \ingroup graph_properties
    4040  ///This iterator provides an Euler tour (Eulerian circuit) of a \e directed
    4141  ///graph (if there exists) and it converts to the \c Arc type of the digraph.
  • lemon/full_graph.h

    r877 r1025  
    622622  };
    623623
     624  class FullBpGraphBase {
     625
     626  protected:
     627
     628    int _red_num, _blue_num;
     629    int _node_num, _edge_num;
     630
     631  public:
     632
     633    typedef FullBpGraphBase Graph;
     634
     635    class Node;
     636    class Arc;
     637    class Edge;
     638
     639    class Node {
     640      friend class FullBpGraphBase;
     641    protected:
     642
     643      int _id;
     644      explicit Node(int id) { _id = id;}
     645
     646    public:
     647      Node() {}
     648      Node (Invalid) { _id = -1; }
     649      bool operator==(const Node& node) const {return _id == node._id;}
     650      bool operator!=(const Node& node) const {return _id != node._id;}
     651      bool operator<(const Node& node) const {return _id < node._id;}
     652    };
     653
     654    class RedNode : public Node {
     655      friend class FullBpGraphBase;
     656    protected:
     657
     658      explicit RedNode(int pid) : Node(pid) {}
     659
     660    public:
     661      RedNode() {}
     662      RedNode(const RedNode& node) : Node(node) {}
     663      RedNode(Invalid) : Node(INVALID){}
     664    };
     665
     666    class BlueNode : public Node {
     667      friend class FullBpGraphBase;
     668    protected:
     669
     670      explicit BlueNode(int pid) : Node(pid) {}
     671
     672    public:
     673      BlueNode() {}
     674      BlueNode(const BlueNode& node) : Node(node) {}
     675      BlueNode(Invalid) : Node(INVALID){}
     676    };
     677
     678    class Edge {
     679      friend class FullBpGraphBase;
     680    protected:
     681
     682      int _id;
     683      explicit Edge(int id) { _id = id;}
     684
     685    public:
     686      Edge() {}
     687      Edge (Invalid) { _id = -1; }
     688      bool operator==(const Edge& arc) const {return _id == arc._id;}
     689      bool operator!=(const Edge& arc) const {return _id != arc._id;}
     690      bool operator<(const Edge& arc) const {return _id < arc._id;}
     691    };
     692
     693    class Arc {
     694      friend class FullBpGraphBase;
     695    protected:
     696
     697      int _id;
     698      explicit Arc(int id) { _id = id;}
     699
     700    public:
     701      operator Edge() const {
     702        return _id != -1 ? edgeFromId(_id / 2) : INVALID;
     703      }
     704
     705      Arc() {}
     706      Arc (Invalid) { _id = -1; }
     707      bool operator==(const Arc& arc) const {return _id == arc._id;}
     708      bool operator!=(const Arc& arc) const {return _id != arc._id;}
     709      bool operator<(const Arc& arc) const {return _id < arc._id;}
     710    };
     711
     712
     713  protected:
     714
     715    FullBpGraphBase()
     716      : _red_num(0), _blue_num(0), _node_num(0), _edge_num(0) {}
     717
     718    void construct(int redNum, int blueNum) {
     719      _red_num = redNum; _blue_num = blueNum;
     720      _node_num = redNum + blueNum; _edge_num = redNum * blueNum;
     721    }
     722
     723  public:
     724
     725    typedef True NodeNumTag;
     726    typedef True EdgeNumTag;
     727    typedef True ArcNumTag;
     728
     729    int nodeNum() const { return _node_num; }
     730    int redNum() const { return _red_num; }
     731    int blueNum() const { return _blue_num; }
     732    int edgeNum() const { return _edge_num; }
     733    int arcNum() const { return 2 * _edge_num; }
     734
     735    int maxNodeId() const { return _node_num - 1; }
     736    int maxRedId() const { return _red_num - 1; }
     737    int maxBlueId() const { return _blue_num - 1; }
     738    int maxEdgeId() const { return _edge_num - 1; }
     739    int maxArcId() const { return 2 * _edge_num - 1; }
     740
     741    bool red(Node n) const { return n._id < _red_num; }
     742    bool blue(Node n) const { return n._id >= _red_num; }
     743
     744    static RedNode asRedNodeUnsafe(Node n) { return RedNode(n._id); }
     745    static BlueNode asBlueNodeUnsafe(Node n) { return BlueNode(n._id); }
     746
     747    Node source(Arc a) const {
     748      if (a._id & 1) {
     749        return Node((a._id >> 1) % _red_num);
     750      } else {
     751        return Node((a._id >> 1) / _red_num + _red_num);
     752      }
     753    }
     754    Node target(Arc a) const {
     755      if (a._id & 1) {
     756        return Node((a._id >> 1) / _red_num + _red_num);
     757      } else {
     758        return Node((a._id >> 1) % _red_num);
     759      }
     760    }
     761
     762    RedNode redNode(Edge e) const {
     763      return RedNode(e._id % _red_num);
     764    }
     765    BlueNode blueNode(Edge e) const {
     766      return BlueNode(e._id / _red_num + _red_num);
     767    }
     768
     769    static bool direction(Arc a) {
     770      return (a._id & 1) == 1;
     771    }
     772
     773    static Arc direct(Edge e, bool d) {
     774      return Arc(e._id * 2 + (d ? 1 : 0));
     775    }
     776
     777    void first(Node& node) const {
     778      node._id = _node_num - 1;
     779    }
     780
     781    static void next(Node& node) {
     782      --node._id;
     783    }
     784
     785    void first(RedNode& node) const {
     786      node._id = _red_num - 1;
     787    }
     788
     789    static void next(RedNode& node) {
     790      --node._id;
     791    }
     792
     793    void first(BlueNode& node) const {
     794      if (_red_num == _node_num) node._id = -1;
     795      else node._id = _node_num - 1;
     796    }
     797
     798    void next(BlueNode& node) const {
     799      if (node._id == _red_num) node._id = -1;
     800      else --node._id;
     801    }
     802
     803    void first(Arc& arc) const {
     804      arc._id = 2 * _edge_num - 1;
     805    }
     806
     807    static void next(Arc& arc) {
     808      --arc._id;
     809    }
     810
     811    void first(Edge& arc) const {
     812      arc._id = _edge_num - 1;
     813    }
     814
     815    static void next(Edge& arc) {
     816      --arc._id;
     817    }
     818
     819    void firstOut(Arc &a, const Node& v) const {
     820      if (v._id < _red_num) {
     821        a._id = 2 * (v._id + _red_num * (_blue_num - 1)) + 1;
     822      } else {
     823        a._id = 2 * (_red_num - 1 + _red_num * (v._id - _red_num));
     824      }
     825    }
     826    void nextOut(Arc &a) const {
     827      if (a._id & 1) {
     828        a._id -= 2 * _red_num;
     829        if (a._id < 0) a._id = -1;
     830      } else {
     831        if (a._id % (2 * _red_num) == 0) a._id = -1;
     832        else a._id -= 2;
     833      }
     834    }
     835
     836    void firstIn(Arc &a, const Node& v) const {
     837      if (v._id < _red_num) {
     838        a._id = 2 * (v._id + _red_num * (_blue_num - 1));
     839      } else {
     840        a._id = 2 * (_red_num - 1 + _red_num * (v._id - _red_num)) + 1;
     841      }
     842    }
     843    void nextIn(Arc &a) const {
     844      if (a._id & 1) {
     845        if (a._id % (2 * _red_num) == 1) a._id = -1;
     846        else a._id -= 2;
     847      } else {
     848        a._id -= 2 * _red_num;
     849        if (a._id < 0) a._id = -1;
     850      }
     851    }
     852
     853    void firstInc(Edge &e, bool& d, const Node& v) const {
     854      if (v._id < _red_num) {
     855        d = true;
     856        e._id = v._id + _red_num * (_blue_num - 1);
     857      } else {
     858        d = false;
     859        e._id = _red_num - 1 + _red_num * (v._id - _red_num);
     860      }
     861    }
     862    void nextInc(Edge &e, bool& d) const {
     863      if (d) {
     864        e._id -= _red_num;
     865        if (e._id < 0) e._id = -1;
     866      } else {
     867        if (e._id % _red_num == 0) e._id = -1;
     868        else --e._id;
     869      }
     870    }
     871
     872    static int id(const Node& v) { return v._id; }
     873    int id(const RedNode& v) const { return v._id; }
     874    int id(const BlueNode& v) const { return v._id - _red_num; }
     875    static int id(Arc e) { return e._id; }
     876    static int id(Edge e) { return e._id; }
     877   
     878    static Node nodeFromId(int id) { return Node(id);}
     879    static Arc arcFromId(int id) { return Arc(id);}
     880    static Edge edgeFromId(int id) { return Edge(id);}
     881
     882    bool valid(Node n) const {
     883      return n._id >= 0 && n._id < _node_num;
     884    }
     885    bool valid(Arc a) const {
     886      return a._id >= 0 && a._id < 2 * _edge_num;
     887    }
     888    bool valid(Edge e) const {
     889      return e._id >= 0 && e._id < _edge_num;
     890    }
     891
     892    RedNode redNode(int index) const {
     893      return RedNode(index);
     894    }
     895
     896    int index(RedNode n) const {
     897      return n._id;
     898    }
     899
     900    BlueNode blueNode(int index) const {
     901      return BlueNode(index + _red_num);
     902    }
     903
     904    int index(BlueNode n) const {
     905      return n._id - _red_num;
     906    }
     907       
     908    void clear() {
     909      _red_num = 0; _blue_num = 0;
     910      _node_num = 0; _edge_num = 0;
     911    }
     912
     913    Edge edge(const Node& u, const Node& v) const {
     914      if (u._id < _red_num) {
     915        if (v._id < _red_num) {
     916          return Edge(-1);
     917        } else {
     918          return Edge(u._id + _red_num * (v._id - _red_num));
     919        }
     920      } else {
     921        if (v._id < _red_num) {
     922          return Edge(v._id + _red_num * (u._id - _red_num));
     923        } else {
     924          return Edge(-1);
     925        }
     926      }
     927    }
     928
     929    Arc arc(const Node& u, const Node& v) const {
     930      if (u._id < _red_num) {
     931        if (v._id < _red_num) {
     932          return Arc(-1);
     933        } else {
     934          return Arc(2 * (u._id + _red_num * (v._id - _red_num)) + 1);
     935        }
     936      } else {
     937        if (v._id < _red_num) {
     938          return Arc(2 * (v._id + _red_num * (u._id - _red_num)));
     939        } else {
     940          return Arc(-1);
     941        }
     942      }
     943    }
     944
     945    typedef True FindEdgeTag;
     946    typedef True FindArcTag;
     947
     948    Edge findEdge(Node u, Node v, Edge prev = INVALID) const {
     949      return prev != INVALID ? INVALID : edge(u, v);
     950    }
     951
     952    Arc findArc(Node s, Node t, Arc prev = INVALID) const {
     953      return prev != INVALID ? INVALID : arc(s, t);
     954    }
     955
     956  };
     957
     958  typedef BpGraphExtender<FullBpGraphBase> ExtendedFullBpGraphBase;
     959
     960  /// \ingroup graphs
     961  ///
     962  /// \brief An undirected full bipartite graph class.
     963  ///
     964  /// FullBpGraph is a simple and fast implmenetation of undirected
     965  /// full bipartite graphs. It contains an edge between every
     966  /// red-blue pairs of nodes, therefore the number of edges is
     967  /// <tt>nr*nb</tt>.  This class is completely static and it needs
     968  /// constant memory space.  Thus you can neither add nor delete
     969  /// nodes or edges, however the structure can be resized using
     970  /// resize().
     971  ///
     972  /// This type fully conforms to the \ref concepts::BpGraph "BpGraph concept".
     973  /// Most of its member functions and nested classes are documented
     974  /// only in the concept class.
     975  ///
     976  /// This class provides constant time counting for nodes, edges and arcs.
     977  ///
     978  /// \sa FullGraph
     979  class FullBpGraph : public ExtendedFullBpGraphBase {
     980  public:
     981
     982    typedef ExtendedFullBpGraphBase Parent;
     983
     984    /// \brief Default constructor.
     985    ///
     986    /// Default constructor. The number of nodes and edges will be zero.
     987    FullBpGraph() { construct(0, 0); }
     988
     989    /// \brief Constructor
     990    ///
     991    /// Constructor.
     992    /// \param redNum The number of the red nodes.
     993    /// \param blueNum The number of the blue nodes.
     994    FullBpGraph(int redNum, int blueNum) { construct(redNum, blueNum); }
     995
     996    /// \brief Resizes the graph
     997    ///
     998    /// This function resizes the graph. It fully destroys and
     999    /// rebuilds the structure, therefore the maps of the graph will be
     1000    /// reallocated automatically and the previous values will be lost.
     1001    void resize(int redNum, int blueNum) {
     1002      Parent::notifier(Arc()).clear();
     1003      Parent::notifier(Edge()).clear();
     1004      Parent::notifier(Node()).clear();
     1005      Parent::notifier(BlueNode()).clear();
     1006      Parent::notifier(RedNode()).clear();
     1007      construct(redNum, blueNum);
     1008      Parent::notifier(RedNode()).build();
     1009      Parent::notifier(BlueNode()).build();
     1010      Parent::notifier(Node()).build();
     1011      Parent::notifier(Edge()).build();
     1012      Parent::notifier(Arc()).build();
     1013    }
     1014
     1015    using Parent::redNode;
     1016    using Parent::blueNode;
     1017
     1018    /// \brief Returns the red node with the given index.
     1019    ///
     1020    /// Returns the red node with the given index. Since this
     1021    /// structure is completely static, the red nodes can be indexed
     1022    /// with integers from the range <tt>[0..redNum()-1]</tt>.
     1023    /// \sa redIndex()
     1024    RedNode redNode(int index) const { return Parent::redNode(index); }
     1025
     1026    /// \brief Returns the index of the given red node.
     1027    ///
     1028    /// Returns the index of the given red node. Since this structure
     1029    /// is completely static, the red nodes can be indexed with
     1030    /// integers from the range <tt>[0..redNum()-1]</tt>.
     1031    ///
     1032    /// \sa operator()()
     1033    int index(RedNode node) const { return Parent::index(node); }
     1034
     1035    /// \brief Returns the blue node with the given index.
     1036    ///
     1037    /// Returns the blue node with the given index. Since this
     1038    /// structure is completely static, the blue nodes can be indexed
     1039    /// with integers from the range <tt>[0..blueNum()-1]</tt>.
     1040    /// \sa blueIndex()
     1041    BlueNode blueNode(int index) const { return Parent::blueNode(index); }
     1042
     1043    /// \brief Returns the index of the given blue node.
     1044    ///
     1045    /// Returns the index of the given blue node. Since this structure
     1046    /// is completely static, the blue nodes can be indexed with
     1047    /// integers from the range <tt>[0..blueNum()-1]</tt>.
     1048    ///
     1049    /// \sa operator()()
     1050    int index(BlueNode node) const { return Parent::index(node); }
     1051
     1052    /// \brief Returns the edge which connects the given nodes.
     1053    ///
     1054    /// Returns the edge which connects the given nodes.
     1055    Edge edge(const Node& u, const Node& v) const {
     1056      return Parent::edge(u, v);
     1057    }
     1058
     1059    /// \brief Returns the arc which connects the given nodes.
     1060    ///
     1061    /// Returns the arc which connects the given nodes.
     1062    Arc arc(const Node& u, const Node& v) const {
     1063      return Parent::arc(u, v);
     1064    }
     1065
     1066    /// \brief Number of nodes.
     1067    int nodeNum() const { return Parent::nodeNum(); }
     1068    /// \brief Number of red nodes.
     1069    int redNum() const { return Parent::redNum(); }
     1070    /// \brief Number of blue nodes.
     1071    int blueNum() const { return Parent::blueNum(); }
     1072    /// \brief Number of arcs.
     1073    int arcNum() const { return Parent::arcNum(); }
     1074    /// \brief Number of edges.
     1075    int edgeNum() const { return Parent::edgeNum(); }
     1076  };
     1077
    6241078
    6251079} //namespace lemon
  • lemon/glpk.cc

    r877 r989  
    557557  void GlpkBase::_clear() {
    558558    glp_erase_prob(lp);
    559     rows.clear();
    560     cols.clear();
    561559  }
    562560
  • lemon/graph_to_eps.h

    r877 r998  
    223223  using T::_copyright;
    224224
    225   using T::NodeTextColorType;
     225  using typename T::NodeTextColorType;
    226226  using T::CUST_COL;
    227227  using T::DIST_COL;
  • lemon/grosso_locatelli_pullan_mc.h

    r904 r918  
    4747  ///
    4848  /// This class provides a simple but highly efficient and robust heuristic
    49   /// method that quickly finds a large clique, but not necessarily the
     49  /// method that quickly finds a quite large clique, but not necessarily the
    5050  /// largest one.
     51  /// The algorithm performs a certain number of iterations to find several
     52  /// cliques and selects the largest one among them. Various limits can be
     53  /// specified to control the running time and the effectiveness of the
     54  /// search process.
    5155  ///
    5256  /// \tparam GR The undirected graph type the algorithm runs on.
     
    8589    };
    8690
     91    /// \brief Constants for the causes of search termination.
     92    ///
     93    /// Enum type containing constants for the different causes of search
     94    /// termination. The \ref run() function returns one of these values.
     95    enum TerminationCause {
     96
     97      /// The iteration count limit is reached.
     98      ITERATION_LIMIT,
     99
     100      /// The step count limit is reached.
     101      STEP_LIMIT,
     102
     103      /// The clique size limit is reached.
     104      SIZE_LIMIT
     105    };
     106
    87107  private:
    88108
     
    94114    // Note: vector<char> is used instead of vector<bool> for efficiency reasons
    95115
     116    // The underlying graph
    96117    const GR &_graph;
    97118    IntNodeMap _id;
     
    100121    BoolMatrix _gr;
    101122    int _n;
     123   
     124    // Search options
     125    bool _delta_based_restart;
     126    int _restart_delta_limit;
     127 
     128    // Search limits
     129    int _iteration_limit;
     130    int _step_limit;
     131    int _size_limit;
    102132
    103133    // The current clique
     
    381411    GrossoLocatelliPullanMc(const GR& graph) :
    382412      _graph(graph), _id(_graph), _rnd(rnd)
    383     {}
     413    {
     414      initOptions();
     415    }
    384416
    385417    /// \brief Constructor with random seed.
     
    392424    GrossoLocatelliPullanMc(const GR& graph, int seed) :
    393425      _graph(graph), _id(_graph), _rnd(seed)
    394     {}
     426    {
     427      initOptions();
     428    }
    395429
    396430    /// \brief Constructor with random number generator.
     
    403437    GrossoLocatelliPullanMc(const GR& graph, const Random& random) :
    404438      _graph(graph), _id(_graph), _rnd(random)
    405     {}
     439    {
     440      initOptions();
     441    }
    406442
    407443    /// \name Execution Control
     444    /// The \ref run() function can be used to execute the algorithm.\n
     445    /// The functions \ref iterationLimit(int), \ref stepLimit(int), and
     446    /// \ref sizeLimit(int) can be used to specify various limits for the
     447    /// search process.
     448   
    408449    /// @{
    409 
    410     /// \brief Runs the algorithm.
    411     ///
    412     /// This function runs the algorithm.
    413     ///
    414     /// \param step_num The maximum number of node selections (steps)
    415     /// during the search process.
    416     /// This parameter controls the running time and the success of the
    417     /// algorithm. For larger values, the algorithm runs slower but it more
     450   
     451    /// \brief Sets the maximum number of iterations.
     452    ///
     453    /// This function sets the maximum number of iterations.
     454    /// Each iteration of the algorithm finds a maximal clique (but not
     455    /// necessarily the largest one) by performing several search steps
     456    /// (node selections).
     457    ///
     458    /// This limit controls the running time and the success of the
     459    /// algorithm. For larger values, the algorithm runs slower, but it more
    418460    /// likely finds larger cliques. For smaller values, the algorithm is
    419461    /// faster but probably gives worse results.
     462    ///
     463    /// The default value is \c 1000.
     464    /// \c -1 means that number of iterations is not limited.
     465    ///
     466    /// \warning You should specify a reasonable limit for the number of
     467    /// iterations and/or the number of search steps.
     468    ///
     469    /// \return <tt>(*this)</tt>
     470    ///
     471    /// \sa stepLimit(int)
     472    /// \sa sizeLimit(int)
     473    GrossoLocatelliPullanMc& iterationLimit(int limit) {
     474      _iteration_limit = limit;
     475      return *this;
     476    }
     477   
     478    /// \brief Sets the maximum number of search steps.
     479    ///
     480    /// This function sets the maximum number of elementary search steps.
     481    /// Each iteration of the algorithm finds a maximal clique (but not
     482    /// necessarily the largest one) by performing several search steps
     483    /// (node selections).
     484    ///
     485    /// This limit controls the running time and the success of the
     486    /// algorithm. For larger values, the algorithm runs slower, but it more
     487    /// likely finds larger cliques. For smaller values, the algorithm is
     488    /// faster but probably gives worse results.
     489    ///
     490    /// The default value is \c -1, which means that number of steps
     491    /// is not limited explicitly. However, the number of iterations is
     492    /// limited and each iteration performs a finite number of search steps.
     493    ///
     494    /// \warning You should specify a reasonable limit for the number of
     495    /// iterations and/or the number of search steps.
     496    ///
     497    /// \return <tt>(*this)</tt>
     498    ///
     499    /// \sa iterationLimit(int)
     500    /// \sa sizeLimit(int)
     501    GrossoLocatelliPullanMc& stepLimit(int limit) {
     502      _step_limit = limit;
     503      return *this;
     504    }
     505   
     506    /// \brief Sets the desired clique size.
     507    ///
     508    /// This function sets the desired clique size that serves as a search
     509    /// limit. If a clique of this size (or a larger one) is found, then the
     510    /// algorithm terminates.
     511    ///
     512    /// This function is especially useful if you know an exact upper bound
     513    /// for the size of the cliques in the graph or if any clique above
     514    /// a certain size limit is sufficient for your application.
     515    ///
     516    /// The default value is \c -1, which means that the size limit is set to
     517    /// the number of nodes in the graph.
     518    ///
     519    /// \return <tt>(*this)</tt>
     520    ///
     521    /// \sa iterationLimit(int)
     522    /// \sa stepLimit(int)
     523    GrossoLocatelliPullanMc& sizeLimit(int limit) {
     524      _size_limit = limit;
     525      return *this;
     526    }
     527   
     528    /// \brief The maximum number of iterations.
     529    ///
     530    /// This function gives back the maximum number of iterations.
     531    /// \c -1 means that no limit is specified.
     532    ///
     533    /// \sa iterationLimit(int)
     534    int iterationLimit() const {
     535      return _iteration_limit;
     536    }
     537   
     538    /// \brief The maximum number of search steps.
     539    ///
     540    /// This function gives back the maximum number of search steps.
     541    /// \c -1 means that no limit is specified.
     542    ///
     543    /// \sa stepLimit(int)
     544    int stepLimit() const {
     545      return _step_limit;
     546    }
     547   
     548    /// \brief The desired clique size.
     549    ///
     550    /// This function gives back the desired clique size that serves as a
     551    /// search limit. \c -1 means that this limit is set to the number of
     552    /// nodes in the graph.
     553    ///
     554    /// \sa sizeLimit(int)
     555    int sizeLimit() const {
     556      return _size_limit;
     557    }
     558
     559    /// \brief Runs the algorithm.
     560    ///
     561    /// This function runs the algorithm. If one of the specified limits
     562    /// is reached, the search process terminates.
     563    ///
    420564    /// \param rule The node selection rule. For more information, see
    421565    /// \ref SelectionRule.
    422566    ///
    423     /// \return The size of the found clique.
    424     int run(int step_num = 100000,
    425             SelectionRule rule = PENALTY_BASED)
     567    /// \return The termination cause of the search. For more information,
     568    /// see \ref TerminationCause.
     569    TerminationCause run(SelectionRule rule = PENALTY_BASED)
    426570    {
    427571      init();
    428572      switch (rule) {
    429573        case RANDOM:
    430           return start<RandomSelectionRule>(step_num);
     574          return start<RandomSelectionRule>();
    431575        case DEGREE_BASED:
    432           return start<DegreeBasedSelectionRule>(step_num);
    433         case PENALTY_BASED:
    434           return start<PenaltyBasedSelectionRule>(step_num);
    435       }
    436       return 0; // avoid warning
     576          return start<DegreeBasedSelectionRule>();
     577        default:
     578          return start<PenaltyBasedSelectionRule>();
     579      }
    437580    }
    438581
     
    440583
    441584    /// \name Query Functions
     585    /// The results of the algorithm can be obtained using these functions.\n
     586    /// The run() function must be called before using them.
     587
    442588    /// @{
    443589
     
    531677
    532678  private:
     679 
     680    // Initialize search options and limits
     681    void initOptions() {
     682      // Search options
     683      _delta_based_restart = true;
     684      _restart_delta_limit = 4;
     685     
     686      // Search limits
     687      _iteration_limit = 1000;
     688      _step_limit = -1;             // this is disabled by default
     689      _size_limit = -1;             // this is disabled by default
     690    }
    533691
    534692    // Adds a node to the current clique
     
    587745    // Executes the algorithm
    588746    template <typename SelectionRuleImpl>
    589     int start(int max_select) {
    590       // Options for the restart rule
    591       const bool delta_based_restart = true;
    592       const int restart_delta_limit = 4;
    593 
    594       if (_n == 0) return 0;
     747    TerminationCause start() {
     748      if (_n == 0) return SIZE_LIMIT;
    595749      if (_n == 1) {
    596750        _best_clique[0] = true;
    597751        _best_size = 1;
    598         return _best_size;
    599       }
    600 
    601       // Iterated local search
     752        return SIZE_LIMIT;
     753      }
     754
     755      // Iterated local search algorithm
     756      const int max_size = _size_limit >= 0 ? _size_limit : _n;
     757      const int max_restart = _iteration_limit >= 0 ?
     758        _iteration_limit : std::numeric_limits<int>::max();
     759      const int max_select = _step_limit >= 0 ?
     760        _step_limit : std::numeric_limits<int>::max();
     761
    602762      SelectionRuleImpl sel_method(*this);
    603       int select = 0;
     763      int select = 0, restart = 0;
    604764      IntVector restart_nodes;
    605 
    606       while (select < max_select) {
     765      while (select < max_select && restart < max_restart) {
    607766
    608767        // Perturbation/restart
    609         if (delta_based_restart) {
     768        restart++;
     769        if (_delta_based_restart) {
    610770          restart_nodes.clear();
    611771          for (int i = 0; i != _n; i++) {
    612             if (_delta[i] >= restart_delta_limit)
     772            if (_delta[i] >= _restart_delta_limit)
    613773              restart_nodes.push_back(i);
    614774          }
     
    664824          _best_clique = _clique;
    665825          _best_size = _size;
    666           if (_best_size == _n) return _best_size;
     826          if (_best_size >= max_size) return SIZE_LIMIT;
    667827        }
    668828        sel_method.update();
    669829      }
    670830
    671       return _best_size;
     831      return (restart >= max_restart ? ITERATION_LIMIT : STEP_LIMIT);
    672832    }
    673833
  • lemon/hartmann_orlin_mmc.h

    r879 r1002  
    9999  /// This class implements the Hartmann-Orlin algorithm for finding
    100100  /// a directed cycle of minimum mean cost in a digraph
    101   /// \ref amo93networkflows, \ref dasdan98minmeancycle.
     101  /// \ref hartmann93finding, \ref dasdan98minmeancycle.
    102102  /// It is an improved version of \ref KarpMmc "Karp"'s original algorithm,
    103103  /// it applies an efficient early termination scheme.
  • lemon/howard_mmc.h

    r877 r1012  
    9999  /// This class implements Howard's policy iteration algorithm for finding
    100100  /// a directed cycle of minimum mean cost in a digraph
    101   /// \ref amo93networkflows, \ref dasdan98minmeancycle.
     101  /// \ref dasdan98minmeancycle, \ref dasdan04experimental.
    102102  /// This class provides the most efficient algorithm for the
    103103  /// minimum mean cycle problem, though the best known theoretical
     
    150150    typedef TR Traits;
    151151
     152    /// \brief Constants for the causes of search termination.
     153    ///
     154    /// Enum type containing constants for the different causes of search
     155    /// termination. The \ref findCycleMean() function returns one of
     156    /// these values.
     157    enum TerminationCause {
     158     
     159      /// No directed cycle can be found in the digraph.
     160      NO_CYCLE = 0,
     161   
     162      /// Optimal solution (minimum cycle mean) is found.
     163      OPTIMAL = 1,
     164
     165      /// The iteration count limit is reached.
     166      ITERATION_LIMIT
     167    };
     168
    152169  private:
    153170
     
    325342    }
    326343
    327     /// \brief Find the minimum cycle mean.
     344    /// \brief Find the minimum cycle mean (or an upper bound).
    328345    ///
    329346    /// This function finds the minimum mean cost of the directed
    330     /// cycles in the digraph.
    331     ///
    332     /// \return \c true if a directed cycle exists in the digraph.
    333     bool findCycleMean() {
     347    /// cycles in the digraph (or an upper bound for it).
     348    ///
     349    /// By default, the function finds the exact minimum cycle mean,
     350    /// but an optional limit can also be specified for the number of
     351    /// iterations performed during the search process.
     352    /// The return value indicates if the optimal solution is found
     353    /// or the iteration limit is reached. In the latter case, an
     354    /// approximate solution is provided, which corresponds to a directed
     355    /// cycle whose mean cost is relatively small, but not necessarily
     356    /// minimal.
     357    ///
     358    /// \param limit  The maximum allowed number of iterations during
     359    /// the search process. Its default value implies that the algorithm
     360    /// runs until it finds the exact optimal solution.
     361    ///
     362    /// \return The termination cause of the search process.
     363    /// For more information, see \ref TerminationCause.
     364    TerminationCause findCycleMean(int limit = std::numeric_limits<int>::max()) {
    334365      // Initialize and find strongly connected components
    335366      init();
     
    337368
    338369      // Find the minimum cycle mean in the components
     370      int iter_count = 0;
     371      bool iter_limit_reached = false;
    339372      for (int comp = 0; comp < _comp_num; ++comp) {
    340373        // Find the minimum mean cycle in the current component
    341374        if (!buildPolicyGraph(comp)) continue;
    342375        while (true) {
     376          if (++iter_count > limit) {
     377            iter_limit_reached = true;
     378            break;
     379          }
    343380          findPolicyCycle();
    344381          if (!computeNodeDistances()) break;
    345382        }
     383
    346384        // Update the best cycle (global minimum mean cycle)
    347385        if ( _curr_found && (!_best_found ||
     
    352390          _best_node = _curr_node;
    353391        }
    354       }
    355       return _best_found;
     392       
     393        if (iter_limit_reached) break;
     394      }
     395
     396      if (iter_limit_reached) {
     397        return ITERATION_LIMIT;
     398      } else {
     399        return _best_found ? OPTIMAL : NO_CYCLE;
     400      }
    356401    }
    357402
  • lemon/karp_mmc.h

    r877 r1002  
    9999  /// This class implements Karp's algorithm for finding a directed
    100100  /// cycle of minimum mean cost in a digraph
    101   /// \ref amo93networkflows, \ref dasdan98minmeancycle.
     101  /// \ref karp78characterization, \ref dasdan98minmeancycle.
    102102  /// It runs in time O(ne) and uses space O(n<sup>2</sup>+e).
    103103  ///
  • lemon/kruskal.h

    r584 r921  
    3131///\file
    3232///\brief Kruskal's algorithm to compute a minimum cost spanning tree
    33 ///
    34 ///Kruskal's algorithm to compute a minimum cost spanning tree.
    35 ///
    3633
    3734namespace lemon {
  • lemon/lemon.pc.in

    r658 r981  
    1 prefix=@prefix@
    2 exec_prefix=@exec_prefix@
    3 libdir=@libdir@
    4 includedir=@includedir@
     1prefix=@CMAKE_INSTALL_PREFIX@
     2exec_prefix=@CMAKE_INSTALL_PREFIX@/bin
     3libdir=@CMAKE_INSTALL_PREFIX@/lib
     4includedir=@CMAKE_INSTALL_PREFIX@/include
    55
    6 Name: @PACKAGE_NAME@
     6Name: @PROJECT_NAME@
    77Description: Library for Efficient Modeling and Optimization in Networks
    8 Version: @PACKAGE_VERSION@
     8Version: @PROJECT_VERSION@
    99Libs: -L${libdir} -lemon @GLPK_LIBS@ @CPLEX_LIBS@ @SOPLEX_LIBS@ @CLP_LIBS@ @CBC_LIBS@
    1010Cflags: -I${includedir}
  • lemon/lgf_reader.h

    r8