Changes in / [1037:d3dcc49e6403:1038:a2d142bb5d3c] in lemon-main
- Files:
-
- 8 added
- 18 deleted
- 96 edited
Legend:
- Unmodified
- Added
- Removed
-
AUTHORS
r320 r992 1 The authors of the 1.x seriesare1 The main developers of release series 1.x are 2 2 3 3 * Balazs Dezso <deba@inf.elte.hu> … … 6 6 * Akos Ladanyi <ladanyi@tmit.bme.hu> 7 7 8 For more details on the actual contribution, please visit the history9 of the main LEMON source repository: http://lemon.cs.elte.hu/hg/lemon8 For more complete list of contributors, please visit the history of 9 the LEMON source code repository: http://lemon.cs.elte.hu/hg/lemon 10 10 11 Moreover, this version is heavily based on the 0.x series of12 LEMON. Hereis the list of people who contributed to those versions.11 Moreover, this version is heavily based on version 0.x of LEMON. Here 12 is the list of people who contributed to those versions. 13 13 14 14 * Mihaly Barasz <klao@cs.elte.hu> … … 24 24 25 25 Again, please visit the history of the old LEMON repository for more 26 details: http://lemon.cs.elte.hu/ svn/lemon/trunk26 details: http://lemon.cs.elte.hu/hg/lemon-0.x -
CMakeLists.txt
r912 r1017 13 13 ELSE() 14 14 EXECUTE_PROCESS( 15 COMMAND ${PYTHON_EXECUTABLE} ./scripts/chg-len.py 15 COMMAND 16 hg log -r. --template "{latesttag}" 16 17 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} 17 OUTPUT_VARIABLE HG_REVISION_ PATH18 OUTPUT_VARIABLE HG_REVISION_TAG 18 19 ERROR_QUIET 19 20 OUTPUT_STRIP_TRAILING_WHITESPACE 20 21 ) 21 22 EXECUTE_PROCESS( 22 COMMAND hg id -i 23 COMMAND 24 hg log -r. --template "{latesttagdistance}" 23 25 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} 24 OUTPUT_VARIABLE HG_REVISION 26 OUTPUT_VARIABLE HG_REVISION_DIST 25 27 ERROR_QUIET 26 28 OUTPUT_STRIP_TRAILING_WHITESPACE 27 29 ) 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 "") 29 40 SET(HG_REVISION_ID "hg-tip") 30 41 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}) 33 49 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}") 35 52 ENDIF() 36 53 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.") 38 56 ENDIF() 39 57 … … 52 70 ELSE() 53 71 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") 55 73 SET(CMAKE_CXX_FLAGS_DEBUG CACHE STRING "-ggdb") 56 74 SET(CMAKE_C_FLAGS_DEBUG CACHE STRING "-ggdb") … … 67 85 # C4996: 'function': was declared deprecated 68 86 ELSE() 69 SET(CXX_WARNING "-Wall -W")87 SET(CXX_WARNING "-Wall") 70 88 ENDIF() 71 89 ENDIF() … … 74 92 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LEMON_CXX_WARNING_FLAGS}") 75 93 76 SET( CMAKE_CXX_FLAGS_MAINTAINER "-Werror -ggdb" CACHE STRING 94 IF(MSVC) 95 SET( CMAKE_CXX_FLAGS_MAINTAINER "/WX ${CMAKE_CXX_FLAGS_DEBUG}" CACHE STRING 77 96 "Flags used by the C++ compiler during maintainer builds." 78 FORCE)79 SET( CMAKE_C_FLAGS_MAINTAINER "-Werror" CACHE STRING97 ) 98 SET( CMAKE_C_FLAGS_MAINTAINER "/WX ${CMAKE_CXX_FLAGS_DEBUG}" CACHE STRING 80 99 "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 ) 109 ELSE() 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 83 117 "-Wl,--warn-unresolved-symbols,--warn-once" CACHE STRING 84 118 "Flags used for linking binaries during maintainer builds." 85 FORCE)86 SET( CMAKE_SHARED_LINKER_FLAGS_MAINTAINER119 ) 120 SET( CMAKE_SHARED_LINKER_FLAGS_MAINTAINER 87 121 "-Wl,--warn-unresolved-symbols,--warn-once" CACHE STRING 88 122 "Flags used by the shared libraries linker during maintainer builds." 89 FORCE ) 123 ) 124 ENDIF() 125 90 126 MARK_AS_ADVANCED( 91 127 CMAKE_CXX_FLAGS_MAINTAINER … … 115 151 SET(LEMON_HAVE_LONG_LONG ${HAVE_LONG_LONG}) 116 152 153 INCLUDE(FindThreads) 154 155 IF(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() 163 ENDIF() 164 165 SET( LEMON_THREADING "${LEMON_THREADING}" CACHE STRING 166 "Choose the threading library, options are: Pthread Win32 None." 167 FORCE ) 168 169 IF(LEMON_THREADING STREQUAL "Pthread") 170 SET(LEMON_USE_PTHREAD TRUE) 171 ELSEIF(LEMON_THREADING STREQUAL "Win32") 172 SET(LEMON_USE_WIN32_THREADS TRUE) 173 ENDIF() 174 117 175 ENABLE_TESTING() 118 176 … … 125 183 ADD_SUBDIRECTORY(lemon) 126 184 IF(${CMAKE_SOURCE_DIR} STREQUAL ${PROJECT_SOURCE_DIR}) 185 ADD_SUBDIRECTORY(contrib) 127 186 ADD_SUBDIRECTORY(demo) 128 187 ADD_SUBDIRECTORY(tools) … … 148 207 ENDIF() 149 208 209 CONFIGURE_FILE( 210 ${PROJECT_SOURCE_DIR}/cmake/version.cmake.in 211 ${PROJECT_BINARY_DIR}/cmake/version.cmake 212 @ONLY 213 ) 214 215 SET(ARCHIVE_BASE_NAME ${CMAKE_PROJECT_NAME}) 216 STRING(TOLOWER ${ARCHIVE_BASE_NAME} ARCHIVE_BASE_NAME) 217 SET(ARCHIVE_NAME ${ARCHIVE_BASE_NAME}-${PROJECT_VERSION}) 218 ADD_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) 150 236 IF(${CMAKE_SOURCE_DIR} STREQUAL ${PROJECT_SOURCE_DIR}) 151 237 SET(CPACK_PACKAGE_NAME ${PROJECT_NAME}) -
INSTALL
r824 r992 2 2 ========================= 3 3 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/). 4 This file contains instructions for building and installing LEMON from 5 source on Linux. The process on Windows is similar. 7 6 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. 7 Note that it is not necessary to install LEMON in order to use 8 it. Instead, you can easily integrate it with your own code 9 directly. For instructions, see 10 https://lemon.cs.elte.hu/trac/lemon/wiki/HowToCompile 11 13 12 14 13 In order to install LEMON from the extracted source tarball you have to 15 14 issue the following commands: 16 15 17 1. `cd lemon-x.y.z'16 1. Step into the root of the source directory. 18 17 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 21 19 22 2. `./configure'20 2. Create a build subdirectory and step into it. 23 21 24 This command runs the configure shell script, which does some checks and25 creates the makefiles.22 $ mkdir build 23 $ cd build 26 24 27 3. `make'25 3. Perform system checks and create the makefiles. 28 26 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 .. 32 28 33 4. `make check'29 4. Build LEMON. 34 30 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 38 32 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 40 53 41 54 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' 54 61 55 62 Configure Options and Variables 56 63 =============================== 57 64 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]...' 65 In Step 3, you can customize the build process by passing options to CMAKE. 61 66 62 Below you will find some useful variables and options (see `./configure --help' 63 for more): 67 $ cmake [OPTIONS] .. 64 68 65 CXX='comp' 69 You find a list of the most useful options below. 66 70 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 75 72 76 73 Set the installation prefix to PREFIX. By default it is /usr/local. 77 74 78 - -enable-tools75 -DCMAKE_BUILD_TYPE=[Release|Debug|Maintainer|...] 79 76 80 Build the programs in the tools subdirectory (default).77 This sets the compiler options. The choices are the following 81 78 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. 83 82 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. 85 85 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. 87 90 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. 91 92 92 --with-glpk-includedir=DIR 93 'MinSizeRel': Size optimized build (-Os with gcc) 93 94 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 97 96 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. 99 99 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 103 101 104 --without-glpk 102 Change the compiler to be used. 105 103 106 Disable GLPK support. 104 -DBUILD_SHARED_LIBS=TRUE 107 105 108 --with-cplex[=PREFIX] 106 Build shared library instead of static one. Think twice if you 107 really want to use this option. 109 108 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 114 112 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. 177 114 178 115 Makefile Variables 179 116 ================== 180 117 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]...' 118 make VERBOSE=1 187 119 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 2 2 copyright/license. 3 3 4 Copyright (C) 2003-201 0Egervary Jeno Kombinatorikus Optimalizalasi4 Copyright (C) 2003-2012 Egervary Jeno Kombinatorikus Optimalizalasi 5 5 Kutatocsoport (Egervary Combinatorial Optimization Research Group, 6 6 EGRES). -
cmake/FindCOIN.cmake
r634 r973 6 6 FIND_LIBRARY(COIN_CBC_LIBRARY 7 7 NAMES Cbc libCbc 8 HINTS ${COIN_ROOT_DIR}/lib/coin 8 9 HINTS ${COIN_ROOT_DIR}/lib 9 10 ) 10 11 FIND_LIBRARY(COIN_CBC_SOLVER_LIBRARY 11 12 NAMES CbcSolver libCbcSolver 13 HINTS ${COIN_ROOT_DIR}/lib/coin 12 14 HINTS ${COIN_ROOT_DIR}/lib 13 15 ) 14 16 FIND_LIBRARY(COIN_CGL_LIBRARY 15 17 NAMES Cgl libCgl 18 HINTS ${COIN_ROOT_DIR}/lib/coin 16 19 HINTS ${COIN_ROOT_DIR}/lib 17 20 ) 18 21 FIND_LIBRARY(COIN_CLP_LIBRARY 19 22 NAMES Clp libClp 23 HINTS ${COIN_ROOT_DIR}/lib/coin 20 24 HINTS ${COIN_ROOT_DIR}/lib 21 25 ) 22 26 FIND_LIBRARY(COIN_COIN_UTILS_LIBRARY 23 27 NAMES CoinUtils libCoinUtils 28 HINTS ${COIN_ROOT_DIR}/lib/coin 24 29 HINTS ${COIN_ROOT_DIR}/lib 25 30 ) 26 31 FIND_LIBRARY(COIN_OSI_LIBRARY 27 32 NAMES Osi libOsi 33 HINTS ${COIN_ROOT_DIR}/lib/coin 28 34 HINTS ${COIN_ROOT_DIR}/lib 29 35 ) 30 36 FIND_LIBRARY(COIN_OSI_CBC_LIBRARY 31 37 NAMES OsiCbc libOsiCbc 38 HINTS ${COIN_ROOT_DIR}/lib/coin 32 39 HINTS ${COIN_ROOT_DIR}/lib 33 40 ) 34 41 FIND_LIBRARY(COIN_OSI_CLP_LIBRARY 35 42 NAMES OsiClp libOsiClp 43 HINTS ${COIN_ROOT_DIR}/lib/coin 36 44 HINTS ${COIN_ROOT_DIR}/lib 37 45 ) 38 46 FIND_LIBRARY(COIN_OSI_VOL_LIBRARY 39 47 NAMES OsiVol libOsiVol 48 HINTS ${COIN_ROOT_DIR}/lib/coin 40 49 HINTS ${COIN_ROOT_DIR}/lib 41 50 ) 42 51 FIND_LIBRARY(COIN_VOL_LIBRARY 43 52 NAMES Vol libVol 53 HINTS ${COIN_ROOT_DIR}/lib/coin 54 HINTS ${COIN_ROOT_DIR}/lib 55 ) 56 57 FIND_LIBRARY(COIN_ZLIB_LIBRARY 58 NAMES z libz 59 HINTS ${COIN_ROOT_DIR}/lib/coin 60 HINTS ${COIN_ROOT_DIR}/lib 61 ) 62 FIND_LIBRARY(COIN_BZ2_LIBRARY 63 NAMES bz2 libbz2 64 HINTS ${COIN_ROOT_DIR}/lib/coin 44 65 HINTS ${COIN_ROOT_DIR}/lib 45 66 ) … … 56 77 COIN_OSI_CBC_LIBRARY 57 78 COIN_OSI_CLP_LIBRARY 58 COIN_OSI_VOL_LIBRARY59 COIN_VOL_LIBRARY79 # COIN_OSI_VOL_LIBRARY 80 # COIN_VOL_LIBRARY 60 81 ) 61 82 62 83 IF(COIN_FOUND) 63 84 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}) 67 94 ENDIF(COIN_FOUND) 68 95 … … 79 106 COIN_OSI_VOL_LIBRARY 80 107 COIN_VOL_LIBRARY 108 COIN_ZLIB_LIBRARY 109 COIN_BZ2_LIBRARY 81 110 ) 82 111 -
cmake/FindCPLEX.cmake
r636 r972 3 3 FIND_PATH(CPLEX_INCLUDE_DIR 4 4 ilcplex/cplex.h 5 PATHS "C:/ILOG/CPLEX 91/include"6 PATHS "/opt/ilog/cplex 91/include"5 PATHS "C:/ILOG/CPLEX/include" 6 PATHS "/opt/ilog/cplex/include" 7 7 HINTS ${CPLEX_ROOT_DIR}/include 8 8 ) 9 9 FIND_LIBRARY(CPLEX_LIBRARY 10 cplex 9111 PATHS "C:/ILOG/CPLEX 91/lib/msvc7/stat_mda"12 PATHS "/opt/ilog/cplex 91/bin"10 cplex 11 PATHS "C:/ILOG/CPLEX/lib/msvc7/stat_mda" 12 PATHS "/opt/ilog/cplex/bin" 13 13 HINTS ${CPLEX_ROOT_DIR}/bin 14 HINTS ${CPLEX_ROOT_DIR}/lib 14 15 ) 15 16 … … 18 19 19 20 FIND_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 22 24 ) 23 25 -
cmake/version.cmake.in
r678 r983 1 SET(LEMON_VERSION "@ PACKAGE_VERSION@" CACHE STRING "LEMON version string.")1 SET(LEMON_VERSION "@LEMON_VERSION@" CACHE STRING "LEMON version string.") -
doc/CMakeLists.txt
r1032 r1038 11 11 @ONLY 12 12 ) 13 14 CONFIGURE_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) 21 IF(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 ) 27 ENDIF() 13 28 14 29 IF(DOXYGEN_EXECUTABLE AND PYTHONINTERP_FOUND AND GHOSTSCRIPT_EXECUTABLE) -
doc/Doxyfile.in
r912 r966 1 # Doxyfile 1. 5.91 # Doxyfile 1.7.3 2 2 3 3 #--------------------------------------------------------------------------- … … 5 5 #--------------------------------------------------------------------------- 6 6 DOXYFILE_ENCODING = UTF-8 7 PROJECT_NAME = @PACKAGE_NAME@ 8 PROJECT_NUMBER = @PACKAGE_VERSION@ 7 PROJECT_NAME = 8 PROJECT_NUMBER = 9 PROJECT_BRIEF = 10 PROJECT_LOGO = 9 11 OUTPUT_DIRECTORY = 10 12 CREATE_SUBDIRS = NO … … 30 32 OPTIMIZE_FOR_FORTRAN = NO 31 33 OPTIMIZE_OUTPUT_VHDL = NO 34 EXTENSION_MAPPING = 32 35 BUILTIN_STL_SUPPORT = YES 33 36 CPP_CLI_SUPPORT = NO … … 55 58 HIDE_SCOPE_NAMES = YES 56 59 SHOW_INCLUDE_FILES = YES 60 FORCE_LOCAL_INCLUDES = NO 57 61 INLINE_INFO = YES 58 62 SORT_MEMBER_DOCS = NO 59 63 SORT_BRIEF_DOCS = NO 64 SORT_MEMBERS_CTORS_1ST = NO 60 65 SORT_GROUP_NAMES = NO 61 66 SORT_BY_SCOPE_NAME = NO 67 STRICT_PROTO_MATCHING = NO 62 68 GENERATE_TODOLIST = YES 63 69 GENERATE_TESTLIST = YES … … 90 96 "@abs_top_srcdir@/lemon/concepts" \ 91 97 "@abs_top_srcdir@/demo" \ 98 "@abs_top_srcdir@/contrib" \ 92 99 "@abs_top_srcdir@/tools" \ 93 100 "@abs_top_srcdir@/test/test_tools.h" \ 101 "@abs_top_builddir@/doc/mainpage.dox" \ 94 102 "@abs_top_builddir@/doc/references.dox" 95 103 INPUT_ENCODING = UTF-8 … … 112 120 FILTER_PATTERNS = 113 121 FILTER_SOURCE_FILES = NO 122 FILTER_SOURCE_PATTERNS = 114 123 #--------------------------------------------------------------------------- 115 124 # configuration options related to source browsing … … 138 147 HTML_FOOTER = 139 148 HTML_STYLESHEET = 149 HTML_COLORSTYLE_HUE = 220 150 HTML_COLORSTYLE_SAT = 100 151 HTML_COLORSTYLE_GAMMA = 80 152 HTML_TIMESTAMP = YES 140 153 HTML_ALIGN_MEMBERS = YES 141 HTML_DYNAMIC_SECTIONS = NO154 HTML_DYNAMIC_SECTIONS = YES 142 155 GENERATE_DOCSET = NO 143 156 DOCSET_FEEDNAME = "Doxygen generated docs" 144 157 DOCSET_BUNDLE_ID = org.doxygen.Project 158 DOCSET_PUBLISHER_ID = org.doxygen.Publisher 159 DOCSET_PUBLISHER_NAME = Publisher 145 160 GENERATE_HTMLHELP = NO 146 161 CHM_FILE = … … 154 169 QHP_NAMESPACE = org.doxygen.Project 155 170 QHP_VIRTUAL_FOLDER = doc 171 QHP_CUST_FILTER_NAME = 172 QHP_CUST_FILTER_ATTRS = 173 QHP_SECT_FILTER_ATTRS = 156 174 QHG_LOCATION = 175 GENERATE_ECLIPSEHELP = NO 176 ECLIPSE_DOC_ID = org.doxygen.Project 157 177 DISABLE_INDEX = NO 158 178 ENUM_VALUES_PER_LINE = 4 159 179 GENERATE_TREEVIEW = NO 180 USE_INLINE_TREES = NO 160 181 TREEVIEW_WIDTH = 250 182 EXT_LINKS_IN_WINDOW = NO 161 183 FORMULA_FONTSIZE = 10 184 FORMULA_TRANSPARENT = YES 185 USE_MATHJAX = NO 186 MATHJAX_RELPATH = http://www.mathjax.org/mathjax 187 SEARCHENGINE = YES 188 SERVER_BASED_SEARCH = NO 162 189 #--------------------------------------------------------------------------- 163 190 # configuration options related to the LaTeX output … … 176 203 LATEX_BATCHMODE = NO 177 204 LATEX_HIDE_INDICES = NO 205 LATEX_SOURCE_CODE = NO 178 206 #--------------------------------------------------------------------------- 179 207 # configuration options related to the RTF output … … 224 252 SKIP_FUNCTION_MACROS = YES 225 253 #--------------------------------------------------------------------------- 226 # Options related to the search engine254 # Configuration::additions related to external references 227 255 #--------------------------------------------------------------------------- 228 256 TAGFILES = "@abs_top_builddir@/doc/libstdc++.tag = http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/ " … … 238 266 HIDE_UNDOC_RELATIONS = YES 239 267 HAVE_DOT = YES 268 DOT_NUM_THREADS = 0 240 269 DOT_FONTNAME = FreeSans 241 270 DOT_FONTSIZE = 10 … … 255 284 DOT_PATH = 256 285 DOTFILE_DIRS = 286 MSCFILE_DIRS = 257 287 DOT_GRAPH_MAX_NODES = 50 258 288 MAX_DOT_GRAPH_DEPTH = 0 … … 261 291 GENERATE_LEGEND = YES 262 292 DOT_CLEANUP = YES 263 #---------------------------------------------------------------------------264 # Configuration::additions related to the search engine265 #---------------------------------------------------------------------------266 SEARCHENGINE = NO -
doc/DoxygenLayout.xml
r316 r928 3 3 <navindex> 4 4 <tab type="mainpage" visible="yes" title=""/> 5 <tab type="modules" visible="yes" title="" />5 <tab type="modules" visible="yes" title="" intro=""/> 6 6 <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=""/> 11 11 </tab> 12 12 <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=""/> 15 15 </tab> 16 16 <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=""/> 19 19 </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=""/> 23 23 </navindex> 24 24 -
doc/coding_style.dox
r440 r919 99 99 \subsection pri-loc-var Private member variables 100 100 101 Private member variables should start with underscore 101 Private member variables should start with underscore. 102 102 103 103 \code 104 _start_with_underscore s104 _start_with_underscore 105 105 \endcode 106 106 -
doc/dirs.dox
r440 r925 32 32 documentation. 33 33 */ 34 35 /** 36 \dir contrib 37 \brief Directory for user contributed source codes. 38 39 You can place your own C++ code using LEMON into this directory, which 40 will compile to an executable along with LEMON when you build the 41 library. This is probably the easiest way of compiling short to medium 42 codes, for this does require neither a LEMON installed system-wide nor 43 adding several paths to the compiler. 44 45 Please have a look at <tt>contrib/CMakeLists.txt</tt> for 46 instruction on how to add your own files into the build process. */ 34 47 35 48 /** -
doc/groups.dox
r1036 r1038 407 407 strongly polynomial \ref klein67primal, \ref goldberg89cyclecanceling. 408 408 409 In general NetworkSimplex is the most efficient implementation, 410 but in special cases other algorithms could be faster. 409 In general, \ref NetworkSimplex and \ref CostScaling are the most efficient 410 implementations. 411 \ref NetworkSimplex is usually the fastest on relatively small graphs (up to 412 several thousands of nodes) and on dense graphs, while \ref CostScaling is 413 typically more efficient on large graphs (e.g. hundreds of thousands of 414 nodes or above), especially if they are sparse. 415 However, other algorithms could be faster in special cases. 411 416 For 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 419 These classes are intended to be used with integer-valued input data 420 (capacities, supply values, and costs), except for \ref CapacityScaling, 421 which is capable of handling real-valued arc costs (other numerical 422 data are required to be integer). 413 423 */ 414 424 … … 449 459 450 460 This group contains the algorithms for finding minimum mean cycles 451 \ref clrs01algorithms, \ref amo93networkflows.461 \ref amo93networkflows, \ref karp78characterization. 452 462 453 463 The \e minimum \e mean \e cycle \e problem is to find a directed cycle … … 465 475 466 476 LEMON 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. 469 478 - \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. 471 480 - \ref HowardMmc Howard's policy iteration algorithm 472 \ref dasdan98minmeancycle .473 474 In practice, the \ref HowardMmc "Howard" algorithm provedto be by far the481 \ref dasdan98minmeancycle, \ref dasdan04experimental. 482 483 In practice, the \ref HowardMmc "Howard" algorithm turned out to be by far the 475 484 most efficient one, though the best known theoretical bound on its running 476 485 time is exponential. … … 540 549 541 550 /** 542 @defgroup planar Planar ityEmbedding and Drawing551 @defgroup planar Planar Embedding and Drawing 543 552 @ingroup algs 544 553 \brief Algorithms for planarity checking, embedding and drawing -
doc/lgf.dox
r440 r1024 64 64 \endcode 65 65 66 The \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 68 graph. If a map is in both of these sections, then it can be used as a 69 regular 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 66 83 The \c \@arcs section is very similar to the \c \@nodes section, 67 84 it again starts with a header line describing the names of the maps, … … 79 96 \endcode 80 97 98 If there is no map in the \c \@arcs section at all, then it must be 99 indicated 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 81 109 The \c \@edges is just a synonym of \c \@arcs. The \@arcs section can 82 110 also store the edge set of an undirected graph. In such case there is 83 111 a conventional method for store arc maps in the file, if two columns 84 ha sthe same caption with \c '+' and \c '-' prefix, then these columns112 have the same caption with \c '+' and \c '-' prefix, then these columns 85 113 can be regarded as the values of an arc map. 86 114 -
doc/min_cost_flow.dox
r877 r1002 102 102 \f[ lower(uv) \leq f(uv) \leq upper(uv) \quad \forall uv\in A \f] 103 103 104 However if the sum of the supply values is zero, then these two problems104 However, if the sum of the supply values is zero, then these two problems 105 105 are equivalent. 106 106 The \ref min_cost_flow_algs "algorithms" in LEMON support the general -
doc/references.bib
r904 r1002 5 5 title = {{LEMON} -- {L}ibrary for {E}fficient {M}odeling and 6 6 {O}ptimization in {N}etworks}, 7 howpublished = {\url{http://lemon.cs.elte.hu/}}, 8 year = 2009 7 howpublished = {\url{http://lemon.cs.elte.hu/}} 9 8 } 10 9 … … 212 211 volume = 23, 213 212 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} 214 223 } 215 224 … … 226 235 } 227 236 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 228 248 229 249 %%%%% Minimum cost flow algorithms %%%%% -
lemon/CMakeLists.txt
r908 r981 5 5 6 6 CONFIGURE_FILE( 7 ${CMAKE_CURRENT_SOURCE_DIR}/config.h. cmake7 ${CMAKE_CURRENT_SOURCE_DIR}/config.h.in 8 8 ${CMAKE_CURRENT_BINARY_DIR}/config.h 9 9 ) 10 10 11 11 CONFIGURE_FILE( 12 ${CMAKE_CURRENT_SOURCE_DIR}/lemon.pc. cmake12 ${CMAKE_CURRENT_SOURCE_DIR}/lemon.pc.in 13 13 ${CMAKE_CURRENT_BINARY_DIR}/lemon.pc 14 14 @ONLY … … 58 58 TARGETS lemon 59 59 ARCHIVE DESTINATION lib 60 LIBRARY DESTINATION lib 60 61 COMPONENT library 61 62 ) -
lemon/adaptors.h
r877 r998 1372 1372 /// and edge filter maps. 1373 1373 SubGraph(GR& graph, NF& node_filter, EF& edge_filter) { 1374 initialize(graph, node_filter, edge_filter);1374 this->initialize(graph, node_filter, edge_filter); 1375 1375 } 1376 1376 … … 2278 2278 /// Creates an undirected graph from the given digraph. 2279 2279 Undirector(DGR& digraph) { 2280 initialize(digraph);2280 this->initialize(digraph); 2281 2281 } 2282 2282 -
lemon/bfs.h
r877 r976 1252 1252 } 1253 1253 _Visitor& visitor; 1254 Constraints() {} 1254 1255 }; 1255 1256 }; -
lemon/bits/alteration_notifier.h
r440 r979 24 24 25 25 #include <lemon/core.h> 26 #include <lemon/bits/lock.h> 26 27 27 28 //\ingroup graphbits … … 252 253 typedef std::list<ObserverBase*> Observers; 253 254 Observers _observers; 254 255 lemon::bits::Lock _lock; 255 256 256 257 public: … … 333 334 334 335 void attach(ObserverBase& observer) { 336 _lock.lock(); 335 337 observer._index = _observers.insert(_observers.begin(), &observer); 336 338 observer._notifier = this; 339 _lock.unlock(); 337 340 } 338 341 339 342 void detach(ObserverBase& observer) { 343 _lock.lock(); 340 344 _observers.erase(observer._index); 341 345 observer._index = _observers.end(); 342 346 observer._notifier = 0; 347 _lock.unlock(); 343 348 } 344 349 -
lemon/bits/bezier.h
r440 r997 160 160 const Point d=(a+b)/2; 161 161 const Point e=(b+c)/2; 162 const Point f=(d+e)/2;162 // const Point f=(d+e)/2; 163 163 R f1=_f(Bezier3(p1,a,d,e),_d); 164 164 R f2=_f(Bezier3(e,d,c,p4),_d); -
lemon/bits/edge_set_extender.h
r884 r1000 524 524 // Returns the base node of the iterator 525 525 Node baseNode(const IncEdgeIt &e) const { 526 return e.direction ? u(e) :v(e);526 return e.direction ? this->u(e) : this->v(e); 527 527 } 528 528 // Running node of the iterator … … 530 530 // Returns the running node of the iterator 531 531 Node runningNode(const IncEdgeIt &e) const { 532 return e.direction ? v(e) :u(e);532 return e.direction ? this->v(e) : this->u(e); 533 533 } 534 534 -
lemon/bits/graph_extender.h
r778 r1027 588 588 // Returns the base node of the iterator 589 589 Node baseNode(const IncEdgeIt &edge) const { 590 return edge._direction ? u(edge) :v(edge);590 return edge._direction ? this->u(edge) : this->v(edge); 591 591 } 592 592 // Running node of the iterator … … 594 594 // Returns the running node of the iterator 595 595 Node runningNode(const IncEdgeIt &edge) const { 596 return edge._direction ? v(edge) :u(edge);596 return edge._direction ? this->v(edge) : this->u(edge); 597 597 } 598 598 … … 747 747 }; 748 748 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 749 1330 } 750 1331 -
lemon/bits/solver_bits.h
r877 r989 45 45 void clear() { 46 46 first_item = -1; 47 last_item = -1; 47 48 first_free_item = -1; 48 49 items.clear(); -
lemon/bits/traits.h
r616 r1026 149 149 : Parent(_digraph, _value) {} 150 150 }; 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 }; 151 233 152 234 }; -
lemon/bits/windows.cc
r877 r1001 41 41 #include <unistd.h> 42 42 #include <ctime> 43 #ifndef WIN32 43 44 #include <sys/times.h> 45 #endif 44 46 #include <sys/time.h> 45 47 #endif … … 129 131 #endif 130 132 } 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 } 131 165 } 132 166 } -
lemon/bits/windows.h
r529 r979 29 29 std::string getWinFormattedDate(); 30 30 int getWinRndSeed(); 31 32 class WinLock { 33 public: 34 WinLock(); 35 ~WinLock(); 36 void lock(); 37 void unlock(); 38 private: 39 void *_repr; 40 }; 31 41 } 32 42 } -
lemon/capacity_scaling.h
r877 r1004 71 71 /// solution method. 72 72 /// 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 /// 73 78 /// Most of the parameters of the problem (except for the digraph) 74 79 /// can be given using separate functions, and the algorithm can be … … 87 92 /// consider to use the named template parameters instead. 88 93 /// 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. 93 99 #ifdef DOXYGEN 94 100 template <typename GR, typename V, typename C, typename TR> … … 423 429 /// 424 430 /// Using this function has the same effect as using \ref supplyMap() 425 /// with sucha map in which \c k is assigned to \c s, \c -k is431 /// with a map in which \c k is assigned to \c s, \c -k is 426 432 /// assigned to \c t and all other nodes have zero supply value. 427 433 /// … … 676 682 } 677 683 678 /// \brief Return the flow map (the primal solution). 684 /// \brief Copy the flow values (the primal solution) into the 685 /// given map. 679 686 /// 680 687 /// This function copies the flow value on each arc into the given … … 700 707 } 701 708 702 /// \brief Return the potential map (the dual solution). 709 /// \brief Copy the potential values (the dual solution) into the 710 /// given map. 703 711 /// 704 712 /// This function copies the potential (dual value) of each node -
lemon/cbc.cc
r746 r1000 26 26 #include <coin/OsiSolverInterface.hpp> 27 27 28 #ifdef COIN_HAS_CLP29 28 #include "coin/OsiClpSolverInterface.hpp" 30 #endif31 #ifdef COIN_HAS_OSL32 #include "coin/OsiOslSolverInterface.hpp"33 #endif34 29 35 30 #include "coin/CbcCutGenerator.hpp" … … 271 266 delete _osi_solver; 272 267 } 273 #ifdef COIN_HAS_CLP274 268 _osi_solver = new OsiClpSolverInterface(); 275 #elif COIN_HAS_OSL276 _osi_solver = new OsiOslSolverInterface();277 #else278 #error Cannot instantiate Osi solver279 #endif280 269 281 270 _osi_solver->loadFromCoinModel(*_prob); … … 329 318 _cbc_model->addCutGenerator(&flowGen, -1, "FlowCover"); 330 319 331 #ifdef COIN_HAS_CLP332 320 OsiClpSolverInterface* osiclp = 333 321 dynamic_cast<OsiClpSolverInterface*>(_cbc_model->solver()); … … 335 323 osiclp->setupForRepeatedUse(2, 0); 336 324 } 337 #endif338 325 339 326 CbcRounding heuristic1(*_cbc_model); … … 449 436 450 437 _prob = new CoinModel(); 451 rows.clear();452 cols.clear();453 438 } 454 439 -
lemon/circulation.h
r877 r998 573 573 574 574 Node act; 575 Node bact=INVALID;576 Node last_activated=INVALID;577 575 while((act=_level->highestActive())!=INVALID) { 578 576 int actlevel=(*_level)[act]; -
lemon/clp.cc
r877 r989 438 438 delete _prob; 439 439 _prob = new ClpSimplex(); 440 rows.clear();441 cols.clear();442 440 _col_names_ref.clear(); 443 441 _clear_temporals(); -
lemon/concept_check.h
r440 r997 36 36 37 37 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&) { } 38 54 39 55 ///\e -
lemon/concepts/graph.h
r877 r1018 73 73 class Graph { 74 74 private: 75 /// Graphs are \e not copy constructible. Use DigraphCopy instead.75 /// Graphs are \e not copy constructible. Use GraphCopy instead. 76 76 Graph(const Graph&) {} 77 77 /// \brief Assignment of a graph to another one is \e not allowed. 78 /// Use DigraphCopy instead.78 /// Use GraphCopy instead. 79 79 void operator=(const Graph&) {} 80 80 -
lemon/concepts/graph_components.h
r877 r1028 109 109 110 110 bool b; 111 ignore_unused_variable_warning(b); 112 111 113 b = (ia == ib) && (ia != ib); 112 114 b = (ia == INVALID) && (ib != INVALID); … … 116 118 const _GraphItem &ia; 117 119 const _GraphItem &ib; 120 Constraints() {} 118 121 }; 119 122 }; … … 175 178 176 179 const _Digraph& digraph; 180 Constraints() {} 177 181 }; 178 182 }; … … 291 295 292 296 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; 293 464 }; 294 465 … … 370 541 371 542 const _Digraph& digraph; 543 Constraints() {} 372 544 }; 373 545 }; … … 422 594 423 595 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; 424 661 }; 425 662 }; … … 490 727 _GraphItemIt it3 = it1; 491 728 _GraphItemIt it4 = INVALID; 729 ignore_unused_variable_warning(it3); 730 ignore_unused_variable_warning(it4); 492 731 493 732 it2 = ++it1; … … 499 738 } 500 739 const GR& g; 740 Constraints() {} 501 741 }; 502 742 }; … … 578 818 _GraphIncIt it3 = it1; 579 819 _GraphIncIt it4 = INVALID; 820 ignore_unused_variable_warning(it3); 821 ignore_unused_variable_warning(it4); 580 822 581 823 it2 = ++it1; … … 587 829 const Base& node; 588 830 const GR& graph; 831 Constraints() {} 589 832 }; 590 833 }; … … 763 1006 764 1007 const _Digraph& digraph; 1008 Constraints() {} 765 1009 }; 766 1010 }; … … 887 1131 888 1132 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; 889 1225 }; 890 1226 }; … … 915 1251 ArcNotifier; 916 1252 1253 mutable NodeNotifier node_notifier; 1254 mutable ArcNotifier arc_notifier; 1255 917 1256 /// \brief Return the node alteration notifier. 918 1257 /// 919 1258 /// This function gives back the node alteration notifier. 920 1259 NodeNotifier& notifier(Node) const { 921 return NodeNotifier();1260 return node_notifier; 922 1261 } 923 1262 … … 926 1265 /// This function gives back the arc alteration notifier. 927 1266 ArcNotifier& notifier(Arc) const { 928 return ArcNotifier();1267 return arc_notifier; 929 1268 } 930 1269 … … 944 1283 945 1284 const _Digraph& digraph; 1285 Constraints() {} 946 1286 }; 947 1287 }; … … 961 1301 962 1302 typedef BAS Base; 1303 typedef AlterableDigraphComponent<Base> Parent; 963 1304 typedef typename Base::Edge Edge; 964 1305 … … 968 1309 EdgeNotifier; 969 1310 1311 mutable EdgeNotifier edge_notifier; 1312 1313 using Parent::notifier; 1314 970 1315 /// \brief Return the edge alteration notifier. 971 1316 /// 972 1317 /// This function gives back the edge alteration notifier. 973 1318 EdgeNotifier& notifier(Edge) const { 974 return EdgeNotifier();1319 return edge_notifier; 975 1320 } 976 1321 … … 985 1330 986 1331 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; 987 1395 }; 988 1396 }; … … 1062 1470 const GR &g; 1063 1471 const typename GraphMap::Value &t; 1472 Constraints() {} 1064 1473 }; 1065 1474 … … 1200 1609 1201 1610 const _Digraph& digraph; 1611 Constraints() {} 1202 1612 }; 1203 1613 }; … … 1285 1695 1286 1696 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; 1287 1842 }; 1288 1843 }; … … 1329 1884 1330 1885 _Digraph& digraph; 1886 Constraints() {} 1331 1887 }; 1332 1888 }; … … 1373 1929 1374 1930 _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; 1375 1991 }; 1376 1992 }; … … 1412 2028 1413 2029 _Digraph& digraph; 2030 Constraints() {} 1414 2031 }; 1415 2032 }; … … 1451 2068 1452 2069 _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> {}; 1455 2082 1456 2083 /// \brief Skeleton class for clearable directed graphs. … … 1479 2106 1480 2107 _Digraph& digraph; 2108 Constraints() {} 1481 2109 }; 1482 2110 }; … … 1489 2117 /// This concept requires \ref AlterableGraphComponent. 1490 2118 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> {}; 1511 2129 1512 2130 } -
lemon/concepts/heap.h
r877 r976 315 315 _Heap& heap; 316 316 ItemIntMap& map; 317 Constraints() {} 317 318 }; 318 319 }; -
lemon/concepts/maps.h
r718 r997 50 50 /// Returns the value associated with the given key. 51 51 Value operator[](const Key &) const { 52 return * static_cast<Value *>(0);52 return *(static_cast<Value *>(0)+1); 53 53 } 54 54 … … 69 69 const typename _ReadMap::Key& own_key; 70 70 const _ReadMap& m; 71 Constraints() {} 71 72 }; 72 73 … … 110 111 const typename _WriteMap::Value& own_val; 111 112 _WriteMap& m; 113 Constraints() {} 112 114 }; 113 115 }; … … 130 132 /// Returns the value associated with the given key. 131 133 Value operator[](const Key &) const { 132 return *static_cast<Value *>(0); 134 Value *r = 0; 135 return *r; 133 136 } 134 137 … … 170 173 /// Returns a reference to the value associated with the given key. 171 174 Reference operator[](const Key &) { 172 return *static_cast<Value *>(0); 175 Value *r = 0; 176 return *r; 173 177 } 174 178 175 179 /// Returns a const reference to the value associated with the given key. 176 180 ConstReference operator[](const Key &) const { 177 return *static_cast<Value *>(0); 181 Value *r = 0; 182 return *r; 178 183 } 179 184 … … 206 211 typename _ReferenceMap::ConstReference own_cref; 207 212 _ReferenceMap& m; 213 Constraints() {} 208 214 }; 209 215 }; -
lemon/concepts/path.h
r785 r976 169 169 } 170 170 _Path& p; 171 PathDumperConstraints() {} 171 172 }; 172 173 … … 194 195 } 195 196 _Path& p; 197 PathDumperConstraints() {} 196 198 }; 197 199 -
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 149 149 typedef typename Graph::template EdgeMap<double> DoubleEdgeMap 150 150 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 151 194 /// \brief Function to count the items in a graph. 152 195 /// … … 200 243 } 201 244 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 202 313 // Arc counting: 203 314 … … 441 552 template <typename From, typename NodeRefMap, typename EdgeRefMap> 442 553 static void copy(const From& from, Graph &to, 443 NodeRefMap& nodeRefMap, EdgeRefMap& edgeRefMap) { 554 NodeRefMap& nodeRefMap, 555 EdgeRefMap& edgeRefMap) { 444 556 to.build(from, nodeRefMap, edgeRefMap); 445 557 } 446 558 }; 447 559 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 448 597 } 449 598 450 /// Check whether a graph is undirected.599 /// \brief Check whether a graph is undirected. 451 600 /// 452 601 /// This function returns \c true if the given graph is undirected. … … 990 1139 graphCopy(const From& from, To& to) { 991 1140 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); 992 1589 } 993 1590 … … 1258 1855 /// The Digraph type 1259 1856 typedef GR Digraph; 1260 1857 1261 1858 protected: 1262 1859 … … 1869 2466 ///a single node \c n, then \ref refresh(Node) "refresh(n)" is enough. 1870 2467 /// 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 1876 2469 { 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 1879 2495 #endif 1880 1881 };1882 1883 /// @}1884 1885 } //namespace lemon1886 1887 #endif -
lemon/cost_scaling.h
r877 r1003 98 98 /// "preflow push-relabel" algorithm for the maximum flow problem. 99 99 /// 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 /// 100 104 /// Most of the parameters of the problem (except for the digraph) 101 105 /// can be given using separate functions, and the algorithm can be … … 114 118 /// consider to use the named template parameters instead. 115 119 /// 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 117 122 /// be integer. 118 /// \warning This algorithm does not support negative costs for such119 /// arcs that haveinfinite upper bound.123 /// \warning This algorithm does not support negative costs for 124 /// arcs having infinite upper bound. 120 125 /// 121 126 /// \note %CostScaling provides three different internal methods, … … 179 184 /// relabel operation. 180 185 /// By default, the so called \ref PARTIAL_AUGMENT 181 /// "Partial Augment-Relabel" method is used, which provedto be186 /// "Partial Augment-Relabel" method is used, which turned out to be 182 187 /// the most efficient and the most robust on various test inputs. 183 188 /// However, the other methods can be selected using the \ref run() … … 234 239 }; 235 240 236 typedef StaticVectorMap<StaticDigraph::Node, LargeCost> LargeCostNodeMap;237 241 typedef StaticVectorMap<StaticDigraph::Arc, LargeCost> LargeCostArcMap; 238 242 … … 285 289 int _max_rank; 286 290 287 // Data for a StaticDigraph structure288 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 295 291 public: 296 292 … … 339 335 CostScaling(const GR& graph) : 340 336 _graph(graph), _node_id(graph), _arc_idf(graph), _arc_idb(graph), 341 _cost_map(_cost_vec), _pi_map(_pi),342 337 INF(std::numeric_limits<Value>::has_infinity ? 343 338 std::numeric_limits<Value>::infinity() : … … 448 443 /// 449 444 /// Using this function has the same effect as using \ref supplyMap() 450 /// with sucha map in which \c k is assigned to \c s, \c -k is445 /// with a map in which \c k is assigned to \c s, \c -k is 451 446 /// assigned to \c t and all other nodes have zero supply value. 452 447 /// … … 494 489 /// \param method The internal method that will be used in the 495 490 /// 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. 497 492 /// 498 493 /// \return \c INFEASIBLE if no feasible flow exists, … … 508 503 /// \see ProblemType, Method 509 504 /// \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"); 511 507 _alpha = factor; 512 508 ProblemType pt = init(); … … 572 568 } 573 569 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 /// 585 586 /// \return <tt>(*this)</tt> 587 /// 588 /// \see resetParams(), run() 586 589 CostScaling& reset() { 587 590 // Resize vectors … … 608 611 _excess.resize(_res_node_num); 609 612 _next_out.resize(_res_node_num); 610 611 _arc_vec.reserve(_res_arc_num);612 _cost_vec.reserve(_res_arc_num);613 613 614 614 // Copy the graph … … 706 706 } 707 707 708 /// \brief Return the flow map (the primal solution). 708 /// \brief Copy the flow values (the primal solution) into the 709 /// given map. 709 710 /// 710 711 /// This function copies the flow value on each arc into the given … … 730 731 } 731 732 732 /// \brief Return the potential map (the dual solution). 733 /// \brief Copy the potential values (the dual solution) into the 734 /// given map. 733 735 /// 734 736 /// This function copies the potential (dual value) of each node … … 887 889 } 888 890 889 return OPTIMAL;890 }891 892 // Execute the algorithm and transform the results893 void start(Method method) {894 // Maximum path length for partial augment895 const int MAX_PATH_LENGTH = 4;896 897 891 // Initialize data structures for buckets 898 892 _max_rank = _alpha * _res_node_num; … … 902 896 _rank.resize(_res_node_num + 1); 903 897 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 905 905 switch (method) { 906 906 case PUSH: … … 908 908 break; 909 909 case AUGMENT: 910 startAugment( );910 startAugment(_res_node_num - 1); 911 911 break; 912 912 case PARTIAL_AUGMENT: 913 startAugment(MAX_PA TH_LENGTH);913 startAugment(MAX_PARTIAL_PATH_LENGTH); 914 914 break; 915 915 } 916 916 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 } 933 974 934 975 // Handle non-zero lower bounds … … 948 989 LargeCost pi_u = _pi[u]; 949 990 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 } 957 1000 } 958 1001 } … … 970 1013 } 971 1014 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); 996 1238 } 997 1239 998 1240 // Global potential update heuristic 999 1241 void globalUpdate() { 1000 int bucket_end = _root + 1;1242 const int bucket_end = _root + 1; 1001 1243 1002 1244 // Initialize buckets … … 1005 1247 } 1006 1248 Value total_excess = 0; 1249 int b0 = bucket_end; 1007 1250 for (int i = 0; i != _res_node_num; ++i) { 1008 1251 if (_excess[i] < 0) { 1009 1252 _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; 1013 1256 } else { 1014 1257 total_excess += _excess[i]; … … 1017 1260 } 1018 1261 if (total_excess == 0) return; 1262 _buckets[0] = b0; 1019 1263 1020 1264 // Search the buckets … … 1038 1282 LargeCost nrc = (_cost[ra] + _pi[v] - pi_u) / _epsilon; 1039 1283 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 } 1042 1287 1043 1288 // Change the rank of v … … 1051 1296 _buckets[old_rank_v] = _bucket_next[v]; 1052 1297 } 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; 1055 1301 } 1056 1302 } 1057 1303 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; 1061 1308 _buckets[new_rank_v] = v; 1062 1309 } … … 1085 1332 1086 1333 /// 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) { 1088 1335 // 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 * 1093 1339 (_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); 1096 1345 int relabel_cnt = 0; 1097 1098 // Perform cost scaling phases 1099 std::vector<int> path; 1346 int eps_phase_cnt = 0; 1100 1347 for ( ; _epsilon >= 1; _epsilon = _epsilon < _alpha && _epsilon > 1 ? 1101 1348 1 : _epsilon / _alpha ) 1102 1349 { 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; 1106 1355 } 1107 1356 … … 1120 1369 1121 1370 // Find an augmenting path from the start node 1122 path.clear();1123 1371 int tip = start; 1124 while ( _excess[tip] >= 0 && int(path.size()) < max_length) {1372 while (int(path.size()) < max_length && _excess[tip] >= 0) { 1125 1373 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]; 1127 1376 int last_out = _first_out[tip+1]; 1128 1377 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 } 1135 1394 } 1136 1395 } 1137 1396 1138 1397 // Relabel tip node 1139 min_red_cost = std::numeric_limits<LargeCost>::max();1140 1398 if (tip != start) { 1141 1399 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]]); 1143 1402 } 1403 last_out = _next_out[tip]; 1144 1404 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 } 1148 1410 } 1149 1411 } … … 1154 1416 // Step back 1155 1417 if (tip != start) { 1156 tip = _source[path.back()]; 1418 int pa = path.back(); 1419 path_arc[pa] = false; 1420 tip = _source[pa]; 1157 1421 path.pop_back(); 1158 1422 } … … 1162 1426 1163 1427 // Augment along the found path (as much flow as possible) 1428 augment: 1164 1429 Value delta; 1165 1430 int pa, u, v = start; … … 1168 1433 u = v; 1169 1434 v = _target[pa]; 1435 path_arc[pa] = false; 1170 1436 delta = std::min(_res_cap[pa], _excess[u]); 1171 1437 _res_cap[pa] -= delta; … … 1173 1439 _excess[u] -= delta; 1174 1440 _excess[v] += delta; 1175 if (_excess[v] > 0 && _excess[v] <= delta) 1441 if (_excess[v] > 0 && _excess[v] <= delta) { 1176 1442 _active_nodes.push_back(v); 1177 } 1443 } 1444 } 1445 path.clear(); 1178 1446 1179 1447 // Global update heuristic 1180 if (relabel_cnt >= next_ update_limit) {1448 if (relabel_cnt >= next_global_update_limit) { 1181 1449 globalUpdate(); 1182 next_update_limit += global_update_freq; 1183 } 1184 } 1185 } 1450 next_global_update_limit += global_update_skip; 1451 } 1452 } 1453 1454 } 1455 1186 1456 } 1187 1457 … … 1189 1459 void startPush() { 1190 1460 // Paramters for heuristics 1191 const int EARLY_TERM_EPSILON_LIMIT = 1000;1461 const int PRICE_REFINEMENT_LIMIT = 2; 1192 1462 const double GLOBAL_UPDATE_FACTOR = 2.0; 1193 1463 1194 const int global_update_ freq = int(GLOBAL_UPDATE_FACTOR *1464 const int global_update_skip = static_cast<int>(GLOBAL_UPDATE_FACTOR * 1195 1465 (_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; 1199 1467 1200 1468 // Perform cost scaling phases 1201 1469 BoolVector hyper(_res_node_num, false); 1202 1470 LargeCostVector hyper_cost(_res_node_num); 1471 int relabel_cnt = 0; 1472 int eps_phase_cnt = 0; 1203 1473 for ( ; _epsilon >= 1; _epsilon = _epsilon < _alpha && _epsilon > 1 ? 1204 1474 1 : _epsilon / _alpha ) 1205 1475 { 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; 1209 1481 } 1210 1482 … … 1278 1550 std::numeric_limits<LargeCost>::max(); 1279 1551 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 } 1283 1557 } 1284 1558 } … … 1298 1572 1299 1573 // Global update heuristic 1300 if (relabel_cnt >= next_ update_limit) {1574 if (relabel_cnt >= next_global_update_limit) { 1301 1575 globalUpdate(); 1302 1576 for (int u = 0; u != _res_node_num; ++u) 1303 1577 hyper[u] = false; 1304 next_ update_limit += global_update_freq;1578 next_global_update_limit += global_update_skip; 1305 1579 } 1306 1580 } -
lemon/cplex.cc
r877 r1016 41 41 int status; 42 42 _cnt = new int; 43 (*_cnt) = 1; 43 44 _env = CPXopenCPLEX(&status); 44 45 if (_env == 0) { … … 471 472 int status; 472 473 _prob = CPXcreateprob(cplexEnv(), &status, "Cplex problem"); 473 rows.clear();474 cols.clear();475 474 } 476 475 -
lemon/cycle_canceling.h
r877 r1013 36 36 #include <lemon/bellman_ford.h> 37 37 #include <lemon/howard_mmc.h> 38 #include <lemon/hartmann_orlin_mmc.h> 38 39 39 40 namespace lemon { … … 49 50 /// \ref amo93networkflows, \ref klein67primal, 50 51 /// \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".) 56 58 /// 57 59 /// Most of the parameters of the problem (except for the digraph) … … 66 68 /// algorithm. By default, it is the same as \c V. 67 69 /// 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 69 72 /// be integer. 70 /// \warning This algorithm does not support negative costs for such71 /// arcs that haveinfinite upper bound.73 /// \warning This algorithm does not support negative costs for 74 /// arcs having infinite upper bound. 72 75 /// 73 76 /// \note For more information about the three available methods, … … 116 119 /// 117 120 /// \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. 121 123 /// However, the other methods can be selected using the \ref run() 122 124 /// function with the proper parameter. 123 125 enum Method { 124 126 /// 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. 127 131 SIMPLE_CYCLE_CANCELING, 128 132 /// The "Minimum Mean Cycle-Canceling" algorithm, which is a … … 130 134 /// \ref goldberg89cyclecanceling. It improves along a 131 135 /// \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)). 133 137 MINIMUM_MEAN_CYCLE_CANCELING, 134 /// The "Cancel AndTighten" algorithm, which can be viewed as an138 /// The "Cancel-and-Tighten" algorithm, which can be viewed as an 135 139 /// improved version of the previous method 136 140 /// \ref goldberg89cyclecanceling. 137 141 /// 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)). 139 143 CANCEL_AND_TIGHTEN 140 144 }; … … 350 354 /// 351 355 /// Using this function has the same effect as using \ref supplyMap() 352 /// with sucha map in which \c k is assigned to \c s, \c -k is356 /// with a map in which \c k is assigned to \c s, \c -k is 353 357 /// assigned to \c t and all other nodes have zero supply value. 354 358 /// … … 611 615 } 612 616 613 /// \brief Return the flow map (the primal solution). 617 /// \brief Copy the flow values (the primal solution) into the 618 /// given map. 614 619 /// 615 620 /// This function copies the flow value on each arc into the given … … 635 640 } 636 641 637 /// \brief Return the potential map (the dual solution). 642 /// \brief Copy the potential values (the dual solution) into the 643 /// given map. 638 644 /// 639 645 /// This function copies the potential (dual value) of each node … … 923 929 // Execute the "Minimum Mean Cycle Canceling" method 924 930 void startMinMeanCycleCanceling() { 925 typedef SimplePath<StaticDigraph> SPath;931 typedef Path<StaticDigraph> SPath; 926 932 typedef typename SPath::ArcIt SPathArcIt; 927 933 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); 929 944 930 945 SPath cycle; 931 MMCmmc(_sgr, _cost_map);932 mmc.cycle(cycle);946 HwMmc hw_mmc(_sgr, _cost_map); 947 hw_mmc.cycle(cycle); 933 948 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 938 967 // Compute delta value 939 968 Value delta = INF; … … 955 984 } 956 985 957 // Execute the "Cancel AndTighten" method986 // Execute the "Cancel-and-Tighten" method 958 987 void startCancelAndTighten() { 959 988 // Constants for the min mean cycle computations 960 989 const double LIMIT_FACTOR = 1.0; 961 990 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); 962 997 963 998 // Contruct auxiliary data vectors … … 1133 1168 } 1134 1169 } else { 1135 typedef HowardMmc<StaticDigraph, CostArcMap> MMC; 1170 typedef HowardMmc<StaticDigraph, CostArcMap> HwMmc; 1171 typedef HartmannOrlinMmc<StaticDigraph, CostArcMap> HoMmc; 1136 1172 typedef typename BellmanFord<StaticDigraph, CostArcMap> 1137 1173 ::template SetDistMap<CostNodeMap>::Create BF; 1138 1174 1139 1175 // Set epsilon to the minimum cycle mean 1176 Cost cycle_cost = 0; 1177 int cycle_size = 1; 1140 1178 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 } 1146 1194 1147 1195 // Compute feasible potentials for the current epsilon -
lemon/dfs.h
r907 r1000 1194 1194 } 1195 1195 _Visitor& visitor; 1196 Constraints() {} 1196 1197 }; 1197 1198 }; -
lemon/euler.h
r877 r919 37 37 ///Euler tour iterator for digraphs. 38 38 39 /// \ingroup graph_prop 39 /// \ingroup graph_properties 40 40 ///This iterator provides an Euler tour (Eulerian circuit) of a \e directed 41 41 ///graph (if there exists) and it converts to the \c Arc type of the digraph. -
lemon/full_graph.h
r877 r1025 622 622 }; 623 623 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 624 1078 625 1079 } //namespace lemon -
lemon/glpk.cc
r877 r989 557 557 void GlpkBase::_clear() { 558 558 glp_erase_prob(lp); 559 rows.clear();560 cols.clear();561 559 } 562 560 -
lemon/graph_to_eps.h
r877 r998 223 223 using T::_copyright; 224 224 225 using T::NodeTextColorType;225 using typename T::NodeTextColorType; 226 226 using T::CUST_COL; 227 227 using T::DIST_COL; -
lemon/grosso_locatelli_pullan_mc.h
r904 r918 47 47 /// 48 48 /// This class provides a simple but highly efficient and robust heuristic 49 /// method that quickly finds a large clique, but not necessarily the49 /// method that quickly finds a quite large clique, but not necessarily the 50 50 /// 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. 51 55 /// 52 56 /// \tparam GR The undirected graph type the algorithm runs on. … … 85 89 }; 86 90 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 87 107 private: 88 108 … … 94 114 // Note: vector<char> is used instead of vector<bool> for efficiency reasons 95 115 116 // The underlying graph 96 117 const GR &_graph; 97 118 IntNodeMap _id; … … 100 121 BoolMatrix _gr; 101 122 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; 102 132 103 133 // The current clique … … 381 411 GrossoLocatelliPullanMc(const GR& graph) : 382 412 _graph(graph), _id(_graph), _rnd(rnd) 383 {} 413 { 414 initOptions(); 415 } 384 416 385 417 /// \brief Constructor with random seed. … … 392 424 GrossoLocatelliPullanMc(const GR& graph, int seed) : 393 425 _graph(graph), _id(_graph), _rnd(seed) 394 {} 426 { 427 initOptions(); 428 } 395 429 396 430 /// \brief Constructor with random number generator. … … 403 437 GrossoLocatelliPullanMc(const GR& graph, const Random& random) : 404 438 _graph(graph), _id(_graph), _rnd(random) 405 {} 439 { 440 initOptions(); 441 } 406 442 407 443 /// \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 408 449 /// @{ 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 418 460 /// likely finds larger cliques. For smaller values, the algorithm is 419 461 /// 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 /// 420 564 /// \param rule The node selection rule. For more information, see 421 565 /// \ref SelectionRule. 422 566 /// 423 /// \return The size of the found clique.424 int run(int step_num = 100000,425 567 /// \return The termination cause of the search. For more information, 568 /// see \ref TerminationCause. 569 TerminationCause run(SelectionRule rule = PENALTY_BASED) 426 570 { 427 571 init(); 428 572 switch (rule) { 429 573 case RANDOM: 430 return start<RandomSelectionRule>( step_num);574 return start<RandomSelectionRule>(); 431 575 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 } 437 580 } 438 581 … … 440 583 441 584 /// \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 442 588 /// @{ 443 589 … … 531 677 532 678 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 } 533 691 534 692 // Adds a node to the current clique … … 587 745 // Executes the algorithm 588 746 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; 595 749 if (_n == 1) { 596 750 _best_clique[0] = true; 597 751 _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 602 762 SelectionRuleImpl sel_method(*this); 603 int select = 0 ;763 int select = 0, restart = 0; 604 764 IntVector restart_nodes; 605 606 while (select < max_select) { 765 while (select < max_select && restart < max_restart) { 607 766 608 767 // Perturbation/restart 609 if (delta_based_restart) { 768 restart++; 769 if (_delta_based_restart) { 610 770 restart_nodes.clear(); 611 771 for (int i = 0; i != _n; i++) { 612 if (_delta[i] >= restart_delta_limit)772 if (_delta[i] >= _restart_delta_limit) 613 773 restart_nodes.push_back(i); 614 774 } … … 664 824 _best_clique = _clique; 665 825 _best_size = _size; 666 if (_best_size == _n) return _best_size;826 if (_best_size >= max_size) return SIZE_LIMIT; 667 827 } 668 828 sel_method.update(); 669 829 } 670 830 671 return _best_size;831 return (restart >= max_restart ? ITERATION_LIMIT : STEP_LIMIT); 672 832 } 673 833 -
lemon/hartmann_orlin_mmc.h
r879 r1002 99 99 /// This class implements the Hartmann-Orlin algorithm for finding 100 100 /// a directed cycle of minimum mean cost in a digraph 101 /// \ref amo93networkflows, \ref dasdan98minmeancycle.101 /// \ref hartmann93finding, \ref dasdan98minmeancycle. 102 102 /// It is an improved version of \ref KarpMmc "Karp"'s original algorithm, 103 103 /// it applies an efficient early termination scheme. -
lemon/howard_mmc.h
r877 r1012 99 99 /// This class implements Howard's policy iteration algorithm for finding 100 100 /// a directed cycle of minimum mean cost in a digraph 101 /// \ref amo93networkflows, \ref dasdan98minmeancycle.101 /// \ref dasdan98minmeancycle, \ref dasdan04experimental. 102 102 /// This class provides the most efficient algorithm for the 103 103 /// minimum mean cycle problem, though the best known theoretical … … 150 150 typedef TR Traits; 151 151 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 152 169 private: 153 170 … … 325 342 } 326 343 327 /// \brief Find the minimum cycle mean .344 /// \brief Find the minimum cycle mean (or an upper bound). 328 345 /// 329 346 /// 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()) { 334 365 // Initialize and find strongly connected components 335 366 init(); … … 337 368 338 369 // Find the minimum cycle mean in the components 370 int iter_count = 0; 371 bool iter_limit_reached = false; 339 372 for (int comp = 0; comp < _comp_num; ++comp) { 340 373 // Find the minimum mean cycle in the current component 341 374 if (!buildPolicyGraph(comp)) continue; 342 375 while (true) { 376 if (++iter_count > limit) { 377 iter_limit_reached = true; 378 break; 379 } 343 380 findPolicyCycle(); 344 381 if (!computeNodeDistances()) break; 345 382 } 383 346 384 // Update the best cycle (global minimum mean cycle) 347 385 if ( _curr_found && (!_best_found || … … 352 390 _best_node = _curr_node; 353 391 } 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 } 356 401 } 357 402 -
lemon/karp_mmc.h
r877 r1002 99 99 /// This class implements Karp's algorithm for finding a directed 100 100 /// cycle of minimum mean cost in a digraph 101 /// \ref amo93networkflows, \ref dasdan98minmeancycle.101 /// \ref karp78characterization, \ref dasdan98minmeancycle. 102 102 /// It runs in time O(ne) and uses space O(n<sup>2</sup>+e). 103 103 /// -
lemon/kruskal.h
r584 r921 31 31 ///\file 32 32 ///\brief Kruskal's algorithm to compute a minimum cost spanning tree 33 ///34 ///Kruskal's algorithm to compute a minimum cost spanning tree.35 ///36 33 37 34 namespace lemon { -
lemon/lemon.pc.in
r658 r981 1 prefix=@ prefix@2 exec_prefix=@ exec_prefix@3 libdir=@ libdir@4 includedir=@ includedir@1 prefix=@CMAKE_INSTALL_PREFIX@ 2 exec_prefix=@CMAKE_INSTALL_PREFIX@/bin 3 libdir=@CMAKE_INSTALL_PREFIX@/lib 4 includedir=@CMAKE_INSTALL_PREFIX@/include 5 5 6 Name: @P ACKAGE_NAME@6 Name: @PROJECT_NAME@ 7 7 Description: Library for Efficient Modeling and Optimization in Networks 8 Version: @P ACKAGE_VERSION@8 Version: @PROJECT_VERSION@ 9 9 Libs: -L${libdir} -lemon @GLPK_LIBS@ @CPLEX_LIBS@ @SOPLEX_LIBS@ @CLP_LIBS@ @CBC_LIBS@ 10 10 Cflags: -I${includedir} -
lemon/lgf_reader.h
r8