COIN-OR::LEMON - Graph Library

Ignore:
Files:
26 added
113 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified .hgignore

    r610 r944  
    2323lemon/stamp-h2
    2424doc/Doxyfile
     25doc/references.dox
    2526cmake/version.cmake
    2627.dirstamp
  • TabularUnified CMakeLists.txt

    r1053 r1110  
    115115SET(LEMON_HAVE_LONG_LONG ${HAVE_LONG_LONG})
    116116
     117INCLUDE(FindPythonInterp)
     118
    117119ENABLE_TESTING()
    118120
  • TabularUnified INSTALL

    r615 r890  
    174174
    175175   Disable COIN-OR support.
     176
     177
     178Makefile Variables
     179==================
     180
     181Some Makefile variables are reserved by the GNU Coding Standards for
     182the use of the "user" - the person building the package. For instance,
     183CXX and CXXFLAGS are such variables, and have the same meaning as
     184explained in the previous section. These variables can be set on the
     185command line when invoking `make' like this:
     186`make [VARIABLE=VALUE]...'
     187
     188WARNINGCXXFLAGS is a non-standard Makefile variable introduced by us
     189to hold several compiler flags related to warnings. Its default value
     190can be overridden when invoking `make'. For example to disable all
     191warning flags use `make WARNINGCXXFLAGS='.
     192
     193In order to turn off a single flag from the default set of warning
     194flags, you can use the CXXFLAGS variable, since this is passed after
     195WARNINGCXXFLAGS. For example to turn off `-Wold-style-cast' (which is
     196used by default when g++ is detected) you can use
     197`make CXXFLAGS="-g -O2 -Wno-old-style-cast"'.
  • TabularUnified LICENSE

    r600 r959  
    22copyright/license.
    33
    4 Copyright (C) 2003-2009 Egervary Jeno Kombinatorikus Optimalizalasi
     4Copyright (C) 2003-2010 Egervary Jeno Kombinatorikus Optimalizalasi
    55Kutatocsoport (Egervary Combinatorial Optimization Research Group,
    66EGRES).
  • TabularUnified Makefile.am

    r799 r840  
    4545include doc/Makefile.am
    4646include tools/Makefile.am
     47include scripts/Makefile.am
    4748
    4849DIST_SUBDIRS = demo
  • TabularUnified NEWS

    r712 r1099  
     12011-11-09 Version 1.2.3 released
     2
     3        Bugfix release.
     4
     5        #428: Add missing lemon/lemon.pc.cmake to the release tarball
     6        #429: Fix VS warnings
     7        #430: Fix LpBase::Constr two-side limit bug
     8
     92011-08-08 Version 1.2.2 released
     10
     11        Bugfix release.
     12
     13        #392: Bug fix in Dfs::start(s,t)
     14        #414: Fix wrong initialization in Preflow
     15        #404: Update Doxygen configuration
     16        #416: Support tests with valgrind
     17        #418: Better Win CodeBlock/MinGW support
     18        #419: Backport build environment improvements from the main branch
     19              - Build of mip_test and lp_test precede the running of the tests
     20              - Also search for coin libs under ${COIN_ROOT_DIR}/lib/coin
     21              - Do not look for COIN_VOL libraries
     22        #382: Allow lgf file without Arc maps
     23        #417: Bug fix in CostScaling
     24
     252010-10-21 Version 1.2.1 released
     26
     27        Bugfix release.
     28
     29        #366: Fix Pred[Matrix]MapPath::empty()
     30        #371: Bug fix in (di)graphCopy()
     31              The target graph is cleared before adding nodes and arcs/edges.
     32
     33        #364: Add missing UndirectedTags
     34        #368: Fix the usage of std::numeric_limits<>::min() in Network Simplex
     35        #372: Fix a critical bug in preflow
     36
     372010-03-19 Version 1.2 released
     38
     39        This is major feature release
     40
     41        * New algorithms
     42          * Bellman-Ford algorithm (#51)
     43          * Minimum mean cycle algorithms (#179)
     44            * Karp, Hartman-Orlin and Howard algorithms
     45          * New minimum cost flow algorithms (#180)
     46            * Cost Scaling algorithms
     47            * Capacity Scaling algorithm
     48            * Cycle-Canceling algorithms
     49          * Planarity related algorithms (#62)
     50            * Planarity checking algorithm
     51            * Planar embedding algorithm
     52            * Schnyder's planar drawing algorithm
     53            * Coloring planar graphs with five or six colors
     54          * Fractional matching algorithms (#314)
     55        * New data structures
     56          * StaticDigraph structure (#68)
     57          * Several new priority queue structures (#50, #301)
     58            * Fibonacci, Radix, Bucket, Pairing, Binomial
     59              D-ary and fourary heaps (#301)
     60          * Iterable map structures (#73)
     61        * Other new tools and functionality
     62          * Map utility functions (#320)
     63          * Reserve functions are added to ListGraph and SmartGraph (#311)
     64          * A resize() function is added to HypercubeGraph (#311)
     65          * A count() function is added to CrossRefMap (#302)
     66          * Support for multiple targets in Suurballe using fullInit() (#181)
     67          * Traits class and named parameters for Suurballe (#323)
     68          * Separate reset() and resetParams() functions in NetworkSimplex
     69            to handle graph changes (#327)
     70          * tolerance() functions are added to HaoOrlin (#306)
     71        * Implementation improvements
     72          * Improvements in weighted matching algorithms (#314)
     73            * Jumpstart initialization
     74          * ArcIt iteration is based on out-arc lists instead of in-arc lists
     75            in ListDigraph (#311)
     76          * Faster add row operation in CbcMip (#203)
     77          * Better implementation for split() in ListDigraph (#311)
     78          * ArgParser can also throw exception instead of exit(1) (#332)
     79        * Miscellaneous
     80          * A simple interactive bootstrap script
     81          * Doc improvements (#62,#180,#299,#302,#303,#304,#307,#311,#331,#315,
     82                #316,#319)
     83            * BibTeX references in the doc (#184)
     84          * Optionally use valgrind when running tests
     85          * Also check ReferenceMapTag in concept checks (#312)
     86          * dimacs-solver uses long long type by default.
     87        * Several bugfixes (compared to release 1.1):
     88          #295: Suppress MSVC warnings using pragmas
     89          ----: Various CMAKE related improvements
     90                * Remove duplications from doc/CMakeLists.txt
     91                * Rename documentation install folder from 'docs' to 'html'
     92                * Add tools/CMakeLists.txt to the tarball
     93                * Generate and install LEMONConfig.cmake
     94                * Change the label of the html project in Visual Studio
     95                * Fix the check for the 'long long' type
     96                * Put the version string into config.h
     97                * Minor CMake improvements
     98                * Set the version to 'hg-tip' if everything fails
     99          #311: Add missing 'explicit' keywords
     100          #302: Fix the implementation and doc of CrossRefMap
     101          #308: Remove duplicate list_graph.h entry from source list
     102          #307: Bugfix in Preflow and Circulation
     103          #305: Bugfix and extension in the rename script
     104          #312: Also check ReferenceMapTag in concept checks
     105          #250: Bugfix in pathSource() and pathTarget()
     106          #321: Use pathCopy(from,to) instead of copyPath(to,from)
     107          #322: Distribure LEMONConfig.cmake.in
     108          #330: Bug fix in map_extender.h
     109          #336: Fix the date field comment of graphToEps() output
     110          #323: Bug fix in Suurballe
     111          #335: Fix clear() function in ExtendFindEnum
     112          #337: Use void* as the LPX object pointer
     113          #317: Fix (and improve) error message in mip_test.cc
     114                Remove unnecessary OsiCbc dependency
     115          #356: Allow multiple executions of weighted matching algorithms (#356)
     116
    11172009-05-13 Version 1.1 released
    2118
     
    73189          ----: Add missing unistd.h include to time_measure.h
    74190          #204: Compilation bug fixed in graph_to_eps.h with VS2005
    75           #214,#215: windows.h should never be included by lemon headers
     191          #214,#215: windows.h should never be included by LEMON headers
    76192          #230: Build systems check the availability of 'long long' type
    77193          #229: Default implementation of Tolerance<> is used for integer types
     
    952112008-10-13 Version 1.0 released
    96212
    97         This is the first stable release of LEMON. Compared to the 0.x
    98         release series, it features a considerably smaller but more
    99         matured set of tools. The API has also completely revised and
    100         changed in several places.
    101 
    102         * The major name changes compared to the 0.x series (see the
     213        This is the first stable release of LEMON. Compared to the 0.x
     214        release series, it features a considerably smaller but more
     215        matured set of tools. The API has also completely revised and
     216        changed in several places.
     217
     218        * The major name changes compared to the 0.x series (see the
    103219          Migration Guide in the doc for more details)
    104220          * Graph -> Digraph, UGraph -> Graph
    105221          * Edge -> Arc, UEdge -> Edge
    106           * source(UEdge)/target(UEdge) -> u(Edge)/v(Edge)
    107         * Other improvements
    108           * Better documentation
    109           * Reviewed and cleaned up codebase
    110           * CMake based build system (along with the autotools based one)
    111         * Contents of the library (ported from 0.x)
    112           * Algorithms
    113             * breadth-first search (bfs.h)
    114             * depth-first search (dfs.h)
    115             * Dijkstra's algorithm (dijkstra.h)
    116             * Kruskal's algorithm (kruskal.h)
    117           * Data structures
    118             * graph data structures (list_graph.h, smart_graph.h)
    119             * path data structures (path.h)
    120             * binary heap data structure (bin_heap.h)
    121             * union-find data structures (unionfind.h)
    122             * miscellaneous property maps (maps.h)
    123             * two dimensional vector and bounding box (dim2.h)
     222          * source(UEdge)/target(UEdge) -> u(Edge)/v(Edge)
     223        * Other improvements
     224          * Better documentation
     225          * Reviewed and cleaned up codebase
     226          * CMake based build system (along with the autotools based one)
     227        * Contents of the library (ported from 0.x)
     228          * Algorithms
     229            * breadth-first search (bfs.h)
     230            * depth-first search (dfs.h)
     231            * Dijkstra's algorithm (dijkstra.h)
     232            * Kruskal's algorithm (kruskal.h)
     233          * Data structures
     234            * graph data structures (list_graph.h, smart_graph.h)
     235            * path data structures (path.h)
     236            * binary heap data structure (bin_heap.h)
     237            * union-find data structures (unionfind.h)
     238            * miscellaneous property maps (maps.h)
     239            * two dimensional vector and bounding box (dim2.h)
    124240          * Concepts
    125             * graph structure concepts (concepts/digraph.h, concepts/graph.h,
     241            * graph structure concepts (concepts/digraph.h, concepts/graph.h,
    126242              concepts/graph_components.h)
    127             * concepts for other structures (concepts/heap.h, concepts/maps.h,
    128               concepts/path.h)
    129           * Tools
    130             * Mersenne twister random number generator (random.h)
    131             * tools for measuring cpu and wall clock time (time_measure.h)
    132             * tools for counting steps and events (counter.h)
    133             * tool for parsing command line arguments (arg_parser.h)
    134             * tool for visualizing graphs (graph_to_eps.h)
    135             * tools for reading and writing data in LEMON Graph Format
     243            * concepts for other structures (concepts/heap.h, concepts/maps.h,
     244              concepts/path.h)
     245          * Tools
     246            * Mersenne twister random number generator (random.h)
     247            * tools for measuring cpu and wall clock time (time_measure.h)
     248            * tools for counting steps and events (counter.h)
     249            * tool for parsing command line arguments (arg_parser.h)
     250            * tool for visualizing graphs (graph_to_eps.h)
     251            * tools for reading and writing data in LEMON Graph Format
    136252              (lgf_reader.h, lgf_writer.h)
    137253            * tools to handle the anomalies of calculations with
    138               floating point numbers (tolerance.h)
     254              floating point numbers (tolerance.h)
    139255            * tools to manage RGB colors (color.h)
    140           * Infrastructure
    141             * extended assertion handling (assert.h)
    142             * exception classes and error handling (error.h)
    143             * concept checking (concept_check.h)
    144             * commonly used mathematical constants (math.h)
     256          * Infrastructure
     257            * extended assertion handling (assert.h)
     258            * exception classes and error handling (error.h)
     259            * concept checking (concept_check.h)
     260            * commonly used mathematical constants (math.h)
  • TabularUnified README

    r705 r921  
    1818   Copying, distribution and modification conditions and terms.
    1919
     20NEWS
     21
     22   News and version history.
     23
    2024INSTALL
    2125
     
    3438   Some example programs to make you easier to get familiar with LEMON.
    3539
     40scripts/
     41
     42   Scripts that make it easier to develop LEMON.
     43
    3644test/
    3745
  • TabularUnified configure.ac

    r1037 r1039  
    4242
    4343AC_CHECK_PROG([doxygen_found],[doxygen],[yes],[no])
     44AC_CHECK_PROG([python_found],[python],[yes],[no])
    4445AC_CHECK_PROG([gs_found],[gs],[yes],[no])
    4546
     
    8283fi
    8384AM_CONDITIONAL([WANT_TOOLS], [test x"$enable_tools" != x"no"])
     85
     86dnl Support for running test cases using valgrind.
     87use_valgrind=no
     88AC_ARG_ENABLE([valgrind],
     89AS_HELP_STRING([--enable-valgrind], [use valgrind when running tests]),
     90              [use_valgrind=yes])
     91
     92if [[ "$use_valgrind" = "yes" ]]; then
     93  AC_CHECK_PROG(HAVE_VALGRIND, valgrind, yes, no)
     94
     95  if [[ "$HAVE_VALGRIND" = "no" ]]; then
     96    AC_MSG_ERROR([Valgrind not found in PATH.])
     97  fi
     98fi
     99AM_CONDITIONAL(USE_VALGRIND, [test "$use_valgrind" = "yes"])
    84100
    85101dnl Checks for header files.
     
    129145echo
    130146echo Build additional tools........ : $enable_tools
     147echo Use valgrind for tests........ : $use_valgrind
    131148echo
    132149echo The packace will be installed in
  • TabularUnified demo/arg_parser_demo.cc

    r463 r956  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    6666    .other("...");
    6767
     68  // Throw an exception when problems occurs. The default behavior is to
     69  // exit(1) on these cases, but this makes Valgrind falsely warn
     70  // about memory leaks.
     71  ap.throwOnProblems();
     72
    6873  // Perform the parsing process
    6974  // (in case of any error it terminates the program)
    70   ap.parse();
     75  // The try {} construct is necessary only if the ap.trowOnProblems()
     76  // setting is in use.
     77  try {
     78    ap.parse();
     79  } catch (ArgParserException &) { return 1; }
    7180
    7281  // Check each option if it has been given and print its value
  • TabularUnified doc/CMakeLists.txt

    r1037 r1110  
    1818)
    1919
    20 IF(DOXYGEN_EXECUTABLE AND GHOSTSCRIPT_EXECUTABLE)
     20IF(DOXYGEN_EXECUTABLE AND PYTHONINTERP_FOUND AND GHOSTSCRIPT_EXECUTABLE)
    2121  FILE(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html/)
    2222  SET(GHOSTSCRIPT_OPTIONS -dNOPAUSE -dBATCH -q -dEPSCrop -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sDEVICE=pngalpha)
     
    2929    COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r18 -sOutputFile=gen-images/edge_biconnected_components.png ${CMAKE_CURRENT_SOURCE_DIR}/images/edge_biconnected_components.eps
    3030    COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r18 -sOutputFile=gen-images/grid_graph.png ${CMAKE_CURRENT_SOURCE_DIR}/images/grid_graph.eps
     31    COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r18 -sOutputFile=gen-images/matching.png ${CMAKE_CURRENT_SOURCE_DIR}/images/matching.eps
    3132    COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r18 -sOutputFile=gen-images/node_biconnected_components.png ${CMAKE_CURRENT_SOURCE_DIR}/images/node_biconnected_components.eps
    3233    COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r18 -sOutputFile=gen-images/nodeshape_0.png ${CMAKE_CURRENT_SOURCE_DIR}/images/nodeshape_0.eps
     
    3536    COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r18 -sOutputFile=gen-images/nodeshape_3.png ${CMAKE_CURRENT_SOURCE_DIR}/images/nodeshape_3.eps
    3637    COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r18 -sOutputFile=gen-images/nodeshape_4.png ${CMAKE_CURRENT_SOURCE_DIR}/images/nodeshape_4.eps
     38    COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r18 -sOutputFile=gen-images/planar.png ${CMAKE_CURRENT_SOURCE_DIR}/images/planar.eps
    3739    COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r18 -sOutputFile=gen-images/strongly_connected_components.png ${CMAKE_CURRENT_SOURCE_DIR}/images/strongly_connected_components.eps
    3840    COMMAND ${CMAKE_COMMAND} -E remove_directory html
     41    COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/scripts/bib2dox.py ${CMAKE_CURRENT_SOURCE_DIR}/references.bib >references.dox
    3942    COMMAND ${DOXYGEN_EXECUTABLE} Doxyfile
    4043    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  • TabularUnified doc/Doxyfile.in

    r1037 r1110  
    9898                         "@abs_top_srcdir@/tools" \
    9999                         "@abs_top_srcdir@/test/test_tools.h" \
    100                          "@abs_top_builddir@/doc/mainpage.dox"
     100                         "@abs_top_builddir@/doc/mainpage.dox" \
     101                         "@abs_top_builddir@/doc/references.dox"
    101102INPUT_ENCODING         = UTF-8
    102103FILE_PATTERNS          = *.h \
  • TabularUnified doc/Makefile.am

    r1112 r1115  
    1212        doc/named-param.dox \
    1313        doc/namespaces.dox \
     14        doc/references.bib \
    1415        doc/template.h \
    1516        doc/html \
     
    2930        connected_components.eps \
    3031        edge_biconnected_components.eps \
     32        matching.eps \
    3133        node_biconnected_components.eps \
     34        planar.eps \
    3235        strongly_connected_components.eps
    3336
     
    6871        fi
    6972
    70 html-local: $(DOC_PNG_IMAGES)
     73references.dox: doc/references.bib
     74        if test ${python_found} = yes; then \
     75          cd doc; \
     76          python @abs_top_srcdir@/scripts/bib2dox.py @abs_top_builddir@/$< >$@; \
     77          cd ..; \
     78        else \
     79          echo; \
     80          echo "Python not found."; \
     81          echo; \
     82          exit 1; \
     83        fi
     84
     85html-local: $(DOC_PNG_IMAGES) references.dox
    7186        if test ${doxygen_found} = yes; then \
    7287          cd doc; \
  • TabularUnified doc/groups.dox

    r710 r963  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    227227
    228228/**
    229 @defgroup matrices Matrices
    230 @ingroup datas
    231 \brief Two dimensional data storages implemented in LEMON.
    232 
    233 This group contains two dimensional data storages implemented in LEMON.
    234 */
    235 
    236 /**
    237229@defgroup paths Path Structures
    238230@ingroup datas
     
    247239any kind of path structure.
    248240
    249 \sa lemon::concepts::Path
     241\sa \ref concepts::Path "Path concept"
     242*/
     243
     244/**
     245@defgroup heaps Heap Structures
     246@ingroup datas
     247\brief %Heap structures implemented in LEMON.
     248
     249This group contains the heap structures implemented in LEMON.
     250
     251LEMON provides several heap classes. They are efficient implementations
     252of the abstract data type \e priority \e queue. They store items with
     253specified values called \e priorities in such a way that finding and
     254removing the item with minimum priority are efficient.
     255The basic operations are adding and erasing items, changing the priority
     256of an item, etc.
     257
     258Heaps are crucial in several algorithms, such as Dijkstra and Prim.
     259The heap implementations have the same interface, thus any of them can be
     260used easily in such algorithms.
     261
     262\sa \ref concepts::Heap "Heap concept"
    250263*/
    251264
     
    260273
    261274/**
     275@defgroup geomdat Geometric Data Structures
     276@ingroup auxdat
     277\brief Geometric data structures implemented in LEMON.
     278
     279This group contains geometric data structures implemented in LEMON.
     280
     281 - \ref lemon::dim2::Point "dim2::Point" implements a two dimensional
     282   vector with the usual operations.
     283 - \ref lemon::dim2::Box "dim2::Box" can be used to determine the
     284   rectangular bounding box of a set of \ref lemon::dim2::Point
     285   "dim2::Point"'s.
     286*/
     287
     288/**
    262289@defgroup algs Algorithms
    263290\brief This group contains the several algorithms
     
    274301
    275302This group contains the common graph search algorithms, namely
    276 \e breadth-first \e search (BFS) and \e depth-first \e search (DFS).
     303\e breadth-first \e search (BFS) and \e depth-first \e search (DFS)
     304\ref clrs01algorithms.
    277305*/
    278306
     
    282310\brief Algorithms for finding shortest paths.
    283311
    284 This group contains the algorithms for finding shortest paths in digraphs.
     312This group contains the algorithms for finding shortest paths in digraphs
     313\ref clrs01algorithms.
    285314
    286315 - \ref Dijkstra algorithm for finding shortest paths from a source node
     
    290319   but the digraph should not contain directed cycles with negative total
    291320   length.
    292  - \ref FloydWarshall "Floyd-Warshall" and \ref Johnson "Johnson" algorithms
    293    for solving the \e all-pairs \e shortest \e paths \e problem when arc
    294    lenghts can be either positive or negative, but the digraph should
    295    not contain directed cycles with negative total length.
    296321 - \ref Suurballe A successive shortest path algorithm for finding
    297322   arc-disjoint paths between two nodes having minimum total length.
     
    299324
    300325/**
     326@defgroup spantree Minimum Spanning Tree Algorithms
     327@ingroup algs
     328\brief Algorithms for finding minimum cost spanning trees and arborescences.
     329
     330This group contains the algorithms for finding minimum cost spanning
     331trees and arborescences \ref clrs01algorithms.
     332*/
     333
     334/**
    301335@defgroup max_flow Maximum Flow Algorithms
    302336@ingroup algs
     
    304338
    305339This group contains the algorithms for finding maximum flows and
    306 feasible circulations.
     340feasible circulations \ref clrs01algorithms, \ref amo93networkflows.
    307341
    308342The \e maximum \e flow \e problem is to find a flow of maximum value between
     
    318352\f[ 0 \leq f(uv) \leq cap(uv) \quad \forall uv\in A \f]
    319353
    320 LEMON contains several algorithms for solving maximum flow problems:
    321 - \ref EdmondsKarp Edmonds-Karp algorithm.
    322 - \ref Preflow Goldberg-Tarjan's preflow push-relabel algorithm.
    323 - \ref DinitzSleatorTarjan Dinitz's blocking flow algorithm with dynamic trees.
    324 - \ref GoldbergTarjan Preflow push-relabel algorithm with dynamic trees.
    325 
    326 In most cases the \ref Preflow "Preflow" algorithm provides the
    327 fastest method for computing a maximum flow. All implementations
    328 also provide functions to query the minimum cut, which is the dual
    329 problem of maximum flow.
    330 
    331 \ref Circulation is a preflow push-relabel algorithm implemented directly
     354\ref Preflow is an efficient implementation of Goldberg-Tarjan's
     355preflow push-relabel algorithm \ref goldberg88newapproach for finding
     356maximum flows. It also provides functions to query the minimum cut,
     357which is the dual problem of maximum flow.
     358
     359\ref Circulation is a preflow push-relabel algorithm implemented directly
    332360for finding feasible circulations, which is a somewhat different problem,
    333361but it is strongly related to maximum flow.
     
    342370
    343371This group contains the algorithms for finding minimum cost flows and
    344 circulations. For more information about this problem and its dual
    345 solution see \ref min_cost_flow "Minimum Cost Flow Problem".
     372circulations \ref amo93networkflows. For more information about this
     373problem and its dual solution, see \ref min_cost_flow
     374"Minimum Cost Flow Problem".
    346375
    347376LEMON contains several algorithms for this problem.
    348377 - \ref NetworkSimplex Primal Network Simplex algorithm with various
    349    pivot strategies.
    350  - \ref CostScaling Push-Relabel and Augment-Relabel algorithms based on
    351    cost scaling.
    352  - \ref CapacityScaling Successive Shortest %Path algorithm with optional
    353    capacity scaling.
    354  - \ref CancelAndTighten The Cancel and Tighten algorithm.
    355  - \ref CycleCanceling Cycle-Canceling algorithms.
     378   pivot strategies \ref dantzig63linearprog, \ref kellyoneill91netsimplex.
     379 - \ref CostScaling Cost Scaling algorithm based on push/augment and
     380   relabel operations \ref goldberg90approximation, \ref goldberg97efficient,
     381   \ref bunnagel98efficient.
     382 - \ref CapacityScaling Capacity Scaling algorithm based on the successive
     383   shortest path method \ref edmondskarp72theoretical.
     384 - \ref CycleCanceling Cycle-Canceling algorithms, two of which are
     385   strongly polynomial \ref klein67primal, \ref goldberg89cyclecanceling.
    356386
    357387In general NetworkSimplex is the most efficient implementation,
     
    376406
    377407\f[ \min_{X \subset V, X\not\in \{\emptyset, V\}}
    378     \sum_{uv\in A, u\in X, v\not\in X}cap(uv) \f]
     408    \sum_{uv\in A: u\in X, v\not\in X}cap(uv) \f]
    379409
    380410LEMON contains several algorithms related to minimum cut problems:
     
    382412- \ref HaoOrlin "Hao-Orlin algorithm" for calculating minimum cut
    383413  in directed graphs.
    384 - \ref NagamochiIbaraki "Nagamochi-Ibaraki algorithm" for
    385   calculating minimum cut in undirected graphs.
    386414- \ref GomoryHu "Gomory-Hu tree computation" for calculating
    387415  all-pairs minimum cut in undirected graphs.
     
    392420
    393421/**
    394 @defgroup graph_properties Connectivity and Other Graph Properties
    395 @ingroup algs
    396 \brief Algorithms for discovering the graph properties
    397 
    398 This group contains the algorithms for discovering the graph properties
    399 like connectivity, bipartiteness, euler property, simplicity etc.
    400 
    401 \image html edge_biconnected_components.png
    402 \image latex edge_biconnected_components.eps "bi-edge-connected components" width=\textwidth
    403 */
    404 
    405 /**
    406 @defgroup planar Planarity Embedding and Drawing
    407 @ingroup algs
    408 \brief Algorithms for planarity checking, embedding and drawing
    409 
    410 This group contains the algorithms for planarity checking,
    411 embedding and drawing.
    412 
    413 \image html planar.png
    414 \image latex planar.eps "Plane graph" width=\textwidth
     422@defgroup min_mean_cycle Minimum Mean Cycle Algorithms
     423@ingroup algs
     424\brief Algorithms for finding minimum mean cycles.
     425
     426This group contains the algorithms for finding minimum mean cycles
     427\ref clrs01algorithms, \ref amo93networkflows.
     428
     429The \e minimum \e mean \e cycle \e problem is to find a directed cycle
     430of minimum mean length (cost) in a digraph.
     431The mean length of a cycle is the average length of its arcs, i.e. the
     432ratio between the total length of the cycle and the number of arcs on it.
     433
     434This problem has an important connection to \e conservative \e length
     435\e functions, too. A length function on the arcs of a digraph is called
     436conservative if and only if there is no directed cycle of negative total
     437length. For an arbitrary length function, the negative of the minimum
     438cycle mean is the smallest \f$\epsilon\f$ value so that increasing the
     439arc lengths uniformly by \f$\epsilon\f$ results in a conservative length
     440function.
     441
     442LEMON contains three algorithms for solving the minimum mean cycle problem:
     443- \ref KarpMmc Karp's original algorithm \ref amo93networkflows,
     444  \ref dasdan98minmeancycle.
     445- \ref HartmannOrlinMmc Hartmann-Orlin's algorithm, which is an improved
     446  version of Karp's algorithm \ref dasdan98minmeancycle.
     447- \ref HowardMmc Howard's policy iteration algorithm
     448  \ref dasdan98minmeancycle.
     449
     450In practice, the \ref HowardMmc "Howard" algorithm proved to be by far the
     451most efficient one, though the best known theoretical bound on its running
     452time is exponential.
     453Both \ref KarpMmc "Karp" and \ref HartmannOrlinMmc "Hartmann-Orlin" algorithms
     454run in time O(ne) and use space O(n<sup>2</sup>+e), but the latter one is
     455typically faster due to the applied early termination scheme.
    415456*/
    416457
     
    433474
    434475The matching algorithms implemented in LEMON:
    435 - \ref MaxBipartiteMatching Hopcroft-Karp augmenting path algorithm
    436   for calculating maximum cardinality matching in bipartite graphs.
    437 - \ref PrBipartiteMatching Push-relabel algorithm
    438   for calculating maximum cardinality matching in bipartite graphs.
    439 - \ref MaxWeightedBipartiteMatching
    440   Successive shortest path algorithm for calculating maximum weighted
    441   matching and maximum weighted bipartite matching in bipartite graphs.
    442 - \ref MinCostMaxBipartiteMatching
    443   Successive shortest path algorithm for calculating minimum cost maximum
    444   matching in bipartite graphs.
    445476- \ref MaxMatching Edmond's blossom shrinking algorithm for calculating
    446477  maximum cardinality matching in general graphs.
     
    450481  Edmond's blossom shrinking algorithm for calculating maximum weighted
    451482  perfect matching in general graphs.
    452 
    453 \image html bipartite_matching.png
    454 \image latex bipartite_matching.eps "Bipartite Matching" width=\textwidth
    455 */
    456 
    457 /**
    458 @defgroup spantree Minimum Spanning Tree Algorithms
    459 @ingroup algs
    460 \brief Algorithms for finding minimum cost spanning trees and arborescences.
    461 
    462 This group contains the algorithms for finding minimum cost spanning
    463 trees and arborescences.
     483- \ref MaxFractionalMatching Push-relabel algorithm for calculating
     484  maximum cardinality fractional matching in general graphs.
     485- \ref MaxWeightedFractionalMatching Augmenting path algorithm for calculating
     486  maximum weighted fractional matching in general graphs.
     487- \ref MaxWeightedPerfectFractionalMatching
     488  Augmenting path algorithm for calculating maximum weighted
     489  perfect fractional matching in general graphs.
     490
     491\image html matching.png
     492\image latex matching.eps "Min Cost Perfect Matching" width=\textwidth
     493*/
     494
     495/**
     496@defgroup graph_properties Connectivity and Other Graph Properties
     497@ingroup algs
     498\brief Algorithms for discovering the graph properties
     499
     500This group contains the algorithms for discovering the graph properties
     501like connectivity, bipartiteness, euler property, simplicity etc.
     502
     503\image html connected_components.png
     504\image latex connected_components.eps "Connected components" width=\textwidth
     505*/
     506
     507/**
     508@defgroup planar Planarity Embedding and Drawing
     509@ingroup algs
     510\brief Algorithms for planarity checking, embedding and drawing
     511
     512This group contains the algorithms for planarity checking,
     513embedding and drawing.
     514
     515\image html planar.png
     516\image latex planar.eps "Plane graph" width=\textwidth
    464517*/
    465518
     
    471524This group contains some algorithms implemented in LEMON
    472525in order to make it easier to implement complex algorithms.
    473 */
    474 
    475 /**
    476 @defgroup approx Approximation Algorithms
    477 @ingroup algs
    478 \brief Approximation algorithms.
    479 
    480 This group contains the approximation and heuristic algorithms
    481 implemented in LEMON.
    482526*/
    483527
     
    492536
    493537/**
    494 @defgroup lp_group Lp and Mip Solvers
     538@defgroup lp_group LP and MIP Solvers
    495539@ingroup gen_opt_group
    496 \brief Lp and Mip solver interfaces for LEMON.
    497 
    498 This group contains Lp and Mip solver interfaces for LEMON. The
    499 various LP solvers could be used in the same manner with this
    500 interface.
    501 */
    502 
    503 /**
    504 @defgroup lp_utils Tools for Lp and Mip Solvers
    505 @ingroup lp_group
    506 \brief Helper tools to the Lp and Mip solvers.
    507 
    508 This group adds some helper tools to general optimization framework
    509 implemented in LEMON.
    510 */
    511 
    512 /**
    513 @defgroup metah Metaheuristics
    514 @ingroup gen_opt_group
    515 \brief Metaheuristics for LEMON library.
    516 
    517 This group contains some metaheuristic optimization tools.
     540\brief LP and MIP solver interfaces for LEMON.
     541
     542This group contains LP and MIP solver interfaces for LEMON.
     543Various LP solvers could be used in the same manner with this
     544high-level interface.
     545
     546The currently supported solvers are \ref glpk, \ref clp, \ref cbc,
     547\ref cplex, \ref soplex.
    518548*/
    519549
     
    588618
    589619/**
    590 @defgroup dimacs_group DIMACS format
     620@defgroup dimacs_group DIMACS Format
    591621@ingroup io_group
    592622\brief Read and write files in DIMACS format
     
    637667\brief Skeleton and concept checking classes for graph structures
    638668
    639 This group contains the skeletons and concept checking classes of LEMON's
    640 graph structures and helper classes used to implement these.
     669This group contains the skeletons and concept checking classes of
     670graph structures.
    641671*/
    642672
     
    650680
    651681/**
     682@defgroup tools Standalone Utility Applications
     683
     684Some utility applications are listed here.
     685
     686The standard compilation procedure (<tt>./configure;make</tt>) will compile
     687them, as well.
     688*/
     689
     690/**
    652691\anchor demoprograms
    653692
     
    661700*/
    662701
    663 /**
    664 @defgroup tools Standalone Utility Applications
    665 
    666 Some utility applications are listed here.
    667 
    668 The standard compilation procedure (<tt>./configure;make</tt>) will compile
    669 them, as well.
    670 */
    671 
    672702}
  • TabularUnified doc/lgf.dox

    r1069 r1081  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2011
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
  • TabularUnified doc/mainpage.dox.in

    r1037 r1039  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    2222\section intro Introduction
    2323
    24 \subsection whatis What is LEMON
    25 
    26 LEMON stands for <b>L</b>ibrary for <b>E</b>fficient <b>M</b>odeling
    27 and <b>O</b>ptimization in <b>N</b>etworks.
    28 It is a C++ template
    29 library aimed at combinatorial optimization tasks which
    30 often involve in working
    31 with graphs.
     24<b>LEMON</b> stands for <i><b>L</b>ibrary for <b>E</b>fficient <b>M</b>odeling
     25and <b>O</b>ptimization in <b>N</b>etworks</i>.
     26It is a C++ template library providing efficient implementations of common
     27data structures and algorithms with focus on combinatorial optimization
     28tasks connected mainly with graphs and networks.
    3229
    3330<b>
     
    3936</b>
    4037
    41 \subsection howtoread How to read the documentation
     38The project is maintained by the
     39<a href="http://www.cs.elte.hu/egres/">Egerv&aacute;ry Research Group on
     40Combinatorial Optimization</a> \ref egres
     41at the Operations Research Department of the
     42<a href="http://www.elte.hu/en/">E&ouml;tv&ouml;s Lor&aacute;nd University</a>,
     43Budapest, Hungary.
     44LEMON is also a member of the <a href="http://www.coin-or.org/">COIN-OR</a>
     45initiative \ref coinor.
     46
     47\section howtoread How to Read the Documentation
    4248
    4349If you would like to get to know the library, see
    4450<a class="el" href="http://lemon.cs.elte.hu/pub/tutorial/">LEMON Tutorial</a>.
     51
     52If you are interested in starting to use the library, see the <a class="el"
     53href="http://lemon.cs.elte.hu/trac/lemon/wiki/InstallGuide/">Installation
     54Guide</a>.
    4555
    4656If you know what you are looking for, then try to find it under the
  • TabularUnified doc/min_cost_flow.dox

    r710 r956  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    2727minimum total cost from a set of supply nodes to a set of demand nodes
    2828in a network with capacity constraints (lower and upper bounds)
    29 and arc costs.
     29and arc costs \ref amo93networkflows.
    3030
    3131Formally, let \f$G=(V,A)\f$ be a digraph, \f$lower: A\rightarrow\mathbf{R}\f$,
     
    7979   - if \f$cost^\pi(uv)<0\f$, then \f$f(uv)=upper(uv)\f$.
    8080 - For all \f$u\in V\f$ nodes:
    81    - \f$\pi(u)<=0\f$;
     81   - \f$\pi(u)\leq 0\f$;
    8282   - if \f$\sum_{uv\in A} f(uv) - \sum_{vu\in A} f(vu) \neq sup(u)\f$,
    8383     then \f$\pi(u)=0\f$.
    84  
     84
    8585Here \f$cost^\pi(uv)\f$ denotes the \e reduced \e cost of the arc
    8686\f$uv\in A\f$ with respect to the potential function \f$\pi\f$, i.e.
     
    120120\f[ lower(uv) \leq f(uv) \leq upper(uv) \quad \forall uv\in A \f]
    121121
    122 It means that the total demand must be less or equal to the 
     122It means that the total demand must be less or equal to the
    123123total supply (i.e. \f$\sum_{u\in V} sup(u)\f$ must be zero or
    124124positive) and all the demands have to be satisfied, but there
     
    146146   - if \f$cost^\pi(uv)<0\f$, then \f$f(uv)=upper(uv)\f$.
    147147 - For all \f$u\in V\f$ nodes:
    148    - \f$\pi(u)>=0\f$;
     148   - \f$\pi(u)\geq 0\f$;
    149149   - if \f$\sum_{uv\in A} f(uv) - \sum_{vu\in A} f(vu) \neq sup(u)\f$,
    150150     then \f$\pi(u)=0\f$.
  • TabularUnified lemon/Makefile.am

    r1106 r1110  
    5959        lemon/arg_parser.h \
    6060        lemon/assert.h \
     61        lemon/bellman_ford.h \
    6162        lemon/bfs.h \
    6263        lemon/bin_heap.h \
     64        lemon/binomial_heap.h \
    6365        lemon/bucket_heap.h \
     66        lemon/capacity_scaling.h \
    6467        lemon/cbc.h \
    6568        lemon/circulation.h \
     
    6871        lemon/concept_check.h \
    6972        lemon/connectivity.h \
     73        lemon/core.h \
     74        lemon/cost_scaling.h \
    7075        lemon/counter.h \
    71         lemon/core.h \
    7276        lemon/cplex.h \
     77        lemon/cycle_canceling.h \
    7378        lemon/dfs.h \
     79        lemon/dheap.h \
    7480        lemon/dijkstra.h \
    7581        lemon/dim2.h \
     
    8086        lemon/euler.h \
    8187        lemon/fib_heap.h \
     88        lemon/fractional_matching.h \
    8289        lemon/full_graph.h \
    8390        lemon/glpk.h \
     
    8592        lemon/graph_to_eps.h \
    8693        lemon/grid_graph.h \
     94        lemon/hartmann_orlin_mmc.h \
     95        lemon/howard_mmc.h \
    8796        lemon/hypercube_graph.h \
     97        lemon/karp_mmc.h \
    8898        lemon/kruskal.h \
    8999        lemon/hao_orlin.h \
     
    100110        lemon/nauty_reader.h \
    101111        lemon/network_simplex.h \
     112        lemon/pairing_heap.h \
    102113        lemon/path.h \
     114        lemon/planarity.h \
    103115        lemon/preflow.h \
     116        lemon/quad_heap.h \
    104117        lemon/radix_heap.h \
    105118        lemon/radix_sort.h \
     
    107120        lemon/smart_graph.h \
    108121        lemon/soplex.h \
     122        lemon/static_graph.h \
    109123        lemon/suurballe.h \
    110124        lemon/time_measure.h \
  • TabularUnified lemon/adaptors.h

    r703 r956  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    361361  /// parameter is set to be \c const.
    362362  ///
     363  /// This class provides item counting in the same time as the adapted
     364  /// digraph structure.
     365  ///
    363366  /// \tparam DGR The type of the adapted digraph.
    364367  /// It must conform to the \ref concepts::Digraph "Digraph" concept.
     
    419422      Parent::initialize(digraph);
    420423      _node_filter = &node_filter;
    421       _arc_filter = &arc_filter;     
     424      _arc_filter = &arc_filter;
    422425    }
    423426
     
    506509
    507510    template <typename V>
    508     class NodeMap 
    509       : public SubMapExtender<SubDigraphBase<DGR, NF, AF, ch>, 
    510               LEMON_SCOPE_FIX(DigraphAdaptorBase<DGR>, NodeMap<V>)> {
     511    class NodeMap
     512      : public SubMapExtender<SubDigraphBase<DGR, NF, AF, ch>,
     513              LEMON_SCOPE_FIX(DigraphAdaptorBase<DGR>, NodeMap<V>)> {
    511514      typedef SubMapExtender<SubDigraphBase<DGR, NF, AF, ch>,
    512         LEMON_SCOPE_FIX(DigraphAdaptorBase<DGR>, NodeMap<V>)> Parent;
     515        LEMON_SCOPE_FIX(DigraphAdaptorBase<DGR>, NodeMap<V>)> Parent;
    513516
    514517    public:
     
    533536
    534537    template <typename V>
    535     class ArcMap 
     538    class ArcMap
    536539      : public SubMapExtender<SubDigraphBase<DGR, NF, AF, ch>,
    537               LEMON_SCOPE_FIX(DigraphAdaptorBase<DGR>, ArcMap<V>)> {
     540              LEMON_SCOPE_FIX(DigraphAdaptorBase<DGR>, ArcMap<V>)> {
    538541      typedef SubMapExtender<SubDigraphBase<DGR, NF, AF, ch>,
    539542        LEMON_SCOPE_FIX(DigraphAdaptorBase<DGR>, ArcMap<V>)> Parent;
     
    580583      Parent::initialize(digraph);
    581584      _node_filter = &node_filter;
    582       _arc_filter = &arc_filter;     
     585      _arc_filter = &arc_filter;
    583586    }
    584587
     
    649652
    650653    template <typename V>
    651     class NodeMap 
     654    class NodeMap
    652655      : public SubMapExtender<SubDigraphBase<DGR, NF, AF, false>,
    653656          LEMON_SCOPE_FIX(DigraphAdaptorBase<DGR>, NodeMap<V>)> {
    654       typedef SubMapExtender<SubDigraphBase<DGR, NF, AF, false>, 
     657      typedef SubMapExtender<SubDigraphBase<DGR, NF, AF, false>,
    655658        LEMON_SCOPE_FIX(DigraphAdaptorBase<DGR>, NodeMap<V>)> Parent;
    656659
     
    676679
    677680    template <typename V>
    678     class ArcMap 
     681    class ArcMap
    679682      : public SubMapExtender<SubDigraphBase<DGR, NF, AF, false>,
    680683          LEMON_SCOPE_FIX(DigraphAdaptorBase<DGR>, ArcMap<V>)> {
     
    719722  /// by adding or removing nodes or arcs, unless the \c GR template
    720723  /// parameter is set to be \c const.
     724  ///
     725  /// This class provides only linear time counting for nodes and arcs.
    721726  ///
    722727  /// \tparam DGR The type of the adapted digraph.
     
    10171022
    10181023    template <typename V>
    1019     class NodeMap 
     1024    class NodeMap
    10201025      : public SubMapExtender<SubGraphBase<GR, NF, EF, ch>,
    10211026          LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, NodeMap<V>)> {
    1022       typedef SubMapExtender<SubGraphBase<GR, NF, EF, ch>, 
     1027      typedef SubMapExtender<SubGraphBase<GR, NF, EF, ch>,
    10231028        LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, NodeMap<V>)> Parent;
    10241029
     
    10441049
    10451050    template <typename V>
    1046     class ArcMap 
     1051    class ArcMap
    10471052      : public SubMapExtender<SubGraphBase<GR, NF, EF, ch>,
    10481053          LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, ArcMap<V>)> {
    1049       typedef SubMapExtender<SubGraphBase<GR, NF, EF, ch>, 
     1054      typedef SubMapExtender<SubGraphBase<GR, NF, EF, ch>,
    10501055        LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, ArcMap<V>)> Parent;
    10511056
     
    10711076
    10721077    template <typename V>
    1073     class EdgeMap 
     1078    class EdgeMap
    10741079      : public SubMapExtender<SubGraphBase<GR, NF, EF, ch>,
    10751080        LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, EdgeMap<V>)> {
    1076       typedef SubMapExtender<SubGraphBase<GR, NF, EF, ch>, 
     1081      typedef SubMapExtender<SubGraphBase<GR, NF, EF, ch>,
    10771082        LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, EdgeMap<V>)> Parent;
    10781083
     
    11131118    NF* _node_filter;
    11141119    EF* _edge_filter;
    1115     SubGraphBase() 
    1116           : Parent(), _node_filter(0), _edge_filter(0) { }
     1120    SubGraphBase()
     1121          : Parent(), _node_filter(0), _edge_filter(0) { }
    11171122
    11181123    void initialize(GR& graph, NF& node_filter, EF& edge_filter) {
     
    12151220
    12161221    template <typename V>
    1217     class NodeMap 
     1222    class NodeMap
    12181223      : public SubMapExtender<SubGraphBase<GR, NF, EF, false>,
    12191224          LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, NodeMap<V>)> {
    1220       typedef SubMapExtender<SubGraphBase<GR, NF, EF, false>, 
     1225      typedef SubMapExtender<SubGraphBase<GR, NF, EF, false>,
    12211226        LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, NodeMap<V>)> Parent;
    12221227
     
    12421247
    12431248    template <typename V>
    1244     class ArcMap 
     1249    class ArcMap
    12451250      : public SubMapExtender<SubGraphBase<GR, NF, EF, false>,
    12461251          LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, ArcMap<V>)> {
    1247       typedef SubMapExtender<SubGraphBase<GR, NF, EF, false>, 
     1252      typedef SubMapExtender<SubGraphBase<GR, NF, EF, false>,
    12481253        LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, ArcMap<V>)> Parent;
    12491254
     
    12691274
    12701275    template <typename V>
    1271     class EdgeMap 
     1276    class EdgeMap
    12721277      : public SubMapExtender<SubGraphBase<GR, NF, EF, false>,
    12731278        LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, EdgeMap<V>)> {
    1274       typedef SubMapExtender<SubGraphBase<GR, NF, EF, false>, 
    1275         LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, EdgeMap<V>)> Parent;
     1279      typedef SubMapExtender<SubGraphBase<GR, NF, EF, false>,
     1280        LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, EdgeMap<V>)> Parent;
    12761281
    12771282    public:
     
    13141319  /// by adding or removing nodes or edges, unless the \c GR template
    13151320  /// parameter is set to be \c const.
     1321  ///
     1322  /// This class provides only linear time counting for nodes, edges and arcs.
    13161323  ///
    13171324  /// \tparam GR The type of the adapted graph.
     
    14711478  /// by adding or removing nodes or arcs/edges, unless the \c GR template
    14721479  /// parameter is set to be \c const.
     1480  ///
     1481  /// This class provides only linear time item counting.
    14731482  ///
    14741483  /// \tparam GR The type of the adapted digraph or graph.
     
    14961505#endif
    14971506    typedef DigraphAdaptorExtender<
    1498       SubDigraphBase<GR, NF, ConstMap<typename GR::Arc, Const<bool, true> >, 
     1507      SubDigraphBase<GR, NF, ConstMap<typename GR::Arc, Const<bool, true> >,
    14991508                     true> > Parent;
    15001509
     
    15171526    /// Creates a subgraph for the given digraph or graph with the
    15181527    /// given node filter map.
    1519     FilterNodes(GR& graph, NF& node_filter) 
     1528    FilterNodes(GR& graph, NF& node_filter)
    15201529      : Parent(), const_true_map()
    15211530    {
     
    15551564                    typename enable_if<UndirectedTagIndicator<GR> >::type> :
    15561565    public GraphAdaptorExtender<
    1557       SubGraphBase<GR, NF, ConstMap<typename GR::Edge, Const<bool, true> >, 
     1566      SubGraphBase<GR, NF, ConstMap<typename GR::Edge, Const<bool, true> >,
    15581567                   true> > {
    15591568
    15601569    typedef GraphAdaptorExtender<
    1561       SubGraphBase<GR, NF, ConstMap<typename GR::Edge, Const<bool, true> >, 
     1570      SubGraphBase<GR, NF, ConstMap<typename GR::Edge, Const<bool, true> >,
    15621571                   true> > Parent;
    15631572
     
    16191628  /// by adding or removing nodes or arcs, unless the \c GR template
    16201629  /// parameter is set to be \c const.
     1630  ///
     1631  /// This class provides only linear time counting for nodes and arcs.
    16211632  ///
    16221633  /// \tparam DGR The type of the adapted digraph.
     
    16431654#endif
    16441655    typedef DigraphAdaptorExtender<
    1645       SubDigraphBase<DGR, ConstMap<typename DGR::Node, Const<bool, true> >, 
     1656      SubDigraphBase<DGR, ConstMap<typename DGR::Node, Const<bool, true> >,
    16461657                     AF, false> > Parent;
    16471658
     
    17291740  /// by adding or removing nodes or edges, unless the \c GR template
    17301741  /// parameter is set to be \c const.
     1742  ///
     1743  /// This class provides only linear time counting for nodes, edges and arcs.
    17311744  ///
    17321745  /// \tparam GR The type of the adapted graph.
     
    17491762  class FilterEdges :
    17501763    public GraphAdaptorExtender<
    1751       SubGraphBase<GR, ConstMap<typename GR::Node, Const<bool, true> >, 
     1764      SubGraphBase<GR, ConstMap<typename GR::Node, Const<bool, true> >,
    17521765                   EF, false> > {
    17531766#endif
    17541767    typedef GraphAdaptorExtender<
    1755       SubGraphBase<GR, ConstMap<typename GR::Node, Const<bool, true > >, 
     1768      SubGraphBase<GR, ConstMap<typename GR::Node, Const<bool, true > >,
    17561769                   EF, false> > Parent;
    17571770
     
    17781791    /// Creates a subgraph for the given graph with the given edge
    17791792    /// filter map.
    1780     FilterEdges(GR& graph, EF& edge_filter) 
     1793    FilterEdges(GR& graph, EF& edge_filter)
    17811794      : Parent(), const_true_map() {
    17821795      Parent::initialize(graph, const_true_map, edge_filter);
     
    18461859      bool _forward;
    18471860
    1848       Arc(const Edge& edge, bool forward) 
     1861      Arc(const Edge& edge, bool forward)
    18491862        : _edge(edge), _forward(forward) {}
    18501863
     
    20862099
    20872100      ArcMapBase(const UndirectorBase<DGR>& adaptor, const V& value)
    2088         : _forward(*adaptor._digraph, value), 
     2101        : _forward(*adaptor._digraph, value),
    20892102          _backward(*adaptor._digraph, value) {}
    20902103
     
    22042217    typedef typename ItemSetTraits<DGR, Edge>::ItemNotifier EdgeNotifier;
    22052218    EdgeNotifier& notifier(Edge) const { return _digraph->notifier(Edge()); }
    2206    
     2219
    22072220    typedef EdgeNotifier ArcNotifier;
    22082221    ArcNotifier& notifier(Arc) const { return _digraph->notifier(Edge()); }
     
    22322245  /// by adding or removing nodes or edges, unless the \c GR template
    22332246  /// parameter is set to be \c const.
     2247  ///
     2248  /// This class provides item counting in the same time as the adapted
     2249  /// digraph structure.
    22342250  ///
    22352251  /// \tparam DGR The type of the adapted digraph.
     
    25352551  /// by adding or removing nodes or arcs, unless the \c GR template
    25362552  /// parameter is set to be \c const.
     2553  ///
     2554  /// This class provides item counting in the same time as the adapted
     2555  /// graph structure.
    25372556  ///
    25382557  /// \tparam GR The type of the adapted graph.
     
    26792698  /// This class conforms to the \ref concepts::Digraph "Digraph" concept.
    26802699  ///
     2700  /// This class provides only linear time counting for nodes and arcs.
     2701  ///
    26812702  /// \tparam DGR The type of the adapted digraph.
    26822703  /// It must conform to the \ref concepts::Digraph "Digraph" concept.
     
    27082729           typename FM = CM,
    27092730           typename TL = Tolerance<typename CM::Value> >
    2710   class ResidualDigraph 
     2731  class ResidualDigraph
    27112732    : public SubDigraph<
    27122733        Undirector<const DGR>,
     
    27652786    ResidualDigraph(const DGR& digraph, const CM& capacity,
    27662787                    FM& flow, const TL& tolerance = Tolerance())
    2767       : Parent(), _capacity(&capacity), _flow(&flow), 
     2788      : Parent(), _capacity(&capacity), _flow(&flow),
    27682789        _graph(digraph), _node_filter(),
    27692790        _forward_filter(capacity, flow, tolerance),
     
    28472868
    28482869      /// Constructor
    2849       ResidualCapacity(const ResidualDigraph<DGR, CM, FM, TL>& adaptor) 
     2870      ResidualCapacity(const ResidualDigraph<DGR, CM, FM, TL>& adaptor)
    28502871        : _adaptor(&adaptor) {}
    28512872
     
    33263347  /// in the adaptor.
    33273348  ///
     3349  /// This class provides item counting in the same time as the adapted
     3350  /// digraph structure.
     3351  ///
    33283352  /// \tparam DGR The type of the adapted digraph.
    33293353  /// It must conform to the \ref concepts::Digraph "Digraph" concept.
     
    34243448    /// to get a node map of the split digraph.
    34253449    /// Its value type is inherited from the first node map type (\c IN).
    3426     /// \tparam IN The type of the node map for the in-nodes. 
     3450    /// \tparam IN The type of the node map for the in-nodes.
    34273451    /// \tparam OUT The type of the node map for the out-nodes.
    34283452    template <typename IN, typename OUT>
  • TabularUnified lemon/arg_parser.cc

    r463 r956  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    2121namespace lemon {
    2222
     23  void ArgParser::_terminate(ArgParserException::Reason reason) const
     24  {
     25    if(_exit_on_problems)
     26      exit(1);
     27    else throw(ArgParserException(reason));
     28  }
     29
     30
    2331  void ArgParser::_showHelp(void *p)
    2432  {
    2533    (static_cast<ArgParser*>(p))->showHelp();
    26     exit(1);
     34    (static_cast<ArgParser*>(p))->_terminate(ArgParserException::HELP);
    2735  }
    2836
    2937  ArgParser::ArgParser(int argc, const char * const *argv)
    30     :_argc(argc), _argv(argv), _command_name(argv[0]) {
     38    :_argc(argc), _argv(argv), _command_name(argv[0]),
     39    _exit_on_problems(true) {
    3140    funcOption("-help","Print a short help message",_showHelp,this);
    3241    synonym("help","-help");
     
    343352        i!=_others_help.end();++i) showHelp(i);
    344353    for(Opts::const_iterator i=_opts.begin();i!=_opts.end();++i) showHelp(i);
    345     exit(1);
     354    _terminate(ArgParserException::HELP);
    346355  }
    347356
     
    352361    std::cerr << "\nType '" << _command_name <<
    353362      " --help' to obtain a short summary on the usage.\n\n";
    354     exit(1);
     363    _terminate(ArgParserException::UNKNOWN_OPT);
    355364  }
    356365
     
    415424      std::cerr << "\nType '" << _command_name <<
    416425        " --help' to obtain a short summary on the usage.\n\n";
    417       exit(1);
     426      _terminate(ArgParserException::INVALID_OPT);
    418427    }
    419428  }
  • TabularUnified lemon/arg_parser.h

    r463 r959  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    3535namespace lemon {
    3636
     37  ///Exception used by ArgParser
     38
     39  ///Exception used by ArgParser.
     40  ///
     41  class ArgParserException : public Exception {
     42  public:
     43    /// Reasons for failure
     44
     45    /// Reasons for failure.
     46    ///
     47    enum Reason {
     48      HELP,         ///< <tt>--help</tt> option was given.
     49      UNKNOWN_OPT,  ///< Unknown option was given.
     50      INVALID_OPT   ///< Invalid combination of options.
     51    };
     52
     53  private:
     54    Reason _reason;
     55
     56  public:
     57    ///Constructor
     58    ArgParserException(Reason r) throw() : _reason(r) {}
     59    ///Virtual destructor
     60    virtual ~ArgParserException() throw() {}
     61    ///A short description of the exception
     62    virtual const char* what() const throw() {
     63      switch(_reason)
     64        {
     65        case HELP:
     66          return "lemon::ArgParseException: ask for help";
     67          break;
     68        case UNKNOWN_OPT:
     69          return "lemon::ArgParseException: unknown option";
     70          break;
     71        case INVALID_OPT:
     72          return "lemon::ArgParseException: invalid combination of options";
     73          break;
     74        }
     75      return "";
     76    }
     77    ///Return the reason for the failure
     78    Reason reason() const {return _reason; }
     79  };
     80
     81
    3782  ///Command line arguments parser
    3883
     
    116161                    const std::string &help,
    117162                    void (*func)(void *),void *data);
     163
     164    bool _exit_on_problems;
     165
     166    void _terminate(ArgParserException::Reason reason) const;
    118167
    119168  public:
     
    381430    const std::vector<std::string> &files() const { return _file_args; }
    382431
     432    ///Throw instead of exit in case of problems
     433    void throwOnProblems()
     434    {
     435      _exit_on_problems=false;
     436    }
    383437  };
    384438}
  • TabularUnified lemon/bfs.h

    r525 r956  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    4848    ///The type of the map that stores the predecessor
    4949    ///arcs of the shortest paths.
    50     ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
     50    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
    5151    typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap;
    5252    ///Instantiates a \c PredMap.
     
    6363
    6464    ///The type of the map that indicates which nodes are processed.
    65     ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
     65    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
     66    ///By default, it is a NullMap.
    6667    typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
    6768    ///Instantiates a \c ProcessedMap.
     
    8283
    8384    ///The type of the map that indicates which nodes are reached.
    84     ///It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
     85    ///It must conform to
     86    ///the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
    8587    typedef typename Digraph::template NodeMap<bool> ReachedMap;
    8688    ///Instantiates a \c ReachedMap.
     
    9799
    98100    ///The type of the map that stores the distances of the nodes.
    99     ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
     101    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
    100102    typedef typename Digraph::template NodeMap<int> DistMap;
    101103    ///Instantiates a \c DistMap.
     
    121123  ///\tparam GR The type of the digraph the algorithm runs on.
    122124  ///The default type is \ref ListDigraph.
     125  ///\tparam TR The traits class that defines various types used by the
     126  ///algorithm. By default, it is \ref BfsDefaultTraits
     127  ///"BfsDefaultTraits<GR>".
     128  ///In most cases, this parameter should not be set directly,
     129  ///consider to use the named template parameters instead.
    123130#ifdef DOXYGEN
    124131  template <typename GR,
     
    226233    ///\ref named-templ-param "Named parameter" for setting
    227234    ///\c PredMap type.
    228     ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
     235    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
    229236    template <class T>
    230237    struct SetPredMap : public Bfs< Digraph, SetPredMapTraits<T> > {
     
    246253    ///\ref named-templ-param "Named parameter" for setting
    247254    ///\c DistMap type.
    248     ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
     255    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
    249256    template <class T>
    250257    struct SetDistMap : public Bfs< Digraph, SetDistMapTraits<T> > {
     
    266273    ///\ref named-templ-param "Named parameter" for setting
    267274    ///\c ReachedMap type.
    268     ///It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
     275    ///It must conform to
     276    ///the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
    269277    template <class T>
    270278    struct SetReachedMap : public Bfs< Digraph, SetReachedMapTraits<T> > {
     
    286294    ///\ref named-templ-param "Named parameter" for setting
    287295    ///\c ProcessedMap type.
    288     ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
     296    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
    289297    template <class T>
    290298    struct SetProcessedMap : public Bfs< Digraph, SetProcessedMapTraits<T> > {
     
    414422    ///The simplest way to execute the BFS algorithm is to use one of the
    415423    ///member functions called \ref run(Node) "run()".\n
    416     ///If you need more control on the execution, first you have to call
    417     ///\ref init(), then you can add several source nodes with
     424    ///If you need better control on the execution, you have to call
     425    ///\ref init() first, then you can add several source nodes with
    418426    ///\ref addSource(). Finally the actual path computation can be
    419427    ///performed with one of the \ref start() functions.
     
    701709    ///Runs the algorithm to visit all nodes in the digraph.
    702710
    703     ///This method runs the %BFS algorithm in order to
    704     ///compute the shortest path to each node.
    705     ///
    706     ///The algorithm computes
    707     ///- the shortest path tree (forest),
    708     ///- the distance of each node from the root(s).
     711    ///This method runs the %BFS algorithm in order to visit all nodes
     712    ///in the digraph.
    709713    ///
    710714    ///\note <tt>b.run(s)</tt> is just a shortcut of the following code.
     
    738742    ///@{
    739743
    740     ///The shortest path to a node.
    741 
    742     ///Returns the shortest path to a node.
     744    ///The shortest path to the given node.
     745
     746    ///Returns the shortest path to the given node from the root(s).
    743747    ///
    744748    ///\warning \c t should be reached from the root(s).
     
    748752    Path path(Node t) const { return Path(*G, *_pred, t); }
    749753
    750     ///The distance of a node from the root(s).
    751 
    752     ///Returns the distance of a node from the root(s).
     754    ///The distance of the given node from the root(s).
     755
     756    ///Returns the distance of the given node from the root(s).
    753757    ///
    754758    ///\warning If node \c v is not reached from the root(s), then
     
    759763    int dist(Node v) const { return (*_dist)[v]; }
    760764
    761     ///Returns the 'previous arc' of the shortest path tree for a node.
    762 
     765    ///\brief Returns the 'previous arc' of the shortest path tree for
     766    ///the given node.
     767    ///
    763768    ///This function returns the 'previous arc' of the shortest path
    764769    ///tree for the node \c v, i.e. it returns the last arc of a
     
    767772    ///
    768773    ///The shortest path tree used here is equal to the shortest path
    769     ///tree used in \ref predNode().
     774    ///tree used in \ref predNode() and \ref predMap().
    770775    ///
    771776    ///\pre Either \ref run(Node) "run()" or \ref init()
     
    773778    Arc predArc(Node v) const { return (*_pred)[v];}
    774779
    775     ///Returns the 'previous node' of the shortest path tree for a node.
    776 
     780    ///\brief Returns the 'previous node' of the shortest path tree for
     781    ///the given node.
     782    ///
    777783    ///This function returns the 'previous node' of the shortest path
    778784    ///tree for the node \c v, i.e. it returns the last but one node
    779     ///from a shortest path from a root to \c v. It is \c INVALID
     785    ///of a shortest path from a root to \c v. It is \c INVALID
    780786    ///if \c v is not reached from the root(s) or if \c v is a root.
    781787    ///
    782788    ///The shortest path tree used here is equal to the shortest path
    783     ///tree used in \ref predArc().
     789    ///tree used in \ref predArc() and \ref predMap().
    784790    ///
    785791    ///\pre Either \ref run(Node) "run()" or \ref init()
     
    802808    ///
    803809    ///Returns a const reference to the node map that stores the predecessor
    804     ///arcs, which form the shortest path tree.
     810    ///arcs, which form the shortest path tree (forest).
    805811    ///
    806812    ///\pre Either \ref run(Node) "run()" or \ref init()
     
    808814    const PredMap &predMap() const { return *_pred;}
    809815
    810     ///Checks if a node is reached from the root(s).
     816    ///Checks if the given node is reached from the root(s).
    811817
    812818    ///Returns \c true if \c v is reached from the root(s).
     
    834840    ///The type of the map that stores the predecessor
    835841    ///arcs of the shortest paths.
    836     ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
     842    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
    837843    typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap;
    838844    ///Instantiates a PredMap.
     
    849855
    850856    ///The type of the map that indicates which nodes are processed.
    851     ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
    852     ///By default it is a NullMap.
     857    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
     858    ///By default, it is a NullMap.
    853859    typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
    854860    ///Instantiates a ProcessedMap.
     
    869875
    870876    ///The type of the map that indicates which nodes are reached.
    871     ///It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
     877    ///It must conform to
     878    ///the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
    872879    typedef typename Digraph::template NodeMap<bool> ReachedMap;
    873880    ///Instantiates a ReachedMap.
     
    884891
    885892    ///The type of the map that stores the distances of the nodes.
    886     ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
     893    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
    887894    typedef typename Digraph::template NodeMap<int> DistMap;
    888895    ///Instantiates a DistMap.
     
    899906
    900907    ///The type of the shortest paths.
    901     ///It must meet the \ref concepts::Path "Path" concept.
     908    ///It must conform to the \ref concepts::Path "Path" concept.
    902909    typedef lemon::Path<Digraph> Path;
    903910  };
     
    905912  /// Default traits class used by BfsWizard
    906913
    907   /// To make it easier to use Bfs algorithm
    908   /// we have created a wizard class.
    909   /// This \ref BfsWizard class needs default traits,
    910   /// as well as the \ref Bfs class.
    911   /// The \ref BfsWizardBase is a class to be the default traits of the
    912   /// \ref BfsWizard class.
     914  /// Default traits class used by BfsWizard.
     915  /// \tparam GR The type of the digraph.
    913916  template<class GR>
    914917  class BfsWizardBase : public BfsWizardDefaultTraits<GR>
     
    938941    /// Constructor.
    939942
    940     /// This constructor does not require parameters, therefore it initiates
     943    /// This constructor does not require parameters, it initiates
    941944    /// all of the attributes to \c 0.
    942945    BfsWizardBase() : _g(0), _reached(0), _processed(0), _pred(0),
     
    963966  /// This class should only be used through the \ref bfs() function,
    964967  /// which makes it easier to use the algorithm.
     968  ///
     969  /// \tparam TR The traits class that defines various types used by the
     970  /// algorithm.
    965971  template<class TR>
    966972  class BfsWizard : public TR
     
    968974    typedef TR Base;
    969975
    970     ///The type of the digraph the algorithm runs on.
    971976    typedef typename TR::Digraph Digraph;
    972977
     
    976981    typedef typename Digraph::OutArcIt OutArcIt;
    977982
    978     ///\brief The type of the map that stores the predecessor
    979     ///arcs of the shortest paths.
    980983    typedef typename TR::PredMap PredMap;
    981     ///\brief The type of the map that stores the distances of the nodes.
    982984    typedef typename TR::DistMap DistMap;
    983     ///\brief The type of the map that indicates which nodes are reached.
    984985    typedef typename TR::ReachedMap ReachedMap;
    985     ///\brief The type of the map that indicates which nodes are processed.
    986986    typedef typename TR::ProcessedMap ProcessedMap;
    987     ///The type of the shortest paths
    988987    typedef typename TR::Path Path;
    989988
     
    10551054    ///Runs BFS algorithm to visit all nodes in the digraph.
    10561055
    1057     ///This method runs BFS algorithm in order to compute
    1058     ///the shortest path to each node.
     1056    ///This method runs BFS algorithm in order to visit all nodes
     1057    ///in the digraph.
    10591058    void run()
    10601059    {
     
    10681067      SetPredMapBase(const TR &b) : TR(b) {}
    10691068    };
    1070     ///\brief \ref named-func-param "Named parameter"
    1071     ///for setting PredMap object.
    1072     ///
    1073     ///\ref named-func-param "Named parameter"
    1074     ///for setting PredMap object.
     1069
     1070    ///\brief \ref named-templ-param "Named parameter" for setting
     1071    ///the predecessor map.
     1072    ///
     1073    ///\ref named-templ-param "Named parameter" function for setting
     1074    ///the map that stores the predecessor arcs of the nodes.
    10751075    template<class T>
    10761076    BfsWizard<SetPredMapBase<T> > predMap(const T &t)
     
    10861086      SetReachedMapBase(const TR &b) : TR(b) {}
    10871087    };
    1088     ///\brief \ref named-func-param "Named parameter"
    1089     ///for setting ReachedMap object.
    1090     ///
    1091     /// \ref named-func-param "Named parameter"
    1092     ///for setting ReachedMap object.
     1088
     1089    ///\brief \ref named-templ-param "Named parameter" for setting
     1090    ///the reached map.
     1091    ///
     1092    ///\ref named-templ-param "Named parameter" function for setting
     1093    ///the map that indicates which nodes are reached.
    10931094    template<class T>
    10941095    BfsWizard<SetReachedMapBase<T> > reachedMap(const T &t)
     
    11041105      SetDistMapBase(const TR &b) : TR(b) {}
    11051106    };
    1106     ///\brief \ref named-func-param "Named parameter"
    1107     ///for setting DistMap object.
    1108     ///
    1109     /// \ref named-func-param "Named parameter"
    1110     ///for setting DistMap object.
     1107
     1108    ///\brief \ref named-templ-param "Named parameter" for setting
     1109    ///the distance map.
     1110    ///
     1111    ///\ref named-templ-param "Named parameter" function for setting
     1112    ///the map that stores the distances of the nodes calculated
     1113    ///by the algorithm.
    11111114    template<class T>
    11121115    BfsWizard<SetDistMapBase<T> > distMap(const T &t)
     
    11221125      SetProcessedMapBase(const TR &b) : TR(b) {}
    11231126    };
    1124     ///\brief \ref named-func-param "Named parameter"
    1125     ///for setting ProcessedMap object.
    1126     ///
    1127     /// \ref named-func-param "Named parameter"
    1128     ///for setting ProcessedMap object.
     1127
     1128    ///\brief \ref named-func-param "Named parameter" for setting
     1129    ///the processed map.
     1130    ///
     1131    ///\ref named-templ-param "Named parameter" function for setting
     1132    ///the map that indicates which nodes are processed.
    11291133    template<class T>
    11301134    BfsWizard<SetProcessedMapBase<T> > processedMap(const T &t)
     
    12651269    ///
    12661270    /// The type of the map that indicates which nodes are reached.
    1267     /// It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
     1271    /// It must conform to
     1272    ///the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
    12681273    typedef typename Digraph::template NodeMap<bool> ReachedMap;
    12691274
     
    13031308  /// does not observe the BFS events. If you want to observe the BFS
    13041309  /// events, you should implement your own visitor class.
    1305   /// \tparam TR Traits class to set various data types used by the
    1306   /// algorithm. The default traits class is
    1307   /// \ref BfsVisitDefaultTraits "BfsVisitDefaultTraits<GR>".
    1308   /// See \ref BfsVisitDefaultTraits for the documentation of
    1309   /// a BFS visit traits class.
     1310  /// \tparam TR The traits class that defines various types used by the
     1311  /// algorithm. By default, it is \ref BfsVisitDefaultTraits
     1312  /// "BfsVisitDefaultTraits<GR>".
     1313  /// In most cases, this parameter should not be set directly,
     1314  /// consider to use the named template parameters instead.
    13101315#ifdef DOXYGEN
    13111316  template <typename GR, typename VS, typename TR>
     
    14261431    /// The simplest way to execute the BFS algorithm is to use one of the
    14271432    /// member functions called \ref run(Node) "run()".\n
    1428     /// If you need more control on the execution, first you have to call
    1429     /// \ref init(), then you can add several source nodes with
     1433    /// If you need better control on the execution, you have to call
     1434    /// \ref init() first, then you can add several source nodes with
    14301435    /// \ref addSource(). Finally the actual path computation can be
    14311436    /// performed with one of the \ref start() functions.
     
    16991704    /// \brief Runs the algorithm to visit all nodes in the digraph.
    17001705    ///
    1701     /// This method runs the %BFS algorithm in order to
    1702     /// compute the shortest path to each node.
    1703     ///
    1704     /// The algorithm computes
    1705     /// - the shortest path tree (forest),
    1706     /// - the distance of each node from the root(s).
     1706    /// This method runs the %BFS algorithm in order to visit all nodes
     1707    /// in the digraph.
    17071708    ///
    17081709    /// \note <tt>b.run(s)</tt> is just a shortcut of the following code.
     
    17361737    ///@{
    17371738
    1738     /// \brief Checks if a node is reached from the root(s).
     1739    /// \brief Checks if the given node is reached from the root(s).
    17391740    ///
    17401741    /// Returns \c true if \c v is reached from the root(s).
  • TabularUnified lemon/bin_heap.h

    r730 r758  
    2020#define LEMON_BIN_HEAP_H
    2121
    22 ///\ingroup auxdat
     22///\ingroup heaps
    2323///\file
    24 ///\brief Binary Heap implementation.
     24///\brief Binary heap implementation.
    2525
    2626#include <vector>
     
    3030namespace lemon {
    3131
    32   ///\ingroup auxdat
     32  /// \ingroup heaps
    3333  ///
    34   ///\brief A Binary Heap implementation.
     34  /// \brief Binary heap data structure.
    3535  ///
    36   ///This class implements the \e binary \e heap data structure.
     36  /// This class implements the \e binary \e heap data structure.
     37  /// It fully conforms to the \ref concepts::Heap "heap concept".
    3738  ///
    38   ///A \e heap is a data structure for storing items with specified values
    39   ///called \e priorities in such a way that finding the item with minimum
    40   ///priority is efficient. \c CMP specifies the ordering of the priorities.
    41   ///In a heap one can change the priority of an item, add or erase an
    42   ///item, etc.
    43   ///
    44   ///\tparam PR Type of the priority of the items.
    45   ///\tparam IM A read and writable item map with int values, used internally
    46   ///to handle the cross references.
    47   ///\tparam CMP A functor class for the ordering of the priorities.
    48   ///The default is \c std::less<PR>.
    49   ///
    50   ///\sa FibHeap
    51   ///\sa Dijkstra
     39  /// \tparam PR Type of the priorities of the items.
     40  /// \tparam IM A read-writable item map with \c int values, used
     41  /// internally to handle the cross references.
     42  /// \tparam CMP A functor class for comparing the priorities.
     43  /// The default is \c std::less<PR>.
     44#ifdef DOXYGEN
     45  template <typename PR, typename IM, typename CMP>
     46#else
    5247  template <typename PR, typename IM, typename CMP = std::less<PR> >
     48#endif
    5349  class BinHeap {
    54 
    5550  public:
    56     ///\e
     51
     52    /// Type of the item-int map.
    5753    typedef IM ItemIntMap;
    58     ///\e
     54    /// Type of the priorities.
    5955    typedef PR Prio;
    60     ///\e
     56    /// Type of the items stored in the heap.
    6157    typedef typename ItemIntMap::Key Item;
    62     ///\e
     58    /// Type of the item-priority pairs.
    6359    typedef std::pair<Item,Prio> Pair;
    64     ///\e
     60    /// Functor type for comparing the priorities.
    6561    typedef CMP Compare;
    6662
    67     /// \brief Type to represent the items states.
    68     ///
    69     /// Each Item element have a state associated to it. It may be "in heap",
    70     /// "pre heap" or "post heap". The latter two are indifferent from the
     63    /// \brief Type to represent the states of the items.
     64    ///
     65    /// Each item has a state associated to it. It can be "in heap",
     66    /// "pre-heap" or "post-heap". The latter two are indifferent from the
    7167    /// heap's point of view, but may be useful to the user.
    7268    ///
     
    8581
    8682  public:
    87     /// \brief The constructor.
    88     ///
    89     /// The constructor.
    90     /// \param map should be given to the constructor, since it is used
    91     /// internally to handle the cross references. The value of the map
    92     /// must be \c PRE_HEAP (<tt>-1</tt>) for every item.
     83
     84    /// \brief Constructor.
     85    ///
     86    /// Constructor.
     87    /// \param map A map that assigns \c int values to the items.
     88    /// It is used internally to handle the cross references.
     89    /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item.
    9390    explicit BinHeap(ItemIntMap &map) : _iim(map) {}
    9491
    95     /// \brief The constructor.
    96     ///
    97     /// The constructor.
    98     /// \param map should be given to the constructor, since it is used
    99     /// internally to handle the cross references. The value of the map
    100     /// should be PRE_HEAP (-1) for each element.
    101     ///
    102     /// \param comp The comparator function object.
     92    /// \brief Constructor.
     93    ///
     94    /// Constructor.
     95    /// \param map A map that assigns \c int values to the items.
     96    /// It is used internally to handle the cross references.
     97    /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item.
     98    /// \param comp The function object used for comparing the priorities.
    10399    BinHeap(ItemIntMap &map, const Compare &comp)
    104100      : _iim(map), _comp(comp) {}
    105101
    106102
    107     /// The number of items stored in the heap.
    108     ///
    109     /// \brief Returns the number of items stored in the heap.
     103    /// \brief The number of items stored in the heap.
     104    ///
     105    /// This function returns the number of items stored in the heap.
    110106    int size() const { return _data.size(); }
    111107
    112     /// \brief Checks if the heap stores no items.
    113     ///
    114     /// Returns \c true if and only if the heap stores no items.
     108    /// \brief Check if the heap is empty.
     109    ///
     110    /// This function returns \c true if the heap is empty.
    115111    bool empty() const { return _data.empty(); }
    116112
    117     /// \brief Make empty this heap.
    118     ///
    119     /// Make empty this heap. It does not change the cross reference map.
    120     /// If you want to reuse what is not surely empty you should first clear
    121     /// the heap and after that you should set the cross reference map for
    122     /// each item to \c PRE_HEAP.
     113    /// \brief Make the heap empty.
     114    ///
     115    /// This functon makes the heap empty.
     116    /// It does not change the cross reference map. If you want to reuse
     117    /// a heap that is not surely empty, you should first clear it and
     118    /// then you should set the cross reference map to \c PRE_HEAP
     119    /// for each item.
    123120    void clear() {
    124121      _data.clear();
     
    128125    static int parent(int i) { return (i-1)/2; }
    129126
    130     static int second_child(int i) { return 2*i+2; }
     127    static int secondChild(int i) { return 2*i+2; }
    131128    bool less(const Pair &p1, const Pair &p2) const {
    132129      return _comp(p1.second, p2.second);
    133130    }
    134131
    135     int bubble_up(int hole, Pair p) {
     132    int bubbleUp(int hole, Pair p) {
    136133      int par = parent(hole);
    137134      while( hole>0 && less(p,_data[par]) ) {
     
    144141    }
    145142
    146     int bubble_down(int hole, Pair p, int length) {
    147       int child = second_child(hole);
     143    int bubbleDown(int hole, Pair p, int length) {
     144      int child = secondChild(hole);
    148145      while(child < length) {
    149146        if( less(_data[child-1], _data[child]) ) {
     
    154151        move(_data[child], hole);
    155152        hole = child;
    156         child = second_child(hole);
     153        child = secondChild(hole);
    157154      }
    158155      child--;
     
    172169
    173170  public:
     171
    174172    /// \brief Insert a pair of item and priority into the heap.
    175173    ///
    176     /// Adds \c p.first to the heap with priority \c p.second.
     174    /// This function inserts \c p.first to the heap with priority
     175    /// \c p.second.
    177176    /// \param p The pair to insert.
     177    /// \pre \c p.first must not be stored in the heap.
    178178    void push(const Pair &p) {
    179179      int n = _data.size();
    180180      _data.resize(n+1);
    181       bubble_up(n, p);
    182     }
    183 
    184     /// \brief Insert an item into the heap with the given heap.
    185     ///
    186     /// Adds \c i to the heap with priority \c p.
     181      bubbleUp(n, p);
     182    }
     183
     184    /// \brief Insert an item into the heap with the given priority.
     185    ///
     186    /// This function inserts the given item into the heap with the
     187    /// given priority.
    187188    /// \param i The item to insert.
    188189    /// \param p The priority of the item.
     190    /// \pre \e i must not be stored in the heap.
    189191    void push(const Item &i, const Prio &p) { push(Pair(i,p)); }
    190192
    191     /// \brief Returns the item with minimum priority relative to \c Compare.
    192     ///
    193     /// This method returns the item with minimum priority relative to \c
    194     /// Compare.
    195     /// \pre The heap must be nonempty.
     193    /// \brief Return the item having minimum priority.
     194    ///
     195    /// This function returns the item having minimum priority.
     196    /// \pre The heap must be non-empty.
    196197    Item top() const {
    197198      return _data[0].first;
    198199    }
    199200
    200     /// \brief Returns the minimum priority relative to \c Compare.
    201     ///
    202     /// It returns the minimum priority relative to \c Compare.
    203     /// \pre The heap must be nonempty.
     201    /// \brief The minimum priority.
     202    ///
     203    /// This function returns the minimum priority.
     204    /// \pre The heap must be non-empty.
    204205    Prio prio() const {
    205206      return _data[0].second;
    206207    }
    207208
    208     /// \brief Deletes the item with minimum priority relative to \c Compare.
    209     ///
    210     /// This method deletes the item with minimum priority relative to \c
    211     /// Compare from the heap.
     209    /// \brief Remove the item having minimum priority.
     210    ///
     211    /// This function removes the item having minimum priority.
    212212    /// \pre The heap must be non-empty.
    213213    void pop() {
     
    215215      _iim.set(_data[0].first, POST_HEAP);
    216216      if (n > 0) {
    217         bubble_down(0, _data[n], n);
     217        bubbleDown(0, _data[n], n);
    218218      }
    219219      _data.pop_back();
    220220    }
    221221
    222     /// \brief Deletes \c i from the heap.
    223     ///
    224     /// This method deletes item \c i from the heap.
    225     /// \param i The item to erase.
    226     /// \pre The item should be in the heap.
     222    /// \brief Remove the given item from the heap.
     223    ///
     224    /// This function removes the given item from the heap if it is
     225    /// already stored.
     226    /// \param i The item to delete.
     227    /// \pre \e i must be in the heap.
    227228    void erase(const Item &i) {
    228229      int h = _iim[i];
     
    230231      _iim.set(_data[h].first, POST_HEAP);
    231232      if( h < n ) {
    232         if ( bubble_up(h, _data[n]) == h) {
    233           bubble_down(h, _data[n], n);
     233        if ( bubbleUp(h, _data[n]) == h) {
     234          bubbleDown(h, _data[n], n);
    234235        }
    235236      }
     
    237238    }
    238239
    239 
    240     /// \brief Returns the priority of \c i.
    241     ///
    242     /// This function returns the priority of item \c i.
    243     /// \param i The item.
    244     /// \pre \c i must be in the heap.
     240    /// \brief The priority of the given item.
     241    ///
     242    /// This function returns the priority of the given item.
     243    /// \param i The item.
     244    /// \pre \e i must be in the heap.
    245245    Prio operator[](const Item &i) const {
    246246      int idx = _iim[i];
     
    248248    }
    249249
    250     /// \brief \c i gets to the heap with priority \c p independently
    251     /// if \c i was already there.
    252     ///
    253     /// This method calls \ref push(\c i, \c p) if \c i is not stored
    254     /// in the heap and sets the priority of \c i to \c p otherwise.
     250    /// \brief Set the priority of an item or insert it, if it is
     251    /// not stored in the heap.
     252    ///
     253    /// This method sets the priority of the given item if it is
     254    /// already stored in the heap. Otherwise it inserts the given
     255    /// item into the heap with the given priority.
    255256    /// \param i The item.
    256257    /// \param p The priority.
     
    261262      }
    262263      else if( _comp(p, _data[idx].second) ) {
    263         bubble_up(idx, Pair(i,p));
     264        bubbleUp(idx, Pair(i,p));
    264265      }
    265266      else {
    266         bubble_down(idx, Pair(i,p), _data.size());
    267       }
    268     }
    269 
    270     /// \brief Decreases the priority of \c i to \c p.
    271     ///
    272     /// This method decreases the priority of item \c i to \c p.
     267        bubbleDown(idx, Pair(i,p), _data.size());
     268      }
     269    }
     270
     271    /// \brief Decrease the priority of an item to the given value.
     272    ///
     273    /// This function decreases the priority of an item to the given value.
    273274    /// \param i The item.
    274275    /// \param p The priority.
    275     /// \pre \c i must be stored in the heap with priority at least \c
    276     /// p relative to \c Compare.
     276    /// \pre \e i must be stored in the heap with priority at least \e p.
    277277    void decrease(const Item &i, const Prio &p) {
    278278      int idx = _iim[i];
    279       bubble_up(idx, Pair(i,p));
    280     }
    281 
    282     /// \brief Increases the priority of \c i to \c p.
    283     ///
    284     /// This method sets the priority of item \c i to \c p.
     279      bubbleUp(idx, Pair(i,p));
     280    }
     281
     282    /// \brief Increase the priority of an item to the given value.
     283    ///
     284    /// This function increases the priority of an item to the given value.
    285285    /// \param i The item.
    286286    /// \param p The priority.
    287     /// \pre \c i must be stored in the heap with priority at most \c
    288     /// p relative to \c Compare.
     287    /// \pre \e i must be stored in the heap with priority at most \e p.
    289288    void increase(const Item &i, const Prio &p) {
    290289      int idx = _iim[i];
    291       bubble_down(idx, Pair(i,p), _data.size());
    292     }
    293 
    294     /// \brief Returns if \c item is in, has already been in, or has
    295     /// never been in the heap.
    296     ///
    297     /// This method returns PRE_HEAP if \c item has never been in the
    298     /// heap, IN_HEAP if it is in the heap at the moment, and POST_HEAP
    299     /// otherwise. In the latter case it is possible that \c item will
    300     /// get back to the heap again.
     290      bubbleDown(idx, Pair(i,p), _data.size());
     291    }
     292
     293    /// \brief Return the state of an item.
     294    ///
     295    /// This method returns \c PRE_HEAP if the given item has never
     296    /// been in the heap, \c IN_HEAP if it is in the heap at the moment,
     297    /// and \c POST_HEAP otherwise.
     298    /// In the latter case it is possible that the item will get back
     299    /// to the heap again.
    301300    /// \param i The item.
    302301    State state(const Item &i) const {
     
    307306    }
    308307
    309     /// \brief Sets the state of the \c item in the heap.
    310     ///
    311     /// Sets the state of the \c item in the heap. It can be used to
    312     /// manually clear the heap when it is important to achive the
    313     /// better time complexity.
     308    /// \brief Set the state of an item in the heap.
     309    ///
     310    /// This function sets the state of the given item in the heap.
     311    /// It can be used to manually clear the heap when it is important
     312    /// to achive better time complexity.
    314313    /// \param i The item.
    315314    /// \param st The state. It should not be \c IN_HEAP.
     
    328327    }
    329328
    330     /// \brief Replaces an item in the heap.
    331     ///
    332     /// The \c i item is replaced with \c j item. The \c i item should
    333     /// be in the heap, while the \c j should be out of the heap. The
    334     /// \c i item will out of the heap and \c j will be in the heap
    335     /// with the same prioriority as prevoiusly the \c i item.
     329    /// \brief Replace an item in the heap.
     330    ///
     331    /// This function replaces item \c i with item \c j.
     332    /// Item \c i must be in the heap, while \c j must be out of the heap.
     333    /// After calling this method, item \c i will be out of the
     334    /// heap and \c j will be in the heap with the same prioriority
     335    /// as item \c i had before.
    336336    void replace(const Item& i, const Item& j) {
    337337      int idx = _iim[i];
  • TabularUnified lemon/bits/array_map.h

    r664 r956  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    7171
    7272  private:
    73  
     73
    7474    // The MapBase of the Map which imlements the core regisitry function.
    7575    typedef typename Notifier::ObserverBase Parent;
  • TabularUnified lemon/bits/default_map.h

    r674 r956  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    158158  public:
    159159    typedef DefaultMap<_Graph, _Item, _Value> Map;
    160    
     160
    161161    typedef typename Parent::GraphType GraphType;
    162162    typedef typename Parent::Value Value;
  • TabularUnified lemon/bits/edge_set_extender.h

    r967 r1110  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2008
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    6464    Node oppositeNode(const Node &n, const Arc &e) const {
    6565      if (n == Parent::source(e))
    66         return Parent::target(e);
     66        return Parent::target(e);
    6767      else if(n==Parent::target(e))
    68         return Parent::source(e);
     68        return Parent::source(e);
    6969      else
    70         return INVALID;
     70        return INVALID;
    7171    }
    7272
     
    9292    // Iterable extensions
    9393
    94     class NodeIt : public Node { 
     94    class NodeIt : public Node {
    9595      const Digraph* digraph;
    9696    public:
     
    101101
    102102      explicit NodeIt(const Digraph& _graph) : digraph(&_graph) {
    103         _graph.first(static_cast<Node&>(*this));
    104       }
    105 
    106       NodeIt(const Digraph& _graph, const Node& node) 
    107         : Node(node), digraph(&_graph) {}
    108 
    109       NodeIt& operator++() { 
    110         digraph->next(*this);
    111         return *this;
    112       }
    113 
    114     };
    115 
    116 
    117     class ArcIt : public Arc { 
     103        _graph.first(static_cast<Node&>(*this));
     104      }
     105
     106      NodeIt(const Digraph& _graph, const Node& node)
     107        : Node(node), digraph(&_graph) {}
     108
     109      NodeIt& operator++() {
     110        digraph->next(*this);
     111        return *this;
     112      }
     113
     114    };
     115
     116
     117    class ArcIt : public Arc {
    118118      const Digraph* digraph;
    119119    public:
     
    124124
    125125      explicit ArcIt(const Digraph& _graph) : digraph(&_graph) {
    126         _graph.first(static_cast<Arc&>(*this));
    127       }
    128 
    129       ArcIt(const Digraph& _graph, const Arc& e) : 
    130         Arc(e), digraph(&_graph) { }
    131 
    132       ArcIt& operator++() { 
    133         digraph->next(*this);
    134         return *this;
    135       }
    136 
    137     };
    138 
    139 
    140     class OutArcIt : public Arc { 
     126        _graph.first(static_cast<Arc&>(*this));
     127      }
     128
     129      ArcIt(const Digraph& _graph, const Arc& e) :
     130        Arc(e), digraph(&_graph) { }
     131
     132      ArcIt& operator++() {
     133        digraph->next(*this);
     134        return *this;
     135      }
     136
     137    };
     138
     139
     140    class OutArcIt : public Arc {
    141141      const Digraph* digraph;
    142142    public:
     
    146146      OutArcIt(Invalid i) : Arc(i) { }
    147147
    148       OutArcIt(const Digraph& _graph, const Node& node) 
    149         : digraph(&_graph) {
    150         _graph.firstOut(*this, node);
    151       }
    152 
    153       OutArcIt(const Digraph& _graph, const Arc& arc) 
    154         : Arc(arc), digraph(&_graph) {}
    155 
    156       OutArcIt& operator++() { 
    157         digraph->nextOut(*this);
    158         return *this;
    159       }
    160 
    161     };
    162 
    163 
    164     class InArcIt : public Arc { 
     148      OutArcIt(const Digraph& _graph, const Node& node)
     149        : digraph(&_graph) {
     150        _graph.firstOut(*this, node);
     151      }
     152
     153      OutArcIt(const Digraph& _graph, const Arc& arc)
     154        : Arc(arc), digraph(&_graph) {}
     155
     156      OutArcIt& operator++() {
     157        digraph->nextOut(*this);
     158        return *this;
     159      }
     160
     161    };
     162
     163
     164    class InArcIt : public Arc {
    165165      const Digraph* digraph;
    166166    public:
     
    170170      InArcIt(Invalid i) : Arc(i) { }
    171171
    172       InArcIt(const Digraph& _graph, const Node& node) 
    173         : digraph(&_graph) {
    174         _graph.firstIn(*this, node);
    175       }
    176 
    177       InArcIt(const Digraph& _graph, const Arc& arc) : 
    178         Arc(arc), digraph(&_graph) {}
    179 
    180       InArcIt& operator++() { 
    181         digraph->nextIn(*this);
    182         return *this;
     172      InArcIt(const Digraph& _graph, const Node& node)
     173        : digraph(&_graph) {
     174        _graph.firstIn(*this, node);
     175      }
     176
     177      InArcIt(const Digraph& _graph, const Arc& arc) :
     178        Arc(arc), digraph(&_graph) {}
     179
     180      InArcIt& operator++() {
     181        digraph->nextIn(*this);
     182        return *this;
    183183      }
    184184
     
    216216
    217217    // Mappable extension
    218    
     218
    219219    template <typename _Value>
    220     class ArcMap 
     220    class ArcMap
    221221      : public MapExtender<DefaultMap<Digraph, Arc, _Value> > {
    222222      typedef MapExtender<DefaultMap<Digraph, Arc, _Value> > Parent;
    223223
    224224    public:
    225       explicit ArcMap(const Digraph& _g) 
    226         : Parent(_g) {}
    227       ArcMap(const Digraph& _g, const _Value& _v) 
    228         : Parent(_g, _v) {}
     225      explicit ArcMap(const Digraph& _g)
     226        : Parent(_g) {}
     227      ArcMap(const Digraph& _g, const _Value& _v)
     228        : Parent(_g, _v) {}
    229229
    230230      ArcMap& operator=(const ArcMap& cmap) {
    231         return operator=<ArcMap>(cmap);
     231        return operator=<ArcMap>(cmap);
    232232      }
    233233
     
    235235      ArcMap& operator=(const CMap& cmap) {
    236236        Parent::operator=(cmap);
    237         return *this;
     237        return *this;
    238238      }
    239239
     
    248248      return arc;
    249249    }
    250    
     250
    251251    void clear() {
    252252      notifier(Arc()).clear();
     
    313313    Node oppositeNode(const Node &n, const Edge &e) const {
    314314      if( n == Parent::u(e))
    315         return Parent::v(e);
     315        return Parent::v(e);
    316316      else if( n == Parent::v(e))
    317         return Parent::u(e);
     317        return Parent::u(e);
    318318      else
    319         return INVALID;
     319        return INVALID;
    320320    }
    321321
     
    341341
    342342    using Parent::notifier;
    343    
     343
    344344    ArcNotifier& notifier(Arc) const {
    345345      return arc_notifier;
     
    351351
    352352
    353     class NodeIt : public Node { 
     353    class NodeIt : public Node {
    354354      const Graph* graph;
    355355    public:
     
    360360
    361361      explicit NodeIt(const Graph& _graph) : graph(&_graph) {
    362         _graph.first(static_cast<Node&>(*this));
    363       }
    364 
    365       NodeIt(const Graph& _graph, const Node& node) 
    366         : Node(node), graph(&_graph) {}
    367 
    368       NodeIt& operator++() { 
    369         graph->next(*this);
    370         return *this;
    371       }
    372 
    373     };
    374 
    375 
    376     class ArcIt : public Arc { 
     362        _graph.first(static_cast<Node&>(*this));
     363      }
     364
     365      NodeIt(const Graph& _graph, const Node& node)
     366        : Node(node), graph(&_graph) {}
     367
     368      NodeIt& operator++() {
     369        graph->next(*this);
     370        return *this;
     371      }
     372
     373    };
     374
     375
     376    class ArcIt : public Arc {
    377377      const Graph* graph;
    378378    public:
     
    383383
    384384      explicit ArcIt(const Graph& _graph) : graph(&_graph) {
    385         _graph.first(static_cast<Arc&>(*this));
    386       }
    387 
    388       ArcIt(const Graph& _graph, const Arc& e) : 
    389         Arc(e), graph(&_graph) { }
    390 
    391       ArcIt& operator++() { 
    392         graph->next(*this);
    393         return *this;
    394       }
    395 
    396     };
    397 
    398 
    399     class OutArcIt : public Arc { 
     385        _graph.first(static_cast<Arc&>(*this));
     386      }
     387
     388      ArcIt(const Graph& _graph, const Arc& e) :
     389        Arc(e), graph(&_graph) { }
     390
     391      ArcIt& operator++() {
     392        graph->next(*this);
     393        return *this;
     394      }
     395
     396    };
     397
     398
     399    class OutArcIt : public Arc {
    400400      const Graph* graph;
    401401    public:
     
    405405      OutArcIt(Invalid i) : Arc(i) { }
    406406
    407       OutArcIt(const Graph& _graph, const Node& node) 
    408         : graph(&_graph) {
    409         _graph.firstOut(*this, node);
    410       }
    411 
    412       OutArcIt(const Graph& _graph, const Arc& arc) 
    413         : Arc(arc), graph(&_graph) {}
    414 
    415       OutArcIt& operator++() { 
    416         graph->nextOut(*this);
    417         return *this;
    418       }
    419 
    420     };
    421 
    422 
    423     class InArcIt : public Arc { 
     407      OutArcIt(const Graph& _graph, const Node& node)
     408        : graph(&_graph) {
     409        _graph.firstOut(*this, node);
     410      }
     411
     412      OutArcIt(const Graph& _graph, const Arc& arc)
     413        : Arc(arc), graph(&_graph) {}
     414
     415      OutArcIt& operator++() {
     416        graph->nextOut(*this);
     417        return *this;
     418      }
     419
     420    };
     421
     422
     423    class InArcIt : public Arc {
    424424      const Graph* graph;
    425425    public:
     
    429429      InArcIt(Invalid i) : Arc(i) { }
    430430
    431       InArcIt(const Graph& _graph, const Node& node) 
    432         : graph(&_graph) {
    433         _graph.firstIn(*this, node);
    434       }
    435 
    436       InArcIt(const Graph& _graph, const Arc& arc) : 
    437         Arc(arc), graph(&_graph) {}
    438 
    439       InArcIt& operator++() { 
    440         graph->nextIn(*this);
    441         return *this;
    442       }
    443 
    444     };
    445 
    446 
    447     class EdgeIt : public Parent::Edge { 
     431      InArcIt(const Graph& _graph, const Node& node)
     432        : graph(&_graph) {
     433        _graph.firstIn(*this, node);
     434      }
     435
     436      InArcIt(const Graph& _graph, const Arc& arc) :
     437        Arc(arc), graph(&_graph) {}
     438
     439      InArcIt& operator++() {
     440        graph->nextIn(*this);
     441        return *this;
     442      }
     443
     444    };
     445
     446
     447    class EdgeIt : public Parent::Edge {
    448448      const Graph* graph;
    449449    public:
     
    454454
    455455      explicit EdgeIt(const Graph& _graph) : graph(&_graph) {
    456         _graph.first(static_cast<Edge&>(*this));
    457       }
    458 
    459       EdgeIt(const Graph& _graph, const Edge& e) : 
    460         Edge(e), graph(&_graph) { }
    461 
    462       EdgeIt& operator++() { 
    463         graph->next(*this);
    464         return *this;
     456        _graph.first(static_cast<Edge&>(*this));
     457      }
     458
     459      EdgeIt(const Graph& _graph, const Edge& e) :
     460        Edge(e), graph(&_graph) { }
     461
     462      EdgeIt& operator++() {
     463        graph->next(*this);
     464        return *this;
    465465      }
    466466
     
    478478
    479479      IncEdgeIt(const Graph& _graph, const Node &n) : graph(&_graph) {
    480         _graph.firstInc(*this, direction, n);
     480        _graph.firstInc(*this, direction, n);
    481481      }
    482482
    483483      IncEdgeIt(const Graph& _graph, const Edge &ue, const Node &n)
    484         : graph(&_graph), Edge(ue) {
    485         direction = (_graph.source(ue) == n);
     484        : graph(&_graph), Edge(ue) {
     485        direction = (_graph.source(ue) == n);
    486486      }
    487487
    488488      IncEdgeIt& operator++() {
    489         graph->nextInc(*this, direction);
    490         return *this;
     489        graph->nextInc(*this, direction);
     490        return *this;
    491491      }
    492492    };
     
    535535
    536536    template <typename _Value>
    537     class ArcMap 
     537    class ArcMap
    538538      : public MapExtender<DefaultMap<Graph, Arc, _Value> > {
    539539      typedef MapExtender<DefaultMap<Graph, Arc, _Value> > Parent;
    540540
    541541    public:
    542       explicit ArcMap(const Graph& _g) 
    543         : Parent(_g) {}
    544       ArcMap(const Graph& _g, const _Value& _v) 
    545         : Parent(_g, _v) {}
     542      explicit ArcMap(const Graph& _g)
     543        : Parent(_g) {}
     544      ArcMap(const Graph& _g, const _Value& _v)
     545        : Parent(_g, _v) {}
    546546
    547547      ArcMap& operator=(const ArcMap& cmap) {
    548         return operator=<ArcMap>(cmap);
     548        return operator=<ArcMap>(cmap);
    549549      }
    550550
     
    552552      ArcMap& operator=(const CMap& cmap) {
    553553        Parent::operator=(cmap);
    554         return *this;
     554        return *this;
    555555      }
    556556
     
    559559
    560560    template <typename _Value>
    561     class EdgeMap 
     561    class EdgeMap
    562562      : public MapExtender<DefaultMap<Graph, Edge, _Value> > {
    563563      typedef MapExtender<DefaultMap<Graph, Edge, _Value> > Parent;
    564564
    565565    public:
    566       explicit EdgeMap(const Graph& _g) 
    567         : Parent(_g) {}
    568 
    569       EdgeMap(const Graph& _g, const _Value& _v) 
    570         : Parent(_g, _v) {}
     566      explicit EdgeMap(const Graph& _g)
     567        : Parent(_g) {}
     568
     569      EdgeMap(const Graph& _g, const _Value& _v)
     570        : Parent(_g, _v) {}
    571571
    572572      EdgeMap& operator=(const EdgeMap& cmap) {
    573         return operator=<EdgeMap>(cmap);
     573        return operator=<EdgeMap>(cmap);
    574574      }
    575575
     
    577577      EdgeMap& operator=(const CMap& cmap) {
    578578        Parent::operator=(cmap);
    579         return *this;
     579        return *this;
    580580      }
    581581
     
    594594      return edge;
    595595    }
    596    
     596
    597597    void clear() {
    598598      notifier(Arc()).clear();
     
    620620      arc_notifier.clear();
    621621    }
    622    
     622
    623623  };
    624624
  • TabularUnified lemon/bits/graph_adaptor_extender.h

    r965 r1081  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2011
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
  • TabularUnified lemon/bits/graph_extender.h

    r732 r825  
    5757    }
    5858
    59     Node fromId(int id, Node) const {
     59    static Node fromId(int id, Node) {
    6060      return Parent::nodeFromId(id);
    6161    }
    6262
    63     Arc fromId(int id, Arc) const {
     63    static Arc fromId(int id, Arc) {
    6464      return Parent::arcFromId(id);
    6565    }
     
    356356    }
    357357
    358     Node fromId(int id, Node) const {
     358    static Node fromId(int id, Node) {
    359359      return Parent::nodeFromId(id);
    360360    }
    361361
    362     Arc fromId(int id, Arc) const {
     362    static Arc fromId(int id, Arc) {
    363363      return Parent::arcFromId(id);
    364364    }
    365365
    366     Edge fromId(int id, Edge) const {
     366    static Edge fromId(int id, Edge) {
    367367      return Parent::edgeFromId(id);
    368368    }
  • TabularUnified lemon/bits/path_dump.h

    r973 r1081  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2011
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
  • TabularUnified lemon/bits/solver_bits.h

    r566 r956  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2008
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
  • TabularUnified lemon/bits/windows.cc

    r1053 r1084  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2011
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    9999      GetSystemTime(&time);
    100100      char buf1[11], buf2[9], buf3[5];
    101           if (GetDateFormat(MY_LOCALE, 0, &time,
     101          if (GetDateFormat(MY_LOCALE, 0, &time,
    102102                        ("ddd MMM dd"), buf1, 11) &&
    103103          GetTimeFormat(MY_LOCALE, 0, &time,
  • TabularUnified lemon/bucket_heap.h

    r730 r956  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    2020#define LEMON_BUCKET_HEAP_H
    2121
    22 ///\ingroup auxdat
     22///\ingroup heaps
    2323///\file
    24 ///\brief Bucket Heap implementation.
     24///\brief Bucket heap implementation.
    2525
    2626#include <vector>
     
    5454  }
    5555
    56   /// \ingroup auxdat
    57   ///
    58   /// \brief A Bucket Heap implementation.
    59   ///
    60   /// This class implements the \e bucket \e heap data structure. A \e heap
    61   /// is a data structure for storing items with specified values called \e
    62   /// priorities in such a way that finding the item with minimum priority is
    63   /// efficient. The bucket heap is very simple implementation, it can store
    64   /// only integer priorities and it stores for each priority in the
    65   /// \f$ [0..C) \f$ range a list of items. So it should be used only when
    66   /// the priorities are small. It is not intended to use as dijkstra heap.
    67   ///
    68   /// \param IM A read and write Item int map, used internally
    69   /// to handle the cross references.
    70   /// \param MIN If the given parameter is false then instead of the
    71   /// minimum value the maximum can be retrivied with the top() and
    72   /// prio() member functions.
     56  /// \ingroup heaps
     57  ///
     58  /// \brief Bucket heap data structure.
     59  ///
     60  /// This class implements the \e bucket \e heap data structure.
     61  /// It practically conforms to the \ref concepts::Heap "heap concept",
     62  /// but it has some limitations.
     63  ///
     64  /// The bucket heap is a very simple structure. It can store only
     65  /// \c int priorities and it maintains a list of items for each priority
     66  /// in the range <tt>[0..C)</tt>. So it should only be used when the
     67  /// priorities are small. It is not intended to use as a Dijkstra heap.
     68  ///
     69  /// \tparam IM A read-writable item map with \c int values, used
     70  /// internally to handle the cross references.
     71  /// \tparam MIN Indicate if the heap is a \e min-heap or a \e max-heap.
     72  /// The default is \e min-heap. If this parameter is set to \c false,
     73  /// then the comparison is reversed, so the top(), prio() and pop()
     74  /// functions deal with the item having maximum priority instead of the
     75  /// minimum.
     76  ///
     77  /// \sa SimpleBucketHeap
    7378  template <typename IM, bool MIN = true>
    7479  class BucketHeap {
    7580
    7681  public:
    77     /// \e
    78     typedef typename IM::Key Item;
    79     /// \e
     82
     83    /// Type of the item-int map.
     84    typedef IM ItemIntMap;
     85    /// Type of the priorities.
    8086    typedef int Prio;
    81     /// \e
    82     typedef std::pair<Item, Prio> Pair;
    83     /// \e
    84     typedef IM ItemIntMap;
     87    /// Type of the items stored in the heap.
     88    typedef typename ItemIntMap::Key Item;
     89    /// Type of the item-priority pairs.
     90    typedef std::pair<Item,Prio> Pair;
    8591
    8692  private:
     
    9096  public:
    9197
    92     /// \brief Type to represent the items states.
    93     ///
    94     /// Each Item element have a state associated to it. It may be "in heap",
    95     /// "pre heap" or "post heap". The latter two are indifferent from the
     98    /// \brief Type to represent the states of the items.
     99    ///
     100    /// Each item has a state associated to it. It can be "in heap",
     101    /// "pre-heap" or "post-heap". The latter two are indifferent from the
    96102    /// heap's point of view, but may be useful to the user.
    97103    ///
     
    105111
    106112  public:
    107     /// \brief The constructor.
    108     ///
    109     /// The constructor.
    110     /// \param map should be given to the constructor, since it is used
    111     /// internally to handle the cross references. The value of the map
    112     /// should be PRE_HEAP (-1) for each element.
     113
     114    /// \brief Constructor.
     115    ///
     116    /// Constructor.
     117    /// \param map A map that assigns \c int values to the items.
     118    /// It is used internally to handle the cross references.
     119    /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item.
    113120    explicit BucketHeap(ItemIntMap &map) : _iim(map), _minimum(0) {}
    114121
    115     /// The number of items stored in the heap.
    116     ///
    117     /// \brief Returns the number of items stored in the heap.
     122    /// \brief The number of items stored in the heap.
     123    ///
     124    /// This function returns the number of items stored in the heap.
    118125    int size() const { return _data.size(); }
    119126
    120     /// \brief Checks if the heap stores no items.
    121     ///
    122     /// Returns \c true if and only if the heap stores no items.
     127    /// \brief Check if the heap is empty.
     128    ///
     129    /// This function returns \c true if the heap is empty.
    123130    bool empty() const { return _data.empty(); }
    124131
    125     /// \brief Make empty this heap.
    126     ///
    127     /// Make empty this heap. It does not change the cross reference
    128     /// map.  If you want to reuse a heap what is not surely empty you
    129     /// should first clear the heap and after that you should set the
    130     /// cross reference map for each item to \c PRE_HEAP.
     132    /// \brief Make the heap empty.
     133    ///
     134    /// This functon makes the heap empty.
     135    /// It does not change the cross reference map. If you want to reuse
     136    /// a heap that is not surely empty, you should first clear it and
     137    /// then you should set the cross reference map to \c PRE_HEAP
     138    /// for each item.
    131139    void clear() {
    132140      _data.clear(); _first.clear(); _minimum = 0;
     
    135143  private:
    136144
    137     void relocate_last(int idx) {
     145    void relocateLast(int idx) {
    138146      if (idx + 1 < int(_data.size())) {
    139147        _data[idx] = _data.back();
     
    175183
    176184  public:
     185
    177186    /// \brief Insert a pair of item and priority into the heap.
    178187    ///
    179     /// Adds \c p.first to the heap with priority \c p.second.
     188    /// This function inserts \c p.first to the heap with priority
     189    /// \c p.second.
    180190    /// \param p The pair to insert.
     191    /// \pre \c p.first must not be stored in the heap.
    181192    void push(const Pair& p) {
    182193      push(p.first, p.second);
     
    185196    /// \brief Insert an item into the heap with the given priority.
    186197    ///
    187     /// Adds \c i to the heap with priority \c p.
     198    /// This function inserts the given item into the heap with the
     199    /// given priority.
    188200    /// \param i The item to insert.
    189201    /// \param p The priority of the item.
     202    /// \pre \e i must not be stored in the heap.
    190203    void push(const Item &i, const Prio &p) {
    191204      int idx = _data.size();
     
    198211    }
    199212
    200     /// \brief Returns the item with minimum priority.
    201     ///
    202     /// This method returns the item with minimum priority.
    203     /// \pre The heap must be nonempty.
     213    /// \brief Return the item having minimum priority.
     214    ///
     215    /// This function returns the item having minimum priority.
     216    /// \pre The heap must be non-empty.
    204217    Item top() const {
    205218      while (_first[_minimum] == -1) {
     
    209222    }
    210223
    211     /// \brief Returns the minimum priority.
    212     ///
    213     /// It returns the minimum priority.
    214     /// \pre The heap must be nonempty.
     224    /// \brief The minimum priority.
     225    ///
     226    /// This function returns the minimum priority.
     227    /// \pre The heap must be non-empty.
    215228    Prio prio() const {
    216229      while (_first[_minimum] == -1) {
     
    220233    }
    221234
    222     /// \brief Deletes the item with minimum priority.
    223     ///
    224     /// This method deletes the item with minimum priority from the heap.
     235    /// \brief Remove the item having minimum priority.
     236    ///
     237    /// This function removes the item having minimum priority.
    225238    /// \pre The heap must be non-empty.
    226239    void pop() {
     
    231244      _iim[_data[idx].item] = -2;
    232245      unlace(idx);
    233       relocate_last(idx);
    234     }
    235 
    236     /// \brief Deletes \c i from the heap.
    237     ///
    238     /// This method deletes item \c i from the heap, if \c i was
    239     /// already stored in the heap.
    240     /// \param i The item to erase.
     246      relocateLast(idx);
     247    }
     248
     249    /// \brief Remove the given item from the heap.
     250    ///
     251    /// This function removes the given item from the heap if it is
     252    /// already stored.
     253    /// \param i The item to delete.
     254    /// \pre \e i must be in the heap.
    241255    void erase(const Item &i) {
    242256      int idx = _iim[i];
    243257      _iim[_data[idx].item] = -2;
    244258      unlace(idx);
    245       relocate_last(idx);
    246     }
    247 
    248 
    249     /// \brief Returns the priority of \c i.
    250     ///
    251     /// This function returns the priority of item \c i.
    252     /// \pre \c i must be in the heap.
    253     /// \param i The item.
     259      relocateLast(idx);
     260    }
     261
     262    /// \brief The priority of the given item.
     263    ///
     264    /// This function returns the priority of the given item.
     265    /// \param i The item.
     266    /// \pre \e i must be in the heap.
    254267    Prio operator[](const Item &i) const {
    255268      int idx = _iim[i];
     
    257270    }
    258271
    259     /// \brief \c i gets to the heap with priority \c p independently
    260     /// if \c i was already there.
    261     ///
    262     /// This method calls \ref push(\c i, \c p) if \c i is not stored
    263     /// in the heap and sets the priority of \c i to \c p otherwise.
     272    /// \brief Set the priority of an item or insert it, if it is
     273    /// not stored in the heap.
     274    ///
     275    /// This method sets the priority of the given item if it is
     276    /// already stored in the heap. Otherwise it inserts the given
     277    /// item into the heap with the given priority.
    264278    /// \param i The item.
    265279    /// \param p The priority.
     
    275289    }
    276290
    277     /// \brief Decreases the priority of \c i to \c p.
    278     ///
    279     /// This method decreases the priority of item \c i to \c p.
    280     /// \pre \c i must be stored in the heap with priority at least \c
    281     /// p relative to \c Compare.
     291    /// \brief Decrease the priority of an item to the given value.
     292    ///
     293    /// This function decreases the priority of an item to the given value.
    282294    /// \param i The item.
    283295    /// \param p The priority.
     296    /// \pre \e i must be stored in the heap with priority at least \e p.
    284297    void decrease(const Item &i, const Prio &p) {
    285298      int idx = _iim[i];
     
    292305    }
    293306
    294     /// \brief Increases the priority of \c i to \c p.
    295     ///
    296     /// This method sets the priority of item \c i to \c p.
    297     /// \pre \c i must be stored in the heap with priority at most \c
    298     /// p relative to \c Compare.
     307    /// \brief Increase the priority of an item to the given value.
     308    ///
     309    /// This function increases the priority of an item to the given value.
    299310    /// \param i The item.
    300311    /// \param p The priority.
     312    /// \pre \e i must be stored in the heap with priority at most \e p.
    301313    void increase(const Item &i, const Prio &p) {
    302314      int idx = _iim[i];
     
    306318    }
    307319
    308     /// \brief Returns if \c item is in, has already been in, or has
    309     /// never been in the heap.
    310     ///
    311     /// This method returns PRE_HEAP if \c item has never been in the
    312     /// heap, IN_HEAP if it is in the heap at the moment, and POST_HEAP
    313     /// otherwise. In the latter case it is possible that \c item will
    314     /// get back to the heap again.
     320    /// \brief Return the state of an item.
     321    ///
     322    /// This method returns \c PRE_HEAP if the given item has never
     323    /// been in the heap, \c IN_HEAP if it is in the heap at the moment,
     324    /// and \c POST_HEAP otherwise.
     325    /// In the latter case it is possible that the item will get back
     326    /// to the heap again.
    315327    /// \param i The item.
    316328    State state(const Item &i) const {
     
    320332    }
    321333
    322     /// \brief Sets the state of the \c item in the heap.
    323     ///
    324     /// Sets the state of the \c item in the heap. It can be used to
    325     /// manually clear the heap when it is important to achive the
    326     /// better time complexity.
     334    /// \brief Set the state of an item in the heap.
     335    ///
     336    /// This function sets the state of the given item in the heap.
     337    /// It can be used to manually clear the heap when it is important
     338    /// to achive better time complexity.
    327339    /// \param i The item.
    328340    /// \param st The state. It should not be \c IN_HEAP.
     
    360372  }; // class BucketHeap
    361373
    362   /// \ingroup auxdat
    363   ///
    364   /// \brief A Simplified Bucket Heap implementation.
     374  /// \ingroup heaps
     375  ///
     376  /// \brief Simplified bucket heap data structure.
    365377  ///
    366378  /// This class implements a simplified \e bucket \e heap data
    367   /// structure.  It does not provide some functionality but it faster
    368   /// and simplier data structure than the BucketHeap. The main
    369   /// difference is that the BucketHeap stores for every key a double
    370   /// linked list while this class stores just simple lists. In the
    371   /// other way it does not support erasing each elements just the
    372   /// minimal and it does not supports key increasing, decreasing.
    373   ///
    374   /// \param IM A read and write Item int map, used internally
    375   /// to handle the cross references.
    376   /// \param MIN If the given parameter is false then instead of the
    377   /// minimum value the maximum can be retrivied with the top() and
    378   /// prio() member functions.
     379  /// structure. It does not provide some functionality, but it is
     380  /// faster and simpler than BucketHeap. The main difference is
     381  /// that BucketHeap stores a doubly-linked list for each key while
     382  /// this class stores only simply-linked lists. It supports erasing
     383  /// only for the item having minimum priority and it does not support
     384  /// key increasing and decreasing.
     385  ///
     386  /// Note that this implementation does not conform to the
     387  /// \ref concepts::Heap "heap concept" due to the lack of some
     388  /// functionality.
     389  ///
     390  /// \tparam IM A read-writable item map with \c int values, used
     391  /// internally to handle the cross references.
     392  /// \tparam MIN Indicate if the heap is a \e min-heap or a \e max-heap.
     393  /// The default is \e min-heap. If this parameter is set to \c false,
     394  /// then the comparison is reversed, so the top(), prio() and pop()
     395  /// functions deal with the item having maximum priority instead of the
     396  /// minimum.
    379397  ///
    380398  /// \sa BucketHeap
     
    383401
    384402  public:
    385     typedef typename IM::Key Item;
     403
     404    /// Type of the item-int map.
     405    typedef IM ItemIntMap;
     406    /// Type of the priorities.
    386407    typedef int Prio;
    387     typedef std::pair<Item, Prio> Pair;
    388     typedef IM ItemIntMap;
     408    /// Type of the items stored in the heap.
     409    typedef typename ItemIntMap::Key Item;
     410    /// Type of the item-priority pairs.
     411    typedef std::pair<Item,Prio> Pair;
    389412
    390413  private:
     
    394417  public:
    395418
    396     /// \brief Type to represent the items states.
    397     ///
    398     /// Each Item element have a state associated to it. It may be "in heap",
    399     /// "pre heap" or "post heap". The latter two are indifferent from the
     419    /// \brief Type to represent the states of the items.
     420    ///
     421    /// Each item has a state associated to it. It can be "in heap",
     422    /// "pre-heap" or "post-heap". The latter two are indifferent from the
    400423    /// heap's point of view, but may be useful to the user.
    401424    ///
     
    410433  public:
    411434
    412     /// \brief The constructor.
    413     ///
    414     /// The constructor.
    415     /// \param map should be given to the constructor, since it is used
    416     /// internally to handle the cross references. The value of the map
    417     /// should be PRE_HEAP (-1) for each element.
     435    /// \brief Constructor.
     436    ///
     437    /// Constructor.
     438    /// \param map A map that assigns \c int values to the items.
     439    /// It is used internally to handle the cross references.
     440    /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item.
    418441    explicit SimpleBucketHeap(ItemIntMap &map)
    419442      : _iim(map), _free(-1), _num(0), _minimum(0) {}
    420443
    421     /// \brief Returns the number of items stored in the heap.
    422     ///
    423     /// The number of items stored in the heap.
     444    /// \brief The number of items stored in the heap.
     445    ///
     446    /// This function returns the number of items stored in the heap.
    424447    int size() const { return _num; }
    425448
    426     /// \brief Checks if the heap stores no items.
    427     ///
    428     /// Returns \c true if and only if the heap stores no items.
     449    /// \brief Check if the heap is empty.
     450    ///
     451    /// This function returns \c true if the heap is empty.
    429452    bool empty() const { return _num == 0; }
    430453
    431     /// \brief Make empty this heap.
    432     ///
    433     /// Make empty this heap. It does not change the cross reference
    434     /// map.  If you want to reuse a heap what is not surely empty you
    435     /// should first clear the heap and after that you should set the
    436     /// cross reference map for each item to \c PRE_HEAP.
     454    /// \brief Make the heap empty.
     455    ///
     456    /// This functon makes the heap empty.
     457    /// It does not change the cross reference map. If you want to reuse
     458    /// a heap that is not surely empty, you should first clear it and
     459    /// then you should set the cross reference map to \c PRE_HEAP
     460    /// for each item.
    437461    void clear() {
    438462      _data.clear(); _first.clear(); _free = -1; _num = 0; _minimum = 0;
     
    441465    /// \brief Insert a pair of item and priority into the heap.
    442466    ///
    443     /// Adds \c p.first to the heap with priority \c p.second.
     467    /// This function inserts \c p.first to the heap with priority
     468    /// \c p.second.
    444469    /// \param p The pair to insert.
     470    /// \pre \c p.first must not be stored in the heap.
    445471    void push(const Pair& p) {
    446472      push(p.first, p.second);
     
    449475    /// \brief Insert an item into the heap with the given priority.
    450476    ///
    451     /// Adds \c i to the heap with priority \c p.
     477    /// This function inserts the given item into the heap with the
     478    /// given priority.
    452479    /// \param i The item to insert.
    453480    /// \param p The priority of the item.
     481    /// \pre \e i must not be stored in the heap.
    454482    void push(const Item &i, const Prio &p) {
    455483      int idx;
     
    472500    }
    473501
    474     /// \brief Returns the item with minimum priority.
    475     ///
    476     /// This method returns the item with minimum priority.
    477     /// \pre The heap must be nonempty.
     502    /// \brief Return the item having minimum priority.
     503    ///
     504    /// This function returns the item having minimum priority.
     505    /// \pre The heap must be non-empty.
    478506    Item top() const {
    479507      while (_first[_minimum] == -1) {
     
    483511    }
    484512
    485     /// \brief Returns the minimum priority.
    486     ///
    487     /// It returns the minimum priority.
    488     /// \pre The heap must be nonempty.
     513    /// \brief The minimum priority.
     514    ///
     515    /// This function returns the minimum priority.
     516    /// \pre The heap must be non-empty.
    489517    Prio prio() const {
    490518      while (_first[_minimum] == -1) {
     
    494522    }
    495523
    496     /// \brief Deletes the item with minimum priority.
    497     ///
    498     /// This method deletes the item with minimum priority from the heap.
     524    /// \brief Remove the item having minimum priority.
     525    ///
     526    /// This function removes the item having minimum priority.
    499527    /// \pre The heap must be non-empty.
    500528    void pop() {
     
    510538    }
    511539
    512     /// \brief Returns the priority of \c i.
    513     ///
    514     /// This function returns the priority of item \c i.
    515     /// \warning This operator is not a constant time function
    516     /// because it scans the whole data structure to find the proper
    517     /// value.
    518     /// \pre \c i must be in the heap.
    519     /// \param i The item.
     540    /// \brief The priority of the given item.
     541    ///
     542    /// This function returns the priority of the given item.
     543    /// \param i The item.
     544    /// \pre \e i must be in the heap.
     545    /// \warning This operator is not a constant time function because
     546    /// it scans the whole data structure to find the proper value.
    520547    Prio operator[](const Item &i) const {
    521       for (int k = 0; k < _first.size(); ++k) {
     548      for (int k = 0; k < int(_first.size()); ++k) {
    522549        int idx = _first[k];
    523550        while (idx != -1) {
     
    531558    }
    532559
    533     /// \brief Returns if \c item is in, has already been in, or has
    534     /// never been in the heap.
    535     ///
    536     /// This method returns PRE_HEAP if \c item has never been in the
    537     /// heap, IN_HEAP if it is in the heap at the moment, and POST_HEAP
    538     /// otherwise. In the latter case it is possible that \c item will
    539     /// get back to the heap again.
     560    /// \brief Return the state of an item.
     561    ///
     562    /// This method returns \c PRE_HEAP if the given item has never
     563    /// been in the heap, \c IN_HEAP if it is in the heap at the moment,
     564    /// and \c POST_HEAP otherwise.
     565    /// In the latter case it is possible that the item will get back
     566    /// to the heap again.
    540567    /// \param i The item.
    541568    State state(const Item &i) const {
  • TabularUnified lemon/cbc.cc

    r1120 r1122  
    9090  }
    9191
     92  int CbcMip::_addRow(Value l, ExprIterator b, ExprIterator e, Value u) {
     93    std::vector<int> indexes;
     94    std::vector<Value> values;
     95
     96    for(ExprIterator it = b; it != e; ++it) {
     97      indexes.push_back(it->first);
     98      values.push_back(it->second);
     99    }
     100
     101    _prob->addRow(values.size(), &indexes.front(), &values.front(), l, u);
     102    return _prob->numberRows() - 1;
     103  }
    92104
    93105  void CbcMip::_eraseCol(int i) {
  • TabularUnified lemon/cbc.h

    r623 r956  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    6363    virtual int _addCol();
    6464    virtual int _addRow();
     65    virtual int _addRow(Value l, ExprIterator b, ExprIterator e, Value u);
    6566
    6667    virtual void _eraseCol(int i);
     
    121122    int _message_level;
    122123
    123    
     124
    124125
    125126  };
  • TabularUnified lemon/circulation.h

    r735 r956  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    6060    /// \brief The type of supply map.
    6161    ///
    62     /// The type of the map that stores the signed supply values of the 
    63     /// nodes. 
     62    /// The type of the map that stores the signed supply values of the
     63    /// nodes.
    6464    /// It must conform to the \ref concepts::ReadMap "ReadMap" concept.
    6565    typedef SM SupplyMap;
     
    7373    /// It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap"
    7474    /// concept.
     75#ifdef DOXYGEN
     76    typedef GR::ArcMap<Value> FlowMap;
     77#else
    7578    typedef typename Digraph::template ArcMap<Value> FlowMap;
     79#endif
    7680
    7781    /// \brief Instantiates a FlowMap.
     
    8892    /// The elevator type used by the algorithm.
    8993    ///
    90     /// \sa Elevator
    91     /// \sa LinkedElevator
     94    /// \sa Elevator, LinkedElevator
     95#ifdef DOXYGEN
     96    typedef lemon::Elevator<GR, GR::Node> Elevator;
     97#else
    9298    typedef lemon::Elevator<Digraph, typename Digraph::Node> Elevator;
     99#endif
    93100
    94101    /// \brief Instantiates an Elevator.
     
    135142     \geq sup(u) \quad \forall u\in V, \f]
    136143     \f[ lower(uv) \leq f(uv) \leq upper(uv) \quad \forall uv\in A. \f]
    137      
     144
    138145     The sum of the supply values, i.e. \f$\sum_{u\in V} sup(u)\f$ must be
    139146     zero or negative in order to have a feasible solution (since the sum
     
    145152     constraints have to be satisfied with equality, i.e. all demands
    146153     have to be satisfied and all supplies have to be used.
    147      
     154
    148155     If you need the opposite inequalities in the supply/demand constraints
    149156     (i.e. the total demand is less than the total supply and all the demands
     
    167174     \tparam SM The type of the supply map. The default map type is
    168175     \ref concepts::Digraph::NodeMap "GR::NodeMap<UM::Value>".
     176     \tparam TR The traits class that defines various types used by the
     177     algorithm. By default, it is \ref CirculationDefaultTraits
     178     "CirculationDefaultTraits<GR, LM, UM, SM>".
     179     In most cases, this parameter should not be set directly,
     180     consider to use the named template parameters instead.
    169181  */
    170182#ifdef DOXYGEN
     
    300312    /// able to automatically created by the algorithm (i.e. the
    301313    /// digraph and the maximum level should be passed to it).
    302     /// However an external elevator object could also be passed to the
     314    /// However, an external elevator object could also be passed to the
    303315    /// algorithm with the \ref elevator(Elevator&) "elevator()" function
    304316    /// before calling \ref run() or \ref init().
     
    326338    /// \param graph The digraph the algorithm runs on.
    327339    /// \param lower The lower bounds for the flow values on the arcs.
    328     /// \param upper The upper bounds (capacities) for the flow values 
     340    /// \param upper The upper bounds (capacities) for the flow values
    329341    /// on the arcs.
    330342    /// \param supply The signed supply values of the nodes.
     
    451463    }
    452464
    453     /// \brief Sets the tolerance used by algorithm.
    454     ///
    455     /// Sets the tolerance used by algorithm.
     465    /// \brief Sets the tolerance used by the algorithm.
     466    ///
     467    /// Sets the tolerance object used by the algorithm.
     468    /// \return <tt>(*this)</tt>
    456469    Circulation& tolerance(const Tolerance& tolerance) {
    457470      _tol = tolerance;
     
    461474    /// \brief Returns a const reference to the tolerance.
    462475    ///
    463     /// Returns a const reference to the tolerance.
     476    /// Returns a const reference to the tolerance object used by
     477    /// the algorithm.
    464478    const Tolerance& tolerance() const {
    465479      return _tol;
     
    468482    /// \name Execution Control
    469483    /// The simplest way to execute the algorithm is to call \ref run().\n
    470     /// If you need more control on the initial solution or the execution,
    471     /// first you have to call one of the \ref init() functions, then
     484    /// If you need better control on the initial solution or the execution,
     485    /// you have to call one of the \ref init() functions first, then
    472486    /// the \ref start() function.
    473487
  • TabularUnified lemon/clp.cc

    r623 r956  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2008
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    7676  int ClpLp::_addRow() {
    7777    _prob->addRow(0, 0, 0, -COIN_DBL_MAX, COIN_DBL_MAX);
     78    return _prob->numberRows() - 1;
     79  }
     80
     81  int ClpLp::_addRow(Value l, ExprIterator b, ExprIterator e, Value u) {
     82    std::vector<int> indexes;
     83    std::vector<Value> values;
     84
     85    for(ExprIterator it = b; it != e; ++it) {
     86      indexes.push_back(it->first);
     87      values.push_back(it->second);
     88    }
     89
     90    _prob->addRow(values.size(), &indexes.front(), &values.front(), l, u);
    7891    return _prob->numberRows() - 1;
    7992  }
  • TabularUnified lemon/clp.h

    r623 r956  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2008
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    7676    virtual int _addCol();
    7777    virtual int _addRow();
     78    virtual int _addRow(Value l, ExprIterator b, ExprIterator e, Value u);
    7879
    7980    virtual void _eraseCol(int i);
     
    138139
    139140    virtual void _messageLevel(MessageLevel);
    140    
     141
    141142  public:
    142143
  • TabularUnified lemon/concepts/digraph.h

    r627 r956  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    3636    /// \brief Class describing the concept of directed graphs.
    3737    ///
    38     /// This class describes the \ref concept "concept" of the
    39     /// immutable directed digraphs.
     38    /// This class describes the common interface of all directed
     39    /// graphs (digraphs).
    4040    ///
    41     /// Note that actual digraph implementation like @ref ListDigraph or
    42     /// @ref SmartDigraph may have several additional functionality.
     41    /// Like all concept classes, it only provides an interface
     42    /// without any sensible implementation. So any general algorithm for
     43    /// directed graphs should compile with this class, but it will not
     44    /// run properly, of course.
     45    /// An actual digraph implementation like \ref ListDigraph or
     46    /// \ref SmartDigraph may have additional functionality.
    4347    ///
    44     /// \sa concept
     48    /// \sa Graph
    4549    class Digraph {
    4650    private:
    47       ///Digraphs are \e not copy constructible. Use DigraphCopy() instead.
    48 
    49       ///Digraphs are \e not copy constructible. Use DigraphCopy() instead.
    50       ///
    51       Digraph(const Digraph &) {};
    52       ///\brief Assignment of \ref Digraph "Digraph"s to another ones are
    53       ///\e not allowed. Use DigraphCopy() instead.
    54 
    55       ///Assignment of \ref Digraph "Digraph"s to another ones are
    56       ///\e not allowed.  Use DigraphCopy() instead.
    57 
     51      /// Diraphs are \e not copy constructible. Use DigraphCopy instead.
     52      Digraph(const Digraph &) {}
     53      /// \brief Assignment of a digraph to another one is \e not allowed.
     54      /// Use DigraphCopy instead.
    5855      void operator=(const Digraph &) {}
     56
    5957    public:
    60       ///\e
    61 
    62       /// Defalult constructor.
    63 
    64       /// Defalult constructor.
    65       ///
     58      /// Default constructor.
    6659      Digraph() { }
    67       /// Class for identifying a node of the digraph
     60
     61      /// The node type of the digraph
    6862
    6963      /// This class identifies a node of the digraph. It also serves
    7064      /// as a base class of the node iterators,
    71       /// thus they will convert to this type.
     65      /// thus they convert to this type.
    7266      class Node {
    7367      public:
    7468        /// Default constructor
    7569
    76         /// @warning The default constructor sets the iterator
    77         /// to an undefined value.
     70        /// Default constructor.
     71        /// \warning It sets the object to an undefined value.
    7872        Node() { }
    7973        /// Copy constructor.
     
    8377        Node(const Node&) { }
    8478
    85         /// Invalid constructor \& conversion.
    86 
    87         /// This constructor initializes the iterator to be invalid.
     79        /// %Invalid constructor \& conversion.
     80
     81        /// Initializes the object to be invalid.
    8882        /// \sa Invalid for more details.
    8983        Node(Invalid) { }
    9084        /// Equality operator
    9185
     86        /// Equality operator.
     87        ///
    9288        /// Two iterators are equal if and only if they point to the
    93         /// same object or both are invalid.
     89        /// same object or both are \c INVALID.
    9490        bool operator==(Node) const { return true; }
    9591
    9692        /// Inequality operator
    9793
    98         /// \sa operator==(Node n)
    99         ///
     94        /// Inequality operator.
    10095        bool operator!=(Node) const { return true; }
    10196
    10297        /// Artificial ordering operator.
    10398
    104         /// To allow the use of digraph descriptors as key type in std::map or
    105         /// similar associative container we require this.
    106         ///
    107         /// \note This operator only have to define some strict ordering of
    108         /// the items; this order has nothing to do with the iteration
    109         /// ordering of the items.
     99        /// Artificial ordering operator.
     100        ///
     101        /// \note This operator only has to define some strict ordering of
     102        /// the nodes; this order has nothing to do with the iteration
     103        /// ordering of the nodes.
    110104        bool operator<(Node) const { return false; }
    111 
    112       };
    113 
    114       /// This iterator goes through each node.
    115 
    116       /// This iterator goes through each node.
    117       /// Its usage is quite simple, for example you can count the number
    118       /// of nodes in digraph \c g of type \c Digraph like this:
     105      };
     106
     107      /// Iterator class for the nodes.
     108
     109      /// This iterator goes through each node of the digraph.
     110      /// Its usage is quite simple, for example, you can count the number
     111      /// of nodes in a digraph \c g of type \c %Digraph like this:
    119112      ///\code
    120113      /// int count=0;
     
    125118        /// Default constructor
    126119
    127         /// @warning The default constructor sets the iterator
    128         /// to an undefined value.
     120        /// Default constructor.
     121        /// \warning It sets the iterator to an undefined value.
    129122        NodeIt() { }
    130123        /// Copy constructor.
     
    133126        ///
    134127        NodeIt(const NodeIt& n) : Node(n) { }
    135         /// Invalid constructor \& conversion.
    136 
    137         /// Initialize the iterator to be invalid.
     128        /// %Invalid constructor \& conversion.
     129
     130        /// Initializes the iterator to be invalid.
    138131        /// \sa Invalid for more details.
    139132        NodeIt(Invalid) { }
    140133        /// Sets the iterator to the first node.
    141134
    142         /// Sets the iterator to the first node of \c g.
    143         ///
    144         NodeIt(const Digraph&) { }
    145         /// Node -> NodeIt conversion.
    146 
    147         /// Sets the iterator to the node of \c the digraph pointed by
    148         /// the trivial iterator.
    149         /// This feature necessitates that each time we
    150         /// iterate the arc-set, the iteration order is the same.
     135        /// Sets the iterator to the first node of the given digraph.
     136        ///
     137        explicit NodeIt(const Digraph&) { }
     138        /// Sets the iterator to the given node.
     139
     140        /// Sets the iterator to the given node of the given digraph.
     141        ///
    151142        NodeIt(const Digraph&, const Node&) { }
    152143        /// Next node.
     
    158149
    159150
    160       /// Class for identifying an arc of the digraph
     151      /// The arc type of the digraph
    161152
    162153      /// This class identifies an arc of the digraph. It also serves
     
    167158        /// Default constructor
    168159
    169         /// @warning The default constructor sets the iterator
    170         /// to an undefined value.
     160        /// Default constructor.
     161        /// \warning It sets the object to an undefined value.
    171162        Arc() { }
    172163        /// Copy constructor.
     
    175166        ///
    176167        Arc(const Arc&) { }
    177         /// Initialize the iterator to be invalid.
    178 
    179         /// Initialize the iterator to be invalid.
    180         ///
     168        /// %Invalid constructor \& conversion.
     169
     170        /// Initializes the object to be invalid.
     171        /// \sa Invalid for more details.
    181172        Arc(Invalid) { }
    182173        /// Equality operator
    183174
     175        /// Equality operator.
     176        ///
    184177        /// Two iterators are equal if and only if they point to the
    185         /// same object or both are invalid.
     178        /// same object or both are \c INVALID.
    186179        bool operator==(Arc) const { return true; }
    187180        /// Inequality operator
    188181
    189         /// \sa operator==(Arc n)
    190         ///
     182        /// Inequality operator.
    191183        bool operator!=(Arc) const { return true; }
    192184
    193185        /// Artificial ordering operator.
    194186
    195         /// To allow the use of digraph descriptors as key type in std::map or
    196         /// similar associative container we require this.
    197         ///
    198         /// \note This operator only have to define some strict ordering of
    199         /// the items; this order has nothing to do with the iteration
    200         /// ordering of the items.
     187        /// Artificial ordering operator.
     188        ///
     189        /// \note This operator only has to define some strict ordering of
     190        /// the arcs; this order has nothing to do with the iteration
     191        /// ordering of the arcs.
    201192        bool operator<(Arc) const { return false; }
    202193      };
    203194
    204       /// This iterator goes trough the outgoing arcs of a node.
     195      /// Iterator class for the outgoing arcs of a node.
    205196
    206197      /// This iterator goes trough the \e outgoing arcs of a certain node
    207198      /// of a digraph.
    208       /// Its usage is quite simple, for example you can count the number
     199      /// Its usage is quite simple, for example, you can count the number
    209200      /// of outgoing arcs of a node \c n
    210       /// in digraph \c g of type \c Digraph as follows.
     201      /// in a digraph \c g of type \c %Digraph as follows.
    211202      ///\code
    212203      /// int count=0;
    213       /// for (Digraph::OutArcIt e(g, n); e!=INVALID; ++e) ++count;
     204      /// for (Digraph::OutArcIt a(g, n); a!=INVALID; ++a) ++count;
    214205      ///\endcode
    215 
    216206      class OutArcIt : public Arc {
    217207      public:
    218208        /// Default constructor
    219209
    220         /// @warning The default constructor sets the iterator
    221         /// to an undefined value.
     210        /// Default constructor.
     211        /// \warning It sets the iterator to an undefined value.
    222212        OutArcIt() { }
    223213        /// Copy constructor.
     
    226216        ///
    227217        OutArcIt(const OutArcIt& e) : Arc(e) { }
    228         /// Initialize the iterator to be invalid.
    229 
    230         /// Initialize the iterator to be invalid.
    231         ///
     218        /// %Invalid constructor \& conversion.
     219
     220        /// Initializes the iterator to be invalid.
     221        /// \sa Invalid for more details.
    232222        OutArcIt(Invalid) { }
    233         /// This constructor sets the iterator to the first outgoing arc.
    234 
    235         /// This constructor sets the iterator to the first outgoing arc of
    236         /// the node.
     223        /// Sets the iterator to the first outgoing arc.
     224
     225        /// Sets the iterator to the first outgoing arc of the given node.
     226        ///
    237227        OutArcIt(const Digraph&, const Node&) { }
    238         /// Arc -> OutArcIt conversion
    239 
    240         /// Sets the iterator to the value of the trivial iterator.
    241         /// This feature necessitates that each time we
    242         /// iterate the arc-set, the iteration order is the same.
     228        /// Sets the iterator to the given arc.
     229
     230        /// Sets the iterator to the given arc of the given digraph.
     231        ///
    243232        OutArcIt(const Digraph&, const Arc&) { }
    244         ///Next outgoing arc
     233        /// Next outgoing arc
    245234
    246235        /// Assign the iterator to the next
     
    249238      };
    250239
    251       /// This iterator goes trough the incoming arcs of a node.
     240      /// Iterator class for the incoming arcs of a node.
    252241
    253242      /// This iterator goes trough the \e incoming arcs of a certain node
    254243      /// of a digraph.
    255       /// Its usage is quite simple, for example you can count the number
    256       /// of outgoing arcs of a node \c n
    257       /// in digraph \c g of type \c Digraph as follows.
     244      /// Its usage is quite simple, for example, you can count the number
     245      /// of incoming arcs of a node \c n
     246      /// in a digraph \c g of type \c %Digraph as follows.
    258247      ///\code
    259248      /// int count=0;
    260       /// for(Digraph::InArcIt e(g, n); e!=INVALID; ++e) ++count;
     249      /// for(Digraph::InArcIt a(g, n); a!=INVALID; ++a) ++count;
    261250      ///\endcode
    262 
    263251      class InArcIt : public Arc {
    264252      public:
    265253        /// Default constructor
    266254
    267         /// @warning The default constructor sets the iterator
    268         /// to an undefined value.
     255        /// Default constructor.
     256        /// \warning It sets the iterator to an undefined value.
    269257        InArcIt() { }
    270258        /// Copy constructor.
     
    273261        ///
    274262        InArcIt(const InArcIt& e) : Arc(e) { }
    275         /// Initialize the iterator to be invalid.
    276 
    277         /// Initialize the iterator to be invalid.
    278         ///
     263        /// %Invalid constructor \& conversion.
     264
     265        /// Initializes the iterator to be invalid.
     266        /// \sa Invalid for more details.
    279267        InArcIt(Invalid) { }
    280         /// This constructor sets the iterator to first incoming arc.
    281 
    282         /// This constructor set the iterator to the first incoming arc of
    283         /// the node.
     268        /// Sets the iterator to the first incoming arc.
     269
     270        /// Sets the iterator to the first incoming arc of the given node.
     271        ///
    284272        InArcIt(const Digraph&, const Node&) { }
    285         /// Arc -> InArcIt conversion
    286 
    287         /// Sets the iterator to the value of the trivial iterator \c e.
    288         /// This feature necessitates that each time we
    289         /// iterate the arc-set, the iteration order is the same.
     273        /// Sets the iterator to the given arc.
     274
     275        /// Sets the iterator to the given arc of the given digraph.
     276        ///
    290277        InArcIt(const Digraph&, const Arc&) { }
    291278        /// Next incoming arc
    292279
    293         /// Assign the iterator to the next inarc of the corresponding node.
    294         ///
     280        /// Assign the iterator to the next
     281        /// incoming arc of the corresponding node.
    295282        InArcIt& operator++() { return *this; }
    296283      };
    297       /// This iterator goes through each arc.
    298 
    299       /// This iterator goes through each arc of a digraph.
    300       /// Its usage is quite simple, for example you can count the number
    301       /// of arcs in a digraph \c g of type \c Digraph as follows:
     284
     285      /// Iterator class for the arcs.
     286
     287      /// This iterator goes through each arc of the digraph.
     288      /// Its usage is quite simple, for example, you can count the number
     289      /// of arcs in a digraph \c g of type \c %Digraph as follows:
    302290      ///\code
    303291      /// int count=0;
    304       /// for(Digraph::ArcIt e(g); e!=INVALID; ++e) ++count;
     292      /// for(Digraph::ArcIt a(g); a!=INVALID; ++a) ++count;
    305293      ///\endcode
    306294      class ArcIt : public Arc {
     
    308296        /// Default constructor
    309297
    310         /// @warning The default constructor sets the iterator
    311         /// to an undefined value.
     298        /// Default constructor.
     299        /// \warning It sets the iterator to an undefined value.
    312300        ArcIt() { }
    313301        /// Copy constructor.
     
    316304        ///
    317305        ArcIt(const ArcIt& e) : Arc(e) { }
    318         /// Initialize the iterator to be invalid.
    319 
    320         /// Initialize the iterator to be invalid.
    321         ///
     306        /// %Invalid constructor \& conversion.
     307
     308        /// Initializes the iterator to be invalid.
     309        /// \sa Invalid for more details.
    322310        ArcIt(Invalid) { }
    323         /// This constructor sets the iterator to the first arc.
    324 
    325         /// This constructor sets the iterator to the first arc of \c g.
    326         ///@param g the digraph
    327         ArcIt(const Digraph& g) { ignore_unused_variable_warning(g); }
    328         /// Arc -> ArcIt conversion
    329 
    330         /// Sets the iterator to the value of the trivial iterator \c e.
    331         /// This feature necessitates that each time we
    332         /// iterate the arc-set, the iteration order is the same.
     311        /// Sets the iterator to the first arc.
     312
     313        /// Sets the iterator to the first arc of the given digraph.
     314        ///
     315        explicit ArcIt(const Digraph& g) { ignore_unused_variable_warning(g); }
     316        /// Sets the iterator to the given arc.
     317
     318        /// Sets the iterator to the given arc of the given digraph.
     319        ///
    333320        ArcIt(const Digraph&, const Arc&) { }
    334         ///Next arc
     321        /// Next arc
    335322
    336323        /// Assign the iterator to the next arc.
     324        ///
    337325        ArcIt& operator++() { return *this; }
    338326      };
    339       ///Gives back the target node of an arc.
    340 
    341       ///Gives back the target node of an arc.
    342       ///
     327
     328      /// \brief The source node of the arc.
     329      ///
     330      /// Returns the source node of the given arc.
     331      Node source(Arc) const { return INVALID; }
     332
     333      /// \brief The target node of the arc.
     334      ///
     335      /// Returns the target node of the given arc.
    343336      Node target(Arc) const { return INVALID; }
    344       ///Gives back the source node of an arc.
    345 
    346       ///Gives back the source node of an arc.
    347       ///
    348       Node source(Arc) const { return INVALID; }
    349 
    350       /// \brief Returns the ID of the node.
     337
     338      /// \brief The ID of the node.
     339      ///
     340      /// Returns the ID of the given node.
    351341      int id(Node) const { return -1; }
    352342
    353       /// \brief Returns the ID of the arc.
     343      /// \brief The ID of the arc.
     344      ///
     345      /// Returns the ID of the given arc.
    354346      int id(Arc) const { return -1; }
    355347
    356       /// \brief Returns the node with the given ID.
    357       ///
    358       /// \pre The argument should be a valid node ID in the graph.
     348      /// \brief The node with the given ID.
     349      ///
     350      /// Returns the node with the given ID.
     351      /// \pre The argument should be a valid node ID in the digraph.
    359352      Node nodeFromId(int) const { return INVALID; }
    360353
    361       /// \brief Returns the arc with the given ID.
    362       ///
    363       /// \pre The argument should be a valid arc ID in the graph.
     354      /// \brief The arc with the given ID.
     355      ///
     356      /// Returns the arc with the given ID.
     357      /// \pre The argument should be a valid arc ID in the digraph.
    364358      Arc arcFromId(int) const { return INVALID; }
    365359
    366       /// \brief Returns an upper bound on the node IDs.
     360      /// \brief An upper bound on the node IDs.
     361      ///
     362      /// Returns an upper bound on the node IDs.
    367363      int maxNodeId() const { return -1; }
    368364
    369       /// \brief Returns an upper bound on the arc IDs.
     365      /// \brief An upper bound on the arc IDs.
     366      ///
     367      /// Returns an upper bound on the arc IDs.
    370368      int maxArcId() const { return -1; }
    371369
     
    393391      int maxId(Arc) const { return -1; }
    394392
     393      /// \brief The opposite node on the arc.
     394      ///
     395      /// Returns the opposite node on the given arc.
     396      Node oppositeNode(Node, Arc) const { return INVALID; }
     397
    395398      /// \brief The base node of the iterator.
    396399      ///
    397       /// Gives back the base node of the iterator.
    398       /// It is always the target of the pointed arc.
    399       Node baseNode(const InArcIt&) const { return INVALID; }
     400      /// Returns the base node of the given outgoing arc iterator
     401      /// (i.e. the source node of the corresponding arc).
     402      Node baseNode(OutArcIt) const { return INVALID; }
    400403
    401404      /// \brief The running node of the iterator.
    402405      ///
    403       /// Gives back the running node of the iterator.
    404       /// It is always the source of the pointed arc.
    405       Node runningNode(const InArcIt&) const { return INVALID; }
     406      /// Returns the running node of the given outgoing arc iterator
     407      /// (i.e. the target node of the corresponding arc).
     408      Node runningNode(OutArcIt) const { return INVALID; }
    406409
    407410      /// \brief The base node of the iterator.
    408411      ///
    409       /// Gives back the base node of the iterator.
    410       /// It is always the source of the pointed arc.
    411       Node baseNode(const OutArcIt&) const { return INVALID; }
     412      /// Returns the base node of the given incomming arc iterator
     413      /// (i.e. the target node of the corresponding arc).
     414      Node baseNode(InArcIt) const { return INVALID; }
    412415
    413416      /// \brief The running node of the iterator.
    414417      ///
    415       /// Gives back the running node of the iterator.
    416       /// It is always the target of the pointed arc.
    417       Node runningNode(const OutArcIt&) const { return INVALID; }
    418 
    419       /// \brief The opposite node on the given arc.
    420       ///
    421       /// Gives back the opposite node on the given arc.
    422       Node oppositeNode(const Node&, const Arc&) const { return INVALID; }
    423 
    424       /// \brief Reference map of the nodes to type \c T.
    425       ///
    426       /// Reference map of the nodes to type \c T.
     418      /// Returns the running node of the given incomming arc iterator
     419      /// (i.e. the source node of the corresponding arc).
     420      Node runningNode(InArcIt) const { return INVALID; }
     421
     422      /// \brief Standard graph map type for the nodes.
     423      ///
     424      /// Standard graph map type for the nodes.
     425      /// It conforms to the ReferenceMap concept.
    427426      template<class T>
    428427      class NodeMap : public ReferenceMap<Node, T, T&, const T&> {
    429428      public:
    430429
    431         ///\e
    432         NodeMap(const Digraph&) { }
    433         ///\e
     430        /// Constructor
     431        explicit NodeMap(const Digraph&) { }
     432        /// Constructor with given initial value
    434433        NodeMap(const Digraph&, T) { }
    435434
    436435      private:
    437436        ///Copy constructor
    438         NodeMap(const NodeMap& nm) : 
     437        NodeMap(const NodeMap& nm) :
    439438          ReferenceMap<Node, T, T&, const T&>(nm) { }
    440439        ///Assignment operator
     
    446445      };
    447446
    448       /// \brief Reference map of the arcs to type \c T.
    449       ///
    450       /// Reference map of the arcs to type \c T.
     447      /// \brief Standard graph map type for the arcs.
     448      ///
     449      /// Standard graph map type for the arcs.
     450      /// It conforms to the ReferenceMap concept.
    451451      template<class T>
    452452      class ArcMap : public ReferenceMap<Arc, T, T&, const T&> {
    453453      public:
    454454
    455         ///\e
    456         ArcMap(const Digraph&) { }
    457         ///\e
     455        /// Constructor
     456        explicit ArcMap(const Digraph&) { }
     457        /// Constructor with given initial value
    458458        ArcMap(const Digraph&, T) { }
     459
    459460      private:
    460461        ///Copy constructor
  • TabularUnified lemon/concepts/graph.h

    r704 r956  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    1919///\ingroup graph_concepts
    2020///\file
    21 ///\brief The concept of Undirected Graphs.
     21///\brief The concept of undirected graphs.
    2222
    2323#ifndef LEMON_CONCEPTS_GRAPH_H
     
    2525
    2626#include <lemon/concepts/graph_components.h>
     27#include <lemon/concepts/maps.h>
     28#include <lemon/concept_check.h>
    2729#include <lemon/core.h>
    2830
     
    3234    /// \ingroup graph_concepts
    3335    ///
    34     /// \brief Class describing the concept of Undirected Graphs.
     36    /// \brief Class describing the concept of undirected graphs.
    3537    ///
    36     /// This class describes the common interface of all Undirected
    37     /// Graphs.
     38    /// This class describes the common interface of all undirected
     39    /// graphs.
    3840    ///
    39     /// As all concept describing classes it provides only interface
    40     /// without any sensible implementation. So any algorithm for
    41     /// undirected graph should compile with this class, but it will not
     41    /// Like all concept classes, it only provides an interface
     42    /// without any sensible implementation. So any general algorithm for
     43    /// undirected graphs should compile with this class, but it will not
    4244    /// run properly, of course.
     45    /// An actual graph implementation like \ref ListGraph or
     46    /// \ref SmartGraph may have additional functionality.
    4347    ///
    44     /// The LEMON undirected graphs also fulfill the concept of
    45     /// directed graphs (\ref lemon::concepts::Digraph "Digraph
    46     /// Concept"). Each edges can be seen as two opposite
    47     /// directed arc and consequently the undirected graph can be
    48     /// seen as the direceted graph of these directed arcs. The
    49     /// Graph has the Edge inner class for the edges and
    50     /// the Arc type for the directed arcs. The Arc type is
    51     /// convertible to Edge or inherited from it so from a directed
    52     /// arc we can get the represented edge.
     48    /// The undirected graphs also fulfill the concept of \ref Digraph
     49    /// "directed graphs", since each edge can also be regarded as two
     50    /// oppositely directed arcs.
     51    /// Undirected graphs provide an Edge type for the undirected edges and
     52    /// an Arc type for the directed arcs. The Arc type is convertible to
     53    /// Edge or inherited from it, i.e. the corresponding edge can be
     54    /// obtained from an arc.
     55    /// EdgeIt and EdgeMap classes can be used for the edges, while ArcIt
     56    /// and ArcMap classes can be used for the arcs (just like in digraphs).
     57    /// Both InArcIt and OutArcIt iterates on the same edges but with
     58    /// opposite direction. IncEdgeIt also iterates on the same edges
     59    /// as OutArcIt and InArcIt, but it is not convertible to Arc,
     60    /// only to Edge.
    5361    ///
    54     /// In the sense of the LEMON each edge has a default
    55     /// direction (it should be in every computer implementation,
    56     /// because the order of edge's nodes defines an
    57     /// orientation). With the default orientation we can define that
    58     /// the directed arc is forward or backward directed. With the \c
    59     /// direction() and \c direct() function we can get the direction
    60     /// of the directed arc and we can direct an edge.
     62    /// In LEMON, each undirected edge has an inherent orientation.
     63    /// Thus it can defined if an arc is forward or backward oriented in
     64    /// an undirected graph with respect to this default oriantation of
     65    /// the represented edge.
     66    /// With the direction() and direct() functions the direction
     67    /// of an arc can be obtained and set, respectively.
    6168    ///
    62     /// The EdgeIt is an iterator for the edges. We can use
    63     /// the EdgeMap to map values for the edges. The InArcIt and
    64     /// OutArcIt iterates on the same edges but with opposite
    65     /// direction. The IncEdgeIt iterates also on the same edges
    66     /// as the OutArcIt and InArcIt but it is not convertible to Arc just
    67     /// to Edge.
     69    /// Only nodes and edges can be added to or removed from an undirected
     70    /// graph and the corresponding arcs are added or removed automatically.
     71    ///
     72    /// \sa Digraph
    6873    class Graph {
     74    private:
     75      /// Graphs are \e not copy constructible. Use DigraphCopy instead.
     76      Graph(const Graph&) {}
     77      /// \brief Assignment of a graph to another one is \e not allowed.
     78      /// Use DigraphCopy instead.
     79      void operator=(const Graph&) {}
     80
    6981    public:
    70       /// \brief The undirected graph should be tagged by the
    71       /// UndirectedTag.
    72       ///
    73       /// The undirected graph should be tagged by the UndirectedTag. This
    74       /// tag helps the enable_if technics to make compile time
     82      /// Default constructor.
     83      Graph() {}
     84
     85      /// \brief Undirected graphs should be tagged with \c UndirectedTag.
     86      ///
     87      /// Undirected graphs should be tagged with \c UndirectedTag.
     88      ///
     89      /// This tag helps the \c enable_if technics to make compile time
    7590      /// specializations for undirected graphs.
    7691      typedef True UndirectedTag;
    7792
    78       /// \brief The base type of node iterators,
    79       /// or in other words, the trivial node iterator.
    80       ///
    81       /// This is the base type of each node iterator,
    82       /// thus each kind of node iterator converts to this.
    83       /// More precisely each kind of node iterator should be inherited
    84       /// from the trivial node iterator.
     93      /// The node type of the graph
     94
     95      /// This class identifies a node of the graph. It also serves
     96      /// as a base class of the node iterators,
     97      /// thus they convert to this type.
    8598      class Node {
    8699      public:
    87100        /// Default constructor
    88101
    89         /// @warning The default constructor sets the iterator
    90         /// to an undefined value.
     102        /// Default constructor.
     103        /// \warning It sets the object to an undefined value.
    91104        Node() { }
    92105        /// Copy constructor.
     
    96109        Node(const Node&) { }
    97110
    98         /// Invalid constructor \& conversion.
    99 
    100         /// This constructor initializes the iterator to be invalid.
     111        /// %Invalid constructor \& conversion.
     112
     113        /// Initializes the object to be invalid.
    101114        /// \sa Invalid for more details.
    102115        Node(Invalid) { }
    103116        /// Equality operator
    104117
     118        /// Equality operator.
     119        ///
    105120        /// Two iterators are equal if and only if they point to the
    106         /// same object or both are invalid.
     121        /// same object or both are \c INVALID.
    107122        bool operator==(Node) const { return true; }
    108123
    109124        /// Inequality operator
    110125
    111         /// \sa operator==(Node n)
    112         ///
     126        /// Inequality operator.
    113127        bool operator!=(Node) const { return true; }
    114128
    115129        /// Artificial ordering operator.
    116130
    117         /// To allow the use of graph descriptors as key type in std::map or
    118         /// similar associative container we require this.
    119         ///
    120         /// \note This operator only have to define some strict ordering of
     131        /// Artificial ordering operator.
     132        ///
     133        /// \note This operator only has to define some strict ordering of
    121134        /// the items; this order has nothing to do with the iteration
    122135        /// ordering of the items.
     
    125138      };
    126139
    127       /// This iterator goes through each node.
    128 
    129       /// This iterator goes through each node.
    130       /// Its usage is quite simple, for example you can count the number
    131       /// of nodes in graph \c g of type \c Graph like this:
     140      /// Iterator class for the nodes.
     141
     142      /// This iterator goes through each node of the graph.
     143      /// Its usage is quite simple, for example, you can count the number
     144      /// of nodes in a graph \c g of type \c %Graph like this:
    132145      ///\code
    133146      /// int count=0;
     
    138151        /// Default constructor
    139152
    140         /// @warning The default constructor sets the iterator
    141         /// to an undefined value.
     153        /// Default constructor.
     154        /// \warning It sets the iterator to an undefined value.
    142155        NodeIt() { }
    143156        /// Copy constructor.
     
    146159        ///
    147160        NodeIt(const NodeIt& n) : Node(n) { }
    148         /// Invalid constructor \& conversion.
    149 
    150         /// Initialize the iterator to be invalid.
     161        /// %Invalid constructor \& conversion.
     162
     163        /// Initializes the iterator to be invalid.
    151164        /// \sa Invalid for more details.
    152165        NodeIt(Invalid) { }
    153166        /// Sets the iterator to the first node.
    154167
    155         /// Sets the iterator to the first node of \c g.
    156         ///
    157         NodeIt(const Graph&) { }
    158         /// Node -> NodeIt conversion.
    159 
    160         /// Sets the iterator to the node of \c the graph pointed by
    161         /// the trivial iterator.
    162         /// This feature necessitates that each time we
    163         /// iterate the arc-set, the iteration order is the same.
     168        /// Sets the iterator to the first node of the given digraph.
     169        ///
     170        explicit NodeIt(const Graph&) { }
     171        /// Sets the iterator to the given node.
     172
     173        /// Sets the iterator to the given node of the given digraph.
     174        ///
    164175        NodeIt(const Graph&, const Node&) { }
    165176        /// Next node.
     
    171182
    172183
    173       /// The base type of the edge iterators.
    174 
    175       /// The base type of the edge iterators.
    176       ///
     184      /// The edge type of the graph
     185
     186      /// This class identifies an edge of the graph. It also serves
     187      /// as a base class of the edge iterators,
     188      /// thus they will convert to this type.
    177189      class Edge {
    178190      public:
    179191        /// Default constructor
    180192
    181         /// @warning The default constructor sets the iterator
    182         /// to an undefined value.
     193        /// Default constructor.
     194        /// \warning It sets the object to an undefined value.
    183195        Edge() { }
    184196        /// Copy constructor.
     
    187199        ///
    188200        Edge(const Edge&) { }
    189         /// Initialize the iterator to be invalid.
    190 
    191         /// Initialize the iterator to be invalid.
    192         ///
     201        /// %Invalid constructor \& conversion.
     202
     203        /// Initializes the object to be invalid.
     204        /// \sa Invalid for more details.
    193205        Edge(Invalid) { }
    194206        /// Equality operator
    195207
     208        /// Equality operator.
     209        ///
    196210        /// Two iterators are equal if and only if they point to the
    197         /// same object or both are invalid.
     211        /// same object or both are \c INVALID.
    198212        bool operator==(Edge) const { return true; }
    199213        /// Inequality operator
    200214
    201         /// \sa operator==(Edge n)
    202         ///
     215        /// Inequality operator.
    203216        bool operator!=(Edge) const { return true; }
    204217
    205218        /// Artificial ordering operator.
    206219
    207         /// To allow the use of graph descriptors as key type in std::map or
    208         /// similar associative container we require this.
    209         ///
    210         /// \note This operator only have to define some strict ordering of
    211         /// the items; this order has nothing to do with the iteration
    212         /// ordering of the items.
     220        /// Artificial ordering operator.
     221        ///
     222        /// \note This operator only has to define some strict ordering of
     223        /// the edges; this order has nothing to do with the iteration
     224        /// ordering of the edges.
    213225        bool operator<(Edge) const { return false; }
    214226      };
    215227
    216       /// This iterator goes through each edge.
    217 
    218       /// This iterator goes through each edge of a graph.
    219       /// Its usage is quite simple, for example you can count the number
    220       /// of edges in a graph \c g of type \c Graph as follows:
     228      /// Iterator class for the edges.
     229
     230      /// This iterator goes through each edge of the graph.
     231      /// Its usage is quite simple, for example, you can count the number
     232      /// of edges in a graph \c g of type \c %Graph as follows:
    221233      ///\code
    222234      /// int count=0;
     
    227239        /// Default constructor
    228240
    229         /// @warning The default constructor sets the iterator
    230         /// to an undefined value.
     241        /// Default constructor.
     242        /// \warning It sets the iterator to an undefined value.
    231243        EdgeIt() { }
    232244        /// Copy constructor.
     
    235247        ///
    236248        EdgeIt(const EdgeIt& e) : Edge(e) { }
    237         /// Initialize the iterator to be invalid.
    238 
    239         /// Initialize the iterator to be invalid.
    240         ///
     249        /// %Invalid constructor \& conversion.
     250
     251        /// Initializes the iterator to be invalid.
     252        /// \sa Invalid for more details.
    241253        EdgeIt(Invalid) { }
    242         /// This constructor sets the iterator to the first edge.
    243 
    244         /// This constructor sets the iterator to the first edge.
    245         EdgeIt(const Graph&) { }
    246         /// Edge -> EdgeIt conversion
    247 
    248         /// Sets the iterator to the value of the trivial iterator.
    249         /// This feature necessitates that each time we
    250         /// iterate the edge-set, the iteration order is the
    251         /// same.
     254        /// Sets the iterator to the first edge.
     255
     256        /// Sets the iterator to the first edge of the given graph.
     257        ///
     258        explicit EdgeIt(const Graph&) { }
     259        /// Sets the iterator to the given edge.
     260
     261        /// Sets the iterator to the given edge of the given graph.
     262        ///
    252263        EdgeIt(const Graph&, const Edge&) { }
    253264        /// Next edge
    254265
    255266        /// Assign the iterator to the next edge.
     267        ///
    256268        EdgeIt& operator++() { return *this; }
    257269      };
    258270
    259       /// \brief This iterator goes trough the incident undirected
    260       /// arcs of a node.
    261       ///
    262       /// This iterator goes trough the incident edges
    263       /// of a certain node of a graph. You should assume that the
    264       /// loop arcs will be iterated twice.
    265       ///
    266       /// Its usage is quite simple, for example you can compute the
    267       /// degree (i.e. count the number of incident arcs of a node \c n
    268       /// in graph \c g of type \c Graph as follows.
     271      /// Iterator class for the incident edges of a node.
     272
     273      /// This iterator goes trough the incident undirected edges
     274      /// of a certain node of a graph.
     275      /// Its usage is quite simple, for example, you can compute the
     276      /// degree (i.e. the number of incident edges) of a node \c n
     277      /// in a graph \c g of type \c %Graph as follows.
    269278      ///
    270279      ///\code
     
    272281      /// for(Graph::IncEdgeIt e(g, n); e!=INVALID; ++e) ++count;
    273282      ///\endcode
     283      ///
     284      /// \warning Loop edges will be iterated twice.
    274285      class IncEdgeIt : public Edge {
    275286      public:
    276287        /// Default constructor
    277288
    278         /// @warning The default constructor sets the iterator
    279         /// to an undefined value.
     289        /// Default constructor.
     290        /// \warning It sets the iterator to an undefined value.
    280291        IncEdgeIt() { }
    281292        /// Copy constructor.
     
    284295        ///
    285296        IncEdgeIt(const IncEdgeIt& e) : Edge(e) { }
    286         /// Initialize the iterator to be invalid.
    287 
    288         /// Initialize the iterator to be invalid.
    289         ///
     297        /// %Invalid constructor \& conversion.
     298
     299        /// Initializes the iterator to be invalid.
     300        /// \sa Invalid for more details.
    290301        IncEdgeIt(Invalid) { }
    291         /// This constructor sets the iterator to first incident arc.
    292 
    293         /// This constructor set the iterator to the first incident arc of
    294         /// the node.
     302        /// Sets the iterator to the first incident edge.
     303
     304        /// Sets the iterator to the first incident edge of the given node.
     305        ///
    295306        IncEdgeIt(const Graph&, const Node&) { }
    296         /// Edge -> IncEdgeIt conversion
    297 
    298         /// Sets the iterator to the value of the trivial iterator \c e.
    299         /// This feature necessitates that each time we
    300         /// iterate the arc-set, the iteration order is the same.
     307        /// Sets the iterator to the given edge.
     308
     309        /// Sets the iterator to the given edge of the given graph.
     310        ///
    301311        IncEdgeIt(const Graph&, const Edge&) { }
    302         /// Next incident arc
    303 
    304         /// Assign the iterator to the next incident arc
     312        /// Next incident edge
     313
     314        /// Assign the iterator to the next incident edge
    305315        /// of the corresponding node.
    306316        IncEdgeIt& operator++() { return *this; }
    307317      };
    308318
    309       /// The directed arc type.
    310 
    311       /// The directed arc type. It can be converted to the
    312       /// edge or it should be inherited from the undirected
    313       /// edge.
     319      /// The arc type of the graph
     320
     321      /// This class identifies a directed arc of the graph. It also serves
     322      /// as a base class of the arc iterators,
     323      /// thus they will convert to this type.
    314324      class Arc {
    315325      public:
    316326        /// Default constructor
    317327
    318         /// @warning The default constructor sets the iterator
    319         /// to an undefined value.
     328        /// Default constructor.
     329        /// \warning It sets the object to an undefined value.
    320330        Arc() { }
    321331        /// Copy constructor.
     
    324334        ///
    325335        Arc(const Arc&) { }
    326         /// Initialize the iterator to be invalid.
    327 
    328         /// Initialize the iterator to be invalid.
    329         ///
     336        /// %Invalid constructor \& conversion.
     337
     338        /// Initializes the object to be invalid.
     339        /// \sa Invalid for more details.
    330340        Arc(Invalid) { }
    331341        /// Equality operator
    332342
     343        /// Equality operator.
     344        ///
    333345        /// Two iterators are equal if and only if they point to the
    334         /// same object or both are invalid.
     346        /// same object or both are \c INVALID.
    335347        bool operator==(Arc) const { return true; }
    336348        /// Inequality operator
    337349
    338         /// \sa operator==(Arc n)
    339         ///
     350        /// Inequality operator.
    340351        bool operator!=(Arc) const { return true; }
    341352
    342353        /// Artificial ordering operator.
    343354
    344         /// To allow the use of graph descriptors as key type in std::map or
    345         /// similar associative container we require this.
    346         ///
    347         /// \note This operator only have to define some strict ordering of
    348         /// the items; this order has nothing to do with the iteration
    349         /// ordering of the items.
     355        /// Artificial ordering operator.
     356        ///
     357        /// \note This operator only has to define some strict ordering of
     358        /// the arcs; this order has nothing to do with the iteration
     359        /// ordering of the arcs.
    350360        bool operator<(Arc) const { return false; }
    351361
    352         /// Converison to Edge
     362        /// Converison to \c Edge
     363
     364        /// Converison to \c Edge.
     365        ///
    353366        operator Edge() const { return Edge(); }
    354367      };
    355       /// This iterator goes through each directed arc.
    356 
    357       /// This iterator goes through each arc of a graph.
    358       /// Its usage is quite simple, for example you can count the number
    359       /// of arcs in a graph \c g of type \c Graph as follows:
     368
     369      /// Iterator class for the arcs.
     370
     371      /// This iterator goes through each directed arc of the graph.
     372      /// Its usage is quite simple, for example, you can count the number
     373      /// of arcs in a graph \c g of type \c %Graph as follows:
    360374      ///\code
    361375      /// int count=0;
    362       /// for(Graph::ArcIt e(g); e!=INVALID; ++e) ++count;
     376      /// for(Graph::ArcIt a(g); a!=INVALID; ++a) ++count;
    363377      ///\endcode
    364378      class ArcIt : public Arc {
     
    366380        /// Default constructor
    367381
    368         /// @warning The default constructor sets the iterator
    369         /// to an undefined value.
     382        /// Default constructor.
     383        /// \warning It sets the iterator to an undefined value.
    370384        ArcIt() { }
    371385        /// Copy constructor.
     
    374388        ///
    375389        ArcIt(const ArcIt& e) : Arc(e) { }
    376         /// Initialize the iterator to be invalid.
    377 
    378         /// Initialize the iterator to be invalid.
    379         ///
     390        /// %Invalid constructor \& conversion.
     391
     392        /// Initializes the iterator to be invalid.
     393        /// \sa Invalid for more details.
    380394        ArcIt(Invalid) { }
    381         /// This constructor sets the iterator to the first arc.
    382 
    383         /// This constructor sets the iterator to the first arc of \c g.
    384         ///@param g the graph
    385         ArcIt(const Graph &g) { ignore_unused_variable_warning(g); }
    386         /// Arc -> ArcIt conversion
    387 
    388         /// Sets the iterator to the value of the trivial iterator \c e.
    389         /// This feature necessitates that each time we
    390         /// iterate the arc-set, the iteration order is the same.
     395        /// Sets the iterator to the first arc.
     396
     397        /// Sets the iterator to the first arc of the given graph.
     398        ///
     399        explicit ArcIt(const Graph &g) { ignore_unused_variable_warning(g); }
     400        /// Sets the iterator to the given arc.
     401
     402        /// Sets the iterator to the given arc of the given graph.
     403        ///
    391404        ArcIt(const Graph&, const Arc&) { }
    392         ///Next arc
     405        /// Next arc
    393406
    394407        /// Assign the iterator to the next arc.
     408        ///
    395409        ArcIt& operator++() { return *this; }
    396410      };
    397411
    398       /// This iterator goes trough the outgoing directed arcs of a node.
    399 
    400       /// This iterator goes trough the \e outgoing arcs of a certain node
    401       /// of a graph.
    402       /// Its usage is quite simple, for example you can count the number
     412      /// Iterator class for the outgoing arcs of a node.
     413
     414      /// This iterator goes trough the \e outgoing directed arcs of a
     415      /// certain node of a graph.
     416      /// Its usage is quite simple, for example, you can count the number
    403417      /// of outgoing arcs of a node \c n
    404       /// in graph \c g of type \c Graph as follows.
     418      /// in a graph \c g of type \c %Graph as follows.
    405419      ///\code
    406420      /// int count=0;
    407       /// for (Graph::OutArcIt e(g, n); e!=INVALID; ++e) ++count;
     421      /// for (Digraph::OutArcIt a(g, n); a!=INVALID; ++a) ++count;
    408422      ///\endcode
    409 
    410423      class OutArcIt : public Arc {
    411424      public:
    412425        /// Default constructor
    413426
    414         /// @warning The default constructor sets the iterator
    415         /// to an undefined value.
     427        /// Default constructor.
     428        /// \warning It sets the iterator to an undefined value.
    416429        OutArcIt() { }
    417430        /// Copy constructor.
     
    420433        ///
    421434        OutArcIt(const OutArcIt& e) : Arc(e) { }
    422         /// Initialize the iterator to be invalid.
    423 
    424         /// Initialize the iterator to be invalid.
    425         ///
     435        /// %Invalid constructor \& conversion.
     436
     437        /// Initializes the iterator to be invalid.
     438        /// \sa Invalid for more details.
    426439        OutArcIt(Invalid) { }
    427         /// This constructor sets the iterator to the first outgoing arc.
    428 
    429         /// This constructor sets the iterator to the first outgoing arc of
    430         /// the node.
    431         ///@param n the node
    432         ///@param g the graph
     440        /// Sets the iterator to the first outgoing arc.
     441
     442        /// Sets the iterator to the first outgoing arc of the given node.
     443        ///
    433444        OutArcIt(const Graph& n, const Node& g) {
    434445          ignore_unused_variable_warning(n);
    435446          ignore_unused_variable_warning(g);
    436447        }
    437         /// Arc -> OutArcIt conversion
    438 
    439         /// Sets the iterator to the value of the trivial iterator.
    440         /// This feature necessitates that each time we
    441         /// iterate the arc-set, the iteration order is the same.
     448        /// Sets the iterator to the given arc.
     449
     450        /// Sets the iterator to the given arc of the given graph.
     451        ///
    442452        OutArcIt(const Graph&, const Arc&) { }
    443         ///Next outgoing arc
     453        /// Next outgoing arc
    444454
    445455        /// Assign the iterator to the next
     
    448458      };
    449459
    450       /// This iterator goes trough the incoming directed arcs of a node.
    451 
    452       /// This iterator goes trough the \e incoming arcs of a certain node
    453       /// of a graph.
    454       /// Its usage is quite simple, for example you can count the number
    455       /// of outgoing arcs of a node \c n
    456       /// in graph \c g of type \c Graph as follows.
     460      /// Iterator class for the incoming arcs of a node.
     461
     462      /// This iterator goes trough the \e incoming directed arcs of a
     463      /// certain node of a graph.
     464      /// Its usage is quite simple, for example, you can count the number
     465      /// of incoming arcs of a node \c n
     466      /// in a graph \c g of type \c %Graph as follows.
    457467      ///\code
    458468      /// int count=0;
    459       /// for(Graph::InArcIt e(g, n); e!=INVALID; ++e) ++count;
     469      /// for (Digraph::InArcIt a(g, n); a!=INVALID; ++a) ++count;
    460470      ///\endcode
    461 
    462471      class InArcIt : public Arc {
    463472      public:
    464473        /// Default constructor
    465474
    466         /// @warning The default constructor sets the iterator
    467         /// to an undefined value.
     475        /// Default constructor.
     476        /// \warning It sets the iterator to an undefined value.
    468477        InArcIt() { }
    469478        /// Copy constructor.
     
    472481        ///
    473482        InArcIt(const InArcIt& e) : Arc(e) { }
    474         /// Initialize the iterator to be invalid.
    475 
    476         /// Initialize the iterator to be invalid.
    477         ///
     483        /// %Invalid constructor \& conversion.
     484
     485        /// Initializes the iterator to be invalid.
     486        /// \sa Invalid for more details.
    478487        InArcIt(Invalid) { }
    479         /// This constructor sets the iterator to first incoming arc.
    480 
    481         /// This constructor set the iterator to the first incoming arc of
    482         /// the node.
    483         ///@param n the node
    484         ///@param g the graph
     488        /// Sets the iterator to the first incoming arc.
     489
     490        /// Sets the iterator to the first incoming arc of the given node.
     491        ///
    485492        InArcIt(const Graph& g, const Node& n) {
    486493          ignore_unused_variable_warning(n);
    487494          ignore_unused_variable_warning(g);
    488495        }
    489         /// Arc -> InArcIt conversion
    490 
    491         /// Sets the iterator to the value of the trivial iterator \c e.
    492         /// This feature necessitates that each time we
    493         /// iterate the arc-set, the iteration order is the same.
     496        /// Sets the iterator to the given arc.
     497
     498        /// Sets the iterator to the given arc of the given graph.
     499        ///
    494500        InArcIt(const Graph&, const Arc&) { }
    495501        /// Next incoming arc
    496502
    497         /// Assign the iterator to the next inarc of the corresponding node.
    498         ///
     503        /// Assign the iterator to the next
     504        /// incoming arc of the corresponding node.
    499505        InArcIt& operator++() { return *this; }
    500506      };
    501507
    502       /// \brief Reference map of the nodes to type \c T.
    503       ///
    504       /// Reference map of the nodes to type \c T.
     508      /// \brief Standard graph map type for the nodes.
     509      ///
     510      /// Standard graph map type for the nodes.
     511      /// It conforms to the ReferenceMap concept.
    505512      template<class T>
    506513      class NodeMap : public ReferenceMap<Node, T, T&, const T&>
     
    508515      public:
    509516
    510         ///\e
    511         NodeMap(const Graph&) { }
    512         ///\e
     517        /// Constructor
     518        explicit NodeMap(const Graph&) { }
     519        /// Constructor with given initial value
    513520        NodeMap(const Graph&, T) { }
    514521
     
    525532      };
    526533
    527       /// \brief Reference map of the arcs to type \c T.
    528       ///
    529       /// Reference map of the arcs to type \c T.
     534      /// \brief Standard graph map type for the arcs.
     535      ///
     536      /// Standard graph map type for the arcs.
     537      /// It conforms to the ReferenceMap concept.
    530538      template<class T>
    531539      class ArcMap : public ReferenceMap<Arc, T, T&, const T&>
     
    533541      public:
    534542
    535         ///\e
    536         ArcMap(const Graph&) { }
    537         ///\e
     543        /// Constructor
     544        explicit ArcMap(const Graph&) { }
     545        /// Constructor with given initial value
    538546        ArcMap(const Graph&, T) { }
     547
    539548      private:
    540549        ///Copy constructor
     
    549558      };
    550559
    551       /// Reference map of the edges to type \c T.
    552 
    553       /// Reference map of the edges to type \c T.
     560      /// \brief Standard graph map type for the edges.
     561      ///
     562      /// Standard graph map type for the edges.
     563      /// It conforms to the ReferenceMap concept.
    554564      template<class T>
    555565      class EdgeMap : public ReferenceMap<Edge, T, T&, const T&>
     
    557567      public:
    558568
    559         ///\e
    560         EdgeMap(const Graph&) { }
    561         ///\e
     569        /// Constructor
     570        explicit EdgeMap(const Graph&) { }
     571        /// Constructor with given initial value
    562572        EdgeMap(const Graph&, T) { }
     573
    563574      private:
    564575        ///Copy constructor
     
    573584      };
    574585
    575       /// \brief Direct the given edge.
    576       ///
    577       /// Direct the given edge. The returned arc source
    578       /// will be the given node.
    579       Arc direct(const Edge&, const Node&) const {
    580         return INVALID;
    581       }
    582 
    583       /// \brief Direct the given edge.
    584       ///
    585       /// Direct the given edge. The returned arc
    586       /// represents the given edge and the direction comes
    587       /// from the bool parameter. The source of the edge and
    588       /// the directed arc is the same when the given bool is true.
    589       Arc direct(const Edge&, bool) const {
    590         return INVALID;
    591       }
    592 
    593       /// \brief Returns true if the arc has default orientation.
    594       ///
    595       /// Returns whether the given directed arc is same orientation as
    596       /// the corresponding edge's default orientation.
    597       bool direction(Arc) const { return true; }
    598 
    599       /// \brief Returns the opposite directed arc.
    600       ///
    601       /// Returns the opposite directed arc.
    602       Arc oppositeArc(Arc) const { return INVALID; }
    603 
    604       /// \brief Opposite node on an arc
    605       ///
    606       /// \return The opposite of the given node on the given edge.
    607       Node oppositeNode(Node, Edge) const { return INVALID; }
    608 
    609       /// \brief First node of the edge.
    610       ///
    611       /// \return The first node of the given edge.
    612       ///
    613       /// Naturally edges don't have direction and thus
    614       /// don't have source and target node. However we use \c u() and \c v()
    615       /// methods to query the two nodes of the arc. The direction of the
    616       /// arc which arises this way is called the inherent direction of the
    617       /// edge, and is used to define the "default" direction
    618       /// of the directed versions of the arcs.
     586      /// \brief The first node of the edge.
     587      ///
     588      /// Returns the first node of the given edge.
     589      ///
     590      /// Edges don't have source and target nodes, however, methods
     591      /// u() and v() are used to query the two end-nodes of an edge.
     592      /// The orientation of an edge that arises this way is called
     593      /// the inherent direction, it is used to define the default
     594      /// direction for the corresponding arcs.
    619595      /// \sa v()
    620596      /// \sa direction()
    621597      Node u(Edge) const { return INVALID; }
    622598
    623       /// \brief Second node of the edge.
    624       ///
    625       /// \return The second node of the given edge.
    626       ///
    627       /// Naturally edges don't have direction and thus
    628       /// don't have source and target node. However we use \c u() and \c v()
    629       /// methods to query the two nodes of the arc. The direction of the
    630       /// arc which arises this way is called the inherent direction of the
    631       /// edge, and is used to define the "default" direction
    632       /// of the directed versions of the arcs.
     599      /// \brief The second node of the edge.
     600      ///
     601      /// Returns the second node of the given edge.
     602      ///
     603      /// Edges don't have source and target nodes, however, methods
     604      /// u() and v() are used to query the two end-nodes of an edge.
     605      /// The orientation of an edge that arises this way is called
     606      /// the inherent direction, it is used to define the default
     607      /// direction for the corresponding arcs.
    633608      /// \sa u()
    634609      /// \sa direction()
    635610      Node v(Edge) const { return INVALID; }
    636611
    637       /// \brief Source node of the directed arc.
     612      /// \brief The source node of the arc.
     613      ///
     614      /// Returns the source node of the given arc.
    638615      Node source(Arc) const { return INVALID; }
    639616
    640       /// \brief Target node of the directed arc.
     617      /// \brief The target node of the arc.
     618      ///
     619      /// Returns the target node of the given arc.
    641620      Node target(Arc) const { return INVALID; }
    642621
    643       /// \brief Returns the id of the node.
     622      /// \brief The ID of the node.
     623      ///
     624      /// Returns the ID of the given node.
    644625      int id(Node) const { return -1; }
    645626
    646       /// \brief Returns the id of the edge.
     627      /// \brief The ID of the edge.
     628      ///
     629      /// Returns the ID of the given edge.
    647630      int id(Edge) const { return -1; }
    648631
    649       /// \brief Returns the id of the arc.
     632      /// \brief The ID of the arc.
     633      ///
     634      /// Returns the ID of the given arc.
    650635      int id(Arc) const { return -1; }
    651636
    652       /// \brief Returns the node with the given id.
    653       ///
    654       /// \pre The argument should be a valid node id in the graph.
     637      /// \brief The node with the given ID.
     638      ///
     639      /// Returns the node with the given ID.
     640      /// \pre The argument should be a valid node ID in the graph.
    655641      Node nodeFromId(int) const { return INVALID; }
    656642
    657       /// \brief Returns the edge with the given id.
    658       ///
    659       /// \pre The argument should be a valid edge id in the graph.
     643      /// \brief The edge with the given ID.
     644      ///
     645      /// Returns the edge with the given ID.
     646      /// \pre The argument should be a valid edge ID in the graph.
    660647      Edge edgeFromId(int) const { return INVALID; }
    661648
    662       /// \brief Returns the arc with the given id.
    663       ///
    664       /// \pre The argument should be a valid arc id in the graph.
     649      /// \brief The arc with the given ID.
     650      ///
     651      /// Returns the arc with the given ID.
     652      /// \pre The argument should be a valid arc ID in the graph.
    665653      Arc arcFromId(int) const { return INVALID; }
    666654
    667       /// \brief Returns an upper bound on the node IDs.
     655      /// \brief An upper bound on the node IDs.
     656      ///
     657      /// Returns an upper bound on the node IDs.
    668658      int maxNodeId() const { return -1; }
    669659
    670       /// \brief Returns an upper bound on the edge IDs.
     660      /// \brief An upper bound on the edge IDs.
     661      ///
     662      /// Returns an upper bound on the edge IDs.
    671663      int maxEdgeId() const { return -1; }
    672664
    673       /// \brief Returns an upper bound on the arc IDs.
     665      /// \brief An upper bound on the arc IDs.
     666      ///
     667      /// Returns an upper bound on the arc IDs.
    674668      int maxArcId() const { return -1; }
     669
     670      /// \brief The direction of the arc.
     671      ///
     672      /// Returns \c true if the direction of the given arc is the same as
     673      /// the inherent orientation of the represented edge.
     674      bool direction(Arc) const { return true; }
     675
     676      /// \brief Direct the edge.
     677      ///
     678      /// Direct the given edge. The returned arc
     679      /// represents the given edge and its direction comes
     680      /// from the bool parameter. If it is \c true, then the direction
     681      /// of the arc is the same as the inherent orientation of the edge.
     682      Arc direct(Edge, bool) const {
     683        return INVALID;
     684      }
     685
     686      /// \brief Direct the edge.
     687      ///
     688      /// Direct the given edge. The returned arc represents the given
     689      /// edge and its source node is the given node.
     690      Arc direct(Edge, Node) const {
     691        return INVALID;
     692      }
     693
     694      /// \brief The oppositely directed arc.
     695      ///
     696      /// Returns the oppositely directed arc representing the same edge.
     697      Arc oppositeArc(Arc) const { return INVALID; }
     698
     699      /// \brief The opposite node on the edge.
     700      ///
     701      /// Returns the opposite node on the given edge.
     702      Node oppositeNode(Node, Edge) const { return INVALID; }
    675703
    676704      void first(Node&) const {}
     
    706734      int maxId(Arc) const { return -1; }
    707735
    708       /// \brief Base node of the iterator
    709       ///
    710       /// Returns the base node (the source in this case) of the iterator
    711       Node baseNode(OutArcIt e) const {
    712         return source(e);
    713       }
    714       /// \brief Running node of the iterator
    715       ///
    716       /// Returns the running node (the target in this case) of the
    717       /// iterator
    718       Node runningNode(OutArcIt e) const {
    719         return target(e);
    720       }
    721 
    722       /// \brief Base node of the iterator
    723       ///
    724       /// Returns the base node (the target in this case) of the iterator
    725       Node baseNode(InArcIt e) const {
    726         return target(e);
    727       }
    728       /// \brief Running node of the iterator
    729       ///
    730       /// Returns the running node (the source in this case) of the
    731       /// iterator
    732       Node runningNode(InArcIt e) const {
    733         return source(e);
    734       }
    735 
    736       /// \brief Base node of the iterator
    737       ///
    738       /// Returns the base node of the iterator
    739       Node baseNode(IncEdgeIt) const {
    740         return INVALID;
    741       }
    742 
    743       /// \brief Running node of the iterator
    744       ///
    745       /// Returns the running node of the iterator
    746       Node runningNode(IncEdgeIt) const {
    747         return INVALID;
    748       }
     736      /// \brief The base node of the iterator.
     737      ///
     738      /// Returns the base node of the given incident edge iterator.
     739      Node baseNode(IncEdgeIt) const { return INVALID; }
     740
     741      /// \brief The running node of the iterator.
     742      ///
     743      /// Returns the running node of the given incident edge iterator.
     744      Node runningNode(IncEdgeIt) const { return INVALID; }
     745
     746      /// \brief The base node of the iterator.
     747      ///
     748      /// Returns the base node of the given outgoing arc iterator
     749      /// (i.e. the source node of the corresponding arc).
     750      Node baseNode(OutArcIt) const { return INVALID; }
     751
     752      /// \brief The running node of the iterator.
     753      ///
     754      /// Returns the running node of the given outgoing arc iterator
     755      /// (i.e. the target node of the corresponding arc).
     756      Node runningNode(OutArcIt) const { return INVALID; }
     757
     758      /// \brief The base node of the iterator.
     759      ///
     760      /// Returns the base node of the given incomming arc iterator
     761      /// (i.e. the target node of the corresponding arc).
     762      Node baseNode(InArcIt) const { return INVALID; }
     763
     764      /// \brief The running node of the iterator.
     765      ///
     766      /// Returns the running node of the given incomming arc iterator
     767      /// (i.e. the source node of the corresponding arc).
     768      Node runningNode(InArcIt) const { return INVALID; }
    749769
    750770      template <typename _Graph>
  • TabularUnified lemon/concepts/graph_components.h

    r713 r956  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    1919///\ingroup graph_concepts
    2020///\file
    21 ///\brief The concept of graph components.
     21///\brief The concepts of graph components.
    2222
    2323#ifndef LEMON_CONCEPTS_GRAPH_COMPONENTS_H
     
    3939    /// \note This class is a template class so that we can use it to
    4040    /// create graph skeleton classes. The reason for this is that \c Node
    41     /// and \c Arc (or \c Edge) types should \e not derive from the same 
     41    /// and \c Arc (or \c Edge) types should \e not derive from the same
    4242    /// base class. For \c Node you should instantiate it with character
    4343    /// \c 'n', for \c Arc with \c 'a' and for \c Edge with \c 'e'.
     
    9090      ///
    9191      /// This operator defines an ordering of the items.
    92       /// It makes possible to use graph item types as key types in 
     92      /// It makes possible to use graph item types as key types in
    9393      /// associative containers (e.g. \c std::map).
    9494      ///
    95       /// \note This operator only have to define some strict ordering of
     95      /// \note This operator only has to define some strict ordering of
    9696      /// the items; this order has nothing to do with the iteration
    9797      /// ordering of the items.
     
    123123    /// This class describes the base interface of directed graph types.
    124124    /// All digraph %concepts have to conform to this class.
    125     /// It just provides types for nodes and arcs and functions 
     125    /// It just provides types for nodes and arcs and functions
    126126    /// to get the source and the target nodes of arcs.
    127127    class BaseDigraphComponent {
     
    427427    /// \brief Concept class for \c NodeIt, \c ArcIt and \c EdgeIt types.
    428428    ///
    429     /// This class describes the concept of \c NodeIt, \c ArcIt and 
     429    /// This class describes the concept of \c NodeIt, \c ArcIt and
    430430    /// \c EdgeIt subtypes of digraph and graph types.
    431431    template <typename GR, typename Item>
     
    467467      /// next item.
    468468      GraphItemIt& operator++() { return *this; }
    469  
     469
    470470      /// \brief Equality operator
    471471      ///
     
    502502    };
    503503
    504     /// \brief Concept class for \c InArcIt, \c OutArcIt and 
     504    /// \brief Concept class for \c InArcIt, \c OutArcIt and
    505505    /// \c IncEdgeIt types.
    506506    ///
    507     /// This class describes the concept of \c InArcIt, \c OutArcIt 
     507    /// This class describes the concept of \c InArcIt, \c OutArcIt
    508508    /// and \c IncEdgeIt subtypes of digraph and graph types.
    509509    ///
    510510    /// \note Since these iterator classes do not inherit from the same
    511511    /// base class, there is an additional template parameter (selector)
    512     /// \c sel. For \c InArcIt you should instantiate it with character 
     512    /// \c sel. For \c InArcIt you should instantiate it with character
    513513    /// \c 'i', for \c OutArcIt with \c 'o' and for \c IncEdgeIt with \c 'e'.
    514514    template <typename GR,
     
    531531      GraphIncIt(const GraphIncIt& it) : Item(it) {}
    532532
    533       /// \brief Constructor that sets the iterator to the first 
     533      /// \brief Constructor that sets the iterator to the first
    534534      /// incoming or outgoing arc.
    535535      ///
    536       /// Constructor that sets the iterator to the first arc 
     536      /// Constructor that sets the iterator to the first arc
    537537      /// incoming to or outgoing from the given node.
    538538      explicit GraphIncIt(const GR&, const Base&) {}
     
    805805      /// \brief Return the first edge incident to the given node.
    806806      ///
    807       /// This function gives back the first edge incident to the given 
     807      /// This function gives back the first edge incident to the given
    808808      /// node. The bool parameter gives back the direction for which the
    809       /// source node of the directed arc representing the edge is the 
     809      /// source node of the directed arc representing the edge is the
    810810      /// given node.
    811811      void firstInc(Edge&, bool&, const Node&) const {}
     
    814814      /// given node.
    815815      ///
    816       /// This function gives back the next edge incident to the given 
     816      /// This function gives back the next edge incident to the given
    817817      /// node. The bool parameter should be used as \c firstInc() use it.
    818818      void nextInc(Edge&, bool&) const {}
     
    991991    ///
    992992    /// This class describes the concept of standard graph maps, i.e.
    993     /// the \c NodeMap, \c ArcMap and \c EdgeMap subtypes of digraph and 
     993    /// the \c NodeMap, \c ArcMap and \c EdgeMap subtypes of digraph and
    994994    /// graph types, which can be used for associating data to graph items.
    995995    /// The standard graph maps must conform to the ReferenceMap concept.
     
    10461046          _Map m1(g);
    10471047          _Map m2(g,t);
    1048          
     1048
    10491049          // Copy constructor
    10501050          // _Map m3(m);
     
    10691069    ///
    10701070    /// This class describes the interface of mappable directed graphs.
    1071     /// It extends \ref BaseDigraphComponent with the standard digraph 
     1071    /// It extends \ref BaseDigraphComponent with the standard digraph
    10721072    /// map classes, namely \c NodeMap and \c ArcMap.
    10731073    /// This concept is part of the Digraph concept.
     
    12061206    ///
    12071207    /// This class describes the interface of mappable undirected graphs.
    1208     /// It extends \ref MappableDigraphComponent with the standard graph 
     1208    /// It extends \ref MappableDigraphComponent with the standard graph
    12091209    /// map class for edges (\c EdgeMap).
    12101210    /// This concept is part of the Graph concept.
     
    12911291    ///
    12921292    /// This class describes the interface of extendable directed graphs.
    1293     /// It extends \ref BaseDigraphComponent with functions for adding 
     1293    /// It extends \ref BaseDigraphComponent with functions for adding
    12941294    /// nodes and arcs to the digraph.
    12951295    /// This concept requires \ref AlterableDigraphComponent.
     
    13351335    ///
    13361336    /// This class describes the interface of extendable undirected graphs.
    1337     /// It extends \ref BaseGraphComponent with functions for adding 
     1337    /// It extends \ref BaseGraphComponent with functions for adding
    13381338    /// nodes and edges to the graph.
    13391339    /// This concept requires \ref AlterableGraphComponent.
     
    13791379    ///
    13801380    /// This class describes the interface of erasable directed graphs.
    1381     /// It extends \ref BaseDigraphComponent with functions for removing 
     1381    /// It extends \ref BaseDigraphComponent with functions for removing
    13821382    /// nodes and arcs from the digraph.
    13831383    /// This concept requires \ref AlterableDigraphComponent.
     
    13921392      /// \brief Erase a node from the digraph.
    13931393      ///
    1394       /// This function erases the given node from the digraph and all arcs 
     1394      /// This function erases the given node from the digraph and all arcs
    13951395      /// connected to the node.
    13961396      void erase(const Node&) {}
     
    14181418    ///
    14191419    /// This class describes the interface of erasable undirected graphs.
    1420     /// It extends \ref BaseGraphComponent with functions for removing 
     1420    /// It extends \ref BaseGraphComponent with functions for removing
    14211421    /// nodes and edges from the graph.
    14221422    /// This concept requires \ref AlterableGraphComponent.
  • TabularUnified lemon/concepts/heap.h

    r631 r956  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    1717 */
    1818
     19#ifndef LEMON_CONCEPTS_HEAP_H
     20#define LEMON_CONCEPTS_HEAP_H
     21
    1922///\ingroup concept
    2023///\file
    2124///\brief The concept of heaps.
    2225
    23 #ifndef LEMON_CONCEPTS_HEAP_H
    24 #define LEMON_CONCEPTS_HEAP_H
    25 
    2626#include <lemon/core.h>
    2727#include <lemon/concept_check.h>
     
    3636    /// \brief The heap concept.
    3737    ///
    38     /// Concept class describing the main interface of heaps. A \e heap
    39     /// is a data structure for storing items with specified values called
    40     /// \e priorities in such a way that finding the item with minimum
    41     /// priority is efficient. In a heap one can change the priority of an
    42     /// item, add or erase an item, etc.
     38    /// This concept class describes the main interface of heaps.
     39    /// The various \ref heaps "heap structures" are efficient
     40    /// implementations of the abstract data type \e priority \e queue.
     41    /// They store items with specified values called \e priorities
     42    /// in such a way that finding and removing the item with minimum
     43    /// priority are efficient. The basic operations are adding and
     44    /// erasing items, changing the priority of an item, etc.
    4345    ///
    44     /// \tparam PR Type of the priority of the items.
    45     /// \tparam IM A read and writable item map with int values, used
     46    /// Heaps are crucial in several algorithms, such as Dijkstra and Prim.
     47    /// Any class that conforms to this concept can be used easily in such
     48    /// algorithms.
     49    ///
     50    /// \tparam PR Type of the priorities of the items.
     51    /// \tparam IM A read-writable item map with \c int values, used
    4652    /// internally to handle the cross references.
    47     /// \tparam Comp A functor class for the ordering of the priorities.
     53    /// \tparam CMP A functor class for comparing the priorities.
    4854    /// The default is \c std::less<PR>.
    4955#ifdef DOXYGEN
    50     template <typename PR, typename IM, typename Comp = std::less<PR> >
    51 #else
    52     template <typename PR, typename IM>
     56    template <typename PR, typename IM, typename CMP>
     57#else
     58    template <typename PR, typename IM, typename CMP = std::less<PR> >
    5359#endif
    5460    class Heap {
     
    6571      ///
    6672      /// Each item has a state associated to it. It can be "in heap",
    67       /// "pre heap" or "post heap". The later two are indifferent
    68       /// from the point of view of the heap, but may be useful for
    69       /// the user.
     73      /// "pre-heap" or "post-heap". The latter two are indifferent from the
     74      /// heap's point of view, but may be useful to the user.
    7075      ///
    7176      /// The item-int map must be initialized in such way that it assigns
     
    7378      enum State {
    7479        IN_HEAP = 0,    ///< = 0. The "in heap" state constant.
    75         PRE_HEAP = -1,  ///< = -1. The "pre heap" state constant.
    76         POST_HEAP = -2  ///< = -2. The "post heap" state constant.
     80        PRE_HEAP = -1,  ///< = -1. The "pre-heap" state constant.
     81        POST_HEAP = -2  ///< = -2. The "post-heap" state constant.
    7782      };
    7883
    79       /// \brief The constructor.
    80       ///
    81       /// The constructor.
     84      /// \brief Constructor.
     85      ///
     86      /// Constructor.
    8287      /// \param map A map that assigns \c int values to keys of type
    8388      /// \c Item. It is used internally by the heap implementations to
    8489      /// handle the cross references. The assigned value must be
    85       /// \c PRE_HEAP (<tt>-1</tt>) for every item.
     90      /// \c PRE_HEAP (<tt>-1</tt>) for each item.
     91#ifdef DOXYGEN
    8692      explicit Heap(ItemIntMap &map) {}
     93#else
     94      explicit Heap(ItemIntMap&) {}
     95#endif
     96
     97      /// \brief Constructor.
     98      ///
     99      /// Constructor.
     100      /// \param map A map that assigns \c int values to keys of type
     101      /// \c Item. It is used internally by the heap implementations to
     102      /// handle the cross references. The assigned value must be
     103      /// \c PRE_HEAP (<tt>-1</tt>) for each item.
     104      /// \param comp The function object used for comparing the priorities.
     105#ifdef DOXYGEN
     106      explicit Heap(ItemIntMap &map, const CMP &comp) {}
     107#else
     108      explicit Heap(ItemIntMap&, const CMP&) {}
     109#endif
    87110
    88111      /// \brief The number of items stored in the heap.
    89112      ///
    90       /// Returns the number of items stored in the heap.
     113      /// This function returns the number of items stored in the heap.
    91114      int size() const { return 0; }
    92115
    93       /// \brief Checks if the heap is empty.
    94       ///
    95       /// Returns \c true if the heap is empty.
     116      /// \brief Check if the heap is empty.
     117      ///
     118      /// This function returns \c true if the heap is empty.
    96119      bool empty() const { return false; }
    97120
    98       /// \brief Makes the heap empty.
    99       ///
    100       /// Makes the heap empty.
    101       void clear();
    102 
    103       /// \brief Inserts an item into the heap with the given priority.
    104       ///
    105       /// Inserts the given item into the heap with the given priority.
     121      /// \brief Make the heap empty.
     122      ///
     123      /// This functon makes the heap empty.
     124      /// It does not change the cross reference map. If you want to reuse
     125      /// a heap that is not surely empty, you should first clear it and
     126      /// then you should set the cross reference map to \c PRE_HEAP
     127      /// for each item.
     128      void clear() {}
     129
     130      /// \brief Insert an item into the heap with the given priority.
     131      ///
     132      /// This function inserts the given item into the heap with the
     133      /// given priority.
    106134      /// \param i The item to insert.
    107135      /// \param p The priority of the item.
     136      /// \pre \e i must not be stored in the heap.
     137#ifdef DOXYGEN
    108138      void push(const Item &i, const Prio &p) {}
    109 
    110       /// \brief Returns the item having minimum priority.
    111       ///
    112       /// Returns the item having minimum priority.
     139#else
     140      void push(const Item&, const Prio&) {}
     141#endif
     142
     143      /// \brief Return the item having minimum priority.
     144      ///
     145      /// This function returns the item having minimum priority.
    113146      /// \pre The heap must be non-empty.
    114       Item top() const {}
     147      Item top() const { return Item(); }
    115148
    116149      /// \brief The minimum priority.
    117150      ///
    118       /// Returns the minimum priority.
     151      /// This function returns the minimum priority.
    119152      /// \pre The heap must be non-empty.
    120       Prio prio() const {}
    121 
    122       /// \brief Removes the item having minimum priority.
    123       ///
    124       /// Removes the item having minimum priority.
     153      Prio prio() const { return Prio(); }
     154
     155      /// \brief Remove the item having minimum priority.
     156      ///
     157      /// This function removes the item having minimum priority.
    125158      /// \pre The heap must be non-empty.
    126159      void pop() {}
    127160
    128       /// \brief Removes an item from the heap.
    129       ///
    130       /// Removes the given item from the heap if it is already stored.
     161      /// \brief Remove the given item from the heap.
     162      ///
     163      /// This function removes the given item from the heap if it is
     164      /// already stored.
    131165      /// \param i The item to delete.
     166      /// \pre \e i must be in the heap.
     167#ifdef DOXYGEN
    132168      void erase(const Item &i) {}
    133 
    134       /// \brief The priority of an item.
    135       ///
    136       /// Returns the priority of the given item.
    137       /// \param i The item.
    138       /// \pre \c i must be in the heap.
     169#else
     170      void erase(const Item&) {}
     171#endif
     172
     173      /// \brief The priority of the given item.
     174      ///
     175      /// This function returns the priority of the given item.
     176      /// \param i The item.
     177      /// \pre \e i must be in the heap.
     178#ifdef DOXYGEN
    139179      Prio operator[](const Item &i) const {}
    140 
    141       /// \brief Sets the priority of an item or inserts it, if it is
     180#else
     181      Prio operator[](const Item&) const { return Prio(); }
     182#endif
     183
     184      /// \brief Set the priority of an item or insert it, if it is
    142185      /// not stored in the heap.
    143186      ///
    144187      /// This method sets the priority of the given item if it is
    145       /// already stored in the heap.
    146       /// Otherwise it inserts the given item with the given priority.
     188      /// already stored in the heap. Otherwise it inserts the given
     189      /// item into the heap with the given priority.
    147190      ///
    148191      /// \param i The item.
    149192      /// \param p The priority.
     193#ifdef DOXYGEN
    150194      void set(const Item &i, const Prio &p) {}
    151 
    152       /// \brief Decreases the priority of an item to the given value.
    153       ///
    154       /// Decreases the priority of an item to the given value.
     195#else
     196      void set(const Item&, const Prio&) {}
     197#endif
     198
     199      /// \brief Decrease the priority of an item to the given value.
     200      ///
     201      /// This function decreases the priority of an item to the given value.
    155202      /// \param i The item.
    156203      /// \param p The priority.
    157       /// \pre \c i must be stored in the heap with priority at least \c p.
     204      /// \pre \e i must be stored in the heap with priority at least \e p.
     205#ifdef DOXYGEN
    158206      void decrease(const Item &i, const Prio &p) {}
    159 
    160       /// \brief Increases the priority of an item to the given value.
    161       ///
    162       /// Increases the priority of an item to the given value.
     207#else
     208      void decrease(const Item&, const Prio&) {}
     209#endif
     210
     211      /// \brief Increase the priority of an item to the given value.
     212      ///
     213      /// This function increases the priority of an item to the given value.
    163214      /// \param i The item.
    164215      /// \param p The priority.
    165       /// \pre \c i must be stored in the heap with priority at most \c p.
     216      /// \pre \e i must be stored in the heap with priority at most \e p.
     217#ifdef DOXYGEN
    166218      void increase(const Item &i, const Prio &p) {}
    167 
    168       /// \brief Returns if an item is in, has already been in, or has
    169       /// never been in the heap.
     219#else
     220      void increase(const Item&, const Prio&) {}
     221#endif
     222
     223      /// \brief Return the state of an item.
    170224      ///
    171225      /// This method returns \c PRE_HEAP if the given item has never
     
    175229      /// to the heap again.
    176230      /// \param i The item.
     231#ifdef DOXYGEN
    177232      State state(const Item &i) const {}
    178 
    179       /// \brief Sets the state of an item in the heap.
    180       ///
    181       /// Sets the state of the given item in the heap. It can be used
    182       /// to manually clear the heap when it is important to achive the
    183       /// better time complexity.
     233#else
     234      State state(const Item&) const { return PRE_HEAP; }
     235#endif
     236
     237      /// \brief Set the state of an item in the heap.
     238      ///
     239      /// This function sets the state of the given item in the heap.
     240      /// It can be used to manually clear the heap when it is important
     241      /// to achive better time complexity.
    184242      /// \param i The item.
    185243      /// \param st The state. It should not be \c IN_HEAP.
     244#ifdef DOXYGEN
    186245      void state(const Item& i, State st) {}
     246#else
     247      void state(const Item&, State) {}
     248#endif
    187249
    188250
  • TabularUnified lemon/concepts/path.h

    r606 r832  
    1919///\ingroup concept
    2020///\file
    21 ///\brief Classes for representing paths in digraphs.
     21///\brief The concept of paths
    2222///
    2323
     
    3939    /// A skeleton structure for representing directed paths in a
    4040    /// digraph.
     41    /// In a sense, a path can be treated as a list of arcs.
     42    /// LEMON path types just store this list. As a consequence, they cannot
     43    /// enumerate the nodes on the path directly and a zero length path
     44    /// cannot store its source node.
     45    ///
     46    /// The arcs of a path should be stored in the order of their directions,
     47    /// i.e. the target node of each arc should be the same as the source
     48    /// node of the next arc. This consistency could be checked using
     49    /// \ref checkPath().
     50    /// The source and target nodes of a (consistent) path can be obtained
     51    /// using \ref pathSource() and \ref pathTarget().
     52    ///
     53    /// A path can be constructed from another path of any type using the
     54    /// copy constructor or the assignment operator.
     55    ///
    4156    /// \tparam GR The digraph type in which the path is.
    42     ///
    43     /// In a sense, the path can be treated as a list of arcs. The
    44     /// lemon path type stores just this list. As a consequence it
    45     /// cannot enumerate the nodes in the path and the zero length
    46     /// paths cannot store the source.
    47     ///
    4857    template <typename GR>
    4958    class Path {
     
    6069      Path() {}
    6170
    62       /// \brief Template constructor
     71      /// \brief Template copy constructor
    6372      template <typename CPath>
    6473      Path(const CPath& cpath) {}
    6574
    66       /// \brief Template assigment
     75      /// \brief Template assigment operator
    6776      template <typename CPath>
    6877      Path& operator=(const CPath& cpath) {
     
    7180      }
    7281
    73       /// Length of the path ie. the number of arcs in the path.
     82      /// Length of the path, i.e. the number of arcs on the path.
    7483      int length() const { return 0;}
    7584
     
    8089      void clear() {}
    8190
    82       /// \brief LEMON style iterator for path arcs
     91      /// \brief LEMON style iterator for enumerating the arcs of a path.
    8392      ///
    84       /// This class is used to iterate on the arcs of the paths.
     93      /// LEMON style iterator class for enumerating the arcs of a path.
    8594      class ArcIt {
    8695      public:
     
    8998        /// Invalid constructor
    9099        ArcIt(Invalid) {}
    91         /// Constructor for first arc
     100        /// Sets the iterator to the first arc of the given path
    92101        ArcIt(const Path &) {}
    93102
    94         /// Conversion to Arc
     103        /// Conversion to \c Arc
    95104        operator Arc() const { return INVALID; }
    96105
     
    193202    ///
    194203    /// A skeleton structure for path dumpers. The path dumpers are
    195     /// the generalization of the paths. The path dumpers can
    196     /// enumerate the arcs of the path wheter in forward or in
    197     /// backward order.  In most time these classes are not used
    198     /// directly rather it used to assign a dumped class to a real
    199     /// path type.
     204    /// the generalization of the paths, they can enumerate the arcs
     205    /// of the path either in forward or in backward order.
     206    /// These classes are typically not used directly, they are rather
     207    /// used to be assigned to a real path type.
    200208    ///
    201209    /// The main purpose of this concept is that the shortest path
    202     /// algorithms can enumerate easily the arcs in reverse order.
    203     /// If we would like to give back a real path from these
    204     /// algorithms then we should create a temporarly path object. In
    205     /// LEMON such algorithms gives back a path dumper what can
    206     /// assigned to a real path and the dumpers can be implemented as
     210    /// algorithms can enumerate the arcs easily in reverse order.
     211    /// In LEMON, such algorithms give back a (reverse) path dumper that
     212    /// can be assigned to a real path. The dumpers can be implemented as
    207213    /// an adaptor class to the predecessor map.
    208214    ///
    209215    /// \tparam GR The digraph type in which the path is.
    210     ///
    211     /// The paths can be constructed from any path type by a
    212     /// template constructor or a template assignment operator.
    213216    template <typename GR>
    214217    class PathDumper {
     
    220223      typedef typename Digraph::Arc Arc;
    221224
    222       /// Length of the path ie. the number of arcs in the path.
     225      /// Length of the path, i.e. the number of arcs on the path.
    223226      int length() const { return 0;}
    224227
     
    228231      /// \brief Forward or reverse dumping
    229232      ///
    230       /// If the RevPathTag is defined and true then reverse dumping
    231       /// is provided in the path dumper. In this case instead of the
    232       /// ArcIt the RevArcIt iterator should be implemented in the
    233       /// dumper.
     233      /// If this tag is defined to be \c True, then reverse dumping
     234      /// is provided in the path dumper. In this case, \c RevArcIt
     235      /// iterator should be implemented instead of \c ArcIt iterator.
    234236      typedef False RevPathTag;
    235237
    236       /// \brief LEMON style iterator for path arcs
     238      /// \brief LEMON style iterator for enumerating the arcs of a path.
    237239      ///
    238       /// This class is used to iterate on the arcs of the paths.
     240      /// LEMON style iterator class for enumerating the arcs of a path.
    239241      class ArcIt {
    240242      public:
     
    243245        /// Invalid constructor
    244246        ArcIt(Invalid) {}
    245         /// Constructor for first arc
     247        /// Sets the iterator to the first arc of the given path
    246248        ArcIt(const PathDumper&) {}
    247249
    248         /// Conversion to Arc
     250        /// Conversion to \c Arc
    249251        operator Arc() const { return INVALID; }
    250252
     
    261263      };
    262264
    263       /// \brief LEMON style iterator for path arcs
     265      /// \brief LEMON style iterator for enumerating the arcs of a path
     266      /// in reverse direction.
    264267      ///
    265       /// This class is used to iterate on the arcs of the paths in
    266       /// reverse direction.
     268      /// LEMON style iterator class for enumerating the arcs of a path
     269      /// in reverse direction.
    267270      class RevArcIt {
    268271      public:
     
    271274        /// Invalid constructor
    272275        RevArcIt(Invalid) {}
    273         /// Constructor for first arc
     276        /// Sets the iterator to the last arc of the given path
    274277        RevArcIt(const PathDumper &) {}
    275278
    276         /// Conversion to Arc
     279        /// Conversion to \c Arc
    277280        operator Arc() const { return INVALID; }
    278281
  • TabularUnified lemon/connectivity.h

    r695 r956  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    259259  /// \return \c true if the digraph is strongly connected.
    260260  /// \note By definition, the empty digraph is strongly connected.
    261   /// 
     261  ///
    262262  /// \see countStronglyConnectedComponents(), stronglyConnectedComponents()
    263263  /// \see connected()
     
    311311  /// \ingroup graph_properties
    312312  ///
    313   /// \brief Count the number of strongly connected components of a 
     313  /// \brief Count the number of strongly connected components of a
    314314  /// directed graph
    315315  ///
     
    745745  /// \brief Check whether an undirected graph is bi-node-connected.
    746746  ///
    747   /// This function checks whether the given undirected graph is 
     747  /// This function checks whether the given undirected graph is
    748748  /// bi-node-connected, i.e. any two edges are on same circle.
    749749  ///
     
    759759  /// \ingroup graph_properties
    760760  ///
    761   /// \brief Count the number of bi-node-connected components of an 
     761  /// \brief Count the number of bi-node-connected components of an
    762762  /// undirected graph.
    763763  ///
     
    813813  /// \retval compMap A writable edge map. The values will be set from 0
    814814  /// to the number of the bi-node-connected components minus one. Each
    815   /// value of the map will be set exactly once, and the values of a 
     815  /// value of the map will be set exactly once, and the values of a
    816816  /// certain component will be set continuously.
    817817  /// \return The number of bi-node-connected components.
     
    859859  ///
    860860  /// \param graph The undirected graph.
    861   /// \retval cutMap A writable node map. The values will be set to 
     861  /// \retval cutMap A writable node map. The values will be set to
    862862  /// \c true for the nodes that separate two or more components
    863863  /// (exactly once for each cut node), and will not be changed for
     
    10861086  /// \brief Check whether an undirected graph is bi-edge-connected.
    10871087  ///
    1088   /// This function checks whether the given undirected graph is 
     1088  /// This function checks whether the given undirected graph is
    10891089  /// bi-edge-connected, i.e. any two nodes are connected with at least
    10901090  /// two edge-disjoint paths.
     
    11931193  ///
    11941194  /// This function finds the bi-edge-connected cut edges in the given
    1195   /// undirected graph. 
     1195  /// undirected graph.
    11961196  ///
    11971197  /// The bi-edge-connected components are the classes of an equivalence
     
    13501350  /// \param digraph The digraph.
    13511351  /// \retval order A readable and writable node map. The values will be
    1352   /// set from 0 to the number of the nodes in the digraph minus one. 
     1352  /// set from 0 to the number of the nodes in the digraph minus one.
    13531353  /// Each value of the map will be set exactly once, and the values will
    13541354  /// be set descending order.
  • TabularUnified lemon/core.h

    r984 r1110  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    12421242  protected:
    12431243
    1244     class AutoNodeMap : public ItemSetTraits<GR, Node>::template Map<Arc>::Type {
     1244    class AutoNodeMap : public ItemSetTraits<GR, Node>::template Map<Arc>::Type
     1245    {
    12451246      typedef typename ItemSetTraits<GR, Node>::template Map<Arc>::Type Parent;
    12461247
     
    12811282    };
    12821283
    1283   protected: 
     1284  protected:
    12841285
    12851286    const Digraph &_g;
  • TabularUnified lemon/counter.h

    r463 r833  
    213213  /// 'Do nothing' version of Counter.
    214214
    215   /// This class can be used in the same way as \ref Counter however it
     215  /// This class can be used in the same way as \ref Counter, but it
    216216  /// does not count at all and does not print report on destruction.
    217217  ///
  • TabularUnified lemon/cplex.cc

    r623 r956  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    112112  }
    113113
     114  int CplexBase::_addRow(Value lb, ExprIterator b,
     115                         ExprIterator e, Value ub) {
     116    int i = CPXgetnumrows(cplexEnv(), _prob);
     117    if (lb == -INF) {
     118      const char s = 'L';
     119      CPXnewrows(cplexEnv(), _prob, 1, &ub, &s, 0, 0);
     120    } else if (ub == INF) {
     121      const char s = 'G';
     122      CPXnewrows(cplexEnv(), _prob, 1, &lb, &s, 0, 0);
     123    } else if (lb == ub){
     124      const char s = 'E';
     125      CPXnewrows(cplexEnv(), _prob, 1, &lb, &s, 0, 0);
     126    } else {
     127      const char s = 'R';
     128      double len = ub - lb;
     129      CPXnewrows(cplexEnv(), _prob, 1, &lb, &s, &len, 0);
     130    }
     131
     132    std::vector<int> indices;
     133    std::vector<int> rowlist;
     134    std::vector<Value> values;
     135
     136    for(ExprIterator it=b; it!=e; ++it) {
     137      indices.push_back(it->first);
     138      values.push_back(it->second);
     139      rowlist.push_back(i);
     140    }
     141
     142    CPXchgcoeflist(cplexEnv(), _prob, values.size(),
     143                   &rowlist.front(), &indices.front(), &values.front());
     144
     145    return i;
     146  }
    114147
    115148  void CplexBase::_eraseCol(int i) {
     
    457490
    458491  void CplexBase::_applyMessageLevel() {
    459     CPXsetintparam(cplexEnv(), CPX_PARAM_SCRIND, 
     492    CPXsetintparam(cplexEnv(), CPX_PARAM_SCRIND,
    460493                   _message_enabled ? CPX_ON : CPX_OFF);
    461494  }
  • TabularUnified lemon/cplex.h

    r623 r793  
    9494    virtual int _addCol();
    9595    virtual int _addRow();
     96    virtual int _addRow(Value l, ExprIterator b, ExprIterator e, Value u);
    9697
    9798    virtual void _eraseCol(int i);
  • TabularUnified lemon/dfs.h

    r1009 r1110  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    4848    ///The type of the map that stores the predecessor
    4949    ///arcs of the %DFS paths.
    50     ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
     50    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
    5151    typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap;
    5252    ///Instantiates a \c PredMap.
     
    6363
    6464    ///The type of the map that indicates which nodes are processed.
    65     ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
     65    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
     66    ///By default, it is a NullMap.
    6667    typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
    6768    ///Instantiates a \c ProcessedMap.
     
    8283
    8384    ///The type of the map that indicates which nodes are reached.
    84     ///It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
     85    ///It must conform to
     86    ///the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
    8587    typedef typename Digraph::template NodeMap<bool> ReachedMap;
    8688    ///Instantiates a \c ReachedMap.
     
    9799
    98100    ///The type of the map that stores the distances of the nodes.
    99     ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
     101    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
    100102    typedef typename Digraph::template NodeMap<int> DistMap;
    101103    ///Instantiates a \c DistMap.
     
    121123  ///\tparam GR The type of the digraph the algorithm runs on.
    122124  ///The default type is \ref ListDigraph.
     125  ///\tparam TR The traits class that defines various types used by the
     126  ///algorithm. By default, it is \ref DfsDefaultTraits
     127  ///"DfsDefaultTraits<GR>".
     128  ///In most cases, this parameter should not be set directly,
     129  ///consider to use the named template parameters instead.
    123130#ifdef DOXYGEN
    124131  template <typename GR,
     
    225232    ///\ref named-templ-param "Named parameter" for setting
    226233    ///\c PredMap type.
    227     ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
     234    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
    228235    template <class T>
    229236    struct SetPredMap : public Dfs<Digraph, SetPredMapTraits<T> > {
     
    245252    ///\ref named-templ-param "Named parameter" for setting
    246253    ///\c DistMap type.
    247     ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
     254    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
    248255    template <class T>
    249256    struct SetDistMap : public Dfs< Digraph, SetDistMapTraits<T> > {
     
    265272    ///\ref named-templ-param "Named parameter" for setting
    266273    ///\c ReachedMap type.
    267     ///It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
     274    ///It must conform to
     275    ///the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
    268276    template <class T>
    269277    struct SetReachedMap : public Dfs< Digraph, SetReachedMapTraits<T> > {
     
    285293    ///\ref named-templ-param "Named parameter" for setting
    286294    ///\c ProcessedMap type.
    287     ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
     295    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
    288296    template <class T>
    289297    struct SetProcessedMap : public Dfs< Digraph, SetProcessedMapTraits<T> > {
     
    412420    ///The simplest way to execute the DFS algorithm is to use one of the
    413421    ///member functions called \ref run(Node) "run()".\n
    414     ///If you need more control on the execution, first you have to call
    415     ///\ref init(), then you can add a source node with \ref addSource()
     422    ///If you need better control on the execution, you have to call
     423    ///\ref init() first, then you can add a source node with \ref addSource()
    416424    ///and perform the actual computation with \ref start().
    417425    ///This procedure can be repeated if there are nodes that have not
     
    633641    ///Runs the algorithm to visit all nodes in the digraph.
    634642
    635     ///This method runs the %DFS algorithm in order to compute the
    636     ///%DFS path to each node.
    637     ///
    638     ///The algorithm computes
    639     ///- the %DFS tree (forest),
    640     ///- the distance of each node from the root(s) in the %DFS tree.
     643    ///This method runs the %DFS algorithm in order to visit all nodes
     644    ///in the digraph.
    641645    ///
    642646    ///\note <tt>d.run()</tt> is just a shortcut of the following code.
     
    670674    ///@{
    671675
    672     ///The DFS path to a node.
    673 
    674     ///Returns the DFS path to a node.
     676    ///The DFS path to the given node.
     677
     678    ///Returns the DFS path to the given node from the root(s).
    675679    ///
    676680    ///\warning \c t should be reached from the root(s).
     
    680684    Path path(Node t) const { return Path(*G, *_pred, t); }
    681685
    682     ///The distance of a node from the root(s).
    683 
    684     ///Returns the distance of a node from the root(s).
     686    ///The distance of the given node from the root(s).
     687
     688    ///Returns the distance of the given node from the root(s).
    685689    ///
    686690    ///\warning If node \c v is not reached from the root(s), then
     
    691695    int dist(Node v) const { return (*_dist)[v]; }
    692696
    693     ///Returns the 'previous arc' of the %DFS tree for a node.
     697    ///Returns the 'previous arc' of the %DFS tree for the given node.
    694698
    695699    ///This function returns the 'previous arc' of the %DFS tree for the
     
    699703    ///
    700704    ///The %DFS tree used here is equal to the %DFS tree used in
    701     ///\ref predNode().
     705    ///\ref predNode() and \ref predMap().
    702706    ///
    703707    ///\pre Either \ref run(Node) "run()" or \ref init()
     
    705709    Arc predArc(Node v) const { return (*_pred)[v];}
    706710
    707     ///Returns the 'previous node' of the %DFS tree.
     711    ///Returns the 'previous node' of the %DFS tree for the given node.
    708712
    709713    ///This function returns the 'previous node' of the %DFS
    710714    ///tree for the node \c v, i.e. it returns the last but one node
    711     ///from a %DFS path from a root to \c v. It is \c INVALID
     715    ///of a %DFS path from a root to \c v. It is \c INVALID
    712716    ///if \c v is not reached from the root(s) or if \c v is a root.
    713717    ///
    714718    ///The %DFS tree used here is equal to the %DFS tree used in
    715     ///\ref predArc().
     719    ///\ref predArc() and \ref predMap().
    716720    ///
    717721    ///\pre Either \ref run(Node) "run()" or \ref init()
     
    734738    ///
    735739    ///Returns a const reference to the node map that stores the predecessor
    736     ///arcs, which form the DFS tree.
     740    ///arcs, which form the DFS tree (forest).
    737741    ///
    738742    ///\pre Either \ref run(Node) "run()" or \ref init()
     
    740744    const PredMap &predMap() const { return *_pred;}
    741745
    742     ///Checks if a node is reached from the root(s).
     746    ///Checks if the given node. node is reached from the root(s).
    743747
    744748    ///Returns \c true if \c v is reached from the root(s).
     
    766770    ///The type of the map that stores the predecessor
    767771    ///arcs of the %DFS paths.
    768     ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
     772    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
    769773    typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap;
    770774    ///Instantiates a PredMap.
     
    781785
    782786    ///The type of the map that indicates which nodes are processed.
    783     ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
    784     ///By default it is a NullMap.
     787    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
     788    ///By default, it is a NullMap.
    785789    typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
    786790    ///Instantiates a ProcessedMap.
     
    801805
    802806    ///The type of the map that indicates which nodes are reached.
    803     ///It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
     807    ///It must conform to
     808    ///the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
    804809    typedef typename Digraph::template NodeMap<bool> ReachedMap;
    805810    ///Instantiates a ReachedMap.
     
    816821
    817822    ///The type of the map that stores the distances of the nodes.
    818     ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
     823    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
    819824    typedef typename Digraph::template NodeMap<int> DistMap;
    820825    ///Instantiates a DistMap.
     
    831836
    832837    ///The type of the DFS paths.
    833     ///It must meet the \ref concepts::Path "Path" concept.
     838    ///It must conform to the \ref concepts::Path "Path" concept.
    834839    typedef lemon::Path<Digraph> Path;
    835840  };
     
    837842  /// Default traits class used by DfsWizard
    838843
    839   /// To make it easier to use Dfs algorithm
    840   /// we have created a wizard class.
    841   /// This \ref DfsWizard class needs default traits,
    842   /// as well as the \ref Dfs class.
    843   /// The \ref DfsWizardBase is a class to be the default traits of the
    844   /// \ref DfsWizard class.
     844  /// Default traits class used by DfsWizard.
     845  /// \tparam GR The type of the digraph.
    845846  template<class GR>
    846847  class DfsWizardBase : public DfsWizardDefaultTraits<GR>
     
    870871    /// Constructor.
    871872
    872     /// This constructor does not require parameters, therefore it initiates
     873    /// This constructor does not require parameters, it initiates
    873874    /// all of the attributes to \c 0.
    874875    DfsWizardBase() : _g(0), _reached(0), _processed(0), _pred(0),
     
    895896  /// This class should only be used through the \ref dfs() function,
    896897  /// which makes it easier to use the algorithm.
     898  ///
     899  /// \tparam TR The traits class that defines various types used by the
     900  /// algorithm.
    897901  template<class TR>
    898902  class DfsWizard : public TR
     
    900904    typedef TR Base;
    901905
    902     ///The type of the digraph the algorithm runs on.
    903906    typedef typename TR::Digraph Digraph;
    904907
     
    908911    typedef typename Digraph::OutArcIt OutArcIt;
    909912
    910     ///\brief The type of the map that stores the predecessor
    911     ///arcs of the DFS paths.
    912913    typedef typename TR::PredMap PredMap;
    913     ///\brief The type of the map that stores the distances of the nodes.
    914914    typedef typename TR::DistMap DistMap;
    915     ///\brief The type of the map that indicates which nodes are reached.
    916915    typedef typename TR::ReachedMap ReachedMap;
    917     ///\brief The type of the map that indicates which nodes are processed.
    918916    typedef typename TR::ProcessedMap ProcessedMap;
    919     ///The type of the DFS paths
    920917    typedef typename TR::Path Path;
    921918
     
    987984    ///Runs DFS algorithm to visit all nodes in the digraph.
    988985
    989     ///This method runs DFS algorithm in order to compute
    990     ///the DFS path to each node.
     986    ///This method runs DFS algorithm in order to visit all nodes
     987    ///in the digraph.
    991988    void run()
    992989    {
     
    1000997      SetPredMapBase(const TR &b) : TR(b) {}
    1001998    };
    1002     ///\brief \ref named-func-param "Named parameter"
    1003     ///for setting PredMap object.
    1004     ///
    1005     ///\ref named-func-param "Named parameter"
    1006     ///for setting PredMap object.
     999
     1000    ///\brief \ref named-templ-param "Named parameter" for setting
     1001    ///the predecessor map.
     1002    ///
     1003    ///\ref named-templ-param "Named parameter" function for setting
     1004    ///the map that stores the predecessor arcs of the nodes.
    10071005    template<class T>
    10081006    DfsWizard<SetPredMapBase<T> > predMap(const T &t)
     
    10181016      SetReachedMapBase(const TR &b) : TR(b) {}
    10191017    };
    1020     ///\brief \ref named-func-param "Named parameter"
    1021     ///for setting ReachedMap object.
    1022     ///
    1023     /// \ref named-func-param "Named parameter"
    1024     ///for setting ReachedMap object.
     1018
     1019    ///\brief \ref named-templ-param "Named parameter" for setting
     1020    ///the reached map.
     1021    ///
     1022    ///\ref named-templ-param "Named parameter" function for setting
     1023    ///the map that indicates which nodes are reached.
    10251024    template<class T>
    10261025    DfsWizard<SetReachedMapBase<T> > reachedMap(const T &t)
     
    10361035      SetDistMapBase(const TR &b) : TR(b) {}
    10371036    };
    1038     ///\brief \ref named-func-param "Named parameter"
    1039     ///for setting DistMap object.
    1040     ///
    1041     /// \ref named-func-param "Named parameter"
    1042     ///for setting DistMap object.
     1037
     1038    ///\brief \ref named-templ-param "Named parameter" for setting
     1039    ///the distance map.
     1040    ///
     1041    ///\ref named-templ-param "Named parameter" function for setting
     1042    ///the map that stores the distances of the nodes calculated
     1043    ///by the algorithm.
    10431044    template<class T>
    10441045    DfsWizard<SetDistMapBase<T> > distMap(const T &t)
     
    10541055      SetProcessedMapBase(const TR &b) : TR(b) {}
    10551056    };
    1056     ///\brief \ref named-func-param "Named parameter"
    1057     ///for setting ProcessedMap object.
    1058     ///
    1059     /// \ref named-func-param "Named parameter"
    1060     ///for setting ProcessedMap object.
     1057
     1058    ///\brief \ref named-func-param "Named parameter" for setting
     1059    ///the processed map.
     1060    ///
     1061    ///\ref named-templ-param "Named parameter" function for setting
     1062    ///the map that indicates which nodes are processed.
    10611063    template<class T>
    10621064    DfsWizard<SetProcessedMapBase<T> > processedMap(const T &t)
     
    12091211    ///
    12101212    /// The type of the map that indicates which nodes are reached.
    1211     /// It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
     1213    /// It must conform to the
     1214    /// \ref concepts::ReadWriteMap "ReadWriteMap" concept.
    12121215    typedef typename Digraph::template NodeMap<bool> ReachedMap;
    12131216
     
    12471250  /// does not observe the DFS events. If you want to observe the DFS
    12481251  /// events, you should implement your own visitor class.
    1249   /// \tparam TR Traits class to set various data types used by the
    1250   /// algorithm. The default traits class is
    1251   /// \ref DfsVisitDefaultTraits "DfsVisitDefaultTraits<GR>".
    1252   /// See \ref DfsVisitDefaultTraits for the documentation of
    1253   /// a DFS visit traits class.
     1252  /// \tparam TR The traits class that defines various types used by the
     1253  /// algorithm. By default, it is \ref DfsVisitDefaultTraits
     1254  /// "DfsVisitDefaultTraits<GR>".
     1255  /// In most cases, this parameter should not be set directly,
     1256  /// consider to use the named template parameters instead.
    12541257#ifdef DOXYGEN
    12551258  template <typename GR, typename VS, typename TR>
     
    13701373    /// The simplest way to execute the DFS algorithm is to use one of the
    13711374    /// member functions called \ref run(Node) "run()".\n
    1372     /// If you need more control on the execution, first you have to call
    1373     /// \ref init(), then you can add a source node with \ref addSource()
     1375    /// If you need better control on the execution, you have to call
     1376    /// \ref init() first, then you can add a source node with \ref addSource()
    13741377    /// and perform the actual computation with \ref start().
    13751378    /// This procedure can be repeated if there are nodes that have not
     
    15841587    /// \brief Runs the algorithm to visit all nodes in the digraph.
    15851588
    1586     /// This method runs the %DFS algorithm in order to
    1587     /// compute the %DFS path to each node.
    1588     ///
    1589     /// The algorithm computes
    1590     /// - the %DFS tree (forest),
    1591     /// - the distance of each node from the root(s) in the %DFS tree.
     1589    /// This method runs the %DFS algorithm in order to visit all nodes
     1590    /// in the digraph.
    15921591    ///
    15931592    /// \note <tt>d.run()</tt> is just a shortcut of the following code.
     
    16211620    ///@{
    16221621
    1623     /// \brief Checks if a node is reached from the root(s).
     1622    /// \brief Checks if the given node is reached from the root(s).
    16241623    ///
    16251624    /// Returns \c true if \c v is reached from the root(s).
  • TabularUnified lemon/dijkstra.h

    r631 r956  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    7171
    7272    ///The type of the map that stores the arc lengths.
    73     ///It must meet the \ref concepts::ReadMap "ReadMap" concept.
     73    ///It must conform to the \ref concepts::ReadMap "ReadMap" concept.
    7474    typedef LEN LengthMap;
    75     ///The type of the length of the arcs.
     75    ///The type of the arc lengths.
    7676    typedef typename LEN::Value Value;
    7777
     
    117117    ///The type of the map that stores the predecessor
    118118    ///arcs of the shortest paths.
    119     ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
     119    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
    120120    typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap;
    121121    ///Instantiates a \c PredMap.
     
    132132
    133133    ///The type of the map that indicates which nodes are processed.
    134     ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
    135     ///By default it is a NullMap.
     134    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
     135    ///By default, it is a NullMap.
    136136    typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
    137137    ///Instantiates a \c ProcessedMap.
     
    152152
    153153    ///The type of the map that stores the distances of the nodes.
    154     ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
     154    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
    155155    typedef typename Digraph::template NodeMap<typename LEN::Value> DistMap;
    156156    ///Instantiates a \c DistMap.
     
    169169  /// \ingroup shortest_path
    170170  ///This class provides an efficient implementation of the %Dijkstra algorithm.
     171  ///
     172  ///The %Dijkstra algorithm solves the single-source shortest path problem
     173  ///when all arc lengths are non-negative. If there are negative lengths,
     174  ///the BellmanFord algorithm should be used instead.
    171175  ///
    172176  ///The arc lengths are passed to the algorithm using a
     
    189193  ///it is necessary. The default map type is \ref
    190194  ///concepts::Digraph::ArcMap "GR::ArcMap<int>".
     195  ///\tparam TR The traits class that defines various types used by the
     196  ///algorithm. By default, it is \ref DijkstraDefaultTraits
     197  ///"DijkstraDefaultTraits<GR, LEN>".
     198  ///In most cases, this parameter should not be set directly,
     199  ///consider to use the named template parameters instead.
    191200#ifdef DOXYGEN
    192201  template <typename GR, typename LEN, typename TR>
     
    202211    typedef typename TR::Digraph Digraph;
    203212
    204     ///The type of the length of the arcs.
    205     typedef typename TR::LengthMap::Value Value;
     213    ///The type of the arc lengths.
     214    typedef typename TR::Value Value;
    206215    ///The type of the map that stores the arc lengths.
    207216    typedef typename TR::LengthMap LengthMap;
     
    305314    ///\ref named-templ-param "Named parameter" for setting
    306315    ///\c PredMap type.
    307     ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
     316    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
    308317    template <class T>
    309318    struct SetPredMap
     
    326335    ///\ref named-templ-param "Named parameter" for setting
    327336    ///\c DistMap type.
    328     ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
     337    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
    329338    template <class T>
    330339    struct SetDistMap
     
    347356    ///\ref named-templ-param "Named parameter" for setting
    348357    ///\c ProcessedMap type.
    349     ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
     358    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
    350359    template <class T>
    351360    struct SetProcessedMap
     
    423432    ///passed to the constructor of the cross reference and the cross
    424433    ///reference should be passed to the constructor of the heap).
    425     ///However external heap and cross reference objects could also be
     434    ///However, external heap and cross reference objects could also be
    426435    ///passed to the algorithm using the \ref heap() function before
    427436    ///calling \ref run(Node) "run()" or \ref init().
     
    444453    ///\ref named-templ-param "Named parameter" for setting
    445454    ///\c OperationTraits type.
     455    /// For more information, see \ref DijkstraDefaultOperationTraits.
    446456    template <class T>
    447457    struct SetOperationTraits
     
    585595    ///The simplest way to execute the %Dijkstra algorithm is to use
    586596    ///one of the member functions called \ref run(Node) "run()".\n
    587     ///If you need more control on the execution, first you have to call
    588     ///\ref init(), then you can add several source nodes with
     597    ///If you need better control on the execution, you have to call
     598    ///\ref init() first, then you can add several source nodes with
    589599    ///\ref addSource(). Finally the actual path computation can be
    590600    ///performed with one of the \ref start() functions.
     
    802812    ///The results of the %Dijkstra algorithm can be obtained using these
    803813    ///functions.\n
    804     ///Either \ref run(Node) "run()" or \ref start() should be called
     814    ///Either \ref run(Node) "run()" or \ref init() should be called
    805815    ///before using them.
    806816
    807817    ///@{
    808818
    809     ///The shortest path to a node.
    810 
    811     ///Returns the shortest path to a node.
     819    ///The shortest path to the given node.
     820
     821    ///Returns the shortest path to the given node from the root(s).
    812822    ///
    813823    ///\warning \c t should be reached from the root(s).
     
    817827    Path path(Node t) const { return Path(*G, *_pred, t); }
    818828
    819     ///The distance of a node from the root(s).
    820 
    821     ///Returns the distance of a node from the root(s).
     829    ///The distance of the given node from the root(s).
     830
     831    ///Returns the distance of the given node from the root(s).
    822832    ///
    823833    ///\warning If node \c v is not reached from the root(s), then
     
    828838    Value dist(Node v) const { return (*_dist)[v]; }
    829839
    830     ///Returns the 'previous arc' of the shortest path tree for a node.
    831 
     840    ///\brief Returns the 'previous arc' of the shortest path tree for
     841    ///the given node.
     842    ///
    832843    ///This function returns the 'previous arc' of the shortest path
    833844    ///tree for the node \c v, i.e. it returns the last arc of a
     
    836847    ///
    837848    ///The shortest path tree used here is equal to the shortest path
    838     ///tree used in \ref predNode().
     849    ///tree used in \ref predNode() and \ref predMap().
    839850    ///
    840851    ///\pre Either \ref run(Node) "run()" or \ref init()
     
    842853    Arc predArc(Node v) const { return (*_pred)[v]; }
    843854
    844     ///Returns the 'previous node' of the shortest path tree for a node.
    845 
     855    ///\brief Returns the 'previous node' of the shortest path tree for
     856    ///the given node.
     857    ///
    846858    ///This function returns the 'previous node' of the shortest path
    847859    ///tree for the node \c v, i.e. it returns the last but one node
    848     ///from a shortest path from a root to \c v. It is \c INVALID
     860    ///of a shortest path from a root to \c v. It is \c INVALID
    849861    ///if \c v is not reached from the root(s) or if \c v is a root.
    850862    ///
    851863    ///The shortest path tree used here is equal to the shortest path
    852     ///tree used in \ref predArc().
     864    ///tree used in \ref predArc() and \ref predMap().
    853865    ///
    854866    ///\pre Either \ref run(Node) "run()" or \ref init()
     
    871883    ///
    872884    ///Returns a const reference to the node map that stores the predecessor
    873     ///arcs, which form the shortest path tree.
     885    ///arcs, which form the shortest path tree (forest).
    874886    ///
    875887    ///\pre Either \ref run(Node) "run()" or \ref init()
     
    877889    const PredMap &predMap() const { return *_pred;}
    878890
    879     ///Checks if a node is reached from the root(s).
     891    ///Checks if the given node is reached from the root(s).
    880892
    881893    ///Returns \c true if \c v is reached from the root(s).
     
    896908                                          Heap::POST_HEAP; }
    897909
    898     ///The current distance of a node from the root(s).
    899 
    900     ///Returns the current distance of a node from the root(s).
     910    ///The current distance of the given node from the root(s).
     911
     912    ///Returns the current distance of the given node from the root(s).
    901913    ///It may be decreased in the following processes.
    902914    ///
     
    925937
    926938    ///The type of the map that stores the arc lengths.
    927     ///It must meet the \ref concepts::ReadMap "ReadMap" concept.
     939    ///It must conform to the \ref concepts::ReadMap "ReadMap" concept.
    928940    typedef LEN LengthMap;
    929     ///The type of the length of the arcs.
     941    ///The type of the arc lengths.
    930942    typedef typename LEN::Value Value;
    931943
     
    974986    ///The type of the map that stores the predecessor
    975987    ///arcs of the shortest paths.
    976     ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
     988    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
    977989    typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap;
    978990    ///Instantiates a PredMap.
     
    9891001
    9901002    ///The type of the map that indicates which nodes are processed.
    991     ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
    992     ///By default it is a NullMap.
     1003    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
     1004    ///By default, it is a NullMap.
    9931005    typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
    9941006    ///Instantiates a ProcessedMap.
     
    10091021
    10101022    ///The type of the map that stores the distances of the nodes.
    1011     ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
     1023    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
    10121024    typedef typename Digraph::template NodeMap<typename LEN::Value> DistMap;
    10131025    ///Instantiates a DistMap.
     
    10241036
    10251037    ///The type of the shortest paths.
    1026     ///It must meet the \ref concepts::Path "Path" concept.
     1038    ///It must conform to the \ref concepts::Path "Path" concept.
    10271039    typedef lemon::Path<Digraph> Path;
    10281040  };
     
    10301042  /// Default traits class used by DijkstraWizard
    10311043
    1032   /// To make it easier to use Dijkstra algorithm
    1033   /// we have created a wizard class.
    1034   /// This \ref DijkstraWizard class needs default traits,
    1035   /// as well as the \ref Dijkstra class.
    1036   /// The \ref DijkstraWizardBase is a class to be the default traits of the
    1037   /// \ref DijkstraWizard class.
     1044  /// Default traits class used by DijkstraWizard.
     1045  /// \tparam GR The type of the digraph.
     1046  /// \tparam LEN The type of the length map.
    10381047  template<typename GR, typename LEN>
    10391048  class DijkstraWizardBase : public DijkstraWizardDefaultTraits<GR,LEN>
     
    10891098  /// This class should only be used through the \ref dijkstra() function,
    10901099  /// which makes it easier to use the algorithm.
     1100  ///
     1101  /// \tparam TR The traits class that defines various types used by the
     1102  /// algorithm.
    10911103  template<class TR>
    10921104  class DijkstraWizard : public TR
     
    10941106    typedef TR Base;
    10951107
    1096     ///The type of the digraph the algorithm runs on.
    10971108    typedef typename TR::Digraph Digraph;
    10981109
     
    11021113    typedef typename Digraph::OutArcIt OutArcIt;
    11031114
    1104     ///The type of the map that stores the arc lengths.
    11051115    typedef typename TR::LengthMap LengthMap;
    1106     ///The type of the length of the arcs.
    11071116    typedef typename LengthMap::Value Value;
    1108     ///\brief The type of the map that stores the predecessor
    1109     ///arcs of the shortest paths.
    11101117    typedef typename TR::PredMap PredMap;
    1111     ///The type of the map that stores the distances of the nodes.
    11121118    typedef typename TR::DistMap DistMap;
    1113     ///The type of the map that indicates which nodes are processed.
    11141119    typedef typename TR::ProcessedMap ProcessedMap;
    1115     ///The type of the shortest paths
    11161120    typedef typename TR::Path Path;
    1117     ///The heap type used by the dijkstra algorithm.
    11181121    typedef typename TR::Heap Heap;
    11191122
     
    11871190      SetPredMapBase(const TR &b) : TR(b) {}
    11881191    };
    1189     ///\brief \ref named-func-param "Named parameter"
    1190     ///for setting PredMap object.
    1191     ///
    1192     ///\ref named-func-param "Named parameter"
    1193     ///for setting PredMap object.
     1192
     1193    ///\brief \ref named-templ-param "Named parameter" for setting
     1194    ///the predecessor map.
     1195    ///
     1196    ///\ref named-templ-param "Named parameter" function for setting
     1197    ///the map that stores the predecessor arcs of the nodes.
    11941198    template<class T>
    11951199    DijkstraWizard<SetPredMapBase<T> > predMap(const T &t)
     
    12051209      SetDistMapBase(const TR &b) : TR(b) {}
    12061210    };
    1207     ///\brief \ref named-func-param "Named parameter"
    1208     ///for setting DistMap object.
    1209     ///
    1210     ///\ref named-func-param "Named parameter"
    1211     ///for setting DistMap object.
     1211
     1212    ///\brief \ref named-templ-param "Named parameter" for setting
     1213    ///the distance map.
     1214    ///
     1215    ///\ref named-templ-param "Named parameter" function for setting
     1216    ///the map that stores the distances of the nodes calculated
     1217    ///by the algorithm.
    12121218    template<class T>
    12131219    DijkstraWizard<SetDistMapBase<T> > distMap(const T &t)
     
    12231229      SetProcessedMapBase(const TR &b) : TR(b) {}
    12241230    };
    1225     ///\brief \ref named-func-param "Named parameter"
    1226     ///for setting ProcessedMap object.
    1227     ///
    1228     /// \ref named-func-param "Named parameter"
    1229     ///for setting ProcessedMap object.
     1231
     1232    ///\brief \ref named-func-param "Named parameter" for setting
     1233    ///the processed map.
     1234    ///
     1235    ///\ref named-templ-param "Named parameter" function for setting
     1236    ///the map that indicates which nodes are processed.
    12301237    template<class T>
    12311238    DijkstraWizard<SetProcessedMapBase<T> > processedMap(const T &t)
     
    12401247      SetPathBase(const TR &b) : TR(b) {}
    12411248    };
     1249
    12421250    ///\brief \ref named-func-param "Named parameter"
    12431251    ///for getting the shortest path to the target node.
  • TabularUnified lemon/dim2.h

    r463 r761  
    2222#include <iostream>
    2323
    24 ///\ingroup misc
     24///\ingroup geomdat
    2525///\file
    2626///\brief A simple two dimensional vector and a bounding box implementation
    27 ///
    28 /// The class \ref lemon::dim2::Point "dim2::Point" implements
    29 /// a two dimensional vector with the usual operations.
    30 ///
    31 /// The class \ref lemon::dim2::Box "dim2::Box" can be used to determine
    32 /// the rectangular bounding box of a set of
    33 /// \ref lemon::dim2::Point "dim2::Point"'s.
    3427
    3528namespace lemon {
     
    4134  namespace dim2 {
    4235
    43   /// \addtogroup misc
     36  /// \addtogroup geomdat
    4437  /// @{
    4538
  • TabularUnified lemon/dimacs.h

    r631 r956  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    6262
    6363  ///This function starts seeking the beginning of the given file for the
    64   ///problem type and size info. 
     64  ///problem type and size info.
    6565  ///The found data is returned in a special struct that can be evaluated
    6666  ///and passed to the appropriate reader function.
     
    213213        std::numeric_limits<Capacity>::infinity() :
    214214        std::numeric_limits<Capacity>::max();
    215  
     215
    216216    while (is >> c) {
    217217      switch (c) {
     
    238238          e = g.addArc(nodes[i], nodes[j]);
    239239          capacity.set(e, _cap);
    240         } 
     240        }
    241241        else if (desc.type==DimacsDescriptor::MAX) {
    242242          is >> i >> j >> _cap;
     
    363363    g.addArc(s,t);
    364364  }
    365  
     365
    366366  /// \brief DIMACS plain (di)graph reader function.
    367367  ///
    368368  /// This function reads a plain (di)graph without any designated nodes
    369   /// and maps (e.g. a matching instance) from DIMACS format, i.e. from 
     369  /// and maps (e.g. a matching instance) from DIMACS format, i.e. from
    370370  /// DIMACS files having a line starting with
    371371  /// \code
     
    393393      nodes[k] = g.addNode();
    394394    }
    395    
     395
    396396    while (is >> c) {
    397397      switch (c) {
  • TabularUnified lemon/edge_set.h

    r717 r956  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2008
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    256256  /// all arcs incident to the given node is erased from the arc set.
    257257  ///
     258  /// This class fully conforms to the \ref concepts::Digraph
     259  /// "Digraph" concept.
     260  /// It provides only linear time counting for nodes and arcs.
     261  ///
    258262  /// \param GR The type of the graph which shares its node set with
    259263  /// this class. Its interface must conform to the
    260264  /// \ref concepts::Digraph "Digraph" or \ref concepts::Graph "Graph"
    261265  /// concept.
    262   ///
    263   /// This class fully conforms to the \ref concepts::Digraph
    264   /// "Digraph" concept.
    265266  template <typename GR>
    266267  class ListArcSet : public ArcSetExtender<ListArcSetBase<GR> > {
     
    686687  /// incident to the given node is erased from the arc set.
    687688  ///
     689  /// This class fully conforms to the \ref concepts::Graph "Graph"
     690  /// concept.
     691  /// It provides only linear time counting for nodes, edges and arcs.
     692  ///
    688693  /// \param GR The type of the graph which shares its node set
    689694  /// with this class. Its interface must conform to the
    690695  /// \ref concepts::Digraph "Digraph" or \ref concepts::Graph "Graph"
    691   /// concept.
    692   ///
    693   /// This class fully conforms to the \ref concepts::Graph "Graph"
    694696  /// concept.
    695697  template <typename GR>
     
    868870    }
    869871
    870     void next(Arc& arc) const {
     872    static void next(Arc& arc) {
    871873      --arc.id;
    872874    }
     
    955957  /// arcs. Therefore the arcs cannot be erased from the arc sets.
    956958  ///
     959  /// This class fully conforms to the \ref concepts::Digraph "Digraph"
     960  /// concept.
     961  /// It provides only linear time counting for nodes and arcs.
     962  ///
    957963  /// \warning If a node is erased from the underlying graph and this
    958964  /// node is the source or target of one arc in the arc set, then
    959965  /// the arc set is invalidated, and it cannot be used anymore. The
    960966  /// validity can be checked with the \c valid() member function.
    961   ///
    962   /// This class fully conforms to the \ref concepts::Digraph
    963   /// "Digraph" concept.
    964967  template <typename GR>
    965968  class SmartArcSet : public ArcSetExtender<SmartArcSetBase<GR> > {
     
    11741177    }
    11751178
    1176     void next(Arc& arc) const {
     1179    static void next(Arc& arc) {
    11771180      --arc.id;
    11781181    }
     
    11821185    }
    11831186
    1184     void next(Edge& arc) const {
     1187    static void next(Edge& arc) {
    11851188      --arc.id;
    11861189    }
     
    13051308  /// edges cannot be erased from the edge sets.
    13061309  ///
     1310  /// This class fully conforms to the \ref concepts::Graph "Graph"
     1311  /// concept.
     1312  /// It provides only linear time counting for nodes, edges and arcs.
     1313  ///
    13071314  /// \warning If a node is erased from the underlying graph and this
    13081315  /// node is incident to one edge in the edge set, then the edge set
    13091316  /// is invalidated, and it cannot be used anymore. The validity can
    13101317  /// be checked with the \c valid() member function.
    1311   ///
    1312   /// This class fully conforms to the \ref concepts::Graph
    1313   /// "Graph" concept.
    13141318  template <typename GR>
    13151319  class SmartEdgeSet : public EdgeSetExtender<SmartEdgeSetBase<GR> > {
  • TabularUnified lemon/euler.h

    r695 r956  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    2727/// \ingroup graph_properties
    2828/// \file
    29 /// \brief Euler tour iterators and a function for checking the \e Eulerian 
     29/// \brief Euler tour iterators and a function for checking the \e Eulerian
    3030/// property.
    3131///
     
    4242  ///
    4343  ///For example, if the given digraph has an Euler tour (i.e it has only one
    44   ///non-trivial component and the in-degree is equal to the out-degree 
     44  ///non-trivial component and the in-degree is equal to the out-degree
    4545  ///for all nodes), then the following code will put the arcs of \c g
    4646  ///to the vector \c et according to an Euler tour of \c g.
     
    139139  ///and \c Edge types of the graph.
    140140  ///
    141   ///For example, if the given graph has an Euler tour (i.e it has only one 
     141  ///For example, if the given graph has an Euler tour (i.e it has only one
    142142  ///non-trivial component and the degree of each node is even),
    143143  ///the following code will print the arc IDs according to an
     
    148148  ///  }
    149149  ///\endcode
    150   ///Although this iterator is for undirected graphs, it still returns 
     150  ///Although this iterator is for undirected graphs, it still returns
    151151  ///arcs in order to indicate the direction of the tour.
    152152  ///(But arcs convert to edges, of course.)
     
    234234    /// Postfix incrementation.
    235235    ///
    236     ///\warning This incrementation returns an \c Arc (which converts to 
     236    ///\warning This incrementation returns an \c Arc (which converts to
    237237    ///an \c Edge), not an \ref EulerIt, as one may expect.
    238238    Arc operator++(int)
  • TabularUnified lemon/fib_heap.h

    r730 r758  
    2121
    2222///\file
    23 ///\ingroup auxdat
    24 ///\brief Fibonacci Heap implementation.
     23///\ingroup heaps
     24///\brief Fibonacci heap implementation.
    2525
    2626#include <vector>
     27#include <utility>
    2728#include <functional>
    2829#include <lemon/math.h>
     
    3031namespace lemon {
    3132
    32   /// \ingroup auxdat
     33  /// \ingroup heaps
    3334  ///
    34   ///\brief Fibonacci Heap.
     35  /// \brief Fibonacci heap data structure.
    3536  ///
    36   ///This class implements the \e Fibonacci \e heap data structure. A \e heap
    37   ///is a data structure for storing items with specified values called \e
    38   ///priorities in such a way that finding the item with minimum priority is
    39   ///efficient. \c CMP specifies the ordering of the priorities. In a heap
    40   ///one can change the priority of an item, add or erase an item, etc.
     37  /// This class implements the \e Fibonacci \e heap data structure.
     38  /// It fully conforms to the \ref concepts::Heap "heap concept".
    4139  ///
    42   ///The methods \ref increase and \ref erase are not efficient in a Fibonacci
    43   ///heap. In case of many calls to these operations, it is better to use a
    44   ///\ref BinHeap "binary heap".
     40  /// The methods \ref increase() and \ref erase() are not efficient in a
     41  /// Fibonacci heap. In case of many calls of these operations, it is
     42  /// better to use other heap structure, e.g. \ref BinHeap "binary heap".
    4543  ///
    46   ///\param PRIO Type of the priority of the items.
    47   ///\param IM A read and writable Item int map, used internally
    48   ///to handle the cross references.
    49   ///\param CMP A class for the ordering of the priorities. The
    50   ///default is \c std::less<PRIO>.
    51   ///
    52   ///\sa BinHeap
    53   ///\sa Dijkstra
     44  /// \tparam PR Type of the priorities of the items.
     45  /// \tparam IM A read-writable item map with \c int values, used
     46  /// internally to handle the cross references.
     47  /// \tparam CMP A functor class for comparing the priorities.
     48  /// The default is \c std::less<PR>.
    5449#ifdef DOXYGEN
    55   template <typename PRIO, typename IM, typename CMP>
     50  template <typename PR, typename IM, typename CMP>
    5651#else
    57   template <typename PRIO, typename IM, typename CMP = std::less<PRIO> >
     52  template <typename PR, typename IM, typename CMP = std::less<PR> >
    5853#endif
    5954  class FibHeap {
    6055  public:
    61     ///\e
     56
     57    /// Type of the item-int map.
    6258    typedef IM ItemIntMap;
    63     ///\e
    64     typedef PRIO Prio;
    65     ///\e
     59    /// Type of the priorities.
     60    typedef PR Prio;
     61    /// Type of the items stored in the heap.
    6662    typedef typename ItemIntMap::Key Item;
    67     ///\e
     63    /// Type of the item-priority pairs.
    6864    typedef std::pair<Item,Prio> Pair;
    69     ///\e
     65    /// Functor type for comparing the priorities.
    7066    typedef CMP Compare;
    7167
     
    8177  public:
    8278
    83     /// \brief Type to represent the items states.
    84     ///
    85     /// Each Item element have a state associated to it. It may be "in heap",
    86     /// "pre heap" or "post heap". The latter two are indifferent from the
     79    /// \brief Type to represent the states of the items.
     80    ///
     81    /// Each item has a state associated to it. It can be "in heap",
     82    /// "pre-heap" or "post-heap". The latter two are indifferent from the
    8783    /// heap's point of view, but may be useful to the user.
    8884    ///
     
    9591    };
    9692
    97     /// \brief The constructor
    98     ///
    99     /// \c map should be given to the constructor, since it is
    100     ///   used internally to handle the cross references.
     93    /// \brief Constructor.
     94    ///
     95    /// Constructor.
     96    /// \param map A map that assigns \c int values to the items.
     97    /// It is used internally to handle the cross references.
     98    /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item.
    10199    explicit FibHeap(ItemIntMap &map)
    102100      : _minimum(0), _iim(map), _num() {}
    103101
    104     /// \brief The constructor
    105     ///
    106     /// \c map should be given to the constructor, since it is used
    107     /// internally to handle the cross references. \c comp is an
    108     /// object for ordering of the priorities.
     102    /// \brief Constructor.
     103    ///
     104    /// Constructor.
     105    /// \param map A map that assigns \c int values to the items.
     106    /// It is used internally to handle the cross references.
     107    /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item.
     108    /// \param comp The function object used for comparing the priorities.
    109109    FibHeap(ItemIntMap &map, const Compare &comp)
    110110      : _minimum(0), _iim(map), _comp(comp), _num() {}
     
    112112    /// \brief The number of items stored in the heap.
    113113    ///
    114     /// Returns the number of items stored in the heap.
     114    /// This function returns the number of items stored in the heap.
    115115    int size() const { return _num; }
    116116
    117     /// \brief Checks if the heap stores no items.
    118     ///
    119     ///   Returns \c true if and only if the heap stores no items.
     117    /// \brief Check if the heap is empty.
     118    ///
     119    /// This function returns \c true if the heap is empty.
    120120    bool empty() const { return _num==0; }
    121121
    122     /// \brief Make empty this heap.
    123     ///
    124     /// Make empty this heap. It does not change the cross reference
    125     /// map.  If you want to reuse a heap what is not surely empty you
    126     /// should first clear the heap and after that you should set the
    127     /// cross reference map for each item to \c PRE_HEAP.
     122    /// \brief Make the heap empty.
     123    ///
     124    /// This functon makes the heap empty.
     125    /// It does not change the cross reference map. If you want to reuse
     126    /// a heap that is not surely empty, you should first clear it and
     127    /// then you should set the cross reference map to \c PRE_HEAP
     128    /// for each item.
    128129    void clear() {
    129130      _data.clear(); _minimum = 0; _num = 0;
    130131    }
    131132
    132     /// \brief \c item gets to the heap with priority \c value independently
    133     /// if \c item was already there.
    134     ///
    135     /// This method calls \ref push(\c item, \c value) if \c item is not
    136     /// stored in the heap and it calls \ref decrease(\c item, \c value) or
    137     /// \ref increase(\c item, \c value) otherwise.
    138     void set (const Item& item, const Prio& value) {
    139       int i=_iim[item];
    140       if ( i >= 0 && _data[i].in ) {
    141         if ( _comp(value, _data[i].prio) ) decrease(item, value);
    142         if ( _comp(_data[i].prio, value) ) increase(item, value);
    143       } else push(item, value);
    144     }
    145 
    146     /// \brief Adds \c item to the heap with priority \c value.
    147     ///
    148     /// Adds \c item to the heap with priority \c value.
    149     /// \pre \c item must not be stored in the heap.
    150     void push (const Item& item, const Prio& value) {
     133    /// \brief Insert an item into the heap with the given priority.
     134    ///
     135    /// This function inserts the given item into the heap with the
     136    /// given priority.
     137    /// \param item The item to insert.
     138    /// \param prio The priority of the item.
     139    /// \pre \e item must not be stored in the heap.
     140    void push (const Item& item, const Prio& prio) {
    151141      int i=_iim[item];
    152142      if ( i < 0 ) {
     
    169159        _data[_minimum].right_neighbor=i;
    170160        _data[i].left_neighbor=_minimum;
    171         if ( _comp( value, _data[_minimum].prio) ) _minimum=i;
     161        if ( _comp( prio, _data[_minimum].prio) ) _minimum=i;
    172162      } else {
    173163        _data[i].right_neighbor=_data[i].left_neighbor=i;
    174164        _minimum=i;
    175165      }
    176       _data[i].prio=value;
     166      _data[i].prio=prio;
    177167      ++_num;
    178168    }
    179169
    180     /// \brief Returns the item with minimum priority relative to \c Compare.
    181     ///
    182     /// This method returns the item with minimum priority relative to \c
    183     /// Compare.
    184     /// \pre The heap must be nonempty.
     170    /// \brief Return the item having minimum priority.
     171    ///
     172    /// This function returns the item having minimum priority.
     173    /// \pre The heap must be non-empty.
    185174    Item top() const { return _data[_minimum].name; }
    186175
    187     /// \brief Returns the minimum priority relative to \c Compare.
    188     ///
    189     /// It returns the minimum priority relative to \c Compare.
    190     /// \pre The heap must be nonempty.
    191     const Prio& prio() const { return _data[_minimum].prio; }
    192 
    193     /// \brief Returns the priority of \c item.
    194     ///
    195     /// It returns the priority of \c item.
    196     /// \pre \c item must be in the heap.
    197     const Prio& operator[](const Item& item) const {
    198       return _data[_iim[item]].prio;
    199     }
    200 
    201     /// \brief Deletes the item with minimum priority relative to \c Compare.
    202     ///
    203     /// This method deletes the item with minimum priority relative to \c
    204     /// Compare from the heap.
     176    /// \brief The minimum priority.
     177    ///
     178    /// This function returns the minimum priority.
     179    /// \pre The heap must be non-empty.
     180    Prio prio() const { return _data[_minimum].prio; }
     181
     182    /// \brief Remove the item having minimum priority.
     183    ///
     184    /// This function removes the item having minimum priority.
    205185    /// \pre The heap must be non-empty.
    206186    void pop() {
     
    209189        _data[_minimum].in=false;
    210190        if ( _data[_minimum].degree!=0 ) {
    211           makeroot(_data[_minimum].child);
     191          makeRoot(_data[_minimum].child);
    212192          _minimum=_data[_minimum].child;
    213193          balance();
     
    222202          int last_child=_data[child].left_neighbor;
    223203
    224           makeroot(child);
     204          makeRoot(child);
    225205
    226206          _data[left].right_neighbor=child;
     
    235215    }
    236216
    237     /// \brief Deletes \c item from the heap.
    238     ///
    239     /// This method deletes \c item from the heap, if \c item was already
    240     /// stored in the heap. It is quite inefficient in Fibonacci heaps.
     217    /// \brief Remove the given item from the heap.
     218    ///
     219    /// This function removes the given item from the heap if it is
     220    /// already stored.
     221    /// \param item The item to delete.
     222    /// \pre \e item must be in the heap.
    241223    void erase (const Item& item) {
    242224      int i=_iim[item];
     
    253235    }
    254236
    255     /// \brief Decreases the priority of \c item to \c value.
    256     ///
    257     /// This method decreases the priority of \c item to \c value.
    258     /// \pre \c item must be stored in the heap with priority at least \c
    259     ///   value relative to \c Compare.
    260     void decrease (Item item, const Prio& value) {
     237    /// \brief The priority of the given item.
     238    ///
     239    /// This function returns the priority of the given item.
     240    /// \param item The item.
     241    /// \pre \e item must be in the heap.
     242    Prio operator[](const Item& item) const {
     243      return _data[_iim[item]].prio;
     244    }
     245
     246    /// \brief Set the priority of an item or insert it, if it is
     247    /// not stored in the heap.
     248    ///
     249    /// This method sets the priority of the given item if it is
     250    /// already stored in the heap. Otherwise it inserts the given
     251    /// item into the heap with the given priority.
     252    /// \param item The item.
     253    /// \param prio The priority.
     254    void set (const Item& item, const Prio& prio) {
    261255      int i=_iim[item];
    262       _data[i].prio=value;
     256      if ( i >= 0 && _data[i].in ) {
     257        if ( _comp(prio, _data[i].prio) ) decrease(item, prio);
     258        if ( _comp(_data[i].prio, prio) ) increase(item, prio);
     259      } else push(item, prio);
     260    }
     261
     262    /// \brief Decrease the priority of an item to the given value.
     263    ///
     264    /// This function decreases the priority of an item to the given value.
     265    /// \param item The item.
     266    /// \param prio The priority.
     267    /// \pre \e item must be stored in the heap with priority at least \e prio.
     268    void decrease (const Item& item, const Prio& prio) {
     269      int i=_iim[item];
     270      _data[i].prio=prio;
    263271      int p=_data[i].parent;
    264272
    265       if ( p!=-1 && _comp(value, _data[p].prio) ) {
     273      if ( p!=-1 && _comp(prio, _data[p].prio) ) {
    266274        cut(i,p);
    267275        cascade(p);
    268276      }
    269       if ( _comp(value, _data[_minimum].prio) ) _minimum=i;
    270     }
    271 
    272     /// \brief Increases the priority of \c item to \c value.
    273     ///
    274     /// This method sets the priority of \c item to \c value. Though
    275     /// there is no precondition on the priority of \c item, this
    276     /// method should be used only if it is indeed necessary to increase
    277     /// (relative to \c Compare) the priority of \c item, because this
    278     /// method is inefficient.
    279     void increase (Item item, const Prio& value) {
     277      if ( _comp(prio, _data[_minimum].prio) ) _minimum=i;
     278    }
     279
     280    /// \brief Increase the priority of an item to the given value.
     281    ///
     282    /// This function increases the priority of an item to the given value.
     283    /// \param item The item.
     284    /// \param prio The priority.
     285    /// \pre \e item must be stored in the heap with priority at most \e prio.
     286    void increase (const Item& item, const Prio& prio) {
    280287      erase(item);
    281       push(item, value);
    282     }
    283 
    284 
    285     /// \brief Returns if \c item is in, has already been in, or has never
    286     /// been in the heap.
    287     ///
    288     /// This method returns PRE_HEAP if \c item has never been in the
    289     /// heap, IN_HEAP if it is in the heap at the moment, and POST_HEAP
    290     /// otherwise. In the latter case it is possible that \c item will
    291     /// get back to the heap again.
     288      push(item, prio);
     289    }
     290
     291    /// \brief Return the state of an item.
     292    ///
     293    /// This method returns \c PRE_HEAP if the given item has never
     294    /// been in the heap, \c IN_HEAP if it is in the heap at the moment,
     295    /// and \c POST_HEAP otherwise.
     296    /// In the latter case it is possible that the item will get back
     297    /// to the heap again.
     298    /// \param item The item.
    292299    State state(const Item &item) const {
    293300      int i=_iim[item];
     
    299306    }
    300307
    301     /// \brief Sets the state of the \c item in the heap.
    302     ///
    303     /// Sets the state of the \c item in the heap. It can be used to
    304     /// manually clear the heap when it is important to achive the
    305     /// better time _complexity.
     308    /// \brief Set the state of an item in the heap.
     309    ///
     310    /// This function sets the state of the given item in the heap.
     311    /// It can be used to manually clear the heap when it is important
     312    /// to achive better time complexity.
    306313    /// \param i The item.
    307314    /// \param st The state. It should not be \c IN_HEAP.
     
    366373    }
    367374
    368     void makeroot(int c) {
     375    void makeRoot(int c) {
    369376      int s=c;
    370377      do {
  • TabularUnified lemon/full_graph.h

    r664 r956  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    2525///\ingroup graphs
    2626///\file
    27 ///\brief FullGraph and FullDigraph classes.
     27///\brief FullDigraph and FullGraph classes.
    2828
    2929namespace lemon {
     
    5252
    5353    Node operator()(int ix) const { return Node(ix); }
    54     int index(const Node& node) const { return node._id; }
     54    static int index(const Node& node) { return node._id; }
    5555
    5656    Arc arc(const Node& s, const Node& t) const {
     
    149149  /// \ingroup graphs
    150150  ///
    151   /// \brief A full digraph class.
    152   ///
    153   /// This is a simple and fast directed full graph implementation.
    154   /// From each node go arcs to each node (including the source node),
    155   /// therefore the number of the arcs in the digraph is the square of
    156   /// the node number. This digraph type is completely static, so you
    157   /// can neither add nor delete either arcs or nodes, and it needs
    158   /// constant space in memory.
    159   ///
    160   /// This class fully conforms to the \ref concepts::Digraph
    161   /// "Digraph concept".
    162   ///
    163   /// The \c FullDigraph and \c FullGraph classes are very similar,
     151  /// \brief A directed full graph class.
     152  ///
     153  /// FullDigraph is a simple and fast implmenetation of directed full
     154  /// (complete) graphs. It contains an arc from each node to each node
     155  /// (including a loop for each node), therefore the number of arcs
     156  /// is the square of the number of nodes.
     157  /// This class is completely static and it needs constant memory space.
     158  /// Thus you can neither add nor delete nodes or arcs, however
     159  /// the structure can be resized using resize().
     160  ///
     161  /// This type fully conforms to the \ref concepts::Digraph "Digraph concept".
     162  /// Most of its member functions and nested classes are documented
     163  /// only in the concept class.
     164  ///
     165  /// This class provides constant time counting for nodes and arcs.
     166  ///
     167  /// \note FullDigraph and FullGraph classes are very similar,
    164168  /// but there are two differences. While this class conforms only
    165   /// to the \ref concepts::Digraph "Digraph" concept, the \c FullGraph
    166   /// class conforms to the \ref concepts::Graph "Graph" concept,
    167   /// moreover \c FullGraph does not contain a loop arc for each
    168   /// node as \c FullDigraph does.
     169  /// to the \ref concepts::Digraph "Digraph" concept, FullGraph
     170  /// conforms to the \ref concepts::Graph "Graph" concept,
     171  /// moreover FullGraph does not contain a loop for each
     172  /// node as this class does.
    169173  ///
    170174  /// \sa FullGraph
     
    174178  public:
    175179
    176     /// \brief Constructor
     180    /// \brief Default constructor.
     181    ///
     182    /// Default constructor. The number of nodes and arcs will be zero.
    177183    FullDigraph() { construct(0); }
    178184
     
    185191    /// \brief Resizes the digraph
    186192    ///
    187     /// Resizes the digraph. The function will fully destroy and
    188     /// rebuild the digraph. This cause that the maps of the digraph will
     193    /// This function resizes the digraph. It fully destroys and
     194    /// rebuilds the structure, therefore the maps of the digraph will be
    189195    /// reallocated automatically and the previous values will be lost.
    190196    void resize(int n) {
     
    198204    /// \brief Returns the node with the given index.
    199205    ///
    200     /// Returns the node with the given index. Since it is a static
    201     /// digraph its nodes can be indexed with integers from the range
    202     /// <tt>[0..nodeNum()-1]</tt>.
     206    /// Returns the node with the given index. Since this structure is
     207    /// completely static, the nodes can be indexed with integers from
     208    /// the range <tt>[0..nodeNum()-1]</tt>.
     209    /// The index of a node is the same as its ID.
    203210    /// \sa index()
    204211    Node operator()(int ix) const { return Parent::operator()(ix); }
     
    206213    /// \brief Returns the index of the given node.
    207214    ///
    208     /// Returns the index of the given node. Since it is a static
    209     /// digraph its nodes can be indexed with integers from the range
    210     /// <tt>[0..nodeNum()-1]</tt>.
    211     /// \sa operator()
    212     int index(const Node& node) const { return Parent::index(node); }
     215    /// Returns the index of the given node. Since this structure is
     216    /// completely static, the nodes can be indexed with integers from
     217    /// the range <tt>[0..nodeNum()-1]</tt>.
     218    /// The index of a node is the same as its ID.
     219    /// \sa operator()()
     220    static int index(const Node& node) { return Parent::index(node); }
    213221
    214222    /// \brief Returns the arc connecting the given nodes.
    215223    ///
    216224    /// Returns the arc connecting the given nodes.
    217     Arc arc(const Node& u, const Node& v) const {
     225    Arc arc(Node u, Node v) const {
    218226      return Parent::arc(u, v);
    219227    }
     
    284292
    285293    Node operator()(int ix) const { return Node(ix); }
    286     int index(const Node& node) const { return node._id; }
     294    static int index(const Node& node) { return node._id; }
    287295
    288296    Edge edge(const Node& u, const Node& v) const {
     
    521529  /// \brief An undirected full graph class.
    522530  ///
    523   /// This is a simple and fast undirected full graph
    524   /// implementation. From each node go edge to each other node,
    525   /// therefore the number of edges in the graph is \f$n(n-1)/2\f$.
    526   /// This graph type is completely static, so you can neither
    527   /// add nor delete either edges or nodes, and it needs constant
    528   /// space in memory.
    529   ///
    530   /// This class fully conforms to the \ref concepts::Graph "Graph concept".
    531   ///
    532   /// The \c FullGraph and \c FullDigraph classes are very similar,
    533   /// but there are two differences. While the \c FullDigraph class
     531  /// FullGraph is a simple and fast implmenetation of undirected full
     532  /// (complete) graphs. It contains an edge between every distinct pair
     533  /// of nodes, therefore the number of edges is <tt>n(n-1)/2</tt>.
     534  /// This class is completely static and it needs constant memory space.
     535  /// Thus you can neither add nor delete nodes or edges, however
     536  /// the structure can be resized using resize().
     537  ///
     538  /// This type fully conforms to the \ref concepts::Graph "Graph concept".
     539  /// Most of its member functions and nested classes are documented
     540  /// only in the concept class.
     541  ///
     542  /// This class provides constant time counting for nodes, edges and arcs.
     543  ///
     544  /// \note FullDigraph and FullGraph classes are very similar,
     545  /// but there are two differences. While FullDigraph
    534546  /// conforms only to the \ref concepts::Digraph "Digraph" concept,
    535547  /// this class conforms to the \ref concepts::Graph "Graph" concept,
    536   /// moreover \c FullGraph does not contain a loop arc for each
    537   /// node as \c FullDigraph does.
     548  /// moreover this class does not contain a loop for each
     549  /// node as FullDigraph does.
    538550  ///
    539551  /// \sa FullDigraph
     
    543555  public:
    544556
    545     /// \brief Constructor
     557    /// \brief Default constructor.
     558    ///
     559    /// Default constructor. The number of nodes and edges will be zero.
    546560    FullGraph() { construct(0); }
    547561
     
    554568    /// \brief Resizes the graph
    555569    ///
    556     /// Resizes the graph. The function will fully destroy and
    557     /// rebuild the graph. This cause that the maps of the graph will
     570    /// This function resizes the graph. It fully destroys and
     571    /// rebuilds the structure, therefore the maps of the graph will be
    558572    /// reallocated automatically and the previous values will be lost.
    559573    void resize(int n) {
     
    569583    /// \brief Returns the node with the given index.
    570584    ///
    571     /// Returns the node with the given index. Since it is a static
    572     /// graph its nodes can be indexed with integers from the range
    573     /// <tt>[0..nodeNum()-1]</tt>.
     585    /// Returns the node with the given index. Since this structure is
     586    /// completely static, the nodes can be indexed with integers from
     587    /// the range <tt>[0..nodeNum()-1]</tt>.
     588    /// The index of a node is the same as its ID.
    574589    /// \sa index()
    575590    Node operator()(int ix) const { return Parent::operator()(ix); }
     
    577592    /// \brief Returns the index of the given node.
    578593    ///
    579     /// Returns the index of the given node. Since it is a static
    580     /// graph its nodes can be indexed with integers from the range
    581     /// <tt>[0..nodeNum()-1]</tt>.
    582     /// \sa operator()
    583     int index(const Node& node) const { return Parent::index(node); }
     594    /// Returns the index of the given node. Since this structure is
     595    /// completely static, the nodes can be indexed with integers from
     596    /// the range <tt>[0..nodeNum()-1]</tt>.
     597    /// The index of a node is the same as its ID.
     598    /// \sa operator()()
     599    static int index(const Node& node) { return Parent::index(node); }
    584600
    585601    /// \brief Returns the arc connecting the given nodes.
    586602    ///
    587603    /// Returns the arc connecting the given nodes.
    588     Arc arc(const Node& s, const Node& t) const {
     604    Arc arc(Node s, Node t) const {
    589605      return Parent::arc(s, t);
    590606    }
    591607
    592     /// \brief Returns the edge connects the given nodes.
    593     ///
    594     /// Returns the edge connects the given nodes.
    595     Edge edge(const Node& u, const Node& v) const {
     608    /// \brief Returns the edge connecting the given nodes.
     609    ///
     610    /// Returns the edge connecting the given nodes.
     611    Edge edge(Node u, Node v) const {
    596612      return Parent::edge(u, v);
    597613    }
  • TabularUnified lemon/glpk.cc

    r623 r956  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    5757    int i = glp_add_rows(lp, 1);
    5858    glp_set_row_bnds(lp, i, GLP_FR, 0.0, 0.0);
     59    return i;
     60  }
     61
     62  int GlpkBase::_addRow(Value lo, ExprIterator b,
     63                        ExprIterator e, Value up) {
     64    int i = glp_add_rows(lp, 1);
     65
     66    if (lo == -INF) {
     67      if (up == INF) {
     68        glp_set_row_bnds(lp, i, GLP_FR, lo, up);
     69      } else {
     70        glp_set_row_bnds(lp, i, GLP_UP, lo, up);
     71      }
     72    } else {
     73      if (up == INF) {
     74        glp_set_row_bnds(lp, i, GLP_LO, lo, up);
     75      } else if (lo != up) {
     76        glp_set_row_bnds(lp, i, GLP_DB, lo, up);
     77      } else {
     78        glp_set_row_bnds(lp, i, GLP_FX, lo, up);
     79      }
     80    }
     81
     82    std::vector<int> indexes;
     83    std::vector<Value> values;
     84
     85    indexes.push_back(0);
     86    values.push_back(0);
     87
     88    for(ExprIterator it = b; it != e; ++it) {
     89      indexes.push_back(it->first);
     90      values.push_back(it->second);
     91    }
     92
     93    glp_set_mat_row(lp, i, values.size() - 1,
     94                    &indexes.front(), &values.front());
    5995    return i;
    6096  }
  • TabularUnified lemon/glpk.h

    r900 r956  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2008
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    3131    class VoidPtr {
    3232    private:
    33       void *_ptr;     
     33      void *_ptr;
    3434    public:
    3535      VoidPtr() : _ptr(0) {}
     
    3939
    4040      template <typename T>
    41       VoidPtr& operator=(T* ptr) { 
    42         _ptr = reinterpret_cast<void*>(ptr); 
     41      VoidPtr& operator=(T* ptr) {
     42        _ptr = reinterpret_cast<void*>(ptr);
    4343        return *this;
    4444      }
     
    6666    virtual int _addCol();
    6767    virtual int _addRow();
     68    virtual int _addRow(Value l, ExprIterator b, ExprIterator e, Value u);
    6869
    6970    virtual void _eraseCol(int i);
     
    124125      }
    125126    };
    126    
     127
    127128    static FreeEnvHelper freeEnvHelper;
    128129
    129130  protected:
    130    
     131
    131132    int _message_level;
    132    
     133
    133134  public:
    134135
  • TabularUnified lemon/gomory_hu.h

    r643 r956  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2008
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    2828
    2929/// \ingroup min_cut
    30 /// \file 
     30/// \file
    3131/// \brief Gomory-Hu cut tree in graphs.
    3232
     
    3939  /// The Gomory-Hu tree is a tree on the node set of a given graph, but it
    4040  /// may contain edges which are not in the original graph. It has the
    41   /// property that the minimum capacity edge of the path between two nodes 
     41  /// property that the minimum capacity edge of the path between two nodes
    4242  /// in this tree has the same weight as the minimum cut in the graph
    4343  /// between these nodes. Moreover the components obtained by removing
     
    4545  /// Therefore once this tree is computed, the minimum cut between any pair
    4646  /// of nodes can easily be obtained.
    47   /// 
     47  ///
    4848  /// The algorithm calculates \e n-1 distinct minimum cuts (currently with
    4949  /// the \ref Preflow algorithm), thus it has \f$O(n^3\sqrt{e})\f$ overall
     
    6161#ifdef DOXYGEN
    6262  template <typename GR,
    63             typename CAP>
     63            typename CAP>
    6464#else
    6565  template <typename GR,
    66             typename CAP = typename GR::template EdgeMap<int> >
     66            typename CAP = typename GR::template EdgeMap<int> >
    6767#endif
    6868  class GomoryHu {
     
    7575    /// The value type of capacities
    7676    typedef typename Capacity::Value Value;
    77    
     77
    7878  private:
    7979
     
    9090    void createStructures() {
    9191      if (!_pred) {
    92         _pred = new typename Graph::template NodeMap<Node>(_graph);
     92        _pred = new typename Graph::template NodeMap<Node>(_graph);
    9393      }
    9494      if (!_weight) {
    95         _weight = new typename Graph::template NodeMap<Value>(_graph);
     95        _weight = new typename Graph::template NodeMap<Value>(_graph);
    9696      }
    9797      if (!_order) {
    98         _order = new typename Graph::template NodeMap<int>(_graph);
     98        _order = new typename Graph::template NodeMap<int>(_graph);
    9999      }
    100100    }
     
    102102    void destroyStructures() {
    103103      if (_pred) {
    104         delete _pred;
     104        delete _pred;
    105105      }
    106106      if (_weight) {
    107         delete _weight;
     107        delete _weight;
    108108      }
    109109      if (_order) {
    110         delete _order;
    111       }
    112     }
    113  
     110        delete _order;
     111      }
     112    }
     113
    114114  public:
    115115
     
    119119    /// \param graph The undirected graph the algorithm runs on.
    120120    /// \param capacity The edge capacity map.
    121     GomoryHu(const Graph& graph, const Capacity& capacity) 
     121    GomoryHu(const Graph& graph, const Capacity& capacity)
    122122      : _graph(graph), _capacity(capacity),
    123         _pred(0), _weight(0), _order(0)
     123        _pred(0), _weight(0), _order(0)
    124124    {
    125125      checkConcept<concepts::ReadMap<Edge, Value>, Capacity>();
     
    135135
    136136  private:
    137  
     137
    138138    // Initialize the internal data structures
    139139    void init() {
     
    146146      }
    147147      (*_pred)[_root] = INVALID;
    148       (*_weight)[_root] = std::numeric_limits<Value>::max(); 
     148      (*_weight)[_root] = std::numeric_limits<Value>::max();
    149149    }
    150150
     
    155155
    156156      for (NodeIt n(_graph); n != INVALID; ++n) {
    157         if (n == _root) continue;
    158 
    159         Node pn = (*_pred)[n];
    160         fa.source(n);
    161         fa.target(pn);
    162 
    163         fa.runMinCut();
    164 
    165         (*_weight)[n] = fa.flowValue();
    166 
    167         for (NodeIt nn(_graph); nn != INVALID; ++nn) {
    168           if (nn != n && fa.minCut(nn) && (*_pred)[nn] == pn) {
    169             (*_pred)[nn] = n;
    170           }
    171         }
    172         if ((*_pred)[pn] != INVALID && fa.minCut((*_pred)[pn])) {
    173           (*_pred)[n] = (*_pred)[pn];
    174           (*_pred)[pn] = n;
    175           (*_weight)[n] = (*_weight)[pn];
    176           (*_weight)[pn] = fa.flowValue();
    177         }
     157        if (n == _root) continue;
     158
     159        Node pn = (*_pred)[n];
     160        fa.source(n);
     161        fa.target(pn);
     162
     163        fa.runMinCut();
     164
     165        (*_weight)[n] = fa.flowValue();
     166
     167        for (NodeIt nn(_graph); nn != INVALID; ++nn) {
     168          if (nn != n && fa.minCut(nn) && (*_pred)[nn] == pn) {
     169            (*_pred)[nn] = n;
     170          }
     171        }
     172        if ((*_pred)[pn] != INVALID && fa.minCut((*_pred)[pn])) {
     173          (*_pred)[n] = (*_pred)[pn];
     174          (*_pred)[pn] = n;
     175          (*_weight)[n] = (*_weight)[pn];
     176          (*_weight)[pn] = fa.flowValue();
     177        }
    178178      }
    179179
     
    182182
    183183      for (NodeIt n(_graph); n != INVALID; ++n) {
    184         std::vector<Node> st;
    185         Node nn = n;
    186         while ((*_order)[nn] == -1) {
    187           st.push_back(nn);
    188           nn = (*_pred)[nn];
    189         }
    190         while (!st.empty()) {
    191           (*_order)[st.back()] = index++;
    192           st.pop_back();
    193         }
     184        std::vector<Node> st;
     185        Node nn = n;
     186        while ((*_order)[nn] == -1) {
     187          st.push_back(nn);
     188          nn = (*_pred)[nn];
     189        }
     190        while (!st.empty()) {
     191          (*_order)[st.back()] = index++;
     192          st.pop_back();
     193        }
    194194      }
    195195    }
     
    198198
    199199    ///\name Execution Control
    200  
     200
    201201    ///@{
    202202
     
    208208      start();
    209209    }
    210    
     210
    211211    /// @}
    212212
     
    233233    /// Gomory-Hu tree.
    234234    ///
    235     /// This function returns the weight of the predecessor edge of the 
     235    /// This function returns the weight of the predecessor edge of the
    236236    /// given node in the Gomory-Hu tree.
    237237    /// If \c node is the root of the tree, the result is undefined.
     
    255255    ///
    256256    /// This function returns the minimum cut value between the nodes
    257     /// \c s and \c t. 
     257    /// \c s and \c t.
    258258    /// It finds the nearest common ancestor of the given nodes in the
    259259    /// Gomory-Hu tree and calculates the minimum weight edge on the
     
    264264      Node sn = s, tn = t;
    265265      Value value = std::numeric_limits<Value>::max();
    266      
     266
    267267      while (sn != tn) {
    268         if ((*_order)[sn] < (*_order)[tn]) {
    269           if ((*_weight)[tn] <= value) value = (*_weight)[tn];
    270           tn = (*_pred)[tn];
    271         } else {
    272           if ((*_weight)[sn] <= value) value = (*_weight)[sn];
    273           sn = (*_pred)[sn];
    274         }
     268        if ((*_order)[sn] < (*_order)[tn]) {
     269          if ((*_weight)[tn] <= value) value = (*_weight)[tn];
     270          tn = (*_pred)[tn];
     271        } else {
     272          if ((*_weight)[sn] <= value) value = (*_weight)[sn];
     273          sn = (*_pred)[sn];
     274        }
    275275      }
    276276      return value;
     
    295295    /// \pre \ref run() must be called before using this function.
    296296    template <typename CutMap>
    297     Value minCutMap(const Node& s, ///<
     297    Value minCutMap(const Node& s,
    298298                    const Node& t,
    299                     ///<
    300299                    CutMap& cutMap
    301                     ///<
    302300                    ) const {
    303301      Node sn = s, tn = t;
     
    305303      Node rn = INVALID;
    306304      Value value = std::numeric_limits<Value>::max();
    307      
     305
    308306      while (sn != tn) {
    309         if ((*_order)[sn] < (*_order)[tn]) {
    310           if ((*_weight)[tn] <= value) {
    311             rn = tn;
     307        if ((*_order)[sn] < (*_order)[tn]) {
     308          if ((*_weight)[tn] <= value) {
     309            rn = tn;
    312310            s_root = false;
    313             value = (*_weight)[tn];
    314           }
    315           tn = (*_pred)[tn];
    316         } else {
    317           if ((*_weight)[sn] <= value) {
    318             rn = sn;
     311            value = (*_weight)[tn];
     312          }
     313          tn = (*_pred)[tn];
     314        } else {
     315          if ((*_weight)[sn] <= value) {
     316            rn = sn;
    319317            s_root = true;
    320             value = (*_weight)[sn];
    321           }
    322           sn = (*_pred)[sn];
    323         }
     318            value = (*_weight)[sn];
     319          }
     320          sn = (*_pred)[sn];
     321        }
    324322      }
    325323
     
    332330      std::vector<Node> st;
    333331      for (NodeIt n(_graph); n != INVALID; ++n) {
    334         st.clear();
     332        st.clear();
    335333        Node nn = n;
    336         while (!reached[nn]) {
    337           st.push_back(nn);
    338           nn = (*_pred)[nn];
    339         }
    340         while (!st.empty()) {
    341           cutMap.set(st.back(), cutMap[nn]);
    342           st.pop_back();
    343         }
    344       }
    345      
     334        while (!reached[nn]) {
     335          st.push_back(nn);
     336          nn = (*_pred)[nn];
     337        }
     338        while (!st.empty()) {
     339          cutMap.set(st.back(), cutMap[nn]);
     340          st.pop_back();
     341        }
     342      }
     343
    346344      return value;
    347345    }
     
    352350
    353351    /// Iterate on the nodes of a minimum cut
    354    
     352
    355353    /// This iterator class lists the nodes of a minimum cut found by
    356354    /// GomoryHu. Before using it, you must allocate a GomoryHu class
     
    360358    /// \c t.
    361359    /// \code
    362     /// GomoruHu<Graph> gom(g, capacities);
     360    /// GomoryHu<Graph> gom(g, capacities);
    363361    /// gom.run();
    364362    /// int cnt=0;
    365     /// for(GomoruHu<Graph>::MinCutNodeIt n(gom,s,t); n!=INVALID; ++n) ++cnt;
     363    /// for(GomoryHu<Graph>::MinCutNodeIt n(gom,s,t); n!=INVALID; ++n) ++cnt;
    366364    /// \endcode
    367365    class MinCutNodeIt
     
    395393                   /// \endcode
    396394                   /// does not necessarily give the same set of nodes.
    397                    /// However it is ensured that
     395                   /// However, it is ensured that
    398396                   /// \code
    399397                   /// MinCutNodeIt(gomory, s, t, true);
     
    445443      }
    446444    };
    447    
     445
    448446    friend class MinCutEdgeIt;
    449    
     447
    450448    /// Iterate on the edges of a minimum cut
    451    
     449
    452450    /// This iterator class lists the edges of a minimum cut found by
    453451    /// GomoryHu. Before using it, you must allocate a GomoryHu class
     
    457455    /// \c t.
    458456    /// \code
    459     /// GomoruHu<Graph> gom(g, capacities);
     457    /// GomoryHu<Graph> gom(g, capacities);
    460458    /// gom.run();
    461459    /// int value=0;
    462     /// for(GomoruHu<Graph>::MinCutEdgeIt e(gom,s,t); e!=INVALID; ++e)
     460    /// for(GomoryHu<Graph>::MinCutEdgeIt e(gom,s,t); e!=INVALID; ++e)
    463461    ///   value+=capacities[e];
    464462    /// \endcode
     
    482480          }
    483481      }
    484      
     482
    485483    public:
    486484      /// Constructor
     
    551549      }
    552550      /// Postfix incrementation
    553      
     551
    554552      /// Postfix incrementation.
    555553      ///
  • TabularUnified lemon/graph_to_eps.h

    r908 r1107  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    143143  ///\param gr  Reference to the graph to be printed.
    144144  ///\param ost Reference to the output stream.
    145   ///By default it is <tt>std::cout</tt>.
     145  ///By default, it is <tt>std::cout</tt>.
    146146  ///\param pros If it is \c true, then the \c ostream referenced by \c os
    147147  ///will be explicitly deallocated by the destructor.
     
    513513  ///Turn on/off pre-scaling
    514514
    515   ///By default graphToEps() rescales the whole image in order to avoid
     515  ///By default, graphToEps() rescales the whole image in order to avoid
    516516  ///very big or very small bounding boxes.
    517517  ///
     
    11151115///\param g Reference to the graph to be printed.
    11161116///\param os Reference to the output stream.
    1117 ///By default it is <tt>std::cout</tt>.
     1117///By default, it is <tt>std::cout</tt>.
    11181118///
    11191119///This function also has a lot of
     
    11271127///\endcode
    11281128///
    1129 ///For more detailed examples see the \ref graph_to_eps_demo.cc demo file.
     1129///For more detailed examples, see the \ref graph_to_eps_demo.cc demo file.
    11301130///
    11311131///\warning Don't forget to put the \ref GraphToEps::run() "run()"
  • TabularUnified lemon/grid_graph.h

    r664 r834  
    471471  /// \brief Grid graph class
    472472  ///
    473   /// This class implements a special graph type. The nodes of the
    474   /// graph can be indexed by two integer \c (i,j) value where \c i is
    475   /// in the \c [0..width()-1] range and j is in the \c
    476   /// [0..height()-1] range. Two nodes are connected in the graph if
    477   /// the indexes differ exactly on one position and exactly one is
    478   /// the difference. The nodes of the graph can be indexed by position
    479   /// with the \c operator()() function. The positions of the nodes can be
    480   /// get with \c pos(), \c col() and \c row() members. The outgoing
     473  /// GridGraph implements a special graph type. The nodes of the
     474  /// graph can be indexed by two integer values \c (i,j) where \c i is
     475  /// in the range <tt>[0..width()-1]</tt> and j is in the range
     476  /// <tt>[0..height()-1]</tt>. Two nodes are connected in the graph if
     477  /// the indices differ exactly on one position and the difference is
     478  /// also exactly one. The nodes of the graph can be obtained by position
     479  /// using the \c operator()() function and the indices of the nodes can
     480  /// be obtained using \c pos(), \c col() and \c row() members. The outgoing
    481481  /// arcs can be retrieved with the \c right(), \c up(), \c left()
    482482  /// and \c down() functions, where the bottom-left corner is the
    483483  /// origin.
     484  ///
     485  /// This class is completely static and it needs constant memory space.
     486  /// Thus you can neither add nor delete nodes or edges, however
     487  /// the structure can be resized using resize().
    484488  ///
    485489  /// \image html grid_graph.png
     
    497501  ///\endcode
    498502  ///
    499   /// This graph type fully conforms to the \ref concepts::Graph
    500   /// "Graph concept".
     503  /// This type fully conforms to the \ref concepts::Graph "Graph concept".
     504  /// Most of its member functions and nested classes are documented
     505  /// only in the concept class.
     506  ///
     507  /// This class provides constant time counting for nodes, edges and arcs.
    501508  class GridGraph : public ExtendedGridGraphBase {
    502509    typedef ExtendedGridGraphBase Parent;
     
    504511  public:
    505512
    506     /// \brief Map to get the indices of the nodes as dim2::Point<int>.
    507     ///
    508     /// Map to get the indices of the nodes as dim2::Point<int>.
     513    /// \brief Map to get the indices of the nodes as \ref dim2::Point
     514    /// "dim2::Point<int>".
     515    ///
     516    /// Map to get the indices of the nodes as \ref dim2::Point
     517    /// "dim2::Point<int>".
    509518    class IndexMap {
    510519    public:
     
    515524
    516525      /// \brief Constructor
    517       ///
    518       /// Constructor
    519526      IndexMap(const GridGraph& graph) : _graph(graph) {}
    520527
    521528      /// \brief The subscript operator
    522       ///
    523       /// The subscript operator.
    524529      Value operator[](Key key) const {
    525530        return _graph.pos(key);
     
    541546
    542547      /// \brief Constructor
    543       ///
    544       /// Constructor
    545548      ColMap(const GridGraph& graph) : _graph(graph) {}
    546549
    547550      /// \brief The subscript operator
    548       ///
    549       /// The subscript operator.
    550551      Value operator[](Key key) const {
    551552        return _graph.col(key);
     
    567568
    568569      /// \brief Constructor
    569       ///
    570       /// Constructor
    571570      RowMap(const GridGraph& graph) : _graph(graph) {}
    572571
    573572      /// \brief The subscript operator
    574       ///
    575       /// The subscript operator.
    576573      Value operator[](Key key) const {
    577574        return _graph.row(key);
     
    584581    /// \brief Constructor
    585582    ///
    586     /// Construct a grid graph with given size.
     583    /// Construct a grid graph with the given size.
    587584    GridGraph(int width, int height) { construct(width, height); }
    588585
    589     /// \brief Resize the graph
    590     ///
    591     /// Resize the graph. The function will fully destroy and rebuild
    592     /// the graph.  This cause that the maps of the graph will
    593     /// reallocated automatically and the previous values will be
    594     /// lost.
     586    /// \brief Resizes the graph
     587    ///
     588    /// This function resizes the graph. It fully destroys and
     589    /// rebuilds the structure, therefore the maps of the graph will be
     590    /// reallocated automatically and the previous values will be lost.
    595591    void resize(int width, int height) {
    596592      Parent::notifier(Arc()).clear();
     
    610606    }
    611607
    612     /// \brief Gives back the column index of the node.
     608    /// \brief The column index of the node.
    613609    ///
    614610    /// Gives back the column index of the node.
     
    617613    }
    618614
    619     /// \brief Gives back the row index of the node.
     615    /// \brief The row index of the node.
    620616    ///
    621617    /// Gives back the row index of the node.
     
    624620    }
    625621
    626     /// \brief Gives back the position of the node.
     622    /// \brief The position of the node.
    627623    ///
    628624    /// Gives back the position of the node, ie. the <tt>(col,row)</tt> pair.
     
    631627    }
    632628
    633     /// \brief Gives back the number of the columns.
     629    /// \brief The number of the columns.
    634630    ///
    635631    /// Gives back the number of the columns.
     
    638634    }
    639635
    640     /// \brief Gives back the number of the rows.
     636    /// \brief The number of the rows.
    641637    ///
    642638    /// Gives back the number of the rows.
     
    645641    }
    646642
    647     /// \brief Gives back the arc goes right from the node.
     643    /// \brief The arc goes right from the node.
    648644    ///
    649645    /// Gives back the arc goes right from the node. If there is not
     
    653649    }
    654650
    655     /// \brief Gives back the arc goes left from the node.
     651    /// \brief The arc goes left from the node.
    656652    ///
    657653    /// Gives back the arc goes left from the node. If there is not
     
    661657    }
    662658
    663     /// \brief Gives back the arc goes up from the node.
     659    /// \brief The arc goes up from the node.
    664660    ///
    665661    /// Gives back the arc goes up from the node. If there is not
     
    669665    }
    670666
    671     /// \brief Gives back the arc goes down from the node.
     667    /// \brief The arc goes down from the node.
    672668    ///
    673669    /// Gives back the arc goes down from the node. If there is not
  • TabularUnified lemon/hao_orlin.h

    r644 r956  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    3232/// \brief Implementation of the Hao-Orlin algorithm.
    3333///
    34 /// Implementation of the Hao-Orlin algorithm for finding a minimum cut 
     34/// Implementation of the Hao-Orlin algorithm for finding a minimum cut
    3535/// in a digraph.
    3636
     
    4242  ///
    4343  /// This class implements the Hao-Orlin algorithm for finding a minimum
    44   /// value cut in a directed graph \f$D=(V,A)\f$. 
     44  /// value cut in a directed graph \f$D=(V,A)\f$.
    4545  /// It takes a fixed node \f$ source \in V \f$ and
    4646  /// consists of two phases: in the first phase it determines a
     
    5959  /// For an undirected graph you can run just the first phase of the
    6060  /// algorithm or you can use the algorithm of Nagamochi and Ibaraki,
    61   /// which solves the undirected problem in \f$ O(nm + n^2 \log n) \f$ 
     61  /// which solves the undirected problem in \f$ O(nm + n^2 \log n) \f$
    6262  /// time. It is implemented in the NagamochiIbaraki algorithm class.
    6363  ///
     
    7777  class HaoOrlin {
    7878  public:
    79    
     79
    8080    /// The digraph type of the algorithm
    8181    typedef GR Digraph;
     
    164164        delete _flow;
    165165      }
     166    }
     167
     168    /// \brief Set the tolerance used by the algorithm.
     169    ///
     170    /// This function sets the tolerance object used by the algorithm.
     171    /// \return <tt>(*this)</tt>
     172    HaoOrlin& tolerance(const Tolerance& tolerance) {
     173      _tolerance = tolerance;
     174      return *this;
     175    }
     176
     177    /// \brief Returns a const reference to the tolerance.
     178    ///
     179    /// This function returns a const reference to the tolerance object
     180    /// used by the algorithm.
     181    const Tolerance& tolerance() const {
     182      return _tolerance;
    166183    }
    167184
     
    848865    ///
    849866    /// This function initializes the internal data structures. It creates
    850     /// the maps and some bucket structures for the algorithm. 
     867    /// the maps and some bucket structures for the algorithm.
    851868    /// The given node is used as the source node for the push-relabel
    852869    /// algorithm.
     
    928945    /// \brief Run the algorithm.
    929946    ///
    930     /// This function runs the algorithm. It uses the given \c source node, 
     947    /// This function runs the algorithm. It uses the given \c source node,
    931948    /// finds a proper \c target node and then calls the \ref init(),
    932949    /// \ref calculateOut() and \ref calculateIn().
     
    942959    /// The result of the %HaoOrlin algorithm
    943960    /// can be obtained using these functions.\n
    944     /// \ref run(), \ref calculateOut() or \ref calculateIn() 
     961    /// \ref run(), \ref calculateOut() or \ref calculateIn()
    945962    /// should be called before using them.
    946963
     
    951968    /// This function returns the value of the minimum cut.
    952969    ///
    953     /// \pre \ref run(), \ref calculateOut() or \ref calculateIn() 
     970    /// \pre \ref run(), \ref calculateOut() or \ref calculateIn()
    954971    /// must be called before using this function.
    955972    Value minCutValue() const {
     
    970987    /// \return The value of the minimum cut.
    971988    ///
    972     /// \pre \ref run(), \ref calculateOut() or \ref calculateIn() 
     989    /// \pre \ref run(), \ref calculateOut() or \ref calculateIn()
    973990    /// must be called before using this function.
    974991    template <typename CutMap>
  • TabularUnified lemon/hypercube_graph.h

    r664 r835  
    263263    }
    264264
    265     int index(Node node) const {
     265    static int index(Node node) {
    266266      return node._id;
    267267    }
     
    283283  /// \brief Hypercube graph class
    284284  ///
    285   /// This class implements a special graph type. The nodes of the graph
    286   /// are indiced with integers with at most \c dim binary digits.
     285  /// HypercubeGraph implements a special graph type. The nodes of the
     286  /// graph are indexed with integers having at most \c dim binary digits.
    287287  /// Two nodes are connected in the graph if and only if their indices
    288288  /// differ only on one position in the binary form.
     289  /// This class is completely static and it needs constant memory space.
     290  /// Thus you can neither add nor delete nodes or edges, however,
     291  /// the structure can be resized using resize().
     292  ///
     293  /// This type fully conforms to the \ref concepts::Graph "Graph concept".
     294  /// Most of its member functions and nested classes are documented
     295  /// only in the concept class.
     296  ///
     297  /// This class provides constant time counting for nodes, edges and arcs.
    289298  ///
    290299  /// \note The type of the indices is chosen to \c int for efficiency
    291300  /// reasons. Thus the maximum dimension of this implementation is 26
    292301  /// (assuming that the size of \c int is 32 bit).
    293   ///
    294   /// This graph type fully conforms to the \ref concepts::Graph
    295   /// "Graph concept".
    296302  class HypercubeGraph : public ExtendedHypercubeGraphBase {
    297303    typedef ExtendedHypercubeGraphBase Parent;
     
    303309    /// Constructs a hypercube graph with \c dim dimensions.
    304310    HypercubeGraph(int dim) { construct(dim); }
     311
     312    /// \brief Resizes the graph
     313    ///
     314    /// This function resizes the graph. It fully destroys and
     315    /// rebuilds the structure, therefore the maps of the graph will be
     316    /// reallocated automatically and the previous values will be lost.
     317    void resize(int dim) {
     318      Parent::notifier(Arc()).clear();
     319      Parent::notifier(Edge()).clear();
     320      Parent::notifier(Node()).clear();
     321      construct(dim);
     322      Parent::notifier(Node()).build();
     323      Parent::notifier(Edge()).build();
     324      Parent::notifier(Arc()).build();
     325    }
    305326
    306327    /// \brief The number of dimensions.
     
    321342    ///
    322343    /// Gives back the dimension id of the given edge.
    323     /// It is in the [0..dim-1] range.
     344    /// It is in the range <tt>[0..dim-1]</tt>.
    324345    int dimension(Edge edge) const {
    325346      return Parent::dimension(edge);
     
    329350    ///
    330351    /// Gives back the dimension id of the given arc.
    331     /// It is in the [0..dim-1] range.
     352    /// It is in the range <tt>[0..dim-1]</tt>.
    332353    int dimension(Arc arc) const {
    333354      return Parent::dimension(arc);
     
    338359    /// Gives back the index of the given node.
    339360    /// The lower bits of the integer describes the node.
    340     int index(Node node) const {
     361    static int index(Node node) {
    341362      return Parent::index(node);
    342363    }
  • TabularUnified lemon/lgf_reader.h

    r1069 r1110  
    428428  ///\endcode
    429429  ///
    430   /// By default the reader uses the first section in the file of the
     430  /// By default, the reader uses the first section in the file of the
    431431  /// proper type. If a section has an optional name, then it can be
    432432  /// selected for reading by giving an optional name parameter to the
     
    563563    friend DigraphReader<TDGR> digraphReader(TDGR& digraph, std::istream& is);
    564564    template <typename TDGR>
    565     friend DigraphReader<TDGR> digraphReader(TDGR& digraph, 
     565    friend DigraphReader<TDGR> digraphReader(TDGR& digraph,
    566566                                             const std::string& fn);
    567567    template <typename TDGR>
     
    11951195
    11961196  };
    1197  
     1197
    11981198  /// \ingroup lemon_io
    11991199  ///
     
    12021202  /// This function just returns a \ref DigraphReader class.
    12031203  ///
    1204   /// With this function a digraph can be read from an 
     1204  /// With this function a digraph can be read from an
    12051205  /// \ref lgf-format "LGF" file or input stream with several maps and
    12061206  /// attributes. For example, there is network flow problem on a
     
    12571257  template <typename GR>
    12581258  class GraphReader;
    1259  
     1259
    12601260  template <typename TGR>
    12611261  GraphReader<TGR> graphReader(TGR& graph, std::istream& is = std::cin);
     
    13941394    friend GraphReader<TGR> graphReader(TGR& graph, std::istream& is);
    13951395    template <typename TGR>
    1396     friend GraphReader<TGR> graphReader(TGR& graph, const std::string& fn); 
     1396    friend GraphReader<TGR> graphReader(TGR& graph, const std::string& fn);
    13971397    template <typename TGR>
    13981398    friend GraphReader<TGR> graphReader(TGR& graph, const char *fn);
     
    20782078  /// \brief Return a \ref GraphReader class
    20792079  ///
    2080   /// This function just returns a \ref GraphReader class. 
    2081   ///
    2082   /// With this function a graph can be read from an 
     2080  /// This function just returns a \ref GraphReader class.
     2081  ///
     2082  /// With this function a graph can be read from an
    20832083  /// \ref lgf-format "LGF" file or input stream with several maps and
    20842084  /// attributes. For example, there is weighted matching problem on a
     
    22362236    /// whitespaces are trimmed from each processed string.
    22372237    ///
    2238     /// For example let's see a section, which contain several
     2238    /// For example, let's see a section, which contain several
    22392239    /// integers, which should be inserted into a vector.
    22402240    ///\code
  • TabularUnified lemon/lgf_writer.h

    r646 r956  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    352352
    353353  template <typename TDGR>
    354   DigraphWriter<TDGR> digraphWriter(const TDGR& digraph, 
     354  DigraphWriter<TDGR> digraphWriter(const TDGR& digraph,
    355355                                   std::ostream& os = std::cout);
    356356  template <typename TDGR>
     
    505505
    506506    template <typename TDGR>
    507     friend DigraphWriter<TDGR> digraphWriter(const TDGR& digraph, 
     507    friend DigraphWriter<TDGR> digraphWriter(const TDGR& digraph,
    508508                                             std::ostream& os);
    509509    template <typename TDGR>
     
    918918  /// \brief Return a \ref DigraphWriter class
    919919  ///
    920   /// This function just returns a \ref DigraphWriter class. 
     920  /// This function just returns a \ref DigraphWriter class.
    921921  ///
    922922  /// With this function a digraph can be write to a file or output
     
    958958  /// \sa digraphWriter(const TDGR& digraph, std::ostream& os)
    959959  template <typename TDGR>
    960   DigraphWriter<TDGR> digraphWriter(const TDGR& digraph, 
     960  DigraphWriter<TDGR> digraphWriter(const TDGR& digraph,
    961961                                    const std::string& fn) {
    962962    DigraphWriter<TDGR> tmp(digraph, fn);
     
    11021102    friend GraphWriter<TGR> graphWriter(const TGR& graph, std::ostream& os);
    11031103    template <typename TGR>
    1104     friend GraphWriter<TGR> graphWriter(const TGR& graph, 
     1104    friend GraphWriter<TGR> graphWriter(const TGR& graph,
    11051105                                        const std::string& fn);
    11061106    template <typename TGR>
    11071107    friend GraphWriter<TGR> graphWriter(const TGR& graph, const char *fn);
    1108    
     1108
    11091109    GraphWriter(GraphWriter& other)
    11101110      : _os(other._os), local_os(other.local_os), _graph(other._graph),
     
    15571557  /// \brief Return a \ref GraphWriter class
    15581558  ///
    1559   /// This function just returns a \ref GraphWriter class. 
     1559  /// This function just returns a \ref GraphWriter class.
    15601560  ///
    15611561  /// With this function a graph can be write to a file or output
  • TabularUnified lemon/list_graph.h

    r664 r956  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    2222///\ingroup graphs
    2323///\file
    24 ///\brief ListDigraph, ListGraph classes.
     24///\brief ListDigraph and ListGraph classes.
    2525
    2626#include <lemon/core.h>
     
    3232
    3333namespace lemon {
     34
     35  class ListDigraph;
    3436
    3537  class ListDigraphBase {
     
    6365    class Node {
    6466      friend class ListDigraphBase;
     67      friend class ListDigraph;
    6568    protected:
    6669
     
    7881    class Arc {
    7982      friend class ListDigraphBase;
     83      friend class ListDigraph;
    8084    protected:
    8185
     
    117121      int n;
    118122      for(n = first_node;
    119           n!=-1 && nodes[n].first_in == -1;
     123          n != -1 && nodes[n].first_out == -1;
    120124          n = nodes[n].next) {}
    121       arc.id = (n == -1) ? -1 : nodes[n].first_in;
     125      arc.id = (n == -1) ? -1 : nodes[n].first_out;
    122126    }
    123127
    124128    void next(Arc& arc) const {
    125       if (arcs[arc.id].next_in != -1) {
    126         arc.id = arcs[arc.id].next_in;
     129      if (arcs[arc.id].next_out != -1) {
     130        arc.id = arcs[arc.id].next_out;
    127131      } else {
    128132        int n;
    129         for(n = nodes[arcs[arc.id].target].next;
    130             n!=-1 && nodes[n].first_in == -1;
     133        for(n = nodes[arcs[arc.id].source].next;
     134            n != -1 && nodes[n].first_out == -1;
    131135            n = nodes[n].next) {}
    132         arc.id = (n == -1) ? -1 : nodes[n].first_in;
     136        arc.id = (n == -1) ? -1 : nodes[n].first_out;
    133137      }
    134138    }
     
    312316  ///A general directed graph structure.
    313317
    314   ///\ref ListDigraph is a simple and fast <em>directed graph</em>
    315   ///implementation based on static linked lists that are stored in
     318  ///\ref ListDigraph is a versatile and fast directed graph
     319  ///implementation based on linked lists that are stored in
    316320  ///\c std::vector structures.
    317321  ///
    318   ///It conforms to the \ref concepts::Digraph "Digraph concept" and it
    319   ///also provides several useful additional functionalities.
    320   ///Most of the member functions and nested classes are documented
     322  ///This type fully conforms to the \ref concepts::Digraph "Digraph concept"
     323  ///and it also provides several useful additional functionalities.
     324  ///Most of its member functions and nested classes are documented
    321325  ///only in the concept class.
    322326  ///
     327  ///This class provides only linear time counting for nodes and arcs.
     328  ///
    323329  ///\sa concepts::Digraph
    324 
     330  ///\sa ListGraph
    325331  class ListDigraph : public ExtendedListDigraphBase {
    326332    typedef ExtendedListDigraphBase Parent;
    327333
    328334  private:
    329     ///ListDigraph is \e not copy constructible. Use copyDigraph() instead.
    330 
    331     ///ListDigraph is \e not copy constructible. Use copyDigraph() instead.
    332     ///
     335    /// Digraphs are \e not copy constructible. Use DigraphCopy instead.
    333336    ListDigraph(const ListDigraph &) :ExtendedListDigraphBase() {};
    334     ///\brief Assignment of ListDigraph to another one is \e not allowed.
    335     ///Use copyDigraph() instead.
    336 
    337     ///Assignment of ListDigraph to another one is \e not allowed.
    338     ///Use copyDigraph() instead.
     337    /// \brief Assignment of a digraph to another one is \e not allowed.
     338    /// Use DigraphCopy instead.
    339339    void operator=(const ListDigraph &) {}
    340340  public:
     
    348348    ///Add a new node to the digraph.
    349349
    350     ///Add a new node to the digraph.
     350    ///This function adds a new node to the digraph.
    351351    ///\return The new node.
    352352    Node addNode() { return Parent::addNode(); }
     
    354354    ///Add a new arc to the digraph.
    355355
    356     ///Add a new arc to the digraph with source node \c s
     356    ///This function adds a new arc to the digraph with source node \c s
    357357    ///and target node \c t.
    358358    ///\return The new arc.
    359     Arc addArc(const Node& s, const Node& t) {
     359    Arc addArc(Node s, Node t) {
    360360      return Parent::addArc(s, t);
    361361    }
     
    363363    ///\brief Erase a node from the digraph.
    364364    ///
    365     ///Erase a node from the digraph.
    366     ///
    367     void erase(const Node& n) { Parent::erase(n); }
     365    ///This function erases the given node along with its outgoing and
     366    ///incoming arcs from the digraph.
     367    ///
     368    ///\note All iterators referencing the removed node or the connected
     369    ///arcs are invalidated, of course.
     370    void erase(Node n) { Parent::erase(n); }
    368371
    369372    ///\brief Erase an arc from the digraph.
    370373    ///
    371     ///Erase an arc from the digraph.
    372     ///
    373     void erase(const Arc& a) { Parent::erase(a); }
     374    ///This function erases the given arc from the digraph.
     375    ///
     376    ///\note All iterators referencing the removed arc are invalidated,
     377    ///of course.
     378    void erase(Arc a) { Parent::erase(a); }
    374379
    375380    /// Node validity check
    376381
    377     /// This function gives back true if the given node is valid,
    378     /// ie. it is a real node of the graph.
    379     ///
    380     /// \warning A Node pointing to a removed item
    381     /// could become valid again later if new nodes are
    382     /// added to the graph.
     382    /// This function gives back \c true if the given node is valid,
     383    /// i.e. it is a real node of the digraph.
     384    ///
     385    /// \warning A removed node could become valid again if new nodes are
     386    /// added to the digraph.
    383387    bool valid(Node n) const { return Parent::valid(n); }
    384388
    385389    /// Arc validity check
    386390
    387     /// This function gives back true if the given arc is valid,
    388     /// ie. it is a real arc of the graph.
    389     ///
    390     /// \warning An Arc pointing to a removed item
    391     /// could become valid again later if new nodes are
    392     /// added to the graph.
     391    /// This function gives back \c true if the given arc is valid,
     392    /// i.e. it is a real arc of the digraph.
     393    ///
     394    /// \warning A removed arc could become valid again if new arcs are
     395    /// added to the digraph.
    393396    bool valid(Arc a) const { return Parent::valid(a); }
    394397
    395     /// Change the target of \c a to \c n
    396 
    397     /// Change the target of \c a to \c n
    398     ///
    399     ///\note The <tt>ArcIt</tt>s and <tt>OutArcIt</tt>s referencing
    400     ///the changed arc remain valid. However <tt>InArcIt</tt>s are
    401     ///invalidated.
     398    /// Change the target node of an arc
     399
     400    /// This function changes the target node of the given arc \c a to \c n.
     401    ///
     402    ///\note \c ArcIt and \c OutArcIt iterators referencing the changed
     403    ///arc remain valid, but \c InArcIt iterators are invalidated.
    402404    ///
    403405    ///\warning This functionality cannot be used together with the Snapshot
     
    406408      Parent::changeTarget(a,n);
    407409    }
    408     /// Change the source of \c a to \c n
    409 
    410     /// Change the source of \c a to \c n
    411     ///
    412     ///\note The <tt>InArcIt</tt>s referencing the changed arc remain
    413     ///valid. However the <tt>ArcIt</tt>s and <tt>OutArcIt</tt>s are
    414     ///invalidated.
     410    /// Change the source node of an arc
     411
     412    /// This function changes the source node of the given arc \c a to \c n.
     413    ///
     414    ///\note \c InArcIt iterators referencing the changed arc remain
     415    ///valid, but \c ArcIt and \c OutArcIt iterators are invalidated.
    415416    ///
    416417    ///\warning This functionality cannot be used together with the Snapshot
     
    420421    }
    421422
    422     /// Invert the direction of an arc.
    423 
    424     ///\note The <tt>ArcIt</tt>s referencing the changed arc remain
    425     ///valid. However <tt>OutArcIt</tt>s and <tt>InArcIt</tt>s are
    426     ///invalidated.
     423    /// Reverse the direction of an arc.
     424
     425    /// This function reverses the direction of the given arc.
     426    ///\note \c ArcIt, \c OutArcIt and \c InArcIt iterators referencing
     427    ///the changed arc are invalidated.
    427428    ///
    428429    ///\warning This functionality cannot be used together with the Snapshot
    429430    ///feature.
    430     void reverseArc(Arc e) {
    431       Node t=target(e);
    432       changeTarget(e,source(e));
    433       changeSource(e,t);
    434     }
    435 
    436     /// Reserve memory for nodes.
    437 
    438     /// Using this function it is possible to avoid the superfluous memory
    439     /// allocation: if you know that the digraph you want to build will
    440     /// be very large (e.g. it will contain millions of nodes and/or arcs)
    441     /// then it is worth reserving space for this amount before starting
    442     /// to build the digraph.
    443     /// \sa reserveArc
    444     void reserveNode(int n) { nodes.reserve(n); };
    445 
    446     /// Reserve memory for arcs.
    447 
    448     /// Using this function it is possible to avoid the superfluous memory
    449     /// allocation: if you know that the digraph you want to build will
    450     /// be very large (e.g. it will contain millions of nodes and/or arcs)
    451     /// then it is worth reserving space for this amount before starting
    452     /// to build the digraph.
    453     /// \sa reserveNode
    454     void reserveArc(int m) { arcs.reserve(m); };
     431    void reverseArc(Arc a) {
     432      Node t=target(a);
     433      changeTarget(a,source(a));
     434      changeSource(a,t);
     435    }
    455436
    456437    ///Contract two nodes.
    457438
    458     ///This function contracts two nodes.
    459     ///Node \p b will be removed but instead of deleting
    460     ///incident arcs, they will be joined to \p a.
    461     ///The last parameter \p r controls whether to remove loops. \c true
    462     ///means that loops will be removed.
    463     ///
    464     ///\note The <tt>ArcIt</tt>s referencing a moved arc remain
    465     ///valid. However <tt>InArcIt</tt>s and <tt>OutArcIt</tt>s
    466     ///may be invalidated.
     439    ///This function contracts the given two nodes.
     440    ///Node \c v is removed, but instead of deleting its
     441    ///incident arcs, they are joined to node \c u.
     442    ///If the last parameter \c r is \c true (this is the default value),
     443    ///then the newly created loops are removed.
     444    ///
     445    ///\note The moved arcs are joined to node \c u using changeSource()
     446    ///or changeTarget(), thus \c ArcIt and \c OutArcIt iterators are
     447    ///invalidated for the outgoing arcs of node \c v and \c InArcIt
     448    ///iterators are invalidated for the incomming arcs of \c v.
     449    ///Moreover all iterators referencing node \c v or the removed
     450    ///loops are also invalidated. Other iterators remain valid.
    467451    ///
    468452    ///\warning This functionality cannot be used together with the Snapshot
    469453    ///feature.
    470     void contract(Node a, Node b, bool r = true)
     454    void contract(Node u, Node v, bool r = true)
    471455    {
    472       for(OutArcIt e(*this,b);e!=INVALID;) {
     456      for(OutArcIt e(*this,v);e!=INVALID;) {
    473457        OutArcIt f=e;
    474458        ++f;
    475         if(r && target(e)==a) erase(e);
    476         else changeSource(e,a);
     459        if(r && target(e)==u) erase(e);
     460        else changeSource(e,u);
    477461        e=f;
    478462      }
    479       for(InArcIt e(*this,b);e!=INVALID;) {
     463      for(InArcIt e(*this,v);e!=INVALID;) {
    480464        InArcIt f=e;
    481465        ++f;
    482         if(r && source(e)==a) erase(e);
    483         else changeTarget(e,a);
     466        if(r && source(e)==u) erase(e);
     467        else changeTarget(e,u);
    484468        e=f;
    485469      }
    486       erase(b);
     470      erase(v);
    487471    }
    488472
    489473    ///Split a node.
    490474
    491     ///This function splits a node. First a new node is added to the digraph,
    492     ///then the source of each outgoing arc of \c n is moved to this new node.
    493     ///If \c connect is \c true (this is the default value), then a new arc
    494     ///from \c n to the newly created node is also added.
     475    ///This function splits the given node. First, a new node is added
     476    ///to the digraph, then the source of each outgoing arc of node \c n
     477    ///is moved to this new node.
     478    ///If the second parameter \c connect is \c true (this is the default
     479    ///value), then a new arc from node \c n to the newly created node
     480    ///is also added.
    495481    ///\return The newly created node.
    496482    ///
    497     ///\note The <tt>ArcIt</tt>s referencing a moved arc remain
    498     ///valid. However <tt>InArcIt</tt>s and <tt>OutArcIt</tt>s may
    499     ///be invalidated.
    500     ///
    501     ///\warning This functionality cannot be used in conjunction with the
     483    ///\note All iterators remain valid.
     484    ///
     485    ///\warning This functionality cannot be used together with the
    502486    ///Snapshot feature.
    503487    Node split(Node n, bool connect = true) {
    504488      Node b = addNode();
    505       for(OutArcIt e(*this,n);e!=INVALID;) {
    506         OutArcIt f=e;
    507         ++f;
    508         changeSource(e,b);
    509         e=f;
     489      nodes[b.id].first_out=nodes[n.id].first_out;
     490      nodes[n.id].first_out=-1;
     491      for(int i=nodes[b.id].first_out; i!=-1; i=arcs[i].next_out) {
     492        arcs[i].source=b.id;
    510493      }
    511494      if (connect) addArc(n,b);
     
    515498    ///Split an arc.
    516499
    517     ///This function splits an arc. First a new node \c b is added to
    518     ///the digraph, then the original arc is re-targeted to \c
    519     ///b. Finally an arc from \c b to the original target is added.
    520     ///
     500    ///This function splits the given arc. First, a new node \c v is
     501    ///added to the digraph, then the target node of the original arc
     502    ///is set to \c v. Finally, an arc from \c v to the original target
     503    ///is added.
    521504    ///\return The newly created node.
     505    ///
     506    ///\note \c InArcIt iterators referencing the original arc are
     507    ///invalidated. Other iterators remain valid.
    522508    ///
    523509    ///\warning This functionality cannot be used together with the
    524510    ///Snapshot feature.
    525     Node split(Arc e) {
    526       Node b = addNode();
    527       addArc(b,target(e));
    528       changeTarget(e,b);
    529       return b;
    530     }
     511    Node split(Arc a) {
     512      Node v = addNode();
     513      addArc(v,target(a));
     514      changeTarget(a,v);
     515      return v;
     516    }
     517
     518    ///Clear the digraph.
     519
     520    ///This function erases all nodes and arcs from the digraph.
     521    ///
     522    ///\note All iterators of the digraph are invalidated, of course.
     523    void clear() {
     524      Parent::clear();
     525    }
     526
     527    /// Reserve memory for nodes.
     528
     529    /// Using this function, it is possible to avoid superfluous memory
     530    /// allocation: if you know that the digraph you want to build will
     531    /// be large (e.g. it will contain millions of nodes and/or arcs),
     532    /// then it is worth reserving space for this amount before starting
     533    /// to build the digraph.
     534    /// \sa reserveArc()
     535    void reserveNode(int n) { nodes.reserve(n); };
     536
     537    /// Reserve memory for arcs.
     538
     539    /// Using this function, it is possible to avoid superfluous memory
     540    /// allocation: if you know that the digraph you want to build will
     541    /// be large (e.g. it will contain millions of nodes and/or arcs),
     542    /// then it is worth reserving space for this amount before starting
     543    /// to build the digraph.
     544    /// \sa reserveNode()
     545    void reserveArc(int m) { arcs.reserve(m); };
    531546
    532547    /// \brief Class to make a snapshot of the digraph and restore
     
    538553    /// restore() function.
    539554    ///
    540     /// \warning Arc and node deletions and other modifications (e.g.
    541     /// contracting, splitting, reversing arcs or nodes) cannot be
     555    /// \note After a state is restored, you cannot restore a later state,
     556    /// i.e. you cannot add the removed nodes and arcs again using
     557    /// another Snapshot instance.
     558    ///
     559    /// \warning Node and arc deletions and other modifications (e.g.
     560    /// reversing, contracting, splitting arcs or nodes) cannot be
    542561    /// restored. These events invalidate the snapshot.
     562    /// However, the arcs and nodes that were added to the digraph after
     563    /// making the current snapshot can be removed without invalidating it.
    543564    class Snapshot {
    544565    protected:
     
    710731      ///
    711732      /// Default constructor.
    712       /// To actually make a snapshot you must call save().
     733      /// You have to call save() to actually make a snapshot.
    713734      Snapshot()
    714735        : digraph(0), node_observer_proxy(*this),
     
    717738      /// \brief Constructor that immediately makes a snapshot.
    718739      ///
    719       /// This constructor immediately makes a snapshot of the digraph.
    720       /// \param _digraph The digraph we make a snapshot of.
    721       Snapshot(ListDigraph &_digraph)
     740      /// This constructor immediately makes a snapshot of the given digraph.
     741      Snapshot(ListDigraph &gr)
    722742        : node_observer_proxy(*this),
    723743          arc_observer_proxy(*this) {
    724         attach(_digraph);
     744        attach(gr);
    725745      }
    726746
    727747      /// \brief Make a snapshot.
    728748      ///
    729       /// Make a snapshot of the digraph.
    730       ///
    731       /// This function can be called more than once. In case of a repeated
     749      /// This function makes a snapshot of the given digraph.
     750      /// It can be called more than once. In case of a repeated
    732751      /// call, the previous snapshot gets lost.
    733       /// \param _digraph The digraph we make the snapshot of.
    734       void save(ListDigraph &_digraph) {
     752      void save(ListDigraph &gr) {
    735753        if (attached()) {
    736754          detach();
    737755          clear();
    738756        }
    739         attach(_digraph);
     757        attach(gr);
    740758      }
    741759
    742760      /// \brief Undo the changes until the last snapshot.
    743       //
    744       /// Undo the changes until the last snapshot created by save().
     761      ///
     762      /// This function undos the changes until the last snapshot
     763      /// created by save() or Snapshot(ListDigraph&).
     764      ///
     765      /// \warning This method invalidates the snapshot, i.e. repeated
     766      /// restoring is not supported unless you call save() again.
    745767      void restore() {
    746768        detach();
     
    756778      }
    757779
    758       /// \brief Gives back true when the snapshot is valid.
     780      /// \brief Returns \c true if the snapshot is valid.
    759781      ///
    760       /// Gives back true when the snapshot is valid.
     782      /// This function returns \c true if the snapshot is valid.
    761783      bool valid() const {
    762784        return attached();
     
    795817
    796818    typedef ListGraphBase Graph;
    797 
    798     class Node;
    799     class Arc;
    800     class Edge;
    801819
    802820    class Node {
     
    848866      bool operator<(const Arc& arc) const {return id < arc.id;}
    849867    };
    850 
    851 
    852868
    853869    ListGraphBase()
     
    11651181  ///A general undirected graph structure.
    11661182
    1167   ///\ref ListGraph is a simple and fast <em>undirected graph</em>
    1168   ///implementation based on static linked lists that are stored in
     1183  ///\ref ListGraph is a versatile and fast undirected graph
     1184  ///implementation based on linked lists that are stored in
    11691185  ///\c std::vector structures.
    11701186  ///
    1171   ///It conforms to the \ref concepts::Graph "Graph concept" and it
    1172   ///also provides several useful additional functionalities.
    1173   ///Most of the member functions and nested classes are documented
     1187  ///This type fully conforms to the \ref concepts::Graph "Graph concept"
     1188  ///and it also provides several useful additional functionalities.
     1189  ///Most of its member functions and nested classes are documented
    11741190  ///only in the concept class.
    11751191  ///
     1192  ///This class provides only linear time counting for nodes, edges and arcs.
     1193  ///
    11761194  ///\sa concepts::Graph
    1177 
     1195  ///\sa ListDigraph
    11781196  class ListGraph : public ExtendedListGraphBase {
    11791197    typedef ExtendedListGraphBase Parent;
    11801198
    11811199  private:
    1182     ///ListGraph is \e not copy constructible. Use copyGraph() instead.
    1183 
    1184     ///ListGraph is \e not copy constructible. Use copyGraph() instead.
    1185     ///
     1200    /// Graphs are \e not copy constructible. Use GraphCopy instead.
    11861201    ListGraph(const ListGraph &) :ExtendedListGraphBase()  {};
    1187     ///\brief Assignment of ListGraph to another one is \e not allowed.
    1188     ///Use copyGraph() instead.
    1189 
    1190     ///Assignment of ListGraph to another one is \e not allowed.
    1191     ///Use copyGraph() instead.
     1202    /// \brief Assignment of a graph to another one is \e not allowed.
     1203    /// Use GraphCopy instead.
    11921204    void operator=(const ListGraph &) {}
    11931205  public:
     
    12021214    /// \brief Add a new node to the graph.
    12031215    ///
    1204     /// Add a new node to the graph.
     1216    /// This function adds a new node to the graph.
    12051217    /// \return The new node.
    12061218    Node addNode() { return Parent::addNode(); }
     
    12081220    /// \brief Add a new edge to the graph.
    12091221    ///
    1210     /// Add a new edge to the graph with source node \c s
    1211     /// and target node \c t.
     1222    /// This function adds a new edge to the graph between nodes
     1223    /// \c u and \c v with inherent orientation from node \c u to
     1224    /// node \c v.
    12121225    /// \return The new edge.
    1213     Edge addEdge(const Node& s, const Node& t) {
    1214       return Parent::addEdge(s, t);
    1215     }
    1216 
    1217     /// \brief Erase a node from the graph.
    1218     ///
    1219     /// Erase a node from the graph.
    1220     ///
    1221     void erase(const Node& n) { Parent::erase(n); }
    1222 
    1223     /// \brief Erase an edge from the graph.
    1224     ///
    1225     /// Erase an edge from the graph.
    1226     ///
    1227     void erase(const Edge& e) { Parent::erase(e); }
     1226    Edge addEdge(Node u, Node v) {
     1227      return Parent::addEdge(u, v);
     1228    }
     1229
     1230    ///\brief Erase a node from the graph.
     1231    ///
     1232    /// This function erases the given node along with its incident arcs
     1233    /// from the graph.
     1234    ///
     1235    /// \note All iterators referencing the removed node or the incident
     1236    /// edges are invalidated, of course.
     1237    void erase(Node n) { Parent::erase(n); }
     1238
     1239    ///\brief Erase an edge from the graph.
     1240    ///
     1241    /// This function erases the given edge from the graph.
     1242    ///
     1243    /// \note All iterators referencing the removed edge are invalidated,
     1244    /// of course.
     1245    void erase(Edge e) { Parent::erase(e); }
    12281246    /// Node validity check
    12291247
    1230     /// This function gives back true if the given node is valid,
    1231     /// ie. it is a real node of the graph.
    1232     ///
    1233     /// \warning A Node pointing to a removed item
    1234     /// could become valid again later if new nodes are
     1248    /// This function gives back \c true if the given node is valid,
     1249    /// i.e. it is a real node of the graph.
     1250    ///
     1251    /// \warning A removed node could become valid again if new nodes are
    12351252    /// added to the graph.
    12361253    bool valid(Node n) const { return Parent::valid(n); }
     1254    /// Edge validity check
     1255
     1256    /// This function gives back \c true if the given edge is valid,
     1257    /// i.e. it is a real edge of the graph.
     1258    ///
     1259    /// \warning A removed edge could become valid again if new edges are
     1260    /// added to the graph.
     1261    bool valid(Edge e) const { return Parent::valid(e); }
    12371262    /// Arc validity check
    12381263
    1239     /// This function gives back true if the given arc is valid,
    1240     /// ie. it is a real arc of the graph.
    1241     ///
    1242     /// \warning An Arc pointing to a removed item
    1243     /// could become valid again later if new edges are
     1264    /// This function gives back \c true if the given arc is valid,
     1265    /// i.e. it is a real arc of the graph.
     1266    ///
     1267    /// \warning A removed arc could become valid again if new edges are
    12441268    /// added to the graph.
    12451269    bool valid(Arc a) const { return Parent::valid(a); }
    1246     /// Edge validity check
    1247 
    1248     /// This function gives back true if the given edge is valid,
    1249     /// ie. it is a real arc of the graph.
    1250     ///
    1251     /// \warning A Edge pointing to a removed item
    1252     /// could become valid again later if new edges are
    1253     /// added to the graph.
    1254     bool valid(Edge e) const { return Parent::valid(e); }
    1255     /// \brief Change the end \c u of \c e to \c n
    1256     ///
    1257     /// This function changes the end \c u of \c e to node \c n.
    1258     ///
    1259     ///\note The <tt>EdgeIt</tt>s and <tt>ArcIt</tt>s referencing the
    1260     ///changed edge are invalidated and if the changed node is the
    1261     ///base node of an iterator then this iterator is also
    1262     ///invalidated.
     1270
     1271    /// \brief Change the first node of an edge.
     1272    ///
     1273    /// This function changes the first node of the given edge \c e to \c n.
     1274    ///
     1275    ///\note \c EdgeIt and \c ArcIt iterators referencing the
     1276    ///changed edge are invalidated and all other iterators whose
     1277    ///base node is the changed node are also invalidated.
    12631278    ///
    12641279    ///\warning This functionality cannot be used together with the
     
    12671282      Parent::changeU(e,n);
    12681283    }
    1269     /// \brief Change the end \c v of \c e to \c n
    1270     ///
    1271     /// This function changes the end \c v of \c e to \c n.
    1272     ///
    1273     ///\note The <tt>EdgeIt</tt>s referencing the changed edge remain
    1274     ///valid, however <tt>ArcIt</tt>s and if the changed node is the
    1275     ///base node of an iterator then this iterator is invalidated.
     1284    /// \brief Change the second node of an edge.
     1285    ///
     1286    /// This function changes the second node of the given edge \c e to \c n.
     1287    ///
     1288    ///\note \c EdgeIt iterators referencing the changed edge remain
     1289    ///valid, but \c ArcIt iterators referencing the changed edge and
     1290    ///all other iterators whose base node is the changed node are also
     1291    ///invalidated.
    12761292    ///
    12771293    ///\warning This functionality cannot be used together with the
     
    12801296      Parent::changeV(e,n);
    12811297    }
     1298
    12821299    /// \brief Contract two nodes.
    12831300    ///
    1284     /// This function contracts two nodes.
    1285     /// Node \p b will be removed but instead of deleting
    1286     /// its neighboring arcs, they will be joined to \p a.
    1287     /// The last parameter \p r controls whether to remove loops. \c true
    1288     /// means that loops will be removed.
    1289     ///
    1290     /// \note The <tt>ArcIt</tt>s referencing a moved arc remain
    1291     /// valid.
     1301    /// This function contracts the given two nodes.
     1302    /// Node \c b is removed, but instead of deleting
     1303    /// its incident edges, they are joined to node \c a.
     1304    /// If the last parameter \c r is \c true (this is the default value),
     1305    /// then the newly created loops are removed.
     1306    ///
     1307    /// \note The moved edges are joined to node \c a using changeU()
     1308    /// or changeV(), thus all edge and arc iterators whose base node is
     1309    /// \c b are invalidated.
     1310    /// Moreover all iterators referencing node \c b or the removed
     1311    /// loops are also invalidated. Other iterators remain valid.
    12921312    ///
    12931313    ///\warning This functionality cannot be used together with the
     
    13081328    }
    13091329
     1330    ///Clear the graph.
     1331
     1332    ///This function erases all nodes and arcs from the graph.
     1333    ///
     1334    ///\note All iterators of the graph are invalidated, of course.
     1335    void clear() {
     1336      Parent::clear();
     1337    }
     1338
     1339    /// Reserve memory for nodes.
     1340
     1341    /// Using this function, it is possible to avoid superfluous memory
     1342    /// allocation: if you know that the graph you want to build will
     1343    /// be large (e.g. it will contain millions of nodes and/or edges),
     1344    /// then it is worth reserving space for this amount before starting
     1345    /// to build the graph.
     1346    /// \sa reserveEdge()
     1347    void reserveNode(int n) { nodes.reserve(n); };
     1348
     1349    /// Reserve memory for edges.
     1350
     1351    /// Using this function, it is possible to avoid superfluous memory
     1352    /// allocation: if you know that the graph you want to build will
     1353    /// be large (e.g. it will contain millions of nodes and/or edges),
     1354    /// then it is worth reserving space for this amount before starting
     1355    /// to build the graph.
     1356    /// \sa reserveNode()
     1357    void reserveEdge(int m) { arcs.reserve(2 * m); };
    13101358
    13111359    /// \brief Class to make a snapshot of the graph and restore
     
    13171365    /// using the restore() function.
    13181366    ///
    1319     /// \warning Edge and node deletions and other modifications
    1320     /// (e.g. changing nodes of edges, contracting nodes) cannot be
    1321     /// restored. These events invalidate the snapshot.
     1367    /// \note After a state is restored, you cannot restore a later state,
     1368    /// i.e. you cannot add the removed nodes and edges again using
     1369    /// another Snapshot instance.
     1370    ///
     1371    /// \warning Node and edge deletions and other modifications
     1372    /// (e.g. changing the end-nodes of edges or contracting nodes)
     1373    /// cannot be restored. These events invalidate the snapshot.
     1374    /// However, the edges and nodes that were added to the graph after
     1375    /// making the current snapshot can be removed without invalidating it.
    13221376    class Snapshot {
    13231377    protected:
     
    14891543      ///
    14901544      /// Default constructor.
    1491       /// To actually make a snapshot you must call save().
     1545      /// You have to call save() to actually make a snapshot.
    14921546      Snapshot()
    14931547        : graph(0), node_observer_proxy(*this),
     
    14961550      /// \brief Constructor that immediately makes a snapshot.
    14971551      ///
    1498       /// This constructor immediately makes a snapshot of the graph.
    1499       /// \param _graph The graph we make a snapshot of.
    1500       Snapshot(ListGraph &_graph)
     1552      /// This constructor immediately makes a snapshot of the given graph.
     1553      Snapshot(ListGraph &gr)
    15011554        : node_observer_proxy(*this),
    15021555          edge_observer_proxy(*this) {
    1503         attach(_graph);
     1556        attach(gr);
    15041557      }
    15051558
    15061559      /// \brief Make a snapshot.
    15071560      ///
    1508       /// Make a snapshot of the graph.
    1509       ///
    1510       /// This function can be called more than once. In case of a repeated
     1561      /// This function makes a snapshot of the given graph.
     1562      /// It can be called more than once. In case of a repeated
    15111563      /// call, the previous snapshot gets lost.
    1512       /// \param _graph The graph we make the snapshot of.
    1513       void save(ListGraph &_graph) {
     1564      void save(ListGraph &gr) {
    15141565        if (attached()) {
    15151566          detach();
    15161567          clear();
    15171568        }
    1518         attach(_graph);
     1569        attach(gr);
    15191570      }
    15201571
    15211572      /// \brief Undo the changes until the last snapshot.
    1522       //
    1523       /// Undo the changes until the last snapshot created by save().
     1573      ///
     1574      /// This function undos the changes until the last snapshot
     1575      /// created by save() or Snapshot(ListGraph&).
     1576      ///
     1577      /// \warning This method invalidates the snapshot, i.e. repeated
     1578      /// restoring is not supported unless you call save() again.
    15241579      void restore() {
    15251580        detach();
     
    15351590      }
    15361591
    1537       /// \brief Gives back true when the snapshot is valid.
     1592      /// \brief Returns \c true if the snapshot is valid.
    15381593      ///
    1539       /// Gives back true when the snapshot is valid.
     1594      /// This function returns \c true if the snapshot is valid.
    15401595      bool valid() const {
    15411596        return attached();
  • TabularUnified lemon/lp.h

    r674 r956  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2008
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    8585#elif LEMON_HAVE_CLP
    8686# define DEFAULT_LP CLP
    87   typedef ClpLp Lp; 
     87  typedef ClpLp Lp;
    8888#endif
    8989#endif
  • TabularUnified lemon/lp_base.cc

    r557 r956  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2008
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
  • TabularUnified lemon/lp_base.h

    r1092 r1100  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2008
     5 * Copyright (C) 2003-2011
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    8383      MESSAGE_VERBOSE
    8484    };
    85    
     85
    8686
    8787    ///The floating point type used by the solver
     
    115115      typedef True LpCol;
    116116      /// Default constructor
    117      
     117
    118118      /// \warning The default constructor sets the Col to an
    119119      /// undefined value.
    120120      Col() {}
    121121      /// Invalid constructor \& conversion.
    122      
     122
    123123      /// This constructor initializes the Col to be invalid.
    124       /// \sa Invalid for more details.     
     124      /// \sa Invalid for more details.
    125125      Col(const Invalid&) : _id(-1) {}
    126126      /// Equality operator
     
    147147    ///Iterator for iterate over the columns of an LP problem
    148148
    149     /// Its usage is quite simple, for example you can count the number
     149    /// Its usage is quite simple, for example, you can count the number
    150150    /// of columns in an LP \c lp:
    151151    ///\code
     
    157157    public:
    158158      /// Default constructor
    159      
     159
    160160      /// \warning The default constructor sets the iterator
    161161      /// to an undefined value.
    162162      ColIt() {}
    163163      /// Sets the iterator to the first Col
    164      
     164
    165165      /// Sets the iterator to the first Col.
    166166      ///
     
    170170      }
    171171      /// Invalid constructor \& conversion
    172      
     172
    173173      /// Initialize the iterator to be invalid.
    174174      /// \sa Invalid for more details.
    175175      ColIt(const Invalid&) : Col(INVALID) {}
    176176      /// Next column
    177      
     177
    178178      /// Assign the iterator to the next column.
    179179      ///
     
    210210      typedef True LpRow;
    211211      /// Default constructor
    212      
     212
    213213      /// \warning The default constructor sets the Row to an
    214214      /// undefined value.
    215215      Row() {}
    216216      /// Invalid constructor \& conversion.
    217      
     217
    218218      /// This constructor initializes the Row to be invalid.
    219       /// \sa Invalid for more details.     
     219      /// \sa Invalid for more details.
    220220      Row(const Invalid&) : _id(-1) {}
    221221      /// Equality operator
     
    225225      bool operator==(Row r) const  {return _id == r._id;}
    226226      /// Inequality operator
    227      
     227
    228228      /// \sa operator==(Row r)
    229229      ///
     
    242242    ///Iterator for iterate over the rows of an LP problem
    243243
    244     /// Its usage is quite simple, for example you can count the number
     244    /// Its usage is quite simple, for example, you can count the number
    245245    /// of rows in an LP \c lp:
    246246    ///\code
     
    252252    public:
    253253      /// Default constructor
    254      
     254
    255255      /// \warning The default constructor sets the iterator
    256256      /// to an undefined value.
    257257      RowIt() {}
    258258      /// Sets the iterator to the first Row
    259      
     259
    260260      /// Sets the iterator to the first Row.
    261261      ///
     
    265265      }
    266266      /// Invalid constructor \& conversion
    267      
     267
    268268      /// Initialize the iterator to be invalid.
    269269      /// \sa Invalid for more details.
    270270      RowIt(const Invalid&) : Row(INVALID) {}
    271271      /// Next row
    272      
     272
    273273      /// Assign the iterator to the next row.
    274274      ///
     
    348348      typedef True SolverExpr;
    349349      /// Default constructor
    350      
     350
    351351      /// Construct an empty expression, the coefficients and
    352352      /// the constant component are initialized to zero.
     
    449449
    450450      ///Iterator over the expression
    451      
    452       ///The iterator iterates over the terms of the expression. 
    453       /// 
     451
     452      ///The iterator iterates over the terms of the expression.
     453      ///
    454454      ///\code
    455455      ///double s=0;
     
    465465
    466466        /// Sets the iterator to the first term
    467        
     467
    468468        /// Sets the iterator to the first term of the expression.
    469469        ///
     
    482482        const Value& operator*() const { return _it->second; }
    483483        /// Next term
    484        
     484
    485485        /// Assign the iterator to the next term.
    486486        ///
     
    494494
    495495      /// Const iterator over the expression
    496      
    497       ///The iterator iterates over the terms of the expression. 
    498       /// 
     496
     497      ///The iterator iterates over the terms of the expression.
     498      ///
    499499      ///\code
    500500      ///double s=0;
     
    510510
    511511        /// Sets the iterator to the first term
    512        
     512
    513513        /// Sets the iterator to the first term of the expression.
    514514        ///
     
    525525
    526526        /// Next term
    527        
     527
    528528        /// Assign the iterator to the next term.
    529529        ///
     
    674674      typedef True SolverExpr;
    675675      /// Default constructor
    676      
     676
    677677      /// Construct an empty expression, the coefficients are
    678678      /// initialized to zero.
     
    709709      }
    710710      /// \brief Removes the coefficients which's absolute value does
    711       /// not exceed \c epsilon. 
     711      /// not exceed \c epsilon.
    712712      void simplify(Value epsilon = 0.0) {
    713713        std::map<int, Value>::iterator it=comps.begin();
     
    758758
    759759      ///Iterator over the expression
    760      
    761       ///The iterator iterates over the terms of the expression. 
    762       /// 
     760
     761      ///The iterator iterates over the terms of the expression.
     762      ///
    763763      ///\code
    764764      ///double s=0;
     
    774774
    775775        /// Sets the iterator to the first term
    776        
     776
    777777        /// Sets the iterator to the first term of the expression.
    778778        ///
     
    792792
    793793        /// Next term
    794        
     794
    795795        /// Assign the iterator to the next term.
    796796        ///
     
    804804
    805805      ///Iterator over the expression
    806      
    807       ///The iterator iterates over the terms of the expression. 
    808       /// 
     806
     807      ///The iterator iterates over the terms of the expression.
     808      ///
    809809      ///\code
    810810      ///double s=0;
     
    820820
    821821        /// Sets the iterator to the first term
    822        
     822
    823823        /// Sets the iterator to the first term of the expression.
    824824        ///
     
    835835
    836836        /// Next term
    837        
     837
    838838        /// Assign the iterator to the next term.
    839839        ///
     
    943943    virtual int _addCol() = 0;
    944944    virtual int _addRow() = 0;
     945
     946    virtual int _addRow(Value l, ExprIterator b, ExprIterator e, Value u) {
     947      int row = _addRow();
     948      _setRowCoeffs(row, b, e);
     949      _setRowLowerBound(row, l);
     950      _setRowUpperBound(row, u);
     951      return row;
     952    }
    945953
    946954    virtual void _eraseCol(int col) = 0;
     
    12081216    ///\return The created row.
    12091217    Row addRow(Value l,const Expr &e, Value u) {
    1210       Row r=addRow();
    1211       row(r,l,e,u);
     1218      Row r;
     1219      e.simplify();
     1220      r._id = _addRowId(_addRow(l - *e, ExprIterator(e.comps.begin(), cols),
     1221                                ExprIterator(e.comps.end(), cols), u - *e));
    12121222      return r;
    12131223    }
     
    12181228    ///\return The created row.
    12191229    Row addRow(const Constr &c) {
    1220       Row r=addRow();
    1221       row(r,c);
     1230      Row r;
     1231      c.expr().simplify();
     1232      r._id = _addRowId(_addRow(c.lowerBounded()?c.lowerBound()-*c.expr():-INF,
     1233                                ExprIterator(c.expr().comps.begin(), cols),
     1234                                ExprIterator(c.expr().comps.end(), cols),
     1235                                c.upperBounded()?c.upperBound()-*c.expr():INF));
    12221236      return r;
    12231237    }
     
    18041818    enum VarStatus {
    18051819      /// The variable is in the basis
    1806       BASIC, 
     1820      BASIC,
    18071821      /// The variable is free, but not basic
    18081822      FREE,
    1809       /// The variable has active lower bound 
     1823      /// The variable has active lower bound
    18101824      LOWER,
    18111825      /// The variable has active upper bound
     
    18861900    }
    18871901    /// Returns a component of the primal ray
    1888    
     1902
    18891903    /// The primal ray is solution of the modified primal problem,
    18901904    /// where we change each finite bound to 0, and we looking for a
     
    19201934
    19211935    /// Returns a component of the dual ray
    1922    
     1936
    19231937    /// The dual ray is solution of the modified primal problem, where
    19241938    /// we change each finite bound to 0 (i.e. the objective function
     
    20622076    }
    20632077    ///The value of the objective function
    2064    
     2078
    20652079    ///\return
    20662080    ///- \ref INF or -\ref INF means either infeasibility or unboundedness
  • TabularUnified lemon/lp_skeleton.cc

    r623 r956  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2008
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    2929
    3030  int SkeletonSolverBase::_addRow()
     31  {
     32    return ++row_num;
     33  }
     34
     35  int SkeletonSolverBase::_addRow(Value, ExprIterator, ExprIterator, Value)
    3136  {
    3237    return ++row_num;
  • TabularUnified lemon/lp_skeleton.h

    r623 r956  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2008
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    2424///\file
    2525///\brief Skeleton file to implement LP/MIP solver interfaces
    26 /// 
     26///
    2727///The classes in this file do nothing, but they can serve as skeletons when
    2828///implementing an interface to new solvers.
     
    3030
    3131  ///A skeleton class to implement LP/MIP solver base interface
    32  
     32
    3333  ///This class does nothing, but it can serve as a skeleton when
    3434  ///implementing an interface to new solvers.
     
    4545    /// \e
    4646    virtual int _addRow();
     47    /// \e
     48    virtual int _addRow(Value l, ExprIterator b, ExprIterator e, Value u);
    4749    /// \e
    4850    virtual void _eraseCol(int i);
  • TabularUnified lemon/maps.h

    r731 r1084  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2011
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    2323#include <functional>
    2424#include <vector>
     25#include <map>
    2526
    2627#include <lemon/core.h>
     
    2930///\ingroup maps
    3031///\brief Miscellaneous property maps
    31 
    32 #include <map>
    3332
    3433namespace lemon {
     
    5857  /// but data written to it is not required (i.e. it will be sent to
    5958  /// <tt>/dev/null</tt>).
    60   /// It conforms the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
     59  /// It conforms to the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
    6160  ///
    6261  /// \sa ConstMap
     
    9190  ///
    9291  /// In other aspects it is equivalent to \c NullMap.
    93   /// So it conforms the \ref concepts::ReadWriteMap "ReadWriteMap"
     92  /// So it conforms to the \ref concepts::ReadWriteMap "ReadWriteMap"
    9493  /// concept, but it absorbs the data written to it.
    9594  ///
     
    160159  ///
    161160  /// In other aspects it is equivalent to \c NullMap.
    162   /// So it conforms the \ref concepts::ReadWriteMap "ReadWriteMap"
     161  /// So it conforms to the \ref concepts::ReadWriteMap "ReadWriteMap"
    163162  /// concept, but it absorbs the data written to it.
    164163  ///
     
    232231  /// This map is essentially a wrapper for \c std::vector. It assigns
    233232  /// values to integer keys from the range <tt>[0..size-1]</tt>.
    234   /// It can be used with some data structures, for example
    235   /// \c UnionFind, \c BinHeap, when the used items are small
    236   /// integers. This map conforms the \ref concepts::ReferenceMap
     233  /// It can be used together with some data structures, e.g.
     234  /// heap types and \c UnionFind, when the used items are small
     235  /// integers. This map conforms to the \ref concepts::ReferenceMap
    237236  /// "ReferenceMap" concept.
    238237  ///
     
    342341  /// stored actually. This value can be different from the default
    343342  /// contructed value (i.e. \c %Value()).
    344   /// This type conforms the \ref concepts::ReferenceMap "ReferenceMap"
     343  /// This type conforms to the \ref concepts::ReferenceMap "ReferenceMap"
    345344  /// concept.
    346345  ///
     
    350349  /// The name of this type also refers to this important usage.
    351350  ///
    352   /// Apart form that this map can be used in many other cases since it
     351  /// Apart form that, this map can be used in many other cases since it
    353352  /// is based on \c std::map, which is a general associative container.
    354   /// However keep in mind that it is usually not as efficient as other
     353  /// However, keep in mind that it is usually not as efficient as other
    355354  /// maps.
    356355  ///
     
    708707  /// The \c Key type of it is inherited from \c M and the \c Value
    709708  /// type is \c V.
    710   /// This type conforms the \ref concepts::ReadMap "ReadMap" concept.
     709  /// This type conforms to the \ref concepts::ReadMap "ReadMap" concept.
    711710  ///
    712711  /// The simplest way of using this map is through the convertMap()
     
    17871786  /// The most important usage of it is storing certain nodes or arcs
    17881787  /// that were marked \c true by an algorithm.
    1789   /// For example it makes easier to store the nodes in the processing
     1788  /// For example, it makes easier to store the nodes in the processing
    17901789  /// order of Dfs algorithm, as the following examples show.
    17911790  /// \code
    17921791  ///   std::vector<Node> v;
    1793   ///   dfs(g,s).processedMap(loggerBoolMap(std::back_inserter(v))).run();
     1792  ///   dfs(g).processedMap(loggerBoolMap(std::back_inserter(v))).run(s);
    17941793  /// \endcode
    17951794  /// \code
    17961795  ///   std::vector<Node> v(countNodes(g));
    1797   ///   dfs(g,s).processedMap(loggerBoolMap(v.begin())).run();
     1796  ///   dfs(g).processedMap(loggerBoolMap(v.begin())).run(s);
    17981797  /// \endcode
    17991798  ///
     
    18021801  ///
    18031802  /// \note LoggerBoolMap is just \ref concepts::WriteMap "writable", so
    1804   /// it cannot be used when a readable map is needed, for example as
     1803  /// it cannot be used when a readable map is needed, for example, as
    18051804  /// \c ReachedMap for \c Bfs, \c Dfs and \c Dijkstra algorithms.
    18061805  ///
     
    18191818  ///
    18201819  /// IdMap provides a unique and immutable id for each item of the
    1821   /// same type (\c Node, \c Arc or \c Edge) in a graph. This id is 
     1820  /// same type (\c Node, \c Arc or \c Edge) in a graph. This id is
    18221821  ///  - \b unique: different items get different ids,
    18231822  ///  - \b immutable: the id of an item does not change (even if you
     
    18271826  /// the items stored in the graph, which is returned by the \c id()
    18281827  /// function of the graph. This map can be inverted with its member
    1829   /// class \c InverseMap or with the \c operator() member.
     1828  /// class \c InverseMap or with the \c operator()() member.
    18301829  ///
    18311830  /// \tparam GR The graph type.
     
    18671866  public:
    18681867
    1869     /// \brief This class represents the inverse of its owner (IdMap).
    1870     ///
    1871     /// This class represents the inverse of its owner (IdMap).
     1868    /// \brief The inverse map type of IdMap.
     1869    ///
     1870    /// The inverse map type of IdMap. The subscript operator gives back
     1871    /// an item by its id.
     1872    /// This type conforms to the \ref concepts::ReadMap "ReadMap" concept.
    18721873    /// \see inverse()
    18731874    class InverseMap {
     
    18841885      explicit InverseMap(const IdMap& map) : _graph(map._graph) {}
    18851886
    1886       /// \brief Gives back the given item from its id.
     1887      /// \brief Gives back an item by its id.
    18871888      ///
    1888       /// Gives back the given item from its id.
     1889      /// Gives back an item by its id.
    18891890      Item operator[](int id) const { return _graph->fromId(id, Item());}
    18901891
     
    18991900  };
    19001901
     1902  /// \brief Returns an \c IdMap class.
     1903  ///
     1904  /// This function just returns an \c IdMap class.
     1905  /// \relates IdMap
     1906  template <typename K, typename GR>
     1907  inline IdMap<GR, K> idMap(const GR& graph) {
     1908    return IdMap<GR, K>(graph);
     1909  }
    19011910
    19021911  /// \brief General cross reference graph map type.
     
    19051914  /// It wraps a standard graph map (\c NodeMap, \c ArcMap or \c EdgeMap)
    19061915  /// and if a key is set to a new value, then stores it in the inverse map.
    1907   /// The values of the map can be accessed
    1908   /// with stl compatible forward iterator.
     1916  /// The graph items can be accessed by their values either using
     1917  /// \c InverseMap or \c operator()(), and the values of the map can be
     1918  /// accessed with an STL compatible forward iterator (\c ValueIt).
     1919  ///
     1920  /// This map is intended to be used when all associated values are
     1921  /// different (the map is actually invertable) or there are only a few
     1922  /// items with the same value.
     1923  /// Otherwise consider to use \c IterableValueMap, which is more
     1924  /// suitable and more efficient for such cases. It provides iterators
     1925  /// to traverse the items with the same associated value, but
     1926  /// it does not have \c InverseMap.
    19091927  ///
    19101928  /// This type is not reference map, so it cannot be modified with
     
    19471965    /// \brief Forward iterator for values.
    19481966    ///
    1949     /// This iterator is an stl compatible forward
     1967    /// This iterator is an STL compatible forward
    19501968    /// iterator on the values of the map. The values can
    19511969    /// be accessed in the <tt>[beginValue, endValue)</tt> range.
    19521970    /// They are considered with multiplicity, so each value is
    19531971    /// traversed for each item it is assigned to.
    1954     class ValueIterator
     1972    class ValueIt
    19551973      : public std::iterator<std::forward_iterator_tag, Value> {
    19561974      friend class CrossRefMap;
    19571975    private:
    1958       ValueIterator(typename Container::const_iterator _it)
     1976      ValueIt(typename Container::const_iterator _it)
    19591977        : it(_it) {}
    19601978    public:
    19611979
    1962       ValueIterator() {}
    1963 
    1964       ValueIterator& operator++() { ++it; return *this; }
    1965       ValueIterator operator++(int) {
    1966         ValueIterator tmp(*this);
     1980      /// Constructor
     1981      ValueIt() {}
     1982
     1983      /// \e
     1984      ValueIt& operator++() { ++it; return *this; }
     1985      /// \e
     1986      ValueIt operator++(int) {
     1987        ValueIt tmp(*this);
    19671988        operator++();
    19681989        return tmp;
    19691990      }
    19701991
     1992      /// \e
    19711993      const Value& operator*() const { return it->first; }
     1994      /// \e
    19721995      const Value* operator->() const { return &(it->first); }
    19731996
    1974       bool operator==(ValueIterator jt) const { return it == jt.it; }
    1975       bool operator!=(ValueIterator jt) const { return it != jt.it; }
     1997      /// \e
     1998      bool operator==(ValueIt jt) const { return it == jt.it; }
     1999      /// \e
     2000      bool operator!=(ValueIt jt) const { return it != jt.it; }
    19762001
    19772002    private:
     
    19792004    };
    19802005
     2006    /// Alias for \c ValueIt
     2007    typedef ValueIt ValueIterator;
     2008
    19812009    /// \brief Returns an iterator to the first value.
    19822010    ///
    1983     /// Returns an stl compatible iterator to the
     2011    /// Returns an STL compatible iterator to the
    19842012    /// first value of the map. The values of the
    19852013    /// map can be accessed in the <tt>[beginValue, endValue)</tt>
    19862014    /// range.
    1987     ValueIterator beginValue() const {
    1988       return ValueIterator(_inv_map.begin());
     2015    ValueIt beginValue() const {
     2016      return ValueIt(_inv_map.begin());
    19892017    }
    19902018
    19912019    /// \brief Returns an iterator after the last value.
    19922020    ///
    1993     /// Returns an stl compatible iterator after the
     2021    /// Returns an STL compatible iterator after the
    19942022    /// last value of the map. The values of the
    19952023    /// map can be accessed in the <tt>[beginValue, endValue)</tt>
    19962024    /// range.
    1997     ValueIterator endValue() const {
    1998       return ValueIterator(_inv_map.end());
     2025    ValueIt endValue() const {
     2026      return ValueIt(_inv_map.end());
    19992027    }
    20002028
     
    20332061      typename Container::const_iterator it = _inv_map.find(val);
    20342062      return it != _inv_map.end() ? it->second : INVALID;
     2063    }
     2064
     2065    /// \brief Returns the number of items with the given value.
     2066    ///
     2067    /// This function returns the number of items with the given value
     2068    /// associated with it.
     2069    int count(const Value &val) const {
     2070      return _inv_map.count(val);
    20352071    }
    20362072
     
    20842120  public:
    20852121
    2086     /// \brief The inverse map type.
    2087     ///
    2088     /// The inverse of this map. The subscript operator of the map
    2089     /// gives back the item that was last assigned to the value.
     2122    /// \brief The inverse map type of CrossRefMap.
     2123    ///
     2124    /// The inverse map type of CrossRefMap. The subscript operator gives
     2125    /// back an item by its value.
     2126    /// This type conforms to the \ref concepts::ReadMap "ReadMap" concept.
     2127    /// \see inverse()
    20902128    class InverseMap {
    20912129    public:
     
    21142152    };
    21152153
    2116     /// \brief It gives back the read-only inverse map.
    2117     ///
    2118     /// It gives back the read-only inverse map.
     2154    /// \brief Gives back the inverse of the map.
     2155    ///
     2156    /// Gives back the inverse of the CrossRefMap.
    21192157    InverseMap inverse() const {
    21202158      return InverseMap(*this);
     
    21232161  };
    21242162
    2125   /// \brief Provides continuous and unique ID for the
     2163  /// \brief Provides continuous and unique id for the
    21262164  /// items of a graph.
    21272165  ///
    21282166  /// RangeIdMap provides a unique and continuous
    2129   /// ID for each item of a given type (\c Node, \c Arc or
     2167  /// id for each item of a given type (\c Node, \c Arc or
    21302168  /// \c Edge) in a graph. This id is
    21312169  ///  - \b unique: different items get different ids,
     
    21382176  /// the \c id() function of the graph or \ref IdMap.
    21392177  /// This map can be inverted with its member class \c InverseMap,
    2140   /// or with the \c operator() member.
     2178  /// or with the \c operator()() member.
    21412179  ///
    21422180  /// \tparam GR The graph type.
     
    22662304    }
    22672305
    2268     /// \brief Gives back the \e RangeId of the item
    2269     ///
    2270     /// Gives back the \e RangeId of the item.
     2306    /// \brief Gives back the \e range \e id of the item
     2307    ///
     2308    /// Gives back the \e range \e id of the item.
    22712309    int operator[](const Item& item) const {
    22722310      return Map::operator[](item);
    22732311    }
    22742312
    2275     /// \brief Gives back the item belonging to a \e RangeId
    2276     /// 
    2277     /// Gives back the item belonging to a \e RangeId.
     2313    /// \brief Gives back the item belonging to a \e range \e id
     2314    ///
     2315    /// Gives back the item belonging to the given \e range \e id.
    22782316    Item operator()(int id) const {
    22792317      return _inv_map[id];
     
    22892327    /// \brief The inverse map type of RangeIdMap.
    22902328    ///
    2291     /// The inverse map type of RangeIdMap.
     2329    /// The inverse map type of RangeIdMap. The subscript operator gives
     2330    /// back an item by its \e range \e id.
     2331    /// This type conforms to the \ref concepts::ReadMap "ReadMap" concept.
    22922332    class InverseMap {
    22932333    public:
     
    23072347      ///
    23082348      /// Subscript operator. It gives back the item
    2309       /// that the descriptor currently belongs to.
     2349      /// that the given \e range \e id currently belongs to.
    23102350      Value operator[](const Key& key) const {
    23112351        return _inverted(key);
     
    23252365    /// \brief Gives back the inverse of the map.
    23262366    ///
    2327     /// Gives back the inverse of the map.
     2367    /// Gives back the inverse of the RangeIdMap.
    23282368    const InverseMap inverse() const {
    23292369      return InverseMap(*this);
    23302370    }
     2371  };
     2372
     2373  /// \brief Returns a \c RangeIdMap class.
     2374  ///
     2375  /// This function just returns an \c RangeIdMap class.
     2376  /// \relates RangeIdMap
     2377  template <typename K, typename GR>
     2378  inline RangeIdMap<GR, K> rangeIdMap(const GR& graph) {
     2379    return RangeIdMap<GR, K>(graph);
     2380  }
     2381
     2382  /// \brief Dynamic iterable \c bool map.
     2383  ///
     2384  /// This class provides a special graph map type which can store a
     2385  /// \c bool value for graph items (\c Node, \c Arc or \c Edge).
     2386  /// For both \c true and \c false values it is possible to iterate on
     2387  /// the keys mapped to the value.
     2388  ///
     2389  /// This type is a reference map, so it can be modified with the
     2390  /// subscript operator.
     2391  ///
     2392  /// \tparam GR The graph type.
     2393  /// \tparam K The key type of the map (\c GR::Node, \c GR::Arc or
     2394  /// \c GR::Edge).
     2395  ///
     2396  /// \see IterableIntMap, IterableValueMap
     2397  /// \see CrossRefMap
     2398  template <typename GR, typename K>
     2399  class IterableBoolMap
     2400    : protected ItemSetTraits<GR, K>::template Map<int>::Type {
     2401  private:
     2402    typedef GR Graph;
     2403
     2404    typedef typename ItemSetTraits<GR, K>::ItemIt KeyIt;
     2405    typedef typename ItemSetTraits<GR, K>::template Map<int>::Type Parent;
     2406
     2407    std::vector<K> _array;
     2408    int _sep;
     2409
     2410  public:
     2411
     2412    /// Indicates that the map is reference map.
     2413    typedef True ReferenceMapTag;
     2414
     2415    /// The key type
     2416    typedef K Key;
     2417    /// The value type
     2418    typedef bool Value;
     2419    /// The const reference type.
     2420    typedef const Value& ConstReference;
     2421
     2422  private:
     2423
     2424    int position(const Key& key) const {
     2425      return Parent::operator[](key);
     2426    }
     2427
     2428  public:
     2429
     2430    /// \brief Reference to the value of the map.
     2431    ///
     2432    /// This class is similar to the \c bool type. It can be converted to
     2433    /// \c bool and it provides the same operators.
     2434    class Reference {
     2435      friend class IterableBoolMap;
     2436    private:
     2437      Reference(IterableBoolMap& map, const Key& key)
     2438        : _key(key), _map(map) {}
     2439    public:
     2440
     2441      Reference& operator=(const Reference& value) {
     2442        _map.set(_key, static_cast<bool>(value));
     2443         return *this;
     2444      }
     2445
     2446      operator bool() const {
     2447        return static_cast<const IterableBoolMap&>(_map)[_key];
     2448      }
     2449
     2450      Reference& operator=(bool value) {
     2451        _map.set(_key, value);
     2452        return *this;
     2453      }
     2454      Reference& operator&=(bool value) {
     2455        _map.set(_key, _map[_key] & value);
     2456        return *this;
     2457      }
     2458      Reference& operator|=(bool value) {
     2459        _map.set(_key, _map[_key] | value);
     2460        return *this;
     2461      }
     2462      Reference& operator^=(bool value) {
     2463        _map.set(_key, _map[_key] ^ value);
     2464        return *this;
     2465      }
     2466    private:
     2467      Key _key;
     2468      IterableBoolMap& _map;
     2469    };
     2470
     2471    /// \brief Constructor of the map with a default value.
     2472    ///
     2473    /// Constructor of the map with a default value.
     2474    explicit IterableBoolMap(const Graph& graph, bool def = false)
     2475      : Parent(graph) {
     2476      typename Parent::Notifier* nf = Parent::notifier();
     2477      Key it;
     2478      for (nf->first(it); it != INVALID; nf->next(it)) {
     2479        Parent::set(it, _array.size());
     2480        _array.push_back(it);
     2481      }
     2482      _sep = (def ? _array.size() : 0);
     2483    }
     2484
     2485    /// \brief Const subscript operator of the map.
     2486    ///
     2487    /// Const subscript operator of the map.
     2488    bool operator[](const Key& key) const {
     2489      return position(key) < _sep;
     2490    }
     2491
     2492    /// \brief Subscript operator of the map.
     2493    ///
     2494    /// Subscript operator of the map.
     2495    Reference operator[](const Key& key) {
     2496      return Reference(*this, key);
     2497    }
     2498
     2499    /// \brief Set operation of the map.
     2500    ///
     2501    /// Set operation of the map.
     2502    void set(const Key& key, bool value) {
     2503      int pos = position(key);
     2504      if (value) {
     2505        if (pos < _sep) return;
     2506        Key tmp = _array[_sep];
     2507        _array[_sep] = key;
     2508        Parent::set(key, _sep);
     2509        _array[pos] = tmp;
     2510        Parent::set(tmp, pos);
     2511        ++_sep;
     2512      } else {
     2513        if (pos >= _sep) return;
     2514        --_sep;
     2515        Key tmp = _array[_sep];
     2516        _array[_sep] = key;
     2517        Parent::set(key, _sep);
     2518        _array[pos] = tmp;
     2519        Parent::set(tmp, pos);
     2520      }
     2521    }
     2522
     2523    /// \brief Set all items.
     2524    ///
     2525    /// Set all items in the map.
     2526    /// \note Constant time operation.
     2527    void setAll(bool value) {
     2528      _sep = (value ? _array.size() : 0);
     2529    }
     2530
     2531    /// \brief Returns the number of the keys mapped to \c true.
     2532    ///
     2533    /// Returns the number of the keys mapped to \c true.
     2534    int trueNum() const {
     2535      return _sep;
     2536    }
     2537
     2538    /// \brief Returns the number of the keys mapped to \c false.
     2539    ///
     2540    /// Returns the number of the keys mapped to \c false.
     2541    int falseNum() const {
     2542      return _array.size() - _sep;
     2543    }
     2544
     2545    /// \brief Iterator for the keys mapped to \c true.
     2546    ///
     2547    /// Iterator for the keys mapped to \c true. It works
     2548    /// like a graph item iterator, it can be converted to
     2549    /// the key type of the map, incremented with \c ++ operator, and
     2550    /// if the iterator leaves the last valid key, it will be equal to
     2551    /// \c INVALID.
     2552    class TrueIt : public Key {
     2553    public:
     2554      typedef Key Parent;
     2555
     2556      /// \brief Creates an iterator.
     2557      ///
     2558      /// Creates an iterator. It iterates on the
     2559      /// keys mapped to \c true.
     2560      /// \param map The IterableBoolMap.
     2561      explicit TrueIt(const IterableBoolMap& map)
     2562        : Parent(map._sep > 0 ? map._array[map._sep - 1] : INVALID),
     2563          _map(&map) {}
     2564
     2565      /// \brief Invalid constructor \& conversion.
     2566      ///
     2567      /// This constructor initializes the iterator to be invalid.
     2568      /// \sa Invalid for more details.
     2569      TrueIt(Invalid) : Parent(INVALID), _map(0) {}
     2570
     2571      /// \brief Increment operator.
     2572      ///
     2573      /// Increment operator.
     2574      TrueIt& operator++() {
     2575        int pos = _map->position(*this);
     2576        Parent::operator=(pos > 0 ? _map->_array[pos - 1] : INVALID);
     2577        return *this;
     2578      }
     2579
     2580    private:
     2581      const IterableBoolMap* _map;
     2582    };
     2583
     2584    /// \brief Iterator for the keys mapped to \c false.
     2585    ///
     2586    /// Iterator for the keys mapped to \c false. It works
     2587    /// like a graph item iterator, it can be converted to
     2588    /// the key type of the map, incremented with \c ++ operator, and
     2589    /// if the iterator leaves the last valid key, it will be equal to
     2590    /// \c INVALID.
     2591    class FalseIt : public Key {
     2592    public:
     2593      typedef Key Parent;
     2594
     2595      /// \brief Creates an iterator.
     2596      ///
     2597      /// Creates an iterator. It iterates on the
     2598      /// keys mapped to \c false.
     2599      /// \param map The IterableBoolMap.
     2600      explicit FalseIt(const IterableBoolMap& map)
     2601        : Parent(map._sep < int(map._array.size()) ?
     2602                 map._array.back() : INVALID), _map(&map) {}
     2603
     2604      /// \brief Invalid constructor \& conversion.
     2605      ///
     2606      /// This constructor initializes the iterator to be invalid.
     2607      /// \sa Invalid for more details.
     2608      FalseIt(Invalid) : Parent(INVALID), _map(0) {}
     2609
     2610      /// \brief Increment operator.
     2611      ///
     2612      /// Increment operator.
     2613      FalseIt& operator++() {
     2614        int pos = _map->position(*this);
     2615        Parent::operator=(pos > _map->_sep ? _map->_array[pos - 1] : INVALID);
     2616        return *this;
     2617      }
     2618
     2619    private:
     2620      const IterableBoolMap* _map;
     2621    };
     2622
     2623    /// \brief Iterator for the keys mapped to a given value.
     2624    ///
     2625    /// Iterator for the keys mapped to a given value. It works
     2626    /// like a graph item iterator, it can be converted to
     2627    /// the key type of the map, incremented with \c ++ operator, and
     2628    /// if the iterator leaves the last valid key, it will be equal to
     2629    /// \c INVALID.
     2630    class ItemIt : public Key {
     2631    public:
     2632      typedef Key Parent;
     2633
     2634      /// \brief Creates an iterator with a value.
     2635      ///
     2636      /// Creates an iterator with a value. It iterates on the
     2637      /// keys mapped to the given value.
     2638      /// \param map The IterableBoolMap.
     2639      /// \param value The value.
     2640      ItemIt(const IterableBoolMap& map, bool value)
     2641        : Parent(value ?
     2642                 (map._sep > 0 ?
     2643                  map._array[map._sep - 1] : INVALID) :
     2644                 (map._sep < int(map._array.size()) ?
     2645                  map._array.back() : INVALID)), _map(&map) {}
     2646
     2647      /// \brief Invalid constructor \& conversion.
     2648      ///
     2649      /// This constructor initializes the iterator to be invalid.
     2650      /// \sa Invalid for more details.
     2651      ItemIt(Invalid) : Parent(INVALID), _map(0) {}
     2652
     2653      /// \brief Increment operator.
     2654      ///
     2655      /// Increment operator.
     2656      ItemIt& operator++() {
     2657        int pos = _map->position(*this);
     2658        int _sep = pos >= _map->_sep ? _map->_sep : 0;
     2659        Parent::operator=(pos > _sep ? _map->_array[pos - 1] : INVALID);
     2660        return *this;
     2661      }
     2662
     2663    private:
     2664      const IterableBoolMap* _map;
     2665    };
     2666
     2667  protected:
     2668
     2669    virtual void add(const Key& key) {
     2670      Parent::add(key);
     2671      Parent::set(key, _array.size());
     2672      _array.push_back(key);
     2673    }
     2674
     2675    virtual void add(const std::vector<Key>& keys) {
     2676      Parent::add(keys);
     2677      for (int i = 0; i < int(keys.size()); ++i) {
     2678        Parent::set(keys[i], _array.size());
     2679        _array.push_back(keys[i]);
     2680      }
     2681    }
     2682
     2683    virtual void erase(const Key& key) {
     2684      int pos = position(key);
     2685      if (pos < _sep) {
     2686        --_sep;
     2687        Parent::set(_array[_sep], pos);
     2688        _array[pos] = _array[_sep];
     2689        Parent::set(_array.back(), _sep);
     2690        _array[_sep] = _array.back();
     2691        _array.pop_back();
     2692      } else {
     2693        Parent::set(_array.back(), pos);
     2694        _array[pos] = _array.back();
     2695        _array.pop_back();
     2696      }
     2697      Parent::erase(key);
     2698    }
     2699
     2700    virtual void erase(const std::vector<Key>& keys) {
     2701      for (int i = 0; i < int(keys.size()); ++i) {
     2702        int pos = position(keys[i]);
     2703        if (pos < _sep) {
     2704          --_sep;
     2705          Parent::set(_array[_sep], pos);
     2706          _array[pos] = _array[_sep];
     2707          Parent::set(_array.back(), _sep);
     2708          _array[_sep] = _array.back();
     2709          _array.pop_back();
     2710        } else {
     2711          Parent::set(_array.back(), pos);
     2712          _array[pos] = _array.back();
     2713          _array.pop_back();
     2714        }
     2715      }
     2716      Parent::erase(keys);
     2717    }
     2718
     2719    virtual void build() {
     2720      Parent::build();
     2721      typename Parent::Notifier* nf = Parent::notifier();
     2722      Key it;
     2723      for (nf->first(it); it != INVALID; nf->next(it)) {
     2724        Parent::set(it, _array.size());
     2725        _array.push_back(it);
     2726      }
     2727      _sep = 0;
     2728    }
     2729
     2730    virtual void clear() {
     2731      _array.clear();
     2732      _sep = 0;
     2733      Parent::clear();
     2734    }
     2735
     2736  };
     2737
     2738
     2739  namespace _maps_bits {
     2740    template <typename Item>
     2741    struct IterableIntMapNode {
     2742      IterableIntMapNode() : value(-1) {}
     2743      IterableIntMapNode(int _value) : value(_value) {}
     2744      Item prev, next;
     2745      int value;
     2746    };
     2747  }
     2748
     2749  /// \brief Dynamic iterable integer map.
     2750  ///
     2751  /// This class provides a special graph map type which can store an
     2752  /// integer value for graph items (\c Node, \c Arc or \c Edge).
     2753  /// For each non-negative value it is possible to iterate on the keys
     2754  /// mapped to the value.
     2755  ///
     2756  /// This map is intended to be used with small integer values, for which
     2757  /// it is efficient, and supports iteration only for non-negative values.
     2758  /// If you need large values and/or iteration for negative integers,
     2759  /// consider to use \ref IterableValueMap instead.
     2760  ///
     2761  /// This type is a reference map, so it can be modified with the
     2762  /// subscript operator.
     2763  ///
     2764  /// \note The size of the data structure depends on the largest
     2765  /// value in the map.
     2766  ///
     2767  /// \tparam GR The graph type.
     2768  /// \tparam K The key type of the map (\c GR::Node, \c GR::Arc or
     2769  /// \c GR::Edge).
     2770  ///
     2771  /// \see IterableBoolMap, IterableValueMap
     2772  /// \see CrossRefMap
     2773  template <typename GR, typename K>
     2774  class IterableIntMap
     2775    : protected ItemSetTraits<GR, K>::
     2776        template Map<_maps_bits::IterableIntMapNode<K> >::Type {
     2777  public:
     2778    typedef typename ItemSetTraits<GR, K>::
     2779      template Map<_maps_bits::IterableIntMapNode<K> >::Type Parent;
     2780
     2781    /// The key type
     2782    typedef K Key;
     2783    /// The value type
     2784    typedef int Value;
     2785    /// The graph type
     2786    typedef GR Graph;
     2787
     2788    /// \brief Constructor of the map.
     2789    ///
     2790    /// Constructor of the map. It sets all values to -1.
     2791    explicit IterableIntMap(const Graph& graph)
     2792      : Parent(graph) {}
     2793
     2794    /// \brief Constructor of the map with a given value.
     2795    ///
     2796    /// Constructor of the map with a given value.
     2797    explicit IterableIntMap(const Graph& graph, int value)
     2798      : Parent(graph, _maps_bits::IterableIntMapNode<K>(value)) {
     2799      if (value >= 0) {
     2800        for (typename Parent::ItemIt it(*this); it != INVALID; ++it) {
     2801          lace(it);
     2802        }
     2803      }
     2804    }
     2805
     2806  private:
     2807
     2808    void unlace(const Key& key) {
     2809      typename Parent::Value& node = Parent::operator[](key);
     2810      if (node.value < 0) return;
     2811      if (node.prev != INVALID) {
     2812        Parent::operator[](node.prev).next = node.next;
     2813      } else {
     2814        _first[node.value] = node.next;
     2815      }
     2816      if (node.next != INVALID) {
     2817        Parent::operator[](node.next).prev = node.prev;
     2818      }
     2819      while (!_first.empty() && _first.back() == INVALID) {
     2820        _first.pop_back();
     2821      }
     2822    }
     2823
     2824    void lace(const Key& key) {
     2825      typename Parent::Value& node = Parent::operator[](key);
     2826      if (node.value < 0) return;
     2827      if (node.value >= int(_first.size())) {
     2828        _first.resize(node.value + 1, INVALID);
     2829      }
     2830      node.prev = INVALID;
     2831      node.next = _first[node.value];
     2832      if (node.next != INVALID) {
     2833        Parent::operator[](node.next).prev = key;
     2834      }
     2835      _first[node.value] = key;
     2836    }
     2837
     2838  public:
     2839
     2840    /// Indicates that the map is reference map.
     2841    typedef True ReferenceMapTag;
     2842
     2843    /// \brief Reference to the value of the map.
     2844    ///
     2845    /// This class is similar to the \c int type. It can
     2846    /// be converted to \c int and it has the same operators.
     2847    class Reference {
     2848      friend class IterableIntMap;
     2849    private:
     2850      Reference(IterableIntMap& map, const Key& key)
     2851        : _key(key), _map(map) {}
     2852    public:
     2853
     2854      Reference& operator=(const Reference& value) {
     2855        _map.set(_key, static_cast<const int&>(value));
     2856         return *this;
     2857      }
     2858
     2859      operator const int&() const {
     2860        return static_cast<const IterableIntMap&>(_map)[_key];
     2861      }
     2862
     2863      Reference& operator=(int value) {
     2864        _map.set(_key, value);
     2865        return *this;
     2866      }
     2867      Reference& operator++() {
     2868        _map.set(_key, _map[_key] + 1);
     2869        return *this;
     2870      }
     2871      int operator++(int) {
     2872        int value = _map[_key];
     2873        _map.set(_key, value + 1);
     2874        return value;
     2875      }
     2876      Reference& operator--() {
     2877        _map.set(_key, _map[_key] - 1);
     2878        return *this;
     2879      }
     2880      int operator--(int) {
     2881        int value = _map[_key];
     2882        _map.set(_key, value - 1);
     2883        return value;
     2884      }
     2885      Reference& operator+=(int value) {
     2886        _map.set(_key, _map[_key] + value);
     2887        return *this;
     2888      }
     2889      Reference& operator-=(int value) {
     2890        _map.set(_key, _map[_key] - value);
     2891        return *this;
     2892      }
     2893      Reference& operator*=(int value) {
     2894        _map.set(_key, _map[_key] * value);
     2895        return *this;
     2896      }
     2897      Reference& operator/=(int value) {
     2898        _map.set(_key, _map[_key] / value);
     2899        return *this;
     2900      }
     2901      Reference& operator%=(int value) {
     2902        _map.set(_key, _map[_key] % value);
     2903        return *this;
     2904      }
     2905      Reference& operator&=(int value) {
     2906        _map.set(_key, _map[_key] & value);
     2907        return *this;
     2908      }
     2909      Reference& operator|=(int value) {
     2910        _map.set(_key, _map[_key] | value);
     2911        return *this;
     2912      }
     2913      Reference& operator^=(int value) {
     2914        _map.set(_key, _map[_key] ^ value);
     2915        return *this;
     2916      }
     2917      Reference& operator<<=(int value) {
     2918        _map.set(_key, _map[_key] << value);
     2919        return *this;
     2920      }
     2921      Reference& operator>>=(int value) {
     2922        _map.set(_key, _map[_key] >> value);
     2923        return *this;
     2924      }
     2925
     2926    private:
     2927      Key _key;
     2928      IterableIntMap& _map;
     2929    };
     2930
     2931    /// The const reference type.
     2932    typedef const Value& ConstReference;
     2933
     2934    /// \brief Gives back the maximal value plus one.
     2935    ///
     2936    /// Gives back the maximal value plus one.
     2937    int size() const {
     2938      return _first.size();
     2939    }
     2940
     2941    /// \brief Set operation of the map.
     2942    ///
     2943    /// Set operation of the map.
     2944    void set(const Key& key, const Value& value) {
     2945      unlace(key);
     2946      Parent::operator[](key).value = value;
     2947      lace(key);
     2948    }
     2949
     2950    /// \brief Const subscript operator of the map.
     2951    ///
     2952    /// Const subscript operator of the map.
     2953    const Value& operator[](const Key& key) const {
     2954      return Parent::operator[](key).value;
     2955    }
     2956
     2957    /// \brief Subscript operator of the map.
     2958    ///
     2959    /// Subscript operator of the map.
     2960    Reference operator[](const Key& key) {
     2961      return Reference(*this, key);
     2962    }
     2963
     2964    /// \brief Iterator for the keys with the same value.
     2965    ///
     2966    /// Iterator for the keys with the same value. It works
     2967    /// like a graph item iterator, it can be converted to
     2968    /// the item type of the map, incremented with \c ++ operator, and
     2969    /// if the iterator leaves the last valid item, it will be equal to
     2970    /// \c INVALID.
     2971    class ItemIt : public Key {
     2972    public:
     2973      typedef Key Parent;
     2974
     2975      /// \brief Invalid constructor \& conversion.
     2976      ///
     2977      /// This constructor initializes the iterator to be invalid.
     2978      /// \sa Invalid for more details.
     2979      ItemIt(Invalid) : Parent(INVALID), _map(0) {}
     2980
     2981      /// \brief Creates an iterator with a value.
     2982      ///
     2983      /// Creates an iterator with a value. It iterates on the
     2984      /// keys mapped to the given value.
     2985      /// \param map The IterableIntMap.
     2986      /// \param value The value.
     2987      ItemIt(const IterableIntMap& map, int value) : _map(&map) {
     2988        if (value < 0 || value >= int(_map->_first.size())) {
     2989          Parent::operator=(INVALID);
     2990        } else {
     2991          Parent::operator=(_map->_first[value]);
     2992        }
     2993      }
     2994
     2995      /// \brief Increment operator.
     2996      ///
     2997      /// Increment operator.
     2998      ItemIt& operator++() {
     2999        Parent::operator=(_map->IterableIntMap::Parent::
     3000                          operator[](static_cast<Parent&>(*this)).next);
     3001        return *this;
     3002      }
     3003
     3004    private:
     3005      const IterableIntMap* _map;
     3006    };
     3007
     3008  protected:
     3009
     3010    virtual void erase(const Key& key) {
     3011      unlace(key);
     3012      Parent::erase(key);
     3013    }
     3014
     3015    virtual void erase(const std::vector<Key>& keys) {
     3016      for (int i = 0; i < int(keys.size()); ++i) {
     3017        unlace(keys[i]);
     3018      }
     3019      Parent::erase(keys);
     3020    }
     3021
     3022    virtual void clear() {
     3023      _first.clear();
     3024      Parent::clear();
     3025    }
     3026
     3027  private:
     3028    std::vector<Key> _first;
     3029  };
     3030
     3031  namespace _maps_bits {
     3032    template <typename Item, typename Value>
     3033    struct IterableValueMapNode {
     3034      IterableValueMapNode(Value _value = Value()) : value(_value) {}
     3035      Item prev, next;
     3036      Value value;
     3037    };
     3038  }
     3039
     3040  /// \brief Dynamic iterable map for comparable values.
     3041  ///
     3042  /// This class provides a special graph map type which can store a
     3043  /// comparable value for graph items (\c Node, \c Arc or \c Edge).
     3044  /// For each value it is possible to iterate on the keys mapped to
     3045  /// the value (\c ItemIt), and the values of the map can be accessed
     3046  /// with an STL compatible forward iterator (\c ValueIt).
     3047  /// The map stores a linked list for each value, which contains
     3048  /// the items mapped to the value, and the used values are stored
     3049  /// in balanced binary tree (\c std::map).
     3050  ///
     3051  /// \ref IterableBoolMap and \ref IterableIntMap are similar classes
     3052  /// specialized for \c bool and \c int values, respectively.
     3053  ///
     3054  /// This type is not reference map, so it cannot be modified with
     3055  /// the subscript operator.
     3056  ///
     3057  /// \tparam GR The graph type.
     3058  /// \tparam K The key type of the map (\c GR::Node, \c GR::Arc or
     3059  /// \c GR::Edge).
     3060  /// \tparam V The value type of the map. It can be any comparable
     3061  /// value type.
     3062  ///
     3063  /// \see IterableBoolMap, IterableIntMap
     3064  /// \see CrossRefMap
     3065  template <typename GR, typename K, typename V>
     3066  class IterableValueMap
     3067    : protected ItemSetTraits<GR, K>::
     3068        template Map<_maps_bits::IterableValueMapNode<K, V> >::Type {
     3069  public:
     3070    typedef typename ItemSetTraits<GR, K>::
     3071      template Map<_maps_bits::IterableValueMapNode<K, V> >::Type Parent;
     3072
     3073    /// The key type
     3074    typedef K Key;
     3075    /// The value type
     3076    typedef V Value;
     3077    /// The graph type
     3078    typedef GR Graph;
     3079
     3080  public:
     3081
     3082    /// \brief Constructor of the map with a given value.
     3083    ///
     3084    /// Constructor of the map with a given value.
     3085    explicit IterableValueMap(const Graph& graph,
     3086                              const Value& value = Value())
     3087      : Parent(graph, _maps_bits::IterableValueMapNode<K, V>(value)) {
     3088      for (typename Parent::ItemIt it(*this); it != INVALID; ++it) {
     3089        lace(it);
     3090      }
     3091    }
     3092
     3093  protected:
     3094
     3095    void unlace(const Key& key) {
     3096      typename Parent::Value& node = Parent::operator[](key);
     3097      if (node.prev != INVALID) {
     3098        Parent::operator[](node.prev).next = node.next;
     3099      } else {
     3100        if (node.next != INVALID) {
     3101          _first[node.value] = node.next;
     3102        } else {
     3103          _first.erase(node.value);
     3104        }
     3105      }
     3106      if (node.next != INVALID) {
     3107        Parent::operator[](node.next).prev = node.prev;
     3108      }
     3109    }
     3110
     3111    void lace(const Key& key) {
     3112      typename Parent::Value& node = Parent::operator[](key);
     3113      typename std::map<Value, Key>::iterator it = _first.find(node.value);
     3114      if (it == _first.end()) {
     3115        node.prev = node.next = INVALID;
     3116        _first.insert(std::make_pair(node.value, key));
     3117      } else {
     3118        node.prev = INVALID;
     3119        node.next = it->second;
     3120        if (node.next != INVALID) {
     3121          Parent::operator[](node.next).prev = key;
     3122        }
     3123        it->second = key;
     3124      }
     3125    }
     3126
     3127  public:
     3128
     3129    /// \brief Forward iterator for values.
     3130    ///
     3131    /// This iterator is an STL compatible forward
     3132    /// iterator on the values of the map. The values can
     3133    /// be accessed in the <tt>[beginValue, endValue)</tt> range.
     3134    class ValueIt
     3135      : public std::iterator<std::forward_iterator_tag, Value> {
     3136      friend class IterableValueMap;
     3137    private:
     3138      ValueIt(typename std::map<Value, Key>::const_iterator _it)
     3139        : it(_it) {}
     3140    public:
     3141
     3142      /// Constructor
     3143      ValueIt() {}
     3144
     3145      /// \e
     3146      ValueIt& operator++() { ++it; return *this; }
     3147      /// \e
     3148      ValueIt operator++(int) {
     3149        ValueIt tmp(*this);
     3150        operator++();
     3151        return tmp;
     3152      }
     3153
     3154      /// \e
     3155      const Value& operator*() const { return it->first; }
     3156      /// \e
     3157      const Value* operator->() const { return &(it->first); }
     3158
     3159      /// \e
     3160      bool operator==(ValueIt jt) const { return it == jt.it; }
     3161      /// \e
     3162      bool operator!=(ValueIt jt) const { return it != jt.it; }
     3163
     3164    private:
     3165      typename std::map<Value, Key>::const_iterator it;
     3166    };
     3167
     3168    /// \brief Returns an iterator to the first value.
     3169    ///
     3170    /// Returns an STL compatible iterator to the
     3171    /// first value of the map. The values of the
     3172    /// map can be accessed in the <tt>[beginValue, endValue)</tt>
     3173    /// range.
     3174    ValueIt beginValue() const {
     3175      return ValueIt(_first.begin());
     3176    }
     3177
     3178    /// \brief Returns an iterator after the last value.
     3179    ///
     3180    /// Returns an STL compatible iterator after the
     3181    /// last value of the map. The values of the
     3182    /// map can be accessed in the <tt>[beginValue, endValue)</tt>
     3183    /// range.
     3184    ValueIt endValue() const {
     3185      return ValueIt(_first.end());
     3186    }
     3187
     3188    /// \brief Set operation of the map.
     3189    ///
     3190    /// Set operation of the map.
     3191    void set(const Key& key, const Value& value) {
     3192      unlace(key);
     3193      Parent::operator[](key).value = value;
     3194      lace(key);
     3195    }
     3196
     3197    /// \brief Const subscript operator of the map.
     3198    ///
     3199    /// Const subscript operator of the map.
     3200    const Value& operator[](const Key& key) const {
     3201      return Parent::operator[](key).value;
     3202    }
     3203
     3204    /// \brief Iterator for the keys with the same value.
     3205    ///
     3206    /// Iterator for the keys with the same value. It works
     3207    /// like a graph item iterator, it can be converted to
     3208    /// the item type of the map, incremented with \c ++ operator, and
     3209    /// if the iterator leaves the last valid item, it will be equal to
     3210    /// \c INVALID.
     3211    class ItemIt : public Key {
     3212    public:
     3213      typedef Key Parent;
     3214
     3215      /// \brief Invalid constructor \& conversion.
     3216      ///
     3217      /// This constructor initializes the iterator to be invalid.
     3218      /// \sa Invalid for more details.
     3219      ItemIt(Invalid) : Parent(INVALID), _map(0) {}
     3220
     3221      /// \brief Creates an iterator with a value.
     3222      ///
     3223      /// Creates an iterator with a value. It iterates on the
     3224      /// keys which have the given value.
     3225      /// \param map The IterableValueMap
     3226      /// \param value The value
     3227      ItemIt(const IterableValueMap& map, const Value& value) : _map(&map) {
     3228        typename std::map<Value, Key>::const_iterator it =
     3229          map._first.find(value);
     3230        if (it == map._first.end()) {
     3231          Parent::operator=(INVALID);
     3232        } else {
     3233          Parent::operator=(it->second);
     3234        }
     3235      }
     3236
     3237      /// \brief Increment operator.
     3238      ///
     3239      /// Increment Operator.
     3240      ItemIt& operator++() {
     3241        Parent::operator=(_map->IterableValueMap::Parent::
     3242                          operator[](static_cast<Parent&>(*this)).next);
     3243        return *this;
     3244      }
     3245
     3246
     3247    private:
     3248      const IterableValueMap* _map;
     3249    };
     3250
     3251  protected:
     3252
     3253    virtual void add(const Key& key) {
     3254      Parent::add(key);
     3255      lace(key);
     3256    }
     3257
     3258    virtual void add(const std::vector<Key>& keys) {
     3259      Parent::add(keys);
     3260      for (int i = 0; i < int(keys.size()); ++i) {
     3261        lace(keys[i]);
     3262      }
     3263    }
     3264
     3265    virtual void erase(const Key& key) {
     3266      unlace(key);
     3267      Parent::erase(key);
     3268    }
     3269
     3270    virtual void erase(const std::vector<Key>& keys) {
     3271      for (int i = 0; i < int(keys.size()); ++i) {
     3272        unlace(keys[i]);
     3273      }
     3274      Parent::erase(keys);
     3275    }
     3276
     3277    virtual void build() {
     3278      Parent::build();
     3279      for (typename Parent::ItemIt it(*this); it != INVALID; ++it) {
     3280        lace(it);
     3281      }
     3282    }
     3283
     3284    virtual void clear() {
     3285      _first.clear();
     3286      Parent::clear();
     3287    }
     3288
     3289  private:
     3290    std::map<Value, Key> _first;
    23313291  };
    23323292
     
    23413301  public:
    23423302
    2343     ///\e
     3303    /// The key type (the \c Arc type of the digraph).
    23443304    typedef typename GR::Arc Key;
    2345     ///\e
     3305    /// The value type (the \c Node type of the digraph).
    23463306    typedef typename GR::Node Value;
    23473307
     
    23823342  public:
    23833343
    2384     ///\e
     3344    /// The key type (the \c Arc type of the digraph).
    23853345    typedef typename GR::Arc Key;
    2386     ///\e
     3346    /// The value type (the \c Node type of the digraph).
    23873347    typedef typename GR::Node Value;
    23883348
     
    24243384  public:
    24253385
     3386    /// The key type (the \c Edge type of the digraph).
     3387    typedef typename GR::Edge Key;
     3388    /// The value type (the \c Arc type of the digraph).
    24263389    typedef typename GR::Arc Value;
    2427     typedef typename GR::Edge Key;
    24283390
    24293391    /// \brief Constructor
     
    24643426  public:
    24653427
     3428    /// The key type (the \c Edge type of the digraph).
     3429    typedef typename GR::Edge Key;
     3430    /// The value type (the \c Arc type of the digraph).
    24663431    typedef typename GR::Arc Value;
    2467     typedef typename GR::Edge Key;
    24683432
    24693433    /// \brief Constructor
     
    25003464  /// whenever the digraph changes.
    25013465  ///
    2502   /// \warning Besides \c addNode() and \c addArc(), a digraph structure 
     3466  /// \warning Besides \c addNode() and \c addArc(), a digraph structure
    25033467  /// may provide alternative ways to modify the digraph.
    25043468  /// The correct behavior of InDegMap is not guarantied if these additional
    2505   /// features are used. For example the functions
     3469  /// features are used. For example, the functions
    25063470  /// \ref ListDigraph::changeSource() "changeSource()",
    25073471  /// \ref ListDigraph::changeTarget() "changeTarget()" and
     
    25163480
    25173481  public:
    2518    
     3482
    25193483    /// The graph type of InDegMap
    25203484    typedef GR Graph;
     
    26303594  /// whenever the digraph changes.
    26313595  ///
    2632   /// \warning Besides \c addNode() and \c addArc(), a digraph structure 
     3596  /// \warning Besides \c addNode() and \c addArc(), a digraph structure
    26333597  /// may provide alternative ways to modify the digraph.
    26343598  /// The correct behavior of OutDegMap is not guarantied if these additional
    2635   /// features are used. For example the functions
     3599  /// features are used. For example, the functions
    26363600  /// \ref ListDigraph::changeSource() "changeSource()",
    26373601  /// \ref ListDigraph::changeTarget() "changeTarget()" and
     
    28013765  }
    28023766
     3767
     3768  /// \brief Copy the values of a graph map to another map.
     3769  ///
     3770  /// This function copies the values of a graph map to another graph map.
     3771  /// \c To::Key must be equal or convertible to \c From::Key and
     3772  /// \c From::Value must be equal or convertible to \c To::Value.
     3773  ///
     3774  /// For example, an edge map of \c int value type can be copied to
     3775  /// an arc map of \c double value type in an undirected graph, but
     3776  /// an arc map cannot be copied to an edge map.
     3777  /// Note that even a \ref ConstMap can be copied to a standard graph map,
     3778  /// but \ref mapFill() can also be used for this purpose.
     3779  ///
     3780  /// \param gr The graph for which the maps are defined.
     3781  /// \param from The map from which the values have to be copied.
     3782  /// It must conform to the \ref concepts::ReadMap "ReadMap" concept.
     3783  /// \param to The map to which the values have to be copied.
     3784  /// It must conform to the \ref concepts::WriteMap "WriteMap" concept.
     3785  template <typename GR, typename From, typename To>
     3786  void mapCopy(const GR& gr, const From& from, To& to) {
     3787    typedef typename To::Key Item;
     3788    typedef typename ItemSetTraits<GR, Item>::ItemIt ItemIt;
     3789
     3790    for (ItemIt it(gr); it != INVALID; ++it) {
     3791      to.set(it, from[it]);
     3792    }
     3793  }
     3794
     3795  /// \brief Compare two graph maps.
     3796  ///
     3797  /// This function compares the values of two graph maps. It returns
     3798  /// \c true if the maps assign the same value for all items in the graph.
     3799  /// The \c Key type of the maps (\c Node, \c Arc or \c Edge) must be equal
     3800  /// and their \c Value types must be comparable using \c %operator==().
     3801  ///
     3802  /// \param gr The graph for which the maps are defined.
     3803  /// \param map1 The first map.
     3804  /// \param map2 The second map.
     3805  template <typename GR, typename Map1, typename Map2>
     3806  bool mapCompare(const GR& gr, const Map1& map1, const Map2& map2) {
     3807    typedef typename Map2::Key Item;
     3808    typedef typename ItemSetTraits<GR, Item>::ItemIt ItemIt;
     3809
     3810    for (ItemIt it(gr); it != INVALID; ++it) {
     3811      if (!(map1[it] == map2[it])) return false;
     3812    }
     3813    return true;
     3814  }
     3815
     3816  /// \brief Return an item having minimum value of a graph map.
     3817  ///
     3818  /// This function returns an item (\c Node, \c Arc or \c Edge) having
     3819  /// minimum value of the given graph map.
     3820  /// If the item set is empty, it returns \c INVALID.
     3821  ///
     3822  /// \param gr The graph for which the map is defined.
     3823  /// \param map The graph map.
     3824  template <typename GR, typename Map>
     3825  typename Map::Key mapMin(const GR& gr, const Map& map) {
     3826    return mapMin(gr, map, std::less<typename Map::Value>());
     3827  }
     3828
     3829  /// \brief Return an item having minimum value of a graph map.
     3830  ///
     3831  /// This function returns an item (\c Node, \c Arc or \c Edge) having
     3832  /// minimum value of the given graph map.
     3833  /// If the item set is empty, it returns \c INVALID.
     3834  ///
     3835  /// \param gr The graph for which the map is defined.
     3836  /// \param map The graph map.
     3837  /// \param comp Comparison function object.
     3838  template <typename GR, typename Map, typename Comp>
     3839  typename Map::Key mapMin(const GR& gr, const Map& map, const Comp& comp) {
     3840    typedef typename Map::Key Item;
     3841    typedef typename Map::Value Value;
     3842    typedef typename ItemSetTraits<GR, Item>::ItemIt ItemIt;
     3843
     3844    ItemIt min_item(gr);
     3845    if (min_item == INVALID) return INVALID;
     3846    Value min = map[min_item];
     3847    for (ItemIt it(gr); it != INVALID; ++it) {
     3848      if (comp(map[it], min)) {
     3849        min = map[it];
     3850        min_item = it;
     3851      }
     3852    }
     3853    return min_item;
     3854  }
     3855
     3856  /// \brief Return an item having maximum value of a graph map.
     3857  ///
     3858  /// This function returns an item (\c Node, \c Arc or \c Edge) having
     3859  /// maximum value of the given graph map.
     3860  /// If the item set is empty, it returns \c INVALID.
     3861  ///
     3862  /// \param gr The graph for which the map is defined.
     3863  /// \param map The graph map.
     3864  template <typename GR, typename Map>
     3865  typename Map::Key mapMax(const GR& gr, const Map& map) {
     3866    return mapMax(gr, map, std::less<typename Map::Value>());
     3867  }
     3868
     3869  /// \brief Return an item having maximum value of a graph map.
     3870  ///
     3871  /// This function returns an item (\c Node, \c Arc or \c Edge) having
     3872  /// maximum value of the given graph map.
     3873  /// If the item set is empty, it returns \c INVALID.
     3874  ///
     3875  /// \param gr The graph for which the map is defined.
     3876  /// \param map The graph map.
     3877  /// \param comp Comparison function object.
     3878  template <typename GR, typename Map, typename Comp>
     3879  typename Map::Key mapMax(const GR& gr, const Map& map, const Comp& comp) {
     3880    typedef typename Map::Key Item;
     3881    typedef typename Map::Value Value;
     3882    typedef typename ItemSetTraits<GR, Item>::ItemIt ItemIt;
     3883
     3884    ItemIt max_item(gr);
     3885    if (max_item == INVALID) return INVALID;
     3886    Value max = map[max_item];
     3887    for (ItemIt it(gr); it != INVALID; ++it) {
     3888      if (comp(max, map[it])) {
     3889        max = map[it];
     3890        max_item = it;
     3891      }
     3892    }
     3893    return max_item;
     3894  }
     3895
     3896  /// \brief Return the minimum value of a graph map.
     3897  ///
     3898  /// This function returns the minimum value of the given graph map.
     3899  /// The corresponding item set of the graph must not be empty.
     3900  ///
     3901  /// \param gr The graph for which the map is defined.
     3902  /// \param map The graph map.
     3903  template <typename GR, typename Map>
     3904  typename Map::Value mapMinValue(const GR& gr, const Map& map) {
     3905    return map[mapMin(gr, map, std::less<typename Map::Value>())];
     3906  }
     3907
     3908  /// \brief Return the minimum value of a graph map.
     3909  ///
     3910  /// This function returns the minimum value of the given graph map.
     3911  /// The corresponding item set of the graph must not be empty.
     3912  ///
     3913  /// \param gr The graph for which the map is defined.
     3914  /// \param map The graph map.
     3915  /// \param comp Comparison function object.
     3916  template <typename GR, typename Map, typename Comp>
     3917  typename Map::Value
     3918  mapMinValue(const GR& gr, const Map& map, const Comp& comp) {
     3919    return map[mapMin(gr, map, comp)];
     3920  }
     3921
     3922  /// \brief Return the maximum value of a graph map.
     3923  ///
     3924  /// This function returns the maximum value of the given graph map.
     3925  /// The corresponding item set of the graph must not be empty.
     3926  ///
     3927  /// \param gr The graph for which the map is defined.
     3928  /// \param map The graph map.
     3929  template <typename GR, typename Map>
     3930  typename Map::Value mapMaxValue(const GR& gr, const Map& map) {
     3931    return map[mapMax(gr, map, std::less<typename Map::Value>())];
     3932  }
     3933
     3934  /// \brief Return the maximum value of a graph map.
     3935  ///
     3936  /// This function returns the maximum value of the given graph map.
     3937  /// The corresponding item set of the graph must not be empty.
     3938  ///
     3939  /// \param gr The graph for which the map is defined.
     3940  /// \param map The graph map.
     3941  /// \param comp Comparison function object.
     3942  template <typename GR, typename Map, typename Comp>
     3943  typename Map::Value
     3944  mapMaxValue(const GR& gr, const Map& map, const Comp& comp) {
     3945    return map[mapMax(gr, map, comp)];
     3946  }
     3947
     3948  /// \brief Return an item having a specified value in a graph map.
     3949  ///
     3950  /// This function returns an item (\c Node, \c Arc or \c Edge) having
     3951  /// the specified assigned value in the given graph map.
     3952  /// If no such item exists, it returns \c INVALID.
     3953  ///
     3954  /// \param gr The graph for which the map is defined.
     3955  /// \param map The graph map.
     3956  /// \param val The value that have to be found.
     3957  template <typename GR, typename Map>
     3958  typename Map::Key
     3959  mapFind(const GR& gr, const Map& map, const typename Map::Value& val) {
     3960    typedef typename Map::Key Item;
     3961    typedef typename ItemSetTraits<GR, Item>::ItemIt ItemIt;
     3962
     3963    for (ItemIt it(gr); it != INVALID; ++it) {
     3964      if (map[it] == val) return it;
     3965    }
     3966    return INVALID;
     3967  }
     3968
     3969  /// \brief Return an item having value for which a certain predicate is
     3970  /// true in a graph map.
     3971  ///
     3972  /// This function returns an item (\c Node, \c Arc or \c Edge) having
     3973  /// such assigned value for which the specified predicate is true
     3974  /// in the given graph map.
     3975  /// If no such item exists, it returns \c INVALID.
     3976  ///
     3977  /// \param gr The graph for which the map is defined.
     3978  /// \param map The graph map.
     3979  /// \param pred The predicate function object.
     3980  template <typename GR, typename Map, typename Pred>
     3981  typename Map::Key
     3982  mapFindIf(const GR& gr, const Map& map, const Pred& pred) {
     3983    typedef typename Map::Key Item;
     3984    typedef typename ItemSetTraits<GR, Item>::ItemIt ItemIt;
     3985
     3986    for (ItemIt it(gr); it != INVALID; ++it) {
     3987      if (pred(map[it])) return it;
     3988    }
     3989    return INVALID;
     3990  }
     3991
     3992  /// \brief Return the number of items having a specified value in a
     3993  /// graph map.
     3994  ///
     3995  /// This function returns the number of items (\c Node, \c Arc or \c Edge)
     3996  /// having the specified assigned value in the given graph map.
     3997  ///
     3998  /// \param gr The graph for which the map is defined.
     3999  /// \param map The graph map.
     4000  /// \param val The value that have to be counted.
     4001  template <typename GR, typename Map>
     4002  int mapCount(const GR& gr, const Map& map, const typename Map::Value& val) {
     4003    typedef typename Map::Key Item;
     4004    typedef typename ItemSetTraits<GR, Item>::ItemIt ItemIt;
     4005
     4006    int cnt = 0;
     4007    for (ItemIt it(gr); it != INVALID; ++it) {
     4008      if (map[it] == val) ++cnt;
     4009    }
     4010    return cnt;
     4011  }
     4012
     4013  /// \brief Return the number of items having values for which a certain
     4014  /// predicate is true in a graph map.
     4015  ///
     4016  /// This function returns the number of items (\c Node, \c Arc or \c Edge)
     4017  /// having such assigned values for which the specified predicate is true
     4018  /// in the given graph map.
     4019  ///
     4020  /// \param gr The graph for which the map is defined.
     4021  /// \param map The graph map.
     4022  /// \param pred The predicate function object.
     4023  template <typename GR, typename Map, typename Pred>
     4024  int mapCountIf(const GR& gr, const Map& map, const Pred& pred) {
     4025    typedef typename Map::Key Item;
     4026    typedef typename ItemSetTraits<GR, Item>::ItemIt ItemIt;
     4027
     4028    int cnt = 0;
     4029    for (ItemIt it(gr); it != INVALID; ++it) {
     4030      if (pred(map[it])) ++cnt;
     4031    }
     4032    return cnt;
     4033  }
     4034
     4035  /// \brief Fill a graph map with a certain value.
     4036  ///
     4037  /// This function sets the specified value for all items (\c Node,
     4038  /// \c Arc or \c Edge) in the given graph map.
     4039  ///
     4040  /// \param gr The graph for which the map is defined.
     4041  /// \param map The graph map. It must conform to the
     4042  /// \ref concepts::WriteMap "WriteMap" concept.
     4043  /// \param val The value.
     4044  template <typename GR, typename Map>
     4045  void mapFill(const GR& gr, Map& map, const typename Map::Value& val) {
     4046    typedef typename Map::Key Item;
     4047    typedef typename ItemSetTraits<GR, Item>::ItemIt ItemIt;
     4048
     4049    for (ItemIt it(gr); it != INVALID; ++it) {
     4050      map.set(it, val);
     4051    }
     4052  }
     4053
    28034054  /// @}
    28044055}
  • TabularUnified lemon/matching.h

    r945 r956  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    1717 */
    1818
    19 #ifndef LEMON_MAX_MATCHING_H
    20 #define LEMON_MAX_MATCHING_H
     19#ifndef LEMON_MATCHING_H
     20#define LEMON_MATCHING_H
    2121
    2222#include <vector>
     
    2929#include <lemon/bin_heap.h>
    3030#include <lemon/maps.h>
     31#include <lemon/fractional_matching.h>
    3132
    3233///\ingroup matching
     
    4243  /// This class implements Edmonds' alternating forest matching algorithm
    4344  /// for finding a maximum cardinality matching in a general undirected graph.
    44   /// It can be started from an arbitrary initial matching 
     45  /// It can be started from an arbitrary initial matching
    4546  /// (the default is the empty one).
    4647  ///
     
    7071    ///\brief Status constants for Gallai-Edmonds decomposition.
    7172    ///
    72     ///These constants are used for indicating the Gallai-Edmonds 
     73    ///These constants are used for indicating the Gallai-Edmonds
    7374    ///decomposition of a graph. The nodes with status \c EVEN (or \c D)
    7475    ///induce a subgraph with factor-critical components, the nodes with
    7576    ///status \c ODD (or \c A) form the canonical barrier, and the nodes
    76     ///with status \c MATCHED (or \c C) induce a subgraph having a 
     77    ///with status \c MATCHED (or \c C) induce a subgraph having a
    7778    ///perfect matching.
    7879    enum Status {
     
    513514    }
    514515
    515     /// \brief Start Edmonds' algorithm with a heuristic improvement 
     516    /// \brief Start Edmonds' algorithm with a heuristic improvement
    516517    /// for dense graphs
    517518    ///
     
    535536    /// \brief Run Edmonds' algorithm
    536537    ///
    537     /// This function runs Edmonds' algorithm. An additional heuristic of 
    538     /// postponing shrinks is used for relatively dense graphs 
     538    /// This function runs Edmonds' algorithm. An additional heuristic of
     539    /// postponing shrinks is used for relatively dense graphs
    539540    /// (for which <tt>m>=2*n</tt> holds).
    540541    void run() {
     
    557558    /// \brief Return the size (cardinality) of the matching.
    558559    ///
    559     /// This function returns the size (cardinality) of the current matching. 
     560    /// This function returns the size (cardinality) of the current matching.
    560561    /// After run() it returns the size of the maximum matching in the graph.
    561562    int matchingSize() const {
     
    571572    /// \brief Return \c true if the given edge is in the matching.
    572573    ///
    573     /// This function returns \c true if the given edge is in the current 
     574    /// This function returns \c true if the given edge is in the current
    574575    /// matching.
    575576    bool matching(const Edge& edge) const {
     
    580581    ///
    581582    /// This function returns the matching arc (or edge) incident to the
    582     /// given node in the current matching or \c INVALID if the node is 
     583    /// given node in the current matching or \c INVALID if the node is
    583584    /// not covered by the matching.
    584585    Arc matching(const Node& n) const {
     
    596597    /// \brief Return the mate of the given node.
    597598    ///
    598     /// This function returns the mate of the given node in the current 
     599    /// This function returns the mate of the given node in the current
    599600    /// matching or \c INVALID if the node is not covered by the matching.
    600601    Node mate(const Node& n) const {
     
    606607
    607608    /// \name Dual Solution
    608     /// Functions to get the dual solution, i.e. the Gallai-Edmonds 
     609    /// Functions to get the dual solution, i.e. the Gallai-Edmonds
    609610    /// decomposition.
    610611
     
    649650  /// \f$O(nm\log n)\f$ time complexity.
    650651  ///
    651   /// The maximum weighted matching problem is to find a subset of the 
    652   /// edges in an undirected graph with maximum overall weight for which 
     652  /// The maximum weighted matching problem is to find a subset of the
     653  /// edges in an undirected graph with maximum overall weight for which
    653654  /// each node has at most one incident edge.
    654655  /// It can be formulated with the following linear program.
     
    674675      \frac{\vert B \vert - 1}{2}z_B\f] */
    675676  ///
    676   /// The algorithm can be executed with the run() function. 
     677  /// The algorithm can be executed with the run() function.
    677678  /// After it the matching (the primal solution) and the dual solution
    678   /// can be obtained using the query functions and the 
    679   /// \ref MaxWeightedMatching::BlossomIt "BlossomIt" nested class, 
    680   /// which is able to iterate on the nodes of a blossom. 
     679  /// can be obtained using the query functions and the
     680  /// \ref MaxWeightedMatching::BlossomIt "BlossomIt" nested class,
     681  /// which is able to iterate on the nodes of a blossom.
    681682  /// If the value type is integer, then the dual solution is multiplied
    682683  /// by \ref MaxWeightedMatching::dualScale "4".
    683684  ///
    684685  /// \tparam GR The undirected graph type the algorithm runs on.
    685   /// \tparam WM The type edge weight map. The default type is 
     686  /// \tparam WM The type edge weight map. The default type is
    686687  /// \ref concepts::Graph::EdgeMap "GR::EdgeMap<int>".
    687688#ifdef DOXYGEN
     
    746747
    747748    enum Status {
    748       EVEN = -1, MATCHED = 0, ODD = 1, UNMATCHED = -2
     749      EVEN = -1, MATCHED = 0, ODD = 1
    749750    };
    750751
     
    798799
    799800    Value _delta_sum;
     801    int _unmatched;
     802
     803    typedef MaxWeightedFractionalMatching<Graph, WeightMap> FractionalMatching;
     804    FractionalMatching *_fractional;
    800805
    801806    void createStructures() {
     
    864869
    865870    void destroyStructures() {
    866       _node_num = countNodes(_graph);
    867       _blossom_num = _node_num * 3 / 2;
    868 
    869871      if (_matching) {
    870872        delete _matching;
     
    941943            if (_delta3->state(e) != _delta3->IN_HEAP && blossom != vb) {
    942944              _delta3->push(e, rw / 2);
    943             }
    944           } else if ((*_blossom_data)[vb].status == UNMATCHED) {
    945             if (_delta3->state(e) != _delta3->IN_HEAP) {
    946               _delta3->push(e, rw);
    947945            }
    948946          } else {
     
    969967                               (*_blossom_data)[vb].offset);
    970968                } else if ((*_delta2)[vb] > _blossom_set->classPrio(vb) -
    971                            (*_blossom_data)[vb].offset){
     969                           (*_blossom_data)[vb].offset) {
    972970                  _delta2->decrease(vb, _blossom_set->classPrio(vb) -
    973971                                   (*_blossom_data)[vb].offset);
     
    988986      if (!_blossom_set->trivial(blossom)) {
    989987        _delta4->push(blossom, (*_blossom_data)[blossom].pot / 2 +
    990                      (*_blossom_data)[blossom].offset);
     988                      (*_blossom_data)[blossom].offset);
    991989      }
    992990    }
     
    10551053                }
    10561054              }
    1057             }
    1058 
    1059           } else if ((*_blossom_data)[vb].status == UNMATCHED) {
    1060             if (_delta3->state(e) == _delta3->IN_HEAP) {
    1061               _delta3->erase(e);
    10621055            }
    10631056          } else {
     
    10971090          std::numeric_limits<Value>::max()) {
    10981091        _delta2->push(blossom, _blossom_set->classPrio(blossom) -
    1099                        (*_blossom_data)[blossom].offset);
     1092                      (*_blossom_data)[blossom].offset);
    11001093      }
    11011094
     
    11361129            if (_delta3->state(e) != _delta3->IN_HEAP && blossom != vb) {
    11371130              _delta3->push(e, rw / 2);
    1138             }
    1139           } else if ((*_blossom_data)[vb].status == UNMATCHED) {
    1140             if (_delta3->state(e) != _delta3->IN_HEAP) {
    1141               _delta3->push(e, rw);
    11421131            }
    11431132          } else {
     
    11771166    }
    11781167
    1179 
    1180     void matchedToUnmatched(int blossom) {
    1181       if (_delta2->state(blossom) == _delta2->IN_HEAP) {
    1182         _delta2->erase(blossom);
    1183       }
    1184 
    1185       for (typename BlossomSet::ItemIt n(*_blossom_set, blossom);
    1186            n != INVALID; ++n) {
    1187         int ni = (*_node_index)[n];
    1188 
    1189         _blossom_set->increase(n, std::numeric_limits<Value>::max());
    1190 
    1191         (*_node_data)[ni].heap.clear();
    1192         (*_node_data)[ni].heap_index.clear();
    1193 
    1194         for (OutArcIt e(_graph, n); e != INVALID; ++e) {
    1195           Node v = _graph.target(e);
    1196           int vb = _blossom_set->find(v);
    1197           int vi = (*_node_index)[v];
    1198 
    1199           Value rw = (*_node_data)[ni].pot + (*_node_data)[vi].pot -
    1200             dualScale * _weight[e];
    1201 
    1202           if ((*_blossom_data)[vb].status == EVEN) {
    1203             if (_delta3->state(e) != _delta3->IN_HEAP) {
    1204               _delta3->push(e, rw);
    1205             }
    1206           }
    1207         }
    1208       }
    1209     }
    1210 
    1211     void unmatchedToMatched(int blossom) {
    1212       for (typename BlossomSet::ItemIt n(*_blossom_set, blossom);
    1213            n != INVALID; ++n) {
    1214         int ni = (*_node_index)[n];
    1215 
    1216         for (InArcIt e(_graph, n); e != INVALID; ++e) {
    1217           Node v = _graph.source(e);
    1218           int vb = _blossom_set->find(v);
    1219           int vi = (*_node_index)[v];
    1220 
    1221           Value rw = (*_node_data)[ni].pot + (*_node_data)[vi].pot -
    1222             dualScale * _weight[e];
    1223 
    1224           if (vb == blossom) {
    1225             if (_delta3->state(e) == _delta3->IN_HEAP) {
    1226               _delta3->erase(e);
    1227             }
    1228           } else if ((*_blossom_data)[vb].status == EVEN) {
    1229 
    1230             if (_delta3->state(e) == _delta3->IN_HEAP) {
    1231               _delta3->erase(e);
    1232             }
    1233 
    1234             int vt = _tree_set->find(vb);
    1235 
    1236             Arc r = _graph.oppositeArc(e);
    1237 
    1238             typename std::map<int, Arc>::iterator it =
    1239               (*_node_data)[ni].heap_index.find(vt);
    1240 
    1241             if (it != (*_node_data)[ni].heap_index.end()) {
    1242               if ((*_node_data)[ni].heap[it->second] > rw) {
    1243                 (*_node_data)[ni].heap.replace(it->second, r);
    1244                 (*_node_data)[ni].heap.decrease(r, rw);
    1245                 it->second = r;
    1246               }
    1247             } else {
    1248               (*_node_data)[ni].heap.push(r, rw);
    1249               (*_node_data)[ni].heap_index.insert(std::make_pair(vt, r));
    1250             }
    1251 
    1252             if ((*_blossom_set)[n] > (*_node_data)[ni].heap.prio()) {
    1253               _blossom_set->decrease(n, (*_node_data)[ni].heap.prio());
    1254 
    1255               if (_delta2->state(blossom) != _delta2->IN_HEAP) {
    1256                 _delta2->push(blossom, _blossom_set->classPrio(blossom) -
    1257                              (*_blossom_data)[blossom].offset);
    1258               } else if ((*_delta2)[blossom] > _blossom_set->classPrio(blossom)-
    1259                          (*_blossom_data)[blossom].offset){
    1260                 _delta2->decrease(blossom, _blossom_set->classPrio(blossom) -
    1261                                  (*_blossom_data)[blossom].offset);
    1262               }
    1263             }
    1264 
    1265           } else if ((*_blossom_data)[vb].status == UNMATCHED) {
    1266             if (_delta3->state(e) == _delta3->IN_HEAP) {
    1267               _delta3->erase(e);
    1268             }
    1269           }
    1270         }
    1271       }
    1272     }
    1273 
    12741168    void alternatePath(int even, int tree) {
    12751169      int odd;
     
    13141208      destroyTree(tree);
    13151209
    1316       (*_blossom_data)[blossom].status = UNMATCHED;
    13171210      (*_blossom_data)[blossom].base = node;
    1318       matchedToUnmatched(blossom);
    1319     }
    1320 
     1211      (*_blossom_data)[blossom].next = INVALID;
     1212    }
    13211213
    13221214    void augmentOnEdge(const Edge& edge) {
     
    13251217      int right = _blossom_set->find(_graph.v(edge));
    13261218
    1327       if ((*_blossom_data)[left].status == EVEN) {
    1328         int left_tree = _tree_set->find(left);
    1329         alternatePath(left, left_tree);
    1330         destroyTree(left_tree);
    1331       } else {
    1332         (*_blossom_data)[left].status = MATCHED;
    1333         unmatchedToMatched(left);
    1334       }
    1335 
    1336       if ((*_blossom_data)[right].status == EVEN) {
    1337         int right_tree = _tree_set->find(right);
    1338         alternatePath(right, right_tree);
    1339         destroyTree(right_tree);
    1340       } else {
    1341         (*_blossom_data)[right].status = MATCHED;
    1342         unmatchedToMatched(right);
    1343       }
     1219      int left_tree = _tree_set->find(left);
     1220      alternatePath(left, left_tree);
     1221      destroyTree(left_tree);
     1222
     1223      int right_tree = _tree_set->find(right);
     1224      alternatePath(right, right_tree);
     1225      destroyTree(right_tree);
    13441226
    13451227      (*_blossom_data)[left].next = _graph.direct(edge, true);
    13461228      (*_blossom_data)[right].next = _graph.direct(edge, false);
     1229    }
     1230
     1231    void augmentOnArc(const Arc& arc) {
     1232
     1233      int left = _blossom_set->find(_graph.source(arc));
     1234      int right = _blossom_set->find(_graph.target(arc));
     1235
     1236      (*_blossom_data)[left].status = MATCHED;
     1237
     1238      int right_tree = _tree_set->find(right);
     1239      alternatePath(right, right_tree);
     1240      destroyTree(right_tree);
     1241
     1242      (*_blossom_data)[left].next = arc;
     1243      (*_blossom_data)[right].next = _graph.oppositeArc(arc);
    13471244    }
    13481245
     
    15491446          (*_blossom_data)[sb].pred = pred;
    15501447          (*_blossom_data)[sb].next =
    1551                            _graph.oppositeArc((*_blossom_data)[tb].next);
     1448            _graph.oppositeArc((*_blossom_data)[tb].next);
    15521449
    15531450          pred = (*_blossom_data)[ub].next;
     
    16491546
    16501547      for (int i = 0; i < int(blossoms.size()); ++i) {
    1651         if ((*_blossom_data)[blossoms[i]].status == MATCHED) {
     1548        if ((*_blossom_data)[blossoms[i]].next != INVALID) {
    16521549
    16531550          Value offset = (*_blossom_data)[blossoms[i]].offset;
     
    16871584        _delta4_index(0), _delta4(0),
    16881585
    1689         _delta_sum() {}
     1586        _delta_sum(), _unmatched(0),
     1587
     1588        _fractional(0)
     1589    {}
    16901590
    16911591    ~MaxWeightedMatching() {
    16921592      destroyStructures();
     1593      if (_fractional) {
     1594        delete _fractional;
     1595      }
    16931596    }
    16941597
     
    17211624        (*_delta4_index)[i] = _delta4->PRE_HEAP;
    17221625      }
    1723      
     1626
     1627      _unmatched = _node_num;
     1628
    17241629      _delta1->clear();
    17251630      _delta2->clear();
     
    17651670    }
    17661671
     1672    /// \brief Initialize the algorithm with fractional matching
     1673    ///
     1674    /// This function initializes the algorithm with a fractional
     1675    /// matching. This initialization is also called jumpstart heuristic.
     1676    void fractionalInit() {
     1677      createStructures();
     1678
     1679      _blossom_node_list.clear();
     1680      _blossom_potential.clear();
     1681
     1682      if (_fractional == 0) {
     1683        _fractional = new FractionalMatching(_graph, _weight, false);
     1684      }
     1685      _fractional->run();
     1686
     1687      for (ArcIt e(_graph); e != INVALID; ++e) {
     1688        (*_node_heap_index)[e] = BinHeap<Value, IntArcMap>::PRE_HEAP;
     1689      }
     1690      for (NodeIt n(_graph); n != INVALID; ++n) {
     1691        (*_delta1_index)[n] = _delta1->PRE_HEAP;
     1692      }
     1693      for (EdgeIt e(_graph); e != INVALID; ++e) {
     1694        (*_delta3_index)[e] = _delta3->PRE_HEAP;
     1695      }
     1696      for (int i = 0; i < _blossom_num; ++i) {
     1697        (*_delta2_index)[i] = _delta2->PRE_HEAP;
     1698        (*_delta4_index)[i] = _delta4->PRE_HEAP;
     1699      }
     1700
     1701      _unmatched = 0;
     1702
     1703      _delta1->clear();
     1704      _delta2->clear();
     1705      _delta3->clear();
     1706      _delta4->clear();
     1707      _blossom_set->clear();
     1708      _tree_set->clear();
     1709
     1710      int index = 0;
     1711      for (NodeIt n(_graph); n != INVALID; ++n) {
     1712        Value pot = _fractional->nodeValue(n);
     1713        (*_node_index)[n] = index;
     1714        (*_node_data)[index].pot = pot;
     1715        (*_node_data)[index].heap_index.clear();
     1716        (*_node_data)[index].heap.clear();
     1717        int blossom =
     1718          _blossom_set->insert(n, std::numeric_limits<Value>::max());
     1719
     1720        (*_blossom_data)[blossom].status = MATCHED;
     1721        (*_blossom_data)[blossom].pred = INVALID;
     1722        (*_blossom_data)[blossom].next = _fractional->matching(n);
     1723        if (_fractional->matching(n) == INVALID) {
     1724          (*_blossom_data)[blossom].base = n;
     1725        }
     1726        (*_blossom_data)[blossom].pot = 0;
     1727        (*_blossom_data)[blossom].offset = 0;
     1728        ++index;
     1729      }
     1730
     1731      typename Graph::template NodeMap<bool> processed(_graph, false);
     1732      for (NodeIt n(_graph); n != INVALID; ++n) {
     1733        if (processed[n]) continue;
     1734        processed[n] = true;
     1735        if (_fractional->matching(n) == INVALID) continue;
     1736        int num = 1;
     1737        Node v = _graph.target(_fractional->matching(n));
     1738        while (n != v) {
     1739          processed[v] = true;
     1740          v = _graph.target(_fractional->matching(v));
     1741          ++num;
     1742        }
     1743
     1744        if (num % 2 == 1) {
     1745          std::vector<int> subblossoms(num);
     1746
     1747          subblossoms[--num] = _blossom_set->find(n);
     1748          _delta1->push(n, _fractional->nodeValue(n));
     1749          v = _graph.target(_fractional->matching(n));
     1750          while (n != v) {
     1751            subblossoms[--num] = _blossom_set->find(v);
     1752            _delta1->push(v, _fractional->nodeValue(v));
     1753            v = _graph.target(_fractional->matching(v));
     1754          }
     1755
     1756          int surface =
     1757            _blossom_set->join(subblossoms.begin(), subblossoms.end());
     1758          (*_blossom_data)[surface].status = EVEN;
     1759          (*_blossom_data)[surface].pred = INVALID;
     1760          (*_blossom_data)[surface].next = INVALID;
     1761          (*_blossom_data)[surface].pot = 0;
     1762          (*_blossom_data)[surface].offset = 0;
     1763
     1764          _tree_set->insert(surface);
     1765          ++_unmatched;
     1766        }
     1767      }
     1768
     1769      for (EdgeIt e(_graph); e != INVALID; ++e) {
     1770        int si = (*_node_index)[_graph.u(e)];
     1771        int sb = _blossom_set->find(_graph.u(e));
     1772        int ti = (*_node_index)[_graph.v(e)];
     1773        int tb = _blossom_set->find(_graph.v(e));
     1774        if ((*_blossom_data)[sb].status == EVEN &&
     1775            (*_blossom_data)[tb].status == EVEN && sb != tb) {
     1776          _delta3->push(e, ((*_node_data)[si].pot + (*_node_data)[ti].pot -
     1777                            dualScale * _weight[e]) / 2);
     1778        }
     1779      }
     1780
     1781      for (NodeIt n(_graph); n != INVALID; ++n) {
     1782        int nb = _blossom_set->find(n);
     1783        if ((*_blossom_data)[nb].status != MATCHED) continue;
     1784        int ni = (*_node_index)[n];
     1785
     1786        for (OutArcIt e(_graph, n); e != INVALID; ++e) {
     1787          Node v = _graph.target(e);
     1788          int vb = _blossom_set->find(v);
     1789          int vi = (*_node_index)[v];
     1790
     1791          Value rw = (*_node_data)[ni].pot + (*_node_data)[vi].pot -
     1792            dualScale * _weight[e];
     1793
     1794          if ((*_blossom_data)[vb].status == EVEN) {
     1795
     1796            int vt = _tree_set->find(vb);
     1797
     1798            typename std::map<int, Arc>::iterator it =
     1799              (*_node_data)[ni].heap_index.find(vt);
     1800
     1801            if (it != (*_node_data)[ni].heap_index.end()) {
     1802              if ((*_node_data)[ni].heap[it->second] > rw) {
     1803                (*_node_data)[ni].heap.replace(it->second, e);
     1804                (*_node_data)[ni].heap.decrease(e, rw);
     1805                it->second = e;
     1806              }
     1807            } else {
     1808              (*_node_data)[ni].heap.push(e, rw);
     1809              (*_node_data)[ni].heap_index.insert(std::make_pair(vt, e));
     1810            }
     1811          }
     1812        }
     1813
     1814        if (!(*_node_data)[ni].heap.empty()) {
     1815          _blossom_set->decrease(n, (*_node_data)[ni].heap.prio());
     1816          _delta2->push(nb, _blossom_set->classPrio(nb));
     1817        }
     1818      }
     1819    }
     1820
    17671821    /// \brief Start the algorithm
    17681822    ///
    17691823    /// This function starts the algorithm.
    17701824    ///
    1771     /// \pre \ref init() must be called before using this function.
     1825    /// \pre \ref init() or \ref fractionalInit() must be called
     1826    /// before using this function.
    17721827    void start() {
    17731828      enum OpType {
     
    17751830      };
    17761831
    1777       int unmatched = _node_num;
    1778       while (unmatched > 0) {
     1832      while (_unmatched > 0) {
    17791833        Value d1 = !_delta1->empty() ?
    17801834          _delta1->prio() : std::numeric_limits<Value>::max();
     
    17891843          _delta4->prio() : std::numeric_limits<Value>::max();
    17901844
    1791         _delta_sum = d1; OpType ot = D1;
     1845        _delta_sum = d3; OpType ot = D3;
     1846        if (d1 < _delta_sum) { _delta_sum = d1; ot = D1; }
    17921847        if (d2 < _delta_sum) { _delta_sum = d2; ot = D2; }
    1793         if (d3 < _delta_sum) { _delta_sum = d3; ot = D3; }
    17941848        if (d4 < _delta_sum) { _delta_sum = d4; ot = D4; }
    1795 
    17961849
    17971850        switch (ot) {
     
    18001853            Node n = _delta1->top();
    18011854            unmatchNode(n);
    1802             --unmatched;
     1855            --_unmatched;
    18031856          }
    18041857          break;
     
    18071860            int blossom = _delta2->top();
    18081861            Node n = _blossom_set->classTop(blossom);
    1809             Arc e = (*_node_data)[(*_node_index)[n]].heap.top();
    1810             extendOnArc(e);
     1862            Arc a = (*_node_data)[(*_node_index)[n]].heap.top();
     1863            if ((*_blossom_data)[blossom].next == INVALID) {
     1864              augmentOnArc(a);
     1865              --_unmatched;
     1866            } else {
     1867              extendOnArc(a);
     1868            }
    18111869          }
    18121870          break;
     
    18211879              _delta3->pop();
    18221880            } else {
    1823               int left_tree;
    1824               if ((*_blossom_data)[left_blossom].status == EVEN) {
    1825                 left_tree = _tree_set->find(left_blossom);
    1826               } else {
    1827                 left_tree = -1;
    1828                 ++unmatched;
    1829               }
    1830               int right_tree;
    1831               if ((*_blossom_data)[right_blossom].status == EVEN) {
    1832                 right_tree = _tree_set->find(right_blossom);
    1833               } else {
    1834                 right_tree = -1;
    1835                 ++unmatched;
    1836               }
     1881              int left_tree = _tree_set->find(left_blossom);
     1882              int right_tree = _tree_set->find(right_blossom);
    18371883
    18381884              if (left_tree == right_tree) {
     
    18401886              } else {
    18411887                augmentOnEdge(e);
    1842                 unmatched -= 2;
     1888                _unmatched -= 2;
    18431889              }
    18441890            }
     
    18581904    /// \note mwm.run() is just a shortcut of the following code.
    18591905    /// \code
    1860     ///   mwm.init();
     1906    ///   mwm.fractionalInit();
    18611907    ///   mwm.start();
    18621908    /// \endcode
    18631909    void run() {
    1864       init();
     1910      fractionalInit();
    18651911      start();
    18661912    }
     
    18691915
    18701916    /// \name Primal Solution
    1871     /// Functions to get the primal solution, i.e. the maximum weighted 
     1917    /// Functions to get the primal solution, i.e. the maximum weighted
    18721918    /// matching.\n
    18731919    /// Either \ref run() or \ref start() function should be called before
     
    18881934        }
    18891935      }
    1890       return sum /= 2;
     1936      return sum / 2;
    18911937    }
    18921938
     
    19081954    /// \brief Return \c true if the given edge is in the matching.
    19091955    ///
    1910     /// This function returns \c true if the given edge is in the found 
     1956    /// This function returns \c true if the given edge is in the found
    19111957    /// matching.
    19121958    ///
     
    19191965    ///
    19201966    /// This function returns the matching arc (or edge) incident to the
    1921     /// given node in the found matching or \c INVALID if the node is 
     1967    /// given node in the found matching or \c INVALID if the node is
    19221968    /// not covered by the matching.
    19231969    ///
     
    19371983    /// \brief Return the mate of the given node.
    19381984    ///
    1939     /// This function returns the mate of the given node in the found 
     1985    /// This function returns the mate of the given node in the found
    19401986    /// matching or \c INVALID if the node is not covered by the matching.
    19411987    ///
     
    19572003    /// \brief Return the value of the dual solution.
    19582004    ///
    1959     /// This function returns the value of the dual solution. 
    1960     /// It should be equal to the primal value scaled by \ref dualScale 
     2005    /// This function returns the value of the dual solution.
     2006    /// It should be equal to the primal value scaled by \ref dualScale
    19612007    /// "dual scale".
    19622008    ///
     
    20132059    /// \brief Iterator for obtaining the nodes of a blossom.
    20142060    ///
    2015     /// This class provides an iterator for obtaining the nodes of the 
     2061    /// This class provides an iterator for obtaining the nodes of the
    20162062    /// given blossom. It lists a subset of the nodes.
    2017     /// Before using this iterator, you must allocate a 
     2063    /// Before using this iterator, you must allocate a
    20182064    /// MaxWeightedMatching class and execute it.
    20192065    class BlossomIt {
     
    20242070      /// Constructor to get the nodes of the given variable.
    20252071      ///
    2026       /// \pre Either \ref MaxWeightedMatching::run() "algorithm.run()" or 
    2027       /// \ref MaxWeightedMatching::start() "algorithm.start()" must be 
     2072      /// \pre Either \ref MaxWeightedMatching::run() "algorithm.run()" or
     2073      /// \ref MaxWeightedMatching::start() "algorithm.start()" must be
    20282074      /// called before initializing this iterator.
    20292075      BlossomIt(const MaxWeightedMatching& algorithm, int variable)
     
    20782124  /// \f$O(nm\log n)\f$ time complexity.
    20792125  ///
    2080   /// The maximum weighted perfect matching problem is to find a subset of 
    2081   /// the edges in an undirected graph with maximum overall weight for which 
     2126  /// The maximum weighted perfect matching problem is to find a subset of
     2127  /// the edges in an undirected graph with maximum overall weight for which
    20822128  /// each node has exactly one incident edge.
    20832129  /// It can be formulated with the following linear program.
     
    21022148      \frac{\vert B \vert - 1}{2}z_B\f] */
    21032149  ///
    2104   /// The algorithm can be executed with the run() function. 
     2150  /// The algorithm can be executed with the run() function.
    21052151  /// After it the matching (the primal solution) and the dual solution
    2106   /// can be obtained using the query functions and the 
    2107   /// \ref MaxWeightedPerfectMatching::BlossomIt "BlossomIt" nested class, 
    2108   /// which is able to iterate on the nodes of a blossom. 
     2152  /// can be obtained using the query functions and the
     2153  /// \ref MaxWeightedPerfectMatching::BlossomIt "BlossomIt" nested class,
     2154  /// which is able to iterate on the nodes of a blossom.
    21092155  /// If the value type is integer, then the dual solution is multiplied
    21102156  /// by \ref MaxWeightedMatching::dualScale "4".
    21112157  ///
    21122158  /// \tparam GR The undirected graph type the algorithm runs on.
    2113   /// \tparam WM The type edge weight map. The default type is 
     2159  /// \tparam WM The type edge weight map. The default type is
    21142160  /// \ref concepts::Graph::EdgeMap "GR::EdgeMap<int>".
    21152161#ifdef DOXYGEN
     
    22222268
    22232269    Value _delta_sum;
     2270    int _unmatched;
     2271
     2272    typedef MaxWeightedPerfectFractionalMatching<Graph, WeightMap>
     2273    FractionalMatching;
     2274    FractionalMatching *_fractional;
    22242275
    22252276    void createStructures() {
     
    22832334
    22842335    void destroyStructures() {
    2285       _node_num = countNodes(_graph);
    2286       _blossom_num = _node_num * 3 / 2;
    2287 
    22882336      if (_matching) {
    22892337        delete _matching;
     
    29583006        _delta4_index(0), _delta4(0),
    29593007
    2960         _delta_sum() {}
     3008        _delta_sum(), _unmatched(0),
     3009
     3010        _fractional(0)
     3011    {}
    29613012
    29623013    ~MaxWeightedPerfectMatching() {
    29633014      destroyStructures();
     3015      if (_fractional) {
     3016        delete _fractional;
     3017      }
    29643018    }
    29653019
     
    29893043        (*_delta4_index)[i] = _delta4->PRE_HEAP;
    29903044      }
     3045
     3046      _unmatched = _node_num;
    29913047
    29923048      _delta2->clear();
     
    30313087    }
    30323088
     3089    /// \brief Initialize the algorithm with fractional matching
     3090    ///
     3091    /// This function initializes the algorithm with a fractional
     3092    /// matching. This initialization is also called jumpstart heuristic.
     3093    void fractionalInit() {
     3094      createStructures();
     3095
     3096      _blossom_node_list.clear();
     3097      _blossom_potential.clear();
     3098
     3099      if (_fractional == 0) {
     3100        _fractional = new FractionalMatching(_graph, _weight, false);
     3101      }
     3102      if (!_fractional->run()) {
     3103        _unmatched = -1;
     3104        return;
     3105      }
     3106
     3107      for (ArcIt e(_graph); e != INVALID; ++e) {
     3108        (*_node_heap_index)[e] = BinHeap<Value, IntArcMap>::PRE_HEAP;
     3109      }
     3110      for (EdgeIt e(_graph); e != INVALID; ++e) {
     3111        (*_delta3_index)[e] = _delta3->PRE_HEAP;
     3112      }
     3113      for (int i = 0; i < _blossom_num; ++i) {
     3114        (*_delta2_index)[i] = _delta2->PRE_HEAP;
     3115        (*_delta4_index)[i] = _delta4->PRE_HEAP;
     3116      }
     3117
     3118      _unmatched = 0;
     3119
     3120      _delta2->clear();
     3121      _delta3->clear();
     3122      _delta4->clear();
     3123      _blossom_set->clear();
     3124      _tree_set->clear();
     3125
     3126      int index = 0;
     3127      for (NodeIt n(_graph); n != INVALID; ++n) {
     3128        Value pot = _fractional->nodeValue(n);
     3129        (*_node_index)[n] = index;
     3130        (*_node_data)[index].pot = pot;
     3131        (*_node_data)[index].heap_index.clear();
     3132        (*_node_data)[index].heap.clear();
     3133        int blossom =
     3134          _blossom_set->insert(n, std::numeric_limits<Value>::max());
     3135
     3136        (*_blossom_data)[blossom].status = MATCHED;
     3137        (*_blossom_data)[blossom].pred = INVALID;
     3138        (*_blossom_data)[blossom].next = _fractional->matching(n);
     3139        (*_blossom_data)[blossom].pot = 0;
     3140        (*_blossom_data)[blossom].offset = 0;
     3141        ++index;
     3142      }
     3143
     3144      typename Graph::template NodeMap<bool> processed(_graph, false);
     3145      for (NodeIt n(_graph); n != INVALID; ++n) {
     3146        if (processed[n]) continue;
     3147        processed[n] = true;
     3148        if (_fractional->matching(n) == INVALID) continue;
     3149        int num = 1;
     3150        Node v = _graph.target(_fractional->matching(n));
     3151        while (n != v) {
     3152          processed[v] = true;
     3153          v = _graph.target(_fractional->matching(v));
     3154          ++num;
     3155        }
     3156
     3157        if (num % 2 == 1) {
     3158          std::vector<int> subblossoms(num);
     3159
     3160          subblossoms[--num] = _blossom_set->find(n);
     3161          v = _graph.target(_fractional->matching(n));
     3162          while (n != v) {
     3163            subblossoms[--num] = _blossom_set->find(v);
     3164            v = _graph.target(_fractional->matching(v));
     3165          }
     3166
     3167          int surface =
     3168            _blossom_set->join(subblossoms.begin(), subblossoms.end());
     3169          (*_blossom_data)[surface].status = EVEN;
     3170          (*_blossom_data)[surface].pred = INVALID;
     3171          (*_blossom_data)[surface].next = INVALID;
     3172          (*_blossom_data)[surface].pot = 0;
     3173          (*_blossom_data)[surface].offset = 0;
     3174
     3175          _tree_set->insert(surface);
     3176          ++_unmatched;
     3177        }
     3178      }
     3179
     3180      for (EdgeIt e(_graph); e != INVALID; ++e) {
     3181        int si = (*_node_index)[_graph.u(e)];
     3182        int sb = _blossom_set->find(_graph.u(e));
     3183        int ti = (*_node_index)[_graph.v(e)];
     3184        int tb = _blossom_set->find(_graph.v(e));
     3185        if ((*_blossom_data)[sb].status == EVEN &&
     3186            (*_blossom_data)[tb].status == EVEN && sb != tb) {
     3187          _delta3->push(e, ((*_node_data)[si].pot + (*_node_data)[ti].pot -
     3188                            dualScale * _weight[e]) / 2);
     3189        }
     3190      }
     3191
     3192      for (NodeIt n(_graph); n != INVALID; ++n) {
     3193        int nb = _blossom_set->find(n);
     3194        if ((*_blossom_data)[nb].status != MATCHED) continue;
     3195        int ni = (*_node_index)[n];
     3196
     3197        for (OutArcIt e(_graph, n); e != INVALID; ++e) {
     3198          Node v = _graph.target(e);
     3199          int vb = _blossom_set->find(v);
     3200          int vi = (*_node_index)[v];
     3201
     3202          Value rw = (*_node_data)[ni].pot + (*_node_data)[vi].pot -
     3203            dualScale * _weight[e];
     3204
     3205          if ((*_blossom_data)[vb].status == EVEN) {
     3206
     3207            int vt = _tree_set->find(vb);
     3208
     3209            typename std::map<int, Arc>::iterator it =
     3210              (*_node_data)[ni].heap_index.find(vt);
     3211
     3212            if (it != (*_node_data)[ni].heap_index.end()) {
     3213              if ((*_node_data)[ni].heap[it->second] > rw) {
     3214                (*_node_data)[ni].heap.replace(it->second, e);
     3215                (*_node_data)[ni].heap.decrease(e, rw);
     3216                it->second = e;
     3217              }
     3218            } else {
     3219              (*_node_data)[ni].heap.push(e, rw);
     3220              (*_node_data)[ni].heap_index.insert(std::make_pair(vt, e));
     3221            }
     3222          }
     3223        }
     3224
     3225        if (!(*_node_data)[ni].heap.empty()) {
     3226          _blossom_set->decrease(n, (*_node_data)[ni].heap.prio());
     3227          _delta2->push(nb, _blossom_set->classPrio(nb));
     3228        }
     3229      }
     3230    }
     3231
    30333232    /// \brief Start the algorithm
    30343233    ///
    30353234    /// This function starts the algorithm.
    30363235    ///
    3037     /// \pre \ref init() must be called before using this function.
     3236    /// \pre \ref init() or \ref fractionalInit() must be called before
     3237    /// using this function.
    30383238    bool start() {
    30393239      enum OpType {
     
    30413241      };
    30423242
    3043       int unmatched = _node_num;
    3044       while (unmatched > 0) {
     3243      if (_unmatched == -1) return false;
     3244
     3245      while (_unmatched > 0) {
    30453246        Value d2 = !_delta2->empty() ?
    30463247          _delta2->prio() : std::numeric_limits<Value>::max();
     
    30523253          _delta4->prio() : std::numeric_limits<Value>::max();
    30533254
    3054         _delta_sum = d2; OpType ot = D2;
    3055         if (d3 < _delta_sum) { _delta_sum = d3; ot = D3; }
     3255        _delta_sum = d3; OpType ot = D3;
     3256        if (d2 < _delta_sum) { _delta_sum = d2; ot = D2; }
    30563257        if (d4 < _delta_sum) { _delta_sum = d4; ot = D4; }
    30573258
     
    30863287              } else {
    30873288                augmentOnEdge(e);
    3088                 unmatched -= 2;
     3289                _unmatched -= 2;
    30893290              }
    30903291            }
     
    31053306    /// \note mwpm.run() is just a shortcut of the following code.
    31063307    /// \code
    3107     ///   mwpm.init();
     3308    ///   mwpm.fractionalInit();
    31083309    ///   mwpm.start();
    31093310    /// \endcode
    31103311    bool run() {
    3111       init();
     3312      fractionalInit();
    31123313      return start();
    31133314    }
     
    31163317
    31173318    /// \name Primal Solution
    3118     /// Functions to get the primal solution, i.e. the maximum weighted 
     3319    /// Functions to get the primal solution, i.e. the maximum weighted
    31193320    /// perfect matching.\n
    31203321    /// Either \ref run() or \ref start() function should be called before
     
    31353336        }
    31363337      }
    3137       return sum /= 2;
     3338      return sum / 2;
    31383339    }
    31393340
    31403341    /// \brief Return \c true if the given edge is in the matching.
    31413342    ///
    3142     /// This function returns \c true if the given edge is in the found 
     3343    /// This function returns \c true if the given edge is in the found
    31433344    /// matching.
    31443345    ///
     
    31513352    ///
    31523353    /// This function returns the matching arc (or edge) incident to the
    3153     /// given node in the found matching or \c INVALID if the node is 
     3354    /// given node in the found matching or \c INVALID if the node is
    31543355    /// not covered by the matching.
    31553356    ///
     
    31693370    /// \brief Return the mate of the given node.
    31703371    ///
    3171     /// This function returns the mate of the given node in the found 
     3372    /// This function returns the mate of the given node in the found
    31723373    /// matching or \c INVALID if the node is not covered by the matching.
    31733374    ///
     
    31883389    /// \brief Return the value of the dual solution.
    31893390    ///
    3190     /// This function returns the value of the dual solution. 
    3191     /// It should be equal to the primal value scaled by \ref dualScale 
     3391    /// This function returns the value of the dual solution.
     3392    /// It should be equal to the primal value scaled by \ref dualScale
    31923393    /// "dual scale".
    31933394    ///
     
    32443445    /// \brief Iterator for obtaining the nodes of a blossom.
    32453446    ///
    3246     /// This class provides an iterator for obtaining the nodes of the 
     3447    /// This class provides an iterator for obtaining the nodes of the
    32473448    /// given blossom. It lists a subset of the nodes.
    3248     /// Before using this iterator, you must allocate a 
     3449    /// Before using this iterator, you must allocate a
    32493450    /// MaxWeightedPerfectMatching class and execute it.
    32503451    class BlossomIt {
     
    32553456      /// Constructor to get the nodes of the given variable.
    32563457      ///
    3257       /// \pre Either \ref MaxWeightedPerfectMatching::run() "algorithm.run()" 
    3258       /// or \ref MaxWeightedPerfectMatching::start() "algorithm.start()" 
     3458      /// \pre Either \ref MaxWeightedPerfectMatching::run() "algorithm.run()"
     3459      /// or \ref MaxWeightedPerfectMatching::start() "algorithm.start()"
    32593460      /// must be called before initializing this iterator.
    32603461      BlossomIt(const MaxWeightedPerfectMatching& algorithm, int variable)
     
    33023503} //END OF NAMESPACE LEMON
    33033504
    3304 #endif //LEMON_MAX_MATCHING_H
     3505#endif //LEMON_MATCHING_H
  • TabularUnified lemon/math.h

    r558 r956  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    5757
    5858  ///Check whether the parameter is NaN or not
    59  
     59
    6060  ///This function checks whether the parameter is NaN or not.
    6161  ///Is should be equivalent with std::isnan(), but it is not
  • TabularUnified lemon/min_cost_arborescence.h

    r672 r956  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2008
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    113113  /// it is necessary. The default map type is \ref
    114114  /// concepts::Digraph::ArcMap "Digraph::ArcMap<int>".
    115   /// \param TR Traits class to set various data types used
    116   /// by the algorithm. The default traits class is
    117   /// \ref MinCostArborescenceDefaultTraits
     115  /// \tparam TR The traits class that defines various types used by the
     116  /// algorithm. By default, it is \ref MinCostArborescenceDefaultTraits
    118117  /// "MinCostArborescenceDefaultTraits<GR, CM>".
     118  /// In most cases, this parameter should not be set directly,
     119  /// consider to use the named template parameters instead.
    119120#ifndef DOXYGEN
    120121  template <typename GR,
     
    123124              MinCostArborescenceDefaultTraits<GR, CM> >
    124125#else
    125   template <typename GR, typename CM, typedef TR>
     126  template <typename GR, typename CM, typename TR>
    126127#endif
    127128  class MinCostArborescence {
    128129  public:
    129130
    130     /// \brief The \ref MinCostArborescenceDefaultTraits "traits class" 
    131     /// of the algorithm. 
     131    /// \brief The \ref MinCostArborescenceDefaultTraits "traits class"
     132    /// of the algorithm.
    132133    typedef TR Traits;
    133134    /// The type of the underlying digraph.
     
    436437    /// \ref named-templ-param "Named parameter" for setting
    437438    /// \c PredMap type.
    438     /// It must meet the \ref concepts::WriteMap "WriteMap" concept, 
     439    /// It must meet the \ref concepts::WriteMap "WriteMap" concept,
    439440    /// and its value type must be the \c Arc type of the digraph.
    440441    template <class T>
     
    489490    /// The simplest way to execute the algorithm is to use
    490491    /// one of the member functions called \c run(...). \n
    491     /// If you need more control on the execution,
    492     /// first you must call \ref init(), then you can add several
     492    /// If you need better control on the execution,
     493    /// you have to call \ref init() first, then you can add several
    493494    /// source nodes with \ref addSource().
    494495    /// Finally \ref start() will perform the arborescence
  • TabularUnified lemon/network_simplex.h

    r976 r978  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    4141  ///
    4242  /// \ref NetworkSimplex implements the primal Network Simplex algorithm
    43   /// for finding a \ref min_cost_flow "minimum cost flow".
    44   /// This algorithm is a specialized version of the linear programming
    45   /// simplex method directly for the minimum cost flow problem.
    46   /// It is one of the most efficient solution methods.
     43  /// for finding a \ref min_cost_flow "minimum cost flow"
     44  /// \ref amo93networkflows, \ref dantzig63linearprog,
     45  /// \ref kellyoneill91netsimplex.
     46  /// This algorithm is a highly efficient specialized version of the
     47  /// linear programming simplex method directly for the minimum cost
     48  /// flow problem.
    4749  ///
    48   /// In general this class is the fastest implementation available
    49   /// in LEMON for the minimum cost flow problem.
    50   /// Moreover it supports both directions of the supply/demand inequality
    51   /// constraints. For more information see \ref SupplyType.
     50  /// In general, %NetworkSimplex is the fastest implementation available
     51  /// in LEMON for this problem.
     52  /// Moreover, it supports both directions of the supply/demand inequality
     53  /// constraints. For more information, see \ref SupplyType.
    5254  ///
    5355  /// Most of the parameters of the problem (except for the digraph)
     
    5759  ///
    5860  /// \tparam GR The digraph type the algorithm runs on.
    59   /// \tparam V The value type used for flow amounts, capacity bounds
    60   /// and supply values in the algorithm. By default it is \c int.
    61   /// \tparam C The value type used for costs and potentials in the
    62   /// algorithm. By default it is the same as \c V.
     61  /// \tparam V The number type used for flow amounts, capacity bounds
     62  /// and supply values in the algorithm. By default, it is \c int.
     63  /// \tparam C The number type used for costs and potentials in the
     64  /// algorithm. By default, it is the same as \c V.
    6365  ///
    64   /// \warning Both value types must be signed and all input data must
     66  /// \warning Both number types must be signed and all input data must
    6567  /// be integer.
    6668  ///
    6769  /// \note %NetworkSimplex provides five different pivot rule
    6870  /// implementations, from which the most efficient one is used
    69   /// by default. For more information see \ref PivotRule.
     71  /// by default. For more information, see \ref PivotRule.
    7072  template <typename GR, typename V = int, typename C = V>
    7173  class NetworkSimplex
     
    9698      UNBOUNDED
    9799    };
    98    
     100
    99101    /// \brief Constants for selecting the type of the supply constraints.
    100102    ///
     
    114116      LEQ
    115117    };
    116    
     118
    117119    /// \brief Constants for selecting the pivot rule.
    118120    ///
     
    123125    /// implementations that significantly affect the running time
    124126    /// of the algorithm.
    125     /// By default \ref BLOCK_SEARCH "Block Search" is used, which
     127    /// By default, \ref BLOCK_SEARCH "Block Search" is used, which
    126128    /// proved to be the most efficient and the most robust on various
    127     /// test inputs according to our benchmark tests.
    128     /// However another pivot rule can be selected using the \ref run()
     129    /// test inputs.
     130    /// However, another pivot rule can be selected using the \ref run()
    129131    /// function with the proper parameter.
    130132    enum PivotRule {
    131133
    132       /// The First Eligible pivot rule.
     134      /// The \e First \e Eligible pivot rule.
    133135      /// The next eligible arc is selected in a wraparound fashion
    134136      /// in every iteration.
    135137      FIRST_ELIGIBLE,
    136138
    137       /// The Best Eligible pivot rule.
     139      /// The \e Best \e Eligible pivot rule.
    138140      /// The best eligible arc is selected in every iteration.
    139141      BEST_ELIGIBLE,
    140142
    141       /// The Block Search pivot rule.
     143      /// The \e Block \e Search pivot rule.
    142144      /// A specified number of arcs are examined in every iteration
    143145      /// in a wraparound fashion and the best eligible arc is selected
     
    145147      BLOCK_SEARCH,
    146148
    147       /// The Candidate List pivot rule.
     149      /// The \e Candidate \e List pivot rule.
    148150      /// In a major iteration a candidate list is built from eligible arcs
    149151      /// in a wraparound fashion and in the following minor iterations
     
    151153      CANDIDATE_LIST,
    152154
    153       /// The Altering Candidate List pivot rule.
     155      /// The \e Altering \e Candidate \e List pivot rule.
    154156      /// It is a modified version of the Candidate List method.
    155157      /// It keeps only the several best eligible arcs from the former
     
    157159      ALTERING_LIST
    158160    };
    159    
     161
    160162  private:
    161163
    162164    TEMPLATE_DIGRAPH_TYPEDEFS(GR);
    163165
    164     typedef std::vector<Arc> ArcVector;
    165     typedef std::vector<Node> NodeVector;
    166166    typedef std::vector<int> IntVector;
    167     typedef std::vector<bool> BoolVector;
    168167    typedef std::vector<Value> ValueVector;
    169168    typedef std::vector<Cost> CostVector;
     169    typedef std::vector<char> BoolVector;
     170    // Note: vector<char> is used instead of vector<bool> for efficiency reasons
    170171
    171172    // State constants for arcs
    172     enum ArcStateEnum {
     173    enum ArcState {
    173174      STATE_UPPER = -1,
    174175      STATE_TREE  =  0,
    175176      STATE_LOWER =  1
    176177    };
     178
     179    typedef std::vector<signed char> StateVector;
     180    // Note: vector<signed char> is used instead of vector<ArcState> for
     181    // efficiency reasons
    177182
    178183  private:
     
    195200    IntVector _source;
    196201    IntVector _target;
     202    bool _arc_mixing;
    197203
    198204    // Node and arc data
     
    214220    IntVector _dirty_revs;
    215221    BoolVector _forward;
    216     IntVector _state;
     222    StateVector _state;
    217223    int _root;
    218224
     
    223229    Value delta;
    224230
     231    const Value MAX;
     232
    225233  public:
    226  
     234
    227235    /// \brief Constant for infinite upper bounds (capacities).
    228236    ///
     
    243251      const IntVector  &_target;
    244252      const CostVector &_cost;
    245       const IntVector &_state;
     253      const StateVector &_state;
    246254      const CostVector &_pi;
    247255      int &_in_arc;
     
    264272      bool findEnteringArc() {
    265273        Cost c;
    266         for (int e = _next_arc; e < _search_arc_num; ++e) {
     274        for (int e = _next_arc; e != _search_arc_num; ++e) {
    267275          c = _state[e] * (_cost[e] + _pi[_source[e]] - _pi[_target[e]]);
    268276          if (c < 0) {
     
    272280          }
    273281        }
    274         for (int e = 0; e < _next_arc; ++e) {
     282        for (int e = 0; e != _next_arc; ++e) {
    275283          c = _state[e] * (_cost[e] + _pi[_source[e]] - _pi[_target[e]]);
    276284          if (c < 0) {
     
    295303      const IntVector  &_target;
    296304      const CostVector &_cost;
    297       const IntVector &_state;
     305      const StateVector &_state;
    298306      const CostVector &_pi;
    299307      int &_in_arc;
     
    312320      bool findEnteringArc() {
    313321        Cost c, min = 0;
    314         for (int e = 0; e < _search_arc_num; ++e) {
     322        for (int e = 0; e != _search_arc_num; ++e) {
    315323          c = _state[e] * (_cost[e] + _pi[_source[e]] - _pi[_target[e]]);
    316324          if (c < min) {
     
    334342      const IntVector  &_target;
    335343      const CostVector &_cost;
    336       const IntVector &_state;
     344      const StateVector &_state;
    337345      const CostVector &_pi;
    338346      int &_in_arc;
     
    353361      {
    354362        // The main parameters of the pivot rule
    355         const double BLOCK_SIZE_FACTOR = 0.5;
     363        const double BLOCK_SIZE_FACTOR = 1.0;
    356364        const int MIN_BLOCK_SIZE = 10;
    357365
     
    365373        Cost c, min = 0;
    366374        int cnt = _block_size;
    367         int e, min_arc = _next_arc;
    368         for (e = _next_arc; e < _search_arc_num; ++e) {
     375        int e;
     376        for (e = _next_arc; e != _search_arc_num; ++e) {
    369377          c = _state[e] * (_cost[e] + _pi[_source[e]] - _pi[_target[e]]);
    370378          if (c < min) {
    371379            min = c;
    372             min_arc = e;
     380            _in_arc = e;
    373381          }
    374382          if (--cnt == 0) {
    375             if (min < 0) break;
     383            if (min < 0) goto search_end;
    376384            cnt = _block_size;
    377385          }
    378386        }
    379         if (min == 0 || cnt > 0) {
    380           for (e = 0; e < _next_arc; ++e) {
    381             c = _state[e] * (_cost[e] + _pi[_source[e]] - _pi[_target[e]]);
    382             if (c < min) {
    383               min = c;
    384               min_arc = e;
    385             }
    386             if (--cnt == 0) {
    387               if (min < 0) break;
    388               cnt = _block_size;
    389             }
     387        for (e = 0; e != _next_arc; ++e) {
     388          c = _state[e] * (_cost[e] + _pi[_source[e]] - _pi[_target[e]]);
     389          if (c < min) {
     390            min = c;
     391            _in_arc = e;
     392          }
     393          if (--cnt == 0) {
     394            if (min < 0) goto search_end;
     395            cnt = _block_size;
    390396          }
    391397        }
    392398        if (min >= 0) return false;
    393         _in_arc = min_arc;
     399
     400      search_end:
    394401        _next_arc = e;
    395402        return true;
     
    408415      const IntVector  &_target;
    409416      const CostVector &_cost;
    410       const IntVector &_state;
     417      const StateVector &_state;
    411418      const CostVector &_pi;
    412419      int &_in_arc;
     
    429436      {
    430437        // The main parameters of the pivot rule
    431         const double LIST_LENGTH_FACTOR = 1.0;
     438        const double LIST_LENGTH_FACTOR = 0.25;
    432439        const int MIN_LIST_LENGTH = 10;
    433440        const double MINOR_LIMIT_FACTOR = 0.1;
     
    446453      bool findEnteringArc() {
    447454        Cost min, c;
    448         int e, min_arc = _next_arc;
     455        int e;
    449456        if (_curr_length > 0 && _minor_count < _minor_limit) {
    450457          // Minor iteration: select the best eligible arc from the
     
    457464            if (c < min) {
    458465              min = c;
    459               min_arc = e;
     466              _in_arc = e;
    460467            }
    461             if (c >= 0) {
     468            else if (c >= 0) {
    462469              _candidates[i--] = _candidates[--_curr_length];
    463470            }
    464471          }
    465           if (min < 0) {
    466             _in_arc = min_arc;
    467             return true;
    468           }
     472          if (min < 0) return true;
    469473        }
    470474
     
    472476        min = 0;
    473477        _curr_length = 0;
    474         for (e = _next_arc; e < _search_arc_num; ++e) {
     478        for (e = _next_arc; e != _search_arc_num; ++e) {
    475479          c = _state[e] * (_cost[e] + _pi[_source[e]] - _pi[_target[e]]);
    476480          if (c < 0) {
     
    478482            if (c < min) {
    479483              min = c;
    480               min_arc = e;
     484              _in_arc = e;
    481485            }
    482             if (_curr_length == _list_length) break;
    483           }
    484         }
    485         if (_curr_length < _list_length) {
    486           for (e = 0; e < _next_arc; ++e) {
    487             c = _state[e] * (_cost[e] + _pi[_source[e]] - _pi[_target[e]]);
    488             if (c < 0) {
    489               _candidates[_curr_length++] = e;
    490               if (c < min) {
    491                 min = c;
    492                 min_arc = e;
    493               }
    494               if (_curr_length == _list_length) break;
     486            if (_curr_length == _list_length) goto search_end;
     487          }
     488        }
     489        for (e = 0; e != _next_arc; ++e) {
     490          c = _state[e] * (_cost[e] + _pi[_source[e]] - _pi[_target[e]]);
     491          if (c < 0) {
     492            _candidates[_curr_length++] = e;
     493            if (c < min) {
     494              min = c;
     495              _in_arc = e;
    495496            }
     497            if (_curr_length == _list_length) goto search_end;
    496498          }
    497499        }
    498500        if (_curr_length == 0) return false;
     501
     502      search_end:
    499503        _minor_count = 1;
    500         _in_arc = min_arc;
    501504        _next_arc = e;
    502505        return true;
     
    515518      const IntVector  &_target;
    516519      const CostVector &_cost;
    517       const IntVector &_state;
     520      const StateVector &_state;
    518521      const CostVector &_pi;
    519522      int &_in_arc;
     
    550553      {
    551554        // The main parameters of the pivot rule
    552         const double BLOCK_SIZE_FACTOR = 1.5;
     555        const double BLOCK_SIZE_FACTOR = 1.0;
    553556        const int MIN_BLOCK_SIZE = 10;
    554557        const double HEAD_LENGTH_FACTOR = 0.1;
     
    568571        // Check the current candidate list
    569572        int e;
    570         for (int i = 0; i < _curr_length; ++i) {
     573        for (int i = 0; i != _curr_length; ++i) {
    571574          e = _candidates[i];
    572575          _cand_cost[e] = _state[e] *
     
    579582        // Extend the list
    580583        int cnt = _block_size;
    581         int last_arc = 0;
    582584        int limit = _head_length;
    583585
    584         for (int e = _next_arc; e < _search_arc_num; ++e) {
     586        for (e = _next_arc; e != _search_arc_num; ++e) {
    585587          _cand_cost[e] = _state[e] *
    586588            (_cost[e] + _pi[_source[e]] - _pi[_target[e]]);
    587589          if (_cand_cost[e] < 0) {
    588590            _candidates[_curr_length++] = e;
    589             last_arc = e;
    590591          }
    591592          if (--cnt == 0) {
    592             if (_curr_length > limit) break;
     593            if (_curr_length > limit) goto search_end;
    593594            limit = 0;
    594595            cnt = _block_size;
    595596          }
    596597        }
    597         if (_curr_length <= limit) {
    598           for (int e = 0; e < _next_arc; ++e) {
    599             _cand_cost[e] = _state[e] *
    600               (_cost[e] + _pi[_source[e]] - _pi[_target[e]]);
    601             if (_cand_cost[e] < 0) {
    602               _candidates[_curr_length++] = e;
    603               last_arc = e;
    604             }
    605             if (--cnt == 0) {
    606               if (_curr_length > limit) break;
    607               limit = 0;
    608               cnt = _block_size;
    609             }
     598        for (e = 0; e != _next_arc; ++e) {
     599          _cand_cost[e] = _state[e] *
     600            (_cost[e] + _pi[_source[e]] - _pi[_target[e]]);
     601          if (_cand_cost[e] < 0) {
     602            _candidates[_curr_length++] = e;
     603          }
     604          if (--cnt == 0) {
     605            if (_curr_length > limit) goto search_end;
     606            limit = 0;
     607            cnt = _block_size;
    610608          }
    611609        }
    612610        if (_curr_length == 0) return false;
    613         _next_arc = last_arc + 1;
     611
     612      search_end:
    614613
    615614        // Make heap of the candidate list (approximating a partial sort)
     
    619618        // Pop the first element of the heap
    620619        _in_arc = _candidates[0];
     620        _next_arc = e;
    621621        pop_heap( _candidates.begin(), _candidates.begin() + _curr_length,
    622622                  _sort_func );
     
    634634    ///
    635635    /// \param graph The digraph the algorithm runs on.
    636     NetworkSimplex(const GR& graph) :
     636    /// \param arc_mixing Indicate if the arcs have to be stored in a
     637    /// mixed order in the internal data structure.
     638    /// In special cases, it could lead to better overall performance,
     639    /// but it is usually slower. Therefore it is disabled by default.
     640    NetworkSimplex(const GR& graph, bool arc_mixing = false) :
    637641      _graph(graph), _node_id(graph), _arc_id(graph),
     642      _arc_mixing(arc_mixing),
     643      MAX(std::numeric_limits<Value>::max()),
    638644      INF(std::numeric_limits<Value>::has_infinity ?
    639           std::numeric_limits<Value>::infinity() :
    640           std::numeric_limits<Value>::max())
     645          std::numeric_limits<Value>::infinity() : MAX)
    641646    {
    642       // Check the value types
     647      // Check the number types
    643648      LEMON_ASSERT(std::numeric_limits<Value>::is_signed,
    644649        "The flow type of NetworkSimplex must be signed");
    645650      LEMON_ASSERT(std::numeric_limits<Cost>::is_signed,
    646651        "The cost type of NetworkSimplex must be signed");
    647        
     652
     653      // Reset data structures
     654      reset();
     655    }
     656
     657    /// \name Parameters
     658    /// The parameters of the algorithm can be specified using these
     659    /// functions.
     660
     661    /// @{
     662
     663    /// \brief Set the lower bounds on the arcs.
     664    ///
     665    /// This function sets the lower bounds on the arcs.
     666    /// If it is not used before calling \ref run(), the lower bounds
     667    /// will be set to zero on all arcs.
     668    ///
     669    /// \param map An arc map storing the lower bounds.
     670    /// Its \c Value type must be convertible to the \c Value type
     671    /// of the algorithm.
     672    ///
     673    /// \return <tt>(*this)</tt>
     674    template <typename LowerMap>
     675    NetworkSimplex& lowerMap(const LowerMap& map) {
     676      _have_lower = true;
     677      for (ArcIt a(_graph); a != INVALID; ++a) {
     678        _lower[_arc_id[a]] = map[a];
     679      }
     680      return *this;
     681    }
     682
     683    /// \brief Set the upper bounds (capacities) on the arcs.
     684    ///
     685    /// This function sets the upper bounds (capacities) on the arcs.
     686    /// If it is not used before calling \ref run(), the upper bounds
     687    /// will be set to \ref INF on all arcs (i.e. the flow value will be
     688    /// unbounded from above).
     689    ///
     690    /// \param map An arc map storing the upper bounds.
     691    /// Its \c Value type must be convertible to the \c Value type
     692    /// of the algorithm.
     693    ///
     694    /// \return <tt>(*this)</tt>
     695    template<typename UpperMap>
     696    NetworkSimplex& upperMap(const UpperMap& map) {
     697      for (ArcIt a(_graph); a != INVALID; ++a) {
     698        _upper[_arc_id[a]] = map[a];
     699      }
     700      return *this;
     701    }
     702
     703    /// \brief Set the costs of the arcs.
     704    ///
     705    /// This function sets the costs of the arcs.
     706    /// If it is not used before calling \ref run(), the costs
     707    /// will be set to \c 1 on all arcs.
     708    ///
     709    /// \param map An arc map storing the costs.
     710    /// Its \c Value type must be convertible to the \c Cost type
     711    /// of the algorithm.
     712    ///
     713    /// \return <tt>(*this)</tt>
     714    template<typename CostMap>
     715    NetworkSimplex& costMap(const CostMap& map) {
     716      for (ArcIt a(_graph); a != INVALID; ++a) {
     717        _cost[_arc_id[a]] = map[a];
     718      }
     719      return *this;
     720    }
     721
     722    /// \brief Set the supply values of the nodes.
     723    ///
     724    /// This function sets the supply values of the nodes.
     725    /// If neither this function nor \ref stSupply() is used before
     726    /// calling \ref run(), the supply of each node will be set to zero.
     727    ///
     728    /// \param map A node map storing the supply values.
     729    /// Its \c Value type must be convertible to the \c Value type
     730    /// of the algorithm.
     731    ///
     732    /// \return <tt>(*this)</tt>
     733    template<typename SupplyMap>
     734    NetworkSimplex& supplyMap(const SupplyMap& map) {
     735      for (NodeIt n(_graph); n != INVALID; ++n) {
     736        _supply[_node_id[n]] = map[n];
     737      }
     738      return *this;
     739    }
     740
     741    /// \brief Set single source and target nodes and a supply value.
     742    ///
     743    /// This function sets a single source node and a single target node
     744    /// and the required flow value.
     745    /// If neither this function nor \ref supplyMap() is used before
     746    /// calling \ref run(), the supply of each node will be set to zero.
     747    ///
     748    /// Using this function has the same effect as using \ref supplyMap()
     749    /// with such a map in which \c k is assigned to \c s, \c -k is
     750    /// assigned to \c t and all other nodes have zero supply value.
     751    ///
     752    /// \param s The source node.
     753    /// \param t The target node.
     754    /// \param k The required amount of flow from node \c s to node \c t
     755    /// (i.e. the supply of \c s and the demand of \c t).
     756    ///
     757    /// \return <tt>(*this)</tt>
     758    NetworkSimplex& stSupply(const Node& s, const Node& t, Value k) {
     759      for (int i = 0; i != _node_num; ++i) {
     760        _supply[i] = 0;
     761      }
     762      _supply[_node_id[s]] =  k;
     763      _supply[_node_id[t]] = -k;
     764      return *this;
     765    }
     766
     767    /// \brief Set the type of the supply constraints.
     768    ///
     769    /// This function sets the type of the supply/demand constraints.
     770    /// If it is not used before calling \ref run(), the \ref GEQ supply
     771    /// type will be used.
     772    ///
     773    /// For more information, see \ref SupplyType.
     774    ///
     775    /// \return <tt>(*this)</tt>
     776    NetworkSimplex& supplyType(SupplyType supply_type) {
     777      _stype = supply_type;
     778      return *this;
     779    }
     780
     781    /// @}
     782
     783    /// \name Execution Control
     784    /// The algorithm can be executed using \ref run().
     785
     786    /// @{
     787
     788    /// \brief Run the algorithm.
     789    ///
     790    /// This function runs the algorithm.
     791    /// The paramters can be specified using functions \ref lowerMap(),
     792    /// \ref upperMap(), \ref costMap(), \ref supplyMap(), \ref stSupply(),
     793    /// \ref supplyType().
     794    /// For example,
     795    /// \code
     796    ///   NetworkSimplex<ListDigraph> ns(graph);
     797    ///   ns.lowerMap(lower).upperMap(upper).costMap(cost)
     798    ///     .supplyMap(sup).run();
     799    /// \endcode
     800    ///
     801    /// This function can be called more than once. All the given parameters
     802    /// are kept for the next call, unless \ref resetParams() or \ref reset()
     803    /// is used, thus only the modified parameters have to be set again.
     804    /// If the underlying digraph was also modified after the construction
     805    /// of the class (or the last \ref reset() call), then the \ref reset()
     806    /// function must be called.
     807    ///
     808    /// \param pivot_rule The pivot rule that will be used during the
     809    /// algorithm. For more information, see \ref PivotRule.
     810    ///
     811    /// \return \c INFEASIBLE if no feasible flow exists,
     812    /// \n \c OPTIMAL if the problem has optimal solution
     813    /// (i.e. it is feasible and bounded), and the algorithm has found
     814    /// optimal flow and node potentials (primal and dual solutions),
     815    /// \n \c UNBOUNDED if the objective function of the problem is
     816    /// unbounded, i.e. there is a directed cycle having negative total
     817    /// cost and infinite upper bound.
     818    ///
     819    /// \see ProblemType, PivotRule
     820    /// \see resetParams(), reset()
     821    ProblemType run(PivotRule pivot_rule = BLOCK_SEARCH) {
     822      if (!init()) return INFEASIBLE;
     823      return start(pivot_rule);
     824    }
     825
     826    /// \brief Reset all the parameters that have been given before.
     827    ///
     828    /// This function resets all the paramaters that have been given
     829    /// before using functions \ref lowerMap(), \ref upperMap(),
     830    /// \ref costMap(), \ref supplyMap(), \ref stSupply(), \ref supplyType().
     831    ///
     832    /// It is useful for multiple \ref run() calls. Basically, all the given
     833    /// parameters are kept for the next \ref run() call, unless
     834    /// \ref resetParams() or \ref reset() is used.
     835    /// If the underlying digraph was also modified after the construction
     836    /// of the class or the last \ref reset() call, then the \ref reset()
     837    /// function must be used, otherwise \ref resetParams() is sufficient.
     838    ///
     839    /// For example,
     840    /// \code
     841    ///   NetworkSimplex<ListDigraph> ns(graph);
     842    ///
     843    ///   // First run
     844    ///   ns.lowerMap(lower).upperMap(upper).costMap(cost)
     845    ///     .supplyMap(sup).run();
     846    ///
     847    ///   // Run again with modified cost map (resetParams() is not called,
     848    ///   // so only the cost map have to be set again)
     849    ///   cost[e] += 100;
     850    ///   ns.costMap(cost).run();
     851    ///
     852    ///   // Run again from scratch using resetParams()
     853    ///   // (the lower bounds will be set to zero on all arcs)
     854    ///   ns.resetParams();
     855    ///   ns.upperMap(capacity).costMap(cost)
     856    ///     .supplyMap(sup).run();
     857    /// \endcode
     858    ///
     859    /// \return <tt>(*this)</tt>
     860    ///
     861    /// \see reset(), run()
     862    NetworkSimplex& resetParams() {
     863      for (int i = 0; i != _node_num; ++i) {
     864        _supply[i] = 0;
     865      }
     866      for (int i = 0; i != _arc_num; ++i) {
     867        _lower[i] = 0;
     868        _upper[i] = INF;
     869        _cost[i] = 1;
     870      }
     871      _have_lower = false;
     872      _stype = GEQ;
     873      return *this;
     874    }
     875
     876    /// \brief Reset the internal data structures and all the parameters
     877    /// that have been given before.
     878    ///
     879    /// This function resets the internal data structures and all the
     880    /// paramaters that have been given before using functions \ref lowerMap(),
     881    /// \ref upperMap(), \ref costMap(), \ref supplyMap(), \ref stSupply(),
     882    /// \ref supplyType().
     883    ///
     884    /// It is useful for multiple \ref run() calls. Basically, all the given
     885    /// parameters are kept for the next \ref run() call, unless
     886    /// \ref resetParams() or \ref reset() is used.
     887    /// If the underlying digraph was also modified after the construction
     888    /// of the class or the last \ref reset() call, then the \ref reset()
     889    /// function must be used, otherwise \ref resetParams() is sufficient.
     890    ///
     891    /// See \ref resetParams() for examples.
     892    ///
     893    /// \return <tt>(*this)</tt>
     894    ///
     895    /// \see resetParams(), run()
     896    NetworkSimplex& reset() {
    648897      // Resize vectors
    649898      _node_num = countNodes(_graph);
     
    672921      _state.resize(max_arc_num);
    673922
    674       // Copy the graph (store the arcs in a mixed order)
     923      // Copy the graph
    675924      int i = 0;
    676925      for (NodeIt n(_graph); n != INVALID; ++n, ++i) {
    677926        _node_id[n] = i;
    678927      }
    679       int k = std::max(int(std::sqrt(double(_arc_num))), 10);
    680       i = 0;
    681       for (ArcIt a(_graph); a != INVALID; ++a) {
    682         _arc_id[a] = i;
    683         _source[i] = _node_id[_graph.source(a)];
    684         _target[i] = _node_id[_graph.target(a)];
    685         if ((i += k) >= _arc_num) i = (i % k) + 1;
    686       }
    687      
    688       // Initialize maps
    689       for (int i = 0; i != _node_num; ++i) {
    690         _supply[i] = 0;
    691       }
    692       for (int i = 0; i != _arc_num; ++i) {
    693         _lower[i] = 0;
    694         _upper[i] = INF;
    695         _cost[i] = 1;
    696       }
    697       _have_lower = false;
    698       _stype = GEQ;
    699     }
    700 
    701     /// \name Parameters
    702     /// The parameters of the algorithm can be specified using these
    703     /// functions.
    704 
    705     /// @{
    706 
    707     /// \brief Set the lower bounds on the arcs.
    708     ///
    709     /// This function sets the lower bounds on the arcs.
    710     /// If it is not used before calling \ref run(), the lower bounds
    711     /// will be set to zero on all arcs.
    712     ///
    713     /// \param map An arc map storing the lower bounds.
    714     /// Its \c Value type must be convertible to the \c Value type
    715     /// of the algorithm.
    716     ///
    717     /// \return <tt>(*this)</tt>
    718     template <typename LowerMap>
    719     NetworkSimplex& lowerMap(const LowerMap& map) {
    720       _have_lower = true;
    721       for (ArcIt a(_graph); a != INVALID; ++a) {
    722         _lower[_arc_id[a]] = map[a];
    723       }
    724       return *this;
    725     }
    726 
    727     /// \brief Set the upper bounds (capacities) on the arcs.
    728     ///
    729     /// This function sets the upper bounds (capacities) on the arcs.
    730     /// If it is not used before calling \ref run(), the upper bounds
    731     /// will be set to \ref INF on all arcs (i.e. the flow value will be
    732     /// unbounded from above on each arc).
    733     ///
    734     /// \param map An arc map storing the upper bounds.
    735     /// Its \c Value type must be convertible to the \c Value type
    736     /// of the algorithm.
    737     ///
    738     /// \return <tt>(*this)</tt>
    739     template<typename UpperMap>
    740     NetworkSimplex& upperMap(const UpperMap& map) {
    741       for (ArcIt a(_graph); a != INVALID; ++a) {
    742         _upper[_arc_id[a]] = map[a];
    743       }
    744       return *this;
    745     }
    746 
    747     /// \brief Set the costs of the arcs.
    748     ///
    749     /// This function sets the costs of the arcs.
    750     /// If it is not used before calling \ref run(), the costs
    751     /// will be set to \c 1 on all arcs.
    752     ///
    753     /// \param map An arc map storing the costs.
    754     /// Its \c Value type must be convertible to the \c Cost type
    755     /// of the algorithm.
    756     ///
    757     /// \return <tt>(*this)</tt>
    758     template<typename CostMap>
    759     NetworkSimplex& costMap(const CostMap& map) {
    760       for (ArcIt a(_graph); a != INVALID; ++a) {
    761         _cost[_arc_id[a]] = map[a];
    762       }
    763       return *this;
    764     }
    765 
    766     /// \brief Set the supply values of the nodes.
    767     ///
    768     /// This function sets the supply values of the nodes.
    769     /// If neither this function nor \ref stSupply() is used before
    770     /// calling \ref run(), the supply of each node will be set to zero.
    771     /// (It makes sense only if non-zero lower bounds are given.)
    772     ///
    773     /// \param map A node map storing the supply values.
    774     /// Its \c Value type must be convertible to the \c Value type
    775     /// of the algorithm.
    776     ///
    777     /// \return <tt>(*this)</tt>
    778     template<typename SupplyMap>
    779     NetworkSimplex& supplyMap(const SupplyMap& map) {
    780       for (NodeIt n(_graph); n != INVALID; ++n) {
    781         _supply[_node_id[n]] = map[n];
    782       }
    783       return *this;
    784     }
    785 
    786     /// \brief Set single source and target nodes and a supply value.
    787     ///
    788     /// This function sets a single source node and a single target node
    789     /// and the required flow value.
    790     /// If neither this function nor \ref supplyMap() is used before
    791     /// calling \ref run(), the supply of each node will be set to zero.
    792     /// (It makes sense only if non-zero lower bounds are given.)
    793     ///
    794     /// Using this function has the same effect as using \ref supplyMap()
    795     /// with such a map in which \c k is assigned to \c s, \c -k is
    796     /// assigned to \c t and all other nodes have zero supply value.
    797     ///
    798     /// \param s The source node.
    799     /// \param t The target node.
    800     /// \param k The required amount of flow from node \c s to node \c t
    801     /// (i.e. the supply of \c s and the demand of \c t).
    802     ///
    803     /// \return <tt>(*this)</tt>
    804     NetworkSimplex& stSupply(const Node& s, const Node& t, Value k) {
    805       for (int i = 0; i != _node_num; ++i) {
    806         _supply[i] = 0;
    807       }
    808       _supply[_node_id[s]] =  k;
    809       _supply[_node_id[t]] = -k;
    810       return *this;
    811     }
    812    
    813     /// \brief Set the type of the supply constraints.
    814     ///
    815     /// This function sets the type of the supply/demand constraints.
    816     /// If it is not used before calling \ref run(), the \ref GEQ supply
    817     /// type will be used.
    818     ///
    819     /// For more information see \ref SupplyType.
    820     ///
    821     /// \return <tt>(*this)</tt>
    822     NetworkSimplex& supplyType(SupplyType supply_type) {
    823       _stype = supply_type;
    824       return *this;
    825     }
    826 
    827     /// @}
    828 
    829     /// \name Execution Control
    830     /// The algorithm can be executed using \ref run().
    831 
    832     /// @{
    833 
    834     /// \brief Run the algorithm.
    835     ///
    836     /// This function runs the algorithm.
    837     /// The paramters can be specified using functions \ref lowerMap(),
    838     /// \ref upperMap(), \ref costMap(), \ref supplyMap(), \ref stSupply(),
    839     /// \ref supplyType().
    840     /// For example,
    841     /// \code
    842     ///   NetworkSimplex<ListDigraph> ns(graph);
    843     ///   ns.lowerMap(lower).upperMap(upper).costMap(cost)
    844     ///     .supplyMap(sup).run();
    845     /// \endcode
    846     ///
    847     /// This function can be called more than once. All the parameters
    848     /// that have been given are kept for the next call, unless
    849     /// \ref reset() is called, thus only the modified parameters
    850     /// have to be set again. See \ref reset() for examples.
    851     /// However the underlying digraph must not be modified after this
    852     /// class have been constructed, since it copies and extends the graph.
    853     ///
    854     /// \param pivot_rule The pivot rule that will be used during the
    855     /// algorithm. For more information see \ref PivotRule.
    856     ///
    857     /// \return \c INFEASIBLE if no feasible flow exists,
    858     /// \n \c OPTIMAL if the problem has optimal solution
    859     /// (i.e. it is feasible and bounded), and the algorithm has found
    860     /// optimal flow and node potentials (primal and dual solutions),
    861     /// \n \c UNBOUNDED if the objective function of the problem is
    862     /// unbounded, i.e. there is a directed cycle having negative total
    863     /// cost and infinite upper bound.
    864     ///
    865     /// \see ProblemType, PivotRule
    866     ProblemType run(PivotRule pivot_rule = BLOCK_SEARCH) {
    867       if (!init()) return INFEASIBLE;
    868       return start(pivot_rule);
    869     }
    870 
    871     /// \brief Reset all the parameters that have been given before.
    872     ///
    873     /// This function resets all the paramaters that have been given
    874     /// before using functions \ref lowerMap(), \ref upperMap(),
    875     /// \ref costMap(), \ref supplyMap(), \ref stSupply(), \ref supplyType().
    876     ///
    877     /// It is useful for multiple run() calls. If this function is not
    878     /// used, all the parameters given before are kept for the next
    879     /// \ref run() call.
    880     /// However the underlying digraph must not be modified after this
    881     /// class have been constructed, since it copies and extends the graph.
    882     ///
    883     /// For example,
    884     /// \code
    885     ///   NetworkSimplex<ListDigraph> ns(graph);
    886     ///
    887     ///   // First run
    888     ///   ns.lowerMap(lower).upperMap(upper).costMap(cost)
    889     ///     .supplyMap(sup).run();
    890     ///
    891     ///   // Run again with modified cost map (reset() is not called,
    892     ///   // so only the cost map have to be set again)
    893     ///   cost[e] += 100;
    894     ///   ns.costMap(cost).run();
    895     ///
    896     ///   // Run again from scratch using reset()
    897     ///   // (the lower bounds will be set to zero on all arcs)
    898     ///   ns.reset();
    899     ///   ns.upperMap(capacity).costMap(cost)
    900     ///     .supplyMap(sup).run();
    901     /// \endcode
    902     ///
    903     /// \return <tt>(*this)</tt>
    904     NetworkSimplex& reset() {
    905       for (int i = 0; i != _node_num; ++i) {
    906         _supply[i] = 0;
    907       }
    908       for (int i = 0; i != _arc_num; ++i) {
    909         _lower[i] = 0;
    910         _upper[i] = INF;
    911         _cost[i] = 1;
    912       }
    913       _have_lower = false;
    914       _stype = GEQ;
     928      if (_arc_mixing) {
     929        // Store the arcs in a mixed order
     930        int k = std::max(int(std::sqrt(double(_arc_num))), 10);
     931        int i = 0, j = 0;
     932        for (ArcIt a(_graph); a != INVALID; ++a) {
     933          _arc_id[a] = i;
     934          _source[i] = _node_id[_graph.source(a)];
     935          _target[i] = _node_id[_graph.target(a)];
     936          if ((i += k) >= _arc_num) i = ++j;
     937        }
     938      } else {
     939        // Store the arcs in the original order
     940        int i = 0;
     941        for (ArcIt a(_graph); a != INVALID; ++a, ++i) {
     942          _arc_id[a] = i;
     943          _source[i] = _node_id[_graph.source(a)];
     944          _target[i] = _node_id[_graph.target(a)];
     945        }
     946      }
     947
     948      // Reset parameters
     949      resetParams();
    915950      return *this;
    916951    }
     
    10251060          Value c = _lower[i];
    10261061          if (c >= 0) {
    1027             _cap[i] = _upper[i] < INF ? _upper[i] - c : INF;
     1062            _cap[i] = _upper[i] < MAX ? _upper[i] - c : INF;
    10281063          } else {
    1029             _cap[i] = _upper[i] < INF + c ? _upper[i] - c : INF;
     1064            _cap[i] = _upper[i] < MAX + c ? _upper[i] - c : INF;
    10301065          }
    10311066          _supply[_source[i]] -= c;
     
    10551090        _state[i] = STATE_LOWER;
    10561091      }
    1057      
     1092
    10581093      // Set data for the artificial root node
    10591094      _root = _node_num;
     
    12191254        e = _pred[u];
    12201255        d = _forward[u] ?
    1221           _flow[e] : (_cap[e] == INF ? INF : _cap[e] - _flow[e]);
     1256          _flow[e] : (_cap[e] >= MAX ? INF : _cap[e] - _flow[e]);
    12221257        if (d < delta) {
    12231258          delta = d;
     
    12291264      for (int u = second; u != join; u = _parent[u]) {
    12301265        e = _pred[u];
    1231         d = _forward[u] ? 
    1232           (_cap[e] == INF ? INF : _cap[e] - _flow[e]) : _flow[e];
     1266        d = _forward[u] ?
     1267          (_cap[e] >= MAX ? INF : _cap[e] - _flow[e]) : _flow[e];
    12331268        if (d <= delta) {
    12341269          delta = d;
     
    13311366
    13321367      // Update _rev_thread using the new _thread values
    1333       for (int i = 0; i < int(_dirty_revs.size()); ++i) {
     1368      for (int i = 0; i != int(_dirty_revs.size()); ++i) {
    13341369        u = _dirty_revs[i];
    13351370        _rev_thread[_thread[u]] = u;
     
    14011436        _pi[u] += sigma;
    14021437      }
     1438    }
     1439
     1440    // Heuristic initial pivots
     1441    bool initialPivots() {
     1442      Value curr, total = 0;
     1443      std::vector<Node> supply_nodes, demand_nodes;
     1444      for (NodeIt u(_graph); u != INVALID; ++u) {
     1445        curr = _supply[_node_id[u]];
     1446        if (curr > 0) {
     1447          total += curr;
     1448          supply_nodes.push_back(u);
     1449        }
     1450        else if (curr < 0) {
     1451          demand_nodes.push_back(u);
     1452        }
     1453      }
     1454      if (_sum_supply > 0) total -= _sum_supply;
     1455      if (total <= 0) return true;
     1456
     1457      IntVector arc_vector;
     1458      if (_sum_supply >= 0) {
     1459        if (supply_nodes.size() == 1 && demand_nodes.size() == 1) {
     1460          // Perform a reverse graph search from the sink to the source
     1461          typename GR::template NodeMap<bool> reached(_graph, false);
     1462          Node s = supply_nodes[0], t = demand_nodes[0];
     1463          std::vector<Node> stack;
     1464          reached[t] = true;
     1465          stack.push_back(t);
     1466          while (!stack.empty()) {
     1467            Node u, v = stack.back();
     1468            stack.pop_back();
     1469            if (v == s) break;
     1470            for (InArcIt a(_graph, v); a != INVALID; ++a) {
     1471              if (reached[u = _graph.source(a)]) continue;
     1472              int j = _arc_id[a];
     1473              if (_cap[j] >= total) {
     1474                arc_vector.push_back(j);
     1475                reached[u] = true;
     1476                stack.push_back(u);
     1477              }
     1478            }
     1479          }
     1480        } else {
     1481          // Find the min. cost incomming arc for each demand node
     1482          for (int i = 0; i != int(demand_nodes.size()); ++i) {
     1483            Node v = demand_nodes[i];
     1484            Cost c, min_cost = std::numeric_limits<Cost>::max();
     1485            Arc min_arc = INVALID;
     1486            for (InArcIt a(_graph, v); a != INVALID; ++a) {
     1487              c = _cost[_arc_id[a]];
     1488              if (c < min_cost) {
     1489                min_cost = c;
     1490                min_arc = a;
     1491              }
     1492            }
     1493            if (min_arc != INVALID) {
     1494              arc_vector.push_back(_arc_id[min_arc]);
     1495            }
     1496          }
     1497        }
     1498      } else {
     1499        // Find the min. cost outgoing arc for each supply node
     1500        for (int i = 0; i != int(supply_nodes.size()); ++i) {
     1501          Node u = supply_nodes[i];
     1502          Cost c, min_cost = std::numeric_limits<Cost>::max();
     1503          Arc min_arc = INVALID;
     1504          for (OutArcIt a(_graph, u); a != INVALID; ++a) {
     1505            c = _cost[_arc_id[a]];
     1506            if (c < min_cost) {
     1507              min_cost = c;
     1508              min_arc = a;
     1509            }
     1510          }
     1511          if (min_arc != INVALID) {
     1512            arc_vector.push_back(_arc_id[min_arc]);
     1513          }
     1514        }
     1515      }
     1516
     1517      // Perform heuristic initial pivots
     1518      for (int i = 0; i != int(arc_vector.size()); ++i) {
     1519        in_arc = arc_vector[i];
     1520        if (_state[in_arc] * (_cost[in_arc] + _pi[_source[in_arc]] -
     1521            _pi[_target[in_arc]]) >= 0) continue;
     1522        findJoinNode();
     1523        bool change = findLeavingArc();
     1524        if (delta >= MAX) return false;
     1525        changeFlow(change);
     1526        if (change) {
     1527          updateTreeStructure();
     1528          updatePotential();
     1529        }
     1530      }
     1531      return true;
    14031532    }
    14041533
     
    14251554      PivotRuleImpl pivot(*this);
    14261555
     1556      // Perform heuristic initial pivots
     1557      if (!initialPivots()) return UNBOUNDED;
     1558
    14271559      // Execute the Network Simplex algorithm
    14281560      while (pivot.findEnteringArc()) {
    14291561        findJoinNode();
    14301562        bool change = findLeavingArc();
    1431         if (delta >= INF) return UNBOUNDED;
     1563        if (delta >= MAX) return UNBOUNDED;
    14321564        changeFlow(change);
    14331565        if (change) {
     
    14361568        }
    14371569      }
    1438      
     1570
    14391571      // Check feasibility
    14401572      for (int e = _search_arc_num; e != _all_arc_num; ++e) {
     
    14531585        }
    14541586      }
    1455      
     1587
    14561588      // Shift potentials to meet the requirements of the GEQ/LEQ type
    14571589      // optimality conditions
  • TabularUnified lemon/path.h

    r867 r956  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    967967    };
    968968
    969    
     969
    970970    template <typename From, typename To,
    971971              bool revEnable = RevPathTagIndicator<From>::value>
     
    973973      static void copy(const From& from, To& to) {
    974974        PathCopySelectorForward<From, To>::copy(from, to);
    975       }     
     975      }
    976976    };
    977977
     
    980980      static void copy(const From& from, To& to) {
    981981        PathCopySelectorBackward<From, To>::copy(from, to);
    982       }     
     982      }
    983983    };
    984984
  • TabularUnified lemon/preflow.h

    r1027 r1110  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2011
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    5353    /// The type of the map that stores the flow values.
    5454    /// It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
     55#ifdef DOXYGEN
     56    typedef GR::ArcMap<Value> FlowMap;
     57#else
    5558    typedef typename Digraph::template ArcMap<Value> FlowMap;
     59#endif
    5660
    5761    /// \brief Instantiates a FlowMap.
     
    6872    /// The elevator type used by Preflow algorithm.
    6973    ///
    70     /// \sa Elevator
    71     /// \sa LinkedElevator
    72     typedef LinkedElevator<Digraph, typename Digraph::Node> Elevator;
     74    /// \sa Elevator, LinkedElevator
     75#ifdef DOXYGEN
     76    typedef lemon::Elevator<GR, GR::Node> Elevator;
     77#else
     78    typedef lemon::Elevator<Digraph, typename Digraph::Node> Elevator;
     79#endif
    7380
    7481    /// \brief Instantiates an Elevator.
     
    96103  /// This class provides an implementation of Goldberg-Tarjan's \e preflow
    97104  /// \e push-relabel algorithm producing a \ref max_flow
    98   /// "flow of maximum value" in a digraph.
     105  /// "flow of maximum value" in a digraph \ref clrs01algorithms,
     106  /// \ref amo93networkflows, \ref goldberg88newapproach.
    99107  /// The preflow algorithms are the fastest known maximum
    100   /// flow algorithms. The current implementation use a mixture of the
     108  /// flow algorithms. The current implementation uses a mixture of the
    101109  /// \e "highest label" and the \e "bound decrease" heuristics.
    102110  /// The worst case time complexity of the algorithm is \f$O(n^2\sqrt{e})\f$.
     
    106114  /// second phase constructs a feasible maximum flow on each arc.
    107115  ///
     116  /// \warning This implementation cannot handle infinite or very large
     117  /// capacities (e.g. the maximum value of \c CAP::Value).
     118  ///
    108119  /// \tparam GR The type of the digraph the algorithm runs on.
    109120  /// \tparam CAP The type of the capacity map. The default map
    110121  /// type is \ref concepts::Digraph::ArcMap "GR::ArcMap<int>".
     122  /// \tparam TR The traits class that defines various types used by the
     123  /// algorithm. By default, it is \ref PreflowDefaultTraits
     124  /// "PreflowDefaultTraits<GR, CAP>".
     125  /// In most cases, this parameter should not be set directly,
     126  /// consider to use the named template parameters instead.
    111127#ifdef DOXYGEN
    112128  template <typename GR, typename CAP, typename TR>
     
    258274    /// able to automatically created by the algorithm (i.e. the
    259275    /// digraph and the maximum level should be passed to it).
    260     /// However an external elevator object could also be passed to the
     276    /// However, an external elevator object could also be passed to the
    261277    /// algorithm with the \ref elevator(Elevator&) "elevator()" function
    262278    /// before calling \ref run() or \ref init().
     
    372388    }
    373389
    374     /// \brief Sets the tolerance used by algorithm.
    375     ///
    376     /// Sets the tolerance used by algorithm.
     390    /// \brief Sets the tolerance used by the algorithm.
     391    ///
     392    /// Sets the tolerance object used by the algorithm.
     393    /// \return <tt>(*this)</tt>
    377394    Preflow& tolerance(const Tolerance& tolerance) {
    378395      _tolerance = tolerance;
     
    382399    /// \brief Returns a const reference to the tolerance.
    383400    ///
    384     /// Returns a const reference to the tolerance.
     401    /// Returns a const reference to the tolerance object used by
     402    /// the algorithm.
    385403    const Tolerance& tolerance() const {
    386404      return _tolerance;
     
    390408    /// The simplest way to execute the preflow algorithm is to use
    391409    /// \ref run() or \ref runMinCut().\n
    392     /// If you need more control on the initial solution or the execution,
    393     /// first you have to call one of the \ref init() functions, then
     410    /// If you need better control on the initial solution or the execution,
     411    /// you have to call one of the \ref init() functions first, then
    394412    /// \ref startFirstPhase() and if you need it \ref startSecondPhase().
    395413
     
    537555        }
    538556      }
    539       for (NodeIt n(_graph); n != INVALID; ++n) 
     557      for (NodeIt n(_graph); n != INVALID; ++n)
    540558        if(n!=_source && n!=_target && _tolerance.positive((*_excess)[n]))
    541559          _level->activate(n);
    542          
     560
    543561      return true;
    544562    }
     
    568586          level = _level->highestActiveLevel();
    569587          --num;
    570          
     588
    571589          Value excess = (*_excess)[n];
    572590          int new_level = _level->maxLevel();
  • TabularUnified lemon/radix_heap.h

    r730 r758  
    2020#define LEMON_RADIX_HEAP_H
    2121
    22 ///\ingroup auxdat
     22///\ingroup heaps
    2323///\file
    24 ///\brief Radix Heap implementation.
     24///\brief Radix heap implementation.
    2525
    2626#include <vector>
     
    3030
    3131
    32   /// \ingroup auxdata
     32  /// \ingroup heaps
    3333  ///
    34   /// \brief A Radix Heap implementation.
     34  /// \brief Radix heap data structure.
    3535  ///
    36   /// This class implements the \e radix \e heap data structure. A \e heap
    37   /// is a data structure for storing items with specified values called \e
    38   /// priorities in such a way that finding the item with minimum priority is
    39   /// efficient. This heap type can store only items with \e int priority.
    40   /// In a heap one can change the priority of an item, add or erase an
    41   /// item, but the priority cannot be decreased under the last removed
    42   /// item's priority.
     36  /// This class implements the \e radix \e heap data structure.
     37  /// It practically conforms to the \ref concepts::Heap "heap concept",
     38  /// but it has some limitations due its special implementation.
     39  /// The type of the priorities must be \c int and the priority of an
     40  /// item cannot be decreased under the priority of the last removed item.
    4341  ///
    44   /// \param IM A read and writable Item int map, used internally
    45   /// to handle the cross references.
    46   ///
    47   /// \see BinHeap
    48   /// \see Dijkstra
     42  /// \tparam IM A read-writable item map with \c int values, used
     43  /// internally to handle the cross references.
    4944  template <typename IM>
    5045  class RadixHeap {
    5146
    5247  public:
    53     typedef typename IM::Key Item;
     48
     49    /// Type of the item-int map.
     50    typedef IM ItemIntMap;
     51    /// Type of the priorities.
    5452    typedef int Prio;
    55     typedef IM ItemIntMap;
     53    /// Type of the items stored in the heap.
     54    typedef typename ItemIntMap::Key Item;
    5655
    5756    /// \brief Exception thrown by RadixHeap.
    5857    ///
    59     /// This Exception is thrown when a smaller priority
    60     /// is inserted into the \e RadixHeap then the last time erased.
     58    /// This exception is thrown when an item is inserted into a
     59    /// RadixHeap with a priority smaller than the last erased one.
    6160    /// \see RadixHeap
    62 
    63     class UnderFlowPriorityError : public Exception {
     61    class PriorityUnderflowError : public Exception {
    6462    public:
    6563      virtual const char* what() const throw() {
    66         return "lemon::RadixHeap::UnderFlowPriorityError";
     64        return "lemon::RadixHeap::PriorityUnderflowError";
    6765      }
    6866    };
    6967
    70     /// \brief Type to represent the items states.
    71     ///
    72     /// Each Item element have a state associated to it. It may be "in heap",
    73     /// "pre heap" or "post heap". The latter two are indifferent from the
     68    /// \brief Type to represent the states of the items.
     69    ///
     70    /// Each item has a state associated to it. It can be "in heap",
     71    /// "pre-heap" or "post-heap". The latter two are indifferent from the
    7472    /// heap's point of view, but may be useful to the user.
    7573    ///
    76     /// The ItemIntMap \e should be initialized in such way that it maps
    77     /// PRE_HEAP (-1) to any element to be put in the heap...
     74    /// The item-int map must be initialized in such way that it assigns
     75    /// \c PRE_HEAP (<tt>-1</tt>) to any element to be put in the heap.
    7876    enum State {
    79       IN_HEAP = 0,
    80       PRE_HEAP = -1,
    81       POST_HEAP = -2
     77      IN_HEAP = 0,    ///< = 0.
     78      PRE_HEAP = -1,  ///< = -1.
     79      POST_HEAP = -2  ///< = -2.
    8280    };
    8381
     
    9795    };
    9896
    99     std::vector<RadixItem> data;
    100     std::vector<RadixBox> boxes;
     97    std::vector<RadixItem> _data;
     98    std::vector<RadixBox> _boxes;
    10199
    102100    ItemIntMap &_iim;
    103101
    104 
    105102  public:
    106     /// \brief The constructor.
    107     ///
    108     /// The constructor.
    109     ///
    110     /// \param map It should be given to the constructor, since it is used
    111     /// internally to handle the cross references. The value of the map
    112     /// should be PRE_HEAP (-1) for each element.
    113     ///
    114     /// \param minimal The initial minimal value of the heap.
    115     /// \param capacity It determines the initial capacity of the heap.
    116     RadixHeap(ItemIntMap &map, int minimal = 0, int capacity = 0)
    117       : _iim(map) {
    118       boxes.push_back(RadixBox(minimal, 1));
    119       boxes.push_back(RadixBox(minimal + 1, 1));
    120       while (lower(boxes.size() - 1, capacity + minimal - 1)) {
     103
     104    /// \brief Constructor.
     105    ///
     106    /// Constructor.
     107    /// \param map A map that assigns \c int values to the items.
     108    /// It is used internally to handle the cross references.
     109    /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item.
     110    /// \param minimum The initial minimum value of the heap.
     111    /// \param capacity The initial capacity of the heap.
     112    RadixHeap(ItemIntMap &map, int minimum = 0, int capacity = 0)
     113      : _iim(map)
     114    {
     115      _boxes.push_back(RadixBox(minimum, 1));
     116      _boxes.push_back(RadixBox(minimum + 1, 1));
     117      while (lower(_boxes.size() - 1, capacity + minimum - 1)) {
    121118        extend();
    122119      }
    123120    }
    124121
    125     /// The number of items stored in the heap.
    126     ///
    127     /// \brief Returns the number of items stored in the heap.
    128     int size() const { return data.size(); }
    129     /// \brief Checks if the heap stores no items.
    130     ///
    131     /// Returns \c true if and only if the heap stores no items.
    132     bool empty() const { return data.empty(); }
    133 
    134     /// \brief Make empty this heap.
    135     ///
    136     /// Make empty this heap. It does not change the cross reference
    137     /// map.  If you want to reuse a heap what is not surely empty you
    138     /// should first clear the heap and after that you should set the
    139     /// cross reference map for each item to \c PRE_HEAP.
    140     void clear(int minimal = 0, int capacity = 0) {
    141       data.clear(); boxes.clear();
    142       boxes.push_back(RadixBox(minimal, 1));
    143       boxes.push_back(RadixBox(minimal + 1, 1));
    144       while (lower(boxes.size() - 1, capacity + minimal - 1)) {
     122    /// \brief The number of items stored in the heap.
     123    ///
     124    /// This function returns the number of items stored in the heap.
     125    int size() const { return _data.size(); }
     126
     127    /// \brief Check if the heap is empty.
     128    ///
     129    /// This function returns \c true if the heap is empty.
     130    bool empty() const { return _data.empty(); }
     131
     132    /// \brief Make the heap empty.
     133    ///
     134    /// This functon makes the heap empty.
     135    /// It does not change the cross reference map. If you want to reuse
     136    /// a heap that is not surely empty, you should first clear it and
     137    /// then you should set the cross reference map to \c PRE_HEAP
     138    /// for each item.
     139    /// \param minimum The minimum value of the heap.
     140    /// \param capacity The capacity of the heap.
     141    void clear(int minimum = 0, int capacity = 0) {
     142      _data.clear(); _boxes.clear();
     143      _boxes.push_back(RadixBox(minimum, 1));
     144      _boxes.push_back(RadixBox(minimum + 1, 1));
     145      while (lower(_boxes.size() - 1, capacity + minimum - 1)) {
    145146        extend();
    146147      }
     
    150151
    151152    bool upper(int box, Prio pr) {
    152       return pr < boxes[box].min;
     153      return pr < _boxes[box].min;
    153154    }
    154155
    155156    bool lower(int box, Prio pr) {
    156       return pr >= boxes[box].min + boxes[box].size;
    157     }
    158 
    159     /// \brief Remove item from the box list.
     157      return pr >= _boxes[box].min + _boxes[box].size;
     158    }
     159
     160    // Remove item from the box list
    160161    void remove(int index) {
    161       if (data[index].prev >= 0) {
    162         data[data[index].prev].next = data[index].next;
     162      if (_data[index].prev >= 0) {
     163        _data[_data[index].prev].next = _data[index].next;
    163164      } else {
    164         boxes[data[index].box].first = data[index].next;
    165       }
    166       if (data[index].next >= 0) {
    167         data[data[index].next].prev = data[index].prev;
    168       }
    169     }
    170 
    171     /// \brief Insert item into the box list.
     165        _boxes[_data[index].box].first = _data[index].next;
     166      }
     167      if (_data[index].next >= 0) {
     168        _data[_data[index].next].prev = _data[index].prev;
     169      }
     170    }
     171
     172    // Insert item into the box list
    172173    void insert(int box, int index) {
    173       if (boxes[box].first == -1) {
    174         boxes[box].first = index;
    175         data[index].next = data[index].prev = -1;
     174      if (_boxes[box].first == -1) {
     175        _boxes[box].first = index;
     176        _data[index].next = _data[index].prev = -1;
    176177      } else {
    177         data[index].next = boxes[box].first;
    178         data[boxes[box].first].prev = index;
    179         data[index].prev = -1;
    180         boxes[box].first = index;
    181       }
    182       data[index].box = box;
    183     }
    184 
    185     /// \brief Add a new box to the box list.
     178        _data[index].next = _boxes[box].first;
     179        _data[_boxes[box].first].prev = index;
     180        _data[index].prev = -1;
     181        _boxes[box].first = index;
     182      }
     183      _data[index].box = box;
     184    }
     185
     186    // Add a new box to the box list
    186187    void extend() {
    187       int min = boxes.back().min + boxes.back().size;
    188       int bs = 2 * boxes.back().size;
    189       boxes.push_back(RadixBox(min, bs));
    190     }
    191 
    192     /// \brief Move an item up into the proper box.
    193     void bubble_up(int index) {
    194       if (!lower(data[index].box, data[index].prio)) return;
     188      int min = _boxes.back().min + _boxes.back().size;
     189      int bs = 2 * _boxes.back().size;
     190      _boxes.push_back(RadixBox(min, bs));
     191    }
     192
     193    // Move an item up into the proper box.
     194    void bubbleUp(int index) {
     195      if (!lower(_data[index].box, _data[index].prio)) return;
    195196      remove(index);
    196       int box = findUp(data[index].box, data[index].prio);
     197      int box = findUp(_data[index].box, _data[index].prio);
    197198      insert(box, index);
    198199    }
    199200
    200     /// \brief Find up the proper box for the item with the given prio.
     201    // Find up the proper box for the item with the given priority
    201202    int findUp(int start, int pr) {
    202203      while (lower(start, pr)) {
    203         if (++start == int(boxes.size())) {
     204        if (++start == int(_boxes.size())) {
    204205          extend();
    205206        }
     
    208209    }
    209210
    210     /// \brief Move an item down into the proper box.
    211     void bubble_down(int index) {
    212       if (!upper(data[index].box, data[index].prio)) return;
     211    // Move an item down into the proper box
     212    void bubbleDown(int index) {
     213      if (!upper(_data[index].box, _data[index].prio)) return;
    213214      remove(index);
    214       int box = findDown(data[index].box, data[index].prio);
     215      int box = findDown(_data[index].box, _data[index].prio);
    215216      insert(box, index);
    216217    }
    217218
    218     /// \brief Find up the proper box for the item with the given prio.
     219    // Find down the proper box for the item with the given priority
    219220    int findDown(int start, int pr) {
    220221      while (upper(start, pr)) {
    221         if (--start < 0) throw UnderFlowPriorityError();
     222        if (--start < 0) throw PriorityUnderflowError();
    222223      }
    223224      return start;
    224225    }
    225226
    226     /// \brief Find the first not empty box.
     227    // Find the first non-empty box
    227228    int findFirst() {
    228229      int first = 0;
    229       while (boxes[first].first == -1) ++first;
     230      while (_boxes[first].first == -1) ++first;
    230231      return first;
    231232    }
    232233
    233     /// \brief Gives back the minimal prio of the box.
     234    // Gives back the minimum priority of the given box
    234235    int minValue(int box) {
    235       int min = data[boxes[box].first].prio;
    236       for (int k = boxes[box].first; k != -1; k = data[k].next) {
    237         if (data[k].prio < min) min = data[k].prio;
     236      int min = _data[_boxes[box].first].prio;
     237      for (int k = _boxes[box].first; k != -1; k = _data[k].next) {
     238        if (_data[k].prio < min) min = _data[k].prio;
    238239      }
    239240      return min;
    240241    }
    241242
    242     /// \brief Rearrange the items of the heap and makes the
    243     /// first box not empty.
     243    // Rearrange the items of the heap and make the first box non-empty
    244244    void moveDown() {
    245245      int box = findFirst();
     
    247247      int min = minValue(box);
    248248      for (int i = 0; i <= box; ++i) {
    249         boxes[i].min = min;
    250         min += boxes[i].size;
    251       }
    252       int curr = boxes[box].first, next;
     249        _boxes[i].min = min;
     250        min += _boxes[i].size;
     251      }
     252      int curr = _boxes[box].first, next;
    253253      while (curr != -1) {
    254         next = data[curr].next;
    255         bubble_down(curr);
     254        next = _data[curr].next;
     255        bubbleDown(curr);
    256256        curr = next;
    257257      }
    258258    }
    259259
    260     void relocate_last(int index) {
    261       if (index != int(data.size()) - 1) {
    262         data[index] = data.back();
    263         if (data[index].prev != -1) {
    264           data[data[index].prev].next = index;
     260    void relocateLast(int index) {
     261      if (index != int(_data.size()) - 1) {
     262        _data[index] = _data.back();
     263        if (_data[index].prev != -1) {
     264          _data[_data[index].prev].next = index;
    265265        } else {
    266           boxes[data[index].box].first = index;
     266          _boxes[_data[index].box].first = index;
    267267        }
    268         if (data[index].next != -1) {
    269           data[data[index].next].prev = index;
     268        if (_data[index].next != -1) {
     269          _data[_data[index].next].prev = index;
    270270        }
    271         _iim[data[index].item] = index;
    272       }
    273       data.pop_back();
     271        _iim[_data[index].item] = index;
     272      }
     273      _data.pop_back();
    274274    }
    275275
     
    278278    /// \brief Insert an item into the heap with the given priority.
    279279    ///
    280     /// Adds \c i to the heap with priority \c p.
     280    /// This function inserts the given item into the heap with the
     281    /// given priority.
    281282    /// \param i The item to insert.
    282283    /// \param p The priority of the item.
     284    /// \pre \e i must not be stored in the heap.
     285    /// \warning This method may throw an \c UnderFlowPriorityException.
    283286    void push(const Item &i, const Prio &p) {
    284       int n = data.size();
     287      int n = _data.size();
    285288      _iim.set(i, n);
    286       data.push_back(RadixItem(i, p));
    287       while (lower(boxes.size() - 1, p)) {
     289      _data.push_back(RadixItem(i, p));
     290      while (lower(_boxes.size() - 1, p)) {
    288291        extend();
    289292      }
    290       int box = findDown(boxes.size() - 1, p);
     293      int box = findDown(_boxes.size() - 1, p);
    291294      insert(box, n);
    292295    }
    293296
    294     /// \brief Returns the item with minimum priority.
    295     ///
    296     /// This method returns the item with minimum priority.
    297     /// \pre The heap must be nonempty.
     297    /// \brief Return the item having minimum priority.
     298    ///
     299    /// This function returns the item having minimum priority.
     300    /// \pre The heap must be non-empty.
    298301    Item top() const {
    299302      const_cast<RadixHeap<ItemIntMap>&>(*this).moveDown();
    300       return data[boxes[0].first].item;
    301     }
    302 
    303     /// \brief Returns the minimum priority.
    304     ///
    305     /// It returns the minimum priority.
    306     /// \pre The heap must be nonempty.
     303      return _data[_boxes[0].first].item;
     304    }
     305
     306    /// \brief The minimum priority.
     307    ///
     308    /// This function returns the minimum priority.
     309    /// \pre The heap must be non-empty.
    307310    Prio prio() const {
    308311      const_cast<RadixHeap<ItemIntMap>&>(*this).moveDown();
    309       return data[boxes[0].first].prio;
     312      return _data[_boxes[0].first].prio;
    310313     }
    311314
    312     /// \brief Deletes the item with minimum priority.
    313     ///
    314     /// This method deletes the item with minimum priority.
     315    /// \brief Remove the item having minimum priority.
     316    ///
     317    /// This function removes the item having minimum priority.
    315318    /// \pre The heap must be non-empty.
    316319    void pop() {
    317320      moveDown();
    318       int index = boxes[0].first;
    319       _iim[data[index].item] = POST_HEAP;
     321      int index = _boxes[0].first;
     322      _iim[_data[index].item] = POST_HEAP;
    320323      remove(index);
    321       relocate_last(index);
    322     }
    323 
    324     /// \brief Deletes \c i from the heap.
    325     ///
    326     /// This method deletes item \c i from the heap, if \c i was
    327     /// already stored in the heap.
    328     /// \param i The item to erase.
     324      relocateLast(index);
     325    }
     326
     327    /// \brief Remove the given item from the heap.
     328    ///
     329    /// This function removes the given item from the heap if it is
     330    /// already stored.
     331    /// \param i The item to delete.
     332    /// \pre \e i must be in the heap.
    329333    void erase(const Item &i) {
    330334      int index = _iim[i];
    331335      _iim[i] = POST_HEAP;
    332336      remove(index);
    333       relocate_last(index);
     337      relocateLast(index);
    334338   }
    335339
    336     /// \brief Returns the priority of \c i.
    337     ///
    338     /// This function returns the priority of item \c i.
    339     /// \pre \c i must be in the heap.
    340     /// \param i The item.
     340    /// \brief The priority of the given item.
     341    ///
     342    /// This function returns the priority of the given item.
     343    /// \param i The item.
     344    /// \pre \e i must be in the heap.
    341345    Prio operator[](const Item &i) const {
    342346      int idx = _iim[i];
    343       return data[idx].prio;
    344     }
    345 
    346     /// \brief \c i gets to the heap with priority \c p independently
    347     /// if \c i was already there.
    348     ///
    349     /// This method calls \ref push(\c i, \c p) if \c i is not stored
    350     /// in the heap and sets the priority of \c i to \c p otherwise.
    351     /// It may throw an \e UnderFlowPriorityException.
     347      return _data[idx].prio;
     348    }
     349
     350    /// \brief Set the priority of an item or insert it, if it is
     351    /// not stored in the heap.
     352    ///
     353    /// This method sets the priority of the given item if it is
     354    /// already stored in the heap. Otherwise it inserts the given
     355    /// item into the heap with the given priority.
    352356    /// \param i The item.
    353357    /// \param p The priority.
     358    /// \pre \e i must be in the heap.
     359    /// \warning This method may throw an \c UnderFlowPriorityException.
    354360    void set(const Item &i, const Prio &p) {
    355361      int idx = _iim[i];
     
    357363        push(i, p);
    358364      }
    359       else if( p >= data[idx].prio ) {
    360         data[idx].prio = p;
    361         bubble_up(idx);
     365      else if( p >= _data[idx].prio ) {
     366        _data[idx].prio = p;
     367        bubbleUp(idx);
    362368      } else {
    363         data[idx].prio = p;
    364         bubble_down(idx);
    365       }
    366     }
    367 
    368 
    369     /// \brief Decreases the priority of \c i to \c p.
    370     ///
    371     /// This method decreases the priority of item \c i to \c p.
    372     /// \pre \c i must be stored in the heap with priority at least \c p, and
    373     /// \c should be greater or equal to the last removed item's priority.
     369        _data[idx].prio = p;
     370        bubbleDown(idx);
     371      }
     372    }
     373
     374    /// \brief Decrease the priority of an item to the given value.
     375    ///
     376    /// This function decreases the priority of an item to the given value.
    374377    /// \param i The item.
    375378    /// \param p The priority.
     379    /// \pre \e i must be stored in the heap with priority at least \e p.
     380    /// \warning This method may throw an \c UnderFlowPriorityException.
    376381    void decrease(const Item &i, const Prio &p) {
    377382      int idx = _iim[i];
    378       data[idx].prio = p;
    379       bubble_down(idx);
    380     }
    381 
    382     /// \brief Increases the priority of \c i to \c p.
    383     ///
    384     /// This method sets the priority of item \c i to \c p.
    385     /// \pre \c i must be stored in the heap with priority at most \c p
     383      _data[idx].prio = p;
     384      bubbleDown(idx);
     385    }
     386
     387    /// \brief Increase the priority of an item to the given value.
     388    ///
     389    /// This function increases the priority of an item to the given value.
    386390    /// \param i The item.
    387391    /// \param p The priority.
     392    /// \pre \e i must be stored in the heap with priority at most \e p.
    388393    void increase(const Item &i, const Prio &p) {
    389394      int idx = _iim[i];
    390       data[idx].prio = p;
    391       bubble_up(idx);
    392     }
    393 
    394     /// \brief Returns if \c item is in, has already been in, or has
    395     /// never been in the heap.
    396     ///
    397     /// This method returns PRE_HEAP if \c item has never been in the
    398     /// heap, IN_HEAP if it is in the heap at the moment, and POST_HEAP
    399     /// otherwise. In the latter case it is possible that \c item will
    400     /// get back to the heap again.
     395      _data[idx].prio = p;
     396      bubbleUp(idx);
     397    }
     398
     399    /// \brief Return the state of an item.
     400    ///
     401    /// This method returns \c PRE_HEAP if the given item has never
     402    /// been in the heap, \c IN_HEAP if it is in the heap at the moment,
     403    /// and \c POST_HEAP otherwise.
     404    /// In the latter case it is possible that the item will get back
     405    /// to the heap again.
    401406    /// \param i The item.
    402407    State state(const Item &i) const {
     
    406411    }
    407412
    408     /// \brief Sets the state of the \c item in the heap.
    409     ///
    410     /// Sets the state of the \c item in the heap. It can be used to
    411     /// manually clear the heap when it is important to achive the
    412     /// better time complexity.
     413    /// \brief Set the state of an item in the heap.
     414    ///
     415    /// This function sets the state of the given item in the heap.
     416    /// It can be used to manually clear the heap when it is important
     417    /// to achive better time complexity.
    413418    /// \param i The item.
    414419    /// \param st The state. It should not be \c IN_HEAP.
  • TabularUnified lemon/smart_graph.h

    r664 r956  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    3333
    3434  class SmartDigraph;
    35   ///Base of SmartDigraph
    36 
    37   ///Base of SmartDigraph
    38   ///
     35
    3936  class SmartDigraphBase {
    4037  protected:
     
    188185  ///\brief A smart directed graph class.
    189186  ///
    190   ///This is a simple and fast digraph implementation.
    191   ///It is also quite memory efficient, but at the price
    192   ///that <b> it does support only limited (only stack-like)
    193   ///node and arc deletions</b>.
    194   ///It fully conforms to the \ref concepts::Digraph "Digraph concept".
    195   ///
    196   ///\sa concepts::Digraph.
     187  ///\ref SmartDigraph is a simple and fast digraph implementation.
     188  ///It is also quite memory efficient but at the price
     189  ///that it does not support node and arc deletion
     190  ///(except for the Snapshot feature).
     191  ///
     192  ///This type fully conforms to the \ref concepts::Digraph "Digraph concept"
     193  ///and it also provides some additional functionalities.
     194  ///Most of its member functions and nested classes are documented
     195  ///only in the concept class.
     196  ///
     197  ///This class provides constant time counting for nodes and arcs.
     198  ///
     199  ///\sa concepts::Digraph
     200  ///\sa SmartGraph
    197201  class SmartDigraph : public ExtendedSmartDigraphBase {
    198202    typedef ExtendedSmartDigraphBase Parent;
    199203
    200204  private:
    201 
    202     ///SmartDigraph is \e not copy constructible. Use DigraphCopy() instead.
    203 
    204     ///SmartDigraph is \e not copy constructible. Use DigraphCopy() instead.
    205     ///
     205    /// Digraphs are \e not copy constructible. Use DigraphCopy instead.
    206206    SmartDigraph(const SmartDigraph &) : ExtendedSmartDigraphBase() {};
    207     ///\brief Assignment of SmartDigraph to another one is \e not allowed.
    208     ///Use DigraphCopy() instead.
    209 
    210     ///Assignment of SmartDigraph to another one is \e not allowed.
    211     ///Use DigraphCopy() instead.
     207    /// \brief Assignment of a digraph to another one is \e not allowed.
     208    /// Use DigraphCopy instead.
    212209    void operator=(const SmartDigraph &) {}
    213210
     
    222219    ///Add a new node to the digraph.
    223220
    224     /// Add a new node to the digraph.
    225     /// \return The new node.
     221    ///This function adds a new node to the digraph.
     222    ///\return The new node.
    226223    Node addNode() { return Parent::addNode(); }
    227224
    228225    ///Add a new arc to the digraph.
    229226
    230     ///Add a new arc to the digraph with source node \c s
     227    ///This function adds a new arc to the digraph with source node \c s
    231228    ///and target node \c t.
    232229    ///\return The new arc.
    233     Arc addArc(const Node& s, const Node& t) {
     230    Arc addArc(Node s, Node t) {
    234231      return Parent::addArc(s, t);
    235232    }
    236233
    237     /// \brief Using this it is possible to avoid the superfluous memory
    238     /// allocation.
    239 
    240     /// Using this it is possible to avoid the superfluous memory
    241     /// allocation: if you know that the digraph you want to build will
    242     /// be very large (e.g. it will contain millions of nodes and/or arcs)
    243     /// then it is worth reserving space for this amount before starting
    244     /// to build the digraph.
    245     /// \sa reserveArc
    246     void reserveNode(int n) { nodes.reserve(n); };
    247 
    248     /// \brief Using this it is possible to avoid the superfluous memory
    249     /// allocation.
    250 
    251     /// Using this it is possible to avoid the superfluous memory
    252     /// allocation: if you know that the digraph you want to build will
    253     /// be very large (e.g. it will contain millions of nodes and/or arcs)
    254     /// then it is worth reserving space for this amount before starting
    255     /// to build the digraph.
    256     /// \sa reserveNode
    257     void reserveArc(int m) { arcs.reserve(m); };
    258 
    259234    /// \brief Node validity check
    260235    ///
    261     /// This function gives back true if the given node is valid,
    262     /// ie. it is a real node of the graph.
     236    /// This function gives back \c true if the given node is valid,
     237    /// i.e. it is a real node of the digraph.
    263238    ///
    264239    /// \warning A removed node (using Snapshot) could become valid again
    265     /// when new nodes are added to the graph.
     240    /// if new nodes are added to the digraph.
    266241    bool valid(Node n) const { return Parent::valid(n); }
    267242
    268243    /// \brief Arc validity check
    269244    ///
    270     /// This function gives back true if the given arc is valid,
    271     /// ie. it is a real arc of the graph.
     245    /// This function gives back \c true if the given arc is valid,
     246    /// i.e. it is a real arc of the digraph.
    272247    ///
    273248    /// \warning A removed arc (using Snapshot) could become valid again
    274     /// when new arcs are added to the graph.
     249    /// if new arcs are added to the graph.
    275250    bool valid(Arc a) const { return Parent::valid(a); }
    276251
    277     ///Clear the digraph.
    278 
    279     ///Erase all the nodes and arcs from the digraph.
    280     ///
    281     void clear() {
    282       Parent::clear();
    283     }
    284 
    285252    ///Split a node.
    286253
    287     ///This function splits a node. First a new node is added to the digraph,
    288     ///then the source of each outgoing arc of \c n is moved to this new node.
    289     ///If \c connect is \c true (this is the default value), then a new arc
    290     ///from \c n to the newly created node is also added.
     254    ///This function splits the given node. First, a new node is added
     255    ///to the digraph, then the source of each outgoing arc of node \c n
     256    ///is moved to this new node.
     257    ///If the second parameter \c connect is \c true (this is the default
     258    ///value), then a new arc from node \c n to the newly created node
     259    ///is also added.
    291260    ///\return The newly created node.
    292261    ///
    293     ///\note The <tt>Arc</tt>s
    294     ///referencing a moved arc remain
    295     ///valid. However <tt>InArc</tt>'s and <tt>OutArc</tt>'s
    296     ///may be invalidated.
     262    ///\note All iterators remain valid.
     263    ///
    297264    ///\warning This functionality cannot be used together with the Snapshot
    298265    ///feature.
     
    309276    }
    310277
     278    ///Clear the digraph.
     279
     280    ///This function erases all nodes and arcs from the digraph.
     281    ///
     282    void clear() {
     283      Parent::clear();
     284    }
     285
     286    /// Reserve memory for nodes.
     287
     288    /// Using this function, it is possible to avoid superfluous memory
     289    /// allocation: if you know that the digraph you want to build will
     290    /// be large (e.g. it will contain millions of nodes and/or arcs),
     291    /// then it is worth reserving space for this amount before starting
     292    /// to build the digraph.
     293    /// \sa reserveArc()
     294    void reserveNode(int n) { nodes.reserve(n); };
     295
     296    /// Reserve memory for arcs.
     297
     298    /// Using this function, it is possible to avoid superfluous memory
     299    /// allocation: if you know that the digraph you want to build will
     300    /// be large (e.g. it will contain millions of nodes and/or arcs),
     301    /// then it is worth reserving space for this amount before starting
     302    /// to build the digraph.
     303    /// \sa reserveNode()
     304    void reserveArc(int m) { arcs.reserve(m); };
     305
    311306  public:
    312307
     
    333328  public:
    334329
    335     ///Class to make a snapshot of the digraph and to restrore to it later.
    336 
    337     ///Class to make a snapshot of the digraph and to restrore to it later.
     330    ///Class to make a snapshot of the digraph and to restore it later.
     331
     332    ///Class to make a snapshot of the digraph and to restore it later.
    338333    ///
    339334    ///The newly added nodes and arcs can be removed using the
    340     ///restore() function.
    341     ///\note After you restore a state, you cannot restore
    342     ///a later state, in other word you cannot add again the arcs deleted
    343     ///by restore() using another one Snapshot instance.
    344     ///
    345     ///\warning If you do not use correctly the snapshot that can cause
    346     ///either broken program, invalid state of the digraph, valid but
    347     ///not the restored digraph or no change. Because the runtime performance
    348     ///the validity of the snapshot is not stored.
     335    ///restore() function. This is the only way for deleting nodes and/or
     336    ///arcs from a SmartDigraph structure.
     337    ///
     338    ///\note After a state is restored, you cannot restore a later state,
     339    ///i.e. you cannot add the removed nodes and arcs again using
     340    ///another Snapshot instance.
     341    ///
     342    ///\warning Node splitting cannot be restored.
     343    ///\warning The validity of the snapshot is not stored due to
     344    ///performance reasons. If you do not use the snapshot correctly,
     345    ///it can cause broken program, invalid or not restored state of
     346    ///the digraph or no change.
    349347    class Snapshot
    350348    {
     
    358356
    359357      ///Default constructor.
    360       ///To actually make a snapshot you must call save().
    361       ///
     358      ///You have to call save() to actually make a snapshot.
    362359      Snapshot() : _graph(0) {}
    363360      ///Constructor that immediately makes a snapshot
    364361
    365       ///This constructor immediately makes a snapshot of the digraph.
    366       ///\param graph The digraph we make a snapshot of.
    367       Snapshot(SmartDigraph &graph) : _graph(&graph) {
     362      ///This constructor immediately makes a snapshot of the given digraph.
     363      ///
     364      Snapshot(SmartDigraph &gr) : _graph(&gr) {
    368365        node_num=_graph->nodes.size();
    369366        arc_num=_graph->arcs.size();
     
    372369      ///Make a snapshot.
    373370
    374       ///Make a snapshot of the digraph.
    375       ///
    376       ///This function can be called more than once. In case of a repeated
     371      ///This function makes a snapshot of the given digraph.
     372      ///It can be called more than once. In case of a repeated
    377373      ///call, the previous snapshot gets lost.
    378       ///\param graph The digraph we make the snapshot of.
    379       void save(SmartDigraph &graph)
    380       {
    381         _graph=&graph;
     374      void save(SmartDigraph &gr) {
     375        _graph=&gr;
    382376        node_num=_graph->nodes.size();
    383377        arc_num=_graph->arcs.size();
     
    386380      ///Undo the changes until a snapshot.
    387381
    388       ///Undo the changes until a snapshot created by save().
    389       ///
    390       ///\note After you restored a state, you cannot restore
    391       ///a later state, in other word you cannot add again the arcs deleted
    392       ///by restore().
     382      ///This function undos the changes until the last snapshot
     383      ///created by save() or Snapshot(SmartDigraph&).
    393384      void restore()
    394385      {
     
    509500    }
    510501
    511     void next(Node& node) const {
     502    static void next(Node& node) {
    512503      --node._id;
    513504    }
     
    517508    }
    518509
    519     void next(Arc& arc) const {
     510    static void next(Arc& arc) {
    520511      --arc._id;
    521512    }
     
    525516    }
    526517
    527     void next(Edge& arc) const {
     518    static void next(Edge& arc) {
    528519      --arc._id;
    529520    }
     
    622613  /// \brief A smart undirected graph class.
    623614  ///
    624   /// This is a simple and fast graph implementation.
    625   /// It is also quite memory efficient, but at the price
    626   /// that <b> it does support only limited (only stack-like)
    627   /// node and arc deletions</b>.
    628   /// It fully conforms to the \ref concepts::Graph "Graph concept".
    629   ///
    630   /// \sa concepts::Graph.
     615  /// \ref SmartGraph is a simple and fast graph implementation.
     616  /// It is also quite memory efficient but at the price
     617  /// that it does not support node and edge deletion
     618  /// (except for the Snapshot feature).
     619  ///
     620  /// This type fully conforms to the \ref concepts::Graph "Graph concept"
     621  /// and it also provides some additional functionalities.
     622  /// Most of its member functions and nested classes are documented
     623  /// only in the concept class.
     624  ///
     625  /// This class provides constant time counting for nodes, edges and arcs.
     626  ///
     627  /// \sa concepts::Graph
     628  /// \sa SmartDigraph
    631629  class SmartGraph : public ExtendedSmartGraphBase {
    632630    typedef ExtendedSmartGraphBase Parent;
    633631
    634632  private:
    635 
    636     ///SmartGraph is \e not copy constructible. Use GraphCopy() instead.
    637 
    638     ///SmartGraph is \e not copy constructible. Use GraphCopy() instead.
    639     ///
     633    /// Graphs are \e not copy constructible. Use GraphCopy instead.
    640634    SmartGraph(const SmartGraph &) : ExtendedSmartGraphBase() {};
    641 
    642     ///\brief Assignment of SmartGraph to another one is \e not allowed.
    643     ///Use GraphCopy() instead.
    644 
    645     ///Assignment of SmartGraph to another one is \e not allowed.
    646     ///Use GraphCopy() instead.
     635    /// \brief Assignment of a graph to another one is \e not allowed.
     636    /// Use GraphCopy instead.
    647637    void operator=(const SmartGraph &) {}
    648638
     
    655645    SmartGraph() {}
    656646
    657     ///Add a new node to the graph.
    658 
    659     /// Add a new node to the graph.
     647    /// \brief Add a new node to the graph.
     648    ///
     649    /// This function adds a new node to the graph.
    660650    /// \return The new node.
    661651    Node addNode() { return Parent::addNode(); }
    662652
    663     ///Add a new edge to the graph.
    664 
    665     ///Add a new edge to the graph with node \c s
    666     ///and \c t.
    667     ///\return The new edge.
    668     Edge addEdge(const Node& s, const Node& t) {
    669       return Parent::addEdge(s, t);
     653    /// \brief Add a new edge to the graph.
     654    ///
     655    /// This function adds a new edge to the graph between nodes
     656    /// \c u and \c v with inherent orientation from node \c u to
     657    /// node \c v.
     658    /// \return The new edge.
     659    Edge addEdge(Node u, Node v) {
     660      return Parent::addEdge(u, v);
    670661    }
    671662
    672663    /// \brief Node validity check
    673664    ///
    674     /// This function gives back true if the given node is valid,
    675     /// ie. it is a real node of the graph.
     665    /// This function gives back \c true if the given node is valid,
     666    /// i.e. it is a real node of the graph.
    676667    ///
    677668    /// \warning A removed node (using Snapshot) could become valid again
    678     /// when new nodes are added to the graph.
     669    /// if new nodes are added to the graph.
    679670    bool valid(Node n) const { return Parent::valid(n); }
    680671
     672    /// \brief Edge validity check
     673    ///
     674    /// This function gives back \c true if the given edge is valid,
     675    /// i.e. it is a real edge of the graph.
     676    ///
     677    /// \warning A removed edge (using Snapshot) could become valid again
     678    /// if new edges are added to the graph.
     679    bool valid(Edge e) const { return Parent::valid(e); }
     680
    681681    /// \brief Arc validity check
    682682    ///
    683     /// This function gives back true if the given arc is valid,
    684     /// ie. it is a real arc of the graph.
     683    /// This function gives back \c true if the given arc is valid,
     684    /// i.e. it is a real arc of the graph.
    685685    ///
    686686    /// \warning A removed arc (using Snapshot) could become valid again
    687     /// when new edges are added to the graph.
     687    /// if new edges are added to the graph.
    688688    bool valid(Arc a) const { return Parent::valid(a); }
    689689
    690     /// \brief Edge validity check
    691     ///
    692     /// This function gives back true if the given edge is valid,
    693     /// ie. it is a real edge of the graph.
    694     ///
    695     /// \warning A removed edge (using Snapshot) could become valid again
    696     /// when new edges are added to the graph.
    697     bool valid(Edge e) const { return Parent::valid(e); }
    698 
    699690    ///Clear the graph.
    700691
    701     ///Erase all the nodes and edges from the graph.
     692    ///This function erases all nodes and arcs from the graph.
    702693    ///
    703694    void clear() {
    704695      Parent::clear();
    705696    }
     697
     698    /// Reserve memory for nodes.
     699
     700    /// Using this function, it is possible to avoid superfluous memory
     701    /// allocation: if you know that the graph you want to build will
     702    /// be large (e.g. it will contain millions of nodes and/or edges),
     703    /// then it is worth reserving space for this amount before starting
     704    /// to build the graph.
     705    /// \sa reserveEdge()
     706    void reserveNode(int n) { nodes.reserve(n); };
     707
     708    /// Reserve memory for edges.
     709
     710    /// Using this function, it is possible to avoid superfluous memory
     711    /// allocation: if you know that the graph you want to build will
     712    /// be large (e.g. it will contain millions of nodes and/or edges),
     713    /// then it is worth reserving space for this amount before starting
     714    /// to build the graph.
     715    /// \sa reserveNode()
     716    void reserveEdge(int m) { arcs.reserve(2 * m); };
    706717
    707718  public:
     
    743754  public:
    744755
    745     ///Class to make a snapshot of the digraph and to restrore to it later.
    746 
    747     ///Class to make a snapshot of the digraph and to restrore to it later.
    748     ///
    749     ///The newly added nodes and arcs can be removed using the
    750     ///restore() function.
    751     ///
    752     ///\note After you restore a state, you cannot restore
    753     ///a later state, in other word you cannot add again the arcs deleted
    754     ///by restore() using another one Snapshot instance.
    755     ///
    756     ///\warning If you do not use correctly the snapshot that can cause
    757     ///either broken program, invalid state of the digraph, valid but
    758     ///not the restored digraph or no change. Because the runtime performance
    759     ///the validity of the snapshot is not stored.
     756    ///Class to make a snapshot of the graph and to restore it later.
     757
     758    ///Class to make a snapshot of the graph and to restore it later.
     759    ///
     760    ///The newly added nodes and edges can be removed using the
     761    ///restore() function. This is the only way for deleting nodes and/or
     762    ///edges from a SmartGraph structure.
     763    ///
     764    ///\note After a state is restored, you cannot restore a later state,
     765    ///i.e. you cannot add the removed nodes and edges again using
     766    ///another Snapshot instance.
     767    ///
     768    ///\warning The validity of the snapshot is not stored due to
     769    ///performance reasons. If you do not use the snapshot correctly,
     770    ///it can cause broken program, invalid or not restored state of
     771    ///the graph or no change.
    760772    class Snapshot
    761773    {
     
    769781
    770782      ///Default constructor.
    771       ///To actually make a snapshot you must call save().
    772       ///
     783      ///You have to call save() to actually make a snapshot.
    773784      Snapshot() : _graph(0) {}
    774785      ///Constructor that immediately makes a snapshot
    775786
    776       ///This constructor immediately makes a snapshot of the digraph.
    777       ///\param graph The digraph we make a snapshot of.
    778       Snapshot(SmartGraph &graph) {
    779         graph.saveSnapshot(*this);
     787      /// This constructor immediately makes a snapshot of the given graph.
     788      ///
     789      Snapshot(SmartGraph &gr) {
     790        gr.saveSnapshot(*this);
    780791      }
    781792
    782793      ///Make a snapshot.
    783794
    784       ///Make a snapshot of the graph.
    785       ///
    786       ///This function can be called more than once. In case of a repeated
     795      ///This function makes a snapshot of the given graph.
     796      ///It can be called more than once. In case of a repeated
    787797      ///call, the previous snapshot gets lost.
    788       ///\param graph The digraph we make the snapshot of.
    789       void save(SmartGraph &graph)
     798      void save(SmartGraph &gr)
    790799      {
    791         graph.saveSnapshot(*this);
    792       }
    793 
    794       ///Undo the changes until a snapshot.
    795 
    796       ///Undo the changes until a snapshot created by save().
    797       ///
    798       ///\note After you restored a state, you cannot restore
    799       ///a later state, in other word you cannot add again the arcs deleted
    800       ///by restore().
     800        gr.saveSnapshot(*this);
     801      }
     802
     803      ///Undo the changes until the last snapshot.
     804
     805      ///This function undos the changes until the last snapshot
     806      ///created by save() or Snapshot(SmartGraph&).
    801807      void restore()
    802808      {
  • TabularUnified lemon/soplex.cc

    r623 r956  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2008
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    9292  }
    9393
     94  int SoplexLp::_addRow(Value l, ExprIterator b, ExprIterator e, Value u) {
     95    soplex::DSVector v;
     96    for (ExprIterator it = b; it != e; ++it) {
     97      v.add(it->first, it->second);
     98    }
     99    soplex::LPRow r(l, v, u);
     100    soplex->addRow(r);
     101
     102    _row_names.push_back(std::string());
     103
     104    return soplex->nRows() - 1;
     105  }
     106
    94107
    95108  void SoplexLp::_eraseCol(int i) {
     
    275288
    276289    _clear_temporals();
    277    
     290
    278291    _applyMessageLevel();
    279292
  • TabularUnified lemon/soplex.h

    r623 r956  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2008
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    8585    virtual int _addCol();
    8686    virtual int _addRow();
     87    virtual int _addRow(Value l, ExprIterator b, ExprIterator e, Value u);
    8788
    8889    virtual void _eraseCol(int i);
  • TabularUnified lemon/suurballe.h

    r925 r956  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    3030#include <lemon/path.h>
    3131#include <lemon/list_graph.h>
     32#include <lemon/dijkstra.h>
    3233#include <lemon/maps.h>
    3334
    3435namespace lemon {
     36
     37  /// \brief Default traits class of Suurballe algorithm.
     38  ///
     39  /// Default traits class of Suurballe algorithm.
     40  /// \tparam GR The digraph type the algorithm runs on.
     41  /// \tparam LEN The type of the length map.
     42  /// The default value is <tt>GR::ArcMap<int></tt>.
     43#ifdef DOXYGEN
     44  template <typename GR, typename LEN>
     45#else
     46  template < typename GR,
     47             typename LEN = typename GR::template ArcMap<int> >
     48#endif
     49  struct SuurballeDefaultTraits
     50  {
     51    /// The type of the digraph.
     52    typedef GR Digraph;
     53    /// The type of the length map.
     54    typedef LEN LengthMap;
     55    /// The type of the lengths.
     56    typedef typename LEN::Value Length;
     57    /// The type of the flow map.
     58    typedef typename GR::template ArcMap<int> FlowMap;
     59    /// The type of the potential map.
     60    typedef typename GR::template NodeMap<Length> PotentialMap;
     61
     62    /// \brief The path type
     63    ///
     64    /// The type used for storing the found arc-disjoint paths.
     65    /// It must conform to the \ref lemon::concepts::Path "Path" concept
     66    /// and it must have an \c addBack() function.
     67    typedef lemon::Path<Digraph> Path;
     68
     69    /// The cross reference type used for the heap.
     70    typedef typename GR::template NodeMap<int> HeapCrossRef;
     71
     72    /// \brief The heap type used for internal Dijkstra computations.
     73    ///
     74    /// The type of the heap used for internal Dijkstra computations.
     75    /// It must conform to the \ref lemon::concepts::Heap "Heap" concept
     76    /// and its priority type must be \c Length.
     77    typedef BinHeap<Length, HeapCrossRef> Heap;
     78  };
    3579
    3680  /// \addtogroup shortest_path
     
    4791  /// "minimum cost flow problem". This implementation is actually an
    4892  /// efficient specialized version of the \ref CapacityScaling
    49   /// "Successive Shortest Path" algorithm directly for this problem.
     93  /// "successive shortest path" algorithm directly for this problem.
    5094  /// Therefore this class provides query functions for flow values and
    5195  /// node potentials (the dual solution) just like the minimum cost flow
     
    58102  /// \warning Length values should be \e non-negative.
    59103  ///
    60   /// \note For finding node-disjoint paths this algorithm can be used
     104  /// \note For finding \e node-disjoint paths, this algorithm can be used
    61105  /// along with the \ref SplitNodes adaptor.
    62106#ifdef DOXYGEN
    63   template <typename GR, typename LEN>
     107  template <typename GR, typename LEN, typename TR>
    64108#else
    65109  template < typename GR,
    66              typename LEN = typename GR::template ArcMap<int> >
     110             typename LEN = typename GR::template ArcMap<int>,
     111             typename TR = SuurballeDefaultTraits<GR, LEN> >
    67112#endif
    68113  class Suurballe
     
    75120  public:
    76121
    77     /// The type of the digraph the algorithm runs on.
    78     typedef GR Digraph;
     122    /// The type of the digraph.
     123    typedef typename TR::Digraph Digraph;
    79124    /// The type of the length map.
    80     typedef LEN LengthMap;
     125    typedef typename TR::LengthMap LengthMap;
    81126    /// The type of the lengths.
    82     typedef typename LengthMap::Value Length;
    83 #ifdef DOXYGEN
     127    typedef typename TR::Length Length;
     128
    84129    /// The type of the flow map.
    85     typedef GR::ArcMap<int> FlowMap;
     130    typedef typename TR::FlowMap FlowMap;
    86131    /// The type of the potential map.
    87     typedef GR::NodeMap<Length> PotentialMap;
    88 #else
    89     /// The type of the flow map.
    90     typedef typename Digraph::template ArcMap<int> FlowMap;
    91     /// The type of the potential map.
    92     typedef typename Digraph::template NodeMap<Length> PotentialMap;
    93 #endif
    94 
     132    typedef typename TR::PotentialMap PotentialMap;
    95133    /// The type of the path structures.
    96     typedef SimplePath<GR> Path;
     134    typedef typename TR::Path Path;
     135    /// The cross reference type used for the heap.
     136    typedef typename TR::HeapCrossRef HeapCrossRef;
     137    /// The heap type used for internal Dijkstra computations.
     138    typedef typename TR::Heap Heap;
     139
     140    /// The \ref SuurballeDefaultTraits "traits class" of the algorithm.
     141    typedef TR Traits;
    97142
    98143  private:
     
    105150    class ResidualDijkstra
    106151    {
    107       typedef typename Digraph::template NodeMap<int> HeapCrossRef;
    108       typedef BinHeap<Length, HeapCrossRef> Heap;
    109 
    110152    private:
    111153
    112       // The digraph the algorithm runs on
    113154      const Digraph &_graph;
    114 
    115       // The main maps
     155      const LengthMap &_length;
    116156      const FlowMap &_flow;
    117       const LengthMap &_length;
    118       PotentialMap &_potential;
    119 
    120       // The distance map
    121       PotentialMap _dist;
    122       // The pred arc map
     157      PotentialMap &_pi;
    123158      PredMap &_pred;
    124       // The processed (i.e. permanently labeled) nodes
    125       std::vector<Node> _proc_nodes;
    126 
    127159      Node _s;
    128160      Node _t;
    129161
     162      PotentialMap _dist;
     163      std::vector<Node> _proc_nodes;
     164
    130165    public:
    131166
    132       /// Constructor.
    133       ResidualDijkstra( const Digraph &graph,
    134                         const FlowMap &flow,
    135                         const LengthMap &length,
    136                         PotentialMap &potential,
    137                         PredMap &pred,
    138                         Node s, Node t ) :
    139         _graph(graph), _flow(flow), _length(length), _potential(potential),
    140         _dist(graph), _pred(pred), _s(s), _t(t) {}
    141 
    142       /// \brief Run the algorithm. It returns \c true if a path is found
    143       /// from the source node to the target node.
    144       bool run() {
     167      // Constructor
     168      ResidualDijkstra(Suurballe &srb) :
     169        _graph(srb._graph), _length(srb._length),
     170        _flow(*srb._flow), _pi(*srb._potential), _pred(srb._pred),
     171        _s(srb._s), _t(srb._t), _dist(_graph) {}
     172
     173      // Run the algorithm and return true if a path is found
     174      // from the source node to the target node.
     175      bool run(int cnt) {
     176        return cnt == 0 ? startFirst() : start();
     177      }
     178
     179    private:
     180
     181      // Execute the algorithm for the first time (the flow and potential
     182      // functions have to be identically zero).
     183      bool startFirst() {
    145184        HeapCrossRef heap_cross_ref(_graph, Heap::PRE_HEAP);
    146185        Heap heap(heap_cross_ref);
     
    152191        while (!heap.empty() && heap.top() != _t) {
    153192          Node u = heap.top(), v;
    154           Length d = heap.prio() + _potential[u], nd;
     193          Length d = heap.prio(), dn;
    155194          _dist[u] = heap.prio();
     195          _proc_nodes.push_back(u);
    156196          heap.pop();
     197
     198          // Traverse outgoing arcs
     199          for (OutArcIt e(_graph, u); e != INVALID; ++e) {
     200            v = _graph.target(e);
     201            switch(heap.state(v)) {
     202              case Heap::PRE_HEAP:
     203                heap.push(v, d + _length[e]);
     204                _pred[v] = e;
     205                break;
     206              case Heap::IN_HEAP:
     207                dn = d + _length[e];
     208                if (dn < heap[v]) {
     209                  heap.decrease(v, dn);
     210                  _pred[v] = e;
     211                }
     212                break;
     213              case Heap::POST_HEAP:
     214                break;
     215            }
     216          }
     217        }
     218        if (heap.empty()) return false;
     219
     220        // Update potentials of processed nodes
     221        Length t_dist = heap.prio();
     222        for (int i = 0; i < int(_proc_nodes.size()); ++i)
     223          _pi[_proc_nodes[i]] = _dist[_proc_nodes[i]] - t_dist;
     224        return true;
     225      }
     226
     227      // Execute the algorithm.
     228      bool start() {
     229        HeapCrossRef heap_cross_ref(_graph, Heap::PRE_HEAP);
     230        Heap heap(heap_cross_ref);
     231        heap.push(_s, 0);
     232        _pred[_s] = INVALID;
     233        _proc_nodes.clear();
     234
     235        // Process nodes
     236        while (!heap.empty() && heap.top() != _t) {
     237          Node u = heap.top(), v;
     238          Length d = heap.prio() + _pi[u], dn;
     239          _dist[u] = heap.prio();
    157240          _proc_nodes.push_back(u);
     241          heap.pop();
    158242
    159243          // Traverse outgoing arcs
     
    162246              v = _graph.target(e);
    163247              switch(heap.state(v)) {
    164               case Heap::PRE_HEAP:
    165                 heap.push(v, d + _length[e] - _potential[v]);
    166                 _pred[v] = e;
    167                 break;
    168               case Heap::IN_HEAP:
    169                 nd = d + _length[e] - _potential[v];
    170                 if (nd < heap[v]) {
    171                   heap.decrease(v, nd);
     248                case Heap::PRE_HEAP:
     249                  heap.push(v, d + _length[e] - _pi[v]);
    172250                  _pred[v] = e;
    173                 }
    174                 break;
    175               case Heap::POST_HEAP:
    176                 break;
     251                  break;
     252                case Heap::IN_HEAP:
     253                  dn = d + _length[e] - _pi[v];
     254                  if (dn < heap[v]) {
     255                    heap.decrease(v, dn);
     256                    _pred[v] = e;
     257                  }
     258                  break;
     259                case Heap::POST_HEAP:
     260                  break;
    177261              }
    178262            }
     
    184268              v = _graph.source(e);
    185269              switch(heap.state(v)) {
    186               case Heap::PRE_HEAP:
    187                 heap.push(v, d - _length[e] - _potential[v]);
    188                 _pred[v] = e;
    189                 break;
    190               case Heap::IN_HEAP:
    191                 nd = d - _length[e] - _potential[v];
    192                 if (nd < heap[v]) {
    193                   heap.decrease(v, nd);
     270                case Heap::PRE_HEAP:
     271                  heap.push(v, d - _length[e] - _pi[v]);
    194272                  _pred[v] = e;
    195                 }
    196                 break;
    197               case Heap::POST_HEAP:
    198                 break;
     273                  break;
     274                case Heap::IN_HEAP:
     275                  dn = d - _length[e] - _pi[v];
     276                  if (dn < heap[v]) {
     277                    heap.decrease(v, dn);
     278                    _pred[v] = e;
     279                  }
     280                  break;
     281                case Heap::POST_HEAP:
     282                  break;
    199283              }
    200284            }
     
    206290        Length t_dist = heap.prio();
    207291        for (int i = 0; i < int(_proc_nodes.size()); ++i)
    208           _potential[_proc_nodes[i]] += _dist[_proc_nodes[i]] - t_dist;
     292          _pi[_proc_nodes[i]] += _dist[_proc_nodes[i]] - t_dist;
    209293        return true;
    210294      }
    211295
    212296    }; //class ResidualDijkstra
     297
     298  public:
     299
     300    /// \name Named Template Parameters
     301    /// @{
     302
     303    template <typename T>
     304    struct SetFlowMapTraits : public Traits {
     305      typedef T FlowMap;
     306    };
     307
     308    /// \brief \ref named-templ-param "Named parameter" for setting
     309    /// \c FlowMap type.
     310    ///
     311    /// \ref named-templ-param "Named parameter" for setting
     312    /// \c FlowMap type.
     313    template <typename T>
     314    struct SetFlowMap
     315      : public Suurballe<GR, LEN, SetFlowMapTraits<T> > {
     316      typedef Suurballe<GR, LEN, SetFlowMapTraits<T> > Create;
     317    };
     318
     319    template <typename T>
     320    struct SetPotentialMapTraits : public Traits {
     321      typedef T PotentialMap;
     322    };
     323
     324    /// \brief \ref named-templ-param "Named parameter" for setting
     325    /// \c PotentialMap type.
     326    ///
     327    /// \ref named-templ-param "Named parameter" for setting
     328    /// \c PotentialMap type.
     329    template <typename T>
     330    struct SetPotentialMap
     331      : public Suurballe<GR, LEN, SetPotentialMapTraits<T> > {
     332      typedef Suurballe<GR, LEN, SetPotentialMapTraits<T> > Create;
     333    };
     334
     335    template <typename T>
     336    struct SetPathTraits : public Traits {
     337      typedef T Path;
     338    };
     339
     340    /// \brief \ref named-templ-param "Named parameter" for setting
     341    /// \c %Path type.
     342    ///
     343    /// \ref named-templ-param "Named parameter" for setting \c %Path type.
     344    /// It must conform to the \ref lemon::concepts::Path "Path" concept
     345    /// and it must have an \c addBack() function.
     346    template <typename T>
     347    struct SetPath
     348      : public Suurballe<GR, LEN, SetPathTraits<T> > {
     349      typedef Suurballe<GR, LEN, SetPathTraits<T> > Create;
     350    };
     351
     352    template <typename H, typename CR>
     353    struct SetHeapTraits : public Traits {
     354      typedef H Heap;
     355      typedef CR HeapCrossRef;
     356    };
     357
     358    /// \brief \ref named-templ-param "Named parameter" for setting
     359    /// \c Heap and \c HeapCrossRef types.
     360    ///
     361    /// \ref named-templ-param "Named parameter" for setting \c Heap
     362    /// and \c HeapCrossRef types with automatic allocation.
     363    /// They will be used for internal Dijkstra computations.
     364    /// The heap type must conform to the \ref lemon::concepts::Heap "Heap"
     365    /// concept and its priority type must be \c Length.
     366    template <typename H,
     367              typename CR = typename Digraph::template NodeMap<int> >
     368    struct SetHeap
     369      : public Suurballe<GR, LEN, SetHeapTraits<H, CR> > {
     370      typedef Suurballe<GR, LEN, SetHeapTraits<H, CR> > Create;
     371    };
     372
     373    /// @}
    213374
    214375  private:
     
    227388
    228389    // The source node
    229     Node _source;
     390    Node _s;
    230391    // The target node
    231     Node _target;
     392    Node _t;
    232393
    233394    // Container to store the found paths
    234     std::vector< SimplePath<Digraph> > paths;
     395    std::vector<Path> _paths;
    235396    int _path_num;
    236397
    237398    // The pred arc map
    238399    PredMap _pred;
    239     // Implementation of the Dijkstra algorithm for finding augmenting
    240     // shortest paths in the residual network
    241     ResidualDijkstra *_dijkstra;
     400
     401    // Data for full init
     402    PotentialMap *_init_dist;
     403    PredMap *_init_pred;
     404    bool _full_init;
     405
     406  protected:
     407
     408    Suurballe() {}
    242409
    243410  public:
     
    252419               const LengthMap &length ) :
    253420      _graph(graph), _length(length), _flow(0), _local_flow(false),
    254       _potential(0), _local_potential(false), _pred(graph)
     421      _potential(0), _local_potential(false), _pred(graph),
     422      _init_dist(0), _init_pred(0)
    255423    {}
    256424
     
    259427      if (_local_flow) delete _flow;
    260428      if (_local_potential) delete _potential;
    261       delete _dijkstra;
     429      delete _init_dist;
     430      delete _init_pred;
    262431    }
    263432
     
    304473    /// \name Execution Control
    305474    /// The simplest way to execute the algorithm is to call the run()
    306     /// function.
    307     /// \n
     475    /// function.\n
     476    /// If you need to execute the algorithm many times using the same
     477    /// source node, then you may call fullInit() once and start()
     478    /// for each target node.\n
    308479    /// If you only need the flow that is the union of the found
    309     /// arc-disjoint paths, you may call init() and findFlow().
     480    /// arc-disjoint paths, then you may call findFlow() instead of
     481    /// start().
    310482
    311483    /// @{
     
    327499    /// \code
    328500    ///   s.init(s);
    329     ///   s.findFlow(t, k);
    330     ///   s.findPaths();
     501    ///   s.start(t, k);
    331502    /// \endcode
    332503    int run(const Node& s, const Node& t, int k = 2) {
    333504      init(s);
    334       findFlow(t, k);
    335       findPaths();
     505      start(t, k);
    336506      return _path_num;
    337507    }
     
    339509    /// \brief Initialize the algorithm.
    340510    ///
    341     /// This function initializes the algorithm.
     511    /// This function initializes the algorithm with the given source node.
    342512    ///
    343513    /// \param s The source node.
    344514    void init(const Node& s) {
    345       _source = s;
     515      _s = s;
    346516
    347517      // Initialize maps
     
    354524        _local_potential = true;
    355525      }
    356       for (ArcIt e(_graph); e != INVALID; ++e) (*_flow)[e] = 0;
    357       for (NodeIt n(_graph); n != INVALID; ++n) (*_potential)[n] = 0;
     526      _full_init = false;
     527    }
     528
     529    /// \brief Initialize the algorithm and perform Dijkstra.
     530    ///
     531    /// This function initializes the algorithm and performs a full
     532    /// Dijkstra search from the given source node. It makes consecutive
     533    /// executions of \ref start() "start(t, k)" faster, since they
     534    /// have to perform %Dijkstra only k-1 times.
     535    ///
     536    /// This initialization is usually worth using instead of \ref init()
     537    /// if the algorithm is executed many times using the same source node.
     538    ///
     539    /// \param s The source node.
     540    void fullInit(const Node& s) {
     541      // Initialize maps
     542      init(s);
     543      if (!_init_dist) {
     544        _init_dist = new PotentialMap(_graph);
     545      }
     546      if (!_init_pred) {
     547        _init_pred = new PredMap(_graph);
     548      }
     549
     550      // Run a full Dijkstra
     551      typename Dijkstra<Digraph, LengthMap>
     552        ::template SetStandardHeap<Heap>
     553        ::template SetDistMap<PotentialMap>
     554        ::template SetPredMap<PredMap>
     555        ::Create dijk(_graph, _length);
     556      dijk.distMap(*_init_dist).predMap(*_init_pred);
     557      dijk.run(s);
     558
     559      _full_init = true;
     560    }
     561
     562    /// \brief Execute the algorithm.
     563    ///
     564    /// This function executes the algorithm.
     565    ///
     566    /// \param t The target node.
     567    /// \param k The number of paths to be found.
     568    ///
     569    /// \return \c k if there are at least \c k arc-disjoint paths from
     570    /// \c s to \c t in the digraph. Otherwise it returns the number of
     571    /// arc-disjoint paths found.
     572    ///
     573    /// \note Apart from the return value, <tt>s.start(t, k)</tt> is
     574    /// just a shortcut of the following code.
     575    /// \code
     576    ///   s.findFlow(t, k);
     577    ///   s.findPaths();
     578    /// \endcode
     579    int start(const Node& t, int k = 2) {
     580      findFlow(t, k);
     581      findPaths();
     582      return _path_num;
    358583    }
    359584
     
    373598    /// \pre \ref init() must be called before using this function.
    374599    int findFlow(const Node& t, int k = 2) {
    375       _target = t;
    376       _dijkstra =
    377         new ResidualDijkstra( _graph, *_flow, _length, *_potential, _pred,
    378                               _source, _target );
     600      _t = t;
     601      ResidualDijkstra dijkstra(*this);
     602
     603      // Initialization
     604      for (ArcIt e(_graph); e != INVALID; ++e) {
     605        (*_flow)[e] = 0;
     606      }
     607      if (_full_init) {
     608        for (NodeIt n(_graph); n != INVALID; ++n) {
     609          (*_potential)[n] = (*_init_dist)[n];
     610        }
     611        Node u = _t;
     612        Arc e;
     613        while ((e = (*_init_pred)[u]) != INVALID) {
     614          (*_flow)[e] = 1;
     615          u = _graph.source(e);
     616        }
     617        _path_num = 1;
     618      } else {
     619        for (NodeIt n(_graph); n != INVALID; ++n) {
     620          (*_potential)[n] = 0;
     621        }
     622        _path_num = 0;
     623      }
    379624
    380625      // Find shortest paths
    381       _path_num = 0;
    382626      while (_path_num < k) {
    383627        // Run Dijkstra
    384         if (!_dijkstra->run()) break;
     628        if (!dijkstra.run(_path_num)) break;
    385629        ++_path_num;
    386630
    387631        // Set the flow along the found shortest path
    388         Node u = _target;
     632        Node u = _t;
    389633        Arc e;
    390634        while ((e = _pred[u]) != INVALID) {
     
    403647    /// \brief Compute the paths from the flow.
    404648    ///
    405     /// This function computes the paths from the found minimum cost flow,
    406     /// which is the union of some arc-disjoint paths.
     649    /// This function computes arc-disjoint paths from the found minimum
     650    /// cost flow, which is the union of them.
    407651    ///
    408652    /// \pre \ref init() and \ref findFlow() must be called before using
     
    412656      for(ArcIt a(_graph); a != INVALID; ++a) res_flow[a] = (*_flow)[a];
    413657
    414       paths.clear();
    415       paths.resize(_path_num);
     658      _paths.clear();
     659      _paths.resize(_path_num);
    416660      for (int i = 0; i < _path_num; ++i) {
    417         Node n = _source;
    418         while (n != _target) {
     661        Node n = _s;
     662        while (n != _t) {
    419663          OutArcIt e(_graph, n);
    420664          for ( ; res_flow[e] == 0; ++e) ;
    421665          n = _graph.target(e);
    422           paths[i].addBack(e);
     666          _paths[i].addBack(e);
    423667          res_flow[e] = 0;
    424668        }
     
    519763    /// this function.
    520764    const Path& path(int i) const {
    521       return paths[i];
     765      return _paths[i];
    522766    }
    523767
  • TabularUnified lemon/time_measure.h

    r631 r833  
    376376    ///This function returns the number of stop() exections that is
    377377    ///necessary to really stop the timer.
    378     ///For example the timer
     378    ///For example, the timer
    379379    ///is running if and only if the return value is \c true
    380380    ///(i.e. greater than
  • TabularUnified lemon/unionfind.h

    r945 r956  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    4444  /// This is a very simple but efficient implementation, providing
    4545  /// only four methods: join (union), find, insert and size.
    46   /// For more features see the \ref UnionFindEnum class.
     46  /// For more features, see the \ref UnionFindEnum class.
    4747  ///
    4848  /// It is primarily used in Kruskal algorithm for finding minimal
  • TabularUnified scripts/chg-len.py

    r439 r780  
    11#! /usr/bin/env python
     2#
     3# This file is a part of LEMON, a generic C++ optimization library.
     4#
     5# Copyright (C) 2003-2009
     6# Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     7# (Egervary Research Group on Combinatorial Optimization, EGRES).
     8#
     9# Permission to use, modify and distribute this software is granted
     10# provided that this copyright notice appears in all copies. For
     11# precise terms see the accompanying LICENSE file.
     12#
     13# This software is provided "AS IS" with no warranty of any kind,
     14# express or implied, and with no claim as to its suitability for any
     15# purpose.
    216
    317import sys
  • TabularUnified scripts/mk-release.sh

    r611 r780  
    11#!/bin/bash
     2#
     3# This file is a part of LEMON, a generic C++ optimization library.
     4#
     5# Copyright (C) 2003-2009
     6# Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     7# (Egervary Research Group on Combinatorial Optimization, EGRES).
     8#
     9# Permission to use, modify and distribute this software is granted
     10# provided that this copyright notice appears in all copies. For
     11# precise terms see the accompanying LICENSE file.
     12#
     13# This software is provided "AS IS" with no warranty of any kind,
     14# express or implied, and with no claim as to its suitability for any
     15# purpose.
    216
    317set -e
  • TabularUnified scripts/unify-sources.sh

    r702 r780  
    11#!/bin/bash
     2#
     3# This file is a part of LEMON, a generic C++ optimization library.
     4#
     5# Copyright (C) 2003-2009
     6# Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     7# (Egervary Research Group on Combinatorial Optimization, EGRES).
     8#
     9# Permission to use, modify and distribute this software is granted
     10# provided that this copyright notice appears in all copies. For
     11# precise terms see the accompanying LICENSE file.
     12#
     13# This software is provided "AS IS" with no warranty of any kind,
     14# express or implied, and with no claim as to its suitability for any
     15# purpose.
    216
    317YEAR=`date +%Y`
  • TabularUnified test/CMakeLists.txt

    r1119 r1122  
    1414SET(TESTS
    1515  adaptors_test
     16  bellman_ford_test
    1617  bfs_test
    1718  circulation_test
     
    2526  error_test
    2627  euler_test
     28  fractional_matching_test
    2729  gomory_hu_test
    2830  graph_copy_test
     
    3739  min_cost_arborescence_test
    3840  min_cost_flow_test
     41  min_mean_cycle_test
    3942  path_test
     43  planarity_test
    4044  preflow_test
    4145  radix_sort_test
  • TabularUnified test/Makefile.am

    r1102 r1110  
     1if USE_VALGRIND
     2TESTS_ENVIRONMENT=$(top_srcdir)/scripts/valgrind-wrapper.sh
     3endif
     4
    15EXTRA_DIST += \
    26        test/CMakeLists.txt
     
    812check_PROGRAMS += \
    913        test/adaptors_test \
     14        test/bellman_ford_test \
    1015        test/bfs_test \
    1116        test/circulation_test \
     
    1924        test/error_test \
    2025        test/euler_test \
     26        test/fractional_matching_test \
    2127        test/gomory_hu_test \
    2228        test/graph_copy_test \
     
    3137        test/min_cost_arborescence_test \
    3238        test/min_cost_flow_test \
     39        test/min_mean_cycle_test \
    3340        test/path_test \
     41        test/planarity_test \
    3442        test/preflow_test \
    3543        test/radix_sort_test \
     
    5462
    5563test_adaptors_test_SOURCES = test/adaptors_test.cc
     64test_bellman_ford_test_SOURCES = test/bellman_ford_test.cc
    5665test_bfs_test_SOURCES = test/bfs_test.cc
    5766test_circulation_test_SOURCES = test/circulation_test.cc
     
    6574test_error_test_SOURCES = test/error_test.cc
    6675test_euler_test_SOURCES = test/euler_test.cc
     76test_fractional_matching_test_SOURCES = test/fractional_matching_test.cc
    6777test_gomory_hu_test_SOURCES = test/gomory_hu_test.cc
    6878test_graph_copy_test_SOURCES = test/graph_copy_test.cc
    6979test_graph_test_SOURCES = test/graph_test.cc
    7080test_graph_utils_test_SOURCES = test/graph_utils_test.cc
     81test_hao_orlin_test_SOURCES = test/hao_orlin_test.cc
    7182test_heap_test_SOURCES = test/heap_test.cc
    7283test_kruskal_test_SOURCES = test/kruskal_test.cc
    73 test_hao_orlin_test_SOURCES = test/hao_orlin_test.cc
    7484test_lgf_test_SOURCES = test/lgf_test.cc
    7585test_lp_test_SOURCES = test/lp_test.cc
     
    7989test_min_cost_arborescence_test_SOURCES = test/min_cost_arborescence_test.cc
    8090test_min_cost_flow_test_SOURCES = test/min_cost_flow_test.cc
     91test_min_mean_cycle_test_SOURCES = test/min_mean_cycle_test.cc
    8192test_path_test_SOURCES = test/path_test.cc
     93test_planarity_test_SOURCES = test/planarity_test.cc
    8294test_preflow_test_SOURCES = test/preflow_test.cc
    8395test_radix_sort_test_SOURCES = test/radix_sort_test.cc
  • TabularUnified test/adaptors_test.cc

    r488 r550  
    13721372
    13731373  GridGraph::EdgeMap<bool> dir_map(graph);
    1374   dir_map[graph.right(n1)] = graph.u(graph.right(n1)) == n1;
    1375   dir_map[graph.up(n1)] = graph.u(graph.up(n1)) != n1;
    1376   dir_map[graph.left(n4)] = graph.u(graph.left(n4)) != n4;
    1377   dir_map[graph.down(n4)] = graph.u(graph.down(n4)) != n4;
     1374  dir_map[graph.right(n1)] = graph.u(graph.right(n1)) != n1;
     1375  dir_map[graph.up(n1)] = graph.u(graph.up(n1)) == n1;
     1376  dir_map[graph.left(n4)] = graph.u(graph.left(n4)) == n4;
     1377  dir_map[graph.down(n4)] = graph.u(graph.down(n4)) == n4;
    13781378
    13791379  // Apply several adaptors on the grid graph
    1380   typedef SplitNodes< ReverseDigraph< const Orienter<
    1381             const GridGraph, GridGraph::EdgeMap<bool> > > >
    1382     RevSplitGridGraph;
    1383   typedef ReverseDigraph<const RevSplitGridGraph> SplitGridGraph;
     1380  typedef SplitNodes<Orienter< const GridGraph, GridGraph::EdgeMap<bool> > >
     1381    SplitGridGraph;
    13841382  typedef Undirector<const SplitGridGraph> USplitGridGraph;
    1385   typedef Undirector<const USplitGridGraph> UUSplitGridGraph;
    1386   checkConcept<concepts::Digraph, RevSplitGridGraph>();
    13871383  checkConcept<concepts::Digraph, SplitGridGraph>();
    13881384  checkConcept<concepts::Graph, USplitGridGraph>();
    1389   checkConcept<concepts::Graph, UUSplitGridGraph>();
    1390 
    1391   RevSplitGridGraph rev_adaptor =
    1392     splitNodes(reverseDigraph(orienter(graph, dir_map)));
    1393   SplitGridGraph adaptor = reverseDigraph(rev_adaptor);
     1385
     1386  SplitGridGraph adaptor = splitNodes(orienter(graph, dir_map));
    13941387  USplitGridGraph uadaptor = undirector(adaptor);
    1395   UUSplitGridGraph uuadaptor = undirector(uadaptor);
    13961388
    13971389  // Check adaptor
     
    14001392  checkGraphConArcList(adaptor, 8);
    14011393
    1402   checkGraphOutArcList(adaptor, rev_adaptor.inNode(n1), 1);
    1403   checkGraphOutArcList(adaptor, rev_adaptor.outNode(n1), 1);
    1404   checkGraphOutArcList(adaptor, rev_adaptor.inNode(n2), 2);
    1405   checkGraphOutArcList(adaptor, rev_adaptor.outNode(n2), 1);
    1406   checkGraphOutArcList(adaptor, rev_adaptor.inNode(n3), 1);
    1407   checkGraphOutArcList(adaptor, rev_adaptor.outNode(n3), 1);
    1408   checkGraphOutArcList(adaptor, rev_adaptor.inNode(n4), 0);
    1409   checkGraphOutArcList(adaptor, rev_adaptor.outNode(n4), 1);
    1410 
    1411   checkGraphInArcList(adaptor, rev_adaptor.inNode(n1), 1);
    1412   checkGraphInArcList(adaptor, rev_adaptor.outNode(n1), 1);
    1413   checkGraphInArcList(adaptor, rev_adaptor.inNode(n2), 1);
    1414   checkGraphInArcList(adaptor, rev_adaptor.outNode(n2), 0);
    1415   checkGraphInArcList(adaptor, rev_adaptor.inNode(n3), 1);
    1416   checkGraphInArcList(adaptor, rev_adaptor.outNode(n3), 1);
    1417   checkGraphInArcList(adaptor, rev_adaptor.inNode(n4), 1);
    1418   checkGraphInArcList(adaptor, rev_adaptor.outNode(n4), 2);
     1394  checkGraphOutArcList(adaptor, adaptor.inNode(n1), 1);
     1395  checkGraphOutArcList(adaptor, adaptor.outNode(n1), 1);
     1396  checkGraphOutArcList(adaptor, adaptor.inNode(n2), 1);
     1397  checkGraphOutArcList(adaptor, adaptor.outNode(n2), 0);
     1398  checkGraphOutArcList(adaptor, adaptor.inNode(n3), 1);
     1399  checkGraphOutArcList(adaptor, adaptor.outNode(n3), 1);
     1400  checkGraphOutArcList(adaptor, adaptor.inNode(n4), 1);
     1401  checkGraphOutArcList(adaptor, adaptor.outNode(n4), 2);
     1402
     1403  checkGraphInArcList(adaptor, adaptor.inNode(n1), 1);
     1404  checkGraphInArcList(adaptor, adaptor.outNode(n1), 1);
     1405  checkGraphInArcList(adaptor, adaptor.inNode(n2), 2);
     1406  checkGraphInArcList(adaptor, adaptor.outNode(n2), 1);
     1407  checkGraphInArcList(adaptor, adaptor.inNode(n3), 1);
     1408  checkGraphInArcList(adaptor, adaptor.outNode(n3), 1);
     1409  checkGraphInArcList(adaptor, adaptor.inNode(n4), 0);
     1410  checkGraphInArcList(adaptor, adaptor.outNode(n4), 1);
    14191411
    14201412  checkNodeIds(adaptor);
     
    14391431  checkGraphArcMap(uadaptor);
    14401432
    1441   checkGraphIncEdgeArcLists(uadaptor, rev_adaptor.inNode(n1), 2);
    1442   checkGraphIncEdgeArcLists(uadaptor, rev_adaptor.outNode(n1), 2);
    1443   checkGraphIncEdgeArcLists(uadaptor, rev_adaptor.inNode(n2), 3);
    1444   checkGraphIncEdgeArcLists(uadaptor, rev_adaptor.outNode(n2), 1);
    1445   checkGraphIncEdgeArcLists(uadaptor, rev_adaptor.inNode(n3), 2);
    1446   checkGraphIncEdgeArcLists(uadaptor, rev_adaptor.outNode(n3), 2);
    1447   checkGraphIncEdgeArcLists(uadaptor, rev_adaptor.inNode(n4), 1);
    1448   checkGraphIncEdgeArcLists(uadaptor, rev_adaptor.outNode(n4), 3);
    1449 
    1450   // Check uuadaptor
    1451   checkGraphNodeList(uuadaptor, 8);
    1452   checkGraphEdgeList(uuadaptor, 16);
    1453   checkGraphArcList(uuadaptor, 32);
    1454   checkGraphConEdgeList(uuadaptor, 16);
    1455   checkGraphConArcList(uuadaptor, 32);
    1456 
    1457   checkNodeIds(uuadaptor);
    1458   checkEdgeIds(uuadaptor);
    1459   checkArcIds(uuadaptor);
    1460 
    1461   checkGraphNodeMap(uuadaptor);
    1462   checkGraphEdgeMap(uuadaptor);
    1463   checkGraphArcMap(uuadaptor);
     1433  checkGraphIncEdgeArcLists(uadaptor, adaptor.inNode(n1), 2);
     1434  checkGraphIncEdgeArcLists(uadaptor, adaptor.outNode(n1), 2);
     1435  checkGraphIncEdgeArcLists(uadaptor, adaptor.inNode(n2), 3);
     1436  checkGraphIncEdgeArcLists(uadaptor, adaptor.outNode(n2), 1);
     1437  checkGraphIncEdgeArcLists(uadaptor, adaptor.inNode(n3), 2);
     1438  checkGraphIncEdgeArcLists(uadaptor, adaptor.outNode(n3), 2);
     1439  checkGraphIncEdgeArcLists(uadaptor, adaptor.inNode(n4), 1);
     1440  checkGraphIncEdgeArcLists(uadaptor, adaptor.outNode(n4), 3);
    14641441}
    14651442
  • TabularUnified test/bfs_test.cc

    r632 r956  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    8484    b = const_bfs_test.emptyQueue();
    8585    i = const_bfs_test.queueSize();
    86    
     86
    8787    bfs_test.start();
    8888    bfs_test.start(t);
     
    105105      ::SetProcessedMap<concepts::WriteMap<Node,bool> >
    106106      ::Create bfs_test(G);
    107      
     107
    108108    concepts::ReadWriteMap<Node,Arc> pred_map;
    109109    concepts::ReadWriteMap<Node,int> dist_map;
    110110    concepts::ReadWriteMap<Node,bool> reached_map;
    111111    concepts::WriteMap<Node,bool> processed_map;
    112    
     112
    113113    bfs_test
    114114      .predMap(pred_map)
     
    120120    bfs_test.run(s,t);
    121121    bfs_test.run();
    122    
     122
    123123    bfs_test.init();
    124124    bfs_test.addSource(s);
     
    129129    b = bfs_test.emptyQueue();
    130130    i = bfs_test.queueSize();
    131    
     131
    132132    bfs_test.start();
    133133    bfs_test.start(t);
  • TabularUnified test/circulation_test.cc

    r658 r956  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    8282  CirculationType circ_test(g, lcap, ucap, supply);
    8383  const CirculationType& const_circ_test = circ_test;
    84    
     84
    8585  circ_test
    8686    .lowerMap(lcap)
     
    8888    .supplyMap(supply)
    8989    .flowMap(flow);
     90
     91  const CirculationType::Elevator& elev = const_circ_test.elevator();
     92  circ_test.elevator(const_cast<CirculationType::Elevator&>(elev));
     93  CirculationType::Tolerance tol = const_circ_test.tolerance();
     94  circ_test.tolerance(tol);
    9095
    9196  circ_test.init();
     
    98103  b = const_circ_test.barrier(n);
    99104  const_circ_test.barrierMap(bar);
    100  
     105
    101106  ignore_unused_variable_warning(fm);
    102107}
  • TabularUnified test/connectivity_test.cc

    r696 r956  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    3030  typedef ListDigraph Digraph;
    3131  typedef Undirector<Digraph> Graph;
    32  
    33   {
    34     Digraph d;
    35     Digraph::NodeMap<int> order(d);
    36     Graph g(d);
    37    
     32
     33  {
     34    Digraph d;
     35    Digraph::NodeMap<int> order(d);
     36    Graph g(d);
     37
    3838    check(stronglyConnected(d), "The empty digraph is strongly connected");
    3939    check(countStronglyConnectedComponents(d) == 0,
     
    4949    check(countBiEdgeConnectedComponents(g) == 0,
    5050          "The empty graph has 0 bi-edge-connected component");
    51          
     51
    5252    check(dag(d), "The empty digraph is DAG.");
    5353    check(checkedTopologicalSort(d, order), "The empty digraph is DAG.");
     
    8383    check(countBiEdgeConnectedComponents(g) == 1,
    8484          "This graph has 1 bi-edge-connected component");
    85          
     85
    8686    check(dag(d), "This digraph is DAG.");
    8787    check(checkedTopologicalSort(d, order), "This digraph is DAG.");
     
    102102    Digraph::NodeMap<int> order(d);
    103103    Graph g(d);
    104    
     104
    105105    Digraph::Node n1 = d.addNode();
    106106    Digraph::Node n2 = d.addNode();
     
    109109    Digraph::Node n5 = d.addNode();
    110110    Digraph::Node n6 = d.addNode();
    111    
     111
    112112    d.addArc(n1, n3);
    113113    d.addArc(n3, n2);
     
    137137    check(!parallelFree(g), "This graph is not parallel-free.");
    138138    check(!simpleGraph(g), "This graph is not simple.");
    139    
     139
    140140    d.addArc(n3, n3);
    141    
     141
    142142    check(!loopFree(d), "This digraph is not loop-free.");
    143143    check(!loopFree(g), "This graph is not loop-free.");
    144144    check(!simpleGraph(d), "This digraph is not simple.");
    145    
     145
    146146    d.addArc(n3, n2);
    147    
     147
    148148    check(!parallelFree(d), "This digraph is not parallel-free.");
    149149  }
    150  
     150
    151151  {
    152152    Digraph d;
    153153    Digraph::ArcMap<bool> cutarcs(d, false);
    154154    Graph g(d);
    155    
     155
    156156    Digraph::Node n1 = d.addNode();
    157157    Digraph::Node n2 = d.addNode();
     
    173173    d.addArc(n6, n7);
    174174    d.addArc(n7, n6);
    175    
     175
    176176    check(!stronglyConnected(d), "This digraph is not strongly connected");
    177177    check(countStronglyConnectedComponents(d) == 3,
     
    236236    Digraph d;
    237237    Digraph::NodeMap<int> order(d);
    238    
     238
    239239    Digraph::Node belt = d.addNode();
    240240    Digraph::Node trousers = d.addNode();
     
    256256    d.addArc(shirt, necktie);
    257257    d.addArc(necktie, coat);
    258    
     258
    259259    check(dag(d), "This digraph is DAG.");
    260260    topologicalSort(d, order);
     
    268268    ListGraph g;
    269269    ListGraph::NodeMap<bool> map(g);
    270    
     270
    271271    ListGraph::Node n1 = g.addNode();
    272272    ListGraph::Node n2 = g.addNode();
     
    284284    g.addEdge(n4, n7);
    285285    g.addEdge(n5, n7);
    286    
     286
    287287    check(bipartite(g), "This graph is bipartite");
    288288    check(bipartitePartitions(g, map), "This graph is bipartite");
    289    
     289
    290290    check(map[n1] == map[n2] && map[n1] == map[n6] && map[n1] == map[n7],
    291291          "Wrong bipartitePartitions()");
  • TabularUnified test/dfs_test.cc

    r1009 r1110  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2011
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    8787    b = const_dfs_test.emptyQueue();
    8888    i = const_dfs_test.queueSize();
    89    
     89
    9090    dfs_test.start();
    9191    dfs_test.start(t);
     
    113113    concepts::ReadWriteMap<Node,bool> reached_map;
    114114    concepts::WriteMap<Node,bool> processed_map;
    115    
     115
    116116    dfs_test
    117117      .predMap(pred_map)
     
    130130    b = dfs_test.emptyQueue();
    131131    i = dfs_test.queueSize();
    132    
     132
    133133    dfs_test.start();
    134134    dfs_test.start(t);
     
    220220  check(dfs.run(s1,t1) && dfs.reached(t1),"Node 3 is reachable from Node 6.");
    221221  }
    222  
     222
    223223  {
    224224    NullMap<Node,Arc> myPredMap;
  • TabularUnified test/digraph_test.cc

    r463 r956  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    2020#include <lemon/list_graph.h>
    2121#include <lemon/smart_graph.h>
     22#include <lemon/static_graph.h>
    2223#include <lemon/full_graph.h>
    2324
     
    3536  checkGraphNodeList(G, 0);
    3637  checkGraphArcList(G, 0);
     38
     39  G.reserveNode(3);
     40  G.reserveArc(4);
    3741
    3842  Node
     
    284288
    285289  snapshot.restore();
     290  snapshot.save(G);
     291
     292  checkGraphNodeList(G, 4);
     293  checkGraphArcList(G, 4);
     294
     295  G.addArc(G.addNode(), G.addNode());
     296
     297  snapshot.restore();
    286298
    287299  checkGraphNodeList(G, 4);
     
    318330    checkConcept<ClearableDigraphComponent<>, SmartDigraph>();
    319331  }
     332  { // Checking StaticDigraph
     333    checkConcept<Digraph, StaticDigraph>();
     334    checkConcept<ClearableDigraphComponent<>, StaticDigraph>();
     335  }
    320336  { // Checking FullDigraph
    321337    checkConcept<Digraph, FullDigraph>();
     
    373389}
    374390
     391void checkStaticDigraph() {
     392  SmartDigraph g;
     393  SmartDigraph::NodeMap<StaticDigraph::Node> nref(g);
     394  SmartDigraph::ArcMap<StaticDigraph::Arc> aref(g);
     395
     396  StaticDigraph G;
     397
     398  checkGraphNodeList(G, 0);
     399  checkGraphArcList(G, 0);
     400
     401  G.build(g, nref, aref);
     402
     403  checkGraphNodeList(G, 0);
     404  checkGraphArcList(G, 0);
     405
     406  SmartDigraph::Node
     407    n1 = g.addNode(),
     408    n2 = g.addNode(),
     409    n3 = g.addNode();
     410
     411  G.build(g, nref, aref);
     412
     413  checkGraphNodeList(G, 3);
     414  checkGraphArcList(G, 0);
     415
     416  SmartDigraph::Arc a1 = g.addArc(n1, n2);
     417
     418  G.build(g, nref, aref);
     419
     420  check(G.source(aref[a1]) == nref[n1] && G.target(aref[a1]) == nref[n2],
     421        "Wrong arc or wrong references");
     422  checkGraphNodeList(G, 3);
     423  checkGraphArcList(G, 1);
     424
     425  checkGraphOutArcList(G, nref[n1], 1);
     426  checkGraphOutArcList(G, nref[n2], 0);
     427  checkGraphOutArcList(G, nref[n3], 0);
     428
     429  checkGraphInArcList(G, nref[n1], 0);
     430  checkGraphInArcList(G, nref[n2], 1);
     431  checkGraphInArcList(G, nref[n3], 0);
     432
     433  checkGraphConArcList(G, 1);
     434
     435  SmartDigraph::Arc
     436    a2 = g.addArc(n2, n1),
     437    a3 = g.addArc(n2, n3),
     438    a4 = g.addArc(n2, n3);
     439
     440  digraphCopy(g, G).nodeRef(nref).run();
     441
     442  checkGraphNodeList(G, 3);
     443  checkGraphArcList(G, 4);
     444
     445  checkGraphOutArcList(G, nref[n1], 1);
     446  checkGraphOutArcList(G, nref[n2], 3);
     447  checkGraphOutArcList(G, nref[n3], 0);
     448
     449  checkGraphInArcList(G, nref[n1], 1);
     450  checkGraphInArcList(G, nref[n2], 1);
     451  checkGraphInArcList(G, nref[n3], 2);
     452
     453  checkGraphConArcList(G, 4);
     454
     455  std::vector<std::pair<int,int> > arcs;
     456  arcs.push_back(std::make_pair(0,1));
     457  arcs.push_back(std::make_pair(0,2));
     458  arcs.push_back(std::make_pair(1,3));
     459  arcs.push_back(std::make_pair(1,2));
     460  arcs.push_back(std::make_pair(3,0));
     461  arcs.push_back(std::make_pair(3,3));
     462  arcs.push_back(std::make_pair(4,2));
     463  arcs.push_back(std::make_pair(4,3));
     464  arcs.push_back(std::make_pair(4,1));
     465
     466  G.build(6, arcs.begin(), arcs.end());
     467
     468  checkGraphNodeList(G, 6);
     469  checkGraphArcList(G, 9);
     470
     471  checkGraphOutArcList(G, G.node(0), 2);
     472  checkGraphOutArcList(G, G.node(1), 2);
     473  checkGraphOutArcList(G, G.node(2), 0);
     474  checkGraphOutArcList(G, G.node(3), 2);
     475  checkGraphOutArcList(G, G.node(4), 3);
     476  checkGraphOutArcList(G, G.node(5), 0);
     477
     478  checkGraphInArcList(G, G.node(0), 1);
     479  checkGraphInArcList(G, G.node(1), 2);
     480  checkGraphInArcList(G, G.node(2), 3);
     481  checkGraphInArcList(G, G.node(3), 3);
     482  checkGraphInArcList(G, G.node(4), 0);
     483  checkGraphInArcList(G, G.node(5), 0);
     484
     485  checkGraphConArcList(G, 9);
     486
     487  checkNodeIds(G);
     488  checkArcIds(G);
     489  checkGraphNodeMap(G);
     490  checkGraphArcMap(G);
     491
     492  int n = G.nodeNum();
     493  int m = G.arcNum();
     494  check(G.index(G.node(n-1)) == n-1, "Wrong index.");
     495  check(G.index(G.arc(m-1)) == m-1, "Wrong index.");
     496}
     497
    375498void checkFullDigraph(int num) {
    376499  typedef FullDigraph Digraph;
    377500  DIGRAPH_TYPEDEFS(Digraph);
     501
    378502  Digraph G(num);
     503  check(G.nodeNum() == num && G.arcNum() == num * num, "Wrong size");
     504
     505  G.resize(num);
     506  check(G.nodeNum() == num && G.arcNum() == num * num, "Wrong size");
    379507
    380508  checkGraphNodeList(G, num);
     
    420548    checkDigraphValidity<SmartDigraph>();
    421549  }
     550  { // Checking StaticDigraph
     551    checkStaticDigraph();
     552  }
    422553  { // Checking FullDigraph
    423554    checkFullDigraph(8);
  • TabularUnified test/dijkstra_test.cc

    r632 r956  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    8686    b = const_dijkstra_test.emptyQueue();
    8787    i = const_dijkstra_test.queueSize();
    88    
     88
    8989    dijkstra_test.start();
    9090    dijkstra_test.start(t);
     
    110110      ::SetHeap<BinHeap<VType, concepts::ReadWriteMap<Node,int> > >
    111111      ::SetStandardHeap<BinHeap<VType, concepts::ReadWriteMap<Node,int> > >
    112       ::SetHeap<BinHeap<VType, concepts::ReadWriteMap<Node,int> >, 
     112      ::SetHeap<BinHeap<VType, concepts::ReadWriteMap<Node,int> >,
    113113                concepts::ReadWriteMap<Node,int> >
    114114      ::Create dijkstra_test(G,length);
     
    120120    concepts::ReadWriteMap<Node,int> heap_cross_ref;
    121121    BinHeap<VType, concepts::ReadWriteMap<Node,int> > heap(heap_cross_ref);
    122    
     122
    123123    dijkstra_test
    124124      .lengthMap(length_map)
     
    137137    b = dijkstra_test.emptyQueue();
    138138    i = dijkstra_test.queueSize();
    139    
     139
    140140    dijkstra_test.start();
    141141    dijkstra_test.start(t);
  • TabularUnified test/edge_set_test.cc

    r559 r956  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2008
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
  • TabularUnified test/euler_test.cc

    r639 r956  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    8686  typedef ListDigraph Digraph;
    8787  typedef Undirector<Digraph> Graph;
    88  
    89   {
    90     Digraph d;
    91     Graph g(d);
    92    
     88
     89  {
     90    Digraph d;
     91    Graph g(d);
     92
    9393    checkDiEulerIt(d);
    9494    checkDiEulerIt(g);
     
    129129    Digraph::Node n2 = d.addNode();
    130130    Digraph::Node n3 = d.addNode();
    131    
     131
    132132    d.addArc(n1, n2);
    133133    d.addArc(n2, n1);
     
    154154    Digraph::Node n5 = d.addNode();
    155155    Digraph::Node n6 = d.addNode();
    156    
     156
    157157    d.addArc(n1, n2);
    158158    d.addArc(n2, n4);
     
    190190    Digraph::Node n4 = d.addNode();
    191191    Digraph::Node n5 = d.addNode();
    192    
     192
    193193    d.addArc(n1, n2);
    194194    d.addArc(n2, n3);
     
    212212    Digraph::Node n2 = d.addNode();
    213213    Digraph::Node n3 = d.addNode();
    214    
     214
    215215    d.addArc(n1, n2);
    216216    d.addArc(n2, n3);
  • TabularUnified test/gomory_hu_test.cc

    r643 r956  
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
     2 *
     3 * This file is a part of LEMON, a generic C++ optimization library.
     4 *
     5 * Copyright (C) 2003-2010
     6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     8 *
     9 * Permission to use, modify and distribute this software is granted
     10 * provided that this copyright notice appears in all copies. For
     11 * precise terms see the accompanying LICENSE file.
     12 *
     13 * This software is provided "AS IS" with no warranty of any kind,
     14 * express or implied, and with no claim as to its suitability for any
     15 * purpose.
     16 *
     17 */
     18
    119#include <iostream>
    220
     
    3452  "source 0\n"
    3553  "target 3\n";
    36  
     54
    3755void checkGomoryHuCompile()
    3856{
     
    7088
    7189int cutValue(const Graph& graph, const BoolNodeMap& cut,
    72              const IntEdgeMap& capacity) {
     90             const IntEdgeMap& capacity) {
    7391
    7492  int sum = 0;
     
    108126      int sum=0;
    109127      for(GomoryHu<Graph>::MinCutEdgeIt a(ght, u, v);a!=INVALID;++a)
    110         sum+=capacity[a]; 
     128        sum+=capacity[a];
    111129      check(sum == ght.minCutValue(u, v), "Problem with MinCutEdgeIt");
    112130
     
    119137    }
    120138  }
    121  
     139
    122140  return 0;
    123141}
  • TabularUnified test/graph_copy_test.cc

    r984 r1081  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2011
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    7171    nodeCrossRef(ncr).arcCrossRef(ecr).
    7272    node(fn, tn).arc(fa, ta).run();
    73  
     73
    7474  check(countNodes(from) == countNodes(to), "Wrong copy.");
    7575  check(countArcs(from) == countArcs(to), "Wrong copy.");
     
    9999  // Test repeated copy
    100100  digraphCopy(from, to).run();
    101  
     101
    102102  check(countNodes(from) == countNodes(to), "Wrong copy.");
    103103  check(countArcs(from) == countArcs(to), "Wrong copy.");
     
    201201  // Test repeated copy
    202202  graphCopy(from, to).run();
    203  
     203
    204204  check(countNodes(from) == countNodes(to), "Wrong copy.");
    205205  check(countEdges(from) == countEdges(to), "Wrong copy.");
  • TabularUnified test/graph_test.cc

    r463 r956  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    3939  checkGraphArcList(G, 0);
    4040
     41  G.reserveNode(3);
     42  G.reserveEdge(3);
     43
    4144  Node
    4245    n1 = G.addNode(),
     
    257260
    258261  snapshot.restore();
     262  snapshot.save(G);
     263
     264  checkGraphNodeList(G, 4);
     265  checkGraphEdgeList(G, 3);
     266  checkGraphArcList(G, 6);
     267
     268  G.addEdge(G.addNode(), G.addNode());
     269
     270  snapshot.restore();
    259271
    260272  checkGraphNodeList(G, 4);
     
    268280
    269281  Graph G(num);
     282  check(G.nodeNum() == num && G.edgeNum() == num * (num - 1) / 2,
     283        "Wrong size");
     284
     285  G.resize(num);
     286  check(G.nodeNum() == num && G.edgeNum() == num * (num - 1) / 2,
     287        "Wrong size");
     288
    270289  checkGraphNodeList(G, num);
    271290  checkGraphEdgeList(G, num * (num - 1) / 2);
     
    412431  check(G.height() == height, "Wrong row number");
    413432
     433  G.resize(width, height);
     434  check(G.width() == width, "Wrong column number");
     435  check(G.height() == height, "Wrong row number");
     436
    414437  for (int i = 0; i < width; ++i) {
    415438    for (int j = 0; j < height; ++j) {
     
    487510
    488511  HypercubeGraph G(dim);
     512  check(G.dimension() == dim, "Wrong dimension");
     513
     514  G.resize(dim);
     515  check(G.dimension() == dim, "Wrong dimension");
     516
    489517  checkGraphNodeList(G, 1 << dim);
    490518  checkGraphEdgeList(G, dim * (1 << (dim-1)));
  • TabularUnified test/hao_orlin_test.cc

    r644 r956  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    8484
    8585template <typename Graph, typename CapMap, typename CutMap>
    86 typename CapMap::Value 
     86typename CapMap::Value
    8787  cutValue(const Graph& graph, const CapMap& cap, const CutMap& cut)
    8888{
     
    111111    ho.run();
    112112    ho.minCutMap(cut);
    113    
     113
    114114    check(ho.minCutValue() == 1, "Wrong cut value");
    115115    check(ho.minCutValue() == cutValue(graph, cap1, cut), "Wrong cut value");
     
    127127    ho.run();
    128128    ho.minCutMap(cut);
    129    
     129
    130130    check(ho.minCutValue() == 1, "Wrong cut value");
    131131    check(ho.minCutValue() == cutValue(graph, cap3, cut), "Wrong cut value");
    132132  }
    133  
     133
    134134  typedef Undirector<SmartDigraph> UGraph;
    135135  UGraph ugraph(graph);
    136  
     136
    137137  {
    138138    HaoOrlin<UGraph, SmartDigraph::ArcMap<int> > ho(ugraph, cap1);
    139139    ho.run();
    140140    ho.minCutMap(cut);
    141    
     141
    142142    check(ho.minCutValue() == 2, "Wrong cut value");
    143143    check(ho.minCutValue() == cutValue(ugraph, cap1, cut), "Wrong cut value");
     
    147147    ho.run();
    148148    ho.minCutMap(cut);
    149    
     149
    150150    check(ho.minCutValue() == 5, "Wrong cut value");
    151151    check(ho.minCutValue() == cutValue(ugraph, cap2, cut), "Wrong cut value");
     
    155155    ho.run();
    156156    ho.minCutMap(cut);
    157    
     157
    158158    check(ho.minCutValue() == 5, "Wrong cut value");
    159159    check(ho.minCutValue() == cutValue(ugraph, cap3, cut), "Wrong cut value");
  • TabularUnified test/heap_test.cc

    r728 r1084  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2011
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    2626
    2727#include <lemon/smart_graph.h>
    28 
    2928#include <lemon/lgf_reader.h>
    3029#include <lemon/dijkstra.h>
     
    3231
    3332#include <lemon/bin_heap.h>
     33#include <lemon/quad_heap.h>
     34#include <lemon/dheap.h>
    3435#include <lemon/fib_heap.h>
     36#include <lemon/pairing_heap.h>
    3537#include <lemon/radix_heap.h>
     38#include <lemon/binomial_heap.h>
    3639#include <lemon/bucket_heap.h>
    3740
     
    9093void heapSortTest() {
    9194  RangeMap<int> map(test_len, -1);
    92 
    9395  Heap heap(map);
    9496
    9597  std::vector<int> v(test_len);
    96 
    9798  for (int i = 0; i < test_len; ++i) {
    9899    v[i] = test_seq[i];
     
    101102  std::sort(v.begin(), v.end());
    102103  for (int i = 0; i < test_len; ++i) {
    103     check(v[i] == heap.prio() ,"Wrong order in heap sort.");
     104    check(v[i] == heap.prio(), "Wrong order in heap sort.");
    104105    heap.pop();
    105106  }
     
    113114
    114115  std::vector<int> v(test_len);
    115 
    116116  for (int i = 0; i < test_len; ++i) {
    117117    v[i] = test_seq[i];
     
    124124  std::sort(v.begin(), v.end());
    125125  for (int i = 0; i < test_len; ++i) {
    126     check(v[i] == heap.prio() ,"Wrong order in heap increase test.");
     126    check(v[i] == heap.prio(), "Wrong order in heap increase test.");
    127127    heap.pop();
    128128  }
    129129}
    130 
    131 
    132130
    133131template <typename Heap>
     
    145143    if (dijkstra.reached(s)) {
    146144      check( dijkstra.dist(t) - dijkstra.dist(s) <= length[a],
    147              "Error in a shortest path tree!");
     145             "Error in shortest path tree.");
    148146    }
    149147  }
     
    154152      Node s = digraph.source(a);
    155153      check( dijkstra.dist(n) - dijkstra.dist(s) == length[a],
    156              "Error in a shortest path tree!");
     154             "Error in shortest path tree.");
    157155    }
    158156  }
     
    176174    run();
    177175
     176  // BinHeap
    178177  {
    179178    typedef BinHeap<Prio, ItemIntMap> IntHeap;
     
    185184    checkConcept<Heap<Prio, IntNodeMap >, NodeHeap>();
    186185    dijkstraHeapTest<NodeHeap>(digraph, length, source);
     186  }
     187
     188  // QuadHeap
     189  {
     190    typedef QuadHeap<Prio, ItemIntMap> IntHeap;
     191    checkConcept<Heap<Prio, ItemIntMap>, IntHeap>();
     192    heapSortTest<IntHeap>();
     193    heapIncreaseTest<IntHeap>();
     194
     195    typedef QuadHeap<Prio, IntNodeMap > NodeHeap;
     196    checkConcept<Heap<Prio, IntNodeMap >, NodeHeap>();
     197    dijkstraHeapTest<NodeHeap>(digraph, length, source);
     198  }
     199
     200  // DHeap
     201  {
     202    typedef DHeap<Prio, ItemIntMap> IntHeap;
     203    checkConcept<Heap<Prio, ItemIntMap>, IntHeap>();
     204    heapSortTest<IntHeap>();
     205    heapIncreaseTest<IntHeap>();
     206
     207    typedef DHeap<Prio, IntNodeMap > NodeHeap;
     208    checkConcept<Heap<Prio, IntNodeMap >, NodeHeap>();
     209    dijkstraHeapTest<NodeHeap>(digraph, length, source);
     210  }
     211
     212  // FibHeap
     213  {
     214    typedef FibHeap<Prio, ItemIntMap> IntHeap;
     215    checkConcept<Heap<Prio, ItemIntMap>, IntHeap>();
     216    heapSortTest<IntHeap>();
     217    heapIncreaseTest<IntHeap>();
     218
     219    typedef FibHeap<Prio, IntNodeMap > NodeHeap;
     220    checkConcept<Heap<Prio, IntNodeMap >, NodeHeap>();
     221    dijkstraHeapTest<NodeHeap>(digraph, length, source);
     222  }
     223
     224  // PairingHeap
     225  {
     226    typedef PairingHeap<Prio, ItemIntMap> IntHeap;
     227    checkConcept<Heap<Prio, ItemIntMap>, IntHeap>();
     228    heapSortTest<IntHeap>();
     229    heapIncreaseTest<IntHeap>();
     230
     231    typedef PairingHeap<Prio, IntNodeMap > NodeHeap;
     232    checkConcept<Heap<Prio, IntNodeMap >, NodeHeap>();
     233    dijkstraHeapTest<NodeHeap>(digraph, length, source);
     234  }
     235
     236  // RadixHeap
     237  {
     238    typedef RadixHeap<ItemIntMap> IntHeap;
     239    checkConcept<Heap<Prio, ItemIntMap>, IntHeap>();
     240    heapSortTest<IntHeap>();
     241    heapIncreaseTest<IntHeap>();
     242
     243    typedef RadixHeap<IntNodeMap > NodeHeap;
     244    checkConcept<Heap<Prio, IntNodeMap >, NodeHeap>();
     245    dijkstraHeapTest<NodeHeap>(digraph, length, source);
     246  }
     247
     248  // BinomialHeap
     249  {
     250    typedef BinomialHeap<Prio, ItemIntMap> IntHeap;
     251    checkConcept<Heap<Prio, ItemIntMap>, IntHeap>();
     252    heapSortTest<IntHeap>();
     253    heapIncreaseTest<IntHeap>();
     254
     255    typedef BinomialHeap<Prio, IntNodeMap > NodeHeap;
     256    checkConcept<Heap<Prio, IntNodeMap >, NodeHeap>();
     257    dijkstraHeapTest<NodeHeap>(digraph, length, source);
     258  }
     259
     260  // BucketHeap, SimpleBucketHeap
     261  {
     262    typedef BucketHeap<ItemIntMap> IntHeap;
     263    checkConcept<Heap<Prio, ItemIntMap>, IntHeap>();
     264    heapSortTest<IntHeap>();
     265    heapIncreaseTest<IntHeap>();
     266
     267    typedef BucketHeap<IntNodeMap > NodeHeap;
     268    checkConcept<Heap<Prio, IntNodeMap >, NodeHeap>();
     269    dijkstraHeapTest<NodeHeap>(digraph, length, source);
     270
     271    typedef SimpleBucketHeap<ItemIntMap> SimpleIntHeap;
     272    heapSortTest<SimpleIntHeap>();
    187273  }
    188274
  • TabularUnified test/lgf_test.cc

    r1087 r1097  
    6464
    6565
    66 int main() 
     66int main()
    6767{
    6868  {
    69     ListDigraph d; 
     69    ListDigraph d;
    7070    ListDigraph::Node s,t;
    7171    ListDigraph::ArcMap<int> label(d);
     
    9494
    9595  {
    96     ListDigraph d; 
     96    ListDigraph d;
    9797    std::istringstream input(test_lgf_nomap);
    9898    digraphReader(d, input).
     
    111111
    112112  {
    113     ListDigraph d; 
     113    ListDigraph d;
    114114    std::istringstream input(test_lgf_bad1);
    115115    bool ok=false;
     
    118118        run();
    119119    }
    120     catch (FormatError&) 
     120    catch (FormatError&)
    121121      {
    122122        ok = true;
     
    140140
    141141  {
    142     ListDigraph d; 
     142    ListDigraph d;
    143143    std::istringstream input(test_lgf_bad2);
    144144    bool ok=false;
  • TabularUnified test/lp_test.cc

    r1092 r1097  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2011
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
  • TabularUnified test/maps_test.cc

    r731 r1084  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2011
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    2424#include <lemon/maps.h>
    2525#include <lemon/list_graph.h>
     26#include <lemon/smart_graph.h>
     27#include <lemon/adaptors.h>
     28#include <lemon/dfs.h>
     29#include <algorithm>
    2630
    2731#include "test_tools.h"
     
    3539
    3640class C {
    37   int x;
     41  int _x;
    3842public:
    39   C(int _x) : x(_x) {}
     43  C(int x) : _x(x) {}
     44  int get() const { return _x; }
     45};
     46inline bool operator<(C c1, C c2) { return c1.get() < c2.get(); }
     47inline bool operator==(C c1, C c2) { return c1.get() == c2.get(); }
     48
     49C createC(int x) { return C(x); }
     50
     51template <typename T>
     52class Less {
     53  T _t;
     54public:
     55  Less(T t): _t(t) {}
     56  bool operator()(const T& t) const { return t < _t; }
    4057};
    4158
     
    5370
    5471int binc(int a, B) { return a+1; }
     72
     73template <typename T>
     74class Sum {
     75  T& _sum;
     76public:
     77  Sum(T& sum) : _sum(sum) {}
     78  void operator()(const T& t) { _sum += t; }
     79};
    5580
    5681typedef ReadMap<A, double> DoubleMap;
     
    201226
    202227    checkConcept<ReadMap<A,B>, MapToFunctor<ReadMap<A,B> > >();
    203     MapToFunctor<ReadMap<A,B> > map = MapToFunctor<ReadMap<A,B> >(ReadMap<A,B>());
     228    MapToFunctor<ReadMap<A,B> > map =
     229      MapToFunctor<ReadMap<A,B> >(ReadMap<A,B>());
    204230
    205231    check(functorToMap(&func)[A()] == 3,
     
    330356  {
    331357    typedef std::vector<int> vec;
     358    checkConcept<WriteMap<int, bool>, LoggerBoolMap<vec::iterator> >();
     359    checkConcept<WriteMap<int, bool>,
     360                 LoggerBoolMap<std::back_insert_iterator<vec> > >();
     361
    332362    vec v1;
    333363    vec v2(10);
     
    349379          it != map2.end(); ++it )
    350380      check(v1[i++] == *it, "Something is wrong with LoggerBoolMap");
    351   }
    352  
    353   // CrossRefMap
    354   {
     381
    355382    typedef ListDigraph Graph;
    356383    DIGRAPH_TYPEDEFS(Graph);
     384    Graph gr;
     385
     386    Node n0 = gr.addNode();
     387    Node n1 = gr.addNode();
     388    Node n2 = gr.addNode();
     389    Node n3 = gr.addNode();
     390
     391    gr.addArc(n3, n0);
     392    gr.addArc(n3, n2);
     393    gr.addArc(n0, n2);
     394    gr.addArc(n2, n1);
     395    gr.addArc(n0, n1);
     396
     397    {
     398      std::vector<Node> v;
     399      dfs(gr).processedMap(loggerBoolMap(std::back_inserter(v))).run();
     400
     401      check(v.size()==4 && v[0]==n1 && v[1]==n2 && v[2]==n0 && v[3]==n3,
     402            "Something is wrong with LoggerBoolMap");
     403    }
     404    {
     405      std::vector<Node> v(countNodes(gr));
     406      dfs(gr).processedMap(loggerBoolMap(v.begin())).run();
     407
     408      check(v.size()==4 && v[0]==n1 && v[1]==n2 && v[2]==n0 && v[3]==n3,
     409            "Something is wrong with LoggerBoolMap");
     410    }
     411  }
     412
     413  // IdMap, RangeIdMap
     414  {
     415    typedef ListDigraph Graph;
     416    DIGRAPH_TYPEDEFS(Graph);
     417
     418    checkConcept<ReadMap<Node, int>, IdMap<Graph, Node> >();
     419    checkConcept<ReadMap<Arc, int>, IdMap<Graph, Arc> >();
     420    checkConcept<ReadMap<Node, int>, RangeIdMap<Graph, Node> >();
     421    checkConcept<ReadMap<Arc, int>, RangeIdMap<Graph, Arc> >();
     422
     423    Graph gr;
     424    IdMap<Graph, Node> nmap(gr);
     425    IdMap<Graph, Arc> amap(gr);
     426    RangeIdMap<Graph, Node> nrmap(gr);
     427    RangeIdMap<Graph, Arc> armap(gr);
     428
     429    Node n0 = gr.addNode();
     430    Node n1 = gr.addNode();
     431    Node n2 = gr.addNode();
     432
     433    Arc a0 = gr.addArc(n0, n1);
     434    Arc a1 = gr.addArc(n0, n2);
     435    Arc a2 = gr.addArc(n2, n1);
     436    Arc a3 = gr.addArc(n2, n0);
     437
     438    check(nmap[n0] == gr.id(n0) && nmap(gr.id(n0)) == n0, "Wrong IdMap");
     439    check(nmap[n1] == gr.id(n1) && nmap(gr.id(n1)) == n1, "Wrong IdMap");
     440    check(nmap[n2] == gr.id(n2) && nmap(gr.id(n2)) == n2, "Wrong IdMap");
     441
     442    check(amap[a0] == gr.id(a0) && amap(gr.id(a0)) == a0, "Wrong IdMap");
     443    check(amap[a1] == gr.id(a1) && amap(gr.id(a1)) == a1, "Wrong IdMap");
     444    check(amap[a2] == gr.id(a2) && amap(gr.id(a2)) == a2, "Wrong IdMap");
     445    check(amap[a3] == gr.id(a3) && amap(gr.id(a3)) == a3, "Wrong IdMap");
     446
     447    check(nmap.inverse()[gr.id(n0)] == n0, "Wrong IdMap::InverseMap");
     448    check(amap.inverse()[gr.id(a0)] == a0, "Wrong IdMap::InverseMap");
     449
     450    check(nrmap.size() == 3 && armap.size() == 4,
     451          "Wrong RangeIdMap::size()");
     452
     453    check(nrmap[n0] == 0 && nrmap(0) == n0, "Wrong RangeIdMap");
     454    check(nrmap[n1] == 1 && nrmap(1) == n1, "Wrong RangeIdMap");
     455    check(nrmap[n2] == 2 && nrmap(2) == n2, "Wrong RangeIdMap");
     456
     457    check(armap[a0] == 0 && armap(0) == a0, "Wrong RangeIdMap");
     458    check(armap[a1] == 1 && armap(1) == a1, "Wrong RangeIdMap");
     459    check(armap[a2] == 2 && armap(2) == a2, "Wrong RangeIdMap");
     460    check(armap[a3] == 3 && armap(3) == a3, "Wrong RangeIdMap");
     461
     462    check(nrmap.inverse()[0] == n0, "Wrong RangeIdMap::InverseMap");
     463    check(armap.inverse()[0] == a0, "Wrong RangeIdMap::InverseMap");
     464
     465    gr.erase(n1);
     466
     467    if (nrmap[n0] == 1) nrmap.swap(n0, n2);
     468    nrmap.swap(n2, n0);
     469    if (armap[a1] == 1) armap.swap(a1, a3);
     470    armap.swap(a3, a1);
     471
     472    check(nrmap.size() == 2 && armap.size() == 2,
     473          "Wrong RangeIdMap::size()");
     474
     475    check(nrmap[n0] == 1 && nrmap(1) == n0, "Wrong RangeIdMap");
     476    check(nrmap[n2] == 0 && nrmap(0) == n2, "Wrong RangeIdMap");
     477
     478    check(armap[a1] == 1 && armap(1) == a1, "Wrong RangeIdMap");
     479    check(armap[a3] == 0 && armap(0) == a3, "Wrong RangeIdMap");
     480
     481    check(nrmap.inverse()[0] == n2, "Wrong RangeIdMap::InverseMap");
     482    check(armap.inverse()[0] == a3, "Wrong RangeIdMap::InverseMap");
     483  }
     484
     485  // SourceMap, TargetMap, ForwardMap, BackwardMap, InDegMap, OutDegMap
     486  {
     487    typedef ListGraph Graph;
     488    GRAPH_TYPEDEFS(Graph);
     489
     490    checkConcept<ReadMap<Arc, Node>, SourceMap<Graph> >();
     491    checkConcept<ReadMap<Arc, Node>, TargetMap<Graph> >();
     492    checkConcept<ReadMap<Edge, Arc>, ForwardMap<Graph> >();
     493    checkConcept<ReadMap<Edge, Arc>, BackwardMap<Graph> >();
     494    checkConcept<ReadMap<Node, int>, InDegMap<Graph> >();
     495    checkConcept<ReadMap<Node, int>, OutDegMap<Graph> >();
     496
     497    Graph gr;
     498    Node n0 = gr.addNode();
     499    Node n1 = gr.addNode();
     500    Node n2 = gr.addNode();
     501
     502    gr.addEdge(n0,n1);
     503    gr.addEdge(n1,n2);
     504    gr.addEdge(n0,n2);
     505    gr.addEdge(n2,n1);
     506    gr.addEdge(n1,n2);
     507    gr.addEdge(n0,n1);
     508
     509    for (EdgeIt e(gr); e != INVALID; ++e) {
     510      check(forwardMap(gr)[e] == gr.direct(e, true), "Wrong ForwardMap");
     511      check(backwardMap(gr)[e] == gr.direct(e, false), "Wrong BackwardMap");
     512    }
     513
     514    check(mapCompare(gr,
     515          sourceMap(orienter(gr, constMap<Edge, bool>(true))),
     516          targetMap(orienter(gr, constMap<Edge, bool>(false)))),
     517          "Wrong SourceMap or TargetMap");
     518
     519    typedef Orienter<Graph, const ConstMap<Edge, bool> > Digraph;
     520    Digraph dgr(gr, constMap<Edge, bool>(true));
     521    OutDegMap<Digraph> odm(dgr);
     522    InDegMap<Digraph> idm(dgr);
     523
     524    check(odm[n0] == 3 && odm[n1] == 2 && odm[n2] == 1, "Wrong OutDegMap");
     525    check(idm[n0] == 0 && idm[n1] == 3 && idm[n2] == 3, "Wrong InDegMap");
     526
     527    gr.addEdge(n2, n0);
     528
     529    check(odm[n0] == 3 && odm[n1] == 2 && odm[n2] == 2, "Wrong OutDegMap");
     530    check(idm[n0] == 1 && idm[n1] == 3 && idm[n2] == 3, "Wrong InDegMap");
     531  }
     532
     533  // CrossRefMap
     534  {
     535    typedef ListDigraph Graph;
     536    DIGRAPH_TYPEDEFS(Graph);
    357537
    358538    checkConcept<ReadWriteMap<Node, int>,
    359539                 CrossRefMap<Graph, Node, int> >();
    360    
     540    checkConcept<ReadWriteMap<Node, bool>,
     541                 CrossRefMap<Graph, Node, bool> >();
     542    checkConcept<ReadWriteMap<Node, double>,
     543                 CrossRefMap<Graph, Node, double> >();
     544
     545    Graph gr;
     546    typedef CrossRefMap<Graph, Node, char> CRMap;
     547    CRMap map(gr);
     548
     549    Node n0 = gr.addNode();
     550    Node n1 = gr.addNode();
     551    Node n2 = gr.addNode();
     552
     553    map.set(n0, 'A');
     554    map.set(n1, 'B');
     555    map.set(n2, 'C');
     556
     557    check(map[n0] == 'A' && map('A') == n0 && map.inverse()['A'] == n0,
     558          "Wrong CrossRefMap");
     559    check(map[n1] == 'B' && map('B') == n1 && map.inverse()['B'] == n1,
     560          "Wrong CrossRefMap");
     561    check(map[n2] == 'C' && map('C') == n2 && map.inverse()['C'] == n2,
     562          "Wrong CrossRefMap");
     563    check(map.count('A') == 1 && map.count('B') == 1 && map.count('C') == 1,
     564          "Wrong CrossRefMap::count()");
     565
     566    CRMap::ValueIt it = map.beginValue();
     567    check(*it++ == 'A' && *it++ == 'B' && *it++ == 'C' &&
     568          it == map.endValue(), "Wrong value iterator");
     569
     570    map.set(n2, 'A');
     571
     572    check(map[n0] == 'A' && map[n1] == 'B' && map[n2] == 'A',
     573          "Wrong CrossRefMap");
     574    check(map('A') == n0 && map.inverse()['A'] == n0, "Wrong CrossRefMap");
     575    check(map('B') == n1 && map.inverse()['B'] == n1, "Wrong CrossRefMap");
     576    check(map('C') == INVALID && map.inverse()['C'] == INVALID,
     577          "Wrong CrossRefMap");
     578    check(map.count('A') == 2 && map.count('B') == 1 && map.count('C') == 0,
     579          "Wrong CrossRefMap::count()");
     580
     581    it = map.beginValue();
     582    check(*it++ == 'A' && *it++ == 'A' && *it++ == 'B' &&
     583          it == map.endValue(), "Wrong value iterator");
     584
     585    map.set(n0, 'C');
     586
     587    check(map[n0] == 'C' && map[n1] == 'B' && map[n2] == 'A',
     588          "Wrong CrossRefMap");
     589    check(map('A') == n2 && map.inverse()['A'] == n2, "Wrong CrossRefMap");
     590    check(map('B') == n1 && map.inverse()['B'] == n1, "Wrong CrossRefMap");
     591    check(map('C') == n0 && map.inverse()['C'] == n0, "Wrong CrossRefMap");
     592    check(map.count('A') == 1 && map.count('B') == 1 && map.count('C') == 1,
     593          "Wrong CrossRefMap::count()");
     594
     595    it = map.beginValue();
     596    check(*it++ == 'A' && *it++ == 'B' && *it++ == 'C' &&
     597          it == map.endValue(), "Wrong value iterator");
     598  }
     599
     600  // CrossRefMap
     601  {
     602    typedef SmartDigraph Graph;
     603    DIGRAPH_TYPEDEFS(Graph);
     604
     605    checkConcept<ReadWriteMap<Node, int>,
     606                 CrossRefMap<Graph, Node, int> >();
     607
    361608    Graph gr;
    362609    typedef CrossRefMap<Graph, Node, char> CRMap;
    363610    typedef CRMap::ValueIterator ValueIt;
    364611    CRMap map(gr);
    365    
     612
    366613    Node n0 = gr.addNode();
    367614    Node n1 = gr.addNode();
    368615    Node n2 = gr.addNode();
    369    
     616
    370617    map.set(n0, 'A');
    371618    map.set(n1, 'B');
     
    385632  }
    386633
     634  // Iterable bool map
     635  {
     636    typedef SmartGraph Graph;
     637    typedef SmartGraph::Node Item;
     638
     639    typedef IterableBoolMap<SmartGraph, SmartGraph::Node> Ibm;
     640    checkConcept<ReferenceMap<Item, bool, bool&, const bool&>, Ibm>();
     641
     642    const int num = 10;
     643    Graph g;
     644    Ibm map0(g, true);
     645    std::vector<Item> items;
     646    for (int i = 0; i < num; ++i) {
     647      items.push_back(g.addNode());
     648    }
     649
     650    Ibm map1(g, true);
     651    int n = 0;
     652    for (Ibm::TrueIt it(map1); it != INVALID; ++it) {
     653      check(map1[static_cast<Item>(it)], "Wrong TrueIt");
     654      ++n;
     655    }
     656    check(n == num, "Wrong number");
     657
     658    n = 0;
     659    for (Ibm::ItemIt it(map1, true); it != INVALID; ++it) {
     660        check(map1[static_cast<Item>(it)], "Wrong ItemIt for true");
     661        ++n;
     662    }
     663    check(n == num, "Wrong number");
     664    check(Ibm::FalseIt(map1) == INVALID, "Wrong FalseIt");
     665    check(Ibm::ItemIt(map1, false) == INVALID, "Wrong ItemIt for false");
     666
     667    map1[items[5]] = true;
     668
     669    n = 0;
     670    for (Ibm::ItemIt it(map1, true); it != INVALID; ++it) {
     671        check(map1[static_cast<Item>(it)], "Wrong ItemIt for true");
     672        ++n;
     673    }
     674    check(n == num, "Wrong number");
     675
     676    map1[items[num / 2]] = false;
     677    check(map1[items[num / 2]] == false, "Wrong map value");
     678
     679    n = 0;
     680    for (Ibm::TrueIt it(map1); it != INVALID; ++it) {
     681        check(map1[static_cast<Item>(it)], "Wrong TrueIt for true");
     682        ++n;
     683    }
     684    check(n == num - 1, "Wrong number");
     685
     686    n = 0;
     687    for (Ibm::FalseIt it(map1); it != INVALID; ++it) {
     688        check(!map1[static_cast<Item>(it)], "Wrong FalseIt for true");
     689        ++n;
     690    }
     691    check(n == 1, "Wrong number");
     692
     693    map1[items[0]] = false;
     694    check(map1[items[0]] == false, "Wrong map value");
     695
     696    map1[items[num - 1]] = false;
     697    check(map1[items[num - 1]] == false, "Wrong map value");
     698
     699    n = 0;
     700    for (Ibm::TrueIt it(map1); it != INVALID; ++it) {
     701        check(map1[static_cast<Item>(it)], "Wrong TrueIt for true");
     702        ++n;
     703    }
     704    check(n == num - 3, "Wrong number");
     705    check(map1.trueNum() == num - 3, "Wrong number");
     706
     707    n = 0;
     708    for (Ibm::FalseIt it(map1); it != INVALID; ++it) {
     709        check(!map1[static_cast<Item>(it)], "Wrong FalseIt for true");
     710        ++n;
     711    }
     712    check(n == 3, "Wrong number");
     713    check(map1.falseNum() == 3, "Wrong number");
     714  }
     715
     716  // Iterable int map
     717  {
     718    typedef SmartGraph Graph;
     719    typedef SmartGraph::Node Item;
     720    typedef IterableIntMap<SmartGraph, SmartGraph::Node> Iim;
     721
     722    checkConcept<ReferenceMap<Item, int, int&, const int&>, Iim>();
     723
     724    const int num = 10;
     725    Graph g;
     726    Iim map0(g, 0);
     727    std::vector<Item> items;
     728    for (int i = 0; i < num; ++i) {
     729      items.push_back(g.addNode());
     730    }
     731
     732    Iim map1(g);
     733    check(map1.size() == 0, "Wrong size");
     734
     735    for (int i = 0; i < num; ++i) {
     736      map1[items[i]] = i;
     737    }
     738    check(map1.size() == num, "Wrong size");
     739
     740    for (int i = 0; i < num; ++i) {
     741      Iim::ItemIt it(map1, i);
     742      check(static_cast<Item>(it) == items[i], "Wrong value");
     743      ++it;
     744      check(static_cast<Item>(it) == INVALID, "Wrong value");
     745    }
     746
     747    for (int i = 0; i < num; ++i) {
     748      map1[items[i]] = i % 2;
     749    }
     750    check(map1.size() == 2, "Wrong size");
     751
     752    int n = 0;
     753    for (Iim::ItemIt it(map1, 0); it != INVALID; ++it) {
     754      check(map1[static_cast<Item>(it)] == 0, "Wrong value");
     755      ++n;
     756    }
     757    check(n == (num + 1) / 2, "Wrong number");
     758
     759    for (Iim::ItemIt it(map1, 1); it != INVALID; ++it) {
     760      check(map1[static_cast<Item>(it)] == 1, "Wrong value");
     761      ++n;
     762    }
     763    check(n == num, "Wrong number");
     764
     765  }
     766
     767  // Iterable value map
     768  {
     769    typedef SmartGraph Graph;
     770    typedef SmartGraph::Node Item;
     771    typedef IterableValueMap<SmartGraph, SmartGraph::Node, double> Ivm;
     772
     773    checkConcept<ReadWriteMap<Item, double>, Ivm>();
     774
     775    const int num = 10;
     776    Graph g;
     777    Ivm map0(g, 0.0);
     778    std::vector<Item> items;
     779    for (int i = 0; i < num; ++i) {
     780      items.push_back(g.addNode());
     781    }
     782
     783    Ivm map1(g, 0.0);
     784    check(distance(map1.beginValue(), map1.endValue()) == 1, "Wrong size");
     785    check(*map1.beginValue() == 0.0, "Wrong value");
     786
     787    for (int i = 0; i < num; ++i) {
     788      map1.set(items[i], static_cast<double>(i));
     789    }
     790    check(distance(map1.beginValue(), map1.endValue()) == num, "Wrong size");
     791
     792    for (int i = 0; i < num; ++i) {
     793      Ivm::ItemIt it(map1, static_cast<double>(i));
     794      check(static_cast<Item>(it) == items[i], "Wrong value");
     795      ++it;
     796      check(static_cast<Item>(it) == INVALID, "Wrong value");
     797    }
     798
     799    for (Ivm::ValueIt vit = map1.beginValue();
     800         vit != map1.endValue(); ++vit) {
     801      check(map1[static_cast<Item>(Ivm::ItemIt(map1, *vit))] == *vit,
     802            "Wrong ValueIt");
     803    }
     804
     805    for (int i = 0; i < num; ++i) {
     806      map1.set(items[i], static_cast<double>(i % 2));
     807    }
     808    check(distance(map1.beginValue(), map1.endValue()) == 2, "Wrong size");
     809
     810    int n = 0;
     811    for (Ivm::ItemIt it(map1, 0.0); it != INVALID; ++it) {
     812      check(map1[static_cast<Item>(it)] == 0.0, "Wrong value");
     813      ++n;
     814    }
     815    check(n == (num + 1) / 2, "Wrong number");
     816
     817    for (Ivm::ItemIt it(map1, 1.0); it != INVALID; ++it) {
     818      check(map1[static_cast<Item>(it)] == 1.0, "Wrong value");
     819      ++n;
     820    }
     821    check(n == num, "Wrong number");
     822
     823  }
     824
     825  // Graph map utilities:
     826  // mapMin(), mapMax(), mapMinValue(), mapMaxValue()
     827  // mapFind(), mapFindIf(), mapCount(), mapCountIf()
     828  // mapCopy(), mapCompare(), mapFill()
     829  {
     830    DIGRAPH_TYPEDEFS(SmartDigraph);
     831
     832    SmartDigraph g;
     833    Node n1 = g.addNode();
     834    Node n2 = g.addNode();
     835    Node n3 = g.addNode();
     836
     837    SmartDigraph::NodeMap<int> map1(g);
     838    SmartDigraph::ArcMap<char> map2(g);
     839    ConstMap<Node, A> cmap1 = A();
     840    ConstMap<Arc, C> cmap2 = C(0);
     841
     842    map1[n1] = 10;
     843    map1[n2] = 5;
     844    map1[n3] = 12;
     845
     846    // mapMin(), mapMax(), mapMinValue(), mapMaxValue()
     847    check(mapMin(g, map1) == n2, "Wrong mapMin()");
     848    check(mapMax(g, map1) == n3, "Wrong mapMax()");
     849    check(mapMin(g, map1, std::greater<int>()) == n3, "Wrong mapMin()");
     850    check(mapMax(g, map1, std::greater<int>()) == n2, "Wrong mapMax()");
     851    check(mapMinValue(g, map1) == 5, "Wrong mapMinValue()");
     852    check(mapMaxValue(g, map1) == 12, "Wrong mapMaxValue()");
     853
     854    check(mapMin(g, map2) == INVALID, "Wrong mapMin()");
     855    check(mapMax(g, map2) == INVALID, "Wrong mapMax()");
     856
     857    check(mapMin(g, cmap1) != INVALID, "Wrong mapMin()");
     858    check(mapMax(g, cmap2) == INVALID, "Wrong mapMax()");
     859
     860    Arc a1 = g.addArc(n1, n2);
     861    Arc a2 = g.addArc(n1, n3);
     862    Arc a3 = g.addArc(n2, n3);
     863    Arc a4 = g.addArc(n3, n1);
     864
     865    map2[a1] = 'b';
     866    map2[a2] = 'a';
     867    map2[a3] = 'b';
     868    map2[a4] = 'c';
     869
     870    // mapMin(), mapMax(), mapMinValue(), mapMaxValue()
     871    check(mapMin(g, map2) == a2, "Wrong mapMin()");
     872    check(mapMax(g, map2) == a4, "Wrong mapMax()");
     873    check(mapMin(g, map2, std::greater<int>()) == a4, "Wrong mapMin()");
     874    check(mapMax(g, map2, std::greater<int>()) == a2, "Wrong mapMax()");
     875    check(mapMinValue(g, map2, std::greater<int>()) == 'c',
     876          "Wrong mapMinValue()");
     877    check(mapMaxValue(g, map2, std::greater<int>()) == 'a',
     878          "Wrong mapMaxValue()");
     879
     880    check(mapMin(g, cmap1) != INVALID, "Wrong mapMin()");
     881    check(mapMax(g, cmap2) != INVALID, "Wrong mapMax()");
     882    check(mapMaxValue(g, cmap2) == C(0), "Wrong mapMaxValue()");
     883
     884    check(mapMin(g, composeMap(functorToMap(&createC), map2)) == a2,
     885          "Wrong mapMin()");
     886    check(mapMax(g, composeMap(functorToMap(&createC), map2)) == a4,
     887          "Wrong mapMax()");
     888    check(mapMinValue(g, composeMap(functorToMap(&createC), map2)) == C('a'),
     889          "Wrong mapMinValue()");
     890    check(mapMaxValue(g, composeMap(functorToMap(&createC), map2)) == C('c'),
     891          "Wrong mapMaxValue()");
     892
     893    // mapFind(), mapFindIf()
     894    check(mapFind(g, map1, 5) == n2, "Wrong mapFind()");
     895    check(mapFind(g, map1, 6) == INVALID, "Wrong mapFind()");
     896    check(mapFind(g, map2, 'a') == a2, "Wrong mapFind()");
     897    check(mapFind(g, map2, 'e') == INVALID, "Wrong mapFind()");
     898    check(mapFind(g, cmap2, C(0)) == ArcIt(g), "Wrong mapFind()");
     899    check(mapFind(g, cmap2, C(1)) == INVALID, "Wrong mapFind()");
     900
     901    check(mapFindIf(g, map1, Less<int>(7)) == n2,
     902          "Wrong mapFindIf()");
     903    check(mapFindIf(g, map1, Less<int>(5)) == INVALID,
     904          "Wrong mapFindIf()");
     905    check(mapFindIf(g, map2, Less<char>('d')) == ArcIt(g),
     906          "Wrong mapFindIf()");
     907    check(mapFindIf(g, map2, Less<char>('a')) == INVALID,
     908          "Wrong mapFindIf()");
     909
     910    // mapCount(), mapCountIf()
     911    check(mapCount(g, map1, 5) == 1, "Wrong mapCount()");
     912    check(mapCount(g, map1, 6) == 0, "Wrong mapCount()");
     913    check(mapCount(g, map2, 'a') == 1, "Wrong mapCount()");
     914    check(mapCount(g, map2, 'b') == 2, "Wrong mapCount()");
     915    check(mapCount(g, map2, 'e') == 0, "Wrong mapCount()");
     916    check(mapCount(g, cmap2, C(0)) == 4, "Wrong mapCount()");
     917    check(mapCount(g, cmap2, C(1)) == 0, "Wrong mapCount()");
     918
     919    check(mapCountIf(g, map1, Less<int>(11)) == 2,
     920          "Wrong mapCountIf()");
     921    check(mapCountIf(g, map1, Less<int>(13)) == 3,
     922          "Wrong mapCountIf()");
     923    check(mapCountIf(g, map1, Less<int>(5)) == 0,
     924          "Wrong mapCountIf()");
     925    check(mapCountIf(g, map2, Less<char>('d')) == 4,
     926          "Wrong mapCountIf()");
     927    check(mapCountIf(g, map2, Less<char>('c')) == 3,
     928          "Wrong mapCountIf()");
     929    check(mapCountIf(g, map2, Less<char>('a')) == 0,
     930          "Wrong mapCountIf()");
     931
     932    // MapIt, ConstMapIt
     933/*
     934These tests can be used after applying bugfix #330
     935    typedef SmartDigraph::NodeMap<int>::MapIt MapIt;
     936    typedef SmartDigraph::NodeMap<int>::ConstMapIt ConstMapIt;
     937    check(*std::min_element(MapIt(map1), MapIt(INVALID)) == 5,
     938          "Wrong NodeMap<>::MapIt");
     939    check(*std::max_element(ConstMapIt(map1), ConstMapIt(INVALID)) == 12,
     940          "Wrong NodeMap<>::MapIt");
     941
     942    int sum = 0;
     943    std::for_each(MapIt(map1), MapIt(INVALID), Sum<int>(sum));
     944    check(sum == 27, "Wrong NodeMap<>::MapIt");
     945    std::for_each(ConstMapIt(map1), ConstMapIt(INVALID), Sum<int>(sum));
     946    check(sum == 54, "Wrong NodeMap<>::ConstMapIt");
     947*/
     948
     949    // mapCopy(), mapCompare(), mapFill()
     950    check(mapCompare(g, map1, map1), "Wrong mapCompare()");
     951    check(mapCompare(g, cmap2, cmap2), "Wrong mapCompare()");
     952    check(mapCompare(g, map1, shiftMap(map1, 0)), "Wrong mapCompare()");
     953    check(mapCompare(g, map2, scaleMap(map2, 1)), "Wrong mapCompare()");
     954    check(!mapCompare(g, map1, shiftMap(map1, 1)), "Wrong mapCompare()");
     955
     956    SmartDigraph::NodeMap<int> map3(g, 0);
     957    SmartDigraph::ArcMap<char> map4(g, 'a');
     958
     959    check(!mapCompare(g, map1, map3), "Wrong mapCompare()");
     960    check(!mapCompare(g, map2, map4), "Wrong mapCompare()");
     961
     962    mapCopy(g, map1, map3);
     963    mapCopy(g, map2, map4);
     964
     965    check(mapCompare(g, map1, map3), "Wrong mapCompare() or mapCopy()");
     966    check(mapCompare(g, map2, map4), "Wrong mapCompare() or mapCopy()");
     967
     968    Undirector<SmartDigraph> ug(g);
     969    Undirector<SmartDigraph>::EdgeMap<char> umap1(ug, 'x');
     970    Undirector<SmartDigraph>::ArcMap<double> umap2(ug, 3.14);
     971
     972    check(!mapCompare(g, map2, umap1), "Wrong mapCompare() or mapCopy()");
     973    check(!mapCompare(g, umap1, map2), "Wrong mapCompare() or mapCopy()");
     974    check(!mapCompare(ug, map2, umap1), "Wrong mapCompare() or mapCopy()");
     975    check(!mapCompare(ug, umap1, map2), "Wrong mapCompare() or mapCopy()");
     976
     977    mapCopy(g, map2, umap1);
     978
     979    check(mapCompare(g, map2, umap1), "Wrong mapCompare() or mapCopy()");
     980    check(mapCompare(g, umap1, map2), "Wrong mapCompare() or mapCopy()");
     981    check(mapCompare(ug, map2, umap1), "Wrong mapCompare() or mapCopy()");
     982    check(mapCompare(ug, umap1, map2), "Wrong mapCompare() or mapCopy()");
     983
     984    mapCopy(g, map2, umap1);
     985    mapCopy(g, umap1, map2);
     986    mapCopy(ug, map2, umap1);
     987    mapCopy(ug, umap1, map2);
     988
     989    check(!mapCompare(ug, umap1, umap2), "Wrong mapCompare() or mapCopy()");
     990    mapCopy(ug, umap1, umap2);
     991    check(mapCompare(ug, umap1, umap2), "Wrong mapCompare() or mapCopy()");
     992
     993    check(!mapCompare(g, map1, constMap<Node>(2)), "Wrong mapCompare()");
     994    mapFill(g, map1, 2);
     995    check(mapCompare(g, constMap<Node>(2), map1), "Wrong mapFill()");
     996
     997    check(!mapCompare(g, map2, constMap<Arc>('z')), "Wrong mapCompare()");
     998    mapCopy(g, constMap<Arc>('z'), map2);
     999    check(mapCompare(g, constMap<Arc>('z'), map2), "Wrong mapCopy()");
     1000  }
     1001
    3871002  return 0;
    3881003}
  • TabularUnified test/matching_test.cc

    r641 r956  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    135135  mat_test.startDense();
    136136  mat_test.run();
    137  
     137
    138138  const_mat_test.matchingSize();
    139139  const_mat_test.matching(e);
     
    144144  const_mat_test.mate(n);
    145145
    146   MaxMatching<Graph>::Status stat = 
     146  MaxMatching<Graph>::Status stat =
    147147    const_mat_test.status(n);
    148148  const MaxMatching<Graph>::StatusMap& smap =
     
    171171  mat_test.start();
    172172  mat_test.run();
    173  
     173
    174174  const_mat_test.matchingWeight();
    175175  const_mat_test.matchingSize();
     
    180180  e = mmap[n];
    181181  const_mat_test.mate(n);
    182  
     182
    183183  int k = 0;
    184184  const_mat_test.dualValue();
     
    208208  mat_test.start();
    209209  mat_test.run();
    210  
     210
    211211  const_mat_test.matchingWeight();
    212212  const_mat_test.matching(e);
     
    216216  e = mmap[n];
    217217  const_mat_test.mate(n);
    218  
     218
    219219  int k = 0;
    220220  const_mat_test.dualValue();
     
    402402      edgeMap("weight", weight).run();
    403403
    404     MaxMatching<SmartGraph> mm(graph);
    405     mm.run();
    406     checkMatching(graph, mm);
    407 
    408     MaxWeightedMatching<SmartGraph> mwm(graph, weight);
    409     mwm.run();
    410     checkWeightedMatching(graph, weight, mwm);
    411 
    412     MaxWeightedPerfectMatching<SmartGraph> mwpm(graph, weight);
    413     bool perfect = mwpm.run();
    414 
    415     check(perfect == (mm.matchingSize() * 2 == countNodes(graph)),
    416           "Perfect matching found");
    417 
    418     if (perfect) {
    419       checkWeightedPerfectMatching(graph, weight, mwpm);
     404    bool perfect;
     405    {
     406      MaxMatching<SmartGraph> mm(graph);
     407      mm.run();
     408      checkMatching(graph, mm);
     409      perfect = 2 * mm.matchingSize() == countNodes(graph);
     410    }
     411
     412    {
     413      MaxWeightedMatching<SmartGraph> mwm(graph, weight);
     414      mwm.run();
     415      checkWeightedMatching(graph, weight, mwm);
     416    }
     417
     418    {
     419      MaxWeightedMatching<SmartGraph> mwm(graph, weight);
     420      mwm.init();
     421      mwm.start();
     422      checkWeightedMatching(graph, weight, mwm);
     423    }
     424
     425    {
     426      MaxWeightedPerfectMatching<SmartGraph> mwpm(graph, weight);
     427      bool result = mwpm.run();
     428
     429      check(result == perfect, "Perfect matching found");
     430      if (perfect) {
     431        checkWeightedPerfectMatching(graph, weight, mwpm);
     432      }
     433    }
     434
     435    {
     436      MaxWeightedPerfectMatching<SmartGraph> mwpm(graph, weight);
     437      mwpm.init();
     438      bool result = mwpm.start();
     439
     440      check(result == perfect, "Perfect matching found");
     441      if (perfect) {
     442        checkWeightedPerfectMatching(graph, weight, mwpm);
     443      }
    420444    }
    421445  }
  • TabularUnified test/min_cost_arborescence_test.cc

    r672 r956  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2008
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    111111  b = const_mcarb_test.emptyQueue();
    112112  i = const_mcarb_test.queueSize();
    113  
     113
    114114  c = const_mcarb_test.arborescenceCost();
    115115  b = const_mcarb_test.arborescence(e);
     
    121121  b = const_mcarb_test.reached(n);
    122122  b = const_mcarb_test.processed(n);
    123  
     123
    124124  i = const_mcarb_test.dualNum();
    125125  c = const_mcarb_test.dualValue();
    126126  i = const_mcarb_test.dualSize(i);
    127127  c = const_mcarb_test.dualValue(i);
    128  
     128
    129129  ignore_unused_variable_warning(am);
    130130  ignore_unused_variable_warning(pm);
  • TabularUnified test/min_cost_flow_test.cc

    r716 r956  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    2525
    2626#include <lemon/network_simplex.h>
     27#include <lemon/capacity_scaling.h>
     28#include <lemon/cost_scaling.h>
     29#include <lemon/cycle_canceling.h>
    2730
    2831#include <lemon/concepts/digraph.h>
     32#include <lemon/concepts/heap.h>
    2933#include <lemon/concept_check.h>
    3034
     
    3337using namespace lemon;
    3438
     39// Test networks
    3540char test_lgf[] =
    3641  "@nodes\n"
     
    4853  "   11     0    0    0    0  -10    0\n"
    4954  "   12   -20  -27    0  -30  -30  -20\n"
    50   "\n"               
     55  "\n"
    5156  "@arcs\n"
    5257  "       cost  cap low1 low2 low3\n"
     
    7782  "target 12\n";
    7883
     84char test_neg1_lgf[] =
     85  "@nodes\n"
     86  "label   sup\n"
     87  "    1   100\n"
     88  "    2     0\n"
     89  "    3     0\n"
     90  "    4  -100\n"
     91  "    5     0\n"
     92  "    6     0\n"
     93  "    7     0\n"
     94  "@arcs\n"
     95  "      cost   low1   low2\n"
     96  "1 2    100      0      0\n"
     97  "1 3     30      0      0\n"
     98  "2 4     20      0      0\n"
     99  "3 4     80      0      0\n"
     100  "3 2     50      0      0\n"
     101  "5 3     10      0      0\n"
     102  "5 6     80      0   1000\n"
     103  "6 7     30      0  -1000\n"
     104  "7 5   -120      0      0\n";
     105
     106char test_neg2_lgf[] =
     107  "@nodes\n"
     108  "label   sup\n"
     109  "    1   100\n"
     110  "    2  -300\n"
     111  "@arcs\n"
     112  "      cost\n"
     113  "1 2     -1\n";
     114
     115
     116// Test data
     117typedef ListDigraph Digraph;
     118DIGRAPH_TYPEDEFS(ListDigraph);
     119
     120Digraph gr;
     121Digraph::ArcMap<int> c(gr), l1(gr), l2(gr), l3(gr), u(gr);
     122Digraph::NodeMap<int> s1(gr), s2(gr), s3(gr), s4(gr), s5(gr), s6(gr);
     123ConstMap<Arc, int> cc(1), cu(std::numeric_limits<int>::max());
     124Node v, w;
     125
     126Digraph neg1_gr;
     127Digraph::ArcMap<int> neg1_c(neg1_gr), neg1_l1(neg1_gr), neg1_l2(neg1_gr);
     128ConstMap<Arc, int> neg1_u1(std::numeric_limits<int>::max()), neg1_u2(5000);
     129Digraph::NodeMap<int> neg1_s(neg1_gr);
     130
     131Digraph neg2_gr;
     132Digraph::ArcMap<int> neg2_c(neg2_gr);
     133ConstMap<Arc, int> neg2_l(0), neg2_u(1000);
     134Digraph::NodeMap<int> neg2_s(neg2_gr);
     135
    79136
    80137enum SupplyType {
     
    84141};
    85142
     143
    86144// Check the interface of an MCF algorithm
    87145template <typename GR, typename Value, typename Cost>
     
    94152    void constraints() {
    95153      checkConcept<concepts::Digraph, GR>();
    96      
     154
    97155      const Constraints& me = *this;
    98156
     
    100158      const MCF& const_mcf = mcf;
    101159
    102       b = mcf.reset()
     160      b = mcf.reset().resetParams()
    103161             .lowerMap(me.lower)
    104162             .upperMap(me.upper)
     
    123181    typedef concepts::WriteMap<Arc, Value> FlowMap;
    124182    typedef concepts::WriteMap<Node, Cost> PotMap;
    125  
     183
    126184    GR g;
    127185    VAM lower;
     
    177235           typename CM, typename SM, typename FM, typename PM >
    178236bool checkPotential( const GR& gr, const LM& lower, const UM& upper,
    179                      const CM& cost, const SM& supply, const FM& flow, 
     237                     const CM& cost, const SM& supply, const FM& flow,
    180238                     const PM& pi, SupplyType type )
    181239{
     
    190248          (red_cost < 0 && flow[e] == upper[e]);
    191249  }
    192  
     250
    193251  for (NodeIt n(gr); opt && n != INVALID; ++n) {
    194252    typename SM::Value sum = 0;
     
    203261    }
    204262  }
    205  
     263
    206264  return opt;
    207265}
     
    228286    }
    229287  }
    230  
     288
    231289  for (NodeIt n(gr); n != INVALID; ++n) {
    232290    dual_cost -= red_supply[n] * pi[n];
     
    237295    dual_cost -= (upper[a] - lower[a]) * std::max(-red_cost, 0);
    238296  }
    239  
     297
    240298  return dual_cost == total;
    241299}
     
    269327}
    270328
     329template < typename MCF, typename Param >
     330void runMcfGeqTests( Param param,
     331                     const std::string &test_str = "",
     332                     bool full_neg_cost_support = false )
     333{
     334  MCF mcf1(gr), mcf2(neg1_gr), mcf3(neg2_gr);
     335
     336  // Basic tests
     337  mcf1.upperMap(u).costMap(c).supplyMap(s1);
     338  checkMcf(mcf1, mcf1.run(param), gr, l1, u, c, s1,
     339           mcf1.OPTIMAL, true,     5240, test_str + "-1");
     340  mcf1.stSupply(v, w, 27);
     341  checkMcf(mcf1, mcf1.run(param), gr, l1, u, c, s2,
     342           mcf1.OPTIMAL, true,     7620, test_str + "-2");
     343  mcf1.lowerMap(l2).supplyMap(s1);
     344  checkMcf(mcf1, mcf1.run(param), gr, l2, u, c, s1,
     345           mcf1.OPTIMAL, true,     5970, test_str + "-3");
     346  mcf1.stSupply(v, w, 27);
     347  checkMcf(mcf1, mcf1.run(param), gr, l2, u, c, s2,
     348           mcf1.OPTIMAL, true,     8010, test_str + "-4");
     349  mcf1.resetParams().supplyMap(s1);
     350  checkMcf(mcf1, mcf1.run(param), gr, l1, cu, cc, s1,
     351           mcf1.OPTIMAL, true,       74, test_str + "-5");
     352  mcf1.lowerMap(l2).stSupply(v, w, 27);
     353  checkMcf(mcf1, mcf1.run(param), gr, l2, cu, cc, s2,
     354           mcf1.OPTIMAL, true,       94, test_str + "-6");
     355  mcf1.reset();
     356  checkMcf(mcf1, mcf1.run(param), gr, l1, cu, cc, s3,
     357           mcf1.OPTIMAL, true,        0, test_str + "-7");
     358  mcf1.lowerMap(l2).upperMap(u);
     359  checkMcf(mcf1, mcf1.run(param), gr, l2, u, cc, s3,
     360           mcf1.INFEASIBLE, false,    0, test_str + "-8");
     361  mcf1.lowerMap(l3).upperMap(u).costMap(c).supplyMap(s4);
     362  checkMcf(mcf1, mcf1.run(param), gr, l3, u, c, s4,
     363           mcf1.OPTIMAL, true,     6360, test_str + "-9");
     364
     365  // Tests for the GEQ form
     366  mcf1.resetParams().upperMap(u).costMap(c).supplyMap(s5);
     367  checkMcf(mcf1, mcf1.run(param), gr, l1, u, c, s5,
     368           mcf1.OPTIMAL, true,     3530, test_str + "-10", GEQ);
     369  mcf1.lowerMap(l2);
     370  checkMcf(mcf1, mcf1.run(param), gr, l2, u, c, s5,
     371           mcf1.OPTIMAL, true,     4540, test_str + "-11", GEQ);
     372  mcf1.supplyMap(s6);
     373  checkMcf(mcf1, mcf1.run(param), gr, l2, u, c, s6,
     374           mcf1.INFEASIBLE, false,    0, test_str + "-12", GEQ);
     375
     376  // Tests with negative costs
     377  mcf2.lowerMap(neg1_l1).costMap(neg1_c).supplyMap(neg1_s);
     378  checkMcf(mcf2, mcf2.run(param), neg1_gr, neg1_l1, neg1_u1, neg1_c, neg1_s,
     379           mcf2.UNBOUNDED, false,     0, test_str + "-13");
     380  mcf2.upperMap(neg1_u2);
     381  checkMcf(mcf2, mcf2.run(param), neg1_gr, neg1_l1, neg1_u2, neg1_c, neg1_s,
     382           mcf2.OPTIMAL, true,   -40000, test_str + "-14");
     383  mcf2.resetParams().lowerMap(neg1_l2).costMap(neg1_c).supplyMap(neg1_s);
     384  checkMcf(mcf2, mcf2.run(param), neg1_gr, neg1_l2, neg1_u1, neg1_c, neg1_s,
     385           mcf2.UNBOUNDED, false,     0, test_str + "-15");
     386
     387  mcf3.costMap(neg2_c).supplyMap(neg2_s);
     388  if (full_neg_cost_support) {
     389    checkMcf(mcf3, mcf3.run(param), neg2_gr, neg2_l, neg2_u, neg2_c, neg2_s,
     390             mcf3.OPTIMAL, true,   -300, test_str + "-16", GEQ);
     391  } else {
     392    checkMcf(mcf3, mcf3.run(param), neg2_gr, neg2_l, neg2_u, neg2_c, neg2_s,
     393             mcf3.UNBOUNDED, false,   0, test_str + "-17", GEQ);
     394  }
     395  mcf3.upperMap(neg2_u);
     396  checkMcf(mcf3, mcf3.run(param), neg2_gr, neg2_l, neg2_u, neg2_c, neg2_s,
     397           mcf3.OPTIMAL, true,     -300, test_str + "-18", GEQ);
     398}
     399
     400template < typename MCF, typename Param >
     401void runMcfLeqTests( Param param,
     402                     const std::string &test_str = "" )
     403{
     404  // Tests for the LEQ form
     405  MCF mcf1(gr);
     406  mcf1.supplyType(mcf1.LEQ);
     407  mcf1.upperMap(u).costMap(c).supplyMap(s6);
     408  checkMcf(mcf1, mcf1.run(param), gr, l1, u, c, s6,
     409           mcf1.OPTIMAL, true,   5080, test_str + "-19", LEQ);
     410  mcf1.lowerMap(l2);
     411  checkMcf(mcf1, mcf1.run(param), gr, l2, u, c, s6,
     412           mcf1.OPTIMAL, true,   5930, test_str + "-20", LEQ);
     413  mcf1.supplyMap(s5);
     414  checkMcf(mcf1, mcf1.run(param), gr, l2, u, c, s5,
     415           mcf1.INFEASIBLE, false,  0, test_str + "-21", LEQ);
     416}
     417
     418
    271419int main()
    272420{
    273   // Check the interfaces
    274   {
    275     typedef concepts::Digraph GR;
    276     checkConcept< McfClassConcept<GR, int, int>,
    277                   NetworkSimplex<GR> >();
    278     checkConcept< McfClassConcept<GR, double, double>,
    279                   NetworkSimplex<GR, double> >();
    280     checkConcept< McfClassConcept<GR, int, double>,
    281                   NetworkSimplex<GR, int, double> >();
    282   }
    283 
    284   // Run various MCF tests
    285   typedef ListDigraph Digraph;
    286   DIGRAPH_TYPEDEFS(ListDigraph);
    287 
    288   // Read the test digraph
    289   Digraph gr;
    290   Digraph::ArcMap<int> c(gr), l1(gr), l2(gr), l3(gr), u(gr);
    291   Digraph::NodeMap<int> s1(gr), s2(gr), s3(gr), s4(gr), s5(gr), s6(gr);
    292   ConstMap<Arc, int> cc(1), cu(std::numeric_limits<int>::max());
    293   Node v, w;
    294 
     421  // Read the test networks
    295422  std::istringstream input(test_lgf);
    296423  DigraphReader<Digraph>(gr, input)
     
    309436    .node("target", w)
    310437    .run();
    311  
    312   // Build test digraphs with negative costs
    313   Digraph neg_gr;
    314   Node n1 = neg_gr.addNode();
    315   Node n2 = neg_gr.addNode();
    316   Node n3 = neg_gr.addNode();
    317   Node n4 = neg_gr.addNode();
    318   Node n5 = neg_gr.addNode();
    319   Node n6 = neg_gr.addNode();
    320   Node n7 = neg_gr.addNode();
    321  
    322   Arc a1 = neg_gr.addArc(n1, n2);
    323   Arc a2 = neg_gr.addArc(n1, n3);
    324   Arc a3 = neg_gr.addArc(n2, n4);
    325   Arc a4 = neg_gr.addArc(n3, n4);
    326   Arc a5 = neg_gr.addArc(n3, n2);
    327   Arc a6 = neg_gr.addArc(n5, n3);
    328   Arc a7 = neg_gr.addArc(n5, n6);
    329   Arc a8 = neg_gr.addArc(n6, n7);
    330   Arc a9 = neg_gr.addArc(n7, n5);
    331  
    332   Digraph::ArcMap<int> neg_c(neg_gr), neg_l1(neg_gr, 0), neg_l2(neg_gr, 0);
    333   ConstMap<Arc, int> neg_u1(std::numeric_limits<int>::max()), neg_u2(5000);
    334   Digraph::NodeMap<int> neg_s(neg_gr, 0);
    335  
    336   neg_l2[a7] =  1000;
    337   neg_l2[a8] = -1000;
    338  
    339   neg_s[n1] =  100;
    340   neg_s[n4] = -100;
    341  
    342   neg_c[a1] =  100;
    343   neg_c[a2] =   30;
    344   neg_c[a3] =   20;
    345   neg_c[a4] =   80;
    346   neg_c[a5] =   50;
    347   neg_c[a6] =   10;
    348   neg_c[a7] =   80;
    349   neg_c[a8] =   30;
    350   neg_c[a9] = -120;
    351 
    352   Digraph negs_gr;
    353   Digraph::NodeMap<int> negs_s(negs_gr);
    354   Digraph::ArcMap<int> negs_c(negs_gr);
    355   ConstMap<Arc, int> negs_l(0), negs_u(1000);
    356   n1 = negs_gr.addNode();
    357   n2 = negs_gr.addNode();
    358   negs_s[n1] = 100;
    359   negs_s[n2] = -300;
    360   negs_c[negs_gr.addArc(n1, n2)] = -1;
    361 
    362 
    363   // A. Test NetworkSimplex with the default pivot rule
    364   {
    365     NetworkSimplex<Digraph> mcf(gr);
    366 
    367     // Check the equality form
    368     mcf.upperMap(u).costMap(c);
    369     checkMcf(mcf, mcf.supplyMap(s1).run(),
    370              gr, l1, u, c, s1, mcf.OPTIMAL, true,   5240, "#A1");
    371     checkMcf(mcf, mcf.stSupply(v, w, 27).run(),
    372              gr, l1, u, c, s2, mcf.OPTIMAL, true,   7620, "#A2");
    373     mcf.lowerMap(l2);
    374     checkMcf(mcf, mcf.supplyMap(s1).run(),
    375              gr, l2, u, c, s1, mcf.OPTIMAL, true,   5970, "#A3");
    376     checkMcf(mcf, mcf.stSupply(v, w, 27).run(),
    377              gr, l2, u, c, s2, mcf.OPTIMAL, true,   8010, "#A4");
    378     mcf.reset();
    379     checkMcf(mcf, mcf.supplyMap(s1).run(),
    380              gr, l1, cu, cc, s1, mcf.OPTIMAL, true,   74, "#A5");
    381     checkMcf(mcf, mcf.lowerMap(l2).stSupply(v, w, 27).run(),
    382              gr, l2, cu, cc, s2, mcf.OPTIMAL, true,   94, "#A6");
    383     mcf.reset();
    384     checkMcf(mcf, mcf.run(),
    385              gr, l1, cu, cc, s3, mcf.OPTIMAL, true,    0, "#A7");
    386     checkMcf(mcf, mcf.lowerMap(l2).upperMap(u).run(),
    387              gr, l2, u, cc, s3, mcf.INFEASIBLE, false, 0, "#A8");
    388     mcf.reset().lowerMap(l3).upperMap(u).costMap(c).supplyMap(s4);
    389     checkMcf(mcf, mcf.run(),
    390              gr, l3, u, c, s4, mcf.OPTIMAL, true,   6360, "#A9");
    391 
    392     // Check the GEQ form
    393     mcf.reset().upperMap(u).costMap(c).supplyMap(s5);
    394     checkMcf(mcf, mcf.run(),
    395              gr, l1, u, c, s5, mcf.OPTIMAL, true,   3530, "#A10", GEQ);
    396     mcf.supplyType(mcf.GEQ);
    397     checkMcf(mcf, mcf.lowerMap(l2).run(),
    398              gr, l2, u, c, s5, mcf.OPTIMAL, true,   4540, "#A11", GEQ);
    399     mcf.supplyMap(s6);
    400     checkMcf(mcf, mcf.run(),
    401              gr, l2, u, c, s6, mcf.INFEASIBLE, false,  0, "#A12", GEQ);
    402 
    403     // Check the LEQ form
    404     mcf.reset().supplyType(mcf.LEQ);
    405     mcf.upperMap(u).costMap(c).supplyMap(s6);
    406     checkMcf(mcf, mcf.run(),
    407              gr, l1, u, c, s6, mcf.OPTIMAL, true,   5080, "#A13", LEQ);
    408     checkMcf(mcf, mcf.lowerMap(l2).run(),
    409              gr, l2, u, c, s6, mcf.OPTIMAL, true,   5930, "#A14", LEQ);
    410     mcf.supplyMap(s5);
    411     checkMcf(mcf, mcf.run(),
    412              gr, l2, u, c, s5, mcf.INFEASIBLE, false,  0, "#A15", LEQ);
    413 
    414     // Check negative costs
    415     NetworkSimplex<Digraph> neg_mcf(neg_gr);
    416     neg_mcf.lowerMap(neg_l1).costMap(neg_c).supplyMap(neg_s);
    417     checkMcf(neg_mcf, neg_mcf.run(), neg_gr, neg_l1, neg_u1,
    418       neg_c, neg_s, neg_mcf.UNBOUNDED, false,    0, "#A16");
    419     neg_mcf.upperMap(neg_u2);
    420     checkMcf(neg_mcf, neg_mcf.run(), neg_gr, neg_l1, neg_u2,
    421       neg_c, neg_s, neg_mcf.OPTIMAL, true,  -40000, "#A17");
    422     neg_mcf.reset().lowerMap(neg_l2).costMap(neg_c).supplyMap(neg_s);
    423     checkMcf(neg_mcf, neg_mcf.run(), neg_gr, neg_l2, neg_u1,
    424       neg_c, neg_s, neg_mcf.UNBOUNDED, false,    0, "#A18");
    425      
    426     NetworkSimplex<Digraph> negs_mcf(negs_gr);
    427     negs_mcf.costMap(negs_c).supplyMap(negs_s);
    428     checkMcf(negs_mcf, negs_mcf.run(), negs_gr, negs_l, negs_u,
    429       negs_c, negs_s, negs_mcf.OPTIMAL, true, -300, "#A19", GEQ);
    430   }
    431 
    432   // B. Test NetworkSimplex with each pivot rule
    433   {
    434     NetworkSimplex<Digraph> mcf(gr);
    435     mcf.supplyMap(s1).costMap(c).upperMap(u).lowerMap(l2);
    436 
    437     checkMcf(mcf, mcf.run(NetworkSimplex<Digraph>::FIRST_ELIGIBLE),
    438              gr, l2, u, c, s1, mcf.OPTIMAL, true,   5970, "#B1");
    439     checkMcf(mcf, mcf.run(NetworkSimplex<Digraph>::BEST_ELIGIBLE),
    440              gr, l2, u, c, s1, mcf.OPTIMAL, true,   5970, "#B2");
    441     checkMcf(mcf, mcf.run(NetworkSimplex<Digraph>::BLOCK_SEARCH),
    442              gr, l2, u, c, s1, mcf.OPTIMAL, true,   5970, "#B3");
    443     checkMcf(mcf, mcf.run(NetworkSimplex<Digraph>::CANDIDATE_LIST),
    444              gr, l2, u, c, s1, mcf.OPTIMAL, true,   5970, "#B4");
    445     checkMcf(mcf, mcf.run(NetworkSimplex<Digraph>::ALTERING_LIST),
    446              gr, l2, u, c, s1, mcf.OPTIMAL, true,   5970, "#B5");
     438
     439  std::istringstream neg_inp1(test_neg1_lgf);
     440  DigraphReader<Digraph>(neg1_gr, neg_inp1)
     441    .arcMap("cost", neg1_c)
     442    .arcMap("low1", neg1_l1)
     443    .arcMap("low2", neg1_l2)
     444    .nodeMap("sup", neg1_s)
     445    .run();
     446
     447  std::istringstream neg_inp2(test_neg2_lgf);
     448  DigraphReader<Digraph>(neg2_gr, neg_inp2)
     449    .arcMap("cost", neg2_c)
     450    .nodeMap("sup", neg2_s)
     451    .run();
     452
     453  // Check the interface of NetworkSimplex
     454  {
     455    typedef concepts::Digraph GR;
     456    checkConcept< McfClassConcept<GR, int, int>,
     457                  NetworkSimplex<GR> >();
     458    checkConcept< McfClassConcept<GR, double, double>,
     459                  NetworkSimplex<GR, double> >();
     460    checkConcept< McfClassConcept<GR, int, double>,
     461                  NetworkSimplex<GR, int, double> >();
     462  }
     463
     464  // Check the interface of CapacityScaling
     465  {
     466    typedef concepts::Digraph GR;
     467    checkConcept< McfClassConcept<GR, int, int>,
     468                  CapacityScaling<GR> >();
     469    checkConcept< McfClassConcept<GR, double, double>,
     470                  CapacityScaling<GR, double> >();
     471    checkConcept< McfClassConcept<GR, int, double>,
     472                  CapacityScaling<GR, int, double> >();
     473    typedef CapacityScaling<GR>::
     474      SetHeap<concepts::Heap<int, RangeMap<int> > >::Create CAS;
     475    checkConcept< McfClassConcept<GR, int, int>, CAS >();
     476  }
     477
     478  // Check the interface of CostScaling
     479  {
     480    typedef concepts::Digraph GR;
     481    checkConcept< McfClassConcept<GR, int, int>,
     482                  CostScaling<GR> >();
     483    checkConcept< McfClassConcept<GR, double, double>,
     484                  CostScaling<GR, double> >();
     485    checkConcept< McfClassConcept<GR, int, double>,
     486                  CostScaling<GR, int, double> >();
     487    typedef CostScaling<GR>::
     488      SetLargeCost<double>::Create COS;
     489    checkConcept< McfClassConcept<GR, int, int>, COS >();
     490  }
     491
     492  // Check the interface of CycleCanceling
     493  {
     494    typedef concepts::Digraph GR;
     495    checkConcept< McfClassConcept<GR, int, int>,
     496                  CycleCanceling<GR> >();
     497    checkConcept< McfClassConcept<GR, double, double>,
     498                  CycleCanceling<GR, double> >();
     499    checkConcept< McfClassConcept<GR, int, double>,
     500                  CycleCanceling<GR, int, double> >();
     501  }
     502
     503  // Test NetworkSimplex
     504  {
     505    typedef NetworkSimplex<Digraph> MCF;
     506    runMcfGeqTests<MCF>(MCF::FIRST_ELIGIBLE, "NS-FE", true);
     507    runMcfLeqTests<MCF>(MCF::FIRST_ELIGIBLE, "NS-FE");
     508    runMcfGeqTests<MCF>(MCF::BEST_ELIGIBLE,  "NS-BE", true);
     509    runMcfLeqTests<MCF>(MCF::BEST_ELIGIBLE,  "NS-BE");
     510    runMcfGeqTests<MCF>(MCF::BLOCK_SEARCH,   "NS-BS", true);
     511    runMcfLeqTests<MCF>(MCF::BLOCK_SEARCH,   "NS-BS");
     512    runMcfGeqTests<MCF>(MCF::CANDIDATE_LIST, "NS-CL", true);
     513    runMcfLeqTests<MCF>(MCF::CANDIDATE_LIST, "NS-CL");
     514    runMcfGeqTests<MCF>(MCF::ALTERING_LIST,  "NS-AL", true);
     515    runMcfLeqTests<MCF>(MCF::ALTERING_LIST,  "NS-AL");
     516  }
     517
     518  // Test CapacityScaling
     519  {
     520    typedef CapacityScaling<Digraph> MCF;
     521    runMcfGeqTests<MCF>(0, "SSP");
     522    runMcfGeqTests<MCF>(2, "CAS");
     523  }
     524
     525  // Test CostScaling
     526  {
     527    typedef CostScaling<Digraph> MCF;
     528    runMcfGeqTests<MCF>(MCF::PUSH, "COS-PR");
     529    runMcfGeqTests<MCF>(MCF::AUGMENT, "COS-AR");
     530    runMcfGeqTests<MCF>(MCF::PARTIAL_AUGMENT, "COS-PAR");
     531  }
     532
     533  // Test CycleCanceling
     534  {
     535    typedef CycleCanceling<Digraph> MCF;
     536    runMcfGeqTests<MCF>(MCF::SIMPLE_CYCLE_CANCELING, "SCC");
     537    runMcfGeqTests<MCF>(MCF::MINIMUM_MEAN_CYCLE_CANCELING, "MMCC");
     538    runMcfGeqTests<MCF>(MCF::CANCEL_AND_TIGHTEN, "CAT");
    447539  }
    448540
  • TabularUnified test/preflow_test.cc

    r1027 r1084  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2011
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    9696  const PreflowType& const_preflow_test = preflow_test;
    9797
     98  const PreflowType::Elevator& elev = const_preflow_test.elevator();
     99  preflow_test.elevator(const_cast<PreflowType::Elevator&>(elev));
     100  PreflowType::Tolerance tol = const_preflow_test.tolerance();
     101  preflow_test.tolerance(tol);
     102
    98103  preflow_test
    99104    .capacityMap(cap)
     
    114119  b = const_preflow_test.minCut(n);
    115120  const_preflow_test.minCutMap(cut);
    116  
     121
    117122  ignore_unused_variable_warning(fm);
    118123}
     
    155160{
    156161  DIGRAPH_TYPEDEFS(SmartDigraph);
    157  
     162
    158163  SmartDigraph g;
    159164  SmartDigraph::ArcMap<int> cap(g),iflow(g);
     
    267272
    268273  initFlowTest();
    269  
     274
    270275  return 0;
    271276}
  • TabularUnified test/suurballe_test.cc

    r670 r956  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    2424#include <lemon/suurballe.h>
    2525#include <lemon/concepts/digraph.h>
     26#include <lemon/concepts/heap.h>
    2627
    2728#include "test_tools.h"
     
    8182  typedef Digraph::Arc Arc;
    8283  typedef concepts::ReadMap<Arc, VType> LengthMap;
    83  
    84   typedef Suurballe<Digraph, LengthMap> SuurballeType;
     84
     85  typedef Suurballe<Digraph, LengthMap> ST;
     86  typedef Suurballe<Digraph, LengthMap>
     87    ::SetFlowMap<ST::FlowMap>
     88    ::SetPotentialMap<ST::PotentialMap>
     89    ::SetPath<SimplePath<Digraph> >
     90    ::SetHeap<concepts::Heap<VType, Digraph::NodeMap<int> > >
     91    ::Create SuurballeType;
    8592
    8693  Digraph g;
     
    102109  k = suurb_test.run(n, n, k);
    103110  suurb_test.init(n);
     111  suurb_test.fullInit(n);
     112  suurb_test.start(n);
     113  suurb_test.start(n, k);
    104114  k = suurb_test.findFlow(n);
    105115  k = suurb_test.findFlow(n, k);
    106116  suurb_test.findPaths();
    107  
     117
    108118  int f;
    109119  VType c;
     
    117127  k = const_suurb_test.pathNum();
    118128  Path<Digraph> p = const_suurb_test.path(k);
    119  
     129
    120130  ignore_unused_variable_warning(fm);
    121131  ignore_unused_variable_warning(pm);
     
    196206    run();
    197207
    198   // Find 2 paths
     208  // Check run()
    199209  {
    200210    Suurballe<ListDigraph> suurballe(digraph, length);
     211
     212    // Find 2 paths
    201213    check(suurballe.run(s, t) == 2, "Wrong number of paths");
    202214    check(checkFlow(digraph, suurballe.flowMap(), s, t, 2),
     
    208220    for (int i = 0; i < suurballe.pathNum(); ++i)
    209221      check(checkPath(digraph, suurballe.path(i), s, t), "Wrong path");
    210   }
    211 
    212   // Find 3 paths
    213   {
    214     Suurballe<ListDigraph> suurballe(digraph, length);
     222
     223    // Find 3 paths
    215224    check(suurballe.run(s, t, 3) == 3, "Wrong number of paths");
    216225    check(checkFlow(digraph, suurballe.flowMap(), s, t, 3),
     
    222231    for (int i = 0; i < suurballe.pathNum(); ++i)
    223232      check(checkPath(digraph, suurballe.path(i), s, t), "Wrong path");
    224   }
    225 
    226   // Find 5 paths (only 3 can be found)
    227   {
    228     Suurballe<ListDigraph> suurballe(digraph, length);
     233
     234    // Find 5 paths (only 3 can be found)
    229235    check(suurballe.run(s, t, 5) == 3, "Wrong number of paths");
    230236    check(checkFlow(digraph, suurballe.flowMap(), s, t, 3),
     
    238244  }
    239245
     246  // Check fullInit() + start()
     247  {
     248    Suurballe<ListDigraph> suurballe(digraph, length);
     249    suurballe.fullInit(s);
     250
     251    // Find 2 paths
     252    check(suurballe.start(t) == 2, "Wrong number of paths");
     253    check(suurballe.totalLength() == 510, "The flow is not optimal");
     254
     255    // Find 3 paths
     256    check(suurballe.start(t, 3) == 3, "Wrong number of paths");
     257    check(suurballe.totalLength() == 1040, "The flow is not optimal");
     258
     259    // Find 5 paths (only 3 can be found)
     260    check(suurballe.start(t, 5) == 3, "Wrong number of paths");
     261    check(suurballe.totalLength() == 1040, "The flow is not optimal");
     262  }
     263
    240264  return 0;
    241265}
  • TabularUnified test/test_tools.h

    r463 r956  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    3838///print something like this (and then exits).
    3939///\verbatim file_name.cc:123: error: This is obviously false. \endverbatim
    40 #define check(rc, msg) \
    41   if(!(rc)) { \
    42     std::cerr << __FILE__ ":" << __LINE__ << ": error: " << msg << std::endl; \
    43     abort(); \
    44   } else { } \
     40#define check(rc, msg)                                                  \
     41  {                                                                     \
     42    if(!(rc)) {                                                         \
     43      std::cerr << __FILE__ ":" << __LINE__ << ": error: "              \
     44                << msg << std::endl;                                    \
     45      abort();                                                          \
     46    } else { }                                                          \
     47  }                                                                     \
     48
    4549
    4650#endif
  • TabularUnified tools/dimacs-solver.cc

    r691 r956  
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2009
     5 * Copyright (C) 2003-2010
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     
    8989  pre.run();
    9090  if(report) std::cerr << "Run Preflow: " << ti << '\n';
    91   if(report) std::cerr << "\nMax flow value: " << pre.flowValue() << '\n'; 
    92 }
    93 
    94 template<class Value>
     91  if(report) std::cerr << "\nMax flow value: " << pre.flowValue() << '\n';
     92}
     93
     94template<class Value, class LargeValue>
    9595void solve_min(ArgParser &ap, std::istream &is, std::ostream &,
    9696               Value infty, DimacsDescriptor &desc)
     
    128128    std::cerr << "Run NetworkSimplex: " << ti << "\n\n";
    129129    std::cerr << "Feasible flow: " << (res ? "found" : "not found") << '\n';
    130     if (res) std::cerr << "Min flow cost: " << ns.totalCost() << '\n';
     130    if (res) std::cerr << "Min flow cost: "
     131                       << ns.template totalCost<LargeValue>() << '\n';
    131132  }
    132133}
     
    148149  if(report) std::cerr << "Run MaxMatching: " << ti << '\n';
    149150  if(report) std::cerr << "\nCardinality of max matching: "
    150                        << mat.matchingSize() << '\n'; 
    151 }
    152 
    153 
    154 template<class Value>
     151                       << mat.matchingSize() << '\n';
     152}
     153
     154
     155template<class Value, class LargeValue>
    155156void solve(ArgParser &ap, std::istream &is, std::ostream &os,
    156157           DimacsDescriptor &desc)
     
    166167      exit(1);
    167168    }
    168  
     169
    169170  switch(desc.type)
    170171    {
    171172    case DimacsDescriptor::MIN:
    172       solve_min<Value>(ap,is,os,infty,desc);
     173      solve_min<Value, LargeValue>(ap,is,os,infty,desc);
    173174      break;
    174175    case DimacsDescriptor::MAX:
     
    238239
    239240  DimacsDescriptor desc = dimacsType(is);
    240  
     241
    241242  if(!ap.given("q"))
    242243    {
     
    263264      std::cout << "\n\n";
    264265    }
    265    
     266
    266267  if(ap.given("double"))
    267     solve<double>(ap,is,os,desc);
     268    solve<double, double>(ap,is,os,desc);
    268269  else if(ap.given("ldouble"))
    269     solve<long double>(ap,is,os,desc);
     270    solve<long double, long double>(ap,is,os,desc);
    270271#ifdef LEMON_HAVE_LONG_LONG
    271272  else if(ap.given("long"))
    272     solve<long long>(ap,is,os,desc);
     273    solve<long long, long long>(ap,is,os,desc);
     274  else solve<int, long long>(ap,is,os,desc);
     275#else
     276  else solve<int, long>(ap,is,os,desc);
    273277#endif
    274   else solve<int>(ap,is,os,desc);
    275278
    276279  return 0;
  • TabularUnified tools/lemon-0.x-to-1.x.sh

    r621 r738  
    3636        -e "s/Edge\>/_Ar_c_label_/g"\
    3737        -e "s/\<edge\>/_ar_c_label_/g"\
    38         -e "s/_edge\>/_ar_c_label_/g"\
     38        -e "s/_edge\>/__ar_c_label_/g"\
    3939        -e "s/Edges\>/_Ar_c_label_s/g"\
    4040        -e "s/\<edges\>/_ar_c_label_s/g"\
    41         -e "s/_edges\>/_ar_c_label_s/g"\
     41        -e "s/_edges\>/__ar_c_label_s/g"\
    4242        -e "s/\([Ee]\)dge\([a-z]\)/_\1d_ge_label_\2/g"\
    4343        -e "s/\([a-z]\)edge/\1_ed_ge_label_/g"\
     
    6969        -e "s/_GR_APH_TY_PEDE_FS_label_/GRAPH_TYPEDEFS/g"\
    7070        -e "s/_DIGR_APH_TY_PEDE_FS_label_/DIGRAPH_TYPEDEFS/g"\
     71        -e "s/\<digraph_adaptor\.h\>/adaptors.h/g"\
     72        -e "s/\<digraph_utils\.h\>/core.h/g"\
     73        -e "s/\<digraph_reader\.h\>/lgf_reader.h/g"\
     74        -e "s/\<digraph_writer\.h\>/lgf_writer.h/g"\
     75        -e "s/\<topology\.h\>/connectivity.h/g"\
    7176        -e "s/DigraphToEps/GraphToEps/g"\
    7277        -e "s/digraphToEps/graphToEps/g"\
Note: See TracChangeset for help on using the changeset viewer.