Changes in / [1401:cd72eae05bdf:1402:3c00344f49c9] in lemon
- Files:
-
- 25 added
- 20 deleted
- 145 edited
-
AUTHORS (modified) (2 diffs)
-
CMakeLists.txt (modified) (8 diffs)
-
INSTALL (modified) (1 diff)
-
LICENSE (modified) (1 diff)
-
Makefile.am (deleted)
-
NEWS (modified) (1 diff)
-
cmake/FindCOIN.cmake (modified) (4 diffs)
-
cmake/FindCPLEX.cmake (deleted)
-
cmake/FindGLPK.cmake (modified) (1 diff)
-
cmake/FindILOG.cmake (added)
-
cmake/FindSOPLEX.cmake (added)
-
cmake/version.cmake.in (modified) (1 diff)
-
configure.ac (deleted)
-
contrib/CMakeLists.txt (added)
-
demo/Makefile.am (deleted)
-
doc/CMakeLists.txt (modified) (4 diffs)
-
doc/Doxyfile.in (modified) (4 diffs)
-
doc/DoxygenLayout.xml (modified) (1 diff)
-
doc/Makefile.am (deleted)
-
doc/coding_style.dox (modified) (2 diffs)
-
doc/dirs.dox (modified) (2 diffs)
-
doc/groups.dox (modified) (15 diffs)
-
doc/images/adaptors1.eps (added)
-
doc/images/adaptors2.eps (added)
-
doc/images/bipartite_partitions.eps (modified) (2 diffs)
-
doc/images/connected_components.eps (modified) (2 diffs)
-
doc/images/edge_biconnected_components.eps (modified) (2 diffs)
-
doc/images/graph_to_eps.png (added)
-
doc/images/node_biconnected_components.eps (modified) (2 diffs)
-
doc/images/strongly_connected_components.eps (modified) (2 diffs)
-
doc/images/tsp.eps (added)
-
doc/lgf.dox (modified) (2 diffs)
-
doc/mainpage.dox.in (modified) (2 diffs)
-
doc/min_cost_flow.dox (modified) (3 diffs)
-
doc/references.bib (modified) (5 diffs)
-
lemon/CMakeLists.txt (modified) (3 diffs)
-
lemon/Makefile.am (deleted)
-
lemon/adaptors.h (modified) (1 diff)
-
lemon/arg_parser.cc (modified) (1 diff)
-
lemon/arg_parser.h (modified) (1 diff)
-
lemon/assert.h (modified) (2 diffs)
-
lemon/base.cc (modified) (3 diffs)
-
lemon/bellman_ford.h (modified) (3 diffs)
-
lemon/bfs.h (modified) (2 diffs)
-
lemon/bin_heap.h (modified) (1 diff)
-
lemon/bits/alteration_notifier.h (modified) (4 diffs)
-
lemon/bits/array_map.h (modified) (1 diff)
-
lemon/bits/bezier.h (modified) (1 diff)
-
lemon/bits/default_map.h (modified) (1 diff)
-
lemon/bits/edge_set_extender.h (modified) (1 diff)
-
lemon/bits/graph_adaptor_extender.h (modified) (1 diff)
-
lemon/bits/graph_extender.h (modified) (2 diffs)
-
lemon/bits/lock.h (added)
-
lemon/bits/map_extender.h (modified) (1 diff)
-
lemon/bits/path_dump.h (modified) (1 diff)
-
lemon/bits/solver_bits.h (modified) (1 diff)
-
lemon/bits/traits.h (modified) (2 diffs)
-
lemon/bits/windows.cc (modified) (7 diffs)
-
lemon/bits/windows.h (modified) (3 diffs)
-
lemon/capacity_scaling.h (modified) (16 diffs)
-
lemon/cbc.cc (modified) (1 diff)
-
lemon/cbc.h (modified) (2 diffs)
-
lemon/christofides_tsp.h (added)
-
lemon/circulation.h (modified) (2 diffs)
-
lemon/clp.cc (modified) (1 diff)
-
lemon/clp.h (modified) (1 diff)
-
lemon/concept_check.h (modified) (3 diffs)
-
lemon/concepts/bpgraph.h (added)
-
lemon/concepts/digraph.h (modified) (4 diffs)
-
lemon/concepts/graph.h (modified) (7 diffs)
-
lemon/concepts/graph_components.h (modified) (22 diffs)
-
lemon/concepts/heap.h (modified) (3 diffs)
-
lemon/concepts/maps.h (modified) (3 diffs)
-
lemon/concepts/path.h (modified) (5 diffs)
-
lemon/config.h.cmake (deleted)
-
lemon/config.h.in (modified) (1 diff)
-
lemon/connectivity.h (modified) (2 diffs)
-
lemon/core.h (modified) (7 diffs)
-
lemon/cost_scaling.h (modified) (41 diffs)
-
lemon/counter.h (modified) (1 diff)
-
lemon/cplex.cc (modified) (4 diffs)
-
lemon/cplex.h (modified) (5 diffs)
-
lemon/cycle_canceling.h (modified) (20 diffs)
-
lemon/dfs.h (modified) (2 diffs)
-
lemon/dijkstra.h (modified) (2 diffs)
-
lemon/dim2.h (modified) (1 diff)
-
lemon/dimacs.h (modified) (8 diffs)
-
lemon/edge_set.h (modified) (1 diff)
-
lemon/edmonds_karp.h (added)
-
lemon/elevator.h (modified) (2 diffs)
-
lemon/euler.h (modified) (2 diffs)
-
lemon/fractional_matching.h (modified) (2 diffs)
-
lemon/full_graph.h (modified) (2 diffs)
-
lemon/glpk.cc (modified) (3 diffs)
-
lemon/glpk.h (modified) (3 diffs)
-
lemon/gomory_hu.h (modified) (2 diffs)
-
lemon/graph_to_eps.h (modified) (4 diffs)
-
lemon/greedy_tsp.h (added)
-
lemon/grosso_locatelli_pullan_mc.h (added)
-
lemon/hao_orlin.h (modified) (8 diffs)
-
lemon/hartmann_orlin_mmc.h (modified) (4 diffs)
-
lemon/howard_mmc.h (modified) (7 diffs)
-
lemon/insertion_tsp.h (added)
-
lemon/karp_mmc.h (modified) (4 diffs)
-
lemon/kruskal.h (modified) (2 diffs)
-
lemon/lemon.pc.cmake (deleted)
-
lemon/lemon.pc.in (modified) (1 diff)
-
lemon/lgf_reader.h (modified) (8 diffs)
-
lemon/lgf_writer.h (modified) (12 diffs)
-
lemon/list_graph.h (modified) (7 diffs)
-
lemon/lp.h (modified) (5 diffs)
-
lemon/lp_base.cc (modified) (1 diff)
-
lemon/lp_base.h (modified) (3 diffs)
-
lemon/lp_skeleton.cc (modified) (2 diffs)
-
lemon/lp_skeleton.h (modified) (3 diffs)
-
lemon/maps.h (modified) (1 diff)
-
lemon/matching.h (modified) (1 diff)
-
lemon/math.h (modified) (2 diffs)
-
lemon/max_cardinality_search.h (added)
-
lemon/min_cost_arborescence.h (modified) (3 diffs)
-
lemon/nagamochi_ibaraki.h (added)
-
lemon/nearest_neighbor_tsp.h (added)
-
lemon/network_simplex.h (modified) (47 diffs)
-
lemon/opt2_tsp.h (added)
-
lemon/path.h (modified) (15 diffs)
-
lemon/planarity.h (modified) (4 diffs)
-
lemon/preflow.h (modified) (11 diffs)
-
lemon/radix_sort.h (modified) (8 diffs)
-
lemon/random.h (modified) (8 diffs)
-
lemon/smart_graph.h (modified) (3 diffs)
-
lemon/soplex.cc (modified) (1 diff)
-
lemon/soplex.h (modified) (1 diff)
-
lemon/static_graph.h (modified) (1 diff)
-
lemon/suurballe.h (modified) (3 diffs)
-
lemon/time_measure.h (modified) (8 diffs)
-
lemon/unionfind.h (modified) (1 diff)
-
m4/lx_check_coin.m4 (deleted)
-
m4/lx_check_cplex.m4 (deleted)
-
m4/lx_check_glpk.m4 (deleted)
-
m4/lx_check_soplex.m4 (deleted)
-
scripts/Makefile.am (deleted)
-
scripts/bib2dox.py (deleted)
-
scripts/bootstrap.sh (deleted)
-
scripts/chg-len.py (deleted)
-
scripts/mk-release.sh (deleted)
-
test/CMakeLists.txt (modified) (6 diffs)
-
test/Makefile.am (deleted)
-
test/adaptors_test.cc (modified) (4 diffs)
-
test/arc_look_up_test.cc (modified) (3 diffs)
-
test/bellman_ford_test.cc (modified) (4 diffs)
-
test/bfs_test.cc (modified) (3 diffs)
-
test/bpgraph_test.cc (added)
-
test/circulation_test.cc (modified) (3 diffs)
-
test/connectivity_test.cc (modified) (4 diffs)
-
test/dfs_test.cc (modified) (4 diffs)
-
test/digraph_test.cc (modified) (8 diffs)
-
test/dijkstra_test.cc (modified) (3 diffs)
-
test/edge_set_test.cc (modified) (9 diffs)
-
test/euler_test.cc (modified) (3 diffs)
-
test/fractional_matching_test.cc (modified) (3 diffs)
-
test/gomory_hu_test.cc (modified) (2 diffs)
-
test/graph_copy_test.cc (modified) (11 diffs)
-
test/graph_test.cc (modified) (7 diffs)
-
test/graph_test.h (modified) (7 diffs)
-
test/hao_orlin_test.cc (modified) (2 diffs)
-
test/heap_test.cc (modified) (1 diff)
-
test/lgf_reader_writer_test.cc (added)
-
test/lgf_test.cc (modified) (6 diffs)
-
test/lp_test.cc (modified) (5 diffs)
-
test/maps_test.cc (modified) (10 diffs)
-
test/matching_test.cc (modified) (2 diffs)
-
test/max_cardinality_search_test.cc (added)
-
test/max_clique_test.cc (added)
-
test/max_flow_test.cc (added)
-
test/min_cost_arborescence_test.cc (modified) (3 diffs)
-
test/min_cost_flow_test.cc (modified) (2 diffs)
-
test/min_mean_cycle_test.cc (modified) (3 diffs)
-
test/mip_test.cc (modified) (2 diffs)
-
test/nagamochi_ibaraki_test.cc (added)
-
test/path_test.cc (modified) (3 diffs)
-
test/planarity_test.cc (modified) (3 diffs)
-
test/preflow_test.cc (deleted)
-
test/radix_sort_test.cc (modified) (7 diffs)
-
test/suurballe_test.cc (modified) (3 diffs)
-
test/time_measure_test.cc (modified) (2 diffs)
-
test/tsp_test.cc (added)
-
tools/Makefile.am (deleted)
-
tools/dimacs-solver.cc (modified) (6 diffs)
-
tools/dimacs-to-lgf.cc (modified) (2 diffs)
-
tools/lgf-gen.cc (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
AUTHORS
r1072 r1148 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> -
CMakeLists.txt
r1159 r1398 1 CMAKE_MINIMUM_REQUIRED(VERSION 2.6) 1 CMAKE_MINIMUM_REQUIRED(VERSION 2.8) 2 3 IF(POLICY CMP0048) 4 CMAKE_POLICY(SET CMP0048 OLD) 5 ENDIF(POLICY CMP0048) 6 7 IF(POLICY CMP0026) 8 #This is for copying the dll's needed by glpk (in lp_test and mip_test) 9 CMAKE_POLICY(SET CMP0026 OLD) 10 ENDIF(POLICY CMP0026) 2 11 3 12 SET(PROJECT_NAME "LEMON") … … 13 22 ELSE() 14 23 EXECUTE_PROCESS( 15 COMMAND ${PYTHON_EXECUTABLE} ./scripts/chg-len.py 24 COMMAND 25 hg log -r. --template "{latesttag}" 16 26 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} 17 OUTPUT_VARIABLE HG_REVISION_ PATH27 OUTPUT_VARIABLE HG_REVISION_TAG 18 28 ERROR_QUIET 19 29 OUTPUT_STRIP_TRAILING_WHITESPACE 20 30 ) 21 31 EXECUTE_PROCESS( 22 COMMAND hg id -i 32 COMMAND 33 hg log -r. --template "{latesttagdistance}" 23 34 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} 24 OUTPUT_VARIABLE HG_REVISION 35 OUTPUT_VARIABLE HG_REVISION_DIST 25 36 ERROR_QUIET 26 37 OUTPUT_STRIP_TRAILING_WHITESPACE 27 38 ) 28 IF(HG_REVISION STREQUAL "") 39 EXECUTE_PROCESS( 40 COMMAND 41 hg log -r. --template "{node|short}" 42 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} 43 OUTPUT_VARIABLE HG_REVISION_ID 44 ERROR_QUIET 45 OUTPUT_STRIP_TRAILING_WHITESPACE 46 ) 47 48 IF(HG_REVISION_TAG STREQUAL "") 29 49 SET(HG_REVISION_ID "hg-tip") 30 50 ELSE() 31 IF(HG_REVISION_PATH STREQUAL "") 32 SET(HG_REVISION_ID ${HG_REVISION}) 51 IF(HG_REVISION_TAG STREQUAL "null") 52 SET(HG_REVISION_TAG "trunk") 53 ELSEIF(HG_REVISION_TAG MATCHES "^r") 54 STRING(SUBSTRING ${HG_REVISION_TAG} 1 -1 HG_REVISION_TAG) 55 ENDIF() 56 IF(HG_REVISION_DIST STREQUAL "0") 57 SET(HG_REVISION ${HG_REVISION_TAG}) 33 58 ELSE() 34 SET(HG_REVISION_ID ${HG_REVISION_PATH}.${HG_REVISION}) 59 SET(HG_REVISION 60 "${HG_REVISION_TAG}+${HG_REVISION_DIST}-${HG_REVISION_ID}") 35 61 ENDIF() 36 62 ENDIF() 37 SET(LEMON_VERSION ${HG_REVISION_ID} CACHE STRING "LEMON version string.") 63 64 SET(LEMON_VERSION ${HG_REVISION} CACHE STRING "LEMON version string.") 38 65 ENDIF() 39 66 … … 44 71 FIND_PACKAGE(Doxygen) 45 72 FIND_PACKAGE(Ghostscript) 46 FIND_PACKAGE(GLPK 4.33) 47 FIND_PACKAGE(CPLEX) 48 FIND_PACKAGE(COIN) 73 74 IF(WIN32) 75 SET(LEMON_WIN32 TRUE) 76 ENDIF(WIN32) 77 78 SET(LEMON_ENABLE_GLPK YES CACHE STRING "Enable GLPK solver backend.") 79 SET(LEMON_ENABLE_ILOG YES CACHE STRING "Enable ILOG (CPLEX) solver backend.") 80 SET(LEMON_ENABLE_COIN YES CACHE STRING "Enable COIN solver backend.") 81 SET(LEMON_ENABLE_SOPLEX YES CACHE STRING "Enable SoPlex solver backend.") 82 83 IF(LEMON_ENABLE_GLPK) 84 FIND_PACKAGE(GLPK 4.33) 85 IF(GLPK_FOUND) 86 SET(LEMON_HAVE_LP TRUE) 87 SET(LEMON_HAVE_MIP TRUE) 88 SET(LEMON_HAVE_GLPK TRUE) 89 ENDIF(GLPK_FOUND) 90 ENDIF(LEMON_ENABLE_GLPK) 91 IF(LEMON_ENABLE_ILOG) 92 FIND_PACKAGE(ILOG) 93 IF(ILOG_FOUND) 94 SET(LEMON_HAVE_LP TRUE) 95 SET(LEMON_HAVE_MIP TRUE) 96 SET(LEMON_HAVE_CPLEX TRUE) 97 ENDIF(ILOG_FOUND) 98 ENDIF(LEMON_ENABLE_ILOG) 99 IF(LEMON_ENABLE_COIN) 100 FIND_PACKAGE(COIN) 101 IF(COIN_FOUND) 102 SET(LEMON_HAVE_LP TRUE) 103 SET(LEMON_HAVE_MIP TRUE) 104 SET(LEMON_HAVE_CLP TRUE) 105 SET(LEMON_HAVE_CBC TRUE) 106 ENDIF(COIN_FOUND) 107 ENDIF(LEMON_ENABLE_COIN) 108 IF(LEMON_ENABLE_SOPLEX) 109 FIND_PACKAGE(SOPLEX) 110 IF(SOPLEX_FOUND) 111 SET(LEMON_HAVE_LP TRUE) 112 SET(LEMON_HAVE_SOPLEX TRUE) 113 ENDIF(SOPLEX_FOUND) 114 ENDIF(LEMON_ENABLE_SOPLEX) 115 116 IF(ILOG_FOUND) 117 SET(DEFAULT_LP "CPLEX") 118 SET(DEFAULT_MIP "CPLEX") 119 ELSEIF(COIN_FOUND) 120 SET(DEFAULT_LP "CLP") 121 SET(DEFAULT_MIP "CBC") 122 ELSEIF(GLPK_FOUND) 123 SET(DEFAULT_LP "GLPK") 124 SET(DEFAULT_MIP "GLPK") 125 ELSEIF(SOPLEX_FOUND) 126 SET(DEFAULT_LP "SOPLEX") 127 ENDIF() 128 129 IF(NOT LEMON_DEFAULT_LP OR 130 (NOT ILOG_FOUND AND (LEMON_DEFAULT_LP STREQUAL "CPLEX")) OR 131 (NOT COIN_FOUND AND (LEMON_DEFAULT_LP STREQUAL "CLP")) OR 132 (NOT GLPK_FOUND AND (LEMON_DEFAULT_LP STREQUAL "GLPK")) OR 133 (NOT SOPLEX_FOUND AND (LEMON_DEFAULT_LP STREQUAL "SOPLEX"))) 134 SET(LEMON_DEFAULT_LP ${DEFAULT_LP} CACHE STRING 135 "Default LP solver backend (GLPK, CPLEX, CLP or SOPLEX)" FORCE) 136 ELSE() 137 SET(LEMON_DEFAULT_LP ${DEFAULT_LP} CACHE STRING 138 "Default LP solver backend (GLPK, CPLEX, CLP or SOPLEX)") 139 ENDIF() 140 IF(NOT LEMON_DEFAULT_MIP OR 141 (NOT ILOG_FOUND AND (LEMON_DEFAULT_MIP STREQUAL "CPLEX")) OR 142 (NOT COIN_FOUND AND (LEMON_DEFAULT_MIP STREQUAL "CBC")) OR 143 (NOT GLPK_FOUND AND (LEMON_DEFAULT_MIP STREQUAL "GLPK"))) 144 SET(LEMON_DEFAULT_MIP ${DEFAULT_MIP} CACHE STRING 145 "Default MIP solver backend (GLPK, CPLEX or CBC)" FORCE) 146 ELSE() 147 SET(LEMON_DEFAULT_MIP ${DEFAULT_MIP} CACHE STRING 148 "Default MIP solver backend (GLPK, CPLEX or CBC)") 149 ENDIF() 150 49 151 50 152 IF(DEFINED ENV{LEMON_CXX_WARNING}) … … 57 159 ELSEIF(MSVC) 58 160 # This part is unnecessary 'casue the same is set by the lemon/core.h. 59 # Still keep it as an example. 60 SET(CXX_WARNING "/wd4250 /wd4355 /wd4503 /wd4800 /wd4996") 161 # Still kept as an example. 162 163 # SET(CXX_WARNING "/wd4250 /wd4267 /wd4355 /wd4503 /wd4800 /wd4996") 164 61 165 # Suppressed warnings: 62 166 # C4250: 'class1' : inherits 'class2::member' via dominance 167 # C4267: conversion from 'size_t' to 'type', possible loss of data 63 168 # C4355: 'this' : used in base member initializer list 64 169 # C4503: 'function' : decorated name length exceeded, name was truncated … … 74 179 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LEMON_CXX_WARNING_FLAGS}") 75 180 76 SET( CMAKE_CXX_FLAGS_MAINTAINER "-Werror -ggdb -O0" CACHE STRING 181 IF(MSVC) 182 SET(CMAKE_CXX_FLAGS "/bigobj ${CMAKE_CXX_FLAGS}") 183 SET( CMAKE_CXX_FLAGS_MAINTAINER "/WX ${CMAKE_CXX_FLAGS_DEBUG}" CACHE STRING 77 184 "Flags used by the C++ compiler during maintainer builds." 78 FORCE)79 SET( CMAKE_C_FLAGS_MAINTAINER "-Werror -O0" CACHE STRING185 ) 186 SET( CMAKE_C_FLAGS_MAINTAINER "/WX ${CMAKE_CXX_FLAGS_DEBUG}" CACHE STRING 80 187 "Flags used by the C compiler during maintainer builds." 81 FORCE)82 SET( CMAKE_EXE_LINKER_FLAGS_MAINTAINER83 " -Wl,--warn-unresolved-symbols,--warn-once" CACHE STRING188 ) 189 SET( CMAKE_EXE_LINKER_FLAGS_MAINTAINER 190 "${CMAKE_EXE_LINKER_FLAGS_DEBUG}" CACHE STRING 84 191 "Flags used for linking binaries during maintainer builds." 85 FORCE)86 SET( CMAKE_SHARED_LINKER_FLAGS_MAINTAINER87 " -Wl,--warn-unresolved-symbols,--warn-once" CACHE STRING192 ) 193 SET( CMAKE_SHARED_LINKER_FLAGS_MAINTAINER 194 "${CMAKE_SHARED_LINKER_FLAGS_DEBUG}" CACHE STRING 88 195 "Flags used by the shared libraries linker during maintainer builds." 89 FORCE ) 196 ) 197 ELSE() 198 SET( CMAKE_CXX_FLAGS_MAINTAINER "-Werror -ggdb -O0" CACHE STRING 199 "Flags used by the C++ compiler during maintainer builds." 200 ) 201 SET( CMAKE_C_FLAGS_MAINTAINER "-Werror -O0" CACHE STRING 202 "Flags used by the C compiler during maintainer builds." 203 ) 204 SET( CMAKE_EXE_LINKER_FLAGS_MAINTAINER 205 "${CMAKE_EXE_LINKER_FLAGS_DEBUG}" CACHE STRING 206 "Flags used for linking binaries during maintainer builds." 207 ) 208 SET( CMAKE_SHARED_LINKER_FLAGS_MAINTAINER 209 "${CMAKE_SHARED_LINKER_FLAGS_DEBUG}" CACHE STRING 210 "Flags used by the shared libraries linker during maintainer builds." 211 ) 212 ENDIF() 213 90 214 MARK_AS_ADVANCED( 91 215 CMAKE_CXX_FLAGS_MAINTAINER … … 115 239 SET(LEMON_HAVE_LONG_LONG ${HAVE_LONG_LONG}) 116 240 117 INCLUDE(FindPythonInterp) 241 INCLUDE(FindThreads) 242 243 IF(NOT LEMON_THREADING) 244 IF(CMAKE_USE_PTHREADS_INIT) 245 SET(LEMON_THREADING "Pthread") 246 ELSEIF(CMAKE_USE_WIN32_THREADS_INIT) 247 SET(LEMON_THREADING "Win32") 248 ELSE() 249 SET(LEMON_THREADING "None") 250 ENDIF() 251 ENDIF() 252 253 SET( LEMON_THREADING "${LEMON_THREADING}" CACHE STRING 254 "Choose the threading library, options are: Pthread Win32 None." 255 FORCE ) 256 257 IF(LEMON_THREADING STREQUAL "Pthread") 258 SET(LEMON_USE_PTHREAD TRUE) 259 ELSEIF(LEMON_THREADING STREQUAL "Win32") 260 SET(LEMON_USE_WIN32_THREADS TRUE) 261 ENDIF() 118 262 119 263 ENABLE_TESTING() … … 127 271 ADD_SUBDIRECTORY(lemon) 128 272 IF(${CMAKE_SOURCE_DIR} STREQUAL ${PROJECT_SOURCE_DIR}) 273 ADD_SUBDIRECTORY(contrib) 129 274 ADD_SUBDIRECTORY(demo) 130 275 ADD_SUBDIRECTORY(tools) … … 150 295 ENDIF() 151 296 297 CONFIGURE_FILE( 298 ${PROJECT_SOURCE_DIR}/cmake/version.cmake.in 299 ${PROJECT_BINARY_DIR}/cmake/version.cmake 300 @ONLY 301 ) 302 303 SET(ARCHIVE_BASE_NAME ${CMAKE_PROJECT_NAME}) 304 STRING(TOLOWER ${ARCHIVE_BASE_NAME} ARCHIVE_BASE_NAME) 305 SET(ARCHIVE_NAME ${ARCHIVE_BASE_NAME}-${PROJECT_VERSION}) 306 ADD_CUSTOM_TARGET(dist 307 COMMAND cmake -E remove_directory ${ARCHIVE_NAME} 308 COMMAND hg archive ${ARCHIVE_NAME} 309 COMMAND cmake -E copy cmake/version.cmake ${ARCHIVE_NAME}/cmake/version.cmake 310 COMMAND tar -czf ${ARCHIVE_BASE_NAME}-nodoc-${PROJECT_VERSION}.tar.gz ${ARCHIVE_NAME} 311 COMMAND zip -r ${ARCHIVE_BASE_NAME}-nodoc-${PROJECT_VERSION}.zip ${ARCHIVE_NAME} 312 COMMAND cmake -E copy_directory doc/html ${ARCHIVE_NAME}/doc/html 313 COMMAND tar -czf ${ARCHIVE_NAME}.tar.gz ${ARCHIVE_NAME} 314 COMMAND zip -r ${ARCHIVE_NAME}.zip ${ARCHIVE_NAME} 315 COMMAND cmake -E copy_directory doc/html ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION} 316 COMMAND tar -czf ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION}.tar.gz ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION} 317 COMMAND zip -r ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION}.zip ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION} 318 COMMAND cmake -E remove_directory ${ARCHIVE_NAME} 319 COMMAND cmake -E remove_directory ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION} 320 DEPENDS html 321 WORKING_DIRECTORY ${PROJECT_BINARY_DIR}) 322 323 # CPACK config (Basically for NSIS) 152 324 IF(${CMAKE_SOURCE_DIR} STREQUAL ${PROJECT_SOURCE_DIR}) 153 325 SET(CPACK_PACKAGE_NAME ${PROJECT_NAME}) -
INSTALL
r890 r1233 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 -DLEMON_DOC_SOURCE_BROWSER=YES 114 110 115 --with-cplex-includedir=DIR 111 Include the browsable cross referenced LEMON source code into the 112 doc. It makes the doc quite bloated, but may be useful for 113 developing LEMON itself. 116 114 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). 115 -DLEMON_DOC_USE_MATHJAX=YES 120 116 121 --with-cplex-libdir=DIR 117 Use MathJax (http://mathjax.org) for rendering the math formulae in 118 the doc. It of much higher quality compared to the default LaTeX 119 generated static images and it allows copy&paste of the formulae to 120 LaTeX, Open Office, MS Word etc. documents. 122 121 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). 122 On the other hand, it needs either Internet access or a locally 123 installed version of MathJax to properly render the doc. 127 124 128 --without-cplex 125 -DLEMON_DOC_MATHJAX_RELPATH=DIRECTORY 126 127 The location of the MathJax library. It defaults to 128 http://www.mathjax.org/mathjax, which necessitates Internet access 129 for proper rendering. The easiest way to make it usable offline is 130 to set this parameter to 'mathjax' and copy all files of the MathJax 131 library into the 'doc/html/mathjax' subdirectory of the build 132 location. 129 133 130 Disable CPLEX support.134 See http://docs.mathjax.org/en/latest/installation.html for more details. 131 135 132 --with-soplex[=PREFIX] 136 137 -DLEMON_ENABLE_GLPK=NO 138 -DLEMON_ENABLE_COIN=NO 139 -DLEMON_ENABLE_ILOG=NO 133 140 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. 141 Enable optional third party libraries. They are all enabled by default. 137 142 138 - -with-soplex-includedir=DIR143 -DLEMON_DEFAULT_LP=GLPK 139 144 140 The directory where the SoPlex header files are located. This is only141 useful when the SoPlex headers and libraries are not under the same142 prefix (which is unlikely).145 Sets the default LP solver backend. The supported values are 146 CPLEX, CLP and GLPK. By default, it is set to the first one which 147 is enabled and succesfully discovered. 143 148 144 - -with-soplex-libdir=DIR149 -DLEMON_DEFAULT_MIP=GLPK 145 150 146 The directory where the SoPlex libraries are located. This is only147 useful when the SoPlex headers and libraries are not under the same148 prefix (which is unlikely).151 Sets the default MIP solver backend. The supported values are 152 CPLEX, CBC and GLPK. By default, it is set to the first one which 153 is enabled and succesfully discovered. 149 154 150 --without-soplex 155 -DGLPK_ROOT_DIR=DIRECTORY 156 -DCOIN_ROOT_DIR=DIRECTORY 157 -DILOG_ROOT_DIR=DIRECTORY 151 158 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 159 Root directory prefixes of optional third party libraries. 177 160 178 161 Makefile Variables 179 162 ================== 180 163 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]...' 164 make VERBOSE=1 187 165 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"'. 166 This results in a more verbose output by showing the full 167 compiler and linker commands. -
LICENSE
r959 r1148 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). -
NEWS
r962 r1281 1 2013-08-10 Version 1.3 released 2 3 This is major feature release 4 5 * New data structures 6 7 #69 : Bipartite graph concepts and implementations 8 9 * New algorithms 10 11 #177: Port Edmonds-Karp algorithm 12 #380, #405: Heuristic algorithm for the max clique problem 13 #386: Heuristic algorithms for symmetric TSP 14 ----: Nagamochi-Ibaraki algorithm [5087694945e4] 15 #397, #56: Max. cardinality search 16 17 * Other new features 18 19 #223: Thread safe graph and graph map implementations 20 #442: Different TimeStamp print formats 21 #457: File export functionality to LpBase 22 #362: Bidirectional iterator support for radixSort() 23 24 * Implementation improvements 25 26 ----: Network Simplex 27 #391: Better update process, pivot rule and arc mixing 28 #435: Improved Altering List pivot rule 29 #417: Various fine tunings in CostScaling 30 #438: Optional iteration limit in HowardMmc 31 #436: Ensure strongly polynomial running time for CycleCanceling 32 while keeping the same performance 33 ----: Make the CBC interface be compatible with latest CBC releases 34 [ee581a0ecfbf] 35 36 * CMAKE has become the default build environment (#434) 37 38 ----: Autotool support has been dropped 39 ----: Improved LP/MIP configuration 40 #465: Enable/disable options for LP/MIP backends 41 #446: Better CPLEX discovery 42 #460: Add cmake config to find SoPlex 43 ----: Allow CPACK configuration on all platforms 44 #390: Add 'Maintainer' CMAKE build type 45 #388: Add 'check' target. 46 #401: Add contrib dir 47 #389: Better version string setting in CMAKE 48 #433: Support shared library build 49 #416: Support testing with valgrind 50 51 * Doc improvements 52 53 #395: SOURCE_BROWSER Doxygen switch is configurable from CMAKE 54 update-external-tags CMAKE target 55 #455: Optionally use MathJax for rendering the math formulae 56 #402, #437, #459, #456, #463: Various doc improvements 57 58 * Bugfixes (compared to release 1.2): 59 60 #432: Add missing doc/template.h and doc/references.bib to release 61 tarball 62 ----: Intel C++ compatibility fixes 63 #441: Fix buggy reinitialization in _solver_bits::VarIndex::clear() 64 #444: Bugfix in path copy constructors and assignment operators 65 #447: Bugfix in AllArcLookUp<> 66 #448: Bugfix in adaptor_test.cc 67 #449: Fix clang compilation warnings and errors 68 #440: Fix a bug + remove redundant typedefs in dimacs-solver 69 #453: Avoid GCC 4.7 compiler warnings 70 #445: Fix missing initialization in CplexEnv::CplexEnv() 71 #428: Add missing lemon/lemon.pc.cmake to the release tarball 72 #393: Create and install lemon.pc 73 #429: Fix VS warnings 74 #430: Fix LpBase::Constr two-side limit bug 75 #392: Bug fix in Dfs::start(s,t) 76 #414: Fix wrong initialization in Preflow 77 #418: Better Win CodeBlock/MinGW support 78 #419: Build environment improvements 79 - Build of mip_test and lp_test precede the running of the tests 80 - Also search for coin libs under ${COIN_ROOT_DIR}/lib/coin 81 - Do not look for COIN_VOL libraries 82 #382: Allow lgf file without Arc maps 83 #417: Bug fix in CostScaling 84 #366: Fix Pred[Matrix]MapPath::empty() 85 #371: Bug fix in (di)graphCopy() 86 The target graph is cleared before adding nodes and arcs/edges. 87 #364: Add missing UndirectedTags 88 #368: Fix the usage of std::numeric_limits<>::min() in Network Simplex 89 #372: Fix a critical bug in preflow 90 #461: Bugfix in assert.h 91 #470: Fix compilation issues related to various gcc versions 92 #446: Fix #define indicating CPLEX availability 93 #294: Add explicit namespace to 94 ignore_unused_variable_warning() usages 95 #420: Bugfix in IterableValueMap 96 #439: Bugfix in biNodeConnected() 97 98 1 99 2010-03-19 Version 1.2 released 2 100 -
cmake/FindCOIN.cmake
r1120 r1398 66 66 ) 67 67 68 FIND_LIBRARY(COIN_PTHREADS_LIBRARY 69 NAMES pthreads libpthreads 70 HINTS ${COIN_ROOT_DIR}/lib/coin 71 HINTS ${COIN_ROOT_DIR}/lib 72 ) 73 68 74 INCLUDE(FindPackageHandleStandardArgs) 69 75 FIND_PACKAGE_HANDLE_STANDARD_ARGS(COIN DEFAULT_MSG … … 83 89 IF(COIN_FOUND) 84 90 SET(COIN_INCLUDE_DIRS ${COIN_INCLUDE_DIR}) 85 SET(COIN_CLP_LIBRARIES "${COIN_CLP_LIBRARY};${COIN_COIN_UTILS_LIBRARY} ;${COIN_ZLIB_LIBRARY};${COIN_BZ2_LIBRARY}")91 SET(COIN_CLP_LIBRARIES "${COIN_CLP_LIBRARY};${COIN_COIN_UTILS_LIBRARY}") 86 92 IF(COIN_ZLIB_LIBRARY) 87 93 SET(COIN_CLP_LIBRARIES "${COIN_CLP_LIBRARIES};${COIN_ZLIB_LIBRARY}") … … 90 96 SET(COIN_CLP_LIBRARIES "${COIN_CLP_LIBRARIES};${COIN_BZ2_LIBRARY}") 91 97 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}") 98 IF(COIN_PTHREADS_LIBRARY) 99 SET(COIN_CLP_LIBRARIES "${COIN_CLP_LIBRARIES};${COIN_PTHREADS_LIBRARY}") 100 ENDIF(COIN_PTHREADS_LIBRARY) 101 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_CLP_LIBRARIES}") 93 102 SET(COIN_LIBRARIES ${COIN_CBC_LIBRARIES}) 94 103 ENDIF(COIN_FOUND) … … 109 118 COIN_BZ2_LIBRARY 110 119 ) 111 112 IF(COIN_FOUND)113 SET(LEMON_HAVE_LP TRUE)114 SET(LEMON_HAVE_MIP TRUE)115 SET(LEMON_HAVE_CLP TRUE)116 SET(LEMON_HAVE_CBC TRUE)117 ENDIF(COIN_FOUND) -
cmake/FindGLPK.cmake
r685 r1232 54 54 55 55 MARK_AS_ADVANCED(GLPK_LIBRARY GLPK_INCLUDE_DIR GLPK_BIN_DIR) 56 57 IF(GLPK_FOUND)58 SET(LEMON_HAVE_LP TRUE)59 SET(LEMON_HAVE_MIP TRUE)60 SET(LEMON_HAVE_GLPK TRUE)61 ENDIF(GLPK_FOUND) -
cmake/version.cmake.in
r725 r1135 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
r1107 r1251 5 5 6 6 SET(LEMON_DOC_SOURCE_BROWSER "NO" CACHE STRING "Include source into the doc (YES/NO).") 7 SET(LEMON_DOC_USE_MATHJAX "NO" CACHE STRING "Use MathJax to display math formulae (YES/NO).") 8 SET(LEMON_DOC_MATHJAX_RELPATH "http://www.mathjax.org/mathjax" CACHE STRING "MathJax library location.") 9 10 SET(LEMON_DOC_LIBSTDC++_URL 11 "http://gcc.gnu.org/onlinedocs/gcc-4.7.3/libstdc++/api" 12 CACHE STRING "GCC libstdc++ doxygen doc url.") 13 7 14 8 15 CONFIGURE_FILE( … … 18 25 ) 19 26 27 # Copy doc from source (if exists) 28 IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/html AND 29 NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/html/index.html) 30 MESSAGE(STATUS "Copy doc from source tree") 31 EXECUTE_PROCESS( 32 COMMAND cmake -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/html ${CMAKE_CURRENT_BINARY_DIR}/html 33 ) 34 ENDIF() 35 20 36 IF(DOXYGEN_EXECUTABLE AND PYTHONINTERP_FOUND AND GHOSTSCRIPT_EXECUTABLE) 21 37 FILE(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html/) … … 24 40 COMMAND ${CMAKE_COMMAND} -E remove_directory gen-images 25 41 COMMAND ${CMAKE_COMMAND} -E make_directory gen-images 26 COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r18 -sOutputFile=gen-images/bipartite_matching.png ${CMAKE_CURRENT_SOURCE_DIR}/images/bipartite_matching.eps 27 COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r18 -sOutputFile=gen-images/bipartite_partitions.png ${CMAKE_CURRENT_SOURCE_DIR}/images/bipartite_partitions.eps 28 COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r18 -sOutputFile=gen-images/connected_components.png ${CMAKE_CURRENT_SOURCE_DIR}/images/connected_components.eps 29 COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r18 -sOutputFile=gen-images/edge_biconnected_components.png ${CMAKE_CURRENT_SOURCE_DIR}/images/edge_biconnected_components.eps 30 COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r18 -sOutputFile=gen-images/grid_graph.png ${CMAKE_CURRENT_SOURCE_DIR}/images/grid_graph.eps 31 COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r18 -sOutputFile=gen-images/matching.png ${CMAKE_CURRENT_SOURCE_DIR}/images/matching.eps 32 COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r18 -sOutputFile=gen-images/node_biconnected_components.png ${CMAKE_CURRENT_SOURCE_DIR}/images/node_biconnected_components.eps 33 COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r18 -sOutputFile=gen-images/nodeshape_0.png ${CMAKE_CURRENT_SOURCE_DIR}/images/nodeshape_0.eps 34 COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r18 -sOutputFile=gen-images/nodeshape_1.png ${CMAKE_CURRENT_SOURCE_DIR}/images/nodeshape_1.eps 35 COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r18 -sOutputFile=gen-images/nodeshape_2.png ${CMAKE_CURRENT_SOURCE_DIR}/images/nodeshape_2.eps 36 COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r18 -sOutputFile=gen-images/nodeshape_3.png ${CMAKE_CURRENT_SOURCE_DIR}/images/nodeshape_3.eps 37 COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r18 -sOutputFile=gen-images/nodeshape_4.png ${CMAKE_CURRENT_SOURCE_DIR}/images/nodeshape_4.eps 38 COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r18 -sOutputFile=gen-images/planar.png ${CMAKE_CURRENT_SOURCE_DIR}/images/planar.eps 39 COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r18 -sOutputFile=gen-images/strongly_connected_components.png ${CMAKE_CURRENT_SOURCE_DIR}/images/strongly_connected_components.eps 42 COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r20 -sOutputFile=gen-images/grid_graph.png ${CMAKE_CURRENT_SOURCE_DIR}/images/grid_graph.eps 43 COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r32 -sOutputFile=gen-images/adaptors2.png ${CMAKE_CURRENT_SOURCE_DIR}/images/adaptors2.eps 44 COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r32 -sOutputFile=gen-images/connected_components.png ${CMAKE_CURRENT_SOURCE_DIR}/images/connected_components.eps 45 COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r32 -sOutputFile=gen-images/strongly_connected_components.png ${CMAKE_CURRENT_SOURCE_DIR}/images/strongly_connected_components.eps 46 COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r32 -sOutputFile=gen-images/node_biconnected_components.png ${CMAKE_CURRENT_SOURCE_DIR}/images/node_biconnected_components.eps 47 COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r32 -sOutputFile=gen-images/edge_biconnected_components.png ${CMAKE_CURRENT_SOURCE_DIR}/images/edge_biconnected_components.eps 48 COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r32 -sOutputFile=gen-images/bipartite_partitions.png ${CMAKE_CURRENT_SOURCE_DIR}/images/bipartite_partitions.eps 49 COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r24 -sOutputFile=gen-images/matching.png ${CMAKE_CURRENT_SOURCE_DIR}/images/matching.eps 50 COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r24 -sOutputFile=gen-images/bipartite_matching.png ${CMAKE_CURRENT_SOURCE_DIR}/images/bipartite_matching.eps 51 COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r40 -sOutputFile=gen-images/planar.png ${CMAKE_CURRENT_SOURCE_DIR}/images/planar.eps 52 COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r24 -sOutputFile=gen-images/tsp.png ${CMAKE_CURRENT_SOURCE_DIR}/images/tsp.eps 53 COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r8 -sOutputFile=gen-images/nodeshape_0.png ${CMAKE_CURRENT_SOURCE_DIR}/images/nodeshape_0.eps 54 COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r8 -sOutputFile=gen-images/nodeshape_1.png ${CMAKE_CURRENT_SOURCE_DIR}/images/nodeshape_1.eps 55 COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r8 -sOutputFile=gen-images/nodeshape_2.png ${CMAKE_CURRENT_SOURCE_DIR}/images/nodeshape_2.eps 56 COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r8 -sOutputFile=gen-images/nodeshape_3.png ${CMAKE_CURRENT_SOURCE_DIR}/images/nodeshape_3.eps 57 COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r8 -sOutputFile=gen-images/nodeshape_4.png ${CMAKE_CURRENT_SOURCE_DIR}/images/nodeshape_4.eps 40 58 COMMAND ${CMAKE_COMMAND} -E remove_directory html 41 COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/scripts/bib2dox.py ${CMAKE_CURRENT_SOURCE_DIR}/references.bib >references.dox42 59 COMMAND ${DOXYGEN_EXECUTABLE} Doxyfile 43 60 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} … … 64 81 IF(WGET_FOUND) 65 82 ADD_CUSTOM_TARGET(update-external-tags 66 COMMAND ${CMAKE_COMMAND} -E make_directory dl 67 # COMMAND ${CMAKE_COMMAND} -E copy libstdc++.tag dl 68 COMMAND ${WGET_EXECUTABLE} wget -P dl -N libstdc++.tag.tmp http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/libstdc++.tag 69 COMMAND ${CMAKE_COMMAND} -E rename dl/libstdc++.tag libstdc++.tag 70 COMMAND ${CMAKE_COMMAND} -E remove dl/libstdc++.tag 71 COMMAND ${CMAKE_COMMAND} -E remove_directory dl 83 COMMAND ${WGET_EXECUTABLE} -N ${LEMON_DOC_LIBSTDC++_URL}/libstdc++.tag 72 84 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} 73 85 ) -
doc/Doxyfile.in
r1107 r1251 78 78 FILE_VERSION_FILTER = 79 79 LAYOUT_FILE = "@abs_top_srcdir@/doc/DoxygenLayout.xml" 80 CITE_BIB_FILES = "@abs_top_srcdir@/doc/references.bib" 80 81 #--------------------------------------------------------------------------- 81 82 # configuration options related to warning and progress messages … … 96 97 "@abs_top_srcdir@/lemon/concepts" \ 97 98 "@abs_top_srcdir@/demo" \ 99 "@abs_top_srcdir@/contrib" \ 98 100 "@abs_top_srcdir@/tools" \ 99 101 "@abs_top_srcdir@/test/test_tools.h" \ 100 "@abs_top_builddir@/doc/mainpage.dox" \ 101 "@abs_top_builddir@/doc/references.dox" 102 "@abs_top_builddir@/doc/mainpage.dox" 102 103 INPUT_ENCODING = UTF-8 103 104 FILE_PATTERNS = *.h \ … … 182 183 FORMULA_FONTSIZE = 10 183 184 FORMULA_TRANSPARENT = YES 184 USE_MATHJAX = NO185 MATHJAX_RELPATH = http://www.mathjax.org/mathjax185 USE_MATHJAX = @LEMON_DOC_USE_MATHJAX@ 186 MATHJAX_RELPATH = @LEMON_DOC_MATHJAX_RELPATH@ 186 187 SEARCHENGINE = YES 187 188 SERVER_BASED_SEARCH = NO … … 253 254 # Configuration::additions related to external references 254 255 #--------------------------------------------------------------------------- 255 TAGFILES = "@abs_top_builddir@/doc/libstdc++.tag = http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/"256 TAGFILES = "@abs_top_builddir@/doc/libstdc++.tag = @LEMON_DOC_LIBSTDC++_URL@" 256 257 GENERATE_TAGFILE = html/lemon.tag 257 258 ALLEXTERNALS = NO -
doc/DoxygenLayout.xml
r1036 r1251 18 18 <tab type="globals" visible="yes" title="" intro=""/> 19 19 </tab> 20 <tab type="dirs" visible="yes" title="" intro=""/>21 20 <tab type="examples" visible="yes" title="" intro=""/> 22 21 <tab type="pages" visible="yes" title="" intro=""/> -
doc/coding_style.dox
r463 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 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
r463 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 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
r959 r1271 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 113 113 detailed documentation of particular adaptors. 114 114 115 Since the adaptor classes conform to the \ref graph_concepts "graph concepts", 116 an adaptor can even be applied to another one. 117 The following image illustrates a situation when a \ref SubDigraph adaptor 118 is applied on a digraph and \ref Undirector is applied on the subgraph. 119 120 \image html adaptors2.png 121 \image latex adaptors2.eps "Using graph adaptors" width=\textwidth 122 115 123 The behavior of graph adaptors can be very different. Some of them keep 116 124 capabilities of the original graph while in other cases this would be … … 310 318 This group contains the common graph search algorithms, namely 311 319 \e breadth-first \e search (BFS) and \e depth-first \e search (DFS) 312 \ refclrs01algorithms.320 \cite clrs01algorithms. 313 321 */ 314 322 … … 319 327 320 328 This group contains the algorithms for finding shortest paths in digraphs 321 \ refclrs01algorithms.329 \cite clrs01algorithms. 322 330 323 331 - \ref Dijkstra algorithm for finding shortest paths from a source node … … 341 349 342 350 This group contains the algorithms for finding minimum cost spanning 343 trees and arborescences \ refclrs01algorithms.351 trees and arborescences \cite clrs01algorithms. 344 352 */ 345 353 … … 350 358 351 359 This group contains the algorithms for finding maximum flows and 352 feasible circulations \ ref clrs01algorithms, \refamo93networkflows.360 feasible circulations \cite clrs01algorithms, \cite amo93networkflows. 353 361 354 362 The \e maximum \e flow \e problem is to find a flow of maximum value between … … 366 374 LEMON contains several algorithms for solving maximum flow problems: 367 375 - \ref EdmondsKarp Edmonds-Karp algorithm 368 \ refedmondskarp72theoretical.376 \cite edmondskarp72theoretical. 369 377 - \ref Preflow Goldberg-Tarjan's preflow push-relabel algorithm 370 \ refgoldberg88newapproach.378 \cite goldberg88newapproach. 371 379 - \ref DinitzSleatorTarjan Dinitz's blocking flow algorithm with dynamic trees 372 \ ref dinic70algorithm, \refsleator83dynamic.380 \cite dinic70algorithm, \cite sleator83dynamic. 373 381 - \ref GoldbergTarjan !Preflow push-relabel algorithm with dynamic trees 374 \ ref goldberg88newapproach, \refsleator83dynamic.382 \cite goldberg88newapproach, \cite sleator83dynamic. 375 383 376 384 In most cases the \ref Preflow algorithm provides the … … 392 400 393 401 This group contains the algorithms for finding minimum cost flows and 394 circulations \ refamo93networkflows. For more information about this395 problem and its dual solution, see \ref min_cost_flow402 circulations \cite amo93networkflows. For more information about this 403 problem and its dual solution, see: \ref min_cost_flow 396 404 "Minimum Cost Flow Problem". 397 405 398 406 LEMON contains several algorithms for this problem. 399 407 - \ref NetworkSimplex Primal Network Simplex algorithm with various 400 pivot strategies \ ref dantzig63linearprog, \refkellyoneill91netsimplex.408 pivot strategies \cite dantzig63linearprog, \cite kellyoneill91netsimplex. 401 409 - \ref CostScaling Cost Scaling algorithm based on push/augment and 402 relabel operations \ ref goldberg90approximation, \refgoldberg97efficient,403 \ refbunnagel98efficient.410 relabel operations \cite goldberg90approximation, \cite goldberg97efficient, 411 \cite bunnagel98efficient. 404 412 - \ref CapacityScaling Capacity Scaling algorithm based on the successive 405 shortest path method \ refedmondskarp72theoretical.413 shortest path method \cite edmondskarp72theoretical. 406 414 - \ref CycleCanceling Cycle-Canceling algorithms, two of which are 407 strongly polynomial \ref klein67primal, \ref goldberg89cyclecanceling. 408 409 In general NetworkSimplex is the most efficient implementation, 410 but in special cases other algorithms could be faster. 415 strongly polynomial \cite klein67primal, \cite goldberg89cyclecanceling. 416 417 In general, \ref NetworkSimplex and \ref CostScaling are the most efficient 418 implementations. 419 \ref NetworkSimplex is usually the fastest on relatively small graphs (up to 420 several thousands of nodes) and on dense graphs, while \ref CostScaling is 421 typically more efficient on large graphs (e.g. hundreds of thousands of 422 nodes or above), especially if they are sparse. 423 However, other algorithms could be faster in special cases. 411 424 For example, if the total supply and/or capacities are rather small, 412 CapacityScaling is usually the fastest algorithm (without effective scaling). 425 \ref CapacityScaling is usually the fastest algorithm 426 (without effective scaling). 427 428 These classes are intended to be used with integer-valued input data 429 (capacities, supply values, and costs), except for \ref CapacityScaling, 430 which is capable of handling real-valued arc costs (other numerical 431 data are required to be integer). 432 433 For more details about these implementations and for a comprehensive 434 experimental study, see the paper \cite KiralyKovacs12MCF. 435 It also compares these codes to other publicly available 436 minimum cost flow solvers. 413 437 */ 414 438 … … 449 473 450 474 This group contains the algorithms for finding minimum mean cycles 451 \ ref clrs01algorithms, \ref amo93networkflows.475 \cite amo93networkflows, \cite karp78characterization. 452 476 453 477 The \e minimum \e mean \e cycle \e problem is to find a directed cycle … … 465 489 466 490 LEMON contains three algorithms for solving the minimum mean cycle problem: 467 - \ref KarpMmc Karp's original algorithm \ref amo93networkflows, 468 \ref dasdan98minmeancycle. 491 - \ref KarpMmc Karp's original algorithm \cite karp78characterization. 469 492 - \ref HartmannOrlinMmc Hartmann-Orlin's algorithm, which is an improved 470 version of Karp's algorithm \ ref dasdan98minmeancycle.493 version of Karp's algorithm \cite hartmann93finding. 471 494 - \ref HowardMmc Howard's policy iteration algorithm 472 \ ref dasdan98minmeancycle.473 474 In practice, the \ref HowardMmc "Howard" algorithm provedto be by far the495 \cite dasdan98minmeancycle, \cite dasdan04experimental. 496 497 In practice, the \ref HowardMmc "Howard" algorithm turned out to be by far the 475 498 most efficient one, though the best known theoretical bound on its running 476 499 time is exponential. 477 500 Both \ref KarpMmc "Karp" and \ref HartmannOrlinMmc "Hartmann-Orlin" algorithms 478 run in time O(ne) and use space O(n<sup>2</sup>+e), but the latter one is 479 typically faster due to the applied early termination scheme. 501 run in time O(nm) and use space O(n<sup>2</sup>+m). 480 502 */ 481 503 … … 540 562 541 563 /** 542 @defgroup planar Planar ityEmbedding and Drawing564 @defgroup planar Planar Embedding and Drawing 543 565 @ingroup algs 544 566 \brief Algorithms for planarity checking, embedding and drawing … … 552 574 553 575 /** 554 @defgroup approx Approximation Algorithms 576 @defgroup tsp Traveling Salesman Problem 577 @ingroup algs 578 \brief Algorithms for the symmetric traveling salesman problem 579 580 This group contains basic heuristic algorithms for the the symmetric 581 \e traveling \e salesman \e problem (TSP). 582 Given an \ref FullGraph "undirected full graph" with a cost map on its edges, 583 the problem is to find a shortest possible tour that visits each node exactly 584 once (i.e. the minimum cost Hamiltonian cycle). 585 586 These TSP algorithms are intended to be used with a \e metric \e cost 587 \e function, i.e. the edge costs should satisfy the triangle inequality. 588 Otherwise the algorithms could yield worse results. 589 590 LEMON provides five well-known heuristics for solving symmetric TSP: 591 - \ref NearestNeighborTsp Neareast neighbor algorithm 592 - \ref GreedyTsp Greedy algorithm 593 - \ref InsertionTsp Insertion heuristic (with four selection methods) 594 - \ref ChristofidesTsp Christofides algorithm 595 - \ref Opt2Tsp 2-opt algorithm 596 597 \ref NearestNeighborTsp, \ref GreedyTsp, and \ref InsertionTsp are the fastest 598 solution methods. Furthermore, \ref InsertionTsp is usually quite effective. 599 600 \ref ChristofidesTsp is somewhat slower, but it has the best guaranteed 601 approximation factor: 3/2. 602 603 \ref Opt2Tsp usually provides the best results in practice, but 604 it is the slowest method. It can also be used to improve given tours, 605 for example, the results of other algorithms. 606 607 \image html tsp.png 608 \image latex tsp.eps "Traveling salesman problem" width=\textwidth 609 */ 610 611 /** 612 @defgroup approx_algs Approximation Algorithms 555 613 @ingroup algs 556 614 \brief Approximation algorithms. … … 558 616 This group contains the approximation and heuristic algorithms 559 617 implemented in LEMON. 618 619 <b>Maximum Clique Problem</b> 620 - \ref GrossoLocatelliPullanMc An efficient heuristic algorithm of 621 Grosso, Locatelli, and Pullan. 560 622 */ 561 623 … … 587 649 high-level interface. 588 650 589 The currently supported solvers are \ ref glpk, \ref clp, \refcbc,590 \ ref cplex, \refsoplex.651 The currently supported solvers are \cite glpk, \cite clp, \cite cbc, 652 \cite cplex, \cite soplex. 591 653 */ 592 654 … … 675 737 This group contains general \c EPS drawing methods and special 676 738 graph exporting tools. 739 740 \image html graph_to_eps.png 677 741 */ 678 742 -
doc/images/bipartite_partitions.eps
r634 r1213 1 1 %!PS-Adobe-2.0 EPSF-2.0 2 2 %%Creator: LEMON, graphToEps() 3 %%CreationDate: Tue Nov 15 16:51:43 20053 %%CreationDate: Fri Mar 8 00:18:43 2013 4 4 %%BoundingBox: 0 0 842 596 5 5 %%EndComments … … 54 54 %Edges: 55 55 gsave 56 513.857 -446.322 296.569 -487.43 79.2808 -528.539 0 0 0 2lb57 513.857 -446.322 575.52 -315.65 5 637.183 -184.989 0 0 0 2lb58 393.468 566.711 494.771 434.577 596.074 302.442 0 0 0 2lb59 393.468 566.711 155.625 579.925 -82.2171 593.138 0 0 0 2lb60 393.468 566.711 251.056 450.726 108.644 334.741 0 0 0 2lb61 869.153 52.8539 732.613 177.648 596.074 302.442 0 0 0 2lb62 869.153 52.8539 753.168 -66.0676 637.183 -184.989 0 0 0 2lb63 -82.2171 593.138 -91.0261 346.487 -99.8351 99.8351 0 0 0 2lb64 -663.61 546.157 -753.168 394.936 -842.726 243.715 0 0 0 2lb65 -663.61 546.157 -574.052 437.513 -484.494 328.869 0 0 0 2lb66 -1077.63 161.498 -960.178 202.606 -842.726 243.715 0 0 0 2lb67 -1077.63 161.498 -968.987 66.0674 -860.344 -29.3633 0 0 0 2lb68 -1177.47 -234.906 -1029.18 -381.722 -880.898 -528.539 0 0 0 2lb69 -1177.47 -234.906 -1018.91 -132.135 -860.344 -29.3633 0 0 0 2lb70 -880.898 -528.539 -744.359 -387.595 -607.82 -246.651 0 0 0 2lb71 -499.175 -499.175 -355.295 -475.685 -211.415 -452.194 0 0 0 2lb72 -499.175 -499.175 -553.498 -372.913 -607.82 -246.651 0 0 0 2lb73 -499.175 -499.175 -386.587 -315.087 -274 -131 0 0 0 2lb74 79.2808 -528.539 -66.0671 -490.366 -211.415 -452.194 0 0 0 2lb75 637.183 -184.989 421.363 -253.993 205.543 -322.996 0 0 0 2lb76 205.543 -322.996 162.966 -226.097 120.389 -129.198 0 0 0 2lb77 399.34 88.0898 259.865 -20.5541 120.389 -129.198 0 0 0 2lb78 399.34 88.0898 253.992 211.415 108.644 334.741 0 0 0 2lb79 -842.726 243.715 -471.281 171.775 -99.8351 99.8351 0 0 0 2lb80 -842.726 243.715 -558.363 56.3575 -274 -131 0 0 0 2lb81 -860.344 -29.3633 -734.082 -138.007 -607.82 -246.651 0 0 0 2lb82 -211.415 -452.194 -45.513 -290.696 120.389 -129.198 0 0 0 2lb83 -99.8351 99.8351 4.40445 217.288 108.644 334.741 0 0 0 2lb84 -99.8351 99.8351 -292.165 214.352 -484.494 328.869 0 0 0 2lb85 120.389 -129.198 -76.8055 -130.099 -274 -131 0 0 0 2lb56 513.857 -446.322 296.569 -487.43 79.2808 -528.539 0 0 0 7.00153 lb 57 513.857 -446.322 575.52 -315.656 637.183 -184.989 0 0 0 7.00153 lb 58 393.468 566.711 494.771 434.577 596.074 302.442 0 0 0 7.00153 lb 59 393.468 566.711 155.625 579.925 -82.2171 593.138 0 0 0 7.00153 lb 60 393.468 566.711 251.056 450.726 108.644 334.741 0 0 0 7.00153 lb 61 869.153 52.8539 732.613 177.648 596.074 302.442 0 0 0 7.00153 lb 62 869.153 52.8539 753.168 -66.0676 637.183 -184.989 0 0 0 7.00153 lb 63 -82.2171 593.138 -91.0261 346.487 -99.8351 99.8351 0 0 0 7.00153 lb 64 -663.61 546.157 -753.168 394.936 -842.726 243.715 0 0 0 7.00153 lb 65 -663.61 546.157 -574.052 437.513 -484.494 328.869 0 0 0 7.00153 lb 66 -1077.63 161.498 -960.178 202.606 -842.726 243.715 0 0 0 7.00153 lb 67 -1077.63 161.498 -968.987 66.0674 -860.344 -29.3633 0 0 0 7.00153 lb 68 -1177.47 -234.906 -1029.18 -381.722 -880.898 -528.539 0 0 0 7.00153 lb 69 -1177.47 -234.906 -1018.91 -132.135 -860.344 -29.3633 0 0 0 7.00153 lb 70 -880.898 -528.539 -744.359 -387.595 -607.82 -246.651 0 0 0 7.00153 lb 71 -499.175 -499.175 -355.295 -475.685 -211.415 -452.194 0 0 0 7.00153 lb 72 -499.175 -499.175 -553.498 -372.913 -607.82 -246.651 0 0 0 7.00153 lb 73 -499.175 -499.175 -386.587 -315.087 -274 -131 0 0 0 7.00153 lb 74 79.2808 -528.539 -66.0671 -490.366 -211.415 -452.194 0 0 0 7.00153 lb 75 637.183 -184.989 421.363 -253.993 205.543 -322.996 0 0 0 7.00153 lb 76 205.543 -322.996 162.966 -226.097 120.389 -129.198 0 0 0 7.00153 lb 77 399.34 88.0898 259.865 -20.5541 120.389 -129.198 0 0 0 7.00153 lb 78 399.34 88.0898 253.992 211.415 108.644 334.741 0 0 0 7.00153 lb 79 -842.726 243.715 -471.281 171.775 -99.8351 99.8351 0 0 0 7.00153 lb 80 -842.726 243.715 -558.363 56.3575 -274 -131 0 0 0 7.00153 lb 81 -860.344 -29.3633 -734.082 -138.007 -607.82 -246.651 0 0 0 7.00153 lb 82 -211.415 -452.194 -45.513 -290.696 120.389 -129.198 0 0 0 7.00153 lb 83 -99.8351 99.8351 4.40445 217.288 108.644 334.741 0 0 0 7.00153 lb 84 -99.8351 99.8351 -292.165 214.352 -484.494 328.869 0 0 0 7.00153 lb 85 120.389 -129.198 -76.8055 -130.099 -274 -131 0 0 0 7.00153 lb 86 86 grestore 87 87 %Nodes: 88 88 gsave 89 -274 -131 2 01 0 0 nc90 -607.82 -246.651 2 01 0 0 nc91 -484.494 328.869 2 00 0 1 nc92 108.644 334.741 2 00 0 1 nc93 120.389 -129.198 2 00 0 1 nc94 -99.8351 99.8351 2 01 0 0 nc95 -211.415 -452.194 2 01 0 0 nc96 -860.344 -29.3633 2 00 0 1 nc97 -842.726 243.715 2 00 0 1 nc98 399.34 88.0898 2 01 0 0 nc99 205.543 -322.996 2 01 0 0 nc100 637.183 -184.989 2 00 0 1 nc101 79.2808 -528.539 2 00 0 1 nc102 -499.175 -499.175 2 00 0 1 nc103 -880.898 -528.539 2 00 0 1 nc104 -1177.47 -234.906 2 01 0 0 nc105 -1077.63 161.498 2 01 0 0 nc106 -663.61 546.157 2 01 0 0 nc107 -82.2171 593.138 2 00 0 1 nc108 596.074 302.442 2 00 0 1 nc109 869.153 52.8539 2 01 0 0 nc110 393.468 566.711 2 01 0 0 nc111 513.857 -446.322 2 01 0 0 nc89 -274 -131 23.3384 1 0 0 nc 90 -607.82 -246.651 23.3384 1 0 0 nc 91 -484.494 328.869 23.3384 0 0 1 nc 92 108.644 334.741 23.3384 0 0 1 nc 93 120.389 -129.198 23.3384 0 0 1 nc 94 -99.8351 99.8351 23.3384 1 0 0 nc 95 -211.415 -452.194 23.3384 1 0 0 nc 96 -860.344 -29.3633 23.3384 0 0 1 nc 97 -842.726 243.715 23.3384 0 0 1 nc 98 399.34 88.0898 23.3384 1 0 0 nc 99 205.543 -322.996 23.3384 1 0 0 nc 100 637.183 -184.989 23.3384 0 0 1 nc 101 79.2808 -528.539 23.3384 0 0 1 nc 102 -499.175 -499.175 23.3384 0 0 1 nc 103 -880.898 -528.539 23.3384 0 0 1 nc 104 -1177.47 -234.906 23.3384 1 0 0 nc 105 -1077.63 161.498 23.3384 1 0 0 nc 106 -663.61 546.157 23.3384 1 0 0 nc 107 -82.2171 593.138 23.3384 0 0 1 nc 108 596.074 302.442 23.3384 0 0 1 nc 109 869.153 52.8539 23.3384 1 0 0 nc 110 393.468 566.711 23.3384 1 0 0 nc 111 513.857 -446.322 23.3384 1 0 0 nc 112 112 grestore 113 113 grestore -
doc/images/connected_components.eps
r634 r1213 1 1 %!PS-Adobe-2.0 EPSF-2.0 2 2 %%Creator: LEMON, graphToEps() 3 %%CreationDate: Fri Nov 4 13:47:12 20053 %%CreationDate: Fri Mar 8 00:18:43 2013 4 4 %%BoundingBox: 0 0 842 596 5 5 %%EndComments … … 54 54 %Edges: 55 55 gsave 56 574.035 177.301 622.149 225.748 670.264 274.195 0 0 0 2lb57 694.579 115.483 682.421 194.839 670.264 274.195 0 0 0 2lb58 280.402 10.3938 246.402 -6.60595 212.403 -23.6057 0 0 0 2lb59 280.402 10.3938 283.493 -18.9695 286.584 -48.3327 0 0 0 2lb60 212.403 -23.6057 249.493 -35.9692 286.584 -48.3327 0 0 0 2lb61 286.584 -48.3327 326.765 -79.2414 366.947 -110.15 0 0 0 2lb62 286.584 -48.3327 278.857 -111.695 271.13 -175.058 0 0 0 2lb63 438.037 -88.514 417.946 -142.604 397.855 -196.694 0 0 0 2lb64 438.037 -88.514 402.492 -99.332 366.947 -110.15 0 0 0 2lb65 397.855 -196.694 382.401 -153.422 366.947 -110.15 0 0 0 2lb66 366.947 -110.15 319.038 -142.604 271.13 -175.058 0 0 0 2lb67 271.13 -175.058 274.221 -213.694 277.311 -252.33 0 0 0 2lb68 271.13 -175.058 238.675 -190.512 206.221 -205.967 0 0 0 2lb69 277.311 -252.33 241.766 -229.149 206.221 -205.967 0 0 0 2lb70 -840.856 -246.718 -804.351 -66.7145 -767.847 113.289 0 0 0 2lb71 -579.033 445.603 -673.44 279.446 -767.847 113.289 0 0 0 2lb72 -579.033 445.603 -524.906 302.104 -470.779 158.605 0 0 0 2lb73 -767.847 113.289 -619.313 135.947 -470.779 158.605 0 0 0 2lb74 906.312 201.403 946.592 42.798 986.873 -115.807 0 0 0 2lb75 906.312 201.403 834.562 91.8901 762.812 -17.6227 0 0 0 2lb76 986.873 -115.807 874.842 -66.7148 762.812 -17.6227 0 0 0 2lb77 -470.779 158.605 -390.218 50.3508 -309.657 -57.9033 0 0 0 2lb78 422.945 521.129 208.955 541.269 -5.03507 561.41 0 0 0 2lb79 422.945 521.129 376.371 417.911 329.797 314.692 0 0 0 2lb80 422.945 521.129 474.554 276.928 526.164 32.7279 0 0 0 2lb81 -5.03507 561.41 -36.5042 440.568 -67.9734 319.727 0 0 0 2lb82 329.797 314.692 130.912 317.209 -67.9734 319.727 0 0 0 2lb83 -67.9734 319.727 229.095 176.227 526.164 32.7279 0 0 0 2lb84 762.812 -17.6227 644.488 7.5526 526.164 32.7279 0 0 0 2lb85 762.812 -17.6227 746.448 -162.381 730.084 -307.139 0 0 0 2lb86 526.164 32.7279 470.779 -128.394 415.393 -289.516 0 0 0 2lb87 730.084 -307.139 572.738 -298.327 415.393 -289.516 0 0 0 2lb88 415.393 -289.516 173.71 -318.468 -67.9734 -347.42 0 0 0 2lb89 -67.9734 -347.42 -188.815 -202.662 -309.657 -57.9033 0 0 0 2lb90 -67.9734 -347.42 -195.758 -390.692 -323.543 -433.964 0 0 0 2lb91 -309.657 -57.9033 -424.775 -160.272 -539.894 -262.64 0 0 0 2lb92 -323.543 -433.964 -431.719 -348.302 -539.894 -262.64 0 0 0 2lb93 -26.6953 -19.9585 44.8558 -96.8093 116.407 -173.66 0 0 0 2lb94 -26.6953 -19.9585 87.2563 9.19185 201.208 38.3422 0 0 0 2lb95 -26.6953 -19.9585 -144.622 43.6422 -262.548 107.243 0 0 0 2lb96 -26.6953 -19.9585 -20.0703 56.8923 -13.4452 133.743 0 0 0 2lb97 116.407 -173.66 158.808 -67.6589 201.208 38.3422 0 0 0 2lb98 -262.548 107.243 -137.997 120.493 -13.4452 133.743 0 0 0 2lb99 -262.548 107.243 -221.472 176.144 -180.397 245.045 0 0 0 2lb100 -13.4452 133.743 -96.9211 189.394 -180.397 245.045 0 0 0 2lb101 -180.397 245.045 -1 42.256 345.099 -132.697 451.748 0 0 0 2lb102 -180.397 245.045 -1 70.838 351.694 -132.697 451.748 0 0 0 2lb103 -416.25 345.746 -274.474 398.747 -132.697 451.748 0 0 0 2lb104 -416.25 345.746 -393.725 457.048 -371.2 568.349 0 0 0 2lb105 -132.697 451.748 -251.948 510.048 -371.2 568.349 0 0 0 2lb106 670.264 274.195 629.188 409.347 588.113 544.499 0 0 0 2lb107 670.264 274.195 797.466 341.771 924.667 409.347 0 0 0 2lb108 588.113 544.499 756.39 476.923 924.667 409.347 0 0 0 2lb109 -689.204 -237.261 - 614.799 -102.648 -567.302 43.6423 0 0 0 2lb110 -689.204 -237.261 -6 41.707 -90.9706 -567.302 43.6423 0 0 0 2lb56 574.035 177.301 622.149 225.748 670.264 274.195 0 0 0 6.25356 lb 57 694.579 115.483 682.421 194.839 670.264 274.195 0 0 0 6.25356 lb 58 280.402 10.3938 246.402 -6.60595 212.403 -23.6057 0 0 0 6.25356 lb 59 280.402 10.3938 283.493 -18.9695 286.584 -48.3327 0 0 0 6.25356 lb 60 212.403 -23.6057 249.493 -35.9692 286.584 -48.3327 0 0 0 6.25356 lb 61 286.584 -48.3327 326.765 -79.2414 366.947 -110.15 0 0 0 6.25356 lb 62 286.584 -48.3327 278.857 -111.695 271.13 -175.058 0 0 0 6.25356 lb 63 438.037 -88.514 417.946 -142.604 397.855 -196.694 0 0 0 6.25356 lb 64 438.037 -88.514 402.492 -99.332 366.947 -110.15 0 0 0 6.25356 lb 65 397.855 -196.694 382.401 -153.422 366.947 -110.15 0 0 0 6.25356 lb 66 366.947 -110.15 319.038 -142.604 271.13 -175.058 0 0 0 6.25356 lb 67 271.13 -175.058 274.221 -213.694 277.311 -252.33 0 0 0 6.25356 lb 68 271.13 -175.058 238.675 -190.512 206.221 -205.967 0 0 0 6.25356 lb 69 277.311 -252.33 241.766 -229.149 206.221 -205.967 0 0 0 6.25356 lb 70 -840.856 -246.718 -804.351 -66.7145 -767.847 113.289 0 0 0 6.25356 lb 71 -579.033 445.603 -673.44 279.446 -767.847 113.289 0 0 0 6.25356 lb 72 -579.033 445.603 -524.906 302.104 -470.779 158.605 0 0 0 6.25356 lb 73 -767.847 113.289 -619.313 135.947 -470.779 158.605 0 0 0 6.25356 lb 74 906.312 201.403 946.592 42.798 986.873 -115.807 0 0 0 6.25356 lb 75 906.312 201.403 834.562 91.8901 762.812 -17.6227 0 0 0 6.25356 lb 76 986.873 -115.807 874.842 -66.7148 762.812 -17.6227 0 0 0 6.25356 lb 77 -470.779 158.605 -390.218 50.3508 -309.657 -57.9033 0 0 0 6.25356 lb 78 422.945 521.129 208.955 541.269 -5.03507 561.41 0 0 0 6.25356 lb 79 422.945 521.129 376.371 417.911 329.797 314.692 0 0 0 6.25356 lb 80 422.945 521.129 474.554 276.928 526.164 32.7279 0 0 0 6.25356 lb 81 -5.03507 561.41 -36.5042 440.568 -67.9734 319.727 0 0 0 6.25356 lb 82 329.797 314.692 130.912 317.209 -67.9734 319.727 0 0 0 6.25356 lb 83 -67.9734 319.727 229.095 176.227 526.164 32.7279 0 0 0 6.25356 lb 84 762.812 -17.6227 644.488 7.5526 526.164 32.7279 0 0 0 6.25356 lb 85 762.812 -17.6227 746.448 -162.381 730.084 -307.139 0 0 0 6.25356 lb 86 526.164 32.7279 470.779 -128.394 415.393 -289.516 0 0 0 6.25356 lb 87 730.084 -307.139 572.738 -298.327 415.393 -289.516 0 0 0 6.25356 lb 88 415.393 -289.516 173.71 -318.468 -67.9734 -347.42 0 0 0 6.25356 lb 89 -67.9734 -347.42 -188.815 -202.662 -309.657 -57.9033 0 0 0 6.25356 lb 90 -67.9734 -347.42 -195.758 -390.692 -323.543 -433.964 0 0 0 6.25356 lb 91 -309.657 -57.9033 -424.775 -160.272 -539.894 -262.64 0 0 0 6.25356 lb 92 -323.543 -433.964 -431.719 -348.302 -539.894 -262.64 0 0 0 6.25356 lb 93 -26.6953 -19.9585 44.8558 -96.8093 116.407 -173.66 0 0 0 6.25356 lb 94 -26.6953 -19.9585 87.2563 9.19185 201.208 38.3422 0 0 0 6.25356 lb 95 -26.6953 -19.9585 -144.622 43.6422 -262.548 107.243 0 0 0 6.25356 lb 96 -26.6953 -19.9585 -20.0703 56.8923 -13.4452 133.743 0 0 0 6.25356 lb 97 116.407 -173.66 158.808 -67.6589 201.208 38.3422 0 0 0 6.25356 lb 98 -262.548 107.243 -137.997 120.493 -13.4452 133.743 0 0 0 6.25356 lb 99 -262.548 107.243 -221.472 176.144 -180.397 245.045 0 0 0 6.25356 lb 100 -13.4452 133.743 -96.9211 189.394 -180.397 245.045 0 0 0 6.25356 lb 101 -180.397 245.045 -113.509 338.465 -132.697 451.748 0 0 0 6.25356 lb 102 -180.397 245.045 -199.585 358.328 -132.697 451.748 0 0 0 6.25356 lb 103 -416.25 345.746 -274.474 398.747 -132.697 451.748 0 0 0 6.25356 lb 104 -416.25 345.746 -393.725 457.048 -371.2 568.349 0 0 0 6.25356 lb 105 -132.697 451.748 -251.948 510.048 -371.2 568.349 0 0 0 6.25356 lb 106 670.264 274.195 629.188 409.347 588.113 544.499 0 0 0 6.25356 lb 107 670.264 274.195 797.466 341.771 924.667 409.347 0 0 0 6.25356 lb 108 588.113 544.499 756.39 476.923 924.667 409.347 0 0 0 6.25356 lb 109 -689.204 -237.261 -587.735 -114.393 -567.302 43.6423 0 0 0 6.25356 lb 110 -689.204 -237.261 -668.771 -79.2259 -567.302 43.6423 0 0 0 6.25356 lb 111 111 grestore 112 112 %Nodes: 113 113 gsave 114 -567.302 43.6423 20 0 0 0 nc115 -689.204 -237.261 20 0 0 0 nc116 924.667 409.347 20 1 0 0 nc117 588.113 544.499 20 1 0 0 nc118 670.264 274.195 20 1 0 0 nc119 -371.2 568.349 20 0 1 0 nc120 -132.697 451.748 20 0 1 0 nc121 -416.25 345.746 20 0 1 0 nc122 -180.397 245.045 20 0 1 0 nc123 -13.4452 133.743 20 0 1 0 nc124 -262.548 107.243 20 0 1 0 nc125 201.208 38.3422 20 0 1 0 nc126 116.407 -173.66 20 0 1 0 nc127 -26.6953 -19.9585 20 0 1 0 nc128 -539.894 -262.64 20 0 0 1 nc129 -323.543 -433.964 20 0 0 1 nc130 -309.657 -57.9033 20 0 0 1 nc131 -67.9734 -347.42 20 0 0 1 nc132 415.393 -289.516 20 0 0 1 nc133 730.084 -307.139 20 0 0 1 nc134 526.164 32.7279 20 0 0 1 nc135 762.812 -17.6227 20 0 0 1 nc136 -67.9734 319.727 20 0 0 1 nc137 329.797 314.692 20 0 0 1 nc138 -5.03507 561.41 20 0 0 1 nc139 422.945 521.129 20 0 0 1 nc140 -470.779 158.605 20 0 0 1 nc141 986.873 -115.807 20 0 0 1 nc142 906.312 201.403 20 0 0 1 nc143 -767.847 113.289 20 0 0 1 nc144 -579.033 445.603 20 0 0 1 nc145 -840.856 -246.718 20 0 0 1 nc146 206.221 -205.967 20 1 1 0 nc147 277.311 -252.33 20 1 1 0 nc148 271.13 -175.058 20 1 1 0 nc149 366.947 -110.15 20 1 1 0 nc150 397.855 -196.694 20 1 1 0 nc151 438.037 -88.514 20 1 1 0 nc152 286.584 -48.3327 20 1 1 0 nc153 212.403 -23.6057 20 1 1 0 nc154 280.402 10.3938 20 1 1 0 nc155 694.579 115.483 20 1 0 0 nc156 574.035 177.301 20 1 0 0 nc114 -567.302 43.6423 20.8452 0 0 0 nc 115 -689.204 -237.261 20.8452 0 0 0 nc 116 924.667 409.347 20.8452 1 0 0 nc 117 588.113 544.499 20.8452 1 0 0 nc 118 670.264 274.195 20.8452 1 0 0 nc 119 -371.2 568.349 20.8452 0 1 0 nc 120 -132.697 451.748 20.8452 0 1 0 nc 121 -416.25 345.746 20.8452 0 1 0 nc 122 -180.397 245.045 20.8452 0 1 0 nc 123 -13.4452 133.743 20.8452 0 1 0 nc 124 -262.548 107.243 20.8452 0 1 0 nc 125 201.208 38.3422 20.8452 0 1 0 nc 126 116.407 -173.66 20.8452 0 1 0 nc 127 -26.6953 -19.9585 20.8452 0 1 0 nc 128 -539.894 -262.64 20.8452 0 0 1 nc 129 -323.543 -433.964 20.8452 0 0 1 nc 130 -309.657 -57.9033 20.8452 0 0 1 nc 131 -67.9734 -347.42 20.8452 0 0 1 nc 132 415.393 -289.516 20.8452 0 0 1 nc 133 730.084 -307.139 20.8452 0 0 1 nc 134 526.164 32.7279 20.8452 0 0 1 nc 135 762.812 -17.6227 20.8452 0 0 1 nc 136 -67.9734 319.727 20.8452 0 0 1 nc 137 329.797 314.692 20.8452 0 0 1 nc 138 -5.03507 561.41 20.8452 0 0 1 nc 139 422.945 521.129 20.8452 0 0 1 nc 140 -470.779 158.605 20.8452 0 0 1 nc 141 986.873 -115.807 20.8452 0 0 1 nc 142 906.312 201.403 20.8452 0 0 1 nc 143 -767.847 113.289 20.8452 0 0 1 nc 144 -579.033 445.603 20.8452 0 0 1 nc 145 -840.856 -246.718 20.8452 0 0 1 nc 146 206.221 -205.967 20.8452 1 1 0 nc 147 277.311 -252.33 20.8452 1 1 0 nc 148 271.13 -175.058 20.8452 1 1 0 nc 149 366.947 -110.15 20.8452 1 1 0 nc 150 397.855 -196.694 20.8452 1 1 0 nc 151 438.037 -88.514 20.8452 1 1 0 nc 152 286.584 -48.3327 20.8452 1 1 0 nc 153 212.403 -23.6057 20.8452 1 1 0 nc 154 280.402 10.3938 20.8452 1 1 0 nc 155 694.579 115.483 20.8452 1 0 0 nc 156 574.035 177.301 20.8452 1 0 0 nc 157 157 grestore 158 158 grestore -
doc/images/edge_biconnected_components.eps
r634 r1213 1 1 %!PS-Adobe-2.0 EPSF-2.0 2 2 %%Creator: LEMON, graphToEps() 3 %%CreationDate: Fri Nov 4 13:47:12 20053 %%CreationDate: Fri Mar 8 00:18:43 2013 4 4 %%BoundingBox: 0 0 842 596 5 5 %%EndComments … … 54 54 %Edges: 55 55 gsave 56 574.035 177.301 622.149 225.748 670.264 274.195 1 0 0 2lb57 694.579 115.483 682.421 194.839 670.264 274.195 1 0 0 2lb58 280.402 10.3938 246.402 -6.60595 212.403 -23.6057 0 0 1 2lb59 280.402 10.3938 283.493 -18.9695 286.584 -48.3327 0 0 1 2lb60 212.403 -23.6057 249.493 -35.9692 286.584 -48.3327 0 0 1 2lb61 286.584 -48.3327 326.765 -79.2414 366.947 -110.15 0 0 1 2lb62 286.584 -48.3327 278.857 -111.695 271.13 -175.058 0 0 1 2lb63 438.037 -88.514 417.946 -142.604 397.855 -196.694 0 0 1 2lb64 438.037 -88.514 402.492 -99.332 366.947 -110.15 0 0 1 2lb65 397.855 -196.694 382.401 -153.422 366.947 -110.15 0 0 1 2lb66 366.947 -110.15 319.038 -142.604 271.13 -175.058 0 0 1 2lb67 271.13 -175.058 274.221 -213.694 277.311 -252.33 0 0 1 2lb68 271.13 -175.058 238.675 -190.512 206.221 -205.967 0 0 1 2lb69 277.311 -252.33 241.766 -229.149 206.221 -205.967 0 0 1 2lb70 -840.856 -246.718 -804.351 -66.7145 -767.847 113.289 1 0 0 2lb71 -579.033 445.603 -673.44 279.446 -767.847 113.289 0 0 1 2lb72 -579.033 445.603 -524.906 302.104 -470.779 158.605 0 0 1 2lb73 -767.847 113.289 -619.313 135.947 -470.779 158.605 0 0 1 2lb74 906.312 201.403 946.592 42.798 986.873 -115.807 0 0 1 2lb75 906.312 201.403 834.562 91.8901 762.812 -17.6227 0 0 1 2lb76 986.873 -115.807 874.842 -66.7148 762.812 -17.6227 0 0 1 2lb77 -470.779 158.605 -390.218 50.3508 -309.657 -57.9033 1 0 0 2lb78 422.945 521.129 208.955 541.269 -5.03507 561.41 0 0 1 2lb79 422.945 521.129 376.371 417.911 329.797 314.692 0 0 1 2lb80 422.945 521.129 474.554 276.928 526.164 32.7279 0 0 1 2lb81 -5.03507 561.41 -36.5042 440.568 -67.9734 319.727 0 0 1 2lb82 329.797 314.692 130.912 317.209 -67.9734 319.727 0 0 1 2lb83 -67.9734 319.727 229.095 176.227 526.164 32.7279 0 0 1 2lb84 762.812 -17.6227 644.488 7.5526 526.164 32.7279 0 0 1 2lb85 762.812 -17.6227 746.448 -162.381 730.084 -307.139 0 0 1 2lb86 526.164 32.7279 470.779 -128.394 415.393 -289.516 0 0 1 2lb87 730.084 -307.139 572.738 -298.327 415.393 -289.516 0 0 1 2lb88 415.393 -289.516 173.71 -318.468 -67.9734 -347.42 1 0 0 2lb89 -67.9734 -347.42 -188.815 -202.662 -309.657 -57.9033 0 0 1 2lb90 -67.9734 -347.42 -195.758 -390.692 -323.543 -433.964 0 0 1 2lb91 -309.657 -57.9033 -424.775 -160.272 -539.894 -262.64 0 0 1 2lb92 -323.543 -433.964 -431.719 -348.302 -539.894 -262.64 0 0 1 2lb93 -26.6953 -19.9585 44.8558 -96.8093 116.407 -173.66 0 0 1 2lb94 -26.6953 -19.9585 87.2563 9.19185 201.208 38.3422 0 0 1 2lb95 -26.6953 -19.9585 -144.622 43.6422 -262.548 107.243 0 0 1 2lb96 -26.6953 -19.9585 -20.0703 56.8923 -13.4452 133.743 0 0 1 2lb97 116.407 -173.66 158.808 -67.6589 201.208 38.3422 0 0 1 2lb98 -262.548 107.243 -137.997 120.493 -13.4452 133.743 0 0 1 2lb99 -262.548 107.243 -221.472 176.144 -180.397 245.045 0 0 1 2lb100 -13.4452 133.743 -96.9211 189.394 -180.397 245.045 0 0 1 2lb101 -180.397 245.045 -1 42.256 345.099 -132.697 451.748 0 0 1 2lb102 -180.397 245.045 -1 70.838 351.694 -132.697 451.748 0 0 1 2lb103 -416.25 345.746 -274.474 398.747 -132.697 451.748 0 0 1 2lb104 -416.25 345.746 -393.725 457.048 -371.2 568.349 0 0 1 2lb105 -132.697 451.748 -251.948 510.048 -371.2 568.349 0 0 1 2lb106 670.264 274.195 629.188 409.347 588.113 544.499 0 0 1 2lb107 670.264 274.195 797.466 341.771 924.667 409.347 0 0 1 2lb108 588.113 544.499 756.39 476.923 924.667 409.347 0 0 1 2lb109 -689.204 -237.261 - 614.799 -102.648 -567.302 43.6423 0 0 1 2lb110 -689.204 -237.261 -6 41.707 -90.9706 -567.302 43.6423 0 0 1 2lb56 574.035 177.301 622.149 225.748 670.264 274.195 1 0 0 6.25356 lb 57 694.579 115.483 682.421 194.839 670.264 274.195 1 0 0 6.25356 lb 58 280.402 10.3938 246.402 -6.60595 212.403 -23.6057 0 0 1 6.25356 lb 59 280.402 10.3938 283.493 -18.9695 286.584 -48.3327 0 0 1 6.25356 lb 60 212.403 -23.6057 249.493 -35.9692 286.584 -48.3327 0 0 1 6.25356 lb 61 286.584 -48.3327 326.765 -79.2414 366.947 -110.15 0 0 1 6.25356 lb 62 286.584 -48.3327 278.857 -111.695 271.13 -175.058 0 0 1 6.25356 lb 63 438.037 -88.514 417.946 -142.604 397.855 -196.694 0 0 1 6.25356 lb 64 438.037 -88.514 402.492 -99.332 366.947 -110.15 0 0 1 6.25356 lb 65 397.855 -196.694 382.401 -153.422 366.947 -110.15 0 0 1 6.25356 lb 66 366.947 -110.15 319.038 -142.604 271.13 -175.058 0 0 1 6.25356 lb 67 271.13 -175.058 274.221 -213.694 277.311 -252.33 0 0 1 6.25356 lb 68 271.13 -175.058 238.675 -190.512 206.221 -205.967 0 0 1 6.25356 lb 69 277.311 -252.33 241.766 -229.149 206.221 -205.967 0 0 1 6.25356 lb 70 -840.856 -246.718 -804.351 -66.7145 -767.847 113.289 1 0 0 6.25356 lb 71 -579.033 445.603 -673.44 279.446 -767.847 113.289 0 0 1 6.25356 lb 72 -579.033 445.603 -524.906 302.104 -470.779 158.605 0 0 1 6.25356 lb 73 -767.847 113.289 -619.313 135.947 -470.779 158.605 0 0 1 6.25356 lb 74 906.312 201.403 946.592 42.798 986.873 -115.807 0 0 1 6.25356 lb 75 906.312 201.403 834.562 91.8901 762.812 -17.6227 0 0 1 6.25356 lb 76 986.873 -115.807 874.842 -66.7148 762.812 -17.6227 0 0 1 6.25356 lb 77 -470.779 158.605 -390.218 50.3508 -309.657 -57.9033 1 0 0 6.25356 lb 78 422.945 521.129 208.955 541.269 -5.03507 561.41 0 0 1 6.25356 lb 79 422.945 521.129 376.371 417.911 329.797 314.692 0 0 1 6.25356 lb 80 422.945 521.129 474.554 276.928 526.164 32.7279 0 0 1 6.25356 lb 81 -5.03507 561.41 -36.5042 440.568 -67.9734 319.727 0 0 1 6.25356 lb 82 329.797 314.692 130.912 317.209 -67.9734 319.727 0 0 1 6.25356 lb 83 -67.9734 319.727 229.095 176.227 526.164 32.7279 0 0 1 6.25356 lb 84 762.812 -17.6227 644.488 7.5526 526.164 32.7279 0 0 1 6.25356 lb 85 762.812 -17.6227 746.448 -162.381 730.084 -307.139 0 0 1 6.25356 lb 86 526.164 32.7279 470.779 -128.394 415.393 -289.516 0 0 1 6.25356 lb 87 730.084 -307.139 572.738 -298.327 415.393 -289.516 0 0 1 6.25356 lb 88 415.393 -289.516 173.71 -318.468 -67.9734 -347.42 1 0 0 6.25356 lb 89 -67.9734 -347.42 -188.815 -202.662 -309.657 -57.9033 0 0 1 6.25356 lb 90 -67.9734 -347.42 -195.758 -390.692 -323.543 -433.964 0 0 1 6.25356 lb 91 -309.657 -57.9033 -424.775 -160.272 -539.894 -262.64 0 0 1 6.25356 lb 92 -323.543 -433.964 -431.719 -348.302 -539.894 -262.64 0 0 1 6.25356 lb 93 -26.6953 -19.9585 44.8558 -96.8093 116.407 -173.66 0 0 1 6.25356 lb 94 -26.6953 -19.9585 87.2563 9.19185 201.208 38.3422 0 0 1 6.25356 lb 95 -26.6953 -19.9585 -144.622 43.6422 -262.548 107.243 0 0 1 6.25356 lb 96 -26.6953 -19.9585 -20.0703 56.8923 -13.4452 133.743 0 0 1 6.25356 lb 97 116.407 -173.66 158.808 -67.6589 201.208 38.3422 0 0 1 6.25356 lb 98 -262.548 107.243 -137.997 120.493 -13.4452 133.743 0 0 1 6.25356 lb 99 -262.548 107.243 -221.472 176.144 -180.397 245.045 0 0 1 6.25356 lb 100 -13.4452 133.743 -96.9211 189.394 -180.397 245.045 0 0 1 6.25356 lb 101 -180.397 245.045 -113.509 338.465 -132.697 451.748 0 0 1 6.25356 lb 102 -180.397 245.045 -199.585 358.328 -132.697 451.748 0 0 1 6.25356 lb 103 -416.25 345.746 -274.474 398.747 -132.697 451.748 0 0 1 6.25356 lb 104 -416.25 345.746 -393.725 457.048 -371.2 568.349 0 0 1 6.25356 lb 105 -132.697 451.748 -251.948 510.048 -371.2 568.349 0 0 1 6.25356 lb 106 670.264 274.195 629.188 409.347 588.113 544.499 0 0 1 6.25356 lb 107 670.264 274.195 797.466 341.771 924.667 409.347 0 0 1 6.25356 lb 108 588.113 544.499 756.39 476.923 924.667 409.347 0 0 1 6.25356 lb 109 -689.204 -237.261 -587.735 -114.393 -567.302 43.6423 0 0 1 6.25356 lb 110 -689.204 -237.261 -668.771 -79.2259 -567.302 43.6423 0 0 1 6.25356 lb 111 111 grestore 112 112 %Nodes: 113 113 gsave 114 -567.302 43.6423 20 0 0 0 nc115 -689.204 -237.261 20 0 0 0 nc116 924.667 409.347 20 0 0 1 nc117 588.113 544.499 20 0 0 1 nc118 670.264 274.195 20 0 0 1 nc119 -371.2 568.349 20 1 1 0 nc120 -132.697 451.748 20 1 1 0 nc121 -416.25 345.746 20 1 1 0 nc122 -180.397 245.045 20 1 1 0 nc123 -13.4452 133.743 20 1 1 0 nc124 -262.548 107.243 20 1 1 0 nc125 201.208 38.3422 20 1 1 0 nc126 116.407 -173.66 20 1 1 0 nc127 -26.6953 -19.9585 20 1 1 0 nc128 -539.894 -262.64 20 0 0.5 0 nc129 -323.543 -433.964 20 0 0.5 0 nc130 -309.657 -57.9033 20 0 0.5 0 nc131 -67.9734 -347.42 20 0 0.5 0 nc132 415.393 -289.516 20 0.5 0 0 nc133 730.084 -307.139 20 0.5 0 0 nc134 526.164 32.7279 20 0.5 0 0 nc135 762.812 -17.6227 20 0.5 0 0 nc136 -67.9734 319.727 20 0.5 0 0 nc137 329.797 314.692 20 0.5 0 0 nc138 -5.03507 561.41 20 0.5 0 0 nc139 422.945 521.129 20 0.5 0 0 nc140 -470.779 158.605 20 0 1 1 nc141 986.873 -115.807 20 0.5 0 0 nc142 906.312 201.403 20 0.5 0 0 nc143 -767.847 113.289 20 0 1 1 nc144 -579.033 445.603 20 0 1 1 nc145 -840.856 -246.718 20 1 0 1 nc146 206.221 -205.967 20 0 0 0.5 nc147 277.311 -252.33 20 0 0 0.5 nc148 271.13 -175.058 20 0 0 0.5 nc149 366.947 -110.15 20 0 0 0.5 nc150 397.855 -196.694 20 0 0 0.5 nc151 438.037 -88.514 20 0 0 0.5 nc152 286.584 -48.3327 20 0 0 0.5 nc153 212.403 -23.6057 20 0 0 0.5 nc154 280.402 10.3938 20 0 0 0.5 nc155 694.579 115.483 20 1 0 0 nc156 574.035 177.301 20 0 1 0 nc114 -567.302 43.6423 20.8452 0 0 0 nc 115 -689.204 -237.261 20.8452 0 0 0 nc 116 924.667 409.347 20.8452 0 0 1 nc 117 588.113 544.499 20.8452 0 0 1 nc 118 670.264 274.195 20.8452 0 0 1 nc 119 -371.2 568.349 20.8452 1 1 0 nc 120 -132.697 451.748 20.8452 1 1 0 nc 121 -416.25 345.746 20.8452 1 1 0 nc 122 -180.397 245.045 20.8452 1 1 0 nc 123 -13.4452 133.743 20.8452 1 1 0 nc 124 -262.548 107.243 20.8452 1 1 0 nc 125 201.208 38.3422 20.8452 1 1 0 nc 126 116.407 -173.66 20.8452 1 1 0 nc 127 -26.6953 -19.9585 20.8452 1 1 0 nc 128 -539.894 -262.64 20.8452 0 0.5 0 nc 129 -323.543 -433.964 20.8452 0 0.5 0 nc 130 -309.657 -57.9033 20.8452 0 0.5 0 nc 131 -67.9734 -347.42 20.8452 0 0.5 0 nc 132 415.393 -289.516 20.8452 0.5 0 0 nc 133 730.084 -307.139 20.8452 0.5 0 0 nc 134 526.164 32.7279 20.8452 0.5 0 0 nc 135 762.812 -17.6227 20.8452 0.5 0 0 nc 136 -67.9734 319.727 20.8452 0.5 0 0 nc 137 329.797 314.692 20.8452 0.5 0 0 nc 138 -5.03507 561.41 20.8452 0.5 0 0 nc 139 422.945 521.129 20.8452 0.5 0 0 nc 140 -470.779 158.605 20.8452 0 1 1 nc 141 986.873 -115.807 20.8452 0.5 0 0 nc 142 906.312 201.403 20.8452 0.5 0 0 nc 143 -767.847 113.289 20.8452 0 1 1 nc 144 -579.033 445.603 20.8452 0 1 1 nc 145 -840.856 -246.718 20.8452 1 0 1 nc 146 206.221 -205.967 20.8452 0 0 0.5 nc 147 277.311 -252.33 20.8452 0 0 0.5 nc 148 271.13 -175.058 20.8452 0 0 0.5 nc 149 366.947 -110.15 20.8452 0 0 0.5 nc 150 397.855 -196.694 20.8452 0 0 0.5 nc 151 438.037 -88.514 20.8452 0 0 0.5 nc 152 286.584 -48.3327 20.8452 0 0 0.5 nc 153 212.403 -23.6057 20.8452 0 0 0.5 nc 154 280.402 10.3938 20.8452 0 0 0.5 nc 155 694.579 115.483 20.8452 1 0 0 nc 156 574.035 177.301 20.8452 0 1 0 nc 157 157 grestore 158 158 grestore -
doc/images/node_biconnected_components.eps
r634 r1213 1 1 %!PS-Adobe-2.0 EPSF-2.0 2 2 %%Creator: LEMON, graphToEps() 3 %%CreationDate: Fri Nov 4 13:47:12 20053 %%CreationDate: Fri Mar 8 00:18:43 2013 4 4 %%BoundingBox: 0 0 842 596 5 5 %%EndComments … … 54 54 %Edges: 55 55 gsave 56 574.035 177.301 622.149 225.748 670.264 274.195 0 1 0 5lb57 694.579 115.483 682.421 194.839 670.264 274.195 1 0 0 5lb58 280.402 10.3938 246.402 -6.60595 212.403 -23.6057 1 1 0.5 5lb59 280.402 10.3938 283.493 -18.9695 286.584 -48.3327 1 1 0.5 5lb60 212.403 -23.6057 249.493 -35.9692 286.584 -48.3327 1 1 0.5 5lb61 286.584 -48.3327 326.765 -79.2414 366.947 -110.15 1 0.5 1 5lb62 286.584 -48.3327 278.857 -111.695 271.13 -175.058 1 0.5 1 5lb63 438.037 -88.514 417.946 -142.604 397.855 -196.694 0.5 0.5 1 5lb64 438.037 -88.514 402.492 -99.332 366.947 -110.15 0.5 0.5 1 5lb65 397.855 -196.694 382.401 -153.422 366.947 -110.15 0.5 0.5 1 5lb66 366.947 -110.15 319.038 -142.604 271.13 -175.058 1 0.5 1 5lb67 271.13 -175.058 274.221 -213.694 277.311 -252.33 0.5 1 1 5lb68 271.13 -175.058 238.675 -190.512 206.221 -205.967 0.5 1 1 5lb69 277.311 -252.33 241.766 -229.149 206.221 -205.967 0.5 1 1 5lb70 -840.856 -246.718 -804.351 -66.7145 -767.847 113.289 0 0.5 0 5lb71 -579.033 445.603 -673.44 279.446 -767.847 113.289 0 0 0.5 5lb72 -579.033 445.603 -524.906 302.104 -470.779 158.605 0 0 0.5 5lb73 -767.847 113.289 -619.313 135.947 -470.779 158.605 0 0 0.5 5lb74 906.312 201.403 946.592 42.798 986.873 -115.807 0 0.5 0.5 5lb75 906.312 201.403 834.562 91.8901 762.812 -17.6227 0 0.5 0.5 5lb76 986.873 -115.807 874.842 -66.7148 762.812 -17.6227 0 0.5 0.5 5lb77 -470.779 158.605 -390.218 50.3508 -309.657 -57.9033 0.5 0.5 0 5lb78 422.945 521.129 208.955 541.269 -5.03507 561.41 0.5 0 0.5 5lb79 422.945 521.129 376.371 417.911 329.797 314.692 0.5 0 0.5 5lb80 422.945 521.129 474.554 276.928 526.164 32.7279 0.5 0 0.5 5lb81 -5.03507 561.41 -36.5042 440.568 -67.9734 319.727 0.5 0 0.5 5lb82 329.797 314.692 130.912 317.209 -67.9734 319.727 0.5 0 0.5 5lb83 -67.9734 319.727 229.095 176.227 526.164 32.7279 0.5 0 0.5 5lb84 762.812 -17.6227 644.488 7.5526 526.164 32.7279 0.5 0.5 0.5 5lb85 762.812 -17.6227 746.448 -162.381 730.084 -307.139 0.5 0.5 0.5 5lb86 526.164 32.7279 470.779 -128.394 415.393 -289.516 0.5 0.5 0.5 5lb87 730.084 -307.139 572.738 -298.327 415.393 -289.516 0.5 0.5 0.5 5lb88 415.393 -289.516 173.71 -318.468 -67.9734 -347.42 1 0.5 0.5 5lb89 -67.9734 -347.42 -188.815 -202.662 -309.657 -57.9033 0.5 1 0.5 5lb90 -67.9734 -347.42 -195.758 -390.692 -323.543 -433.964 0.5 1 0.5 5lb91 -309.657 -57.9033 -424.775 -160.272 -539.894 -262.64 0.5 1 0.5 5lb92 -323.543 -433.964 -431.719 -348.302 -539.894 -262.64 0.5 1 0.5 5lb93 -26.6953 -19.9585 44.8558 -96.8093 116.407 -173.66 1 1 0 5lb94 -26.6953 -19.9585 87.2563 9.19185 201.208 38.3422 1 1 0 5lb95 -26.6953 -19.9585 -144.622 43.6422 -262.548 107.243 1 0 1 5lb96 -26.6953 -19.9585 -20.0703 56.8923 -13.4452 133.743 1 0 1 5lb97 116.407 -173.66 158.808 -67.6589 201.208 38.3422 1 1 0 5lb98 -262.548 107.243 -137.997 120.493 -13.4452 133.743 1 0 1 5lb99 -262.548 107.243 -221.472 176.144 -180.397 245.045 1 0 1 5lb100 -13.4452 133.743 -96.9211 189.394 -180.397 245.045 1 0 1 5lb101 -180.397 245.045 -1 40.307 344.649 -132.697 451.748 0 1 1 5lb102 -180.397 245.045 -1 72.787 352.144 -132.697 451.748 0 1 1 5lb103 -416.25 345.746 -274.474 398.747 -132.697 451.748 0.5 0 0 5lb104 -416.25 345.746 -393.725 457.048 -371.2 568.349 0.5 0 0 5lb105 -132.697 451.748 -251.948 510.048 -371.2 568.349 0.5 0 0 5lb106 670.264 274.195 629.188 409.347 588.113 544.499 0 0 1 5lb107 670.264 274.195 797.466 341.771 924.667 409.347 0 0 1 5lb108 588.113 544.499 756.39 476.923 924.667 409.347 0 0 1 5lb109 -689.204 -237.261 - 612.964 -103.444 -567.302 43.6423 0 0 0 5lb110 -689.204 -237.261 -6 43.542 -90.1744 -567.302 43.6423 0 0 0 5lb56 574.035 177.301 622.149 225.748 670.264 274.195 0 1 0 6.25356 lb 57 694.579 115.483 682.421 194.839 670.264 274.195 1 0 0 6.25356 lb 58 280.402 10.3938 246.402 -6.60595 212.403 -23.6057 1 1 0.5 6.25356 lb 59 280.402 10.3938 283.493 -18.9695 286.584 -48.3327 1 1 0.5 6.25356 lb 60 212.403 -23.6057 249.493 -35.9692 286.584 -48.3327 1 1 0.5 6.25356 lb 61 286.584 -48.3327 326.765 -79.2414 366.947 -110.15 1 0.5 1 6.25356 lb 62 286.584 -48.3327 278.857 -111.695 271.13 -175.058 1 0.5 1 6.25356 lb 63 438.037 -88.514 417.946 -142.604 397.855 -196.694 0.5 0.5 1 6.25356 lb 64 438.037 -88.514 402.492 -99.332 366.947 -110.15 0.5 0.5 1 6.25356 lb 65 397.855 -196.694 382.401 -153.422 366.947 -110.15 0.5 0.5 1 6.25356 lb 66 366.947 -110.15 319.038 -142.604 271.13 -175.058 1 0.5 1 6.25356 lb 67 271.13 -175.058 274.221 -213.694 277.311 -252.33 0.5 1 1 6.25356 lb 68 271.13 -175.058 238.675 -190.512 206.221 -205.967 0.5 1 1 6.25356 lb 69 277.311 -252.33 241.766 -229.149 206.221 -205.967 0.5 1 1 6.25356 lb 70 -840.856 -246.718 -804.351 -66.7145 -767.847 113.289 0 0.5 0 6.25356 lb 71 -579.033 445.603 -673.44 279.446 -767.847 113.289 0 0 0.5 6.25356 lb 72 -579.033 445.603 -524.906 302.104 -470.779 158.605 0 0 0.5 6.25356 lb 73 -767.847 113.289 -619.313 135.947 -470.779 158.605 0 0 0.5 6.25356 lb 74 906.312 201.403 946.592 42.798 986.873 -115.807 0 0.5 0.5 6.25356 lb 75 906.312 201.403 834.562 91.8901 762.812 -17.6227 0 0.5 0.5 6.25356 lb 76 986.873 -115.807 874.842 -66.7148 762.812 -17.6227 0 0.5 0.5 6.25356 lb 77 -470.779 158.605 -390.218 50.3508 -309.657 -57.9033 0.5 0.5 0 6.25356 lb 78 422.945 521.129 208.955 541.269 -5.03507 561.41 0.5 0 0.5 6.25356 lb 79 422.945 521.129 376.371 417.911 329.797 314.692 0.5 0 0.5 6.25356 lb 80 422.945 521.129 474.554 276.928 526.164 32.7279 0.5 0 0.5 6.25356 lb 81 -5.03507 561.41 -36.5042 440.568 -67.9734 319.727 0.5 0 0.5 6.25356 lb 82 329.797 314.692 130.912 317.209 -67.9734 319.727 0.5 0 0.5 6.25356 lb 83 -67.9734 319.727 229.095 176.227 526.164 32.7279 0.5 0 0.5 6.25356 lb 84 762.812 -17.6227 644.488 7.5526 526.164 32.7279 0.5 0.5 0.5 6.25356 lb 85 762.812 -17.6227 746.448 -162.381 730.084 -307.139 0.5 0.5 0.5 6.25356 lb 86 526.164 32.7279 470.779 -128.394 415.393 -289.516 0.5 0.5 0.5 6.25356 lb 87 730.084 -307.139 572.738 -298.327 415.393 -289.516 0.5 0.5 0.5 6.25356 lb 88 415.393 -289.516 173.71 -318.468 -67.9734 -347.42 1 0.5 0.5 6.25356 lb 89 -67.9734 -347.42 -188.815 -202.662 -309.657 -57.9033 0.5 1 0.5 6.25356 lb 90 -67.9734 -347.42 -195.758 -390.692 -323.543 -433.964 0.5 1 0.5 6.25356 lb 91 -309.657 -57.9033 -424.775 -160.272 -539.894 -262.64 0.5 1 0.5 6.25356 lb 92 -323.543 -433.964 -431.719 -348.302 -539.894 -262.64 0.5 1 0.5 6.25356 lb 93 -26.6953 -19.9585 44.8558 -96.8093 116.407 -173.66 1 1 0 6.25356 lb 94 -26.6953 -19.9585 87.2563 9.19185 201.208 38.3422 1 1 0 6.25356 lb 95 -26.6953 -19.9585 -144.622 43.6422 -262.548 107.243 1 0 1 6.25356 lb 96 -26.6953 -19.9585 -20.0703 56.8923 -13.4452 133.743 1 0 1 6.25356 lb 97 116.407 -173.66 158.808 -67.6589 201.208 38.3422 1 1 0 6.25356 lb 98 -262.548 107.243 -137.997 120.493 -13.4452 133.743 1 0 1 6.25356 lb 99 -262.548 107.243 -221.472 176.144 -180.397 245.045 1 0 1 6.25356 lb 100 -13.4452 133.743 -96.9211 189.394 -180.397 245.045 1 0 1 6.25356 lb 101 -180.397 245.045 -113.509 338.465 -132.697 451.748 0 1 1 6.25356 lb 102 -180.397 245.045 -199.585 358.328 -132.697 451.748 0 1 1 6.25356 lb 103 -416.25 345.746 -274.474 398.747 -132.697 451.748 0.5 0 0 6.25356 lb 104 -416.25 345.746 -393.725 457.048 -371.2 568.349 0.5 0 0 6.25356 lb 105 -132.697 451.748 -251.948 510.048 -371.2 568.349 0.5 0 0 6.25356 lb 106 670.264 274.195 629.188 409.347 588.113 544.499 0 0 1 6.25356 lb 107 670.264 274.195 797.466 341.771 924.667 409.347 0 0 1 6.25356 lb 108 588.113 544.499 756.39 476.923 924.667 409.347 0 0 1 6.25356 lb 109 -689.204 -237.261 -587.735 -114.393 -567.302 43.6423 0 0 0 6.25356 lb 110 -689.204 -237.261 -668.771 -79.2259 -567.302 43.6423 0 0 0 6.25356 lb 111 111 grestore 112 112 %Nodes: 113 113 gsave 114 -567.302 43.6423 20 0 0 1 nc115 -689.204 -237.261 20 0 0 1 nc116 924.667 409.347 20 0 0 1 nc117 588.113 544.499 20 0 0 1 nc118 670.264 274.195 20 1 0 0 nc119 -371.2 568.349 20 0 0 1 nc120 -132.697 451.748 20 1 0 0 nc121 -416.25 345.746 20 0 0 1 nc122 -180.397 245.045 20 1 0 0 nc123 -13.4452 133.743 20 0 0 1 nc124 -262.548 107.243 20 0 0 1 nc125 201.208 38.3422 20 0 0 1 nc126 116.407 -173.66 20 0 0 1 nc127 -26.6953 -19.9585 20 1 0 0 nc128 -539.894 -262.64 20 0 0 1 nc129 -323.543 -433.964 20 0 0 1 nc130 -309.657 -57.9033 20 1 0 0 nc131 -67.9734 -347.42 20 1 0 0 nc132 415.393 -289.516 20 1 0 0 nc133 730.084 -307.139 20 0 0 1 nc134 526.164 32.7279 20 1 0 0 nc135 762.812 -17.6227 20 1 0 0 nc136 -67.9734 319.727 20 0 0 1 nc137 329.797 314.692 20 0 0 1 nc138 -5.03507 561.41 20 0 0 1 nc139 422.945 521.129 20 0 0 1 nc140 -470.779 158.605 20 1 0 0 nc141 986.873 -115.807 20 0 0 1 nc142 906.312 201.403 20 0 0 1 nc143 -767.847 113.289 20 1 0 0 nc144 -579.033 445.603 20 0 0 1 nc145 -840.856 -246.718 20 0 0 1 nc146 206.221 -205.967 20 0 0 1 nc147 277.311 -252.33 20 0 0 1 nc148 271.13 -175.058 20 1 0 0 nc149 366.947 -110.15 20 1 0 0 nc150 397.855 -196.694 20 0 0 1 nc151 438.037 -88.514 20 0 0 1 nc152 286.584 -48.3327 20 1 0 0 nc153 212.403 -23.6057 20 0 0 1 nc154 280.402 10.3938 20 0 0 1 nc155 694.579 115.483 20 0 0 1 nc156 574.035 177.301 20 0 0 1 nc114 -567.302 43.6423 20.8452 0 0 1 nc 115 -689.204 -237.261 20.8452 0 0 1 nc 116 924.667 409.347 20.8452 0 0 1 nc 117 588.113 544.499 20.8452 0 0 1 nc 118 670.264 274.195 20.8452 1 0 0 nc 119 -371.2 568.349 20.8452 0 0 1 nc 120 -132.697 451.748 20.8452 1 0 0 nc 121 -416.25 345.746 20.8452 0 0 1 nc 122 -180.397 245.045 20.8452 1 0 0 nc 123 -13.4452 133.743 20.8452 0 0 1 nc 124 -262.548 107.243 20.8452 0 0 1 nc 125 201.208 38.3422 20.8452 0 0 1 nc 126 116.407 -173.66 20.8452 0 0 1 nc 127 -26.6953 -19.9585 20.8452 1 0 0 nc 128 -539.894 -262.64 20.8452 0 0 1 nc 129 -323.543 -433.964 20.8452 0 0 1 nc 130 -309.657 -57.9033 20.8452 1 0 0 nc 131 -67.9734 -347.42 20.8452 1 0 0 nc 132 415.393 -289.516 20.8452 1 0 0 nc 133 730.084 -307.139 20.8452 0 0 1 nc 134 526.164 32.7279 20.8452 1 0 0 nc 135 762.812 -17.6227 20.8452 1 0 0 nc 136 -67.9734 319.727 20.8452 0 0 1 nc 137 329.797 314.692 20.8452 0 0 1 nc 138 -5.03507 561.41 20.8452 0 0 1 nc 139 422.945 521.129 20.8452 0 0 1 nc 140 -470.779 158.605 20.8452 1 0 0 nc 141 986.873 -115.807 20.8452 0 0 1 nc 142 906.312 201.403 20.8452 0 0 1 nc 143 -767.847 113.289 20.8452 1 0 0 nc 144 -579.033 445.603 20.8452 0 0 1 nc 145 -840.856 -246.718 20.8452 0 0 1 nc 146 206.221 -205.967 20.8452 0 0 1 nc 147 277.311 -252.33 20.8452 0 0 1 nc 148 271.13 -175.058 20.8452 1 0 0 nc 149 366.947 -110.15 20.8452 1 0 0 nc 150 397.855 -196.694 20.8452 0 0 1 nc 151 438.037 -88.514 20.8452 0 0 1 nc 152 286.584 -48.3327 20.8452 1 0 0 nc 153 212.403 -23.6057 20.8452 0 0 1 nc 154 280.402 10.3938 20.8452 0 0 1 nc 155 694.579 115.483 20.8452 0 0 1 nc 156 574.035 177.301 20.8452 0 0 1 nc 157 157 grestore 158 158 grestore -
doc/images/strongly_connected_components.eps
r634 r1213 1 1 %!PS-Adobe-2.0 EPSF-2.0 2 2 %%Creator: LEMON, graphToEps() 3 %%CreationDate: Fri Nov 4 13:47:12 20053 %%CreationDate: Fri Mar 8 00:22:15 2013 4 4 %%BoundingBox: 0 0 842 596 5 5 %%EndComments … … 54 54 %Edges: 55 55 gsave 56 2setlinewidth 0 0 1 setrgbcolor newpath56 4.56973 setlinewidth 0 0 1 setrgbcolor newpath 57 57 218.178 27.2723 moveto 58 19 2.373 -40.1551 188.622 -49.9556 169.228 -100.631curveto stroke59 newpath 16 4.939 -111.838 moveto 165.492 -99.2013 lineto 172.964 -102.061lineto closepath fill60 2setlinewidth 0 0 1 setrgbcolor newpath58 195.849 -31.0725 190.033 -46.2697 176.306 -82.1369 curveto stroke 59 newpath 163.235 -116.291 moveto 165.206 -77.8889 lineto 187.405 -86.3849 lineto closepath fill 60 4.56973 setlinewidth 0 0 1 setrgbcolor newpath 61 61 44.8044 15.5841 moveto 62 1 19.293 20.6059 129.775 21.3125 186.25 25.1199 curveto stroke63 newpath 198.223 25.927 moveto 186.519 21.1289 lineto 185.981 29.1108 lineto closepath fill64 2setlinewidth 1 0 0 setrgbcolor newpath62 109.705 19.9594 126.016 21.0591 166.493 23.7879 curveto stroke 63 newpath 202.98 26.2477 moveto 167.292 11.9299 lineto 165.694 35.6458 lineto closepath fill 64 4.56973 setlinewidth 1 0 0 setrgbcolor newpath 65 65 218.178 27.2723 moveto 66 28 5.395 -87.4449 290.763 -96.6058 348.102 -194.464curveto stroke67 newpath 35 4.169 -204.818 moveto 344.651 -196.487 lineto 351.554 -192.442lineto closepath fill68 2setlinewidth 0 0 1 setrgbcolor newpath66 281.264 -80.3935 289.87 -95.0808 338.092 -177.379 curveto stroke 67 newpath 356.579 -208.932 moveto 327.837 -183.388 lineto 348.346 -171.371 lineto closepath fill 68 4.56973 setlinewidth 0 0 1 setrgbcolor newpath 69 69 157.79 -130.517 moveto 70 1 08.71 -67.0521 102.27 -58.7243 64.3804 -9.72954 curveto stroke71 newpath 5 7.0394 -0.236898 moveto 67.5446 -7.28254 lineto 61.2162 -12.1765lineto closepath fill72 2setlinewidth 1 0 0 setrgbcolor newpath70 114.446 -74.4692 104.358 -61.4239 76.4943 -25.394 curveto stroke 71 newpath 54.1228 3.53455 moveto 85.8959 -18.1234 lineto 67.0928 -32.6646 lineto closepath fill 72 4.56973 setlinewidth 1 0 0 setrgbcolor newpath 73 73 -105.193 -261.035 moveto 74 -3 5.6576 -132.801 -30.5923 -123.459 29.5506 -12.5464curveto stroke75 newpath 3 5.2708 -1.99743 moveto 33.0669 -14.4531 lineto 26.0343 -10.6397lineto closepath fill76 2setlinewidth 0 0 1 setrgbcolor newpath74 -39.4801 -139.85 -31.344 -124.846 20.1113 -29.9539 curveto stroke 75 newpath 37.5434 2.19358 moveto 30.559 -35.6192 lineto 9.66361 -24.2886 lineto closepath fill 76 4.56973 setlinewidth 0 0 1 setrgbcolor newpath 77 77 -465.576 -42.8564 moveto 78 -55 9.078 -25.5413 -569.47 -23.6169 -644.498 -9.72286 curveto stroke79 newpath -6 56.297 -7.5378 moveto -643.77 -5.78973 lineto -645.226 -13.656lineto closepath fill80 2setlinewidth 0 0 1 setrgbcolor newpath78 -550.335 -27.1603 -566.8 -24.1113 -625.027 -13.3286 curveto stroke 79 newpath -660.985 -6.66971 moveto -622.863 -1.64245 lineto -627.191 -25.0148 lineto closepath fill 80 4.56973 setlinewidth 0 0 1 setrgbcolor newpath 81 81 -574.666 -153.893 moveto 82 -5 28.842 -107.252 -521.515 -99.794 -488.002 -65.683curveto stroke83 newpath -47 9.592 -57.123 moveto -485.149 -68.4863 lineto -490.856 -62.8797lineto closepath fill84 2setlinewidth 1 0 0 setrgbcolor newpath82 -535.911 -114.447 -524.692 -103.027 -501.88 -79.8085 curveto stroke 83 newpath -476.251 -53.7222 moveto -493.402 -88.1377 lineto -510.358 -71.4793 lineto closepath fill 84 4.56973 setlinewidth 1 0 0 setrgbcolor newpath 85 85 -490.901 120.777 moveto 86 -48 0.122 51.1328 -478.519 40.7713 -470.47 -11.2329curveto stroke87 newpath -46 8.635 -23.0917 moveto -474.423 -11.8447 lineto -466.517 -10.6212lineto closepath fill88 2setlinewidth 0 0 1 setrgbcolor newpath86 -481.623 60.8277 -479.143 44.8049 -473.499 8.33636 curveto stroke 87 newpath -467.906 -27.8032 moveto -485.244 6.51862 lineto -461.754 10.1541 lineto closepath fill 88 4.56973 setlinewidth 0 0 1 setrgbcolor newpath 89 89 -675.963 -3.89604 moveto 90 -63 2.116 -68.8235 -626.228 -77.5422 -592.575 -127.374curveto stroke91 newpath -58 5.859 -137.319 moveto -595.89 -129.612 lineto -589.26 -125.135lineto closepath fill92 2setlinewidth 0 0 1 setrgbcolor newpath90 -637.405 -60.9909 -628.201 -74.6206 -603.658 -110.963 curveto stroke 91 newpath -583.191 -141.27 moveto -613.507 -117.615 lineto -593.808 -104.312 lineto closepath fill 92 4.56973 setlinewidth 0 0 1 setrgbcolor newpath 93 93 -490.901 120.777 moveto 94 -43 5.445 215.844 -430.107 224.995 -384.3 303.522curveto stroke95 newpath -37 8.253 313.887 moveto -380.845 301.507 lineto -387.755 305.537lineto closepath fill96 2setlinewidth 0 0 1 setrgbcolor newpath94 -439.75 208.465 -431.238 223.057 -394.278 286.417 curveto stroke 95 newpath -375.851 318.006 moveto -384.012 280.429 lineto -404.543 292.406 lineto closepath fill 96 4.56973 setlinewidth 0 0 1 setrgbcolor newpath 97 97 -266.879 114.933 moveto 98 -3 67.067 117.547 -377.642 117.822 -458.912 119.943curveto stroke99 newpath -47 0.908 120.255 moveto -458.807 123.941 lineto -459.016 115.944lineto closepath fill100 2setlinewidth 0 0 1 setrgbcolor newpath98 -358.311 117.318 -375.109 117.756 -439.117 119.426 curveto stroke 99 newpath -475.674 120.38 moveto -438.807 131.307 lineto -439.426 107.545 lineto closepath fill 100 4.56973 setlinewidth 0 0 1 setrgbcolor newpath 101 101 -368.176 331.163 moveto 102 -32 2.511 233.685 -318.018 224.095 -280.454 143.911curveto stroke103 newpath -27 5.364 133.044 moveto -284.076 142.214 lineto -276.832 145.608lineto closepath fill104 2setlinewidth 1 0 0 setrgbcolor newpath102 -326.156 241.466 -318.997 226.186 -288.855 161.843 curveto stroke 103 newpath -273.341 128.727 moveto -299.617 156.801 lineto -278.092 166.885 lineto closepath fill 104 4.56973 setlinewidth 1 0 0 setrgbcolor newpath 105 105 -266.879 114.933 moveto 106 -22 4.004 235.52 -220.448 245.52 -184.094 347.765curveto stroke107 newpath -1 80.074 359.072 moveto -180.325 346.425 lineto -187.863 349.105lineto closepath fill108 2setlinewidth 0 0 1 setrgbcolor newpath106 -226.764 227.755 -221.069 243.774 -190.728 329.107 curveto stroke 107 newpath -178.477 363.564 moveto -179.53 325.126 lineto -201.926 333.089 lineto closepath fill 108 4.56973 setlinewidth 0 0 1 setrgbcolor newpath 109 109 -251.294 -335.059 moveto 110 -1 89.25 -303.624 -179.902 -298.887 -133.738 -275.498 curveto stroke111 newpath -1 23.034 -270.074 moveto -131.93 -279.066 lineto -135.546 -271.93lineto closepath fill112 2setlinewidth 0 0 1 setrgbcolor newpath110 -198.044 -308.079 -183.61 -300.766 -151.402 -284.448 curveto stroke 111 newpath -118.781 -267.92 moveto -146.031 -295.049 lineto -156.774 -273.846 lineto closepath fill 112 4.56973 setlinewidth 0 0 1 setrgbcolor newpath 113 113 -389.604 -136.361 moveto 114 -3 27.15 -226.083 -321.098 -234.777 -269.576 -308.795curveto stroke115 newpath -2 62.72 -318.644 moveto -272.859 -311.081 lineto -266.293 -306.51lineto closepath fill116 2setlinewidth 1 0 0 setrgbcolor newpath114 -332.039 -219.059 -322.392 -232.919 -280.889 -292.543 curveto stroke 115 newpath -259.996 -322.557 moveto -290.643 -299.333 lineto -271.134 -285.753 lineto closepath fill 116 4.56973 setlinewidth 1 0 0 setrgbcolor newpath 117 117 5.84406 175.322 moveto 118 -7 6.0754 267.926 -83.1051 275.873 -152.172 353.948curveto stroke119 newpath -16 0.122 362.936 moveto -149.176 356.598 lineto -155.168 351.298lineto closepath fill120 2setlinewidth 0 0 1 setrgbcolor newpath118 -70.5724 261.706 -81.8227 274.423 -139.051 339.116 curveto stroke 119 newpath -163.281 366.507 moveto -130.149 346.991 lineto -147.953 331.242 lineto closepath fill 120 4.56973 setlinewidth 0 0 1 setrgbcolor newpath 121 121 169.478 311.683 moveto 122 96.8003 251.119 88.6819 244.353 30.4273 195.808curveto stroke123 newpath 21.2086 188.126 moveto 27.8666 198.881 lineto 32.988 192.735 lineto closepath fill124 2setlinewidth 0 0 1 setrgbcolor newpath122 103.641 256.819 90.7821 246.103 45.6398 208.485 curveto stroke 123 newpath 17.546 185.074 moveto 38.0313 217.615 lineto 53.2483 199.355 lineto closepath fill 124 4.56973 setlinewidth 0 0 1 setrgbcolor newpath 125 125 342.851 111.037 moveto 126 26 3.766 202.563 256.831 210.589 190.4 287.47curveto stroke127 newpath 1 82.554 296.55 moveto 193.427 290.085 lineto 187.373 284.855lineto closepath fill128 2setlinewidth 0 0 1 setrgbcolor newpath126 269.224 196.246 258.132 209.083 203.347 272.486 curveto stroke 127 newpath 179.437 300.157 moveto 212.34 280.257 lineto 194.354 264.716 lineto closepath fill 128 4.56973 setlinewidth 0 0 1 setrgbcolor newpath 129 129 5.84406 175.322 moveto 130 1 63.16 145.314 173.605 143.321 311.418 117.033 curveto stroke131 newpath 32 3.205 114.784 moveto 310.668 113.104 lineto 312.167 120.962lineto closepath fill132 2setlinewidth 0 0 1 setrgbcolor newpath130 155.419 146.79 172.221 143.585 291.966 120.743 curveto stroke 131 newpath 327.888 113.891 moveto 289.739 109.069 lineto 294.193 132.418 lineto closepath fill 132 4.56973 setlinewidth 0 0 1 setrgbcolor newpath 133 133 342.851 111.037 moveto 134 49 7.255 2.58683 505.964 -3.53033 643.932 -100.436curveto stroke135 newpath 65 3.752 -107.334 moveto 641.633 -103.71 lineto 646.231 -97.163lineto closepath fill136 2setlinewidth 0 0 1 setrgbcolor newpath134 490.978 6.99574 505.015 -2.86383 627.727 -89.0547 curveto stroke 135 newpath 657.653 -110.074 moveto 620.896 -98.7802 lineto 634.558 -79.3291 lineto closepath fill 136 4.56973 setlinewidth 0 0 1 setrgbcolor newpath 137 137 364.28 -222.074 moveto 138 354. 298 -66.9063 353.616 -56.2971 344.905 79.1029curveto stroke139 newpath 34 4.135 91.0781 moveto 348.897 79.3597 lineto 340.914 78.8461lineto closepath fill140 2setlinewidth 0 0 1 setrgbcolor newpath138 354.807 -74.8128 353.709 -57.7536 346.177 59.3416 curveto stroke 139 newpath 343.829 95.836 moveto 358.037 60.1045 lineto 334.316 58.5786 lineto closepath fill 140 4.56973 setlinewidth 0 0 1 setrgbcolor newpath 141 141 670.118 -118.829 moveto 142 5 28.037 -166.793 517.967 -170.192 394.599 -211.839curveto stroke143 newpath 3 83.229 -215.677 moveto 393.32 -208.049 lineto 395.878 -215.629lineto closepath fill144 2setlinewidth 1 0 0 setrgbcolor newpath142 535.595 -164.241 519.412 -169.704 413.361 -205.505 curveto stroke 143 newpath 378.712 -217.202 moveto 409.559 -194.245 lineto 417.162 -216.766 lineto closepath fill 144 4.56973 setlinewidth 1 0 0 setrgbcolor newpath 145 145 -105.193 -261.035 moveto 146 11 8.401 -242.479 129.015 -241.598 332.39 -224.721curveto stroke147 newpath 34 4.348 -223.728 moveto 332.72 -228.707 lineto 332.059 -220.734 lineto closepath fill148 2setlinewidth 0 0 1 setrgbcolor newpath146 110.939 -243.099 128.069 -241.677 312.655 -226.358 curveto stroke 147 newpath 349.1 -223.334 moveto 313.638 -238.202 lineto 311.672 -214.514 lineto closepath fill 148 4.56973 setlinewidth 0 0 1 setrgbcolor newpath 149 149 -105.193 -261.035 moveto 150 -1 60.867 -161.176 -166.028 -151.918 -212.336 -68.858curveto stroke151 newpath -2 18.179 -58.3769 moveto -208.842 -66.9102 lineto -215.829 -70.8058lineto closepath fill152 2setlinewidth 0 0 1 setrgbcolor newpath150 -156.746 -168.566 -164.987 -153.784 -202.693 -86.1539 curveto stroke 151 newpath -220.5 -54.2129 moveto -192.312 -80.3665 lineto -213.073 -91.9413 lineto closepath fill 152 4.56973 setlinewidth 0 0 1 setrgbcolor newpath 153 153 -227.918 -40.9084 moveto 154 -29 8.35 -82.4884 -307.42 -87.8432 -362.048 -120.093curveto stroke155 newpath -37 2.381 -126.193 moveto -364.081 -116.648 lineto -360.014 -123.537lineto closepath fill154 -290.327 -77.7521 -304.558 -86.1532 -344.995 -110.026 curveto stroke 155 newpath -376.487 -128.617 moveto -351.037 -99.7914 lineto -338.953 -120.26 lineto closepath fill 156 156 grestore 157 157 %Nodes: 158 158 gsave 159 -389.604 -136.361 200 1 0 nc160 -227.918 -40.9084 200 1 0 nc161 -105.193 -261.035 200 1 0 nc162 364.28 -222.074 201 1 0 nc163 670.118 -118.829 201 1 0 nc164 342.851 111.037 201 1 0 nc165 5.84406 175.322 201 1 0 nc166 169.478 311.683 201 1 0 nc167 -173.374 377.916 201 0 1 nc168 -251.294 -335.059 200 1 0 nc169 -266.879 114.933 200 0 0 nc170 -368.176 331.163 200 0 0 nc171 -490.901 120.777 200 0 0 nc172 -574.666 -153.893 201 0 0 nc173 -675.963 -3.89604 201 0 0 nc174 -465.576 -42.8564 201 0 0 nc175 44.8044 15.5841 200 0 1 nc176 157.79 -130.517 200 0 1 nc177 218.178 27.2723 200 0 1 nc159 -389.604 -136.361 15.2324 0 1 0 nc 160 -227.918 -40.9084 15.2324 0 1 0 nc 161 -105.193 -261.035 15.2324 0 1 0 nc 162 364.28 -222.074 15.2324 1 1 0 nc 163 670.118 -118.829 15.2324 1 1 0 nc 164 342.851 111.037 15.2324 1 1 0 nc 165 5.84406 175.322 15.2324 1 1 0 nc 166 169.478 311.683 15.2324 1 1 0 nc 167 -173.374 377.916 15.2324 1 0 1 nc 168 -251.294 -335.059 15.2324 0 1 0 nc 169 -266.879 114.933 15.2324 0 0 0 nc 170 -368.176 331.163 15.2324 0 0 0 nc 171 -490.901 120.777 15.2324 0 0 0 nc 172 -574.666 -153.893 15.2324 1 0 0 nc 173 -675.963 -3.89604 15.2324 1 0 0 nc 174 -465.576 -42.8564 15.2324 1 0 0 nc 175 44.8044 15.5841 15.2324 0 0 1 nc 176 157.79 -130.517 15.2324 0 0 1 nc 177 218.178 27.2723 15.2324 0 0 1 nc 178 178 grestore 179 179 grestore -
doc/lgf.dox
r1069 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 64 64 \endcode 65 65 66 The \c \@arcs section is very similar to the \c \@nodes section, it 67 again starts with a header line describing the names of the maps, but 68 the \c "label" map is not obligatory here. The following lines 69 describe the arcs. The first two tokens of each line are the source 70 and the target node of the arc, respectively, then come the map 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 83 The \c \@arcs section is very similar to the \c \@nodes section, 84 it again starts with a header line describing the names of the maps, 85 but the \c "label" map is not obligatory here. The following lines 86 describe the arcs. The first two tokens of each line are 87 the source and the target node of the arc, respectively, then come the map 71 88 values. The source and target tokens must be node labels. 72 89 -
doc/mainpage.dox.in
r1039 r1221 26 26 It is a C++ template library providing efficient implementations of common 27 27 data structures and algorithms with focus on combinatorial optimization 28 tasks connected mainly with graphs and networks .28 tasks connected mainly with graphs and networks \cite DezsoJuttnerKovacs11Lemon. 29 29 30 30 <b> … … 38 38 The project is maintained by the 39 39 <a href="http://www.cs.elte.hu/egres/">Egerváry Research Group on 40 Combinatorial Optimization</a> \ refegres40 Combinatorial Optimization</a> \cite egres 41 41 at the Operations Research Department of the 42 42 <a href="http://www.elte.hu/en/">Eötvös Loránd University</a>, 43 43 Budapest, Hungary. 44 44 LEMON is also a member of the <a href="http://www.coin-or.org/">COIN-OR</a> 45 initiative \ refcoinor.45 initiative \cite coinor. 46 46 47 47 \section howtoread How to Read the Documentation -
doc/min_cost_flow.dox
r956 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 27 27 minimum total cost from a set of supply nodes to a set of demand nodes 28 28 in a network with capacity constraints (lower and upper bounds) 29 and arc costs \ refamo93networkflows.29 and arc costs \cite amo93networkflows. 30 30 31 31 Formally, let \f$G=(V,A)\f$ be a digraph, \f$lower: A\rightarrow\mathbf{R}\f$, … … 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
r802 r1219 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 … … 21 20 {O}perations {R}esearch}, 22 21 url = {http://www.coin-or.org/} 22 } 23 24 25 %%%%% Papers related to LEMON %%%%% 26 27 @article{DezsoJuttnerKovacs11Lemon, 28 author = {B. Dezs{\H o} and A. J\"uttner and P. Kov\'acs}, 29 title = {{LEMON} -- an open source {C++} graph template library}, 30 journal = {Electronic Notes in Theoretical Computer Science}, 31 volume = {264}, 32 pages = {23--45}, 33 year = {2011}, 34 note = {Proc. 2nd Workshop on Generative Technologies} 35 } 36 37 @article{KiralyKovacs12MCF, 38 author = {Z. Kir\'aly and P. Kov\'acs}, 39 title = {Efficient implementations of minimum-cost flow algorithms}, 40 journal = {Acta Universitatis Sapientiae, Informatica}, 41 year = {2012}, 42 volume = {4}, 43 pages = {67--118} 23 44 } 24 45 … … 212 233 volume = 23, 213 234 pages = {309-311} 235 } 236 237 @article{hartmann93finding, 238 author = {Mark Hartmann and James B. Orlin}, 239 title = {Finding minimum cost to time ratio cycles with small 240 integral transit times}, 241 journal = {Networks}, 242 year = 1993, 243 volume = 23, 244 pages = {567-574} 214 245 } 215 246 … … 226 257 } 227 258 259 @article{dasdan04experimental, 260 author = {Ali Dasdan}, 261 title = {Experimental analysis of the fastest optimum cycle 262 ratio and mean algorithms}, 263 journal = {ACM Trans. Des. Autom. Electron. Syst.}, 264 year = 2004, 265 volume = 9, 266 issue = 4, 267 pages = {385-418} 268 } 269 228 270 229 271 %%%%% Minimum cost flow algorithms %%%%% … … 298 340 address = {Dublin, Ireland}, 299 341 year = 1991, 300 month = sep, 301 } 342 month = sep 343 } 344 345 %%%%% Other algorithms %%%%% 346 347 @article{grosso08maxclique, 348 author = {Andrea Grosso and Marco Locatelli and Wayne Pullan}, 349 title = {Simple ingredients leading to very efficient 350 heuristics for the maximum clique problem}, 351 journal = {Journal of Heuristics}, 352 year = 2008, 353 volume = 14, 354 number = 6, 355 pages = {587--612} 356 } -
lemon/CMakeLists.txt
r1113 r1315 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 … … 37 37 IF(LEMON_HAVE_CPLEX) 38 38 SET(LEMON_SOURCES ${LEMON_SOURCES} cplex.cc) 39 INCLUDE_DIRECTORIES(${ CPLEX_INCLUDE_DIRS})39 INCLUDE_DIRECTORIES(${ILOG_INCLUDE_DIRS}) 40 40 ENDIF() 41 41 … … 50 50 ENDIF() 51 51 52 IF(LEMON_HAVE_SOPLEX) 53 SET(LEMON_SOURCES ${LEMON_SOURCES} soplex.cc) 54 INCLUDE_DIRECTORIES(${SOPLEX_INCLUDE_DIRS}) 55 ENDIF() 56 52 57 ADD_LIBRARY(lemon ${LEMON_SOURCES}) 58 59 TARGET_LINK_LIBRARIES(lemon 60 ${GLPK_LIBRARIES} ${COIN_LIBRARIES} ${ILOG_LIBRARIES} ${SOPLEX_LIBRARIES} 61 ) 62 53 63 IF(UNIX) 54 SET_TARGET_PROPERTIES(lemon PROPERTIES OUTPUT_NAME emon )64 SET_TARGET_PROPERTIES(lemon PROPERTIES OUTPUT_NAME emon VERSION ${LEMON_VERSION} SOVERSION ${LEMON_VERSION}) 55 65 ENDIF() 56 66 -
lemon/adaptors.h
r1401 r1402 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). -
lemon/arg_parser.cc
r956 r1397 222 222 { 223 223 Opts::iterator o = _opts.find(opt); 224 Opts::iterator s = _opts.find(syn);225 224 LEMON_ASSERT(o!=_opts.end(), "Unknown option: '"+opt+"'"); 226 LEMON_ASSERT(s==_opts.end(), "Option already used: '"+syn+"'"); 225 LEMON_ASSERT(_opts.find(syn)==_opts.end(), 226 "Option already used: '"+syn+"'"); 227 227 ParData p; 228 228 p.help=opt; -
lemon/arg_parser.h
r959 r1327 27 27 #include <sstream> 28 28 #include <algorithm> 29 #include <lemon/core.h> 29 30 #include <lemon/assert.h> 30 31 -
lemon/assert.h
r463 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 200 200 ::lemon::_assert_bits::cstringify(msg), \ 201 201 #exp), 0))) 202 # if LEMON_ENABLE_DEBUG202 # if defined LEMON_ENABLE_DEBUG 203 203 # define LEMON_DEBUG(exp, msg) \ 204 204 (static_cast<void> (!!(exp) ? 0 : ( \ -
lemon/base.cc
r554 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 22 22 #include<lemon/tolerance.h> 23 23 #include<lemon/core.h> 24 #include<lemon/time_measure.h> 24 25 namespace lemon { 25 26 … … 32 33 #endif 33 34 35 TimeStamp::Format TimeStamp::_format = TimeStamp::NORMAL; 36 34 37 } //namespace lemon -
lemon/bellman_ford.h
r960 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 150 150 /// This class provides an efficient implementation of the Bellman-Ford 151 151 /// algorithm. The maximum time complexity of the algorithm is 152 /// <tt>O(n e)</tt>.152 /// <tt>O(nm)</tt>. 153 153 /// 154 154 /// The Bellman-Ford algorithm solves the single-source shortest path … … 201 201 /// The type of the paths. 202 202 typedef PredMapPath<Digraph, PredMap> Path; 203 ///\brief The \ref BellmanFordDefaultOperationTraits203 ///\brief The \ref lemon::BellmanFordDefaultOperationTraits 204 204 /// "operation traits class" of the algorithm. 205 205 typedef typename TR::OperationTraits OperationTraits; 206 206 207 ///The \ref BellmanFordDefaultTraits "traits class" of the algorithm. 207 ///\brief The \ref lemon::BellmanFordDefaultTraits "traits class" 208 ///of the algorithm. 208 209 typedef TR Traits; 209 210 -
lemon/bfs.h
r1127 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 153 153 typedef PredMapPath<Digraph, PredMap> Path; 154 154 155 ///The \ref BfsDefaultTraits "traits class" of the algorithm.155 ///The \ref lemon::BfsDefaultTraits "traits class" of the algorithm. 156 156 typedef TR Traits; 157 157 -
lemon/bin_heap.h
r758 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). -
lemon/bits/alteration_notifier.h
r463 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 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/array_map.h
r956 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). -
lemon/bits/bezier.h
r1157 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). -
lemon/bits/default_map.h
r956 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). -
lemon/bits/edge_set_extender.h
r1159 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). -
lemon/bits/graph_adaptor_extender.h
r965 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). -
lemon/bits/graph_extender.h
r1159 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 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/map_extender.h
r867 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). -
lemon/bits/path_dump.h
r973 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). -
lemon/bits/solver_bits.h
r1142 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). -
lemon/bits/traits.h
r663 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 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
r1055 r1341 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 22 22 #include<lemon/bits/windows.h> 23 23 24 #ifdef WIN32 24 #if defined(LEMON_WIN32) && defined(__GNUC__) 25 #pragma GCC diagnostic ignored "-Wold-style-cast" 26 #endif 27 28 #ifdef LEMON_WIN32 25 29 #ifndef WIN32_LEAN_AND_MEAN 26 30 #define WIN32_LEAN_AND_MEAN … … 41 45 #include <unistd.h> 42 46 #include <ctime> 43 #ifndef WIN3247 #ifndef LEMON_WIN32 44 48 #include <sys/times.h> 45 49 #endif … … 56 60 double &cutime, double &cstime) 57 61 { 58 #ifdef WIN3262 #ifdef LEMON_WIN32 59 63 static const double ch = 4294967296.0e-7; 60 64 static const double cl = 1.0e-7; … … 95 99 { 96 100 std::ostringstream os; 97 #ifdef WIN32101 #ifdef LEMON_WIN32 98 102 SYSTEMTIME time; 99 103 GetSystemTime(&time); 100 104 char buf1[11], buf2[9], buf3[5]; 101 if (GetDateFormat(MY_LOCALE, 0, &time,105 if (GetDateFormat(MY_LOCALE, 0, &time, 102 106 ("ddd MMM dd"), buf1, 11) && 103 107 GetTimeFormat(MY_LOCALE, 0, &time, … … 121 125 int getWinRndSeed() 122 126 { 123 #ifdef WIN32127 #ifdef LEMON_WIN32 124 128 FILETIME time; 125 129 GetSystemTimeAsFileTime(&time); … … 131 135 #endif 132 136 } 137 138 WinLock::WinLock() { 139 #ifdef LEMON_WIN32 140 CRITICAL_SECTION *lock = new CRITICAL_SECTION; 141 InitializeCriticalSection(lock); 142 _repr = lock; 143 #else 144 _repr = 0; //Just to avoid 'unused variable' warning with clang 145 #endif 146 } 147 148 WinLock::~WinLock() { 149 #ifdef LEMON_WIN32 150 CRITICAL_SECTION *lock = static_cast<CRITICAL_SECTION*>(_repr); 151 DeleteCriticalSection(lock); 152 delete lock; 153 #endif 154 } 155 156 void WinLock::lock() { 157 #ifdef LEMON_WIN32 158 CRITICAL_SECTION *lock = static_cast<CRITICAL_SECTION*>(_repr); 159 EnterCriticalSection(lock); 160 #endif 161 } 162 163 void WinLock::unlock() { 164 #ifdef LEMON_WIN32 165 CRITICAL_SECTION *lock = static_cast<CRITICAL_SECTION*>(_repr); 166 LeaveCriticalSection(lock); 167 #endif 168 } 133 169 } 134 170 } -
lemon/bits/windows.h
r576 r1340 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 20 20 #define LEMON_BITS_WINDOWS_H 21 21 22 #include <lemon/config.h> 22 23 #include <string> 23 24 … … 29 30 std::string getWinFormattedDate(); 30 31 int getWinRndSeed(); 32 33 class WinLock { 34 public: 35 WinLock(); 36 ~WinLock(); 37 void lock(); 38 void unlock();\ 39 private: 40 void *_repr; 41 }; 31 42 } 32 43 } -
lemon/capacity_scaling.h
r956 r1363 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 28 28 #include <limits> 29 29 #include <lemon/core.h> 30 #include <lemon/maps.h> 30 31 #include <lemon/bin_heap.h> 31 32 … … 67 68 /// \ref CapacityScaling implements the capacity scaling version 68 69 /// of the successive shortest path algorithm for finding a 69 /// \ref min_cost_flow "minimum cost flow" \ref amo93networkflows, 70 /// \ref edmondskarp72theoretical. It is an efficient dual 71 /// solution method. 70 /// \ref min_cost_flow "minimum cost flow" \cite amo93networkflows, 71 /// \cite edmondskarp72theoretical. It is an efficient dual 72 /// solution method, which runs in polynomial time 73 /// \f$O(m\log U (n+m)\log n)\f$, where <i>U</i> denotes the maximum 74 /// of node supply and arc capacity values. 75 /// 76 /// This algorithm is typically slower than \ref CostScaling and 77 /// \ref NetworkSimplex, but in special cases, it can be more 78 /// efficient than them. 79 /// (For more information, see \ref min_cost_flow_algs "the module page".) 72 80 /// 73 81 /// Most of the parameters of the problem (except for the digraph) … … 87 95 /// consider to use the named template parameters instead. 88 96 /// 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. 97 /// \warning Both \c V and \c C must be signed number types. 98 /// \warning Capacity bounds and supply values must be integer, but 99 /// arc costs can be arbitrary real numbers. 100 /// \warning This algorithm does not support negative costs for 101 /// arcs having infinite upper bound. 93 102 #ifdef DOXYGEN 94 103 template <typename GR, typename V, typename C, typename TR> … … 111 120 typedef typename TR::Heap Heap; 112 121 113 /// The \ref CapacityScalingDefaultTraits "traits class" of the algorithm 122 /// \brief The \ref lemon::CapacityScalingDefaultTraits "traits class" 123 /// of the algorithm 114 124 typedef TR Traits; 115 125 … … 155 165 156 166 // Parameters of the problem 157 bool _ha ve_lower;167 bool _has_lower; 158 168 Value _sum_supply; 159 169 … … 348 358 template <typename LowerMap> 349 359 CapacityScaling& lowerMap(const LowerMap& map) { 350 _ha ve_lower = true;360 _has_lower = true; 351 361 for (ArcIt a(_graph); a != INVALID; ++a) { 352 362 _lower[_arc_idf[a]] = map[a]; 353 _lower[_arc_idb[a]] = map[a];354 363 } 355 364 return *this; … … 423 432 /// 424 433 /// 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 is434 /// with a map in which \c k is assigned to \c s, \c -k is 426 435 /// assigned to \c t and all other nodes have zero supply value. 427 436 /// … … 535 544 _cost[j] = _forward[j] ? 1 : -1; 536 545 } 537 _ha ve_lower = false;546 _has_lower = false; 538 547 return *this; 539 548 } … … 638 647 /// 639 648 /// This function returns the total cost of the found flow. 640 /// Its complexity is O( e).649 /// Its complexity is O(m). 641 650 /// 642 651 /// \note The return type of the function can be specified as a … … 676 685 } 677 686 678 /// \brief Return the flow map (the primal solution). 687 /// \brief Copy the flow values (the primal solution) into the 688 /// given map. 679 689 /// 680 690 /// This function copies the flow value on each arc into the given … … 700 710 } 701 711 702 /// \brief Return the potential map (the dual solution). 712 /// \brief Copy the potential values (the dual solution) into the 713 /// given map. 703 714 /// 704 715 /// This function copies the potential (dual value) of each node … … 730 741 if (_sum_supply > 0) return INFEASIBLE; 731 742 743 // Check lower and upper bounds 744 LEMON_DEBUG(checkBoundMaps(), 745 "Upper bounds must be greater or equal to the lower bounds"); 746 747 732 748 // Initialize vectors 733 749 for (int i = 0; i != _root; ++i) { … … 739 755 const Value MAX = std::numeric_limits<Value>::max(); 740 756 int last_out; 741 if (_ha ve_lower) {757 if (_has_lower) { 742 758 for (int i = 0; i != _root; ++i) { 743 759 last_out = _first_out[i+1]; … … 824 840 } 825 841 842 // Check if the upper bound is greater than or equal to the lower bound 843 // on each forward arc. 844 bool checkBoundMaps() { 845 for (int j = 0; j != _res_arc_num; ++j) { 846 if (_forward[j] && _upper[j] < _lower[j]) return false; 847 } 848 return true; 849 } 850 826 851 ProblemType start() { 827 852 // Execute the algorithm … … 833 858 834 859 // Handle non-zero lower bounds 835 if (_ha ve_lower) {860 if (_has_lower) { 836 861 int limit = _first_out[_root]; 837 862 for (int j = 0; j != limit; ++j) { 838 if ( !_forward[j]) _res_cap[j] += _lower[j];863 if (_forward[j]) _res_cap[_reverse[j]] += _lower[j]; 839 864 } 840 865 } -
lemon/cbc.cc
r1159 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). -
lemon/cbc.h
r956 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 17 17 */ 18 18 19 // -*- C++ -*-20 19 #ifndef LEMON_CBC_H 21 20 #define LEMON_CBC_H -
lemon/circulation.h
r1159 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 196 196 public: 197 197 198 ///The \ref CirculationDefaultTraits "traits class" of the algorithm. 198 /// \brief The \ref lemon::CirculationDefaultTraits "traits class" 199 /// of the algorithm. 199 200 typedef TR Traits; 200 201 ///The type of the digraph the algorithm runs on. -
lemon/clp.cc
r1142 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). -
lemon/clp.h
r956 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). -
lemon/concept_check.h
r1157 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 59 59 #if !defined(NDEBUG) 60 60 void (Concept::*x)() = & Concept::constraints; 61 ignore_unused_variable_warning(x);61 ::lemon::ignore_unused_variable_warning(x); 62 62 #endif 63 63 } … … 69 69 typedef typename Concept::template Constraints<Type> ConceptCheck; 70 70 void (ConceptCheck::*x)() = & ConceptCheck::constraints; 71 ignore_unused_variable_warning(x);71 ::lemon::ignore_unused_variable_warning(x); 72 72 #endif 73 73 } -
lemon/concepts/digraph.h
r956 r1271 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 313 313 /// Sets the iterator to the first arc of the given digraph. 314 314 /// 315 explicit ArcIt(const Digraph& g) { ignore_unused_variable_warning(g); } 315 explicit ArcIt(const Digraph& g) { 316 ::lemon::ignore_unused_variable_warning(g); 317 } 316 318 /// Sets the iterator to the given arc. 317 319 … … 410 412 /// \brief The base node of the iterator. 411 413 /// 412 /// Returns the base node of the given incom ming arc iterator414 /// Returns the base node of the given incoming arc iterator 413 415 /// (i.e. the target node of the corresponding arc). 414 416 Node baseNode(InArcIt) const { return INVALID; } … … 416 418 /// \brief The running node of the iterator. 417 419 /// 418 /// Returns the running node of the given incom ming arc iterator420 /// Returns the running node of the given incoming arc iterator 419 421 /// (i.e. the source node of the corresponding arc). 420 422 Node runningNode(InArcIt) const { return INVALID; } -
lemon/concepts/graph.h
r956 r1271 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 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 … … 397 397 /// Sets the iterator to the first arc of the given graph. 398 398 /// 399 explicit ArcIt(const Graph &g) { ignore_unused_variable_warning(g); } 399 explicit ArcIt(const Graph &g) { 400 ::lemon::ignore_unused_variable_warning(g); 401 } 400 402 /// Sets the iterator to the given arc. 401 403 … … 443 445 /// 444 446 OutArcIt(const Graph& n, const Node& g) { 445 ignore_unused_variable_warning(n);446 ignore_unused_variable_warning(g);447 ::lemon::ignore_unused_variable_warning(n); 448 ::lemon::ignore_unused_variable_warning(g); 447 449 } 448 450 /// Sets the iterator to the given arc. … … 491 493 /// 492 494 InArcIt(const Graph& g, const Node& n) { 493 ignore_unused_variable_warning(n);494 ignore_unused_variable_warning(g);495 ::lemon::ignore_unused_variable_warning(n); 496 ::lemon::ignore_unused_variable_warning(g); 495 497 } 496 498 /// Sets the iterator to the given arc. … … 758 760 /// \brief The base node of the iterator. 759 761 /// 760 /// Returns the base node of the given incom ming arc iterator762 /// Returns the base node of the given incoming arc iterator 761 763 /// (i.e. the target node of the corresponding arc). 762 764 Node baseNode(InArcIt) const { return INVALID; } … … 764 766 /// \brief The running node of the iterator. 765 767 /// 766 /// Returns the running node of the given incom ming arc iterator768 /// Returns the running node of the given incoming arc iterator 767 769 /// (i.e. the source node of the corresponding arc). 768 770 Node runningNode(InArcIt) const { return INVALID; } -
lemon/concepts/graph_components.h
r1159 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 109 109 110 110 bool b; 111 ::lemon::ignore_unused_variable_warning(b); 112 111 113 b = (ia == ib) && (ia != ib); 112 114 b = (ia == INVALID) && (ib != INVALID); … … 288 290 ue = e; 289 291 bool d = graph.direction(e); 290 ignore_unused_variable_warning(d);292 ::lemon::ignore_unused_variable_warning(d); 291 293 } 292 294 } … … 294 296 const _Graph& graph; 295 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 ::lemon::ignore_unused_variable_warning(b); 460 } 461 } 462 463 const _BpGraph& bpgraph; 296 464 }; 297 465 … … 367 535 368 536 nid = digraph.maxNodeId(); 369 ignore_unused_variable_warning(nid);537 ::lemon::ignore_unused_variable_warning(nid); 370 538 eid = digraph.maxArcId(); 371 ignore_unused_variable_warning(eid);539 ::lemon::ignore_unused_variable_warning(eid); 372 540 } 373 541 … … 422 590 edge = graph.edgeFromId(ueid); 423 591 ueid = graph.maxEdgeId(); 424 ignore_unused_variable_warning(ueid);592 ::lemon::ignore_unused_variable_warning(ueid); 425 593 } 426 594 427 595 const _Graph& graph; 428 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 ::lemon::ignore_unused_variable_warning(rid); 657 ::lemon::ignore_unused_variable_warning(bid); 658 } 659 660 const _BpGraph& bpgraph; 429 661 }; 430 662 }; … … 495 727 _GraphItemIt it3 = it1; 496 728 _GraphItemIt it4 = INVALID; 497 ignore_unused_variable_warning(it3);498 ignore_unused_variable_warning(it4);729 ::lemon::ignore_unused_variable_warning(it3); 730 ::lemon::ignore_unused_variable_warning(it4); 499 731 500 732 it2 = ++it1; … … 586 818 _GraphIncIt it3 = it1; 587 819 _GraphIncIt it4 = INVALID; 588 ignore_unused_variable_warning(it3);589 ignore_unused_variable_warning(it4);820 ::lemon::ignore_unused_variable_warning(it3); 821 ::lemon::ignore_unused_variable_warning(it4); 590 822 591 823 it2 = ++it1; … … 644 876 void next(Arc&) const {} 645 877 646 /// \brief Return the first arc incom ming to the given node.647 /// 648 /// This function gives back the first arc incom ming to the878 /// \brief Return the first arc incoming to the given node. 879 /// 880 /// This function gives back the first arc incoming to the 649 881 /// given node. 650 882 void firstIn(Arc&, const Node&) const {} 651 883 652 /// \brief Return the next arc incom ming to the given node.653 /// 654 /// This function gives back the next arc incom ming to the884 /// \brief Return the next arc incoming to the given node. 885 /// 886 /// This function gives back the next arc incoming to the 655 887 /// given node. 656 888 void nextIn(Arc&) const {} … … 769 1001 n = digraph.baseNode(oait); 770 1002 n = digraph.runningNode(oait); 771 ignore_unused_variable_warning(n);1003 ::lemon::ignore_unused_variable_warning(n); 772 1004 } 773 1005 } … … 903 1135 }; 904 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; 1225 }; 1226 }; 1227 905 1228 /// \brief Skeleton class for alterable directed graphs. 906 1229 /// … … 928 1251 ArcNotifier; 929 1252 1253 mutable NodeNotifier node_notifier; 1254 mutable ArcNotifier arc_notifier; 1255 930 1256 /// \brief Return the node alteration notifier. 931 1257 /// 932 1258 /// This function gives back the node alteration notifier. 933 1259 NodeNotifier& notifier(Node) const { 934 return NodeNotifier();1260 return node_notifier; 935 1261 } 936 1262 … … 939 1265 /// This function gives back the arc alteration notifier. 940 1266 ArcNotifier& notifier(Arc) const { 941 return ArcNotifier();1267 return arc_notifier; 942 1268 } 943 1269 … … 952 1278 = digraph.notifier(typename _Digraph::Arc()); 953 1279 954 ignore_unused_variable_warning(nn);955 ignore_unused_variable_warning(en);1280 ::lemon::ignore_unused_variable_warning(nn); 1281 ::lemon::ignore_unused_variable_warning(en); 956 1282 } 957 1283 … … 975 1301 976 1302 typedef BAS Base; 1303 typedef AlterableDigraphComponent<Base> Parent; 977 1304 typedef typename Base::Edge Edge; 978 1305 … … 982 1309 EdgeNotifier; 983 1310 1311 mutable EdgeNotifier edge_notifier; 1312 1313 using Parent::notifier; 1314 984 1315 /// \brief Return the edge alteration notifier. 985 1316 /// 986 1317 /// This function gives back the edge alteration notifier. 987 1318 EdgeNotifier& notifier(Edge) const { 988 return EdgeNotifier();1319 return edge_notifier; 989 1320 } 990 1321 … … 995 1326 typename _Graph::EdgeNotifier& uen 996 1327 = graph.notifier(typename _Graph::Edge()); 997 ignore_unused_variable_warning(uen);1328 ::lemon::ignore_unused_variable_warning(uen); 998 1329 } 999 1330 1000 1331 const _Graph& graph; 1001 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 ::lemon::ignore_unused_variable_warning(rnn); 1391 ::lemon::ignore_unused_variable_warning(bnn); 1392 } 1393 1394 const _BpGraph& bpgraph; 1002 1395 }; 1003 1396 }; … … 1069 1462 // m3 = cmap; 1070 1463 1071 ignore_unused_variable_warning(m1);1072 ignore_unused_variable_warning(m2);1073 // ignore_unused_variable_warning(m3);1464 ::lemon::ignore_unused_variable_warning(m1); 1465 ::lemon::ignore_unused_variable_warning(m2); 1466 // ::lemon::ignore_unused_variable_warning(m3); 1074 1467 } 1075 1468 … … 1306 1699 }; 1307 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; 1842 }; 1843 }; 1844 1308 1845 /// \brief Skeleton class for extendable directed graphs. 1309 1846 /// … … 1396 1933 }; 1397 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; 1991 }; 1992 }; 1993 1398 1994 /// \brief Skeleton class for erasable directed graphs. 1399 1995 /// … … 1476 2072 }; 1477 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> {}; 2082 1478 2083 /// \brief Skeleton class for clearable directed graphs. 1479 2084 /// … … 1512 2117 /// This concept requires \ref AlterableGraphComponent. 1513 2118 template <typename BAS = BaseGraphComponent> 1514 class ClearableGraphComponent : public ClearableDigraphComponent<BAS> { 1515 public: 1516 1517 typedef BAS Base; 1518 1519 /// \brief Erase all nodes and edges from the graph. 1520 /// 1521 /// This function erases all nodes and edges from the graph. 1522 void clear() {} 1523 1524 template <typename _Graph> 1525 struct Constraints { 1526 void constraints() { 1527 checkConcept<Base, _Graph>(); 1528 graph.clear(); 1529 } 1530 1531 _Graph& graph; 1532 Constraints() {} 1533 }; 1534 }; 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> {}; 1535 2129 1536 2130 } -
lemon/concepts/heap.h
r1127 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 261 261 item=Item(); 262 262 prio=Prio(); 263 ignore_unused_variable_warning(item);264 ignore_unused_variable_warning(prio);263 ::lemon::ignore_unused_variable_warning(item); 264 ::lemon::ignore_unused_variable_warning(prio); 265 265 266 266 OwnItem own_item; … … 269 269 own_item=Item(); 270 270 own_prio=Prio(); 271 ignore_unused_variable_warning(own_item);272 ignore_unused_variable_warning(own_prio);273 ignore_unused_variable_warning(own_state);271 ::lemon::ignore_unused_variable_warning(own_item); 272 ::lemon::ignore_unused_variable_warning(own_prio); 273 ::lemon::ignore_unused_variable_warning(own_state); 274 274 275 275 _Heap heap1(map); 276 276 _Heap heap2 = heap1; 277 ignore_unused_variable_warning(heap1);278 ignore_unused_variable_warning(heap2);277 ::lemon::ignore_unused_variable_warning(heap1); 278 ::lemon::ignore_unused_variable_warning(heap2); 279 279 280 280 int s = heap.size(); 281 ignore_unused_variable_warning(s);281 ::lemon::ignore_unused_variable_warning(s); 282 282 bool e = heap.empty(); 283 ignore_unused_variable_warning(e);283 ::lemon::ignore_unused_variable_warning(e); 284 284 285 285 prio = heap.prio(); -
lemon/concepts/maps.h
r1157 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 61 61 own_val = m[own_key]; 62 62 63 ignore_unused_variable_warning(key);64 ignore_unused_variable_warning(val);65 ignore_unused_variable_warning(own_key);66 ignore_unused_variable_warning(own_val);63 ::lemon::ignore_unused_variable_warning(key); 64 ::lemon::ignore_unused_variable_warning(val); 65 ::lemon::ignore_unused_variable_warning(own_key); 66 ::lemon::ignore_unused_variable_warning(own_val); 67 67 } 68 68 const Key& key; … … 101 101 m.set(own_key, own_val); 102 102 103 ignore_unused_variable_warning(key);104 ignore_unused_variable_warning(val);105 ignore_unused_variable_warning(own_key);106 ignore_unused_variable_warning(own_val);103 ::lemon::ignore_unused_variable_warning(key); 104 ::lemon::ignore_unused_variable_warning(val); 105 ::lemon::ignore_unused_variable_warning(own_key); 106 ::lemon::ignore_unused_variable_warning(own_val); 107 107 } 108 108 const Key& key; -
lemon/concepts/path.h
r1127 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 76 76 template <typename CPath> 77 77 Path& operator=(const CPath& cpath) { 78 ignore_unused_variable_warning(cpath);78 ::lemon::ignore_unused_variable_warning(cpath); 79 79 return *this; 80 80 } … … 136 136 e = (i < ii); 137 137 138 ignore_unused_variable_warning(l);139 ignore_unused_variable_warning(pp);140 ignore_unused_variable_warning(e);141 ignore_unused_variable_warning(id);142 ignore_unused_variable_warning(ii);143 ignore_unused_variable_warning(ed);138 ::lemon::ignore_unused_variable_warning(l); 139 ::lemon::ignore_unused_variable_warning(pp); 140 ::lemon::ignore_unused_variable_warning(e); 141 ::lemon::ignore_unused_variable_warning(id); 142 ::lemon::ignore_unused_variable_warning(ii); 143 ::lemon::ignore_unused_variable_warning(ed); 144 144 } 145 145 }; … … 163 163 e = (i != INVALID); 164 164 165 ignore_unused_variable_warning(l);166 ignore_unused_variable_warning(e);167 ignore_unused_variable_warning(id);168 ignore_unused_variable_warning(ed);165 ::lemon::ignore_unused_variable_warning(l); 166 ::lemon::ignore_unused_variable_warning(e); 167 ::lemon::ignore_unused_variable_warning(id); 168 ::lemon::ignore_unused_variable_warning(ed); 169 169 } 170 170 _Path& p; … … 189 189 e = (i != INVALID); 190 190 191 ignore_unused_variable_warning(l);192 ignore_unused_variable_warning(e);193 ignore_unused_variable_warning(id);194 ignore_unused_variable_warning(ed);191 ::lemon::ignore_unused_variable_warning(l); 192 ::lemon::ignore_unused_variable_warning(e); 193 ::lemon::ignore_unused_variable_warning(id); 194 ::lemon::ignore_unused_variable_warning(ed); 195 195 } 196 196 _Path& p; -
lemon/config.h.in
r725 r1340 1 /* The version string */ 2 # undef LEMON_VERSION1 #ifndef LEMON_CONFIG_H 2 #define LEMON_CONFIG_H 3 3 4 /* Define to 1 if you have long long */ 5 # undef LEMON_HAVE_LONG_LONG4 #define LEMON_VERSION "@PROJECT_VERSION@" 5 #cmakedefine LEMON_HAVE_LONG_LONG 1 6 6 7 /* Define to 1 if you have any LP solver. */ 8 #undef LEMON_HAVE_LP 7 #cmakedefine LEMON_WIN32 1 9 8 10 /* Define to 1 if you have any MIP solver. */ 11 #undef LEMON_HAVE_MIP 9 #cmakedefine LEMON_HAVE_LP 1 10 #cmakedefine LEMON_HAVE_MIP 1 11 #cmakedefine LEMON_HAVE_GLPK 1 12 #cmakedefine LEMON_HAVE_CPLEX 1 13 #cmakedefine LEMON_HAVE_SOPLEX 1 14 #cmakedefine LEMON_HAVE_CLP 1 15 #cmakedefine LEMON_HAVE_CBC 1 12 16 13 /* Define to 1 if you have CPLEX. */ 14 #undef LEMON_HAVE_CPLEX 17 #define LEMON_CPLEX_ 1 18 #define LEMON_CLP_ 2 19 #define LEMON_GLPK_ 3 20 #define LEMON_SOPLEX_ 4 21 #define LEMON_CBC_ 5 15 22 16 /* Define to 1 if you have GLPK. */ 17 # undef LEMON_HAVE_GLPK23 #cmakedefine LEMON_DEFAULT_LP LEMON_@LEMON_DEFAULT_LP@_ 24 #cmakedefine LEMON_DEFAULT_MIP LEMON_@LEMON_DEFAULT_MIP@_ 18 25 19 /* Define to 1 if you have SOPLEX */ 20 # undef LEMON_HAVE_SOPLEX26 #cmakedefine LEMON_USE_PTHREAD 1 27 #cmakedefine LEMON_USE_WIN32_THREADS 1 21 28 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 29 #endif -
lemon/connectivity.h
r956 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 746 746 /// 747 747 /// This function checks whether the given undirected graph is 748 /// bi-node-connected, i.e. any two edges are on same circle. 748 /// bi-node-connected, i.e. a connected graph without articulation 749 /// node. 749 750 /// 750 751 /// \return \c true if the graph bi-node-connected. 751 /// \note By definition, the empty graph is bi-node-connected. 752 /// 753 /// \note By definition, 754 /// \li a graph consisting of zero or one node is bi-node-connected, 755 /// \li a graph consisting of two isolated nodes 756 /// is \e not bi-node-connected and 757 /// \li a graph consisting of two nodes connected by an edge 758 /// is bi-node-connected. 752 759 /// 753 760 /// \see countBiNodeConnectedComponents(), biNodeConnectedComponents() 754 761 template <typename Graph> 755 762 bool biNodeConnected(const Graph& graph) { 763 bool hasNonIsolated = false, hasIsolated = false; 764 for (typename Graph::NodeIt n(graph); n != INVALID; ++n) { 765 if (typename Graph::OutArcIt(graph, n) == INVALID) { 766 if (hasIsolated || hasNonIsolated) { 767 return false; 768 } else { 769 hasIsolated = true; 770 } 771 } else { 772 if (hasIsolated) { 773 return false; 774 } else { 775 hasNonIsolated = true; 776 } 777 } 778 } 756 779 return countBiNodeConnectedComponents(graph) <= 1; 757 780 } -
lemon/core.h
r1159 r1341 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 20 20 #define LEMON_CORE_H 21 21 22 #include <vector>23 #include <algorithm>24 25 #include <lemon/config.h>26 #include <lemon/bits/enable_if.h>27 #include <lemon/bits/traits.h>28 #include <lemon/assert.h>29 30 // Disable the following warnings when compiling with MSVC:31 // C4250: 'class1' : inherits 'class2::member' via dominance32 // C4355: 'this' : used in base member initializer list33 // C4503: 'function' : decorated name length exceeded, name was truncated34 // C4800: 'type' : forcing value to bool 'true' or 'false' (performance warning)35 // C4996: 'function': was declared deprecated36 #ifdef _MSC_VER37 #pragma warning( disable : 4250 4355 4503 4800 4996 )38 #endif39 40 22 ///\file 41 23 ///\brief LEMON core utilities. … … 44 26 ///It is automatically included by all graph types, therefore it usually 45 27 ///do not have to be included directly. 28 29 // Disable the following warnings when compiling with MSVC: 30 // C4250: 'class1' : inherits 'class2::member' via dominance 31 // C4267: conversion from 'size_t' to 'type', possible loss of data 32 // C4355: 'this' : used in base member initializer list 33 // C4503: 'function' : decorated name length exceeded, name was truncated 34 // C4800: 'type' : forcing value to bool 'true' or 'false' (performance warning) 35 // C4996: 'function': was declared deprecated 36 #ifdef _MSC_VER 37 #pragma warning( disable : 4250 4267 4355 4503 4800 4996 ) 38 #endif 39 40 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8) 41 // Needed by the [DI]GRAPH_TYPEDEFS marcos for gcc 4.8 42 #pragma GCC diagnostic ignored "-Wunused-local-typedefs" 43 #endif 44 45 #include <vector> 46 #include <algorithm> 47 48 #include <lemon/config.h> 49 #include <lemon/bits/enable_if.h> 50 #include <lemon/bits/traits.h> 51 #include <lemon/assert.h> 52 53 46 54 47 55 namespace lemon { … … 149 157 typedef typename Graph::template EdgeMap<double> DoubleEdgeMap 150 158 159 ///Create convenience typedefs for the bipartite graph types and iterators 160 161 ///This \c \#define creates the same convenient type definitions as 162 ///defined by \ref GRAPH_TYPEDEFS(BpGraph) and ten more, namely it 163 ///creates \c RedNode, \c RedNodeIt, \c BoolRedNodeMap, 164 ///\c IntRedNodeMap, \c DoubleRedNodeMap, \c BlueNode, \c BlueNodeIt, 165 ///\c BoolBlueNodeMap, \c IntBlueNodeMap, \c DoubleBlueNodeMap. 166 /// 167 ///\note If the graph type is a dependent type, ie. the graph type depend 168 ///on a template parameter, then use \c TEMPLATE_BPGRAPH_TYPEDEFS() 169 ///macro. 170 #define BPGRAPH_TYPEDEFS(BpGraph) \ 171 GRAPH_TYPEDEFS(BpGraph); \ 172 typedef BpGraph::RedNode RedNode; \ 173 typedef BpGraph::RedNodeIt RedNodeIt; \ 174 typedef BpGraph::RedNodeMap<bool> BoolRedNodeMap; \ 175 typedef BpGraph::RedNodeMap<int> IntRedNodeMap; \ 176 typedef BpGraph::RedNodeMap<double> DoubleRedNodeMap; \ 177 typedef BpGraph::BlueNode BlueNode; \ 178 typedef BpGraph::BlueNodeIt BlueNodeIt; \ 179 typedef BpGraph::BlueNodeMap<bool> BoolBlueNodeMap; \ 180 typedef BpGraph::BlueNodeMap<int> IntBlueNodeMap; \ 181 typedef BpGraph::BlueNodeMap<double> DoubleBlueNodeMap 182 183 ///Create convenience typedefs for the bipartite graph types and iterators 184 185 ///\see BPGRAPH_TYPEDEFS 186 /// 187 ///\note Use this macro, if the graph type is a dependent type, 188 ///ie. the graph type depend on a template parameter. 189 #define TEMPLATE_BPGRAPH_TYPEDEFS(BpGraph) \ 190 TEMPLATE_GRAPH_TYPEDEFS(BpGraph); \ 191 typedef typename BpGraph::RedNode RedNode; \ 192 typedef typename BpGraph::RedNodeIt RedNodeIt; \ 193 typedef typename BpGraph::template RedNodeMap<bool> BoolRedNodeMap; \ 194 typedef typename BpGraph::template RedNodeMap<int> IntRedNodeMap; \ 195 typedef typename BpGraph::template RedNodeMap<double> DoubleRedNodeMap; \ 196 typedef typename BpGraph::BlueNode BlueNode; \ 197 typedef typename BpGraph::BlueNodeIt BlueNodeIt; \ 198 typedef typename BpGraph::template BlueNodeMap<bool> BoolBlueNodeMap; \ 199 typedef typename BpGraph::template BlueNodeMap<int> IntBlueNodeMap; \ 200 typedef typename BpGraph::template BlueNodeMap<double> DoubleBlueNodeMap 201 151 202 /// \brief Function to count the items in a graph. 152 203 /// … … 200 251 } 201 252 253 namespace _graph_utils_bits { 254 255 template <typename Graph, typename Enable = void> 256 struct CountRedNodesSelector { 257 static int count(const Graph &g) { 258 return countItems<Graph, typename Graph::RedNode>(g); 259 } 260 }; 261 262 template <typename Graph> 263 struct CountRedNodesSelector< 264 Graph, typename 265 enable_if<typename Graph::NodeNumTag, void>::type> 266 { 267 static int count(const Graph &g) { 268 return g.redNum(); 269 } 270 }; 271 } 272 273 /// \brief Function to count the red nodes in the graph. 274 /// 275 /// This function counts the red nodes in the graph. 276 /// The complexity of the function is O(n) but for some 277 /// graph structures it is specialized to run in O(1). 278 /// 279 /// If the graph contains a \e redNum() member function and a 280 /// \e NodeNumTag tag then this function calls directly the member 281 /// function to query the cardinality of the node set. 282 template <typename Graph> 283 inline int countRedNodes(const Graph& g) { 284 return _graph_utils_bits::CountRedNodesSelector<Graph>::count(g); 285 } 286 287 namespace _graph_utils_bits { 288 289 template <typename Graph, typename Enable = void> 290 struct CountBlueNodesSelector { 291 static int count(const Graph &g) { 292 return countItems<Graph, typename Graph::BlueNode>(g); 293 } 294 }; 295 296 template <typename Graph> 297 struct CountBlueNodesSelector< 298 Graph, typename 299 enable_if<typename Graph::NodeNumTag, void>::type> 300 { 301 static int count(const Graph &g) { 302 return g.blueNum(); 303 } 304 }; 305 } 306 307 /// \brief Function to count the blue nodes in the graph. 308 /// 309 /// This function counts the blue nodes in the graph. 310 /// The complexity of the function is O(n) but for some 311 /// graph structures it is specialized to run in O(1). 312 /// 313 /// If the graph contains a \e blueNum() member function and a 314 /// \e NodeNumTag tag then this function calls directly the member 315 /// function to query the cardinality of the node set. 316 template <typename Graph> 317 inline int countBlueNodes(const Graph& g) { 318 return _graph_utils_bits::CountBlueNodesSelector<Graph>::count(g); 319 } 320 202 321 // Arc counting: 203 322 … … 441 560 template <typename From, typename NodeRefMap, typename EdgeRefMap> 442 561 static void copy(const From& from, Graph &to, 443 NodeRefMap& nodeRefMap, EdgeRefMap& edgeRefMap) { 562 NodeRefMap& nodeRefMap, 563 EdgeRefMap& edgeRefMap) { 444 564 to.build(from, nodeRefMap, edgeRefMap); 445 565 } 446 566 }; 447 567 568 template <typename BpGraph, typename Enable = void> 569 struct BpGraphCopySelector { 570 template <typename From, typename RedNodeRefMap, 571 typename BlueNodeRefMap, typename EdgeRefMap> 572 static void copy(const From& from, BpGraph &to, 573 RedNodeRefMap& redNodeRefMap, 574 BlueNodeRefMap& blueNodeRefMap, 575 EdgeRefMap& edgeRefMap) { 576 to.clear(); 577 for (typename From::RedNodeIt it(from); it != INVALID; ++it) { 578 redNodeRefMap[it] = to.addRedNode(); 579 } 580 for (typename From::BlueNodeIt it(from); it != INVALID; ++it) { 581 blueNodeRefMap[it] = to.addBlueNode(); 582 } 583 for (typename From::EdgeIt it(from); it != INVALID; ++it) { 584 edgeRefMap[it] = to.addEdge(redNodeRefMap[from.redNode(it)], 585 blueNodeRefMap[from.blueNode(it)]); 586 } 587 } 588 }; 589 590 template <typename BpGraph> 591 struct BpGraphCopySelector< 592 BpGraph, 593 typename enable_if<typename BpGraph::BuildTag, void>::type> 594 { 595 template <typename From, typename RedNodeRefMap, 596 typename BlueNodeRefMap, typename EdgeRefMap> 597 static void copy(const From& from, BpGraph &to, 598 RedNodeRefMap& redNodeRefMap, 599 BlueNodeRefMap& blueNodeRefMap, 600 EdgeRefMap& edgeRefMap) { 601 to.build(from, redNodeRefMap, blueNodeRefMap, edgeRefMap); 602 } 603 }; 604 448 605 } 606 607 /// \brief Check whether a graph is undirected. 608 /// 609 /// This function returns \c true if the given graph is undirected. 610 #ifdef DOXYGEN 611 template <typename GR> 612 bool undirected(const GR& g) { return false; } 613 #else 614 template <typename GR> 615 typename enable_if<UndirectedTagIndicator<GR>, bool>::type 616 undirected(const GR&) { 617 return true; 618 } 619 template <typename GR> 620 typename disable_if<UndirectedTagIndicator<GR>, bool>::type 621 undirected(const GR&) { 622 return false; 623 } 624 #endif 449 625 450 626 /// \brief Class to copy a digraph. … … 971 1147 graphCopy(const From& from, To& to) { 972 1148 return GraphCopy<From, To>(from, to); 1149 } 1150 1151 /// \brief Class to copy a bipartite graph. 1152 /// 1153 /// Class to copy a bipartite graph to another graph (duplicate a 1154 /// graph). The simplest way of using it is through the 1155 /// \c bpGraphCopy() function. 1156 /// 1157 /// This class not only make a copy of a bipartite graph, but it can 1158 /// create references and cross references between the nodes, edges 1159 /// and arcs of the two graphs, and it can copy maps for using with 1160 /// the newly created graph. 1161 /// 1162 /// To make a copy from a graph, first an instance of BpGraphCopy 1163 /// should be created, then the data belongs to the graph should 1164 /// assigned to copy. In the end, the \c run() member should be 1165 /// called. 1166 /// 1167 /// The next code copies a graph with several data: 1168 ///\code 1169 /// BpGraphCopy<OrigBpGraph, NewBpGraph> cg(orig_graph, new_graph); 1170 /// // Create references for the nodes 1171 /// OrigBpGraph::NodeMap<NewBpGraph::Node> nr(orig_graph); 1172 /// cg.nodeRef(nr); 1173 /// // Create cross references (inverse) for the edges 1174 /// NewBpGraph::EdgeMap<OrigBpGraph::Edge> ecr(new_graph); 1175 /// cg.edgeCrossRef(ecr); 1176 /// // Copy a red node map 1177 /// OrigBpGraph::RedNodeMap<double> ormap(orig_graph); 1178 /// NewBpGraph::RedNodeMap<double> nrmap(new_graph); 1179 /// cg.redNodeMap(ormap, nrmap); 1180 /// // Copy a node 1181 /// OrigBpGraph::Node on; 1182 /// NewBpGraph::Node nn; 1183 /// cg.node(on, nn); 1184 /// // Execute copying 1185 /// cg.run(); 1186 ///\endcode 1187 template <typename From, typename To> 1188 class BpGraphCopy { 1189 private: 1190 1191 typedef typename From::Node Node; 1192 typedef typename From::RedNode RedNode; 1193 typedef typename From::BlueNode BlueNode; 1194 typedef typename From::NodeIt NodeIt; 1195 typedef typename From::Arc Arc; 1196 typedef typename From::ArcIt ArcIt; 1197 typedef typename From::Edge Edge; 1198 typedef typename From::EdgeIt EdgeIt; 1199 1200 typedef typename To::Node TNode; 1201 typedef typename To::RedNode TRedNode; 1202 typedef typename To::BlueNode TBlueNode; 1203 typedef typename To::Arc TArc; 1204 typedef typename To::Edge TEdge; 1205 1206 typedef typename From::template RedNodeMap<TRedNode> RedNodeRefMap; 1207 typedef typename From::template BlueNodeMap<TBlueNode> BlueNodeRefMap; 1208 typedef typename From::template EdgeMap<TEdge> EdgeRefMap; 1209 1210 struct NodeRefMap { 1211 NodeRefMap(const From& from, const RedNodeRefMap& red_node_ref, 1212 const BlueNodeRefMap& blue_node_ref) 1213 : _from(from), _red_node_ref(red_node_ref), 1214 _blue_node_ref(blue_node_ref) {} 1215 1216 typedef typename From::Node Key; 1217 typedef typename To::Node Value; 1218 1219 Value operator[](const Key& key) const { 1220 if (_from.red(key)) { 1221 return _red_node_ref[_from.asRedNodeUnsafe(key)]; 1222 } else { 1223 return _blue_node_ref[_from.asBlueNodeUnsafe(key)]; 1224 } 1225 } 1226 1227 const From& _from; 1228 const RedNodeRefMap& _red_node_ref; 1229 const BlueNodeRefMap& _blue_node_ref; 1230 }; 1231 1232 struct ArcRefMap { 1233 ArcRefMap(const From& from, const To& to, const EdgeRefMap& edge_ref) 1234 : _from(from), _to(to), _edge_ref(edge_ref) {} 1235 1236 typedef typename From::Arc Key; 1237 typedef typename To::Arc Value; 1238 1239 Value operator[](const Key& key) const { 1240 return _to.direct(_edge_ref[key], _from.direction(key)); 1241 } 1242 1243 const From& _from; 1244 const To& _to; 1245 const EdgeRefMap& _edge_ref; 1246 }; 1247 1248 public: 1249 1250 /// \brief Constructor of BpGraphCopy. 1251 /// 1252 /// Constructor of BpGraphCopy for copying the content of the 1253 /// \c from graph into the \c to graph. 1254 BpGraphCopy(const From& from, To& to) 1255 : _from(from), _to(to) {} 1256 1257 /// \brief Destructor of BpGraphCopy 1258 /// 1259 /// Destructor of BpGraphCopy. 1260 ~BpGraphCopy() { 1261 for (int i = 0; i < int(_node_maps.size()); ++i) { 1262 delete _node_maps[i]; 1263 } 1264 for (int i = 0; i < int(_red_maps.size()); ++i) { 1265 delete _red_maps[i]; 1266 } 1267 for (int i = 0; i < int(_blue_maps.size()); ++i) { 1268 delete _blue_maps[i]; 1269 } 1270 for (int i = 0; i < int(_arc_maps.size()); ++i) { 1271 delete _arc_maps[i]; 1272 } 1273 for (int i = 0; i < int(_edge_maps.size()); ++i) { 1274 delete _edge_maps[i]; 1275 } 1276 } 1277 1278 /// \brief Copy the node references into the given map. 1279 /// 1280 /// This function copies the node references into the given map. 1281 /// The parameter should be a map, whose key type is the Node type of 1282 /// the source graph, while the value type is the Node type of the 1283 /// destination graph. 1284 template <typename NodeRef> 1285 BpGraphCopy& nodeRef(NodeRef& map) { 1286 _node_maps.push_back(new _core_bits::RefCopy<From, Node, 1287 NodeRefMap, NodeRef>(map)); 1288 return *this; 1289 } 1290 1291 /// \brief Copy the node cross references into the given map. 1292 /// 1293 /// This function copies the node cross references (reverse references) 1294 /// into the given map. The parameter should be a map, whose key type 1295 /// is the Node type of the destination graph, while the value type is 1296 /// the Node type of the source graph. 1297 template <typename NodeCrossRef> 1298 BpGraphCopy& nodeCrossRef(NodeCrossRef& map) { 1299 _node_maps.push_back(new _core_bits::CrossRefCopy<From, Node, 1300 NodeRefMap, NodeCrossRef>(map)); 1301 return *this; 1302 } 1303 1304 /// \brief Make a copy of the given node map. 1305 /// 1306 /// This function makes a copy of the given node map for the newly 1307 /// created graph. 1308 /// The key type of the new map \c tmap should be the Node type of the 1309 /// destination graph, and the key type of the original map \c map 1310 /// should be the Node type of the source graph. 1311 template <typename FromMap, typename ToMap> 1312 BpGraphCopy& nodeMap(const FromMap& map, ToMap& tmap) { 1313 _node_maps.push_back(new _core_bits::MapCopy<From, Node, 1314 NodeRefMap, FromMap, ToMap>(map, tmap)); 1315 return *this; 1316 } 1317 1318 /// \brief Make a copy of the given node. 1319 /// 1320 /// This function makes a copy of the given node. 1321 BpGraphCopy& node(const Node& node, TNode& tnode) { 1322 _node_maps.push_back(new _core_bits::ItemCopy<From, Node, 1323 NodeRefMap, TNode>(node, tnode)); 1324 return *this; 1325 } 1326 1327 /// \brief Copy the red node references into the given map. 1328 /// 1329 /// This function copies the red node references into the given 1330 /// map. The parameter should be a map, whose key type is the 1331 /// Node type of the source graph with the red item set, while the 1332 /// value type is the Node type of the destination graph. 1333 template <typename RedRef> 1334 BpGraphCopy& redRef(RedRef& map) { 1335 _red_maps.push_back(new _core_bits::RefCopy<From, RedNode, 1336 RedNodeRefMap, RedRef>(map)); 1337 return *this; 1338 } 1339 1340 /// \brief Copy the red node cross references into the given map. 1341 /// 1342 /// This function copies the red node cross references (reverse 1343 /// references) into the given map. The parameter should be a map, 1344 /// whose key type is the Node type of the destination graph with 1345 /// the red item set, while the value type is the Node type of the 1346 /// source graph. 1347 template <typename RedCrossRef> 1348 BpGraphCopy& redCrossRef(RedCrossRef& map) { 1349 _red_maps.push_back(new _core_bits::CrossRefCopy<From, RedNode, 1350 RedNodeRefMap, RedCrossRef>(map)); 1351 return *this; 1352 } 1353 1354 /// \brief Make a copy of the given red node map. 1355 /// 1356 /// This function makes a copy of the given red node map for the newly 1357 /// created graph. 1358 /// The key type of the new map \c tmap should be the Node type of 1359 /// the destination graph with the red items, and the key type of 1360 /// the original map \c map should be the Node type of the source 1361 /// graph. 1362 template <typename FromMap, typename ToMap> 1363 BpGraphCopy& redNodeMap(const FromMap& map, ToMap& tmap) { 1364 _red_maps.push_back(new _core_bits::MapCopy<From, RedNode, 1365 RedNodeRefMap, FromMap, ToMap>(map, tmap)); 1366 return *this; 1367 } 1368 1369 /// \brief Make a copy of the given red node. 1370 /// 1371 /// This function makes a copy of the given red node. 1372 BpGraphCopy& redNode(const RedNode& node, TRedNode& tnode) { 1373 _red_maps.push_back(new _core_bits::ItemCopy<From, RedNode, 1374 RedNodeRefMap, TRedNode>(node, tnode)); 1375 return *this; 1376 } 1377 1378 /// \brief Copy the blue node references into the given map. 1379 /// 1380 /// This function copies the blue node references into the given 1381 /// map. The parameter should be a map, whose key type is the 1382 /// Node type of the source graph with the blue item set, while the 1383 /// value type is the Node type of the destination graph. 1384 template <typename BlueRef> 1385 BpGraphCopy& blueRef(BlueRef& map) { 1386 _blue_maps.push_back(new _core_bits::RefCopy<From, BlueNode, 1387 BlueNodeRefMap, BlueRef>(map)); 1388 return *this; 1389 } 1390 1391 /// \brief Copy the blue node cross references into the given map. 1392 /// 1393 /// This function copies the blue node cross references (reverse 1394 /// references) into the given map. The parameter should be a map, 1395 /// whose key type is the Node type of the destination graph with 1396 /// the blue item set, while the value type is the Node type of the 1397 /// source graph. 1398 template <typename BlueCrossRef> 1399 BpGraphCopy& blueCrossRef(BlueCrossRef& map) { 1400 _blue_maps.push_back(new _core_bits::CrossRefCopy<From, BlueNode, 1401 BlueNodeRefMap, BlueCrossRef>(map)); 1402 return *this; 1403 } 1404 1405 /// \brief Make a copy of the given blue node map. 1406 /// 1407 /// This function makes a copy of the given blue node map for the newly 1408 /// created graph. 1409 /// The key type of the new map \c tmap should be the Node type of 1410 /// the destination graph with the blue items, and the key type of 1411 /// the original map \c map should be the Node type of the source 1412 /// graph. 1413 template <typename FromMap, typename ToMap> 1414 BpGraphCopy& blueNodeMap(const FromMap& map, ToMap& tmap) { 1415 _blue_maps.push_back(new _core_bits::MapCopy<From, BlueNode, 1416 BlueNodeRefMap, FromMap, ToMap>(map, tmap)); 1417 return *this; 1418 } 1419 1420 /// \brief Make a copy of the given blue node. 1421 /// 1422 /// This function makes a copy of the given blue node. 1423 BpGraphCopy& blueNode(const BlueNode& node, TBlueNode& tnode) { 1424 _blue_maps.push_back(new _core_bits::ItemCopy<From, BlueNode, 1425 BlueNodeRefMap, TBlueNode>(node, tnode)); 1426 return *this; 1427 } 1428 1429 /// \brief Copy the arc references into the given map. 1430 /// 1431 /// This function copies the arc references into the given map. 1432 /// The parameter should be a map, whose key type is the Arc type of 1433 /// the source graph, while the value type is the Arc type of the 1434 /// destination graph. 1435 template <typename ArcRef> 1436 BpGraphCopy& arcRef(ArcRef& map) { 1437 _arc_maps.push_back(new _core_bits::RefCopy<From, Arc, 1438 ArcRefMap, ArcRef>(map)); 1439 return *this; 1440 } 1441 1442 /// \brief Copy the arc cross references into the given map. 1443 /// 1444 /// This function copies the arc cross references (reverse references) 1445 /// into the given map. The parameter should be a map, whose key type 1446 /// is the Arc type of the destination graph, while the value type is 1447 /// the Arc type of the source graph. 1448 template <typename ArcCrossRef> 1449 BpGraphCopy& arcCrossRef(ArcCrossRef& map) { 1450 _arc_maps.push_back(new _core_bits::CrossRefCopy<From, Arc, 1451 ArcRefMap, ArcCrossRef>(map)); 1452 return *this; 1453 } 1454 1455 /// \brief Make a copy of the given arc map. 1456 /// 1457 /// This function makes a copy of the given arc map for the newly 1458 /// created graph. 1459 /// The key type of the new map \c tmap should be the Arc type of the 1460 /// destination graph, and the key type of the original map \c map 1461 /// should be the Arc type of the source graph. 1462 template <typename FromMap, typename ToMap> 1463 BpGraphCopy& arcMap(const FromMap& map, ToMap& tmap) { 1464 _arc_maps.push_back(new _core_bits::MapCopy<From, Arc, 1465 ArcRefMap, FromMap, ToMap>(map, tmap)); 1466 return *this; 1467 } 1468 1469 /// \brief Make a copy of the given arc. 1470 /// 1471 /// This function makes a copy of the given arc. 1472 BpGraphCopy& arc(const Arc& arc, TArc& tarc) { 1473 _arc_maps.push_back(new _core_bits::ItemCopy<From, Arc, 1474 ArcRefMap, TArc>(arc, tarc)); 1475 return *this; 1476 } 1477 1478 /// \brief Copy the edge references into the given map. 1479 /// 1480 /// This function copies the edge references into the given map. 1481 /// The parameter should be a map, whose key type is the Edge type of 1482 /// the source graph, while the value type is the Edge type of the 1483 /// destination graph. 1484 template <typename EdgeRef> 1485 BpGraphCopy& edgeRef(EdgeRef& map) { 1486 _edge_maps.push_back(new _core_bits::RefCopy<From, Edge, 1487 EdgeRefMap, EdgeRef>(map)); 1488 return *this; 1489 } 1490 1491 /// \brief Copy the edge cross references into the given map. 1492 /// 1493 /// This function copies the edge cross references (reverse references) 1494 /// into the given map. The parameter should be a map, whose key type 1495 /// is the Edge type of the destination graph, while the value type is 1496 /// the Edge type of the source graph. 1497 template <typename EdgeCrossRef> 1498 BpGraphCopy& edgeCrossRef(EdgeCrossRef& map) { 1499 _edge_maps.push_back(new _core_bits::CrossRefCopy<From, 1500 Edge, EdgeRefMap, EdgeCrossRef>(map)); 1501 return *this; 1502 } 1503 1504 /// \brief Make a copy of the given edge map. 1505 /// 1506 /// This function makes a copy of the given edge map for the newly 1507 /// created graph. 1508 /// The key type of the new map \c tmap should be the Edge type of the 1509 /// destination graph, and the key type of the original map \c map 1510 /// should be the Edge type of the source graph. 1511 template <typename FromMap, typename ToMap> 1512 BpGraphCopy& edgeMap(const FromMap& map, ToMap& tmap) { 1513 _edge_maps.push_back(new _core_bits::MapCopy<From, Edge, 1514 EdgeRefMap, FromMap, ToMap>(map, tmap)); 1515 return *this; 1516 } 1517 1518 /// \brief Make a copy of the given edge. 1519 /// 1520 /// This function makes a copy of the given edge. 1521 BpGraphCopy& edge(const Edge& edge, TEdge& tedge) { 1522 _edge_maps.push_back(new _core_bits::ItemCopy<From, Edge, 1523 EdgeRefMap, TEdge>(edge, tedge)); 1524 return *this; 1525 } 1526 1527 /// \brief Execute copying. 1528 /// 1529 /// This function executes the copying of the graph along with the 1530 /// copying of the assigned data. 1531 void run() { 1532 RedNodeRefMap redNodeRefMap(_from); 1533 BlueNodeRefMap blueNodeRefMap(_from); 1534 NodeRefMap nodeRefMap(_from, redNodeRefMap, blueNodeRefMap); 1535 EdgeRefMap edgeRefMap(_from); 1536 ArcRefMap arcRefMap(_from, _to, edgeRefMap); 1537 _core_bits::BpGraphCopySelector<To>:: 1538 copy(_from, _to, redNodeRefMap, blueNodeRefMap, edgeRefMap); 1539 for (int i = 0; i < int(_node_maps.size()); ++i) { 1540 _node_maps[i]->copy(_from, nodeRefMap); 1541 } 1542 for (int i = 0; i < int(_red_maps.size()); ++i) { 1543 _red_maps[i]->copy(_from, redNodeRefMap); 1544 } 1545 for (int i = 0; i < int(_blue_maps.size()); ++i) { 1546 _blue_maps[i]->copy(_from, blueNodeRefMap); 1547 } 1548 for (int i = 0; i < int(_edge_maps.size()); ++i) { 1549 _edge_maps[i]->copy(_from, edgeRefMap); 1550 } 1551 for (int i = 0; i < int(_arc_maps.size()); ++i) { 1552 _arc_maps[i]->copy(_from, arcRefMap); 1553 } 1554 } 1555 1556 private: 1557 1558 const From& _from; 1559 To& _to; 1560 1561 std::vector<_core_bits::MapCopyBase<From, Node, NodeRefMap>* > 1562 _node_maps; 1563 1564 std::vector<_core_bits::MapCopyBase<From, RedNode, RedNodeRefMap>* > 1565 _red_maps; 1566 1567 std::vector<_core_bits::MapCopyBase<From, BlueNode, BlueNodeRefMap>* > 1568 _blue_maps; 1569 1570 std::vector<_core_bits::MapCopyBase<From, Arc, ArcRefMap>* > 1571 _arc_maps; 1572 1573 std::vector<_core_bits::MapCopyBase<From, Edge, EdgeRefMap>* > 1574 _edge_maps; 1575 1576 }; 1577 1578 /// \brief Copy a graph to another graph. 1579 /// 1580 /// This function copies a graph to another graph. 1581 /// The complete usage of it is detailed in the BpGraphCopy class, 1582 /// but a short example shows a basic work: 1583 ///\code 1584 /// graphCopy(src, trg).nodeRef(nr).edgeCrossRef(ecr).run(); 1585 ///\endcode 1586 /// 1587 /// After the copy the \c nr map will contain the mapping from the 1588 /// nodes of the \c from graph to the nodes of the \c to graph and 1589 /// \c ecr will contain the mapping from the edges of the \c to graph 1590 /// to the edges of the \c from graph. 1591 /// 1592 /// \see BpGraphCopy 1593 template <typename From, typename To> 1594 BpGraphCopy<From, To> 1595 bpGraphCopy(const From& from, To& to) { 1596 return BpGraphCopy<From, To>(from, to); 973 1597 } 974 1598 -
lemon/cost_scaling.h
r1041 r1298 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 92 92 /// \ref CostScaling implements a cost scaling algorithm that performs 93 93 /// push/augment and relabel operations for finding a \ref min_cost_flow 94 /// "minimum cost flow" \ref amo93networkflows, \ref goldberg90approximation, 95 /// \ref goldberg97efficient, \ref bunnagel98efficient. 94 /// "minimum cost flow" \cite amo93networkflows, 95 /// \cite goldberg90approximation, 96 /// \cite goldberg97efficient, \cite bunnagel98efficient. 96 97 /// It is a highly efficient primal-dual solution method, which 97 98 /// can be viewed as the generalization of the \ref Preflow 98 99 /// "preflow push-relabel" algorithm for the maximum flow problem. 100 /// It is a polynomial algorithm, its running time complexity is 101 /// \f$O(n^2m\log(nK))\f$, where <i>K</i> denotes the maximum arc cost. 102 /// 103 /// In general, \ref NetworkSimplex and \ref CostScaling are the fastest 104 /// implementations available in LEMON for solving this problem. 105 /// (For more information, see \ref min_cost_flow_algs "the module page".) 99 106 /// 100 107 /// Most of the parameters of the problem (except for the digraph) … … 114 121 /// consider to use the named template parameters instead. 115 122 /// 116 /// \warning Both number types must be signed and all input data must 123 /// \warning Both \c V and \c C must be signed number types. 124 /// \warning All input data (capacities, supply values, and costs) must 117 125 /// be integer. 118 /// \warning This algorithm does not support negative costs for such119 /// arcs that haveinfinite upper bound.126 /// \warning This algorithm does not support negative costs for 127 /// arcs having infinite upper bound. 120 128 /// 121 129 /// \note %CostScaling provides three different internal methods, … … 146 154 typedef typename TR::LargeCost LargeCost; 147 155 148 /// The \ref CostScalingDefaultTraits "traits class" of the algorithm 156 /// \brief The \ref lemon::CostScalingDefaultTraits "traits class" 157 /// of the algorithm 149 158 typedef TR Traits; 150 159 … … 179 188 /// relabel operation. 180 189 /// By default, the so called \ref PARTIAL_AUGMENT 181 /// "Partial Augment-Relabel" method is used, which provedto be190 /// "Partial Augment-Relabel" method is used, which turned out to be 182 191 /// the most efficient and the most robust on various test inputs. 183 192 /// However, the other methods can be selected using the \ref run() … … 206 215 typedef std::vector<LargeCost> LargeCostVector; 207 216 typedef std::vector<char> BoolVector; 208 // Note: vector<char> is used instead of vector<bool> for efficiency reasons 217 // Note: vector<char> is used instead of vector<bool> 218 // for efficiency reasons 209 219 210 220 private: … … 234 244 }; 235 245 236 typedef StaticVectorMap<StaticDigraph::Node, LargeCost> LargeCostNodeMap;237 246 typedef StaticVectorMap<StaticDigraph::Arc, LargeCost> LargeCostArcMap; 238 247 … … 248 257 249 258 // Parameters of the problem 250 bool _ha ve_lower;259 bool _has_lower; 251 260 Value _sum_supply; 252 261 int _sup_node_num; … … 285 294 int _max_rank; 286 295 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 296 public: 296 297 … … 339 340 CostScaling(const GR& graph) : 340 341 _graph(graph), _node_id(graph), _arc_idf(graph), _arc_idb(graph), 341 _cost_map(_cost_vec), _pi_map(_pi),342 342 INF(std::numeric_limits<Value>::has_infinity ? 343 343 std::numeric_limits<Value>::infinity() : … … 373 373 template <typename LowerMap> 374 374 CostScaling& lowerMap(const LowerMap& map) { 375 _ha ve_lower = true;375 _has_lower = true; 376 376 for (ArcIt a(_graph); a != INVALID; ++a) { 377 377 _lower[_arc_idf[a]] = map[a]; 378 _lower[_arc_idb[a]] = map[a];379 378 } 380 379 return *this; … … 448 447 /// 449 448 /// 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 is449 /// with a map in which \c k is assigned to \c s, \c -k is 451 450 /// assigned to \c t and all other nodes have zero supply value. 452 451 /// … … 494 493 /// \param method The internal method that will be used in the 495 494 /// algorithm. For more information, see \ref Method. 496 /// \param factor The cost scaling factor. It must be larger than one.495 /// \param factor The cost scaling factor. It must be at least two. 497 496 /// 498 497 /// \return \c INFEASIBLE if no feasible flow exists, … … 508 507 /// \see ProblemType, Method 509 508 /// \see resetParams(), reset() 510 ProblemType run(Method method = PARTIAL_AUGMENT, int factor = 8) { 509 ProblemType run(Method method = PARTIAL_AUGMENT, int factor = 16) { 510 LEMON_ASSERT(factor >= 2, "The scaling factor must be at least 2"); 511 511 _alpha = factor; 512 512 ProblemType pt = init(); … … 568 568 _scost[_reverse[j]] = 0; 569 569 } 570 _ha ve_lower = false;570 _has_lower = false; 571 571 return *this; 572 572 } 573 573 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. 574 /// \brief Reset the internal data structures and all the parameters 575 /// that have been given before. 576 /// 577 /// This function resets the internal data structures and all the 578 /// paramaters that have been given before using functions \ref lowerMap(), 579 /// \ref upperMap(), \ref costMap(), \ref supplyMap(), \ref stSupply(). 580 /// 581 /// It is useful for multiple \ref run() calls. By default, all the given 582 /// parameters are kept for the next \ref run() call, unless 583 /// \ref resetParams() or \ref reset() is used. 584 /// If the underlying digraph was also modified after the construction 585 /// of the class or the last \ref reset() call, then the \ref reset() 586 /// function must be used, otherwise \ref resetParams() is sufficient. 587 /// 588 /// See \ref resetParams() for examples. 589 /// 585 590 /// \return <tt>(*this)</tt> 591 /// 592 /// \see resetParams(), run() 586 593 CostScaling& reset() { 587 594 // Resize vectors … … 608 615 _excess.resize(_res_node_num); 609 616 _next_out.resize(_res_node_num); 610 611 _arc_vec.reserve(_res_arc_num);612 _cost_vec.reserve(_res_arc_num);613 617 614 618 // Copy the graph … … 668 672 /// 669 673 /// This function returns the total cost of the found flow. 670 /// Its complexity is O( e).674 /// Its complexity is O(m). 671 675 /// 672 676 /// \note The return type of the function can be specified as a … … 706 710 } 707 711 708 /// \brief Return the flow map (the primal solution). 712 /// \brief Copy the flow values (the primal solution) into the 713 /// given map. 709 714 /// 710 715 /// This function copies the flow value on each arc into the given … … 730 735 } 731 736 732 /// \brief Return the potential map (the dual solution). 737 /// \brief Copy the potential values (the dual solution) into the 738 /// given map. 733 739 /// 734 740 /// This function copies the potential (dual value) of each node … … 760 766 if (_sum_supply > 0) return INFEASIBLE; 761 767 768 // Check lower and upper bounds 769 LEMON_DEBUG(checkBoundMaps(), 770 "Upper bounds must be greater or equal to the lower bounds"); 771 762 772 763 773 // Initialize vectors … … 770 780 const Value MAX = std::numeric_limits<Value>::max(); 771 781 int last_out; 772 if (_ha ve_lower) {782 if (_has_lower) { 773 783 for (int i = 0; i != _root; ++i) { 774 784 last_out = _first_out[i+1]; … … 827 837 sup[n] = _supply[_node_id[n]]; 828 838 } 829 if (_ha ve_lower) {839 if (_has_lower) { 830 840 for (ArcIt a(_graph); a != INVALID; ++a) { 831 841 int j = _arc_idf[a]; … … 887 897 } 888 898 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 899 // Initialize data structures for buckets 898 900 _max_rank = _alpha * _res_node_num; … … 902 904 _rank.resize(_res_node_num + 1); 903 905 904 // Execute the algorithm 906 return OPTIMAL; 907 } 908 909 // Check if the upper bound is greater than or equal to the lower bound 910 // on each forward arc. 911 bool checkBoundMaps() { 912 for (int j = 0; j != _res_arc_num; ++j) { 913 if (_forward[j] && _upper[j] < _lower[j]) return false; 914 } 915 return true; 916 } 917 918 // Execute the algorithm and transform the results 919 void start(Method method) { 920 const int MAX_PARTIAL_PATH_LENGTH = 4; 921 905 922 switch (method) { 906 923 case PUSH: … … 911 928 break; 912 929 case PARTIAL_AUGMENT: 913 startAugment(MAX_PA TH_LENGTH);930 startAugment(MAX_PARTIAL_PATH_LENGTH); 914 931 break; 915 932 } 916 933 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(); 934 // Compute node potentials (dual solution) 935 for (int i = 0; i != _res_node_num; ++i) { 936 _pi[i] = static_cast<Cost>(_pi[i] / (_res_node_num * _alpha)); 937 } 938 bool optimal = true; 939 for (int i = 0; optimal && i != _res_node_num; ++i) { 940 LargeCost pi_i = _pi[i]; 941 int last_out = _first_out[i+1]; 942 for (int j = _first_out[i]; j != last_out; ++j) { 943 if (_res_cap[j] > 0 && _scost[j] + pi_i - _pi[_target[j]] < 0) { 944 optimal = false; 945 break; 946 } 947 } 948 } 949 950 if (!optimal) { 951 // Compute node potentials for the original costs with BellmanFord 952 // (if it is necessary) 953 typedef std::pair<int, int> IntPair; 954 StaticDigraph sgr; 955 std::vector<IntPair> arc_vec; 956 std::vector<LargeCost> cost_vec; 957 LargeCostArcMap cost_map(cost_vec); 958 959 arc_vec.clear(); 960 cost_vec.clear(); 961 for (int j = 0; j != _res_arc_num; ++j) { 962 if (_res_cap[j] > 0) { 963 int u = _source[j], v = _target[j]; 964 arc_vec.push_back(IntPair(u, v)); 965 cost_vec.push_back(_scost[j] + _pi[u] - _pi[v]); 966 } 967 } 968 sgr.build(_res_node_num, arc_vec.begin(), arc_vec.end()); 969 970 typename BellmanFord<StaticDigraph, LargeCostArcMap>::Create 971 bf(sgr, cost_map); 972 bf.init(0); 973 bf.start(); 974 975 for (int i = 0; i != _res_node_num; ++i) { 976 _pi[i] += bf.dist(sgr.node(i)); 977 } 978 } 979 980 // Shift potentials to meet the requirements of the GEQ type 981 // optimality conditions 982 LargeCost max_pot = _pi[_root]; 983 for (int i = 0; i != _res_node_num; ++i) { 984 if (_pi[i] > max_pot) max_pot = _pi[i]; 985 } 986 if (max_pot != 0) { 987 for (int i = 0; i != _res_node_num; ++i) { 988 _pi[i] -= max_pot; 989 } 990 } 933 991 934 992 // Handle non-zero lower bounds 935 if (_ha ve_lower) {993 if (_has_lower) { 936 994 int limit = _first_out[_root]; 937 995 for (int j = 0; j != limit; ++j) { 938 if ( !_forward[j]) _res_cap[j] += _lower[j];996 if (_forward[j]) _res_cap[_reverse[j]] += _lower[j]; 939 997 } 940 998 } … … 948 1006 LargeCost pi_u = _pi[u]; 949 1007 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; 1008 Value delta = _res_cap[a]; 1009 if (delta > 0) { 1010 int v = _target[a]; 1011 if (_cost[a] + pi_u - _pi[v] < 0) { 1012 _excess[u] -= delta; 1013 _excess[v] += delta; 1014 _res_cap[a] = 0; 1015 _res_cap[_reverse[a]] += delta; 1016 } 957 1017 } 958 1018 } … … 970 1030 } 971 1031 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; 1032 // Price (potential) refinement heuristic 1033 bool priceRefinement() { 1034 1035 // Stack for stroing the topological order 1036 IntVector stack(_res_node_num); 1037 int stack_top; 1038 1039 // Perform phases 1040 while (topologicalSort(stack, stack_top)) { 1041 1042 // Compute node ranks in the acyclic admissible network and 1043 // store the nodes in buckets 1044 for (int i = 0; i != _res_node_num; ++i) { 1045 _rank[i] = 0; 1046 } 1047 const int bucket_end = _root + 1; 1048 for (int r = 0; r != _max_rank; ++r) { 1049 _buckets[r] = bucket_end; 1050 } 1051 int top_rank = 0; 1052 for ( ; stack_top >= 0; --stack_top) { 1053 int u = stack[stack_top], v; 1054 int rank_u = _rank[u]; 1055 1056 LargeCost rc, pi_u = _pi[u]; 1057 int last_out = _first_out[u+1]; 1058 for (int a = _first_out[u]; a != last_out; ++a) { 1059 if (_res_cap[a] > 0) { 1060 v = _target[a]; 1061 rc = _cost[a] + pi_u - _pi[v]; 1062 if (rc < 0) { 1063 LargeCost nrc = static_cast<LargeCost>((-rc - 0.5) / _epsilon); 1064 if (nrc < LargeCost(_max_rank)) { 1065 int new_rank_v = rank_u + static_cast<int>(nrc); 1066 if (new_rank_v > _rank[v]) { 1067 _rank[v] = new_rank_v; 1068 } 1069 } 1070 } 1071 } 1072 } 1073 1074 if (rank_u > 0) { 1075 top_rank = std::max(top_rank, rank_u); 1076 int bfirst = _buckets[rank_u]; 1077 _bucket_next[u] = bfirst; 1078 _bucket_prev[bfirst] = u; 1079 _buckets[rank_u] = u; 1080 } 1081 } 1082 1083 // Check if the current flow is epsilon-optimal 1084 if (top_rank == 0) { 1085 return true; 1086 } 1087 1088 // Process buckets in top-down order 1089 for (int rank = top_rank; rank > 0; --rank) { 1090 while (_buckets[rank] != bucket_end) { 1091 // Remove the first node from the current bucket 1092 int u = _buckets[rank]; 1093 _buckets[rank] = _bucket_next[u]; 1094 1095 // Search the outgoing arcs of u 1096 LargeCost rc, pi_u = _pi[u]; 1097 int last_out = _first_out[u+1]; 1098 int v, old_rank_v, new_rank_v; 1099 for (int a = _first_out[u]; a != last_out; ++a) { 1100 if (_res_cap[a] > 0) { 1101 v = _target[a]; 1102 old_rank_v = _rank[v]; 1103 1104 if (old_rank_v < rank) { 1105 1106 // Compute the new rank of node v 1107 rc = _cost[a] + pi_u - _pi[v]; 1108 if (rc < 0) { 1109 new_rank_v = rank; 1110 } else { 1111 LargeCost nrc = rc / _epsilon; 1112 new_rank_v = 0; 1113 if (nrc < LargeCost(_max_rank)) { 1114 new_rank_v = rank - 1 - static_cast<int>(nrc); 1115 } 1116 } 1117 1118 // Change the rank of node v 1119 if (new_rank_v > old_rank_v) { 1120 _rank[v] = new_rank_v; 1121 1122 // Remove v from its old bucket 1123 if (old_rank_v > 0) { 1124 if (_buckets[old_rank_v] == v) { 1125 _buckets[old_rank_v] = _bucket_next[v]; 1126 } else { 1127 int pv = _bucket_prev[v], nv = _bucket_next[v]; 1128 _bucket_next[pv] = nv; 1129 _bucket_prev[nv] = pv; 1130 } 1131 } 1132 1133 // Insert v into its new bucket 1134 int nv = _buckets[new_rank_v]; 1135 _bucket_next[v] = nv; 1136 _bucket_prev[nv] = v; 1137 _buckets[new_rank_v] = v; 1138 } 1139 } 1140 } 1141 } 1142 1143 // Refine potential of node u 1144 _pi[u] -= rank * _epsilon; 1145 } 1146 } 1147 1148 } 1149 1150 return false; 1151 } 1152 1153 // Find and cancel cycles in the admissible network and 1154 // determine topological order using DFS 1155 bool topologicalSort(IntVector &stack, int &stack_top) { 1156 const int MAX_CYCLE_CANCEL = 1; 1157 1158 BoolVector reached(_res_node_num, false); 1159 BoolVector processed(_res_node_num, false); 1160 IntVector pred(_res_node_num); 1161 for (int i = 0; i != _res_node_num; ++i) { 1162 _next_out[i] = _first_out[i]; 1163 } 1164 stack_top = -1; 1165 1166 int cycle_cnt = 0; 1167 for (int start = 0; start != _res_node_num; ++start) { 1168 if (reached[start]) continue; 1169 1170 // Start DFS search from this start node 1171 pred[start] = -1; 1172 int tip = start, v; 1173 while (true) { 1174 // Check the outgoing arcs of the current tip node 1175 reached[tip] = true; 1176 LargeCost pi_tip = _pi[tip]; 1177 int a, last_out = _first_out[tip+1]; 1178 for (a = _next_out[tip]; a != last_out; ++a) { 1179 if (_res_cap[a] > 0) { 1180 v = _target[a]; 1181 if (_cost[a] + pi_tip - _pi[v] < 0) { 1182 if (!reached[v]) { 1183 // A new node is reached 1184 reached[v] = true; 1185 pred[v] = tip; 1186 _next_out[tip] = a; 1187 tip = v; 1188 a = _next_out[tip]; 1189 last_out = _first_out[tip+1]; 1190 break; 1191 } 1192 else if (!processed[v]) { 1193 // A cycle is found 1194 ++cycle_cnt; 1195 _next_out[tip] = a; 1196 1197 // Find the minimum residual capacity along the cycle 1198 Value d, delta = _res_cap[a]; 1199 int u, delta_node = tip; 1200 for (u = tip; u != v; ) { 1201 u = pred[u]; 1202 d = _res_cap[_next_out[u]]; 1203 if (d <= delta) { 1204 delta = d; 1205 delta_node = u; 1206 } 1207 } 1208 1209 // Augment along the cycle 1210 _res_cap[a] -= delta; 1211 _res_cap[_reverse[a]] += delta; 1212 for (u = tip; u != v; ) { 1213 u = pred[u]; 1214 int ca = _next_out[u]; 1215 _res_cap[ca] -= delta; 1216 _res_cap[_reverse[ca]] += delta; 1217 } 1218 1219 // Check the maximum number of cycle canceling 1220 if (cycle_cnt >= MAX_CYCLE_CANCEL) { 1221 return false; 1222 } 1223 1224 // Roll back search to delta_node 1225 if (delta_node != tip) { 1226 for (u = tip; u != delta_node; u = pred[u]) { 1227 reached[u] = false; 1228 } 1229 tip = delta_node; 1230 a = _next_out[tip] + 1; 1231 last_out = _first_out[tip+1]; 1232 break; 1233 } 1234 } 1235 } 1236 } 1237 } 1238 1239 // Step back to the previous node 1240 if (a == last_out) { 1241 processed[tip] = true; 1242 stack[++stack_top] = tip; 1243 tip = pred[tip]; 1244 if (tip < 0) { 1245 // Finish DFS from the current start node 1246 break; 1247 } 1248 ++_next_out[tip]; 1249 } 1250 } 1251 1252 } 1253 1254 return (cycle_cnt == 0); 996 1255 } 997 1256 998 1257 // Global potential update heuristic 999 1258 void globalUpdate() { 1000 int bucket_end = _root + 1;1259 const int bucket_end = _root + 1; 1001 1260 1002 1261 // Initialize buckets … … 1005 1264 } 1006 1265 Value total_excess = 0; 1266 int b0 = bucket_end; 1007 1267 for (int i = 0; i != _res_node_num; ++i) { 1008 1268 if (_excess[i] < 0) { 1009 1269 _rank[i] = 0; 1010 _bucket_next[i] = _buckets[0];1011 _bucket_prev[ _buckets[0]] = i;1012 _buckets[0]= i;1270 _bucket_next[i] = b0; 1271 _bucket_prev[b0] = i; 1272 b0 = i; 1013 1273 } else { 1014 1274 total_excess += _excess[i]; … … 1017 1277 } 1018 1278 if (total_excess == 0) return; 1279 _buckets[0] = b0; 1019 1280 1020 1281 // Search the buckets … … 1026 1287 _buckets[r] = _bucket_next[u]; 1027 1288 1028 // Search the incom ming arcs of u1289 // Search the incoming arcs of u 1029 1290 LargeCost pi_u = _pi[u]; 1030 1291 int last_out = _first_out[u+1]; … … 1038 1299 LargeCost nrc = (_cost[ra] + _pi[v] - pi_u) / _epsilon; 1039 1300 int new_rank_v = old_rank_v; 1040 if (nrc < LargeCost(_max_rank)) 1041 new_rank_v = r + 1 + int(nrc); 1301 if (nrc < LargeCost(_max_rank)) { 1302 new_rank_v = r + 1 + static_cast<int>(nrc); 1303 } 1042 1304 1043 1305 // Change the rank of v … … 1051 1313 _buckets[old_rank_v] = _bucket_next[v]; 1052 1314 } else { 1053 _bucket_next[_bucket_prev[v]] = _bucket_next[v]; 1054 _bucket_prev[_bucket_next[v]] = _bucket_prev[v]; 1315 int pv = _bucket_prev[v], nv = _bucket_next[v]; 1316 _bucket_next[pv] = nv; 1317 _bucket_prev[nv] = pv; 1055 1318 } 1056 1319 } 1057 1320 1058 // Insert v to its new bucket 1059 _bucket_next[v] = _buckets[new_rank_v]; 1060 _bucket_prev[_buckets[new_rank_v]] = v; 1321 // Insert v into its new bucket 1322 int nv = _buckets[new_rank_v]; 1323 _bucket_next[v] = nv; 1324 _bucket_prev[nv] = v; 1061 1325 _buckets[new_rank_v] = v; 1062 1326 } … … 1087 1351 void startAugment(int max_length) { 1088 1352 // 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 * 1353 const int PRICE_REFINEMENT_LIMIT = 2; 1354 const double GLOBAL_UPDATE_FACTOR = 1.0; 1355 const int global_update_skip = static_cast<int>(GLOBAL_UPDATE_FACTOR * 1093 1356 (_res_node_num + _sup_node_num * _sup_node_num)); 1094 int next_update_limit = global_update_freq; 1095 1357 int next_global_update_limit = global_update_skip; 1358 1359 // Perform cost scaling phases 1360 IntVector path; 1361 BoolVector path_arc(_res_arc_num, false); 1096 1362 int relabel_cnt = 0; 1097 1098 // Perform cost scaling phases 1099 std::vector<int> path; 1363 int eps_phase_cnt = 0; 1100 1364 for ( ; _epsilon >= 1; _epsilon = _epsilon < _alpha && _epsilon > 1 ? 1101 1365 1 : _epsilon / _alpha ) 1102 1366 { 1103 // Early termination heuristic 1104 if (_epsilon <= EARLY_TERM_EPSILON_LIMIT) { 1105 if (earlyTermination()) break; 1367 ++eps_phase_cnt; 1368 1369 // Price refinement heuristic 1370 if (eps_phase_cnt >= PRICE_REFINEMENT_LIMIT) { 1371 if (priceRefinement()) continue; 1106 1372 } 1107 1373 … … 1120 1386 1121 1387 // Find an augmenting path from the start node 1122 path.clear();1123 1388 int tip = start; 1124 while ( _excess[tip] >= 0 && int(path.size()) < max_length) {1389 while (int(path.size()) < max_length && _excess[tip] >= 0) { 1125 1390 int u; 1126 LargeCost min_red_cost, rc, pi_tip = _pi[tip]; 1391 LargeCost rc, min_red_cost = std::numeric_limits<LargeCost>::max(); 1392 LargeCost pi_tip = _pi[tip]; 1127 1393 int last_out = _first_out[tip+1]; 1128 1394 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; 1395 if (_res_cap[a] > 0) { 1396 u = _target[a]; 1397 rc = _cost[a] + pi_tip - _pi[u]; 1398 if (rc < 0) { 1399 path.push_back(a); 1400 _next_out[tip] = a; 1401 if (path_arc[a]) { 1402 goto augment; // a cycle is found, stop path search 1403 } 1404 tip = u; 1405 path_arc[a] = true; 1406 goto next_step; 1407 } 1408 else if (rc < min_red_cost) { 1409 min_red_cost = rc; 1410 } 1135 1411 } 1136 1412 } 1137 1413 1138 1414 // Relabel tip node 1139 min_red_cost = std::numeric_limits<LargeCost>::max();1140 1415 if (tip != start) { 1141 1416 int ra = _reverse[path.back()]; 1142 min_red_cost = _cost[ra] + pi_tip - _pi[_target[ra]]; 1417 min_red_cost = 1418 std::min(min_red_cost, _cost[ra] + pi_tip - _pi[_target[ra]]); 1143 1419 } 1420 last_out = _next_out[tip]; 1144 1421 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; 1422 if (_res_cap[a] > 0) { 1423 rc = _cost[a] + pi_tip - _pi[_target[a]]; 1424 if (rc < min_red_cost) { 1425 min_red_cost = rc; 1426 } 1148 1427 } 1149 1428 } … … 1154 1433 // Step back 1155 1434 if (tip != start) { 1156 tip = _source[path.back()]; 1435 int pa = path.back(); 1436 path_arc[pa] = false; 1437 tip = _source[pa]; 1157 1438 path.pop_back(); 1158 1439 } … … 1162 1443 1163 1444 // Augment along the found path (as much flow as possible) 1445 augment: 1164 1446 Value delta; 1165 1447 int pa, u, v = start; … … 1168 1450 u = v; 1169 1451 v = _target[pa]; 1452 path_arc[pa] = false; 1170 1453 delta = std::min(_res_cap[pa], _excess[u]); 1171 1454 _res_cap[pa] -= delta; … … 1173 1456 _excess[u] -= delta; 1174 1457 _excess[v] += delta; 1175 if (_excess[v] > 0 && _excess[v] <= delta) 1458 if (_excess[v] > 0 && _excess[v] <= delta) { 1176 1459 _active_nodes.push_back(v); 1177 } 1460 } 1461 } 1462 path.clear(); 1178 1463 1179 1464 // Global update heuristic 1180 if (relabel_cnt >= next_ update_limit) {1465 if (relabel_cnt >= next_global_update_limit) { 1181 1466 globalUpdate(); 1182 next_update_limit += global_update_freq; 1183 } 1184 } 1185 } 1467 next_global_update_limit += global_update_skip; 1468 } 1469 } 1470 1471 } 1472 1186 1473 } 1187 1474 … … 1189 1476 void startPush() { 1190 1477 // Paramters for heuristics 1191 const int EARLY_TERM_EPSILON_LIMIT = 1000;1478 const int PRICE_REFINEMENT_LIMIT = 2; 1192 1479 const double GLOBAL_UPDATE_FACTOR = 2.0; 1193 1480 1194 const int global_update_ freq = int(GLOBAL_UPDATE_FACTOR *1481 const int global_update_skip = static_cast<int>(GLOBAL_UPDATE_FACTOR * 1195 1482 (_res_node_num + _sup_node_num * _sup_node_num)); 1196 int next_update_limit = global_update_freq; 1197 1198 int relabel_cnt = 0; 1483 int next_global_update_limit = global_update_skip; 1199 1484 1200 1485 // Perform cost scaling phases 1201 1486 BoolVector hyper(_res_node_num, false); 1202 1487 LargeCostVector hyper_cost(_res_node_num); 1488 int relabel_cnt = 0; 1489 int eps_phase_cnt = 0; 1203 1490 for ( ; _epsilon >= 1; _epsilon = _epsilon < _alpha && _epsilon > 1 ? 1204 1491 1 : _epsilon / _alpha ) 1205 1492 { 1206 // Early termination heuristic 1207 if (_epsilon <= EARLY_TERM_EPSILON_LIMIT) { 1208 if (earlyTermination()) break; 1493 ++eps_phase_cnt; 1494 1495 // Price refinement heuristic 1496 if (eps_phase_cnt >= PRICE_REFINEMENT_LIMIT) { 1497 if (priceRefinement()) continue; 1209 1498 } 1210 1499 … … 1278 1567 std::numeric_limits<LargeCost>::max(); 1279 1568 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; 1569 if (_res_cap[a] > 0) { 1570 rc = _cost[a] + pi_n - _pi[_target[a]]; 1571 if (rc < min_red_cost) { 1572 min_red_cost = rc; 1573 } 1283 1574 } 1284 1575 } … … 1298 1589 1299 1590 // Global update heuristic 1300 if (relabel_cnt >= next_ update_limit) {1591 if (relabel_cnt >= next_global_update_limit) { 1301 1592 globalUpdate(); 1302 1593 for (int u = 0; u != _res_node_num; ++u) 1303 1594 hyper[u] = false; 1304 next_ update_limit += global_update_freq;1595 next_global_update_limit += global_update_skip; 1305 1596 } 1306 1597 } -
lemon/counter.h
r833 r1327 22 22 #include <string> 23 23 #include <iostream> 24 25 #include <lemon/core.h> 24 26 25 27 ///\ingroup timecount -
lemon/cplex.cc
r1142 r1347 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 38 38 } 39 39 40 void CplexEnv::incCnt() 41 { 42 _cnt_lock->lock(); 43 ++(*_cnt); 44 _cnt_lock->unlock(); 45 } 46 47 void CplexEnv::decCnt() 48 { 49 _cnt_lock->lock(); 50 --(*_cnt); 51 if (*_cnt == 0) { 52 delete _cnt; 53 _cnt_lock->unlock(); 54 delete _cnt_lock; 55 CPXcloseCPLEX(&_env); 56 } 57 else _cnt_lock->unlock(); 58 } 59 40 60 CplexEnv::CplexEnv() { 41 61 int status; 62 _env = CPXopenCPLEX(&status); 63 if (_env == 0) 64 throw LicenseError(status); 42 65 _cnt = new int; 43 _env = CPXopenCPLEX(&status); 44 if (_env == 0) { 45 delete _cnt; 46 _cnt = 0; 47 throw LicenseError(status); 48 } 66 (*_cnt) = 1; 67 _cnt_lock = new bits::Lock; 49 68 } 50 69 … … 52 71 _env = other._env; 53 72 _cnt = other._cnt; 54 ++(*_cnt); 73 _cnt_lock = other._cnt_lock; 74 incCnt(); 55 75 } 56 76 57 77 CplexEnv& CplexEnv::operator=(const CplexEnv& other) { 78 decCnt(); 58 79 _env = other._env; 59 80 _cnt = other._cnt; 60 ++(*_cnt); 81 _cnt_lock = other._cnt_lock; 82 incCnt(); 61 83 return *this; 62 84 } 63 85 64 86 CplexEnv::~CplexEnv() { 65 --(*_cnt); 66 if (*_cnt == 0) { 67 delete _cnt; 68 CPXcloseCPLEX(&_env); 69 } 87 decCnt(); 70 88 } 71 89 … … 491 509 _message_enabled ? CPX_ON : CPX_OFF); 492 510 } 511 512 void CplexBase::_write(std::string file, std::string format) const 513 { 514 if(format == "MPS" || format == "LP") 515 CPXwriteprob(cplexEnv(), cplexLp(), file.c_str(), format.c_str()); 516 else if(format == "SOL") 517 CPXsolwrite(cplexEnv(), cplexLp(), file.c_str()); 518 else throw UnsupportedFormatError(format); 519 } 520 521 493 522 494 523 // CplexLp members -
lemon/cplex.h
r793 r1347 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 24 24 25 25 #include <lemon/lp_base.h> 26 #include <lemon/bits/lock.h> 26 27 27 28 struct cpxenv; … … 41 42 cpxenv* _env; 42 43 mutable int* _cnt; 43 44 mutable bits::Lock* _cnt_lock; 45 46 void incCnt(); 47 void decCnt(); 48 44 49 public: 45 50 … … 151 156 bool _message_enabled; 152 157 158 void _write(std::string file, std::string format) const; 159 153 160 public: 154 161 … … 171 178 const cpxlp* cplexLp() const { return _prob; } 172 179 180 #ifdef DOXYGEN 181 /// Write the problem or the solution to a file in the given format 182 183 /// This function writes the problem or the solution 184 /// to a file in the given format. 185 /// Trying to write in an unsupported format will trigger 186 /// \ref lemon::LpBase::UnsupportedFormatError "UnsupportedFormatError". 187 /// \param file The file path 188 /// \param format The output file format. 189 /// Supportted formats are "MPS", "LP" and "SOL". 190 void write(std::string file, std::string format = "MPS") const {} 191 #endif 192 173 193 }; 174 194 -
lemon/cycle_canceling.h
r956 r1298 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 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 { … … 47 48 /// \ref CycleCanceling implements three different cycle-canceling 48 49 /// algorithms for finding a \ref min_cost_flow "minimum cost flow" 49 /// \ref amo93networkflows, \ref klein67primal, 50 /// \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. 50 /// \cite amo93networkflows, \cite klein67primal, 51 /// \cite goldberg89cyclecanceling. 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 \f$O(n^2 m^2 \log n)\f$, 55 /// but in practice, it is typically orders of magnitude slower than 56 /// the scaling algorithms and \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 129 133 /// well-known strongly polynomial method 130 /// \ refgoldberg89cyclecanceling. It improves along a134 /// \cite 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 \f$O(n^2 m^3 \log n)\f$. 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 /// \ refgoldberg89cyclecanceling.140 /// \cite 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 \f$O(n^2 m^2 \log n)\f$. 139 143 CANCEL_AND_TIGHTEN 140 144 }; … … 192 196 193 197 // Parameters of the problem 194 bool _ha ve_lower;198 bool _has_lower; 195 199 Value _sum_supply; 196 200 … … 275 279 template <typename LowerMap> 276 280 CycleCanceling& lowerMap(const LowerMap& map) { 277 _ha ve_lower = true;281 _has_lower = true; 278 282 for (ArcIt a(_graph); a != INVALID; ++a) { 279 283 _lower[_arc_idf[a]] = map[a]; 280 _lower[_arc_idb[a]] = map[a];281 284 } 282 285 return *this; … … 350 353 /// 351 354 /// 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 is355 /// with a map in which \c k is assigned to \c s, \c -k is 353 356 /// assigned to \c t and all other nodes have zero supply value. 354 357 /// … … 468 471 _cost[_reverse[j]] = 0; 469 472 } 470 _ha ve_lower = false;473 _has_lower = false; 471 474 return *this; 472 475 } … … 573 576 /// 574 577 /// This function returns the total cost of the found flow. 575 /// Its complexity is O( e).578 /// Its complexity is O(m). 576 579 /// 577 580 /// \note The return type of the function can be specified as a … … 611 614 } 612 615 613 /// \brief Return the flow map (the primal solution). 616 /// \brief Copy the flow values (the primal solution) into the 617 /// given map. 614 618 /// 615 619 /// This function copies the flow value on each arc into the given … … 635 639 } 636 640 637 /// \brief Return the potential map (the dual solution). 641 /// \brief Copy the potential values (the dual solution) into the 642 /// given map. 638 643 /// 639 644 /// This function copies the potential (dual value) of each node … … 665 670 if (_sum_supply > 0) return INFEASIBLE; 666 671 672 // Check lower and upper bounds 673 LEMON_DEBUG(checkBoundMaps(), 674 "Upper bounds must be greater or equal to the lower bounds"); 675 667 676 668 677 // Initialize vectors … … 675 684 const Value MAX = std::numeric_limits<Value>::max(); 676 685 int last_out; 677 if (_ha ve_lower) {686 if (_has_lower) { 678 687 for (int i = 0; i != _root; ++i) { 679 688 last_out = _first_out[i+1]; … … 718 727 sup[n] = _supply[_node_id[n]]; 719 728 } 720 if (_ha ve_lower) {729 if (_has_lower) { 721 730 for (ArcIt a(_graph); a != INVALID; ++a) { 722 731 int j = _arc_idf[a]; … … 773 782 774 783 return OPTIMAL; 784 } 785 786 // Check if the upper bound is greater than or equal to the lower bound 787 // on each forward arc. 788 bool checkBoundMaps() { 789 for (int j = 0; j != _res_arc_num; ++j) { 790 if (_forward[j] && _upper[j] < _lower[j]) return false; 791 } 792 return true; 775 793 } 776 794 … … 817 835 818 836 // Handle non-zero lower bounds 819 if (_ha ve_lower) {837 if (_has_lower) { 820 838 int limit = _first_out[_root]; 821 839 for (int j = 0; j != limit; ++j) { 822 if ( !_forward[j]) _res_cap[j] += _lower[j];840 if (_forward[j]) _res_cap[_reverse[j]] += _lower[j]; 823 841 } 824 842 } … … 923 941 // Execute the "Minimum Mean Cycle Canceling" method 924 942 void startMinMeanCycleCanceling() { 925 typedef SimplePath<StaticDigraph> SPath;943 typedef Path<StaticDigraph> SPath; 926 944 typedef typename SPath::ArcIt SPathArcIt; 927 945 typedef typename HowardMmc<StaticDigraph, CostArcMap> 928 ::template SetPath<SPath>::Create MMC; 946 ::template SetPath<SPath>::Create HwMmc; 947 typedef typename HartmannOrlinMmc<StaticDigraph, CostArcMap> 948 ::template SetPath<SPath>::Create HoMmc; 949 950 const double HW_ITER_LIMIT_FACTOR = 1.0; 951 const int HW_ITER_LIMIT_MIN_VALUE = 5; 952 953 const int hw_iter_limit = 954 std::max(static_cast<int>(HW_ITER_LIMIT_FACTOR * _node_num), 955 HW_ITER_LIMIT_MIN_VALUE); 929 956 930 957 SPath cycle; 931 MMCmmc(_sgr, _cost_map);932 mmc.cycle(cycle);958 HwMmc hw_mmc(_sgr, _cost_map); 959 hw_mmc.cycle(cycle); 933 960 buildResidualNetwork(); 934 while (mmc.findCycleMean() && mmc.cycleCost() < 0) { 935 // Find the cycle 936 mmc.findCycle(); 961 while (true) { 962 963 typename HwMmc::TerminationCause hw_tc = 964 hw_mmc.findCycleMean(hw_iter_limit); 965 if (hw_tc == HwMmc::ITERATION_LIMIT) { 966 // Howard's algorithm reached the iteration limit, start a 967 // strongly polynomial algorithm instead 968 HoMmc ho_mmc(_sgr, _cost_map); 969 ho_mmc.cycle(cycle); 970 // Find a minimum mean cycle (Hartmann-Orlin algorithm) 971 if (!(ho_mmc.findCycleMean() && ho_mmc.cycleCost() < 0)) break; 972 ho_mmc.findCycle(); 973 } else { 974 // Find a minimum mean cycle (Howard algorithm) 975 if (!(hw_tc == HwMmc::OPTIMAL && hw_mmc.cycleCost() < 0)) break; 976 hw_mmc.findCycle(); 977 } 937 978 938 979 // Compute delta value … … 955 996 } 956 997 957 // Execute the "Cancel AndTighten" method998 // Execute the "Cancel-and-Tighten" method 958 999 void startCancelAndTighten() { 959 1000 // Constants for the min mean cycle computations 960 1001 const double LIMIT_FACTOR = 1.0; 961 1002 const int MIN_LIMIT = 5; 1003 const double HW_ITER_LIMIT_FACTOR = 1.0; 1004 const int HW_ITER_LIMIT_MIN_VALUE = 5; 1005 1006 const int hw_iter_limit = 1007 std::max(static_cast<int>(HW_ITER_LIMIT_FACTOR * _node_num), 1008 HW_ITER_LIMIT_MIN_VALUE); 962 1009 963 1010 // Contruct auxiliary data vectors … … 1133 1180 } 1134 1181 } else { 1135 typedef HowardMmc<StaticDigraph, CostArcMap> MMC; 1182 typedef HowardMmc<StaticDigraph, CostArcMap> HwMmc; 1183 typedef HartmannOrlinMmc<StaticDigraph, CostArcMap> HoMmc; 1136 1184 typedef typename BellmanFord<StaticDigraph, CostArcMap> 1137 1185 ::template SetDistMap<CostNodeMap>::Create BF; 1138 1186 1139 1187 // Set epsilon to the minimum cycle mean 1188 Cost cycle_cost = 0; 1189 int cycle_size = 1; 1140 1190 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(); 1191 HwMmc hw_mmc(_sgr, _cost_map); 1192 if (hw_mmc.findCycleMean(hw_iter_limit) == HwMmc::ITERATION_LIMIT) { 1193 // Howard's algorithm reached the iteration limit, start a 1194 // strongly polynomial algorithm instead 1195 HoMmc ho_mmc(_sgr, _cost_map); 1196 ho_mmc.findCycleMean(); 1197 epsilon = -ho_mmc.cycleMean(); 1198 cycle_cost = ho_mmc.cycleCost(); 1199 cycle_size = ho_mmc.cycleSize(); 1200 } else { 1201 // Set epsilon 1202 epsilon = -hw_mmc.cycleMean(); 1203 cycle_cost = hw_mmc.cycleCost(); 1204 cycle_size = hw_mmc.cycleSize(); 1205 } 1146 1206 1147 1207 // Compute feasible potentials for the current epsilon -
lemon/dfs.h
r1159 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 153 153 typedef PredMapPath<Digraph, PredMap> Path; 154 154 155 ///The \ref DfsDefaultTraits "traits class" of the algorithm.155 ///The \ref lemon::DfsDefaultTraits "traits class" of the algorithm. 156 156 typedef TR Traits; 157 157 -
lemon/dijkstra.h
r956 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 228 228 ///The heap type used by the algorithm. 229 229 typedef typename TR::Heap Heap; 230 /// \brief The \ref DijkstraDefaultOperationTraits "operation traits class"231 /// of the algorithm.230 /// \brief The \ref lemon::DijkstraDefaultOperationTraits 231 /// "operation traits class" of the algorithm. 232 232 typedef typename TR::OperationTraits OperationTraits; 233 233 234 ///The \ref DijkstraDefaultTraits "traits class" of the algorithm.234 ///The \ref lemon::DijkstraDefaultTraits "traits class" of the algorithm. 235 235 typedef TR Traits; 236 236 -
lemon/dim2.h
r761 r1311 21 21 22 22 #include <iostream> 23 #include <algorithm> 23 24 24 25 ///\ingroup geomdat -
lemon/dimacs.h
r956 r1375 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 26 26 #include <lemon/maps.h> 27 27 #include <lemon/error.h> 28 28 29 /// \ingroup dimacs_group 29 30 /// \file … … 123 124 /// 124 125 /// If the file type was previously evaluated by dimacsType(), then 125 /// the descriptor struct should be given by the \c des tparameter.126 /// the descriptor struct should be given by the \c desc parameter. 126 127 template <typename Digraph, typename LowerMap, 127 128 typename CapacityMap, typename CostMap, … … 277 278 /// 278 279 /// If the file type was previously evaluated by dimacsType(), then 279 /// the descriptor struct should be given by the \c des tparameter.280 /// the descriptor struct should be given by the \c desc parameter. 280 281 template<typename Digraph, typename CapacityMap> 281 282 void readDimacsMax(std::istream& is, … … 304 305 /// 305 306 /// If the file type was previously evaluated by dimacsType(), then 306 /// the descriptor struct should be given by the \c des tparameter.307 /// the descriptor struct should be given by the \c desc parameter. 307 308 template<typename Digraph, typename LengthMap> 308 309 void readDimacsSp(std::istream& is, … … 335 336 /// 336 337 /// If the file type was previously evaluated by dimacsType(), then 337 /// the descriptor struct should be given by the \c des tparameter.338 /// the descriptor struct should be given by the \c desc parameter. 338 339 template<typename Digraph, typename CapacityMap> 339 340 void readDimacsCap(std::istream& is, … … 344 345 typename Digraph::Node u,v; 345 346 if(desc.type==DimacsDescriptor::NONE) desc=dimacsType(is); 346 if(desc.type!=DimacsDescriptor::MAX ||desc.type!=DimacsDescriptor::SP)347 if(desc.type!=DimacsDescriptor::MAX && desc.type!=DimacsDescriptor::SP) 347 348 throw FormatError("Problem type mismatch"); 348 349 _readDimacs(is, g, capacity, u, v, infty, desc); … … 375 376 /// 376 377 /// If the file type was previously evaluated by dimacsType(), then 377 /// the descriptor struct should be given by the \c des tparameter.378 /// the descriptor struct should be given by the \c desc parameter. 378 379 template<typename Graph> 379 380 void readDimacsMat(std::istream& is, Graph &g, -
lemon/edge_set.h
r956 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). -
lemon/elevator.h
r628 r1328 168 168 int onLevel(int l) const 169 169 { 170 return _first[l+1]-_first[l];170 return static_cast<int>(_first[l+1]-_first[l]); 171 171 } 172 172 ///Return true if level \c l is empty. … … 178 178 int aboveLevel(int l) const 179 179 { 180 return _first[_max_level+1]-_first[l+1];180 return static_cast<int>(_first[_max_level+1]-_first[l+1]); 181 181 } 182 182 ///Return the number of active items on level \c l. 183 183 int activesOnLevel(int l) const 184 184 { 185 return _last_active[l]-_first[l]+1;185 return static_cast<int>(_last_active[l]-_first[l]+1); 186 186 } 187 187 ///Return true if there is no active item on level \c l. -
lemon/euler.h
r956 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 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/fractional_matching.h
r956 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 124 124 public: 125 125 126 /// \brief The \ref MaxFractionalMatchingDefaultTraits "traits127 /// class" of the algorithm.126 /// \brief The \ref lemon::MaxFractionalMatchingDefaultTraits 127 /// "traits class" of the algorithm. 128 128 typedef TR Traits; 129 129 /// The type of the graph the algorithm runs on. -
lemon/full_graph.h
r956 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 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
r1142 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 581 581 break; 582 582 } 583 } 584 585 void GlpkBase::_write(std::string file, std::string format) const 586 { 587 if(format == "MPS") 588 glp_write_mps(lp, GLP_MPS_FILE, 0, file.c_str()); 589 else if(format == "LP") 590 glp_write_lp(lp, 0, file.c_str()); 591 else throw UnsupportedFormatError(format); 583 592 } 584 593 … … 999 1008 const char* GlpkMip::_solverName() const { return "GlpkMip"; } 1000 1009 1010 1011 1001 1012 } //END OF NAMESPACE LEMON -
lemon/glpk.h
r956 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 116 116 virtual void _messageLevel(MessageLevel level); 117 117 118 virtual void _write(std::string file, std::string format) const; 119 118 120 private: 119 121 … … 145 147 int lpxCol(Col c) const { return cols(id(c)); } 146 148 149 #ifdef DOXYGEN 150 /// Write the problem or the solution to a file in the given format 151 152 /// This function writes the problem or the solution 153 /// to a file in the given format. 154 /// Trying to write in an unsupported format will trigger 155 /// \ref LpBase::UnsupportedFormatError. 156 /// \param file The file path 157 /// \param format The output file format. 158 /// Supportted formats are "MPS" and "LP". 159 void write(std::string file, std::string format = "MPS") const {} 160 #endif 161 147 162 }; 148 163 -
lemon/gomory_hu.h
r956 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 47 47 /// 48 48 /// The algorithm calculates \e n-1 distinct minimum cuts (currently with 49 /// the \ref Preflow algorithm), thus it has \f$O(n^3\sqrt{ e})\f$ overall49 /// the \ref Preflow algorithm), thus it has \f$O(n^3\sqrt{m})\f$ overall 50 50 /// time complexity. It calculates a rooted Gomory-Hu tree. 51 51 /// The structure of the tree and the edge weights can be -
lemon/graph_to_eps.h
r1159 r1340 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 26 26 #include<vector> 27 27 28 #ifndef WIN3228 #ifndef LEMON_WIN32 29 29 #include<sys/time.h> 30 30 #include<ctime> … … 223 223 using T::_copyright; 224 224 225 using typename T::NodeTextColorType;226 225 using T::CUST_COL; 227 226 using T::DIST_COL; … … 676 675 { 677 676 os << "%%CreationDate: "; 678 #ifndef WIN32677 #ifndef LEMON_WIN32 679 678 timeval tv; 680 679 gettimeofday(&tv, 0); -
lemon/hao_orlin.h
r956 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 54 54 /// preflow push-relabel algorithm. Our implementation calculates 55 55 /// the minimum cut in \f$ O(n^2\sqrt{m}) \f$ time (we use the 56 /// highest-label rule), or in \f$O(nm)\f$ for unit capacities. The57 /// purpose of such algorithm is e.g.testing network reliability.56 /// highest-label rule), or in \f$O(nm)\f$ for unit capacities. A notable 57 /// use of this algorithm is testing network reliability. 58 58 /// 59 59 /// For an undirected graph you can run just the first phase of the … … 913 913 /// source-side (i.e. a set \f$ X\subsetneq V \f$ with 914 914 /// \f$ source \in X \f$ and minimal outgoing capacity). 915 /// It updates the stored cut if (and only if) the newly found one 916 /// is better. 915 917 /// 916 918 /// \pre \ref init() must be called before using this function. … … 925 927 /// sink-side (i.e. a set \f$ X\subsetneq V \f$ with 926 928 /// \f$ source \notin X \f$ and minimal outgoing capacity). 929 /// It updates the stored cut if (and only if) the newly found one 930 /// is better. 927 931 /// 928 932 /// \pre \ref init() must be called before using this function. … … 934 938 /// \brief Run the algorithm. 935 939 /// 936 /// This function runs the algorithm. It finds nodes \c source and937 /// \c target arbitrarily andthen calls \ref init(), \ref calculateOut()940 /// This function runs the algorithm. It chooses source node, 941 /// then calls \ref init(), \ref calculateOut() 938 942 /// and \ref calculateIn(). 939 943 void run() { … … 945 949 /// \brief Run the algorithm. 946 950 /// 947 /// This function runs the algorithm. It uses the given \c source node,948 /// finds a proper \c target node and then calls the \ref init(),949 /// \ref calculateOut() and \ref calculateIn().951 /// This function runs the algorithm. It calls \ref init(), 952 /// \ref calculateOut() and \ref calculateIn() with the given 953 /// source node. 950 954 void run(const Node& s) { 951 955 init(s); … … 966 970 /// \brief Return the value of the minimum cut. 967 971 /// 968 /// This function returns the value of the minimum cut. 972 /// This function returns the value of the best cut found by the 973 /// previously called \ref run(), \ref calculateOut() or \ref 974 /// calculateIn(). 969 975 /// 970 976 /// \pre \ref run(), \ref calculateOut() or \ref calculateIn() … … 977 983 /// \brief Return a minimum cut. 978 984 /// 979 /// This function sets \c cutMap to the characteristic vector of a 980 /// minimum value cut: it will give a non-empty set \f$ X\subsetneq V \f$ 981 /// with minimal outgoing capacity (i.e. \c cutMap will be \c true exactly 985 /// This function gives the best cut found by the 986 /// previously called \ref run(), \ref calculateOut() or \ref 987 /// calculateIn(). 988 /// 989 /// It sets \c cutMap to the characteristic vector of the found 990 /// minimum value cut - a non-empty set \f$ X\subsetneq V \f$ 991 /// of minimum outgoing capacity (i.e. \c cutMap will be \c true exactly 982 992 /// for the nodes of \f$ X \f$). 983 993 /// -
lemon/hartmann_orlin_mmc.h
r959 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 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. 102 /// It is an improved version of \ref KarpMmc "Karp"'s original algorithm, 103 /// it applies an efficient early termination scheme. 104 /// It runs in time O(ne) and uses space O(n<sup>2</sup>+e). 101 /// \cite hartmann93finding, \cite dasdan98minmeancycle. 102 /// This method is based on \ref KarpMmc "Karp"'s original algorithm, but 103 /// applies an early termination scheme. It makes the algorithm 104 /// significantly faster for some problem instances, but slower for others. 105 /// The algorithm runs in time O(nm) and uses space O(n<sup>2</sup>+m). 105 106 /// 106 107 /// \tparam GR The type of the digraph the algorithm runs on. … … 143 144 /// 144 145 /// The path type of the found cycles. 145 /// Using the \ref HartmannOrlinMmcDefaultTraits "default traits class", 146 /// Using the \ref lemon::HartmannOrlinMmcDefaultTraits 147 /// "default traits class", 146 148 /// it is \ref lemon::Path "Path<Digraph>". 147 149 typedef typename TR::Path Path; 148 150 149 /// The \ref HartmannOrlinMmcDefaultTraits "traits class" of the algorithm 151 /// \brief The 152 /// \ref lemon::HartmannOrlinMmcDefaultTraits "traits class" 153 /// of the algorithm 150 154 typedef TR Traits; 151 155 … … 275 279 /// 276 280 /// If you don't call this function before calling \ref run() or 277 /// \ref findCycleMean(), it will allocate a local \ref Path "path"278 /// structure. The destuctor deallocates this automatically281 /// \ref findCycleMean(), a local \ref Path "path" structure 282 /// will be allocated. The destuctor deallocates this automatically 279 283 /// allocated object, of course. 280 284 /// -
lemon/howard_mmc.h
r956 r1271 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 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 /// \cite dasdan98minmeancycle, \cite dasdan04experimental. 102 102 /// This class provides the most efficient algorithm for the 103 103 /// minimum mean cycle problem, though the best known theoretical … … 143 143 /// 144 144 /// The path type of the found cycles. 145 /// Using the \ref HowardMmcDefaultTraits "default traits class",145 /// Using the \ref lemon::HowardMmcDefaultTraits "default traits class", 146 146 /// it is \ref lemon::Path "Path<Digraph>". 147 147 typedef typename TR::Path Path; 148 148 149 /// The \ref HowardMmcDefaultTraits "traits class" of the algorithm149 /// The \ref lemon::HowardMmcDefaultTraits "traits class" of the algorithm 150 150 typedef TR Traits; 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 }; 151 168 152 169 private: … … 266 283 /// 267 284 /// If you don't call this function before calling \ref run() or 268 /// \ref findCycleMean(), it will allocate a local \ref Path "path"269 /// structure. The destuctor deallocates this automatically285 /// \ref findCycleMean(), a local \ref Path "path" structure 286 /// will be allocated. The destuctor deallocates this automatically 270 287 /// allocated object, of course. 271 288 /// … … 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 = 365 std::numeric_limits<int>::max()) { 334 366 // Initialize and find strongly connected components 335 367 init(); … … 337 369 338 370 // Find the minimum cycle mean in the components 371 int iter_count = 0; 372 bool iter_limit_reached = false; 339 373 for (int comp = 0; comp < _comp_num; ++comp) { 340 374 // Find the minimum mean cycle in the current component 341 375 if (!buildPolicyGraph(comp)) continue; 342 376 while (true) { 377 if (++iter_count > limit) { 378 iter_limit_reached = true; 379 break; 380 } 343 381 findPolicyCycle(); 344 382 if (!computeNodeDistances()) break; 345 383 } 384 346 385 // Update the best cycle (global minimum mean cycle) 347 386 if ( _curr_found && (!_best_found || … … 352 391 _best_node = _curr_node; 353 392 } 354 } 355 return _best_found; 393 394 if (iter_limit_reached) break; 395 } 396 397 if (iter_limit_reached) { 398 return ITERATION_LIMIT; 399 } else { 400 return _best_found ? OPTIMAL : NO_CYCLE; 401 } 356 402 } 357 403 -
lemon/karp_mmc.h
r956 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 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, \refdasdan98minmeancycle.102 /// It runs in time O(n e) and uses space O(n<sup>2</sup>+e).101 /// \cite karp78characterization, \cite dasdan98minmeancycle. 102 /// It runs in time O(nm) and uses space O(n<sup>2</sup>+m). 103 103 /// 104 104 /// \tparam GR The type of the digraph the algorithm runs on. … … 141 141 /// 142 142 /// The path type of the found cycles. 143 /// Using the \ref KarpMmcDefaultTraits "default traits class",143 /// Using the \ref lemon::KarpMmcDefaultTraits "default traits class", 144 144 /// it is \ref lemon::Path "Path<Digraph>". 145 145 typedef typename TR::Path Path; 146 146 147 /// The \ref KarpMmcDefaultTraits "traits class" of the algorithm147 /// The \ref lemon::KarpMmcDefaultTraits "traits class" of the algorithm 148 148 typedef TR Traits; 149 149 … … 271 271 /// 272 272 /// If you don't call this function before calling \ref run() or 273 /// \ref findCycleMean(), it will allocate a local \ref Path "path"274 /// structure. The destuctor deallocates this automatically273 /// \ref findCycleMean(), a local \ref Path "path" structure 274 /// will be allocated. The destuctor deallocates this automatically 275 275 /// allocated object, of course. 276 276 /// -
lemon/kruskal.h
r631 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 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
r705 r1133 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
r1107 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 15 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 155 155 }; 156 156 157 template <typename Value> 157 template <typename Value, 158 typename Map = std::map<std::string, Value> > 158 159 struct MapLookUpConverter { 159 const std::map<std::string, Value>& _map;160 161 MapLookUpConverter(const std::map<std::string, Value>& map)160 const Map& _map; 161 162 MapLookUpConverter(const Map& map) 162 163 : _map(map) {} 163 164 164 165 Value operator()(const std::string& str) { 165 typename std::map<std::string, Value>::const_iterator it = 166 _map.find(str); 166 typename Map::const_iterator it = _map.find(str); 167 167 if (it == _map.end()) { 168 168 std::ostringstream msg; … … 171 171 } 172 172 return it->second; 173 } 174 }; 175 176 template <typename Value, 177 typename Map1 = std::map<std::string, Value>, 178 typename Map2 = std::map<std::string, Value> > 179 struct DoubleMapLookUpConverter { 180 const Map1& _map1; 181 const Map2& _map2; 182 183 DoubleMapLookUpConverter(const Map1& map1, const Map2& map2) 184 : _map1(map1), _map2(map2) {} 185 186 Value operator()(const std::string& str) { 187 typename Map1::const_iterator it1 = _map1.find(str); 188 typename Map2::const_iterator it2 = _map2.find(str); 189 if (it1 == _map1.end()) { 190 if (it2 == _map2.end()) { 191 std::ostringstream msg; 192 msg << "Item not found: " << str; 193 throw FormatError(msg.str()); 194 } else { 195 return it2->second; 196 } 197 } else { 198 if (it2 == _map2.end()) { 199 return it1->second; 200 } else { 201 std::ostringstream msg; 202 msg << "Item is ambigous: " << str; 203 throw FormatError(msg.str()); 204 } 205 } 173 206 } 174 207 }; … … 1198 1231 /// \ingroup lemon_io 1199 1232 /// 1200 /// \brief Return a \ref DigraphReader class 1201 /// 1202 /// This function just returns a \ref DigraphReader class. 1233 /// \brief Return a \ref lemon::DigraphReader "DigraphReader" class 1234 /// 1235 /// This function just returns a \ref lemon::DigraphReader 1236 /// "DigraphReader" class. 1203 1237 /// 1204 1238 /// With this function a digraph can be read from an … … 1220 1254 ///\endcode 1221 1255 /// 1222 /// For a complete documentation, please see the \ref DigraphReader 1256 /// For a complete documentation, please see the 1257 /// \ref lemon::DigraphReader "DigraphReader" 1223 1258 /// class documentation. 1224 /// \warning Don't forget to put the \ref DigraphReader::run() "run()"1259 /// \warning Don't forget to put the \ref lemon::DigraphReader::run() "run()" 1225 1260 /// to the end of the parameter list. 1226 1261 /// \relates DigraphReader … … 2076 2111 /// \ingroup lemon_io 2077 2112 /// 2078 /// \brief Return a \ref GraphReaderclass2079 /// 2080 /// This function just returns a \ref GraphReaderclass.2113 /// \brief Return a \ref lemon::GraphReader "GraphReader" class 2114 /// 2115 /// This function just returns a \ref lemon::GraphReader "GraphReader" class. 2081 2116 /// 2082 2117 /// With this function a graph can be read from an … … 2094 2129 ///\endcode 2095 2130 /// 2096 /// For a complete documentation, please see the \ref GraphReader 2131 /// For a complete documentation, please see the 2132 /// \ref lemon::GraphReader "GraphReader" 2097 2133 /// class documentation. 2098 /// \warning Don't forget to put the \ref GraphReader::run() "run()"2134 /// \warning Don't forget to put the \ref lemon::GraphReader::run() "run()" 2099 2135 /// to the end of the parameter list. 2100 2136 /// \relates GraphReader … … 2126 2162 GraphReader<TGR> graphReader(TGR& graph, const char* fn) { 2127 2163 GraphReader<TGR> tmp(graph, fn); 2164 return tmp; 2165 } 2166 2167 template <typename BGR> 2168 class BpGraphReader; 2169 2170 template <typename TBGR> 2171 BpGraphReader<TBGR> bpGraphReader(TBGR& graph, std::istream& is = std::cin); 2172 template <typename TBGR> 2173 BpGraphReader<TBGR> bpGraphReader(TBGR& graph, const std::string& fn); 2174 template <typename TBGR> 2175 BpGraphReader<TBGR> bpGraphReader(TBGR& graph, const char *fn); 2176 2177 /// \ingroup lemon_io 2178 /// 2179 /// \brief \ref lgf-format "LGF" reader for bipartite graphs 2180 /// 2181 /// This utility reads an \ref lgf-format "LGF" file. 2182 /// 2183 /// It can be used almost the same way as \c GraphReader, but it 2184 /// reads the red and blue nodes from separate sections, and these 2185 /// sections can contain different set of maps. 2186 /// 2187 /// The red and blue node maps are read from the corresponding 2188 /// sections. If a map is defined with the same name in both of 2189 /// these sections, then it can be read as a node map. 2190 template <typename BGR> 2191 class BpGraphReader { 2192 public: 2193 2194 typedef BGR Graph; 2195 2196 private: 2197 2198 TEMPLATE_BPGRAPH_TYPEDEFS(BGR); 2199 2200 std::istream* _is; 2201 bool local_is; 2202 std::string _filename; 2203 2204 BGR& _graph; 2205 2206 std::string _nodes_caption; 2207 std::string _edges_caption; 2208 std::string _attributes_caption; 2209 2210 typedef std::map<std::string, RedNode> RedNodeIndex; 2211 RedNodeIndex _red_node_index; 2212 typedef std::map<std::string, BlueNode> BlueNodeIndex; 2213 BlueNodeIndex _blue_node_index; 2214 typedef std::map<std::string, Edge> EdgeIndex; 2215 EdgeIndex _edge_index; 2216 2217 typedef std::vector<std::pair<std::string, 2218 _reader_bits::MapStorageBase<RedNode>*> > RedNodeMaps; 2219 RedNodeMaps _red_node_maps; 2220 typedef std::vector<std::pair<std::string, 2221 _reader_bits::MapStorageBase<BlueNode>*> > BlueNodeMaps; 2222 BlueNodeMaps _blue_node_maps; 2223 2224 typedef std::vector<std::pair<std::string, 2225 _reader_bits::MapStorageBase<Edge>*> > EdgeMaps; 2226 EdgeMaps _edge_maps; 2227 2228 typedef std::multimap<std::string, _reader_bits::ValueStorageBase*> 2229 Attributes; 2230 Attributes _attributes; 2231 2232 bool _use_nodes; 2233 bool _use_edges; 2234 2235 bool _skip_nodes; 2236 bool _skip_edges; 2237 2238 int line_num; 2239 std::istringstream line; 2240 2241 public: 2242 2243 /// \brief Constructor 2244 /// 2245 /// Construct an undirected graph reader, which reads from the given 2246 /// input stream. 2247 BpGraphReader(BGR& graph, std::istream& is = std::cin) 2248 : _is(&is), local_is(false), _graph(graph), 2249 _use_nodes(false), _use_edges(false), 2250 _skip_nodes(false), _skip_edges(false) {} 2251 2252 /// \brief Constructor 2253 /// 2254 /// Construct an undirected graph reader, which reads from the given 2255 /// file. 2256 BpGraphReader(BGR& graph, const std::string& fn) 2257 : _is(new std::ifstream(fn.c_str())), local_is(true), 2258 _filename(fn), _graph(graph), 2259 _use_nodes(false), _use_edges(false), 2260 _skip_nodes(false), _skip_edges(false) { 2261 if (!(*_is)) { 2262 delete _is; 2263 throw IoError("Cannot open file", fn); 2264 } 2265 } 2266 2267 /// \brief Constructor 2268 /// 2269 /// Construct an undirected graph reader, which reads from the given 2270 /// file. 2271 BpGraphReader(BGR& graph, const char* fn) 2272 : _is(new std::ifstream(fn)), local_is(true), 2273 _filename(fn), _graph(graph), 2274 _use_nodes(false), _use_edges(false), 2275 _skip_nodes(false), _skip_edges(false) { 2276 if (!(*_is)) { 2277 delete _is; 2278 throw IoError("Cannot open file", fn); 2279 } 2280 } 2281 2282 /// \brief Destructor 2283 ~BpGraphReader() { 2284 for (typename RedNodeMaps::iterator it = _red_node_maps.begin(); 2285 it != _red_node_maps.end(); ++it) { 2286 delete it->second; 2287 } 2288 2289 for (typename BlueNodeMaps::iterator it = _blue_node_maps.begin(); 2290 it != _blue_node_maps.end(); ++it) { 2291 delete it->second; 2292 } 2293 2294 for (typename EdgeMaps::iterator it = _edge_maps.begin(); 2295 it != _edge_maps.end(); ++it) { 2296 delete it->second; 2297 } 2298 2299 for (typename Attributes::iterator it = _attributes.begin(); 2300 it != _attributes.end(); ++it) { 2301 delete it->second; 2302 } 2303 2304 if (local_is) { 2305 delete _is; 2306 } 2307 2308 } 2309 2310 private: 2311 template <typename TBGR> 2312 friend BpGraphReader<TBGR> bpGraphReader(TBGR& graph, std::istream& is); 2313 template <typename TBGR> 2314 friend BpGraphReader<TBGR> bpGraphReader(TBGR& graph, 2315 const std::string& fn); 2316 template <typename TBGR> 2317 friend BpGraphReader<TBGR> bpGraphReader(TBGR& graph, const char *fn); 2318 2319 BpGraphReader(BpGraphReader& other) 2320 : _is(other._is), local_is(other.local_is), _graph(other._graph), 2321 _use_nodes(other._use_nodes), _use_edges(other._use_edges), 2322 _skip_nodes(other._skip_nodes), _skip_edges(other._skip_edges) { 2323 2324 other._is = 0; 2325 other.local_is = false; 2326 2327 _red_node_index.swap(other._red_node_index); 2328 _blue_node_index.swap(other._blue_node_index); 2329 _edge_index.swap(other._edge_index); 2330 2331 _red_node_maps.swap(other._red_node_maps); 2332 _blue_node_maps.swap(other._blue_node_maps); 2333 _edge_maps.swap(other._edge_maps); 2334 _attributes.swap(other._attributes); 2335 2336 _nodes_caption = other._nodes_caption; 2337 _edges_caption = other._edges_caption; 2338 _attributes_caption = other._attributes_caption; 2339 2340 } 2341 2342 BpGraphReader& operator=(const BpGraphReader&); 2343 2344 public: 2345 2346 /// \name Reading Rules 2347 /// @{ 2348 2349 /// \brief Node map reading rule 2350 /// 2351 /// Add a node map reading rule to the reader. 2352 template <typename Map> 2353 BpGraphReader& nodeMap(const std::string& caption, Map& map) { 2354 checkConcept<concepts::WriteMap<Node, typename Map::Value>, Map>(); 2355 _reader_bits::MapStorageBase<RedNode>* red_storage = 2356 new _reader_bits::MapStorage<RedNode, Map>(map); 2357 _red_node_maps.push_back(std::make_pair(caption, red_storage)); 2358 _reader_bits::MapStorageBase<BlueNode>* blue_storage = 2359 new _reader_bits::MapStorage<BlueNode, Map>(map); 2360 _blue_node_maps.push_back(std::make_pair(caption, blue_storage)); 2361 return *this; 2362 } 2363 2364 /// \brief Node map reading rule 2365 /// 2366 /// Add a node map reading rule with specialized converter to the 2367 /// reader. 2368 template <typename Map, typename Converter> 2369 BpGraphReader& nodeMap(const std::string& caption, Map& map, 2370 const Converter& converter = Converter()) { 2371 checkConcept<concepts::WriteMap<Node, typename Map::Value>, Map>(); 2372 _reader_bits::MapStorageBase<RedNode>* red_storage = 2373 new _reader_bits::MapStorage<RedNode, Map, Converter>(map, converter); 2374 _red_node_maps.push_back(std::make_pair(caption, red_storage)); 2375 _reader_bits::MapStorageBase<BlueNode>* blue_storage = 2376 new _reader_bits::MapStorage<BlueNode, Map, Converter>(map, converter); 2377 _blue_node_maps.push_back(std::make_pair(caption, blue_storage)); 2378 return *this; 2379 } 2380 2381 /// Add a red node map reading rule to the reader. 2382 template <typename Map> 2383 BpGraphReader& redNodeMap(const std::string& caption, Map& map) { 2384 checkConcept<concepts::WriteMap<RedNode, typename Map::Value>, Map>(); 2385 _reader_bits::MapStorageBase<RedNode>* storage = 2386 new _reader_bits::MapStorage<RedNode, Map>(map); 2387 _red_node_maps.push_back(std::make_pair(caption, storage)); 2388 return *this; 2389 } 2390 2391 /// \brief Red node map reading rule 2392 /// 2393 /// Add a red node map node reading rule with specialized converter to 2394 /// the reader. 2395 template <typename Map, typename Converter> 2396 BpGraphReader& redNodeMap(const std::string& caption, Map& map, 2397 const Converter& converter = Converter()) { 2398 checkConcept<concepts::WriteMap<RedNode, typename Map::Value>, Map>(); 2399 _reader_bits::MapStorageBase<RedNode>* storage = 2400 new _reader_bits::MapStorage<RedNode, Map, Converter>(map, converter); 2401 _red_node_maps.push_back(std::make_pair(caption, storage)); 2402 return *this; 2403 } 2404 2405 /// Add a blue node map reading rule to the reader. 2406 template <typename Map> 2407 BpGraphReader& blueNodeMap(const std::string& caption, Map& map) { 2408 checkConcept<concepts::WriteMap<BlueNode, typename Map::Value>, Map>(); 2409 _reader_bits::MapStorageBase<BlueNode>* storage = 2410 new _reader_bits::MapStorage<BlueNode, Map>(map); 2411 _blue_node_maps.push_back(std::make_pair(caption, storage)); 2412 return *this; 2413 } 2414 2415 /// \brief Blue node map reading rule 2416 /// 2417 /// Add a blue node map reading rule with specialized converter to 2418 /// the reader. 2419 template <typename Map, typename Converter> 2420 BpGraphReader& blueNodeMap(const std::string& caption, Map& map, 2421 const Converter& converter = Converter()) { 2422 checkConcept<concepts::WriteMap<BlueNode, typename Map::Value>, Map>(); 2423 _reader_bits::MapStorageBase<BlueNode>* storage = 2424 new _reader_bits::MapStorage<BlueNode, Map, Converter>(map, converter); 2425 _blue_node_maps.push_back(std::make_pair(caption, storage)); 2426 return *this; 2427 } 2428 2429 /// \brief Edge map reading rule 2430 /// 2431 /// Add an edge map reading rule to the reader. 2432 template <typename Map> 2433 BpGraphReader& edgeMap(const std::string& caption, Map& map) { 2434 checkConcept<concepts::WriteMap<Edge, typename Map::Value>, Map>(); 2435 _reader_bits::MapStorageBase<Edge>* storage = 2436 new _reader_bits::MapStorage<Edge, Map>(map); 2437 _edge_maps.push_back(std::make_pair(caption, storage)); 2438 return *this; 2439 } 2440 2441 /// \brief Edge map reading rule 2442 /// 2443 /// Add an edge map reading rule with specialized converter to the 2444 /// reader. 2445 template <typename Map, typename Converter> 2446 BpGraphReader& edgeMap(const std::string& caption, Map& map, 2447 const Converter& converter = Converter()) { 2448 checkConcept<concepts::WriteMap<Edge, typename Map::Value>, Map>(); 2449 _reader_bits::MapStorageBase<Edge>* storage = 2450 new _reader_bits::MapStorage<Edge, Map, Converter>(map, converter); 2451 _edge_maps.push_back(std::make_pair(caption, storage)); 2452 return *this; 2453 } 2454 2455 /// \brief Arc map reading rule 2456 /// 2457 /// Add an arc map reading rule to the reader. 2458 template <typename Map> 2459 BpGraphReader& arcMap(const std::string& caption, Map& map) { 2460 checkConcept<concepts::WriteMap<Arc, typename Map::Value>, Map>(); 2461 _reader_bits::MapStorageBase<Edge>* forward_storage = 2462 new _reader_bits::GraphArcMapStorage<Graph, true, Map>(_graph, map); 2463 _edge_maps.push_back(std::make_pair('+' + caption, forward_storage)); 2464 _reader_bits::MapStorageBase<Edge>* backward_storage = 2465 new _reader_bits::GraphArcMapStorage<BGR, false, Map>(_graph, map); 2466 _edge_maps.push_back(std::make_pair('-' + caption, backward_storage)); 2467 return *this; 2468 } 2469 2470 /// \brief Arc map reading rule 2471 /// 2472 /// Add an arc map reading rule with specialized converter to the 2473 /// reader. 2474 template <typename Map, typename Converter> 2475 BpGraphReader& arcMap(const std::string& caption, Map& map, 2476 const Converter& converter = Converter()) { 2477 checkConcept<concepts::WriteMap<Arc, typename Map::Value>, Map>(); 2478 _reader_bits::MapStorageBase<Edge>* forward_storage = 2479 new _reader_bits::GraphArcMapStorage<BGR, true, Map, Converter> 2480 (_graph, map, converter); 2481 _edge_maps.push_back(std::make_pair('+' + caption, forward_storage)); 2482 _reader_bits::MapStorageBase<Edge>* backward_storage = 2483 new _reader_bits::GraphArcMapStorage<BGR, false, Map, Converter> 2484 (_graph, map, converter); 2485 _edge_maps.push_back(std::make_pair('-' + caption, backward_storage)); 2486 return *this; 2487 } 2488 2489 /// \brief Attribute reading rule 2490 /// 2491 /// Add an attribute reading rule to the reader. 2492 template <typename Value> 2493 BpGraphReader& attribute(const std::string& caption, Value& value) { 2494 _reader_bits::ValueStorageBase* storage = 2495 new _reader_bits::ValueStorage<Value>(value); 2496 _attributes.insert(std::make_pair(caption, storage)); 2497 return *this; 2498 } 2499 2500 /// \brief Attribute reading rule 2501 /// 2502 /// Add an attribute reading rule with specialized converter to the 2503 /// reader. 2504 template <typename Value, typename Converter> 2505 BpGraphReader& attribute(const std::string& caption, Value& value, 2506 const Converter& converter = Converter()) { 2507 _reader_bits::ValueStorageBase* storage = 2508 new _reader_bits::ValueStorage<Value, Converter>(value, converter); 2509 _attributes.insert(std::make_pair(caption, storage)); 2510 return *this; 2511 } 2512 2513 /// \brief Node reading rule 2514 /// 2515 /// Add a node reading rule to reader. 2516 BpGraphReader& node(const std::string& caption, Node& node) { 2517 typedef _reader_bits::DoubleMapLookUpConverter< 2518 Node, RedNodeIndex, BlueNodeIndex> Converter; 2519 Converter converter(_red_node_index, _blue_node_index); 2520 _reader_bits::ValueStorageBase* storage = 2521 new _reader_bits::ValueStorage<Node, Converter>(node, converter); 2522 _attributes.insert(std::make_pair(caption, storage)); 2523 return *this; 2524 } 2525 2526 /// \brief Red node reading rule 2527 /// 2528 /// Add a red node reading rule to reader. 2529 BpGraphReader& redNode(const std::string& caption, RedNode& node) { 2530 typedef _reader_bits::MapLookUpConverter<RedNode> Converter; 2531 Converter converter(_red_node_index); 2532 _reader_bits::ValueStorageBase* storage = 2533 new _reader_bits::ValueStorage<RedNode, Converter>(node, converter); 2534 _attributes.insert(std::make_pair(caption, storage)); 2535 return *this; 2536 } 2537 2538 /// \brief Blue node reading rule 2539 /// 2540 /// Add a blue node reading rule to reader. 2541 BpGraphReader& blueNode(const std::string& caption, BlueNode& node) { 2542 typedef _reader_bits::MapLookUpConverter<BlueNode> Converter; 2543 Converter converter(_blue_node_index); 2544 _reader_bits::ValueStorageBase* storage = 2545 new _reader_bits::ValueStorage<BlueNode, Converter>(node, converter); 2546 _attributes.insert(std::make_pair(caption, storage)); 2547 return *this; 2548 } 2549 2550 /// \brief Edge reading rule 2551 /// 2552 /// Add an edge reading rule to reader. 2553 BpGraphReader& edge(const std::string& caption, Edge& edge) { 2554 typedef _reader_bits::MapLookUpConverter<Edge> Converter; 2555 Converter converter(_edge_index); 2556 _reader_bits::ValueStorageBase* storage = 2557 new _reader_bits::ValueStorage<Edge, Converter>(edge, converter); 2558 _attributes.insert(std::make_pair(caption, storage)); 2559 return *this; 2560 } 2561 2562 /// \brief Arc reading rule 2563 /// 2564 /// Add an arc reading rule to reader. 2565 BpGraphReader& arc(const std::string& caption, Arc& arc) { 2566 typedef _reader_bits::GraphArcLookUpConverter<BGR> Converter; 2567 Converter converter(_graph, _edge_index); 2568 _reader_bits::ValueStorageBase* storage = 2569 new _reader_bits::ValueStorage<Arc, Converter>(arc, converter); 2570 _attributes.insert(std::make_pair(caption, storage)); 2571 return *this; 2572 } 2573 2574 /// @} 2575 2576 /// \name Select Section by Name 2577 /// @{ 2578 2579 /// \brief Set \c \@nodes section to be read 2580 /// 2581 /// Set \c \@nodes section to be read. 2582 BpGraphReader& nodes(const std::string& caption) { 2583 _nodes_caption = caption; 2584 return *this; 2585 } 2586 2587 /// \brief Set \c \@edges section to be read 2588 /// 2589 /// Set \c \@edges section to be read. 2590 BpGraphReader& edges(const std::string& caption) { 2591 _edges_caption = caption; 2592 return *this; 2593 } 2594 2595 /// \brief Set \c \@attributes section to be read 2596 /// 2597 /// Set \c \@attributes section to be read. 2598 BpGraphReader& attributes(const std::string& caption) { 2599 _attributes_caption = caption; 2600 return *this; 2601 } 2602 2603 /// @} 2604 2605 /// \name Using Previously Constructed Node or Edge Set 2606 /// @{ 2607 2608 /// \brief Use previously constructed node set 2609 /// 2610 /// Use previously constructed node set, and specify the node 2611 /// label map. 2612 template <typename Map> 2613 BpGraphReader& useNodes(const Map& map) { 2614 checkConcept<concepts::ReadMap<Node, typename Map::Value>, Map>(); 2615 LEMON_ASSERT(!_use_nodes, "Multiple usage of useNodes() member"); 2616 _use_nodes = true; 2617 _writer_bits::DefaultConverter<typename Map::Value> converter; 2618 for (RedNodeIt n(_graph); n != INVALID; ++n) { 2619 _red_node_index.insert(std::make_pair(converter(map[n]), n)); 2620 } 2621 for (BlueNodeIt n(_graph); n != INVALID; ++n) { 2622 _blue_node_index.insert(std::make_pair(converter(map[n]), n)); 2623 } 2624 return *this; 2625 } 2626 2627 /// \brief Use previously constructed node set 2628 /// 2629 /// Use previously constructed node set, and specify the node 2630 /// label map and a functor which converts the label map values to 2631 /// \c std::string. 2632 template <typename Map, typename Converter> 2633 BpGraphReader& useNodes(const Map& map, 2634 const Converter& converter = Converter()) { 2635 checkConcept<concepts::ReadMap<Node, typename Map::Value>, Map>(); 2636 LEMON_ASSERT(!_use_nodes, "Multiple usage of useNodes() member"); 2637 _use_nodes = true; 2638 for (RedNodeIt n(_graph); n != INVALID; ++n) { 2639 _red_node_index.insert(std::make_pair(converter(map[n]), n)); 2640 } 2641 for (BlueNodeIt n(_graph); n != INVALID; ++n) { 2642 _blue_node_index.insert(std::make_pair(converter(map[n]), n)); 2643 } 2644 return *this; 2645 } 2646 2647 /// \brief Use previously constructed edge set 2648 /// 2649 /// Use previously constructed edge set, and specify the edge 2650 /// label map. 2651 template <typename Map> 2652 BpGraphReader& useEdges(const Map& map) { 2653 checkConcept<concepts::ReadMap<Edge, typename Map::Value>, Map>(); 2654 LEMON_ASSERT(!_use_edges, "Multiple usage of useEdges() member"); 2655 _use_edges = true; 2656 _writer_bits::DefaultConverter<typename Map::Value> converter; 2657 for (EdgeIt a(_graph); a != INVALID; ++a) { 2658 _edge_index.insert(std::make_pair(converter(map[a]), a)); 2659 } 2660 return *this; 2661 } 2662 2663 /// \brief Use previously constructed edge set 2664 /// 2665 /// Use previously constructed edge set, and specify the edge 2666 /// label map and a functor which converts the label map values to 2667 /// \c std::string. 2668 template <typename Map, typename Converter> 2669 BpGraphReader& useEdges(const Map& map, 2670 const Converter& converter = Converter()) { 2671 checkConcept<concepts::ReadMap<Edge, typename Map::Value>, Map>(); 2672 LEMON_ASSERT(!_use_edges, "Multiple usage of useEdges() member"); 2673 _use_edges = true; 2674 for (EdgeIt a(_graph); a != INVALID; ++a) { 2675 _edge_index.insert(std::make_pair(converter(map[a]), a)); 2676 } 2677 return *this; 2678 } 2679 2680 /// \brief Skip the reading of node section 2681 /// 2682 /// Omit the reading of the node section. This implies that each node 2683 /// map reading rule will be abandoned, and the nodes of the graph 2684 /// will not be constructed, which usually cause that the edge set 2685 /// could not be read due to lack of node name 2686 /// could not be read due to lack of node name resolving. 2687 /// Therefore \c skipEdges() function should also be used, or 2688 /// \c useNodes() should be used to specify the label of the nodes. 2689 BpGraphReader& skipNodes() { 2690 LEMON_ASSERT(!_skip_nodes, "Skip nodes already set"); 2691 _skip_nodes = true; 2692 return *this; 2693 } 2694 2695 /// \brief Skip the reading of edge section 2696 /// 2697 /// Omit the reading of the edge section. This implies that each edge 2698 /// map reading rule will be abandoned, and the edges of the graph 2699 /// will not be constructed. 2700 BpGraphReader& skipEdges() { 2701 LEMON_ASSERT(!_skip_edges, "Skip edges already set"); 2702 _skip_edges = true; 2703 return *this; 2704 } 2705 2706 /// @} 2707 2708 private: 2709 2710 bool readLine() { 2711 std::string str; 2712 while(++line_num, std::getline(*_is, str)) { 2713 line.clear(); line.str(str); 2714 char c; 2715 if (line >> std::ws >> c && c != '#') { 2716 line.putback(c); 2717 return true; 2718 } 2719 } 2720 return false; 2721 } 2722 2723 bool readSuccess() { 2724 return static_cast<bool>(*_is); 2725 } 2726 2727 void skipSection() { 2728 char c; 2729 while (readSuccess() && line >> c && c != '@') { 2730 readLine(); 2731 } 2732 if (readSuccess()) { 2733 line.putback(c); 2734 } 2735 } 2736 2737 void readRedNodes() { 2738 2739 std::vector<int> map_index(_red_node_maps.size()); 2740 int map_num, label_index; 2741 2742 char c; 2743 if (!readLine() || !(line >> c) || c == '@') { 2744 if (readSuccess() && line) line.putback(c); 2745 if (!_red_node_maps.empty()) 2746 throw FormatError("Cannot find map names"); 2747 return; 2748 } 2749 line.putback(c); 2750 2751 { 2752 std::map<std::string, int> maps; 2753 2754 std::string map; 2755 int index = 0; 2756 while (_reader_bits::readToken(line, map)) { 2757 if (maps.find(map) != maps.end()) { 2758 std::ostringstream msg; 2759 msg << "Multiple occurence of red node map: " << map; 2760 throw FormatError(msg.str()); 2761 } 2762 maps.insert(std::make_pair(map, index)); 2763 ++index; 2764 } 2765 2766 for (int i = 0; i < static_cast<int>(_red_node_maps.size()); ++i) { 2767 std::map<std::string, int>::iterator jt = 2768 maps.find(_red_node_maps[i].first); 2769 if (jt == maps.end()) { 2770 std::ostringstream msg; 2771 msg << "Map not found: " << _red_node_maps[i].first; 2772 throw FormatError(msg.str()); 2773 } 2774 map_index[i] = jt->second; 2775 } 2776 2777 { 2778 std::map<std::string, int>::iterator jt = maps.find("label"); 2779 if (jt != maps.end()) { 2780 label_index = jt->second; 2781 } else { 2782 label_index = -1; 2783 } 2784 } 2785 map_num = maps.size(); 2786 } 2787 2788 while (readLine() && line >> c && c != '@') { 2789 line.putback(c); 2790 2791 std::vector<std::string> tokens(map_num); 2792 for (int i = 0; i < map_num; ++i) { 2793 if (!_reader_bits::readToken(line, tokens[i])) { 2794 std::ostringstream msg; 2795 msg << "Column not found (" << i + 1 << ")"; 2796 throw FormatError(msg.str()); 2797 } 2798 } 2799 if (line >> std::ws >> c) 2800 throw FormatError("Extra character at the end of line"); 2801 2802 RedNode n; 2803 if (!_use_nodes) { 2804 n = _graph.addRedNode(); 2805 if (label_index != -1) 2806 _red_node_index.insert(std::make_pair(tokens[label_index], n)); 2807 } else { 2808 if (label_index == -1) 2809 throw FormatError("Label map not found"); 2810 typename std::map<std::string, RedNode>::iterator it = 2811 _red_node_index.find(tokens[label_index]); 2812 if (it == _red_node_index.end()) { 2813 std::ostringstream msg; 2814 msg << "Node with label not found: " << tokens[label_index]; 2815 throw FormatError(msg.str()); 2816 } 2817 n = it->second; 2818 } 2819 2820 for (int i = 0; i < static_cast<int>(_red_node_maps.size()); ++i) { 2821 _red_node_maps[i].second->set(n, tokens[map_index[i]]); 2822 } 2823 2824 } 2825 if (readSuccess()) { 2826 line.putback(c); 2827 } 2828 } 2829 2830 void readBlueNodes() { 2831 2832 std::vector<int> map_index(_blue_node_maps.size()); 2833 int map_num, label_index; 2834 2835 char c; 2836 if (!readLine() || !(line >> c) || c == '@') { 2837 if (readSuccess() && line) line.putback(c); 2838 if (!_blue_node_maps.empty()) 2839 throw FormatError("Cannot find map names"); 2840 return; 2841 } 2842 line.putback(c); 2843 2844 { 2845 std::map<std::string, int> maps; 2846 2847 std::string map; 2848 int index = 0; 2849 while (_reader_bits::readToken(line, map)) { 2850 if (maps.find(map) != maps.end()) { 2851 std::ostringstream msg; 2852 msg << "Multiple occurence of blue node map: " << map; 2853 throw FormatError(msg.str()); 2854 } 2855 maps.insert(std::make_pair(map, index)); 2856 ++index; 2857 } 2858 2859 for (int i = 0; i < static_cast<int>(_blue_node_maps.size()); ++i) { 2860 std::map<std::string, int>::iterator jt = 2861 maps.find(_blue_node_maps[i].first); 2862 if (jt == maps.end()) { 2863 std::ostringstream msg; 2864 msg << "Map not found: " << _blue_node_maps[i].first; 2865 throw FormatError(msg.str()); 2866 } 2867 map_index[i] = jt->second; 2868 } 2869 2870 { 2871 std::map<std::string, int>::iterator jt = maps.find("label"); 2872 if (jt != maps.end()) { 2873 label_index = jt->second; 2874 } else { 2875 label_index = -1; 2876 } 2877 } 2878 map_num = maps.size(); 2879 } 2880 2881 while (readLine() && line >> c && c != '@') { 2882 line.putback(c); 2883 2884 std::vector<std::string> tokens(map_num); 2885 for (int i = 0; i < map_num; ++i) { 2886 if (!_reader_bits::readToken(line, tokens[i])) { 2887 std::ostringstream msg; 2888 msg << "Column not found (" << i + 1 << ")"; 2889 throw FormatError(msg.str()); 2890 } 2891 } 2892 if (line >> std::ws >> c) 2893 throw FormatError("Extra character at the end of line"); 2894 2895 BlueNode n; 2896 if (!_use_nodes) { 2897 n = _graph.addBlueNode(); 2898 if (label_index != -1) 2899 _blue_node_index.insert(std::make_pair(tokens[label_index], n)); 2900 } else { 2901 if (label_index == -1) 2902 throw FormatError("Label map not found"); 2903 typename std::map<std::string, BlueNode>::iterator it = 2904 _blue_node_index.find(tokens[label_index]); 2905 if (it == _blue_node_index.end()) { 2906 std::ostringstream msg; 2907 msg << "Node with label not found: " << tokens[label_index]; 2908 throw FormatError(msg.str()); 2909 } 2910 n = it->second; 2911 } 2912 2913 for (int i = 0; i < static_cast<int>(_blue_node_maps.size()); ++i) { 2914 _blue_node_maps[i].second->set(n, tokens[map_index[i]]); 2915 } 2916 2917 } 2918 if (readSuccess()) { 2919 line.putback(c); 2920 } 2921 } 2922 2923 void readEdges() { 2924 2925 std::vector<int> map_index(_edge_maps.size()); 2926 int map_num, label_index; 2927 2928 char c; 2929 if (!readLine() || !(line >> c) || c == '@') { 2930 if (readSuccess() && line) line.putback(c); 2931 if (!_edge_maps.empty()) 2932 throw FormatError("Cannot find map names"); 2933 return; 2934 } 2935 line.putback(c); 2936 2937 { 2938 std::map<std::string, int> maps; 2939 2940 std::string map; 2941 int index = 0; 2942 while (_reader_bits::readToken(line, map)) { 2943 if (maps.find(map) != maps.end()) { 2944 std::ostringstream msg; 2945 msg << "Multiple occurence of edge map: " << map; 2946 throw FormatError(msg.str()); 2947 } 2948 maps.insert(std::make_pair(map, index)); 2949 ++index; 2950 } 2951 2952 for (int i = 0; i < static_cast<int>(_edge_maps.size()); ++i) { 2953 std::map<std::string, int>::iterator jt = 2954 maps.find(_edge_maps[i].first); 2955 if (jt == maps.end()) { 2956 std::ostringstream msg; 2957 msg << "Map not found: " << _edge_maps[i].first; 2958 throw FormatError(msg.str()); 2959 } 2960 map_index[i] = jt->second; 2961 } 2962 2963 { 2964 std::map<std::string, int>::iterator jt = maps.find("label"); 2965 if (jt != maps.end()) { 2966 label_index = jt->second; 2967 } else { 2968 label_index = -1; 2969 } 2970 } 2971 map_num = maps.size(); 2972 } 2973 2974 while (readLine() && line >> c && c != '@') { 2975 line.putback(c); 2976 2977 std::string source_token; 2978 std::string target_token; 2979 2980 if (!_reader_bits::readToken(line, source_token)) 2981 throw FormatError("Red node not found"); 2982 2983 if (!_reader_bits::readToken(line, target_token)) 2984 throw FormatError("Blue node not found"); 2985 2986 std::vector<std::string> tokens(map_num); 2987 for (int i = 0; i < map_num; ++i) { 2988 if (!_reader_bits::readToken(line, tokens[i])) { 2989 std::ostringstream msg; 2990 msg << "Column not found (" << i + 1 << ")"; 2991 throw FormatError(msg.str()); 2992 } 2993 } 2994 if (line >> std::ws >> c) 2995 throw FormatError("Extra character at the end of line"); 2996 2997 Edge e; 2998 if (!_use_edges) { 2999 typename RedNodeIndex::iterator rit = 3000 _red_node_index.find(source_token); 3001 if (rit == _red_node_index.end()) { 3002 std::ostringstream msg; 3003 msg << "Item not found: " << source_token; 3004 throw FormatError(msg.str()); 3005 } 3006 RedNode source = rit->second; 3007 typename BlueNodeIndex::iterator it = 3008 _blue_node_index.find(target_token); 3009 if (it == _blue_node_index.end()) { 3010 std::ostringstream msg; 3011 msg << "Item not found: " << target_token; 3012 throw FormatError(msg.str()); 3013 } 3014 BlueNode target = it->second; 3015 3016 // It is checked that source is red and 3017 // target is blue, so this should be safe: 3018 e = _graph.addEdge(source, target); 3019 if (label_index != -1) 3020 _edge_index.insert(std::make_pair(tokens[label_index], e)); 3021 } else { 3022 if (label_index == -1) 3023 throw FormatError("Label map not found"); 3024 typename std::map<std::string, Edge>::iterator it = 3025 _edge_index.find(tokens[label_index]); 3026 if (it == _edge_index.end()) { 3027 std::ostringstream msg; 3028 msg << "Edge with label not found: " << tokens[label_index]; 3029 throw FormatError(msg.str()); 3030 } 3031 e = it->second; 3032 } 3033 3034 for (int i = 0; i < static_cast<int>(_edge_maps.size()); ++i) { 3035 _edge_maps[i].second->set(e, tokens[map_index[i]]); 3036 } 3037 3038 } 3039 if (readSuccess()) { 3040 line.putback(c); 3041 } 3042 } 3043 3044 void readAttributes() { 3045 3046 std::set<std::string> read_attr; 3047 3048 char c; 3049 while (readLine() && line >> c && c != '@') { 3050 line.putback(c); 3051 3052 std::string attr, token; 3053 if (!_reader_bits::readToken(line, attr)) 3054 throw FormatError("Attribute name not found"); 3055 if (!_reader_bits::readToken(line, token)) 3056 throw FormatError("Attribute value not found"); 3057 if (line >> c) 3058 throw FormatError("Extra character at the end of line"); 3059 3060 { 3061 std::set<std::string>::iterator it = read_attr.find(attr); 3062 if (it != read_attr.end()) { 3063 std::ostringstream msg; 3064 msg << "Multiple occurence of attribute: " << attr; 3065 throw FormatError(msg.str()); 3066 } 3067 read_attr.insert(attr); 3068 } 3069 3070 { 3071 typename Attributes::iterator it = _attributes.lower_bound(attr); 3072 while (it != _attributes.end() && it->first == attr) { 3073 it->second->set(token); 3074 ++it; 3075 } 3076 } 3077 3078 } 3079 if (readSuccess()) { 3080 line.putback(c); 3081 } 3082 for (typename Attributes::iterator it = _attributes.begin(); 3083 it != _attributes.end(); ++it) { 3084 if (read_attr.find(it->first) == read_attr.end()) { 3085 std::ostringstream msg; 3086 msg << "Attribute not found: " << it->first; 3087 throw FormatError(msg.str()); 3088 } 3089 } 3090 } 3091 3092 public: 3093 3094 /// \name Execution of the Reader 3095 /// @{ 3096 3097 /// \brief Start the batch processing 3098 /// 3099 /// This function starts the batch processing 3100 void run() { 3101 3102 LEMON_ASSERT(_is != 0, "This reader assigned to an other reader"); 3103 3104 bool red_nodes_done = _skip_nodes; 3105 bool blue_nodes_done = _skip_nodes; 3106 bool edges_done = _skip_edges; 3107 bool attributes_done = false; 3108 3109 line_num = 0; 3110 readLine(); 3111 skipSection(); 3112 3113 while (readSuccess()) { 3114 try { 3115 char c; 3116 std::string section, caption; 3117 line >> c; 3118 _reader_bits::readToken(line, section); 3119 _reader_bits::readToken(line, caption); 3120 3121 if (line >> c) 3122 throw FormatError("Extra character at the end of line"); 3123 3124 if (section == "red_nodes" && !red_nodes_done) { 3125 if (_nodes_caption.empty() || _nodes_caption == caption) { 3126 readRedNodes(); 3127 red_nodes_done = true; 3128 } 3129 } else if (section == "blue_nodes" && !blue_nodes_done) { 3130 if (_nodes_caption.empty() || _nodes_caption == caption) { 3131 readBlueNodes(); 3132 blue_nodes_done = true; 3133 } 3134 } else if ((section == "edges" || section == "arcs") && 3135 !edges_done) { 3136 if (_edges_caption.empty() || _edges_caption == caption) { 3137 readEdges(); 3138 edges_done = true; 3139 } 3140 } else if (section == "attributes" && !attributes_done) { 3141 if (_attributes_caption.empty() || _attributes_caption == caption) { 3142 readAttributes(); 3143 attributes_done = true; 3144 } 3145 } else { 3146 readLine(); 3147 skipSection(); 3148 } 3149 } catch (FormatError& error) { 3150 error.line(line_num); 3151 error.file(_filename); 3152 throw; 3153 } 3154 } 3155 3156 if (!red_nodes_done) { 3157 throw FormatError("Section @red_nodes not found"); 3158 } 3159 3160 if (!blue_nodes_done) { 3161 throw FormatError("Section @blue_nodes not found"); 3162 } 3163 3164 if (!edges_done) { 3165 throw FormatError("Section @edges not found"); 3166 } 3167 3168 if (!attributes_done && !_attributes.empty()) { 3169 throw FormatError("Section @attributes not found"); 3170 } 3171 3172 } 3173 3174 /// @} 3175 3176 }; 3177 3178 /// \ingroup lemon_io 3179 /// 3180 /// \brief Return a \ref lemon::BpGraphReader "BpGraphReader" class 3181 /// 3182 /// This function just returns a \ref lemon::BpGraphReader 3183 /// "BpGraphReader" class. 3184 /// 3185 /// With this function a graph can be read from an 3186 /// \ref lgf-format "LGF" file or input stream with several maps and 3187 /// attributes. For example, there is bipartite weighted matching problem 3188 /// on a graph, i.e. a graph with a \e weight map on the edges. This 3189 /// graph can be read with the following code: 3190 /// 3191 ///\code 3192 ///ListBpGraph graph; 3193 ///ListBpGraph::EdgeMap<int> weight(graph); 3194 ///bpGraphReader(graph, std::cin). 3195 /// edgeMap("weight", weight). 3196 /// run(); 3197 ///\endcode 3198 /// 3199 /// For a complete documentation, please see the 3200 /// \ref lemon::BpGraphReader "BpGraphReader" 3201 /// class documentation. 3202 /// \warning Don't forget to put the \ref lemon::BpGraphReader::run() "run()" 3203 /// to the end of the parameter list. 3204 /// \relates BpGraphReader 3205 /// \sa bpGraphReader(TBGR& graph, const std::string& fn) 3206 /// \sa bpGraphReader(TBGR& graph, const char* fn) 3207 template <typename TBGR> 3208 BpGraphReader<TBGR> bpGraphReader(TBGR& graph, std::istream& is) { 3209 BpGraphReader<TBGR> tmp(graph, is); 3210 return tmp; 3211 } 3212 3213 /// \brief Return a \ref BpGraphReader class 3214 /// 3215 /// This function just returns a \ref BpGraphReader class. 3216 /// \relates BpGraphReader 3217 /// \sa bpGraphReader(TBGR& graph, std::istream& is) 3218 template <typename TBGR> 3219 BpGraphReader<TBGR> bpGraphReader(TBGR& graph, const std::string& fn) { 3220 BpGraphReader<TBGR> tmp(graph, fn); 3221 return tmp; 3222 } 3223 3224 /// \brief Return a \ref BpGraphReader class 3225 /// 3226 /// This function just returns a \ref BpGraphReader class. 3227 /// \relates BpGraphReader 3228 /// \sa bpGraphReader(TBGR& graph, std::istream& is) 3229 template <typename TBGR> 3230 BpGraphReader<TBGR> bpGraphReader(TBGR& graph, const char* fn) { 3231 BpGraphReader<TBGR> tmp(graph, fn); 2128 3232 return tmp; 2129 3233 } -
lemon/lgf_writer.h
r956 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 192 192 }; 193 193 194 template <typename Value> 194 template <typename Value, 195 typename Map = std::map<Value, std::string> > 195 196 struct MapLookUpConverter { 196 const std::map<Value, std::string>& _map;197 198 MapLookUpConverter(const std::map<Value, std::string>& map)197 const Map& _map; 198 199 MapLookUpConverter(const Map& map) 199 200 : _map(map) {} 200 201 201 std::string operator()(const Value& str) { 202 typename std::map<Value, std::string>::const_iterator it = 203 _map.find(str); 202 std::string operator()(const Value& value) { 203 typename Map::const_iterator it = _map.find(value); 204 204 if (it == _map.end()) { 205 205 throw FormatError("Item not found"); 206 206 } 207 207 return it->second; 208 } 209 }; 210 211 template <typename Value, 212 typename Map1 = std::map<Value, std::string>, 213 typename Map2 = std::map<Value, std::string> > 214 struct DoubleMapLookUpConverter { 215 const Map1& _map1; 216 const Map2& _map2; 217 218 DoubleMapLookUpConverter(const Map1& map1, const Map2& map2) 219 : _map1(map1), _map2(map2) {} 220 221 std::string operator()(const Value& value) { 222 typename Map1::const_iterator it1 = _map1.find(value); 223 typename Map1::const_iterator it2 = _map2.find(value); 224 if (it1 == _map1.end()) { 225 if (it2 == _map2.end()) { 226 throw FormatError("Item not found"); 227 } else { 228 return it2->second; 229 } 230 } else { 231 if (it2 == _map2.end()) { 232 return it1->second; 233 } else { 234 throw FormatError("Item is ambigous"); 235 } 236 } 208 237 } 209 238 }; … … 916 945 /// \ingroup lemon_io 917 946 /// 918 /// \brief Return a \ref DigraphWriter class 919 /// 920 /// This function just returns a \ref DigraphWriter class. 947 /// \brief Return a \ref lemon::DigraphWriter "DigraphWriter" class 948 /// 949 /// This function just returns a \ref lemon::DigraphWriter 950 /// "DigraphWriter" class. 921 951 /// 922 952 /// With this function a digraph can be write to a file or output … … 939 969 ///\endcode 940 970 /// 941 /// For a complete documentation, please see the \ref DigraphWriter 971 /// For a complete documentation, please see the 972 /// \ref lemon::DigraphWriter "DigraphWriter" 942 973 /// class documentation. 943 /// \warning Don't forget to put the \ref DigraphWriter::run() "run()"974 /// \warning Don't forget to put the \ref lemon::DigraphWriter::run() "run()" 944 975 /// to the end of the parameter list. 945 976 /// \relates DigraphWriter … … 987 1018 /// \ingroup lemon_io 988 1019 /// 989 /// \brief \ref lgf-format "LGF" writer for directed graphs1020 /// \brief \ref lgf-format "LGF" writer for undirected graphs 990 1021 /// 991 1022 /// This utility writes an \ref lgf-format "LGF" file. … … 1043 1074 /// \brief Constructor 1044 1075 /// 1045 /// Construct a directed graph writer, which writes to the given1046 /// output stream.1076 /// Construct an undirected graph writer, which writes to the 1077 /// given output stream. 1047 1078 GraphWriter(const GR& graph, std::ostream& os = std::cout) 1048 1079 : _os(&os), local_os(false), _graph(graph), … … 1051 1082 /// \brief Constructor 1052 1083 /// 1053 /// Construct a directed graph writer, which writes to the given1084 /// Construct a undirected graph writer, which writes to the given 1054 1085 /// output file. 1055 1086 GraphWriter(const GR& graph, const std::string& fn) … … 1064 1095 /// \brief Constructor 1065 1096 /// 1066 /// Construct a directed graph writer, which writes to the given1097 /// Construct a undirected graph writer, which writes to the given 1067 1098 /// output file. 1068 1099 GraphWriter(const GR& graph, const char* fn) … … 1290 1321 } 1291 1322 1292 /// \brief Add an additional caption to the \c \@ arcs section1293 /// 1294 /// Add an additional caption to the \c \@ arcs section.1323 /// \brief Add an additional caption to the \c \@edges section 1324 /// 1325 /// Add an additional caption to the \c \@edges section. 1295 1326 GraphWriter& edges(const std::string& caption) { 1296 1327 _edges_caption = caption; … … 1555 1586 /// \ingroup lemon_io 1556 1587 /// 1557 /// \brief Return a \ref GraphWriterclass1558 /// 1559 /// This function just returns a \ref GraphWriterclass.1588 /// \brief Return a \ref lemon::GraphWriter "GraphWriter" class 1589 /// 1590 /// This function just returns a \ref lemon::GraphWriter "GraphWriter" class. 1560 1591 /// 1561 1592 /// With this function a graph can be write to a file or output … … 1574 1605 ///\endcode 1575 1606 /// 1576 /// For a complete documentation, please see the \ref GraphWriter 1607 /// For a complete documentation, please see the 1608 /// \ref lemon::GraphWriter "GraphWriter" 1577 1609 /// class documentation. 1578 /// \warning Don't forget to put the \ref GraphWriter::run() "run()"1610 /// \warning Don't forget to put the \ref lemon::GraphWriter::run() "run()" 1579 1611 /// to the end of the parameter list. 1580 1612 /// \relates GraphWriter … … 1606 1638 GraphWriter<TGR> graphWriter(const TGR& graph, const char* fn) { 1607 1639 GraphWriter<TGR> tmp(graph, fn); 1640 return tmp; 1641 } 1642 1643 template <typename BGR> 1644 class BpGraphWriter; 1645 1646 template <typename TBGR> 1647 BpGraphWriter<TBGR> bpGraphWriter(const TBGR& graph, 1648 std::ostream& os = std::cout); 1649 template <typename TBGR> 1650 BpGraphWriter<TBGR> bpGraphWriter(const TBGR& graph, const std::string& fn); 1651 template <typename TBGR> 1652 BpGraphWriter<TBGR> bpGraphWriter(const TBGR& graph, const char* fn); 1653 1654 /// \ingroup lemon_io 1655 /// 1656 /// \brief \ref lgf-format "LGF" writer for undirected bipartite graphs 1657 /// 1658 /// This utility writes an \ref lgf-format "LGF" file. 1659 /// 1660 /// It can be used almost the same way as \c GraphWriter, but it 1661 /// reads the red and blue nodes from separate sections, and these 1662 /// sections can contain different set of maps. 1663 /// 1664 /// The red and blue node maps are written to the corresponding 1665 /// sections. The node maps are written to both of these sections 1666 /// with the same map name. 1667 template <typename BGR> 1668 class BpGraphWriter { 1669 public: 1670 1671 typedef BGR BpGraph; 1672 TEMPLATE_BPGRAPH_TYPEDEFS(BGR); 1673 1674 private: 1675 1676 1677 std::ostream* _os; 1678 bool local_os; 1679 1680 const BGR& _graph; 1681 1682 std::string _nodes_caption; 1683 std::string _edges_caption; 1684 std::string _attributes_caption; 1685 1686 typedef std::map<Node, std::string> RedNodeIndex; 1687 RedNodeIndex _red_node_index; 1688 typedef std::map<Node, std::string> BlueNodeIndex; 1689 BlueNodeIndex _blue_node_index; 1690 typedef std::map<Edge, std::string> EdgeIndex; 1691 EdgeIndex _edge_index; 1692 1693 typedef std::vector<std::pair<std::string, 1694 _writer_bits::MapStorageBase<RedNode>* > > RedNodeMaps; 1695 RedNodeMaps _red_node_maps; 1696 typedef std::vector<std::pair<std::string, 1697 _writer_bits::MapStorageBase<BlueNode>* > > BlueNodeMaps; 1698 BlueNodeMaps _blue_node_maps; 1699 1700 typedef std::vector<std::pair<std::string, 1701 _writer_bits::MapStorageBase<Edge>* > >EdgeMaps; 1702 EdgeMaps _edge_maps; 1703 1704 typedef std::vector<std::pair<std::string, 1705 _writer_bits::ValueStorageBase*> > Attributes; 1706 Attributes _attributes; 1707 1708 bool _skip_nodes; 1709 bool _skip_edges; 1710 1711 public: 1712 1713 /// \brief Constructor 1714 /// 1715 /// Construct a bipartite graph writer, which writes to the given 1716 /// output stream. 1717 BpGraphWriter(const BGR& graph, std::ostream& os = std::cout) 1718 : _os(&os), local_os(false), _graph(graph), 1719 _skip_nodes(false), _skip_edges(false) {} 1720 1721 /// \brief Constructor 1722 /// 1723 /// Construct a bipartite graph writer, which writes to the given 1724 /// output file. 1725 BpGraphWriter(const BGR& graph, const std::string& fn) 1726 : _os(new std::ofstream(fn.c_str())), local_os(true), _graph(graph), 1727 _skip_nodes(false), _skip_edges(false) { 1728 if (!(*_os)) { 1729 delete _os; 1730 throw IoError("Cannot write file", fn); 1731 } 1732 } 1733 1734 /// \brief Constructor 1735 /// 1736 /// Construct a bipartite graph writer, which writes to the given 1737 /// output file. 1738 BpGraphWriter(const BGR& graph, const char* fn) 1739 : _os(new std::ofstream(fn)), local_os(true), _graph(graph), 1740 _skip_nodes(false), _skip_edges(false) { 1741 if (!(*_os)) { 1742 delete _os; 1743 throw IoError("Cannot write file", fn); 1744 } 1745 } 1746 1747 /// \brief Destructor 1748 ~BpGraphWriter() { 1749 for (typename RedNodeMaps::iterator it = _red_node_maps.begin(); 1750 it != _red_node_maps.end(); ++it) { 1751 delete it->second; 1752 } 1753 1754 for (typename BlueNodeMaps::iterator it = _blue_node_maps.begin(); 1755 it != _blue_node_maps.end(); ++it) { 1756 delete it->second; 1757 } 1758 1759 for (typename EdgeMaps::iterator it = _edge_maps.begin(); 1760 it != _edge_maps.end(); ++it) { 1761 delete it->second; 1762 } 1763 1764 for (typename Attributes::iterator it = _attributes.begin(); 1765 it != _attributes.end(); ++it) { 1766 delete it->second; 1767 } 1768 1769 if (local_os) { 1770 delete _os; 1771 } 1772 } 1773 1774 private: 1775 1776 template <typename TBGR> 1777 friend BpGraphWriter<TBGR> bpGraphWriter(const TBGR& graph, 1778 std::ostream& os); 1779 template <typename TBGR> 1780 friend BpGraphWriter<TBGR> bpGraphWriter(const TBGR& graph, 1781 const std::string& fn); 1782 template <typename TBGR> 1783 friend BpGraphWriter<TBGR> bpGraphWriter(const TBGR& graph, const char *fn); 1784 1785 BpGraphWriter(BpGraphWriter& other) 1786 : _os(other._os), local_os(other.local_os), _graph(other._graph), 1787 _skip_nodes(other._skip_nodes), _skip_edges(other._skip_edges) { 1788 1789 other._os = 0; 1790 other.local_os = false; 1791 1792 _red_node_index.swap(other._red_node_index); 1793 _blue_node_index.swap(other._blue_node_index); 1794 _edge_index.swap(other._edge_index); 1795 1796 _red_node_maps.swap(other._red_node_maps); 1797 _blue_node_maps.swap(other._blue_node_maps); 1798 _edge_maps.swap(other._edge_maps); 1799 _attributes.swap(other._attributes); 1800 1801 _nodes_caption = other._nodes_caption; 1802 _edges_caption = other._edges_caption; 1803 _attributes_caption = other._attributes_caption; 1804 } 1805 1806 BpGraphWriter& operator=(const BpGraphWriter&); 1807 1808 public: 1809 1810 /// \name Writing Rules 1811 /// @{ 1812 1813 /// \brief Node map writing rule 1814 /// 1815 /// Add a node map writing rule to the writer. 1816 template <typename Map> 1817 BpGraphWriter& nodeMap(const std::string& caption, const Map& map) { 1818 checkConcept<concepts::ReadMap<Node, typename Map::Value>, Map>(); 1819 _writer_bits::MapStorageBase<RedNode>* red_storage = 1820 new _writer_bits::MapStorage<RedNode, Map>(map); 1821 _red_node_maps.push_back(std::make_pair(caption, red_storage)); 1822 _writer_bits::MapStorageBase<BlueNode>* blue_storage = 1823 new _writer_bits::MapStorage<BlueNode, Map>(map); 1824 _blue_node_maps.push_back(std::make_pair(caption, blue_storage)); 1825 return *this; 1826 } 1827 1828 /// \brief Node map writing rule 1829 /// 1830 /// Add a node map writing rule with specialized converter to the 1831 /// writer. 1832 template <typename Map, typename Converter> 1833 BpGraphWriter& nodeMap(const std::string& caption, const Map& map, 1834 const Converter& converter = Converter()) { 1835 checkConcept<concepts::ReadMap<Node, typename Map::Value>, Map>(); 1836 _writer_bits::MapStorageBase<RedNode>* red_storage = 1837 new _writer_bits::MapStorage<RedNode, Map, Converter>(map, converter); 1838 _red_node_maps.push_back(std::make_pair(caption, red_storage)); 1839 _writer_bits::MapStorageBase<BlueNode>* blue_storage = 1840 new _writer_bits::MapStorage<BlueNode, Map, Converter>(map, converter); 1841 _blue_node_maps.push_back(std::make_pair(caption, blue_storage)); 1842 return *this; 1843 } 1844 1845 /// \brief Red node map writing rule 1846 /// 1847 /// Add a red node map writing rule to the writer. 1848 template <typename Map> 1849 BpGraphWriter& redNodeMap(const std::string& caption, const Map& map) { 1850 checkConcept<concepts::ReadMap<RedNode, typename Map::Value>, Map>(); 1851 _writer_bits::MapStorageBase<RedNode>* storage = 1852 new _writer_bits::MapStorage<RedNode, Map>(map); 1853 _red_node_maps.push_back(std::make_pair(caption, storage)); 1854 return *this; 1855 } 1856 1857 /// \brief Red node map writing rule 1858 /// 1859 /// Add a red node map writing rule with specialized converter to the 1860 /// writer. 1861 template <typename Map, typename Converter> 1862 BpGraphWriter& redNodeMap(const std::string& caption, const Map& map, 1863 const Converter& converter = Converter()) { 1864 checkConcept<concepts::ReadMap<RedNode, typename Map::Value>, Map>(); 1865 _writer_bits::MapStorageBase<RedNode>* storage = 1866 new _writer_bits::MapStorage<RedNode, Map, Converter>(map, converter); 1867 _red_node_maps.push_back(std::make_pair(caption, storage)); 1868 return *this; 1869 } 1870 1871 /// \brief Blue node map writing rule 1872 /// 1873 /// Add a blue node map writing rule to the writer. 1874 template <typename Map> 1875 BpGraphWriter& blueNodeMap(const std::string& caption, const Map& map) { 1876 checkConcept<concepts::ReadMap<BlueNode, typename Map::Value>, Map>(); 1877 _writer_bits::MapStorageBase<BlueNode>* storage = 1878 new _writer_bits::MapStorage<BlueNode, Map>(map); 1879 _blue_node_maps.push_back(std::make_pair(caption, storage)); 1880 return *this; 1881 } 1882 1883 /// \brief Blue node map writing rule 1884 /// 1885 /// Add a blue node map writing rule with specialized converter to the 1886 /// writer. 1887 template <typename Map, typename Converter> 1888 BpGraphWriter& blueNodeMap(const std::string& caption, const Map& map, 1889 const Converter& converter = Converter()) { 1890 checkConcept<concepts::ReadMap<BlueNode, typename Map::Value>, Map>(); 1891 _writer_bits::MapStorageBase<BlueNode>* storage = 1892 new _writer_bits::MapStorage<BlueNode, Map, Converter>(map, converter); 1893 _blue_node_maps.push_back(std::make_pair(caption, storage)); 1894 return *this; 1895 } 1896 1897 /// \brief Edge map writing rule 1898 /// 1899 /// Add an edge map writing rule to the writer. 1900 template <typename Map> 1901 BpGraphWriter& edgeMap(const std::string& caption, const Map& map) { 1902 checkConcept<concepts::ReadMap<Edge, typename Map::Value>, Map>(); 1903 _writer_bits::MapStorageBase<Edge>* storage = 1904 new _writer_bits::MapStorage<Edge, Map>(map); 1905 _edge_maps.push_back(std::make_pair(caption, storage)); 1906 return *this; 1907 } 1908 1909 /// \brief Edge map writing rule 1910 /// 1911 /// Add an edge map writing rule with specialized converter to the 1912 /// writer. 1913 template <typename Map, typename Converter> 1914 BpGraphWriter& edgeMap(const std::string& caption, const Map& map, 1915 const Converter& converter = Converter()) { 1916 checkConcept<concepts::ReadMap<Edge, typename Map::Value>, Map>(); 1917 _writer_bits::MapStorageBase<Edge>* storage = 1918 new _writer_bits::MapStorage<Edge, Map, Converter>(map, converter); 1919 _edge_maps.push_back(std::make_pair(caption, storage)); 1920 return *this; 1921 } 1922 1923 /// \brief Arc map writing rule 1924 /// 1925 /// Add an arc map writing rule to the writer. 1926 template <typename Map> 1927 BpGraphWriter& arcMap(const std::string& caption, const Map& map) { 1928 checkConcept<concepts::ReadMap<Arc, typename Map::Value>, Map>(); 1929 _writer_bits::MapStorageBase<Edge>* forward_storage = 1930 new _writer_bits::GraphArcMapStorage<BGR, true, Map>(_graph, map); 1931 _edge_maps.push_back(std::make_pair('+' + caption, forward_storage)); 1932 _writer_bits::MapStorageBase<Edge>* backward_storage = 1933 new _writer_bits::GraphArcMapStorage<BGR, false, Map>(_graph, map); 1934 _edge_maps.push_back(std::make_pair('-' + caption, backward_storage)); 1935 return *this; 1936 } 1937 1938 /// \brief Arc map writing rule 1939 /// 1940 /// Add an arc map writing rule with specialized converter to the 1941 /// writer. 1942 template <typename Map, typename Converter> 1943 BpGraphWriter& arcMap(const std::string& caption, const Map& map, 1944 const Converter& converter = Converter()) { 1945 checkConcept<concepts::ReadMap<Arc, typename Map::Value>, Map>(); 1946 _writer_bits::MapStorageBase<Edge>* forward_storage = 1947 new _writer_bits::GraphArcMapStorage<BGR, true, Map, Converter> 1948 (_graph, map, converter); 1949 _edge_maps.push_back(std::make_pair('+' + caption, forward_storage)); 1950 _writer_bits::MapStorageBase<Edge>* backward_storage = 1951 new _writer_bits::GraphArcMapStorage<BGR, false, Map, Converter> 1952 (_graph, map, converter); 1953 _edge_maps.push_back(std::make_pair('-' + caption, backward_storage)); 1954 return *this; 1955 } 1956 1957 /// \brief Attribute writing rule 1958 /// 1959 /// Add an attribute writing rule to the writer. 1960 template <typename Value> 1961 BpGraphWriter& attribute(const std::string& caption, const Value& value) { 1962 _writer_bits::ValueStorageBase* storage = 1963 new _writer_bits::ValueStorage<Value>(value); 1964 _attributes.push_back(std::make_pair(caption, storage)); 1965 return *this; 1966 } 1967 1968 /// \brief Attribute writing rule 1969 /// 1970 /// Add an attribute writing rule with specialized converter to the 1971 /// writer. 1972 template <typename Value, typename Converter> 1973 BpGraphWriter& attribute(const std::string& caption, const Value& value, 1974 const Converter& converter = Converter()) { 1975 _writer_bits::ValueStorageBase* storage = 1976 new _writer_bits::ValueStorage<Value, Converter>(value, converter); 1977 _attributes.push_back(std::make_pair(caption, storage)); 1978 return *this; 1979 } 1980 1981 /// \brief Node writing rule 1982 /// 1983 /// Add a node writing rule to the writer. 1984 BpGraphWriter& node(const std::string& caption, const Node& node) { 1985 typedef _writer_bits::DoubleMapLookUpConverter< 1986 Node, RedNodeIndex, BlueNodeIndex> Converter; 1987 Converter converter(_red_node_index, _blue_node_index); 1988 _writer_bits::ValueStorageBase* storage = 1989 new _writer_bits::ValueStorage<Node, Converter>(node, converter); 1990 _attributes.push_back(std::make_pair(caption, storage)); 1991 return *this; 1992 } 1993 1994 /// \brief Red node writing rule 1995 /// 1996 /// Add a red node writing rule to the writer. 1997 BpGraphWriter& redNode(const std::string& caption, const RedNode& node) { 1998 typedef _writer_bits::MapLookUpConverter<Node> Converter; 1999 Converter converter(_red_node_index); 2000 _writer_bits::ValueStorageBase* storage = 2001 new _writer_bits::ValueStorage<Node, Converter>(node, converter); 2002 _attributes.push_back(std::make_pair(caption, storage)); 2003 return *this; 2004 } 2005 2006 /// \brief Blue node writing rule 2007 /// 2008 /// Add a blue node writing rule to the writer. 2009 BpGraphWriter& blueNode(const std::string& caption, const BlueNode& node) { 2010 typedef _writer_bits::MapLookUpConverter<Node> Converter; 2011 Converter converter(_blue_node_index); 2012 _writer_bits::ValueStorageBase* storage = 2013 new _writer_bits::ValueStorage<Node, Converter>(node, converter); 2014 _attributes.push_back(std::make_pair(caption, storage)); 2015 return *this; 2016 } 2017 2018 /// \brief Edge writing rule 2019 /// 2020 /// Add an edge writing rule to writer. 2021 BpGraphWriter& edge(const std::string& caption, const Edge& edge) { 2022 typedef _writer_bits::MapLookUpConverter<Edge> Converter; 2023 Converter converter(_edge_index); 2024 _writer_bits::ValueStorageBase* storage = 2025 new _writer_bits::ValueStorage<Edge, Converter>(edge, converter); 2026 _attributes.push_back(std::make_pair(caption, storage)); 2027 return *this; 2028 } 2029 2030 /// \brief Arc writing rule 2031 /// 2032 /// Add an arc writing rule to writer. 2033 BpGraphWriter& arc(const std::string& caption, const Arc& arc) { 2034 typedef _writer_bits::GraphArcLookUpConverter<BGR> Converter; 2035 Converter converter(_graph, _edge_index); 2036 _writer_bits::ValueStorageBase* storage = 2037 new _writer_bits::ValueStorage<Arc, Converter>(arc, converter); 2038 _attributes.push_back(std::make_pair(caption, storage)); 2039 return *this; 2040 } 2041 2042 /// \name Section Captions 2043 /// @{ 2044 2045 /// \brief Add an additional caption to the \c \@red_nodes and 2046 /// \c \@blue_nodes section 2047 /// 2048 /// Add an additional caption to the \c \@red_nodes and \c 2049 /// \@blue_nodes section. 2050 BpGraphWriter& nodes(const std::string& caption) { 2051 _nodes_caption = caption; 2052 return *this; 2053 } 2054 2055 /// \brief Add an additional caption to the \c \@edges section 2056 /// 2057 /// Add an additional caption to the \c \@edges section. 2058 BpGraphWriter& edges(const std::string& caption) { 2059 _edges_caption = caption; 2060 return *this; 2061 } 2062 2063 /// \brief Add an additional caption to the \c \@attributes section 2064 /// 2065 /// Add an additional caption to the \c \@attributes section. 2066 BpGraphWriter& attributes(const std::string& caption) { 2067 _attributes_caption = caption; 2068 return *this; 2069 } 2070 2071 /// \name Skipping Section 2072 /// @{ 2073 2074 /// \brief Skip writing the node set 2075 /// 2076 /// The \c \@red_nodes and \c \@blue_nodes section will not be 2077 /// written to the stream. 2078 BpGraphWriter& skipNodes() { 2079 LEMON_ASSERT(!_skip_nodes, "Multiple usage of skipNodes() member"); 2080 _skip_nodes = true; 2081 return *this; 2082 } 2083 2084 /// \brief Skip writing edge set 2085 /// 2086 /// The \c \@edges section will not be written to the stream. 2087 BpGraphWriter& skipEdges() { 2088 LEMON_ASSERT(!_skip_edges, "Multiple usage of skipEdges() member"); 2089 _skip_edges = true; 2090 return *this; 2091 } 2092 2093 /// @} 2094 2095 private: 2096 2097 void writeRedNodes() { 2098 _writer_bits::MapStorageBase<RedNode>* label = 0; 2099 for (typename RedNodeMaps::iterator it = _red_node_maps.begin(); 2100 it != _red_node_maps.end(); ++it) { 2101 if (it->first == "label") { 2102 label = it->second; 2103 break; 2104 } 2105 } 2106 2107 *_os << "@red_nodes"; 2108 if (!_nodes_caption.empty()) { 2109 _writer_bits::writeToken(*_os << ' ', _nodes_caption); 2110 } 2111 *_os << std::endl; 2112 2113 if (label == 0) { 2114 *_os << "label" << '\t'; 2115 } 2116 for (typename RedNodeMaps::iterator it = _red_node_maps.begin(); 2117 it != _red_node_maps.end(); ++it) { 2118 _writer_bits::writeToken(*_os, it->first) << '\t'; 2119 } 2120 *_os << std::endl; 2121 2122 std::vector<RedNode> nodes; 2123 for (RedNodeIt n(_graph); n != INVALID; ++n) { 2124 nodes.push_back(n); 2125 } 2126 2127 if (label == 0) { 2128 IdMap<BGR, Node> id_map(_graph); 2129 _writer_bits::MapLess<IdMap<BGR, Node> > id_less(id_map); 2130 std::sort(nodes.begin(), nodes.end(), id_less); 2131 } else { 2132 label->sort(nodes); 2133 } 2134 2135 for (int i = 0; i < static_cast<int>(nodes.size()); ++i) { 2136 RedNode n = nodes[i]; 2137 if (label == 0) { 2138 std::ostringstream os; 2139 os << _graph.id(static_cast<Node>(n)); 2140 _writer_bits::writeToken(*_os, os.str()); 2141 *_os << '\t'; 2142 _red_node_index.insert(std::make_pair(n, os.str())); 2143 } 2144 for (typename RedNodeMaps::iterator it = _red_node_maps.begin(); 2145 it != _red_node_maps.end(); ++it) { 2146 std::string value = it->second->get(n); 2147 _writer_bits::writeToken(*_os, value); 2148 if (it->first == "label") { 2149 _red_node_index.insert(std::make_pair(n, value)); 2150 } 2151 *_os << '\t'; 2152 } 2153 *_os << std::endl; 2154 } 2155 } 2156 2157 void writeBlueNodes() { 2158 _writer_bits::MapStorageBase<BlueNode>* label = 0; 2159 for (typename BlueNodeMaps::iterator it = _blue_node_maps.begin(); 2160 it != _blue_node_maps.end(); ++it) { 2161 if (it->first == "label") { 2162 label = it->second; 2163 break; 2164 } 2165 } 2166 2167 *_os << "@blue_nodes"; 2168 if (!_nodes_caption.empty()) { 2169 _writer_bits::writeToken(*_os << ' ', _nodes_caption); 2170 } 2171 *_os << std::endl; 2172 2173 if (label == 0) { 2174 *_os << "label" << '\t'; 2175 } 2176 for (typename BlueNodeMaps::iterator it = _blue_node_maps.begin(); 2177 it != _blue_node_maps.end(); ++it) { 2178 _writer_bits::writeToken(*_os, it->first) << '\t'; 2179 } 2180 *_os << std::endl; 2181 2182 std::vector<BlueNode> nodes; 2183 for (BlueNodeIt n(_graph); n != INVALID; ++n) { 2184 nodes.push_back(n); 2185 } 2186 2187 if (label == 0) { 2188 IdMap<BGR, Node> id_map(_graph); 2189 _writer_bits::MapLess<IdMap<BGR, Node> > id_less(id_map); 2190 std::sort(nodes.begin(), nodes.end(), id_less); 2191 } else { 2192 label->sort(nodes); 2193 } 2194 2195 for (int i = 0; i < static_cast<int>(nodes.size()); ++i) { 2196 BlueNode n = nodes[i]; 2197 if (label == 0) { 2198 std::ostringstream os; 2199 os << _graph.id(static_cast<Node>(n)); 2200 _writer_bits::writeToken(*_os, os.str()); 2201 *_os << '\t'; 2202 _blue_node_index.insert(std::make_pair(n, os.str())); 2203 } 2204 for (typename BlueNodeMaps::iterator it = _blue_node_maps.begin(); 2205 it != _blue_node_maps.end(); ++it) { 2206 std::string value = it->second->get(n); 2207 _writer_bits::writeToken(*_os, value); 2208 if (it->first == "label") { 2209 _blue_node_index.insert(std::make_pair(n, value)); 2210 } 2211 *_os << '\t'; 2212 } 2213 *_os << std::endl; 2214 } 2215 } 2216 2217 void createRedNodeIndex() { 2218 _writer_bits::MapStorageBase<RedNode>* label = 0; 2219 for (typename RedNodeMaps::iterator it = _red_node_maps.begin(); 2220 it != _red_node_maps.end(); ++it) { 2221 if (it->first == "label") { 2222 label = it->second; 2223 break; 2224 } 2225 } 2226 2227 if (label == 0) { 2228 for (RedNodeIt n(_graph); n != INVALID; ++n) { 2229 std::ostringstream os; 2230 os << _graph.id(n); 2231 _red_node_index.insert(std::make_pair(n, os.str())); 2232 } 2233 } else { 2234 for (RedNodeIt n(_graph); n != INVALID; ++n) { 2235 std::string value = label->get(n); 2236 _red_node_index.insert(std::make_pair(n, value)); 2237 } 2238 } 2239 } 2240 2241 void createBlueNodeIndex() { 2242 _writer_bits::MapStorageBase<BlueNode>* label = 0; 2243 for (typename BlueNodeMaps::iterator it = _blue_node_maps.begin(); 2244 it != _blue_node_maps.end(); ++it) { 2245 if (it->first == "label") { 2246 label = it->second; 2247 break; 2248 } 2249 } 2250 2251 if (label == 0) { 2252 for (BlueNodeIt n(_graph); n != INVALID; ++n) { 2253 std::ostringstream os; 2254 os << _graph.id(n); 2255 _blue_node_index.insert(std::make_pair(n, os.str())); 2256 } 2257 } else { 2258 for (BlueNodeIt n(_graph); n != INVALID; ++n) { 2259 std::string value = label->get(n); 2260 _blue_node_index.insert(std::make_pair(n, value)); 2261 } 2262 } 2263 } 2264 2265 void writeEdges() { 2266 _writer_bits::MapStorageBase<Edge>* label = 0; 2267 for (typename EdgeMaps::iterator it = _edge_maps.begin(); 2268 it != _edge_maps.end(); ++it) { 2269 if (it->first == "label") { 2270 label = it->second; 2271 break; 2272 } 2273 } 2274 2275 *_os << "@edges"; 2276 if (!_edges_caption.empty()) { 2277 _writer_bits::writeToken(*_os << ' ', _edges_caption); 2278 } 2279 *_os << std::endl; 2280 2281 *_os << '\t' << '\t'; 2282 if (label == 0) { 2283 *_os << "label" << '\t'; 2284 } 2285 for (typename EdgeMaps::iterator it = _edge_maps.begin(); 2286 it != _edge_maps.end(); ++it) { 2287 _writer_bits::writeToken(*_os, it->first) << '\t'; 2288 } 2289 *_os << std::endl; 2290 2291 std::vector<Edge> edges; 2292 for (EdgeIt n(_graph); n != INVALID; ++n) { 2293 edges.push_back(n); 2294 } 2295 2296 if (label == 0) { 2297 IdMap<BGR, Edge> id_map(_graph); 2298 _writer_bits::MapLess<IdMap<BGR, Edge> > id_less(id_map); 2299 std::sort(edges.begin(), edges.end(), id_less); 2300 } else { 2301 label->sort(edges); 2302 } 2303 2304 for (int i = 0; i < static_cast<int>(edges.size()); ++i) { 2305 Edge e = edges[i]; 2306 _writer_bits::writeToken(*_os, _red_node_index. 2307 find(_graph.redNode(e))->second); 2308 *_os << '\t'; 2309 _writer_bits::writeToken(*_os, _blue_node_index. 2310 find(_graph.blueNode(e))->second); 2311 *_os << '\t'; 2312 if (label == 0) { 2313 std::ostringstream os; 2314 os << _graph.id(e); 2315 _writer_bits::writeToken(*_os, os.str()); 2316 *_os << '\t'; 2317 _edge_index.insert(std::make_pair(e, os.str())); 2318 } 2319 for (typename EdgeMaps::iterator it = _edge_maps.begin(); 2320 it != _edge_maps.end(); ++it) { 2321 std::string value = it->second->get(e); 2322 _writer_bits::writeToken(*_os, value); 2323 if (it->first == "label") { 2324 _edge_index.insert(std::make_pair(e, value)); 2325 } 2326 *_os << '\t'; 2327 } 2328 *_os << std::endl; 2329 } 2330 } 2331 2332 void createEdgeIndex() { 2333 _writer_bits::MapStorageBase<Edge>* label = 0; 2334 for (typename EdgeMaps::iterator it = _edge_maps.begin(); 2335 it != _edge_maps.end(); ++it) { 2336 if (it->first == "label") { 2337 label = it->second; 2338 break; 2339 } 2340 } 2341 2342 if (label == 0) { 2343 for (EdgeIt e(_graph); e != INVALID; ++e) { 2344 std::ostringstream os; 2345 os << _graph.id(e); 2346 _edge_index.insert(std::make_pair(e, os.str())); 2347 } 2348 } else { 2349 for (EdgeIt e(_graph); e != INVALID; ++e) { 2350 std::string value = label->get(e); 2351 _edge_index.insert(std::make_pair(e, value)); 2352 } 2353 } 2354 } 2355 2356 void writeAttributes() { 2357 if (_attributes.empty()) return; 2358 *_os << "@attributes"; 2359 if (!_attributes_caption.empty()) { 2360 _writer_bits::writeToken(*_os << ' ', _attributes_caption); 2361 } 2362 *_os << std::endl; 2363 for (typename Attributes::iterator it = _attributes.begin(); 2364 it != _attributes.end(); ++it) { 2365 _writer_bits::writeToken(*_os, it->first) << ' '; 2366 _writer_bits::writeToken(*_os, it->second->get()); 2367 *_os << std::endl; 2368 } 2369 } 2370 2371 public: 2372 2373 /// \name Execution of the Writer 2374 /// @{ 2375 2376 /// \brief Start the batch processing 2377 /// 2378 /// This function starts the batch processing. 2379 void run() { 2380 if (!_skip_nodes) { 2381 writeRedNodes(); 2382 writeBlueNodes(); 2383 } else { 2384 createRedNodeIndex(); 2385 createBlueNodeIndex(); 2386 } 2387 if (!_skip_edges) { 2388 writeEdges(); 2389 } else { 2390 createEdgeIndex(); 2391 } 2392 writeAttributes(); 2393 } 2394 2395 /// \brief Give back the stream of the writer 2396 /// 2397 /// Give back the stream of the writer 2398 std::ostream& ostream() { 2399 return *_os; 2400 } 2401 2402 /// @} 2403 }; 2404 2405 /// \ingroup lemon_io 2406 /// 2407 /// \brief Return a \ref lemon::BpGraphWriter "BpGraphWriter" class 2408 /// 2409 /// This function just returns a \ref lemon::BpGraphWriter 2410 /// "BpGraphWriter" class. 2411 /// 2412 /// With this function a bipartite graph can be write to a file or output 2413 /// stream in \ref lgf-format "LGF" format with several maps and 2414 /// attributes. For example, with the following code a bipartite 2415 /// weighted matching problem can be written to the standard output, 2416 /// i.e. a graph with a \e weight map on the edges: 2417 /// 2418 ///\code 2419 ///ListBpGraph graph; 2420 ///ListBpGraph::EdgeMap<int> weight(graph); 2421 /// // Setting the weight map 2422 ///bpGraphWriter(graph, std::cout). 2423 /// edgeMap("weight", weight). 2424 /// run(); 2425 ///\endcode 2426 /// 2427 /// For a complete documentation, please see the 2428 /// \ref lemon::BpGraphWriter "BpGraphWriter" 2429 /// class documentation. 2430 /// \warning Don't forget to put the \ref lemon::BpGraphWriter::run() "run()" 2431 /// to the end of the parameter list. 2432 /// \relates BpGraphWriter 2433 /// \sa bpGraphWriter(const TBGR& graph, const std::string& fn) 2434 /// \sa bpGraphWriter(const TBGR& graph, const char* fn) 2435 template <typename TBGR> 2436 BpGraphWriter<TBGR> bpGraphWriter(const TBGR& graph, std::ostream& os) { 2437 BpGraphWriter<TBGR> tmp(graph, os); 2438 return tmp; 2439 } 2440 2441 /// \brief Return a \ref BpGraphWriter class 2442 /// 2443 /// This function just returns a \ref BpGraphWriter class. 2444 /// \relates BpGraphWriter 2445 /// \sa graphWriter(const TBGR& graph, std::ostream& os) 2446 template <typename TBGR> 2447 BpGraphWriter<TBGR> bpGraphWriter(const TBGR& graph, const std::string& fn) { 2448 BpGraphWriter<TBGR> tmp(graph, fn); 2449 return tmp; 2450 } 2451 2452 /// \brief Return a \ref BpGraphWriter class 2453 /// 2454 /// This function just returns a \ref BpGraphWriter class. 2455 /// \relates BpGraphWriter 2456 /// \sa graphWriter(const TBGR& graph, std::ostream& os) 2457 template <typename TBGR> 2458 BpGraphWriter<TBGR> bpGraphWriter(const TBGR& graph, const char* fn) { 2459 BpGraphWriter<TBGR> tmp(graph, fn); 1608 2460 return tmp; 1609 2461 } -
lemon/list_graph.h
r956 r1357 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 446 446 ///or changeTarget(), thus \c ArcIt and \c OutArcIt iterators are 447 447 ///invalidated for the outgoing arcs of node \c v and \c InArcIt 448 ///iterators are invalidated for the incom ming arcs of \c v.448 ///iterators are invalidated for the incoming arcs of \c v. 449 449 ///Moreover all iterators referencing node \c v or the removed 450 450 ///loops are also invalidated. Other iterators remain valid. … … 583 583 } 584 584 virtual void add(const std::vector<Node>& nodes) { 585 for (int i = nodes.size() - 1; i >= 0; ++i) {585 for (int i = nodes.size() - 1; i >= 0; --i) { 586 586 snapshot.addNode(nodes[i]); 587 587 } … … 633 633 } 634 634 virtual void add(const std::vector<Arc>& arcs) { 635 for (int i = arcs.size() - 1; i >= 0; ++i) {635 for (int i = arcs.size() - 1; i >= 0; --i) { 636 636 snapshot.addArc(arcs[i]); 637 637 } … … 1395 1395 } 1396 1396 virtual void add(const std::vector<Node>& nodes) { 1397 for (int i = nodes.size() - 1; i >= 0; ++i) {1397 for (int i = nodes.size() - 1; i >= 0; --i) { 1398 1398 snapshot.addNode(nodes[i]); 1399 1399 } … … 1445 1445 } 1446 1446 virtual void add(const std::vector<Edge>& edges) { 1447 for (int i = edges.size() - 1; i >= 0; ++i) {1447 for (int i = edges.size() - 1; i >= 0; --i) { 1448 1448 snapshot.addEdge(edges[i]); 1449 1449 } … … 1600 1600 1601 1601 /// @} 1602 1603 class ListBpGraphBase { 1604 1605 protected: 1606 1607 struct NodeT { 1608 int first_out; 1609 int prev, next; 1610 int partition_prev, partition_next; 1611 int partition_index; 1612 bool red; 1613 }; 1614 1615 struct ArcT { 1616 int target; 1617 int prev_out, next_out; 1618 }; 1619 1620 std::vector<NodeT> nodes; 1621 1622 int first_node, first_red, first_blue; 1623 int max_red, max_blue; 1624 1625 int first_free_red, first_free_blue; 1626 1627 std::vector<ArcT> arcs; 1628 1629 int first_free_arc; 1630 1631 public: 1632 1633 typedef ListBpGraphBase BpGraph; 1634 1635 class Node { 1636 friend class ListBpGraphBase; 1637 protected: 1638 1639 int id; 1640 explicit Node(int pid) { id = pid;} 1641 1642 public: 1643 Node() {} 1644 Node (Invalid) { id = -1; } 1645 bool operator==(const Node& node) const {return id == node.id;} 1646 bool operator!=(const Node& node) const {return id != node.id;} 1647 bool operator<(const Node& node) const {return id < node.id;} 1648 }; 1649 1650 class RedNode : public Node { 1651 friend class ListBpGraphBase; 1652 protected: 1653 1654 explicit RedNode(int pid) : Node(pid) {} 1655 1656 public: 1657 RedNode() {} 1658 RedNode(const RedNode& node) : Node(node) {} 1659 RedNode(Invalid) : Node(INVALID){} 1660 }; 1661 1662 class BlueNode : public Node { 1663 friend class ListBpGraphBase; 1664 protected: 1665 1666 explicit BlueNode(int pid) : Node(pid) {} 1667 1668 public: 1669 BlueNode() {} 1670 BlueNode(const BlueNode& node) : Node(node) {} 1671 BlueNode(Invalid) : Node(INVALID){} 1672 }; 1673 1674 class Edge { 1675 friend class ListBpGraphBase; 1676 protected: 1677 1678 int id; 1679 explicit Edge(int pid) { id = pid;} 1680 1681 public: 1682 Edge() {} 1683 Edge (Invalid) { id = -1; } 1684 bool operator==(const Edge& edge) const {return id == edge.id;} 1685 bool operator!=(const Edge& edge) const {return id != edge.id;} 1686 bool operator<(const Edge& edge) const {return id < edge.id;} 1687 }; 1688 1689 class Arc { 1690 friend class ListBpGraphBase; 1691 protected: 1692 1693 int id; 1694 explicit Arc(int pid) { id = pid;} 1695 1696 public: 1697 operator Edge() const { 1698 return id != -1 ? edgeFromId(id / 2) : INVALID; 1699 } 1700 1701 Arc() {} 1702 Arc (Invalid) { id = -1; } 1703 bool operator==(const Arc& arc) const {return id == arc.id;} 1704 bool operator!=(const Arc& arc) const {return id != arc.id;} 1705 bool operator<(const Arc& arc) const {return id < arc.id;} 1706 }; 1707 1708 ListBpGraphBase() 1709 : nodes(), first_node(-1), 1710 first_red(-1), first_blue(-1), 1711 max_red(-1), max_blue(-1), 1712 first_free_red(-1), first_free_blue(-1), 1713 arcs(), first_free_arc(-1) {} 1714 1715 1716 bool red(Node n) const { return nodes[n.id].red; } 1717 bool blue(Node n) const { return !nodes[n.id].red; } 1718 1719 static RedNode asRedNodeUnsafe(Node n) { return RedNode(n.id); } 1720 static BlueNode asBlueNodeUnsafe(Node n) { return BlueNode(n.id); } 1721 1722 int maxNodeId() const { return nodes.size()-1; } 1723 int maxRedId() const { return max_red; } 1724 int maxBlueId() const { return max_blue; } 1725 int maxEdgeId() const { return arcs.size() / 2 - 1; } 1726 int maxArcId() const { return arcs.size()-1; } 1727 1728 Node source(Arc e) const { return Node(arcs[e.id ^ 1].target); } 1729 Node target(Arc e) const { return Node(arcs[e.id].target); } 1730 1731 RedNode redNode(Edge e) const { 1732 return RedNode(arcs[2 * e.id].target); 1733 } 1734 BlueNode blueNode(Edge e) const { 1735 return BlueNode(arcs[2 * e.id + 1].target); 1736 } 1737 1738 static bool direction(Arc e) { 1739 return (e.id & 1) == 1; 1740 } 1741 1742 static Arc direct(Edge e, bool d) { 1743 return Arc(e.id * 2 + (d ? 1 : 0)); 1744 } 1745 1746 void first(Node& node) const { 1747 node.id = first_node; 1748 } 1749 1750 void next(Node& node) const { 1751 node.id = nodes[node.id].next; 1752 } 1753 1754 void first(RedNode& node) const { 1755 node.id = first_red; 1756 } 1757 1758 void next(RedNode& node) const { 1759 node.id = nodes[node.id].partition_next; 1760 } 1761 1762 void first(BlueNode& node) const { 1763 node.id = first_blue; 1764 } 1765 1766 void next(BlueNode& node) const { 1767 node.id = nodes[node.id].partition_next; 1768 } 1769 1770 void first(Arc& e) const { 1771 int n = first_node; 1772 while (n != -1 && nodes[n].first_out == -1) { 1773 n = nodes[n].next; 1774 } 1775 e.id = (n == -1) ? -1 : nodes[n].first_out; 1776 } 1777 1778 void next(Arc& e) const { 1779 if (arcs[e.id].next_out != -1) { 1780 e.id = arcs[e.id].next_out; 1781 } else { 1782 int n = nodes[arcs[e.id ^ 1].target].next; 1783 while(n != -1 && nodes[n].first_out == -1) { 1784 n = nodes[n].next; 1785 } 1786 e.id = (n == -1) ? -1 : nodes[n].first_out; 1787 } 1788 } 1789 1790 void first(Edge& e) const { 1791 int n = first_node; 1792 while (n != -1) { 1793 e.id = nodes[n].first_out; 1794 while ((e.id & 1) != 1) { 1795 e.id = arcs[e.id].next_out; 1796 } 1797 if (e.id != -1) { 1798 e.id /= 2; 1799 return; 1800 } 1801 n = nodes[n].next; 1802 } 1803 e.id = -1; 1804 } 1805 1806 void next(Edge& e) const { 1807 int n = arcs[e.id * 2].target; 1808 e.id = arcs[(e.id * 2) | 1].next_out; 1809 while ((e.id & 1) != 1) { 1810 e.id = arcs[e.id].next_out; 1811 } 1812 if (e.id != -1) { 1813 e.id /= 2; 1814 return; 1815 } 1816 n = nodes[n].next; 1817 while (n != -1) { 1818 e.id = nodes[n].first_out; 1819 while ((e.id & 1) != 1) { 1820 e.id = arcs[e.id].next_out; 1821 } 1822 if (e.id != -1) { 1823 e.id /= 2; 1824 return; 1825 } 1826 n = nodes[n].next; 1827 } 1828 e.id = -1; 1829 } 1830 1831 void firstOut(Arc &e, const Node& v) const { 1832 e.id = nodes[v.id].first_out; 1833 } 1834 void nextOut(Arc &e) const { 1835 e.id = arcs[e.id].next_out; 1836 } 1837 1838 void firstIn(Arc &e, const Node& v) const { 1839 e.id = ((nodes[v.id].first_out) ^ 1); 1840 if (e.id == -2) e.id = -1; 1841 } 1842 void nextIn(Arc &e) const { 1843 e.id = ((arcs[e.id ^ 1].next_out) ^ 1); 1844 if (e.id == -2) e.id = -1; 1845 } 1846 1847 void firstInc(Edge &e, bool& d, const Node& v) const { 1848 int a = nodes[v.id].first_out; 1849 if (a != -1 ) { 1850 e.id = a / 2; 1851 d = ((a & 1) == 1); 1852 } else { 1853 e.id = -1; 1854 d = true; 1855 } 1856 } 1857 void nextInc(Edge &e, bool& d) const { 1858 int a = (arcs[(e.id * 2) | (d ? 1 : 0)].next_out); 1859 if (a != -1 ) { 1860 e.id = a / 2; 1861 d = ((a & 1) == 1); 1862 } else { 1863 e.id = -1; 1864 d = true; 1865 } 1866 } 1867 1868 static int id(Node v) { return v.id; } 1869 int id(RedNode v) const { return nodes[v.id].partition_index; } 1870 int id(BlueNode v) const { return nodes[v.id].partition_index; } 1871 static int id(Arc e) { return e.id; } 1872 static int id(Edge e) { return e.id; } 1873 1874 static Node nodeFromId(int id) { return Node(id);} 1875 static Arc arcFromId(int id) { return Arc(id);} 1876 static Edge edgeFromId(int id) { return Edge(id);} 1877 1878 bool valid(Node n) const { 1879 return n.id >= 0 && n.id < static_cast<int>(nodes.size()) && 1880 nodes[n.id].prev != -2; 1881 } 1882 1883 bool valid(Arc a) const { 1884 return a.id >= 0 && a.id < static_cast<int>(arcs.size()) && 1885 arcs[a.id].prev_out != -2; 1886 } 1887 1888 bool valid(Edge e) const { 1889 return e.id >= 0 && 2 * e.id < static_cast<int>(arcs.size()) && 1890 arcs[2 * e.id].prev_out != -2; 1891 } 1892 1893 RedNode addRedNode() { 1894 int n; 1895 1896 if(first_free_red==-1) { 1897 n = nodes.size(); 1898 nodes.push_back(NodeT()); 1899 nodes[n].partition_index = ++max_red; 1900 nodes[n].red = true; 1901 } else { 1902 n = first_free_red; 1903 first_free_red = nodes[n].next; 1904 } 1905 1906 nodes[n].next = first_node; 1907 if (first_node != -1) nodes[first_node].prev = n; 1908 first_node = n; 1909 nodes[n].prev = -1; 1910 1911 nodes[n].partition_next = first_red; 1912 if (first_red != -1) nodes[first_red].partition_prev = n; 1913 first_red = n; 1914 nodes[n].partition_prev = -1; 1915 1916 nodes[n].first_out = -1; 1917 1918 return RedNode(n); 1919 } 1920 1921 BlueNode addBlueNode() { 1922 int n; 1923 1924 if(first_free_blue==-1) { 1925 n = nodes.size(); 1926 nodes.push_back(NodeT()); 1927 nodes[n].partition_index = ++max_blue; 1928 nodes[n].red = false; 1929 } else { 1930 n = first_free_blue; 1931 first_free_blue = nodes[n].next; 1932 } 1933 1934 nodes[n].next = first_node; 1935 if (first_node != -1) nodes[first_node].prev = n; 1936 first_node = n; 1937 nodes[n].prev = -1; 1938 1939 nodes[n].partition_next = first_blue; 1940 if (first_blue != -1) nodes[first_blue].partition_prev = n; 1941 first_blue = n; 1942 nodes[n].partition_prev = -1; 1943 1944 nodes[n].first_out = -1; 1945 1946 return BlueNode(n); 1947 } 1948 1949 Edge addEdge(Node u, Node v) { 1950 int n; 1951 1952 if (first_free_arc == -1) { 1953 n = arcs.size(); 1954 arcs.push_back(ArcT()); 1955 arcs.push_back(ArcT()); 1956 } else { 1957 n = first_free_arc; 1958 first_free_arc = arcs[n].next_out; 1959 } 1960 1961 arcs[n].target = u.id; 1962 arcs[n | 1].target = v.id; 1963 1964 arcs[n].next_out = nodes[v.id].first_out; 1965 if (nodes[v.id].first_out != -1) { 1966 arcs[nodes[v.id].first_out].prev_out = n; 1967 } 1968 arcs[n].prev_out = -1; 1969 nodes[v.id].first_out = n; 1970 1971 arcs[n | 1].next_out = nodes[u.id].first_out; 1972 if (nodes[u.id].first_out != -1) { 1973 arcs[nodes[u.id].first_out].prev_out = (n | 1); 1974 } 1975 arcs[n | 1].prev_out = -1; 1976 nodes[u.id].first_out = (n | 1); 1977 1978 return Edge(n / 2); 1979 } 1980 1981 void erase(const Node& node) { 1982 int n = node.id; 1983 1984 if(nodes[n].next != -1) { 1985 nodes[nodes[n].next].prev = nodes[n].prev; 1986 } 1987 1988 if(nodes[n].prev != -1) { 1989 nodes[nodes[n].prev].next = nodes[n].next; 1990 } else { 1991 first_node = nodes[n].next; 1992 } 1993 1994 if (nodes[n].partition_next != -1) { 1995 nodes[nodes[n].partition_next].partition_prev = nodes[n].partition_prev; 1996 } 1997 1998 if (nodes[n].partition_prev != -1) { 1999 nodes[nodes[n].partition_prev].partition_next = nodes[n].partition_next; 2000 } else { 2001 if (nodes[n].red) { 2002 first_red = nodes[n].partition_next; 2003 } else { 2004 first_blue = nodes[n].partition_next; 2005 } 2006 } 2007 2008 if (nodes[n].red) { 2009 nodes[n].next = first_free_red; 2010 first_free_red = n; 2011 } else { 2012 nodes[n].next = first_free_blue; 2013 first_free_blue = n; 2014 } 2015 nodes[n].prev = -2; 2016 } 2017 2018 void erase(const Edge& edge) { 2019 int n = edge.id * 2; 2020 2021 if (arcs[n].next_out != -1) { 2022 arcs[arcs[n].next_out].prev_out = arcs[n].prev_out; 2023 } 2024 2025 if (arcs[n].prev_out != -1) { 2026 arcs[arcs[n].prev_out].next_out = arcs[n].next_out; 2027 } else { 2028 nodes[arcs[n | 1].target].first_out = arcs[n].next_out; 2029 } 2030 2031 if (arcs[n | 1].next_out != -1) { 2032 arcs[arcs[n | 1].next_out].prev_out = arcs[n | 1].prev_out; 2033 } 2034 2035 if (arcs[n | 1].prev_out != -1) { 2036 arcs[arcs[n | 1].prev_out].next_out = arcs[n | 1].next_out; 2037 } else { 2038 nodes[arcs[n].target].first_out = arcs[n | 1].next_out; 2039 } 2040 2041 arcs[n].next_out = first_free_arc; 2042 first_free_arc = n; 2043 arcs[n].prev_out = -2; 2044 arcs[n | 1].prev_out = -2; 2045 2046 } 2047 2048 void clear() { 2049 arcs.clear(); 2050 nodes.clear(); 2051 first_node = first_free_arc = first_red = first_blue = 2052 max_red = max_blue = first_free_red = first_free_blue = -1; 2053 } 2054 2055 protected: 2056 2057 void changeRed(Edge e, RedNode n) { 2058 if(arcs[(2 * e.id) | 1].next_out != -1) { 2059 arcs[arcs[(2 * e.id) | 1].next_out].prev_out = 2060 arcs[(2 * e.id) | 1].prev_out; 2061 } 2062 if(arcs[(2 * e.id) | 1].prev_out != -1) { 2063 arcs[arcs[(2 * e.id) | 1].prev_out].next_out = 2064 arcs[(2 * e.id) | 1].next_out; 2065 } else { 2066 nodes[arcs[2 * e.id].target].first_out = 2067 arcs[(2 * e.id) | 1].next_out; 2068 } 2069 2070 if (nodes[n.id].first_out != -1) { 2071 arcs[nodes[n.id].first_out].prev_out = ((2 * e.id) | 1); 2072 } 2073 arcs[2 * e.id].target = n.id; 2074 arcs[(2 * e.id) | 1].prev_out = -1; 2075 arcs[(2 * e.id) | 1].next_out = nodes[n.id].first_out; 2076 nodes[n.id].first_out = ((2 * e.id) | 1); 2077 } 2078 2079 void changeBlue(Edge e, BlueNode n) { 2080 if(arcs[2 * e.id].next_out != -1) { 2081 arcs[arcs[2 * e.id].next_out].prev_out = arcs[2 * e.id].prev_out; 2082 } 2083 if(arcs[2 * e.id].prev_out != -1) { 2084 arcs[arcs[2 * e.id].prev_out].next_out = 2085 arcs[2 * e.id].next_out; 2086 } else { 2087 nodes[arcs[(2 * e.id) | 1].target].first_out = 2088 arcs[2 * e.id].next_out; 2089 } 2090 2091 if (nodes[n.id].first_out != -1) { 2092 arcs[nodes[n.id].first_out].prev_out = 2 * e.id; 2093 } 2094 arcs[(2 * e.id) | 1].target = n.id; 2095 arcs[2 * e.id].prev_out = -1; 2096 arcs[2 * e.id].next_out = nodes[n.id].first_out; 2097 nodes[n.id].first_out = 2 * e.id; 2098 } 2099 2100 }; 2101 2102 typedef BpGraphExtender<ListBpGraphBase> ExtendedListBpGraphBase; 2103 2104 2105 /// \addtogroup graphs 2106 /// @{ 2107 2108 ///A general undirected graph structure. 2109 2110 ///\ref ListBpGraph is a versatile and fast undirected graph 2111 ///implementation based on linked lists that are stored in 2112 ///\c std::vector structures. 2113 /// 2114 ///This type fully conforms to the \ref concepts::BpGraph "BpGraph concept" 2115 ///and it also provides several useful additional functionalities. 2116 ///Most of its member functions and nested classes are documented 2117 ///only in the concept class. 2118 /// 2119 ///This class provides only linear time counting for nodes, edges and arcs. 2120 /// 2121 ///\sa concepts::BpGraph 2122 ///\sa ListDigraph 2123 class ListBpGraph : public ExtendedListBpGraphBase { 2124 typedef ExtendedListBpGraphBase Parent; 2125 2126 private: 2127 /// BpGraphs are \e not copy constructible. Use BpGraphCopy instead. 2128 ListBpGraph(const ListBpGraph &) :ExtendedListBpGraphBase() {}; 2129 /// \brief Assignment of a graph to another one is \e not allowed. 2130 /// Use BpGraphCopy instead. 2131 void operator=(const ListBpGraph &) {} 2132 public: 2133 /// Constructor 2134 2135 /// Constructor. 2136 /// 2137 ListBpGraph() {} 2138 2139 typedef Parent::OutArcIt IncEdgeIt; 2140 2141 /// \brief Add a new red node to the graph. 2142 /// 2143 /// This function adds a red new node to the graph. 2144 /// \return The new node. 2145 RedNode addRedNode() { return Parent::addRedNode(); } 2146 2147 /// \brief Add a new blue node to the graph. 2148 /// 2149 /// This function adds a blue new node to the graph. 2150 /// \return The new node. 2151 BlueNode addBlueNode() { return Parent::addBlueNode(); } 2152 2153 /// \brief Add a new edge to the graph. 2154 /// 2155 /// This function adds a new edge to the graph between nodes 2156 /// \c u and \c v with inherent orientation from node \c u to 2157 /// node \c v. 2158 /// \return The new edge. 2159 Edge addEdge(RedNode u, BlueNode v) { 2160 return Parent::addEdge(u, v); 2161 } 2162 Edge addEdge(BlueNode v, RedNode u) { 2163 return Parent::addEdge(u, v); 2164 } 2165 2166 ///\brief Erase a node from the graph. 2167 /// 2168 /// This function erases the given node along with its incident arcs 2169 /// from the graph. 2170 /// 2171 /// \note All iterators referencing the removed node or the incident 2172 /// edges are invalidated, of course. 2173 void erase(Node n) { Parent::erase(n); } 2174 2175 ///\brief Erase an edge from the graph. 2176 /// 2177 /// This function erases the given edge from the graph. 2178 /// 2179 /// \note All iterators referencing the removed edge are invalidated, 2180 /// of course. 2181 void erase(Edge e) { Parent::erase(e); } 2182 /// Node validity check 2183 2184 /// This function gives back \c true if the given node is valid, 2185 /// i.e. it is a real node of the graph. 2186 /// 2187 /// \warning A removed node could become valid again if new nodes are 2188 /// added to the graph. 2189 bool valid(Node n) const { return Parent::valid(n); } 2190 /// Edge validity check 2191 2192 /// This function gives back \c true if the given edge is valid, 2193 /// i.e. it is a real edge of the graph. 2194 /// 2195 /// \warning A removed edge could become valid again if new edges are 2196 /// added to the graph. 2197 bool valid(Edge e) const { return Parent::valid(e); } 2198 /// Arc validity check 2199 2200 /// This function gives back \c true if the given arc is valid, 2201 /// i.e. it is a real arc of the graph. 2202 /// 2203 /// \warning A removed arc could become valid again if new edges are 2204 /// added to the graph. 2205 bool valid(Arc a) const { return Parent::valid(a); } 2206 2207 /// \brief Change the red node of an edge. 2208 /// 2209 /// This function changes the red node of the given edge \c e to \c n. 2210 /// 2211 ///\note \c EdgeIt and \c ArcIt iterators referencing the 2212 ///changed edge are invalidated and all other iterators whose 2213 ///base node is the changed node are also invalidated. 2214 /// 2215 ///\warning This functionality cannot be used together with the 2216 ///Snapshot feature. 2217 void changeRed(Edge e, RedNode n) { 2218 Parent::changeRed(e, n); 2219 } 2220 /// \brief Change the blue node of an edge. 2221 /// 2222 /// This function changes the blue node of the given edge \c e to \c n. 2223 /// 2224 ///\note \c EdgeIt iterators referencing the changed edge remain 2225 ///valid, but \c ArcIt iterators referencing the changed edge and 2226 ///all other iterators whose base node is the changed node are also 2227 ///invalidated. 2228 /// 2229 ///\warning This functionality cannot be used together with the 2230 ///Snapshot feature. 2231 void changeBlue(Edge e, BlueNode n) { 2232 Parent::changeBlue(e, n); 2233 } 2234 2235 ///Clear the graph. 2236 2237 ///This function erases all nodes and arcs from the graph. 2238 /// 2239 ///\note All iterators of the graph are invalidated, of course. 2240 void clear() { 2241 Parent::clear(); 2242 } 2243 2244 /// Reserve memory for nodes. 2245 2246 /// Using this function, it is possible to avoid superfluous memory 2247 /// allocation: if you know that the graph you want to build will 2248 /// be large (e.g. it will contain millions of nodes and/or edges), 2249 /// then it is worth reserving space for this amount before starting 2250 /// to build the graph. 2251 /// \sa reserveEdge() 2252 void reserveNode(int n) { nodes.reserve(n); }; 2253 2254 /// Reserve memory for edges. 2255 2256 /// Using this function, it is possible to avoid superfluous memory 2257 /// allocation: if you know that the graph you want to build will 2258 /// be large (e.g. it will contain millions of nodes and/or edges), 2259 /// then it is worth reserving space for this amount before starting 2260 /// to build the graph. 2261 /// \sa reserveNode() 2262 void reserveEdge(int m) { arcs.reserve(2 * m); }; 2263 2264 /// \brief Class to make a snapshot of the graph and restore 2265 /// it later. 2266 /// 2267 /// Class to make a snapshot of the graph and restore it later. 2268 /// 2269 /// The newly added nodes and edges can be removed 2270 /// using the restore() function. 2271 /// 2272 /// \note After a state is restored, you cannot restore a later state, 2273 /// i.e. you cannot add the removed nodes and edges again using 2274 /// another Snapshot instance. 2275 /// 2276 /// \warning Node and edge deletions and other modifications 2277 /// (e.g. changing the end-nodes of edges or contracting nodes) 2278 /// cannot be restored. These events invalidate the snapshot. 2279 /// However, the edges and nodes that were added to the graph after 2280 /// making the current snapshot can be removed without invalidating it. 2281 class Snapshot { 2282 protected: 2283 2284 typedef Parent::NodeNotifier NodeNotifier; 2285 2286 class NodeObserverProxy : public NodeNotifier::ObserverBase { 2287 public: 2288 2289 NodeObserverProxy(Snapshot& _snapshot) 2290 : snapshot(_snapshot) {} 2291 2292 using NodeNotifier::ObserverBase::attach; 2293 using NodeNotifier::ObserverBase::detach; 2294 using NodeNotifier::ObserverBase::attached; 2295 2296 protected: 2297 2298 virtual void add(const Node& node) { 2299 snapshot.addNode(node); 2300 } 2301 virtual void add(const std::vector<Node>& nodes) { 2302 for (int i = nodes.size() - 1; i >= 0; --i) { 2303 snapshot.addNode(nodes[i]); 2304 } 2305 } 2306 virtual void erase(const Node& node) { 2307 snapshot.eraseNode(node); 2308 } 2309 virtual void erase(const std::vector<Node>& nodes) { 2310 for (int i = 0; i < int(nodes.size()); ++i) { 2311 snapshot.eraseNode(nodes[i]); 2312 } 2313 } 2314 virtual void build() { 2315 Node node; 2316 std::vector<Node> nodes; 2317 for (notifier()->first(node); node != INVALID; 2318 notifier()->next(node)) { 2319 nodes.push_back(node); 2320 } 2321 for (int i = nodes.size() - 1; i >= 0; --i) { 2322 snapshot.addNode(nodes[i]); 2323 } 2324 } 2325 virtual void clear() { 2326 Node node; 2327 for (notifier()->first(node); node != INVALID; 2328 notifier()->next(node)) { 2329 snapshot.eraseNode(node); 2330 } 2331 } 2332 2333 Snapshot& snapshot; 2334 }; 2335 2336 class EdgeObserverProxy : public EdgeNotifier::ObserverBase { 2337 public: 2338 2339 EdgeObserverProxy(Snapshot& _snapshot) 2340 : snapshot(_snapshot) {} 2341 2342 using EdgeNotifier::ObserverBase::attach; 2343 using EdgeNotifier::ObserverBase::detach; 2344 using EdgeNotifier::ObserverBase::attached; 2345 2346 protected: 2347 2348 virtual void add(const Edge& edge) { 2349 snapshot.addEdge(edge); 2350 } 2351 virtual void add(const std::vector<Edge>& edges) { 2352 for (int i = edges.size() - 1; i >= 0; --i) { 2353 snapshot.addEdge(edges[i]); 2354 } 2355 } 2356 virtual void erase(const Edge& edge) { 2357 snapshot.eraseEdge(edge); 2358 } 2359 virtual void erase(const std::vector<Edge>& edges) { 2360 for (int i = 0; i < int(edges.size()); ++i) { 2361 snapshot.eraseEdge(edges[i]); 2362 } 2363 } 2364 virtual void build() { 2365 Edge edge; 2366 std::vector<Edge> edges; 2367 for (notifier()->first(edge); edge != INVALID; 2368 notifier()->next(edge)) { 2369 edges.push_back(edge); 2370 } 2371 for (int i = edges.size() - 1; i >= 0; --i) { 2372 snapshot.addEdge(edges[i]); 2373 } 2374 } 2375 virtual void clear() { 2376 Edge edge; 2377 for (notifier()->first(edge); edge != INVALID; 2378 notifier()->next(edge)) { 2379 snapshot.eraseEdge(edge); 2380 } 2381 } 2382 2383 Snapshot& snapshot; 2384 }; 2385 2386 ListBpGraph *graph; 2387 2388 NodeObserverProxy node_observer_proxy; 2389 EdgeObserverProxy edge_observer_proxy; 2390 2391 std::list<Node> added_nodes; 2392 std::list<Edge> added_edges; 2393 2394 2395 void addNode(const Node& node) { 2396 added_nodes.push_front(node); 2397 } 2398 void eraseNode(const Node& node) { 2399 std::list<Node>::iterator it = 2400 std::find(added_nodes.begin(), added_nodes.end(), node); 2401 if (it == added_nodes.end()) { 2402 clear(); 2403 edge_observer_proxy.detach(); 2404 throw NodeNotifier::ImmediateDetach(); 2405 } else { 2406 added_nodes.erase(it); 2407 } 2408 } 2409 2410 void addEdge(const Edge& edge) { 2411 added_edges.push_front(edge); 2412 } 2413 void eraseEdge(const Edge& edge) { 2414 std::list<Edge>::iterator it = 2415 std::find(added_edges.begin(), added_edges.end(), edge); 2416 if (it == added_edges.end()) { 2417 clear(); 2418 node_observer_proxy.detach(); 2419 throw EdgeNotifier::ImmediateDetach(); 2420 } else { 2421 added_edges.erase(it); 2422 } 2423 } 2424 2425 void attach(ListBpGraph &_graph) { 2426 graph = &_graph; 2427 node_observer_proxy.attach(graph->notifier(Node())); 2428 edge_observer_proxy.attach(graph->notifier(Edge())); 2429 } 2430 2431 void detach() { 2432 node_observer_proxy.detach(); 2433 edge_observer_proxy.detach(); 2434 } 2435 2436 bool attached() const { 2437 return node_observer_proxy.attached(); 2438 } 2439 2440 void clear() { 2441 added_nodes.clear(); 2442 added_edges.clear(); 2443 } 2444 2445 public: 2446 2447 /// \brief Default constructor. 2448 /// 2449 /// Default constructor. 2450 /// You have to call save() to actually make a snapshot. 2451 Snapshot() 2452 : graph(0), node_observer_proxy(*this), 2453 edge_observer_proxy(*this) {} 2454 2455 /// \brief Constructor that immediately makes a snapshot. 2456 /// 2457 /// This constructor immediately makes a snapshot of the given graph. 2458 Snapshot(ListBpGraph &gr) 2459 : node_observer_proxy(*this), 2460 edge_observer_proxy(*this) { 2461 attach(gr); 2462 } 2463 2464 /// \brief Make a snapshot. 2465 /// 2466 /// This function makes a snapshot of the given graph. 2467 /// It can be called more than once. In case of a repeated 2468 /// call, the previous snapshot gets lost. 2469 void save(ListBpGraph &gr) { 2470 if (attached()) { 2471 detach(); 2472 clear(); 2473 } 2474 attach(gr); 2475 } 2476 2477 /// \brief Undo the changes until the last snapshot. 2478 /// 2479 /// This function undos the changes until the last snapshot 2480 /// created by save() or Snapshot(ListBpGraph&). 2481 /// 2482 /// \warning This method invalidates the snapshot, i.e. repeated 2483 /// restoring is not supported unless you call save() again. 2484 void restore() { 2485 detach(); 2486 for(std::list<Edge>::iterator it = added_edges.begin(); 2487 it != added_edges.end(); ++it) { 2488 graph->erase(*it); 2489 } 2490 for(std::list<Node>::iterator it = added_nodes.begin(); 2491 it != added_nodes.end(); ++it) { 2492 graph->erase(*it); 2493 } 2494 clear(); 2495 } 2496 2497 /// \brief Returns \c true if the snapshot is valid. 2498 /// 2499 /// This function returns \c true if the snapshot is valid. 2500 bool valid() const { 2501 return attached(); 2502 } 2503 }; 2504 }; 2505 2506 /// @} 1602 2507 } //namespace lemon 1603 2508 -
lemon/lp.h
r956 r1340 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 23 23 24 24 25 #if def LEMON_HAVE_GLPK25 #if LEMON_DEFAULT_LP == LEMON_GLPK_ || LEMON_DEFAULT_MIP == LEMON_GLPK_ 26 26 #include <lemon/glpk.h> 27 #elif LEMON_HAVE_CPLEX 27 #endif 28 #if LEMON_DEFAULT_LP == LEMON_CPLEX_ || LEMON_DEFAULT_MIP == LEMON_CPLEX_ 28 29 #include <lemon/cplex.h> 29 #elif LEMON_HAVE_SOPLEX 30 #endif 31 #if LEMON_DEFAULT_LP == LEMON_SOPLEX_ 30 32 #include <lemon/soplex.h> 31 #elif LEMON_HAVE_CLP 33 #endif 34 #if LEMON_DEFAULT_LP == LEMON_CLP_ 32 35 #include <lemon/clp.h> 36 #endif 37 #if LEMON_DEFAULT_MIP == LEMON_CBC_ 38 #include <lemon/cbc.h> 33 39 #endif 34 40 … … 44 50 ///\ingroup lp_group 45 51 /// 46 ///Currently, the possible values are \c GLPK, \c CPLEX,47 ///\c SOPLEX or \c CLP52 ///Currently, the possible values are \c LEMON_GLPK_, \c LEMON_CPLEX_, 53 ///\c LEMON_SOPLEX_ or \c LEMON_CLP_ 48 54 #define LEMON_DEFAULT_LP SOLVER 49 55 ///The default LP solver … … 60 66 ///\ingroup lp_group 61 67 /// 62 ///Currently, the possible values are \c GLPK or \c CPLEX 68 ///Currently, the possible values are \c LEMON_GLPK_, \c LEMON_CPLEX_ 69 ///or \c LEMON_CBC_ 63 70 #define LEMON_DEFAULT_MIP SOLVER 64 71 ///The default MIP solver. … … 67 74 ///\ingroup lp_group 68 75 /// 69 ///Currently, it is either \c GlpkMip or \c CplexMip76 ///Currently, it is either \c GlpkMip, \c CplexMip , \c CbcMip 70 77 typedef GlpkMip Mip; 71 78 #else 72 #ifdef LEMON_HAVE_GLPK 73 # define LEMON_DEFAULT_LP GLPK 79 #if LEMON_DEFAULT_LP == LEMON_GLPK_ 74 80 typedef GlpkLp Lp; 75 # define LEMON_DEFAULT_MIP GLPK 81 #elif LEMON_DEFAULT_LP == LEMON_CPLEX_ 82 typedef CplexLp Lp; 83 #elif LEMON_DEFAULT_LP == LEMON_SOPLEX_ 84 typedef SoplexLp Lp; 85 #elif LEMON_DEFAULT_LP == LEMON_CLP_ 86 typedef ClpLp Lp; 87 #endif 88 #if LEMON_DEFAULT_MIP == LEMON_GLPK_ 76 89 typedef GlpkMip Mip; 77 #elif LEMON_HAVE_CPLEX 78 # define LEMON_DEFAULT_LP CPLEX 79 typedef CplexLp Lp; 80 # define LEMON_DEFAULT_MIP CPLEX 90 #elif LEMON_DEFAULT_MIP == LEMON_CPLEX_ 81 91 typedef CplexMip Mip; 82 #elif LEMON_HAVE_SOPLEX 83 # define DEFAULT_LP SOPLEX 84 typedef SoplexLp Lp; 85 #elif LEMON_HAVE_CLP 86 # define DEFAULT_LP CLP 87 typedef ClpLp Lp; 92 #elif LEMON_DEFAULT_MIP == LEMON_CBC_ 93 typedef CbcMip Mip; 88 94 #endif 89 95 #endif -
lemon/lp_base.cc
r956 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). -
lemon/lp_base.h
r1143 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 1008 1008 public: 1009 1009 1010 ///Unsupported file format exception 1011 class UnsupportedFormatError : public Exception 1012 { 1013 std::string _format; 1014 mutable std::string _what; 1015 public: 1016 explicit UnsupportedFormatError(std::string format) throw() 1017 : _format(format) { } 1018 virtual ~UnsupportedFormatError() throw() {} 1019 virtual const char* what() const throw() { 1020 try { 1021 _what.clear(); 1022 std::ostringstream oss; 1023 oss << "lemon::UnsupportedFormatError: " << _format; 1024 _what = oss.str(); 1025 } 1026 catch (...) {} 1027 if (!_what.empty()) return _what.c_str(); 1028 else return "lemon::UnsupportedFormatError"; 1029 } 1030 }; 1031 1032 protected: 1033 virtual void _write(std::string, std::string format) const 1034 { 1035 throw UnsupportedFormatError(format); 1036 } 1037 1038 public: 1039 1010 1040 /// Virtual destructor 1011 1041 virtual ~LpBase() {} … … 1556 1586 void min() { _setSense(MIN); } 1557 1587 1558 ///Clear sthe problem1588 ///Clear the problem 1559 1589 void clear() { _clear(); rows.clear(); cols.clear(); } 1560 1590 1561 /// Set sthe message level of the solver1591 /// Set the message level of the solver 1562 1592 void messageLevel(MessageLevel level) { _messageLevel(level); } 1593 1594 /// Write the problem to a file in the given format 1595 1596 /// This function writes the problem to a file in the given format. 1597 /// Different solver backends may support different formats. 1598 /// Trying to write in an unsupported format will trigger 1599 /// \ref UnsupportedFormatError. For the supported formats, 1600 /// visit the documentation of the base class of the related backends 1601 /// (\ref CplexBase, \ref GlpkBase etc.) 1602 /// \param file The file path 1603 /// \param format The output file format. 1604 void write(std::string file, std::string format = "MPS") const 1605 { 1606 _write(file.c_str(),format.c_str()); 1607 } 1563 1608 1564 1609 ///@} -
lemon/lp_skeleton.cc
r956 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 92 92 void SkeletonSolverBase::_messageLevel(MessageLevel) {} 93 93 94 void SkeletonSolverBase::_write(std::string, std::string) const {} 95 94 96 LpSkeleton::SolveExitStatus LpSkeleton::_solve() { return SOLVED; } 95 97 -
lemon/lp_skeleton.h
r956 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 145 145 ///\e 146 146 virtual void _messageLevel(MessageLevel); 147 148 ///\e 149 virtual void _write(std::string file, std::string format) const; 150 147 151 }; 148 152 … … 223 227 ///\e 224 228 virtual const char* _solverName() const; 229 225 230 }; 226 231 -
lemon/maps.h
r1057 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). -
lemon/matching.h
r956 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). -
lemon/math.h
r956 r1311 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 66 66 } 67 67 68 ///Round a value to its closest integer 69 inline double round(double r) { 70 return (r > 0.0) ? std::floor(r + 0.5) : std::ceil(r - 0.5); 71 } 72 68 73 /// @} 69 74 70 75 } //namespace lemon 71 76 72 #endif //LEMON_ TOLERANCE_H77 #endif //LEMON_MATH_H -
lemon/min_cost_arborescence.h
r956 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 102 102 /// the minimum cost subgraph that is the union of arborescences with the 103 103 /// given sources and spans all the nodes which are reachable from the 104 /// sources. The time complexity of the algorithm is O(n<sup>2</sup>+ e).104 /// sources. The time complexity of the algorithm is O(n<sup>2</sup>+m). 105 105 /// 106 106 /// The algorithm also provides an optimal dual solution, therefore … … 129 129 public: 130 130 131 /// \brief The \ref MinCostArborescenceDefaultTraits "traits class"131 /// \brief The \ref lemon::MinCostArborescenceDefaultTraits "traits class" 132 132 /// of the algorithm. 133 133 typedef TR Traits; -
lemon/network_simplex.h
r978 r1318 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 42 42 /// \ref NetworkSimplex implements the primal Network Simplex algorithm 43 43 /// for finding a \ref min_cost_flow "minimum cost flow" 44 /// \ ref amo93networkflows, \refdantzig63linearprog,45 /// \ refkellyoneill91netsimplex.44 /// \cite amo93networkflows, \cite dantzig63linearprog, 45 /// \cite kellyoneill91netsimplex. 46 46 /// This algorithm is a highly efficient specialized version of the 47 47 /// linear programming simplex method directly for the minimum cost 48 48 /// flow problem. 49 49 /// 50 /// In general, %NetworkSimplex is the fastest implementation available 51 /// in LEMON for this problem. 52 /// Moreover, it supports both directions of the supply/demand inequality 53 /// constraints. For more information, see \ref SupplyType. 50 /// In general, \ref NetworkSimplex and \ref CostScaling are the fastest 51 /// implementations available in LEMON for solving this problem. 52 /// (For more information, see \ref min_cost_flow_algs "the module page".) 53 /// Furthermore, this class supports both directions of the supply/demand 54 /// inequality constraints. For more information, see \ref SupplyType. 54 55 /// 55 56 /// Most of the parameters of the problem (except for the digraph) … … 64 65 /// algorithm. By default, it is the same as \c V. 65 66 /// 66 /// \warning Both number types must be signed and all input data must 67 /// \warning Both \c V and \c C must be signed number types. 68 /// \warning All input data (capacities, supply values, and costs) must 67 69 /// be integer. 68 70 /// … … 122 124 /// the \ref run() function. 123 125 /// 124 /// \ref NetworkSimplex provides five different pivot rule125 /// implementations that significantly affectthe running time126 /// \ref NetworkSimplex provides five different implementations for 127 /// the pivot strategy that significantly affects the running time 126 128 /// of the algorithm. 127 /// By default, \ref BLOCK_SEARCH "Block Search" is used, which 128 /// proved to be the most efficient and the most robust on various 129 /// test inputs. 130 /// However, another pivot rule can be selected using the \ref run() 131 /// function with the proper parameter. 129 /// According to experimental tests conducted on various problem 130 /// instances, \ref BLOCK_SEARCH "Block Search" and 131 /// \ref ALTERING_LIST "Altering Candidate List" rules turned out 132 /// to be the most efficient. 133 /// Since \ref BLOCK_SEARCH "Block Search" is a simpler strategy that 134 /// seemed to be slightly more robust, it is used by default. 135 /// However, another pivot rule can easily be selected using the 136 /// \ref run() function with the proper parameter. 132 137 enum PivotRule { 133 138 … … 155 160 /// The \e Altering \e Candidate \e List pivot rule. 156 161 /// It is a modified version of the Candidate List method. 157 /// It keeps only the severalbest eligible arcs from the former162 /// It keeps only a few of the best eligible arcs from the former 158 163 /// candidate list and extends this list in every iteration. 159 164 ALTERING_LIST … … 167 172 typedef std::vector<Value> ValueVector; 168 173 typedef std::vector<Cost> CostVector; 169 typedef std::vector<char> BoolVector; 170 // Note: vector<char> is used instead of vector<bool> for efficiency reasons 174 typedef std::vector<signed char> CharVector; 175 // Note: vector<signed char> is used instead of vector<ArcState> and 176 // vector<ArcDirection> for efficiency reasons 171 177 172 178 // State constants for arcs … … 177 183 }; 178 184 179 typedef std::vector<signed char> StateVector; 180 // Note: vector<signed char> is used instead of vector<ArcState> for 181 // efficiency reasons 185 // Direction constants for tree arcs 186 enum ArcDirection { 187 DIR_DOWN = -1, 188 DIR_UP = 1 189 }; 182 190 183 191 private: … … 191 199 192 200 // Parameters of the problem 193 bool _ha ve_lower;201 bool _has_lower; 194 202 SupplyType _stype; 195 203 Value _sum_supply; … … 218 226 IntVector _succ_num; 219 227 IntVector _last_succ; 228 CharVector _pred_dir; 229 CharVector _state; 220 230 IntVector _dirty_revs; 221 BoolVector _forward;222 StateVector _state;223 231 int _root; 224 232 225 233 // Temporary data used in the current pivot iteration 226 234 int in_arc, join, u_in, v_in, u_out, v_out; 227 int first, second, right, last;228 int stem, par_stem, new_stem;229 235 Value delta; 230 236 … … 251 257 const IntVector &_target; 252 258 const CostVector &_cost; 253 const StateVector &_state;259 const CharVector &_state; 254 260 const CostVector &_pi; 255 261 int &_in_arc; … … 303 309 const IntVector &_target; 304 310 const CostVector &_cost; 305 const StateVector &_state;311 const CharVector &_state; 306 312 const CostVector &_pi; 307 313 int &_in_arc; … … 342 348 const IntVector &_target; 343 349 const CostVector &_cost; 344 const StateVector &_state;350 const CharVector &_state; 345 351 const CostVector &_pi; 346 352 int &_in_arc; … … 415 421 const IntVector &_target; 416 422 const CostVector &_cost; 417 const StateVector &_state;423 const CharVector &_state; 418 424 const CostVector &_pi; 419 425 int &_in_arc; … … 518 524 const IntVector &_target; 519 525 const CostVector &_cost; 520 const StateVector &_state;526 const CharVector &_state; 521 527 const CostVector &_pi; 522 528 int &_in_arc; … … 537 543 SortFunc(const CostVector &map) : _map(map) {} 538 544 bool operator()(int left, int right) { 539 return _map[left] >_map[right];545 return _map[left] < _map[right]; 540 546 } 541 547 }; … … 555 561 const double BLOCK_SIZE_FACTOR = 1.0; 556 562 const int MIN_BLOCK_SIZE = 10; 557 const double HEAD_LENGTH_FACTOR = 0. 1;563 const double HEAD_LENGTH_FACTOR = 0.01; 558 564 const int MIN_HEAD_LENGTH = 3; 559 565 … … 571 577 // Check the current candidate list 572 578 int e; 579 Cost c; 573 580 for (int i = 0; i != _curr_length; ++i) { 574 581 e = _candidates[i]; 575 _cand_cost[e] = _state[e] * 576 (_cost[e] + _pi[_source[e]] - _pi[_target[e]]); 577 if (_cand_cost[e] >= 0) { 582 c = _state[e] * (_cost[e] + _pi[_source[e]] - _pi[_target[e]]); 583 if (c < 0) { 584 _cand_cost[e] = c; 585 } else { 578 586 _candidates[i--] = _candidates[--_curr_length]; 579 587 } … … 585 593 586 594 for (e = _next_arc; e != _search_arc_num; ++e) { 587 _cand_cost[e] = _state[e] *588 (_cost[e] + _pi[_source[e]] - _pi[_target[e]]);589 if (_cand_cost[e] < 0) {595 c = _state[e] * (_cost[e] + _pi[_source[e]] - _pi[_target[e]]); 596 if (c < 0) { 597 _cand_cost[e] = c; 590 598 _candidates[_curr_length++] = e; 591 599 } … … 597 605 } 598 606 for (e = 0; e != _next_arc; ++e) { 599 _cand_cost[e] = _state[e] *600 (_cost[e] + _pi[_source[e]] - _pi[_target[e]]);601 if (_cand_cost[e] < 0) {607 c = _state[e] * (_cost[e] + _pi[_source[e]] - _pi[_target[e]]); 608 if (c < 0) { 609 _cand_cost[e] = c; 602 610 _candidates[_curr_length++] = e; 603 611 } … … 612 620 search_end: 613 621 614 // Make heap of the candidate list (approximating a partial sort) 615 make_heap( _candidates.begin(), _candidates.begin() + _curr_length, 616 _sort_func ); 617 618 // Pop the first element of the heap 622 // Perform partial sort operation on the candidate list 623 int new_length = std::min(_head_length + 1, _curr_length); 624 std::partial_sort(_candidates.begin(), _candidates.begin() + new_length, 625 _candidates.begin() + _curr_length, _sort_func); 626 627 // Select the entering arc and remove it from the list 619 628 _in_arc = _candidates[0]; 620 629 _next_arc = e; 621 pop_heap( _candidates.begin(), _candidates.begin() + _curr_length, 622 _sort_func ); 623 _curr_length = std::min(_head_length, _curr_length - 1); 630 _candidates[0] = _candidates[new_length - 1]; 631 _curr_length = new_length - 1; 624 632 return true; 625 633 } … … 634 642 /// 635 643 /// \param graph The digraph the algorithm runs on. 636 /// \param arc_mixing Indicate if the arcs have tobe stored in a644 /// \param arc_mixing Indicate if the arcs will be stored in a 637 645 /// mixed order in the internal data structure. 638 /// In special cases, it could lead to better overall performance, 639 /// but it is usually slower. Therefore it is disabled by default. 640 NetworkSimplex(const GR& graph, bool arc_mixing = false) : 646 /// In general, it leads to similar performance as using the original 647 /// arc order, but it makes the algorithm more robust and in special 648 /// cases, even significantly faster. Therefore, it is enabled by default. 649 NetworkSimplex(const GR& graph, bool arc_mixing = true) : 641 650 _graph(graph), _node_id(graph), _arc_id(graph), 642 651 _arc_mixing(arc_mixing), … … 674 683 template <typename LowerMap> 675 684 NetworkSimplex& lowerMap(const LowerMap& map) { 676 _ha ve_lower = true;685 _has_lower = true; 677 686 for (ArcIt a(_graph); a != INVALID; ++a) { 678 687 _lower[_arc_id[a]] = map[a]; … … 731 740 /// 732 741 /// \return <tt>(*this)</tt> 742 /// 743 /// \sa supplyType() 733 744 template<typename SupplyMap> 734 745 NetworkSimplex& supplyMap(const SupplyMap& map) { … … 747 758 /// 748 759 /// Using this function has the same effect as using \ref supplyMap() 749 /// with sucha map in which \c k is assigned to \c s, \c -k is760 /// with a map in which \c k is assigned to \c s, \c -k is 750 761 /// assigned to \c t and all other nodes have zero supply value. 751 762 /// … … 869 880 _cost[i] = 1; 870 881 } 871 _ha ve_lower = false;882 _has_lower = false; 872 883 _stype = GEQ; 873 884 return *this; … … 914 925 _parent.resize(all_node_num); 915 926 _pred.resize(all_node_num); 916 _ forward.resize(all_node_num);927 _pred_dir.resize(all_node_num); 917 928 _thread.resize(all_node_num); 918 929 _rev_thread.resize(all_node_num); … … 926 937 _node_id[n] = i; 927 938 } 928 if (_arc_mixing ) {939 if (_arc_mixing && _node_num > 1) { 929 940 // Store the arcs in a mixed order 930 int k = std::max(int(std::sqrt(double(_arc_num))), 10);941 const int skip = std::max(_arc_num / _node_num, 3); 931 942 int i = 0, j = 0; 932 943 for (ArcIt a(_graph); a != INVALID; ++a) { … … 934 945 _source[i] = _node_id[_graph.source(a)]; 935 946 _target[i] = _node_id[_graph.target(a)]; 936 if ((i += k) >= _arc_num) i = ++j;947 if ((i += skip) >= _arc_num) i = ++j; 937 948 } 938 949 } else { … … 963 974 /// 964 975 /// This function returns the total cost of the found flow. 965 /// Its complexity is O( e).976 /// Its complexity is O(m). 966 977 /// 967 978 /// \note The return type of the function can be specified as a … … 1000 1011 } 1001 1012 1002 /// \brief Return the flow map (the primal solution). 1013 /// \brief Copy the flow values (the primal solution) into the 1014 /// given map. 1003 1015 /// 1004 1016 /// This function copies the flow value on each arc into the given … … 1024 1036 } 1025 1037 1026 /// \brief Return the potential map (the dual solution). 1038 /// \brief Copy the potential values (the dual solution) into the 1039 /// given map. 1027 1040 /// 1028 1041 /// This function copies the potential (dual value) of each node … … 1055 1068 (_stype == LEQ && _sum_supply >= 0)) ) return false; 1056 1069 1070 // Check lower and upper bounds 1071 LEMON_DEBUG(checkBoundMaps(), 1072 "Upper bounds must be greater or equal to the lower bounds"); 1073 1057 1074 // Remove non-zero lower bounds 1058 if (_ha ve_lower) {1075 if (_has_lower) { 1059 1076 for (int i = 0; i != _arc_num; ++i) { 1060 1077 Value c = _lower[i]; … … 1117 1134 _state[e] = STATE_TREE; 1118 1135 if (_supply[u] >= 0) { 1119 _ forward[u] = true;1136 _pred_dir[u] = DIR_UP; 1120 1137 _pi[u] = 0; 1121 1138 _source[e] = u; … … 1124 1141 _cost[e] = 0; 1125 1142 } else { 1126 _ forward[u] = false;1143 _pred_dir[u] = DIR_DOWN; 1127 1144 _pi[u] = ART_COST; 1128 1145 _source[e] = _root; … … 1144 1161 _last_succ[u] = u; 1145 1162 if (_supply[u] >= 0) { 1146 _ forward[u] = true;1163 _pred_dir[u] = DIR_UP; 1147 1164 _pi[u] = 0; 1148 1165 _pred[u] = e; … … 1154 1171 _state[e] = STATE_TREE; 1155 1172 } else { 1156 _ forward[u] = false;1173 _pred_dir[u] = DIR_DOWN; 1157 1174 _pi[u] = ART_COST; 1158 1175 _pred[u] = f; … … 1185 1202 _last_succ[u] = u; 1186 1203 if (_supply[u] <= 0) { 1187 _ forward[u] = false;1204 _pred_dir[u] = DIR_DOWN; 1188 1205 _pi[u] = 0; 1189 1206 _pred[u] = e; … … 1195 1212 _state[e] = STATE_TREE; 1196 1213 } else { 1197 _ forward[u] = true;1214 _pred_dir[u] = DIR_UP; 1198 1215 _pi[u] = -ART_COST; 1199 1216 _pred[u] = f; … … 1219 1236 } 1220 1237 1238 // Check if the upper bound is greater than or equal to the lower bound 1239 // on each arc. 1240 bool checkBoundMaps() { 1241 for (int j = 0; j != _arc_num; ++j) { 1242 if (_upper[j] < _lower[j]) return false; 1243 } 1244 return true; 1245 } 1246 1221 1247 // Find the join node 1222 1248 void findJoinNode() { … … 1238 1264 // Initialize first and second nodes according to the direction 1239 1265 // of the cycle 1266 int first, second; 1240 1267 if (_state[in_arc] == STATE_LOWER) { 1241 1268 first = _source[in_arc]; … … 1247 1274 delta = _cap[in_arc]; 1248 1275 int result = 0; 1249 Value d;1276 Value c, d; 1250 1277 int e; 1251 1278 1252 // Search the cycle along the path form the first node to the root1279 // Search the cycle form the first node to the join node 1253 1280 for (int u = first; u != join; u = _parent[u]) { 1254 1281 e = _pred[u]; 1255 d = _forward[u] ? 1256 _flow[e] : (_cap[e] >= MAX ? INF : _cap[e] - _flow[e]); 1282 d = _flow[e]; 1283 if (_pred_dir[u] == DIR_DOWN) { 1284 c = _cap[e]; 1285 d = c >= MAX ? INF : c - d; 1286 } 1257 1287 if (d < delta) { 1258 1288 delta = d; … … 1261 1291 } 1262 1292 } 1263 // Search the cycle along the path form the second node to the root 1293 1294 // Search the cycle form the second node to the join node 1264 1295 for (int u = second; u != join; u = _parent[u]) { 1265 1296 e = _pred[u]; 1266 d = _forward[u] ? 1267 (_cap[e] >= MAX ? INF : _cap[e] - _flow[e]) : _flow[e]; 1297 d = _flow[e]; 1298 if (_pred_dir[u] == DIR_UP) { 1299 c = _cap[e]; 1300 d = c >= MAX ? INF : c - d; 1301 } 1268 1302 if (d <= delta) { 1269 1303 delta = d; … … 1290 1324 _flow[in_arc] += val; 1291 1325 for (int u = _source[in_arc]; u != join; u = _parent[u]) { 1292 _flow[_pred[u]] += _forward[u] ? -val :val;1326 _flow[_pred[u]] -= _pred_dir[u] * val; 1293 1327 } 1294 1328 for (int u = _target[in_arc]; u != join; u = _parent[u]) { 1295 _flow[_pred[u]] += _ forward[u] ? val : -val;1329 _flow[_pred[u]] += _pred_dir[u] * val; 1296 1330 } 1297 1331 } … … 1308 1342 // Update the tree structure 1309 1343 void updateTreeStructure() { 1310 int u, w;1311 1344 int old_rev_thread = _rev_thread[u_out]; 1312 1345 int old_succ_num = _succ_num[u_out]; … … 1314 1347 v_out = _parent[u_out]; 1315 1348 1316 u = _last_succ[u_in]; // the last successor of u_in 1317 right = _thread[u]; // the node after it 1318 1319 // Handle the case when old_rev_thread equals to v_in 1320 // (it also means that join and v_out coincide) 1321 if (old_rev_thread == v_in) { 1322 last = _thread[_last_succ[u_out]]; 1349 // Check if u_in and u_out coincide 1350 if (u_in == u_out) { 1351 // Update _parent, _pred, _pred_dir 1352 _parent[u_in] = v_in; 1353 _pred[u_in] = in_arc; 1354 _pred_dir[u_in] = u_in == _source[in_arc] ? DIR_UP : DIR_DOWN; 1355 1356 // Update _thread and _rev_thread 1357 if (_thread[v_in] != u_out) { 1358 int after = _thread[old_last_succ]; 1359 _thread[old_rev_thread] = after; 1360 _rev_thread[after] = old_rev_thread; 1361 after = _thread[v_in]; 1362 _thread[v_in] = u_out; 1363 _rev_thread[u_out] = v_in; 1364 _thread[old_last_succ] = after; 1365 _rev_thread[after] = old_last_succ; 1366 } 1323 1367 } else { 1324 last = _thread[v_in]; 1325 } 1326 1327 // Update _thread and _parent along the stem nodes (i.e. the nodes 1328 // between u_in and u_out, whose parent have to be changed) 1329 _thread[v_in] = stem = u_in; 1330 _dirty_revs.clear(); 1331 _dirty_revs.push_back(v_in); 1332 par_stem = v_in; 1333 while (stem != u_out) { 1334 // Insert the next stem node into the thread list 1335 new_stem = _parent[stem]; 1336 _thread[u] = new_stem; 1337 _dirty_revs.push_back(u); 1338 1339 // Remove the subtree of stem from the thread list 1340 w = _rev_thread[stem]; 1341 _thread[w] = right; 1342 _rev_thread[right] = w; 1343 1344 // Change the parent node and shift stem nodes 1345 _parent[stem] = par_stem; 1346 par_stem = stem; 1347 stem = new_stem; 1348 1349 // Update u and right 1350 u = _last_succ[stem] == _last_succ[par_stem] ? 1351 _rev_thread[par_stem] : _last_succ[stem]; 1352 right = _thread[u]; 1353 } 1354 _parent[u_out] = par_stem; 1355 _thread[u] = last; 1356 _rev_thread[last] = u; 1357 _last_succ[u_out] = u; 1358 1359 // Remove the subtree of u_out from the thread list except for 1360 // the case when old_rev_thread equals to v_in 1361 // (it also means that join and v_out coincide) 1362 if (old_rev_thread != v_in) { 1363 _thread[old_rev_thread] = right; 1364 _rev_thread[right] = old_rev_thread; 1365 } 1366 1367 // Update _rev_thread using the new _thread values 1368 for (int i = 0; i != int(_dirty_revs.size()); ++i) { 1369 u = _dirty_revs[i]; 1370 _rev_thread[_thread[u]] = u; 1371 } 1372 1373 // Update _pred, _forward, _last_succ and _succ_num for the 1374 // stem nodes from u_out to u_in 1375 int tmp_sc = 0, tmp_ls = _last_succ[u_out]; 1376 u = u_out; 1377 while (u != u_in) { 1378 w = _parent[u]; 1379 _pred[u] = _pred[w]; 1380 _forward[u] = !_forward[w]; 1381 tmp_sc += _succ_num[u] - _succ_num[w]; 1382 _succ_num[u] = tmp_sc; 1383 _last_succ[w] = tmp_ls; 1384 u = w; 1385 } 1386 _pred[u_in] = in_arc; 1387 _forward[u_in] = (u_in == _source[in_arc]); 1388 _succ_num[u_in] = old_succ_num; 1389 1390 // Set limits for updating _last_succ form v_in and v_out 1391 // towards the root 1392 int up_limit_in = -1; 1393 int up_limit_out = -1; 1394 if (_last_succ[join] == v_in) { 1395 up_limit_out = join; 1396 } else { 1397 up_limit_in = join; 1368 // Handle the case when old_rev_thread equals to v_in 1369 // (it also means that join and v_out coincide) 1370 int thread_continue = old_rev_thread == v_in ? 1371 _thread[old_last_succ] : _thread[v_in]; 1372 1373 // Update _thread and _parent along the stem nodes (i.e. the nodes 1374 // between u_in and u_out, whose parent have to be changed) 1375 int stem = u_in; // the current stem node 1376 int par_stem = v_in; // the new parent of stem 1377 int next_stem; // the next stem node 1378 int last = _last_succ[u_in]; // the last successor of stem 1379 int before, after = _thread[last]; 1380 _thread[v_in] = u_in; 1381 _dirty_revs.clear(); 1382 _dirty_revs.push_back(v_in); 1383 while (stem != u_out) { 1384 // Insert the next stem node into the thread list 1385 next_stem = _parent[stem]; 1386 _thread[last] = next_stem; 1387 _dirty_revs.push_back(last); 1388 1389 // Remove the subtree of stem from the thread list 1390 before = _rev_thread[stem]; 1391 _thread[before] = after; 1392 _rev_thread[after] = before; 1393 1394 // Change the parent node and shift stem nodes 1395 _parent[stem] = par_stem; 1396 par_stem = stem; 1397 stem = next_stem; 1398 1399 // Update last and after 1400 last = _last_succ[stem] == _last_succ[par_stem] ? 1401 _rev_thread[par_stem] : _last_succ[stem]; 1402 after = _thread[last]; 1403 } 1404 _parent[u_out] = par_stem; 1405 _thread[last] = thread_continue; 1406 _rev_thread[thread_continue] = last; 1407 _last_succ[u_out] = last; 1408 1409 // Remove the subtree of u_out from the thread list except for 1410 // the case when old_rev_thread equals to v_in 1411 if (old_rev_thread != v_in) { 1412 _thread[old_rev_thread] = after; 1413 _rev_thread[after] = old_rev_thread; 1414 } 1415 1416 // Update _rev_thread using the new _thread values 1417 for (int i = 0; i != int(_dirty_revs.size()); ++i) { 1418 int u = _dirty_revs[i]; 1419 _rev_thread[_thread[u]] = u; 1420 } 1421 1422 // Update _pred, _pred_dir, _last_succ and _succ_num for the 1423 // stem nodes from u_out to u_in 1424 int tmp_sc = 0, tmp_ls = _last_succ[u_out]; 1425 for (int u = u_out, p = _parent[u]; u != u_in; u = p, p = _parent[u]) { 1426 _pred[u] = _pred[p]; 1427 _pred_dir[u] = -_pred_dir[p]; 1428 tmp_sc += _succ_num[u] - _succ_num[p]; 1429 _succ_num[u] = tmp_sc; 1430 _last_succ[p] = tmp_ls; 1431 } 1432 _pred[u_in] = in_arc; 1433 _pred_dir[u_in] = u_in == _source[in_arc] ? DIR_UP : DIR_DOWN; 1434 _succ_num[u_in] = old_succ_num; 1398 1435 } 1399 1436 1400 1437 // Update _last_succ from v_in towards the root 1401 for (u = v_in; u != up_limit_in && _last_succ[u] == v_in; 1402 u = _parent[u]) { 1403 _last_succ[u] = _last_succ[u_out]; 1404 } 1438 int up_limit_out = _last_succ[join] == v_in ? join : -1; 1439 int last_succ_out = _last_succ[u_out]; 1440 for (int u = v_in; u != -1 && _last_succ[u] == v_in; u = _parent[u]) { 1441 _last_succ[u] = last_succ_out; 1442 } 1443 1405 1444 // Update _last_succ from v_out towards the root 1406 1445 if (join != old_rev_thread && v_in != old_rev_thread) { 1407 for ( u = v_out; u != up_limit_out && _last_succ[u] == old_last_succ;1446 for (int u = v_out; u != up_limit_out && _last_succ[u] == old_last_succ; 1408 1447 u = _parent[u]) { 1409 1448 _last_succ[u] = old_rev_thread; 1410 1449 } 1411 } else { 1412 for (u = v_out; u != up_limit_out && _last_succ[u] == old_last_succ; 1450 } 1451 else if (last_succ_out != old_last_succ) { 1452 for (int u = v_out; u != up_limit_out && _last_succ[u] == old_last_succ; 1413 1453 u = _parent[u]) { 1414 _last_succ[u] = _last_succ[u_out];1454 _last_succ[u] = last_succ_out; 1415 1455 } 1416 1456 } 1417 1457 1418 1458 // Update _succ_num from v_in to join 1419 for ( u = v_in; u != join; u = _parent[u]) {1459 for (int u = v_in; u != join; u = _parent[u]) { 1420 1460 _succ_num[u] += old_succ_num; 1421 1461 } 1422 1462 // Update _succ_num from v_out to join 1423 for ( u = v_out; u != join; u = _parent[u]) {1463 for (int u = v_out; u != join; u = _parent[u]) { 1424 1464 _succ_num[u] -= old_succ_num; 1425 1465 } 1426 1466 } 1427 1467 1428 // Update potentials 1468 // Update potentials in the subtree that has been moved 1429 1469 void updatePotential() { 1430 Cost sigma = _forward[u_in] ? 1431 _pi[v_in] - _pi[u_in] - _cost[_pred[u_in]] : 1432 _pi[v_in] - _pi[u_in] + _cost[_pred[u_in]]; 1433 // Update potentials in the subtree, which has been moved 1470 Cost sigma = _pi[v_in] - _pi[u_in] - 1471 _pred_dir[u_in] * _cost[in_arc]; 1434 1472 int end = _thread[_last_succ[u_in]]; 1435 1473 for (int u = u_in; u != end; u = _thread[u]) { … … 1479 1517 } 1480 1518 } else { 1481 // Find the min. cost incom ming arc for each demand node1519 // Find the min. cost incoming arc for each demand node 1482 1520 for (int i = 0; i != int(demand_nodes.size()); ++i) { 1483 1521 Node v = demand_nodes[i]; … … 1575 1613 1576 1614 // Transform the solution and the supply map to the original form 1577 if (_ha ve_lower) {1615 if (_has_lower) { 1578 1616 for (int i = 0; i != _arc_num; ++i) { 1579 1617 Value c = _lower[i]; -
lemon/path.h
r1146 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 44 44 /// 45 45 /// In a sense, the path can be treated as a list of arcs. The 46 /// lemonpath type stores just this list. As a consequence, it46 /// LEMON path type stores just this list. As a consequence, it 47 47 /// cannot enumerate the nodes of the path and the source node of 48 48 /// a zero length path is undefined. … … 149 149 void clear() { head.clear(); tail.clear(); } 150 150 151 /// \brief The n th arc.151 /// \brief The n-th arc. 152 152 /// 153 153 /// \pre \c n is in the <tt>[0..length() - 1]</tt> range. … … 157 157 } 158 158 159 /// \brief Initialize arc iterator to point to the n th arc159 /// \brief Initialize arc iterator to point to the n-th arc 160 160 /// 161 161 /// \pre \c n is in the <tt>[0..length() - 1]</tt> range. … … 245 245 /// 246 246 /// In a sense, the path can be treated as a list of arcs. The 247 /// lemonpath type stores just this list. As a consequence it247 /// LEMON path type stores just this list. As a consequence it 248 248 /// cannot enumerate the nodes in the path and the zero length paths 249 249 /// cannot store the source. … … 318 318 /// Constructor with starting point 319 319 ArcIt(const SimplePath &_path, int _idx) 320 : idx(_idx), path(&_path) {}320 : path(&_path), idx(_idx) {} 321 321 322 322 public: … … 354 354 void clear() { data.clear(); } 355 355 356 /// \brief The n th arc.356 /// \brief The n-th arc. 357 357 /// 358 358 /// \pre \c n is in the <tt>[0..length() - 1]</tt> range. … … 361 361 } 362 362 363 /// \brief Initializes arc iterator to point to the n th arc.363 /// \brief Initializes arc iterator to point to the n-th arc. 364 364 ArcIt nthIt(int n) const { 365 365 return ArcIt(*this, n); … … 422 422 /// 423 423 /// In a sense, the path can be treated as a list of arcs. The 424 /// lemonpath type stores just this list. As a consequence it424 /// LEMON path type stores just this list. As a consequence it 425 425 /// cannot enumerate the nodes in the path and the zero length paths 426 426 /// cannot store the source. … … 544 544 }; 545 545 546 /// \brief The n th arc.547 /// 548 /// This function looks for the n th arc in O(n) time.546 /// \brief The n-th arc. 547 /// 548 /// This function looks for the n-th arc in O(n) time. 549 549 /// \pre \c n is in the <tt>[0..length() - 1]</tt> range. 550 550 const Arc& nth(int n) const { … … 556 556 } 557 557 558 /// \brief Initializes arc iterator to point to the n th arc.558 /// \brief Initializes arc iterator to point to the n-th arc. 559 559 ArcIt nthIt(int n) const { 560 560 Node *node = first; … … 775 775 /// 776 776 /// In a sense, the path can be treated as a list of arcs. The 777 /// lemonpath type stores just this list. As a consequence it777 /// LEMON path type stores just this list. As a consequence it 778 778 /// cannot enumerate the nodes in the path and the source node of 779 779 /// a zero length path is undefined. … … 884 884 }; 885 885 886 /// \brief The n th arc.886 /// \brief The n-th arc. 887 887 /// 888 888 /// \pre \c n is in the <tt>[0..length() - 1]</tt> range. … … 891 891 } 892 892 893 /// \brief The arc iterator pointing to the n th arc.893 /// \brief The arc iterator pointing to the n-th arc. 894 894 ArcIt nthIt(int n) const { 895 895 return ArcIt(*this, n); … … 1095 1095 /// 1096 1096 /// In a sense, the path can be treated as a list of arcs. The 1097 /// lemonpath type stores only this list. As a consequence, it1097 /// LEMON path type stores only this list. As a consequence, it 1098 1098 /// cannot enumerate the nodes in the path and the zero length paths 1099 1099 /// cannot have a source node. -
lemon/planarity.h
r956 r1400 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 73 73 74 74 void discover(const Arc& arc) { 75 Node source = _graph.source(arc);76 75 Node target = _graph.target(arc); 77 76 … … 2385 2384 if (!pe.run()) return false; 2386 2385 2387 run(pe );2386 run(pe.embeddingMap()); 2388 2387 return true; 2389 2388 } … … 2399 2398 void run(const EmbeddingMap& embedding) { 2400 2399 typedef SmartEdgeSet<Graph> AuxGraph; 2400 2401 if (countNodes(_graph) < 3) { 2402 int y = 0; 2403 for (typename Graph::NodeIt n(_graph); n != INVALID; ++n) { 2404 _point_map[n].x = 0; 2405 _point_map[n].y = y++; 2406 } 2407 return; 2408 } 2401 2409 2402 2410 if (3 * countNodes(_graph) - 6 == countEdges(_graph)) { -
lemon/preflow.h
r1107 r1385 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 103 103 /// This class provides an implementation of Goldberg-Tarjan's \e preflow 104 104 /// \e push-relabel algorithm producing a \ref max_flow 105 /// "flow of maximum value" in a digraph \ refclrs01algorithms,106 /// \ ref amo93networkflows, \refgoldberg88newapproach.105 /// "flow of maximum value" in a digraph \cite clrs01algorithms, 106 /// \cite amo93networkflows, \cite goldberg88newapproach. 107 107 /// The preflow algorithms are the fastest known maximum 108 108 /// flow algorithms. The current implementation uses a mixture of the 109 109 /// \e "highest label" and the \e "bound decrease" heuristics. 110 /// The worst case time complexity of the algorithm is \f$O(n^2\sqrt{ e})\f$.110 /// The worst case time complexity of the algorithm is \f$O(n^2\sqrt{m})\f$. 111 111 /// 112 112 /// The algorithm consists of two phases. After the first phase … … 135 135 public: 136 136 137 ///The \ref PreflowDefaultTraits "traits class" of the algorithm.137 ///The \ref lemon::PreflowDefaultTraits "traits class" of the algorithm. 138 138 typedef TR Traits; 139 139 ///The type of the digraph the algorithm runs on. … … 477 477 /// flow to the given \c flowMap. The \c flowMap should contain a 478 478 /// flow or at least a preflow, i.e. at each node excluding the 479 /// source node the incoming flow should greater or equal to the479 /// source node the incoming flow should be greater or equal to the 480 480 /// outgoing flow. 481 481 /// \return \c false if the given \c flowMap is not a preflow. … … 496 496 excess -= (*_flow)[e]; 497 497 } 498 if ( excess < 0&& n != _source) return false;498 if (_tolerance.negative(excess) && n != _source) return false; 499 499 (*_excess)[n] = excess; 500 500 } … … 555 555 } 556 556 } 557 for (NodeIt n(_graph); n != INVALID; ++n) 557 for (NodeIt n(_graph); n != INVALID; ++n) 558 558 if(n!=_source && n!=_target && _tolerance.positive((*_excess)[n])) 559 559 _level->activate(n); 560 560 561 561 return true; 562 562 } … … 586 586 level = _level->highestActiveLevel(); 587 587 --num; 588 588 589 589 Value excess = (*_excess)[n]; 590 590 int new_level = _level->maxLevel(); … … 640 640 (*_excess)[n] = excess; 641 641 642 if ( excess != 0) {642 if (_tolerance.nonZero(excess)) { 643 643 if (new_level + 1 < _level->maxLevel()) { 644 644 _level->liftHighestActive(new_level + 1); … … 721 721 (*_excess)[n] = excess; 722 722 723 if ( excess != 0) {723 if (_tolerance.nonZero(excess)) { 724 724 if (new_level + 1 < _level->maxLevel()) { 725 725 _level->liftActiveOn(level, new_level + 1); … … 792 792 if (!reached[n]) { 793 793 _level->dirtyTopButOne(n); 794 } else if ( (*_excess)[n] > 0&& _target != n) {794 } else if (_tolerance.positive((*_excess)[n]) && _target != n) { 795 795 _level->activate(n); 796 796 } … … 853 853 (*_excess)[n] = excess; 854 854 855 if ( excess != 0) {855 if (_tolerance.nonZero(excess)) { 856 856 if (new_level + 1 < _level->maxLevel()) { 857 857 _level->liftHighestActive(new_level + 1); -
lemon/radix_sort.h
r606 r1328 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 35 35 namespace _radix_sort_bits { 36 36 37 template <typename Iterator> 38 bool unitRange(Iterator first, Iterator last) { 39 ++first; 40 return first == last; 41 } 42 37 43 template <typename Value> 38 44 struct Identity { … … 61 67 std::iter_swap(first, last); 62 68 ++first; 63 if (!(first < last)) {64 return first;65 }66 69 while (true) { 67 70 while (!(functor(*first) & mask)) { … … 72 75 --last; 73 76 } 74 if ( !(first < last)) {77 if (unitRange(last, first)) { 75 78 return first; 76 79 } … … 98 101 std::iter_swap(first, last); 99 102 ++first; 100 if (!(first < last)) {101 return first;102 }103 103 while (true) { 104 104 while (functor(*first) < 0) { … … 109 109 --last; 110 110 } 111 if ( !(first < last)) {111 if (unitRange(last, first)) { 112 112 return first; 113 113 } … … 120 120 void radixIntroSort(Iterator first, Iterator last, 121 121 Functor functor, Value mask) { 122 while (mask != 0 && last - first > 1) {122 while (mask != 0 && first != last && !unitRange(first, last)) { 123 123 Iterator cut = radixSortPartition(first, last, functor, mask); 124 124 mask >>= 1; … … 329 329 Allocator allocator; 330 330 331 int length = st d::distance(first, last);331 int length = static_cast<int>(std::distance(first, last)); 332 332 Key* buffer = allocator.allocate(2 * length); 333 333 try { -
lemon/random.h
r631 r1396 63 63 #define LEMON_RANDOM_H 64 64 65 #include <lemon/config.h> 66 65 67 #include <algorithm> 66 68 #include <iterator> … … 72 74 #include <lemon/dim2.h> 73 75 74 #ifndef WIN3276 #ifndef LEMON_WIN32 75 77 #include <sys/time.h> 76 78 #include <ctime> … … 200 202 initState(init); 201 203 202 num = length > end - begin ? length : end - begin;204 num = static_cast<int>(length > end - begin ? length : end - begin); 203 205 while (num--) { 204 206 curr[0] = (curr[0] ^ ((curr[1] ^ (curr[1] >> (bits - 2))) * mul1)) … … 214 216 } 215 217 216 num = length - 1; cnt = length - (curr - state) - 1;218 num = length - 1; cnt = static_cast<int>(length - (curr - state) - 1); 217 219 while (num--) { 218 220 curr[0] = (curr[0] ^ ((curr[1] ^ (curr[1] >> (bits - 2))) * mul2)) … … 341 343 num = rnd() & mask; 342 344 } while (num > max); 343 return num;345 return static_cast<Result>(num); 344 346 } 345 347 }; … … 606 608 /// \return Currently always \c true. 607 609 bool seed() { 608 #ifndef WIN32610 #ifndef LEMON_WIN32 609 611 if (seedFromFile("/dev/urandom", 0)) return true; 610 612 #endif … … 626 628 /// \param offset The offset, from the file read. 627 629 /// \return \c true when the seeding successes. 628 #ifndef WIN32630 #ifndef LEMON_WIN32 629 631 bool seedFromFile(const std::string& file = "/dev/urandom", int offset = 0) 630 632 #else … … 648 650 /// \return Currently always \c true. 649 651 bool seedFromTime() { 650 #ifndef WIN32652 #ifndef LEMON_WIN32 651 653 timeval tv; 652 654 gettimeofday(&tv, 0); -
lemon/smart_graph.h
r956 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 406 406 std::vector<ArcT> arcs; 407 407 408 int first_free_arc;409 410 408 public: 411 409 … … 812 810 }; 813 811 812 class SmartBpGraphBase { 813 814 protected: 815 816 struct NodeT { 817 int first_out; 818 int partition_next; 819 int partition_index; 820 bool red; 821 }; 822 823 struct ArcT { 824 int target; 825 int next_out; 826 }; 827 828 std::vector<NodeT> nodes; 829 std::vector<ArcT> arcs; 830 831 int first_red, first_blue; 832 int max_red, max_blue; 833 834 public: 835 836 typedef SmartBpGraphBase Graph; 837 838 class Node; 839 class Arc; 840 class Edge; 841 842 class Node { 843 friend class SmartBpGraphBase; 844 protected: 845 846 int _id; 847 explicit Node(int id) { _id = id;} 848 849 public: 850 Node() {} 851 Node (Invalid) { _id = -1; } 852 bool operator==(const Node& node) const {return _id == node._id;} 853 bool operator!=(const Node& node) const {return _id != node._id;} 854 bool operator<(const Node& node) const {return _id < node._id;} 855 }; 856 857 class RedNode : public Node { 858 friend class SmartBpGraphBase; 859 protected: 860 861 explicit RedNode(int pid) : Node(pid) {} 862 863 public: 864 RedNode() {} 865 RedNode(const RedNode& node) : Node(node) {} 866 RedNode(Invalid) : Node(INVALID){} 867 }; 868 869 class BlueNode : public Node { 870 friend class SmartBpGraphBase; 871 protected: 872 873 explicit BlueNode(int pid) : Node(pid) {} 874 875 public: 876 BlueNode() {} 877 BlueNode(const BlueNode& node) : Node(node) {} 878 BlueNode(Invalid) : Node(INVALID){} 879 }; 880 881 class Edge { 882 friend class SmartBpGraphBase; 883 protected: 884 885 int _id; 886 explicit Edge(int id) { _id = id;} 887 888 public: 889 Edge() {} 890 Edge (Invalid) { _id = -1; } 891 bool operator==(const Edge& arc) const {return _id == arc._id;} 892 bool operator!=(const Edge& arc) const {return _id != arc._id;} 893 bool operator<(const Edge& arc) const {return _id < arc._id;} 894 }; 895 896 class Arc { 897 friend class SmartBpGraphBase; 898 protected: 899 900 int _id; 901 explicit Arc(int id) { _id = id;} 902 903 public: 904 operator Edge() const { 905 return _id != -1 ? edgeFromId(_id / 2) : INVALID; 906 } 907 908 Arc() {} 909 Arc (Invalid) { _id = -1; } 910 bool operator==(const Arc& arc) const {return _id == arc._id;} 911 bool operator!=(const Arc& arc) const {return _id != arc._id;} 912 bool operator<(const Arc& arc) const {return _id < arc._id;} 913 }; 914 915 916 917 SmartBpGraphBase() 918 : nodes(), arcs(), first_red(-1), first_blue(-1), 919 max_red(-1), max_blue(-1) {} 920 921 typedef True NodeNumTag; 922 typedef True EdgeNumTag; 923 typedef True ArcNumTag; 924 925 int nodeNum() const { return nodes.size(); } 926 int redNum() const { return max_red + 1; } 927 int blueNum() const { return max_blue + 1; } 928 int edgeNum() const { return arcs.size() / 2; } 929 int arcNum() const { return arcs.size(); } 930 931 int maxNodeId() const { return nodes.size()-1; } 932 int maxRedId() const { return max_red; } 933 int maxBlueId() const { return max_blue; } 934 int maxEdgeId() const { return arcs.size() / 2 - 1; } 935 int maxArcId() const { return arcs.size()-1; } 936 937 bool red(Node n) const { return nodes[n._id].red; } 938 bool blue(Node n) const { return !nodes[n._id].red; } 939 940 static RedNode asRedNodeUnsafe(Node n) { return RedNode(n._id); } 941 static BlueNode asBlueNodeUnsafe(Node n) { return BlueNode(n._id); } 942 943 Node source(Arc a) const { return Node(arcs[a._id ^ 1].target); } 944 Node target(Arc a) const { return Node(arcs[a._id].target); } 945 946 RedNode redNode(Edge e) const { 947 return RedNode(arcs[2 * e._id].target); 948 } 949 BlueNode blueNode(Edge e) const { 950 return BlueNode(arcs[2 * e._id + 1].target); 951 } 952 953 static bool direction(Arc a) { 954 return (a._id & 1) == 1; 955 } 956 957 static Arc direct(Edge e, bool d) { 958 return Arc(e._id * 2 + (d ? 1 : 0)); 959 } 960 961 void first(Node& node) const { 962 node._id = nodes.size() - 1; 963 } 964 965 static void next(Node& node) { 966 --node._id; 967 } 968 969 void first(RedNode& node) const { 970 node._id = first_red; 971 } 972 973 void next(RedNode& node) const { 974 node._id = nodes[node._id].partition_next; 975 } 976 977 void first(BlueNode& node) const { 978 node._id = first_blue; 979 } 980 981 void next(BlueNode& node) const { 982 node._id = nodes[node._id].partition_next; 983 } 984 985 void first(Arc& arc) const { 986 arc._id = arcs.size() - 1; 987 } 988 989 static void next(Arc& arc) { 990 --arc._id; 991 } 992 993 void first(Edge& arc) const { 994 arc._id = arcs.size() / 2 - 1; 995 } 996 997 static void next(Edge& arc) { 998 --arc._id; 999 } 1000 1001 void firstOut(Arc &arc, const Node& v) const { 1002 arc._id = nodes[v._id].first_out; 1003 } 1004 void nextOut(Arc &arc) const { 1005 arc._id = arcs[arc._id].next_out; 1006 } 1007 1008 void firstIn(Arc &arc, const Node& v) const { 1009 arc._id = ((nodes[v._id].first_out) ^ 1); 1010 if (arc._id == -2) arc._id = -1; 1011 } 1012 void nextIn(Arc &arc) const { 1013 arc._id = ((arcs[arc._id ^ 1].next_out) ^ 1); 1014 if (arc._id == -2) arc._id = -1; 1015 } 1016 1017 void firstInc(Edge &arc, bool& d, const Node& v) const { 1018 int de = nodes[v._id].first_out; 1019 if (de != -1) { 1020 arc._id = de / 2; 1021 d = ((de & 1) == 1); 1022 } else { 1023 arc._id = -1; 1024 d = true; 1025 } 1026 } 1027 void nextInc(Edge &arc, bool& d) const { 1028 int de = (arcs[(arc._id * 2) | (d ? 1 : 0)].next_out); 1029 if (de != -1) { 1030 arc._id = de / 2; 1031 d = ((de & 1) == 1); 1032 } else { 1033 arc._id = -1; 1034 d = true; 1035 } 1036 } 1037 1038 static int id(Node v) { return v._id; } 1039 int id(RedNode v) const { return nodes[v._id].partition_index; } 1040 int id(BlueNode v) const { return nodes[v._id].partition_index; } 1041 static int id(Arc e) { return e._id; } 1042 static int id(Edge e) { return e._id; } 1043 1044 static Node nodeFromId(int id) { return Node(id);} 1045 static Arc arcFromId(int id) { return Arc(id);} 1046 static Edge edgeFromId(int id) { return Edge(id);} 1047 1048 bool valid(Node n) const { 1049 return n._id >= 0 && n._id < static_cast<int>(nodes.size()); 1050 } 1051 bool valid(Arc a) const { 1052 return a._id >= 0 && a._id < static_cast<int>(arcs.size()); 1053 } 1054 bool valid(Edge e) const { 1055 return e._id >= 0 && 2 * e._id < static_cast<int>(arcs.size()); 1056 } 1057 1058 RedNode addRedNode() { 1059 int n = nodes.size(); 1060 nodes.push_back(NodeT()); 1061 nodes[n].first_out = -1; 1062 nodes[n].red = true; 1063 nodes[n].partition_index = ++max_red; 1064 nodes[n].partition_next = first_red; 1065 first_red = n; 1066 1067 return RedNode(n); 1068 } 1069 1070 BlueNode addBlueNode() { 1071 int n = nodes.size(); 1072 nodes.push_back(NodeT()); 1073 nodes[n].first_out = -1; 1074 nodes[n].red = false; 1075 nodes[n].partition_index = ++max_blue; 1076 nodes[n].partition_next = first_blue; 1077 first_blue = n; 1078 1079 return BlueNode(n); 1080 } 1081 1082 Edge addEdge(RedNode u, BlueNode v) { 1083 int n = arcs.size(); 1084 arcs.push_back(ArcT()); 1085 arcs.push_back(ArcT()); 1086 1087 arcs[n].target = u._id; 1088 arcs[n | 1].target = v._id; 1089 1090 arcs[n].next_out = nodes[v._id].first_out; 1091 nodes[v._id].first_out = n; 1092 1093 arcs[n | 1].next_out = nodes[u._id].first_out; 1094 nodes[u._id].first_out = (n | 1); 1095 1096 return Edge(n / 2); 1097 } 1098 1099 void clear() { 1100 arcs.clear(); 1101 nodes.clear(); 1102 first_red = -1; 1103 first_blue = -1; 1104 max_blue = -1; 1105 max_red = -1; 1106 } 1107 1108 }; 1109 1110 typedef BpGraphExtender<SmartBpGraphBase> ExtendedSmartBpGraphBase; 1111 1112 /// \ingroup graphs 1113 /// 1114 /// \brief A smart undirected bipartite graph class. 1115 /// 1116 /// \ref SmartBpGraph is a simple and fast bipartite graph implementation. 1117 /// It is also quite memory efficient but at the price 1118 /// that it does not support node and edge deletion 1119 /// (except for the Snapshot feature). 1120 /// 1121 /// This type fully conforms to the \ref concepts::BpGraph "BpGraph concept" 1122 /// and it also provides some additional functionalities. 1123 /// Most of its member functions and nested classes are documented 1124 /// only in the concept class. 1125 /// 1126 /// This class provides constant time counting for nodes, edges and arcs. 1127 /// 1128 /// \sa concepts::BpGraph 1129 /// \sa SmartGraph 1130 class SmartBpGraph : public ExtendedSmartBpGraphBase { 1131 typedef ExtendedSmartBpGraphBase Parent; 1132 1133 private: 1134 /// Graphs are \e not copy constructible. Use GraphCopy instead. 1135 SmartBpGraph(const SmartBpGraph &) : ExtendedSmartBpGraphBase() {}; 1136 /// \brief Assignment of a graph to another one is \e not allowed. 1137 /// Use GraphCopy instead. 1138 void operator=(const SmartBpGraph &) {} 1139 1140 public: 1141 1142 /// Constructor 1143 1144 /// Constructor. 1145 /// 1146 SmartBpGraph() {} 1147 1148 /// \brief Add a new red node to the graph. 1149 /// 1150 /// This function adds a red new node to the graph. 1151 /// \return The new node. 1152 RedNode addRedNode() { return Parent::addRedNode(); } 1153 1154 /// \brief Add a new blue node to the graph. 1155 /// 1156 /// This function adds a blue new node to the graph. 1157 /// \return The new node. 1158 BlueNode addBlueNode() { return Parent::addBlueNode(); } 1159 1160 /// \brief Add a new edge to the graph. 1161 /// 1162 /// This function adds a new edge to the graph between nodes 1163 /// \c u and \c v with inherent orientation from node \c u to 1164 /// node \c v. 1165 /// \return The new edge. 1166 Edge addEdge(RedNode u, BlueNode v) { 1167 return Parent::addEdge(u, v); 1168 } 1169 Edge addEdge(BlueNode v, RedNode u) { 1170 return Parent::addEdge(u, v); 1171 } 1172 1173 /// \brief Node validity check 1174 /// 1175 /// This function gives back \c true if the given node is valid, 1176 /// i.e. it is a real node of the graph. 1177 /// 1178 /// \warning A removed node (using Snapshot) could become valid again 1179 /// if new nodes are added to the graph. 1180 bool valid(Node n) const { return Parent::valid(n); } 1181 1182 /// \brief Edge validity check 1183 /// 1184 /// This function gives back \c true if the given edge is valid, 1185 /// i.e. it is a real edge of the graph. 1186 /// 1187 /// \warning A removed edge (using Snapshot) could become valid again 1188 /// if new edges are added to the graph. 1189 bool valid(Edge e) const { return Parent::valid(e); } 1190 1191 /// \brief Arc validity check 1192 /// 1193 /// This function gives back \c true if the given arc is valid, 1194 /// i.e. it is a real arc of the graph. 1195 /// 1196 /// \warning A removed arc (using Snapshot) could become valid again 1197 /// if new edges are added to the graph. 1198 bool valid(Arc a) const { return Parent::valid(a); } 1199 1200 ///Clear the graph. 1201 1202 ///This function erases all nodes and arcs from the graph. 1203 /// 1204 void clear() { 1205 Parent::clear(); 1206 } 1207 1208 /// Reserve memory for nodes. 1209 1210 /// Using this function, it is possible to avoid superfluous memory 1211 /// allocation: if you know that the graph you want to build will 1212 /// be large (e.g. it will contain millions of nodes and/or edges), 1213 /// then it is worth reserving space for this amount before starting 1214 /// to build the graph. 1215 /// \sa reserveEdge() 1216 void reserveNode(int n) { nodes.reserve(n); }; 1217 1218 /// Reserve memory for edges. 1219 1220 /// Using this function, it is possible to avoid superfluous memory 1221 /// allocation: if you know that the graph you want to build will 1222 /// be large (e.g. it will contain millions of nodes and/or edges), 1223 /// then it is worth reserving space for this amount before starting 1224 /// to build the graph. 1225 /// \sa reserveNode() 1226 void reserveEdge(int m) { arcs.reserve(2 * m); }; 1227 1228 public: 1229 1230 class Snapshot; 1231 1232 protected: 1233 1234 void saveSnapshot(Snapshot &s) 1235 { 1236 s._graph = this; 1237 s.node_num = nodes.size(); 1238 s.arc_num = arcs.size(); 1239 } 1240 1241 void restoreSnapshot(const Snapshot &s) 1242 { 1243 while(s.arc_num<arcs.size()) { 1244 int n=arcs.size()-1; 1245 Edge arc=edgeFromId(n/2); 1246 Parent::notifier(Edge()).erase(arc); 1247 std::vector<Arc> dir; 1248 dir.push_back(arcFromId(n)); 1249 dir.push_back(arcFromId(n-1)); 1250 Parent::notifier(Arc()).erase(dir); 1251 nodes[arcs[n-1].target].first_out=arcs[n].next_out; 1252 nodes[arcs[n].target].first_out=arcs[n-1].next_out; 1253 arcs.pop_back(); 1254 arcs.pop_back(); 1255 } 1256 while(s.node_num<nodes.size()) { 1257 int n=nodes.size()-1; 1258 Node node = nodeFromId(n); 1259 if (Parent::red(node)) { 1260 first_red = nodes[n].partition_next; 1261 if (first_red != -1) { 1262 max_red = nodes[first_red].partition_index; 1263 } else { 1264 max_red = -1; 1265 } 1266 Parent::notifier(RedNode()).erase(asRedNodeUnsafe(node)); 1267 } else { 1268 first_blue = nodes[n].partition_next; 1269 if (first_blue != -1) { 1270 max_blue = nodes[first_blue].partition_index; 1271 } else { 1272 max_blue = -1; 1273 } 1274 Parent::notifier(BlueNode()).erase(asBlueNodeUnsafe(node)); 1275 } 1276 Parent::notifier(Node()).erase(node); 1277 nodes.pop_back(); 1278 } 1279 } 1280 1281 public: 1282 1283 ///Class to make a snapshot of the graph and to restore it later. 1284 1285 ///Class to make a snapshot of the graph and to restore it later. 1286 /// 1287 ///The newly added nodes and edges can be removed using the 1288 ///restore() function. This is the only way for deleting nodes and/or 1289 ///edges from a SmartBpGraph structure. 1290 /// 1291 ///\note After a state is restored, you cannot restore a later state, 1292 ///i.e. you cannot add the removed nodes and edges again using 1293 ///another Snapshot instance. 1294 /// 1295 ///\warning The validity of the snapshot is not stored due to 1296 ///performance reasons. If you do not use the snapshot correctly, 1297 ///it can cause broken program, invalid or not restored state of 1298 ///the graph or no change. 1299 class Snapshot 1300 { 1301 SmartBpGraph *_graph; 1302 protected: 1303 friend class SmartBpGraph; 1304 unsigned int node_num; 1305 unsigned int arc_num; 1306 public: 1307 ///Default constructor. 1308 1309 ///Default constructor. 1310 ///You have to call save() to actually make a snapshot. 1311 Snapshot() : _graph(0) {} 1312 ///Constructor that immediately makes a snapshot 1313 1314 /// This constructor immediately makes a snapshot of the given graph. 1315 /// 1316 Snapshot(SmartBpGraph &gr) { 1317 gr.saveSnapshot(*this); 1318 } 1319 1320 ///Make a snapshot. 1321 1322 ///This function makes a snapshot of the given graph. 1323 ///It can be called more than once. In case of a repeated 1324 ///call, the previous snapshot gets lost. 1325 void save(SmartBpGraph &gr) 1326 { 1327 gr.saveSnapshot(*this); 1328 } 1329 1330 ///Undo the changes until the last snapshot. 1331 1332 ///This function undos the changes until the last snapshot 1333 ///created by save() or Snapshot(SmartBpGraph&). 1334 void restore() 1335 { 1336 _graph->restoreSnapshot(*this); 1337 } 1338 }; 1339 }; 1340 814 1341 } //namespace lemon 815 1342 -
lemon/soplex.cc
r956 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). -
lemon/soplex.h
r956 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). -
lemon/static_graph.h
r956 r1328 204 204 205 205 node_num = n; 206 arc_num = st d::distance(first, last);206 arc_num = static_cast<int>(std::distance(first, last)); 207 207 208 208 node_first_out = new int[node_num + 1]; -
lemon/suurballe.h
r956 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 138 138 typedef typename TR::Heap Heap; 139 139 140 /// The \ref SuurballeDefaultTraits "traits class" of the algorithm.140 /// The \ref lemon::SuurballeDefaultTraits "traits class" of the algorithm. 141 141 typedef TR Traits; 142 142 … … 683 683 /// This function returns the total length of the found paths, i.e. 684 684 /// the total cost of the found flow. 685 /// The complexity of the function is O( e).685 /// The complexity of the function is O(m). 686 686 /// 687 687 /// \pre \ref run() or \ref findFlow() must be called before using -
lemon/time_measure.h
r833 r1340 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 24 24 ///\brief Tools for measuring cpu usage 25 25 26 #ifdef WIN32 26 #include <lemon/config.h> 27 28 #ifdef LEMON_WIN32 27 29 #include <lemon/bits/windows.h> 28 30 #else … … 35 37 #include <fstream> 36 38 #include <iostream> 39 #include <lemon/math.h> 37 40 38 41 namespace lemon { … … 64 67 double rtime; 65 68 69 public: 70 ///Display format specifier 71 72 ///\e 73 /// 74 enum Format { 75 /// Reports all measured values 76 NORMAL = 0, 77 /// Only real time and an error indicator is displayed 78 SHORT = 1 79 }; 80 81 private: 82 static Format _format; 83 66 84 void _reset() { 67 85 utime = stime = cutime = cstime = rtime = 0; … … 70 88 public: 71 89 90 ///Set output format 91 92 ///Set output format. 93 /// 94 ///The output format is global for all timestamp instances. 95 static void format(Format f) { _format = f; } 96 ///Retrieve the current output format 97 98 ///Retrieve the current output format 99 /// 100 ///The output format is global for all timestamp instances. 101 static Format format() { return _format; } 102 103 72 104 ///Read the current time values of the process 73 105 void stamp() 74 106 { 75 #ifndef WIN32107 #ifndef LEMON_WIN32 76 108 timeval tv; 77 109 gettimeofday(&tv, 0); … … 225 257 inline std::ostream& operator<<(std::ostream& os,const TimeStamp &t) 226 258 { 227 os << "u: " << t.userTime() << 228 "s, s: " << t.systemTime() << 229 "s, cu: " << t.cUserTime() << 230 "s, cs: " << t.cSystemTime() << 231 "s, real: " << t.realTime() << "s"; 259 switch(t._format) 260 { 261 case TimeStamp::NORMAL: 262 os << "u: " << t.userTime() << 263 "s, s: " << t.systemTime() << 264 "s, cu: " << t.cUserTime() << 265 "s, cs: " << t.cSystemTime() << 266 "s, real: " << t.realTime() << "s"; 267 break; 268 case TimeStamp::SHORT: 269 double total = t.userTime()+t.systemTime()+ 270 t.cUserTime()+t.cSystemTime(); 271 os << t.realTime() 272 << "s (err: " << round((t.realTime()-total)/ 273 t.realTime()*10000)/100 274 << "%)"; 275 break; 276 } 232 277 return os; 233 278 } … … 469 514 std::string _title; 470 515 std::ostream &_os; 516 bool _active; 471 517 public: 472 518 ///Constructor … … 476 522 ///\param os The stream to print the report to. 477 523 ///\param run Sets whether the timer should start immediately. 478 TimeReport(std::string title,std::ostream &os=std::cerr,bool run=true) 479 : Timer(run), _title(title), _os(os){} 524 ///\param active Sets whether the report should actually be printed 525 /// on destruction. 526 TimeReport(std::string title,std::ostream &os=std::cerr,bool run=true, 527 bool active=true) 528 : Timer(run), _title(title), _os(os), _active(active) {} 480 529 ///Destructor that prints the ellapsed time 481 530 ~TimeReport() 482 531 { 483 _os << _title << *this << std::endl; 484 } 532 if(_active) _os << _title << *this << std::endl; 533 } 534 535 ///Retrieve the activity status 536 537 ///\e 538 /// 539 bool active() const { return _active; } 540 ///Set the activity status 541 542 /// This function set whether the time report should actually be printed 543 /// on destruction. 544 void active(bool a) { _active=a; } 485 545 }; 486 546 -
lemon/unionfind.h
r956 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). -
test/CMakeLists.txt
r1159 r1264 17 17 bellman_ford_test 18 18 bfs_test 19 bpgraph_test 19 20 circulation_test 20 21 connectivity_test … … 35 36 heap_test 36 37 kruskal_test 38 lgf_reader_writer_test 37 39 lgf_test 38 40 maps_test 39 41 matching_test 42 max_cardinality_search_test 43 max_clique_test 44 max_flow_test 40 45 min_cost_arborescence_test 41 46 min_cost_flow_test 42 47 min_mean_cycle_test 48 nagamochi_ibaraki_test 43 49 path_test 44 50 planarity_test 45 preflow_test46 51 radix_sort_test 47 52 random_test 48 53 suurballe_test 49 54 time_measure_test 55 tsp_test 50 56 unionfind_test 51 57 ) … … 64 70 ENDIF() 65 71 IF(LEMON_HAVE_CPLEX) 66 SET(LP_TEST_LIBS ${LP_TEST_LIBS} ${ CPLEX_LIBRARIES})72 SET(LP_TEST_LIBS ${LP_TEST_LIBS} ${ILOG_LIBRARIES}) 67 73 ENDIF() 68 74 IF(LEMON_HAVE_CLP) 69 75 SET(LP_TEST_LIBS ${LP_TEST_LIBS} ${COIN_CLP_LIBRARIES}) 76 ENDIF() 77 IF(LEMON_HAVE_SOPLEX) 78 SET(LP_TEST_LIBS ${LP_TEST_LIBS} ${SOPLEX_LIBRARIES}) 70 79 ENDIF() 71 80 … … 88 97 GET_FILENAME_COMPONENT(TARGET_PATH ${TARGET_LOC} PATH) 89 98 ADD_CUSTOM_COMMAND(TARGET lp_test POST_BUILD 90 COMMAND ${CMAKE_COMMAND} -E copy ${ CPLEX_BIN_DIR}/cplex.dll${TARGET_PATH}99 COMMAND ${CMAKE_COMMAND} -E copy ${ILOG_CPLEX_DLL} ${TARGET_PATH} 91 100 ) 92 101 ENDIF() … … 106 115 ENDIF() 107 116 IF(LEMON_HAVE_CPLEX) 108 SET(MIP_TEST_LIBS ${MIP_TEST_LIBS} ${ CPLEX_LIBRARIES})117 SET(MIP_TEST_LIBS ${MIP_TEST_LIBS} ${ILOG_LIBRARIES}) 109 118 ENDIF() 110 119 IF(LEMON_HAVE_CBC) … … 130 139 GET_FILENAME_COMPONENT(TARGET_PATH ${TARGET_LOC} PATH) 131 140 ADD_CUSTOM_COMMAND(TARGET mip_test POST_BUILD 132 COMMAND ${CMAKE_COMMAND} -E copy ${ CPLEX_BIN_DIR}/cplex.dll${TARGET_PATH}141 COMMAND ${CMAKE_COMMAND} -E copy ${ILOG_CPLEX_DLL} ${TARGET_PATH} 133 142 ) 134 143 ENDIF() -
test/adaptors_test.cc
r1159 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 66 66 Digraph::Arc a2 = digraph.addArc(n1, n3); 67 67 Digraph::Arc a3 = digraph.addArc(n2, n3); 68 ignore_unused_variable_warning(a3);68 ::lemon::ignore_unused_variable_warning(a3); 69 69 70 70 // Check the adaptor … … 101 101 Adaptor::Arc a7 = adaptor.addArc(n1, n4); 102 102 Adaptor::Arc a8 = adaptor.addArc(n1, n2); 103 ignore_unused_variable_warning(a6,a7,a8);103 ::lemon::ignore_unused_variable_warning(a6,a7,a8); 104 104 105 105 adaptor.erase(a1); … … 761 761 Digraph::Arc a2 = digraph.addArc(n1, n3); 762 762 Digraph::Arc a3 = digraph.addArc(n2, n3); 763 ignore_unused_variable_warning(a1,a2,a3);763 ::lemon::ignore_unused_variable_warning(a1,a2,a3); 764 764 765 765 checkGraphNodeList(adaptor, 6); -
test/arc_look_up_test.cc
r1149 r1312 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 25 25 using namespace lemon; 26 26 27 const int lgfn = 4;28 27 const std::string lgf = 29 28 "@nodes\n" … … 69 68 std::istringstream lgfs(lgf); 70 69 DigraphReader<ListDigraph>(graph, lgfs).run(); 71 70 72 71 AllArcLookUp<ListDigraph> lookup(graph); 73 72 74 73 int numArcs = countArcs(graph); 75 74 76 75 int arcCnt = 0; 77 76 for(ListDigraph::NodeIt n1(graph); n1 != INVALID; ++n1) 78 77 for(ListDigraph::NodeIt n2(graph); n2 != INVALID; ++n2) 79 78 for(ListDigraph::Arc a = lookup(n1, n2); a != INVALID; 80 a = lookup(n1, n2, a))81 ++arcCnt;79 a = lookup(n1, n2, a)) 80 ++arcCnt; 82 81 check(arcCnt==numArcs, "Wrong total number of arcs"); 83 82 -
test/bellman_ford_test.cc
r960 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 66 66 Arc e; 67 67 Value l; 68 ::lemon::ignore_unused_variable_warning(l); 68 69 int k=3; 69 70 bool b; 71 ::lemon::ignore_unused_variable_warning(b); 70 72 BF::DistMap d(gr); 71 73 BF::PredMap p(gr); … … 148 150 Digraph g; 149 151 bool b; 152 ::lemon::ignore_unused_variable_warning(b); 153 150 154 bellmanFord(g,LengthMap()).run(Node()); 151 155 b = bellmanFord(g,LengthMap()).run(Node(),Node()); … … 191 195 192 196 ListPath<Digraph> path; 193 Value dist ;197 Value dist = 0; 194 198 bool reached = bellmanFord(gr,length).path(path).dist(dist).run(s,t); 195 199 -
test/bfs_test.cc
r956 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 62 62 Arc e; 63 63 int l, i; 64 ::lemon::ignore_unused_variable_warning(l,i); 64 65 bool b; 65 66 BType::DistMap d(G); … … 151 152 Digraph g; 152 153 bool b; 154 ::lemon::ignore_unused_variable_warning(b); 155 153 156 bfs(g).run(Node()); 154 157 b=bfs(g).run(Node(),Node()); -
test/circulation_test.cc
r956 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 74 74 VType v; 75 75 bool b; 76 ::lemon::ignore_unused_variable_warning(v,b); 76 77 77 78 typedef Circulation<Digraph, CapMap, CapMap, SupplyMap> … … 104 105 const_circ_test.barrierMap(bar); 105 106 106 ignore_unused_variable_warning(fm);107 ::lemon::ignore_unused_variable_warning(fm); 107 108 } 108 109 -
test/connectivity_test.cc
r1159 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 69 69 Graph g(d); 70 70 Digraph::Node n = d.addNode(); 71 ignore_unused_variable_warning(n);71 ::lemon::ignore_unused_variable_warning(n); 72 72 73 73 check(stronglyConnected(d), "This digraph is strongly connected"); … … 98 98 check(simpleGraph(g), "This graph is simple."); 99 99 } 100 101 { 102 ListGraph g; 103 ListGraph::NodeMap<bool> map(g); 104 105 ListGraph::Node n1 = g.addNode(); 106 ListGraph::Node n2 = g.addNode(); 107 108 ListGraph::Edge e1 = g.addEdge(n1, n2); 109 ::lemon::ignore_unused_variable_warning(e1); 110 check(biNodeConnected(g), "Graph is bi-node-connected"); 111 112 ListGraph::Node n3 = g.addNode(); 113 ::lemon::ignore_unused_variable_warning(n3); 114 check(!biNodeConnected(g), "Graph is not bi-node-connected"); 115 } 116 100 117 101 118 { … … 247 264 Digraph::Node watch = d.addNode(); 248 265 Digraph::Node pants = d.addNode(); 249 ignore_unused_variable_warning(watch);266 ::lemon::ignore_unused_variable_warning(watch); 250 267 251 268 d.addArc(socks, shoe); -
test/dfs_test.cc
r1107 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 68 68 int l, i; 69 69 bool b; 70 ::lemon::ignore_unused_variable_warning(l,i,b); 71 70 72 DType::DistMap d(G); 71 73 DType::PredMap p(G); … … 152 154 Digraph g; 153 155 bool b; 156 ::lemon::ignore_unused_variable_warning(b); 157 154 158 dfs(g).run(Node()); 155 159 b=dfs(g).run(Node(),Node()); … … 220 224 check(dfs.run(s1,t1) && dfs.reached(t1),"Node 3 is reachable from Node 6."); 221 225 } 222 226 223 227 { 224 228 NullMap<Node,Arc> myPredMap; -
test/digraph_test.cc
r1159 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 65 65 a3 = G.addArc(n2, n3), 66 66 a4 = G.addArc(n2, n3); 67 ignore_unused_variable_warning(a2,a3,a4);67 ::lemon::ignore_unused_variable_warning(a2,a3,a4); 68 68 69 69 checkGraphNodeList(G, 3); … … 94 94 Arc a1 = G.addArc(n1, n2), a2 = G.addArc(n2, n1), 95 95 a3 = G.addArc(n2, n3), a4 = G.addArc(n2, n3); 96 ignore_unused_variable_warning(a1,a2,a3,a4);96 ::lemon::ignore_unused_variable_warning(a1,a2,a3,a4); 97 97 98 98 Node n4 = G.split(n2); … … 128 128 a3 = G.addArc(n4, n3), a4 = G.addArc(n4, n3), 129 129 a5 = G.addArc(n2, n4); 130 ignore_unused_variable_warning(a1,a2,a3,a5);130 ::lemon::ignore_unused_variable_warning(a1,a2,a3,a5); 131 131 132 132 checkGraphNodeList(G, 4); … … 208 208 a3 = G.addArc(n4, n3), a4 = G.addArc(n3, n1), 209 209 a5 = G.addArc(n2, n4); 210 ignore_unused_variable_warning(a2,a3,a4,a5);210 ::lemon::ignore_unused_variable_warning(a2,a3,a4,a5); 211 211 212 212 // Check arc deletion … … 256 256 Arc a1 = G.addArc(n1, n2), a2 = G.addArc(n2, n1), 257 257 a3 = G.addArc(n2, n3), a4 = G.addArc(n2, n3); 258 ignore_unused_variable_warning(a1,a2,a3,a4);258 ::lemon::ignore_unused_variable_warning(a1,a2,a3,a4); 259 259 260 260 typename Digraph::Snapshot snapshot(G); … … 357 357 e1 = g.addArc(n1, n2), 358 358 e2 = g.addArc(n2, n3); 359 ignore_unused_variable_warning(e2);359 ::lemon::ignore_unused_variable_warning(e2); 360 360 361 361 check(g.valid(n1), "Wrong validity check"); … … 443 443 a3 = g.addArc(n2, n3), 444 444 a4 = g.addArc(n2, n3); 445 ::lemon::ignore_unused_variable_warning(a2,a3,a4); 445 446 446 447 digraphCopy(g, G).nodeRef(nref).run(); -
test/dijkstra_test.cc
r956 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 66 66 int i; 67 67 bool b; 68 ::lemon::ignore_unused_variable_warning(l,i,b); 69 68 70 DType::DistMap d(G); 69 71 DType::PredMap p(G); … … 163 165 Digraph g; 164 166 bool b; 167 ::lemon::ignore_unused_variable_warning(b); 168 165 169 dijkstra(g,LengthMap()).run(Node()); 166 170 b=dijkstra(g,LengthMap()).run(Node(),Node()); -
test/edge_set_test.cc
r1159 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 45 45 46 46 Digraph::Arc ga1 = digraph.addArc(n1, n2); 47 ignore_unused_variable_warning(ga1);47 ::lemon::ignore_unused_variable_warning(ga1); 48 48 49 49 ArcSet arc_set(digraph); 50 50 51 51 Digraph::Arc ga2 = digraph.addArc(n2, n1); 52 ignore_unused_variable_warning(ga2);52 ::lemon::ignore_unused_variable_warning(ga2); 53 53 54 54 checkGraphNodeList(arc_set, 2); … … 78 78 a3 = arc_set.addArc(n2, n3), 79 79 a4 = arc_set.addArc(n2, n3); 80 ignore_unused_variable_warning(a2,a3,a4);80 ::lemon::ignore_unused_variable_warning(a2,a3,a4); 81 81 82 82 checkGraphNodeList(arc_set, 3); … … 115 115 116 116 Digraph::Arc ga1 = digraph.addArc(n1, n2); 117 ignore_unused_variable_warning(ga1);117 ::lemon::ignore_unused_variable_warning(ga1); 118 118 119 119 ArcSet arc_set(digraph); 120 120 121 121 Digraph::Arc ga2 = digraph.addArc(n2, n1); 122 ignore_unused_variable_warning(ga2);122 ::lemon::ignore_unused_variable_warning(ga2); 123 123 124 124 checkGraphNodeList(arc_set, 2); … … 148 148 a3 = arc_set.addArc(n2, n3), 149 149 a4 = arc_set.addArc(n2, n3); 150 ignore_unused_variable_warning(a2,a3,a4);150 ::lemon::ignore_unused_variable_warning(a2,a3,a4); 151 151 152 152 checkGraphNodeList(arc_set, 3); … … 199 199 200 200 Digraph::Arc ga1 = digraph.addArc(n1, n2); 201 ignore_unused_variable_warning(ga1);201 ::lemon::ignore_unused_variable_warning(ga1); 202 202 203 203 EdgeSet edge_set(digraph); 204 204 205 205 Digraph::Arc ga2 = digraph.addArc(n2, n1); 206 ignore_unused_variable_warning(ga2);206 ::lemon::ignore_unused_variable_warning(ga2); 207 207 208 208 checkGraphNodeList(edge_set, 2); … … 241 241 e3 = edge_set.addEdge(n2, n3), 242 242 e4 = edge_set.addEdge(n2, n3); 243 ignore_unused_variable_warning(e2,e3,e4);243 ::lemon::ignore_unused_variable_warning(e2,e3,e4); 244 244 245 245 checkGraphNodeList(edge_set, 3); … … 287 287 288 288 Digraph::Arc ga1 = digraph.addArc(n1, n2); 289 ignore_unused_variable_warning(ga1);289 ::lemon::ignore_unused_variable_warning(ga1); 290 290 291 291 EdgeSet edge_set(digraph); 292 292 293 293 Digraph::Arc ga2 = digraph.addArc(n2, n1); 294 ignore_unused_variable_warning(ga2);294 ::lemon::ignore_unused_variable_warning(ga2); 295 295 296 296 checkGraphNodeList(edge_set, 2); … … 329 329 e3 = edge_set.addEdge(n2, n3), 330 330 e4 = edge_set.addEdge(n2, n3); 331 ignore_unused_variable_warning(e2,e3,e4);331 ::lemon::ignore_unused_variable_warning(e2,e3,e4); 332 332 333 333 checkGraphNodeList(edge_set, 3); -
test/euler_test.cc
r1159 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 102 102 Graph g(d); 103 103 Digraph::Node n = d.addNode(); 104 ignore_unused_variable_warning(n);105 104 ::lemon::ignore_unused_variable_warning(n); 105 106 106 checkDiEulerIt(d); 107 107 checkDiEulerIt(g); … … 191 191 Digraph::Node n4 = d.addNode(); 192 192 Digraph::Node n5 = d.addNode(); 193 ignore_unused_variable_warning(n0,n4,n5);193 ::lemon::ignore_unused_variable_warning(n0,n4,n5); 194 194 195 195 d.addArc(n1, n2); -
test/fractional_matching_test.cc
r956 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 343 343 pv += weight[mwfm.matching(n)]; 344 344 SmartGraph::Node o = graph.target(mwfm.matching(n)); 345 ::lemon::ignore_unused_variable_warning(o); 345 346 } else { 346 347 check(mwfm.nodeValue(n) == 0, "Invalid matching"); … … 407 408 pv += weight[mwpfm.matching(n)]; 408 409 SmartGraph::Node o = graph.target(mwpfm.matching(n)); 410 ::lemon::ignore_unused_variable_warning(o); 409 411 } 410 412 -
test/gomory_hu_test.cc
r956 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 69 69 Value v; 70 70 int d; 71 ::lemon::ignore_unused_variable_warning(v,d); 71 72 72 73 GomoryHu<Graph, CapMap> gh_test(g, cap); -
test/graph_copy_test.cc
r984 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 19 19 #include <lemon/smart_graph.h> 20 20 #include <lemon/list_graph.h> 21 #include <lemon/static_graph.h> 21 22 #include <lemon/lgf_reader.h> 22 23 #include <lemon/error.h> … … 27 28 using namespace lemon; 28 29 30 template <typename GR> 29 31 void digraph_copy_test() { 30 32 const int nn = 10; … … 54 56 55 57 // Test digraph copy 56 ListDigraphto;57 ListDigraph::NodeMap<int> tnm(to);58 ListDigraph::ArcMap<int> tam(to);59 ListDigraph::Node tn;60 ListDigraph::Arc ta;61 62 SmartDigraph::NodeMap< ListDigraph::Node> nr(from);63 SmartDigraph::ArcMap< ListDigraph::Arc> er(from);64 65 ListDigraph::NodeMap<SmartDigraph::Node> ncr(to);66 ListDigraph::ArcMap<SmartDigraph::Arc> ecr(to);58 GR to; 59 typename GR::template NodeMap<int> tnm(to); 60 typename GR::template ArcMap<int> tam(to); 61 typename GR::Node tn; 62 typename GR::Arc ta; 63 64 SmartDigraph::NodeMap<typename GR::Node> nr(from); 65 SmartDigraph::ArcMap<typename GR::Arc> er(from); 66 67 typename GR::template NodeMap<SmartDigraph::Node> ncr(to); 68 typename GR::template ArcMap<SmartDigraph::Arc> ecr(to); 67 69 68 70 digraphCopy(from, to). … … 71 73 nodeCrossRef(ncr).arcCrossRef(ecr). 72 74 node(fn, tn).arc(fa, ta).run(); 73 75 74 76 check(countNodes(from) == countNodes(to), "Wrong copy."); 75 77 check(countArcs(from) == countArcs(to), "Wrong copy."); … … 87 89 } 88 90 89 for ( ListDigraph::NodeIt it(to); it != INVALID; ++it) {91 for (typename GR::NodeIt it(to); it != INVALID; ++it) { 90 92 check(nr[ncr[it]] == it, "Wrong copy."); 91 93 } 92 94 93 for ( ListDigraph::ArcIt it(to); it != INVALID; ++it) {95 for (typename GR::ArcIt it(to); it != INVALID; ++it) { 94 96 check(er[ecr[it]] == it, "Wrong copy."); 95 97 } … … 99 101 // Test repeated copy 100 102 digraphCopy(from, to).run(); 101 103 102 104 check(countNodes(from) == countNodes(to), "Wrong copy."); 103 105 check(countArcs(from) == countArcs(to), "Wrong copy."); 104 106 } 105 107 108 template <typename GR> 106 109 void graph_copy_test() { 107 110 const int nn = 10; … … 136 139 137 140 // Test graph copy 138 ListGraphto;139 ListGraph::NodeMap<int> tnm(to);140 ListGraph::ArcMap<int> tam(to);141 ListGraph::EdgeMap<int> tem(to);142 ListGraph::Node tn;143 ListGraph::Arc ta;144 ListGraph::Edge te;145 146 SmartGraph::NodeMap< ListGraph::Node> nr(from);147 SmartGraph::ArcMap< ListGraph::Arc> ar(from);148 SmartGraph::EdgeMap< ListGraph::Edge> er(from);149 150 ListGraph::NodeMap<SmartGraph::Node> ncr(to);151 ListGraph::ArcMap<SmartGraph::Arc> acr(to);152 ListGraph::EdgeMap<SmartGraph::Edge> ecr(to);141 GR to; 142 typename GR::template NodeMap<int> tnm(to); 143 typename GR::template ArcMap<int> tam(to); 144 typename GR::template EdgeMap<int> tem(to); 145 typename GR::Node tn; 146 typename GR::Arc ta; 147 typename GR::Edge te; 148 149 SmartGraph::NodeMap<typename GR::Node> nr(from); 150 SmartGraph::ArcMap<typename GR::Arc> ar(from); 151 SmartGraph::EdgeMap<typename GR::Edge> er(from); 152 153 typename GR::template NodeMap<SmartGraph::Node> ncr(to); 154 typename GR::template ArcMap<SmartGraph::Arc> acr(to); 155 typename GR::template EdgeMap<SmartGraph::Edge> ecr(to); 153 156 154 157 graphCopy(from, to). … … 185 188 } 186 189 187 for ( ListGraph::NodeIt it(to); it != INVALID; ++it) {190 for (typename GR::NodeIt it(to); it != INVALID; ++it) { 188 191 check(nr[ncr[it]] == it, "Wrong copy."); 189 192 } 190 193 191 for ( ListGraph::ArcIt it(to); it != INVALID; ++it) {194 for (typename GR::ArcIt it(to); it != INVALID; ++it) { 192 195 check(ar[acr[it]] == it, "Wrong copy."); 193 196 } 194 for ( ListGraph::EdgeIt it(to); it != INVALID; ++it) {197 for (typename GR::EdgeIt it(to); it != INVALID; ++it) { 195 198 check(er[ecr[it]] == it, "Wrong copy."); 196 199 } … … 201 204 // Test repeated copy 202 205 graphCopy(from, to).run(); 203 206 204 207 check(countNodes(from) == countNodes(to), "Wrong copy."); 205 208 check(countEdges(from) == countEdges(to), "Wrong copy."); … … 207 210 } 208 211 212 template <typename GR> 213 void bpgraph_copy_test() { 214 const int nn = 10; 215 216 // Build a graph 217 SmartBpGraph from; 218 SmartBpGraph::NodeMap<int> fnm(from); 219 SmartBpGraph::RedNodeMap<int> frnm(from); 220 SmartBpGraph::BlueNodeMap<int> fbnm(from); 221 SmartBpGraph::ArcMap<int> fam(from); 222 SmartBpGraph::EdgeMap<int> fem(from); 223 SmartBpGraph::Node fn = INVALID; 224 SmartBpGraph::RedNode frn = INVALID; 225 SmartBpGraph::BlueNode fbn = INVALID; 226 SmartBpGraph::Arc fa = INVALID; 227 SmartBpGraph::Edge fe = INVALID; 228 229 std::vector<SmartBpGraph::RedNode> frnv; 230 for (int i = 0; i < nn; ++i) { 231 SmartBpGraph::RedNode node = from.addRedNode(); 232 frnv.push_back(node); 233 fnm[node] = i * i; 234 frnm[node] = i + i; 235 if (i == 0) { 236 fn = node; 237 frn = node; 238 } 239 } 240 241 std::vector<SmartBpGraph::BlueNode> fbnv; 242 for (int i = 0; i < nn; ++i) { 243 SmartBpGraph::BlueNode node = from.addBlueNode(); 244 fbnv.push_back(node); 245 fnm[node] = i * i; 246 fbnm[node] = i + i; 247 if (i == 0) fbn = node; 248 } 249 250 for (int i = 0; i < nn; ++i) { 251 for (int j = 0; j < nn; ++j) { 252 SmartBpGraph::Edge edge = from.addEdge(frnv[i], fbnv[j]); 253 fem[edge] = i * i + j * j; 254 fam[from.direct(edge, true)] = i + j * j; 255 fam[from.direct(edge, false)] = i * i + j; 256 if (i == 0 && j == 0) fa = from.direct(edge, true); 257 if (i == 0 && j == 0) fe = edge; 258 } 259 } 260 261 // Test graph copy 262 GR to; 263 typename GR::template NodeMap<int> tnm(to); 264 typename GR::template RedNodeMap<int> trnm(to); 265 typename GR::template BlueNodeMap<int> tbnm(to); 266 typename GR::template ArcMap<int> tam(to); 267 typename GR::template EdgeMap<int> tem(to); 268 typename GR::Node tn; 269 typename GR::RedNode trn; 270 typename GR::BlueNode tbn; 271 typename GR::Arc ta; 272 typename GR::Edge te; 273 274 SmartBpGraph::NodeMap<typename GR::Node> nr(from); 275 SmartBpGraph::RedNodeMap<typename GR::RedNode> rnr(from); 276 SmartBpGraph::BlueNodeMap<typename GR::BlueNode> bnr(from); 277 SmartBpGraph::ArcMap<typename GR::Arc> ar(from); 278 SmartBpGraph::EdgeMap<typename GR::Edge> er(from); 279 280 typename GR::template NodeMap<SmartBpGraph::Node> ncr(to); 281 typename GR::template RedNodeMap<SmartBpGraph::RedNode> rncr(to); 282 typename GR::template BlueNodeMap<SmartBpGraph::BlueNode> bncr(to); 283 typename GR::template ArcMap<SmartBpGraph::Arc> acr(to); 284 typename GR::template EdgeMap<SmartBpGraph::Edge> ecr(to); 285 286 bpGraphCopy(from, to). 287 nodeMap(fnm, tnm). 288 redNodeMap(frnm, trnm).blueNodeMap(fbnm, tbnm). 289 arcMap(fam, tam).edgeMap(fem, tem). 290 nodeRef(nr).redRef(rnr).blueRef(bnr). 291 arcRef(ar).edgeRef(er). 292 nodeCrossRef(ncr).redCrossRef(rncr).blueCrossRef(bncr). 293 arcCrossRef(acr).edgeCrossRef(ecr). 294 node(fn, tn).redNode(frn, trn).blueNode(fbn, tbn). 295 arc(fa, ta).edge(fe, te).run(); 296 297 check(countNodes(from) == countNodes(to), "Wrong copy."); 298 check(countRedNodes(from) == countRedNodes(to), "Wrong copy."); 299 check(countBlueNodes(from) == countBlueNodes(to), "Wrong copy."); 300 check(countEdges(from) == countEdges(to), "Wrong copy."); 301 check(countArcs(from) == countArcs(to), "Wrong copy."); 302 303 for (SmartBpGraph::NodeIt it(from); it != INVALID; ++it) { 304 check(ncr[nr[it]] == it, "Wrong copy."); 305 check(fnm[it] == tnm[nr[it]], "Wrong copy."); 306 } 307 308 for (SmartBpGraph::RedNodeIt it(from); it != INVALID; ++it) { 309 check(ncr[nr[it]] == it, "Wrong copy."); 310 check(fnm[it] == tnm[nr[it]], "Wrong copy."); 311 check(rnr[it] == nr[it], "Wrong copy."); 312 check(rncr[rnr[it]] == it, "Wrong copy."); 313 check(frnm[it] == trnm[rnr[it]], "Wrong copy."); 314 check(to.red(rnr[it]), "Wrong copy."); 315 } 316 317 for (SmartBpGraph::BlueNodeIt it(from); it != INVALID; ++it) { 318 check(ncr[nr[it]] == it, "Wrong copy."); 319 check(fnm[it] == tnm[nr[it]], "Wrong copy."); 320 check(bnr[it] == nr[it], "Wrong copy."); 321 check(bncr[bnr[it]] == it, "Wrong copy."); 322 check(fbnm[it] == tbnm[bnr[it]], "Wrong copy."); 323 check(to.blue(bnr[it]), "Wrong copy."); 324 } 325 326 for (SmartBpGraph::ArcIt it(from); it != INVALID; ++it) { 327 check(acr[ar[it]] == it, "Wrong copy."); 328 check(fam[it] == tam[ar[it]], "Wrong copy."); 329 check(nr[from.source(it)] == to.source(ar[it]), "Wrong copy."); 330 check(nr[from.target(it)] == to.target(ar[it]), "Wrong copy."); 331 } 332 333 for (SmartBpGraph::EdgeIt it(from); it != INVALID; ++it) { 334 check(ecr[er[it]] == it, "Wrong copy."); 335 check(fem[it] == tem[er[it]], "Wrong copy."); 336 check(nr[from.u(it)] == to.u(er[it]) || nr[from.u(it)] == to.v(er[it]), 337 "Wrong copy."); 338 check(nr[from.v(it)] == to.u(er[it]) || nr[from.v(it)] == to.v(er[it]), 339 "Wrong copy."); 340 check((from.u(it) != from.v(it)) == (to.u(er[it]) != to.v(er[it])), 341 "Wrong copy."); 342 } 343 344 for (typename GR::NodeIt it(to); it != INVALID; ++it) { 345 check(nr[ncr[it]] == it, "Wrong copy."); 346 } 347 for (typename GR::RedNodeIt it(to); it != INVALID; ++it) { 348 check(rncr[it] == ncr[it], "Wrong copy."); 349 check(rnr[rncr[it]] == it, "Wrong copy."); 350 } 351 for (typename GR::BlueNodeIt it(to); it != INVALID; ++it) { 352 check(bncr[it] == ncr[it], "Wrong copy."); 353 check(bnr[bncr[it]] == it, "Wrong copy."); 354 } 355 for (typename GR::ArcIt it(to); it != INVALID; ++it) { 356 check(ar[acr[it]] == it, "Wrong copy."); 357 } 358 for (typename GR::EdgeIt it(to); it != INVALID; ++it) { 359 check(er[ecr[it]] == it, "Wrong copy."); 360 } 361 check(tn == nr[fn], "Wrong copy."); 362 check(trn == rnr[frn], "Wrong copy."); 363 check(tbn == bnr[fbn], "Wrong copy."); 364 check(ta == ar[fa], "Wrong copy."); 365 check(te == er[fe], "Wrong copy."); 366 367 // Test repeated copy 368 bpGraphCopy(from, to).run(); 369 370 check(countNodes(from) == countNodes(to), "Wrong copy."); 371 check(countRedNodes(from) == countRedNodes(to), "Wrong copy."); 372 check(countBlueNodes(from) == countBlueNodes(to), "Wrong copy."); 373 check(countEdges(from) == countEdges(to), "Wrong copy."); 374 check(countArcs(from) == countArcs(to), "Wrong copy."); 375 } 376 209 377 210 378 int main() { 211 digraph_copy_test(); 212 graph_copy_test(); 379 digraph_copy_test<SmartDigraph>(); 380 digraph_copy_test<ListDigraph>(); 381 digraph_copy_test<StaticDigraph>(); 382 graph_copy_test<SmartGraph>(); 383 graph_copy_test<ListGraph>(); 384 bpgraph_copy_test<SmartBpGraph>(); 385 bpgraph_copy_test<ListBpGraph>(); 213 386 214 387 return 0; -
test/graph_test.cc
r1159 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 67 67 Edge e2 = G.addEdge(n2, n1), 68 68 e3 = G.addEdge(n2, n3); 69 ignore_unused_variable_warning(e2,e3);69 ::lemon::ignore_unused_variable_warning(e2,e3); 70 70 71 71 checkGraphNodeList(G, 3); … … 100 100 e3 = G.addEdge(n2, n3), e4 = G.addEdge(n1, n4), 101 101 e5 = G.addEdge(n4, n3); 102 ignore_unused_variable_warning(e1,e3,e4,e5);102 ::lemon::ignore_unused_variable_warning(e1,e3,e4,e5); 103 103 104 104 checkGraphNodeList(G, 4); … … 180 180 e3 = G.addEdge(n2, n3), e4 = G.addEdge(n1, n4), 181 181 e5 = G.addEdge(n4, n3); 182 ignore_unused_variable_warning(e1,e3,e4,e5);182 ::lemon::ignore_unused_variable_warning(e1,e3,e4,e5); 183 183 184 184 // Check edge deletion … … 221 221 Edge e1 = G.addEdge(n1, n2), e2 = G.addEdge(n2, n1), 222 222 e3 = G.addEdge(n2, n3); 223 ignore_unused_variable_warning(e1,e2,e3);223 ::lemon::ignore_unused_variable_warning(e1,e2,e3); 224 224 225 225 checkGraphNodeList(G, 3); … … 386 386 e1 = g.addEdge(n1, n2), 387 387 e2 = g.addEdge(n2, n3); 388 ignore_unused_variable_warning(e2);388 ::lemon::ignore_unused_variable_warning(e2); 389 389 390 390 check(g.valid(n1), "Wrong validity check"); … … 525 525 526 526 Node n = G.nodeFromId(dim); 527 ignore_unused_variable_warning(n);527 ::lemon::ignore_unused_variable_warning(n); 528 528 529 529 for (NodeIt n(G); n != INVALID; ++n) { -
test/graph_test.h
r463 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 42 42 43 43 template<class Graph> 44 void checkGraphRedNodeList(const Graph &G, int cnt) 45 { 46 typename Graph::RedNodeIt n(G); 47 for(int i=0;i<cnt;i++) { 48 check(n!=INVALID,"Wrong red Node list linking."); 49 check(G.red(n),"Wrong node set check."); 50 check(!G.blue(n),"Wrong node set check."); 51 typename Graph::Node nn = n; 52 check(G.asRedNodeUnsafe(nn) == n,"Wrong node conversion."); 53 check(G.asRedNode(nn) == n,"Wrong node conversion."); 54 check(G.asBlueNode(nn) == INVALID,"Wrong node conversion."); 55 ++n; 56 } 57 check(n==INVALID,"Wrong red Node list linking."); 58 check(countRedNodes(G)==cnt,"Wrong red Node number."); 59 } 60 61 template<class Graph> 62 void checkGraphBlueNodeList(const Graph &G, int cnt) 63 { 64 typename Graph::BlueNodeIt n(G); 65 for(int i=0;i<cnt;i++) { 66 check(n!=INVALID,"Wrong blue Node list linking."); 67 check(G.blue(n),"Wrong node set check."); 68 check(!G.red(n),"Wrong node set check."); 69 typename Graph::Node nn = n; 70 check(G.asBlueNodeUnsafe(nn) == n,"Wrong node conversion."); 71 check(G.asBlueNode(nn) == n,"Wrong node conversion."); 72 check(G.asRedNode(nn) == INVALID,"Wrong node conversion."); 73 ++n; 74 } 75 check(n==INVALID,"Wrong blue Node list linking."); 76 check(countBlueNodes(G)==cnt,"Wrong blue Node number."); 77 } 78 79 template<class Graph> 44 80 void checkGraphArcList(const Graph &G, int cnt) 45 81 { … … 167 203 template <typename Graph> 168 204 void checkNodeIds(const Graph& G) { 205 typedef typename Graph::Node Node; 169 206 std::set<int> values; 170 207 for (typename Graph::NodeIt n(G); n != INVALID; ++n) { … … 174 211 values.insert(G.id(n)); 175 212 } 213 check(G.maxId(Node()) <= G.maxNodeId(), "Wrong maximum id"); 214 } 215 216 template <typename Graph> 217 void checkRedNodeIds(const Graph& G) { 218 typedef typename Graph::RedNode RedNode; 219 std::set<int> values; 220 for (typename Graph::RedNodeIt n(G); n != INVALID; ++n) { 221 check(G.red(n), "Wrong partition"); 222 check(values.find(G.id(n)) == values.end(), "Wrong id"); 223 check(G.id(n) <= G.maxRedId(), "Wrong maximum id"); 224 values.insert(G.id(n)); 225 } 226 check(G.maxId(RedNode()) == G.maxRedId(), "Wrong maximum id"); 227 } 228 229 template <typename Graph> 230 void checkBlueNodeIds(const Graph& G) { 231 typedef typename Graph::BlueNode BlueNode; 232 std::set<int> values; 233 for (typename Graph::BlueNodeIt n(G); n != INVALID; ++n) { 234 check(G.blue(n), "Wrong partition"); 235 check(values.find(G.id(n)) == values.end(), "Wrong id"); 236 check(G.id(n) <= G.maxBlueId(), "Wrong maximum id"); 237 values.insert(G.id(n)); 238 } 239 check(G.maxId(BlueNode()) == G.maxBlueId(), "Wrong maximum id"); 176 240 } 177 241 178 242 template <typename Graph> 179 243 void checkArcIds(const Graph& G) { 244 typedef typename Graph::Arc Arc; 180 245 std::set<int> values; 181 246 for (typename Graph::ArcIt a(G); a != INVALID; ++a) { … … 185 250 values.insert(G.id(a)); 186 251 } 252 check(G.maxId(Arc()) <= G.maxArcId(), "Wrong maximum id"); 187 253 } 188 254 189 255 template <typename Graph> 190 256 void checkEdgeIds(const Graph& G) { 257 typedef typename Graph::Edge Edge; 191 258 std::set<int> values; 192 259 for (typename Graph::EdgeIt e(G); e != INVALID; ++e) { … … 196 263 values.insert(G.id(e)); 197 264 } 265 check(G.maxId(Edge()) <= G.maxEdgeId(), "Wrong maximum id"); 198 266 } 199 267 … … 229 297 230 298 template <typename Graph> 299 void checkGraphRedNodeMap(const Graph& G) { 300 typedef typename Graph::Node Node; 301 typedef typename Graph::RedNodeIt RedNodeIt; 302 303 typedef typename Graph::template RedNodeMap<int> IntRedNodeMap; 304 IntRedNodeMap map(G, 42); 305 for (RedNodeIt it(G); it != INVALID; ++it) { 306 check(map[it] == 42, "Wrong map constructor."); 307 } 308 int s = 0; 309 for (RedNodeIt it(G); it != INVALID; ++it) { 310 map[it] = 0; 311 check(map[it] == 0, "Wrong operator[]."); 312 map.set(it, s); 313 check(map[it] == s, "Wrong set."); 314 ++s; 315 } 316 s = s * (s - 1) / 2; 317 for (RedNodeIt it(G); it != INVALID; ++it) { 318 s -= map[it]; 319 } 320 check(s == 0, "Wrong sum."); 321 322 // map = constMap<Node>(12); 323 // for (NodeIt it(G); it != INVALID; ++it) { 324 // check(map[it] == 12, "Wrong operator[]."); 325 // } 326 } 327 328 template <typename Graph> 329 void checkGraphBlueNodeMap(const Graph& G) { 330 typedef typename Graph::Node Node; 331 typedef typename Graph::BlueNodeIt BlueNodeIt; 332 333 typedef typename Graph::template BlueNodeMap<int> IntBlueNodeMap; 334 IntBlueNodeMap map(G, 42); 335 for (BlueNodeIt it(G); it != INVALID; ++it) { 336 check(map[it] == 42, "Wrong map constructor."); 337 } 338 int s = 0; 339 for (BlueNodeIt it(G); it != INVALID; ++it) { 340 map[it] = 0; 341 check(map[it] == 0, "Wrong operator[]."); 342 map.set(it, s); 343 check(map[it] == s, "Wrong set."); 344 ++s; 345 } 346 s = s * (s - 1) / 2; 347 for (BlueNodeIt it(G); it != INVALID; ++it) { 348 s -= map[it]; 349 } 350 check(s == 0, "Wrong sum."); 351 352 // map = constMap<Node>(12); 353 // for (NodeIt it(G); it != INVALID; ++it) { 354 // check(map[it] == 12, "Wrong operator[]."); 355 // } 356 } 357 358 template <typename Graph> 231 359 void checkGraphArcMap(const Graph& G) { 232 360 typedef typename Graph::Arc Arc; -
test/hao_orlin_test.cc
r956 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 67 67 CutMap cut; 68 68 Value v; 69 ::lemon::ignore_unused_variable_warning(v); 69 70 70 71 HaoOrlin<Digraph, CapMap> ho_test(g, cap); -
test/heap_test.cc
r1065 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). -
test/lgf_test.cc
r1087 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 15 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 64 64 65 65 66 int main() 66 int main() 67 67 { 68 68 { 69 ListDigraph d; 69 ListDigraph d; 70 70 ListDigraph::Node s,t; 71 71 ListDigraph::ArcMap<int> label(d); … … 94 94 95 95 { 96 ListDigraph d; 96 ListDigraph d; 97 97 std::istringstream input(test_lgf_nomap); 98 98 digraphReader(d, input). … … 111 111 112 112 { 113 ListDigraph d; 113 ListDigraph d; 114 114 std::istringstream input(test_lgf_bad1); 115 115 bool ok=false; … … 118 118 run(); 119 119 } 120 catch (FormatError&) 120 catch (FormatError&) 121 121 { 122 122 ok = true; … … 140 140 141 141 { 142 ListDigraph d; 142 ListDigraph d; 143 143 std::istringstream input(test_lgf_bad2); 144 144 bool ok=false; -
test/lp_test.cc
r1140 r1300 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 40 40 #endif 41 41 42 #ifdef LEMON_HAVE_LP 43 #include <lemon/lp.h> 44 #endif 42 45 using namespace lemon; 43 46 … … 199 202 c = c <= 4; 200 203 LP::Constr c2; 204 #if ( __GNUC__ == 4 ) && ( __GNUC_MINOR__ == 3 ) 205 c2 = ( -3 <= v ) <= 4; 206 #else 201 207 c2 = -3 <= v <= 4; 208 #endif 209 202 210 } 203 211 … … 241 249 { 242 250 LP::DualExpr e,f,g; 243 LP::Row p1 = INVALID, p2 = INVALID, p3 = INVALID, 244 p4 = INVALID, p5 = INVALID; 251 LP::Row p1 = INVALID, p2 = INVALID; 245 252 246 253 e[p1]=2; … … 413 420 lpTest(lp_skel); 414 421 422 #ifdef LEMON_HAVE_LP 423 { 424 Lp lp,lp2; 425 lpTest(lp); 426 aTest(lp2); 427 cloneTest<Lp>(); 428 } 429 #endif 430 415 431 #ifdef LEMON_HAVE_GLPK 416 432 { -
test/maps_test.cc
r1159 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 104 104 NullMap<A,B> map1; 105 105 NullMap<A,B> map2 = map1; 106 ignore_unused_variable_warning(map2);106 ::lemon::ignore_unused_variable_warning(map2); 107 107 map1 = nullMap<A,B>(); 108 108 } … … 115 115 ConstMap<A,B> map2 = B(); 116 116 ConstMap<A,B> map3 = map1; 117 ignore_unused_variable_warning(map2,map3);117 ::lemon::ignore_unused_variable_warning(map2,map3); 118 118 119 119 map1 = constMap<A>(B()); … … 122 122 ConstMap<A,C> map4(C(1)); 123 123 ConstMap<A,C> map5 = map4; 124 ignore_unused_variable_warning(map5);124 ::lemon::ignore_unused_variable_warning(map5); 125 125 126 126 map4 = constMap<A>(C(2)); … … 144 144 IdentityMap<A> map1; 145 145 IdentityMap<A> map2 = map1; 146 ignore_unused_variable_warning(map2);146 ::lemon::ignore_unused_variable_warning(map2); 147 147 148 148 map1 = identityMap<A>(); … … 205 205 checkConcept<ReadMap<B,double>, CompMap>(); 206 206 CompMap map1 = CompMap(DoubleMap(),ReadMap<B,A>()); 207 ignore_unused_variable_warning(map1);207 ::lemon::ignore_unused_variable_warning(map1); 208 208 CompMap map2 = composeMap(DoubleMap(), ReadMap<B,A>()); 209 ignore_unused_variable_warning(map2);209 ::lemon::ignore_unused_variable_warning(map2); 210 210 211 211 SparseMap<double, bool> m1(false); m1[3.14] = true; … … 220 220 checkConcept<ReadMap<A,double>, CombMap>(); 221 221 CombMap map1 = CombMap(DoubleMap(), DoubleMap()); 222 ignore_unused_variable_warning(map1);222 ::lemon::ignore_unused_variable_warning(map1); 223 223 CombMap map2 = combineMap(DoubleMap(), DoubleMap(), std::plus<double>()); 224 ignore_unused_variable_warning(map2);224 ::lemon::ignore_unused_variable_warning(map2); 225 225 226 226 check(combineMap(constMap<B,int,2>(), identityMap<B>(), &binc)[B()] == 3, … … 234 234 FunctorToMap<F> map1; 235 235 FunctorToMap<F> map2 = FunctorToMap<F>(F()); 236 ignore_unused_variable_warning(map2);236 ::lemon::ignore_unused_variable_warning(map2); 237 237 238 238 B b = functorToMap(F())[A()]; 239 ignore_unused_variable_warning(b);239 ::lemon::ignore_unused_variable_warning(b); 240 240 241 241 checkConcept<ReadMap<A,B>, MapToFunctor<ReadMap<A,B> > >(); 242 242 MapToFunctor<ReadMap<A,B> > map = 243 243 MapToFunctor<ReadMap<A,B> >(ReadMap<A,B>()); 244 ignore_unused_variable_warning(map);244 ::lemon::ignore_unused_variable_warning(map); 245 245 246 246 check(functorToMap(&func)[A()] == 3, … … 260 260 ConvertMap<ReadMap<double, int>, double> >(); 261 261 ConvertMap<RangeMap<bool>, int> map1(rangeMap(1, true)); 262 ignore_unused_variable_warning(map1);262 ::lemon::ignore_unused_variable_warning(map1); 263 263 ConvertMap<RangeMap<bool>, int> map2 = convertMap<int>(rangeMap(2, false)); 264 ignore_unused_variable_warning(map2);264 ::lemon::ignore_unused_variable_warning(map2); 265 265 266 266 } … … 536 536 537 537 typedef Orienter<Graph, const ConstMap<Edge, bool> > Digraph; 538 Digraph dgr(gr, constMap<Edge, bool>(true)); 538 ConstMap<Edge, bool> true_edge_map(true); 539 Digraph dgr(gr, true_edge_map); 539 540 OutDegMap<Digraph> odm(dgr); 540 541 InDegMap<Digraph> idm(dgr); -
test/matching_test.cc
r956 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 146 146 MaxMatching<Graph>::Status stat = 147 147 const_mat_test.status(n); 148 ::lemon::ignore_unused_variable_warning(stat); 148 149 const MaxMatching<Graph>::StatusMap& smap = 149 150 const_mat_test.statusMap(); -
test/min_cost_arborescence_test.cc
r956 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 92 92 VType c; 93 93 bool b; 94 ::lemon::ignore_unused_variable_warning(c,b); 94 95 int i; 95 96 CostMap cost; … … 127 128 c = const_mcarb_test.dualValue(i); 128 129 129 ignore_unused_variable_warning(am);130 ignore_unused_variable_warning(pm);130 ::lemon::ignore_unused_variable_warning(am); 131 ::lemon::ignore_unused_variable_warning(pm); 131 132 } 132 133 -
test/min_cost_flow_test.cc
r956 r1318 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 396 396 checkMcf(mcf3, mcf3.run(param), neg2_gr, neg2_l, neg2_u, neg2_c, neg2_s, 397 397 mcf3.OPTIMAL, true, -300, test_str + "-18", GEQ); 398 399 // Tests for empty graph 400 Digraph gr0; 401 MCF mcf0(gr0); 402 mcf0.run(param); 403 check(mcf0.totalCost() == 0, "Wrong total cost"); 398 404 } 399 405 -
test/min_mean_cycle_test.cc
r956 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 111 111 int cost, int size) { 112 112 MMC alg(gr, lm); 113 alg.findCycleMean();113 check(alg.findCycleMean(), "Wrong result"); 114 114 check(alg.cycleMean() == static_cast<double>(cost) / size, 115 115 "Wrong cycle mean"); … … 211 211 checkMmcAlg<HowardMmc<GR, IntArcMap> >(gr, l3, c3, 0, 1); 212 212 checkMmcAlg<HowardMmc<GR, IntArcMap> >(gr, l4, c4, -1, 1); 213 214 // Howard with iteration limit 215 HowardMmc<GR, IntArcMap> mmc(gr, l1); 216 check((mmc.findCycleMean(2) == HowardMmc<GR, IntArcMap>::ITERATION_LIMIT), 217 "Wrong termination cause"); 218 check((mmc.findCycleMean(4) == HowardMmc<GR, IntArcMap>::OPTIMAL), 219 "Wrong termination cause"); 213 220 } 214 221 -
test/mip_test.cc
r795 r1300 31 31 #ifdef LEMON_HAVE_CBC 32 32 #include <lemon/cbc.h> 33 #endif 34 35 #ifdef LEMON_HAVE_MIP 36 #include <lemon/lp.h> 33 37 #endif 34 38 … … 129 133 { 130 134 135 #ifdef LEMON_HAVE_MIP 136 { 137 Mip mip1; 138 aTest(mip1); 139 cloneTest<Mip>(); 140 } 141 #endif 142 131 143 #ifdef LEMON_HAVE_GLPK 132 144 { -
test/path_test.cc
r1144 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 22 22 #include <lemon/concepts/path.h> 23 23 #include <lemon/concepts/digraph.h> 24 #include <lemon/concept_check.h> 24 25 25 26 #include <lemon/path.h> … … 31 32 using namespace lemon; 32 33 33 void check_concepts() { 34 checkConcept<concepts::Path<ListDigraph>, concepts::Path<ListDigraph> >(); 35 checkConcept<concepts::Path<ListDigraph>, Path<ListDigraph> >(); 36 checkConcept<concepts::Path<ListDigraph>, SimplePath<ListDigraph> >(); 37 checkConcept<concepts::Path<ListDigraph>, StaticPath<ListDigraph> >(); 38 checkConcept<concepts::Path<ListDigraph>, ListPath<ListDigraph> >(); 34 template <typename GR> 35 void checkConcepts() { 36 checkConcept<concepts::Path<GR>, concepts::Path<GR> >(); 37 checkConcept<concepts::Path<GR>, Path<GR> >(); 38 checkConcept<concepts::Path<GR>, SimplePath<GR> >(); 39 checkConcept<concepts::Path<GR>, StaticPath<GR> >(); 40 checkConcept<concepts::Path<GR>, ListPath<GR> >(); 41 } 42 43 // Conecpt checking for path structures 44 void checkPathConcepts() { 45 checkConcepts<concepts::Digraph>(); 46 checkConcepts<ListDigraph>(); 39 47 } 40 48 41 49 // Check if proper copy consructor is called (use valgrind for testing) 42 template<class _Path> 43 void checkCopy() 44 { 50 template <typename GR, typename P1, typename P2> 51 void checkCopy(typename GR::Arc a) { 52 P1 p; 53 p.addBack(a); 54 P1 q; 55 q = p; 56 P1 r(p); 57 P2 q2; 58 q2 = p; 59 P2 r2(p); 60 } 61 62 // Tests for copy constructors and assignment operators of paths 63 void checkPathCopy() { 45 64 ListDigraph g; 46 ListDigraph::Arc a = g.addArc(g.addNode(), g.addNode()); 47 48 _Path p,q; 49 p.addBack(a); 50 q=p; 51 _Path r(p); 52 StaticPath<ListDigraph> s(r); 53 } 54 65 ListDigraph::Arc a = g.addArc(g.addNode(), g.addNode()); 66 67 typedef Path<ListDigraph> Path1; 68 typedef SimplePath<ListDigraph> Path2; 69 typedef ListPath<ListDigraph> Path3; 70 typedef StaticPath<ListDigraph> Path4; 71 checkCopy<ListDigraph, Path1, Path2>(a); 72 checkCopy<ListDigraph, Path1, Path3>(a); 73 checkCopy<ListDigraph, Path1, Path4>(a); 74 checkCopy<ListDigraph, Path2, Path1>(a); 75 checkCopy<ListDigraph, Path2, Path3>(a); 76 checkCopy<ListDigraph, Path2, Path4>(a); 77 checkCopy<ListDigraph, Path3, Path1>(a); 78 checkCopy<ListDigraph, Path3, Path2>(a); 79 checkCopy<ListDigraph, Path3, Path4>(a); 80 } 81 82 // Class for testing path functions 83 class CheckPathFunctions { 84 typedef ListDigraph GR; 85 DIGRAPH_TYPEDEFS(GR); 86 GR gr; 87 const GR& cgr; 88 Node n1, n2, n3, n4; 89 Node tmp_n; 90 Arc a1, a2, a3, a4; 91 Arc tmp_a; 92 93 public: 94 95 CheckPathFunctions() : cgr(gr) { 96 n1 = gr.addNode(); 97 n2 = gr.addNode(); 98 n3 = gr.addNode(); 99 n4 = gr.addNode(); 100 a1 = gr.addArc(n1, n2); 101 a2 = gr.addArc(n2, n3); 102 a3 = gr.addArc(n3, n4); 103 a4 = gr.addArc(n4, n1); 104 } 105 106 void run() { 107 checkBackAndFrontInsertablePath<Path<GR> >(); 108 checkBackAndFrontInsertablePath<ListPath<GR> >(); 109 checkBackInsertablePath<SimplePath<GR> >(); 110 111 checkListPathSplitAndSplice(); 112 } 113 114 private: 115 116 template <typename P> 117 void checkBackInsertablePath() { 118 119 // Create and check empty path 120 P p; 121 const P& cp = p; 122 check(cp.empty(), "The path is not empty"); 123 check(cp.length() == 0, "The path is not empty"); 124 // check(cp.front() == INVALID, "Wrong front()"); 125 // check(cp.back() == INVALID, "Wrong back()"); 126 typename P::ArcIt ai(cp); 127 check(ai == INVALID, "Wrong ArcIt"); 128 check(pathSource(cgr, cp) == INVALID, "Wrong pathSource()"); 129 check(pathTarget(cgr, cp) == INVALID, "Wrong pathTarget()"); 130 check(checkPath(cgr, cp), "Wrong checkPath()"); 131 PathNodeIt<P> ni(cgr, cp); 132 check(ni == INVALID, "Wrong PathNodeIt"); 133 134 // Check single-arc path 135 p.addBack(a1); 136 check(!cp.empty(), "Wrong empty()"); 137 check(cp.length() == 1, "Wrong length"); 138 check(cp.front() == a1, "Wrong front()"); 139 check(cp.back() == a1, "Wrong back()"); 140 check(cp.nth(0) == a1, "Wrong nth()"); 141 ai = cp.nthIt(0); 142 check((tmp_a = ai) == a1, "Wrong nthIt()"); 143 check(++ai == INVALID, "Wrong nthIt()"); 144 typename P::ArcIt ai2(cp); 145 check((tmp_a = ai2) == a1, "Wrong ArcIt"); 146 check(++ai2 == INVALID, "Wrong ArcIt"); 147 check(pathSource(cgr, cp) == n1, "Wrong pathSource()"); 148 check(pathTarget(cgr, cp) == n2, "Wrong pathTarget()"); 149 check(checkPath(cgr, cp), "Wrong checkPath()"); 150 PathNodeIt<P> ni2(cgr, cp); 151 check((tmp_n = ni2) == n1, "Wrong PathNodeIt"); 152 check((tmp_n = ++ni2) == n2, "Wrong PathNodeIt"); 153 check(++ni2 == INVALID, "Wrong PathNodeIt"); 154 155 // Check adding more arcs 156 p.addBack(a2); 157 p.addBack(a3); 158 check(!cp.empty(), "Wrong empty()"); 159 check(cp.length() == 3, "Wrong length"); 160 check(cp.front() == a1, "Wrong front()"); 161 check(cp.back() == a3, "Wrong back()"); 162 check(cp.nth(0) == a1, "Wrong nth()"); 163 check(cp.nth(1) == a2, "Wrong nth()"); 164 check(cp.nth(2) == a3, "Wrong nth()"); 165 typename P::ArcIt ai3(cp); 166 check((tmp_a = ai3) == a1, "Wrong ArcIt"); 167 check((tmp_a = ++ai3) == a2, "Wrong nthIt()"); 168 check((tmp_a = ++ai3) == a3, "Wrong nthIt()"); 169 check(++ai3 == INVALID, "Wrong nthIt()"); 170 ai = cp.nthIt(0); 171 check((tmp_a = ai) == a1, "Wrong nthIt()"); 172 check((tmp_a = ++ai) == a2, "Wrong nthIt()"); 173 ai = cp.nthIt(2); 174 check((tmp_a = ai) == a3, "Wrong nthIt()"); 175 check(++ai == INVALID, "Wrong nthIt()"); 176 check(pathSource(cgr, cp) == n1, "Wrong pathSource()"); 177 check(pathTarget(cgr, cp) == n4, "Wrong pathTarget()"); 178 check(checkPath(cgr, cp), "Wrong checkPath()"); 179 PathNodeIt<P> ni3(cgr, cp); 180 check((tmp_n = ni3) == n1, "Wrong PathNodeIt"); 181 check((tmp_n = ++ni3) == n2, "Wrong PathNodeIt"); 182 check((tmp_n = ++ni3) == n3, "Wrong PathNodeIt"); 183 check((tmp_n = ++ni3) == n4, "Wrong PathNodeIt"); 184 check(++ni3 == INVALID, "Wrong PathNodeIt"); 185 186 // Check arc removal and addition 187 p.eraseBack(); 188 p.eraseBack(); 189 p.addBack(a2); 190 check(!cp.empty(), "Wrong empty()"); 191 check(cp.length() == 2, "Wrong length"); 192 check(cp.front() == a1, "Wrong front()"); 193 check(cp.back() == a2, "Wrong back()"); 194 check(pathSource(cgr, cp) == n1, "Wrong pathSource()"); 195 check(pathTarget(cgr, cp) == n3, "Wrong pathTarget()"); 196 check(checkPath(cgr, cp), "Wrong checkPath()"); 197 198 // Check clear() 199 p.clear(); 200 check(cp.empty(), "The path is not empty"); 201 check(cp.length() == 0, "The path is not empty"); 202 203 // Check inconsistent path 204 p.addBack(a4); 205 p.addBack(a2); 206 p.addBack(a1); 207 check(!cp.empty(), "Wrong empty()"); 208 check(cp.length() == 3, "Wrong length"); 209 check(cp.front() == a4, "Wrong front()"); 210 check(cp.back() == a1, "Wrong back()"); 211 check(pathSource(cgr, cp) == n4, "Wrong pathSource()"); 212 check(pathTarget(cgr, cp) == n2, "Wrong pathTarget()"); 213 check(!checkPath(cgr, cp), "Wrong checkPath()"); 214 } 215 216 template <typename P> 217 void checkBackAndFrontInsertablePath() { 218 219 // Include back insertable test cases 220 checkBackInsertablePath<P>(); 221 222 // Check front and back insertion 223 P p; 224 const P& cp = p; 225 p.addFront(a4); 226 p.addBack(a1); 227 p.addFront(a3); 228 check(!cp.empty(), "Wrong empty()"); 229 check(cp.length() == 3, "Wrong length"); 230 check(cp.front() == a3, "Wrong front()"); 231 check(cp.back() == a1, "Wrong back()"); 232 check(cp.nth(0) == a3, "Wrong nth()"); 233 check(cp.nth(1) == a4, "Wrong nth()"); 234 check(cp.nth(2) == a1, "Wrong nth()"); 235 typename P::ArcIt ai(cp); 236 check((tmp_a = ai) == a3, "Wrong ArcIt"); 237 check((tmp_a = ++ai) == a4, "Wrong nthIt()"); 238 check((tmp_a = ++ai) == a1, "Wrong nthIt()"); 239 check(++ai == INVALID, "Wrong nthIt()"); 240 ai = cp.nthIt(0); 241 check((tmp_a = ai) == a3, "Wrong nthIt()"); 242 check((tmp_a = ++ai) == a4, "Wrong nthIt()"); 243 ai = cp.nthIt(2); 244 check((tmp_a = ai) == a1, "Wrong nthIt()"); 245 check(++ai == INVALID, "Wrong nthIt()"); 246 check(pathSource(cgr, cp) == n3, "Wrong pathSource()"); 247 check(pathTarget(cgr, cp) == n2, "Wrong pathTarget()"); 248 check(checkPath(cgr, cp), "Wrong checkPath()"); 249 250 // Check eraseFront() 251 p.eraseFront(); 252 p.addBack(a2); 253 check(!cp.empty(), "Wrong empty()"); 254 check(cp.length() == 3, "Wrong length"); 255 check(cp.front() == a4, "Wrong front()"); 256 check(cp.back() == a2, "Wrong back()"); 257 check(cp.nth(0) == a4, "Wrong nth()"); 258 check(cp.nth(1) == a1, "Wrong nth()"); 259 check(cp.nth(2) == a2, "Wrong nth()"); 260 typename P::ArcIt ai2(cp); 261 check((tmp_a = ai2) == a4, "Wrong ArcIt"); 262 check((tmp_a = ++ai2) == a1, "Wrong nthIt()"); 263 check((tmp_a = ++ai2) == a2, "Wrong nthIt()"); 264 check(++ai2 == INVALID, "Wrong nthIt()"); 265 ai = cp.nthIt(0); 266 check((tmp_a = ai) == a4, "Wrong nthIt()"); 267 check((tmp_a = ++ai) == a1, "Wrong nthIt()"); 268 ai = cp.nthIt(2); 269 check((tmp_a = ai) == a2, "Wrong nthIt()"); 270 check(++ai == INVALID, "Wrong nthIt()"); 271 check(pathSource(cgr, cp) == n4, "Wrong pathSource()"); 272 check(pathTarget(cgr, cp) == n3, "Wrong pathTarget()"); 273 check(checkPath(cgr, cp), "Wrong checkPath()"); 274 } 275 276 void checkListPathSplitAndSplice() { 277 278 // Build a path with spliceFront() and spliceBack() 279 ListPath<GR> p1, p2, p3, p4; 280 p1.addBack(a3); 281 p1.addFront(a2); 282 p2.addBack(a1); 283 p1.spliceFront(p2); 284 p3.addFront(a4); 285 p1.spliceBack(p3); 286 check(p1.length() == 4, "Wrong length"); 287 check(p1.front() == a1, "Wrong front()"); 288 check(p1.back() == a4, "Wrong back()"); 289 ListPath<GR>::ArcIt ai(p1); 290 check((tmp_a = ai) == a1, "Wrong ArcIt"); 291 check((tmp_a = ++ai) == a2, "Wrong nthIt()"); 292 check((tmp_a = ++ai) == a3, "Wrong nthIt()"); 293 check((tmp_a = ++ai) == a4, "Wrong nthIt()"); 294 check(++ai == INVALID, "Wrong nthIt()"); 295 check(checkPath(cgr, p1), "Wrong checkPath()"); 296 297 // Check split() 298 p1.split(p1.nthIt(2), p2); 299 check(p1.length() == 2, "Wrong length"); 300 ai = p1.nthIt(0); 301 check((tmp_a = ai) == a1, "Wrong ArcIt"); 302 check((tmp_a = ++ai) == a2, "Wrong nthIt()"); 303 check(++ai == INVALID, "Wrong nthIt()"); 304 check(checkPath(cgr, p1), "Wrong checkPath()"); 305 check(p2.length() == 2, "Wrong length"); 306 ai = p2.nthIt(0); 307 check((tmp_a = ai) == a3, "Wrong ArcIt"); 308 check((tmp_a = ++ai) == a4, "Wrong nthIt()"); 309 check(++ai == INVALID, "Wrong nthIt()"); 310 check(checkPath(cgr, p2), "Wrong checkPath()"); 311 312 // Check split() and splice() 313 p1.spliceFront(p2); 314 p1.split(p1.nthIt(2), p2); 315 p2.split(p2.nthIt(1), p3); 316 p2.spliceBack(p1); 317 p2.splice(p2.nthIt(1), p3); 318 check(p2.length() == 4, "Wrong length"); 319 check(p2.front() == a1, "Wrong front()"); 320 check(p2.back() == a4, "Wrong back()"); 321 ai = p2.nthIt(0); 322 check((tmp_a = ai) == a1, "Wrong ArcIt"); 323 check((tmp_a = ++ai) == a2, "Wrong nthIt()"); 324 check((tmp_a = ++ai) == a3, "Wrong nthIt()"); 325 check((tmp_a = ++ai) == a4, "Wrong nthIt()"); 326 check(++ai == INVALID, "Wrong nthIt()"); 327 check(checkPath(cgr, p2), "Wrong checkPath()"); 328 } 329 330 }; 331 55 332 int main() { 56 check_concepts(); 57 58 checkCopy<Path<ListDigraph> >(); 59 checkCopy<SimplePath<ListDigraph> >(); 60 checkCopy<ListPath<ListDigraph> >(); 61 62 ListDigraph g; 63 ListDigraph::Arc a = g.addArc(g.addNode(), g.addNode()); 64 65 Path<ListDigraph> p; 66 StaticPath<ListDigraph> q,r; 67 p.addBack(a); 68 q=p; 69 r=q; 70 StaticPath<ListDigraph> s(q); 333 checkPathConcepts(); 334 checkPathCopy(); 335 CheckPathFunctions cpf; 336 cpf.run(); 71 337 72 338 return 0; -
test/planarity_test.cc
r862 r1400 31 31 using namespace lemon::dim2; 32 32 33 const int lgfn = 4;33 const int lgfn = 8; 34 34 const std::string lgf[lgfn] = { 35 "@nodes\n" 36 "label\n" 37 "@edges\n" 38 " label\n", 39 40 "@nodes\n" 41 "label\n" 42 "0\n" 43 "@edges\n" 44 " label\n", 45 46 "@nodes\n" 47 "label\n" 48 "0\n" 49 "1\n" 50 "@edges\n" 51 " label\n" 52 "0 1 0\n", 53 54 "@nodes\n" 55 "label\n" 56 "0\n" 57 "1\n" 58 "2\n" 59 "@edges\n" 60 " label\n" 61 "0 1 0\n" 62 "1 2 1\n" 63 "2 0 2\n", 64 35 65 "@nodes\n" 36 66 "label\n" … … 137 167 } 138 168 } 139 check(face_num + countNodes(graph) - countConnectedComponents(graph) == 140 countEdges(graph) + 1, "Euler test does not passed"); 169 170 if (face_num != 0) { 171 check(face_num + countNodes(graph) - countConnectedComponents(graph) == 172 countEdges(graph) + 1, "Euler test does not passed"); 173 } 141 174 } 142 175 … … 246 279 checkEmbedding(graph, pe); 247 280 248 PlanarDrawing<Graph> pd(graph); 249 pd.run(pe.embeddingMap()); 250 checkDrawing(graph, pd); 251 252 PlanarColoring<Graph> pc(graph); 253 pc.runFiveColoring(pe.embeddingMap()); 254 checkColoring(graph, pc, 5); 281 { 282 PlanarDrawing<Graph> pd(graph); 283 pd.run(pe.embeddingMap()); 284 checkDrawing(graph, pd); 285 } 286 287 { 288 PlanarDrawing<Graph> pd(graph); 289 pd.run(); 290 checkDrawing(graph, pd); 291 } 292 293 { 294 PlanarColoring<Graph> pc(graph); 295 pc.runFiveColoring(pe.embeddingMap()); 296 checkColoring(graph, pc, 5); 297 } 298 299 { 300 PlanarColoring<Graph> pc(graph); 301 pc.runFiveColoring(); 302 checkColoring(graph, pc, 5); 303 } 255 304 256 305 } else { -
test/radix_sort_test.cc
r467 r1341 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 16 16 * 17 17 */ 18 19 #include <lemon/core.h> 18 20 19 21 #include <lemon/time_measure.h> … … 26 28 27 29 #include <vector> 30 #include <list> 28 31 #include <algorithm> 29 32 … … 40 43 int negate(int a) { return - a; } 41 44 42 43 void generateIntSequence(int n, std::vector<int>& data) { 45 template<class T> 46 bool isTheSame(T &a, T&b) 47 { 48 typename T::iterator ai=a.begin(); 49 typename T::iterator bi=b.begin(); 50 for(;ai!=a.end()||bi!=b.end();++ai,++bi) 51 if(*ai!=*bi) return false; 52 return ai==a.end()&&bi==b.end(); 53 } 54 55 template<class T> 56 T listsort(typename T::iterator b, typename T::iterator e) 57 { 58 if(b==e) return T(); 59 typename T::iterator bn=b; 60 if(++bn==e) { 61 T l; 62 l.push_back(*b); 63 return l; 64 } 65 typename T::iterator m=b; 66 bool x=false; 67 for(typename T::iterator i=b;i!=e;++i,x=!x) 68 if(x) ++m; 69 T l1(listsort<T>(b,m)); 70 T l2(listsort<T>(m,e)); 71 T l; 72 while((!l1.empty())&&(!l2.empty())) 73 if(l1.front()<=l2.front()) 74 { 75 l.push_back(l1.front()); 76 l1.pop_front(); 77 } 78 else { 79 l.push_back(l2.front()); 80 l2.pop_front(); 81 } 82 while(!l1.empty()) 83 { 84 l.push_back(l1.front()); 85 l1.pop_front(); 86 } 87 while(!l2.empty()) 88 { 89 l.push_back(l2.front()); 90 l2.pop_front(); 91 } 92 return l; 93 } 94 95 template<class T> 96 void generateIntSequence(int n, T & data) { 44 97 int prime = 9973; 45 98 int root = 136, value = 1; … … 50 103 } 51 104 52 void generateCharSequence(int n, std::vector<unsigned char>& data) { 105 template<class T> 106 void generateCharSequence(int n, T & data) { 53 107 int prime = 251; 54 108 int root = 3, value = root; … … 72 126 } 73 127 74 radixSort(data2.begin(), data2.end(), Negate()); 128 // radixSort(data2.begin(), data2.end(), Negate()); 129 // for (int i = 0; i < n; ++i) { 130 // check(data1[i] == data2[n - 1 - i], "Test failed"); 131 // } 132 133 // radixSort(data2.begin(), data2.end(), negate); 134 // for (int i = 0; i < n; ++i) { 135 // check(data1[i] == data2[n - 1 - i], "Test failed"); 136 // } 137 138 } 139 140 { 141 std::vector<unsigned char> data1(n); 142 generateCharSequence(n, data1); 143 144 std::vector<unsigned char> data2(data1); 145 std::sort(data1.begin(), data1.end()); 146 147 radixSort(data2.begin(), data2.end()); 148 for (int i = 0; i < n; ++i) { 149 check(data1[i] == data2[i], "Test failed"); 150 } 151 152 } 153 { 154 std::list<int> data1; 155 generateIntSequence(n, data1); 156 157 std::list<int> data2(listsort<std::list<int> >(data1.begin(), data1.end())); 158 159 radixSort(data1.begin(), data1.end()); 160 161 check(isTheSame(data1,data2), "Test failed"); 162 163 164 // radixSort(data2.begin(), data2.end(), Negate()); 165 // check(isTheSame(data1,data2), "Test failed"); 166 // for (int i = 0; i < n; ++i) { 167 // check(data1[i] == data2[n - 1 - i], "Test failed"); 168 // } 169 170 // radixSort(data2.begin(), data2.end(), negate); 171 // for (int i = 0; i < n; ++i) { 172 // check(data1[i] == data2[n - 1 - i], "Test failed"); 173 // } 174 175 } 176 177 { 178 std::list<unsigned char> data1(n); 179 generateCharSequence(n, data1); 180 181 std::list<unsigned char> data2(listsort<std::list<unsigned char> > 182 (data1.begin(), 183 data1.end())); 184 185 radixSort(data1.begin(), data1.end()); 186 check(isTheSame(data1,data2), "Test failed"); 187 188 } 189 } 190 191 192 void checkStableRadixSort() { 193 { 194 std::vector<int> data1; 195 generateIntSequence(n, data1); 196 197 std::vector<int> data2(data1); 198 std::sort(data1.begin(), data1.end()); 199 200 stableRadixSort(data2.begin(), data2.end()); 201 for (int i = 0; i < n; ++i) { 202 check(data1[i] == data2[i], "Test failed"); 203 } 204 205 stableRadixSort(data2.begin(), data2.end(), Negate()); 75 206 for (int i = 0; i < n; ++i) { 76 207 check(data1[i] == data2[n - 1 - i], "Test failed"); 77 208 } 78 209 79 radixSort(data2.begin(), data2.end(), negate);210 stableRadixSort(data2.begin(), data2.end(), negate); 80 211 for (int i = 0; i < n; ++i) { 81 212 check(data1[i] == data2[n - 1 - i], "Test failed"); 82 213 } 83 84 214 } 85 215 … … 97 227 98 228 } 99 } 100 101 102 void checkStableRadixSort() { 103 { 104 std::vector<int> data1; 105 generateIntSequence(n, data1); 106 107 std::vector<int> data2(data1); 108 std::sort(data1.begin(), data1.end()); 109 110 stableRadixSort(data2.begin(), data2.end()); 111 for (int i = 0; i < n; ++i) { 112 check(data1[i] == data2[i], "Test failed"); 113 } 114 115 stableRadixSort(data2.begin(), data2.end(), Negate()); 116 for (int i = 0; i < n; ++i) { 117 check(data1[i] == data2[n - 1 - i], "Test failed"); 118 } 119 120 stableRadixSort(data2.begin(), data2.end(), negate); 121 for (int i = 0; i < n; ++i) { 122 check(data1[i] == data2[n - 1 - i], "Test failed"); 123 } 124 } 125 126 { 127 std::vector<unsigned char> data1(n); 128 generateCharSequence(n, data1); 129 130 std::vector<unsigned char> data2(data1); 131 std::sort(data1.begin(), data1.end()); 132 133 radixSort(data2.begin(), data2.end()); 134 for (int i = 0; i < n; ++i) { 135 check(data1[i] == data2[i], "Test failed"); 136 } 229 { 230 std::list<int> data1; 231 generateIntSequence(n, data1); 232 233 std::list<int> data2(listsort<std::list<int> >(data1.begin(), 234 data1.end())); 235 stableRadixSort(data1.begin(), data1.end()); 236 check(isTheSame(data1,data2), "Test failed"); 237 238 // stableRadixSort(data2.begin(), data2.end(), Negate()); 239 // for (int i = 0; i < n; ++i) { 240 // check(data1[i] == data2[n - 1 - i], "Test failed"); 241 // } 242 243 // stableRadixSort(data2.begin(), data2.end(), negate); 244 // for (int i = 0; i < n; ++i) { 245 // check(data1[i] == data2[n - 1 - i], "Test failed"); 246 // } 247 } 248 249 { 250 std::list<unsigned char> data1(n); 251 generateCharSequence(n, data1); 252 253 std::list<unsigned char> data2(listsort<std::list<unsigned char> > 254 (data1.begin(), 255 data1.end())); 256 radixSort(data1.begin(), data1.end()); 257 check(isTheSame(data1,data2), "Test failed"); 137 258 138 259 } -
test/suurballe_test.cc
r956 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 118 118 int f; 119 119 VType c; 120 ::lemon::ignore_unused_variable_warning(f,c); 121 120 122 c = const_suurb_test.totalLength(); 121 123 f = const_suurb_test.flow(e); … … 128 130 Path<Digraph> p = const_suurb_test.path(k); 129 131 130 ignore_unused_variable_warning(fm);131 ignore_unused_variable_warning(pm);132 ::lemon::ignore_unused_variable_warning(fm); 133 ::lemon::ignore_unused_variable_warning(pm); 132 134 } 133 135 -
test/time_measure_test.cc
r1157 r1270 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 36 36 { 37 37 TimeStamp x(T); 38 ignore_unused_variable_warning(x);38 ::lemon::ignore_unused_variable_warning(x); 39 39 } 40 40 } -
tools/dimacs-solver.cc
r956 r1386 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 118 118 if (report) std::cerr << "Read the file: " << ti << '\n'; 119 119 120 ti.restart(); 121 NetworkSimplex<Digraph, Value> ns(g); 120 typedef NetworkSimplex<Digraph, Value> MCF; 121 ti.restart(); 122 MCF ns(g); 122 123 ns.lowerMap(lower).upperMap(cap).costMap(cost).supplyMap(sup); 123 124 if (sum_sup > 0) ns.supplyType(ns.LEQ); 124 125 if (report) std::cerr << "Setup NetworkSimplex class: " << ti << '\n'; 125 126 ti.restart(); 126 boolres = ns.run();127 typename MCF::ProblemType res = ns.run(); 127 128 if (report) { 128 129 std::cerr << "Run NetworkSimplex: " << ti << "\n\n"; 129 std::cerr << "Feasible flow: " << (res ? "found" : "not found") << '\n'; 130 std::cerr << "Feasible flow: " << (res == MCF::OPTIMAL ? "found" : 131 "not found") << '\n'; 130 132 if (res) std::cerr << "Min flow cost: " 131 133 << ns.template totalCost<LargeValue>() << '\n'; … … 188 190 189 191 int main(int argc, const char *argv[]) { 190 typedef SmartDigraph Digraph;191 192 typedef Digraph::Arc Arc;193 192 194 193 std::string inputName; … … 224 223 throw IoError("Cannot open the file for writing", ap.files()[1]); 225 224 } 225 // fall through 226 226 case 1: 227 227 input.open(ap.files()[0].c_str()); … … 229 229 throw IoError("File cannot be found", ap.files()[0]); 230 230 } 231 // fall through 231 232 case 0: 232 233 break; … … 253 254 case DimacsDescriptor::SP: 254 255 std::cout << "sp"; 256 break; 255 257 case DimacsDescriptor::MAT: 256 258 std::cout << "mat"; -
tools/dimacs-to-lgf.cc
r631 r1397 74 74 throw IoError("Cannot open the file for writing", ap.files()[1]); 75 75 } 76 // fall through 76 77 case 1: 77 78 input.open(ap.files()[0].c_str()); … … 79 80 throw IoError("File cannot be found", ap.files()[0]); 80 81 } 82 // fall through 81 83 case 0: 82 84 break; -
tools/lgf-gen.cc
r701 r1308 247 247 struct BeachIt; 248 248 249 typedef std::multimap<double, BeachIt > SpikeHeap;249 typedef std::multimap<double, BeachIt*> SpikeHeap; 250 250 251 251 typedef std::multimap<Part, SpikeHeap::iterator, YLess> Beach; … … 330 330 331 331 if (bit->second != spikeheap.end()) { 332 delete bit->second->second; 332 333 spikeheap.erase(bit->second); 333 334 } … … 343 344 circle_form(points[prev], points[curr], points[site])) { 344 345 double x = circle_point(points[prev], points[curr], points[site]); 345 pit = spikeheap.insert(std::make_pair(x, BeachIt(beach.end())));346 pit->second .it =346 pit = spikeheap.insert(std::make_pair(x, new BeachIt(beach.end()))); 347 pit->second->it = 347 348 beach.insert(std::make_pair(Part(prev, curr, site), pit)); 348 349 } else { … … 356 357 circle_form(points[site], points[curr],points[next])) { 357 358 double x = circle_point(points[site], points[curr], points[next]); 358 nit = spikeheap.insert(std::make_pair(x, BeachIt(beach.end())));359 nit->second .it =359 nit = spikeheap.insert(std::make_pair(x, new BeachIt(beach.end()))); 360 nit->second->it = 360 361 beach.insert(std::make_pair(Part(site, curr, next), nit)); 361 362 } else { … … 367 368 sweep = spit->first; 368 369 369 Beach::iterator bit = spit->second .it;370 Beach::iterator bit = spit->second->it; 370 371 371 372 int prev = bit->first.prev; … … 400 401 int nnt = nbit->first.next; 401 402 402 if (bit->second != spikeheap.end()) spikeheap.erase(bit->second); 403 if (pbit->second != spikeheap.end()) spikeheap.erase(pbit->second); 404 if (nbit->second != spikeheap.end()) spikeheap.erase(nbit->second); 405 403 if (bit->second != spikeheap.end()) 404 { 405 delete bit->second->second; 406 spikeheap.erase(bit->second); 407 } 408 if (pbit->second != spikeheap.end()) 409 { 410 delete pbit->second->second; 411 spikeheap.erase(pbit->second); 412 } 413 if (nbit->second != spikeheap.end()) 414 { 415 delete nbit->second->second; 416 spikeheap.erase(nbit->second); 417 } 418 406 419 beach.erase(nbit); 407 420 beach.erase(bit); … … 413 426 double x = circle_point(points[ppv], points[prev], points[next]); 414 427 if (x < sweep) x = sweep; 415 pit = spikeheap.insert(std::make_pair(x, BeachIt(beach.end())));416 pit->second .it =428 pit = spikeheap.insert(std::make_pair(x, new BeachIt(beach.end()))); 429 pit->second->it = 417 430 beach.insert(std::make_pair(Part(ppv, prev, next), pit)); 418 431 } else { … … 425 438 double x = circle_point(points[prev], points[next], points[nnt]); 426 439 if (x < sweep) x = sweep; 427 nit = spikeheap.insert(std::make_pair(x, BeachIt(beach.end())));428 nit->second .it =440 nit = spikeheap.insert(std::make_pair(x, new BeachIt(beach.end()))); 441 nit->second->it = 429 442 beach.insert(std::make_pair(Part(prev, next, nnt), nit)); 430 443 } else {
Note: See TracChangeset
for help on using the changeset viewer.

