Changes in / [330:34e185734b42:331:a412d990f043] in lemon-1.0
- Files:
-
- 9 added
- 2 deleted
- 71 edited
Legend:
- Unmodified
- Added
- Removed
-
.hgignore
r155 r298 30 30 syntax: regexp 31 31 (.*/)?\#[^/]*\#$ 32 (.*/)?\.\#[^/]*$ 32 33 ^doc/html/.* 34 ^doc/.*\.tag 33 35 ^autom4te.cache/.* 34 36 ^build-aux/.* -
CMakeLists.txt
r141 r274 1 project (LEMON) 2 enable_testing () 3 add_subdirectory (lemon) 4 add_subdirectory (demo) 5 add_subdirectory (test) 1 CMAKE_MINIMUM_REQUIRED(VERSION 2.6) 2 3 SET(PROJECT_NAME "LEMON") 4 SET(PROJECT_VERSION "hg-tip" CACHE STRING "The version string.") 5 6 PROJECT(${PROJECT_NAME}) 7 8 SET(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) 9 10 INCLUDE(FindDoxygen) 11 INCLUDE(FindGhostscript) 12 13 ENABLE_TESTING() 14 15 ADD_SUBDIRECTORY(lemon) 16 ADD_SUBDIRECTORY(demo) 17 ADD_SUBDIRECTORY(doc) 18 ADD_SUBDIRECTORY(test) 19 20 IF(WIN32) 21 INSTALL(FILES ${CMAKE_SOURCE_DIR}/cmake/nsis/lemon.ico 22 DESTINATION bin) 23 ENDIF(WIN32) 24 25 IF(WIN32) 26 SET(CPACK_PACKAGE_NAME ${PROJECT_NAME}) 27 SET(CPACK_PACKAGE_VENDOR 28 "EGRES - Egervary Research Group on Combinatorial Optimization") 29 SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY 30 "LEMON - Library of Efficient Models and Optimization in Networks") 31 SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/LICENSE") 32 33 SET(CPACK_PACKAGE_VERSION ${PROJECT_VERSION}) 34 35 SET(CPACK_PACKAGE_INSTALL_DIRECTORY 36 "${PROJECT_NAME} ${PROJECT_VERSION}") 37 SET(CPACK_PACKAGE_INSTALL_REGISTRY_KEY 38 "${PROJECT_NAME} ${PROJECT_VERSION}") 39 40 # Variables to generate a component-based installer. 41 #SET(CPACK_COMPONENTS_ALL headers library html_documentation) 42 43 #SET(CPACK_COMPONENT_HEADERS_DISPLAY_NAME "C++ headers") 44 #SET(CPACK_COMPONENT_LIBRARY_DISPLAY_NAME "Static library") 45 #SET(CPACK_COMPONENT_HTML_DOCUMENTATION_DISPLAY_NAME "HTML documentation") 46 47 #SET(CPACK_COMPONENT_HEADERS_DESCRIPTION 48 # "C++ header files for use with the LEMON library") 49 #SET(CPACK_COMPONENT_LIBRARY_DESCRIPTION 50 # "Static library used to build programs with LEMON") 51 #SET(CPACK_COMPONENT_HTML_DOCUMENTATION_DESCRIPTION 52 # "Doxygen generated documentation") 53 54 #SET(CPACK_COMPONENT_HEADERS_DEPENDS library) 55 56 #SET(CPACK_COMPONENT_HEADERS_GROUP "Development") 57 #SET(CPACK_COMPONENT_LIBRARY_GROUP "Development") 58 #SET(CPACK_COMPONENT_HTML_DOCUMENTATION_GROUP "Documentation") 59 60 #SET(CPACK_COMPONENT_GROUP_DEVELOPMENT_DESCRIPTION 61 # "Components needed to develop software using LEMON") 62 #SET(CPACK_COMPONENT_GROUP_DOCUMENTATION_DESCRIPTION 63 # "Documentation of LEMON") 64 65 #SET(CPACK_ALL_INSTALL_TYPES Full Developer) 66 67 #SET(CPACK_COMPONENT_HEADERS_INSTALL_TYPES Developer Full) 68 #SET(CPACK_COMPONENT_LIBRARY_INSTALL_TYPES Developer Full) 69 #SET(CPACK_COMPONENT_HTML_DOCUMENTATION_INSTALL_TYPES Full) 70 71 SET(CPACK_GENERATOR "NSIS") 72 SET(CPACK_NSIS_MUI_ICON "${CMAKE_SOURCE_DIR}/cmake/nsis/lemon.ico") 73 SET(CPACK_NSIS_MUI_UNIICON "${CMAKE_SOURCE_DIR}/cmake/nsis/uninstall.ico") 74 #SET(CPACK_PACKAGE_ICON "${CMAKE_SOURCE_DIR}/cmake/nsis\\\\installer.bmp") 75 SET(CPACK_NSIS_INSTALLED_ICON_NAME "bin\\\\lemon.ico") 76 SET(CPACK_NSIS_DISPLAY_NAME "${CPACK_PACKAGE_INSTALL_DIRECTORY} ${PROJECT_NAME}") 77 SET(CPACK_NSIS_HELP_LINK "http:\\\\\\\\lemon.cs.elte.hu") 78 SET(CPACK_NSIS_URL_INFO_ABOUT "http:\\\\\\\\lemon.cs.elte.hu") 79 SET(CPACK_NSIS_CONTACT "lemon-user@lemon.cs.elte.hu") 80 SET(CPACK_NSIS_CREATE_ICONS_EXTRA " 81 CreateShortCut \\\"$SMPROGRAMS\\\\$STARTMENU_FOLDER\\\\Documentation.lnk\\\" \\\"$INSTDIR\\\\doc\\\\index.html\\\" 82 ") 83 SET(CPACK_NSIS_DELETE_ICONS_EXTRA " 84 !insertmacro MUI_STARTMENU_GETFOLDER Application $MUI_TEMP 85 Delete \\\"$SMPROGRAMS\\\\$MUI_TEMP\\\\Documentation.lnk\\\" 86 ") 87 88 INCLUDE(CPack) 89 ENDIF(WIN32) -
INSTALL
r5 r325 2 2 ========================= 3 3 4 4 Since you are reading this I assume you already obtained one of the release 5 5 tarballs and successfully extracted it. The latest version of LEMON is 6 available at our web page (http://lemon.cs.elte.hu/).6 available at our web page (http://lemon.cs.elte.hu/). 7 7 8 8 In order to install LEMON from the extracted source tarball you have to 9 9 issue the following commands: 10 10 11 1. `cd lemon-x.y.z'11 1. `cd lemon-x.y.z' 12 12 13 This changes to the directory which was created when you extracted the14 sources. The x.y.z part is a version number.13 This command changes to the directory which was created when you 14 extracted the sources. The x.y.z part is a version number. 15 15 16 2. `./configure'16 2. `./configure' 17 17 18 Thisruns the configure shell script, which does some checks and19 configuration (creates makefiles etc).18 This command runs the configure shell script, which does some checks and 19 creates the makefiles. 20 20 21 3. `make'21 3. `make' 22 22 23 This command compiles the non-template part of LEMON into libemon.a file. 24 It also compiles the benchmark and demo programs when enabled. 23 This command compiles the non-template part of LEMON into libemon.a 24 file. It also compiles the programs in the tools and demo subdirectories 25 when enabled. 25 26 26 4. `make check'27 4. `make check' 27 28 28 This step is optional, but recommended. It runs the test programs that we29 developed for LEMON to check whether the library works properly on your30 platform.29 This step is optional, but recommended. It runs the test programs that 30 we developed for LEMON to check whether the library works properly on 31 your platform. 31 32 32 5. `make install'33 5. `make install' 33 34 34 This command installs LEMON under /usr/local (you will need root 35 privileges to be able to do that). If you want to install it to some 36 other location, then pass the --prefix=DIRECTORY flag to configure in 37 step 1. For example: `./configure --prefix=/home/username/lemon' 35 This command installs LEMON under /usr/local (you will need root 36 privileges to be able to do that). If you want to install it to some 37 other location, then pass the --prefix=DIRECTORY flag to configure in 38 step 2. For example: `./configure --prefix=/home/username/lemon'. 39 40 6. `make install-html' 41 42 This command installs the documentation under share/doc/lemon/docs. The 43 generated documentation is included in the tarball. If you want to 44 generate it yourself, then run `make html'. Note that for this you need 45 to have the following programs installed: Doxygen, Graphviz, Ghostscript, 46 Latex. 38 47 39 48 40 Configure Flags41 =============== 49 Configure Options and Variables 50 =============================== 42 51 43 You can pass the following flags to configure in step 1 44 (see ./configure --help for more): 52 In step 2 you can customize the actions of configure by setting variables 53 and passing options to it. This can be done like this: 54 `./configure [OPTION]... [VARIABLE=VALUE]...' 45 55 46 CXX=comp 56 Below you will find some useful variables and options (see `./configure --help' 57 for more): 58 59 CXX='comp' 47 60 48 61 Change the C++ compiler to 'comp'. … … 50 63 CXXFLAGS='flags' 51 64 52 Pass the 'flags' to the compiler. For example 53 CXXFLAGS='-O3 -march=pentium-m' 54 turns on generation of aggressively optimized 55 Pentium-M specific code. 65 Pass the 'flags' to the compiler. For example CXXFLAGS='-O3 -march=pentium-m' 66 turns on generation of aggressively optimized Pentium-M specific code. 67 68 --prefix=PREFIX 69 70 Set the installation prefix to PREFIX. By default it is /usr/local. 56 71 57 72 --enable-demo 58 73 59 Build the demo programs too.74 Build the examples in the demo subdirectory. 60 75 61 76 --disable-demo 62 77 63 Do not build the demo programs(default).78 Do not build the examples in the demo subdirectory (default). 64 79 65 --enable- benchmark80 --enable-tools 66 81 67 Build the benchmark programs too.82 Build the programs in the tools subdirectory (default). 68 83 69 --disable- benchmark84 --disable-tools 70 85 71 Do not build the benchmark programs (default).86 Do not build the programs in the tools subdirectory. 72 87 73 88 --with-glpk[=PREFIX] … … 116 131 117 132 Disable CPLEX support. 133 134 --with-soplex[=PREFIX] 135 136 Enable SoPlex support (default). You should specify the prefix too if 137 you installed SoPlex to some non-standard location (e.g. your home 138 directory). If it is not found, SoPlex support will be disabled. 139 140 --with-soplex-includedir=DIR 141 142 The directory where the SoPlex header files are located. This is only 143 useful when the SoPlex headers and libraries are not under the same 144 prefix (which is unlikely). 145 146 --with-soplex-libdir=DIR 147 148 The directory where the SoPlex libraries are located. This is only 149 useful when the SoPlex headers and libraries are not under the same 150 prefix (which is unlikely). 151 152 --without-soplex 153 154 Disable SoPlex support. -
Makefile.am
r330 r331 10 10 m4/lx_check_glpk.m4 \ 11 11 m4/lx_check_soplex.m4 \ 12 CMakeLists.txt 12 CMakeLists.txt \ 13 cmake 13 14 14 15 pkgconfigdir = $(libdir)/pkgconfig … … 25 26 bin_PROGRAMS = 26 27 check_PROGRAMS = 28 dist_bin_SCRIPTS = 27 29 TESTS = 28 30 XFAIL_TESTS = … … 32 34 include doc/Makefile.am 33 35 include demo/Makefile.am 34 include benchmark/Makefile.am35 36 include tools/Makefile.am 36 37 -
NEWS
r5 r262 1 20XX-XX-XX Version 1.0 released 2 3 This is the first stable release of LEMON. Compared to the 0.x 4 release series, it features a considerably smaller but more 5 matured set of tools. The API has also completely revised and 6 changed in several places. 7 8 * The major name changes compared to the 0.x series 9 * Graph -> Digraph, UGraph -> Graph 10 * Edge -> Arc, UEdge -> Edge 11 * source(UEdge)/target(UEdge) -> u(Edge)/v(Edge) 12 * Other improvements 13 * Better documentation 14 * Reviewed and cleaned up codebase 15 * CMake based build system (along with the autotools based one) 16 * Contents of the library (ported from 0.x) 17 * Algorithms 18 * breadth-first search (bfs.h) 19 * depth-first search (dfs.h) 20 * Dijkstra's algorithm (dijkstra.h) 21 * Kruskal's algorithm (kruskal.h) 22 * Data structures 23 * graph data structures (list_graph.h, smart_graph.h) 24 * path data structures (path.h) 25 * binary heap data structure (bin_heap.h) 26 * union-find data structures (unionfind.h) 27 * miscellaneous property maps (maps.h) 28 * two dimensional vector and bounding box (dim2.h) 29 * Concepts 30 * graph structure concepts (concepts/digraph.h, concepts/graph.h, 31 concepts/graph_components.h) 32 * concepts for other structures (concepts/heap.h, concepts/maps.h, 33 concepts/path.h) 34 * Tools 35 * Mersenne twister random number generator (random.h) 36 * tools for measuring cpu and wall clock time (time_measure.h) 37 * tools for counting steps and events (counter.h) 38 * tool for parsing command line arguments (arg_parser.h) 39 * tool for visualizing graphs (graph_to_eps.h) 40 * tools for reading and writing data in LEMON Graph Format 41 (lgf_reader.h, lgf_writer.h) 42 * tools to handle the anomalies of calculations with 43 floating point numbers (tolerance.h) 44 * tools to manage RGB colors (color.h) 45 * Infrastructure 46 * extended assertion handling (assert.h) 47 * exception classes and error handling (error.h) 48 * concept checking (concept_check.h) 49 * commonly used mathematical constants (math.h) -
README
r24 r325 1 ------------------------------------------------------------------ 1 ================================================================== 2 2 LEMON - a Library of Efficient Models and Optimization in Networks 3 ------------------------------------------------------------------ 3 ================================================================== 4 4 5 LEMON is the abbreviation of Library of Efficient Models and 6 Optimization in Networks. It is an open source library written in 7 C++. It provides a set of easy-to-use implementation of common data 8 structures and algorithms in the area of optimization and helps 9 implementing new ones. It is an especially suitable tool to solve the 10 design and optimization problems of telecommunications networks. To 11 achieve wide usability, a fundamental design requirement is the 12 genericity of interface of data structures and algorithms. LEMON is an 13 open source library end invites people all around the world in its 14 development. 5 LEMON is an open source library written in C++. It provides 6 easy-to-use implementations of common data structures and algorithms 7 in the area of optimization and helps implementing new ones. The main 8 focus is on graphs and graph algorithms, thus it is especially 9 suitable for solving design and optimization problems of 10 telecommunication networks. To achieve wide usability its data 11 structures and algorithms provide generic interfaces. 15 12 16 --------17 13 Contents 18 -------- 14 ======== 19 15 20 COPYING,LICENSE16 LICENSE 21 17 22 Copying, distribution and modification conditions and terms.18 Copying, distribution and modification conditions and terms. 23 19 24 20 INSTALL 25 21 26 For general building and installation instructions, see the file.22 General building and installation instructions. 27 23 28 24 lemon/ 29 25 30 Source code of LEMON itself.26 Source code of LEMON library. 31 27 32 28 doc/ 33 29 34 Documentation of LEMON. The starting page is doc/html/index.html. 35 The documentation installs into the directory 36 37 /usr/local/share/doc/lemon/html 38 39 or -- if you use different prefix -- into 40 41 ${prefix}/share/doc/lemon/html 42 43 (see also INSTALL). 30 Documentation of LEMON. The starting page is doc/html/index.html. 44 31 45 32 demo/ 46 33 47 Some demonstration programs to make you easier to get familiar with 48 LEMON. Use --enable-demo configure option to also compile these codes 49 (see also INSTALL). 34 Some example programs to make you easier to get familiar with LEMON. 50 35 51 36 test/ 52 37 53 Contains programs to check the integrity and correctness of 54 LEMON. The command 'make check' performs these tests. 38 Programs to check the integrity and correctness of LEMON. 55 39 56 benchmark/ 57 58 Contains programs measuring the performance of LEMON. Use 59 --enable-benchmark configure option to also compile these codes (see 60 also INSTALL). 40 tools/ 41 42 Various utilities related to LEMON. -
configure.ac
r219 r314 2 2 3 3 dnl Version information. 4 m4_define([lemon_version_number], []) 4 m4_define([lemon_version_number], 5 [m4_normalize(esyscmd([echo ${LEMON_VERSION}]))]) 6 dnl m4_define([lemon_version_number], []) 7 m4_define([lemon_hg_path], [m4_normalize(esyscmd([./scripts/chg-len.py]))]) 5 8 m4_define([lemon_hg_revision], [m4_normalize(esyscmd([hg id -i]))]) 6 m4_define([lemon_version], [ifelse(lemon_version_number(), [], [lemon_hg_revision()], [lemon_version_number()])]) 9 m4_define([lemon_version], [ifelse(lemon_version_number(), 10 [], 11 [lemon_hg_path().lemon_hg_revision()], 12 [lemon_version_number()])]) 7 13 8 14 AC_PREREQ([2.59]) 9 AC_INIT([LEMON], [lemon_version()], [lemon- devel@lemon.cs.elte.hu], [lemon])15 AC_INIT([LEMON], [lemon_version()], [lemon-user@lemon.cs.elte.hu], [lemon]) 10 16 AC_CONFIG_AUX_DIR([build-aux]) 11 17 AC_CONFIG_MACRO_DIR([m4]) … … 15 21 16 22 lx_cmdline_cxxflags_set=${CXXFLAGS+set} 23 24 dnl Do compilation tests using the C++ compiler. 25 AC_LANG([C++]) 17 26 18 27 dnl Checks for programs. … … 26 35 AC_CHECK_PROG([gs_found],[gs],[yes],[no]) 27 36 28 if test x"$lx_cmdline_cxxflags_set" != x"set" -a "$GXX" = yes; then 37 dnl Detect Intel compiler. 38 AC_MSG_CHECKING([whether we are using the Intel C++ compiler]) 39 AC_COMPILE_IFELSE([#ifndef __INTEL_COMPILER 40 choke me 41 #endif], [ICC=[yes]], [ICC=[no]]) 42 if test x"$ICC" = x"yes"; then 43 AC_MSG_RESULT([yes]) 44 else 45 AC_MSG_RESULT([no]) 46 fi 47 48 dnl Set custom compiler flags when using g++. 49 if test x"$lx_cmdline_cxxflags_set" != x"set" -a "$GXX" = yes -a "$ICC" = no; then 29 50 CXXFLAGS="$CXXFLAGS -Wall -W -Wall -W -Wunused -Wformat=2 -Wctor-dtor-privacy -Wnon-virtual-dtor -Wno-char-subscripts -Wwrite-strings -Wno-char-subscripts -Wreturn-type -Wcast-qual -Wcast-align -Wsign-promo -Woverloaded-virtual -Woverloaded-virtual -ansi -fno-strict-aliasing -Wold-style-cast -Wno-unknown-pragmas" 30 51 fi 31 52 32 53 dnl Checks for libraries. 33 LX_CHECK_GLPK34 LX_CHECK_CPLEX35 LX_CHECK_SOPLEX54 #LX_CHECK_GLPK 55 #LX_CHECK_CPLEX 56 #LX_CHECK_SOPLEX 36 57 37 dnl Disable/enable building the demo programs 58 dnl Disable/enable building the demo programs. 38 59 AC_ARG_ENABLE([demo], 39 60 AS_HELP_STRING([--enable-demo], [build the demo programs]) … … 48 69 AM_CONDITIONAL([WANT_DEMO], [test x"$enable_demo" != x"no"]) 49 70 50 dnl Disable/enable building the binary tools 71 dnl Disable/enable building the binary tools. 51 72 AC_ARG_ENABLE([tools], 52 73 AS_HELP_STRING([--enable-tools], [build additional tools @<:@default@:>@]) … … 60 81 fi 61 82 AM_CONDITIONAL([WANT_TOOLS], [test x"$enable_tools" != x"no"]) 62 63 dnl Disable/enable building the benchmarks64 AC_ARG_ENABLE([benchmark],65 AS_HELP_STRING([--enable-benchmark], [build the benchmarks])66 AS_HELP_STRING([--disable-benchmark], [do not build the benchmarks @<:@default@:>@]),67 [], [enable_benchmark=no])68 AC_MSG_CHECKING([whether to build the benchmarks])69 if test x"$enable_benchmark" != x"no"; then70 AC_MSG_RESULT([yes])71 else72 AC_MSG_RESULT([no])73 fi74 AM_CONDITIONAL([WANT_BENCHMARK], [test x"$enable_benchmark" != x"no"])75 83 76 84 dnl Checks for header files. … … 108 116 echo C++ compiles flags............ : $CXXFLAGS 109 117 echo 110 echo GLPK support.................. : $lx_glpk_found 111 echo CPLEX support................. : $lx_cplex_found 112 echo SOPLEX support................ : $lx_soplex_found 113 echo 114 echo Build benchmarks.............. : $enable_benchmark 118 #echo GLPK support.................. : $lx_glpk_found 119 #echo CPLEX support................. : $lx_cplex_found 120 #echo SOPLEX support................ : $lx_soplex_found 121 #echo 115 122 echo Build demo programs........... : $enable_demo 116 123 echo Build additional tools........ : $enable_tools -
demo/CMakeLists.txt
r141 r225 1 include_directories (${LEMON_SOURCE_DIR})1 INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}) 2 2 3 link_directories (${LEMON_BINARY_DIR}/lemon)3 LINK_DIRECTORIES(${CMAKE_BINARY_DIR}/lemon) 4 4 5 set(DEMOS5 SET(DEMOS 6 6 arg_parser_demo 7 7 graph_to_eps_demo 8 8 lgf_demo) 9 9 10 foreach(DEMO_NAME ${DEMOS})11 add_executable(${DEMO_NAME} ${DEMO_NAME}.cc)12 target_link_libraries(${DEMO_NAME} lemon)13 endforeach(DEMO_NAME)10 FOREACH(DEMO_NAME ${DEMOS}) 11 ADD_EXECUTABLE(${DEMO_NAME} ${DEMO_NAME}.cc) 12 TARGET_LINK_LIBRARIES(${DEMO_NAME} lemon) 13 ENDFOREACH(DEMO_NAME) -
demo/arg_parser_demo.cc
r209 r315 28 28 29 29 using namespace lemon; 30 int main(int argc, c onst char **argv)30 int main(int argc, char **argv) 31 31 { 32 32 // Initialize the argument parser -
demo/graph_to_eps_demo.cc
r220 r317 27 27 /// how to handle parallel egdes, how to change the properties (like 28 28 /// color, shape, size, title etc.) of nodes and arcs individually 29 /// using appropriate \ref maps-page "graph maps".29 /// using appropriate graph maps. 30 30 /// 31 31 /// \include graph_to_eps_demo.cc -
demo/lgf_demo.cc
r209 r294 45 45 46 46 try { 47 digraphReader( "digraph.lgf", g). // read the directed graph into g47 digraphReader(g, "digraph.lgf"). // read the directed graph into g 48 48 arcMap("capacity", cap). // read the 'capacity' arc map into cap 49 49 node("source", s). // read 'source' node to s 50 50 node("target", t). // read 'target' node to t 51 51 run(); 52 } catch ( DataFormatError& error) { // check if there was any error52 } catch (Exception& error) { // check if there was any error 53 53 std::cerr << "Error: " << error.what() << std::endl; 54 54 return -1; … … 61 61 std::cout << "We can write it to the standard output:" << std::endl; 62 62 63 digraphWriter( std::cout, g).// write g to the standard output63 digraphWriter(g). // write g to the standard output 64 64 arcMap("capacity", cap). // write cap into 'capacity' 65 65 node("source", s). // write s to 'source' -
doc/Doxyfile.in
r219 r321 1 # Doxyfile 1.5. 51 # Doxyfile 1.5.7.1 2 2 3 3 #--------------------------------------------------------------------------- … … 16 16 INLINE_INHERITED_MEMB = NO 17 17 FULL_PATH_NAMES = YES 18 STRIP_FROM_PATH = @abs_top_srcdir@19 STRIP_FROM_INC_PATH = @abs_top_srcdir@18 STRIP_FROM_PATH = "@abs_top_srcdir@" 19 STRIP_FROM_INC_PATH = "@abs_top_srcdir@" 20 20 SHORT_NAMES = YES 21 21 JAVADOC_AUTOBRIEF = NO … … 34 34 CPP_CLI_SUPPORT = NO 35 35 SIP_SUPPORT = NO 36 IDL_PROPERTY_SUPPORT = YES 36 37 DISTRIBUTE_GROUP_DOC = NO 37 38 SUBGROUPING = YES 38 39 TYPEDEF_HIDES_STRUCT = NO 40 SYMBOL_CACHE_SIZE = 0 39 41 #--------------------------------------------------------------------------- 40 42 # Build related configuration options … … 67 69 SHOW_USED_FILES = YES 68 70 SHOW_DIRECTORIES = YES 71 SHOW_FILES = YES 72 SHOW_NAMESPACES = YES 69 73 FILE_VERSION_FILTER = 74 LAYOUT_FILE = DoxygenLayout.xml 70 75 #--------------------------------------------------------------------------- 71 76 # configuration options related to warning and progress messages … … 76 81 WARN_IF_DOC_ERROR = YES 77 82 WARN_NO_PARAMDOC = NO 78 WARN_FORMAT = "$file:$line: $text 83 WARN_FORMAT = "$file:$line: $text" 79 84 WARN_LOGFILE = doxygen.log 80 85 #--------------------------------------------------------------------------- 81 86 # configuration options related to the input files 82 87 #--------------------------------------------------------------------------- 83 INPUT = @abs_top_srcdir@/doc\84 @abs_top_srcdir@/lemon\85 @abs_top_srcdir@/lemon/bits\86 @abs_top_srcdir@/lemon/concepts\87 @abs_top_srcdir@/demo\88 @abs_top_srcdir@/tools\89 @abs_top_srcdir@/test/test_tools.h88 INPUT = "@abs_top_srcdir@/doc" \ 89 "@abs_top_srcdir@/lemon" \ 90 "@abs_top_srcdir@/lemon/bits" \ 91 "@abs_top_srcdir@/lemon/concepts" \ 92 "@abs_top_srcdir@/demo" \ 93 "@abs_top_srcdir@/tools" \ 94 "@abs_top_srcdir@/test/test_tools.h" 90 95 INPUT_ENCODING = UTF-8 91 96 FILE_PATTERNS = *.h \ … … 97 102 EXCLUDE_PATTERNS = 98 103 EXCLUDE_SYMBOLS = 99 EXAMPLE_PATH = @abs_top_srcdir@/demo\100 @abs_top_srcdir@/LICENSE\101 @abs_top_srcdir@/doc104 EXAMPLE_PATH = "@abs_top_srcdir@/demo" \ 105 "@abs_top_srcdir@/LICENSE" \ 106 "@abs_top_srcdir@/doc" 102 107 EXAMPLE_PATTERNS = 103 108 EXAMPLE_RECURSIVE = NO 104 IMAGE_PATH = @abs_top_srcdir@/doc/images\105 @abs_top_builddir@/doc/gen-images109 IMAGE_PATH = "@abs_top_srcdir@/doc/images" \ 110 "@abs_top_builddir@/doc/gen-images" 106 111 INPUT_FILTER = 107 112 FILTER_PATTERNS = … … 134 139 HTML_STYLESHEET = 135 140 HTML_ALIGN_MEMBERS = YES 136 GENERATE_HTMLHELP= NO141 HTML_DYNAMIC_SECTIONS = NO 137 142 GENERATE_DOCSET = NO 138 143 DOCSET_FEEDNAME = "Doxygen generated docs" 139 144 DOCSET_BUNDLE_ID = org.doxygen.Project 140 HTML_DYNAMIC_SECTIONS= NO145 GENERATE_HTMLHELP = NO 141 146 CHM_FILE = 142 147 HHC_LOCATION = 143 148 GENERATE_CHI = NO 149 CHM_INDEX_ENCODING = 144 150 BINARY_TOC = NO 145 151 TOC_EXPAND = NO 152 GENERATE_QHP = NO 153 QCH_FILE = 154 QHP_NAMESPACE = org.doxygen.Project 155 QHP_VIRTUAL_FOLDER = doc 156 QHG_LOCATION = 146 157 DISABLE_INDEX = NO 147 158 ENUM_VALUES_PER_LINE = 4 148 159 GENERATE_TREEVIEW = NO 149 160 TREEVIEW_WIDTH = 250 161 FORMULA_FONTSIZE = 10 150 162 #--------------------------------------------------------------------------- 151 163 # configuration options related to the LaTeX output … … 222 234 # Configuration options related to the dot tool 223 235 #--------------------------------------------------------------------------- 224 CLASS_DIAGRAMS = NO236 CLASS_DIAGRAMS = YES 225 237 MSCGEN_PATH = 226 238 HIDE_UNDOC_RELATIONS = YES 227 239 HAVE_DOT = YES 240 DOT_FONTNAME = FreeSans 241 DOT_FONTSIZE = 10 242 DOT_FONTPATH = 228 243 CLASS_GRAPH = YES 229 244 COLLABORATION_GRAPH = NO -
doc/Makefile.am
r156 r322 1 1 EXTRA_DIST += \ 2 2 doc/Doxyfile.in \ 3 doc/DoxygenLayout.xml \ 3 4 doc/coding_style.dox \ 4 5 doc/dirs.dox \ … … 7 8 doc/license.dox \ 8 9 doc/mainpage.dox \ 10 doc/migration.dox \ 11 doc/named-param.dox \ 9 12 doc/namespaces.dox \ 10 doc/html 13 doc/html \ 14 doc/CMakeLists.txt 11 15 12 16 DOC_EPS_IMAGES18 = \ -
doc/dirs.dox
r209 r325 19 19 /** 20 20 \dir demo 21 \brief A collection of demo application .21 \brief A collection of demo applications. 22 22 23 This directory contains several simple demo application , mainly23 This directory contains several simple demo applications, mainly 24 24 for educational purposes. 25 25 */ … … 29 29 \brief Auxiliary (and the whole generated) documentation. 30 30 31 Auxiliary (and the whole generated) documentation. 31 This directory contains some auxiliary pages and the whole generated 32 documentation. 32 33 */ 33 34 … … 42 43 /** 43 44 \dir tools 44 \brief Some useful executables 45 \brief Some useful executables. 45 46 46 47 This directory contains the sources of some useful complete executables. 47 48 48 */ 49 50 51 49 52 50 /** 53 51 \dir lemon 54 \brief Base include directory of LEMON 52 \brief Base include directory of LEMON. 55 53 56 This is the base directory of lemonincludes, so each include file must be54 This is the base directory of LEMON includes, so each include file must be 57 55 prefixed with this, e.g. 58 56 \code … … 64 62 /** 65 63 \dir concepts 66 \brief Concept descriptors and checking classes 64 \brief Concept descriptors and checking classes. 67 65 68 This directory contains the concept descriptors and concept check ers. As a user69 you typically don't have to deal with these files.66 This directory contains the concept descriptors and concept checking tools. 67 For more information see the \ref concept "Concepts" module. 70 68 */ 71 69 72 70 /** 73 71 \dir bits 74 \brief Implementation helper files72 \brief Auxiliary tools for implementation. 75 73 76 This directory contains some helper classes to implement graphs, maps and77 some other classes. As a user you typically don't have to deal with these 78 files.74 This directory contains some auxiliary classes for implementing graphs, 75 maps and some other classes. 76 As a user you typically don't have to deal with these files. 79 77 */ -
doc/groups.dox
r210 r325 55 55 You are free to use the graph structure that fit your requirements 56 56 the best, most graph algorithms and auxiliary data structures can be used 57 with any graph structures. 57 with any graph structure. 58 59 <b>See also:</b> \ref graph_concepts "Graph Structure Concepts". 58 60 */ 59 61 … … 75 77 This group describes the map structures implemented in LEMON. 76 78 77 LEMON provides several special purpose maps that e.g. combine79 LEMON provides several special purpose maps and map adaptors that e.g. combine 78 80 new maps from existing ones. 81 82 <b>See also:</b> \ref map_concepts "Map Concepts". 79 83 */ 80 84 … … 87 91 values to the nodes and arcs of graphs. 88 92 */ 89 90 93 91 94 /** … … 105 108 algorithms. If a function type algorithm is called then the function 106 109 type map adaptors can be used comfortable. For example let's see the 107 usage of map adaptors with the \c digraphToEps() function.110 usage of map adaptors with the \c graphToEps() function. 108 111 \code 109 112 Color nodeColor(int deg) { … … 119 122 Digraph::NodeMap<int> degree_map(graph); 120 123 121 digraphToEps(graph, "graph.eps")124 graphToEps(graph, "graph.eps") 122 125 .coords(coords).scaleToA4().undirected() 123 126 .nodeColors(composeMap(functorToMap(nodeColor), degree_map)) … … 125 128 \endcode 126 129 The \c functorToMap() function makes an \c int to \c Color map from the 127 \ e nodeColor() function. The \c composeMap() compose the \edegree_map130 \c nodeColor() function. The \c composeMap() compose the \c degree_map 128 131 and the previously created map. The composed map is a proper function to 129 132 get the color of each node. … … 163 166 @defgroup paths Path Structures 164 167 @ingroup datas 165 \brief Path structures implemented in LEMON.168 \brief %Path structures implemented in LEMON. 166 169 167 170 This group describes the path structures implemented in LEMON. … … 174 177 175 178 \sa lemon::concepts::Path 176 177 179 */ 178 180 … … 186 188 */ 187 189 188 189 190 /** 190 191 @defgroup algs Algorithms … … 202 203 203 204 This group describes the common graph search algorithms like 204 Breadth- first search (Bfs) and Depth-first search (Dfs).205 */ 206 207 /** 208 @defgroup shortest_path Shortest Path algorithms205 Breadth-First Search (BFS) and Depth-First Search (DFS). 206 */ 207 208 /** 209 @defgroup shortest_path Shortest Path Algorithms 209 210 @ingroup algs 210 211 \brief Algorithms for finding shortest paths. … … 214 215 215 216 /** 216 @defgroup max_flow Maximum Flow algorithms217 @defgroup max_flow Maximum Flow Algorithms 217 218 @ingroup algs 218 219 \brief Algorithms for finding maximum flows. … … 242 243 provides functions to query the minimum cut, which is the dual linear 243 244 programming problem of the maximum flow. 244 245 */ 246 247 /** 248 @defgroup min_cost_flow Minimum Cost Flow algorithms 245 */ 246 247 /** 248 @defgroup min_cost_flow Minimum Cost Flow Algorithms 249 249 @ingroup algs 250 250 … … 256 256 257 257 /** 258 @defgroup min_cut Minimum Cut algorithms258 @defgroup min_cut Minimum Cut Algorithms 259 259 @ingroup algs 260 260 … … 283 283 If you want to find minimum cut just between two distinict nodes, 284 284 please see the \ref max_flow "Maximum Flow page". 285 286 */ 287 288 /** 289 @defgroup graph_prop Connectivity and other graph properties 285 */ 286 287 /** 288 @defgroup graph_prop Connectivity and Other Graph Properties 290 289 @ingroup algs 291 290 \brief Algorithms for discovering the graph properties … … 299 298 300 299 /** 301 @defgroup planar Planarity embedding and drawing300 @defgroup planar Planarity Embedding and Drawing 302 301 @ingroup algs 303 302 \brief Algorithms for planarity checking, embedding and drawing … … 311 310 312 311 /** 313 @defgroup matching Matching algorithms312 @defgroup matching Matching Algorithms 314 313 @ingroup algs 315 314 \brief Algorithms for finding matchings in graphs and bipartite graphs. … … 326 325 maximum cardinality matching. 327 326 328 L emoncontains the next algorithms:327 LEMON contains the next algorithms: 329 328 - \ref lemon::MaxBipartiteMatching "MaxBipartiteMatching" Hopcroft-Karp 330 329 augmenting path algorithm for calculate maximum cardinality matching in … … 349 348 \image html bipartite_matching.png 350 349 \image latex bipartite_matching.eps "Bipartite Matching" width=\textwidth 351 352 */ 353 354 /** 355 @defgroup spantree Minimum Spanning Tree algorithms 350 */ 351 352 /** 353 @defgroup spantree Minimum Spanning Tree Algorithms 356 354 @ingroup algs 357 355 \brief Algorithms for finding a minimum cost spanning tree in a graph. … … 361 359 */ 362 360 363 364 /** 365 @defgroup auxalg Auxiliary algorithms 361 /** 362 @defgroup auxalg Auxiliary Algorithms 366 363 @ingroup algs 367 364 \brief Auxiliary algorithms implemented in LEMON. … … 372 369 373 370 /** 374 @defgroup approx Approximation algorithms 371 @defgroup approx Approximation Algorithms 372 @ingroup algs 375 373 \brief Approximation algorithms. 376 374 … … 386 384 This group describes some general optimization frameworks 387 385 implemented in LEMON. 388 389 */ 390 391 /** 392 @defgroup lp_group Lp and Mip solvers 386 */ 387 388 /** 389 @defgroup lp_group Lp and Mip Solvers 393 390 @ingroup gen_opt_group 394 391 \brief Lp and Mip solver interfaces for LEMON. … … 397 394 various LP solvers could be used in the same manner with this 398 395 interface. 399 400 */ 401 402 /** 403 @defgroup lp_utils Tools for Lp and Mip solvers 396 */ 397 398 /** 399 @defgroup lp_utils Tools for Lp and Mip Solvers 404 400 @ingroup lp_group 405 401 \brief Helper tools to the Lp and Mip solvers. … … 442 438 443 439 /** 444 @defgroup timecount Time measuring and Counting440 @defgroup timecount Time Measuring and Counting 445 441 @ingroup misc 446 442 \brief Simple tools for measuring the performance of algorithms. … … 448 444 This group describes simple tools for measuring the performance 449 445 of algorithms. 450 */451 452 /**453 @defgroup graphbits Tools for Graph Implementation454 @ingroup utils455 \brief Tools to make it easier to create graphs.456 457 This group describes the tools that makes it easier to create graphs and458 the maps that dynamically update with the graph changes.459 446 */ 460 447 … … 472 459 473 460 This group describes the tools for importing and exporting graphs 474 and graph related data. Now it supports the LEMON format, the 475 \c DIMACS format and the encapsulated postscript (EPS) format. 476 */ 477 478 /** 479 @defgroup lemon_io Lemon Input-Output 461 and graph related data. Now it supports the \ref lgf-format 462 "LEMON Graph Format", the \c DIMACS format and the encapsulated 463 postscript (EPS) format. 464 */ 465 466 /** 467 @defgroup lemon_io LEMON Input-Output 480 468 @ingroup io_group 481 \brief Reading and writing \ref lgf-format "Lemon Graph Format".469 \brief Reading and writing LEMON Graph Format. 482 470 483 471 This group describes methods for reading and writing 484 \ref lgf-format "L emonGraph Format".485 */ 486 487 /** 488 @defgroup eps_io Postscript exporting472 \ref lgf-format "LEMON Graph Format". 473 */ 474 475 /** 476 @defgroup eps_io Postscript Exporting 489 477 @ingroup io_group 490 478 \brief General \c EPS drawer and graph exporter … … 494 482 */ 495 483 496 497 484 /** 498 485 @defgroup concept Concepts … … 504 491 The purpose of the classes in this group is fourfold. 505 492 506 - These classes contain the documentations of the concepts. In order493 - These classes contain the documentations of the %concepts. In order 507 494 to avoid document multiplications, an implementation of a concept 508 495 simply refers to the corresponding concept class. 509 496 510 497 - These classes declare every functions, <tt>typedef</tt>s etc. an 511 implementation of the concepts should provide, however completely498 implementation of the %concepts should provide, however completely 512 499 without implementations and real data structures behind the 513 500 interface. On the other hand they should provide nothing else. All … … 522 509 523 510 - Finally, They can serve as a skeleton of a new implementation of a concept. 524 525 */ 526 511 */ 527 512 528 513 /** … … 535 520 */ 536 521 537 /* --- Unused group 538 @defgroup experimental Experimental Structures and Algorithms 539 This group describes some Experimental structures and algorithms. 540 The stuff here is subject to change. 522 /** 523 @defgroup map_concepts Map Concepts 524 @ingroup concept 525 \brief Skeleton and concept checking classes for maps 526 527 This group describes the skeletons and concept checking classes of maps. 541 528 */ 542 529 -
doc/lgf.dox
r212 r317 22 22 23 23 24 \page lgf-format L emonGraph Format (LGF)24 \page lgf-format LEMON Graph Format (LGF) 25 25 26 26 The \e LGF is a <em>column oriented</em> … … 79 79 \endcode 80 80 81 The \c \@edges is just a synonym of \c \@arcs. The @arcs section can81 The \c \@edges is just a synonym of \c \@arcs. The \@arcs section can 82 82 also store the edge set of an undirected graph. In such case there is 83 83 a conventional method for store arc maps in the file, if two columns -
doc/mainpage.dox
r209 r318 51 51 If you 52 52 want to see how LEMON works, see 53 some \ref demoprograms "demo programs" !53 some \ref demoprograms "demo programs". 54 54 55 55 If you know what you are looking for then try to find it under the … … 57 57 section. 58 58 59 59 If you are a user of the old (0.x) series of LEMON, please check out the 60 \ref migration "Migration Guide" for the backward incompatibilities. 60 61 */ -
lemon/CMakeLists.txt
r141 r225 1 include_directories (${LEMON_SOURCE_DIR}) 2 add_library (lemon arg_parser.cc base.cc color.cc random.cc) 1 INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}) 2 3 ADD_LIBRARY(lemon 4 arg_parser.cc 5 base.cc 6 color.cc 7 random.cc) 8 9 INSTALL( 10 TARGETS lemon 11 ARCHIVE DESTINATION lib 12 COMPONENT library) 13 14 INSTALL( 15 DIRECTORY . bits concepts 16 DESTINATION include/lemon 17 COMPONENT headers 18 FILES_MATCHING PATTERN "*.h") -
lemon/Makefile.am
r220 r259 13 13 lemon/random.cc 14 14 15 16 lemon_libemon_la_CXXFLAGS = $(GLPK_CFLAGS) $(CPLEX_CFLAGS) $(SOPLEX_CXXFLAGS) 17 lemon_libemon_la_LDFLAGS = $(GLPK_LIBS) $(CPLEX_LIBS) $(SOPLEX_LIBS) 15 #lemon_libemon_la_CXXFLAGS = $(GLPK_CFLAGS) $(CPLEX_CFLAGS) $(SOPLEX_CXXFLAGS) 16 #lemon_libemon_la_LDFLAGS = $(GLPK_LIBS) $(CPLEX_LIBS) $(SOPLEX_LIBS) 18 17 19 18 lemon_HEADERS += \ -
lemon/arg_parser.cc
r214 r315 27 27 } 28 28 29 ArgParser::ArgParser(int argc, const char * *argv) :_argc(argc), _argv(argv),30 29 ArgParser::ArgParser(int argc, const char * const *argv) 30 :_argc(argc), _argv(argv), _command_name(argv[0]) { 31 31 funcOption("-help","Print a short help message",_showHelp,this); 32 32 synonym("help","-help"); 33 33 synonym("h","-help"); 34 35 34 } 36 35 -
lemon/arg_parser.h
r214 r315 17 17 */ 18 18 19 #ifndef LEMON_ARG_PARSER 20 #define LEMON_ARG_PARSER 19 #ifndef LEMON_ARG_PARSER_H 20 #define LEMON_ARG_PARSER_H 21 21 22 22 #include <vector> … … 47 47 48 48 int _argc; 49 const char * *_argv;49 const char * const *_argv; 50 50 51 51 enum OptType { UNKNOWN=0, BOOL=1, STRING=2, DOUBLE=3, INTEGER=4, FUNC=5 }; … … 120 120 121 121 ///Constructor 122 ArgParser(int argc, const char * *argv);122 ArgParser(int argc, const char * const *argv); 123 123 124 124 ~ArgParser(); … … 311 311 ///This is the type of the return value of ArgParser::operator[](). 312 312 ///It automatically converts to \c int, \c double, \c bool or 313 ///\c std::string if the type of the option matches, otherwise it 314 ///throws an exception (i.e. it performs runtime type checking). 313 ///\c std::string if the type of the option matches, which is checked 314 ///with an \ref LEMON_ASSERT "assertion" (i.e. it performs runtime 315 ///type checking). 315 316 class RefType 316 317 { … … 383 384 } 384 385 385 #endif // LEMON_ARG_PARSER 386 #endif // LEMON_ARG_PARSER_H -
lemon/assert.h
r218 r290 28 28 namespace lemon { 29 29 30 inline void assert_fail_log(const char *file, int line, const char *function, 31 const char *message, const char *assertion) 30 inline void assert_fail_abort(const char *file, int line, 31 const char *function, const char* message, 32 const char *assertion) 32 33 { 33 34 std::cerr << file << ":" << line << ": "; … … 38 39 std::cerr << " (assertion '" << assertion << "' failed)"; 39 40 std::cerr << std::endl; 40 }41 42 inline void assert_fail_abort(const char *file, int line,43 const char *function, const char* message,44 const char *assertion)45 {46 assert_fail_log(file, line, function, message, assertion);47 41 std::abort(); 48 42 } … … 64 58 65 59 #undef LEMON_ASSERT 66 #undef LEMON_FIXME67 60 #undef LEMON_DEBUG 68 61 69 #if (defined(LEMON_ASSERT_LOG) ? 1 : 0) + \ 70 (defined(LEMON_ASSERT_ABORT) ? 1 : 0) + \ 62 #if (defined(LEMON_ASSERT_ABORT) ? 1 : 0) + \ 71 63 (defined(LEMON_ASSERT_CUSTOM) ? 1 : 0) > 1 72 64 #error "LEMON assertion system is not set properly" 73 65 #endif 74 66 75 #if ((defined(LEMON_ASSERT_LOG) ? 1 : 0) + \ 76 (defined(LEMON_ASSERT_ABORT) ? 1 : 0) + \ 67 #if ((defined(LEMON_ASSERT_ABORT) ? 1 : 0) + \ 77 68 (defined(LEMON_ASSERT_CUSTOM) ? 1 : 0) == 1 || \ 78 69 defined(LEMON_ENABLE_ASSERTS)) && \ … … 83 74 84 75 85 #if defined LEMON_ASSERT_LOG 86 # undef LEMON_ASSERT_HANDLER 87 # define LEMON_ASSERT_HANDLER ::lemon::assert_fail_log 88 #elif defined LEMON_ASSERT_ABORT 76 #if defined LEMON_ASSERT_ABORT 89 77 # undef LEMON_ASSERT_HANDLER 90 78 # define LEMON_ASSERT_HANDLER ::lemon::assert_fail_abort … … 108 96 # elif defined _MSC_VER 109 97 # define LEMON_FUNCTION_NAME (__FUNCSIG__) 98 # elif __STDC_VERSION__ >= 199901L 99 # define LEMON_FUNCTION_NAME (__func__) 110 100 # else 111 # define LEMON_FUNCTION_NAME ( __func__)101 # define LEMON_FUNCTION_NAME ("<unknown>") 112 102 # endif 113 103 #endif … … 119 109 /// \brief Macro for assertion with customizable message 120 110 /// 121 /// Macro for assertion with customizable message. \param exp An122 /// expression that must be convertible to \c bool. If it is \c123 /// false, then an assertion is raised. The concrete behaviour depends 124 /// on the settings of the assertion system. \param msg A <tt>const125 /// char*</tt> parameter, which can be used to provide information126 /// about the circumstances of the failed assertion.111 /// Macro for assertion with customizable message. 112 /// \param exp An expression that must be convertible to \c bool. If it is \c 113 /// false, then an assertion is raised. The concrete behaviour depends on the 114 /// settings of the assertion system. 115 /// \param msg A <tt>const char*</tt> parameter, which can be used to provide 116 /// information about the circumstances of the failed assertion. 127 117 /// 128 118 /// The assertions are enabled in the default behaviour. … … 138 128 /// The checking is also disabled when the standard macro \c NDEBUG is defined. 139 129 /// 140 /// The LEMON assertion system has a wide range of customization 141 /// properties. As a default behaviour the failed assertion prints a 142 /// short log message to the standard error and aborts the execution. 143 /// 144 /// The following modes can be used in the assertion system: 145 /// 146 /// - \c LEMON_ASSERT_LOG The failed assertion prints a short log 147 /// message to the standard error and continues the execution. 148 /// - \c LEMON_ASSERT_ABORT This mode is similar to the \c 149 /// LEMON_ASSERT_LOG, but it aborts the program. It is the default 150 /// behaviour. 130 /// As a default behaviour the failed assertion prints a short log message to 131 /// the standard error and aborts the execution. 132 /// 133 /// However, the following modes can be used in the assertion system: 134 /// - \c LEMON_ASSERT_ABORT The failed assertion prints a short log message to 135 /// the standard error and aborts the program. It is the default behaviour. 151 136 /// - \c LEMON_ASSERT_CUSTOM The user can define own assertion handler 152 137 /// function. … … 176 161 /// \ingroup exceptions 177 162 /// 178 /// \brief Macro for mark not yet implemented features.179 ///180 /// Macro for mark not yet implemented features and outstanding bugs.181 /// It is close to be the shortcut of the following code:182 /// \code183 /// LEMON_ASSERT(false, msg);184 /// \endcode185 ///186 /// \see LEMON_ASSERT187 # define LEMON_FIXME(msg) \188 (LEMON_ASSERT_HANDLER(__FILE__, __LINE__, LEMON_FUNCTION_NAME, \189 ::lemon::_assert_bits::cstringify(msg), \190 static_cast<const char*>(0)))191 192 /// \ingroup exceptions193 ///194 163 /// \brief Macro for internal assertions 195 164 /// … … 223 192 # ifndef LEMON_ASSERT_HANDLER 224 193 # define LEMON_ASSERT(exp, msg) (static_cast<void>(0)) 225 # define LEMON_FIXME(msg) (static_cast<void>(0))226 194 # define LEMON_DEBUG(exp, msg) (static_cast<void>(0)) 227 195 # else … … 232 200 ::lemon::_assert_bits::cstringify(msg), \ 233 201 #exp), 0))) 234 # define LEMON_FIXME(msg) \235 (LEMON_ASSERT_HANDLER(__FILE__, __LINE__, LEMON_FUNCTION_NAME, \236 ::lemon::_assert_bits::cstringify(msg), \237 static_cast<const char*>(0)))238 239 202 # if LEMON_ENABLE_DEBUG 240 203 # define LEMON_DEBUG(exp, msg) \ -
lemon/bfs.h
r220 r305 22 22 ///\ingroup search 23 23 ///\file 24 ///\brief B fsalgorithm.24 ///\brief BFS algorithm. 25 25 26 26 #include <lemon/list_graph.h> … … 29 29 #include <lemon/error.h> 30 30 #include <lemon/maps.h> 31 #include <lemon/path.h> 31 32 32 33 namespace lemon { 33 34 35 34 36 35 ///Default traits class of Bfs class. … … 41 40 struct BfsDefaultTraits 42 41 { 43 ///The digraph typethe algorithm runs on.42 ///The type of the digraph the algorithm runs on. 44 43 typedef GR Digraph; 45 ///\brief The type of the map that stores the last 44 45 ///\brief The type of the map that stores the predecessor 46 46 ///arcs of the shortest paths. 47 47 /// 48 ///The type of the map that stores the last48 ///The type of the map that stores the predecessor 49 49 ///arcs of the shortest paths. 50 50 ///It must meet the \ref concepts::WriteMap "WriteMap" concept. 51 /// 52 typedef typename Digraph::template NodeMap<typename GR::Arc> PredMap; 51 typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap; 53 52 ///Instantiates a PredMap. 54 53 55 ///This function instantiates a \ref PredMap. 56 ///\param G is the digraph, to which we would like to define the PredMap. 57 ///\todo The digraph alone may be insufficient to initialize 58 static PredMap *createPredMap(const GR &G) 59 { 60 return new PredMap(G); 61 } 54 ///This function instantiates a PredMap. 55 ///\param g is the digraph, to which we would like to define the 56 ///PredMap. 57 static PredMap *createPredMap(const Digraph &g) 58 { 59 return new PredMap(g); 60 } 61 62 62 ///The type of the map that indicates which nodes are processed. 63 63 64 64 ///The type of the map that indicates which nodes are processed. 65 65 ///It must meet the \ref concepts::WriteMap "WriteMap" concept. 66 ///\todo named parameter to set this type, function to read and write.67 66 typedef NullMap<typename Digraph::Node,bool> ProcessedMap; 68 67 ///Instantiates a ProcessedMap. 69 68 70 ///This function instantiates a \refProcessedMap.69 ///This function instantiates a ProcessedMap. 71 70 ///\param g is the digraph, to which 72 ///we would like to define the \refProcessedMap71 ///we would like to define the ProcessedMap 73 72 #ifdef DOXYGEN 74 static ProcessedMap *createProcessedMap(const GR&g)73 static ProcessedMap *createProcessedMap(const Digraph &g) 75 74 #else 76 static ProcessedMap *createProcessedMap(const GR&)75 static ProcessedMap *createProcessedMap(const Digraph &) 77 76 #endif 78 77 { 79 78 return new ProcessedMap(); 80 79 } 80 81 81 ///The type of the map that indicates which nodes are reached. 82 82 83 83 ///The type of the map that indicates which nodes are reached. 84 ///It must meet the \ref concepts::WriteMap "WriteMap" concept. 85 ///\todo named parameter to set this type, function to read and write. 84 ///It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept. 86 85 typedef typename Digraph::template NodeMap<bool> ReachedMap; 87 86 ///Instantiates a ReachedMap. 88 87 89 ///This function instantiates a \ref ReachedMap. 90 ///\param G is the digraph, to which 91 ///we would like to define the \ref ReachedMap. 92 static ReachedMap *createReachedMap(const GR &G) 93 { 94 return new ReachedMap(G); 95 } 96 ///The type of the map that stores the dists of the nodes. 97 98 ///The type of the map that stores the dists of the nodes. 88 ///This function instantiates a ReachedMap. 89 ///\param g is the digraph, to which 90 ///we would like to define the ReachedMap. 91 static ReachedMap *createReachedMap(const Digraph &g) 92 { 93 return new ReachedMap(g); 94 } 95 96 ///The type of the map that stores the distances of the nodes. 97 98 ///The type of the map that stores the distances of the nodes. 99 99 ///It must meet the \ref concepts::WriteMap "WriteMap" concept. 100 ///101 100 typedef typename Digraph::template NodeMap<int> DistMap; 102 101 ///Instantiates a DistMap. 103 102 104 ///This function instantiates a \refDistMap.105 ///\param G is the digraph, to which we would like to define106 /// the \ref DistMap107 static DistMap *createDistMap(const GR &G)108 { 109 return new DistMap( G);103 ///This function instantiates a DistMap. 104 ///\param g is the digraph, to which we would like to define the 105 ///DistMap. 106 static DistMap *createDistMap(const Digraph &g) 107 { 108 return new DistMap(g); 110 109 } 111 110 }; … … 116 115 ///This class provides an efficient implementation of the %BFS algorithm. 117 116 /// 118 ///\tparam GR The digraph type the algorithm runs on. The default value is 119 ///\ref ListDigraph. The value of GR is not used directly by Bfs, it 120 ///is only passed to \ref BfsDefaultTraits. 117 ///There is also a \ref bfs() "function-type interface" for the BFS 118 ///algorithm, which is convenient in the simplier cases and it can be 119 ///used easier. 120 /// 121 ///\tparam GR The type of the digraph the algorithm runs on. 122 ///The default value is \ref ListDigraph. The value of GR is not used 123 ///directly by \ref Bfs, it is only passed to \ref BfsDefaultTraits. 121 124 ///\tparam TR Traits class to set various data types used by the algorithm. 122 125 ///The default traits class is … … 124 127 ///See \ref BfsDefaultTraits for the documentation of 125 128 ///a Bfs traits class. 126 127 129 #ifdef DOXYGEN 128 130 template <typename GR, … … 134 136 class Bfs { 135 137 public: 136 /** 137 * \brief \ref Exception for uninitialized parameters. 138 * 139 * This error represents problems in the initialization 140 * of the parameters of the algorithms. 141 */ 142 class UninitializedParameter : public lemon::UninitializedParameter { 143 public: 144 virtual const char* what() const throw() { 145 return "lemon::Bfs::UninitializedParameter"; 146 } 147 }; 148 138 139 ///The type of the digraph the algorithm runs on. 140 typedef typename TR::Digraph Digraph; 141 142 ///\brief The type of the map that stores the predecessor arcs of the 143 ///shortest paths. 144 typedef typename TR::PredMap PredMap; 145 ///The type of the map that stores the distances of the nodes. 146 typedef typename TR::DistMap DistMap; 147 ///The type of the map that indicates which nodes are reached. 148 typedef typename TR::ReachedMap ReachedMap; 149 ///The type of the map that indicates which nodes are processed. 150 typedef typename TR::ProcessedMap ProcessedMap; 151 ///The type of the paths. 152 typedef PredMapPath<Digraph, PredMap> Path; 153 154 ///The traits class. 149 155 typedef TR Traits; 150 ///The type of the underlying digraph. 151 typedef typename TR::Digraph Digraph; 152 153 ///\brief The type of the map that stores the last 154 ///arcs of the shortest paths. 155 typedef typename TR::PredMap PredMap; 156 ///The type of the map indicating which nodes are reached. 157 typedef typename TR::ReachedMap ReachedMap; 158 ///The type of the map indicating which nodes are processed. 159 typedef typename TR::ProcessedMap ProcessedMap; 160 ///The type of the map that stores the dists of the nodes. 161 typedef typename TR::DistMap DistMap; 156 162 157 private: 163 158 … … 167 162 typedef typename Digraph::OutArcIt OutArcIt; 168 163 169 // /Pointer to the underlying digraph.164 //Pointer to the underlying digraph. 170 165 const Digraph *G; 171 // /Pointer to the map of predecessorsarcs.166 //Pointer to the map of predecessor arcs. 172 167 PredMap *_pred; 173 // /Indicates if \ref _pred is locally allocated (\ctrue) or not.168 //Indicates if _pred is locally allocated (true) or not. 174 169 bool local_pred; 175 // /Pointer to the map of distances.170 //Pointer to the map of distances. 176 171 DistMap *_dist; 177 // /Indicates if \ref _dist is locally allocated (\ctrue) or not.172 //Indicates if _dist is locally allocated (true) or not. 178 173 bool local_dist; 179 // /Pointer to the map of reached status of the nodes.174 //Pointer to the map of reached status of the nodes. 180 175 ReachedMap *_reached; 181 // /Indicates if \ref _reached is locally allocated (\ctrue) or not.176 //Indicates if _reached is locally allocated (true) or not. 182 177 bool local_reached; 183 // /Pointer to the map of processed status of the nodes.178 //Pointer to the map of processed status of the nodes. 184 179 ProcessedMap *_processed; 185 // /Indicates if \ref _processed is locally allocated (\ctrue) or not.180 //Indicates if _processed is locally allocated (true) or not. 186 181 bool local_processed; 187 182 … … 190 185 int _curr_dist; 191 186 192 ///Creates the maps if necessary. 193 194 ///\todo Better memory allocation (instead of new). 187 //Creates the maps if necessary. 195 188 void create_maps() 196 189 { … … 226 219 227 220 template <class T> 228 struct DefPredMapTraits : public Traits {221 struct SetPredMapTraits : public Traits { 229 222 typedef T PredMap; 230 223 static PredMap *createPredMap(const Digraph &) 231 224 { 232 throw UninitializedParameter(); 225 LEMON_ASSERT(false, "PredMap is not initialized"); 226 return 0; // ignore warnings 233 227 } 234 228 }; 235 229 ///\brief \ref named-templ-param "Named parameter" for setting 236 ///PredMap type 237 /// 238 ///\ref named-templ-param "Named parameter" for setting PredMap type239 /// 230 ///PredMap type. 231 /// 232 ///\ref named-templ-param "Named parameter" for setting 233 ///PredMap type. 240 234 template <class T> 241 struct DefPredMap : public Bfs< Digraph, DefPredMapTraits<T> > {242 typedef Bfs< Digraph, DefPredMapTraits<T> > Create;235 struct SetPredMap : public Bfs< Digraph, SetPredMapTraits<T> > { 236 typedef Bfs< Digraph, SetPredMapTraits<T> > Create; 243 237 }; 244 238 245 239 template <class T> 246 struct DefDistMapTraits : public Traits {240 struct SetDistMapTraits : public Traits { 247 241 typedef T DistMap; 248 242 static DistMap *createDistMap(const Digraph &) 249 243 { 250 throw UninitializedParameter(); 244 LEMON_ASSERT(false, "DistMap is not initialized"); 245 return 0; // ignore warnings 251 246 } 252 247 }; 253 248 ///\brief \ref named-templ-param "Named parameter" for setting 254 ///DistMap type 255 /// 256 ///\ref named-templ-param "Named parameter" for setting DistMap type257 /// 249 ///DistMap type. 250 /// 251 ///\ref named-templ-param "Named parameter" for setting 252 ///DistMap type. 258 253 template <class T> 259 struct DefDistMap : public Bfs< Digraph, DefDistMapTraits<T> > {260 typedef Bfs< Digraph, DefDistMapTraits<T> > Create;254 struct SetDistMap : public Bfs< Digraph, SetDistMapTraits<T> > { 255 typedef Bfs< Digraph, SetDistMapTraits<T> > Create; 261 256 }; 262 257 263 258 template <class T> 264 struct DefReachedMapTraits : public Traits {259 struct SetReachedMapTraits : public Traits { 265 260 typedef T ReachedMap; 266 261 static ReachedMap *createReachedMap(const Digraph &) 267 262 { 268 throw UninitializedParameter(); 263 LEMON_ASSERT(false, "ReachedMap is not initialized"); 264 return 0; // ignore warnings 269 265 } 270 266 }; 271 267 ///\brief \ref named-templ-param "Named parameter" for setting 272 ///ReachedMap type 273 /// 274 ///\ref named-templ-param "Named parameter" for setting ReachedMap type275 /// 268 ///ReachedMap type. 269 /// 270 ///\ref named-templ-param "Named parameter" for setting 271 ///ReachedMap type. 276 272 template <class T> 277 struct DefReachedMap : public Bfs< Digraph, DefReachedMapTraits<T> > {278 typedef Bfs< Digraph, DefReachedMapTraits<T> > Create;273 struct SetReachedMap : public Bfs< Digraph, SetReachedMapTraits<T> > { 274 typedef Bfs< Digraph, SetReachedMapTraits<T> > Create; 279 275 }; 280 276 281 277 template <class T> 282 struct DefProcessedMapTraits : public Traits {278 struct SetProcessedMapTraits : public Traits { 283 279 typedef T ProcessedMap; 284 280 static ProcessedMap *createProcessedMap(const Digraph &) 285 281 { 286 throw UninitializedParameter(); 282 LEMON_ASSERT(false, "ProcessedMap is not initialized"); 283 return 0; // ignore warnings 287 284 } 288 285 }; 289 286 ///\brief \ref named-templ-param "Named parameter" for setting 290 ///ProcessedMap type 291 /// 292 ///\ref named-templ-param "Named parameter" for setting ProcessedMap type293 /// 287 ///ProcessedMap type. 288 /// 289 ///\ref named-templ-param "Named parameter" for setting 290 ///ProcessedMap type. 294 291 template <class T> 295 struct DefProcessedMap : public Bfs< Digraph, DefProcessedMapTraits<T> > {296 typedef Bfs< Digraph, DefProcessedMapTraits<T> > Create;292 struct SetProcessedMap : public Bfs< Digraph, SetProcessedMapTraits<T> > { 293 typedef Bfs< Digraph, SetProcessedMapTraits<T> > Create; 297 294 }; 298 295 299 struct DefDigraphProcessedMapTraits : public Traits {296 struct SetStandardProcessedMapTraits : public Traits { 300 297 typedef typename Digraph::template NodeMap<bool> ProcessedMap; 301 static ProcessedMap *createProcessedMap(const Digraph & G)298 static ProcessedMap *createProcessedMap(const Digraph &g) 302 299 { 303 return new ProcessedMap(G); 300 return new ProcessedMap(g); 301 return 0; // ignore warnings 304 302 } 305 303 }; 306 ///\brief \ref named-templ-param "Named parameter" 307 /// for setting the ProcessedMap type to be Digraph::NodeMap<bool>.308 /// 309 ///\ref named-templ-param "Named parameter" 310 /// for setting the ProcessedMap type to be Digraph::NodeMap<bool>.304 ///\brief \ref named-templ-param "Named parameter" for setting 305 ///ProcessedMap type to be <tt>Digraph::NodeMap<bool></tt>. 306 /// 307 ///\ref named-templ-param "Named parameter" for setting 308 ///ProcessedMap type to be <tt>Digraph::NodeMap<bool></tt>. 311 309 ///If you don't set it explicitly, it will be automatically allocated. 312 template <class T> 313 struct DefProcessedMapToBeDefaultMap : 314 public Bfs< Digraph, DefDigraphProcessedMapTraits> { 315 typedef Bfs< Digraph, DefDigraphProcessedMapTraits> Create; 310 struct SetStandardProcessedMap : 311 public Bfs< Digraph, SetStandardProcessedMapTraits > { 312 typedef Bfs< Digraph, SetStandardProcessedMapTraits > Create; 316 313 }; 317 314 … … 322 319 ///Constructor. 323 320 324 /// \param _G the digraph the algorithm will run on.325 /// 326 Bfs(const Digraph & _G) :327 G(& _G),321 ///Constructor. 322 ///\param g The digraph the algorithm runs on. 323 Bfs(const Digraph &g) : 324 G(&g), 328 325 _pred(NULL), local_pred(false), 329 326 _dist(NULL), local_dist(false), … … 341 338 } 342 339 343 ///Sets the map storingthe predecessor arcs.344 345 ///Sets the map storingthe predecessor arcs.340 ///Sets the map that stores the predecessor arcs. 341 342 ///Sets the map that stores the predecessor arcs. 346 343 ///If you don't use this function before calling \ref run(), 347 344 ///it will allocate one. The destructor deallocates this … … 358 355 } 359 356 360 ///Sets the map indicating the reached nodes.361 362 ///Sets the map indicating the reached nodes.357 ///Sets the map that indicates which nodes are reached. 358 359 ///Sets the map that indicates which nodes are reached. 363 360 ///If you don't use this function before calling \ref run(), 364 361 ///it will allocate one. The destructor deallocates this … … 375 372 } 376 373 377 ///Sets the map indicating the processed nodes.378 379 ///Sets the map indicating the processed nodes.374 ///Sets the map that indicates which nodes are processed. 375 376 ///Sets the map that indicates which nodes are processed. 380 377 ///If you don't use this function before calling \ref run(), 381 378 ///it will allocate one. The destructor deallocates this … … 392 389 } 393 390 394 ///Sets the map storing the distances calculated by the algorithm. 395 396 ///Sets the map storing the distances calculated by the algorithm. 391 ///Sets the map that stores the distances of the nodes. 392 393 ///Sets the map that stores the distances of the nodes calculated by 394 ///the algorithm. 397 395 ///If you don't use this function before calling \ref run(), 398 396 ///it will allocate one. The destructor deallocates this … … 410 408 411 409 public: 410 412 411 ///\name Execution control 413 412 ///The simplest way to execute the algorithm is to use 414 ///one of the member functions called \ c run(...).413 ///one of the member functions called \ref lemon::Bfs::run() "run()". 415 414 ///\n 416 ///If you need more control on the execution, 417 /// first you must call \ref init(), then you can add several source nodes418 /// with \ref addSource().419 ///Finally \ref start() will perform the actual path420 /// computation.415 ///If you need more control on the execution, first you must call 416 ///\ref lemon::Bfs::init() "init()", then you can add several source 417 ///nodes with \ref lemon::Bfs::addSource() "addSource()". 418 ///Finally \ref lemon::Bfs::start() "start()" will perform the 419 ///actual path computation. 421 420 422 421 ///@{ 423 422 424 /// \briefInitializes the internal data structures.425 /// 423 ///Initializes the internal data structures. 424 426 425 ///Initializes the internal data structures. 427 426 /// … … 461 460 ///\return The processed node. 462 461 /// 463 ///\ warning The queue must not be empty!462 ///\pre The queue must not be empty. 464 463 Node processNextNode() 465 464 { … … 483 482 ///Processes the next node. 484 483 485 ///Processes the next node . And checks thatthe given target node484 ///Processes the next node and checks if the given target node 486 485 ///is reached. If the target node is reachable from the processed 487 ///node then the reached parameter will be set true. The reached 488 ///parameter should be initially false. 486 ///node, then the \c reach parameter will be set to \c true. 489 487 /// 490 488 ///\param target The target node. 491 ///\retval reach Indicates that the target node is reached. 489 ///\retval reach Indicates if the target node is reached. 490 ///It should be initially \c false. 491 /// 492 492 ///\return The processed node. 493 493 /// 494 ///\ warning The queue must not be empty!494 ///\pre The queue must not be empty. 495 495 Node processNextNode(Node target, bool& reach) 496 496 { … … 515 515 ///Processes the next node. 516 516 517 ///Processes the next node. And checks that at least one of 518 ///reached node has true value in the \c nm node map. If one node 519 ///with true value is reachable from the processed node then the 520 ///rnode parameter will be set to the first of such nodes. 521 /// 522 ///\param nm The node map of possible targets. 517 ///Processes the next node and checks if at least one of reached 518 ///nodes has \c true value in the \c nm node map. If one node 519 ///with \c true value is reachable from the processed node, then the 520 ///\c rnode parameter will be set to the first of such nodes. 521 /// 522 ///\param nm A \c bool (or convertible) node map that indicates the 523 ///possible targets. 523 524 ///\retval rnode The reached target node. 525 ///It should be initially \c INVALID. 526 /// 524 527 ///\return The processed node. 525 528 /// 526 ///\ warning The queue must not be empty!529 ///\pre The queue must not be empty. 527 530 template<class NM> 528 531 Node processNextNode(const NM& nm, Node& rnode) … … 546 549 } 547 550 548 ///Next node to be processed. 549 550 ///Next node to be processed. 551 /// 552 ///\return The next node to be processed or INVALID if the queue is 553 /// empty. 554 Node nextNode() 551 ///The next node to be processed. 552 553 ///Returns the next node to be processed or \c INVALID if the queue 554 ///is empty. 555 Node nextNode() const 555 556 { 556 557 return _queue_tail<_queue_head?_queue[_queue_tail]:INVALID; … … 558 559 559 560 ///\brief Returns \c false if there are nodes 560 ///to be processed in the queue561 ///to be processed. 561 562 /// 562 563 ///Returns \c false if there are nodes 563 ///to be processed in the queue 564 bool emptyQueue() { return _queue_tail==_queue_head; } 564 ///to be processed in the queue. 565 bool emptyQueue() const { return _queue_tail==_queue_head; } 566 565 567 ///Returns the number of the nodes to be processed. 566 568 567 569 ///Returns the number of the nodes to be processed in the queue. 568 int queueSize() { return _queue_head-_queue_tail; }570 int queueSize() const { return _queue_head-_queue_tail; } 569 571 570 572 ///Executes the algorithm. … … 572 574 ///Executes the algorithm. 573 575 /// 574 ///\pre init() must be called and at least one node should be added575 ///with addSource() before using this function.576 ///577 576 ///This method runs the %BFS algorithm from the root node(s) 578 ///in order to 579 ///compute the 580 ///shortest path to each node. The algorithm computes 581 ///- The shortest path tree. 582 ///- The distance of each node from the root(s). 577 ///in order to compute the shortest path to each node. 578 /// 579 ///The algorithm computes 580 ///- the shortest path tree (forest), 581 ///- the distance of each node from the root(s). 582 /// 583 ///\pre init() must be called and at least one root node should be 584 ///added with addSource() before using this function. 585 /// 586 ///\note <tt>b.start()</tt> is just a shortcut of the following code. 587 ///\code 588 /// while ( !b.emptyQueue() ) { 589 /// b.processNextNode(); 590 /// } 591 ///\endcode 583 592 void start() 584 593 { … … 586 595 } 587 596 588 ///Executes the algorithm until \c dest is reached. 589 590 ///Executes the algorithm until \c dest is reached. 591 /// 592 ///\pre init() must be called and at least one node should be added 593 ///with addSource() before using this function. 597 ///Executes the algorithm until the given target node is reached. 598 599 ///Executes the algorithm until the given target node is reached. 594 600 /// 595 601 ///This method runs the %BFS algorithm from the root node(s) 596 ///in order to compute the shortest path to \c dest. 602 ///in order to compute the shortest path to \c t. 603 /// 597 604 ///The algorithm computes 598 ///- The shortest path to \c dest. 599 ///- The distance of \c dest from the root(s). 600 void start(Node dest) 605 ///- the shortest path to \c t, 606 ///- the distance of \c t from the root(s). 607 /// 608 ///\pre init() must be called and at least one root node should be 609 ///added with addSource() before using this function. 610 /// 611 ///\note <tt>b.start(t)</tt> is just a shortcut of the following code. 612 ///\code 613 /// bool reach = false; 614 /// while ( !b.emptyQueue() && !reach ) { 615 /// b.processNextNode(t, reach); 616 /// } 617 ///\endcode 618 void start(Node t) 601 619 { 602 620 bool reach = false; 603 while ( !emptyQueue() && !reach ) processNextNode( dest, reach);621 while ( !emptyQueue() && !reach ) processNextNode(t, reach); 604 622 } 605 623 … … 608 626 ///Executes the algorithm until a condition is met. 609 627 /// 610 /// \pre init() must be called and at least one node should be added611 /// with addSource() before using this function.612 /// 613 /// \param nm must be a bool (or convertible) node map. The614 /// algorithm will stop when it reaches a node \c v with615 /// <tt>nm[v]</tt> true.628 ///This method runs the %BFS algorithm from the root node(s) in 629 ///order to compute the shortest path to a node \c v with 630 /// <tt>nm[v]</tt> true, if such a node can be found. 631 /// 632 ///\param nm A \c bool (or convertible) node map. The algorithm 633 ///will stop when it reaches a node \c v with <tt>nm[v]</tt> true. 616 634 /// 617 635 ///\return The reached node \c v with <tt>nm[v]</tt> true or 618 636 ///\c INVALID if no such node was found. 619 template<class NM> 620 Node start(const NM &nm) 637 /// 638 ///\pre init() must be called and at least one root node should be 639 ///added with addSource() before using this function. 640 /// 641 ///\note <tt>b.start(nm)</tt> is just a shortcut of the following code. 642 ///\code 643 /// Node rnode = INVALID; 644 /// while ( !b.emptyQueue() && rnode == INVALID ) { 645 /// b.processNextNode(nm, rnode); 646 /// } 647 /// return rnode; 648 ///\endcode 649 template<class NodeBoolMap> 650 Node start(const NodeBoolMap &nm) 621 651 { 622 652 Node rnode = INVALID; … … 627 657 } 628 658 629 ///Runs %BFS algorithm from node \c s.630 631 ///This method runs the %BFS algorithm from a rootnode \c s632 ///in order to 633 /// compute the634 /// shortest path to each node.The algorithm computes635 ///- The shortest path tree.636 ///- The distance of each node from the root.637 /// 638 ///\note b.run(s)is just a shortcut of the following code.659 ///Runs the algorithm from the given source node. 660 661 ///This method runs the %BFS algorithm from node \c s 662 ///in order to compute the shortest path to each node. 663 /// 664 ///The algorithm computes 665 ///- the shortest path tree, 666 ///- the distance of each node from the root. 667 /// 668 ///\note <tt>b.run(s)</tt> is just a shortcut of the following code. 639 669 ///\code 640 670 /// b.init(); … … 650 680 ///Finds the shortest path between \c s and \c t. 651 681 652 ///Finds the shortest path between \c s and \c t. 653 /// 654 ///\return The length of the shortest s---t path if there exists one, 655 ///0 otherwise. 656 ///\note Apart from the return value, b.run(s) is 657 ///just a shortcut of the following code. 682 ///This method runs the %BFS algorithm from node \c s 683 ///in order to compute the shortest path to node \c t 684 ///(it stops searching when \c t is processed). 685 /// 686 ///\return \c true if \c t is reachable form \c s. 687 /// 688 ///\note Apart from the return value, <tt>b.run(s,t)</tt> is just a 689 ///shortcut of the following code. 658 690 ///\code 659 691 /// b.init(); … … 661 693 /// b.start(t); 662 694 ///\endcode 663 intrun(Node s,Node t) {695 bool run(Node s,Node t) { 664 696 init(); 665 697 addSource(s); 666 698 start(t); 667 return reached(t) ? _curr_dist : 0; 699 return reached(t); 700 } 701 702 ///Runs the algorithm to visit all nodes in the digraph. 703 704 ///This method runs the %BFS algorithm in order to 705 ///compute the shortest path to each node. 706 /// 707 ///The algorithm computes 708 ///- the shortest path tree (forest), 709 ///- the distance of each node from the root(s). 710 /// 711 ///\note <tt>b.run(s)</tt> is just a shortcut of the following code. 712 ///\code 713 /// b.init(); 714 /// for (NodeIt n(gr); n != INVALID; ++n) { 715 /// if (!b.reached(n)) { 716 /// b.addSource(n); 717 /// b.start(); 718 /// } 719 /// } 720 ///\endcode 721 void run() { 722 init(); 723 for (NodeIt n(*G); n != INVALID; ++n) { 724 if (!reached(n)) { 725 addSource(n); 726 start(); 727 } 728 } 668 729 } 669 730 … … 673 734 ///The result of the %BFS algorithm can be obtained using these 674 735 ///functions.\n 675 /// Before the use of these functions,676 /// either run() or start() must be calleb.736 ///Either \ref lemon::Bfs::run() "run()" or \ref lemon::Bfs::start() 737 ///"start()" must be called before using them. 677 738 678 739 ///@{ 679 740 680 typedef PredMapPath<Digraph, PredMap> Path; 681 682 ///Gives back the shortest path. 683 684 ///Gives back the shortest path. 685 ///\pre The \c t should be reachable from the source. 686 Path path(Node t) 687 { 688 return Path(*G, *_pred, t); 689 } 741 ///The shortest path to a node. 742 743 ///Returns the shortest path to a node. 744 /// 745 ///\warning \c t should be reachable from the root(s). 746 /// 747 ///\pre Either \ref run() or \ref start() must be called before 748 ///using this function. 749 Path path(Node t) const { return Path(*G, *_pred, t); } 690 750 691 751 ///The distance of a node from the root(s). 692 752 693 753 ///Returns the distance of a node from the root(s). 694 ///\pre \ref run() must be called before using this function. 695 ///\warning If node \c v in unreachable from the root(s) the return value 696 ///of this function is undefined. 754 /// 755 ///\warning If node \c v is not reachable from the root(s), then 756 ///the return value of this function is undefined. 757 /// 758 ///\pre Either \ref run() or \ref start() must be called before 759 ///using this function. 697 760 int dist(Node v) const { return (*_dist)[v]; } 698 761 699 ///Returns the 'previous arc' of the shortest path tree. 700 701 ///For a node \c v it returns the 'previous arc' 702 ///of the shortest path tree, 703 ///i.e. it returns the last arc of a shortest path from the root(s) to \c 704 ///v. It is \ref INVALID 705 ///if \c v is unreachable from the root(s) or \c v is a root. The 706 ///shortest path tree used here is equal to the shortest path tree used in 707 ///\ref predNode(). 708 ///\pre Either \ref run() or \ref start() must be called before using 709 ///this function. 762 ///Returns the 'previous arc' of the shortest path tree for a node. 763 764 ///This function returns the 'previous arc' of the shortest path 765 ///tree for the node \c v, i.e. it returns the last arc of a 766 ///shortest path from the root(s) to \c v. It is \c INVALID if \c v 767 ///is not reachable from the root(s) or if \c v is a root. 768 /// 769 ///The shortest path tree used here is equal to the shortest path 770 ///tree used in \ref predNode(). 771 /// 772 ///\pre Either \ref run() or \ref start() must be called before 773 ///using this function. 710 774 Arc predArc(Node v) const { return (*_pred)[v];} 711 775 712 ///Returns the 'previous node' of the shortest path tree. 713 714 ///For a node \c v it returns the 'previous node' 715 ///of the shortest path tree, 716 ///i.e. it returns the last but one node from a shortest path from the 717 ///root(a) to \c /v. 718 ///It is INVALID if \c v is unreachable from the root(s) or 719 ///if \c v itself a root. 776 ///Returns the 'previous node' of the shortest path tree for a node. 777 778 ///This function returns the 'previous node' of the shortest path 779 ///tree for the node \c v, i.e. it returns the last but one node 780 ///from a shortest path from the root(s) to \c v. It is \c INVALID 781 ///if \c v is not reachable from the root(s) or if \c v is a root. 782 /// 720 783 ///The shortest path tree used here is equal to the shortest path 721 784 ///tree used in \ref predArc(). 785 /// 722 786 ///\pre Either \ref run() or \ref start() must be called before 723 787 ///using this function. … … 725 789 G->source((*_pred)[v]); } 726 790 727 ///Returns a reference to the NodeMap of distances. 728 729 ///Returns a reference to the NodeMap of distances. 730 ///\pre Either \ref run() or \ref init() must 731 ///be called before using this function. 791 ///\brief Returns a const reference to the node map that stores the 792 /// distances of the nodes. 793 /// 794 ///Returns a const reference to the node map that stores the distances 795 ///of the nodes calculated by the algorithm. 796 /// 797 ///\pre Either \ref run() or \ref init() 798 ///must be called before using this function. 732 799 const DistMap &distMap() const { return *_dist;} 733 800 734 ///Returns a reference to the shortest path tree map. 735 736 ///Returns a reference to the NodeMap of the arcs of the 737 ///shortest path tree. 801 ///\brief Returns a const reference to the node map that stores the 802 ///predecessor arcs. 803 /// 804 ///Returns a const reference to the node map that stores the predecessor 805 ///arcs, which form the shortest path tree. 806 /// 738 807 ///\pre Either \ref run() or \ref init() 739 808 ///must be called before using this function. 740 809 const PredMap &predMap() const { return *_pred;} 741 810 742 ///Checks if a node is reachable from the root. 743 744 ///Returns \c true if \c v is reachable from the root. 745 ///\warning The source nodes are indicated as unreached. 811 ///Checks if a node is reachable from the root(s). 812 813 ///Returns \c true if \c v is reachable from the root(s). 746 814 ///\pre Either \ref run() or \ref start() 747 815 ///must be called before using this function. 748 /// 749 bool reached(Node v) { return (*_reached)[v]; } 816 bool reached(Node v) const { return (*_reached)[v]; } 750 817 751 818 ///@} 752 819 }; 753 820 754 ///Default traits class of Bfsfunction.755 756 ///Default traits class of Bfsfunction.821 ///Default traits class of bfs() function. 822 823 ///Default traits class of bfs() function. 757 824 ///\tparam GR Digraph type. 758 825 template<class GR> 759 826 struct BfsWizardDefaultTraits 760 827 { 761 ///The digraph typethe algorithm runs on.828 ///The type of the digraph the algorithm runs on. 762 829 typedef GR Digraph; 763 ///\brief The type of the map that stores the last 830 831 ///\brief The type of the map that stores the predecessor 764 832 ///arcs of the shortest paths. 765 833 /// 766 ///The type of the map that stores the last834 ///The type of the map that stores the predecessor 767 835 ///arcs of the shortest paths. 768 836 ///It must meet the \ref concepts::WriteMap "WriteMap" concept. 769 /// 770 typedef NullMap<typename Digraph::Node,typename GR::Arc> PredMap; 837 typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap; 771 838 ///Instantiates a PredMap. 772 839 773 ///This function instantiates a \ref PredMap. 774 ///\param g is the digraph, to which we would like to define the PredMap. 775 ///\todo The digraph alone may be insufficient to initialize 776 #ifdef DOXYGEN 777 static PredMap *createPredMap(const GR &g) 778 #else 779 static PredMap *createPredMap(const GR &) 780 #endif 781 { 782 return new PredMap(); 840 ///This function instantiates a PredMap. 841 ///\param g is the digraph, to which we would like to define the 842 ///PredMap. 843 static PredMap *createPredMap(const Digraph &g) 844 { 845 return new PredMap(g); 783 846 } 784 847 … … 787 850 ///The type of the map that indicates which nodes are processed. 788 851 ///It must meet the \ref concepts::WriteMap "WriteMap" concept. 789 /// \todo named parameter to set this type, function to read and write.852 ///By default it is a NullMap. 790 853 typedef NullMap<typename Digraph::Node,bool> ProcessedMap; 791 854 ///Instantiates a ProcessedMap. 792 855 793 ///This function instantiates a \refProcessedMap.856 ///This function instantiates a ProcessedMap. 794 857 ///\param g is the digraph, to which 795 ///we would like to define the \ref ProcessedMap858 ///we would like to define the ProcessedMap. 796 859 #ifdef DOXYGEN 797 static ProcessedMap *createProcessedMap(const GR&g)860 static ProcessedMap *createProcessedMap(const Digraph &g) 798 861 #else 799 static ProcessedMap *createProcessedMap(const GR&)862 static ProcessedMap *createProcessedMap(const Digraph &) 800 863 #endif 801 864 { 802 865 return new ProcessedMap(); 803 866 } 867 804 868 ///The type of the map that indicates which nodes are reached. 805 869 806 870 ///The type of the map that indicates which nodes are reached. 807 ///It must meet the \ref concepts::WriteMap "WriteMap" concept. 808 ///\todo named parameter to set this type, function to read and write. 871 ///It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept. 809 872 typedef typename Digraph::template NodeMap<bool> ReachedMap; 810 873 ///Instantiates a ReachedMap. 811 874 812 ///This function instantiates a \ref ReachedMap. 813 ///\param G is the digraph, to which 814 ///we would like to define the \ref ReachedMap. 815 static ReachedMap *createReachedMap(const GR &G) 816 { 817 return new ReachedMap(G); 818 } 819 ///The type of the map that stores the dists of the nodes. 820 821 ///The type of the map that stores the dists of the nodes. 875 ///This function instantiates a ReachedMap. 876 ///\param g is the digraph, to which 877 ///we would like to define the ReachedMap. 878 static ReachedMap *createReachedMap(const Digraph &g) 879 { 880 return new ReachedMap(g); 881 } 882 883 ///The type of the map that stores the distances of the nodes. 884 885 ///The type of the map that stores the distances of the nodes. 822 886 ///It must meet the \ref concepts::WriteMap "WriteMap" concept. 823 /// 824 typedef NullMap<typename Digraph::Node,int> DistMap; 887 typedef typename Digraph::template NodeMap<int> DistMap; 825 888 ///Instantiates a DistMap. 826 889 827 ///This function instantiates a \refDistMap.890 ///This function instantiates a DistMap. 828 891 ///\param g is the digraph, to which we would like to define 829 ///the \ref DistMap 830 #ifdef DOXYGEN 831 static DistMap *createDistMap(const GR &g) 832 #else 833 static DistMap *createDistMap(const GR &) 834 #endif 835 { 836 return new DistMap(); 837 } 892 ///the DistMap 893 static DistMap *createDistMap(const Digraph &g) 894 { 895 return new DistMap(g); 896 } 897 898 ///The type of the shortest paths. 899 900 ///The type of the shortest paths. 901 ///It must meet the \ref concepts::Path "Path" concept. 902 typedef lemon::Path<Digraph> Path; 838 903 }; 839 904 840 /// Default traits used by \refBfsWizard905 /// Default traits class used by BfsWizard 841 906 842 907 /// To make it easier to use Bfs algorithm 843 /// we have created a wizard class.908 /// we have created a wizard class. 844 909 /// This \ref BfsWizard class needs default traits, 845 /// as well as the \ref Bfs class.910 /// as well as the \ref Bfs class. 846 911 /// The \ref BfsWizardBase is a class to be the default traits of the 847 912 /// \ref BfsWizard class. … … 852 917 typedef BfsWizardDefaultTraits<GR> Base; 853 918 protected: 854 // / Type of the nodes in the digraph.919 //The type of the nodes in the digraph. 855 920 typedef typename Base::Digraph::Node Node; 856 921 857 // / Pointer to the underlying digraph.922 //Pointer to the digraph the algorithm runs on. 858 923 void *_g; 859 // /Pointer to the map of reached nodes.924 //Pointer to the map of reached nodes. 860 925 void *_reached; 861 // /Pointer to the map of processed nodes.926 //Pointer to the map of processed nodes. 862 927 void *_processed; 863 // /Pointer to the map of predecessors arcs.928 //Pointer to the map of predecessors arcs. 864 929 void *_pred; 865 // /Pointer to the map of distances.930 //Pointer to the map of distances. 866 931 void *_dist; 867 ///Pointer to the source node. 868 Node _source; 932 //Pointer to the shortest path to the target node. 933 void *_path; 934 //Pointer to the distance of the target node. 935 int *_di; 869 936 870 937 public: … … 872 939 873 940 /// This constructor does not require parameters, therefore it initiates 874 /// all of the attributes to default values (0, INVALID).941 /// all of the attributes to \c 0. 875 942 BfsWizardBase() : _g(0), _reached(0), _processed(0), _pred(0), 876 _dist(0), _source(INVALID) {}943 _dist(0), _path(0), _di(0) {} 877 944 878 945 /// Constructor. 879 946 880 /// This constructor requires some parameters, 881 /// listed in the parameters list. 882 /// Others are initiated to 0. 883 /// \param g is the initial value of \ref _g 884 /// \param s is the initial value of \ref _source 885 BfsWizardBase(const GR &g, Node s=INVALID) : 947 /// This constructor requires one parameter, 948 /// others are initiated to \c 0. 949 /// \param g The digraph the algorithm runs on. 950 BfsWizardBase(const GR &g) : 886 951 _g(reinterpret_cast<void*>(const_cast<GR*>(&g))), 887 _reached(0), _processed(0), _pred(0), _dist(0), _source(s) {}952 _reached(0), _processed(0), _pred(0), _dist(0), _path(0), _di(0) {} 888 953 889 954 }; 890 955 891 /// A class to make the usage of Bfs algorithm easier 892 893 /// This class is created to make it easier to use Bfs algorithm. 894 /// It uses the functions and features of the plain \ref Bfs, 895 /// but it is much simpler to use it. 956 /// Auxiliary class for the function-type interface of BFS algorithm. 957 958 /// This auxiliary class is created to implement the 959 /// \ref bfs() "function-type interface" of \ref Bfs algorithm. 960 /// It does not have own \ref run() method, it uses the functions 961 /// and features of the plain \ref Bfs. 896 962 /// 897 /// Simplicity means that the way to change the types defined 898 /// in the traits class is based on functions that returns the new class 899 /// and not on templatable built-in classes. 900 /// When using the plain \ref Bfs 901 /// the new class with the modified type comes from 902 /// the original class by using the :: 903 /// operator. In the case of \ref BfsWizard only 904 /// a function have to be called and it will 905 /// return the needed class. 906 /// 907 /// It does not have own \ref run method. When its \ref run method is called 908 /// it initiates a plain \ref Bfs class, and calls the \ref Bfs::run 909 /// method of it. 963 /// This class should only be used through the \ref bfs() function, 964 /// which makes it easier to use the algorithm. 910 965 template<class TR> 911 966 class BfsWizard : public TR … … 913 968 typedef TR Base; 914 969 915 ///The type of the underlying digraph.970 ///The type of the digraph the algorithm runs on. 916 971 typedef typename TR::Digraph Digraph; 917 //\e 972 918 973 typedef typename Digraph::Node Node; 919 //\e920 974 typedef typename Digraph::NodeIt NodeIt; 921 //\e922 975 typedef typename Digraph::Arc Arc; 923 //\e924 976 typedef typename Digraph::OutArcIt OutArcIt; 925 977 926 ///\brief The type of the map that stores 927 ///the reached nodes 928 typedef typename TR::ReachedMap ReachedMap; 929 ///\brief The type of the map that stores 930 ///the processed nodes 931 typedef typename TR::ProcessedMap ProcessedMap; 932 ///\brief The type of the map that stores the last 978 ///\brief The type of the map that stores the predecessor 933 979 ///arcs of the shortest paths. 934 980 typedef typename TR::PredMap PredMap; 935 /// The type of the map that stores the dists of the nodes.981 ///\brief The type of the map that stores the distances of the nodes. 936 982 typedef typename TR::DistMap DistMap; 983 ///\brief The type of the map that indicates which nodes are reached. 984 typedef typename TR::ReachedMap ReachedMap; 985 ///\brief The type of the map that indicates which nodes are processed. 986 typedef typename TR::ProcessedMap ProcessedMap; 987 ///The type of the shortest paths 988 typedef typename TR::Path Path; 937 989 938 990 public: 991 939 992 /// Constructor. 940 993 BfsWizard() : TR() {} … … 944 997 /// Constructor that requires parameters. 945 998 /// These parameters will be the default values for the traits class. 946 BfsWizard(const Digraph &g, Node s=INVALID) : 947 TR(g,s) {} 999 /// \param g The digraph the algorithm runs on. 1000 BfsWizard(const Digraph &g) : 1001 TR(g) {} 948 1002 949 1003 ///Copy constructor … … 952 1006 ~BfsWizard() {} 953 1007 954 ///Runs Bfs algorithm from a given node. 955 956 ///Runs Bfs algorithm from a given node. 957 ///The node can be given by the \ref source function. 1008 ///Runs BFS algorithm from the given source node. 1009 1010 ///This method runs BFS algorithm from node \c s 1011 ///in order to compute the shortest path to each node. 1012 void run(Node s) 1013 { 1014 Bfs<Digraph,TR> alg(*reinterpret_cast<const Digraph*>(Base::_g)); 1015 if (Base::_pred) 1016 alg.predMap(*reinterpret_cast<PredMap*>(Base::_pred)); 1017 if (Base::_dist) 1018 alg.distMap(*reinterpret_cast<DistMap*>(Base::_dist)); 1019 if (Base::_reached) 1020 alg.reachedMap(*reinterpret_cast<ReachedMap*>(Base::_reached)); 1021 if (Base::_processed) 1022 alg.processedMap(*reinterpret_cast<ProcessedMap*>(Base::_processed)); 1023 if (s!=INVALID) 1024 alg.run(s); 1025 else 1026 alg.run(); 1027 } 1028 1029 ///Finds the shortest path between \c s and \c t. 1030 1031 ///This method runs BFS algorithm from node \c s 1032 ///in order to compute the shortest path to node \c t 1033 ///(it stops searching when \c t is processed). 1034 /// 1035 ///\return \c true if \c t is reachable form \c s. 1036 bool run(Node s, Node t) 1037 { 1038 Bfs<Digraph,TR> alg(*reinterpret_cast<const Digraph*>(Base::_g)); 1039 if (Base::_pred) 1040 alg.predMap(*reinterpret_cast<PredMap*>(Base::_pred)); 1041 if (Base::_dist) 1042 alg.distMap(*reinterpret_cast<DistMap*>(Base::_dist)); 1043 if (Base::_reached) 1044 alg.reachedMap(*reinterpret_cast<ReachedMap*>(Base::_reached)); 1045 if (Base::_processed) 1046 alg.processedMap(*reinterpret_cast<ProcessedMap*>(Base::_processed)); 1047 alg.run(s,t); 1048 if (Base::_path) 1049 *reinterpret_cast<Path*>(Base::_path) = alg.path(t); 1050 if (Base::_di) 1051 *Base::_di = alg.dist(t); 1052 return alg.reached(t); 1053 } 1054 1055 ///Runs BFS algorithm to visit all nodes in the digraph. 1056 1057 ///This method runs BFS algorithm in order to compute 1058 ///the shortest path to each node. 958 1059 void run() 959 1060 { 960 if(Base::_source==INVALID) throw UninitializedParameter(); 961 Bfs<Digraph,TR> alg(*reinterpret_cast<const Digraph*>(Base::_g)); 962 if(Base::_reached) 963 alg.reachedMap(*reinterpret_cast<ReachedMap*>(Base::_reached)); 964 if(Base::_processed) 965 alg.processedMap(*reinterpret_cast<ProcessedMap*>(Base::_processed)); 966 if(Base::_pred) 967 alg.predMap(*reinterpret_cast<PredMap*>(Base::_pred)); 968 if(Base::_dist) 969 alg.distMap(*reinterpret_cast<DistMap*>(Base::_dist)); 970 alg.run(Base::_source); 971 } 972 973 ///Runs Bfs algorithm from the given node. 974 975 ///Runs Bfs algorithm from the given node. 976 ///\param s is the given source. 977 void run(Node s) 978 { 979 Base::_source=s; 980 run(); 1061 run(INVALID); 981 1062 } 982 1063 983 1064 template<class T> 984 struct DefPredMapBase : public Base {1065 struct SetPredMapBase : public Base { 985 1066 typedef T PredMap; 986 1067 static PredMap *createPredMap(const Digraph &) { return 0; }; 987 DefPredMapBase(const TR &b) : TR(b) {}1068 SetPredMapBase(const TR &b) : TR(b) {} 988 1069 }; 989 990 ///\brief \ref named-templ-param "Named parameter" 991 ///function for setting PredMap 992 /// 993 /// \ref named-templ-param "Named parameter" 994 ///function for setting PredMap 995 /// 1070 ///\brief \ref named-func-param "Named parameter" 1071 ///for setting PredMap object. 1072 /// 1073 ///\ref named-func-param "Named parameter" 1074 ///for setting PredMap object. 996 1075 template<class T> 997 BfsWizard< DefPredMapBase<T> > predMap(const T &t)1076 BfsWizard<SetPredMapBase<T> > predMap(const T &t) 998 1077 { 999 1078 Base::_pred=reinterpret_cast<void*>(const_cast<T*>(&t)); 1000 return BfsWizard<DefPredMapBase<T> >(*this); 1001 } 1002 1079 return BfsWizard<SetPredMapBase<T> >(*this); 1080 } 1003 1081 1004 1082 template<class T> 1005 struct DefReachedMapBase : public Base {1083 struct SetReachedMapBase : public Base { 1006 1084 typedef T ReachedMap; 1007 1085 static ReachedMap *createReachedMap(const Digraph &) { return 0; }; 1008 DefReachedMapBase(const TR &b) : TR(b) {}1086 SetReachedMapBase(const TR &b) : TR(b) {} 1009 1087 }; 1010 1011 ///\brief \ref named-templ-param "Named parameter" 1012 ///function for setting ReachedMap 1013 /// 1014 /// \ref named-templ-param "Named parameter" 1015 ///function for setting ReachedMap 1016 /// 1088 ///\brief \ref named-func-param "Named parameter" 1089 ///for setting ReachedMap object. 1090 /// 1091 /// \ref named-func-param "Named parameter" 1092 ///for setting ReachedMap object. 1017 1093 template<class T> 1018 BfsWizard< DefReachedMapBase<T> > reachedMap(const T &t)1094 BfsWizard<SetReachedMapBase<T> > reachedMap(const T &t) 1019 1095 { 1020 1096 Base::_reached=reinterpret_cast<void*>(const_cast<T*>(&t)); 1021 return BfsWizard<DefReachedMapBase<T> >(*this); 1022 } 1023 1097 return BfsWizard<SetReachedMapBase<T> >(*this); 1098 } 1024 1099 1025 1100 template<class T> 1026 struct DefProcessedMapBase : public Base { 1101 struct SetDistMapBase : public Base { 1102 typedef T DistMap; 1103 static DistMap *createDistMap(const Digraph &) { return 0; }; 1104 SetDistMapBase(const TR &b) : TR(b) {} 1105 }; 1106 ///\brief \ref named-func-param "Named parameter" 1107 ///for setting DistMap object. 1108 /// 1109 /// \ref named-func-param "Named parameter" 1110 ///for setting DistMap object. 1111 template<class T> 1112 BfsWizard<SetDistMapBase<T> > distMap(const T &t) 1113 { 1114 Base::_dist=reinterpret_cast<void*>(const_cast<T*>(&t)); 1115 return BfsWizard<SetDistMapBase<T> >(*this); 1116 } 1117 1118 template<class T> 1119 struct SetProcessedMapBase : public Base { 1027 1120 typedef T ProcessedMap; 1028 1121 static ProcessedMap *createProcessedMap(const Digraph &) { return 0; }; 1029 DefProcessedMapBase(const TR &b) : TR(b) {}1122 SetProcessedMapBase(const TR &b) : TR(b) {} 1030 1123 }; 1031 1032 ///\brief \ref named-templ-param "Named parameter" 1033 ///function for setting ProcessedMap 1034 /// 1035 /// \ref named-templ-param "Named parameter" 1036 ///function for setting ProcessedMap 1037 /// 1124 ///\brief \ref named-func-param "Named parameter" 1125 ///for setting ProcessedMap object. 1126 /// 1127 /// \ref named-func-param "Named parameter" 1128 ///for setting ProcessedMap object. 1038 1129 template<class T> 1039 BfsWizard< DefProcessedMapBase<T> > processedMap(const T &t)1130 BfsWizard<SetProcessedMapBase<T> > processedMap(const T &t) 1040 1131 { 1041 1132 Base::_processed=reinterpret_cast<void*>(const_cast<T*>(&t)); 1042 return BfsWizard<DefProcessedMapBase<T> >(*this); 1043 } 1044 1133 return BfsWizard<SetProcessedMapBase<T> >(*this); 1134 } 1045 1135 1046 1136 template<class T> 1047 struct DefDistMapBase : public Base { 1048 typedef T DistMap; 1049 static DistMap *createDistMap(const Digraph &) { return 0; }; 1050 DefDistMapBase(const TR &b) : TR(b) {} 1137 struct SetPathBase : public Base { 1138 typedef T Path; 1139 SetPathBase(const TR &b) : TR(b) {} 1051 1140 }; 1052 1053 ///\brief \ref named-templ-param "Named parameter" 1054 ///function for setting DistMap type 1055 /// 1056 /// \ref named-templ-param "Named parameter" 1057 ///function for setting DistMap type 1058 /// 1141 ///\brief \ref named-func-param "Named parameter" 1142 ///for getting the shortest path to the target node. 1143 /// 1144 ///\ref named-func-param "Named parameter" 1145 ///for getting the shortest path to the target node. 1059 1146 template<class T> 1060 BfsWizard<DefDistMapBase<T> > distMap(const T &t) 1061 { 1062 Base::_dist=reinterpret_cast<void*>(const_cast<T*>(&t)); 1063 return BfsWizard<DefDistMapBase<T> >(*this); 1064 } 1065 1066 /// Sets the source node, from which the Bfs algorithm runs. 1067 1068 /// Sets the source node, from which the Bfs algorithm runs. 1069 /// \param s is the source node. 1070 BfsWizard<TR> &source(Node s) 1071 { 1072 Base::_source=s; 1147 BfsWizard<SetPathBase<T> > path(const T &t) 1148 { 1149 Base::_path=reinterpret_cast<void*>(const_cast<T*>(&t)); 1150 return BfsWizard<SetPathBase<T> >(*this); 1151 } 1152 1153 ///\brief \ref named-func-param "Named parameter" 1154 ///for getting the distance of the target node. 1155 /// 1156 ///\ref named-func-param "Named parameter" 1157 ///for getting the distance of the target node. 1158 BfsWizard dist(const int &d) 1159 { 1160 Base::_di=const_cast<int*>(&d); 1073 1161 return *this; 1074 1162 } … … 1076 1164 }; 1077 1165 1078 ///Function type interface for Bfsalgorithm.1166 ///Function-type interface for BFS algorithm. 1079 1167 1080 1168 /// \ingroup search 1081 ///Function type interface for Bfsalgorithm.1169 ///Function-type interface for BFS algorithm. 1082 1170 /// 1083 ///This function also has several 1084 ///\ref named-templ-func-param "named parameters", 1171 ///This function also has several \ref named-func-param "named parameters", 1085 1172 ///they are declared as the members of class \ref BfsWizard. 1086 ///The following 1087 ///example shows how to use these parameters. 1173 ///The following examples show how to use these parameters. 1088 1174 ///\code 1089 /// bfs(g,source).predMap(preds).run(); 1175 /// // Compute shortest path from node s to each node 1176 /// bfs(g).predMap(preds).distMap(dists).run(s); 1177 /// 1178 /// // Compute shortest path from s to t 1179 /// bool reached = bfs(g).path(p).dist(d).run(s,t); 1090 1180 ///\endcode 1091 1181 ///\warning Don't forget to put the \ref BfsWizard::run() "run()" … … 1095 1185 template<class GR> 1096 1186 BfsWizard<BfsWizardBase<GR> > 1097 bfs(const GR & g,typename GR::Node s=INVALID)1187 bfs(const GR &digraph) 1098 1188 { 1099 return BfsWizard<BfsWizardBase<GR> >( g,s);1189 return BfsWizard<BfsWizardBase<GR> >(digraph); 1100 1190 } 1101 1191 1102 1192 #ifdef DOXYGEN 1103 /// \brief Visitor class for bfs.1193 /// \brief Visitor class for BFS. 1104 1194 /// 1105 1195 /// This class defines the interface of the BfsVisit events, and 1106 /// it could be the base of a real Visitor class.1196 /// it could be the base of a real visitor class. 1107 1197 template <typename _Digraph> 1108 1198 struct BfsVisitor { … … 1110 1200 typedef typename Digraph::Arc Arc; 1111 1201 typedef typename Digraph::Node Node; 1112 /// \brief Called when the arc reach a node. 1113 /// 1114 /// It is called when the bfs find an arc which target is not 1115 /// reached yet. 1202 /// \brief Called for the source node(s) of the BFS. 1203 /// 1204 /// This function is called for the source node(s) of the BFS. 1205 void start(const Node& node) {} 1206 /// \brief Called when a node is reached first time. 1207 /// 1208 /// This function is called when a node is reached first time. 1209 void reach(const Node& node) {} 1210 /// \brief Called when a node is processed. 1211 /// 1212 /// This function is called when a node is processed. 1213 void process(const Node& node) {} 1214 /// \brief Called when an arc reaches a new node. 1215 /// 1216 /// This function is called when the BFS finds an arc whose target node 1217 /// is not reached yet. 1116 1218 void discover(const Arc& arc) {} 1117 /// \brief Called when the node reached first time. 1118 /// 1119 /// It is Called when the node reached first time. 1120 void reach(const Node& node) {} 1121 /// \brief Called when the arc examined but target of the arc 1219 /// \brief Called when an arc is examined but its target node is 1122 1220 /// already discovered. 1123 1221 /// 1124 /// It called when the arc examined but the target of the arc1222 /// This function is called when an arc is examined but its target node is 1125 1223 /// already discovered. 1126 1224 void examine(const Arc& arc) {} 1127 /// \brief Called for the source node of the bfs.1128 ///1129 /// It is called for the source node of the bfs.1130 void start(const Node& node) {}1131 /// \brief Called when the node processed.1132 ///1133 /// It is Called when the node processed.1134 void process(const Node& node) {}1135 1225 }; 1136 1226 #else … … 1140 1230 typedef typename Digraph::Arc Arc; 1141 1231 typedef typename Digraph::Node Node; 1232 void start(const Node&) {} 1233 void reach(const Node&) {} 1234 void process(const Node&) {} 1142 1235 void discover(const Arc&) {} 1143 void reach(const Node&) {}1144 1236 void examine(const Arc&) {} 1145 void start(const Node&) {}1146 void process(const Node&) {}1147 1237 1148 1238 template <typename _Visitor> … … 1151 1241 Arc arc; 1152 1242 Node node; 1243 visitor.start(node); 1244 visitor.reach(node); 1245 visitor.process(node); 1153 1246 visitor.discover(arc); 1154 visitor.reach(node);1155 1247 visitor.examine(arc); 1156 visitor.start(node);1157 visitor.process(node);1158 1248 } 1159 1249 _Visitor& visitor; … … 1165 1255 /// 1166 1256 /// Default traits class of BfsVisit class. 1167 /// \tparam _Digraph Digraph type.1257 /// \tparam _Digraph The type of the digraph the algorithm runs on. 1168 1258 template<class _Digraph> 1169 1259 struct BfsVisitDefaultTraits { 1170 1260 1171 /// \brief The digraph typethe algorithm runs on.1261 /// \brief The type of the digraph the algorithm runs on. 1172 1262 typedef _Digraph Digraph; 1173 1263 … … 1175 1265 /// 1176 1266 /// The type of the map that indicates which nodes are reached. 1177 /// It must meet the \ref concepts::WriteMap "WriteMap" concept. 1178 /// \todo named parameter to set this type, function to read and write. 1267 /// It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept. 1179 1268 typedef typename Digraph::template NodeMap<bool> ReachedMap; 1180 1269 1181 1270 /// \brief Instantiates a ReachedMap. 1182 1271 /// 1183 /// This function instantiates a \refReachedMap.1272 /// This function instantiates a ReachedMap. 1184 1273 /// \param digraph is the digraph, to which 1185 /// we would like to define the \refReachedMap.1274 /// we would like to define the ReachedMap. 1186 1275 static ReachedMap *createReachedMap(const Digraph &digraph) { 1187 1276 return new ReachedMap(digraph); … … 1192 1281 /// \ingroup search 1193 1282 /// 1194 /// \brief %BFS Visit algorithm class.1283 /// \brief %BFS algorithm class with visitor interface. 1195 1284 /// 1196 1285 /// This class provides an efficient implementation of the %BFS algorithm … … 1199 1288 /// The %BfsVisit class provides an alternative interface to the Bfs 1200 1289 /// class. It works with callback mechanism, the BfsVisit object calls 1201 /// on every bfs event the \c Visitor class member functions.1290 /// the member functions of the \c Visitor class on every BFS event. 1202 1291 /// 1203 /// \tparam _Digraph The digraph type the algorithm runs on. 1292 /// This interface of the BFS algorithm should be used in special cases 1293 /// when extra actions have to be performed in connection with certain 1294 /// events of the BFS algorithm. Otherwise consider to use Bfs or bfs() 1295 /// instead. 1296 /// 1297 /// \tparam _Digraph The type of the digraph the algorithm runs on. 1204 1298 /// The default value is 1205 /// \ref ListDigraph. The value of _Digraph is not used directly by Bfs, it1206 /// is only passed to \ref BfsDefaultTraits.1207 /// \tparam _Visitor The Visitor object for the algorithm. The1208 /// \ref BfsVisitor "BfsVisitor<_Digraph>" is an empty Visitorwhich1209 /// does not observe the B fs events. If you want to observe the bfs1210 /// events you should implement your own Visitor class.1299 /// \ref ListDigraph. The value of _Digraph is not used directly by 1300 /// \ref BfsVisit, it is only passed to \ref BfsVisitDefaultTraits. 1301 /// \tparam _Visitor The Visitor type that is used by the algorithm. 1302 /// \ref BfsVisitor "BfsVisitor<_Digraph>" is an empty visitor, which 1303 /// does not observe the BFS events. If you want to observe the BFS 1304 /// events, you should implement your own visitor class. 1211 1305 /// \tparam _Traits Traits class to set various data types used by the 1212 1306 /// algorithm. The default traits class is 1213 1307 /// \ref BfsVisitDefaultTraits "BfsVisitDefaultTraits<_Digraph>". 1214 1308 /// See \ref BfsVisitDefaultTraits for the documentation of 1215 /// a B fsvisit traits class.1309 /// a BFS visit traits class. 1216 1310 #ifdef DOXYGEN 1217 1311 template <typename _Digraph, typename _Visitor, typename _Traits> … … 1219 1313 template <typename _Digraph = ListDigraph, 1220 1314 typename _Visitor = BfsVisitor<_Digraph>, 1221 typename _Traits = Bfs DefaultTraits<_Digraph> >1315 typename _Traits = BfsVisitDefaultTraits<_Digraph> > 1222 1316 #endif 1223 1317 class BfsVisit { 1224 1318 public: 1225 1319 1226 /// \brief \ref Exception for uninitialized parameters. 1227 /// 1228 /// This error represents problems in the initialization 1229 /// of the parameters of the algorithms. 1230 class UninitializedParameter : public lemon::UninitializedParameter { 1231 public: 1232 virtual const char* what() const throw() 1233 { 1234 return "lemon::BfsVisit::UninitializedParameter"; 1235 } 1236 }; 1237 1320 ///The traits class. 1238 1321 typedef _Traits Traits; 1239 1322 1323 ///The type of the digraph the algorithm runs on. 1240 1324 typedef typename Traits::Digraph Digraph; 1241 1325 1326 ///The visitor type used by the algorithm. 1242 1327 typedef _Visitor Visitor; 1243 1328 1244 ///The type of the map indicatingwhich nodes are reached.1329 ///The type of the map that indicates which nodes are reached. 1245 1330 typedef typename Traits::ReachedMap ReachedMap; 1246 1331 … … 1252 1337 typedef typename Digraph::OutArcIt OutArcIt; 1253 1338 1254 // /Pointer to the underlying digraph.1339 //Pointer to the underlying digraph. 1255 1340 const Digraph *_digraph; 1256 // /Pointer to the visitor object.1341 //Pointer to the visitor object. 1257 1342 Visitor *_visitor; 1258 // /Pointer to the map of reached status of the nodes.1343 //Pointer to the map of reached status of the nodes. 1259 1344 ReachedMap *_reached; 1260 // /Indicates if \ref _reached is locally allocated (\ctrue) or not.1345 //Indicates if _reached is locally allocated (true) or not. 1261 1346 bool local_reached; 1262 1347 … … 1264 1349 int _list_front, _list_back; 1265 1350 1266 /// \brief Creates the maps if necessary. 1267 /// 1268 /// Creates the maps if necessary. 1351 //Creates the maps if necessary. 1269 1352 void create_maps() { 1270 1353 if(!_reached) { … … 1286 1369 ///@{ 1287 1370 template <class T> 1288 struct DefReachedMapTraits : public Traits {1371 struct SetReachedMapTraits : public Traits { 1289 1372 typedef T ReachedMap; 1290 1373 static ReachedMap *createReachedMap(const Digraph &digraph) { 1291 throw UninitializedParameter(); 1374 LEMON_ASSERT(false, "ReachedMap is not initialized"); 1375 return 0; // ignore warnings 1292 1376 } 1293 1377 }; 1294 1378 /// \brief \ref named-templ-param "Named parameter" for setting 1295 /// ReachedMap type 1296 /// 1297 /// \ref named-templ-param "Named parameter" for setting ReachedMap type 1379 /// ReachedMap type. 1380 /// 1381 /// \ref named-templ-param "Named parameter" for setting ReachedMap type. 1298 1382 template <class T> 1299 struct DefReachedMap : public BfsVisit< Digraph, Visitor,1300 DefReachedMapTraits<T> > {1301 typedef BfsVisit< Digraph, Visitor, DefReachedMapTraits<T> > Create;1383 struct SetReachedMap : public BfsVisit< Digraph, Visitor, 1384 SetReachedMapTraits<T> > { 1385 typedef BfsVisit< Digraph, Visitor, SetReachedMapTraits<T> > Create; 1302 1386 }; 1303 1387 ///@} … … 1309 1393 /// Constructor. 1310 1394 /// 1311 /// \param digraph the digraph the algorithm will run on. 1312 /// \param visitor The visitor of the algorithm. 1313 /// 1395 /// \param digraph The digraph the algorithm runs on. 1396 /// \param visitor The visitor object of the algorithm. 1314 1397 BfsVisit(const Digraph& digraph, Visitor& visitor) 1315 1398 : _digraph(&digraph), _visitor(&visitor), … … 1317 1400 1318 1401 /// \brief Destructor. 1319 ///1320 /// Destructor.1321 1402 ~BfsVisit() { 1322 1403 if(local_reached) delete _reached; 1323 1404 } 1324 1405 1325 /// \brief Sets the map indicating if a node isreached.1326 /// 1327 /// Sets the map indicating if a node isreached.1406 /// \brief Sets the map that indicates which nodes are reached. 1407 /// 1408 /// Sets the map that indicates which nodes are reached. 1328 1409 /// If you don't use this function before calling \ref run(), 1329 /// it will allocate one. The dest uctor deallocates this1410 /// it will allocate one. The destructor deallocates this 1330 1411 /// automatically allocated map, of course. 1331 1412 /// \return <tt> (*this) </tt> … … 1340 1421 1341 1422 public: 1423 1342 1424 /// \name Execution control 1343 1425 /// The simplest way to execute the algorithm is to use 1344 /// one of the member functions called \c run(...). 1426 /// one of the member functions called \ref lemon::BfsVisit::run() 1427 /// "run()". 1345 1428 /// \n 1346 /// If you need more control on the execution, 1347 /// first you must call \ref init(), then you can adda source node1348 /// with \ref addSource().1349 /// Finally \ref start() will perform the actual path1350 /// computation.1429 /// If you need more control on the execution, first you must call 1430 /// \ref lemon::BfsVisit::init() "init()", then you can add several 1431 /// source nodes with \ref lemon::BfsVisit::addSource() "addSource()". 1432 /// Finally \ref lemon::BfsVisit::start() "start()" will perform the 1433 /// actual path computation. 1351 1434 1352 1435 /// @{ 1436 1353 1437 /// \brief Initializes the internal data structures. 1354 1438 /// 1355 1439 /// Initializes the internal data structures. 1356 ///1357 1440 void init() { 1358 1441 create_maps(); … … 1382 1465 /// \return The processed node. 1383 1466 /// 1384 /// \pre The queue must not be empty !1467 /// \pre The queue must not be empty. 1385 1468 Node processNextNode() { 1386 1469 Node n = _list[++_list_front]; … … 1403 1486 /// \brief Processes the next node. 1404 1487 /// 1405 /// Processes the next node . And checks thatthe given target node1488 /// Processes the next node and checks if the given target node 1406 1489 /// is reached. If the target node is reachable from the processed 1407 /// node then the reached parameter will be set true. The reached 1408 /// parameter should be initially false. 1490 /// node, then the \c reach parameter will be set to \c true. 1409 1491 /// 1410 1492 /// \param target The target node. 1411 /// \retval reach Indicates that the target node is reached. 1493 /// \retval reach Indicates if the target node is reached. 1494 /// It should be initially \c false. 1495 /// 1412 1496 /// \return The processed node. 1413 1497 /// 1414 /// \ warning The queue must not be empty!1498 /// \pre The queue must not be empty. 1415 1499 Node processNextNode(Node target, bool& reach) { 1416 1500 Node n = _list[++_list_front]; … … 1434 1518 /// \brief Processes the next node. 1435 1519 /// 1436 /// Processes the next node. And checks that at least one of 1437 /// reached node has true value in the \c nm node map. If one node 1438 /// with true value is reachable from the processed node then the 1439 /// rnode parameter will be set to the first of such nodes. 1440 /// 1441 /// \param nm The node map of possible targets. 1520 /// Processes the next node and checks if at least one of reached 1521 /// nodes has \c true value in the \c nm node map. If one node 1522 /// with \c true value is reachable from the processed node, then the 1523 /// \c rnode parameter will be set to the first of such nodes. 1524 /// 1525 /// \param nm A \c bool (or convertible) node map that indicates the 1526 /// possible targets. 1442 1527 /// \retval rnode The reached target node. 1528 /// It should be initially \c INVALID. 1529 /// 1443 1530 /// \return The processed node. 1444 1531 /// 1445 /// \ warning The queue must not be empty!1532 /// \pre The queue must not be empty. 1446 1533 template <typename NM> 1447 1534 Node processNextNode(const NM& nm, Node& rnode) { … … 1464 1551 } 1465 1552 1466 /// \brief Next node to be processed. 1467 /// 1468 /// Next node to be processed. 1469 /// 1470 /// \return The next node to be processed or INVALID if the stack is 1471 /// empty. 1472 Node nextNode() { 1553 /// \brief The next node to be processed. 1554 /// 1555 /// Returns the next node to be processed or \c INVALID if the queue 1556 /// is empty. 1557 Node nextNode() const { 1473 1558 return _list_front != _list_back ? _list[_list_front + 1] : INVALID; 1474 1559 } 1475 1560 1476 1561 /// \brief Returns \c false if there are nodes 1477 /// to be processed in the queue1562 /// to be processed. 1478 1563 /// 1479 1564 /// Returns \c false if there are nodes 1480 /// to be processed in the queue 1481 bool emptyQueue() { return _list_front == _list_back; }1565 /// to be processed in the queue. 1566 bool emptyQueue() const { return _list_front == _list_back; } 1482 1567 1483 1568 /// \brief Returns the number of the nodes to be processed. 1484 1569 /// 1485 1570 /// Returns the number of the nodes to be processed in the queue. 1486 int queueSize() { return _list_back - _list_front; }1571 int queueSize() const { return _list_back - _list_front; } 1487 1572 1488 1573 /// \brief Executes the algorithm. … … 1490 1575 /// Executes the algorithm. 1491 1576 /// 1492 /// \pre init() must be called and at least one node should be added 1577 /// This method runs the %BFS algorithm from the root node(s) 1578 /// in order to compute the shortest path to each node. 1579 /// 1580 /// The algorithm computes 1581 /// - the shortest path tree (forest), 1582 /// - the distance of each node from the root(s). 1583 /// 1584 /// \pre init() must be called and at least one root node should be added 1493 1585 /// with addSource() before using this function. 1586 /// 1587 /// \note <tt>b.start()</tt> is just a shortcut of the following code. 1588 /// \code 1589 /// while ( !b.emptyQueue() ) { 1590 /// b.processNextNode(); 1591 /// } 1592 /// \endcode 1494 1593 void start() { 1495 1594 while ( !emptyQueue() ) processNextNode(); 1496 1595 } 1497 1596 1498 /// \brief Executes the algorithm until \c dest is reached. 1499 /// 1500 /// Executes the algorithm until \c dest is reached. 1501 /// 1502 /// \pre init() must be called and at least one node should be added 1503 /// with addSource() before using this function. 1504 void start(Node dest) { 1597 /// \brief Executes the algorithm until the given target node is reached. 1598 /// 1599 /// Executes the algorithm until the given target node is reached. 1600 /// 1601 /// This method runs the %BFS algorithm from the root node(s) 1602 /// in order to compute the shortest path to \c t. 1603 /// 1604 /// The algorithm computes 1605 /// - the shortest path to \c t, 1606 /// - the distance of \c t from the root(s). 1607 /// 1608 /// \pre init() must be called and at least one root node should be 1609 /// added with addSource() before using this function. 1610 /// 1611 /// \note <tt>b.start(t)</tt> is just a shortcut of the following code. 1612 /// \code 1613 /// bool reach = false; 1614 /// while ( !b.emptyQueue() && !reach ) { 1615 /// b.processNextNode(t, reach); 1616 /// } 1617 /// \endcode 1618 void start(Node t) { 1505 1619 bool reach = false; 1506 while ( !emptyQueue() && !reach ) processNextNode( dest, reach);1620 while ( !emptyQueue() && !reach ) processNextNode(t, reach); 1507 1621 } 1508 1622 … … 1511 1625 /// Executes the algorithm until a condition is met. 1512 1626 /// 1513 /// \pre init() must be called and at least one node should be added 1514 /// with addSource() before using this function. 1515 /// 1516 ///\param nm must be a bool (or convertible) node map. The 1517 ///algorithm will stop when it reaches a node \c v with 1627 /// This method runs the %BFS algorithm from the root node(s) in 1628 /// order to compute the shortest path to a node \c v with 1629 /// <tt>nm[v]</tt> true, if such a node can be found. 1630 /// 1631 /// \param nm must be a bool (or convertible) node map. The 1632 /// algorithm will stop when it reaches a node \c v with 1518 1633 /// <tt>nm[v]</tt> true. 1519 1634 /// 1520 ///\return The reached node \c v with <tt>nm[v]</tt> true or 1521 ///\c INVALID if no such node was found. 1635 /// \return The reached node \c v with <tt>nm[v]</tt> true or 1636 /// \c INVALID if no such node was found. 1637 /// 1638 /// \pre init() must be called and at least one root node should be 1639 /// added with addSource() before using this function. 1640 /// 1641 /// \note <tt>b.start(nm)</tt> is just a shortcut of the following code. 1642 /// \code 1643 /// Node rnode = INVALID; 1644 /// while ( !b.emptyQueue() && rnode == INVALID ) { 1645 /// b.processNextNode(nm, rnode); 1646 /// } 1647 /// return rnode; 1648 /// \endcode 1522 1649 template <typename NM> 1523 1650 Node start(const NM &nm) { … … 1529 1656 } 1530 1657 1531 /// \brief Runs %BFSVisit algorithm from node \c s. 1532 /// 1533 /// This method runs the %BFS algorithm from a root node \c s. 1534 /// \note b.run(s) is just a shortcut of the following code. 1658 /// \brief Runs the algorithm from the given source node. 1659 /// 1660 /// This method runs the %BFS algorithm from node \c s 1661 /// in order to compute the shortest path to each node. 1662 /// 1663 /// The algorithm computes 1664 /// - the shortest path tree, 1665 /// - the distance of each node from the root. 1666 /// 1667 /// \note <tt>b.run(s)</tt> is just a shortcut of the following code. 1535 1668 ///\code 1536 1669 /// b.init(); … … 1544 1677 } 1545 1678 1546 /// \brief Runs %BFSVisit algorithm to visit all nodes in the digraph. 1679 /// \brief Finds the shortest path between \c s and \c t. 1680 /// 1681 /// This method runs the %BFS algorithm from node \c s 1682 /// in order to compute the shortest path to node \c t 1683 /// (it stops searching when \c t is processed). 1684 /// 1685 /// \return \c true if \c t is reachable form \c s. 1686 /// 1687 /// \note Apart from the return value, <tt>b.run(s,t)</tt> is just a 1688 /// shortcut of the following code. 1689 ///\code 1690 /// b.init(); 1691 /// b.addSource(s); 1692 /// b.start(t); 1693 ///\endcode 1694 bool run(Node s,Node t) { 1695 init(); 1696 addSource(s); 1697 start(t); 1698 return reached(t); 1699 } 1700 1701 /// \brief Runs the algorithm to visit all nodes in the digraph. 1547 1702 /// 1548 1703 /// This method runs the %BFS algorithm in order to 1549 /// compute the %BFS path to each node. The algorithm computes 1550 /// - The %BFS tree. 1551 /// - The distance of each node from the root in the %BFS tree. 1552 /// 1553 ///\note b.run() is just a shortcut of the following code. 1704 /// compute the shortest path to each node. 1705 /// 1706 /// The algorithm computes 1707 /// - the shortest path tree (forest), 1708 /// - the distance of each node from the root(s). 1709 /// 1710 /// \note <tt>b.run(s)</tt> is just a shortcut of the following code. 1554 1711 ///\code 1555 1712 /// b.init(); 1556 /// for (NodeIt it(digraph); it != INVALID; ++it) {1557 /// if (!b.reached( it)) {1558 /// b.addSource( it);1713 /// for (NodeIt n(gr); n != INVALID; ++n) { 1714 /// if (!b.reached(n)) { 1715 /// b.addSource(n); 1559 1716 /// b.start(); 1560 1717 /// } … … 1570 1727 } 1571 1728 } 1729 1572 1730 ///@} 1573 1731 … … 1575 1733 /// The result of the %BFS algorithm can be obtained using these 1576 1734 /// functions.\n 1577 /// Before the use of these functions, 1578 /// either run() or start() must be called. 1735 /// Either \ref lemon::BfsVisit::run() "run()" or 1736 /// \ref lemon::BfsVisit::start() "start()" must be called before 1737 /// using them. 1579 1738 ///@{ 1580 1739 1581 /// \brief Checks if a node is reachable from the root .1740 /// \brief Checks if a node is reachable from the root(s). 1582 1741 /// 1583 1742 /// Returns \c true if \c v is reachable from the root(s). 1584 /// \warning The source nodes are inditated as unreachable.1585 1743 /// \pre Either \ref run() or \ref start() 1586 1744 /// must be called before using this function. 1587 ///1588 1745 bool reached(Node v) { return (*_reached)[v]; } 1746 1589 1747 ///@} 1748 1590 1749 }; 1591 1750 … … 1593 1752 1594 1753 #endif 1595 -
lemon/bits/alteration_notifier.h
r220 r318 25 25 #include <lemon/core.h> 26 26 27 // /\ingroup graphbits28 // /\file29 // /\brief Observer notifier for graph alteration observers.27 //\ingroup graphbits 28 //\file 29 //\brief Observer notifier for graph alteration observers. 30 30 31 31 namespace lemon { 32 32 33 /// \ingroup graphbits 34 /// 35 /// \brief Notifier class to notify observes about alterations in 36 /// a container. 37 /// 38 /// The simple graph's can be refered as two containers, one node container 39 /// and one edge container. But they are not standard containers they 40 /// does not store values directly they are just key continars for more 41 /// value containers which are the node and edge maps. 42 /// 43 /// The graph's node and edge sets can be changed as we add or erase 44 /// nodes and edges in the graph. Lemon would like to handle easily 45 /// that the node and edge maps should contain values for all nodes or 46 /// edges. If we want to check on every indicing if the map contains 47 /// the current indicing key that cause a drawback in the performance 48 /// in the library. We use another solution we notify all maps about 49 /// an alteration in the graph, which cause only drawback on the 50 /// alteration of the graph. 51 /// 52 /// This class provides an interface to the container. The \e first() and \e 53 /// next() member functions make possible to iterate on the keys of the 54 /// container. The \e id() function returns an integer id for each key. 55 /// The \e maxId() function gives back an upper bound of the ids. 56 /// 57 /// For the proper functonality of this class, we should notify it 58 /// about each alteration in the container. The alterations have four type 59 /// as \e add(), \e erase(), \e build() and \e clear(). The \e add() and 60 /// \e erase() signals that only one or few items added or erased to or 61 /// from the graph. If all items are erased from the graph or from an empty 62 /// graph a new graph is builded then it can be signaled with the 63 /// clear() and build() members. Important rule that if we erase items 64 /// from graph we should first signal the alteration and after that erase 65 /// them from the container, on the other way on item addition we should 66 /// first extend the container and just after that signal the alteration. 67 /// 68 /// The alteration can be observed with a class inherited from the 69 /// \e ObserverBase nested class. The signals can be handled with 70 /// overriding the virtual functions defined in the base class. The 71 /// observer base can be attached to the notifier with the 72 /// \e attach() member and can be detached with detach() function. The 73 /// alteration handlers should not call any function which signals 74 /// an other alteration in the same notifier and should not 75 /// detach any observer from the notifier. 76 /// 77 /// Alteration observers try to be exception safe. If an \e add() or 78 /// a \e clear() function throws an exception then the remaining 79 /// observeres will not be notified and the fulfilled additions will 80 /// be rolled back by calling the \e erase() or \e clear() 81 /// functions. Thence the \e erase() and \e clear() should not throw 82 /// exception. Actullay, it can be throw only 83 /// \ref AlterationObserver::ImmediateDetach ImmediateDetach 84 /// exception which detach the observer from the notifier. 85 /// 86 /// There are some place when the alteration observing is not completly 87 /// reliable. If we want to carry out the node degree in the graph 88 /// as in the \ref InDegMap and we use the reverseEdge that cause 89 /// unreliable functionality. Because the alteration observing signals 90 /// only erasing and adding but not the reversing it will stores bad 91 /// degrees. The sub graph adaptors cannot signal the alterations because 92 /// just a setting in the filter map can modify the graph and this cannot 93 /// be watched in any way. 94 /// 95 /// \param _Container The container which is observed. 96 /// \param _Item The item type which is obserbved. 33 // \ingroup graphbits 34 // 35 // \brief Notifier class to notify observes about alterations in 36 // a container. 37 // 38 // The simple graph's can be refered as two containers, one node container 39 // and one edge container. But they are not standard containers they 40 // does not store values directly they are just key continars for more 41 // value containers which are the node and edge maps. 42 // 43 // The graph's node and edge sets can be changed as we add or erase 44 // nodes and edges in the graph. LEMON would like to handle easily 45 // that the node and edge maps should contain values for all nodes or 46 // edges. If we want to check on every indicing if the map contains 47 // the current indicing key that cause a drawback in the performance 48 // in the library. We use another solution we notify all maps about 49 // an alteration in the graph, which cause only drawback on the 50 // alteration of the graph. 51 // 52 // This class provides an interface to the container. The \e first() and \e 53 // next() member functions make possible to iterate on the keys of the 54 // container. The \e id() function returns an integer id for each key. 55 // The \e maxId() function gives back an upper bound of the ids. 56 // 57 // For the proper functonality of this class, we should notify it 58 // about each alteration in the container. The alterations have four type 59 // as \e add(), \e erase(), \e build() and \e clear(). The \e add() and 60 // \e erase() signals that only one or few items added or erased to or 61 // from the graph. If all items are erased from the graph or from an empty 62 // graph a new graph is builded then it can be signaled with the 63 // clear() and build() members. Important rule that if we erase items 64 // from graph we should first signal the alteration and after that erase 65 // them from the container, on the other way on item addition we should 66 // first extend the container and just after that signal the alteration. 67 // 68 // The alteration can be observed with a class inherited from the 69 // \e ObserverBase nested class. The signals can be handled with 70 // overriding the virtual functions defined in the base class. The 71 // observer base can be attached to the notifier with the 72 // \e attach() member and can be detached with detach() function. The 73 // alteration handlers should not call any function which signals 74 // an other alteration in the same notifier and should not 75 // detach any observer from the notifier. 76 // 77 // Alteration observers try to be exception safe. If an \e add() or 78 // a \e clear() function throws an exception then the remaining 79 // observeres will not be notified and the fulfilled additions will 80 // be rolled back by calling the \e erase() or \e clear() 81 // functions. Thence the \e erase() and \e clear() should not throw 82 // exception. Actullay, it can be throw only \ref ImmediateDetach 83 // exception which detach the observer from the notifier. 84 // 85 // There are some place when the alteration observing is not completly 86 // reliable. If we want to carry out the node degree in the graph 87 // as in the \ref InDegMap and we use the reverseEdge that cause 88 // unreliable functionality. Because the alteration observing signals 89 // only erasing and adding but not the reversing it will stores bad 90 // degrees. The sub graph adaptors cannot signal the alterations because 91 // just a setting in the filter map can modify the graph and this cannot 92 // be watched in any way. 93 // 94 // \param _Container The container which is observed. 95 // \param _Item The item type which is obserbved. 97 96 98 97 template <typename _Container, typename _Item> … … 105 104 typedef _Item Item; 106 105 107 // /\brief Exception which can be called from \e clear() and108 // /\e erase().109 // /110 // /From the \e clear() and \e erase() function only this111 // /exception is allowed to throw. The exception immediatly112 // /detaches the current observer from the notifier. Because the113 // /\e clear() and \e erase() should not throw other exceptions114 // /it can be used to invalidate the observer.106 // \brief Exception which can be called from \e clear() and 107 // \e erase(). 108 // 109 // From the \e clear() and \e erase() function only this 110 // exception is allowed to throw. The exception immediatly 111 // detaches the current observer from the notifier. Because the 112 // \e clear() and \e erase() should not throw other exceptions 113 // it can be used to invalidate the observer. 115 114 struct ImmediateDetach {}; 116 115 117 /// \brief ObserverBase is the base class for the observers. 118 /// 119 /// ObserverBase is the abstract base class for the observers. 120 /// It will be notified about an item was inserted into or 121 /// erased from the graph. 122 /// 123 /// The observer interface contains some pure virtual functions 124 /// to override. The add() and erase() functions are 125 /// to notify the oberver when one item is added or 126 /// erased. 127 /// 128 /// The build() and clear() members are to notify the observer 129 /// about the container is built from an empty container or 130 /// is cleared to an empty container. 131 116 // \brief ObserverBase is the base class for the observers. 117 // 118 // ObserverBase is the abstract base class for the observers. 119 // It will be notified about an item was inserted into or 120 // erased from the graph. 121 // 122 // The observer interface contains some pure virtual functions 123 // to override. The add() and erase() functions are 124 // to notify the oberver when one item is added or 125 // erased. 126 // 127 // The build() and clear() members are to notify the observer 128 // about the container is built from an empty container or 129 // is cleared to an empty container. 132 130 class ObserverBase { 133 131 protected: … … 136 134 friend class AlterationNotifier; 137 135 138 /// \brief Default constructor. 139 /// 140 /// Default constructor for ObserverBase. 141 /// 136 // \brief Default constructor. 137 // 138 // Default constructor for ObserverBase. 142 139 ObserverBase() : _notifier(0) {} 143 140 144 // /\brief Constructor which attach the observer into notifier.145 // /146 // /Constructor which attach the observer into notifier.141 // \brief Constructor which attach the observer into notifier. 142 // 143 // Constructor which attach the observer into notifier. 147 144 ObserverBase(AlterationNotifier& nf) { 148 145 attach(nf); 149 146 } 150 147 151 // /\brief Constructor which attach the obserever to the same notifier.152 // /153 // /Constructor which attach the obserever to the same notifier as154 // /the other observer is attached to.148 // \brief Constructor which attach the obserever to the same notifier. 149 // 150 // Constructor which attach the obserever to the same notifier as 151 // the other observer is attached to. 155 152 ObserverBase(const ObserverBase& copy) { 156 153 if (copy.attached()) { … … 159 156 } 160 157 161 // /\brief Destructor158 // \brief Destructor 162 159 virtual ~ObserverBase() { 163 160 if (attached()) { … … 166 163 } 167 164 168 /// \brief Attaches the observer into an AlterationNotifier. 169 /// 170 /// This member attaches the observer into an AlterationNotifier. 171 /// 165 // \brief Attaches the observer into an AlterationNotifier. 166 // 167 // This member attaches the observer into an AlterationNotifier. 172 168 void attach(AlterationNotifier& nf) { 173 169 nf.attach(*this); 174 170 } 175 171 176 /// \brief Detaches the observer into an AlterationNotifier. 177 /// 178 /// This member detaches the observer from an AlterationNotifier. 179 /// 172 // \brief Detaches the observer into an AlterationNotifier. 173 // 174 // This member detaches the observer from an AlterationNotifier. 180 175 void detach() { 181 176 _notifier->detach(*this); 182 177 } 183 178 184 /// \brief Gives back a pointer to the notifier which the map 185 /// attached into. 186 /// 187 /// This function gives back a pointer to the notifier which the map 188 /// attached into. 189 /// 179 // \brief Gives back a pointer to the notifier which the map 180 // attached into. 181 // 182 // This function gives back a pointer to the notifier which the map 183 // attached into. 190 184 Notifier* notifier() const { return const_cast<Notifier*>(_notifier); } 191 185 192 // /Gives back true when the observer is attached into a notifier.186 // Gives back true when the observer is attached into a notifier. 193 187 bool attached() const { return _notifier != 0; } 194 188 … … 202 196 typename std::list<ObserverBase*>::iterator _index; 203 197 204 // /\brief The member function to notificate the observer about an205 // /item is added to the container.206 // /207 // /The add() member function notificates the observer about an item208 // /is added to the container. It have to be overrided in the209 // /subclasses.198 // \brief The member function to notificate the observer about an 199 // item is added to the container. 200 // 201 // The add() member function notificates the observer about an item 202 // is added to the container. It have to be overrided in the 203 // subclasses. 210 204 virtual void add(const Item&) = 0; 211 205 212 // /\brief The member function to notificate the observer about213 // /more item is added to the container.214 // /215 // /The add() member function notificates the observer about more item216 // /is added to the container. It have to be overrided in the217 // /subclasses.206 // \brief The member function to notificate the observer about 207 // more item is added to the container. 208 // 209 // The add() member function notificates the observer about more item 210 // is added to the container. It have to be overrided in the 211 // subclasses. 218 212 virtual void add(const std::vector<Item>& items) = 0; 219 213 220 // /\brief The member function to notificate the observer about an221 // /item is erased from the container.222 // /223 // /The erase() member function notificates the observer about an224 // /item is erased from the container. It have to be overrided in225 // /the subclasses.214 // \brief The member function to notificate the observer about an 215 // item is erased from the container. 216 // 217 // The erase() member function notificates the observer about an 218 // item is erased from the container. It have to be overrided in 219 // the subclasses. 226 220 virtual void erase(const Item&) = 0; 227 221 228 // /\brief The member function to notificate the observer about229 // /more item is erased from the container.230 // /231 // /The erase() member function notificates the observer about more item232 // /is erased from the container. It have to be overrided in the233 // /subclasses.222 // \brief The member function to notificate the observer about 223 // more item is erased from the container. 224 // 225 // The erase() member function notificates the observer about more item 226 // is erased from the container. It have to be overrided in the 227 // subclasses. 234 228 virtual void erase(const std::vector<Item>& items) = 0; 235 229 236 /// \brief The member function to notificate the observer about the 237 /// container is built. 238 /// 239 /// The build() member function notificates the observer about the 240 /// container is built from an empty container. It have to be 241 /// overrided in the subclasses. 242 230 // \brief The member function to notificate the observer about the 231 // container is built. 232 // 233 // The build() member function notificates the observer about the 234 // container is built from an empty container. It have to be 235 // overrided in the subclasses. 243 236 virtual void build() = 0; 244 237 245 // /\brief The member function to notificate the observer about all246 // /items are erased from the container.247 // /248 // /The clear() member function notificates the observer about all249 // /items are erased from the container. It have to be overrided in250 // /the subclasses.238 // \brief The member function to notificate the observer about all 239 // items are erased from the container. 240 // 241 // The clear() member function notificates the observer about all 242 // items are erased from the container. It have to be overrided in 243 // the subclasses. 251 244 virtual void clear() = 0; 252 245 … … 263 256 public: 264 257 265 // /\brief Default constructor.266 // /267 // /The default constructor of the AlterationNotifier.268 // /It creates an empty notifier.258 // \brief Default constructor. 259 // 260 // The default constructor of the AlterationNotifier. 261 // It creates an empty notifier. 269 262 AlterationNotifier() 270 263 : container(0) {} 271 264 272 // /\brief Constructor.273 // /274 // /Constructor with the observed container parameter.265 // \brief Constructor. 266 // 267 // Constructor with the observed container parameter. 275 268 AlterationNotifier(const Container& _container) 276 269 : container(&_container) {} 277 270 278 // /\brief Copy Constructor of the AlterationNotifier.279 // /280 // /Copy constructor of the AlterationNotifier.281 // /It creates only an empty notifier because the copiable282 // /notifier's observers have to be registered still into that notifier.271 // \brief Copy Constructor of the AlterationNotifier. 272 // 273 // Copy constructor of the AlterationNotifier. 274 // It creates only an empty notifier because the copiable 275 // notifier's observers have to be registered still into that notifier. 283 276 AlterationNotifier(const AlterationNotifier& _notifier) 284 277 : container(_notifier.container) {} 285 278 286 /// \brief Destructor. 287 /// 288 /// Destructor of the AlterationNotifier. 289 /// 279 // \brief Destructor. 280 // 281 // Destructor of the AlterationNotifier. 290 282 ~AlterationNotifier() { 291 283 typename Observers::iterator it; … … 295 287 } 296 288 297 // /\brief Sets the container.298 // /299 // /Sets the container.289 // \brief Sets the container. 290 // 291 // Sets the container. 300 292 void setContainer(const Container& _container) { 301 293 container = &_container; … … 308 300 public: 309 301 310 311 312 /// \brief First item in the container. 313 /// 314 /// Returns the first item in the container. It is 315 /// for start the iteration on the container. 302 // \brief First item in the container. 303 // 304 // Returns the first item in the container. It is 305 // for start the iteration on the container. 316 306 void first(Item& item) const { 317 307 container->first(item); 318 308 } 319 309 320 // /\brief Next item in the container.321 // /322 // /Returns the next item in the container. It is323 // /for iterate on the container.310 // \brief Next item in the container. 311 // 312 // Returns the next item in the container. It is 313 // for iterate on the container. 324 314 void next(Item& item) const { 325 315 container->next(item); 326 316 } 327 317 328 // /\brief Returns the id of the item.329 // /330 // /Returns the id of the item provided by the container.318 // \brief Returns the id of the item. 319 // 320 // Returns the id of the item provided by the container. 331 321 int id(const Item& item) const { 332 322 return container->id(item); 333 323 } 334 324 335 // /\brief Returns the maximum id of the container.336 // /337 // /Returns the maximum id of the container.325 // \brief Returns the maximum id of the container. 326 // 327 // Returns the maximum id of the container. 338 328 int maxId() const { 339 329 return container->maxId(Item()); … … 355 345 public: 356 346 357 /// \brief Notifies all the registed observers about an item added to 358 /// the container. 359 /// 360 /// It notifies all the registed observers about an item added to 361 /// the container. 362 /// 347 // \brief Notifies all the registed observers about an item added to 348 // the container. 349 // 350 // It notifies all the registed observers about an item added to 351 // the container. 363 352 void add(const Item& item) { 364 353 typename Observers::reverse_iterator it; … … 376 365 } 377 366 378 /// \brief Notifies all the registed observers about more item added to 379 /// the container. 380 /// 381 /// It notifies all the registed observers about more item added to 382 /// the container. 383 /// 367 // \brief Notifies all the registed observers about more item added to 368 // the container. 369 // 370 // It notifies all the registed observers about more item added to 371 // the container. 384 372 void add(const std::vector<Item>& items) { 385 373 typename Observers::reverse_iterator it; … … 397 385 } 398 386 399 /// \brief Notifies all the registed observers about an item erased from 400 /// the container. 401 /// 402 /// It notifies all the registed observers about an item erased from 403 /// the container. 404 /// 387 // \brief Notifies all the registed observers about an item erased from 388 // the container. 389 // 390 // It notifies all the registed observers about an item erased from 391 // the container. 405 392 void erase(const Item& item) throw() { 406 393 typename Observers::iterator it = _observers.begin(); … … 410 397 ++it; 411 398 } catch (const ImmediateDetach&) { 412 it = _observers.erase(it);413 399 (*it)->_index = _observers.end(); 414 400 (*it)->_notifier = 0; 415 }416 }417 }418 419 /// \brief Notifies all the registed observers about more item erased 420 // / from the container.421 // /422 // / It notifies all the registed observers about more item erased from423 // / the container.424 // /401 it = _observers.erase(it); 402 } 403 } 404 } 405 406 // \brief Notifies all the registed observers about more item erased 407 // from the container. 408 // 409 // It notifies all the registed observers about more item erased from 410 // the container. 425 411 void erase(const std::vector<Item>& items) { 426 412 typename Observers::iterator it = _observers.begin(); … … 430 416 ++it; 431 417 } catch (const ImmediateDetach&) { 432 it = _observers.erase(it);433 418 (*it)->_index = _observers.end(); 434 419 (*it)->_notifier = 0; 435 } 436 } 437 } 438 439 /// \brief Notifies all the registed observers about the container is 440 /// built. 441 /// 442 /// Notifies all the registed observers about the container is built 443 /// from an empty container. 420 it = _observers.erase(it); 421 } 422 } 423 } 424 425 // \brief Notifies all the registed observers about the container is 426 // built. 427 // 428 // Notifies all the registed observers about the container is built 429 // from an empty container. 444 430 void build() { 445 431 typename Observers::reverse_iterator it; … … 457 443 } 458 444 459 // /\brief Notifies all the registed observers about all items are460 // /erased.461 // /462 // /Notifies all the registed observers about all items are erased463 // /from the container.445 // \brief Notifies all the registed observers about all items are 446 // erased. 447 // 448 // Notifies all the registed observers about all items are erased 449 // from the container. 464 450 void clear() { 465 451 typename Observers::iterator it = _observers.begin(); … … 469 455 ++it; 470 456 } catch (const ImmediateDetach&) { 471 it = _observers.erase(it);472 457 (*it)->_index = _observers.end(); 473 458 (*it)->_notifier = 0; 459 it = _observers.erase(it); 474 460 } 475 461 } -
lemon/bits/array_map.h
r209 r318 27 27 #include <lemon/concepts/maps.h> 28 28 29 // /\ingroup graphbits30 // /\file31 // /\brief Graph map based on the array storage.29 // \ingroup graphbits 30 // \file 31 // \brief Graph map based on the array storage. 32 32 33 33 namespace lemon { 34 34 35 // /\ingroup graphbits36 // /37 // /\brief Graph map based on the array storage.38 // /39 // /The ArrayMap template class is graph map structure what40 // /automatically updates the map when a key is added to or erased from41 // /the map. This map uses the allocators to implement42 // /the container functionality.43 // /44 // /The template parameters are the Graph the current Item type and45 // /the Value type of the map.35 // \ingroup graphbits 36 // 37 // \brief Graph map based on the array storage. 38 // 39 // The ArrayMap template class is graph map structure what 40 // automatically updates the map when a key is added to or erased from 41 // the map. This map uses the allocators to implement 42 // the container functionality. 43 // 44 // The template parameters are the Graph the current Item type and 45 // the Value type of the map. 46 46 template <typename _Graph, typename _Item, typename _Value> 47 47 class ArrayMap 48 48 : public ItemSetTraits<_Graph, _Item>::ItemNotifier::ObserverBase { 49 49 public: 50 // /The graph type of the maps.50 // The graph type of the maps. 51 51 typedef _Graph Graph; 52 // /The item type of the map.52 // The item type of the map. 53 53 typedef _Item Item; 54 // /The reference map tag.54 // The reference map tag. 55 55 typedef True ReferenceMapTag; 56 56 57 // /The key type of the maps.57 // The key type of the maps. 58 58 typedef _Item Key; 59 // /The value type of the map.59 // The value type of the map. 60 60 typedef _Value Value; 61 61 62 // /The const reference type of the map.62 // The const reference type of the map. 63 63 typedef const _Value& ConstReference; 64 // /The reference type of the map.64 // The reference type of the map. 65 65 typedef _Value& Reference; 66 66 67 // /The notifier type.67 // The notifier type. 68 68 typedef typename ItemSetTraits<_Graph, _Item>::ItemNotifier Notifier; 69 69 70 // /The MapBase of the Map which imlements the core regisitry function.70 // The MapBase of the Map which imlements the core regisitry function. 71 71 typedef typename Notifier::ObserverBase Parent; 72 72 … … 76 76 public: 77 77 78 // /\brief Graph initialized map constructor.79 // /80 // /Graph initialized map constructor.78 // \brief Graph initialized map constructor. 79 // 80 // Graph initialized map constructor. 81 81 explicit ArrayMap(const Graph& graph) { 82 82 Parent::attach(graph.notifier(Item())); … … 90 90 } 91 91 92 // /\brief Constructor to use default value to initialize the map.93 // /94 // /It constructs a map and initialize all of the the map.92 // \brief Constructor to use default value to initialize the map. 93 // 94 // It constructs a map and initialize all of the the map. 95 95 ArrayMap(const Graph& graph, const Value& value) { 96 96 Parent::attach(graph.notifier(Item())); … … 104 104 } 105 105 106 /// \brief Constructor to copy a map of the same map type. 107 /// 108 /// Constructor to copy a map of the same map type. 106 private: 107 // \brief Constructor to copy a map of the same map type. 108 // 109 // Constructor to copy a map of the same map type. 109 110 ArrayMap(const ArrayMap& copy) : Parent() { 110 111 if (copy.attached()) { … … 122 123 } 123 124 124 // /\brief Assign operator.125 // /126 // /This operator assigns for each item in the map the127 // /value mapped to the same item in the copied map.128 // /The parameter map should be indiced with the same129 // /itemset because this assign operator does not change130 // /the container of the map.125 // \brief Assign operator. 126 // 127 // This operator assigns for each item in the map the 128 // value mapped to the same item in the copied map. 129 // The parameter map should be indiced with the same 130 // itemset because this assign operator does not change 131 // the container of the map. 131 132 ArrayMap& operator=(const ArrayMap& cmap) { 132 133 return operator=<ArrayMap>(cmap); … … 134 135 135 136 136 // /\brief Template assign operator.137 // /138 // /The given parameter should be conform to the ReadMap139 // /concecpt and could be indiced by the current item set of140 // /the NodeMap. In this case the value for each item141 // /is assigned by the value of the given ReadMap.137 // \brief Template assign operator. 138 // 139 // The given parameter should be conform to the ReadMap 140 // concecpt and could be indiced by the current item set of 141 // the NodeMap. In this case the value for each item 142 // is assigned by the value of the given ReadMap. 142 143 template <typename CMap> 143 144 ArrayMap& operator=(const CMap& cmap) { … … 151 152 } 152 153 153 /// \brief The destructor of the map. 154 /// 155 /// The destructor of the map. 154 public: 155 // \brief The destructor of the map. 156 // 157 // The destructor of the map. 156 158 virtual ~ArrayMap() { 157 159 if (attached()) { … … 169 171 public: 170 172 171 // /\brief The subscript operator.172 // /173 // /The subscript operator. The map can be subscripted by the174 // /actual keys of the graph.173 // \brief The subscript operator. 174 // 175 // The subscript operator. The map can be subscripted by the 176 // actual keys of the graph. 175 177 Value& operator[](const Key& key) { 176 178 int id = Parent::notifier()->id(key); … … 178 180 } 179 181 180 // /\brief The const subscript operator.181 // /182 // /The const subscript operator. The map can be subscripted by the183 // /actual keys of the graph.182 // \brief The const subscript operator. 183 // 184 // The const subscript operator. The map can be subscripted by the 185 // actual keys of the graph. 184 186 const Value& operator[](const Key& key) const { 185 187 int id = Parent::notifier()->id(key); … … 187 189 } 188 190 189 // /\brief Setter function of the map.190 // /191 // /Setter function of the map. Equivalent with map[key] = val.192 // /This is a compatibility feature with the not dereferable maps.191 // \brief Setter function of the map. 192 // 193 // Setter function of the map. Equivalent with map[key] = val. 194 // This is a compatibility feature with the not dereferable maps. 193 195 void set(const Key& key, const Value& val) { 194 196 (*this)[key] = val; … … 197 199 protected: 198 200 199 // /\brief Adds a new key to the map.200 // /201 // /It adds a new key to the map. It called by the observer notifier202 // /and it overrides the add() member function of the observer base.201 // \brief Adds a new key to the map. 202 // 203 // It adds a new key to the map. It called by the observer notifier 204 // and it overrides the add() member function of the observer base. 203 205 virtual void add(const Key& key) { 204 206 Notifier* nf = Parent::notifier(); … … 225 227 } 226 228 227 // /\brief Adds more new keys to the map.228 // /229 // /It adds more new keys to the map. It called by the observer notifier230 // /and it overrides the add() member function of the observer base.229 // \brief Adds more new keys to the map. 230 // 231 // It adds more new keys to the map. It called by the observer notifier 232 // and it overrides the add() member function of the observer base. 231 233 virtual void add(const std::vector<Key>& keys) { 232 234 Notifier* nf = Parent::notifier(); … … 269 271 } 270 272 271 // /\brief Erase a key from the map.272 // /273 // /Erase a key from the map. It called by the observer notifier274 // /and it overrides the erase() member function of the observer base.273 // \brief Erase a key from the map. 274 // 275 // Erase a key from the map. It called by the observer notifier 276 // and it overrides the erase() member function of the observer base. 275 277 virtual void erase(const Key& key) { 276 278 int id = Parent::notifier()->id(key); … … 278 280 } 279 281 280 // /\brief Erase more keys from the map.281 // /282 // /Erase more keys from the map. It called by the observer notifier283 // /and it overrides the erase() member function of the observer base.282 // \brief Erase more keys from the map. 283 // 284 // Erase more keys from the map. It called by the observer notifier 285 // and it overrides the erase() member function of the observer base. 284 286 virtual void erase(const std::vector<Key>& keys) { 285 287 for (int i = 0; i < int(keys.size()); ++i) { … … 289 291 } 290 292 291 // /\brief Buildes the map.292 // /293 // /It buildes the map. It called by the observer notifier294 // /and it overrides the build() member function of the observer base.293 // \brief Buildes the map. 294 // 295 // It buildes the map. It called by the observer notifier 296 // and it overrides the build() member function of the observer base. 295 297 virtual void build() { 296 298 Notifier* nf = Parent::notifier(); … … 303 305 } 304 306 305 // /\brief Clear the map.306 // /307 // /It erase all items from the map. It called by the observer notifier308 // /and it overrides the clear() member function of the observer base.307 // \brief Clear the map. 308 // 309 // It erase all items from the map. It called by the observer notifier 310 // and it overrides the clear() member function of the observer base. 309 311 virtual void clear() { 310 312 Notifier* nf = Parent::notifier(); -
lemon/bits/base_extender.h
r220 r318 29 29 #include <lemon/concepts/maps.h> 30 30 31 // /\ingroup digraphbits32 // /\file33 // /\brief Extenders for the digraph types31 //\ingroup digraphbits 32 //\file 33 //\brief Extenders for the digraph types 34 34 namespace lemon { 35 35 36 // /\ingroup digraphbits37 // /38 // /\brief BaseDigraph to BaseGraph extender36 // \ingroup digraphbits 37 // 38 // \brief BaseDigraph to BaseGraph extender 39 39 template <typename Base> 40 40 class UndirDigraphExtender : public Base { … … 60 60 Arc() {} 61 61 62 // /Invalid arc constructor62 // Invalid arc constructor 63 63 Arc(Invalid i) : Edge(i), forward(true) {} 64 64 … … 75 75 }; 76 76 77 78 79 using Parent::source; 80 81 /// Source of the given Arc. 77 // First node of the edge 78 Node u(const Edge &e) const { 79 return Parent::source(e); 80 } 81 82 // Source of the given arc 82 83 Node source(const Arc &e) const { 83 84 return e.forward ? Parent::source(e) : Parent::target(e); 84 85 } 85 86 86 using Parent::target; 87 88 /// Target of the given Arc. 87 // Second node of the edge 88 Node v(const Edge &e) const { 89 return Parent::target(e); 90 } 91 92 // Target of the given arc 89 93 Node target(const Arc &e) const { 90 94 return e.forward ? Parent::target(e) : Parent::source(e); 91 95 } 92 96 93 /// \brief Directed arc from an edge. 94 /// 95 /// Returns a directed arc corresponding to the specified Edge. 96 /// If the given bool is true the given edge and the 97 /// returned arc have the same source node. 98 static Arc direct(const Edge &ue, bool d) { 99 return Arc(ue, d); 100 } 101 102 /// Returns whether the given directed arc is same orientation as the 103 /// corresponding edge. 104 /// 105 /// \todo reference to the corresponding point of the undirected digraph 106 /// concept. "What does the direction of an edge mean?" 107 static bool direction(const Arc &e) { return e.forward; } 108 97 // \brief Directed arc from an edge. 98 // 99 // Returns a directed arc corresponding to the specified edge. 100 // If the given bool is true, the first node of the given edge and 101 // the source node of the returned arc are the same. 102 static Arc direct(const Edge &e, bool d) { 103 return Arc(e, d); 104 } 105 106 // Returns whether the given directed arc has the same orientation 107 // as the corresponding edge. 108 static bool direction(const Arc &a) { return a.forward; } 109 109 110 110 using Parent::first; … … 229 229 return Parent::maxArcId(); 230 230 } 231 232 231 233 232 int arcNum() const { … … 300 299 Red() {} 301 300 Red(const Node& node) : Node(node) { 302 LEMON_ ASSERT(Parent::red(node) || node == INVALID,303 301 LEMON_DEBUG(Parent::red(node) || node == INVALID, 302 typename Parent::NodeSetError()); 304 303 } 305 304 Red& operator=(const Node& node) { 306 LEMON_ ASSERT(Parent::red(node) || node == INVALID,307 305 LEMON_DEBUG(Parent::red(node) || node == INVALID, 306 typename Parent::NodeSetError()); 308 307 Node::operator=(node); 309 308 return *this; … … 332 331 Blue() {} 333 332 Blue(const Node& node) : Node(node) { 334 LEMON_ ASSERT(Parent::blue(node) || node == INVALID,335 333 LEMON_DEBUG(Parent::blue(node) || node == INVALID, 334 typename Parent::NodeSetError()); 336 335 } 337 336 Blue& operator=(const Node& node) { 338 LEMON_ ASSERT(Parent::blue(node) || node == INVALID,339 337 LEMON_DEBUG(Parent::blue(node) || node == INVALID, 338 typename Parent::NodeSetError()); 340 339 Node::operator=(node); 341 340 return *this; -
lemon/bits/bezier.h
r209 r318 20 20 #define LEMON_BEZIER_H 21 21 22 // /\ingroup misc23 // /\file24 // /\brief Classes to compute with Bezier curves.25 // /26 // /Up to now this file is used internally by \ref graph_to_eps.h22 //\ingroup misc 23 //\file 24 //\brief Classes to compute with Bezier curves. 25 // 26 //Up to now this file is used internally by \ref graph_to_eps.h 27 27 28 28 #include<lemon/dim2.h> -
lemon/bits/default_map.h
r209 r318 20 20 #define LEMON_BITS_DEFAULT_MAP_H 21 21 22 23 22 #include <lemon/bits/array_map.h> 24 23 #include <lemon/bits/vector_map.h> 25 24 //#include <lemon/bits/debug_map.h> 26 25 27 // /\ingroup graphbits28 // /\file29 // /\brief Graph maps that construct and destruct their elements dynamically.26 //\ingroup graphbits 27 //\file 28 //\brief Graph maps that construct and destruct their elements dynamically. 30 29 31 30 namespace lemon { … … 150 149 // #endif 151 150 152 // / \e151 // DefaultMap class 153 152 template <typename _Graph, typename _Item, typename _Value> 154 153 class DefaultMap -
lemon/bits/enable_if.h
r220 r318 36 36 #define LEMON_BITS_ENABLE_IF_H 37 37 38 // /\file39 // /\brief Miscellaneous basic utilities38 //\file 39 //\brief Miscellaneous basic utilities 40 40 41 41 namespace lemon 42 42 { 43 43 44 // /Basic type for defining "tags". A "YES" condition for \c enable_if.44 // Basic type for defining "tags". A "YES" condition for \c enable_if. 45 45 46 // /Basic type for defining "tags". A "YES" condition for \c enable_if.47 // /48 // /\sa False46 // Basic type for defining "tags". A "YES" condition for \c enable_if. 47 // 48 //\sa False 49 49 struct True { 50 // /\e50 //\e 51 51 static const bool value = true; 52 52 }; 53 53 54 // /Basic type for defining "tags". A "NO" condition for \c enable_if.54 // Basic type for defining "tags". A "NO" condition for \c enable_if. 55 55 56 // /Basic type for defining "tags". A "NO" condition for \c enable_if.57 // /58 // /\sa True56 // Basic type for defining "tags". A "NO" condition for \c enable_if. 57 // 58 //\sa True 59 59 struct False { 60 // /\e60 //\e 61 61 static const bool value = false; 62 62 }; -
lemon/bits/graph_extender.h
r220 r318 28 28 #include <lemon/concepts/maps.h> 29 29 30 // /\ingroup graphbits31 // /\file32 // /\brief Extenders for the digraph types30 //\ingroup graphbits 31 //\file 32 //\brief Extenders for the digraph types 33 33 namespace lemon { 34 34 35 // /\ingroup graphbits36 // /37 // /\brief Extender for the Digraphs35 // \ingroup graphbits 36 // 37 // \brief Extender for the Digraphs 38 38 template <typename Base> 39 39 class DigraphExtender : public Base { … … 187 187 }; 188 188 189 // /\brief Base node of the iterator190 // /191 // /Returns the base node (i.e. the source in this case) of the iterator189 // \brief Base node of the iterator 190 // 191 // Returns the base node (i.e. the source in this case) of the iterator 192 192 Node baseNode(const OutArcIt &arc) const { 193 193 return Parent::source(arc); 194 194 } 195 // /\brief Running node of the iterator196 // /197 // /Returns the running node (i.e. the target in this case) of the198 // /iterator195 // \brief Running node of the iterator 196 // 197 // Returns the running node (i.e. the target in this case) of the 198 // iterator 199 199 Node runningNode(const OutArcIt &arc) const { 200 200 return Parent::target(arc); 201 201 } 202 202 203 // /\brief Base node of the iterator204 // /205 // /Returns the base node (i.e. the target in this case) of the iterator203 // \brief Base node of the iterator 204 // 205 // Returns the base node (i.e. the target in this case) of the iterator 206 206 Node baseNode(const InArcIt &arc) const { 207 207 return Parent::target(arc); 208 208 } 209 // /\brief Running node of the iterator210 // /211 // /Returns the running node (i.e. the source in this case) of the212 // /iterator209 // \brief Running node of the iterator 210 // 211 // Returns the running node (i.e. the source in this case) of the 212 // iterator 213 213 Node runningNode(const InArcIt &arc) const { 214 214 return Parent::source(arc); … … 228 228 : Parent(digraph, value) {} 229 229 230 private: 230 231 NodeMap& operator=(const NodeMap& cmap) { 231 232 return operator=<NodeMap>(cmap); … … 252 253 : Parent(digraph, value) {} 253 254 255 private: 254 256 ArcMap& operator=(const ArcMap& cmap) { 255 257 return operator=<ArcMap>(cmap); … … 324 326 }; 325 327 326 // /\ingroup _graphbits327 // /328 // /\brief Extender for the Graphs328 // \ingroup _graphbits 329 // 330 // \brief Extender for the Graphs 329 331 template <typename Base> 330 332 class GraphExtender : public Base { … … 554 556 }; 555 557 556 // /\brief Base node of the iterator557 // /558 // /Returns the base node (ie. the source in this case) of the iterator558 // \brief Base node of the iterator 559 // 560 // Returns the base node (ie. the source in this case) of the iterator 559 561 Node baseNode(const OutArcIt &arc) const { 560 562 return Parent::source(static_cast<const Arc&>(arc)); 561 563 } 562 // /\brief Running node of the iterator563 // /564 // /Returns the running node (ie. the target in this case) of the565 // /iterator564 // \brief Running node of the iterator 565 // 566 // Returns the running node (ie. the target in this case) of the 567 // iterator 566 568 Node runningNode(const OutArcIt &arc) const { 567 569 return Parent::target(static_cast<const Arc&>(arc)); 568 570 } 569 571 570 // /\brief Base node of the iterator571 // /572 // /Returns the base node (ie. the target in this case) of the iterator572 // \brief Base node of the iterator 573 // 574 // Returns the base node (ie. the target in this case) of the iterator 573 575 Node baseNode(const InArcIt &arc) const { 574 576 return Parent::target(static_cast<const Arc&>(arc)); 575 577 } 576 // /\brief Running node of the iterator577 // /578 // /Returns the running node (ie. the source in this case) of the579 // /iterator578 // \brief Running node of the iterator 579 // 580 // Returns the running node (ie. the source in this case) of the 581 // iterator 580 582 Node runningNode(const InArcIt &arc) const { 581 583 return Parent::source(static_cast<const Arc&>(arc)); 582 584 } 583 585 584 // /Base node of the iterator585 // /586 // /Returns the base node of the iterator586 // Base node of the iterator 587 // 588 // Returns the base node of the iterator 587 589 Node baseNode(const IncEdgeIt &edge) const { 588 590 return edge._direction ? u(edge) : v(edge); 589 591 } 590 // /Running node of the iterator591 // /592 // /Returns the running node of the iterator592 // Running node of the iterator 593 // 594 // Returns the running node of the iterator 593 595 Node runningNode(const IncEdgeIt &edge) const { 594 596 return edge._direction ? v(edge) : u(edge); … … 609 611 : Parent(graph, value) {} 610 612 613 private: 611 614 NodeMap& operator=(const NodeMap& cmap) { 612 615 return operator=<NodeMap>(cmap); … … 633 636 : Parent(graph, value) {} 634 637 638 private: 635 639 ArcMap& operator=(const ArcMap& cmap) { 636 640 return operator=<ArcMap>(cmap); … … 658 662 : Parent(graph, value) {} 659 663 664 private: 660 665 EdgeMap& operator=(const EdgeMap& cmap) { 661 666 return operator=<EdgeMap>(cmap); -
lemon/bits/map_extender.h
r209 r318 27 27 #include <lemon/concepts/maps.h> 28 28 29 // /\file30 // /\brief Extenders for iterable maps.29 //\file 30 //\brief Extenders for iterable maps. 31 31 32 32 namespace lemon { 33 33 34 // /\ingroup graphbits35 // /36 // /\brief Extender for maps34 // \ingroup graphbits 35 // 36 // \brief Extender for maps 37 37 template <typename _Map> 38 38 class MapExtender : public _Map { … … 63 63 : Parent(graph, value) {} 64 64 65 private: 65 66 MapExtender& operator=(const MapExtender& cmap) { 66 67 return operator=<MapExtender>(cmap); … … 73 74 } 74 75 76 public: 75 77 class MapIt : public Item { 76 78 public: … … 170 172 }; 171 173 172 // /\ingroup graphbits173 // /174 // /\brief Extender for maps which use a subset of the items.174 // \ingroup graphbits 175 // 176 // \brief Extender for maps which use a subset of the items. 175 177 template <typename _Graph, typename _Map> 176 178 class SubMapExtender : public _Map { … … 201 203 : Parent(_graph, _value), graph(_graph) {} 202 204 205 private: 203 206 SubMapExtender& operator=(const SubMapExtender& cmap) { 204 207 return operator=<MapExtender>(cmap); … … 215 218 } 216 219 220 public: 217 221 class MapIt : public Item { 218 222 public: -
lemon/bits/traits.h
r220 r318 20 20 #define LEMON_BITS_TRAITS_H 21 21 22 // /\file23 // /\brief Traits for graphs and maps24 // /22 //\file 23 //\brief Traits for graphs and maps 24 // 25 25 26 26 #include <lemon/bits/enable_if.h> -
lemon/bits/vector_map.h
r220 r318 29 29 #include <lemon/concepts/maps.h> 30 30 31 // /\ingroup graphbits32 // /33 // /\file34 // /\brief Vector based graph maps.31 //\ingroup graphbits 32 // 33 //\file 34 //\brief Vector based graph maps. 35 35 namespace lemon { 36 36 37 /// \ingroup graphbits 38 /// 39 /// \brief Graph map based on the std::vector storage. 40 /// 41 /// The VectorMap template class is graph map structure what 42 /// automatically updates the map when a key is added to or erased from 43 /// the map. This map type uses the std::vector to store the values. 44 /// 45 /// \tparam _Notifier The AlterationNotifier that will notify this map. 46 /// \tparam _Item The item type of the graph items. 47 /// \tparam _Value The value type of the map. 48 /// \todo Fix the doc: there is _Graph parameter instead of _Notifier. 37 // \ingroup graphbits 38 // 39 // \brief Graph map based on the std::vector storage. 40 // 41 // The VectorMap template class is graph map structure what 42 // automatically updates the map when a key is added to or erased from 43 // the map. This map type uses the std::vector to store the values. 44 // 45 // \tparam _Graph The graph this map is attached to. 46 // \tparam _Item The item type of the graph items. 47 // \tparam _Value The value type of the map. 49 48 template <typename _Graph, typename _Item, typename _Value> 50 49 class VectorMap … … 52 51 private: 53 52 54 // /The container type of the map.53 // The container type of the map. 55 54 typedef std::vector<_Value> Container; 56 55 57 56 public: 58 57 59 // /The graph type of the map.58 // The graph type of the map. 60 59 typedef _Graph Graph; 61 // /The item type of the map.60 // The item type of the map. 62 61 typedef _Item Item; 63 // /The reference map tag.62 // The reference map tag. 64 63 typedef True ReferenceMapTag; 65 64 66 // /The key type of the map.65 // The key type of the map. 67 66 typedef _Item Key; 68 // /The value type of the map.67 // The value type of the map. 69 68 typedef _Value Value; 70 69 71 // /The notifier type.70 // The notifier type. 72 71 typedef typename ItemSetTraits<_Graph, _Item>::ItemNotifier Notifier; 73 72 74 // /The map type.73 // The map type. 75 74 typedef VectorMap Map; 76 // /The base class of the map.75 // The base class of the map. 77 76 typedef typename Notifier::ObserverBase Parent; 78 77 79 // /The reference type of the map;78 // The reference type of the map; 80 79 typedef typename Container::reference Reference; 81 // /The const reference type of the map;80 // The const reference type of the map; 82 81 typedef typename Container::const_reference ConstReference; 83 82 84 83 85 // /\brief Constructor to attach the new map into the notifier.86 // /87 // /It constructs a map and attachs it into the notifier.88 // /It adds all the items of the graph to the map.84 // \brief Constructor to attach the new map into the notifier. 85 // 86 // It constructs a map and attachs it into the notifier. 87 // It adds all the items of the graph to the map. 89 88 VectorMap(const Graph& graph) { 90 89 Parent::attach(graph.notifier(Item())); … … 92 91 } 93 92 94 // /\brief Constructor uses given value to initialize the map.95 // /96 // /It constructs a map uses a given value to initialize the map.97 // /It adds all the items of the graph to the map.93 // \brief Constructor uses given value to initialize the map. 94 // 95 // It constructs a map uses a given value to initialize the map. 96 // It adds all the items of the graph to the map. 98 97 VectorMap(const Graph& graph, const Value& value) { 99 98 Parent::attach(graph.notifier(Item())); … … 101 100 } 102 101 103 /// \brief Copy constructor 104 /// 105 /// Copy constructor. 102 private: 103 // \brief Copy constructor 104 // 105 // Copy constructor. 106 106 VectorMap(const VectorMap& _copy) : Parent() { 107 107 if (_copy.attached()) { … … 111 111 } 112 112 113 // /\brief Assign operator.114 // /115 // /This operator assigns for each item in the map the116 // /value mapped to the same item in the copied map.117 // /The parameter map should be indiced with the same118 // /itemset because this assign operator does not change119 // /the container of the map.113 // \brief Assign operator. 114 // 115 // This operator assigns for each item in the map the 116 // value mapped to the same item in the copied map. 117 // The parameter map should be indiced with the same 118 // itemset because this assign operator does not change 119 // the container of the map. 120 120 VectorMap& operator=(const VectorMap& cmap) { 121 121 return operator=<VectorMap>(cmap); … … 123 123 124 124 125 // /\brief Template assign operator.126 // /127 // /The given parameter should be conform to the ReadMap128 // /concecpt and could be indiced by the current item set of129 // /the NodeMap. In this case the value for each item130 // /is assigned by the value of the given ReadMap.125 // \brief Template assign operator. 126 // 127 // The given parameter should be conform to the ReadMap 128 // concecpt and could be indiced by the current item set of 129 // the NodeMap. In this case the value for each item 130 // is assigned by the value of the given ReadMap. 131 131 template <typename CMap> 132 132 VectorMap& operator=(const CMap& cmap) { … … 142 142 public: 143 143 144 // /\brief The subcript operator.145 // /146 // /The subscript operator. The map can be subscripted by the147 // /actual items of the graph.144 // \brief The subcript operator. 145 // 146 // The subscript operator. The map can be subscripted by the 147 // actual items of the graph. 148 148 Reference operator[](const Key& key) { 149 149 return container[Parent::notifier()->id(key)]; 150 150 } 151 151 152 // /\brief The const subcript operator.153 // /154 // /The const subscript operator. The map can be subscripted by the155 // /actual items of the graph.152 // \brief The const subcript operator. 153 // 154 // The const subscript operator. The map can be subscripted by the 155 // actual items of the graph. 156 156 ConstReference operator[](const Key& key) const { 157 157 return container[Parent::notifier()->id(key)]; … … 159 159 160 160 161 // /\brief The setter function of the map.162 // /163 // /It the same as operator[](key) = value expression.161 // \brief The setter function of the map. 162 // 163 // It the same as operator[](key) = value expression. 164 164 void set(const Key& key, const Value& value) { 165 165 (*this)[key] = value; … … 168 168 protected: 169 169 170 // /\brief Adds a new key to the map.171 // /172 // /It adds a new key to the map. It called by the observer notifier173 // /and it overrides the add() member function of the observer base.170 // \brief Adds a new key to the map. 171 // 172 // It adds a new key to the map. It called by the observer notifier 173 // and it overrides the add() member function of the observer base. 174 174 virtual void add(const Key& key) { 175 175 int id = Parent::notifier()->id(key); … … 179 179 } 180 180 181 // /\brief Adds more new keys to the map.182 // /183 // /It adds more new keys to the map. It called by the observer notifier184 // /and it overrides the add() member function of the observer base.181 // \brief Adds more new keys to the map. 182 // 183 // It adds more new keys to the map. It called by the observer notifier 184 // and it overrides the add() member function of the observer base. 185 185 virtual void add(const std::vector<Key>& keys) { 186 186 int max = container.size() - 1; … … 194 194 } 195 195 196 // /\brief Erase a key from the map.197 // /198 // /Erase a key from the map. It called by the observer notifier199 // /and it overrides the erase() member function of the observer base.196 // \brief Erase a key from the map. 197 // 198 // Erase a key from the map. It called by the observer notifier 199 // and it overrides the erase() member function of the observer base. 200 200 virtual void erase(const Key& key) { 201 201 container[Parent::notifier()->id(key)] = Value(); 202 202 } 203 203 204 // /\brief Erase more keys from the map.205 // /206 // /Erase more keys from the map. It called by the observer notifier207 // /and it overrides the erase() member function of the observer base.204 // \brief Erase more keys from the map. 205 // 206 // Erase more keys from the map. It called by the observer notifier 207 // and it overrides the erase() member function of the observer base. 208 208 virtual void erase(const std::vector<Key>& keys) { 209 209 for (int i = 0; i < int(keys.size()); ++i) { … … 212 212 } 213 213 214 // /\brief Buildes the map.215 // /216 // /It buildes the map. It called by the observer notifier217 // /and it overrides the build() member function of the observer base.214 // \brief Buildes the map. 215 // 216 // It buildes the map. It called by the observer notifier 217 // and it overrides the build() member function of the observer base. 218 218 virtual void build() { 219 219 int size = Parent::notifier()->maxId() + 1; … … 222 222 } 223 223 224 // /\brief Clear the map.225 // /226 // /It erase all items from the map. It called by the observer notifier227 // /and it overrides the clear() member function of the observer base.224 // \brief Clear the map. 225 // 226 // It erase all items from the map. It called by the observer notifier 227 // and it overrides the clear() member function of the observer base. 228 228 virtual void clear() { 229 229 container.clear(); -
lemon/color.h
r209 r317 93 93 extern const Color DARK_CYAN; 94 94 95 ///Map <tt>int</tt>s to different \ref Color "Color"s95 ///Map <tt>int</tt>s to different <tt>Color</tt>s 96 96 97 97 ///This map assigns one of the predefined \ref Color "Color"s to -
lemon/concept_check.h
r209 r285 17 17 */ 18 18 19 // This file contains a modified version of the concept checking 20 // utility from BOOST. 21 // See the appropriate copyright notice below. 22 23 // (C) Copyright Jeremy Siek 2000. 24 // Distributed under the Boost Software License, Version 1.0. (See 25 // accompanying file LICENSE_1_0.txt or copy at 26 // http://www.boost.org/LICENSE_1_0.txt) 27 // 28 // Revision History: 29 // 05 May 2001: Workarounds for HP aCC from Thomas Matelich. (Jeremy Siek) 30 // 02 April 2001: Removed limits header altogether. (Jeremy Siek) 31 // 01 April 2001: Modified to use new <boost/limits.hpp> header. (JMaddock) 32 // 33 34 // See http://www.boost.org/libs/concept_check for documentation. 19 // The contents of this file was inspired by the concept checking 20 // utility of the BOOST library (http://www.boost.org). 35 21 36 22 ///\file 37 23 ///\brief Basic utilities for concept checking. 38 24 /// 39 ///\todo Are we still using BOOST concept checking utility?40 ///Is the BOOST copyright notice necessary?41 25 42 26 #ifndef LEMON_CONCEPT_CHECK_H -
lemon/concepts/digraph.h
r220 r263 435 435 NodeMap(const Digraph&, T) { } 436 436 437 private: 437 438 ///Copy constructor 438 439 NodeMap(const NodeMap& nm) : ReadWriteMap< Node, T >(nm) { } … … 457 458 ///\e 458 459 ArcMap(const Digraph&, T) { } 460 private: 459 461 ///Copy constructor 460 462 ArcMap(const ArcMap& em) : ReadWriteMap<Arc,T>(em) { } -
lemon/concepts/graph.h
r220 r263 513 513 NodeMap(const Graph&, T) { } 514 514 515 private: 515 516 ///Copy constructor 516 517 NodeMap(const NodeMap& nm) : ReadWriteMap< Node, T >(nm) { } … … 536 537 ///\e 537 538 ArcMap(const Graph&, T) { } 539 private: 538 540 ///Copy constructor 539 541 ArcMap(const ArcMap& em) : ReadWriteMap<Arc,T>(em) { } … … 559 561 ///\e 560 562 EdgeMap(const Graph&, T) { } 563 private: 561 564 ///Copy constructor 562 565 EdgeMap(const EdgeMap& em) : ReadWriteMap<Edge,T>(em) {} -
lemon/concepts/graph_components.h
r220 r317 983 983 /// 984 984 /// This class describes the common interface of the graph maps 985 /// (NodeMap, ArcMap), that is \ref maps-page "maps" whichcan be used to985 /// (NodeMap, ArcMap), that is maps that can be used to 986 986 /// associate data to graph descriptors (nodes or arcs). 987 987 template <typename _Graph, typename _Item, typename _Value> … … 1006 1006 /// Construct a new map for the graph and initalise the values. 1007 1007 GraphMap(const Graph&, const Value&) {} 1008 1009 private: 1008 1010 /// \brief Copy constructor. 1009 1011 /// … … 1022 1024 } 1023 1025 1026 public: 1024 1027 template<typename _Map> 1025 1028 struct Constraints { … … 1031 1034 _Map a2(g,t); 1032 1035 // Copy constructor. 1033 _Map b(c); 1034 1035 ReadMap<Key, Value> cmap; 1036 b = cmap; 1037 1036 // _Map b(c); 1037 1038 // ReadMap<Key, Value> cmap; 1039 // b = cmap; 1040 1041 ignore_unused_variable_warning(a); 1038 1042 ignore_unused_variable_warning(a2); 1039 ignore_unused_variable_warning(b);1043 // ignore_unused_variable_warning(b); 1040 1044 } 1041 1045 … … 1083 1087 : Parent(digraph, value) {} 1084 1088 1089 private: 1085 1090 /// \brief Copy constructor. 1086 1091 /// … … 1120 1125 : Parent(digraph, value) {} 1121 1126 1127 private: 1122 1128 /// \brief Copy constructor. 1123 1129 /// … … 1216 1222 : Parent(graph, value) {} 1217 1223 1224 private: 1218 1225 /// \brief Copy constructor. 1219 1226 /// -
lemon/concepts/heap.h
r220 r290 130 130 /// Otherwise it inserts the given item with the given priority. 131 131 /// 132 /// It may throw an \ref UnderflowPriorityException.133 132 /// \param i The item. 134 133 /// \param p The priority. -
lemon/concepts/maps.h
r220 r318 23 23 #include <lemon/concept_check.h> 24 24 25 ///\ingroup concept25 ///\ingroup map_concepts 26 26 ///\file 27 27 ///\brief The concept of maps. … … 31 31 namespace concepts { 32 32 33 /// \addtogroup concept33 /// \addtogroup map_concepts 34 34 /// @{ 35 35 -
lemon/concepts/path.h
r220 r281 21 21 ///\brief Classes for representing paths in digraphs. 22 22 /// 23 ///\todo Iterators have obsolete style24 23 25 24 #ifndef LEMON_CONCEPT_PATH_H … … 67 66 /// \brief Template assigment 68 67 template <typename CPath> 69 Path& operator=(const CPath& cpath) {} 68 Path& operator=(const CPath& cpath) { 69 ignore_unused_variable_warning(cpath); 70 return *this; 71 } 70 72 71 73 /// Length of the path ie. the number of arcs in the path. … … 78 80 void clear() {} 79 81 80 /// \brief L emonstyle iterator for path arcs82 /// \brief LEMON style iterator for path arcs 81 83 /// 82 84 /// This class is used to iterate on the arcs of the paths. … … 201 203 /// If we would like to give back a real path from these 202 204 /// algorithms then we should create a temporarly path object. In 203 /// L emonsuch algorithms gives back a path dumper what can205 /// LEMON such algorithms gives back a path dumper what can 204 206 /// assigned to a real path and the dumpers can be implemented as 205 207 /// an adaptor class to the predecessor map. … … 233 235 typedef False RevPathTag; 234 236 235 /// \brief L emonstyle iterator for path arcs237 /// \brief LEMON style iterator for path arcs 236 238 /// 237 239 /// This class is used to iterate on the arcs of the paths. … … 260 262 }; 261 263 262 /// \brief L emonstyle iterator for path arcs264 /// \brief LEMON style iterator for path arcs 263 265 /// 264 266 /// This class is used to iterate on the arcs of the paths in -
lemon/core.h
r220 r327 25 25 #include <lemon/bits/enable_if.h> 26 26 #include <lemon/bits/traits.h> 27 #include <lemon/assert.h> 27 28 28 29 ///\file 29 30 ///\brief LEMON core utilities. 31 /// 32 ///This header file contains core utilities for LEMON. 33 ///It is automatically included by all graph types, therefore it usually 34 ///do not have to be included directly. 30 35 31 36 namespace lemon { … … 55 60 /// @{ 56 61 57 ///Create sconvenience typedefs for the digraph types and iterators58 59 ///This \c \#define creates convenien ce typedefs for the following types60 /// of \c Digraph: \c Node, \c NodeIt, \c Arc, \c ArcIt, \c InArcIt,62 ///Create convenience typedefs for the digraph types and iterators 63 64 ///This \c \#define creates convenient type definitions for the following 65 ///types of \c Digraph: \c Node, \c NodeIt, \c Arc, \c ArcIt, \c InArcIt, 61 66 ///\c OutArcIt, \c BoolNodeMap, \c IntNodeMap, \c DoubleNodeMap, 62 67 ///\c BoolArcMap, \c IntArcMap, \c DoubleArcMap. … … 79 84 typedef Digraph::ArcMap<double> DoubleArcMap 80 85 81 ///Create sconvenience typedefs for the digraph types and iterators86 ///Create convenience typedefs for the digraph types and iterators 82 87 83 88 ///\see DIGRAPH_TYPEDEFS … … 99 104 typedef typename Digraph::template ArcMap<double> DoubleArcMap 100 105 101 ///Create sconvenience typedefs for the graph types and iterators102 103 ///This \c \#define creates the same convenien ce typedefs as defined106 ///Create convenience typedefs for the graph types and iterators 107 108 ///This \c \#define creates the same convenient type definitions as defined 104 109 ///by \ref DIGRAPH_TYPEDEFS(Graph) and six more, namely it creates 105 110 ///\c Edge, \c EdgeIt, \c IncEdgeIt, \c BoolEdgeMap, \c IntEdgeMap, … … 107 112 /// 108 113 ///\note If the graph type is a dependent type, ie. the graph type depend 109 ///on a template parameter, then use \c TEMPLATE_ DIGRAPH_TYPEDEFS()114 ///on a template parameter, then use \c TEMPLATE_GRAPH_TYPEDEFS() 110 115 ///macro. 111 116 #define GRAPH_TYPEDEFS(Graph) \ … … 118 123 typedef Graph::EdgeMap<double> DoubleEdgeMap 119 124 120 ///Create sconvenience typedefs for the graph types and iterators125 ///Create convenience typedefs for the graph types and iterators 121 126 122 127 ///\see GRAPH_TYPEDEFS … … 133 138 typedef typename Graph::template EdgeMap<double> DoubleEdgeMap 134 139 135 /// \brief Function to count the items in thegraph.136 /// 137 /// This function counts the items (nodes, arcs etc ) in thegraph.138 /// The complexity of the function is O(n)because140 /// \brief Function to count the items in a graph. 141 /// 142 /// This function counts the items (nodes, arcs etc.) in a graph. 143 /// The complexity of the function is linear because 139 144 /// it iterates on all of the items. 140 145 template <typename Graph, typename Item> … … 173 178 /// 174 179 /// This function counts the nodes in the graph. 175 /// The complexity of the function is O(n)but for some176 /// graph structures it is specialized to run in O(1).177 /// 178 /// If the graph contains a \enodeNum() member function and a179 /// \ eNodeNumTag tag then this function calls directly the member180 /// The complexity of the function is <em>O</em>(<em>n</em>), but for some 181 /// graph structures it is specialized to run in <em>O</em>(1). 182 /// 183 /// \note If the graph contains a \c nodeNum() member function and a 184 /// \c NodeNumTag tag then this function calls directly the member 180 185 /// function to query the cardinality of the node set. 181 186 template <typename Graph> … … 209 214 /// 210 215 /// This function counts the arcs in the graph. 211 /// The complexity of the function is O(e)but for some212 /// graph structures it is specialized to run in O(1).213 /// 214 /// If the graph contains a \earcNum() member function and a215 /// \ e EdgeNumTag tag then this function calls directly the member216 /// The complexity of the function is <em>O</em>(<em>m</em>), but for some 217 /// graph structures it is specialized to run in <em>O</em>(1). 218 /// 219 /// \note If the graph contains a \c arcNum() member function and a 220 /// \c ArcNumTag tag then this function calls directly the member 216 221 /// function to query the cardinality of the arc set. 217 222 template <typename Graph> … … 221 226 222 227 // Edge counting: 228 223 229 namespace _core_bits { 224 230 … … 244 250 ///