COIN-OR::LEMON - Graph Library

Changes in / [244:c30731a37f91:247:f1158744a112] in lemon-main


Ignore:
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)
     1CMAKE_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
     8SET(PROJECT_NAME "LEMON")
     9SET(PROJECT_VERSION_MAJOR "0")
     10SET(PROJECT_VERSION_MINOR "99")
     11SET(PROJECT_VERSION_PATCH "0")
     12SET(PROJECT_VERSION
     13  "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
     14
     15PROJECT(${PROJECT_NAME})
     16
     17SET(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
     18
     19INCLUDE(FindDoxygen)
     20INCLUDE(FindGhostscript)
     21
     22ENABLE_TESTING()
     23
     24ADD_SUBDIRECTORY(lemon)
     25ADD_SUBDIRECTORY(demo)
     26ADD_SUBDIRECTORY(doc)
     27ADD_SUBDIRECTORY(test)
     28
     29IF(WIN32)
     30  INSTALL(FILES ${CMAKE_SOURCE_DIR}/cmake/nsis/lemon.ico
     31    DESTINATION bin)
     32ENDIF(WIN32)
     33
     34IF(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)
     101ENDIF(WIN32)
  • INSTALL

    r5 r245  
    44   Since you are reading this I assume you already obtained one of the release
    55tarballs and successfully extracted it. The latest version of LEMON is
    6 available at our webpage (http://lemon.cs.elte.hu/).
     6available at our web page (http://lemon.cs.elte.hu/).
    77
    88   In order to install LEMON from the extracted source tarball you have to
    99issue the following commands:
    1010
    11   1. `cd lemon-x.y.z'
     11   1. `cd lemon-x.y.z'
    1212
    13      This changes to the directory which was created when you extracted the
    14      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.
    1515
    16   2. `./configure'
     16   2. `./configure'
    1717
    18      This runs the configure shell script, which does some checks and
    19      configuration (creates makefiles etc).
     18      This command runs the configure shell script, which does some checks and
     19      creates the makefiles.
    2020
    21   3. `make'
     21   3. `make'
    2222
    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.
    2526
    26   4. `make check'
     27   4. `make check'
    2728
    28      This step is optional, but recommended. It runs the test programs that we
    29      developed for LEMON to check whether the library works properly on your
    30      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.
    3132
    32   5. `make install'
     33   5. `make install'
    3334
    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.
    3847
    3948
    40 Configure Flags
    41 ===============
     49Configure Options and Variables
     50===============================
    4251
    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
     53and passing options to it. This can be done like this:
     54`./configure [OPTION]... [VARIABLE=VALUE]...'
    4555
    46 CXX=comp
     56   Below you will find some useful variables and options (see
     57`./configure --help' for more):
     58
     59CXX='comp'
    4760
    4861  Change the C++ compiler to 'comp'.
     
    5063CXXFLAGS='flags'
    5164
    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.
    5671
    5772--enable-demo
    5873
    59    Build the demo programs too.
     74   Build the examples in the demo subdirectory.
    6075
    6176--disable-demo
    6277
    63    Do not build the demo programs (default).
     78   Do not build the examples in the demo subdirectory (default).
    6479
    6580--enable-benchmark
    6681
    67    Build the benchmark programs too.
     82   Build the programs in the benchmark subdirectory.
    6883
    6984--disable-benchmark
    7085
    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.
    7295
    7396--with-glpk[=PREFIX]
     
    116139
    117140   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  
    99        m4/lx_check_glpk.m4 \
    1010        m4/lx_check_soplex.m4 \
    11         CMakeLists.txt
     11        CMakeLists.txt \
     12        cmake
    1213
    1314pkgconfigdir = $(libdir)/pkgconfig
  • README

    r24 r246  
    1 ------------------------------------------------------------------
     1==================================================================
    22LEMON - a Library of Efficient Models and Optimization in Networks
    3 ------------------------------------------------------------------
     3==================================================================
    44
    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.
     5LEMON is an open source library written in C++. It provides
     6easy-to-use implementations of common data structures and algorithms
     7in the area of optimization and helps implementing new ones. The main
     8focus is on graphs and graph algorithms, thus it is especially
     9suitable for solving design and optimization problems of
     10telecommunication networks. To achieve wide usability its data
     11structures and algorithms provide generic interfaces.
    1512
    16 --------
    1713Contents
    18 --------
     14========
    1915
    20 COPYING, LICENSE
     16LICENSE
    2117
    22   Copying, distribution and modification conditions and terms.
     18   Copying, distribution and modification conditions and terms.
    2319
    2420INSTALL
    2521
    26   For general building and installation instructions, see the file.
     22   General building and installation instructions.
    2723
    2824lemon/
    2925
    30   Source code of LEMON itself.
     26   Source code of LEMON library.
    3127
    3228doc/
    3329
    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.
    4431
    4532demo/
    4633
    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.
    5035
    5136test/
    5237
    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.
    5539
    5640benchmark/
    5741 
    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
     44tools/
     45
     46   Various utilities related to LEMON.
  • configure.ac

    r175 r236  
    77
    88AC_PREREQ([2.59])
    9 AC_INIT([LEMON], [lemon_version()], [lemon-devel@lemon.cs.elte.hu], [lemon])
     9AC_INIT([LEMON], [lemon_version()], [lemon-user@lemon.cs.elte.hu], [lemon])
    1010AC_CONFIG_AUX_DIR([build-aux])
    1111AC_CONFIG_MACRO_DIR([m4])
     
    2626AC_CHECK_PROG([gs_found],[gs],[yes],[no])
    2727
     28dnl Set custom compiler flags when using g++.
    2829if test x"$lx_cmdline_cxxflags_set" != x"set" -a "$GXX" = yes; then
    2930  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"
     
    3536LX_CHECK_SOPLEX
    3637
    37 dnl Disable/enable building the demo programs
     38dnl Disable/enable building the demo programs.
    3839AC_ARG_ENABLE([demo],
    3940AS_HELP_STRING([--enable-demo], [build the demo programs])
     
    4849AM_CONDITIONAL([WANT_DEMO], [test x"$enable_demo" != x"no"])
    4950
    50 dnl Disable/enable building the binary tools
     51dnl Disable/enable building the binary tools.
    5152AC_ARG_ENABLE([tools],
    5253AS_HELP_STRING([--enable-tools], [build additional tools @<:@default@:>@])
     
    6162AM_CONDITIONAL([WANT_TOOLS], [test x"$enable_tools" != x"no"])
    6263
    63 dnl Disable/enable building the benchmarks
     64dnl Disable/enable building the benchmarks.
    6465AC_ARG_ENABLE([benchmark],
    6566AS_HELP_STRING([--enable-benchmark], [build the benchmarks])
     
    8788AC_HEADER_STDC
    8889AC_CHECK_FUNCS(gettimeofday times ctime_r)
     90
     91dnl Add dependencies on files generated by configure.
     92AC_SUBST([CONFIG_STATUS_DEPENDENCIES],
     93  ['$(top_srcdir)/doc/Doxyfile.in $(top_srcdir)/lemon/lemon.pc.in'])
    8994
    9095AC_CONFIG_FILES([
  • demo/CMakeLists.txt

    r141 r225  
    1 include_directories (${LEMON_SOURCE_DIR})
     1INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR})
    22
    3 link_directories (${LEMON_BINARY_DIR}/lemon)
     3LINK_DIRECTORIES(${CMAKE_BINARY_DIR}/lemon)
    44
    5 set (DEMOS
     5SET(DEMOS
    66  arg_parser_demo
    77  graph_to_eps_demo
    88  lgf_demo)
    99
    10 foreach (DEMO_NAME ${DEMOS})
    11   add_executable (${DEMO_NAME} ${DEMO_NAME}.cc)
    12   target_link_libraries (${DEMO_NAME} lemon)
    13   endforeach (DEMO_NAME)
     10FOREACH(DEMO_NAME ${DEMOS})
     11  ADD_EXECUTABLE(${DEMO_NAME} ${DEMO_NAME}.cc)
     12  TARGET_LINK_LIBRARIES(${DEMO_NAME} lemon)
     13ENDFOREACH(DEMO_NAME)
  • demo/graph_to_eps_demo.cc

    r211 r220  
    3232
    3333#include<lemon/list_graph.h>
    34 #include<lemon/graph_utils.h>
    3534#include<lemon/graph_to_eps.h>
    3635#include<lemon/math.h>
  • doc/Doxyfile.in

    r212 r226  
    1616INLINE_INHERITED_MEMB  = NO
    1717FULL_PATH_NAMES        = YES
    18 STRIP_FROM_PATH        = @abs_top_srcdir@
    19 STRIP_FROM_INC_PATH    = @abs_top_srcdir@
     18STRIP_FROM_PATH        = "@abs_top_srcdir@"
     19STRIP_FROM_INC_PATH    = "@abs_top_srcdir@"
    2020SHORT_NAMES            = YES
    2121JAVADOC_AUTOBRIEF      = NO
     
    8181# configuration options related to the input files
    8282#---------------------------------------------------------------------------
    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.h
     83INPUT                  = "@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"
    9090INPUT_ENCODING         = UTF-8
    9191FILE_PATTERNS          = *.h \
     
    9797EXCLUDE_PATTERNS       =
    9898EXCLUDE_SYMBOLS        =
    99 EXAMPLE_PATH           = @abs_top_srcdir@/demo \
    100                          @abs_top_srcdir@/LICENSE \
    101                          @abs_top_srcdir@/doc
     99EXAMPLE_PATH           = "@abs_top_srcdir@/demo" \
     100                         "@abs_top_srcdir@/LICENSE" \
     101                         "@abs_top_srcdir@/doc"
    102102EXAMPLE_PATTERNS       =
    103103EXAMPLE_RECURSIVE      = NO
    104 IMAGE_PATH             = @abs_top_srcdir@/doc/images \
    105                          @abs_top_builddir@/doc/gen-images
     104IMAGE_PATH             = "@abs_top_srcdir@/doc/images" \
     105                         "@abs_top_builddir@/doc/gen-images"
    106106INPUT_FILTER           =
    107107FILTER_PATTERNS        =
     
    146146DISABLE_INDEX          = NO
    147147ENUM_VALUES_PER_LINE   = 4
    148 GENERATE_TREEVIEW      = YES
     148GENERATE_TREEVIEW      = NO
    149149TREEVIEW_WIDTH         = 250
    150150#---------------------------------------------------------------------------
  • doc/Makefile.am

    r156 r227  
    88        doc/mainpage.dox \
    99        doc/namespaces.dox \
    10         doc/html
     10        doc/html \
     11        doc/CMakeLists.txt
    1112
    1213DOC_EPS_IMAGES18 = \
  • doc/groups.dox

    r210 r236  
    326326maximum cardinality matching.
    327327
    328 Lemon contains the next algorithms:
     328LEMON contains the next algorithms:
    329329- \ref lemon::MaxBipartiteMatching "MaxBipartiteMatching" Hopcroft-Karp
    330330  augmenting path algorithm for calculate maximum cardinality matching in
     
    477477
    478478/**
    479 @defgroup lemon_io Lemon Input-Output
     479@defgroup lemon_io LEMON Input-Output
    480480@ingroup io_group
    481 \brief Reading and writing \ref lgf-format "Lemon Graph Format".
     481\brief Reading and writing \ref lgf-format "LEMON Graph Format".
    482482
    483483This group describes methods for reading and writing
    484 \ref lgf-format "Lemon Graph Format".
     484\ref lgf-format "LEMON Graph Format".
    485485*/
    486486
  • doc/lgf.dox

    r212 r236  
    2222
    2323
    24 \page lgf-format Lemon Graph Format (LGF)
     24\page lgf-format LEMON Graph Format (LGF)
    2525
    2626The \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)
     1INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR})
     2
     3ADD_LIBRARY(lemon
     4  arg_parser.cc
     5  base.cc
     6  color.cc
     7  random.cc)
     8
     9INSTALL(
     10  TARGETS lemon
     11  ARCHIVE DESTINATION lib
     12  COMPONENT library)
     13
     14INSTALL(
     15  DIRECTORY . bits concepts
     16  DESTINATION include/lemon
     17  COMPONENT headers
     18  FILES_MATCHING PATTERN "*.h")
  • lemon/Makefile.am

    r195 r220  
    2525        lemon/concept_check.h \
    2626        lemon/counter.h \
     27        lemon/core.h \
    2728        lemon/dfs.h \
    2829        lemon/dijkstra.h \
     
    3031        lemon/error.h \
    3132        lemon/graph_to_eps.h \
    32         lemon/graph_utils.h \
    3333        lemon/kruskal.h \
    3434        lemon/lgf_reader.h \
     
    5050        lemon/bits/bezier.h \
    5151        lemon/bits/default_map.h \
     52        lemon/bits/enable_if.h \
    5253        lemon/bits/graph_extender.h \
    53         lemon/bits/invalid.h \
    5454        lemon/bits/map_extender.h \
    5555        lemon/bits/path_dump.h \
    5656        lemon/bits/traits.h \
    57         lemon/bits/utility.h \
    5857        lemon/bits/vector_map.h
    5958
  • lemon/assert.h

    r212 r218  
    238238
    239239#    if LEMON_ENABLE_DEBUG
    240 #      define LEMON_DEBUG(exp, msg)
     240#      define LEMON_DEBUG(exp, msg)                                     \
    241241         (static_cast<void> (!!(exp) ? 0 : (                            \
    242242           LEMON_ASSERT_HANDLER(__FILE__, __LINE__,                     \
  • lemon/base.cc

    r209 r220  
    2121
    2222#include<lemon/tolerance.h>
    23 #include<lemon/bits/invalid.h>
     23#include<lemon/core.h>
    2424namespace lemon {
    2525
  • lemon/bfs.h

    r244 r247  
    2525
    2626#include <lemon/list_graph.h>
    27 #include <lemon/graph_utils.h>
    2827#include <lemon/bits/path_dump.h>
    29 #include <lemon/bits/invalid.h>
     28#include <lemon/core.h>
    3029#include <lemon/error.h>
    3130#include <lemon/maps.h>
  • lemon/bits/alteration_notifier.h

    r209 r236  
    2323#include <list>
    2424
    25 #include <lemon/bits/utility.h>
     25#include <lemon/core.h>
    2626
    2727///\ingroup graphbits
     
    4242  ///
    4343  /// The graph's node and edge sets can be changed as we add or erase
    44   /// nodes and edges in the graph. Lemon would like to handle easily
     44  /// nodes and edges in the graph. LEMON would like to handle easily
    4545  /// that the node and edge maps should contain values for all nodes or
    4646  /// edges. If we want to check on every indicing if the map contains
     
    410410          ++it;
    411411        } catch (const ImmediateDetach&) {
    412           it = _observers.erase(it);
    413412          (*it)->_index = _observers.end();
    414413          (*it)->_notifier = 0;
     414          it = _observers.erase(it);
    415415        }
    416416      }
     
    430430          ++it;
    431431        } catch (const ImmediateDetach&) {
    432           it = _observers.erase(it);
    433432          (*it)->_index = _observers.end();
    434433          (*it)->_notifier = 0;
     434          it = _observers.erase(it);
    435435        }
    436436      }
     
    469469          ++it;
    470470        } catch (const ImmediateDetach&) {
    471           it = _observers.erase(it);
    472471          (*it)->_index = _observers.end();
    473472          (*it)->_notifier = 0;
     473          it = _observers.erase(it);
    474474        }
    475475      }
  • lemon/bits/base_extender.h

    r209 r220  
    2020#define LEMON_BITS_BASE_EXTENDER_H
    2121
    22 #include <lemon/bits/invalid.h>
     22#include <lemon/core.h>
    2323#include <lemon/error.h>
    2424
  • lemon/bits/graph_extender.h

    r209 r220  
    2020#define LEMON_BITS_GRAPH_EXTENDER_H
    2121
    22 #include <lemon/bits/invalid.h>
    23 #include <lemon/bits/utility.h>
     22#include <lemon/core.h>
    2423
    2524#include <lemon/bits/map_extender.h>
  • lemon/bits/traits.h

    r209 r220  
    2020#define LEMON_BITS_TRAITS_H
    2121
    22 #include <lemon/bits/utility.h>
    23 
    2422///\file
    2523///\brief Traits for graphs and maps
    2624///
    2725
     26#include <lemon/bits/enable_if.h>
     27
    2828namespace lemon {
     29
     30  struct InvalidType {};
     31
    2932  template <typename _Graph, typename _Item>
    3033  class ItemSetTraits {};
  • lemon/bits/vector_map.h

    r209 r220  
    2323#include <algorithm>
    2424
    25 #include <lemon/bits/traits.h>
    26 #include <lemon/bits/utility.h>
    27 
     25#include <lemon/core.h>
    2826#include <lemon/bits/alteration_notifier.h>
    2927
  • lemon/concepts/digraph.h

    r209 r220  
    2424///\brief The concept of directed graphs.
    2525
    26 #include <lemon/bits/invalid.h>
    27 #include <lemon/bits/utility.h>
     26#include <lemon/core.h>
    2827#include <lemon/concepts/maps.h>
    2928#include <lemon/concept_check.h>
  • lemon/concepts/graph.h

    r209 r220  
    2626#include <lemon/concepts/graph_components.h>
    2727#include <lemon/concepts/graph.h>
    28 #include <lemon/bits/utility.h>
     28#include <lemon/core.h>
    2929
    3030namespace lemon {
  • lemon/concepts/graph_components.h

    r209 r220  
    2525#define LEMON_CONCEPT_GRAPH_COMPONENTS_H
    2626
    27 #include <lemon/bits/invalid.h>
     27#include <lemon/core.h>
    2828#include <lemon/concepts/maps.h>
    2929
  • lemon/concepts/heap.h

    r209 r220  
    2424#define LEMON_CONCEPT_HEAP_H
    2525
    26 #include <lemon/bits/invalid.h>
     26#include <lemon/core.h>
    2727
    2828namespace lemon {
  • lemon/concepts/maps.h

    r210 r220  
    2020#define LEMON_CONCEPT_MAPS_H
    2121
    22 #include <lemon/bits/utility.h>
     22#include <lemon/core.h>
    2323#include <lemon/concept_check.h>
    2424
  • lemon/concepts/path.h

    r212 r236  
    2626#define LEMON_CONCEPT_PATH_H
    2727
    28 #include <lemon/bits/invalid.h>
    29 #include <lemon/bits/utility.h>
     28#include <lemon/core.h>
    3029#include <lemon/concept_check.h>
    3130
     
    7978      void clear() {}
    8079
    81       /// \brief Lemon style iterator for path arcs
     80      /// \brief LEMON style iterator for path arcs
    8281      ///
    8382      /// This class is used to iterate on the arcs of the paths.
     
    202201    /// If we would like to give back a real path from these
    203202    /// algorithms then we should create a temporarly path object. In
    204     /// Lemon such algorithms gives back a path dumper what can
     203    /// LEMON such algorithms gives back a path dumper what can
    205204    /// assigned to a real path and the dumpers can be implemented as
    206205    /// an adaptor class to the predecessor map.
     
    234233      typedef False RevPathTag;
    235234
    236       /// \brief Lemon style iterator for path arcs
     235      /// \brief LEMON style iterator for path arcs
    237236      ///
    238237      /// This class is used to iterate on the arcs of the paths.
     
    261260      };
    262261
    263       /// \brief Lemon style iterator for path arcs
     262      /// \brief LEMON style iterator for path arcs
    264263      ///
    265264      /// This class is used to iterate on the arcs of the paths in
  • lemon/dfs.h

    r244 r247  
    2525
    2626#include <lemon/list_graph.h>
    27 #include <lemon/graph_utils.h>
    2827#include <lemon/bits/path_dump.h>
    29 #include <lemon/bits/invalid.h>
     28#include <lemon/core.h>
    3029#include <lemon/error.h>
    3130#include <lemon/assert.h>
  • lemon/dijkstra.h

    r244 r247  
    2828#include <lemon/bin_heap.h>
    2929#include <lemon/bits/path_dump.h>
    30 #include <lemon/bits/invalid.h>
     30#include <lemon/core.h>
    3131#include <lemon/error.h>
    3232#include <lemon/maps.h>
  • lemon/dim2.h

    r209 r241  
    2121
    2222#include <iostream>
    23 #include <lemon/bits/utility.h>
    2423
    2524///\ingroup misc
     
    4645  /// @{
    4746
    48   /// A simple two dimensional vector (plainvector) implementation
    49 
    50   /// A simple two dimensional vector (plainvector) implementation
     47  /// A simple two dimensional vector (plain vector) implementation
     48
     49  /// A simple two dimensional vector (plain vector) implementation
    5150  /// with the usual vector operations.
    5251  template<typename T>
     
    187186  }
    188187
    189   ///Read a plainvector from a stream
    190 
    191   ///Read a plainvector from a stream.
     188  ///Read a plain vector from a stream
     189
     190  ///Read a plain vector from a stream.
    192191  ///\relates Point
    193192  ///
     
    215214  }
    216215
    217   ///Write a plainvector to a stream
    218 
    219   ///Write a plainvector to a stream.
     216  ///Write a plain vector to a stream
     217
     218  ///Write a plain vector to a stream.
    220219  ///\relates Point
    221220  ///
     
    262261
    263262
    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    ///
    268267    template<typename T>
    269268    class BoundingBox {
    270       Point<T> bottom_left, top_right;
     269      Point<T> _bottom_left, _top_right;
    271270      bool _empty;
    272271    public:
     
    276275
    277276      ///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      }
    279281
    280282      ///Construct an instance from two points
     
    287289      BoundingBox(Point<T> a,Point<T> b)
    288290      {
    289         bottom_left=a;
    290         top_right=b;
     291        _bottom_left = a;
     292        _top_right = b;
    291293        _empty = false;
    292294      }
     
    303305      BoundingBox(T l,T b,T r,T t)
    304306      {
    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);
    307309        _empty = false;
    308310      }
     
    321323      ///Make the BoundingBox empty
    322324      void clear() {
    323         _empty=1;
     325        _empty = true;
    324326      }
    325327
     
    329331      ///If the bounding box is empty, then the return value is not defined.
    330332      Point<T> bottomLeft() const {
    331         return bottom_left;
     333        return _bottom_left;
    332334      }
    333335
     
    335337
    336338      ///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.
    338340      void bottomLeft(Point<T> p) {
    339         bottom_left = p;
     341        _bottom_left = p;
    340342      }
    341343
     
    345347      ///If the bounding box is empty, then the return value is not defined.
    346348      Point<T> topRight() const {
    347         return top_right;
     349        return _top_right;
    348350      }
    349351
     
    351353
    352354      ///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.
    354356      void topRight(Point<T> p) {
    355         top_right = p;
     357        _top_right = p;
    356358      }
    357359
     
    361363      ///If the bounding box is empty, then the return value is not defined.
    362364      Point<T> bottomRight() const {
    363         return Point<T>(top_right.x,bottom_left.y);
     365        return Point<T>(_top_right.x,_bottom_left.y);
    364366      }
    365367
     
    367369
    368370      ///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.
    370372      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;
    373375      }
    374376
     
    378380      ///If the bounding box is empty, then the return value is not defined.
    379381      Point<T> topLeft() const {
    380         return Point<T>(bottom_left.x,top_right.y);
     382        return Point<T>(_bottom_left.x,_top_right.y);
    381383      }
    382384
     
    384386
    385387      ///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.
    387389      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;
    390392      }
    391393
     
    395397      ///If the bounding box is empty, then the return value is not defined.
    396398      T bottom() const {
    397         return bottom_left.y;
     399        return _bottom_left.y;
    398400      }
    399401
     
    401403
    402404      ///Set the bottom of the box.
    403       ///It should only be used for non-empty box.
     405      ///\pre The box must not be empty.
    404406      void bottom(T t) {
    405         bottom_left.y = t;
     407        _bottom_left.y = t;
    406408      }
    407409
     
    411413      ///If the bounding box is empty, then the return value is not defined.
    412414      T top() const {
    413         return top_right.y;
     415        return _top_right.y;
    414416      }
    415417
     
    417419
    418420      ///Set the top of the box.
    419       ///It should only be used for non-empty box.
     421      ///\pre The box must not be empty.
    420422      void top(T t) {
    421         top_right.y = t;
     423        _top_right.y = t;
    422424      }
    423425
     
    427429      ///If the bounding box is empty, then the return value is not defined.
    428430      T left() const {
    429         return bottom_left.x;
     431        return _bottom_left.x;
    430432      }
    431433
     
    433435
    434436      ///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.
    436438      void left(T t) {
    437         bottom_left.x = t;
     439        _bottom_left.x = t;
    438440      }
    439441
     
    443445      ///If the bounding box is empty, then the return value is not defined.
    444446      T right() const {
    445         return top_right.x;
     447        return _top_right.x;
    446448      }
    447449
     
    449451
    450452      ///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.
    452454      void right(T t) {
    453         top_right.x = t;
     455        _top_right.x = t;
    454456      }
    455457
     
    459461      ///If the bounding box is empty, then the return value is not defined.
    460462      T height() const {
    461         return top_right.y-bottom_left.y;
     463        return _top_right.y-_bottom_left.y;
    462464      }
    463465
     
    467469      ///If the bounding box is empty, then the return value is not defined.
    468470      T width() const {
    469         return top_right.x-bottom_left.x;
     471        return _top_right.x-_bottom_left.x;
    470472      }
    471473
     
    474476        if (_empty)
    475477          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 );
    479481        }
    480482      }
     
    485487      ///
    486488      BoundingBox& add(const Point<T>& u){
    487         if (_empty){
    488           bottom_left=top_right=u;
     489        if (_empty) {
     490          _bottom_left = _top_right = u;
    489491          _empty = false;
    490492        }
    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;
    496498        }
    497499        return *this;
     
    504506      BoundingBox& add(const BoundingBox &u){
    505507        if ( !u.empty() ){
    506           this->add(u.bottomLeft());
    507           this->add(u.topRight());
     508          add(u._bottom_left);
     509          add(u._top_right);
    508510        }
    509511        return *this;
     
    516518      BoundingBox operator&(const BoundingBox& u) const {
    517519        BoundingBox b;
    518         if (this->_empty || u._empty) {
     520        if (_empty || u._empty) {
    519521          b._empty = true;
    520522        } 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;
    527529        }
    528530        return b;
  • lemon/graph_to_eps.h

    r212 r220  
    3636
    3737#include<lemon/math.h>
    38 #include<lemon/bits/invalid.h>
     38#include<lemon/core.h>
    3939#include<lemon/dim2.h>
    4040#include<lemon/maps.h>
  • lemon/kruskal.h

    r216 r220  
    2323#include <vector>
    2424#include <lemon/unionfind.h>
    25 // #include <lemon/graph_utils.h>
    2625#include <lemon/maps.h>
    2726
    28 // #include <lemon/radix_sort.h>
    29 
    30 #include <lemon/bits/utility.h>
     27#include <lemon/core.h>
    3128#include <lemon/bits/traits.h>
    3229
     
    301298  /// \return The total cost of the found spanning tree.
    302299  ///
    303   /// \note If the input graph is not (weakly) connected, a spanning 
     300  /// \note If the input graph is not (weakly) connected, a spanning
    304301  /// forest is calculated instead of a spanning tree.
    305302
  • lemon/lgf_reader.h

    r212 r236  
    1919///\ingroup lemon_io
    2020///\file
    21 ///\brief \ref lgf-format "Lemon Graph Format" reader.
     21///\brief \ref lgf-format "LEMON Graph Format" reader.
    2222
    2323
     
    3333
    3434#include <lemon/assert.h>
    35 #include <lemon/graph_utils.h>
     35#include <lemon/core.h>
    3636
    3737#include <lemon/lgf_writer.h>
     
    23022302  ///
    23032303  /// This class can be used to read the sections, the map names and
    2304   /// the attributes from a file. Usually, the Lemon programs know
     2304  /// the attributes from a file. Usually, the LEMON programs know
    23052305  /// that, which type of graph, which maps and which attributes
    23062306  /// should be read from a file, but in general tools (like glemon)
  • lemon/lgf_writer.h

    r212 r240  
    1919///\ingroup lemon_io
    2020///\file
    21 ///\brief \ref lgf-format "Lemon Graph Format" writer.
     21///\brief \ref lgf-format "LEMON Graph Format" writer.
    2222
    2323
     
    3535
    3636#include <lemon/assert.h>
    37 #include <lemon/graph_utils.h>
     37#include <lemon/core.h>
     38#include <lemon/maps.h>
    3839
    3940namespace lemon {
     
    934935    bool local_os;
    935936
    936     Graph& _graph;
     937    const Graph& _graph;
    937938
    938939    std::string _nodes_caption;
  • lemon/list_graph.h

    r212 r239  
    2424///\brief ListDigraph, ListGraph classes.
    2525
     26#include <lemon/core.h>
     27#include <lemon/error.h>
    2628#include <lemon/bits/graph_extender.h>
    2729
     
    362364    }
    363365
     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
    364378    /// Node validity check
    365379
     
    382396    bool valid(Arc a) const { return Parent::valid(a); }
    383397
    384     /// Change the target of \c e to \c n
    385 
    386     /// Change the target of \c e to \c n
     398    /// Change the target of \c a to \c n
     399
     400    /// Change the target of \c a to \c n
    387401    ///
    388402    ///\note The <tt>ArcIt</tt>s and <tt>OutArcIt</tt>s referencing
     
    392406    ///\warning This functionality cannot be used together with the Snapshot
    393407    ///feature.
    394     void changeTarget(Arc e, Node n) {
    395       Parent::changeTarget(e,n);
    396     }
    397     /// Change the source of \c e to \c n
    398 
    399     /// Change the source of \c e to \c n
    400     ///
    401     ///\note The <tt>ArcIt</tt>s and <tt>InArcIt</tt>s referencing
    402     ///the changed arc remain valid. However <tt>OutArcIt</tt>s are
     408    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
    403417    ///invalidated.
    404418    ///
    405419    ///\warning This functionality cannot be used together with the Snapshot
    406420    ///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);
    409423    }
    410424
     
    829843
    830844    public:
    831       operator Edge() const { return edgeFromId(id / 2); }
     845      operator Edge() const {
     846        return id != -1 ? edgeFromId(id / 2) : INVALID;
     847      }
    832848
    833849      Arc() {}
     
    11011117  protected:
    11021118
    1103     void changeTarget(Edge e, Node n) {
     1119    void changeV(Edge e, Node n) {
    11041120      if(arcs[2 * e.id].next_out != -1) {
    11051121        arcs[arcs[2 * e.id].next_out].prev_out = arcs[2 * e.id].prev_out;
     
    11221138    }
    11231139
    1124     void changeSource(Edge e, Node n) {
     1140    void changeU(Edge e, Node n) {
    11251141      if(arcs[(2 * e.id) | 1].next_out != -1) {
    11261142        arcs[arcs[(2 * e.id) | 1].next_out].prev_out =
     
    12061222      return Parent::addEdge(s, t);
    12071223    }
     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); }
    12081236    /// Node validity check
    12091237
     
    12331261    /// added to the graph.
    12341262    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.
    12421271    ///
    12431272    ///\warning This functionality cannot be used together with the
    12441273    ///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.
    12541284    ///
    12551285    ///\warning This functionality cannot be used together with the
    12561286    ///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);
    12951289    }
    12961290    /// \brief Contract two nodes.
     
    13121306        if (r && runningNode(e) == a) {
    13131307          erase(e);
    1314         } else if (source(e) == b) {
    1315           changeSource(e, a);
     1308        } else if (u(e) == b) {
     1309          changeU(e, a);
    13161310        } else {
    1317           changeTarget(e, a);
     1311          changeV(e, a);
    13181312        }
    13191313        e = f;
  • lemon/maps.h

    r209 r220  
    2424#include <vector>
    2525
    26 #include <lemon/bits/utility.h>
    27 #include <lemon/bits/traits.h>
     26#include <lemon/core.h>
    2827
    2928///\file
     
    17811780  }
    17821781
     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
    17832702  /// @}
    17842703}
  • lemon/path.h

    r209 r236  
    2929
    3030#include <lemon/error.h>
    31 #include <lemon/bits/invalid.h>
     31#include <lemon/core.h>
    3232#include <lemon/concepts/path.h>
    3333
     
    8383    }
    8484
    85     /// \brief Lemon style iterator for path arcs
     85    /// \brief LEMON style iterator for path arcs
    8686    ///
    8787    /// This class is used to iterate on the arcs of the paths.
  • lemon/smart_graph.h

    r209 r238  
    2626#include <vector>
    2727
    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>
    3429#include <lemon/error.h>
    35 
    3630#include <lemon/bits/graph_extender.h>
    3731
     
    472466
    473467    public:
    474       operator Edge() const { return edgeFromId(_id / 2); }
     468      operator Edge() const {
     469        return _id != -1 ? edgeFromId(_id / 2) : INVALID;
     470      }
    475471
    476472      Arc() {}
  • lemon/unionfind.h

    r209 r236  
    3131#include <functional>
    3232
    33 #include <lemon/bits/invalid.h>
     33#include <lemon/core.h>
    3434
    3535namespace lemon {
     
    498498    }
    499499
    500     /// \brief Lemon style iterator for the representant items.
     500    /// \brief LEMON style iterator for the representant items.
    501501    ///
    502502    /// ClassIt is a lemon style iterator for the components. It iterates
     
    550550    };
    551551
    552     /// \brief Lemon style iterator for the items of a component.
     552    /// \brief LEMON style iterator for the items of a component.
    553553    ///
    554554    /// ClassIt is a lemon style iterator for the components. It iterates
     
    808808    }
    809809
    810     /// \brief Lemon style iterator for the classes.
     810    /// \brief LEMON style iterator for the classes.
    811811    ///
    812812    /// ClassIt is a lemon style iterator for the components. It iterates
     
    860860    };
    861861
    862     /// \brief Lemon style iterator for the items of a component.
     862    /// \brief LEMON style iterator for the items of a component.
    863863    ///
    864864    /// ClassIt is a lemon style iterator for the components. It iterates
     
    16561656    }
    16571657
    1658     /// \brief Lemon style iterator for the items of a class.
     1658    /// \brief LEMON style iterator for the items of a class.
    16591659    ///
    16601660    /// ClassIt is a lemon style iterator for the components. It iterates
  • test/CMakeLists.txt

    r203 r225  
    1 include_directories (${LEMON_SOURCE_DIR})
     1INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR})
    22
    3 link_directories (${LEMON_BINARY_DIR}/lemon)
     3LINK_DIRECTORIES(${CMAKE_BINARY_DIR}/lemon)
    44
    5 set (TESTS
     5SET(TESTS
    66  bfs_test
    77  counter_test
     
    1717  kruskal_test
    1818  maps_test
     19  random_test
    1920  path_test
    20   random_test
    2121  time_measure_test
    2222  unionfind_test)
    2323
    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)
     24FOREACH(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})
     28ENDFOREACH(TEST_NAME)
  • test/Makefile.am

    r203 r228  
    44noinst_HEADERS += \
    55        test/graph_test.h \
    6         test/graph_maps_test.h \
    76        test/test_tools.h
    87
  • test/bfs_test.cc

    r209 r228  
    2020#include <lemon/smart_graph.h>
    2121#include <lemon/list_graph.h>
     22#include <lemon/lgf_reader.h>
    2223#include <lemon/bfs.h>
    2324#include <lemon/path.h>
     
    2728
    2829using namespace lemon;
     30
     31char 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";
    2952
    3053void checkBfsCompile()
     
    5073  n  = bfs_test.predNode(n);
    5174  d  = bfs_test.distMap();
     75
    5276  p  = bfs_test.predMap();
    5377  //  pn = bfs_test.predNodeMap();
     
    81105  Digraph G;
    82106  Node s, t;
    83   PetStruct<Digraph> ps = addPetersen(G, 5);
    84107
    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();
    87113
    88114  Bfs<Digraph> bfs_test(G);
    89115  bfs_test.run(s);
    90116
    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));
    92118
    93119  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.");
    95121  check(checkPath(G, p),"path() found a wrong path.");
    96122  check(pathSource(G, p) == s,"path() found a wrong path.");
     
    98124
    99125
    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);
    103129    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));
    106132  }
    107133
    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      }
    118146    }
    119147  }
  • test/dfs_test.cc

    r209 r228  
    2020#include <lemon/smart_graph.h>
    2121#include <lemon/list_graph.h>
     22#include <lemon/lgf_reader.h>
     23
    2224#include <lemon/dfs.h>
    2325#include <lemon/path.h>
     
    2729
    2830using namespace lemon;
     31
     32char 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";
    2955
    3056void checkDfsCompile()
     
    4066  DType::DistMap d(G);
    4167  DType::PredMap p(G);
    42   //  DType::PredNodeMap pn(G);
    4368
    4469  DType dfs_test(G);
     
    5176  d  = dfs_test.distMap();
    5277  p  = dfs_test.predMap();
    53   //  pn = dfs_test.predNodeMap();
    5478  b  = dfs_test.reached(n);
    5579
     
    81105  Digraph G;
    82106  Node s, t;
    83   PetStruct<Digraph> ps = addPetersen(G, 5);
    84107
    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();
    87113
    88114  Dfs<Digraph> dfs_test(G);
     
    96122
    97123  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      }
    106134    }
    107135  }
  • test/digraph_test.cc

    r209 r228  
    2525#include "test_tools.h"
    2626#include "graph_test.h"
    27 #include "graph_maps_test.h"
    2827
    2928using namespace lemon;
    3029using namespace lemon::concepts;
    3130
    32 void check_concepts() {
     31template <class Digraph>
     32void 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
     83void checkConcepts() {
    3384  { // Checking digraph components
    3485    checkConcept<BaseDigraphComponent, BaseDigraphComponent >();
     
    52103    checkConcept<ClearableDigraphComponent<>, ListDigraph>();
    53104    checkConcept<ErasableDigraphComponent<>, ListDigraph>();
    54     checkDigraphIterators<ListDigraph>();
    55105  }
    56106  { // Checking SmartDigraph
     
    59109    checkConcept<ExtendableDigraphComponent<>, SmartDigraph>();
    60110    checkConcept<ClearableDigraphComponent<>, SmartDigraph>();
    61     checkDigraphIterators<SmartDigraph>();
    62111  }
    63112//  { // Checking FullDigraph
    64113//    checkConcept<Digraph, FullDigraph>();
    65 //    checkDigraphIterators<FullDigraph>();
    66114//  }
    67115//  { // Checking HyperCubeDigraph
    68116//    checkConcept<Digraph, HyperCubeDigraph>();
    69 //    checkDigraphIterators<HyperCubeDigraph>();
    70117//  }
    71118}
    72119
    73120template <typename Digraph>
    74 void check_graph_validity() {
     121void checkDigraphValidity() {
    75122  TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
    76123  Digraph g;
     
    93140
    94141template <typename Digraph>
    95 void check_graph_validity_erase() {
     142void checkDigraphValidityErase() {
    96143  TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
    97144  Digraph g;
     
    121168}
    122169
    123 void check_digraphs() {
     170void checkDigraphs() {
    124171  { // Checking ListDigraph
    125172    checkDigraph<ListDigraph>();
    126     checkGraphNodeMap<ListDigraph>();
    127     checkGraphArcMap<ListDigraph>();
    128 
    129     check_graph_validity_erase<ListDigraph>();
     173    checkDigraphValidityErase<ListDigraph>();
    130174  }
    131175  { // Checking SmartDigraph
    132176    checkDigraph<SmartDigraph>();
    133     checkGraphNodeMap<SmartDigraph>();
    134     checkGraphArcMap<SmartDigraph>();
    135 
    136     check_graph_validity<SmartDigraph>();
     177    checkDigraphValidity<SmartDigraph>();
    137178  }
    138179}
    139180
    140181int main() {
    141   check_concepts();
    142   check_digraphs();
     182  checkDigraphs();
     183  checkConcepts();
    143184  return 0;
    144185}
  • test/dijkstra_test.cc

    r210 r228  
    2020#include <lemon/smart_graph.h>
    2121#include <lemon/list_graph.h>
    22 #include <lemon/graph_utils.h>
     22#include <lemon/lgf_reader.h>
     23
    2324#include <lemon/dijkstra.h>
    2425#include <lemon/path.h>
     
    2829
    2930using namespace lemon;
     31
     32char 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";
    3052
    3153void checkDijkstraCompile()
     
    86108  Node s, t;
    87109  LengthMap length(G);
    88   PetStruct<Digraph> ps = addPetersen(G, 5);
    89110
    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();
    97117
    98118  Dijkstra<Digraph, LengthMap>
     
    100120  dijkstra_test.run(s);
    101121
    102   check(dijkstra_test.dist(t)==13,"Dijkstra found a wrong path.");
     122  check(dijkstra_test.dist(t)==3,"Dijkstra found a wrong path.");
    103123
    104124  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.");
    106126  check(checkPath(G, p),"path() found a wrong path.");
    107127  check(pathSource(G, p) == s,"path() found a wrong path.");
     
    117137  }
    118138
    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      }
    128150    }
    129151  }
  • test/dim_test.cc

    r209 r242  
    5959  box1.add(b);
    6060
    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,
    6563        "Wrong addition of points to dim2::BoundingBox.");
    6664
    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.");
    6968
    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));
    7770  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.");
    8185
    8286  return 0;
  • test/error_test.cc

    r209 r223  
    3030#ifdef LEMON_DISABLE_ASSERTS
    3131#undef LEMON_DISABLE_ASSERTS
     32#endif
     33
     34#ifdef NDEBUG
     35#undef NDEBUG
    3236#endif
    3337
  • test/graph_copy_test.cc

    r209 r220  
    2020#include <lemon/list_graph.h>
    2121#include <lemon/lgf_reader.h>
    22 #include <lemon/graph_utils.h>
    2322#include <lemon/error.h>
    2423
  • test/graph_test.cc

    r209 r228  
    2525#include "test_tools.h"
    2626#include "graph_test.h"
    27 #include "graph_maps_test.h"
    2827
    2928using namespace lemon;
    3029using namespace lemon::concepts;
    3130
    32 void check_concepts() {
     31template <class Graph>
     32void 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
     98void checkConcepts() {
    3399  { // Checking graph components
    34100    checkConcept<BaseGraphComponent, BaseGraphComponent >();
     
    52118    checkConcept<ClearableGraphComponent<>, ListGraph>();
    53119    checkConcept<ErasableGraphComponent<>, ListGraph>();
    54     checkGraphIterators<ListGraph>();
    55120  }
    56121  { // Checking SmartGraph
     
    59124    checkConcept<ExtendableGraphComponent<>, SmartGraph>();
    60125    checkConcept<ClearableGraphComponent<>, SmartGraph>();
    61     checkGraphIterators<SmartGraph>();
    62126  }
    63127//  { // Checking FullGraph
     
    72136
    73137template <typename Graph>
    74 void check_graph_validity() {
     138void checkGraphValidity() {
    75139  TEMPLATE_GRAPH_TYPEDEFS(Graph);
    76140  Graph g;
     
    95159
    96160template <typename Graph>
    97 void check_graph_validity_erase() {
     161void checkGraphValidityErase() {
    98162  TEMPLATE_GRAPH_TYPEDEFS(Graph);
    99163  Graph g;
     
    169233// }
    170234
    171 void check_graphs() {
     235void checkGraphs() {
    172236  { // Checking ListGraph
    173237    checkGraph<ListGraph>();
    174     checkGraphNodeMap<ListGraph>();
    175     checkGraphEdgeMap<ListGraph>();
    176 
    177     check_graph_validity_erase<ListGraph>();
     238    checkGraphValidityErase<ListGraph>();
    178239  }
    179240  { // Checking SmartGraph
    180241    checkGraph<SmartGraph>();
    181     checkGraphNodeMap<SmartGraph>();
    182     checkGraphEdgeMap<SmartGraph>();
    183 
    184     check_graph_validity<SmartGraph>();
     242    checkGraphValidity<SmartGraph>();
    185243  }
    186244//   { // Checking FullGraph
     
    198256
    199257int main() {
    200   check_concepts();
    201   check_graphs();
     258  checkConcepts();
     259  checkGraphs();
    202260  return 0;
    203261}
  • test/graph_test.h

    r209 r228  
    2020#define LEMON_TEST_GRAPH_TEST_H
    2121
    22 #include <lemon/graph_utils.h>
     22#include <set>
     23
     24#include <lemon/core.h>
     25#include <lemon/maps.h>
     26
    2327#include "test_tools.h"
    2428
     
    4347    for(int i=0;i<cnt;i++) {
    4448      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");
    4553      ++e;
    4654    }
     
    5664      check(e!=INVALID,"Wrong OutArc list linking.");
    5765      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.");
    5868      ++e;
    5969    }
     
    6979      check(e!=INVALID,"Wrong InArc list linking.");
    7080      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.");
    7183      ++e;
    7284    }
     
    8193    for(int i=0;i<cnt;i++) {
    8294      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");
    8397      ++e;
    8498    }
     
    94108      check(e!=INVALID,"Wrong IncEdge list linking.");
    95109      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.");
    96113      ++e;
    97114    }
     
    100117  }
    101118
    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 
    112119  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) {
    115253    typedef typename Graph::Edge Edge;
    116254    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
    259281
    260282} //namespace lemon
  • test/graph_utils_test.cc

    r210 r220  
    2121
    2222#include <lemon/random.h>
    23 #include <lemon/graph_utils.h>
    2423#include <lemon/list_graph.h>
    2524#include <lemon/smart_graph.h>
     25#include <lemon/maps.h>
    2626
    2727#include "graph_test.h"
Note: See TracChangeset for help on using the changeset viewer.