Changes in / [244:c30731a37f91:247:f1158744a112] in lemon-main
- Files:
-
- 6 added
- 4 deleted
- 51 edited
Legend:
- Unmodified
- Added
- Removed
-
CMakeLists.txt
r141 r236 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 #EXECUTE_PROCESS( 4 # COMMAND hg id -i 5 # OUTPUT_VARIABLE HG_REVISION 6 # OUTPUT_STRIP_TRAILING_WHITESPACE) 7 8 SET(PROJECT_NAME "LEMON") 9 SET(PROJECT_VERSION_MAJOR "0") 10 SET(PROJECT_VERSION_MINOR "99") 11 SET(PROJECT_VERSION_PATCH "0") 12 SET(PROJECT_VERSION 13 "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}") 14 15 PROJECT(${PROJECT_NAME}) 16 17 SET(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) 18 19 INCLUDE(FindDoxygen) 20 INCLUDE(FindGhostscript) 21 22 ENABLE_TESTING() 23 24 ADD_SUBDIRECTORY(lemon) 25 ADD_SUBDIRECTORY(demo) 26 ADD_SUBDIRECTORY(doc) 27 ADD_SUBDIRECTORY(test) 28 29 IF(WIN32) 30 INSTALL(FILES ${CMAKE_SOURCE_DIR}/cmake/nsis/lemon.ico 31 DESTINATION bin) 32 ENDIF(WIN32) 33 34 IF(WIN32) 35 SET(CPACK_PACKAGE_NAME ${PROJECT_NAME}) 36 SET(CPACK_PACKAGE_VENDOR 37 "EGRES - Egervary Research Group on Combinatorial Optimization") 38 SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY 39 "LEMON - Library of Efficient Models and Optimization in Networks") 40 SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/LICENSE") 41 42 SET(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR}) 43 SET(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR}) 44 SET(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH}) 45 SET(CPACK_PACKAGE_VERSION ${PROJECT_VERSION}) 46 47 SET(CPACK_PACKAGE_INSTALL_DIRECTORY 48 "${PROJECT_NAME} ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}") 49 SET(CPACK_PACKAGE_INSTALL_REGISTRY_KEY 50 "${PROJECT_NAME} ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}") 51 52 # Variables to generate a component-based installer. 53 #SET(CPACK_COMPONENTS_ALL headers library html_documentation) 54 55 #SET(CPACK_COMPONENT_HEADERS_DISPLAY_NAME "C++ headers") 56 #SET(CPACK_COMPONENT_LIBRARY_DISPLAY_NAME "Static library") 57 #SET(CPACK_COMPONENT_HTML_DOCUMENTATION_DISPLAY_NAME "HTML documentation") 58 59 #SET(CPACK_COMPONENT_HEADERS_DESCRIPTION 60 # "C++ header files for use with the LEMON library") 61 #SET(CPACK_COMPONENT_LIBRARY_DESCRIPTION 62 # "Static library used to build programs with LEMON") 63 #SET(CPACK_COMPONENT_HTML_DOCUMENTATION_DESCRIPTION 64 # "Doxygen generated documentation") 65 66 #SET(CPACK_COMPONENT_HEADERS_DEPENDS library) 67 68 #SET(CPACK_COMPONENT_HEADERS_GROUP "Development") 69 #SET(CPACK_COMPONENT_LIBRARY_GROUP "Development") 70 #SET(CPACK_COMPONENT_HTML_DOCUMENTATION_GROUP "Documentation") 71 72 #SET(CPACK_COMPONENT_GROUP_DEVELOPMENT_DESCRIPTION 73 # "Components needed to develop software using LEMON") 74 #SET(CPACK_COMPONENT_GROUP_DOCUMENTATION_DESCRIPTION 75 # "Documentation of LEMON") 76 77 #SET(CPACK_ALL_INSTALL_TYPES Full Developer) 78 79 #SET(CPACK_COMPONENT_HEADERS_INSTALL_TYPES Developer Full) 80 #SET(CPACK_COMPONENT_LIBRARY_INSTALL_TYPES Developer Full) 81 #SET(CPACK_COMPONENT_HTML_DOCUMENTATION_INSTALL_TYPES Full) 82 83 SET(CPACK_GENERATOR "NSIS") 84 SET(CPACK_NSIS_MUI_ICON "${CMAKE_SOURCE_DIR}/cmake/nsis/lemon.ico") 85 SET(CPACK_NSIS_MUI_UNIICON "${CMAKE_SOURCE_DIR}/cmake/nsis/uninstall.ico") 86 #SET(CPACK_PACKAGE_ICON "${CMAKE_SOURCE_DIR}/cmake/nsis\\\\installer.bmp") 87 SET(CPACK_NSIS_INSTALLED_ICON_NAME "bin\\\\lemon.ico") 88 SET(CPACK_NSIS_DISPLAY_NAME "${CPACK_PACKAGE_INSTALL_DIRECTORY} ${PROJECT_NAME}") 89 SET(CPACK_NSIS_HELP_LINK "http:\\\\\\\\lemon.cs.elte.hu") 90 SET(CPACK_NSIS_URL_INFO_ABOUT "http:\\\\\\\\lemon.cs.elte.hu") 91 SET(CPACK_NSIS_CONTACT "lemon-user@lemon.cs.elte.hu") 92 SET(CPACK_NSIS_CREATE_ICONS_EXTRA " 93 CreateShortCut \\\"$SMPROGRAMS\\\\$STARTMENU_FOLDER\\\\Documentation.lnk\\\" \\\"$INSTDIR\\\\doc\\\\index.html\\\" 94 ") 95 SET(CPACK_NSIS_DELETE_ICONS_EXTRA " 96 !insertmacro MUI_STARTMENU_GETFOLDER Application $MUI_TEMP 97 Delete \\\"$SMPROGRAMS\\\\$MUI_TEMP\\\\Documentation.lnk\\\" 98 ") 99 100 INCLUDE(CPack) 101 ENDIF(WIN32) -
INSTALL
r5 r245 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, benchmark and demo 25 subdirectories 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 57 `./configure --help' 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 80 --enable-benchmark 66 81 67 Build the benchmark programs too.82 Build the programs in the benchmark subdirectory. 68 83 69 84 --disable-benchmark 70 85 71 Do not build the benchmark programs (default). 86 Do not build the programs in the benchmark subdirectory (default). 87 88 --enable-tools 89 90 Build the programs in the tools subdirectory (default). 91 92 --disable-tools 93 94 Do not build the programs in the tools subdirectory. 72 95 73 96 --with-glpk[=PREFIX] … … 116 139 117 140 Disable CPLEX support. 141 142 --with-soplex[=PREFIX] 143 144 Enable SoPlex support (default). You should specify the prefix too if 145 you installed SoPlex to some non-standard location (e.g. your home 146 directory). If it is not found, SoPlex support will be disabled. 147 148 --with-soplex-includedir=DIR 149 150 The directory where the SoPlex header files are located. This is only 151 useful when the SoPlex headers and libraries are not under the same 152 prefix (which is unlikely). 153 154 --with-soplex-libdir=DIR 155 156 The directory where the SoPlex libraries are located. This is only 157 useful when the SoPlex headers and libraries are not under the same 158 prefix (which is unlikely). 159 160 --without-soplex 161 162 Disable SoPlex support. -
Makefile.am
r146 r227 9 9 m4/lx_check_glpk.m4 \ 10 10 m4/lx_check_soplex.m4 \ 11 CMakeLists.txt 11 CMakeLists.txt \ 12 cmake 12 13 13 14 pkgconfigdir = $(libdir)/pkgconfig -
README
r24 r246 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 Contains programs to check the integrity and correctness of LEMON. 55 39 56 40 benchmark/ 57 41 58 Contains programs measuring the performance of LEMON. Use 59 --enable-benchmark configure option to also compile these codes (see 60 also INSTALL). 42 Contains programs for measuring the performance of algorithms. 43 44 tools/ 45 46 Various utilities related to LEMON. -
configure.ac
r175 r236 7 7 8 8 AC_PREREQ([2.59]) 9 AC_INIT([LEMON], [lemon_version()], [lemon- devel@lemon.cs.elte.hu], [lemon])9 AC_INIT([LEMON], [lemon_version()], [lemon-user@lemon.cs.elte.hu], [lemon]) 10 10 AC_CONFIG_AUX_DIR([build-aux]) 11 11 AC_CONFIG_MACRO_DIR([m4]) … … 26 26 AC_CHECK_PROG([gs_found],[gs],[yes],[no]) 27 27 28 dnl Set custom compiler flags when using g++. 28 29 if test x"$lx_cmdline_cxxflags_set" != x"set" -a "$GXX" = yes; then 29 30 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" … … 35 36 LX_CHECK_SOPLEX 36 37 37 dnl Disable/enable building the demo programs 38 dnl Disable/enable building the demo programs. 38 39 AC_ARG_ENABLE([demo], 39 40 AS_HELP_STRING([--enable-demo], [build the demo programs]) … … 48 49 AM_CONDITIONAL([WANT_DEMO], [test x"$enable_demo" != x"no"]) 49 50 50 dnl Disable/enable building the binary tools 51 dnl Disable/enable building the binary tools. 51 52 AC_ARG_ENABLE([tools], 52 53 AS_HELP_STRING([--enable-tools], [build additional tools @<:@default@:>@]) … … 61 62 AM_CONDITIONAL([WANT_TOOLS], [test x"$enable_tools" != x"no"]) 62 63 63 dnl Disable/enable building the benchmarks 64 dnl Disable/enable building the benchmarks. 64 65 AC_ARG_ENABLE([benchmark], 65 66 AS_HELP_STRING([--enable-benchmark], [build the benchmarks]) … … 87 88 AC_HEADER_STDC 88 89 AC_CHECK_FUNCS(gettimeofday times ctime_r) 90 91 dnl Add dependencies on files generated by configure. 92 AC_SUBST([CONFIG_STATUS_DEPENDENCIES], 93 ['$(top_srcdir)/doc/Doxyfile.in $(top_srcdir)/lemon/lemon.pc.in']) 89 94 90 95 AC_CONFIG_FILES([ -
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/graph_to_eps_demo.cc
r211 r220 32 32 33 33 #include<lemon/list_graph.h> 34 #include<lemon/graph_utils.h>35 34 #include<lemon/graph_to_eps.h> 36 35 #include<lemon/math.h> -
doc/Doxyfile.in
r212 r226 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 … … 81 81 # configuration options related to the input files 82 82 #--------------------------------------------------------------------------- 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.h83 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.h" 90 90 INPUT_ENCODING = UTF-8 91 91 FILE_PATTERNS = *.h \ … … 97 97 EXCLUDE_PATTERNS = 98 98 EXCLUDE_SYMBOLS = 99 EXAMPLE_PATH = @abs_top_srcdir@/demo\100 @abs_top_srcdir@/LICENSE\101 @abs_top_srcdir@/doc99 EXAMPLE_PATH = "@abs_top_srcdir@/demo" \ 100 "@abs_top_srcdir@/LICENSE" \ 101 "@abs_top_srcdir@/doc" 102 102 EXAMPLE_PATTERNS = 103 103 EXAMPLE_RECURSIVE = NO 104 IMAGE_PATH = @abs_top_srcdir@/doc/images\105 @abs_top_builddir@/doc/gen-images104 IMAGE_PATH = "@abs_top_srcdir@/doc/images" \ 105 "@abs_top_builddir@/doc/gen-images" 106 106 INPUT_FILTER = 107 107 FILTER_PATTERNS = … … 146 146 DISABLE_INDEX = NO 147 147 ENUM_VALUES_PER_LINE = 4 148 GENERATE_TREEVIEW = YES148 GENERATE_TREEVIEW = NO 149 149 TREEVIEW_WIDTH = 250 150 150 #--------------------------------------------------------------------------- -
doc/Makefile.am
r156 r227 8 8 doc/mainpage.dox \ 9 9 doc/namespaces.dox \ 10 doc/html 10 doc/html \ 11 doc/CMakeLists.txt 11 12 12 13 DOC_EPS_IMAGES18 = \ -
doc/groups.dox
r210 r236 326 326 maximum cardinality matching. 327 327 328 L emoncontains the next algorithms:328 LEMON contains the next algorithms: 329 329 - \ref lemon::MaxBipartiteMatching "MaxBipartiteMatching" Hopcroft-Karp 330 330 augmenting path algorithm for calculate maximum cardinality matching in … … 477 477 478 478 /** 479 @defgroup lemon_io L emonInput-Output479 @defgroup lemon_io LEMON Input-Output 480 480 @ingroup io_group 481 \brief Reading and writing \ref lgf-format "L emonGraph Format".481 \brief Reading and writing \ref lgf-format "LEMON Graph Format". 482 482 483 483 This group describes methods for reading and writing 484 \ref lgf-format "L emonGraph Format".484 \ref lgf-format "LEMON Graph Format". 485 485 */ 486 486 -
doc/lgf.dox
r212 r236 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> -
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
r195 r220 25 25 lemon/concept_check.h \ 26 26 lemon/counter.h \ 27 lemon/core.h \ 27 28 lemon/dfs.h \ 28 29 lemon/dijkstra.h \ … … 30 31 lemon/error.h \ 31 32 lemon/graph_to_eps.h \ 32 lemon/graph_utils.h \33 33 lemon/kruskal.h \ 34 34 lemon/lgf_reader.h \ … … 50 50 lemon/bits/bezier.h \ 51 51 lemon/bits/default_map.h \ 52 lemon/bits/enable_if.h \ 52 53 lemon/bits/graph_extender.h \ 53 lemon/bits/invalid.h \54 54 lemon/bits/map_extender.h \ 55 55 lemon/bits/path_dump.h \ 56 56 lemon/bits/traits.h \ 57 lemon/bits/utility.h \58 57 lemon/bits/vector_map.h 59 58 -
lemon/assert.h
r212 r218 238 238 239 239 # if LEMON_ENABLE_DEBUG 240 # define LEMON_DEBUG(exp, msg) 240 # define LEMON_DEBUG(exp, msg) \ 241 241 (static_cast<void> (!!(exp) ? 0 : ( \ 242 242 LEMON_ASSERT_HANDLER(__FILE__, __LINE__, \ -
lemon/base.cc
r209 r220 21 21 22 22 #include<lemon/tolerance.h> 23 #include<lemon/ bits/invalid.h>23 #include<lemon/core.h> 24 24 namespace lemon { 25 25 -
lemon/bfs.h
r244 r247 25 25 26 26 #include <lemon/list_graph.h> 27 #include <lemon/graph_utils.h>28 27 #include <lemon/bits/path_dump.h> 29 #include <lemon/ bits/invalid.h>28 #include <lemon/core.h> 30 29 #include <lemon/error.h> 31 30 #include <lemon/maps.h> -
lemon/bits/alteration_notifier.h
r209 r236 23 23 #include <list> 24 24 25 #include <lemon/ bits/utility.h>25 #include <lemon/core.h> 26 26 27 27 ///\ingroup graphbits … … 42 42 /// 43 43 /// The graph's node and edge sets can be changed as we add or erase 44 /// nodes and edges in the graph. L emonwould like to handle easily44 /// nodes and edges in the graph. LEMON would like to handle easily 45 45 /// that the node and edge maps should contain values for all nodes or 46 46 /// edges. If we want to check on every indicing if the map contains … … 410 410 ++it; 411 411 } catch (const ImmediateDetach&) { 412 it = _observers.erase(it);413 412 (*it)->_index = _observers.end(); 414 413 (*it)->_notifier = 0; 414 it = _observers.erase(it); 415 415 } 416 416 } … … 430 430 ++it; 431 431 } catch (const ImmediateDetach&) { 432 it = _observers.erase(it);433 432 (*it)->_index = _observers.end(); 434 433 (*it)->_notifier = 0; 434 it = _observers.erase(it); 435 435 } 436 436 } … … 469 469 ++it; 470 470 } catch (const ImmediateDetach&) { 471 it = _observers.erase(it);472 471 (*it)->_index = _observers.end(); 473 472 (*it)->_notifier = 0; 473 it = _observers.erase(it); 474 474 } 475 475 } -
lemon/bits/base_extender.h
r209 r220 20 20 #define LEMON_BITS_BASE_EXTENDER_H 21 21 22 #include <lemon/ bits/invalid.h>22 #include <lemon/core.h> 23 23 #include <lemon/error.h> 24 24 -
lemon/bits/graph_extender.h
r209 r220 20 20 #define LEMON_BITS_GRAPH_EXTENDER_H 21 21 22 #include <lemon/bits/invalid.h> 23 #include <lemon/bits/utility.h> 22 #include <lemon/core.h> 24 23 25 24 #include <lemon/bits/map_extender.h> -
lemon/bits/traits.h
r209 r220 20 20 #define LEMON_BITS_TRAITS_H 21 21 22 #include <lemon/bits/utility.h>23 24 22 ///\file 25 23 ///\brief Traits for graphs and maps 26 24 /// 27 25 26 #include <lemon/bits/enable_if.h> 27 28 28 namespace lemon { 29 30 struct InvalidType {}; 31 29 32 template <typename _Graph, typename _Item> 30 33 class ItemSetTraits {}; -
lemon/bits/vector_map.h
r209 r220 23 23 #include <algorithm> 24 24 25 #include <lemon/bits/traits.h> 26 #include <lemon/bits/utility.h> 27 25 #include <lemon/core.h> 28 26 #include <lemon/bits/alteration_notifier.h> 29 27 -
lemon/concepts/digraph.h
r209 r220 24 24 ///\brief The concept of directed graphs. 25 25 26 #include <lemon/bits/invalid.h> 27 #include <lemon/bits/utility.h> 26 #include <lemon/core.h> 28 27 #include <lemon/concepts/maps.h> 29 28 #include <lemon/concept_check.h> -
lemon/concepts/graph.h
r209 r220 26 26 #include <lemon/concepts/graph_components.h> 27 27 #include <lemon/concepts/graph.h> 28 #include <lemon/ bits/utility.h>28 #include <lemon/core.h> 29 29 30 30 namespace lemon { -
lemon/concepts/graph_components.h
r209 r220 25 25 #define LEMON_CONCEPT_GRAPH_COMPONENTS_H 26 26 27 #include <lemon/ bits/invalid.h>27 #include <lemon/core.h> 28 28 #include <lemon/concepts/maps.h> 29 29 -
lemon/concepts/heap.h
r209 r220 24 24 #define LEMON_CONCEPT_HEAP_H 25 25 26 #include <lemon/ bits/invalid.h>26 #include <lemon/core.h> 27 27 28 28 namespace lemon { -
lemon/concepts/maps.h
r210 r220 20 20 #define LEMON_CONCEPT_MAPS_H 21 21 22 #include <lemon/ bits/utility.h>22 #include <lemon/core.h> 23 23 #include <lemon/concept_check.h> 24 24 -
lemon/concepts/path.h
r212 r236 26 26 #define LEMON_CONCEPT_PATH_H 27 27 28 #include <lemon/bits/invalid.h> 29 #include <lemon/bits/utility.h> 28 #include <lemon/core.h> 30 29 #include <lemon/concept_check.h> 31 30 … … 79 78 void clear() {} 80 79 81 /// \brief L emonstyle iterator for path arcs80 /// \brief LEMON style iterator for path arcs 82 81 /// 83 82 /// This class is used to iterate on the arcs of the paths. … … 202 201 /// If we would like to give back a real path from these 203 202 /// algorithms then we should create a temporarly path object. In 204 /// L emonsuch algorithms gives back a path dumper what can203 /// LEMON such algorithms gives back a path dumper what can 205 204 /// assigned to a real path and the dumpers can be implemented as 206 205 /// an adaptor class to the predecessor map. … … 234 233 typedef False RevPathTag; 235 234 236 /// \brief L emonstyle iterator for path arcs235 /// \brief LEMON style iterator for path arcs 237 236 /// 238 237 /// This class is used to iterate on the arcs of the paths. … … 261 260 }; 262 261 263 /// \brief L emonstyle iterator for path arcs262 /// \brief LEMON style iterator for path arcs 264 263 /// 265 264 /// This class is used to iterate on the arcs of the paths in -
lemon/dfs.h
r244 r247 25 25 26 26 #include <lemon/list_graph.h> 27 #include <lemon/graph_utils.h>28 27 #include <lemon/bits/path_dump.h> 29 #include <lemon/ bits/invalid.h>28 #include <lemon/core.h> 30 29 #include <lemon/error.h> 31 30 #include <lemon/assert.h> -
lemon/dijkstra.h
r244 r247 28 28 #include <lemon/bin_heap.h> 29 29 #include <lemon/bits/path_dump.h> 30 #include <lemon/ bits/invalid.h>30 #include <lemon/core.h> 31 31 #include <lemon/error.h> 32 32 #include <lemon/maps.h> -
lemon/dim2.h
r209 r241 21 21 22 22 #include <iostream> 23 #include <lemon/bits/utility.h>24 23 25 24 ///\ingroup misc … … 46 45 /// @{ 47 46 48 /// A simple two dimensional vector (plain vector) implementation49 50 /// A simple two dimensional vector (plain vector) implementation47 /// A simple two dimensional vector (plain vector) implementation 48 49 /// A simple two dimensional vector (plain vector) implementation 51 50 /// with the usual vector operations. 52 51 template<typename T> … … 187 186 } 188 187 189 ///Read a plain vector from a stream190 191 ///Read a plain vector from a stream.188 ///Read a plain vector from a stream 189 190 ///Read a plain vector from a stream. 192 191 ///\relates Point 193 192 /// … … 215 214 } 216 215 217 ///Write a plain vector to a stream218 219 ///Write a plain vector to a stream.216 ///Write a plain vector to a stream 217 218 ///Write a plain vector to a stream. 220 219 ///\relates Point 221 220 /// … … 262 261 263 262 264 /// A class to calculate or store the bounding box of plainvectors.265 266 /// A class to calculate or store the bounding box of plainvectors.267 ///263 /// A class to calculate or store the bounding box of plain vectors. 264 265 /// A class to calculate or store the bounding box of plain vectors. 266 /// 268 267 template<typename T> 269 268 class BoundingBox { 270 Point<T> bottom_left,top_right;269 Point<T> _bottom_left, _top_right; 271 270 bool _empty; 272 271 public: … … 276 275 277 276 ///Construct an instance from one point 278 BoundingBox(Point<T> a) { bottom_left=top_right=a; _empty = false; } 277 BoundingBox(Point<T> a) { 278 _bottom_left = _top_right = a; 279 _empty = false; 280 } 279 281 280 282 ///Construct an instance from two points … … 287 289 BoundingBox(Point<T> a,Point<T> b) 288 290 { 289 bottom_left=a;290 top_right=b;291 _bottom_left = a; 292 _top_right = b; 291 293 _empty = false; 292 294 } … … 303 305 BoundingBox(T l,T b,T r,T t) 304 306 { 305 bottom_left=Point<T>(l,b);306 top_right=Point<T>(r,t);307 _bottom_left=Point<T>(l,b); 308 _top_right=Point<T>(r,t); 307 309 _empty = false; 308 310 } … … 321 323 ///Make the BoundingBox empty 322 324 void clear() { 323 _empty =1;325 _empty = true; 324 326 } 325 327 … … 329 331 ///If the bounding box is empty, then the return value is not defined. 330 332 Point<T> bottomLeft() const { 331 return bottom_left;333 return _bottom_left; 332 334 } 333 335 … … 335 337 336 338 ///Set the bottom left corner of the box. 337 /// It should only be used for non-empty box.339 ///\pre The box must not be empty. 338 340 void bottomLeft(Point<T> p) { 339 bottom_left = p;341 _bottom_left = p; 340 342 } 341 343 … … 345 347 ///If the bounding box is empty, then the return value is not defined. 346 348 Point<T> topRight() const { 347 return top_right;349 return _top_right; 348 350 } 349 351 … … 351 353 352 354 ///Set the top right corner of the box. 353 /// It should only be used for non-empty box.355 ///\pre The box must not be empty. 354 356 void topRight(Point<T> p) { 355 top_right = p;357 _top_right = p; 356 358 } 357 359 … … 361 363 ///If the bounding box is empty, then the return value is not defined. 362 364 Point<T> bottomRight() const { 363 return Point<T>( top_right.x,bottom_left.y);365 return Point<T>(_top_right.x,_bottom_left.y); 364 366 } 365 367 … … 367 369 368 370 ///Set the bottom right corner of the box. 369 /// It should only be used for non-empty box.371 ///\pre The box must not be empty. 370 372 void bottomRight(Point<T> p) { 371 top_right.x = p.x;372 bottom_left.y = p.y;373 _top_right.x = p.x; 374 _bottom_left.y = p.y; 373 375 } 374 376 … … 378 380 ///If the bounding box is empty, then the return value is not defined. 379 381 Point<T> topLeft() const { 380 return Point<T>( bottom_left.x,top_right.y);382 return Point<T>(_bottom_left.x,_top_right.y); 381 383 } 382 384 … … 384 386 385 387 ///Set the top left corner of the box. 386 /// It should only be used for non-empty box.388 ///\pre The box must not be empty. 387 389 void topLeft(Point<T> p) { 388 top_right.y = p.y;389 bottom_left.x = p.x;390 _top_right.y = p.y; 391 _bottom_left.x = p.x; 390 392 } 391 393 … … 395 397 ///If the bounding box is empty, then the return value is not defined. 396 398 T bottom() const { 397 return bottom_left.y;399 return _bottom_left.y; 398 400 } 399 401 … … 401 403 402 404 ///Set the bottom of the box. 403 /// It should only be used for non-empty box.405 ///\pre The box must not be empty. 404 406 void bottom(T t) { 405 bottom_left.y = t;407 _bottom_left.y = t; 406 408 } 407 409 … … 411 413 ///If the bounding box is empty, then the return value is not defined. 412 414 T top() const { 413 return top_right.y;415 return _top_right.y; 414 416 } 415 417 … … 417 419 418 420 ///Set the top of the box. 419 /// It should only be used for non-empty box.421 ///\pre The box must not be empty. 420 422 void top(T t) { 421 top_right.y = t;423 _top_right.y = t; 422 424 } 423 425 … … 427 429 ///If the bounding box is empty, then the return value is not defined. 428 430 T left() const { 429 return bottom_left.x;431 return _bottom_left.x; 430 432 } 431 433 … … 433 435 434 436 ///Set the left side of the box. 435 /// It should only be used for non-empty box.437 ///\pre The box must not be empty. 436 438 void left(T t) { 437 bottom_left.x = t;439 _bottom_left.x = t; 438 440 } 439 441 … … 443 445 ///If the bounding box is empty, then the return value is not defined. 444 446 T right() const { 445 return top_right.x;447 return _top_right.x; 446 448 } 447 449 … … 449 451 450 452 ///Set the right side of the box. 451 /// It should only be used for non-empty box.453 ///\pre The box must not be empty. 452 454 void right(T t) { 453 top_right.x = t;455 _top_right.x = t; 454 456 } 455 457 … … 459 461 ///If the bounding box is empty, then the return value is not defined. 460 462 T height() const { 461 return top_right.y-bottom_left.y;463 return _top_right.y-_bottom_left.y; 462 464 } 463 465 … … 467 469 ///If the bounding box is empty, then the return value is not defined. 468 470 T width() const { 469 return top_right.x-bottom_left.x;471 return _top_right.x-_bottom_left.x; 470 472 } 471 473 … … 474 476 if (_empty) 475 477 return false; 476 else {477 return ( (u.x-bottom_left.x)*(top_right.x-u.x) >= 0 &&478 (u.y-bottom_left.y)*(top_right.y-u.y) >= 0 );478 else { 479 return ( (u.x-_bottom_left.x)*(_top_right.x-u.x) >= 0 && 480 (u.y-_bottom_left.y)*(_top_right.y-u.y) >= 0 ); 479 481 } 480 482 } … … 485 487 /// 486 488 BoundingBox& add(const Point<T>& u){ 487 if (_empty) {488 bottom_left=top_right=u;489 if (_empty) { 490 _bottom_left = _top_right = u; 489 491 _empty = false; 490 492 } 491 else {492 if ( bottom_left.x > u.x)bottom_left.x = u.x;493 if ( bottom_left.y > u.y)bottom_left.y = u.y;494 if ( top_right.x < u.x)top_right.x = u.x;495 if ( top_right.y < u.y)top_right.y = u.y;493 else { 494 if (_bottom_left.x > u.x) _bottom_left.x = u.x; 495 if (_bottom_left.y > u.y) _bottom_left.y = u.y; 496 if (_top_right.x < u.x) _top_right.x = u.x; 497 if (_top_right.y < u.y) _top_right.y = u.y; 496 498 } 497 499 return *this; … … 504 506 BoundingBox& add(const BoundingBox &u){ 505 507 if ( !u.empty() ){ 506 this->add(u.bottomLeft());507 this->add(u.topRight());508 add(u._bottom_left); 509 add(u._top_right); 508 510 } 509 511 return *this; … … 516 518 BoundingBox operator&(const BoundingBox& u) const { 517 519 BoundingBox b; 518 if ( this->_empty || u._empty) {520 if (_empty || u._empty) { 519 521 b._empty = true; 520 522 } else { 521 b. bottom_left.x = std::max(this->bottom_left.x,u.bottom_left.x);522 b. bottom_left.y = std::max(this->bottom_left.y,u.bottom_left.y);523 b. top_right.x = std::min(this->top_right.x,u.top_right.x);524 b. top_right.y = std::min(this->top_right.y,u.top_right.y);525 b._empty = b. bottom_left.x > b.top_right.x ||526 b. bottom_left.y > b.top_right.y;523 b._bottom_left.x = std::max(_bottom_left.x, u._bottom_left.x); 524 b._bottom_left.y = std::max(_bottom_left.y, u._bottom_left.y); 525 b._top_right.x = std::min(_top_right.x, u._top_right.x); 526 b._top_right.y = std::min(_top_right.y, u._top_right.y); 527 b._empty = b._bottom_left.x > b._top_right.x || 528 b._bottom_left.y > b._top_right.y; 527 529 } 528 530 return b; -
lemon/graph_to_eps.h
r212 r220 36 36 37 37 #include<lemon/math.h> 38 #include<lemon/ bits/invalid.h>38 #include<lemon/core.h> 39 39 #include<lemon/dim2.h> 40 40 #include<lemon/maps.h> -
lemon/kruskal.h
r216 r220 23 23 #include <vector> 24 24 #include <lemon/unionfind.h> 25 // #include <lemon/graph_utils.h>26 25 #include <lemon/maps.h> 27 26 28 // #include <lemon/radix_sort.h> 29 30 #include <lemon/bits/utility.h> 27 #include <lemon/core.h> 31 28 #include <lemon/bits/traits.h> 32 29 … … 301 298 /// \return The total cost of the found spanning tree. 302 299 /// 303 /// \note If the input graph is not (weakly) connected, a spanning 300 /// \note If the input graph is not (weakly) connected, a spanning 304 301 /// forest is calculated instead of a spanning tree. 305 302 -
lemon/lgf_reader.h
r212 r236 19 19 ///\ingroup lemon_io 20 20 ///\file 21 ///\brief \ref lgf-format "L emonGraph Format" reader.21 ///\brief \ref lgf-format "LEMON Graph Format" reader. 22 22 23 23 … … 33 33 34 34 #include <lemon/assert.h> 35 #include <lemon/ graph_utils.h>35 #include <lemon/core.h> 36 36 37 37 #include <lemon/lgf_writer.h> … … 2302 2302 /// 2303 2303 /// This class can be used to read the sections, the map names and 2304 /// the attributes from a file. Usually, the L emonprograms know2304 /// the attributes from a file. Usually, the LEMON programs know 2305 2305 /// that, which type of graph, which maps and which attributes 2306 2306 /// should be read from a file, but in general tools (like glemon) -
lemon/lgf_writer.h
r212 r240 19 19 ///\ingroup lemon_io 20 20 ///\file 21 ///\brief \ref lgf-format "L emonGraph Format" writer.21 ///\brief \ref lgf-format "LEMON Graph Format" writer. 22 22 23 23 … … 35 35 36 36 #include <lemon/assert.h> 37 #include <lemon/graph_utils.h> 37 #include <lemon/core.h> 38 #include <lemon/maps.h> 38 39 39 40 namespace lemon { … … 934 935 bool local_os; 935 936 936 Graph& _graph;937 const Graph& _graph; 937 938 938 939 std::string _nodes_caption; -
lemon/list_graph.h
r212 r239 24 24 ///\brief ListDigraph, ListGraph classes. 25 25 26 #include <lemon/core.h> 27 #include <lemon/error.h> 26 28 #include <lemon/bits/graph_extender.h> 27 29 … … 362 364 } 363 365 366 ///\brief Erase a node from the digraph. 367 /// 368 ///Erase a node from the digraph. 369 /// 370 void erase(const Node& n) { Parent::erase(n); } 371 372 ///\brief Erase an arc from the digraph. 373 /// 374 ///Erase an arc from the digraph. 375 /// 376 void erase(const Arc& a) { Parent::erase(a); } 377 364 378 /// Node validity check 365 379 … … 382 396 bool valid(Arc a) const { return Parent::valid(a); } 383 397 384 /// Change the target of \c eto \c n385 386 /// Change the target of \c eto \c n398 /// Change the target of \c a to \c n 399 400 /// Change the target of \c a to \c n 387 401 /// 388 402 ///\note The <tt>ArcIt</tt>s and <tt>OutArcIt</tt>s referencing … … 392 406 ///\warning This functionality cannot be used together with the Snapshot 393 407 ///feature. 394 void changeTarget(Arc e, Node n) {395 Parent::changeTarget( e,n);396 } 397 /// Change the source of \c eto \c n398 399 /// Change the source of \c eto \c n400 /// 401 ///\note The <tt> ArcIt</tt>s and <tt>InArcIt</tt>s referencing402 /// the changed arc remain valid. However<tt>OutArcIt</tt>s are408 void changeTarget(Arc a, Node n) { 409 Parent::changeTarget(a,n); 410 } 411 /// Change the source of \c a to \c n 412 413 /// Change the source of \c a to \c n 414 /// 415 ///\note The <tt>InArcIt</tt>s referencing the changed arc remain 416 ///valid. However the <tt>ArcIt<tt>s and <tt>OutArcIt</tt>s are 403 417 ///invalidated. 404 418 /// 405 419 ///\warning This functionality cannot be used together with the Snapshot 406 420 ///feature. 407 void changeSource(Arc e, Node n) {408 Parent::changeSource( e,n);421 void changeSource(Arc a, Node n) { 422 Parent::changeSource(a,n); 409 423 } 410 424 … … 829 843 830 844 public: 831 operator Edge() const { return edgeFromId(id / 2); } 845 operator Edge() const { 846 return id != -1 ? edgeFromId(id / 2) : INVALID; 847 } 832 848 833 849 Arc() {} … … 1101 1117 protected: 1102 1118 1103 void change Target(Edge e, Node n) {1119 void changeV(Edge e, Node n) { 1104 1120 if(arcs[2 * e.id].next_out != -1) { 1105 1121 arcs[arcs[2 * e.id].next_out].prev_out = arcs[2 * e.id].prev_out; … … 1122 1138 } 1123 1139 1124 void change Source(Edge e, Node n) {1140 void changeU(Edge e, Node n) { 1125 1141 if(arcs[(2 * e.id) | 1].next_out != -1) { 1126 1142 arcs[arcs[(2 * e.id) | 1].next_out].prev_out = … … 1206 1222 return Parent::addEdge(s, t); 1207 1223 } 1224 1225 /// \brief Erase a node from the graph. 1226 /// 1227 /// Erase a node from the graph. 1228 /// 1229 void erase(const Node& n) { Parent::erase(n); } 1230 1231 /// \brief Erase an edge from the graph. 1232 /// 1233 /// Erase an edge from the graph. 1234 /// 1235 void erase(const Edge& e) { Parent::erase(e); } 1208 1236 /// Node validity check 1209 1237 … … 1233 1261 /// added to the graph. 1234 1262 bool valid(Edge e) const { return Parent::valid(e); } 1235 /// \brief Change the source of \c e to \c n 1236 /// 1237 /// This function changes the source of \c e to \c n. 1238 /// 1239 ///\note The <tt>ArcIt</tt>s and <tt>InArcIt</tt>s 1240 ///referencing the changed arc remain 1241 ///valid. However <tt>OutArcIt</tt>s are invalidated. 1263 /// \brief Change the end \c u of \c e to \c n 1264 /// 1265 /// This function changes the end \c u of \c e to node \c n. 1266 /// 1267 ///\note The <tt>EdgeIt</tt>s and <tt>ArcIt</tt>s referencing the 1268 ///changed edge are invalidated and if the changed node is the 1269 ///base node of an iterator then this iterator is also 1270 ///invalidated. 1242 1271 /// 1243 1272 ///\warning This functionality cannot be used together with the 1244 1273 ///Snapshot feature. 1245 void changeSource(Edge e, Node n) { 1246 Parent::changeSource(e,n); 1247 } 1248 /// \brief Change the target of \c e to \c n 1249 /// 1250 /// This function changes the target of \c e to \c n. 1251 /// 1252 /// \note The <tt>ArcIt</tt>s referencing the changed arc remain 1253 /// valid. However the other iterators may be invalidated. 1274 void changeU(Edge e, Node n) { 1275 Parent::changeU(e,n); 1276 } 1277 /// \brief Change the end \c v of \c e to \c n 1278 /// 1279 /// This function changes the end \c v of \c e to \c n. 1280 /// 1281 ///\note The <tt>EdgeIt</tt>s referencing the changed edge remain 1282 ///valid, however <tt>ArcIt</tt>s and if the changed node is the 1283 ///base node of an iterator then this iterator is invalidated. 1254 1284 /// 1255 1285 ///\warning This functionality cannot be used together with the 1256 1286 ///Snapshot feature. 1257 void changeTarget(Edge e, Node n) { 1258 Parent::changeTarget(e,n); 1259 } 1260 /// \brief Change the source of \c e to \c n 1261 /// 1262 /// This function changes the source of \c e to \c n. 1263 /// It also changes the proper node of the represented edge. 1264 /// 1265 ///\note The <tt>ArcIt</tt>s and <tt>InArcIt</tt>s 1266 ///referencing the changed arc remain 1267 ///valid. However <tt>OutArcIt</tt>s are invalidated. 1268 /// 1269 ///\warning This functionality cannot be used together with the 1270 ///Snapshot feature. 1271 void changeSource(Arc e, Node n) { 1272 if (Parent::direction(e)) { 1273 Parent::changeSource(e,n); 1274 } else { 1275 Parent::changeTarget(e,n); 1276 } 1277 } 1278 /// \brief Change the target of \c e to \c n 1279 /// 1280 /// This function changes the target of \c e to \c n. 1281 /// It also changes the proper node of the represented edge. 1282 /// 1283 ///\note The <tt>ArcIt</tt>s and <tt>OutArcIt</tt>s 1284 ///referencing the changed arc remain 1285 ///valid. However <tt>InArcIt</tt>s are invalidated. 1286 /// 1287 ///\warning This functionality cannot be used together with the 1288 ///Snapshot feature. 1289 void changeTarget(Arc e, Node n) { 1290 if (Parent::direction(e)) { 1291 Parent::changeTarget(e,n); 1292 } else { 1293 Parent::changeSource(e,n); 1294 } 1287 void changeV(Edge e, Node n) { 1288 Parent::changeV(e,n); 1295 1289 } 1296 1290 /// \brief Contract two nodes. … … 1312 1306 if (r && runningNode(e) == a) { 1313 1307 erase(e); 1314 } else if ( source(e) == b) {1315 change Source(e, a);1308 } else if (u(e) == b) { 1309 changeU(e, a); 1316 1310 } else { 1317 change Target(e, a);1311 changeV(e, a); 1318 1312 } 1319 1313 e = f; -
lemon/maps.h
r209 r220 24 24 #include <vector> 25 25 26 #include <lemon/bits/utility.h> 27 #include <lemon/bits/traits.h> 26 #include <lemon/core.h> 28 27 29 28 ///\file … … 1781 1780 } 1782 1781 1782 /// Provides an immutable and unique id for each item in the graph. 1783 1784 /// The IdMap class provides a unique and immutable id for each item of the 1785 /// same type (e.g. node) in the graph. This id is <ul><li>\b unique: 1786 /// different items (nodes) get different ids <li>\b immutable: the id of an 1787 /// item (node) does not change (even if you delete other nodes). </ul> 1788 /// Through this map you get access (i.e. can read) the inner id values of 1789 /// the items stored in the graph. This map can be inverted with its member 1790 /// class \c InverseMap or with the \c operator() member. 1791 /// 1792 template <typename _Graph, typename _Item> 1793 class IdMap { 1794 public: 1795 typedef _Graph Graph; 1796 typedef int Value; 1797 typedef _Item Item; 1798 typedef _Item Key; 1799 1800 /// \brief Constructor. 1801 /// 1802 /// Constructor of the map. 1803 explicit IdMap(const Graph& graph) : _graph(&graph) {} 1804 1805 /// \brief Gives back the \e id of the item. 1806 /// 1807 /// Gives back the immutable and unique \e id of the item. 1808 int operator[](const Item& item) const { return _graph->id(item);} 1809 1810 /// \brief Gives back the item by its id. 1811 /// 1812 /// Gives back the item by its id. 1813 Item operator()(int id) { return _graph->fromId(id, Item()); } 1814 1815 private: 1816 const Graph* _graph; 1817 1818 public: 1819 1820 /// \brief The class represents the inverse of its owner (IdMap). 1821 /// 1822 /// The class represents the inverse of its owner (IdMap). 1823 /// \see inverse() 1824 class InverseMap { 1825 public: 1826 1827 /// \brief Constructor. 1828 /// 1829 /// Constructor for creating an id-to-item map. 1830 explicit InverseMap(const Graph& graph) : _graph(&graph) {} 1831 1832 /// \brief Constructor. 1833 /// 1834 /// Constructor for creating an id-to-item map. 1835 explicit InverseMap(const IdMap& map) : _graph(map._graph) {} 1836 1837 /// \brief Gives back the given item from its id. 1838 /// 1839 /// Gives back the given item from its id. 1840 /// 1841 Item operator[](int id) const { return _graph->fromId(id, Item());} 1842 1843 private: 1844 const Graph* _graph; 1845 }; 1846 1847 /// \brief Gives back the inverse of the map. 1848 /// 1849 /// Gives back the inverse of the IdMap. 1850 InverseMap inverse() const { return InverseMap(*_graph);} 1851 1852 }; 1853 1854 1855 /// \brief General invertable graph-map type. 1856 1857 /// This type provides simple invertable graph-maps. 1858 /// The InvertableMap wraps an arbitrary ReadWriteMap 1859 /// and if a key is set to a new value then store it 1860 /// in the inverse map. 1861 /// 1862 /// The values of the map can be accessed 1863 /// with stl compatible forward iterator. 1864 /// 1865 /// \tparam _Graph The graph type. 1866 /// \tparam _Item The item type of the graph. 1867 /// \tparam _Value The value type of the map. 1868 /// 1869 /// \see IterableValueMap 1870 template <typename _Graph, typename _Item, typename _Value> 1871 class InvertableMap 1872 : protected ItemSetTraits<_Graph, _Item>::template Map<_Value>::Type { 1873 private: 1874 1875 typedef typename ItemSetTraits<_Graph, _Item>:: 1876 template Map<_Value>::Type Map; 1877 typedef _Graph Graph; 1878 1879 typedef std::map<_Value, _Item> Container; 1880 Container _inv_map; 1881 1882 public: 1883 1884 /// The key type of InvertableMap (Node, Arc, Edge). 1885 typedef typename Map::Key Key; 1886 /// The value type of the InvertableMap. 1887 typedef typename Map::Value Value; 1888 1889 1890 1891 /// \brief Constructor. 1892 /// 1893 /// Construct a new InvertableMap for the graph. 1894 /// 1895 explicit InvertableMap(const Graph& graph) : Map(graph) {} 1896 1897 /// \brief Forward iterator for values. 1898 /// 1899 /// This iterator is an stl compatible forward 1900 /// iterator on the values of the map. The values can 1901 /// be accessed in the [beginValue, endValue) range. 1902 /// 1903 class ValueIterator 1904 : public std::iterator<std::forward_iterator_tag, Value> { 1905 friend class InvertableMap; 1906 private: 1907 ValueIterator(typename Container::const_iterator _it) 1908 : it(_it) {} 1909 public: 1910 1911 ValueIterator() {} 1912 1913 ValueIterator& operator++() { ++it; return *this; } 1914 ValueIterator operator++(int) { 1915 ValueIterator tmp(*this); 1916 operator++(); 1917 return tmp; 1918 } 1919 1920 const Value& operator*() const { return it->first; } 1921 const Value* operator->() const { return &(it->first); } 1922 1923 bool operator==(ValueIterator jt) const { return it == jt.it; } 1924 bool operator!=(ValueIterator jt) const { return it != jt.it; } 1925 1926 private: 1927 typename Container::const_iterator it; 1928 }; 1929 1930 /// \brief Returns an iterator to the first value. 1931 /// 1932 /// Returns an stl compatible iterator to the 1933 /// first value of the map. The values of the 1934 /// map can be accessed in the [beginValue, endValue) 1935 /// range. 1936 ValueIterator beginValue() const { 1937 return ValueIterator(_inv_map.begin()); 1938 } 1939 1940 /// \brief Returns an iterator after the last value. 1941 /// 1942 /// Returns an stl compatible iterator after the 1943 /// last value of the map. The values of the 1944 /// map can be accessed in the [beginValue, endValue) 1945 /// range. 1946 ValueIterator endValue() const { 1947 return ValueIterator(_inv_map.end()); 1948 } 1949 1950 /// \brief The setter function of the map. 1951 /// 1952 /// Sets the mapped value. 1953 void set(const Key& key, const Value& val) { 1954 Value oldval = Map::operator[](key); 1955 typename Container::iterator it = _inv_map.find(oldval); 1956 if (it != _inv_map.end() && it->second == key) { 1957 _inv_map.erase(it); 1958 } 1959 _inv_map.insert(make_pair(val, key)); 1960 Map::set(key, val); 1961 } 1962 1963 /// \brief The getter function of the map. 1964 /// 1965 /// It gives back the value associated with the key. 1966 typename MapTraits<Map>::ConstReturnValue 1967 operator[](const Key& key) const { 1968 return Map::operator[](key); 1969 } 1970 1971 /// \brief Gives back the item by its value. 1972 /// 1973 /// Gives back the item by its value. 1974 Key operator()(const Value& key) const { 1975 typename Container::const_iterator it = _inv_map.find(key); 1976 return it != _inv_map.end() ? it->second : INVALID; 1977 } 1978 1979 protected: 1980 1981 /// \brief Erase the key from the map. 1982 /// 1983 /// Erase the key to the map. It is called by the 1984 /// \c AlterationNotifier. 1985 virtual void erase(const Key& key) { 1986 Value val = Map::operator[](key); 1987 typename Container::iterator it = _inv_map.find(val); 1988 if (it != _inv_map.end() && it->second == key) { 1989 _inv_map.erase(it); 1990 } 1991 Map::erase(key); 1992 } 1993 1994 /// \brief Erase more keys from the map. 1995 /// 1996 /// Erase more keys from the map. It is called by the 1997 /// \c AlterationNotifier. 1998 virtual void erase(const std::vector<Key>& keys) { 1999 for (int i = 0; i < int(keys.size()); ++i) { 2000 Value val = Map::operator[](keys[i]); 2001 typename Container::iterator it = _inv_map.find(val); 2002 if (it != _inv_map.end() && it->second == keys[i]) { 2003 _inv_map.erase(it); 2004 } 2005 } 2006 Map::erase(keys); 2007 } 2008 2009 /// \brief Clear the keys from the map and inverse map. 2010 /// 2011 /// Clear the keys from the map and inverse map. It is called by the 2012 /// \c AlterationNotifier. 2013 virtual void clear() { 2014 _inv_map.clear(); 2015 Map::clear(); 2016 } 2017 2018 public: 2019 2020 /// \brief The inverse map type. 2021 /// 2022 /// The inverse of this map. The subscript operator of the map 2023 /// gives back always the item what was last assigned to the value. 2024 class InverseMap { 2025 public: 2026 /// \brief Constructor of the InverseMap. 2027 /// 2028 /// Constructor of the InverseMap. 2029 explicit InverseMap(const InvertableMap& inverted) 2030 : _inverted(inverted) {} 2031 2032 /// The value type of the InverseMap. 2033 typedef typename InvertableMap::Key Value; 2034 /// The key type of the InverseMap. 2035 typedef typename InvertableMap::Value Key; 2036 2037 /// \brief Subscript operator. 2038 /// 2039 /// Subscript operator. It gives back always the item 2040 /// what was last assigned to the value. 2041 Value operator[](const Key& key) const { 2042 return _inverted(key); 2043 } 2044 2045 private: 2046 const InvertableMap& _inverted; 2047 }; 2048 2049 /// \brief It gives back the just readable inverse map. 2050 /// 2051 /// It gives back the just readable inverse map. 2052 InverseMap inverse() const { 2053 return InverseMap(*this); 2054 } 2055 2056 2057 2058 }; 2059 2060 /// \brief Provides a mutable, continuous and unique descriptor for each 2061 /// item in the graph. 2062 /// 2063 /// The DescriptorMap class provides a unique and continuous (but mutable) 2064 /// descriptor (id) for each item of the same type (e.g. node) in the 2065 /// graph. This id is <ul><li>\b unique: different items (nodes) get 2066 /// different ids <li>\b continuous: the range of the ids is the set of 2067 /// integers between 0 and \c n-1, where \c n is the number of the items of 2068 /// this type (e.g. nodes) (so the id of a node can change if you delete an 2069 /// other node, i.e. this id is mutable). </ul> This map can be inverted 2070 /// with its member class \c InverseMap, or with the \c operator() member. 2071 /// 2072 /// \tparam _Graph The graph class the \c DescriptorMap belongs to. 2073 /// \tparam _Item The Item is the Key of the Map. It may be Node, Arc or 2074 /// Edge. 2075 template <typename _Graph, typename _Item> 2076 class DescriptorMap 2077 : protected ItemSetTraits<_Graph, _Item>::template Map<int>::Type { 2078 2079 typedef _Item Item; 2080 typedef typename ItemSetTraits<_Graph, _Item>::template Map<int>::Type Map; 2081 2082 public: 2083 /// The graph class of DescriptorMap. 2084 typedef _Graph Graph; 2085 2086 /// The key type of DescriptorMap (Node, Arc, Edge). 2087 typedef typename Map::Key Key; 2088 /// The value type of DescriptorMap. 2089 typedef typename Map::Value Value; 2090 2091 /// \brief Constructor. 2092 /// 2093 /// Constructor for descriptor map. 2094 explicit DescriptorMap(const Graph& _graph) : Map(_graph) { 2095 Item it; 2096 const typename Map::Notifier* nf = Map::notifier(); 2097 for (nf->first(it); it != INVALID; nf->next(it)) { 2098 Map::set(it, _inv_map.size()); 2099 _inv_map.push_back(it); 2100 } 2101 } 2102 2103 protected: 2104 2105 /// \brief Add a new key to the map. 2106 /// 2107 /// Add a new key to the map. It is called by the 2108 /// \c AlterationNotifier. 2109 virtual void add(const Item& item) { 2110 Map::add(item); 2111 Map::set(item, _inv_map.size()); 2112 _inv_map.push_back(item); 2113 } 2114 2115 /// \brief Add more new keys to the map. 2116 /// 2117 /// Add more new keys to the map. It is called by the 2118 /// \c AlterationNotifier. 2119 virtual void add(const std::vector<Item>& items) { 2120 Map::add(items); 2121 for (int i = 0; i < int(items.size()); ++i) { 2122 Map::set(items[i], _inv_map.size()); 2123 _inv_map.push_back(items[i]); 2124 } 2125 } 2126 2127 /// \brief Erase the key from the map. 2128 /// 2129 /// Erase the key from the map. It is called by the 2130 /// \c AlterationNotifier. 2131 virtual void erase(const Item& item) { 2132 Map::set(_inv_map.back(), Map::operator[](item)); 2133 _inv_map[Map::operator[](item)] = _inv_map.back(); 2134 _inv_map.pop_back(); 2135 Map::erase(item); 2136 } 2137 2138 /// \brief Erase more keys from the map. 2139 /// 2140 /// Erase more keys from the map. It is called by the 2141 /// \c AlterationNotifier. 2142 virtual void erase(const std::vector<Item>& items) { 2143 for (int i = 0; i < int(items.size()); ++i) { 2144 Map::set(_inv_map.back(), Map::operator[](items[i])); 2145 _inv_map[Map::operator[](items[i])] = _inv_map.back(); 2146 _inv_map.pop_back(); 2147 } 2148 Map::erase(items); 2149 } 2150 2151 /// \brief Build the unique map. 2152 /// 2153 /// Build the unique map. It is called by the 2154 /// \c AlterationNotifier. 2155 virtual void build() { 2156 Map::build(); 2157 Item it; 2158 const typename Map::Notifier* nf = Map::notifier(); 2159 for (nf->first(it); it != INVALID; nf->next(it)) { 2160 Map::set(it, _inv_map.size()); 2161 _inv_map.push_back(it); 2162 } 2163 } 2164 2165 /// \brief Clear the keys from the map. 2166 /// 2167 /// Clear the keys from the map. It is called by the 2168 /// \c AlterationNotifier. 2169 virtual void clear() { 2170 _inv_map.clear(); 2171 Map::clear(); 2172 } 2173 2174 public: 2175 2176 /// \brief Returns the maximal value plus one. 2177 /// 2178 /// Returns the maximal value plus one in the map. 2179 unsigned int size() const { 2180 return _inv_map.size(); 2181 } 2182 2183 /// \brief Swaps the position of the two items in the map. 2184 /// 2185 /// Swaps the position of the two items in the map. 2186 void swap(const Item& p, const Item& q) { 2187 int pi = Map::operator[](p); 2188 int qi = Map::operator[](q); 2189 Map::set(p, qi); 2190 _inv_map[qi] = p; 2191 Map::set(q, pi); 2192 _inv_map[pi] = q; 2193 } 2194 2195 /// \brief Gives back the \e descriptor of the item. 2196 /// 2197 /// Gives back the mutable and unique \e descriptor of the map. 2198 int operator[](const Item& item) const { 2199 return Map::operator[](item); 2200 } 2201 2202 /// \brief Gives back the item by its descriptor. 2203 /// 2204 /// Gives back th item by its descriptor. 2205 Item operator()(int id) const { 2206 return _inv_map[id]; 2207 } 2208 2209 private: 2210 2211 typedef std::vector<Item> Container; 2212 Container _inv_map; 2213 2214 public: 2215 /// \brief The inverse map type of DescriptorMap. 2216 /// 2217 /// The inverse map type of DescriptorMap. 2218 class InverseMap { 2219 public: 2220 /// \brief Constructor of the InverseMap. 2221 /// 2222 /// Constructor of the InverseMap. 2223 explicit InverseMap(const DescriptorMap& inverted) 2224 : _inverted(inverted) {} 2225 2226 2227 /// The value type of the InverseMap. 2228 typedef typename DescriptorMap::Key Value; 2229 /// The key type of the InverseMap. 2230 typedef typename DescriptorMap::Value Key; 2231 2232 /// \brief Subscript operator. 2233 /// 2234 /// Subscript operator. It gives back the item 2235 /// that the descriptor belongs to currently. 2236 Value operator[](const Key& key) const { 2237 return _inverted(key); 2238 } 2239 2240 /// \brief Size of the map. 2241 /// 2242 /// Returns the size of the map. 2243 unsigned int size() const { 2244 return _inverted.size(); 2245 } 2246 2247 private: 2248 const DescriptorMap& _inverted; 2249 }; 2250 2251 /// \brief Gives back the inverse of the map. 2252 /// 2253 /// Gives back the inverse of the map. 2254 const InverseMap inverse() const { 2255 return InverseMap(*this); 2256 } 2257 }; 2258 2259 /// \brief Returns the source of the given arc. 2260 /// 2261 /// The SourceMap gives back the source Node of the given arc. 2262 /// \see TargetMap 2263 template <typename Digraph> 2264 class SourceMap { 2265 public: 2266 2267 typedef typename Digraph::Node Value; 2268 typedef typename Digraph::Arc Key; 2269 2270 /// \brief Constructor 2271 /// 2272 /// Constructor 2273 /// \param _digraph The digraph that the map belongs to. 2274 explicit SourceMap(const Digraph& digraph) : _digraph(digraph) {} 2275 2276 /// \brief The subscript operator. 2277 /// 2278 /// The subscript operator. 2279 /// \param arc The arc 2280 /// \return The source of the arc 2281 Value operator[](const Key& arc) const { 2282 return _digraph.source(arc); 2283 } 2284 2285 private: 2286 const Digraph& _digraph; 2287 }; 2288 2289 /// \brief Returns a \ref SourceMap class. 2290 /// 2291 /// This function just returns an \ref SourceMap class. 2292 /// \relates SourceMap 2293 template <typename Digraph> 2294 inline SourceMap<Digraph> sourceMap(const Digraph& digraph) { 2295 return SourceMap<Digraph>(digraph); 2296 } 2297 2298 /// \brief Returns the target of the given arc. 2299 /// 2300 /// The TargetMap gives back the target Node of the given arc. 2301 /// \see SourceMap 2302 template <typename Digraph> 2303 class TargetMap { 2304 public: 2305 2306 typedef typename Digraph::Node Value; 2307 typedef typename Digraph::Arc Key; 2308 2309 /// \brief Constructor 2310 /// 2311 /// Constructor 2312 /// \param _digraph The digraph that the map belongs to. 2313 explicit TargetMap(const Digraph& digraph) : _digraph(digraph) {} 2314 2315 /// \brief The subscript operator. 2316 /// 2317 /// The subscript operator. 2318 /// \param e The arc 2319 /// \return The target of the arc 2320 Value operator[](const Key& e) const { 2321 return _digraph.target(e); 2322 } 2323 2324 private: 2325 const Digraph& _digraph; 2326 }; 2327 2328 /// \brief Returns a \ref TargetMap class. 2329 /// 2330 /// This function just returns a \ref TargetMap class. 2331 /// \relates TargetMap 2332 template <typename Digraph> 2333 inline TargetMap<Digraph> targetMap(const Digraph& digraph) { 2334 return TargetMap<Digraph>(digraph); 2335 } 2336 2337 /// \brief Returns the "forward" directed arc view of an edge. 2338 /// 2339 /// Returns the "forward" directed arc view of an edge. 2340 /// \see BackwardMap 2341 template <typename Graph> 2342 class ForwardMap { 2343 public: 2344 2345 typedef typename Graph::Arc Value; 2346 typedef typename Graph::Edge Key; 2347 2348 /// \brief Constructor 2349 /// 2350 /// Constructor 2351 /// \param _graph The graph that the map belongs to. 2352 explicit ForwardMap(const Graph& graph) : _graph(graph) {} 2353 2354 /// \brief The subscript operator. 2355 /// 2356 /// The subscript operator. 2357 /// \param key An edge 2358 /// \return The "forward" directed arc view of edge 2359 Value operator[](const Key& key) const { 2360 return _graph.direct(key, true); 2361 } 2362 2363 private: 2364 const Graph& _graph; 2365 }; 2366 2367 /// \brief Returns a \ref ForwardMap class. 2368 /// 2369 /// This function just returns an \ref ForwardMap class. 2370 /// \relates ForwardMap 2371 template <typename Graph> 2372 inline ForwardMap<Graph> forwardMap(const Graph& graph) { 2373 return ForwardMap<Graph>(graph); 2374 } 2375 2376 /// \brief Returns the "backward" directed arc view of an edge. 2377 /// 2378 /// Returns the "backward" directed arc view of an edge. 2379 /// \see ForwardMap 2380 template <typename Graph> 2381 class BackwardMap { 2382 public: 2383 2384 typedef typename Graph::Arc Value; 2385 typedef typename Graph::Edge Key; 2386 2387 /// \brief Constructor 2388 /// 2389 /// Constructor 2390 /// \param _graph The graph that the map belongs to. 2391 explicit BackwardMap(const Graph& graph) : _graph(graph) {} 2392 2393 /// \brief The subscript operator. 2394 /// 2395 /// The subscript operator. 2396 /// \param key An edge 2397 /// \return The "backward" directed arc view of edge 2398 Value operator[](const Key& key) const { 2399 return _graph.direct(key, false); 2400 } 2401 2402 private: 2403 const Graph& _graph; 2404 }; 2405 2406 /// \brief Returns a \ref BackwardMap class 2407 2408 /// This function just returns a \ref BackwardMap class. 2409 /// \relates BackwardMap 2410 template <typename Graph> 2411 inline BackwardMap<Graph> backwardMap(const Graph& graph) { 2412 return BackwardMap<Graph>(graph); 2413 } 2414 2415 /// \brief Potential difference map 2416 /// 2417 /// If there is an potential map on the nodes then we 2418 /// can get an arc map as we get the substraction of the 2419 /// values of the target and source. 2420 template <typename Digraph, typename NodeMap> 2421 class PotentialDifferenceMap { 2422 public: 2423 typedef typename Digraph::Arc Key; 2424 typedef typename NodeMap::Value Value; 2425 2426 /// \brief Constructor 2427 /// 2428 /// Contructor of the map 2429 explicit PotentialDifferenceMap(const Digraph& digraph, 2430 const NodeMap& potential) 2431 : _digraph(digraph), _potential(potential) {} 2432 2433 /// \brief Const subscription operator 2434 /// 2435 /// Const subscription operator 2436 Value operator[](const Key& arc) const { 2437 return _potential[_digraph.target(arc)] - 2438 _potential[_digraph.source(arc)]; 2439 } 2440 2441 private: 2442 const Digraph& _digraph; 2443 const NodeMap& _potential; 2444 }; 2445 2446 /// \brief Returns a PotentialDifferenceMap. 2447 /// 2448 /// This function just returns a PotentialDifferenceMap. 2449 /// \relates PotentialDifferenceMap 2450 template <typename Digraph, typename NodeMap> 2451 PotentialDifferenceMap<Digraph, NodeMap> 2452 potentialDifferenceMap(const Digraph& digraph, const NodeMap& potential) { 2453 return PotentialDifferenceMap<Digraph, NodeMap>(digraph, potential); 2454 } 2455 2456 /// \brief Map of the node in-degrees. 2457 /// 2458 /// This map returns the in-degree of a node. Once it is constructed, 2459 /// the degrees are stored in a standard NodeMap, so each query is done 2460 /// in constant time. On the other hand, the values are updated automatically 2461 /// whenever the digraph changes. 2462 /// 2463 /// \warning Besides addNode() and addArc(), a digraph structure may provide 2464 /// alternative ways to modify the digraph. The correct behavior of InDegMap 2465 /// is not guarantied if these additional features are used. For example 2466 /// the functions \ref ListDigraph::changeSource() "changeSource()", 2467 /// \ref ListDigraph::changeTarget() "changeTarget()" and 2468 /// \ref ListDigraph::reverseArc() "reverseArc()" 2469 /// of \ref ListDigraph will \e not update the degree values correctly. 2470 /// 2471 /// \sa OutDegMap 2472 2473 template <typename _Digraph> 2474 class InDegMap 2475 : protected ItemSetTraits<_Digraph, typename _Digraph::Arc> 2476 ::ItemNotifier::ObserverBase { 2477 2478 public: 2479 2480 typedef _Digraph Digraph; 2481 typedef int Value; 2482 typedef typename Digraph::Node Key; 2483 2484 typedef typename ItemSetTraits<Digraph, typename Digraph::Arc> 2485 ::ItemNotifier::ObserverBase Parent; 2486 2487 private: 2488 2489 class AutoNodeMap 2490 : public ItemSetTraits<Digraph, Key>::template Map<int>::Type { 2491 public: 2492 2493 typedef typename ItemSetTraits<Digraph, Key>:: 2494 template Map<int>::Type Parent; 2495 2496 AutoNodeMap(const Digraph& digraph) : Parent(digraph, 0) {} 2497 2498 virtual void add(const Key& key) { 2499 Parent::add(key); 2500 Parent::set(key, 0); 2501 } 2502 2503 virtual void add(const std::vector<Key>& keys) { 2504 Parent::add(keys); 2505 for (int i = 0; i < int(keys.size()); ++i) { 2506 Parent::set(keys[i], 0); 2507 } 2508 } 2509 2510 virtual void build() { 2511 Parent::build(); 2512 Key it; 2513 typename Parent::Notifier* nf = Parent::notifier(); 2514 for (nf->first(it); it != INVALID; nf->next(it)) { 2515 Parent::set(it, 0); 2516 } 2517 } 2518 }; 2519 2520 public: 2521 2522 /// \brief Constructor. 2523 /// 2524 /// Constructor for creating in-degree map. 2525 explicit InDegMap(const Digraph& digraph) 2526 : _digraph(digraph), _deg(digraph) { 2527 Parent::attach(_digraph.notifier(typename Digraph::Arc())); 2528 2529 for(typename Digraph::NodeIt it(_digraph); it != INVALID; ++it) { 2530 _deg[it] = countInArcs(_digraph, it); 2531 } 2532 } 2533 2534 /// Gives back the in-degree of a Node. 2535 int operator[](const Key& key) const { 2536 return _deg[key]; 2537 } 2538 2539 protected: 2540 2541 typedef typename Digraph::Arc Arc; 2542 2543 virtual void add(const Arc& arc) { 2544 ++_deg[_digraph.target(arc)]; 2545 } 2546 2547 virtual void add(const std::vector<Arc>& arcs) { 2548 for (int i = 0; i < int(arcs.size()); ++i) { 2549 ++_deg[_digraph.target(arcs[i])]; 2550 } 2551 } 2552 2553 virtual void erase(const Arc& arc) { 2554 --_deg[_digraph.target(arc)]; 2555 } 2556 2557 virtual void erase(const std::vector<Arc>& arcs) { 2558 for (int i = 0; i < int(arcs.size()); ++i) { 2559 --_deg[_digraph.target(arcs[i])]; 2560 } 2561 } 2562 2563 virtual void build() { 2564 for(typename Digraph::NodeIt it(_digraph); it != INVALID; ++it) { 2565 _deg[it] = countInArcs(_digraph, it); 2566 } 2567 } 2568 2569 virtual void clear() { 2570 for(typename Digraph::NodeIt it(_digraph); it != INVALID; ++it) { 2571 _deg[it] = 0; 2572 } 2573 } 2574 private: 2575 2576 const Digraph& _digraph; 2577 AutoNodeMap _deg; 2578 }; 2579 2580 /// \brief Map of the node out-degrees. 2581 /// 2582 /// This map returns the out-degree of a node. Once it is constructed, 2583 /// the degrees are stored in a standard NodeMap, so each query is done 2584 /// in constant time. On the other hand, the values are updated automatically 2585 /// whenever the digraph changes. 2586 /// 2587 /// \warning Besides addNode() and addArc(), a digraph structure may provide 2588 /// alternative ways to modify the digraph. The correct behavior of OutDegMap 2589 /// is not guarantied if these additional features are used. For example 2590 /// the functions \ref ListDigraph::changeSource() "changeSource()", 2591 /// \ref ListDigraph::changeTarget() "changeTarget()" and 2592 /// \ref ListDigraph::reverseArc() "reverseArc()" 2593 /// of \ref ListDigraph will \e not update the degree values correctly. 2594 /// 2595 /// \sa InDegMap 2596 2597 template <typename _Digraph> 2598 class OutDegMap 2599 : protected ItemSetTraits<_Digraph, typename _Digraph::Arc> 2600 ::ItemNotifier::ObserverBase { 2601 2602 public: 2603 2604 typedef _Digraph Digraph; 2605 typedef int Value; 2606 typedef typename Digraph::Node Key; 2607 2608 typedef typename ItemSetTraits<Digraph, typename Digraph::Arc> 2609 ::ItemNotifier::ObserverBase Parent; 2610 2611 private: 2612 2613 class AutoNodeMap 2614 : public ItemSetTraits<Digraph, Key>::template Map<int>::Type { 2615 public: 2616 2617 typedef typename ItemSetTraits<Digraph, Key>:: 2618 template Map<int>::Type Parent; 2619 2620 AutoNodeMap(const Digraph& digraph) : Parent(digraph, 0) {} 2621 2622 virtual void add(const Key& key) { 2623 Parent::add(key); 2624 Parent::set(key, 0); 2625 } 2626 virtual void add(const std::vector<Key>& keys) { 2627 Parent::add(keys); 2628 for (int i = 0; i < int(keys.size()); ++i) { 2629 Parent::set(keys[i], 0); 2630 } 2631 } 2632 virtual void build() { 2633 Parent::build(); 2634 Key it; 2635 typename Parent::Notifier* nf = Parent::notifier(); 2636 for (nf->first(it); it != INVALID; nf->next(it)) { 2637 Parent::set(it, 0); 2638 } 2639 } 2640 }; 2641 2642 public: 2643 2644 /// \brief Constructor. 2645 /// 2646 /// Constructor for creating out-degree map. 2647 explicit OutDegMap(const Digraph& digraph) 2648 : _digraph(digraph), _deg(digraph) { 2649 Parent::attach(_digraph.notifier(typename Digraph::Arc())); 2650 2651 for(typename Digraph::NodeIt it(_digraph); it != INVALID; ++it) { 2652 _deg[it] = countOutArcs(_digraph, it); 2653 } 2654 } 2655 2656 /// Gives back the out-degree of a Node. 2657 int operator[](const Key& key) const { 2658 return _deg[key]; 2659 } 2660 2661 protected: 2662 2663 typedef typename Digraph::Arc Arc; 2664 2665 virtual void add(const Arc& arc) { 2666 ++_deg[_digraph.source(arc)]; 2667 } 2668 2669 virtual void add(const std::vector<Arc>& arcs) { 2670 for (int i = 0; i < int(arcs.size()); ++i) { 2671 ++_deg[_digraph.source(arcs[i])]; 2672 } 2673 } 2674 2675 virtual void erase(const Arc& arc) { 2676 --_deg[_digraph.source(arc)]; 2677 } 2678 2679 virtual void erase(const std::vector<Arc>& arcs) { 2680 for (int i = 0; i < int(arcs.size()); ++i) { 2681 --_deg[_digraph.source(arcs[i])]; 2682 } 2683 } 2684 2685 virtual void build() { 2686 for(typename Digraph::NodeIt it(_digraph); it != INVALID; ++it) { 2687 _deg[it] = countOutArcs(_digraph, it); 2688 } 2689 } 2690 2691 virtual void clear() { 2692 for(typename Digraph::NodeIt it(_digraph); it != INVALID; ++it) { 2693 _deg[it] = 0; 2694 } 2695 } 2696 private: 2697 2698 const Digraph& _digraph; 2699 AutoNodeMap _deg; 2700 }; 2701 1783 2702 /// @} 1784 2703 } -
lemon/path.h
r209 r236 29 29 30 30 #include <lemon/error.h> 31 #include <lemon/ bits/invalid.h>31 #include <lemon/core.h> 32 32 #include <lemon/concepts/path.h> 33 33 … … 83 83 } 84 84 85 /// \brief L emonstyle iterator for path arcs85 /// \brief LEMON style iterator for path arcs 86 86 /// 87 87 /// This class is used to iterate on the arcs of the paths. -
lemon/smart_graph.h
r209 r238 26 26 #include <vector> 27 27 28 #include <lemon/bits/invalid.h> 29 30 #include <lemon/bits/base_extender.h> 31 #include <lemon/bits/graph_extender.h> 32 33 #include <lemon/bits/utility.h> 28 #include <lemon/core.h> 34 29 #include <lemon/error.h> 35 36 30 #include <lemon/bits/graph_extender.h> 37 31 … … 472 466 473 467 public: 474 operator Edge() const { return edgeFromId(_id / 2); } 468 operator Edge() const { 469 return _id != -1 ? edgeFromId(_id / 2) : INVALID; 470 } 475 471 476 472 Arc() {} -
lemon/unionfind.h
r209 r236 31 31 #include <functional> 32 32 33 #include <lemon/ bits/invalid.h>33 #include <lemon/core.h> 34 34 35 35 namespace lemon { … … 498 498 } 499 499 500 /// \brief L emonstyle iterator for the representant items.500 /// \brief LEMON style iterator for the representant items. 501 501 /// 502 502 /// ClassIt is a lemon style iterator for the components. It iterates … … 550 550 }; 551 551 552 /// \brief L emonstyle iterator for the items of a component.552 /// \brief LEMON style iterator for the items of a component. 553 553 /// 554 554 /// ClassIt is a lemon style iterator for the components. It iterates … … 808 808 } 809 809 810 /// \brief L emonstyle iterator for the classes.810 /// \brief LEMON style iterator for the classes. 811 811 /// 812 812 /// ClassIt is a lemon style iterator for the components. It iterates … … 860 860 }; 861 861 862 /// \brief L emonstyle iterator for the items of a component.862 /// \brief LEMON style iterator for the items of a component. 863 863 /// 864 864 /// ClassIt is a lemon style iterator for the components. It iterates … … 1656 1656 } 1657 1657 1658 /// \brief L emonstyle iterator for the items of a class.1658 /// \brief LEMON style iterator for the items of a class. 1659 1659 /// 1660 1660 /// ClassIt is a lemon style iterator for the components. It iterates -
test/CMakeLists.txt
r203 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(TESTS5 SET(TESTS 6 6 bfs_test 7 7 counter_test … … 17 17 kruskal_test 18 18 maps_test 19 random_test 19 20 path_test 20 random_test21 21 time_measure_test 22 22 unionfind_test) 23 23 24 foreach(TEST_NAME ${TESTS})25 add_executable(${TEST_NAME} ${TEST_NAME}.cc)26 target_link_libraries(${TEST_NAME} lemon)27 add_test(${TEST_NAME} ${TEST_NAME})28 endforeach(TEST_NAME)24 FOREACH(TEST_NAME ${TESTS}) 25 ADD_EXECUTABLE(${TEST_NAME} ${TEST_NAME}.cc) 26 TARGET_LINK_LIBRARIES(${TEST_NAME} lemon) 27 ADD_TEST(${TEST_NAME} ${TEST_NAME}) 28 ENDFOREACH(TEST_NAME) -
test/Makefile.am
r203 r228 4 4 noinst_HEADERS += \ 5 5 test/graph_test.h \ 6 test/graph_maps_test.h \7 6 test/test_tools.h 8 7 -
test/bfs_test.cc
r209 r228 20 20 #include <lemon/smart_graph.h> 21 21 #include <lemon/list_graph.h> 22 #include <lemon/lgf_reader.h> 22 23 #include <lemon/bfs.h> 23 24 #include <lemon/path.h> … … 27 28 28 29 using namespace lemon; 30 31 char test_lgf[] = 32 "@nodes\n" 33 "label\n" 34 "0\n" 35 "1\n" 36 "2\n" 37 "3\n" 38 "4\n" 39 "5\n" 40 "@arcs\n" 41 " label\n" 42 "0 1 0\n" 43 "1 2 1\n" 44 "2 3 2\n" 45 "3 4 3\n" 46 "0 3 4\n" 47 "0 3 5\n" 48 "5 2 6\n" 49 "@attributes\n" 50 "source 0\n" 51 "target 4\n"; 29 52 30 53 void checkBfsCompile() … … 50 73 n = bfs_test.predNode(n); 51 74 d = bfs_test.distMap(); 75 52 76 p = bfs_test.predMap(); 53 77 // pn = bfs_test.predNodeMap(); … … 81 105 Digraph G; 82 106 Node s, t; 83 PetStruct<Digraph> ps = addPetersen(G, 5);84 107 85 s=ps.outer[2]; 86 t=ps.inner[0]; 108 std::istringstream input(test_lgf); 109 digraphReader(input, G). 110 node("source", s). 111 node("target", t). 112 run(); 87 113 88 114 Bfs<Digraph> bfs_test(G); 89 115 bfs_test.run(s); 90 116 91 check(bfs_test.dist(t)== 3,"Bfs found a wrong path." << bfs_test.dist(t));117 check(bfs_test.dist(t)==2,"Bfs found a wrong path." << bfs_test.dist(t)); 92 118 93 119 Path<Digraph> p = bfs_test.path(t); 94 check(p.length()== 3,"path() found a wrong path.");120 check(p.length()==2,"path() found a wrong path."); 95 121 check(checkPath(G, p),"path() found a wrong path."); 96 122 check(pathSource(G, p) == s,"path() found a wrong path."); … … 98 124 99 125 100 for(ArcIt e(G); e==INVALID; ++e) {101 Node u=G.source( e);102 Node v=G.target( e);126 for(ArcIt a(G); a!=INVALID; ++a) { 127 Node u=G.source(a); 128 Node v=G.target(a); 103 129 check( !bfs_test.reached(u) || 104 (bfs_test.dist(v) >bfs_test.dist(u)+1),105 "Wrong output." );130 (bfs_test.dist(v) <= bfs_test.dist(u)+1), 131 "Wrong output." << G.id(v) << ' ' << G.id(u)); 106 132 } 107 133 108 for(NodeIt v(G); v==INVALID; ++v) { 109 check(bfs_test.reached(v),"Each node should be reached."); 110 if ( bfs_test.predArc(v)!=INVALID ) { 111 Arc e=bfs_test.predArc(v); 112 Node u=G.source(e); 113 check(u==bfs_test.predNode(v),"Wrong tree."); 114 check(bfs_test.dist(v) - bfs_test.dist(u) == 1, 115 "Wrong distance. Difference: " 116 << std::abs(bfs_test.dist(v) - bfs_test.dist(u) 117 - 1)); 134 for(NodeIt v(G); v!=INVALID; ++v) { 135 if (bfs_test.reached(v)) { 136 check(v==s || bfs_test.predArc(v)!=INVALID, "Wrong tree."); 137 if (bfs_test.predArc(v)!=INVALID ) { 138 Arc a=bfs_test.predArc(v); 139 Node u=G.source(a); 140 check(u==bfs_test.predNode(v),"Wrong tree."); 141 check(bfs_test.dist(v) - bfs_test.dist(u) == 1, 142 "Wrong distance. Difference: " 143 << std::abs(bfs_test.dist(v) - bfs_test.dist(u) 144 - 1)); 145 } 118 146 } 119 147 } -
test/dfs_test.cc
r209 r228 20 20 #include <lemon/smart_graph.h> 21 21 #include <lemon/list_graph.h> 22 #include <lemon/lgf_reader.h> 23 22 24 #include <lemon/dfs.h> 23 25 #include <lemon/path.h> … … 27 29 28 30 using namespace lemon; 31 32 char test_lgf[] = 33 "@nodes\n" 34 "label\n" 35 "0\n" 36 "1\n" 37 "2\n" 38 "3\n" 39 "4\n" 40 "5\n" 41 "6\n" 42 "@arcs\n" 43 " label\n" 44 "0 1 0\n" 45 "1 2 1\n" 46 "2 3 2\n" 47 "1 4 3\n" 48 "4 2 4\n" 49 "4 5 5\n" 50 "5 0 6\n" 51 "6 3 7\n" 52 "@attributes\n" 53 "source 0\n" 54 "target 5\n"; 29 55 30 56 void checkDfsCompile() … … 40 66 DType::DistMap d(G); 41 67 DType::PredMap p(G); 42 // DType::PredNodeMap pn(G);43 68 44 69 DType dfs_test(G); … … 51 76 d = dfs_test.distMap(); 52 77 p = dfs_test.predMap(); 53 // pn = dfs_test.predNodeMap();54 78 b = dfs_test.reached(n); 55 79 … … 81 105 Digraph G; 82 106 Node s, t; 83 PetStruct<Digraph> ps = addPetersen(G, 5);84 107 85 s=ps.outer[2]; 86 t=ps.inner[0]; 108 std::istringstream input(test_lgf); 109 digraphReader(input, G). 110 node("source", s). 111 node("target", t). 112 run(); 87 113 88 114 Dfs<Digraph> dfs_test(G); … … 96 122 97 123 for(NodeIt v(G); v!=INVALID; ++v) { 98 check(dfs_test.reached(v),"Each node should be reached."); 99 if ( dfs_test.predArc(v)!=INVALID ) { 100 Arc e=dfs_test.predArc(v); 101 Node u=G.source(e); 102 check(u==dfs_test.predNode(v),"Wrong tree."); 103 check(dfs_test.dist(v) - dfs_test.dist(u) == 1, 104 "Wrong distance. (" << dfs_test.dist(u) << "->" 105 <<dfs_test.dist(v) << ')'); 124 if (dfs_test.reached(v)) { 125 check(v==s || dfs_test.predArc(v)!=INVALID, "Wrong tree."); 126 if (dfs_test.predArc(v)!=INVALID ) { 127 Arc e=dfs_test.predArc(v); 128 Node u=G.source(e); 129 check(u==dfs_test.predNode(v),"Wrong tree."); 130 check(dfs_test.dist(v) - dfs_test.dist(u) == 1, 131 "Wrong distance. (" << dfs_test.dist(u) << "->" 132 <<dfs_test.dist(v) << ')'); 133 } 106 134 } 107 135 } -
test/digraph_test.cc
r209 r228 25 25 #include "test_tools.h" 26 26 #include "graph_test.h" 27 #include "graph_maps_test.h"28 27 29 28 using namespace lemon; 30 29 using namespace lemon::concepts; 31 30 32 void check_concepts() { 31 template <class Digraph> 32 void checkDigraph() { 33 TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); 34 Digraph G; 35 36 checkGraphNodeList(G, 0); 37 checkGraphArcList(G, 0); 38 39 Node 40 n1 = G.addNode(), 41 n2 = G.addNode(), 42 n3 = G.addNode(); 43 checkGraphNodeList(G, 3); 44 checkGraphArcList(G, 0); 45 46 Arc a1 = G.addArc(n1, n2); 47 check(G.source(a1) == n1 && G.target(a1) == n2, "Wrong arc"); 48 checkGraphNodeList(G, 3); 49 checkGraphArcList(G, 1); 50 51 checkGraphOutArcList(G, n1, 1); 52 checkGraphOutArcList(G, n2, 0); 53 checkGraphOutArcList(G, n3, 0); 54 55 checkGraphInArcList(G, n1, 0); 56 checkGraphInArcList(G, n2, 1); 57 checkGraphInArcList(G, n3, 0); 58 59 checkGraphConArcList(G, 1); 60 61 Arc a2 = G.addArc(n2, n1), a3 = G.addArc(n2, n3), a4 = G.addArc(n2, n3); 62 checkGraphNodeList(G, 3); 63 checkGraphArcList(G, 4); 64 65 checkGraphOutArcList(G, n1, 1); 66 checkGraphOutArcList(G, n2, 3); 67 checkGraphOutArcList(G, n3, 0); 68 69 checkGraphInArcList(G, n1, 1); 70 checkGraphInArcList(G, n2, 1); 71 checkGraphInArcList(G, n3, 2); 72 73 checkGraphConArcList(G, 4); 74 75 checkNodeIds(G); 76 checkArcIds(G); 77 checkGraphNodeMap(G); 78 checkGraphArcMap(G); 79 80 } 81 82 83 void checkConcepts() { 33 84 { // Checking digraph components 34 85 checkConcept<BaseDigraphComponent, BaseDigraphComponent >(); … … 52 103 checkConcept<ClearableDigraphComponent<>, ListDigraph>(); 53 104 checkConcept<ErasableDigraphComponent<>, ListDigraph>(); 54 checkDigraphIterators<ListDigraph>();55 105 } 56 106 { // Checking SmartDigraph … … 59 109 checkConcept<ExtendableDigraphComponent<>, SmartDigraph>(); 60 110 checkConcept<ClearableDigraphComponent<>, SmartDigraph>(); 61 checkDigraphIterators<SmartDigraph>();62 111 } 63 112 // { // Checking FullDigraph 64 113 // checkConcept<Digraph, FullDigraph>(); 65 // checkDigraphIterators<FullDigraph>();66 114 // } 67 115 // { // Checking HyperCubeDigraph 68 116 // checkConcept<Digraph, HyperCubeDigraph>(); 69 // checkDigraphIterators<HyperCubeDigraph>();70 117 // } 71 118 } 72 119 73 120 template <typename Digraph> 74 void check _graph_validity() {121 void checkDigraphValidity() { 75 122 TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); 76 123 Digraph g; … … 93 140 94 141 template <typename Digraph> 95 void check _graph_validity_erase() {142 void checkDigraphValidityErase() { 96 143 TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); 97 144 Digraph g; … … 121 168 } 122 169 123 void check _digraphs() {170 void checkDigraphs() { 124 171 { // Checking ListDigraph 125 172 checkDigraph<ListDigraph>(); 126 checkGraphNodeMap<ListDigraph>(); 127 checkGraphArcMap<ListDigraph>(); 128 129 check_graph_validity_erase<ListDigraph>(); 173 checkDigraphValidityErase<ListDigraph>(); 130 174 } 131 175 { // Checking SmartDigraph 132 176 checkDigraph<SmartDigraph>(); 133 checkGraphNodeMap<SmartDigraph>(); 134 checkGraphArcMap<SmartDigraph>(); 135 136 check_graph_validity<SmartDigraph>(); 177 checkDigraphValidity<SmartDigraph>(); 137 178 } 138 179 } 139 180 140 181 int main() { 141 check _concepts();142 check _digraphs();182 checkDigraphs(); 183 checkConcepts(); 143 184 return 0; 144 185 } -
test/dijkstra_test.cc
r210 r228 20 20 #include <lemon/smart_graph.h> 21 21 #include <lemon/list_graph.h> 22 #include <lemon/graph_utils.h> 22 #include <lemon/lgf_reader.h> 23 23 24 #include <lemon/dijkstra.h> 24 25 #include <lemon/path.h> … … 28 29 29 30 using namespace lemon; 31 32 char test_lgf[] = 33 "@nodes\n" 34 "label\n" 35 "0\n" 36 "1\n" 37 "2\n" 38 "3\n" 39 "4\n" 40 "@arcs\n" 41 " label length\n" 42 "0 1 0 1\n" 43 "1 2 1 1\n" 44 "2 3 2 1\n" 45 "0 3 4 5\n" 46 "0 3 5 10\n" 47 "0 3 6 7\n" 48 "4 2 7 1\n" 49 "@attributes\n" 50 "source 0\n" 51 "target 3\n"; 30 52 31 53 void checkDijkstraCompile() … … 86 108 Node s, t; 87 109 LengthMap length(G); 88 PetStruct<Digraph> ps = addPetersen(G, 5);89 110 90 for(int i=0;i<5;i++) { 91 length[ps.outcir[i]]=4; 92 length[ps.incir[i]]=1; 93 length[ps.chords[i]]=10; 94 } 95 s=ps.outer[0]; 96 t=ps.inner[1]; 111 std::istringstream input(test_lgf); 112 digraphReader(input, G). 113 arcMap("length", length). 114 node("source", s). 115 node("target", t). 116 run(); 97 117 98 118 Dijkstra<Digraph, LengthMap> … … 100 120 dijkstra_test.run(s); 101 121 102 check(dijkstra_test.dist(t)== 13,"Dijkstra found a wrong path.");122 check(dijkstra_test.dist(t)==3,"Dijkstra found a wrong path."); 103 123 104 124 Path<Digraph> p = dijkstra_test.path(t); 105 check(p.length()== 4,"getPath() found a wrong path.");125 check(p.length()==3,"getPath() found a wrong path."); 106 126 check(checkPath(G, p),"path() found a wrong path."); 107 127 check(pathSource(G, p) == s,"path() found a wrong path."); … … 117 137 } 118 138 119 for(NodeIt v(G); v!=INVALID; ++v){ 120 check(dijkstra_test.reached(v),"Each node should be reached."); 121 if ( dijkstra_test.predArc(v)!=INVALID ) { 122 Arc e=dijkstra_test.predArc(v); 123 Node u=G.source(e); 124 check(u==dijkstra_test.predNode(v),"Wrong tree."); 125 check(dijkstra_test.dist(v) - dijkstra_test.dist(u) == length[e], 126 "Wrong distance! Difference: " << 127 std::abs(dijkstra_test.dist(v)-dijkstra_test.dist(u)-length[e])); 139 for(NodeIt v(G); v!=INVALID; ++v) { 140 if (dijkstra_test.reached(v)) { 141 check(v==s || dijkstra_test.predArc(v)!=INVALID, "Wrong tree."); 142 if (dijkstra_test.predArc(v)!=INVALID ) { 143 Arc e=dijkstra_test.predArc(v); 144 Node u=G.source(e); 145 check(u==dijkstra_test.predNode(v),"Wrong tree."); 146 check(dijkstra_test.dist(v) - dijkstra_test.dist(u) == length[e], 147 "Wrong distance! Difference: " << 148 std::abs(dijkstra_test.dist(v)-dijkstra_test.dist(u)-length[e])); 149 } 128 150 } 129 151 } -
test/dim_test.cc
r209 r242 59 59 box1.add(b); 60 60 61 check(box1.bottomLeft().x==1 && 62 box1.bottomLeft().y==2 && 63 box1.topRight().x==3 && 64 box1.topRight().y==4, 61 check(box1.left()==1 && box1.bottom()==2 && 62 box1.right()==3 && box1.top()==4, 65 63 "Wrong addition of points to dim2::BoundingBox."); 66 64 67 p.x=2; p.y=3; 68 check(box1.inside(p), "Wrong inside() in dim2::BoundingBox."); 65 check(box1.inside(Point(2,3)), "Wrong inside() in dim2::BoundingBox."); 66 check(box1.inside(Point(1,3)), "Wrong inside() in dim2::BoundingBox."); 67 check(!box1.inside(Point(0,3)), "Wrong inside() in dim2::BoundingBox."); 69 68 70 p.x=1; p.y=3; 71 check(box1.inside(p), "Wrong inside() in dim2::BoundingBox."); 72 73 p.x=0; p.y=3; 74 check(!box1.inside(p), "Wrong inside() in dim2::BoundingBox."); 75 76 BB box2(p); 69 BB box2(Point(2,2)); 77 70 check(!box2.empty(), "Wrong empty() in dim2::BoundingBox."); 78 79 box2.add(box1); 80 check(box2.inside(p), "Wrong inside() in dim2::BoundingBox."); 71 72 box2.bottomLeft(Point(2,0)); 73 box2.topRight(Point(5,3)); 74 BB box3 = box1 & box2; 75 check(!box3.empty() && 76 box3.left()==2 && box3.bottom()==2 && 77 box3.right()==3 && box3.top()==3, 78 "Wrong intersection of two dim2::BoundingBox objects."); 79 80 box1.add(box2); 81 check(!box1.empty() && 82 box1.left()==1 && box1.bottom()==0 && 83 box1.right()==5 && box1.top()==4, 84 "Wrong addition of two dim2::BoundingBox objects."); 81 85 82 86 return 0; -
test/error_test.cc
r209 r223 30 30 #ifdef LEMON_DISABLE_ASSERTS 31 31 #undef LEMON_DISABLE_ASSERTS 32 #endif 33 34 #ifdef NDEBUG 35 #undef NDEBUG 32 36 #endif 33 37 -
test/graph_copy_test.cc
r209 r220 20 20 #include <lemon/list_graph.h> 21 21 #include <lemon/lgf_reader.h> 22 #include <lemon/graph_utils.h>23 22 #include <lemon/error.h> 24 23 -
test/graph_test.cc
r209 r228 25 25 #include "test_tools.h" 26 26 #include "graph_test.h" 27 #include "graph_maps_test.h"28 27 29 28 using namespace lemon; 30 29 using namespace lemon::concepts; 31 30 32 void check_concepts() { 31 template <class Graph> 32 void checkGraph() { 33 TEMPLATE_GRAPH_TYPEDEFS(Graph); 34 35 Graph G; 36 checkGraphNodeList(G, 0); 37 checkGraphEdgeList(G, 0); 38 39 Node 40 n1 = G.addNode(), 41 n2 = G.addNode(), 42 n3 = G.addNode(); 43 checkGraphNodeList(G, 3); 44 checkGraphEdgeList(G, 0); 45 46 Edge e1 = G.addEdge(n1, n2); 47 check((G.u(e1) == n1 && G.v(e1) == n2) || (G.u(e1) == n2 && G.v(e1) == n1), 48 "Wrong edge"); 49 checkGraphNodeList(G, 3); 50 checkGraphArcList(G, 2); 51 checkGraphEdgeList(G, 1); 52 53 checkGraphOutArcList(G, n1, 1); 54 checkGraphOutArcList(G, n2, 1); 55 checkGraphOutArcList(G, n3, 0); 56 57 checkGraphInArcList(G, n1, 1); 58 checkGraphInArcList(G, n2, 1); 59 checkGraphInArcList(G, n3, 0); 60 61 checkGraphIncEdgeList(G, n1, 1); 62 checkGraphIncEdgeList(G, n2, 1); 63 checkGraphIncEdgeList(G, n3, 0); 64 65 checkGraphConArcList(G, 2); 66 checkGraphConEdgeList(G, 1); 67 68 Edge e2 = G.addEdge(n2, n1), e3 = G.addEdge(n2, n3); 69 checkGraphNodeList(G, 3); 70 checkGraphArcList(G, 6); 71 checkGraphEdgeList(G, 3); 72 73 checkGraphOutArcList(G, n1, 2); 74 checkGraphOutArcList(G, n2, 3); 75 checkGraphOutArcList(G, n3, 1); 76 77 checkGraphInArcList(G, n1, 2); 78 checkGraphInArcList(G, n2, 3); 79 checkGraphInArcList(G, n3, 1); 80 81 checkGraphIncEdgeList(G, n1, 2); 82 checkGraphIncEdgeList(G, n2, 3); 83 checkGraphIncEdgeList(G, n3, 1); 84 85 checkGraphConArcList(G, 6); 86 checkGraphConEdgeList(G, 3); 87 88 checkArcDirections(G); 89 90 checkNodeIds(G); 91 checkArcIds(G); 92 checkEdgeIds(G); 93 checkGraphNodeMap(G); 94 checkGraphArcMap(G); 95 checkGraphEdgeMap(G); 96 } 97 98 void checkConcepts() { 33 99 { // Checking graph components 34 100 checkConcept<BaseGraphComponent, BaseGraphComponent >(); … … 52 118 checkConcept<ClearableGraphComponent<>, ListGraph>(); 53 119 checkConcept<ErasableGraphComponent<>, ListGraph>(); 54 checkGraphIterators<ListGraph>();55 120 } 56 121 { // Checking SmartGraph … … 59 124 checkConcept<ExtendableGraphComponent<>, SmartGraph>(); 60 125 checkConcept<ClearableGraphComponent<>, SmartGraph>(); 61 checkGraphIterators<SmartGraph>();62 126 } 63 127 // { // Checking FullGraph … … 72 136 73 137 template <typename Graph> 74 void check _graph_validity() {138 void checkGraphValidity() { 75 139 TEMPLATE_GRAPH_TYPEDEFS(Graph); 76 140 Graph g; … … 95 159 96 160 template <typename Graph> 97 void check _graph_validity_erase() {161 void checkGraphValidityErase() { 98 162 TEMPLATE_GRAPH_TYPEDEFS(Graph); 99 163 Graph g; … … 169 233 // } 170 234 171 void check _graphs() {235 void checkGraphs() { 172 236 { // Checking ListGraph 173 237 checkGraph<ListGraph>(); 174 checkGraphNodeMap<ListGraph>(); 175 checkGraphEdgeMap<ListGraph>(); 176 177 check_graph_validity_erase<ListGraph>(); 238 checkGraphValidityErase<ListGraph>(); 178 239 } 179 240 { // Checking SmartGraph 180 241 checkGraph<SmartGraph>(); 181 checkGraphNodeMap<SmartGraph>(); 182 checkGraphEdgeMap<SmartGraph>(); 183 184 check_graph_validity<SmartGraph>(); 242 checkGraphValidity<SmartGraph>(); 185 243 } 186 244 // { // Checking FullGraph … … 198 256 199 257 int main() { 200 check _concepts();201 check _graphs();258 checkConcepts(); 259 checkGraphs(); 202 260 return 0; 203 261 } -
test/graph_test.h
r209 r228 20 20 #define LEMON_TEST_GRAPH_TEST_H 21 21 22 #include <lemon/graph_utils.h> 22 #include <set> 23 24 #include <lemon/core.h> 25 #include <lemon/maps.h> 26 23 27 #include "test_tools.h" 24 28 … … 43 47 for(int i=0;i<cnt;i++) { 44 48 check(e!=INVALID,"Wrong Arc list linking."); 49 check(G.oppositeNode(G.source(e), e) == G.target(e), 50 "Wrong opposite node"); 51 check(G.oppositeNode(G.target(e), e) == G.source(e), 52 "Wrong opposite node"); 45 53 ++e; 46 54 } … … 56 64 check(e!=INVALID,"Wrong OutArc list linking."); 57 65 check(n==G.source(e),"Wrong OutArc list linking."); 66 check(n==G.baseNode(e),"Wrong OutArc list linking."); 67 check(G.target(e)==G.runningNode(e),"Wrong OutArc list linking."); 58 68 ++e; 59 69 } … … 69 79 check(e!=INVALID,"Wrong InArc list linking."); 70 80 check(n==G.target(e),"Wrong InArc list linking."); 81 check(n==G.baseNode(e),"Wrong OutArc list linking."); 82 check(G.source(e)==G.runningNode(e),"Wrong OutArc list linking."); 71 83 ++e; 72 84 } … … 81 93 for(int i=0;i<cnt;i++) { 82 94 check(e!=INVALID,"Wrong Edge list linking."); 95 check(G.oppositeNode(G.u(e), e) == G.v(e), "Wrong opposite node"); 96 check(G.oppositeNode(G.v(e), e) == G.u(e), "Wrong opposite node"); 83 97 ++e; 84 98 } … … 94 108 check(e!=INVALID,"Wrong IncEdge list linking."); 95 109 check(n==G.u(e) || n==G.v(e),"Wrong IncEdge list linking."); 110 check(n==G.baseNode(e),"Wrong OutArc list linking."); 111 check(G.u(e)==G.runningNode(e) || G.v(e)==G.runningNode(e), 112 "Wrong OutArc list linking."); 96 113 ++e; 97 114 } … … 100 117 } 101 118 102 template <class Digraph>103 void checkDigraphIterators() {104 typedef typename Digraph::Node Node;105 typedef typename Digraph::NodeIt NodeIt;106 typedef typename Digraph::Arc Arc;107 typedef typename Digraph::ArcIt ArcIt;108 typedef typename Digraph::InArcIt InArcIt;109 typedef typename Digraph::OutArcIt OutArcIt;110 }111 112 119 template <class Graph> 113 void checkGraphIterators() { 114 checkDigraphIterators<Graph>(); 120 void checkGraphConArcList(const Graph &G, int cnt) { 121 int i = 0; 122 for (typename Graph::NodeIt u(G); u != INVALID; ++u) { 123 for (typename Graph::NodeIt v(G); v != INVALID; ++v) { 124 for (ConArcIt<Graph> a(G, u, v); a != INVALID; ++a) { 125 check(G.source(a) == u, "Wrong iterator."); 126 check(G.target(a) == v, "Wrong iterator."); 127 ++i; 128 } 129 } 130 } 131 check(cnt == i, "Wrong iterator."); 132 } 133 134 template <class Graph> 135 void checkGraphConEdgeList(const Graph &G, int cnt) { 136 int i = 0; 137 for (typename Graph::NodeIt u(G); u != INVALID; ++u) { 138 for (typename Graph::NodeIt v(G); v != INVALID; ++v) { 139 for (ConEdgeIt<Graph> e(G, u, v); e != INVALID; ++e) { 140 check((G.u(e) == u && G.v(e) == v) || 141 (G.u(e) == v && G.v(e) == u), "Wrong iterator."); 142 i += u == v ? 2 : 1; 143 } 144 } 145 } 146 check(2 * cnt == i, "Wrong iterator."); 147 } 148 149 template <typename Graph> 150 void checkArcDirections(const Graph& G) { 151 for (typename Graph::ArcIt a(G); a != INVALID; ++a) { 152 check(G.source(a) == G.target(G.oppositeArc(a)), "Wrong direction"); 153 check(G.target(a) == G.source(G.oppositeArc(a)), "Wrong direction"); 154 check(G.direct(a, G.direction(a)) == a, "Wrong direction"); 155 } 156 } 157 158 template <typename Graph> 159 void checkNodeIds(const Graph& G) { 160 std::set<int> values; 161 for (typename Graph::NodeIt n(G); n != INVALID; ++n) { 162 check(G.nodeFromId(G.id(n)) == n, "Wrong id"); 163 check(values.find(G.id(n)) == values.end(), "Wrong id"); 164 check(G.id(n) <= G.maxNodeId(), "Wrong maximum id"); 165 values.insert(G.id(n)); 166 } 167 } 168 169 template <typename Graph> 170 void checkArcIds(const Graph& G) { 171 std::set<int> values; 172 for (typename Graph::ArcIt a(G); a != INVALID; ++a) { 173 check(G.arcFromId(G.id(a)) == a, "Wrong id"); 174 check(values.find(G.id(a)) == values.end(), "Wrong id"); 175 check(G.id(a) <= G.maxArcId(), "Wrong maximum id"); 176 values.insert(G.id(a)); 177 } 178 } 179 180 template <typename Graph> 181 void checkEdgeIds(const Graph& G) { 182 std::set<int> values; 183 for (typename Graph::EdgeIt e(G); e != INVALID; ++e) { 184 check(G.edgeFromId(G.id(e)) == e, "Wrong id"); 185 check(values.find(G.id(e)) == values.end(), "Wrong id"); 186 check(G.id(e) <= G.maxEdgeId(), "Wrong maximum id"); 187 values.insert(G.id(e)); 188 } 189 } 190 191 template <typename Graph> 192 void checkGraphNodeMap(const Graph& G) { 193 typedef typename Graph::Node Node; 194 typedef typename Graph::NodeIt NodeIt; 195 196 typedef typename Graph::template NodeMap<int> IntNodeMap; 197 IntNodeMap map(G, 42); 198 for (NodeIt it(G); it != INVALID; ++it) { 199 check(map[it] == 42, "Wrong map constructor."); 200 } 201 int s = 0; 202 for (NodeIt it(G); it != INVALID; ++it) { 203 map[it] = 0; 204 check(map[it] == 0, "Wrong operator[]."); 205 map.set(it, s); 206 check(map[it] == s, "Wrong set."); 207 ++s; 208 } 209 s = s * (s - 1) / 2; 210 for (NodeIt it(G); it != INVALID; ++it) { 211 s -= map[it]; 212 } 213 check(s == 0, "Wrong sum."); 214 215 map = constMap<Node>(12); 216 for (NodeIt it(G); it != INVALID; ++it) { 217 check(map[it] == 12, "Wrong operator[]."); 218 } 219 } 220 221 template <typename Graph> 222 void checkGraphArcMap(const Graph& G) { 223 typedef typename Graph::Arc Arc; 224 typedef typename Graph::ArcIt ArcIt; 225 226 typedef typename Graph::template ArcMap<int> IntArcMap; 227 IntArcMap map(G, 42); 228 for (ArcIt it(G); it != INVALID; ++it) { 229 check(map[it] == 42, "Wrong map constructor."); 230 } 231 int s = 0; 232 for (ArcIt it(G); it != INVALID; ++it) { 233 map[it] = 0; 234 check(map[it] == 0, "Wrong operator[]."); 235 map.set(it, s); 236 check(map[it] == s, "Wrong set."); 237 ++s; 238 } 239 s = s * (s - 1) / 2; 240 for (ArcIt it(G); it != INVALID; ++it) { 241 s -= map[it]; 242 } 243 check(s == 0, "Wrong sum."); 244 245 map = constMap<Arc>(12); 246 for (ArcIt it(G); it != INVALID; ++it) { 247 check(map[it] == 12, "Wrong operator[]."); 248 } 249 } 250 251 template <typename Graph> 252 void checkGraphEdgeMap(const Graph& G) { 115 253 typedef typename Graph::Edge Edge; 116 254 typedef typename Graph::EdgeIt EdgeIt; 117 typedef typename Graph::IncEdgeIt IncEdgeIt; 118 } 119 120 // Structure returned by addPetersen() 121 template<class Digraph> 122 struct PetStruct 123 { 124 // Vector containing the outer nodes 125 std::vector<typename Digraph::Node> outer; 126 // Vector containing the inner nodes 127 std::vector<typename Digraph::Node> inner; 128 // Vector containing the arcs of the inner circle 129 std::vector<typename Digraph::Arc> incir; 130 // Vector containing the arcs of the outer circle 131 std::vector<typename Digraph::Arc> outcir; 132 // Vector containing the chord arcs 133 std::vector<typename Digraph::Arc> chords; 134 }; 135 136 // Adds the reverse pair of all arcs to a digraph 137 template<class Digraph> 138 void bidirDigraph(Digraph &G) 139 { 140 typedef typename Digraph::Arc Arc; 141 typedef typename Digraph::ArcIt ArcIt; 142 143 std::vector<Arc> ee; 144 145 for(ArcIt e(G);e!=INVALID;++e) ee.push_back(e); 146 147 for(int i=0;i<int(ee.size());++i) 148 G.addArc(G.target(ee[i]),G.source(ee[i])); 149 } 150 151 // Adds a Petersen digraph to G. 152 // Returns the nodes and arcs of the generated digraph. 153 template<typename Digraph> 154 PetStruct<Digraph> addPetersen(Digraph &G,int num = 5) 155 { 156 PetStruct<Digraph> n; 157 158 for(int i=0;i<num;i++) { 159 n.outer.push_back(G.addNode()); 160 n.inner.push_back(G.addNode()); 161 } 162 163 for(int i=0;i<num;i++) { 164 n.chords.push_back(G.addArc(n.outer[i],n.inner[i])); 165 n.outcir.push_back(G.addArc(n.outer[i],n.outer[(i+1) % num])); 166 n.incir.push_back(G.addArc(n.inner[i],n.inner[(i+2) % num])); 167 } 168 169 return n; 170 } 171 172 // Checks the bidirectioned Petersen digraph 173 template<class Digraph> 174 void checkBidirPetersen(const Digraph &G, int num = 5) 175 { 176 typedef typename Digraph::NodeIt NodeIt; 177 178 checkGraphNodeList(G, 2 * num); 179 checkGraphArcList(G, 6 * num); 180 181 for(NodeIt n(G);n!=INVALID;++n) { 182 checkGraphInArcList(G, n, 3); 183 checkGraphOutArcList(G, n, 3); 184 } 185 } 186 187 // Structure returned by addUPetersen() 188 template<class Graph> 189 struct UPetStruct 190 { 191 // Vector containing the outer nodes 192 std::vector<typename Graph::Node> outer; 193 // Vector containing the inner nodes 194 std::vector<typename Graph::Node> inner; 195 // Vector containing the edges of the inner circle 196 std::vector<typename Graph::Edge> incir; 197 // Vector containing the edges of the outer circle 198 std::vector<typename Graph::Edge> outcir; 199 // Vector containing the chord edges 200 std::vector<typename Graph::Edge> chords; 201 }; 202 203 // Adds a Petersen graph to \c G. 204 // Returns the nodes and edges of the generated graph. 205 template<typename Graph> 206 UPetStruct<Graph> addUPetersen(Graph &G,int num=5) 207 { 208 UPetStruct<Graph> n; 209 210 for(int i=0;i<num;i++) { 211 n.outer.push_back(G.addNode()); 212 n.inner.push_back(G.addNode()); 213 } 214 215 for(int i=0;i<num;i++) { 216 n.chords.push_back(G.addEdge(n.outer[i],n.inner[i])); 217 n.outcir.push_back(G.addEdge(n.outer[i],n.outer[(i+1)%num])); 218 n.incir.push_back(G.addEdge(n.inner[i],n.inner[(i+2)%num])); 219 } 220 221 return n; 222 } 223 224 // Checks the undirected Petersen graph 225 template<class Graph> 226 void checkUndirPetersen(const Graph &G, int num = 5) 227 { 228 typedef typename Graph::NodeIt NodeIt; 229 230 checkGraphNodeList(G, 2 * num); 231 checkGraphEdgeList(G, 3 * num); 232 checkGraphArcList(G, 6 * num); 233 234 for(NodeIt n(G);n!=INVALID;++n) { 235 checkGraphIncEdgeList(G, n, 3); 236 } 237 } 238 239 template <class Digraph> 240 void checkDigraph() { 241 const int num = 5; 242 Digraph G; 243 checkGraphNodeList(G, 0); 244 checkGraphArcList(G, 0); 245 addPetersen(G, num); 246 bidirDigraph(G); 247 checkBidirPetersen(G, num); 248 } 249 250 template <class Graph> 251 void checkGraph() { 252 const int num = 5; 253 Graph G; 254 checkGraphNodeList(G, 0); 255 checkGraphEdgeList(G, 0); 256 addUPetersen(G, num); 257 checkUndirPetersen(G, num); 258 } 255 256 typedef typename Graph::template EdgeMap<int> IntEdgeMap; 257 IntEdgeMap map(G, 42); 258 for (EdgeIt it(G); it != INVALID; ++it) { 259 check(map[it] == 42, "Wrong map constructor."); 260 } 261 int s = 0; 262 for (EdgeIt it(G); it != INVALID; ++it) { 263 map[it] = 0; 264 check(map[it] == 0, "Wrong operator[]."); 265 map.set(it, s); 266 check(map[it] == s, "Wrong set."); 267 ++s; 268 } 269 s = s * (s - 1) / 2; 270 for (EdgeIt it(G); it != INVALID; ++it) { 271 s -= map[it]; 272 } 273 check(s == 0, "Wrong sum."); 274 275 map = constMap<Edge>(12); 276 for (EdgeIt it(G); it != INVALID; ++it) { 277 check(map[it] == 12, "Wrong operator[]."); 278 } 279 } 280 259 281 260 282 } //namespace lemon -
test/graph_utils_test.cc
r210 r220 21 21 22 22 #include <lemon/random.h> 23 #include <lemon/graph_utils.h>24 23 #include <lemon/list_graph.h> 25 24 #include <lemon/smart_graph.h> 25 #include <lemon/maps.h> 26 26 27 27 #include "graph_test.h"
Note: See TracChangeset
for help on using the changeset viewer.