Changes in / [1120:ee581a0ecfbf:1122:0976225b5cae] in lemon
- Files:
-
- 26 added
- 113 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified .hgignore ¶
r610 r944 23 23 lemon/stamp-h2 24 24 doc/Doxyfile 25 doc/references.dox 25 26 cmake/version.cmake 26 27 .dirstamp -
TabularUnified CMakeLists.txt ¶
r1053 r1110 115 115 SET(LEMON_HAVE_LONG_LONG ${HAVE_LONG_LONG}) 116 116 117 INCLUDE(FindPythonInterp) 118 117 119 ENABLE_TESTING() 118 120 -
TabularUnified INSTALL ¶
r615 r890 174 174 175 175 Disable COIN-OR support. 176 177 178 Makefile Variables 179 ================== 180 181 Some Makefile variables are reserved by the GNU Coding Standards for 182 the use of the "user" - the person building the package. For instance, 183 CXX and CXXFLAGS are such variables, and have the same meaning as 184 explained in the previous section. These variables can be set on the 185 command line when invoking `make' like this: 186 `make [VARIABLE=VALUE]...' 187 188 WARNINGCXXFLAGS is a non-standard Makefile variable introduced by us 189 to hold several compiler flags related to warnings. Its default value 190 can be overridden when invoking `make'. For example to disable all 191 warning flags use `make WARNINGCXXFLAGS='. 192 193 In order to turn off a single flag from the default set of warning 194 flags, you can use the CXXFLAGS variable, since this is passed after 195 WARNINGCXXFLAGS. For example to turn off `-Wold-style-cast' (which is 196 used by default when g++ is detected) you can use 197 `make CXXFLAGS="-g -O2 -Wno-old-style-cast"'. -
TabularUnified LICENSE ¶
r600 r959 2 2 copyright/license. 3 3 4 Copyright (C) 2003-20 09Egervary Jeno Kombinatorikus Optimalizalasi4 Copyright (C) 2003-2010 Egervary Jeno Kombinatorikus Optimalizalasi 5 5 Kutatocsoport (Egervary Combinatorial Optimization Research Group, 6 6 EGRES). -
TabularUnified Makefile.am ¶
r799 r840 45 45 include doc/Makefile.am 46 46 include tools/Makefile.am 47 include scripts/Makefile.am 47 48 48 49 DIST_SUBDIRS = demo -
TabularUnified NEWS ¶
r712 r1099 1 2011-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 9 2011-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 25 2010-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 37 2010-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 1 117 2009-05-13 Version 1.1 released 2 118 … … 73 189 ----: Add missing unistd.h include to time_measure.h 74 190 #204: Compilation bug fixed in graph_to_eps.h with VS2005 75 #214,#215: windows.h should never be included by lemonheaders191 #214,#215: windows.h should never be included by LEMON headers 76 192 #230: Build systems check the availability of 'long long' type 77 193 #229: Default implementation of Tolerance<> is used for integer types … … 95 211 2008-10-13 Version 1.0 released 96 212 97 98 99 100 101 102 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 103 219 Migration Guide in the doc for more details) 104 220 * Graph -> Digraph, UGraph -> Graph 105 221 * Edge -> Arc, UEdge -> Edge 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 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) 124 240 * Concepts 125 241 * graph structure concepts (concepts/digraph.h, concepts/graph.h, 126 242 concepts/graph_components.h) 127 128 129 130 131 132 133 134 135 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 136 252 (lgf_reader.h, lgf_writer.h) 137 253 * tools to handle the anomalies of calculations with 138 254 floating point numbers (tolerance.h) 139 255 * tools to manage RGB colors (color.h) 140 141 142 143 144 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 18 18 Copying, distribution and modification conditions and terms. 19 19 20 NEWS 21 22 News and version history. 23 20 24 INSTALL 21 25 … … 34 38 Some example programs to make you easier to get familiar with LEMON. 35 39 40 scripts/ 41 42 Scripts that make it easier to develop LEMON. 43 36 44 test/ 37 45 -
TabularUnified configure.ac ¶
r1037 r1039 42 42 43 43 AC_CHECK_PROG([doxygen_found],[doxygen],[yes],[no]) 44 AC_CHECK_PROG([python_found],[python],[yes],[no]) 44 45 AC_CHECK_PROG([gs_found],[gs],[yes],[no]) 45 46 … … 82 83 fi 83 84 AM_CONDITIONAL([WANT_TOOLS], [test x"$enable_tools" != x"no"]) 85 86 dnl Support for running test cases using valgrind. 87 use_valgrind=no 88 AC_ARG_ENABLE([valgrind], 89 AS_HELP_STRING([--enable-valgrind], [use valgrind when running tests]), 90 [use_valgrind=yes]) 91 92 if [[ "$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 98 fi 99 AM_CONDITIONAL(USE_VALGRIND, [test "$use_valgrind" = "yes"]) 84 100 85 101 dnl Checks for header files. … … 129 145 echo 130 146 echo Build additional tools........ : $enable_tools 147 echo Use valgrind for tests........ : $use_valgrind 131 148 echo 132 149 echo The packace will be installed in -
TabularUnified demo/arg_parser_demo.cc ¶
r463 r956 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 66 66 .other("..."); 67 67 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 68 73 // Perform the parsing process 69 74 // (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; } 71 80 72 81 // Check each option if it has been given and print its value -
TabularUnified doc/CMakeLists.txt ¶
r1037 r1110 18 18 ) 19 19 20 IF(DOXYGEN_EXECUTABLE AND GHOSTSCRIPT_EXECUTABLE)20 IF(DOXYGEN_EXECUTABLE AND PYTHONINTERP_FOUND AND GHOSTSCRIPT_EXECUTABLE) 21 21 FILE(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html/) 22 22 SET(GHOSTSCRIPT_OPTIONS -dNOPAUSE -dBATCH -q -dEPSCrop -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sDEVICE=pngalpha) … … 29 29 COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r18 -sOutputFile=gen-images/edge_biconnected_components.png ${CMAKE_CURRENT_SOURCE_DIR}/images/edge_biconnected_components.eps 30 30 COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r18 -sOutputFile=gen-images/grid_graph.png ${CMAKE_CURRENT_SOURCE_DIR}/images/grid_graph.eps 31 COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r18 -sOutputFile=gen-images/matching.png ${CMAKE_CURRENT_SOURCE_DIR}/images/matching.eps 31 32 COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r18 -sOutputFile=gen-images/node_biconnected_components.png ${CMAKE_CURRENT_SOURCE_DIR}/images/node_biconnected_components.eps 32 33 COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r18 -sOutputFile=gen-images/nodeshape_0.png ${CMAKE_CURRENT_SOURCE_DIR}/images/nodeshape_0.eps … … 35 36 COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r18 -sOutputFile=gen-images/nodeshape_3.png ${CMAKE_CURRENT_SOURCE_DIR}/images/nodeshape_3.eps 36 37 COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r18 -sOutputFile=gen-images/nodeshape_4.png ${CMAKE_CURRENT_SOURCE_DIR}/images/nodeshape_4.eps 38 COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r18 -sOutputFile=gen-images/planar.png ${CMAKE_CURRENT_SOURCE_DIR}/images/planar.eps 37 39 COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r18 -sOutputFile=gen-images/strongly_connected_components.png ${CMAKE_CURRENT_SOURCE_DIR}/images/strongly_connected_components.eps 38 40 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 39 42 COMMAND ${DOXYGEN_EXECUTABLE} Doxyfile 40 43 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} -
TabularUnified doc/Doxyfile.in ¶
r1037 r1110 98 98 "@abs_top_srcdir@/tools" \ 99 99 "@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" 101 102 INPUT_ENCODING = UTF-8 102 103 FILE_PATTERNS = *.h \ -
TabularUnified doc/Makefile.am ¶
r1112 r1115 12 12 doc/named-param.dox \ 13 13 doc/namespaces.dox \ 14 doc/references.bib \ 14 15 doc/template.h \ 15 16 doc/html \ … … 29 30 connected_components.eps \ 30 31 edge_biconnected_components.eps \ 32 matching.eps \ 31 33 node_biconnected_components.eps \ 34 planar.eps \ 32 35 strongly_connected_components.eps 33 36 … … 68 71 fi 69 72 70 html-local: $(DOC_PNG_IMAGES) 73 references.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 85 html-local: $(DOC_PNG_IMAGES) references.dox 71 86 if test ${doxygen_found} = yes; then \ 72 87 cd doc; \ -
TabularUnified doc/groups.dox ¶
r710 r963 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 227 227 228 228 /** 229 @defgroup matrices Matrices230 @ingroup datas231 \brief Two dimensional data storages implemented in LEMON.232 233 This group contains two dimensional data storages implemented in LEMON.234 */235 236 /**237 229 @defgroup paths Path Structures 238 230 @ingroup datas … … 247 239 any kind of path structure. 248 240 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 249 This group contains the heap structures implemented in LEMON. 250 251 LEMON provides several heap classes. They are efficient implementations 252 of the abstract data type \e priority \e queue. They store items with 253 specified values called \e priorities in such a way that finding and 254 removing the item with minimum priority are efficient. 255 The basic operations are adding and erasing items, changing the priority 256 of an item, etc. 257 258 Heaps are crucial in several algorithms, such as Dijkstra and Prim. 259 The heap implementations have the same interface, thus any of them can be 260 used easily in such algorithms. 261 262 \sa \ref concepts::Heap "Heap concept" 250 263 */ 251 264 … … 260 273 261 274 /** 275 @defgroup geomdat Geometric Data Structures 276 @ingroup auxdat 277 \brief Geometric data structures implemented in LEMON. 278 279 This 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 /** 262 289 @defgroup algs Algorithms 263 290 \brief This group contains the several algorithms … … 274 301 275 302 This 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. 277 305 */ 278 306 … … 282 310 \brief Algorithms for finding shortest paths. 283 311 284 This group contains the algorithms for finding shortest paths in digraphs. 312 This group contains the algorithms for finding shortest paths in digraphs 313 \ref clrs01algorithms. 285 314 286 315 - \ref Dijkstra algorithm for finding shortest paths from a source node … … 290 319 but the digraph should not contain directed cycles with negative total 291 320 length. 292 - \ref FloydWarshall "Floyd-Warshall" and \ref Johnson "Johnson" algorithms293 for solving the \e all-pairs \e shortest \e paths \e problem when arc294 lenghts can be either positive or negative, but the digraph should295 not contain directed cycles with negative total length.296 321 - \ref Suurballe A successive shortest path algorithm for finding 297 322 arc-disjoint paths between two nodes having minimum total length. … … 299 324 300 325 /** 326 @defgroup spantree Minimum Spanning Tree Algorithms 327 @ingroup algs 328 \brief Algorithms for finding minimum cost spanning trees and arborescences. 329 330 This group contains the algorithms for finding minimum cost spanning 331 trees and arborescences \ref clrs01algorithms. 332 */ 333 334 /** 301 335 @defgroup max_flow Maximum Flow Algorithms 302 336 @ingroup algs … … 304 338 305 339 This group contains the algorithms for finding maximum flows and 306 feasible circulations .340 feasible circulations \ref clrs01algorithms, \ref amo93networkflows. 307 341 308 342 The \e maximum \e flow \e problem is to find a flow of maximum value between … … 318 352 \f[ 0 \leq f(uv) \leq cap(uv) \quad \forall uv\in A \f] 319 353 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 355 preflow push-relabel algorithm \ref goldberg88newapproach for finding 356 maximum flows. It also provides functions to query the minimum cut, 357 which is the dual problem of maximum flow. 358 359 \ref Circulation is a preflow push-relabel algorithm implemented directly 332 360 for finding feasible circulations, which is a somewhat different problem, 333 361 but it is strongly related to maximum flow. … … 342 370 343 371 This 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". 372 circulations \ref amo93networkflows. For more information about this 373 problem and its dual solution, see \ref min_cost_flow 374 "Minimum Cost Flow Problem". 346 375 347 376 LEMON contains several algorithms for this problem. 348 377 - \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. 356 386 357 387 In general NetworkSimplex is the most efficient implementation, … … 376 406 377 407 \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] 379 409 380 410 LEMON contains several algorithms related to minimum cut problems: … … 382 412 - \ref HaoOrlin "Hao-Orlin algorithm" for calculating minimum cut 383 413 in directed graphs. 384 - \ref NagamochiIbaraki "Nagamochi-Ibaraki algorithm" for385 calculating minimum cut in undirected graphs.386 414 - \ref GomoryHu "Gomory-Hu tree computation" for calculating 387 415 all-pairs minimum cut in undirected graphs. … … 392 420 393 421 /** 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 426 This group contains the algorithms for finding minimum mean cycles 427 \ref clrs01algorithms, \ref amo93networkflows. 428 429 The \e minimum \e mean \e cycle \e problem is to find a directed cycle 430 of minimum mean length (cost) in a digraph. 431 The mean length of a cycle is the average length of its arcs, i.e. the 432 ratio between the total length of the cycle and the number of arcs on it. 433 434 This 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 436 conservative if and only if there is no directed cycle of negative total 437 length. For an arbitrary length function, the negative of the minimum 438 cycle mean is the smallest \f$\epsilon\f$ value so that increasing the 439 arc lengths uniformly by \f$\epsilon\f$ results in a conservative length 440 function. 441 442 LEMON 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 450 In practice, the \ref HowardMmc "Howard" algorithm proved to be by far the 451 most efficient one, though the best known theoretical bound on its running 452 time is exponential. 453 Both \ref KarpMmc "Karp" and \ref HartmannOrlinMmc "Hartmann-Orlin" algorithms 454 run in time O(ne) and use space O(n<sup>2</sup>+e), but the latter one is 455 typically faster due to the applied early termination scheme. 415 456 */ 416 457 … … 433 474 434 475 The matching algorithms implemented in LEMON: 435 - \ref MaxBipartiteMatching Hopcroft-Karp augmenting path algorithm436 for calculating maximum cardinality matching in bipartite graphs.437 - \ref PrBipartiteMatching Push-relabel algorithm438 for calculating maximum cardinality matching in bipartite graphs.439 - \ref MaxWeightedBipartiteMatching440 Successive shortest path algorithm for calculating maximum weighted441 matching and maximum weighted bipartite matching in bipartite graphs.442 - \ref MinCostMaxBipartiteMatching443 Successive shortest path algorithm for calculating minimum cost maximum444 matching in bipartite graphs.445 476 - \ref MaxMatching Edmond's blossom shrinking algorithm for calculating 446 477 maximum cardinality matching in general graphs. … … 450 481 Edmond's blossom shrinking algorithm for calculating maximum weighted 451 482 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 500 This group contains the algorithms for discovering the graph properties 501 like 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 512 This group contains the algorithms for planarity checking, 513 embedding and drawing. 514 515 \image html planar.png 516 \image latex planar.eps "Plane graph" width=\textwidth 464 517 */ 465 518 … … 471 524 This group contains some algorithms implemented in LEMON 472 525 in order to make it easier to implement complex algorithms. 473 */474 475 /**476 @defgroup approx Approximation Algorithms477 @ingroup algs478 \brief Approximation algorithms.479 480 This group contains the approximation and heuristic algorithms481 implemented in LEMON.482 526 */ 483 527 … … 492 536 493 537 /** 494 @defgroup lp_group L p and MipSolvers538 @defgroup lp_group LP and MIP Solvers 495 539 @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 542 This group contains LP and MIP solver interfaces for LEMON. 543 Various LP solvers could be used in the same manner with this 544 high-level interface. 545 546 The currently supported solvers are \ref glpk, \ref clp, \ref cbc, 547 \ref cplex, \ref soplex. 518 548 */ 519 549 … … 588 618 589 619 /** 590 @defgroup dimacs_group DIMACS format620 @defgroup dimacs_group DIMACS Format 591 621 @ingroup io_group 592 622 \brief Read and write files in DIMACS format … … 637 667 \brief Skeleton and concept checking classes for graph structures 638 668 639 This group contains the skeletons and concept checking classes of LEMON's640 graph structures and helper classes used to implement these.669 This group contains the skeletons and concept checking classes of 670 graph structures. 641 671 */ 642 672 … … 650 680 651 681 /** 682 @defgroup tools Standalone Utility Applications 683 684 Some utility applications are listed here. 685 686 The standard compilation procedure (<tt>./configure;make</tt>) will compile 687 them, as well. 688 */ 689 690 /** 652 691 \anchor demoprograms 653 692 … … 661 700 */ 662 701 663 /**664 @defgroup tools Standalone Utility Applications665 666 Some utility applications are listed here.667 668 The standard compilation procedure (<tt>./configure;make</tt>) will compile669 them, as well.670 */671 672 702 } -
TabularUnified doc/lgf.dox ¶
r1069 r1081 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2011 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). -
TabularUnified doc/mainpage.dox.in ¶
r1037 r1039 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 22 22 \section intro Introduction 23 23 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 25 and <b>O</b>ptimization in <b>N</b>etworks</i>. 26 It is a C++ template library providing efficient implementations of common 27 data structures and algorithms with focus on combinatorial optimization 28 tasks connected mainly with graphs and networks. 32 29 33 30 <b> … … 39 36 </b> 40 37 41 \subsection howtoread How to read the documentation 38 The project is maintained by the 39 <a href="http://www.cs.elte.hu/egres/">Egerváry Research Group on 40 Combinatorial Optimization</a> \ref egres 41 at the Operations Research Department of the 42 <a href="http://www.elte.hu/en/">Eötvös Loránd University</a>, 43 Budapest, Hungary. 44 LEMON is also a member of the <a href="http://www.coin-or.org/">COIN-OR</a> 45 initiative \ref coinor. 46 47 \section howtoread How to Read the Documentation 42 48 43 49 If you would like to get to know the library, see 44 50 <a class="el" href="http://lemon.cs.elte.hu/pub/tutorial/">LEMON Tutorial</a>. 51 52 If you are interested in starting to use the library, see the <a class="el" 53 href="http://lemon.cs.elte.hu/trac/lemon/wiki/InstallGuide/">Installation 54 Guide</a>. 45 55 46 56 If you know what you are looking for, then try to find it under the -
TabularUnified doc/min_cost_flow.dox ¶
r710 r956 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 27 27 minimum total cost from a set of supply nodes to a set of demand nodes 28 28 in a network with capacity constraints (lower and upper bounds) 29 and arc costs .29 and arc costs \ref amo93networkflows. 30 30 31 31 Formally, let \f$G=(V,A)\f$ be a digraph, \f$lower: A\rightarrow\mathbf{R}\f$, … … 79 79 - if \f$cost^\pi(uv)<0\f$, then \f$f(uv)=upper(uv)\f$. 80 80 - For all \f$u\in V\f$ nodes: 81 - \f$\pi(u) <=0\f$;81 - \f$\pi(u)\leq 0\f$; 82 82 - if \f$\sum_{uv\in A} f(uv) - \sum_{vu\in A} f(vu) \neq sup(u)\f$, 83 83 then \f$\pi(u)=0\f$. 84 84 85 85 Here \f$cost^\pi(uv)\f$ denotes the \e reduced \e cost of the arc 86 86 \f$uv\in A\f$ with respect to the potential function \f$\pi\f$, i.e. … … 120 120 \f[ lower(uv) \leq f(uv) \leq upper(uv) \quad \forall uv\in A \f] 121 121 122 It means that the total demand must be less or equal to the 122 It means that the total demand must be less or equal to the 123 123 total supply (i.e. \f$\sum_{u\in V} sup(u)\f$ must be zero or 124 124 positive) and all the demands have to be satisfied, but there … … 146 146 - if \f$cost^\pi(uv)<0\f$, then \f$f(uv)=upper(uv)\f$. 147 147 - For all \f$u\in V\f$ nodes: 148 - \f$\pi(u) >=0\f$;148 - \f$\pi(u)\geq 0\f$; 149 149 - if \f$\sum_{uv\in A} f(uv) - \sum_{vu\in A} f(vu) \neq sup(u)\f$, 150 150 then \f$\pi(u)=0\f$. -
TabularUnified lemon/Makefile.am ¶
r1106 r1110 59 59 lemon/arg_parser.h \ 60 60 lemon/assert.h \ 61 lemon/bellman_ford.h \ 61 62 lemon/bfs.h \ 62 63 lemon/bin_heap.h \ 64 lemon/binomial_heap.h \ 63 65 lemon/bucket_heap.h \ 66 lemon/capacity_scaling.h \ 64 67 lemon/cbc.h \ 65 68 lemon/circulation.h \ … … 68 71 lemon/concept_check.h \ 69 72 lemon/connectivity.h \ 73 lemon/core.h \ 74 lemon/cost_scaling.h \ 70 75 lemon/counter.h \ 71 lemon/core.h \72 76 lemon/cplex.h \ 77 lemon/cycle_canceling.h \ 73 78 lemon/dfs.h \ 79 lemon/dheap.h \ 74 80 lemon/dijkstra.h \ 75 81 lemon/dim2.h \ … … 80 86 lemon/euler.h \ 81 87 lemon/fib_heap.h \ 88 lemon/fractional_matching.h \ 82 89 lemon/full_graph.h \ 83 90 lemon/glpk.h \ … … 85 92 lemon/graph_to_eps.h \ 86 93 lemon/grid_graph.h \ 94 lemon/hartmann_orlin_mmc.h \ 95 lemon/howard_mmc.h \ 87 96 lemon/hypercube_graph.h \ 97 lemon/karp_mmc.h \ 88 98 lemon/kruskal.h \ 89 99 lemon/hao_orlin.h \ … … 100 110 lemon/nauty_reader.h \ 101 111 lemon/network_simplex.h \ 112 lemon/pairing_heap.h \ 102 113 lemon/path.h \ 114 lemon/planarity.h \ 103 115 lemon/preflow.h \ 116 lemon/quad_heap.h \ 104 117 lemon/radix_heap.h \ 105 118 lemon/radix_sort.h \ … … 107 120 lemon/smart_graph.h \ 108 121 lemon/soplex.h \ 122 lemon/static_graph.h \ 109 123 lemon/suurballe.h \ 110 124 lemon/time_measure.h \ -
TabularUnified lemon/adaptors.h ¶
r703 r956 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 361 361 /// parameter is set to be \c const. 362 362 /// 363 /// This class provides item counting in the same time as the adapted 364 /// digraph structure. 365 /// 363 366 /// \tparam DGR The type of the adapted digraph. 364 367 /// It must conform to the \ref concepts::Digraph "Digraph" concept. … … 419 422 Parent::initialize(digraph); 420 423 _node_filter = &node_filter; 421 _arc_filter = &arc_filter; 424 _arc_filter = &arc_filter; 422 425 } 423 426 … … 506 509 507 510 template <typename V> 508 class NodeMap 509 : public SubMapExtender<SubDigraphBase<DGR, NF, AF, ch>, 510 511 class NodeMap 512 : public SubMapExtender<SubDigraphBase<DGR, NF, AF, ch>, 513 LEMON_SCOPE_FIX(DigraphAdaptorBase<DGR>, NodeMap<V>)> { 511 514 typedef SubMapExtender<SubDigraphBase<DGR, NF, AF, ch>, 512 515 LEMON_SCOPE_FIX(DigraphAdaptorBase<DGR>, NodeMap<V>)> Parent; 513 516 514 517 public: … … 533 536 534 537 template <typename V> 535 class ArcMap 538 class ArcMap 536 539 : public SubMapExtender<SubDigraphBase<DGR, NF, AF, ch>, 537 540 LEMON_SCOPE_FIX(DigraphAdaptorBase<DGR>, ArcMap<V>)> { 538 541 typedef SubMapExtender<SubDigraphBase<DGR, NF, AF, ch>, 539 542 LEMON_SCOPE_FIX(DigraphAdaptorBase<DGR>, ArcMap<V>)> Parent; … … 580 583 Parent::initialize(digraph); 581 584 _node_filter = &node_filter; 582 _arc_filter = &arc_filter; 585 _arc_filter = &arc_filter; 583 586 } 584 587 … … 649 652 650 653 template <typename V> 651 class NodeMap 654 class NodeMap 652 655 : public SubMapExtender<SubDigraphBase<DGR, NF, AF, false>, 653 656 LEMON_SCOPE_FIX(DigraphAdaptorBase<DGR>, NodeMap<V>)> { 654 typedef SubMapExtender<SubDigraphBase<DGR, NF, AF, false>, 657 typedef SubMapExtender<SubDigraphBase<DGR, NF, AF, false>, 655 658 LEMON_SCOPE_FIX(DigraphAdaptorBase<DGR>, NodeMap<V>)> Parent; 656 659 … … 676 679 677 680 template <typename V> 678 class ArcMap 681 class ArcMap 679 682 : public SubMapExtender<SubDigraphBase<DGR, NF, AF, false>, 680 683 LEMON_SCOPE_FIX(DigraphAdaptorBase<DGR>, ArcMap<V>)> { … … 719 722 /// by adding or removing nodes or arcs, unless the \c GR template 720 723 /// parameter is set to be \c const. 724 /// 725 /// This class provides only linear time counting for nodes and arcs. 721 726 /// 722 727 /// \tparam DGR The type of the adapted digraph. … … 1017 1022 1018 1023 template <typename V> 1019 class NodeMap 1024 class NodeMap 1020 1025 : public SubMapExtender<SubGraphBase<GR, NF, EF, ch>, 1021 1026 LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, NodeMap<V>)> { 1022 typedef SubMapExtender<SubGraphBase<GR, NF, EF, ch>, 1027 typedef SubMapExtender<SubGraphBase<GR, NF, EF, ch>, 1023 1028 LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, NodeMap<V>)> Parent; 1024 1029 … … 1044 1049 1045 1050 template <typename V> 1046 class ArcMap 1051 class ArcMap 1047 1052 : public SubMapExtender<SubGraphBase<GR, NF, EF, ch>, 1048 1053 LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, ArcMap<V>)> { 1049 typedef SubMapExtender<SubGraphBase<GR, NF, EF, ch>, 1054 typedef SubMapExtender<SubGraphBase<GR, NF, EF, ch>, 1050 1055 LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, ArcMap<V>)> Parent; 1051 1056 … … 1071 1076 1072 1077 template <typename V> 1073 class EdgeMap 1078 class EdgeMap 1074 1079 : public SubMapExtender<SubGraphBase<GR, NF, EF, ch>, 1075 1080 LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, EdgeMap<V>)> { 1076 typedef SubMapExtender<SubGraphBase<GR, NF, EF, ch>, 1081 typedef SubMapExtender<SubGraphBase<GR, NF, EF, ch>, 1077 1082 LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, EdgeMap<V>)> Parent; 1078 1083 … … 1113 1118 NF* _node_filter; 1114 1119 EF* _edge_filter; 1115 SubGraphBase() 1116 1120 SubGraphBase() 1121 : Parent(), _node_filter(0), _edge_filter(0) { } 1117 1122 1118 1123 void initialize(GR& graph, NF& node_filter, EF& edge_filter) { … … 1215 1220 1216 1221 template <typename V> 1217 class NodeMap 1222 class NodeMap 1218 1223 : public SubMapExtender<SubGraphBase<GR, NF, EF, false>, 1219 1224 LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, NodeMap<V>)> { 1220 typedef SubMapExtender<SubGraphBase<GR, NF, EF, false>, 1225 typedef SubMapExtender<SubGraphBase<GR, NF, EF, false>, 1221 1226 LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, NodeMap<V>)> Parent; 1222 1227 … … 1242 1247 1243 1248 template <typename V> 1244 class ArcMap 1249 class ArcMap 1245 1250 : public SubMapExtender<SubGraphBase<GR, NF, EF, false>, 1246 1251 LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, ArcMap<V>)> { 1247 typedef SubMapExtender<SubGraphBase<GR, NF, EF, false>, 1252 typedef SubMapExtender<SubGraphBase<GR, NF, EF, false>, 1248 1253 LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, ArcMap<V>)> Parent; 1249 1254 … … 1269 1274 1270 1275 template <typename V> 1271 class EdgeMap 1276 class EdgeMap 1272 1277 : public SubMapExtender<SubGraphBase<GR, NF, EF, false>, 1273 1278 LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, EdgeMap<V>)> { 1274 typedef SubMapExtender<SubGraphBase<GR, NF, EF, false>, 1275 1279 typedef SubMapExtender<SubGraphBase<GR, NF, EF, false>, 1280 LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, EdgeMap<V>)> Parent; 1276 1281 1277 1282 public: … … 1314 1319 /// by adding or removing nodes or edges, unless the \c GR template 1315 1320 /// parameter is set to be \c const. 1321 /// 1322 /// This class provides only linear time counting for nodes, edges and arcs. 1316 1323 /// 1317 1324 /// \tparam GR The type of the adapted graph. … … 1471 1478 /// by adding or removing nodes or arcs/edges, unless the \c GR template 1472 1479 /// parameter is set to be \c const. 1480 /// 1481 /// This class provides only linear time item counting. 1473 1482 /// 1474 1483 /// \tparam GR The type of the adapted digraph or graph. … … 1496 1505 #endif 1497 1506 typedef DigraphAdaptorExtender< 1498 SubDigraphBase<GR, NF, ConstMap<typename GR::Arc, Const<bool, true> >, 1507 SubDigraphBase<GR, NF, ConstMap<typename GR::Arc, Const<bool, true> >, 1499 1508 true> > Parent; 1500 1509 … … 1517 1526 /// Creates a subgraph for the given digraph or graph with the 1518 1527 /// given node filter map. 1519 FilterNodes(GR& graph, NF& node_filter) 1528 FilterNodes(GR& graph, NF& node_filter) 1520 1529 : Parent(), const_true_map() 1521 1530 { … … 1555 1564 typename enable_if<UndirectedTagIndicator<GR> >::type> : 1556 1565 public GraphAdaptorExtender< 1557 SubGraphBase<GR, NF, ConstMap<typename GR::Edge, Const<bool, true> >, 1566 SubGraphBase<GR, NF, ConstMap<typename GR::Edge, Const<bool, true> >, 1558 1567 true> > { 1559 1568 1560 1569 typedef GraphAdaptorExtender< 1561 SubGraphBase<GR, NF, ConstMap<typename GR::Edge, Const<bool, true> >, 1570 SubGraphBase<GR, NF, ConstMap<typename GR::Edge, Const<bool, true> >, 1562 1571 true> > Parent; 1563 1572 … … 1619 1628 /// by adding or removing nodes or arcs, unless the \c GR template 1620 1629 /// parameter is set to be \c const. 1630 /// 1631 /// This class provides only linear time counting for nodes and arcs. 1621 1632 /// 1622 1633 /// \tparam DGR The type of the adapted digraph. … … 1643 1654 #endif 1644 1655 typedef DigraphAdaptorExtender< 1645 SubDigraphBase<DGR, ConstMap<typename DGR::Node, Const<bool, true> >, 1656 SubDigraphBase<DGR, ConstMap<typename DGR::Node, Const<bool, true> >, 1646 1657 AF, false> > Parent; 1647 1658 … … 1729 1740 /// by adding or removing nodes or edges, unless the \c GR template 1730 1741 /// parameter is set to be \c const. 1742 /// 1743 /// This class provides only linear time counting for nodes, edges and arcs. 1731 1744 /// 1732 1745 /// \tparam GR The type of the adapted graph. … … 1749 1762 class FilterEdges : 1750 1763 public GraphAdaptorExtender< 1751 SubGraphBase<GR, ConstMap<typename GR::Node, Const<bool, true> >, 1764 SubGraphBase<GR, ConstMap<typename GR::Node, Const<bool, true> >, 1752 1765 EF, false> > { 1753 1766 #endif 1754 1767 typedef GraphAdaptorExtender< 1755 SubGraphBase<GR, ConstMap<typename GR::Node, Const<bool, true > >, 1768 SubGraphBase<GR, ConstMap<typename GR::Node, Const<bool, true > >, 1756 1769 EF, false> > Parent; 1757 1770 … … 1778 1791 /// Creates a subgraph for the given graph with the given edge 1779 1792 /// filter map. 1780 FilterEdges(GR& graph, EF& edge_filter) 1793 FilterEdges(GR& graph, EF& edge_filter) 1781 1794 : Parent(), const_true_map() { 1782 1795 Parent::initialize(graph, const_true_map, edge_filter); … … 1846 1859 bool _forward; 1847 1860 1848 Arc(const Edge& edge, bool forward) 1861 Arc(const Edge& edge, bool forward) 1849 1862 : _edge(edge), _forward(forward) {} 1850 1863 … … 2086 2099 2087 2100 ArcMapBase(const UndirectorBase<DGR>& adaptor, const V& value) 2088 : _forward(*adaptor._digraph, value), 2101 : _forward(*adaptor._digraph, value), 2089 2102 _backward(*adaptor._digraph, value) {} 2090 2103 … … 2204 2217 typedef typename ItemSetTraits<DGR, Edge>::ItemNotifier EdgeNotifier; 2205 2218 EdgeNotifier& notifier(Edge) const { return _digraph->notifier(Edge()); } 2206 2219 2207 2220 typedef EdgeNotifier ArcNotifier; 2208 2221 ArcNotifier& notifier(Arc) const { return _digraph->notifier(Edge()); } … … 2232 2245 /// by adding or removing nodes or edges, unless the \c GR template 2233 2246 /// parameter is set to be \c const. 2247 /// 2248 /// This class provides item counting in the same time as the adapted 2249 /// digraph structure. 2234 2250 /// 2235 2251 /// \tparam DGR The type of the adapted digraph. … … 2535 2551 /// by adding or removing nodes or arcs, unless the \c GR template 2536 2552 /// parameter is set to be \c const. 2553 /// 2554 /// This class provides item counting in the same time as the adapted 2555 /// graph structure. 2537 2556 /// 2538 2557 /// \tparam GR The type of the adapted graph. … … 2679 2698 /// This class conforms to the \ref concepts::Digraph "Digraph" concept. 2680 2699 /// 2700 /// This class provides only linear time counting for nodes and arcs. 2701 /// 2681 2702 /// \tparam DGR The type of the adapted digraph. 2682 2703 /// It must conform to the \ref concepts::Digraph "Digraph" concept. … … 2708 2729 typename FM = CM, 2709 2730 typename TL = Tolerance<typename CM::Value> > 2710 class ResidualDigraph 2731 class ResidualDigraph 2711 2732 : public SubDigraph< 2712 2733 Undirector<const DGR>, … … 2765 2786 ResidualDigraph(const DGR& digraph, const CM& capacity, 2766 2787 FM& flow, const TL& tolerance = Tolerance()) 2767 : Parent(), _capacity(&capacity), _flow(&flow), 2788 : Parent(), _capacity(&capacity), _flow(&flow), 2768 2789 _graph(digraph), _node_filter(), 2769 2790 _forward_filter(capacity, flow, tolerance), … … 2847 2868 2848 2869 /// Constructor 2849 ResidualCapacity(const ResidualDigraph<DGR, CM, FM, TL>& adaptor) 2870 ResidualCapacity(const ResidualDigraph<DGR, CM, FM, TL>& adaptor) 2850 2871 : _adaptor(&adaptor) {} 2851 2872 … … 3326 3347 /// in the adaptor. 3327 3348 /// 3349 /// This class provides item counting in the same time as the adapted 3350 /// digraph structure. 3351 /// 3328 3352 /// \tparam DGR The type of the adapted digraph. 3329 3353 /// It must conform to the \ref concepts::Digraph "Digraph" concept. … … 3424 3448 /// to get a node map of the split digraph. 3425 3449 /// 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. 3427 3451 /// \tparam OUT The type of the node map for the out-nodes. 3428 3452 template <typename IN, typename OUT> -
TabularUnified lemon/arg_parser.cc ¶
r463 r956 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 21 21 namespace lemon { 22 22 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 23 31 void ArgParser::_showHelp(void *p) 24 32 { 25 33 (static_cast<ArgParser*>(p))->showHelp(); 26 exit(1);34 (static_cast<ArgParser*>(p))->_terminate(ArgParserException::HELP); 27 35 } 28 36 29 37 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) { 31 40 funcOption("-help","Print a short help message",_showHelp,this); 32 41 synonym("help","-help"); … … 343 352 i!=_others_help.end();++i) showHelp(i); 344 353 for(Opts::const_iterator i=_opts.begin();i!=_opts.end();++i) showHelp(i); 345 exit(1);354 _terminate(ArgParserException::HELP); 346 355 } 347 356 … … 352 361 std::cerr << "\nType '" << _command_name << 353 362 " --help' to obtain a short summary on the usage.\n\n"; 354 exit(1);363 _terminate(ArgParserException::UNKNOWN_OPT); 355 364 } 356 365 … … 415 424 std::cerr << "\nType '" << _command_name << 416 425 " --help' to obtain a short summary on the usage.\n\n"; 417 exit(1);426 _terminate(ArgParserException::INVALID_OPT); 418 427 } 419 428 } -
TabularUnified lemon/arg_parser.h ¶
r463 r959 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 35 35 namespace lemon { 36 36 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 37 82 ///Command line arguments parser 38 83 … … 116 161 const std::string &help, 117 162 void (*func)(void *),void *data); 163 164 bool _exit_on_problems; 165 166 void _terminate(ArgParserException::Reason reason) const; 118 167 119 168 public: … … 381 430 const std::vector<std::string> &files() const { return _file_args; } 382 431 432 ///Throw instead of exit in case of problems 433 void throwOnProblems() 434 { 435 _exit_on_problems=false; 436 } 383 437 }; 384 438 } -
TabularUnified lemon/bfs.h ¶
r525 r956 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 48 48 ///The type of the map that stores the predecessor 49 49 ///arcs of the shortest paths. 50 ///It must meetthe \ref concepts::WriteMap "WriteMap" concept.50 ///It must conform to the \ref concepts::WriteMap "WriteMap" concept. 51 51 typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap; 52 52 ///Instantiates a \c PredMap. … … 63 63 64 64 ///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. 66 67 typedef NullMap<typename Digraph::Node,bool> ProcessedMap; 67 68 ///Instantiates a \c ProcessedMap. … … 82 83 83 84 ///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. 85 87 typedef typename Digraph::template NodeMap<bool> ReachedMap; 86 88 ///Instantiates a \c ReachedMap. … … 97 99 98 100 ///The type of the map that stores the distances of the nodes. 99 ///It must meetthe \ref concepts::WriteMap "WriteMap" concept.101 ///It must conform to the \ref concepts::WriteMap "WriteMap" concept. 100 102 typedef typename Digraph::template NodeMap<int> DistMap; 101 103 ///Instantiates a \c DistMap. … … 121 123 ///\tparam GR The type of the digraph the algorithm runs on. 122 124 ///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. 123 130 #ifdef DOXYGEN 124 131 template <typename GR, … … 226 233 ///\ref named-templ-param "Named parameter" for setting 227 234 ///\c PredMap type. 228 ///It must meetthe \ref concepts::WriteMap "WriteMap" concept.235 ///It must conform to the \ref concepts::WriteMap "WriteMap" concept. 229 236 template <class T> 230 237 struct SetPredMap : public Bfs< Digraph, SetPredMapTraits<T> > { … … 246 253 ///\ref named-templ-param "Named parameter" for setting 247 254 ///\c DistMap type. 248 ///It must meetthe \ref concepts::WriteMap "WriteMap" concept.255 ///It must conform to the \ref concepts::WriteMap "WriteMap" concept. 249 256 template <class T> 250 257 struct SetDistMap : public Bfs< Digraph, SetDistMapTraits<T> > { … … 266 273 ///\ref named-templ-param "Named parameter" for setting 267 274 ///\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. 269 277 template <class T> 270 278 struct SetReachedMap : public Bfs< Digraph, SetReachedMapTraits<T> > { … … 286 294 ///\ref named-templ-param "Named parameter" for setting 287 295 ///\c ProcessedMap type. 288 ///It must meetthe \ref concepts::WriteMap "WriteMap" concept.296 ///It must conform to the \ref concepts::WriteMap "WriteMap" concept. 289 297 template <class T> 290 298 struct SetProcessedMap : public Bfs< Digraph, SetProcessedMapTraits<T> > { … … 414 422 ///The simplest way to execute the BFS algorithm is to use one of the 415 423 ///member functions called \ref run(Node) "run()".\n 416 ///If you need more control on the execution, firstyou have to call417 ///\ref init() , then you can add several source nodes with424 ///If you need better control on the execution, you have to call 425 ///\ref init() first, then you can add several source nodes with 418 426 ///\ref addSource(). Finally the actual path computation can be 419 427 ///performed with one of the \ref start() functions. … … 701 709 ///Runs the algorithm to visit all nodes in the digraph. 702 710 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. 709 713 /// 710 714 ///\note <tt>b.run(s)</tt> is just a shortcut of the following code. … … 738 742 ///@{ 739 743 740 ///The shortest path to anode.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). 743 747 /// 744 748 ///\warning \c t should be reached from the root(s). … … 748 752 Path path(Node t) const { return Path(*G, *_pred, t); } 749 753 750 ///The distance of anode from the root(s).751 752 ///Returns the distance of anode 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). 753 757 /// 754 758 ///\warning If node \c v is not reached from the root(s), then … … 759 763 int dist(Node v) const { return (*_dist)[v]; } 760 764 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 /// 763 768 ///This function returns the 'previous arc' of the shortest path 764 769 ///tree for the node \c v, i.e. it returns the last arc of a … … 767 772 /// 768 773 ///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(). 770 775 /// 771 776 ///\pre Either \ref run(Node) "run()" or \ref init() … … 773 778 Arc predArc(Node v) const { return (*_pred)[v];} 774 779 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 /// 777 783 ///This function returns the 'previous node' of the shortest path 778 784 ///tree for the node \c v, i.e. it returns the last but one node 779 /// froma shortest path from a root to \c v. It is \c INVALID785 ///of a shortest path from a root to \c v. It is \c INVALID 780 786 ///if \c v is not reached from the root(s) or if \c v is a root. 781 787 /// 782 788 ///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(). 784 790 /// 785 791 ///\pre Either \ref run(Node) "run()" or \ref init() … … 802 808 /// 803 809 ///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). 805 811 /// 806 812 ///\pre Either \ref run(Node) "run()" or \ref init() … … 808 814 const PredMap &predMap() const { return *_pred;} 809 815 810 ///Checks if anode is reached from the root(s).816 ///Checks if the given node is reached from the root(s). 811 817 812 818 ///Returns \c true if \c v is reached from the root(s). … … 834 840 ///The type of the map that stores the predecessor 835 841 ///arcs of the shortest paths. 836 ///It must meetthe \ref concepts::WriteMap "WriteMap" concept.842 ///It must conform to the \ref concepts::WriteMap "WriteMap" concept. 837 843 typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap; 838 844 ///Instantiates a PredMap. … … 849 855 850 856 ///The type of the map that indicates which nodes are processed. 851 ///It must meetthe \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. 853 859 typedef NullMap<typename Digraph::Node,bool> ProcessedMap; 854 860 ///Instantiates a ProcessedMap. … … 869 875 870 876 ///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. 872 879 typedef typename Digraph::template NodeMap<bool> ReachedMap; 873 880 ///Instantiates a ReachedMap. … … 884 891 885 892 ///The type of the map that stores the distances of the nodes. 886 ///It must meetthe \ref concepts::WriteMap "WriteMap" concept.893 ///It must conform to the \ref concepts::WriteMap "WriteMap" concept. 887 894 typedef typename Digraph::template NodeMap<int> DistMap; 888 895 ///Instantiates a DistMap. … … 899 906 900 907 ///The type of the shortest paths. 901 ///It must meetthe \ref concepts::Path "Path" concept.908 ///It must conform to the \ref concepts::Path "Path" concept. 902 909 typedef lemon::Path<Digraph> Path; 903 910 }; … … 905 912 /// Default traits class used by BfsWizard 906 913 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. 913 916 template<class GR> 914 917 class BfsWizardBase : public BfsWizardDefaultTraits<GR> … … 938 941 /// Constructor. 939 942 940 /// This constructor does not require parameters, thereforeit initiates943 /// This constructor does not require parameters, it initiates 941 944 /// all of the attributes to \c 0. 942 945 BfsWizardBase() : _g(0), _reached(0), _processed(0), _pred(0), … … 963 966 /// This class should only be used through the \ref bfs() function, 964 967 /// which makes it easier to use the algorithm. 968 /// 969 /// \tparam TR The traits class that defines various types used by the 970 /// algorithm. 965 971 template<class TR> 966 972 class BfsWizard : public TR … … 968 974 typedef TR Base; 969 975 970 ///The type of the digraph the algorithm runs on.971 976 typedef typename TR::Digraph Digraph; 972 977 … … 976 981 typedef typename Digraph::OutArcIt OutArcIt; 977 982 978 ///\brief The type of the map that stores the predecessor979 ///arcs of the shortest paths.980 983 typedef typename TR::PredMap PredMap; 981 ///\brief The type of the map that stores the distances of the nodes.982 984 typedef typename TR::DistMap DistMap; 983 ///\brief The type of the map that indicates which nodes are reached.984 985 typedef typename TR::ReachedMap ReachedMap; 985 ///\brief The type of the map that indicates which nodes are processed.986 986 typedef typename TR::ProcessedMap ProcessedMap; 987 ///The type of the shortest paths988 987 typedef typename TR::Path Path; 989 988 … … 1055 1054 ///Runs BFS algorithm to visit all nodes in the digraph. 1056 1055 1057 ///This method runs BFS algorithm in order to compute1058 /// the shortest path to each node.1056 ///This method runs BFS algorithm in order to visit all nodes 1057 ///in the digraph. 1059 1058 void run() 1060 1059 { … … 1068 1067 SetPredMapBase(const TR &b) : TR(b) {} 1069 1068 }; 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. 1075 1075 template<class T> 1076 1076 BfsWizard<SetPredMapBase<T> > predMap(const T &t) … … 1086 1086 SetReachedMapBase(const TR &b) : TR(b) {} 1087 1087 }; 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. 1093 1094 template<class T> 1094 1095 BfsWizard<SetReachedMapBase<T> > reachedMap(const T &t) … … 1104 1105 SetDistMapBase(const TR &b) : TR(b) {} 1105 1106 }; 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. 1111 1114 template<class T> 1112 1115 BfsWizard<SetDistMapBase<T> > distMap(const T &t) … … 1122 1125 SetProcessedMapBase(const TR &b) : TR(b) {} 1123 1126 }; 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. 1129 1133 template<class T> 1130 1134 BfsWizard<SetProcessedMapBase<T> > processedMap(const T &t) … … 1265 1269 /// 1266 1270 /// 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. 1268 1273 typedef typename Digraph::template NodeMap<bool> ReachedMap; 1269 1274 … … 1303 1308 /// does not observe the BFS events. If you want to observe the BFS 1304 1309 /// events, you should implement your own visitor class. 1305 /// \tparam TR T raits class to set various datatypes used by the1306 /// algorithm. The default traits class is1307 /// \ref BfsVisitDefaultTraits"BfsVisitDefaultTraits<GR>".1308 /// See \ref BfsVisitDefaultTraits for the documentation of1309 /// 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. 1310 1315 #ifdef DOXYGEN 1311 1316 template <typename GR, typename VS, typename TR> … … 1426 1431 /// The simplest way to execute the BFS algorithm is to use one of the 1427 1432 /// member functions called \ref run(Node) "run()".\n 1428 /// If you need more control on the execution, firstyou have to call1429 /// \ref init() , then you can add several source nodes with1433 /// If you need better control on the execution, you have to call 1434 /// \ref init() first, then you can add several source nodes with 1430 1435 /// \ref addSource(). Finally the actual path computation can be 1431 1436 /// performed with one of the \ref start() functions. … … 1699 1704 /// \brief Runs the algorithm to visit all nodes in the digraph. 1700 1705 /// 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. 1707 1708 /// 1708 1709 /// \note <tt>b.run(s)</tt> is just a shortcut of the following code. … … 1736 1737 ///@{ 1737 1738 1738 /// \brief Checks if anode is reached from the root(s).1739 /// \brief Checks if the given node is reached from the root(s). 1739 1740 /// 1740 1741 /// Returns \c true if \c v is reached from the root(s). -
TabularUnified lemon/bin_heap.h ¶
r730 r758 20 20 #define LEMON_BIN_HEAP_H 21 21 22 ///\ingroup auxdat22 ///\ingroup heaps 23 23 ///\file 24 ///\brief Binary Heap implementation.24 ///\brief Binary heap implementation. 25 25 26 26 #include <vector> … … 30 30 namespace lemon { 31 31 32 /// \ingroup auxdat32 /// \ingroup heaps 33 33 /// 34 /// \brief A Binary Heap implementation.34 /// \brief Binary heap data structure. 35 35 /// 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". 37 38 /// 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 52 47 template <typename PR, typename IM, typename CMP = std::less<PR> > 48 #endif 53 49 class BinHeap { 54 55 50 public: 56 ///\e 51 52 /// Type of the item-int map. 57 53 typedef IM ItemIntMap; 58 /// \e54 /// Type of the priorities. 59 55 typedef PR Prio; 60 /// \e56 /// Type of the items stored in the heap. 61 57 typedef typename ItemIntMap::Key Item; 62 /// \e58 /// Type of the item-priority pairs. 63 59 typedef std::pair<Item,Prio> Pair; 64 /// \e60 /// Functor type for comparing the priorities. 65 61 typedef CMP Compare; 66 62 67 /// \brief Type to represent the items states.68 /// 69 /// Each Item element have a state associated to it. It maybe "in heap",70 /// "pre heap" or "postheap". The latter two are indifferent from the63 /// \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 71 67 /// heap's point of view, but may be useful to the user. 72 68 /// … … 85 81 86 82 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. 93 90 explicit BinHeap(ItemIntMap &map) : _iim(map) {} 94 91 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. 103 99 BinHeap(ItemIntMap &map, const Compare &comp) 104 100 : _iim(map), _comp(comp) {} 105 101 106 102 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. 110 106 int size() const { return _data.size(); } 111 107 112 /// \brief Check s 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. 115 111 bool empty() const { return _data.empty(); } 116 112 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. 123 120 void clear() { 124 121 _data.clear(); … … 128 125 static int parent(int i) { return (i-1)/2; } 129 126 130 static int second _child(int i) { return 2*i+2; }127 static int secondChild(int i) { return 2*i+2; } 131 128 bool less(const Pair &p1, const Pair &p2) const { 132 129 return _comp(p1.second, p2.second); 133 130 } 134 131 135 int bubble _up(int hole, Pair p) {132 int bubbleUp(int hole, Pair p) { 136 133 int par = parent(hole); 137 134 while( hole>0 && less(p,_data[par]) ) { … … 144 141 } 145 142 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); 148 145 while(child < length) { 149 146 if( less(_data[child-1], _data[child]) ) { … … 154 151 move(_data[child], hole); 155 152 hole = child; 156 child = second _child(hole);153 child = secondChild(hole); 157 154 } 158 155 child--; … … 172 169 173 170 public: 171 174 172 /// \brief Insert a pair of item and priority into the heap. 175 173 /// 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. 177 176 /// \param p The pair to insert. 177 /// \pre \c p.first must not be stored in the heap. 178 178 void push(const Pair &p) { 179 179 int n = _data.size(); 180 180 _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. 187 188 /// \param i The item to insert. 188 189 /// \param p The priority of the item. 190 /// \pre \e i must not be stored in the heap. 189 191 void push(const Item &i, const Prio &p) { push(Pair(i,p)); } 190 192 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. 196 197 Item top() const { 197 198 return _data[0].first; 198 199 } 199 200 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 non empty.201 /// \brief The minimum priority. 202 /// 203 /// This function returns the minimum priority. 204 /// \pre The heap must be non-empty. 204 205 Prio prio() const { 205 206 return _data[0].second; 206 207 } 207 208 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. 212 212 /// \pre The heap must be non-empty. 213 213 void pop() { … … 215 215 _iim.set(_data[0].first, POST_HEAP); 216 216 if (n > 0) { 217 bubble _down(0, _data[n], n);217 bubbleDown(0, _data[n], n); 218 218 } 219 219 _data.pop_back(); 220 220 } 221 221 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. 227 228 void erase(const Item &i) { 228 229 int h = _iim[i]; … … 230 231 _iim.set(_data[h].first, POST_HEAP); 231 232 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); 234 235 } 235 236 } … … 237 238 } 238 239 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. 245 245 Prio operator[](const Item &i) const { 246 246 int idx = _iim[i]; … … 248 248 } 249 249 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. 255 256 /// \param i The item. 256 257 /// \param p The priority. … … 261 262 } 262 263 else if( _comp(p, _data[idx].second) ) { 263 bubble _up(idx, Pair(i,p));264 bubbleUp(idx, Pair(i,p)); 264 265 } 265 266 else { 266 bubble _down(idx, Pair(i,p), _data.size());267 } 268 } 269 270 /// \brief Decrease s 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. 273 274 /// \param i The item. 274 275 /// \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. 277 277 void decrease(const Item &i, const Prio &p) { 278 278 int idx = _iim[i]; 279 bubble _up(idx, Pair(i,p));280 } 281 282 /// \brief Increase s 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. 285 285 /// \param i The item. 286 286 /// \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. 289 288 void increase(const Item &i, const Prio &p) { 290 289 int idx = _iim[i]; 291 bubble _down(idx, Pair(i,p), _data.size());292 } 293 294 /// \brief Return s if \c item is in, has already been in, or has295 /// never been in the heap.296 /// 297 /// This method returns PRE_HEAP if \c item has never been in the298 /// heap, IN_HEAP if it is in the heap at the moment, and POST_HEAP299 /// otherwise. In the latter case it is possible that \c item will300 /// get backto 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. 301 300 /// \param i The item. 302 301 State state(const Item &i) const { … … 307 306 } 308 307 309 /// \brief Set s the state of the \citem in the heap.310 /// 311 /// Sets the state of the \c item in the heap. It can be used to312 /// manually clear the heap when it is important to achive the313 /// 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. 314 313 /// \param i The item. 315 314 /// \param st The state. It should not be \c IN_HEAP. … … 328 327 } 329 328 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. 336 336 void replace(const Item& i, const Item& j) { 337 337 int idx = _iim[i]; -
TabularUnified lemon/bits/array_map.h ¶
r664 r956 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 71 71 72 72 private: 73 73 74 74 // The MapBase of the Map which imlements the core regisitry function. 75 75 typedef typename Notifier::ObserverBase Parent; -
TabularUnified lemon/bits/default_map.h ¶
r674 r956 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 158 158 public: 159 159 typedef DefaultMap<_Graph, _Item, _Value> Map; 160 160 161 161 typedef typename Parent::GraphType GraphType; 162 162 typedef typename Parent::Value Value; -
TabularUnified lemon/bits/edge_set_extender.h ¶
r967 r1110 1 /* -*- C++-*-1 /* -*- mode: C++; indent-tabs-mode: nil; -*- 2 2 * 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. 4 4 * 5 * Copyright (C) 2003-20 085 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 64 64 Node oppositeNode(const Node &n, const Arc &e) const { 65 65 if (n == Parent::source(e)) 66 66 return Parent::target(e); 67 67 else if(n==Parent::target(e)) 68 68 return Parent::source(e); 69 69 else 70 70 return INVALID; 71 71 } 72 72 … … 92 92 // Iterable extensions 93 93 94 class NodeIt : public Node { 94 class NodeIt : public Node { 95 95 const Digraph* digraph; 96 96 public: … … 101 101 102 102 explicit NodeIt(const Digraph& _graph) : digraph(&_graph) { 103 104 } 105 106 NodeIt(const Digraph& _graph, const Node& node) 107 108 109 NodeIt& operator++() { 110 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 { 118 118 const Digraph* digraph; 119 119 public: … … 124 124 125 125 explicit ArcIt(const Digraph& _graph) : digraph(&_graph) { 126 127 } 128 129 ArcIt(const Digraph& _graph, const Arc& e) : 130 131 132 ArcIt& operator++() { 133 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 { 141 141 const Digraph* digraph; 142 142 public: … … 146 146 OutArcIt(Invalid i) : Arc(i) { } 147 147 148 OutArcIt(const Digraph& _graph, const Node& node) 149 150 151 } 152 153 OutArcIt(const Digraph& _graph, const Arc& arc) 154 155 156 OutArcIt& operator++() { 157 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 { 165 165 const Digraph* digraph; 166 166 public: … … 170 170 InArcIt(Invalid i) : Arc(i) { } 171 171 172 InArcIt(const Digraph& _graph, const Node& node) 173 174 175 } 176 177 InArcIt(const Digraph& _graph, const Arc& arc) : 178 179 180 InArcIt& operator++() { 181 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; 183 183 } 184 184 … … 216 216 217 217 // Mappable extension 218 218 219 219 template <typename _Value> 220 class ArcMap 220 class ArcMap 221 221 : public MapExtender<DefaultMap<Digraph, Arc, _Value> > { 222 222 typedef MapExtender<DefaultMap<Digraph, Arc, _Value> > Parent; 223 223 224 224 public: 225 explicit ArcMap(const Digraph& _g) 226 227 ArcMap(const Digraph& _g, const _Value& _v) 228 225 explicit ArcMap(const Digraph& _g) 226 : Parent(_g) {} 227 ArcMap(const Digraph& _g, const _Value& _v) 228 : Parent(_g, _v) {} 229 229 230 230 ArcMap& operator=(const ArcMap& cmap) { 231 231 return operator=<ArcMap>(cmap); 232 232 } 233 233 … … 235 235 ArcMap& operator=(const CMap& cmap) { 236 236 Parent::operator=(cmap); 237 237 return *this; 238 238 } 239 239 … … 248 248 return arc; 249 249 } 250 250 251 251 void clear() { 252 252 notifier(Arc()).clear(); … … 313 313 Node oppositeNode(const Node &n, const Edge &e) const { 314 314 if( n == Parent::u(e)) 315 315 return Parent::v(e); 316 316 else if( n == Parent::v(e)) 317 317 return Parent::u(e); 318 318 else 319 319 return INVALID; 320 320 } 321 321 … … 341 341 342 342 using Parent::notifier; 343 343 344 344 ArcNotifier& notifier(Arc) const { 345 345 return arc_notifier; … … 351 351 352 352 353 class NodeIt : public Node { 353 class NodeIt : public Node { 354 354 const Graph* graph; 355 355 public: … … 360 360 361 361 explicit NodeIt(const Graph& _graph) : graph(&_graph) { 362 363 } 364 365 NodeIt(const Graph& _graph, const Node& node) 366 367 368 NodeIt& operator++() { 369 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 { 377 377 const Graph* graph; 378 378 public: … … 383 383 384 384 explicit ArcIt(const Graph& _graph) : graph(&_graph) { 385 386 } 387 388 ArcIt(const Graph& _graph, const Arc& e) : 389 390 391 ArcIt& operator++() { 392 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 { 400 400 const Graph* graph; 401 401 public: … … 405 405 OutArcIt(Invalid i) : Arc(i) { } 406 406 407 OutArcIt(const Graph& _graph, const Node& node) 408 409 410 } 411 412 OutArcIt(const Graph& _graph, const Arc& arc) 413 414 415 OutArcIt& operator++() { 416 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 { 424 424 const Graph* graph; 425 425 public: … … 429 429 InArcIt(Invalid i) : Arc(i) { } 430 430 431 InArcIt(const Graph& _graph, const Node& node) 432 433 434 } 435 436 InArcIt(const Graph& _graph, const Arc& arc) : 437 438 439 InArcIt& operator++() { 440 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 { 448 448 const Graph* graph; 449 449 public: … … 454 454 455 455 explicit EdgeIt(const Graph& _graph) : graph(&_graph) { 456 457 } 458 459 EdgeIt(const Graph& _graph, const Edge& e) : 460 461 462 EdgeIt& operator++() { 463 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; 465 465 } 466 466 … … 478 478 479 479 IncEdgeIt(const Graph& _graph, const Node &n) : graph(&_graph) { 480 480 _graph.firstInc(*this, direction, n); 481 481 } 482 482 483 483 IncEdgeIt(const Graph& _graph, const Edge &ue, const Node &n) 484 485 484 : graph(&_graph), Edge(ue) { 485 direction = (_graph.source(ue) == n); 486 486 } 487 487 488 488 IncEdgeIt& operator++() { 489 490 return *this; 489 graph->nextInc(*this, direction); 490 return *this; 491 491 } 492 492 }; … … 535 535 536 536 template <typename _Value> 537 class ArcMap 537 class ArcMap 538 538 : public MapExtender<DefaultMap<Graph, Arc, _Value> > { 539 539 typedef MapExtender<DefaultMap<Graph, Arc, _Value> > Parent; 540 540 541 541 public: 542 explicit ArcMap(const Graph& _g) 543 544 ArcMap(const Graph& _g, const _Value& _v) 545 542 explicit ArcMap(const Graph& _g) 543 : Parent(_g) {} 544 ArcMap(const Graph& _g, const _Value& _v) 545 : Parent(_g, _v) {} 546 546 547 547 ArcMap& operator=(const ArcMap& cmap) { 548 548 return operator=<ArcMap>(cmap); 549 549 } 550 550 … … 552 552 ArcMap& operator=(const CMap& cmap) { 553 553 Parent::operator=(cmap); 554 554 return *this; 555 555 } 556 556 … … 559 559 560 560 template <typename _Value> 561 class EdgeMap 561 class EdgeMap 562 562 : public MapExtender<DefaultMap<Graph, Edge, _Value> > { 563 563 typedef MapExtender<DefaultMap<Graph, Edge, _Value> > Parent; 564 564 565 565 public: 566 explicit EdgeMap(const Graph& _g) 567 568 569 EdgeMap(const Graph& _g, const _Value& _v) 570 566 explicit EdgeMap(const Graph& _g) 567 : Parent(_g) {} 568 569 EdgeMap(const Graph& _g, const _Value& _v) 570 : Parent(_g, _v) {} 571 571 572 572 EdgeMap& operator=(const EdgeMap& cmap) { 573 573 return operator=<EdgeMap>(cmap); 574 574 } 575 575 … … 577 577 EdgeMap& operator=(const CMap& cmap) { 578 578 Parent::operator=(cmap); 579 579 return *this; 580 580 } 581 581 … … 594 594 return edge; 595 595 } 596 596 597 597 void clear() { 598 598 notifier(Arc()).clear(); … … 620 620 arc_notifier.clear(); 621 621 } 622 622 623 623 }; 624 624 -
TabularUnified lemon/bits/graph_adaptor_extender.h ¶
r965 r1081 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2011 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). -
TabularUnified lemon/bits/graph_extender.h ¶
r732 r825 57 57 } 58 58 59 Node fromId(int id, Node) const{59 static Node fromId(int id, Node) { 60 60 return Parent::nodeFromId(id); 61 61 } 62 62 63 Arc fromId(int id, Arc) const{63 static Arc fromId(int id, Arc) { 64 64 return Parent::arcFromId(id); 65 65 } … … 356 356 } 357 357 358 Node fromId(int id, Node) const{358 static Node fromId(int id, Node) { 359 359 return Parent::nodeFromId(id); 360 360 } 361 361 362 Arc fromId(int id, Arc) const{362 static Arc fromId(int id, Arc) { 363 363 return Parent::arcFromId(id); 364 364 } 365 365 366 Edge fromId(int id, Edge) const{366 static Edge fromId(int id, Edge) { 367 367 return Parent::edgeFromId(id); 368 368 } -
TabularUnified lemon/bits/path_dump.h ¶
r973 r1081 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2011 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). -
TabularUnified lemon/bits/solver_bits.h ¶
r566 r956 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 085 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). -
TabularUnified lemon/bits/windows.cc ¶
r1053 r1084 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2011 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 99 99 GetSystemTime(&time); 100 100 char buf1[11], buf2[9], buf3[5]; 101 101 if (GetDateFormat(MY_LOCALE, 0, &time, 102 102 ("ddd MMM dd"), buf1, 11) && 103 103 GetTimeFormat(MY_LOCALE, 0, &time, -
TabularUnified lemon/bucket_heap.h ¶
r730 r956 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 20 20 #define LEMON_BUCKET_HEAP_H 21 21 22 ///\ingroup auxdat22 ///\ingroup heaps 23 23 ///\file 24 ///\brief Bucket Heap implementation.24 ///\brief Bucket heap implementation. 25 25 26 26 #include <vector> … … 54 54 } 55 55 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 73 78 template <typename IM, bool MIN = true> 74 79 class BucketHeap { 75 80 76 81 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. 80 86 typedef int Prio; 81 /// \e82 typedef std::pair<Item, Prio> Pair;83 /// \e84 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; 85 91 86 92 private: … … 90 96 public: 91 97 92 /// \brief Type to represent the items states.93 /// 94 /// Each Item element have a state associated to it. It maybe "in heap",95 /// "pre heap" or "postheap". The latter two are indifferent from the98 /// \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 96 102 /// heap's point of view, but may be useful to the user. 97 103 /// … … 105 111 106 112 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. 113 120 explicit BucketHeap(ItemIntMap &map) : _iim(map), _minimum(0) {} 114 121 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. 118 125 int size() const { return _data.size(); } 119 126 120 /// \brief Check s 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. 123 130 bool empty() const { return _data.empty(); } 124 131 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. 131 139 void clear() { 132 140 _data.clear(); _first.clear(); _minimum = 0; … … 135 143 private: 136 144 137 void relocate _last(int idx) {145 void relocateLast(int idx) { 138 146 if (idx + 1 < int(_data.size())) { 139 147 _data[idx] = _data.back(); … … 175 183 176 184 public: 185 177 186 /// \brief Insert a pair of item and priority into the heap. 178 187 /// 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. 180 190 /// \param p The pair to insert. 191 /// \pre \c p.first must not be stored in the heap. 181 192 void push(const Pair& p) { 182 193 push(p.first, p.second); … … 185 196 /// \brief Insert an item into the heap with the given priority. 186 197 /// 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. 188 200 /// \param i The item to insert. 189 201 /// \param p The priority of the item. 202 /// \pre \e i must not be stored in the heap. 190 203 void push(const Item &i, const Prio &p) { 191 204 int idx = _data.size(); … … 198 211 } 199 212 200 /// \brief Return s the item withminimum priority.201 /// 202 /// This method returns the item withminimum priority.203 /// \pre The heap must be non empty.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. 204 217 Item top() const { 205 218 while (_first[_minimum] == -1) { … … 209 222 } 210 223 211 /// \brief Returns the minimum priority.212 /// 213 /// Itreturns the minimum priority.214 /// \pre The heap must be non empty.224 /// \brief The minimum priority. 225 /// 226 /// This function returns the minimum priority. 227 /// \pre The heap must be non-empty. 215 228 Prio prio() const { 216 229 while (_first[_minimum] == -1) { … … 220 233 } 221 234 222 /// \brief Deletes the item withminimum 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. 225 238 /// \pre The heap must be non-empty. 226 239 void pop() { … … 231 244 _iim[_data[idx].item] = -2; 232 245 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. 241 255 void erase(const Item &i) { 242 256 int idx = _iim[i]; 243 257 _iim[_data[idx].item] = -2; 244 258 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. 254 267 Prio operator[](const Item &i) const { 255 268 int idx = _iim[i]; … … 257 270 } 258 271 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. 264 278 /// \param i The item. 265 279 /// \param p The priority. … … 275 289 } 276 290 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. 282 294 /// \param i The item. 283 295 /// \param p The priority. 296 /// \pre \e i must be stored in the heap with priority at least \e p. 284 297 void decrease(const Item &i, const Prio &p) { 285 298 int idx = _iim[i]; … … 292 305 } 293 306 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. 299 310 /// \param i The item. 300 311 /// \param p The priority. 312 /// \pre \e i must be stored in the heap with priority at most \e p. 301 313 void increase(const Item &i, const Prio &p) { 302 314 int idx = _iim[i]; … … 306 318 } 307 319 308 /// \brief Return s if \c item is in, has already been in, or has309 /// never been in the heap.310 /// 311 /// This method returns PRE_HEAP if \c item has never been in the312 /// heap, IN_HEAP if it is in the heap at the moment, and POST_HEAP313 /// otherwise. In the latter case it is possible that \c item will314 /// get backto 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. 315 327 /// \param i The item. 316 328 State state(const Item &i) const { … … 320 332 } 321 333 322 /// \brief Set s the state of the \citem in the heap.323 /// 324 /// Sets the state of the \c item in the heap. It can be used to325 /// manually clear the heap when it is important to achive the326 /// 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. 327 339 /// \param i The item. 328 340 /// \param st The state. It should not be \c IN_HEAP. … … 360 372 }; // class BucketHeap 361 373 362 /// \ingroup auxdat363 /// 364 /// \brief A Simplified Bucket Heap implementation.374 /// \ingroup heaps 375 /// 376 /// \brief Simplified bucket heap data structure. 365 377 /// 366 378 /// 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. 379 397 /// 380 398 /// \sa BucketHeap … … 383 401 384 402 public: 385 typedef typename IM::Key Item; 403 404 /// Type of the item-int map. 405 typedef IM ItemIntMap; 406 /// Type of the priorities. 386 407 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; 389 412 390 413 private: … … 394 417 public: 395 418 396 /// \brief Type to represent the items states.397 /// 398 /// Each Item element have a state associated to it. It maybe "in heap",399 /// "pre heap" or "postheap". The latter two are indifferent from the419 /// \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 400 423 /// heap's point of view, but may be useful to the user. 401 424 /// … … 410 433 public: 411 434 412 /// \brief The constructor.413 /// 414 /// The constructor.415 /// \param map should be given to the constructor, since it is used416 /// internally to handle the cross references. The value of the map417 /// 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. 418 441 explicit SimpleBucketHeap(ItemIntMap &map) 419 442 : _iim(map), _free(-1), _num(0), _minimum(0) {} 420 443 421 /// \brief Returns the number of items stored in the heap.422 /// 423 /// Th e 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. 424 447 int size() const { return _num; } 425 448 426 /// \brief Check s 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. 429 452 bool empty() const { return _num == 0; } 430 453 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. 437 461 void clear() { 438 462 _data.clear(); _first.clear(); _free = -1; _num = 0; _minimum = 0; … … 441 465 /// \brief Insert a pair of item and priority into the heap. 442 466 /// 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. 444 469 /// \param p The pair to insert. 470 /// \pre \c p.first must not be stored in the heap. 445 471 void push(const Pair& p) { 446 472 push(p.first, p.second); … … 449 475 /// \brief Insert an item into the heap with the given priority. 450 476 /// 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. 452 479 /// \param i The item to insert. 453 480 /// \param p The priority of the item. 481 /// \pre \e i must not be stored in the heap. 454 482 void push(const Item &i, const Prio &p) { 455 483 int idx; … … 472 500 } 473 501 474 /// \brief Return s the item withminimum priority.475 /// 476 /// This method returns the item withminimum priority.477 /// \pre The heap must be non empty.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. 478 506 Item top() const { 479 507 while (_first[_minimum] == -1) { … … 483 511 } 484 512 485 /// \brief Returns the minimum priority.486 /// 487 /// Itreturns the minimum priority.488 /// \pre The heap must be non empty.513 /// \brief The minimum priority. 514 /// 515 /// This function returns the minimum priority. 516 /// \pre The heap must be non-empty. 489 517 Prio prio() const { 490 518 while (_first[_minimum] == -1) { … … 494 522 } 495 523 496 /// \brief Deletes the item withminimum 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. 499 527 /// \pre The heap must be non-empty. 500 528 void pop() { … … 510 538 } 511 539 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. 520 547 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) { 522 549 int idx = _first[k]; 523 550 while (idx != -1) { … … 531 558 } 532 559 533 /// \brief Return s if \c item is in, has already been in, or has534 /// never been in the heap.535 /// 536 /// This method returns PRE_HEAP if \c item has never been in the537 /// heap, IN_HEAP if it is in the heap at the moment, and POST_HEAP538 /// otherwise. In the latter case it is possible that \c item will539 /// get backto 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. 540 567 /// \param i The item. 541 568 State state(const Item &i) const { -
TabularUnified lemon/cbc.cc ¶
r1120 r1122 90 90 } 91 91 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 } 92 104 93 105 void CbcMip::_eraseCol(int i) { -
TabularUnified lemon/cbc.h ¶
r623 r956 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 63 63 virtual int _addCol(); 64 64 virtual int _addRow(); 65 virtual int _addRow(Value l, ExprIterator b, ExprIterator e, Value u); 65 66 66 67 virtual void _eraseCol(int i); … … 121 122 int _message_level; 122 123 123 124 124 125 125 126 }; -
TabularUnified lemon/circulation.h ¶
r735 r956 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 60 60 /// \brief The type of supply map. 61 61 /// 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. 64 64 /// It must conform to the \ref concepts::ReadMap "ReadMap" concept. 65 65 typedef SM SupplyMap; … … 73 73 /// It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap" 74 74 /// concept. 75 #ifdef DOXYGEN 76 typedef GR::ArcMap<Value> FlowMap; 77 #else 75 78 typedef typename Digraph::template ArcMap<Value> FlowMap; 79 #endif 76 80 77 81 /// \brief Instantiates a FlowMap. … … 88 92 /// The elevator type used by the algorithm. 89 93 /// 90 /// \sa Elevator 91 /// \sa LinkedElevator 94 /// \sa Elevator, LinkedElevator 95 #ifdef DOXYGEN 96 typedef lemon::Elevator<GR, GR::Node> Elevator; 97 #else 92 98 typedef lemon::Elevator<Digraph, typename Digraph::Node> Elevator; 99 #endif 93 100 94 101 /// \brief Instantiates an Elevator. … … 135 142 \geq sup(u) \quad \forall u\in V, \f] 136 143 \f[ lower(uv) \leq f(uv) \leq upper(uv) \quad \forall uv\in A. \f] 137 144 138 145 The sum of the supply values, i.e. \f$\sum_{u\in V} sup(u)\f$ must be 139 146 zero or negative in order to have a feasible solution (since the sum … … 145 152 constraints have to be satisfied with equality, i.e. all demands 146 153 have to be satisfied and all supplies have to be used. 147 154 148 155 If you need the opposite inequalities in the supply/demand constraints 149 156 (i.e. the total demand is less than the total supply and all the demands … … 167 174 \tparam SM The type of the supply map. The default map type is 168 175 \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. 169 181 */ 170 182 #ifdef DOXYGEN … … 300 312 /// able to automatically created by the algorithm (i.e. the 301 313 /// digraph and the maximum level should be passed to it). 302 /// However an external elevator object could also be passed to the314 /// However, an external elevator object could also be passed to the 303 315 /// algorithm with the \ref elevator(Elevator&) "elevator()" function 304 316 /// before calling \ref run() or \ref init(). … … 326 338 /// \param graph The digraph the algorithm runs on. 327 339 /// \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 329 341 /// on the arcs. 330 342 /// \param supply The signed supply values of the nodes. … … 451 463 } 452 464 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> 456 469 Circulation& tolerance(const Tolerance& tolerance) { 457 470 _tol = tolerance; … … 461 474 /// \brief Returns a const reference to the tolerance. 462 475 /// 463 /// Returns a const reference to the tolerance. 476 /// Returns a const reference to the tolerance object used by 477 /// the algorithm. 464 478 const Tolerance& tolerance() const { 465 479 return _tol; … … 468 482 /// \name Execution Control 469 483 /// The simplest way to execute the algorithm is to call \ref run().\n 470 /// If you need morecontrol on the initial solution or the execution,471 /// first you have to call one of the \ref init() functions, then484 /// 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 472 486 /// the \ref start() function. 473 487 -
TabularUnified lemon/clp.cc ¶
r623 r956 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 085 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 76 76 int ClpLp::_addRow() { 77 77 _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); 78 91 return _prob->numberRows() - 1; 79 92 } -
TabularUnified lemon/clp.h ¶
r623 r956 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 085 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 76 76 virtual int _addCol(); 77 77 virtual int _addRow(); 78 virtual int _addRow(Value l, ExprIterator b, ExprIterator e, Value u); 78 79 79 80 virtual void _eraseCol(int i); … … 138 139 139 140 virtual void _messageLevel(MessageLevel); 140 141 141 142 public: 142 143 -
TabularUnified lemon/concepts/digraph.h ¶
r627 r956 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 36 36 /// \brief Class describing the concept of directed graphs. 37 37 /// 38 /// This class describes the \ref concept "concept" of the39 /// immutable directed digraphs.38 /// This class describes the common interface of all directed 39 /// graphs (digraphs). 40 40 /// 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. 43 47 /// 44 /// \sa concept48 /// \sa Graph 45 49 class Digraph { 46 50 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. 58 55 void operator=(const Digraph &) {} 56 59 57 public: 60 ///\e 61 62 /// Defalult constructor. 63 64 /// Defalult constructor. 65 /// 58 /// Default constructor. 66 59 Digraph() { } 67 /// Class for identifying a node of the digraph 60 61 /// The node type of the digraph 68 62 69 63 /// This class identifies a node of the digraph. It also serves 70 64 /// as a base class of the node iterators, 71 /// thus they willconvert to this type.65 /// thus they convert to this type. 72 66 class Node { 73 67 public: 74 68 /// Default constructor 75 69 76 /// @warning The default constructor sets the iterator77 /// to an undefined value.70 /// Default constructor. 71 /// \warning It sets the object to an undefined value. 78 72 Node() { } 79 73 /// Copy constructor. … … 83 77 Node(const Node&) { } 84 78 85 /// Invalid constructor \& conversion.86 87 /// This constructor initializes the iteratorto be invalid.79 /// %Invalid constructor \& conversion. 80 81 /// Initializes the object to be invalid. 88 82 /// \sa Invalid for more details. 89 83 Node(Invalid) { } 90 84 /// Equality operator 91 85 86 /// Equality operator. 87 /// 92 88 /// 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. 94 90 bool operator==(Node) const { return true; } 95 91 96 92 /// Inequality operator 97 93 98 /// \sa operator==(Node n) 99 /// 94 /// Inequality operator. 100 95 bool operator!=(Node) const { return true; } 101 96 102 97 /// Artificial ordering operator. 103 98 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. 110 104 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: 119 112 ///\code 120 113 /// int count=0; … … 125 118 /// Default constructor 126 119 127 /// @warning The default constructor sets the iterator128 /// to an undefined value.120 /// Default constructor. 121 /// \warning It sets the iterator to an undefined value. 129 122 NodeIt() { } 130 123 /// Copy constructor. … … 133 126 /// 134 127 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. 138 131 /// \sa Invalid for more details. 139 132 NodeIt(Invalid) { } 140 133 /// Sets the iterator to the first node. 141 134 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 /// 151 142 NodeIt(const Digraph&, const Node&) { } 152 143 /// Next node. … … 158 149 159 150 160 /// Class for identifying an arcof the digraph151 /// The arc type of the digraph 161 152 162 153 /// This class identifies an arc of the digraph. It also serves … … 167 158 /// Default constructor 168 159 169 /// @warning The default constructor sets the iterator170 /// to an undefined value.160 /// Default constructor. 161 /// \warning It sets the object to an undefined value. 171 162 Arc() { } 172 163 /// Copy constructor. … … 175 166 /// 176 167 Arc(const Arc&) { } 177 /// Initialize the iterator to be invalid.178 179 /// Initialize the iteratorto be invalid.180 /// 168 /// %Invalid constructor \& conversion. 169 170 /// Initializes the object to be invalid. 171 /// \sa Invalid for more details. 181 172 Arc(Invalid) { } 182 173 /// Equality operator 183 174 175 /// Equality operator. 176 /// 184 177 /// 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. 186 179 bool operator==(Arc) const { return true; } 187 180 /// Inequality operator 188 181 189 /// \sa operator==(Arc n) 190 /// 182 /// Inequality operator. 191 183 bool operator!=(Arc) const { return true; } 192 184 193 185 /// Artificial ordering operator. 194 186 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. 201 192 bool operator<(Arc) const { return false; } 202 193 }; 203 194 204 /// This iterator goes troughthe outgoing arcs of a node.195 /// Iterator class for the outgoing arcs of a node. 205 196 206 197 /// This iterator goes trough the \e outgoing arcs of a certain node 207 198 /// of a digraph. 208 /// Its usage is quite simple, for example you can count the number199 /// Its usage is quite simple, for example, you can count the number 209 200 /// of outgoing arcs of a node \c n 210 /// in digraph \c g of type \cDigraph as follows.201 /// in a digraph \c g of type \c %Digraph as follows. 211 202 ///\code 212 203 /// 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; 214 205 ///\endcode 215 216 206 class OutArcIt : public Arc { 217 207 public: 218 208 /// Default constructor 219 209 220 /// @warning The default constructor sets the iterator221 /// to an undefined value.210 /// Default constructor. 211 /// \warning It sets the iterator to an undefined value. 222 212 OutArcIt() { } 223 213 /// Copy constructor. … … 226 216 /// 227 217 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. 232 222 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 of236 /// 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 /// 237 227 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 /// 243 232 OutArcIt(const Digraph&, const Arc&) { } 244 /// Next outgoing arc233 /// Next outgoing arc 245 234 246 235 /// Assign the iterator to the next … … 249 238 }; 250 239 251 /// This iterator goes troughthe incoming arcs of a node.240 /// Iterator class for the incoming arcs of a node. 252 241 253 242 /// This iterator goes trough the \e incoming arcs of a certain node 254 243 /// of a digraph. 255 /// Its usage is quite simple, for example you can count the number256 /// of outgoing arcs of a node \c n257 /// in digraph \c g of type \cDigraph 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. 258 247 ///\code 259 248 /// 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; 261 250 ///\endcode 262 263 251 class InArcIt : public Arc { 264 252 public: 265 253 /// Default constructor 266 254 267 /// @warning The default constructor sets the iterator268 /// to an undefined value.255 /// Default constructor. 256 /// \warning It sets the iterator to an undefined value. 269 257 InArcIt() { } 270 258 /// Copy constructor. … … 273 261 /// 274 262 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. 279 267 InArcIt(Invalid) { } 280 /// This constructor sets the iterator tofirst incoming arc.281 282 /// This constructor set the iterator to the first incoming arc of283 /// 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 /// 284 272 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 /// 290 277 InArcIt(const Digraph&, const Arc&) { } 291 278 /// Next incoming arc 292 279 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. 295 282 InArcIt& operator++() { return *this; } 296 283 }; 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: 302 290 ///\code 303 291 /// int count=0; 304 /// for(Digraph::ArcIt e(g); e!=INVALID; ++e) ++count;292 /// for(Digraph::ArcIt a(g); a!=INVALID; ++a) ++count; 305 293 ///\endcode 306 294 class ArcIt : public Arc { … … 308 296 /// Default constructor 309 297 310 /// @warning The default constructor sets the iterator311 /// to an undefined value.298 /// Default constructor. 299 /// \warning It sets the iterator to an undefined value. 312 300 ArcIt() { } 313 301 /// Copy constructor. … … 316 304 /// 317 305 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. 322 310 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 /// 333 320 ArcIt(const Digraph&, const Arc&) { } 334 /// Next arc321 /// Next arc 335 322 336 323 /// Assign the iterator to the next arc. 324 /// 337 325 ArcIt& operator++() { return *this; } 338 326 }; 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. 343 336 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. 351 341 int id(Node) const { return -1; } 352 342 353 /// \brief Returns the ID of the arc. 343 /// \brief The ID of the arc. 344 /// 345 /// Returns the ID of the given arc. 354 346 int id(Arc) const { return -1; } 355 347 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. 359 352 Node nodeFromId(int) const { return INVALID; } 360 353 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. 364 358 Arc arcFromId(int) const { return INVALID; } 365 359 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. 367 363 int maxNodeId() const { return -1; } 368 364 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. 370 368 int maxArcId() const { return -1; } 371 369 … … 393 391 int maxId(Arc) const { return -1; } 394 392 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 395 398 /// \brief The base node of the iterator. 396 399 /// 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; } 400 403 401 404 /// \brief The running node of the iterator. 402 405 /// 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; } 406 409 407 410 /// \brief The base node of the iterator. 408 411 /// 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; } 412 415 413 416 /// \brief The running node of the iterator. 414 417 /// 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. 427 426 template<class T> 428 427 class NodeMap : public ReferenceMap<Node, T, T&, const T&> { 429 428 public: 430 429 431 /// \e432 NodeMap(const Digraph&) { }433 /// \e430 /// Constructor 431 explicit NodeMap(const Digraph&) { } 432 /// Constructor with given initial value 434 433 NodeMap(const Digraph&, T) { } 435 434 436 435 private: 437 436 ///Copy constructor 438 NodeMap(const NodeMap& nm) : 437 NodeMap(const NodeMap& nm) : 439 438 ReferenceMap<Node, T, T&, const T&>(nm) { } 440 439 ///Assignment operator … … 446 445 }; 447 446 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. 451 451 template<class T> 452 452 class ArcMap : public ReferenceMap<Arc, T, T&, const T&> { 453 453 public: 454 454 455 /// \e456 ArcMap(const Digraph&) { }457 /// \e455 /// Constructor 456 explicit ArcMap(const Digraph&) { } 457 /// Constructor with given initial value 458 458 ArcMap(const Digraph&, T) { } 459 459 460 private: 460 461 ///Copy constructor -
TabularUnified lemon/concepts/graph.h ¶
r704 r956 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 19 19 ///\ingroup graph_concepts 20 20 ///\file 21 ///\brief The concept of Undirected Graphs.21 ///\brief The concept of undirected graphs. 22 22 23 23 #ifndef LEMON_CONCEPTS_GRAPH_H … … 25 25 26 26 #include <lemon/concepts/graph_components.h> 27 #include <lemon/concepts/maps.h> 28 #include <lemon/concept_check.h> 27 29 #include <lemon/core.h> 28 30 … … 32 34 /// \ingroup graph_concepts 33 35 /// 34 /// \brief Class describing the concept of Undirected Graphs.36 /// \brief Class describing the concept of undirected graphs. 35 37 /// 36 /// This class describes the common interface of all Undirected37 /// Graphs.38 /// This class describes the common interface of all undirected 39 /// graphs. 38 40 /// 39 /// As all concept describing classes it provides onlyinterface40 /// without any sensible implementation. So any algorithm for41 /// undirected graph should compile with this class, but it will not41 /// 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 42 44 /// run properly, of course. 45 /// An actual graph implementation like \ref ListGraph or 46 /// \ref SmartGraph may have additional functionality. 43 47 /// 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. 53 61 /// 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. 61 68 /// 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 68 73 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 69 81 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 75 90 /// specializations for undirected graphs. 76 91 typedef True UndirectedTag; 77 92 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. 85 98 class Node { 86 99 public: 87 100 /// Default constructor 88 101 89 /// @warning The default constructor sets the iterator90 /// to an undefined value.102 /// Default constructor. 103 /// \warning It sets the object to an undefined value. 91 104 Node() { } 92 105 /// Copy constructor. … … 96 109 Node(const Node&) { } 97 110 98 /// Invalid constructor \& conversion.99 100 /// This constructor initializes the iteratorto be invalid.111 /// %Invalid constructor \& conversion. 112 113 /// Initializes the object to be invalid. 101 114 /// \sa Invalid for more details. 102 115 Node(Invalid) { } 103 116 /// Equality operator 104 117 118 /// Equality operator. 119 /// 105 120 /// 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. 107 122 bool operator==(Node) const { return true; } 108 123 109 124 /// Inequality operator 110 125 111 /// \sa operator==(Node n) 112 /// 126 /// Inequality operator. 113 127 bool operator!=(Node) const { return true; } 114 128 115 129 /// Artificial ordering operator. 116 130 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 121 134 /// the items; this order has nothing to do with the iteration 122 135 /// ordering of the items. … … 125 138 }; 126 139 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 number131 /// of nodes in graph \c g of type \cGraph 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: 132 145 ///\code 133 146 /// int count=0; … … 138 151 /// Default constructor 139 152 140 /// @warning The default constructor sets the iterator141 /// to an undefined value.153 /// Default constructor. 154 /// \warning It sets the iterator to an undefined value. 142 155 NodeIt() { } 143 156 /// Copy constructor. … … 146 159 /// 147 160 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. 151 164 /// \sa Invalid for more details. 152 165 NodeIt(Invalid) { } 153 166 /// Sets the iterator to the first node. 154 167 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 /// 164 175 NodeIt(const Graph&, const Node&) { } 165 176 /// Next node. … … 171 182 172 183 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. 177 189 class Edge { 178 190 public: 179 191 /// Default constructor 180 192 181 /// @warning The default constructor sets the iterator182 /// to an undefined value.193 /// Default constructor. 194 /// \warning It sets the object to an undefined value. 183 195 Edge() { } 184 196 /// Copy constructor. … … 187 199 /// 188 200 Edge(const Edge&) { } 189 /// Initialize the iterator to be invalid.190 191 /// Initialize the iteratorto be invalid.192 /// 201 /// %Invalid constructor \& conversion. 202 203 /// Initializes the object to be invalid. 204 /// \sa Invalid for more details. 193 205 Edge(Invalid) { } 194 206 /// Equality operator 195 207 208 /// Equality operator. 209 /// 196 210 /// 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. 198 212 bool operator==(Edge) const { return true; } 199 213 /// Inequality operator 200 214 201 /// \sa operator==(Edge n) 202 /// 215 /// Inequality operator. 203 216 bool operator!=(Edge) const { return true; } 204 217 205 218 /// Artificial ordering operator. 206 219 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. 213 225 bool operator<(Edge) const { return false; } 214 226 }; 215 227 216 /// This iterator goes through each edge.217 218 /// This iterator goes through each edge of agraph.219 /// Its usage is quite simple, for example you can count the number220 /// 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: 221 233 ///\code 222 234 /// int count=0; … … 227 239 /// Default constructor 228 240 229 /// @warning The default constructor sets the iterator230 /// to an undefined value.241 /// Default constructor. 242 /// \warning It sets the iterator to an undefined value. 231 243 EdgeIt() { } 232 244 /// Copy constructor. … … 235 247 /// 236 248 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. 241 253 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 /// 252 263 EdgeIt(const Graph&, const Edge&) { } 253 264 /// Next edge 254 265 255 266 /// Assign the iterator to the next edge. 267 /// 256 268 EdgeIt& operator++() { return *this; } 257 269 }; 258 270 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. 269 278 /// 270 279 ///\code … … 272 281 /// for(Graph::IncEdgeIt e(g, n); e!=INVALID; ++e) ++count; 273 282 ///\endcode 283 /// 284 /// \warning Loop edges will be iterated twice. 274 285 class IncEdgeIt : public Edge { 275 286 public: 276 287 /// Default constructor 277 288 278 /// @warning The default constructor sets the iterator279 /// to an undefined value.289 /// Default constructor. 290 /// \warning It sets the iterator to an undefined value. 280 291 IncEdgeIt() { } 281 292 /// Copy constructor. … … 284 295 /// 285 296 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. 290 301 IncEdgeIt(Invalid) { } 291 /// This constructor sets the iterator to first incident arc.292 293 /// This constructor set the iterator to the first incident arc of294 /// 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 /// 295 306 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 /// 301 311 IncEdgeIt(const Graph&, const Edge&) { } 302 /// Next incident arc303 304 /// Assign the iterator to the next incident arc312 /// Next incident edge 313 314 /// Assign the iterator to the next incident edge 305 315 /// of the corresponding node. 306 316 IncEdgeIt& operator++() { return *this; } 307 317 }; 308 318 309 /// The directed arc type.310 311 /// Th e directed arc type. It can be converted to the312 /// edge or it should be inherited from the undirected313 /// 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. 314 324 class Arc { 315 325 public: 316 326 /// Default constructor 317 327 318 /// @warning The default constructor sets the iterator319 /// to an undefined value.328 /// Default constructor. 329 /// \warning It sets the object to an undefined value. 320 330 Arc() { } 321 331 /// Copy constructor. … … 324 334 /// 325 335 Arc(const Arc&) { } 326 /// Initialize the iterator to be invalid.327 328 /// Initialize the iteratorto be invalid.329 /// 336 /// %Invalid constructor \& conversion. 337 338 /// Initializes the object to be invalid. 339 /// \sa Invalid for more details. 330 340 Arc(Invalid) { } 331 341 /// Equality operator 332 342 343 /// Equality operator. 344 /// 333 345 /// 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. 335 347 bool operator==(Arc) const { return true; } 336 348 /// Inequality operator 337 349 338 /// \sa operator==(Arc n) 339 /// 350 /// Inequality operator. 340 351 bool operator!=(Arc) const { return true; } 341 352 342 353 /// Artificial ordering operator. 343 354 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. 350 360 bool operator<(Arc) const { return false; } 351 361 352 /// Converison to Edge 362 /// Converison to \c Edge 363 364 /// Converison to \c Edge. 365 /// 353 366 operator Edge() const { return Edge(); } 354 367 }; 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: 360 374 ///\code 361 375 /// int count=0; 362 /// for(Graph::ArcIt e(g); e!=INVALID; ++e) ++count;376 /// for(Graph::ArcIt a(g); a!=INVALID; ++a) ++count; 363 377 ///\endcode 364 378 class ArcIt : public Arc { … … 366 380 /// Default constructor 367 381 368 /// @warning The default constructor sets the iterator369 /// to an undefined value.382 /// Default constructor. 383 /// \warning It sets the iterator to an undefined value. 370 384 ArcIt() { } 371 385 /// Copy constructor. … … 374 388 /// 375 389 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. 380 394 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 /// 391 404 ArcIt(const Graph&, const Arc&) { } 392 /// Next arc405 /// Next arc 393 406 394 407 /// Assign the iterator to the next arc. 408 /// 395 409 ArcIt& operator++() { return *this; } 396 410 }; 397 411 398 /// This iterator goes trough the outgoing directedarcs of a node.399 400 /// This iterator goes trough the \e outgoing arcs of a certain node401 /// of a graph.402 /// Its usage is quite simple, for example you can count the number412 /// 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 403 417 /// of outgoing arcs of a node \c n 404 /// in graph \c g of type \cGraph as follows.418 /// in a graph \c g of type \c %Graph as follows. 405 419 ///\code 406 420 /// 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; 408 422 ///\endcode 409 410 423 class OutArcIt : public Arc { 411 424 public: 412 425 /// Default constructor 413 426 414 /// @warning The default constructor sets the iterator415 /// to an undefined value.427 /// Default constructor. 428 /// \warning It sets the iterator to an undefined value. 416 429 OutArcIt() { } 417 430 /// Copy constructor. … … 420 433 /// 421 434 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. 426 439 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 /// 433 444 OutArcIt(const Graph& n, const Node& g) { 434 445 ignore_unused_variable_warning(n); 435 446 ignore_unused_variable_warning(g); 436 447 } 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 /// 442 452 OutArcIt(const Graph&, const Arc&) { } 443 /// Next outgoing arc453 /// Next outgoing arc 444 454 445 455 /// Assign the iterator to the next … … 448 458 }; 449 459 450 /// This iterator goes trough the incoming directedarcs of a node.451 452 /// This iterator goes trough the \e incoming arcs of a certain node453 /// of a graph.454 /// Its usage is quite simple, for example you can count the number455 /// of outgoing arcs of a node \c n456 /// in graph \c g of type \cGraph 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. 457 467 ///\code 458 468 /// 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; 460 470 ///\endcode 461 462 471 class InArcIt : public Arc { 463 472 public: 464 473 /// Default constructor 465 474 466 /// @warning The default constructor sets the iterator467 /// to an undefined value.475 /// Default constructor. 476 /// \warning It sets the iterator to an undefined value. 468 477 InArcIt() { } 469 478 /// Copy constructor. … … 472 481 /// 473 482 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. 478 487 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 /// 485 492 InArcIt(const Graph& g, const Node& n) { 486 493 ignore_unused_variable_warning(n); 487 494 ignore_unused_variable_warning(g); 488 495 } 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 /// 494 500 InArcIt(const Graph&, const Arc&) { } 495 501 /// Next incoming arc 496 502 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. 499 505 InArcIt& operator++() { return *this; } 500 506 }; 501 507 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. 505 512 template<class T> 506 513 class NodeMap : public ReferenceMap<Node, T, T&, const T&> … … 508 515 public: 509 516 510 /// \e511 NodeMap(const Graph&) { }512 /// \e517 /// Constructor 518 explicit NodeMap(const Graph&) { } 519 /// Constructor with given initial value 513 520 NodeMap(const Graph&, T) { } 514 521 … … 525 532 }; 526 533 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. 530 538 template<class T> 531 539 class ArcMap : public ReferenceMap<Arc, T, T&, const T&> … … 533 541 public: 534 542 535 /// \e536 ArcMap(const Graph&) { }537 /// \e543 /// Constructor 544 explicit ArcMap(const Graph&) { } 545 /// Constructor with given initial value 538 546 ArcMap(const Graph&, T) { } 547 539 548 private: 540 549 ///Copy constructor … … 549 558 }; 550 559 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. 554 564 template<class T> 555 565 class EdgeMap : public ReferenceMap<Edge, T, T&, const T&> … … 557 567 public: 558 568 559 /// \e560 EdgeMap(const Graph&) { }561 /// \e569 /// Constructor 570 explicit EdgeMap(const Graph&) { } 571 /// Constructor with given initial value 562 572 EdgeMap(const Graph&, T) { } 573 563 574 private: 564 575 ///Copy constructor … … 573 584 }; 574 585 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. 619 595 /// \sa v() 620 596 /// \sa direction() 621 597 Node u(Edge) const { return INVALID; } 622 598 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. 633 608 /// \sa u() 634 609 /// \sa direction() 635 610 Node v(Edge) const { return INVALID; } 636 611 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. 638 615 Node source(Arc) const { return INVALID; } 639 616 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. 641 620 Node target(Arc) const { return INVALID; } 642 621 643 /// \brief Returns the id of the node. 622 /// \brief The ID of the node. 623 /// 624 /// Returns the ID of the given node. 644 625 int id(Node) const { return -1; } 645 626 646 /// \brief Returns the id of the edge. 627 /// \brief The ID of the edge. 628 /// 629 /// Returns the ID of the given edge. 647 630 int id(Edge) const { return -1; } 648 631 649 /// \brief Returns the id of the arc. 632 /// \brief The ID of the arc. 633 /// 634 /// Returns the ID of the given arc. 650 635 int id(Arc) const { return -1; } 651 636 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. 655 641 Node nodeFromId(int) const { return INVALID; } 656 642 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. 660 647 Edge edgeFromId(int) const { return INVALID; } 661 648 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. 665 653 Arc arcFromId(int) const { return INVALID; } 666 654 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. 668 658 int maxNodeId() const { return -1; } 669 659 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. 671 663 int maxEdgeId() const { return -1; } 672 664 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. 674 668 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; } 675 703 676 704 void first(Node&) const {} … … 706 734 int maxId(Arc) const { return -1; } 707 735 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; } 749 769 750 770 template <typename _Graph> -
TabularUnified lemon/concepts/graph_components.h ¶
r713 r956 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 19 19 ///\ingroup graph_concepts 20 20 ///\file 21 ///\brief The concept of graph components.21 ///\brief The concepts of graph components. 22 22 23 23 #ifndef LEMON_CONCEPTS_GRAPH_COMPONENTS_H … … 39 39 /// \note This class is a template class so that we can use it to 40 40 /// 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 42 42 /// base class. For \c Node you should instantiate it with character 43 43 /// \c 'n', for \c Arc with \c 'a' and for \c Edge with \c 'e'. … … 90 90 /// 91 91 /// 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 93 93 /// associative containers (e.g. \c std::map). 94 94 /// 95 /// \note This operator only ha veto define some strict ordering of95 /// \note This operator only has to define some strict ordering of 96 96 /// the items; this order has nothing to do with the iteration 97 97 /// ordering of the items. … … 123 123 /// This class describes the base interface of directed graph types. 124 124 /// 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 126 126 /// to get the source and the target nodes of arcs. 127 127 class BaseDigraphComponent { … … 427 427 /// \brief Concept class for \c NodeIt, \c ArcIt and \c EdgeIt types. 428 428 /// 429 /// This class describes the concept of \c NodeIt, \c ArcIt and 429 /// This class describes the concept of \c NodeIt, \c ArcIt and 430 430 /// \c EdgeIt subtypes of digraph and graph types. 431 431 template <typename GR, typename Item> … … 467 467 /// next item. 468 468 GraphItemIt& operator++() { return *this; } 469 469 470 470 /// \brief Equality operator 471 471 /// … … 502 502 }; 503 503 504 /// \brief Concept class for \c InArcIt, \c OutArcIt and 504 /// \brief Concept class for \c InArcIt, \c OutArcIt and 505 505 /// \c IncEdgeIt types. 506 506 /// 507 /// This class describes the concept of \c InArcIt, \c OutArcIt 507 /// This class describes the concept of \c InArcIt, \c OutArcIt 508 508 /// and \c IncEdgeIt subtypes of digraph and graph types. 509 509 /// 510 510 /// \note Since these iterator classes do not inherit from the same 511 511 /// 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 513 513 /// \c 'i', for \c OutArcIt with \c 'o' and for \c IncEdgeIt with \c 'e'. 514 514 template <typename GR, … … 531 531 GraphIncIt(const GraphIncIt& it) : Item(it) {} 532 532 533 /// \brief Constructor that sets the iterator to the first 533 /// \brief Constructor that sets the iterator to the first 534 534 /// incoming or outgoing arc. 535 535 /// 536 /// Constructor that sets the iterator to the first arc 536 /// Constructor that sets the iterator to the first arc 537 537 /// incoming to or outgoing from the given node. 538 538 explicit GraphIncIt(const GR&, const Base&) {} … … 805 805 /// \brief Return the first edge incident to the given node. 806 806 /// 807 /// This function gives back the first edge incident to the given 807 /// This function gives back the first edge incident to the given 808 808 /// 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 810 810 /// given node. 811 811 void firstInc(Edge&, bool&, const Node&) const {} … … 814 814 /// given node. 815 815 /// 816 /// This function gives back the next edge incident to the given 816 /// This function gives back the next edge incident to the given 817 817 /// node. The bool parameter should be used as \c firstInc() use it. 818 818 void nextInc(Edge&, bool&) const {} … … 991 991 /// 992 992 /// 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 994 994 /// graph types, which can be used for associating data to graph items. 995 995 /// The standard graph maps must conform to the ReferenceMap concept. … … 1046 1046 _Map m1(g); 1047 1047 _Map m2(g,t); 1048 1048 1049 1049 // Copy constructor 1050 1050 // _Map m3(m); … … 1069 1069 /// 1070 1070 /// 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 1072 1072 /// map classes, namely \c NodeMap and \c ArcMap. 1073 1073 /// This concept is part of the Digraph concept. … … 1206 1206 /// 1207 1207 /// 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 1209 1209 /// map class for edges (\c EdgeMap). 1210 1210 /// This concept is part of the Graph concept. … … 1291 1291 /// 1292 1292 /// 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 1294 1294 /// nodes and arcs to the digraph. 1295 1295 /// This concept requires \ref AlterableDigraphComponent. … … 1335 1335 /// 1336 1336 /// 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 1338 1338 /// nodes and edges to the graph. 1339 1339 /// This concept requires \ref AlterableGraphComponent. … … 1379 1379 /// 1380 1380 /// 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 1382 1382 /// nodes and arcs from the digraph. 1383 1383 /// This concept requires \ref AlterableDigraphComponent. … … 1392 1392 /// \brief Erase a node from the digraph. 1393 1393 /// 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 1395 1395 /// connected to the node. 1396 1396 void erase(const Node&) {} … … 1418 1418 /// 1419 1419 /// 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 1421 1421 /// nodes and edges from the graph. 1422 1422 /// This concept requires \ref AlterableGraphComponent. -
TabularUnified lemon/concepts/heap.h ¶
r631 r956 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 17 17 */ 18 18 19 #ifndef LEMON_CONCEPTS_HEAP_H 20 #define LEMON_CONCEPTS_HEAP_H 21 19 22 ///\ingroup concept 20 23 ///\file 21 24 ///\brief The concept of heaps. 22 25 23 #ifndef LEMON_CONCEPTS_HEAP_H24 #define LEMON_CONCEPTS_HEAP_H25 26 26 #include <lemon/core.h> 27 27 #include <lemon/concept_check.h> … … 36 36 /// \brief The heap concept. 37 37 /// 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. 43 45 /// 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 46 52 /// internally to handle the cross references. 47 /// \tparam C omp A functor class for the ordering ofthe priorities.53 /// \tparam CMP A functor class for comparing the priorities. 48 54 /// The default is \c std::less<PR>. 49 55 #ifdef DOXYGEN 50 template <typename PR, typename IM, typename C omp = 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> > 53 59 #endif 54 60 class Heap { … … 65 71 /// 66 72 /// 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. 70 75 /// 71 76 /// The item-int map must be initialized in such way that it assigns … … 73 78 enum State { 74 79 IN_HEAP = 0, ///< = 0. The "in heap" state constant. 75 PRE_HEAP = -1, ///< = -1. The "pre 76 POST_HEAP = -2 ///< = -2. The "post 80 PRE_HEAP = -1, ///< = -1. The "pre-heap" state constant. 81 POST_HEAP = -2 ///< = -2. The "post-heap" state constant. 77 82 }; 78 83 79 /// \brief The constructor.80 /// 81 /// The constructor.84 /// \brief Constructor. 85 /// 86 /// Constructor. 82 87 /// \param map A map that assigns \c int values to keys of type 83 88 /// \c Item. It is used internally by the heap implementations to 84 89 /// 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 86 92 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 87 110 88 111 /// \brief The number of items stored in the heap. 89 112 /// 90 /// Returns the number of items stored in the heap.113 /// This function returns the number of items stored in the heap. 91 114 int size() const { return 0; } 92 115 93 /// \brief Check sif 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. 96 119 bool empty() const { return false; } 97 120 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. 106 134 /// \param i The item to insert. 107 135 /// \param p The priority of the item. 136 /// \pre \e i must not be stored in the heap. 137 #ifdef DOXYGEN 108 138 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. 113 146 /// \pre The heap must be non-empty. 114 Item top() const { }147 Item top() const { return Item(); } 115 148 116 149 /// \brief The minimum priority. 117 150 /// 118 /// Returns the minimum priority.151 /// This function returns the minimum priority. 119 152 /// \pre The heap must be non-empty. 120 Prio prio() const { }121 122 /// \brief Remove sthe 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. 125 158 /// \pre The heap must be non-empty. 126 159 void pop() {} 127 160 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. 131 165 /// \param i The item to delete. 166 /// \pre \e i must be in the heap. 167 #ifdef DOXYGEN 132 168 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 139 179 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 142 185 /// not stored in the heap. 143 186 /// 144 187 /// This method sets the priority of the given item if it is 145 /// already stored in the heap. 146 /// Otherwise it inserts the given itemwith the given priority.188 /// already stored in the heap. Otherwise it inserts the given 189 /// item into the heap with the given priority. 147 190 /// 148 191 /// \param i The item. 149 192 /// \param p The priority. 193 #ifdef DOXYGEN 150 194 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. 155 202 /// \param i The item. 156 203 /// \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 158 206 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. 163 214 /// \param i The item. 164 215 /// \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 166 218 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. 170 224 /// 171 225 /// This method returns \c PRE_HEAP if the given item has never … … 175 229 /// to the heap again. 176 230 /// \param i The item. 231 #ifdef DOXYGEN 177 232 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. 184 242 /// \param i The item. 185 243 /// \param st The state. It should not be \c IN_HEAP. 244 #ifdef DOXYGEN 186 245 void state(const Item& i, State st) {} 246 #else 247 void state(const Item&, State) {} 248 #endif 187 249 188 250 -
TabularUnified lemon/concepts/path.h ¶
r606 r832 19 19 ///\ingroup concept 20 20 ///\file 21 ///\brief Classes for representing paths in digraphs.21 ///\brief The concept of paths 22 22 /// 23 23 … … 39 39 /// A skeleton structure for representing directed paths in a 40 40 /// 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 /// 41 56 /// \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. The44 /// lemon path type stores just this list. As a consequence it45 /// cannot enumerate the nodes in the path and the zero length46 /// paths cannot store the source.47 ///48 57 template <typename GR> 49 58 class Path { … … 60 69 Path() {} 61 70 62 /// \brief Template co nstructor71 /// \brief Template copy constructor 63 72 template <typename CPath> 64 73 Path(const CPath& cpath) {} 65 74 66 /// \brief Template assigment 75 /// \brief Template assigment operator 67 76 template <typename CPath> 68 77 Path& operator=(const CPath& cpath) { … … 71 80 } 72 81 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. 74 83 int length() const { return 0;} 75 84 … … 80 89 void clear() {} 81 90 82 /// \brief LEMON style iterator for path arcs91 /// \brief LEMON style iterator for enumerating the arcs of a path. 83 92 /// 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. 85 94 class ArcIt { 86 95 public: … … 89 98 /// Invalid constructor 90 99 ArcIt(Invalid) {} 91 /// Constructor for first arc100 /// Sets the iterator to the first arc of the given path 92 101 ArcIt(const Path &) {} 93 102 94 /// Conversion to Arc103 /// Conversion to \c Arc 95 104 operator Arc() const { return INVALID; } 96 105 … … 193 202 /// 194 203 /// 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. 200 208 /// 201 209 /// 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 207 213 /// an adaptor class to the predecessor map. 208 214 /// 209 215 /// \tparam GR The digraph type in which the path is. 210 ///211 /// The paths can be constructed from any path type by a212 /// template constructor or a template assignment operator.213 216 template <typename GR> 214 217 class PathDumper { … … 220 223 typedef typename Digraph::Arc Arc; 221 224 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. 223 226 int length() const { return 0;} 224 227 … … 228 231 /// \brief Forward or reverse dumping 229 232 /// 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. 234 236 typedef False RevPathTag; 235 237 236 /// \brief LEMON style iterator for path arcs238 /// \brief LEMON style iterator for enumerating the arcs of a path. 237 239 /// 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. 239 241 class ArcIt { 240 242 public: … … 243 245 /// Invalid constructor 244 246 ArcIt(Invalid) {} 245 /// Constructor for first arc247 /// Sets the iterator to the first arc of the given path 246 248 ArcIt(const PathDumper&) {} 247 249 248 /// Conversion to Arc250 /// Conversion to \c Arc 249 251 operator Arc() const { return INVALID; } 250 252 … … 261 263 }; 262 264 263 /// \brief LEMON style iterator for path arcs 265 /// \brief LEMON style iterator for enumerating the arcs of a path 266 /// in reverse direction. 264 267 /// 265 /// This class is used to iterate on the arcs of the paths in266 /// reverse direction.268 /// LEMON style iterator class for enumerating the arcs of a path 269 /// in reverse direction. 267 270 class RevArcIt { 268 271 public: … … 271 274 /// Invalid constructor 272 275 RevArcIt(Invalid) {} 273 /// Constructor for first arc276 /// Sets the iterator to the last arc of the given path 274 277 RevArcIt(const PathDumper &) {} 275 278 276 /// Conversion to Arc279 /// Conversion to \c Arc 277 280 operator Arc() const { return INVALID; } 278 281 -
TabularUnified lemon/connectivity.h ¶
r695 r956 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 259 259 /// \return \c true if the digraph is strongly connected. 260 260 /// \note By definition, the empty digraph is strongly connected. 261 /// 261 /// 262 262 /// \see countStronglyConnectedComponents(), stronglyConnectedComponents() 263 263 /// \see connected() … … 311 311 /// \ingroup graph_properties 312 312 /// 313 /// \brief Count the number of strongly connected components of a 313 /// \brief Count the number of strongly connected components of a 314 314 /// directed graph 315 315 /// … … 745 745 /// \brief Check whether an undirected graph is bi-node-connected. 746 746 /// 747 /// This function checks whether the given undirected graph is 747 /// This function checks whether the given undirected graph is 748 748 /// bi-node-connected, i.e. any two edges are on same circle. 749 749 /// … … 759 759 /// \ingroup graph_properties 760 760 /// 761 /// \brief Count the number of bi-node-connected components of an 761 /// \brief Count the number of bi-node-connected components of an 762 762 /// undirected graph. 763 763 /// … … 813 813 /// \retval compMap A writable edge map. The values will be set from 0 814 814 /// 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 816 816 /// certain component will be set continuously. 817 817 /// \return The number of bi-node-connected components. … … 859 859 /// 860 860 /// \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 862 862 /// \c true for the nodes that separate two or more components 863 863 /// (exactly once for each cut node), and will not be changed for … … 1086 1086 /// \brief Check whether an undirected graph is bi-edge-connected. 1087 1087 /// 1088 /// This function checks whether the given undirected graph is 1088 /// This function checks whether the given undirected graph is 1089 1089 /// bi-edge-connected, i.e. any two nodes are connected with at least 1090 1090 /// two edge-disjoint paths. … … 1193 1193 /// 1194 1194 /// This function finds the bi-edge-connected cut edges in the given 1195 /// undirected graph. 1195 /// undirected graph. 1196 1196 /// 1197 1197 /// The bi-edge-connected components are the classes of an equivalence … … 1350 1350 /// \param digraph The digraph. 1351 1351 /// \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. 1353 1353 /// Each value of the map will be set exactly once, and the values will 1354 1354 /// be set descending order. -
TabularUnified lemon/core.h ¶
r984 r1110 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 1242 1242 protected: 1243 1243 1244 class AutoNodeMap : public ItemSetTraits<GR, Node>::template Map<Arc>::Type { 1244 class AutoNodeMap : public ItemSetTraits<GR, Node>::template Map<Arc>::Type 1245 { 1245 1246 typedef typename ItemSetTraits<GR, Node>::template Map<Arc>::Type Parent; 1246 1247 … … 1281 1282 }; 1282 1283 1283 protected: 1284 protected: 1284 1285 1285 1286 const Digraph &_g; -
TabularUnified lemon/counter.h ¶
r463 r833 213 213 /// 'Do nothing' version of Counter. 214 214 215 /// This class can be used in the same way as \ref Counter howeverit215 /// This class can be used in the same way as \ref Counter, but it 216 216 /// does not count at all and does not print report on destruction. 217 217 /// -
TabularUnified lemon/cplex.cc ¶
r623 r956 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 112 112 } 113 113 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 } 114 147 115 148 void CplexBase::_eraseCol(int i) { … … 457 490 458 491 void CplexBase::_applyMessageLevel() { 459 CPXsetintparam(cplexEnv(), CPX_PARAM_SCRIND, 492 CPXsetintparam(cplexEnv(), CPX_PARAM_SCRIND, 460 493 _message_enabled ? CPX_ON : CPX_OFF); 461 494 } -
TabularUnified lemon/cplex.h ¶
r623 r793 94 94 virtual int _addCol(); 95 95 virtual int _addRow(); 96 virtual int _addRow(Value l, ExprIterator b, ExprIterator e, Value u); 96 97 97 98 virtual void _eraseCol(int i); -
TabularUnified lemon/dfs.h ¶
r1009 r1110 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 48 48 ///The type of the map that stores the predecessor 49 49 ///arcs of the %DFS paths. 50 ///It must meetthe \ref concepts::WriteMap "WriteMap" concept.50 ///It must conform to the \ref concepts::WriteMap "WriteMap" concept. 51 51 typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap; 52 52 ///Instantiates a \c PredMap. … … 63 63 64 64 ///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. 66 67 typedef NullMap<typename Digraph::Node,bool> ProcessedMap; 67 68 ///Instantiates a \c ProcessedMap. … … 82 83 83 84 ///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. 85 87 typedef typename Digraph::template NodeMap<bool> ReachedMap; 86 88 ///Instantiates a \c ReachedMap. … … 97 99 98 100 ///The type of the map that stores the distances of the nodes. 99 ///It must meetthe \ref concepts::WriteMap "WriteMap" concept.101 ///It must conform to the \ref concepts::WriteMap "WriteMap" concept. 100 102 typedef typename Digraph::template NodeMap<int> DistMap; 101 103 ///Instantiates a \c DistMap. … … 121 123 ///\tparam GR The type of the digraph the algorithm runs on. 122 124 ///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. 123 130 #ifdef DOXYGEN 124 131 template <typename GR, … … 225 232 ///\ref named-templ-param "Named parameter" for setting 226 233 ///\c PredMap type. 227 ///It must meetthe \ref concepts::WriteMap "WriteMap" concept.234 ///It must conform to the \ref concepts::WriteMap "WriteMap" concept. 228 235 template <class T> 229 236 struct SetPredMap : public Dfs<Digraph, SetPredMapTraits<T> > { … … 245 252 ///\ref named-templ-param "Named parameter" for setting 246 253 ///\c DistMap type. 247 ///It must meetthe \ref concepts::WriteMap "WriteMap" concept.254 ///It must conform to the \ref concepts::WriteMap "WriteMap" concept. 248 255 template <class T> 249 256 struct SetDistMap : public Dfs< Digraph, SetDistMapTraits<T> > { … … 265 272 ///\ref named-templ-param "Named parameter" for setting 266 273 ///\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. 268 276 template <class T> 269 277 struct SetReachedMap : public Dfs< Digraph, SetReachedMapTraits<T> > { … … 285 293 ///\ref named-templ-param "Named parameter" for setting 286 294 ///\c ProcessedMap type. 287 ///It must meetthe \ref concepts::WriteMap "WriteMap" concept.295 ///It must conform to the \ref concepts::WriteMap "WriteMap" concept. 288 296 template <class T> 289 297 struct SetProcessedMap : public Dfs< Digraph, SetProcessedMapTraits<T> > { … … 412 420 ///The simplest way to execute the DFS algorithm is to use one of the 413 421 ///member functions called \ref run(Node) "run()".\n 414 ///If you need more control on the execution, firstyou have to call415 ///\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() 416 424 ///and perform the actual computation with \ref start(). 417 425 ///This procedure can be repeated if there are nodes that have not … … 633 641 ///Runs the algorithm to visit all nodes in the digraph. 634 642 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. 641 645 /// 642 646 ///\note <tt>d.run()</tt> is just a shortcut of the following code. … … 670 674 ///@{ 671 675 672 ///The DFS path to anode.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). 675 679 /// 676 680 ///\warning \c t should be reached from the root(s). … … 680 684 Path path(Node t) const { return Path(*G, *_pred, t); } 681 685 682 ///The distance of anode from the root(s).683 684 ///Returns the distance of anode 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). 685 689 /// 686 690 ///\warning If node \c v is not reached from the root(s), then … … 691 695 int dist(Node v) const { return (*_dist)[v]; } 692 696 693 ///Returns the 'previous arc' of the %DFS tree for anode.697 ///Returns the 'previous arc' of the %DFS tree for the given node. 694 698 695 699 ///This function returns the 'previous arc' of the %DFS tree for the … … 699 703 /// 700 704 ///The %DFS tree used here is equal to the %DFS tree used in 701 ///\ref predNode() .705 ///\ref predNode() and \ref predMap(). 702 706 /// 703 707 ///\pre Either \ref run(Node) "run()" or \ref init() … … 705 709 Arc predArc(Node v) const { return (*_pred)[v];} 706 710 707 ///Returns the 'previous node' of the %DFS tree .711 ///Returns the 'previous node' of the %DFS tree for the given node. 708 712 709 713 ///This function returns the 'previous node' of the %DFS 710 714 ///tree for the node \c v, i.e. it returns the last but one node 711 /// froma %DFS path from a root to \c v. It is \c INVALID715 ///of a %DFS path from a root to \c v. It is \c INVALID 712 716 ///if \c v is not reached from the root(s) or if \c v is a root. 713 717 /// 714 718 ///The %DFS tree used here is equal to the %DFS tree used in 715 ///\ref predArc() .719 ///\ref predArc() and \ref predMap(). 716 720 /// 717 721 ///\pre Either \ref run(Node) "run()" or \ref init() … … 734 738 /// 735 739 ///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). 737 741 /// 738 742 ///\pre Either \ref run(Node) "run()" or \ref init() … … 740 744 const PredMap &predMap() const { return *_pred;} 741 745 742 ///Checks if anode is reached from the root(s).746 ///Checks if the given node. node is reached from the root(s). 743 747 744 748 ///Returns \c true if \c v is reached from the root(s). … … 766 770 ///The type of the map that stores the predecessor 767 771 ///arcs of the %DFS paths. 768 ///It must meetthe \ref concepts::WriteMap "WriteMap" concept.772 ///It must conform to the \ref concepts::WriteMap "WriteMap" concept. 769 773 typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap; 770 774 ///Instantiates a PredMap. … … 781 785 782 786 ///The type of the map that indicates which nodes are processed. 783 ///It must meetthe \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. 785 789 typedef NullMap<typename Digraph::Node,bool> ProcessedMap; 786 790 ///Instantiates a ProcessedMap. … … 801 805 802 806 ///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. 804 809 typedef typename Digraph::template NodeMap<bool> ReachedMap; 805 810 ///Instantiates a ReachedMap. … … 816 821 817 822 ///The type of the map that stores the distances of the nodes. 818 ///It must meetthe \ref concepts::WriteMap "WriteMap" concept.823 ///It must conform to the \ref concepts::WriteMap "WriteMap" concept. 819 824 typedef typename Digraph::template NodeMap<int> DistMap; 820 825 ///Instantiates a DistMap. … … 831 836 832 837 ///The type of the DFS paths. 833 ///It must meetthe \ref concepts::Path "Path" concept.838 ///It must conform to the \ref concepts::Path "Path" concept. 834 839 typedef lemon::Path<Digraph> Path; 835 840 }; … … 837 842 /// Default traits class used by DfsWizard 838 843 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. 845 846 template<class GR> 846 847 class DfsWizardBase : public DfsWizardDefaultTraits<GR> … … 870 871 /// Constructor. 871 872 872 /// This constructor does not require parameters, thereforeit initiates873 /// This constructor does not require parameters, it initiates 873 874 /// all of the attributes to \c 0. 874 875 DfsWizardBase() : _g(0), _reached(0), _processed(0), _pred(0), … … 895 896 /// This class should only be used through the \ref dfs() function, 896 897 /// which makes it easier to use the algorithm. 898 /// 899 /// \tparam TR The traits class that defines various types used by the 900 /// algorithm. 897 901 template<class TR> 898 902 class DfsWizard : public TR … … 900 904 typedef TR Base; 901 905 902 ///The type of the digraph the algorithm runs on.903 906 typedef typename TR::Digraph Digraph; 904 907 … … 908 911 typedef typename Digraph::OutArcIt OutArcIt; 909 912 910 ///\brief The type of the map that stores the predecessor911 ///arcs of the DFS paths.912 913 typedef typename TR::PredMap PredMap; 913 ///\brief The type of the map that stores the distances of the nodes.914 914 typedef typename TR::DistMap DistMap; 915 ///\brief The type of the map that indicates which nodes are reached.916 915 typedef typename TR::ReachedMap ReachedMap; 917 ///\brief The type of the map that indicates which nodes are processed.918 916 typedef typename TR::ProcessedMap ProcessedMap; 919 ///The type of the DFS paths920 917 typedef typename TR::Path Path; 921 918 … … 987 984 ///Runs DFS algorithm to visit all nodes in the digraph. 988 985 989 ///This method runs DFS algorithm in order to compute990 /// the DFS path to each node.986 ///This method runs DFS algorithm in order to visit all nodes 987 ///in the digraph. 991 988 void run() 992 989 { … … 1000 997 SetPredMapBase(const TR &b) : TR(b) {} 1001 998 }; 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. 1007 1005 template<class T> 1008 1006 DfsWizard<SetPredMapBase<T> > predMap(const T &t) … … 1018 1016 SetReachedMapBase(const TR &b) : TR(b) {} 1019 1017 }; 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. 1025 1024 template<class T> 1026 1025 DfsWizard<SetReachedMapBase<T> > reachedMap(const T &t) … … 1036 1035 SetDistMapBase(const TR &b) : TR(b) {} 1037 1036 }; 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. 1043 1044 template<class T> 1044 1045 DfsWizard<SetDistMapBase<T> > distMap(const T &t) … … 1054 1055 SetProcessedMapBase(const TR &b) : TR(b) {} 1055 1056 }; 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. 1061 1063 template<class T> 1062 1064 DfsWizard<SetProcessedMapBase<T> > processedMap(const T &t) … … 1209 1211 /// 1210 1212 /// 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. 1212 1215 typedef typename Digraph::template NodeMap<bool> ReachedMap; 1213 1216 … … 1247 1250 /// does not observe the DFS events. If you want to observe the DFS 1248 1251 /// events, you should implement your own visitor class. 1249 /// \tparam TR T raits class to set various datatypes used by the1250 /// algorithm. The default traits class is1251 /// \ref DfsVisitDefaultTraits"DfsVisitDefaultTraits<GR>".1252 /// See \ref DfsVisitDefaultTraits for the documentation of1253 /// 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. 1254 1257 #ifdef DOXYGEN 1255 1258 template <typename GR, typename VS, typename TR> … … 1370 1373 /// The simplest way to execute the DFS algorithm is to use one of the 1371 1374 /// member functions called \ref run(Node) "run()".\n 1372 /// If you need more control on the execution, firstyou have to call1373 /// \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() 1374 1377 /// and perform the actual computation with \ref start(). 1375 1378 /// This procedure can be repeated if there are nodes that have not … … 1584 1587 /// \brief Runs the algorithm to visit all nodes in the digraph. 1585 1588 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. 1592 1591 /// 1593 1592 /// \note <tt>d.run()</tt> is just a shortcut of the following code. … … 1621 1620 ///@{ 1622 1621 1623 /// \brief Checks if anode is reached from the root(s).1622 /// \brief Checks if the given node is reached from the root(s). 1624 1623 /// 1625 1624 /// Returns \c true if \c v is reached from the root(s). -
TabularUnified lemon/dijkstra.h ¶
r631 r956 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 71 71 72 72 ///The type of the map that stores the arc lengths. 73 ///It must meetthe \ref concepts::ReadMap "ReadMap" concept.73 ///It must conform to the \ref concepts::ReadMap "ReadMap" concept. 74 74 typedef LEN LengthMap; 75 ///The type of the length of the arcs.75 ///The type of the arc lengths. 76 76 typedef typename LEN::Value Value; 77 77 … … 117 117 ///The type of the map that stores the predecessor 118 118 ///arcs of the shortest paths. 119 ///It must meetthe \ref concepts::WriteMap "WriteMap" concept.119 ///It must conform to the \ref concepts::WriteMap "WriteMap" concept. 120 120 typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap; 121 121 ///Instantiates a \c PredMap. … … 132 132 133 133 ///The type of the map that indicates which nodes are processed. 134 ///It must meetthe \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. 136 136 typedef NullMap<typename Digraph::Node,bool> ProcessedMap; 137 137 ///Instantiates a \c ProcessedMap. … … 152 152 153 153 ///The type of the map that stores the distances of the nodes. 154 ///It must meetthe \ref concepts::WriteMap "WriteMap" concept.154 ///It must conform to the \ref concepts::WriteMap "WriteMap" concept. 155 155 typedef typename Digraph::template NodeMap<typename LEN::Value> DistMap; 156 156 ///Instantiates a \c DistMap. … … 169 169 /// \ingroup shortest_path 170 170 ///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. 171 175 /// 172 176 ///The arc lengths are passed to the algorithm using a … … 189 193 ///it is necessary. The default map type is \ref 190 194 ///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. 191 200 #ifdef DOXYGEN 192 201 template <typename GR, typename LEN, typename TR> … … 202 211 typedef typename TR::Digraph Digraph; 203 212 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; 206 215 ///The type of the map that stores the arc lengths. 207 216 typedef typename TR::LengthMap LengthMap; … … 305 314 ///\ref named-templ-param "Named parameter" for setting 306 315 ///\c PredMap type. 307 ///It must meetthe \ref concepts::WriteMap "WriteMap" concept.316 ///It must conform to the \ref concepts::WriteMap "WriteMap" concept. 308 317 template <class T> 309 318 struct SetPredMap … … 326 335 ///\ref named-templ-param "Named parameter" for setting 327 336 ///\c DistMap type. 328 ///It must meetthe \ref concepts::WriteMap "WriteMap" concept.337 ///It must conform to the \ref concepts::WriteMap "WriteMap" concept. 329 338 template <class T> 330 339 struct SetDistMap … … 347 356 ///\ref named-templ-param "Named parameter" for setting 348 357 ///\c ProcessedMap type. 349 ///It must meetthe \ref concepts::WriteMap "WriteMap" concept.358 ///It must conform to the \ref concepts::WriteMap "WriteMap" concept. 350 359 template <class T> 351 360 struct SetProcessedMap … … 423 432 ///passed to the constructor of the cross reference and the cross 424 433 ///reference should be passed to the constructor of the heap). 425 ///However external heap and cross reference objects could also be434 ///However, external heap and cross reference objects could also be 426 435 ///passed to the algorithm using the \ref heap() function before 427 436 ///calling \ref run(Node) "run()" or \ref init(). … … 444 453 ///\ref named-templ-param "Named parameter" for setting 445 454 ///\c OperationTraits type. 455 /// For more information, see \ref DijkstraDefaultOperationTraits. 446 456 template <class T> 447 457 struct SetOperationTraits … … 585 595 ///The simplest way to execute the %Dijkstra algorithm is to use 586 596 ///one of the member functions called \ref run(Node) "run()".\n 587 ///If you need more control on the execution, firstyou have to call588 ///\ref init() , then you can add several source nodes with597 ///If you need better control on the execution, you have to call 598 ///\ref init() first, then you can add several source nodes with 589 599 ///\ref addSource(). Finally the actual path computation can be 590 600 ///performed with one of the \ref start() functions. … … 802 812 ///The results of the %Dijkstra algorithm can be obtained using these 803 813 ///functions.\n 804 ///Either \ref run(Node) "run()" or \ref start() should be called814 ///Either \ref run(Node) "run()" or \ref init() should be called 805 815 ///before using them. 806 816 807 817 ///@{ 808 818 809 ///The shortest path to anode.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). 812 822 /// 813 823 ///\warning \c t should be reached from the root(s). … … 817 827 Path path(Node t) const { return Path(*G, *_pred, t); } 818 828 819 ///The distance of anode from the root(s).820 821 ///Returns the distance of anode 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). 822 832 /// 823 833 ///\warning If node \c v is not reached from the root(s), then … … 828 838 Value dist(Node v) const { return (*_dist)[v]; } 829 839 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 /// 832 843 ///This function returns the 'previous arc' of the shortest path 833 844 ///tree for the node \c v, i.e. it returns the last arc of a … … 836 847 /// 837 848 ///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(). 839 850 /// 840 851 ///\pre Either \ref run(Node) "run()" or \ref init() … … 842 853 Arc predArc(Node v) const { return (*_pred)[v]; } 843 854 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 /// 846 858 ///This function returns the 'previous node' of the shortest path 847 859 ///tree for the node \c v, i.e. it returns the last but one node 848 /// froma shortest path from a root to \c v. It is \c INVALID860 ///of a shortest path from a root to \c v. It is \c INVALID 849 861 ///if \c v is not reached from the root(s) or if \c v is a root. 850 862 /// 851 863 ///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(). 853 865 /// 854 866 ///\pre Either \ref run(Node) "run()" or \ref init() … … 871 883 /// 872 884 ///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). 874 886 /// 875 887 ///\pre Either \ref run(Node) "run()" or \ref init() … … 877 889 const PredMap &predMap() const { return *_pred;} 878 890 879 ///Checks if anode is reached from the root(s).891 ///Checks if the given node is reached from the root(s). 880 892 881 893 ///Returns \c true if \c v is reached from the root(s). … … 896 908 Heap::POST_HEAP; } 897 909 898 ///The current distance of anode from the root(s).899 900 ///Returns the current distance of anode 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). 901 913 ///It may be decreased in the following processes. 902 914 /// … … 925 937 926 938 ///The type of the map that stores the arc lengths. 927 ///It must meetthe \ref concepts::ReadMap "ReadMap" concept.939 ///It must conform to the \ref concepts::ReadMap "ReadMap" concept. 928 940 typedef LEN LengthMap; 929 ///The type of the length of the arcs.941 ///The type of the arc lengths. 930 942 typedef typename LEN::Value Value; 931 943 … … 974 986 ///The type of the map that stores the predecessor 975 987 ///arcs of the shortest paths. 976 ///It must meetthe \ref concepts::WriteMap "WriteMap" concept.988 ///It must conform to the \ref concepts::WriteMap "WriteMap" concept. 977 989 typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap; 978 990 ///Instantiates a PredMap. … … 989 1001 990 1002 ///The type of the map that indicates which nodes are processed. 991 ///It must meetthe \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. 993 1005 typedef NullMap<typename Digraph::Node,bool> ProcessedMap; 994 1006 ///Instantiates a ProcessedMap. … … 1009 1021 1010 1022 ///The type of the map that stores the distances of the nodes. 1011 ///It must meetthe \ref concepts::WriteMap "WriteMap" concept.1023 ///It must conform to the \ref concepts::WriteMap "WriteMap" concept. 1012 1024 typedef typename Digraph::template NodeMap<typename LEN::Value> DistMap; 1013 1025 ///Instantiates a DistMap. … … 1024 1036 1025 1037 ///The type of the shortest paths. 1026 ///It must meetthe \ref concepts::Path "Path" concept.1038 ///It must conform to the \ref concepts::Path "Path" concept. 1027 1039 typedef lemon::Path<Digraph> Path; 1028 1040 }; … … 1030 1042 /// Default traits class used by DijkstraWizard 1031 1043 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. 1038 1047 template<typename GR, typename LEN> 1039 1048 class DijkstraWizardBase : public DijkstraWizardDefaultTraits<GR,LEN> … … 1089 1098 /// This class should only be used through the \ref dijkstra() function, 1090 1099 /// which makes it easier to use the algorithm. 1100 /// 1101 /// \tparam TR The traits class that defines various types used by the 1102 /// algorithm. 1091 1103 template<class TR> 1092 1104 class DijkstraWizard : public TR … … 1094 1106 typedef TR Base; 1095 1107 1096 ///The type of the digraph the algorithm runs on.1097 1108 typedef typename TR::Digraph Digraph; 1098 1109 … … 1102 1113 typedef typename Digraph::OutArcIt OutArcIt; 1103 1114 1104 ///The type of the map that stores the arc lengths.1105 1115 typedef typename TR::LengthMap LengthMap; 1106 ///The type of the length of the arcs.1107 1116 typedef typename LengthMap::Value Value; 1108 ///\brief The type of the map that stores the predecessor1109 ///arcs of the shortest paths.1110 1117 typedef typename TR::PredMap PredMap; 1111 ///The type of the map that stores the distances of the nodes.1112 1118 typedef typename TR::DistMap DistMap; 1113 ///The type of the map that indicates which nodes are processed.1114 1119 typedef typename TR::ProcessedMap ProcessedMap; 1115 ///The type of the shortest paths1116 1120 typedef typename TR::Path Path; 1117 ///The heap type used by the dijkstra algorithm.1118 1121 typedef typename TR::Heap Heap; 1119 1122 … … 1187 1190 SetPredMapBase(const TR &b) : TR(b) {} 1188 1191 }; 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. 1194 1198 template<class T> 1195 1199 DijkstraWizard<SetPredMapBase<T> > predMap(const T &t) … … 1205 1209 SetDistMapBase(const TR &b) : TR(b) {} 1206 1210 }; 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. 1212 1218 template<class T> 1213 1219 DijkstraWizard<SetDistMapBase<T> > distMap(const T &t) … … 1223 1229 SetProcessedMapBase(const TR &b) : TR(b) {} 1224 1230 }; 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. 1230 1237 template<class T> 1231 1238 DijkstraWizard<SetProcessedMapBase<T> > processedMap(const T &t) … … 1240 1247 SetPathBase(const TR &b) : TR(b) {} 1241 1248 }; 1249 1242 1250 ///\brief \ref named-func-param "Named parameter" 1243 1251 ///for getting the shortest path to the target node. -
TabularUnified lemon/dim2.h ¶
r463 r761 22 22 #include <iostream> 23 23 24 ///\ingroup misc24 ///\ingroup geomdat 25 25 ///\file 26 26 ///\brief A simple two dimensional vector and a bounding box implementation 27 ///28 /// The class \ref lemon::dim2::Point "dim2::Point" implements29 /// a two dimensional vector with the usual operations.30 ///31 /// The class \ref lemon::dim2::Box "dim2::Box" can be used to determine32 /// the rectangular bounding box of a set of33 /// \ref lemon::dim2::Point "dim2::Point"'s.34 27 35 28 namespace lemon { … … 41 34 namespace dim2 { 42 35 43 /// \addtogroup misc36 /// \addtogroup geomdat 44 37 /// @{ 45 38 -
TabularUnified lemon/dimacs.h ¶
r631 r956 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 62 62 63 63 ///This function starts seeking the beginning of the given file for the 64 ///problem type and size info. 64 ///problem type and size info. 65 65 ///The found data is returned in a special struct that can be evaluated 66 66 ///and passed to the appropriate reader function. … … 213 213 std::numeric_limits<Capacity>::infinity() : 214 214 std::numeric_limits<Capacity>::max(); 215 215 216 216 while (is >> c) { 217 217 switch (c) { … … 238 238 e = g.addArc(nodes[i], nodes[j]); 239 239 capacity.set(e, _cap); 240 } 240 } 241 241 else if (desc.type==DimacsDescriptor::MAX) { 242 242 is >> i >> j >> _cap; … … 363 363 g.addArc(s,t); 364 364 } 365 365 366 366 /// \brief DIMACS plain (di)graph reader function. 367 367 /// 368 368 /// 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 370 370 /// DIMACS files having a line starting with 371 371 /// \code … … 393 393 nodes[k] = g.addNode(); 394 394 } 395 395 396 396 while (is >> c) { 397 397 switch (c) { -
TabularUnified lemon/edge_set.h ¶
r717 r956 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 085 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 256 256 /// all arcs incident to the given node is erased from the arc set. 257 257 /// 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 /// 258 262 /// \param GR The type of the graph which shares its node set with 259 263 /// this class. Its interface must conform to the 260 264 /// \ref concepts::Digraph "Digraph" or \ref concepts::Graph "Graph" 261 265 /// concept. 262 ///263 /// This class fully conforms to the \ref concepts::Digraph264 /// "Digraph" concept.265 266 template <typename GR> 266 267 class ListArcSet : public ArcSetExtender<ListArcSetBase<GR> > { … … 686 687 /// incident to the given node is erased from the arc set. 687 688 /// 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 /// 688 693 /// \param GR The type of the graph which shares its node set 689 694 /// with this class. Its interface must conform to the 690 695 /// \ref concepts::Digraph "Digraph" or \ref concepts::Graph "Graph" 691 /// concept.692 ///693 /// This class fully conforms to the \ref concepts::Graph "Graph"694 696 /// concept. 695 697 template <typename GR> … … 868 870 } 869 871 870 void next(Arc& arc) const{872 static void next(Arc& arc) { 871 873 --arc.id; 872 874 } … … 955 957 /// arcs. Therefore the arcs cannot be erased from the arc sets. 956 958 /// 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 /// 957 963 /// \warning If a node is erased from the underlying graph and this 958 964 /// node is the source or target of one arc in the arc set, then 959 965 /// the arc set is invalidated, and it cannot be used anymore. The 960 966 /// validity can be checked with the \c valid() member function. 961 ///962 /// This class fully conforms to the \ref concepts::Digraph963 /// "Digraph" concept.964 967 template <typename GR> 965 968 class SmartArcSet : public ArcSetExtender<SmartArcSetBase<GR> > { … … 1174 1177 } 1175 1178 1176 void next(Arc& arc) const{1179 static void next(Arc& arc) { 1177 1180 --arc.id; 1178 1181 } … … 1182 1185 } 1183 1186 1184 void next(Edge& arc) const{1187 static void next(Edge& arc) { 1185 1188 --arc.id; 1186 1189 } … … 1305 1308 /// edges cannot be erased from the edge sets. 1306 1309 /// 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 /// 1307 1314 /// \warning If a node is erased from the underlying graph and this 1308 1315 /// node is incident to one edge in the edge set, then the edge set 1309 1316 /// is invalidated, and it cannot be used anymore. The validity can 1310 1317 /// be checked with the \c valid() member function. 1311 ///1312 /// This class fully conforms to the \ref concepts::Graph1313 /// "Graph" concept.1314 1318 template <typename GR> 1315 1319 class SmartEdgeSet : public EdgeSetExtender<SmartEdgeSetBase<GR> > { -
TabularUnified lemon/euler.h ¶
r695 r956 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 27 27 /// \ingroup graph_properties 28 28 /// \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 30 30 /// property. 31 31 /// … … 42 42 /// 43 43 ///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 45 45 ///for all nodes), then the following code will put the arcs of \c g 46 46 ///to the vector \c et according to an Euler tour of \c g. … … 139 139 ///and \c Edge types of the graph. 140 140 /// 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 142 142 ///non-trivial component and the degree of each node is even), 143 143 ///the following code will print the arc IDs according to an … … 148 148 /// } 149 149 ///\endcode 150 ///Although this iterator is for undirected graphs, it still returns 150 ///Although this iterator is for undirected graphs, it still returns 151 151 ///arcs in order to indicate the direction of the tour. 152 152 ///(But arcs convert to edges, of course.) … … 234 234 /// Postfix incrementation. 235 235 /// 236 ///\warning This incrementation returns an \c Arc (which converts to 236 ///\warning This incrementation returns an \c Arc (which converts to 237 237 ///an \c Edge), not an \ref EulerIt, as one may expect. 238 238 Arc operator++(int) -
TabularUnified lemon/fib_heap.h ¶
r730 r758 21 21 22 22 ///\file 23 ///\ingroup auxdat24 ///\brief Fibonacci Heap implementation.23 ///\ingroup heaps 24 ///\brief Fibonacci heap implementation. 25 25 26 26 #include <vector> 27 #include <utility> 27 28 #include <functional> 28 29 #include <lemon/math.h> … … 30 31 namespace lemon { 31 32 32 /// \ingroup auxdat33 /// \ingroup heaps 33 34 /// 34 /// \brief Fibonacci Heap.35 /// \brief Fibonacci heap data structure. 35 36 /// 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". 41 39 /// 42 /// The methods \ref increase and \ref erase are not efficient in a Fibonacci43 /// heap. In case of many calls to these operations, it is better to use a44 /// \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". 45 43 /// 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>. 54 49 #ifdef DOXYGEN 55 template <typename PR IO, typename IM, typename CMP>50 template <typename PR, typename IM, typename CMP> 56 51 #else 57 template <typename PR IO, typename IM, typename CMP = std::less<PRIO> >52 template <typename PR, typename IM, typename CMP = std::less<PR> > 58 53 #endif 59 54 class FibHeap { 60 55 public: 61 ///\e 56 57 /// Type of the item-int map. 62 58 typedef IM ItemIntMap; 63 /// \e64 typedef PR IOPrio;65 /// \e59 /// Type of the priorities. 60 typedef PR Prio; 61 /// Type of the items stored in the heap. 66 62 typedef typename ItemIntMap::Key Item; 67 /// \e63 /// Type of the item-priority pairs. 68 64 typedef std::pair<Item,Prio> Pair; 69 /// \e65 /// Functor type for comparing the priorities. 70 66 typedef CMP Compare; 71 67 … … 81 77 public: 82 78 83 /// \brief Type to represent the items states.84 /// 85 /// Each Item element have a state associated to it. It maybe "in heap",86 /// "pre heap" or "postheap". The latter two are indifferent from the79 /// \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 87 83 /// heap's point of view, but may be useful to the user. 88 84 /// … … 95 91 }; 96 92 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. 101 99 explicit FibHeap(ItemIntMap &map) 102 100 : _minimum(0), _iim(map), _num() {} 103 101 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. 109 109 FibHeap(ItemIntMap &map, const Compare &comp) 110 110 : _minimum(0), _iim(map), _comp(comp), _num() {} … … 112 112 /// \brief The number of items stored in the heap. 113 113 /// 114 /// Returns the number of items stored in the heap.114 /// This function returns the number of items stored in the heap. 115 115 int size() const { return _num; } 116 116 117 /// \brief Check s 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. 120 120 bool empty() const { return _num==0; } 121 121 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. 128 129 void clear() { 129 130 _data.clear(); _minimum = 0; _num = 0; 130 131 } 131 132 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) { 151 141 int i=_iim[item]; 152 142 if ( i < 0 ) { … … 169 159 _data[_minimum].right_neighbor=i; 170 160 _data[i].left_neighbor=_minimum; 171 if ( _comp( value, _data[_minimum].prio) ) _minimum=i;161 if ( _comp( prio, _data[_minimum].prio) ) _minimum=i; 172 162 } else { 173 163 _data[i].right_neighbor=_data[i].left_neighbor=i; 174 164 _minimum=i; 175 165 } 176 _data[i].prio= value;166 _data[i].prio=prio; 177 167 ++_num; 178 168 } 179 169 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. 185 174 Item top() const { return _data[_minimum].name; } 186 175 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. 205 185 /// \pre The heap must be non-empty. 206 186 void pop() { … … 209 189 _data[_minimum].in=false; 210 190 if ( _data[_minimum].degree!=0 ) { 211 make root(_data[_minimum].child);191 makeRoot(_data[_minimum].child); 212 192 _minimum=_data[_minimum].child; 213 193 balance(); … … 222 202 int last_child=_data[child].left_neighbor; 223 203 224 make root(child);204 makeRoot(child); 225 205 226 206 _data[left].right_neighbor=child; … … 235 215 } 236 216 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. 241 223 void erase (const Item& item) { 242 224 int i=_iim[item]; … … 253 235 } 254 236 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) { 261 255 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; 263 271 int p=_data[i].parent; 264 272 265 if ( p!=-1 && _comp( value, _data[p].prio) ) {273 if ( p!=-1 && _comp(prio, _data[p].prio) ) { 266 274 cut(i,p); 267 275 cascade(p); 268 276 } 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) { 280 287 erase(item); 281 push(item, value);282 } 283 284 285 /// \brief Returns if \c item is in, has already been in, or has never286 /// been in the heap.287 /// 288 /// This method returns PRE_HEAP if \c item has never been in the289 /// heap, IN_HEAP if it is in the heap at the moment, and POST_HEAP290 /// otherwise. In the latter case it is possible that \c item will291 /// 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. 292 299 State state(const Item &item) const { 293 300 int i=_iim[item]; … … 299 306 } 300 307 301 /// \brief Set s the state of the \citem in the heap.302 /// 303 /// Sets the state of the \c item in the heap. It can be used to304 /// manually clear the heap when it is important to achive the305 /// 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. 306 313 /// \param i The item. 307 314 /// \param st The state. It should not be \c IN_HEAP. … … 366 373 } 367 374 368 void make root(int c) {375 void makeRoot(int c) { 369 376 int s=c; 370 377 do { -
TabularUnified lemon/full_graph.h ¶
r664 r956 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 25 25 ///\ingroup graphs 26 26 ///\file 27 ///\brief Full Graph and FullDigraph classes.27 ///\brief FullDigraph and FullGraph classes. 28 28 29 29 namespace lemon { … … 52 52 53 53 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; } 55 55 56 56 Arc arc(const Node& s, const Node& t) const { … … 149 149 /// \ingroup graphs 150 150 /// 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, 164 168 /// but there are two differences. While this class conforms only 165 /// to the \ref concepts::Digraph "Digraph" concept, the \cFullGraph166 /// c lass conforms to the \ref concepts::Graph "Graph" concept,167 /// moreover \c FullGraph does not contain a loop arcfor each168 /// node as \c FullDigraphdoes.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. 169 173 /// 170 174 /// \sa FullGraph … … 174 178 public: 175 179 176 /// \brief Constructor 180 /// \brief Default constructor. 181 /// 182 /// Default constructor. The number of nodes and arcs will be zero. 177 183 FullDigraph() { construct(0); } 178 184 … … 185 191 /// \brief Resizes the digraph 186 192 /// 187 /// Resizes the digraph. The function will fully destroyand188 /// rebuild the digraph. This cause that the maps of the digraph will193 /// This function resizes the digraph. It fully destroys and 194 /// rebuilds the structure, therefore the maps of the digraph will be 189 195 /// reallocated automatically and the previous values will be lost. 190 196 void resize(int n) { … … 198 204 /// \brief Returns the node with the given index. 199 205 /// 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. 203 210 /// \sa index() 204 211 Node operator()(int ix) const { return Parent::operator()(ix); } … … 206 213 /// \brief Returns the index of the given node. 207 214 /// 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); } 213 221 214 222 /// \brief Returns the arc connecting the given nodes. 215 223 /// 216 224 /// 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 { 218 226 return Parent::arc(u, v); 219 227 } … … 284 292 285 293 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; } 287 295 288 296 Edge edge(const Node& u, const Node& v) const { … … 521 529 /// \brief An undirected full graph class. 522 530 /// 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 534 546 /// conforms only to the \ref concepts::Digraph "Digraph" concept, 535 547 /// this class conforms to the \ref concepts::Graph "Graph" concept, 536 /// moreover \c FullGraph does not contain a loop arcfor each537 /// node as \cFullDigraph does.548 /// moreover this class does not contain a loop for each 549 /// node as FullDigraph does. 538 550 /// 539 551 /// \sa FullDigraph … … 543 555 public: 544 556 545 /// \brief Constructor 557 /// \brief Default constructor. 558 /// 559 /// Default constructor. The number of nodes and edges will be zero. 546 560 FullGraph() { construct(0); } 547 561 … … 554 568 /// \brief Resizes the graph 555 569 /// 556 /// Resizes the graph. The function will fully destroyand557 /// rebuild the graph. This cause that the maps of the graph will570 /// This function resizes the graph. It fully destroys and 571 /// rebuilds the structure, therefore the maps of the graph will be 558 572 /// reallocated automatically and the previous values will be lost. 559 573 void resize(int n) { … … 569 583 /// \brief Returns the node with the given index. 570 584 /// 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. 574 589 /// \sa index() 575 590 Node operator()(int ix) const { return Parent::operator()(ix); } … … 577 592 /// \brief Returns the index of the given node. 578 593 /// 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); } 584 600 585 601 /// \brief Returns the arc connecting the given nodes. 586 602 /// 587 603 /// 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 { 589 605 return Parent::arc(s, t); 590 606 } 591 607 592 /// \brief Returns the edge connect sthe given nodes.593 /// 594 /// Returns the edge connect sthe 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 { 596 612 return Parent::edge(u, v); 597 613 } -
TabularUnified lemon/glpk.cc ¶
r623 r956 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 57 57 int i = glp_add_rows(lp, 1); 58 58 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()); 59 95 return i; 60 96 } -
TabularUnified lemon/glpk.h ¶
r900 r956 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 085 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 31 31 class VoidPtr { 32 32 private: 33 void *_ptr; 33 void *_ptr; 34 34 public: 35 35 VoidPtr() : _ptr(0) {} … … 39 39 40 40 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); 43 43 return *this; 44 44 } … … 66 66 virtual int _addCol(); 67 67 virtual int _addRow(); 68 virtual int _addRow(Value l, ExprIterator b, ExprIterator e, Value u); 68 69 69 70 virtual void _eraseCol(int i); … … 124 125 } 125 126 }; 126 127 127 128 static FreeEnvHelper freeEnvHelper; 128 129 129 130 protected: 130 131 131 132 int _message_level; 132 133 133 134 public: 134 135 -
TabularUnified lemon/gomory_hu.h ¶
r643 r956 1 /* -*- C++-*-1 /* -*- mode: C++; indent-tabs-mode: nil; -*- 2 2 * 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. 4 4 * 5 * Copyright (C) 2003-20 085 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 28 28 29 29 /// \ingroup min_cut 30 /// \file 30 /// \file 31 31 /// \brief Gomory-Hu cut tree in graphs. 32 32 … … 39 39 /// The Gomory-Hu tree is a tree on the node set of a given graph, but it 40 40 /// 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 42 42 /// in this tree has the same weight as the minimum cut in the graph 43 43 /// between these nodes. Moreover the components obtained by removing … … 45 45 /// Therefore once this tree is computed, the minimum cut between any pair 46 46 /// of nodes can easily be obtained. 47 /// 47 /// 48 48 /// The algorithm calculates \e n-1 distinct minimum cuts (currently with 49 49 /// the \ref Preflow algorithm), thus it has \f$O(n^3\sqrt{e})\f$ overall … … 61 61 #ifdef DOXYGEN 62 62 template <typename GR, 63 63 typename CAP> 64 64 #else 65 65 template <typename GR, 66 66 typename CAP = typename GR::template EdgeMap<int> > 67 67 #endif 68 68 class GomoryHu { … … 75 75 /// The value type of capacities 76 76 typedef typename Capacity::Value Value; 77 77 78 78 private: 79 79 … … 90 90 void createStructures() { 91 91 if (!_pred) { 92 92 _pred = new typename Graph::template NodeMap<Node>(_graph); 93 93 } 94 94 if (!_weight) { 95 95 _weight = new typename Graph::template NodeMap<Value>(_graph); 96 96 } 97 97 if (!_order) { 98 98 _order = new typename Graph::template NodeMap<int>(_graph); 99 99 } 100 100 } … … 102 102 void destroyStructures() { 103 103 if (_pred) { 104 104 delete _pred; 105 105 } 106 106 if (_weight) { 107 107 delete _weight; 108 108 } 109 109 if (_order) { 110 111 } 112 } 113 110 delete _order; 111 } 112 } 113 114 114 public: 115 115 … … 119 119 /// \param graph The undirected graph the algorithm runs on. 120 120 /// \param capacity The edge capacity map. 121 GomoryHu(const Graph& graph, const Capacity& capacity) 121 GomoryHu(const Graph& graph, const Capacity& capacity) 122 122 : _graph(graph), _capacity(capacity), 123 _pred(0), _weight(0), _order(0) 123 _pred(0), _weight(0), _order(0) 124 124 { 125 125 checkConcept<concepts::ReadMap<Edge, Value>, Capacity>(); … … 135 135 136 136 private: 137 137 138 138 // Initialize the internal data structures 139 139 void init() { … … 146 146 } 147 147 (*_pred)[_root] = INVALID; 148 (*_weight)[_root] = std::numeric_limits<Value>::max(); 148 (*_weight)[_root] = std::numeric_limits<Value>::max(); 149 149 } 150 150 … … 155 155 156 156 for (NodeIt n(_graph); n != INVALID; ++n) { 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 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 } 178 178 } 179 179 … … 182 182 183 183 for (NodeIt n(_graph); n != INVALID; ++n) { 184 185 186 187 188 189 190 191 192 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 } 194 194 } 195 195 } … … 198 198 199 199 ///\name Execution Control 200 200 201 201 ///@{ 202 202 … … 208 208 start(); 209 209 } 210 210 211 211 /// @} 212 212 … … 233 233 /// Gomory-Hu tree. 234 234 /// 235 /// This function returns the weight of the predecessor edge of the 235 /// This function returns the weight of the predecessor edge of the 236 236 /// given node in the Gomory-Hu tree. 237 237 /// If \c node is the root of the tree, the result is undefined. … … 255 255 /// 256 256 /// This function returns the minimum cut value between the nodes 257 /// \c s and \c t. 257 /// \c s and \c t. 258 258 /// It finds the nearest common ancestor of the given nodes in the 259 259 /// Gomory-Hu tree and calculates the minimum weight edge on the … … 264 264 Node sn = s, tn = t; 265 265 Value value = std::numeric_limits<Value>::max(); 266 266 267 267 while (sn != tn) { 268 269 270 271 272 273 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 } 275 275 } 276 276 return value; … … 295 295 /// \pre \ref run() must be called before using this function. 296 296 template <typename CutMap> 297 Value minCutMap(const Node& s, ///<297 Value minCutMap(const Node& s, 298 298 const Node& t, 299 ///<300 299 CutMap& cutMap 301 ///<302 300 ) const { 303 301 Node sn = s, tn = t; … … 305 303 Node rn = INVALID; 306 304 Value value = std::numeric_limits<Value>::max(); 307 305 308 306 while (sn != tn) { 309 310 311 307 if ((*_order)[sn] < (*_order)[tn]) { 308 if ((*_weight)[tn] <= value) { 309 rn = tn; 312 310 s_root = false; 313 314 315 316 317 318 311 value = (*_weight)[tn]; 312 } 313 tn = (*_pred)[tn]; 314 } else { 315 if ((*_weight)[sn] <= value) { 316 rn = sn; 319 317 s_root = true; 320 321 322 323 318 value = (*_weight)[sn]; 319 } 320 sn = (*_pred)[sn]; 321 } 324 322 } 325 323 … … 332 330 std::vector<Node> st; 333 331 for (NodeIt n(_graph); n != INVALID; ++n) { 334 332 st.clear(); 335 333 Node nn = n; 336 337 338 339 340 341 342 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 346 344 return value; 347 345 } … … 352 350 353 351 /// Iterate on the nodes of a minimum cut 354 352 355 353 /// This iterator class lists the nodes of a minimum cut found by 356 354 /// GomoryHu. Before using it, you must allocate a GomoryHu class … … 360 358 /// \c t. 361 359 /// \code 362 /// Gomor uHu<Graph> gom(g, capacities);360 /// GomoryHu<Graph> gom(g, capacities); 363 361 /// gom.run(); 364 362 /// int cnt=0; 365 /// for(Gomor uHu<Graph>::MinCutNodeIt n(gom,s,t); n!=INVALID; ++n) ++cnt;363 /// for(GomoryHu<Graph>::MinCutNodeIt n(gom,s,t); n!=INVALID; ++n) ++cnt; 366 364 /// \endcode 367 365 class MinCutNodeIt … … 395 393 /// \endcode 396 394 /// does not necessarily give the same set of nodes. 397 /// However it is ensured that395 /// However, it is ensured that 398 396 /// \code 399 397 /// MinCutNodeIt(gomory, s, t, true); … … 445 443 } 446 444 }; 447 445 448 446 friend class MinCutEdgeIt; 449 447 450 448 /// Iterate on the edges of a minimum cut 451 449 452 450 /// This iterator class lists the edges of a minimum cut found by 453 451 /// GomoryHu. Before using it, you must allocate a GomoryHu class … … 457 455 /// \c t. 458 456 /// \code 459 /// Gomor uHu<Graph> gom(g, capacities);457 /// GomoryHu<Graph> gom(g, capacities); 460 458 /// gom.run(); 461 459 /// int value=0; 462 /// for(Gomor uHu<Graph>::MinCutEdgeIt e(gom,s,t); e!=INVALID; ++e)460 /// for(GomoryHu<Graph>::MinCutEdgeIt e(gom,s,t); e!=INVALID; ++e) 463 461 /// value+=capacities[e]; 464 462 /// \endcode … … 482 480 } 483 481 } 484 482 485 483 public: 486 484 /// Constructor … … 551 549 } 552 550 /// Postfix incrementation 553 551 554 552 /// Postfix incrementation. 555 553 /// -
TabularUnified lemon/graph_to_eps.h ¶
r908 r1107 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 143 143 ///\param gr Reference to the graph to be printed. 144 144 ///\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>. 146 146 ///\param pros If it is \c true, then the \c ostream referenced by \c os 147 147 ///will be explicitly deallocated by the destructor. … … 513 513 ///Turn on/off pre-scaling 514 514 515 ///By default graphToEps() rescales the whole image in order to avoid515 ///By default, graphToEps() rescales the whole image in order to avoid 516 516 ///very big or very small bounding boxes. 517 517 /// … … 1115 1115 ///\param g Reference to the graph to be printed. 1116 1116 ///\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>. 1118 1118 /// 1119 1119 ///This function also has a lot of … … 1127 1127 ///\endcode 1128 1128 /// 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. 1130 1130 /// 1131 1131 ///\warning Don't forget to put the \ref GraphToEps::run() "run()" -
TabularUnified lemon/grid_graph.h ¶
r664 r834 471 471 /// \brief Grid graph class 472 472 /// 473 /// This classimplements a special graph type. The nodes of the474 /// graph can be indexed by two integer \c (i,j) valuewhere \c i is475 /// in the \c [0..width()-1] range and j is in the \c476 /// [0..height()-1] range.Two nodes are connected in the graph if477 /// the ind exes differ exactly on one position and exactly one is478 /// the difference. The nodes of the graph can be indexed by position479 /// with the \c operator()() function. The positions of the nodes can be480 /// get with\c pos(), \c col() and \c row() members. The outgoing473 /// 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 481 481 /// arcs can be retrieved with the \c right(), \c up(), \c left() 482 482 /// and \c down() functions, where the bottom-left corner is the 483 483 /// 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(). 484 488 /// 485 489 /// \image html grid_graph.png … … 497 501 ///\endcode 498 502 /// 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. 501 508 class GridGraph : public ExtendedGridGraphBase { 502 509 typedef ExtendedGridGraphBase Parent; … … 504 511 public: 505 512 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>". 509 518 class IndexMap { 510 519 public: … … 515 524 516 525 /// \brief Constructor 517 ///518 /// Constructor519 526 IndexMap(const GridGraph& graph) : _graph(graph) {} 520 527 521 528 /// \brief The subscript operator 522 ///523 /// The subscript operator.524 529 Value operator[](Key key) const { 525 530 return _graph.pos(key); … … 541 546 542 547 /// \brief Constructor 543 ///544 /// Constructor545 548 ColMap(const GridGraph& graph) : _graph(graph) {} 546 549 547 550 /// \brief The subscript operator 548 ///549 /// The subscript operator.550 551 Value operator[](Key key) const { 551 552 return _graph.col(key); … … 567 568 568 569 /// \brief Constructor 569 ///570 /// Constructor571 570 RowMap(const GridGraph& graph) : _graph(graph) {} 572 571 573 572 /// \brief The subscript operator 574 ///575 /// The subscript operator.576 573 Value operator[](Key key) const { 577 574 return _graph.row(key); … … 584 581 /// \brief Constructor 585 582 /// 586 /// Construct a grid graph with given size.583 /// Construct a grid graph with the given size. 587 584 GridGraph(int width, int height) { construct(width, height); } 588 585 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. 595 591 void resize(int width, int height) { 596 592 Parent::notifier(Arc()).clear(); … … 610 606 } 611 607 612 /// \brief Gives back the column index of the node.608 /// \brief The column index of the node. 613 609 /// 614 610 /// Gives back the column index of the node. … … 617 613 } 618 614 619 /// \brief Gives back the row index of the node.615 /// \brief The row index of the node. 620 616 /// 621 617 /// Gives back the row index of the node. … … 624 620 } 625 621 626 /// \brief Gives back the position of the node.622 /// \brief The position of the node. 627 623 /// 628 624 /// Gives back the position of the node, ie. the <tt>(col,row)</tt> pair. … … 631 627 } 632 628 633 /// \brief Gives back the number of the columns.629 /// \brief The number of the columns. 634 630 /// 635 631 /// Gives back the number of the columns. … … 638 634 } 639 635 640 /// \brief Gives back the number of the rows.636 /// \brief The number of the rows. 641 637 /// 642 638 /// Gives back the number of the rows. … … 645 641 } 646 642 647 /// \brief Gives back the arc goes right from the node.643 /// \brief The arc goes right from the node. 648 644 /// 649 645 /// Gives back the arc goes right from the node. If there is not … … 653 649 } 654 650 655 /// \brief Gives back the arc goes left from the node.651 /// \brief The arc goes left from the node. 656 652 /// 657 653 /// Gives back the arc goes left from the node. If there is not … … 661 657 } 662 658 663 /// \brief Gives back the arc goes up from the node.659 /// \brief The arc goes up from the node. 664 660 /// 665 661 /// Gives back the arc goes up from the node. If there is not … … 669 665 } 670 666 671 /// \brief Gives back the arc goes down from the node.667 /// \brief The arc goes down from the node. 672 668 /// 673 669 /// Gives back the arc goes down from the node. If there is not -
TabularUnified lemon/hao_orlin.h ¶
r644 r956 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 32 32 /// \brief Implementation of the Hao-Orlin algorithm. 33 33 /// 34 /// Implementation of the Hao-Orlin algorithm for finding a minimum cut 34 /// Implementation of the Hao-Orlin algorithm for finding a minimum cut 35 35 /// in a digraph. 36 36 … … 42 42 /// 43 43 /// 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$. 45 45 /// It takes a fixed node \f$ source \in V \f$ and 46 46 /// consists of two phases: in the first phase it determines a … … 59 59 /// For an undirected graph you can run just the first phase of the 60 60 /// 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$ 62 62 /// time. It is implemented in the NagamochiIbaraki algorithm class. 63 63 /// … … 77 77 class HaoOrlin { 78 78 public: 79 79 80 80 /// The digraph type of the algorithm 81 81 typedef GR Digraph; … … 164 164 delete _flow; 165 165 } 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; 166 183 } 167 184 … … 848 865 /// 849 866 /// 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. 851 868 /// The given node is used as the source node for the push-relabel 852 869 /// algorithm. … … 928 945 /// \brief Run the algorithm. 929 946 /// 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, 931 948 /// finds a proper \c target node and then calls the \ref init(), 932 949 /// \ref calculateOut() and \ref calculateIn(). … … 942 959 /// The result of the %HaoOrlin algorithm 943 960 /// can be obtained using these functions.\n 944 /// \ref run(), \ref calculateOut() or \ref calculateIn() 961 /// \ref run(), \ref calculateOut() or \ref calculateIn() 945 962 /// should be called before using them. 946 963 … … 951 968 /// This function returns the value of the minimum cut. 952 969 /// 953 /// \pre \ref run(), \ref calculateOut() or \ref calculateIn() 970 /// \pre \ref run(), \ref calculateOut() or \ref calculateIn() 954 971 /// must be called before using this function. 955 972 Value minCutValue() const { … … 970 987 /// \return The value of the minimum cut. 971 988 /// 972 /// \pre \ref run(), \ref calculateOut() or \ref calculateIn() 989 /// \pre \ref run(), \ref calculateOut() or \ref calculateIn() 973 990 /// must be called before using this function. 974 991 template <typename CutMap> -
TabularUnified lemon/hypercube_graph.h ¶
r664 r835 263 263 } 264 264 265 int index(Node node) const{265 static int index(Node node) { 266 266 return node._id; 267 267 } … … 283 283 /// \brief Hypercube graph class 284 284 /// 285 /// This class implements a special graph type. The nodes of the graph286 /// are indiced with integers withat 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. 287 287 /// Two nodes are connected in the graph if and only if their indices 288 288 /// 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. 289 298 /// 290 299 /// \note The type of the indices is chosen to \c int for efficiency 291 300 /// reasons. Thus the maximum dimension of this implementation is 26 292 301 /// (assuming that the size of \c int is 32 bit). 293 ///294 /// This graph type fully conforms to the \ref concepts::Graph295 /// "Graph concept".296 302 class HypercubeGraph : public ExtendedHypercubeGraphBase { 297 303 typedef ExtendedHypercubeGraphBase Parent; … … 303 309 /// Constructs a hypercube graph with \c dim dimensions. 304 310 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 } 305 326 306 327 /// \brief The number of dimensions. … … 321 342 /// 322 343 /// 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>. 324 345 int dimension(Edge edge) const { 325 346 return Parent::dimension(edge); … … 329 350 /// 330 351 /// 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>. 332 353 int dimension(Arc arc) const { 333 354 return Parent::dimension(arc); … … 338 359 /// Gives back the index of the given node. 339 360 /// The lower bits of the integer describes the node. 340 int index(Node node) const{361 static int index(Node node) { 341 362 return Parent::index(node); 342 363 } -
TabularUnified lemon/lgf_reader.h ¶
r1069 r1110 428 428 ///\endcode 429 429 /// 430 /// By default the reader uses the first section in the file of the430 /// By default, the reader uses the first section in the file of the 431 431 /// proper type. If a section has an optional name, then it can be 432 432 /// selected for reading by giving an optional name parameter to the … … 563 563 friend DigraphReader<TDGR> digraphReader(TDGR& digraph, std::istream& is); 564 564 template <typename TDGR> 565 friend DigraphReader<TDGR> digraphReader(TDGR& digraph, 565 friend DigraphReader<TDGR> digraphReader(TDGR& digraph, 566 566 const std::string& fn); 567 567 template <typename TDGR> … … 1195 1195 1196 1196 }; 1197 1197 1198 1198 /// \ingroup lemon_io 1199 1199 /// … … 1202 1202 /// This function just returns a \ref DigraphReader class. 1203 1203 /// 1204 /// With this function a digraph can be read from an 1204 /// With this function a digraph can be read from an 1205 1205 /// \ref lgf-format "LGF" file or input stream with several maps and 1206 1206 /// attributes. For example, there is network flow problem on a … … 1257 1257 template <typename GR> 1258 1258 class GraphReader; 1259 1259 1260 1260 template <typename TGR> 1261 1261 GraphReader<TGR> graphReader(TGR& graph, std::istream& is = std::cin); … … 1394 1394 friend GraphReader<TGR> graphReader(TGR& graph, std::istream& is); 1395 1395 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); 1397 1397 template <typename TGR> 1398 1398 friend GraphReader<TGR> graphReader(TGR& graph, const char *fn); … … 2078 2078 /// \brief Return a \ref GraphReader class 2079 2079 /// 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 2083 2083 /// \ref lgf-format "LGF" file or input stream with several maps and 2084 2084 /// attributes. For example, there is weighted matching problem on a … … 2236 2236 /// whitespaces are trimmed from each processed string. 2237 2237 /// 2238 /// For example let's see a section, which contain several2238 /// For example, let's see a section, which contain several 2239 2239 /// integers, which should be inserted into a vector. 2240 2240 ///\code -
TabularUnified lemon/lgf_writer.h ¶
r646 r956 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 352 352 353 353 template <typename TDGR> 354 DigraphWriter<TDGR> digraphWriter(const TDGR& digraph, 354 DigraphWriter<TDGR> digraphWriter(const TDGR& digraph, 355 355 std::ostream& os = std::cout); 356 356 template <typename TDGR> … … 505 505 506 506 template <typename TDGR> 507 friend DigraphWriter<TDGR> digraphWriter(const TDGR& digraph, 507 friend DigraphWriter<TDGR> digraphWriter(const TDGR& digraph, 508 508 std::ostream& os); 509 509 template <typename TDGR> … … 918 918 /// \brief Return a \ref DigraphWriter class 919 919 /// 920 /// This function just returns a \ref DigraphWriter class. 920 /// This function just returns a \ref DigraphWriter class. 921 921 /// 922 922 /// With this function a digraph can be write to a file or output … … 958 958 /// \sa digraphWriter(const TDGR& digraph, std::ostream& os) 959 959 template <typename TDGR> 960 DigraphWriter<TDGR> digraphWriter(const TDGR& digraph, 960 DigraphWriter<TDGR> digraphWriter(const TDGR& digraph, 961 961 const std::string& fn) { 962 962 DigraphWriter<TDGR> tmp(digraph, fn); … … 1102 1102 friend GraphWriter<TGR> graphWriter(const TGR& graph, std::ostream& os); 1103 1103 template <typename TGR> 1104 friend GraphWriter<TGR> graphWriter(const TGR& graph, 1104 friend GraphWriter<TGR> graphWriter(const TGR& graph, 1105 1105 const std::string& fn); 1106 1106 template <typename TGR> 1107 1107 friend GraphWriter<TGR> graphWriter(const TGR& graph, const char *fn); 1108 1108 1109 1109 GraphWriter(GraphWriter& other) 1110 1110 : _os(other._os), local_os(other.local_os), _graph(other._graph), … … 1557 1557 /// \brief Return a \ref GraphWriter class 1558 1558 /// 1559 /// This function just returns a \ref GraphWriter class. 1559 /// This function just returns a \ref GraphWriter class. 1560 1560 /// 1561 1561 /// With this function a graph can be write to a file or output -
TabularUnified lemon/list_graph.h ¶
r664 r956 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 22 22 ///\ingroup graphs 23 23 ///\file 24 ///\brief ListDigraph ,ListGraph classes.24 ///\brief ListDigraph and ListGraph classes. 25 25 26 26 #include <lemon/core.h> … … 32 32 33 33 namespace lemon { 34 35 class ListDigraph; 34 36 35 37 class ListDigraphBase { … … 63 65 class Node { 64 66 friend class ListDigraphBase; 67 friend class ListDigraph; 65 68 protected: 66 69 … … 78 81 class Arc { 79 82 friend class ListDigraphBase; 83 friend class ListDigraph; 80 84 protected: 81 85 … … 117 121 int n; 118 122 for(n = first_node; 119 n !=-1 && nodes[n].first_in== -1;123 n != -1 && nodes[n].first_out == -1; 120 124 n = nodes[n].next) {} 121 arc.id = (n == -1) ? -1 : nodes[n].first_ in;125 arc.id = (n == -1) ? -1 : nodes[n].first_out; 122 126 } 123 127 124 128 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; 127 131 } else { 128 132 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; 131 135 n = nodes[n].next) {} 132 arc.id = (n == -1) ? -1 : nodes[n].first_ in;136 arc.id = (n == -1) ? -1 : nodes[n].first_out; 133 137 } 134 138 } … … 312 316 ///A general directed graph structure. 313 317 314 ///\ref ListDigraph is a simple and fast <em>directed graph</em>315 ///implementation based on staticlinked lists that are stored in318 ///\ref ListDigraph is a versatile and fast directed graph 319 ///implementation based on linked lists that are stored in 316 320 ///\c std::vector structures. 317 321 /// 318 /// It conforms to the \ref concepts::Digraph "Digraph concept" and it319 ///a lso provides several useful additional functionalities.320 ///Most of themember functions and nested classes are documented322 ///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 321 325 ///only in the concept class. 322 326 /// 327 ///This class provides only linear time counting for nodes and arcs. 328 /// 323 329 ///\sa concepts::Digraph 324 330 ///\sa ListGraph 325 331 class ListDigraph : public ExtendedListDigraphBase { 326 332 typedef ExtendedListDigraphBase Parent; 327 333 328 334 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. 333 336 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. 339 339 void operator=(const ListDigraph &) {} 340 340 public: … … 348 348 ///Add a new node to the digraph. 349 349 350 /// Adda new node to the digraph.350 ///This function adds a new node to the digraph. 351 351 ///\return The new node. 352 352 Node addNode() { return Parent::addNode(); } … … 354 354 ///Add a new arc to the digraph. 355 355 356 /// Adda new arc to the digraph with source node \c s356 ///This function adds a new arc to the digraph with source node \c s 357 357 ///and target node \c t. 358 358 ///\return The new arc. 359 Arc addArc( const Node& s, const Node&t) {359 Arc addArc(Node s, Node t) { 360 360 return Parent::addArc(s, t); 361 361 } … … 363 363 ///\brief Erase a node from the digraph. 364 364 /// 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); } 368 371 369 372 ///\brief Erase an arc from the digraph. 370 373 /// 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); } 374 379 375 380 /// Node validity check 376 381 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. 383 387 bool valid(Node n) const { return Parent::valid(n); } 384 388 385 389 /// Arc validity check 386 390 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. 393 396 bool valid(Arc a) const { return Parent::valid(a); } 394 397 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. 402 404 /// 403 405 ///\warning This functionality cannot be used together with the Snapshot … … 406 408 Parent::changeTarget(a,n); 407 409 } 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. 415 416 /// 416 417 ///\warning This functionality cannot be used together with the Snapshot … … 420 421 } 421 422 422 /// Invertthe direction of an arc.423 424 /// \note The <tt>ArcIt</tt>s referencing the changed arc remain425 /// valid. However <tt>OutArcIt</tt>s and <tt>InArcIt</tt>s are426 /// 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. 427 428 /// 428 429 ///\warning This functionality cannot be used together with the Snapshot 429 430 ///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 } 455 436 456 437 ///Contract two nodes. 457 438 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. 467 451 /// 468 452 ///\warning This functionality cannot be used together with the Snapshot 469 453 ///feature. 470 void contract(Node a, Node b, bool r = true)454 void contract(Node u, Node v, bool r = true) 471 455 { 472 for(OutArcIt e(*this, b);e!=INVALID;) {456 for(OutArcIt e(*this,v);e!=INVALID;) { 473 457 OutArcIt f=e; 474 458 ++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); 477 461 e=f; 478 462 } 479 for(InArcIt e(*this, b);e!=INVALID;) {463 for(InArcIt e(*this,v);e!=INVALID;) { 480 464 InArcIt f=e; 481 465 ++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); 484 468 e=f; 485 469 } 486 erase( b);470 erase(v); 487 471 } 488 472 489 473 ///Split a node. 490 474 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. 495 481 ///\return The newly created node. 496 482 /// 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 502 486 ///Snapshot feature. 503 487 Node split(Node n, bool connect = true) { 504 488 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; 510 493 } 511 494 if (connect) addArc(n,b); … … 515 498 ///Split an arc. 516 499 517 ///This function splits an arc. First a new node \c b is added to518 /// the digraph, then the original arc is re-targeted to \c519 /// 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. 521 504 ///\return The newly created node. 505 /// 506 ///\note \c InArcIt iterators referencing the original arc are 507 ///invalidated. Other iterators remain valid. 522 508 /// 523 509 ///\warning This functionality cannot be used together with the 524 510 ///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); }; 531 546 532 547 /// \brief Class to make a snapshot of the digraph and restore … … 538 553 /// restore() function. 539 554 /// 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 542 561 /// 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. 543 564 class Snapshot { 544 565 protected: … … 710 731 /// 711 732 /// Default constructor. 712 /// To actually make a snapshot you must call save().733 /// You have to call save() to actually make a snapshot. 713 734 Snapshot() 714 735 : digraph(0), node_observer_proxy(*this), … … 717 738 /// \brief Constructor that immediately makes a snapshot. 718 739 /// 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) 722 742 : node_observer_proxy(*this), 723 743 arc_observer_proxy(*this) { 724 attach( _digraph);744 attach(gr); 725 745 } 726 746 727 747 /// \brief Make a snapshot. 728 748 /// 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 732 751 /// 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) { 735 753 if (attached()) { 736 754 detach(); 737 755 clear(); 738 756 } 739 attach( _digraph);757 attach(gr); 740 758 } 741 759 742 760 /// \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. 745 767 void restore() { 746 768 detach(); … … 756 778 } 757 779 758 /// \brief Gives back true whenthe snapshot is valid.780 /// \brief Returns \c true if the snapshot is valid. 759 781 /// 760 /// Gives back true whenthe snapshot is valid.782 /// This function returns \c true if the snapshot is valid. 761 783 bool valid() const { 762 784 return attached(); … … 795 817 796 818 typedef ListGraphBase Graph; 797 798 class Node;799 class Arc;800 class Edge;801 819 802 820 class Node { … … 848 866 bool operator<(const Arc& arc) const {return id < arc.id;} 849 867 }; 850 851 852 868 853 869 ListGraphBase() … … 1165 1181 ///A general undirected graph structure. 1166 1182 1167 ///\ref ListGraph is a simple and fast <em>undirected graph</em>1168 ///implementation based on staticlinked lists that are stored in1183 ///\ref ListGraph is a versatile and fast undirected graph 1184 ///implementation based on linked lists that are stored in 1169 1185 ///\c std::vector structures. 1170 1186 /// 1171 /// It conforms to the \ref concepts::Graph "Graph concept" and it1172 ///a lso provides several useful additional functionalities.1173 ///Most of themember functions and nested classes are documented1187 ///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 1174 1190 ///only in the concept class. 1175 1191 /// 1192 ///This class provides only linear time counting for nodes, edges and arcs. 1193 /// 1176 1194 ///\sa concepts::Graph 1177 1195 ///\sa ListDigraph 1178 1196 class ListGraph : public ExtendedListGraphBase { 1179 1197 typedef ExtendedListGraphBase Parent; 1180 1198 1181 1199 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. 1186 1201 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. 1192 1204 void operator=(const ListGraph &) {} 1193 1205 public: … … 1202 1214 /// \brief Add a new node to the graph. 1203 1215 /// 1204 /// Adda new node to the graph.1216 /// This function adds a new node to the graph. 1205 1217 /// \return The new node. 1206 1218 Node addNode() { return Parent::addNode(); } … … 1208 1220 /// \brief Add a new edge to the graph. 1209 1221 /// 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. 1212 1225 /// \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); } 1228 1246 /// Node validity check 1229 1247 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 1235 1252 /// added to the graph. 1236 1253 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); } 1237 1262 /// Arc validity check 1238 1263 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 1244 1268 /// added to the graph. 1245 1269 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. 1263 1278 /// 1264 1279 ///\warning This functionality cannot be used together with the … … 1267 1282 Parent::changeU(e,n); 1268 1283 } 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. 1276 1292 /// 1277 1293 ///\warning This functionality cannot be used together with the … … 1280 1296 Parent::changeV(e,n); 1281 1297 } 1298 1282 1299 /// \brief Contract two nodes. 1283 1300 /// 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. 1292 1312 /// 1293 1313 ///\warning This functionality cannot be used together with the … … 1308 1328 } 1309 1329 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); }; 1310 1358 1311 1359 /// \brief Class to make a snapshot of the graph and restore … … 1317 1365 /// using the restore() function. 1318 1366 /// 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. 1322 1376 class Snapshot { 1323 1377 protected: … … 1489 1543 /// 1490 1544 /// Default constructor. 1491 /// To actually make a snapshot you must call save().1545 /// You have to call save() to actually make a snapshot. 1492 1546 Snapshot() 1493 1547 : graph(0), node_observer_proxy(*this), … … 1496 1550 /// \brief Constructor that immediately makes a snapshot. 1497 1551 /// 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) 1501 1554 : node_observer_proxy(*this), 1502 1555 edge_observer_proxy(*this) { 1503 attach( _graph);1556 attach(gr); 1504 1557 } 1505 1558 1506 1559 /// \brief Make a snapshot. 1507 1560 /// 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 1511 1563 /// 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) { 1514 1565 if (attached()) { 1515 1566 detach(); 1516 1567 clear(); 1517 1568 } 1518 attach( _graph);1569 attach(gr); 1519 1570 } 1520 1571 1521 1572 /// \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. 1524 1579 void restore() { 1525 1580 detach(); … … 1535 1590 } 1536 1591 1537 /// \brief Gives back true whenthe snapshot is valid.1592 /// \brief Returns \c true if the snapshot is valid. 1538 1593 /// 1539 /// Gives back true whenthe snapshot is valid.1594 /// This function returns \c true if the snapshot is valid. 1540 1595 bool valid() const { 1541 1596 return attached(); -
TabularUnified lemon/lp.h ¶
r674 r956 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 085 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 85 85 #elif LEMON_HAVE_CLP 86 86 # define DEFAULT_LP CLP 87 typedef ClpLp Lp; 87 typedef ClpLp Lp; 88 88 #endif 89 89 #endif -
TabularUnified lemon/lp_base.cc ¶
r557 r956 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 085 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). -
TabularUnified lemon/lp_base.h ¶
r1092 r1100 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 085 * Copyright (C) 2003-2011 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 83 83 MESSAGE_VERBOSE 84 84 }; 85 85 86 86 87 87 ///The floating point type used by the solver … … 115 115 typedef True LpCol; 116 116 /// Default constructor 117 117 118 118 /// \warning The default constructor sets the Col to an 119 119 /// undefined value. 120 120 Col() {} 121 121 /// Invalid constructor \& conversion. 122 122 123 123 /// This constructor initializes the Col to be invalid. 124 /// \sa Invalid for more details. 124 /// \sa Invalid for more details. 125 125 Col(const Invalid&) : _id(-1) {} 126 126 /// Equality operator … … 147 147 ///Iterator for iterate over the columns of an LP problem 148 148 149 /// Its usage is quite simple, for example you can count the number149 /// Its usage is quite simple, for example, you can count the number 150 150 /// of columns in an LP \c lp: 151 151 ///\code … … 157 157 public: 158 158 /// Default constructor 159 159 160 160 /// \warning The default constructor sets the iterator 161 161 /// to an undefined value. 162 162 ColIt() {} 163 163 /// Sets the iterator to the first Col 164 164 165 165 /// Sets the iterator to the first Col. 166 166 /// … … 170 170 } 171 171 /// Invalid constructor \& conversion 172 172 173 173 /// Initialize the iterator to be invalid. 174 174 /// \sa Invalid for more details. 175 175 ColIt(const Invalid&) : Col(INVALID) {} 176 176 /// Next column 177 177 178 178 /// Assign the iterator to the next column. 179 179 /// … … 210 210 typedef True LpRow; 211 211 /// Default constructor 212 212 213 213 /// \warning The default constructor sets the Row to an 214 214 /// undefined value. 215 215 Row() {} 216 216 /// Invalid constructor \& conversion. 217 217 218 218 /// This constructor initializes the Row to be invalid. 219 /// \sa Invalid for more details. 219 /// \sa Invalid for more details. 220 220 Row(const Invalid&) : _id(-1) {} 221 221 /// Equality operator … … 225 225 bool operator==(Row r) const {return _id == r._id;} 226 226 /// Inequality operator 227 227 228 228 /// \sa operator==(Row r) 229 229 /// … … 242 242 ///Iterator for iterate over the rows of an LP problem 243 243 244 /// Its usage is quite simple, for example you can count the number244 /// Its usage is quite simple, for example, you can count the number 245 245 /// of rows in an LP \c lp: 246 246 ///\code … … 252 252 public: 253 253 /// Default constructor 254 254 255 255 /// \warning The default constructor sets the iterator 256 256 /// to an undefined value. 257 257 RowIt() {} 258 258 /// Sets the iterator to the first Row 259 259 260 260 /// Sets the iterator to the first Row. 261 261 /// … … 265 265 } 266 266 /// Invalid constructor \& conversion 267 267 268 268 /// Initialize the iterator to be invalid. 269 269 /// \sa Invalid for more details. 270 270 RowIt(const Invalid&) : Row(INVALID) {} 271 271 /// Next row 272 272 273 273 /// Assign the iterator to the next row. 274 274 /// … … 348 348 typedef True SolverExpr; 349 349 /// Default constructor 350 350 351 351 /// Construct an empty expression, the coefficients and 352 352 /// the constant component are initialized to zero. … … 449 449 450 450 ///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 /// 454 454 ///\code 455 455 ///double s=0; … … 465 465 466 466 /// Sets the iterator to the first term 467 467 468 468 /// Sets the iterator to the first term of the expression. 469 469 /// … … 482 482 const Value& operator*() const { return _it->second; } 483 483 /// Next term 484 484 485 485 /// Assign the iterator to the next term. 486 486 /// … … 494 494 495 495 /// 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 /// 499 499 ///\code 500 500 ///double s=0; … … 510 510 511 511 /// Sets the iterator to the first term 512 512 513 513 /// Sets the iterator to the first term of the expression. 514 514 /// … … 525 525 526 526 /// Next term 527 527 528 528 /// Assign the iterator to the next term. 529 529 /// … … 674 674 typedef True SolverExpr; 675 675 /// Default constructor 676 676 677 677 /// Construct an empty expression, the coefficients are 678 678 /// initialized to zero. … … 709 709 } 710 710 /// \brief Removes the coefficients which's absolute value does 711 /// not exceed \c epsilon. 711 /// not exceed \c epsilon. 712 712 void simplify(Value epsilon = 0.0) { 713 713 std::map<int, Value>::iterator it=comps.begin(); … … 758 758 759 759 ///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 /// 763 763 ///\code 764 764 ///double s=0; … … 774 774 775 775 /// Sets the iterator to the first term 776 776 777 777 /// Sets the iterator to the first term of the expression. 778 778 /// … … 792 792 793 793 /// Next term 794 794 795 795 /// Assign the iterator to the next term. 796 796 /// … … 804 804 805 805 ///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 /// 809 809 ///\code 810 810 ///double s=0; … … 820 820 821 821 /// Sets the iterator to the first term 822 822 823 823 /// Sets the iterator to the first term of the expression. 824 824 /// … … 835 835 836 836 /// Next term 837 837 838 838 /// Assign the iterator to the next term. 839 839 /// … … 943 943 virtual int _addCol() = 0; 944 944 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 } 945 953 946 954 virtual void _eraseCol(int col) = 0; … … 1208 1216 ///\return The created row. 1209 1217 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)); 1212 1222 return r; 1213 1223 } … … 1218 1228 ///\return The created row. 1219 1229 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)); 1222 1236 return r; 1223 1237 } … … 1804 1818 enum VarStatus { 1805 1819 /// The variable is in the basis 1806 BASIC, 1820 BASIC, 1807 1821 /// The variable is free, but not basic 1808 1822 FREE, 1809 /// The variable has active lower bound 1823 /// The variable has active lower bound 1810 1824 LOWER, 1811 1825 /// The variable has active upper bound … … 1886 1900 } 1887 1901 /// Returns a component of the primal ray 1888 1902 1889 1903 /// The primal ray is solution of the modified primal problem, 1890 1904 /// where we change each finite bound to 0, and we looking for a … … 1920 1934 1921 1935 /// Returns a component of the dual ray 1922 1936 1923 1937 /// The dual ray is solution of the modified primal problem, where 1924 1938 /// we change each finite bound to 0 (i.e. the objective function … … 2062 2076 } 2063 2077 ///The value of the objective function 2064 2078 2065 2079 ///\return 2066 2080 ///- \ref INF or -\ref INF means either infeasibility or unboundedness -
TabularUnified lemon/lp_skeleton.cc ¶
r623 r956 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 085 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 29 29 30 30 int SkeletonSolverBase::_addRow() 31 { 32 return ++row_num; 33 } 34 35 int SkeletonSolverBase::_addRow(Value, ExprIterator, ExprIterator, Value) 31 36 { 32 37 return ++row_num; -
TabularUnified lemon/lp_skeleton.h ¶
r623 r956 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 085 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 24 24 ///\file 25 25 ///\brief Skeleton file to implement LP/MIP solver interfaces 26 /// 26 /// 27 27 ///The classes in this file do nothing, but they can serve as skeletons when 28 28 ///implementing an interface to new solvers. … … 30 30 31 31 ///A skeleton class to implement LP/MIP solver base interface 32 32 33 33 ///This class does nothing, but it can serve as a skeleton when 34 34 ///implementing an interface to new solvers. … … 45 45 /// \e 46 46 virtual int _addRow(); 47 /// \e 48 virtual int _addRow(Value l, ExprIterator b, ExprIterator e, Value u); 47 49 /// \e 48 50 virtual void _eraseCol(int i); -
TabularUnified lemon/maps.h ¶
r731 r1084 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2011 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 23 23 #include <functional> 24 24 #include <vector> 25 #include <map> 25 26 26 27 #include <lemon/core.h> … … 29 30 ///\ingroup maps 30 31 ///\brief Miscellaneous property maps 31 32 #include <map>33 32 34 33 namespace lemon { … … 58 57 /// but data written to it is not required (i.e. it will be sent to 59 58 /// <tt>/dev/null</tt>). 60 /// It conforms t he \ref concepts::ReadWriteMap "ReadWriteMap" concept.59 /// It conforms to the \ref concepts::ReadWriteMap "ReadWriteMap" concept. 61 60 /// 62 61 /// \sa ConstMap … … 91 90 /// 92 91 /// In other aspects it is equivalent to \c NullMap. 93 /// So it conforms t he \ref concepts::ReadWriteMap "ReadWriteMap"92 /// So it conforms to the \ref concepts::ReadWriteMap "ReadWriteMap" 94 93 /// concept, but it absorbs the data written to it. 95 94 /// … … 160 159 /// 161 160 /// In other aspects it is equivalent to \c NullMap. 162 /// So it conforms t he \ref concepts::ReadWriteMap "ReadWriteMap"161 /// So it conforms to the \ref concepts::ReadWriteMap "ReadWriteMap" 163 162 /// concept, but it absorbs the data written to it. 164 163 /// … … 232 231 /// This map is essentially a wrapper for \c std::vector. It assigns 233 232 /// values to integer keys from the range <tt>[0..size-1]</tt>. 234 /// It can be used with some data structures, for example235 /// \c UnionFind, \c BinHeap, when the used items are small236 /// integers. This map conforms t he \ref concepts::ReferenceMap233 /// 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 237 236 /// "ReferenceMap" concept. 238 237 /// … … 342 341 /// stored actually. This value can be different from the default 343 342 /// contructed value (i.e. \c %Value()). 344 /// This type conforms t he \ref concepts::ReferenceMap "ReferenceMap"343 /// This type conforms to the \ref concepts::ReferenceMap "ReferenceMap" 345 344 /// concept. 346 345 /// … … 350 349 /// The name of this type also refers to this important usage. 351 350 /// 352 /// Apart form that this map can be used in many other cases since it351 /// Apart form that, this map can be used in many other cases since it 353 352 /// 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 other353 /// However, keep in mind that it is usually not as efficient as other 355 354 /// maps. 356 355 /// … … 708 707 /// The \c Key type of it is inherited from \c M and the \c Value 709 708 /// type is \c V. 710 /// This type conforms t he \ref concepts::ReadMap "ReadMap" concept.709 /// This type conforms to the \ref concepts::ReadMap "ReadMap" concept. 711 710 /// 712 711 /// The simplest way of using this map is through the convertMap() … … 1787 1786 /// The most important usage of it is storing certain nodes or arcs 1788 1787 /// that were marked \c true by an algorithm. 1789 /// For example it makes easier to store the nodes in the processing1788 /// For example, it makes easier to store the nodes in the processing 1790 1789 /// order of Dfs algorithm, as the following examples show. 1791 1790 /// \code 1792 1791 /// 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); 1794 1793 /// \endcode 1795 1794 /// \code 1796 1795 /// std::vector<Node> v(countNodes(g)); 1797 /// dfs(g ,s).processedMap(loggerBoolMap(v.begin())).run();1796 /// dfs(g).processedMap(loggerBoolMap(v.begin())).run(s); 1798 1797 /// \endcode 1799 1798 /// … … 1802 1801 /// 1803 1802 /// \note LoggerBoolMap is just \ref concepts::WriteMap "writable", so 1804 /// it cannot be used when a readable map is needed, for example as1803 /// it cannot be used when a readable map is needed, for example, as 1805 1804 /// \c ReachedMap for \c Bfs, \c Dfs and \c Dijkstra algorithms. 1806 1805 /// … … 1819 1818 /// 1820 1819 /// 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 1822 1821 /// - \b unique: different items get different ids, 1823 1822 /// - \b immutable: the id of an item does not change (even if you … … 1827 1826 /// the items stored in the graph, which is returned by the \c id() 1828 1827 /// 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. 1830 1829 /// 1831 1830 /// \tparam GR The graph type. … … 1867 1866 public: 1868 1867 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. 1872 1873 /// \see inverse() 1873 1874 class InverseMap { … … 1884 1885 explicit InverseMap(const IdMap& map) : _graph(map._graph) {} 1885 1886 1886 /// \brief Gives back the given item fromits id.1887 /// \brief Gives back an item by its id. 1887 1888 /// 1888 /// Gives back the given item fromits id.1889 /// Gives back an item by its id. 1889 1890 Item operator[](int id) const { return _graph->fromId(id, Item());} 1890 1891 … … 1899 1900 }; 1900 1901 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 } 1901 1910 1902 1911 /// \brief General cross reference graph map type. … … 1905 1914 /// It wraps a standard graph map (\c NodeMap, \c ArcMap or \c EdgeMap) 1906 1915 /// 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. 1909 1927 /// 1910 1928 /// This type is not reference map, so it cannot be modified with … … 1947 1965 /// \brief Forward iterator for values. 1948 1966 /// 1949 /// This iterator is an stlcompatible forward1967 /// This iterator is an STL compatible forward 1950 1968 /// iterator on the values of the map. The values can 1951 1969 /// be accessed in the <tt>[beginValue, endValue)</tt> range. 1952 1970 /// They are considered with multiplicity, so each value is 1953 1971 /// traversed for each item it is assigned to. 1954 class ValueIt erator1972 class ValueIt 1955 1973 : public std::iterator<std::forward_iterator_tag, Value> { 1956 1974 friend class CrossRefMap; 1957 1975 private: 1958 ValueIt erator(typename Container::const_iterator _it)1976 ValueIt(typename Container::const_iterator _it) 1959 1977 : it(_it) {} 1960 1978 public: 1961 1979 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); 1967 1988 operator++(); 1968 1989 return tmp; 1969 1990 } 1970 1991 1992 /// \e 1971 1993 const Value& operator*() const { return it->first; } 1994 /// \e 1972 1995 const Value* operator->() const { return &(it->first); } 1973 1996 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; } 1976 2001 1977 2002 private: … … 1979 2004 }; 1980 2005 2006 /// Alias for \c ValueIt 2007 typedef ValueIt ValueIterator; 2008 1981 2009 /// \brief Returns an iterator to the first value. 1982 2010 /// 1983 /// Returns an stlcompatible iterator to the2011 /// Returns an STL compatible iterator to the 1984 2012 /// first value of the map. The values of the 1985 2013 /// map can be accessed in the <tt>[beginValue, endValue)</tt> 1986 2014 /// range. 1987 ValueIt eratorbeginValue() const {1988 return ValueIt erator(_inv_map.begin());2015 ValueIt beginValue() const { 2016 return ValueIt(_inv_map.begin()); 1989 2017 } 1990 2018 1991 2019 /// \brief Returns an iterator after the last value. 1992 2020 /// 1993 /// Returns an stlcompatible iterator after the2021 /// Returns an STL compatible iterator after the 1994 2022 /// last value of the map. The values of the 1995 2023 /// map can be accessed in the <tt>[beginValue, endValue)</tt> 1996 2024 /// range. 1997 ValueIt eratorendValue() const {1998 return ValueIt erator(_inv_map.end());2025 ValueIt endValue() const { 2026 return ValueIt(_inv_map.end()); 1999 2027 } 2000 2028 … … 2033 2061 typename Container::const_iterator it = _inv_map.find(val); 2034 2062 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); 2035 2071 } 2036 2072 … … 2084 2120 public: 2085 2121 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() 2090 2128 class InverseMap { 2091 2129 public: … … 2114 2152 }; 2115 2153 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. 2119 2157 InverseMap inverse() const { 2120 2158 return InverseMap(*this); … … 2123 2161 }; 2124 2162 2125 /// \brief Provides continuous and unique IDfor the2163 /// \brief Provides continuous and unique id for the 2126 2164 /// items of a graph. 2127 2165 /// 2128 2166 /// RangeIdMap provides a unique and continuous 2129 /// IDfor each item of a given type (\c Node, \c Arc or2167 /// id for each item of a given type (\c Node, \c Arc or 2130 2168 /// \c Edge) in a graph. This id is 2131 2169 /// - \b unique: different items get different ids, … … 2138 2176 /// the \c id() function of the graph or \ref IdMap. 2139 2177 /// 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. 2141 2179 /// 2142 2180 /// \tparam GR The graph type. … … 2266 2304 } 2267 2305 2268 /// \brief Gives back the \e RangeId of the item2269 /// 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. 2271 2309 int operator[](const Item& item) const { 2272 2310 return Map::operator[](item); 2273 2311 } 2274 2312 2275 /// \brief Gives back the item belonging to a \e RangeId2276 /// 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. 2278 2316 Item operator()(int id) const { 2279 2317 return _inv_map[id]; … … 2289 2327 /// \brief The inverse map type of RangeIdMap. 2290 2328 /// 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. 2292 2332 class InverseMap { 2293 2333 public: … … 2307 2347 /// 2308 2348 /// Subscript operator. It gives back the item 2309 /// that the descriptorcurrently belongs to.2349 /// that the given \e range \e id currently belongs to. 2310 2350 Value operator[](const Key& key) const { 2311 2351 return _inverted(key); … … 2325 2365 /// \brief Gives back the inverse of the map. 2326 2366 /// 2327 /// Gives back the inverse of the map.2367 /// Gives back the inverse of the RangeIdMap. 2328 2368 const InverseMap inverse() const { 2329 2369 return InverseMap(*this); 2330 2370 } 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; 2331 3291 }; 2332 3292 … … 2341 3301 public: 2342 3302 2343 /// \e3303 /// The key type (the \c Arc type of the digraph). 2344 3304 typedef typename GR::Arc Key; 2345 /// \e3305 /// The value type (the \c Node type of the digraph). 2346 3306 typedef typename GR::Node Value; 2347 3307 … … 2382 3342 public: 2383 3343 2384 /// \e3344 /// The key type (the \c Arc type of the digraph). 2385 3345 typedef typename GR::Arc Key; 2386 /// \e3346 /// The value type (the \c Node type of the digraph). 2387 3347 typedef typename GR::Node Value; 2388 3348 … … 2424 3384 public: 2425 3385 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). 2426 3389 typedef typename GR::Arc Value; 2427 typedef typename GR::Edge Key;2428 3390 2429 3391 /// \brief Constructor … … 2464 3426 public: 2465 3427 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). 2466 3431 typedef typename GR::Arc Value; 2467 typedef typename GR::Edge Key;2468 3432 2469 3433 /// \brief Constructor … … 2500 3464 /// whenever the digraph changes. 2501 3465 /// 2502 /// \warning Besides \c addNode() and \c addArc(), a digraph structure 3466 /// \warning Besides \c addNode() and \c addArc(), a digraph structure 2503 3467 /// may provide alternative ways to modify the digraph. 2504 3468 /// The correct behavior of InDegMap is not guarantied if these additional 2505 /// features are used. For example the functions3469 /// features are used. For example, the functions 2506 3470 /// \ref ListDigraph::changeSource() "changeSource()", 2507 3471 /// \ref ListDigraph::changeTarget() "changeTarget()" and … … 2516 3480 2517 3481 public: 2518 3482 2519 3483 /// The graph type of InDegMap 2520 3484 typedef GR Graph; … … 2630 3594 /// whenever the digraph changes. 2631 3595 /// 2632 /// \warning Besides \c addNode() and \c addArc(), a digraph structure 3596 /// \warning Besides \c addNode() and \c addArc(), a digraph structure 2633 3597 /// may provide alternative ways to modify the digraph. 2634 3598 /// The correct behavior of OutDegMap is not guarantied if these additional 2635 /// features are used. For example the functions3599 /// features are used. For example, the functions 2636 3600 /// \ref ListDigraph::changeSource() "changeSource()", 2637 3601 /// \ref ListDigraph::changeTarget() "changeTarget()" and … … 2801 3765 } 2802 3766 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 2803 4054 /// @} 2804 4055 } -
TabularUnified lemon/matching.h ¶
r945 r956 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 17 17 */ 18 18 19 #ifndef LEMON_MA X_MATCHING_H20 #define LEMON_MA X_MATCHING_H19 #ifndef LEMON_MATCHING_H 20 #define LEMON_MATCHING_H 21 21 22 22 #include <vector> … … 29 29 #include <lemon/bin_heap.h> 30 30 #include <lemon/maps.h> 31 #include <lemon/fractional_matching.h> 31 32 32 33 ///\ingroup matching … … 42 43 /// This class implements Edmonds' alternating forest matching algorithm 43 44 /// 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 45 46 /// (the default is the empty one). 46 47 /// … … 70 71 ///\brief Status constants for Gallai-Edmonds decomposition. 71 72 /// 72 ///These constants are used for indicating the Gallai-Edmonds 73 ///These constants are used for indicating the Gallai-Edmonds 73 74 ///decomposition of a graph. The nodes with status \c EVEN (or \c D) 74 75 ///induce a subgraph with factor-critical components, the nodes with 75 76 ///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 77 78 ///perfect matching. 78 79 enum Status { … … 513 514 } 514 515 515 /// \brief Start Edmonds' algorithm with a heuristic improvement 516 /// \brief Start Edmonds' algorithm with a heuristic improvement 516 517 /// for dense graphs 517 518 /// … … 535 536 /// \brief Run Edmonds' algorithm 536 537 /// 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 539 540 /// (for which <tt>m>=2*n</tt> holds). 540 541 void run() { … … 557 558 /// \brief Return the size (cardinality) of the matching. 558 559 /// 559 /// This function returns the size (cardinality) of the current matching. 560 /// This function returns the size (cardinality) of the current matching. 560 561 /// After run() it returns the size of the maximum matching in the graph. 561 562 int matchingSize() const { … … 571 572 /// \brief Return \c true if the given edge is in the matching. 572 573 /// 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 574 575 /// matching. 575 576 bool matching(const Edge& edge) const { … … 580 581 /// 581 582 /// 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 583 584 /// not covered by the matching. 584 585 Arc matching(const Node& n) const { … … 596 597 /// \brief Return the mate of the given node. 597 598 /// 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 599 600 /// matching or \c INVALID if the node is not covered by the matching. 600 601 Node mate(const Node& n) const { … … 606 607 607 608 /// \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 609 610 /// decomposition. 610 611 … … 649 650 /// \f$O(nm\log n)\f$ time complexity. 650 651 /// 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 653 654 /// each node has at most one incident edge. 654 655 /// It can be formulated with the following linear program. … … 674 675 \frac{\vert B \vert - 1}{2}z_B\f] */ 675 676 /// 676 /// The algorithm can be executed with the run() function. 677 /// The algorithm can be executed with the run() function. 677 678 /// 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. 681 682 /// If the value type is integer, then the dual solution is multiplied 682 683 /// by \ref MaxWeightedMatching::dualScale "4". 683 684 /// 684 685 /// \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 686 687 /// \ref concepts::Graph::EdgeMap "GR::EdgeMap<int>". 687 688 #ifdef DOXYGEN … … 746 747 747 748 enum Status { 748 EVEN = -1, MATCHED = 0, ODD = 1 , UNMATCHED = -2749 EVEN = -1, MATCHED = 0, ODD = 1 749 750 }; 750 751 … … 798 799 799 800 Value _delta_sum; 801 int _unmatched; 802 803 typedef MaxWeightedFractionalMatching<Graph, WeightMap> FractionalMatching; 804 FractionalMatching *_fractional; 800 805 801 806 void createStructures() { … … 864 869 865 870 void destroyStructures() { 866 _node_num = countNodes(_graph);867 _blossom_num = _node_num * 3 / 2;868 869 871 if (_matching) { 870 872 delete _matching; … … 941 943 if (_delta3->state(e) != _delta3->IN_HEAP && blossom != vb) { 942 944 _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);947 945 } 948 946 } else { … … 969 967 (*_blossom_data)[vb].offset); 970 968 } else if ((*_delta2)[vb] > _blossom_set->classPrio(vb) - 971 (*_blossom_data)[vb].offset) {969 (*_blossom_data)[vb].offset) { 972 970 _delta2->decrease(vb, _blossom_set->classPrio(vb) - 973 971 (*_blossom_data)[vb].offset); … … 988 986 if (!_blossom_set->trivial(blossom)) { 989 987 _delta4->push(blossom, (*_blossom_data)[blossom].pot / 2 + 990 (*_blossom_data)[blossom].offset);988 (*_blossom_data)[blossom].offset); 991 989 } 992 990 } … … 1055 1053 } 1056 1054 } 1057 }1058 1059 } else if ((*_blossom_data)[vb].status == UNMATCHED) {1060 if (_delta3->state(e) == _delta3->IN_HEAP) {1061 _delta3->erase(e);1062 1055 } 1063 1056 } else { … … 1097 1090 std::numeric_limits<Value>::max()) { 1098 1091 _delta2->push(blossom, _blossom_set->classPrio(blossom) - 1099 1092 (*_blossom_data)[blossom].offset); 1100 1093 } 1101 1094 … … 1136 1129 if (_delta3->state(e) != _delta3->IN_HEAP && blossom != vb) { 1137 1130 _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);1142 1131 } 1143 1132 } else { … … 1177 1166 } 1178 1167 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 1274 1168 void alternatePath(int even, int tree) { 1275 1169 int odd; … … 1314 1208 destroyTree(tree); 1315 1209 1316 (*_blossom_data)[blossom].status = UNMATCHED;1317 1210 (*_blossom_data)[blossom].base = node; 1318 matchedToUnmatched(blossom); 1319 } 1320 1211 (*_blossom_data)[blossom].next = INVALID; 1212 } 1321 1213 1322 1214 void augmentOnEdge(const Edge& edge) { … … 1325 1217 int right = _blossom_set->find(_graph.v(edge)); 1326 1218 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); 1344 1226 1345 1227 (*_blossom_data)[left].next = _graph.direct(edge, true); 1346 1228 (*_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); 1347 1244 } 1348 1245 … … 1549 1446 (*_blossom_data)[sb].pred = pred; 1550 1447 (*_blossom_data)[sb].next = 1551 1448 _graph.oppositeArc((*_blossom_data)[tb].next); 1552 1449 1553 1450 pred = (*_blossom_data)[ub].next; … … 1649 1546 1650 1547 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) { 1652 1549 1653 1550 Value offset = (*_blossom_data)[blossoms[i]].offset; … … 1687 1584 _delta4_index(0), _delta4(0), 1688 1585 1689 _delta_sum() {} 1586 _delta_sum(), _unmatched(0), 1587 1588 _fractional(0) 1589 {} 1690 1590 1691 1591 ~MaxWeightedMatching() { 1692 1592 destroyStructures(); 1593 if (_fractional) { 1594 delete _fractional; 1595 } 1693 1596 } 1694 1597 … … 1721 1624 (*_delta4_index)[i] = _delta4->PRE_HEAP; 1722 1625 } 1723 1626 1627 _unmatched = _node_num; 1628 1724 1629 _delta1->clear(); 1725 1630 _delta2->clear(); … … 1765 1670 } 1766 1671 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 1767 1821 /// \brief Start the algorithm 1768 1822 /// 1769 1823 /// This function starts the algorithm. 1770 1824 /// 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. 1772 1827 void start() { 1773 1828 enum OpType { … … 1775 1830 }; 1776 1831 1777 int unmatched = _node_num; 1778 while (unmatched > 0) { 1832 while (_unmatched > 0) { 1779 1833 Value d1 = !_delta1->empty() ? 1780 1834 _delta1->prio() : std::numeric_limits<Value>::max(); … … 1789 1843 _delta4->prio() : std::numeric_limits<Value>::max(); 1790 1844 1791 _delta_sum = d1; OpType ot = D1; 1845 _delta_sum = d3; OpType ot = D3; 1846 if (d1 < _delta_sum) { _delta_sum = d1; ot = D1; } 1792 1847 if (d2 < _delta_sum) { _delta_sum = d2; ot = D2; } 1793 if (d3 < _delta_sum) { _delta_sum = d3; ot = D3; }1794 1848 if (d4 < _delta_sum) { _delta_sum = d4; ot = D4; } 1795 1796 1849 1797 1850 switch (ot) { … … 1800 1853 Node n = _delta1->top(); 1801 1854 unmatchNode(n); 1802 -- unmatched;1855 --_unmatched; 1803 1856 } 1804 1857 break; … … 1807 1860 int blossom = _delta2->top(); 1808 1861 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 } 1811 1869 } 1812 1870 break; … … 1821 1879 _delta3->pop(); 1822 1880 } 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); 1837 1883 1838 1884 if (left_tree == right_tree) { … … 1840 1886 } else { 1841 1887 augmentOnEdge(e); 1842 unmatched -= 2;1888 _unmatched -= 2; 1843 1889 } 1844 1890 } … … 1858 1904 /// \note mwm.run() is just a shortcut of the following code. 1859 1905 /// \code 1860 /// mwm. init();1906 /// mwm.fractionalInit(); 1861 1907 /// mwm.start(); 1862 1908 /// \endcode 1863 1909 void run() { 1864 init();1910 fractionalInit(); 1865 1911 start(); 1866 1912 } … … 1869 1915 1870 1916 /// \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 1872 1918 /// matching.\n 1873 1919 /// Either \ref run() or \ref start() function should be called before … … 1888 1934 } 1889 1935 } 1890 return sum / =2;1936 return sum / 2; 1891 1937 } 1892 1938 … … 1908 1954 /// \brief Return \c true if the given edge is in the matching. 1909 1955 /// 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 1911 1957 /// matching. 1912 1958 /// … … 1919 1965 /// 1920 1966 /// 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 1922 1968 /// not covered by the matching. 1923 1969 /// … … 1937 1983 /// \brief Return the mate of the given node. 1938 1984 /// 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 1940 1986 /// matching or \c INVALID if the node is not covered by the matching. 1941 1987 /// … … 1957 2003 /// \brief Return the value of the dual solution. 1958 2004 /// 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 1961 2007 /// "dual scale". 1962 2008 /// … … 2013 2059 /// \brief Iterator for obtaining the nodes of a blossom. 2014 2060 /// 2015 /// This class provides an iterator for obtaining the nodes of the 2061 /// This class provides an iterator for obtaining the nodes of the 2016 2062 /// 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 2018 2064 /// MaxWeightedMatching class and execute it. 2019 2065 class BlossomIt { … … 2024 2070 /// Constructor to get the nodes of the given variable. 2025 2071 /// 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 2028 2074 /// called before initializing this iterator. 2029 2075 BlossomIt(const MaxWeightedMatching& algorithm, int variable) … … 2078 2124 /// \f$O(nm\log n)\f$ time complexity. 2079 2125 /// 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 2082 2128 /// each node has exactly one incident edge. 2083 2129 /// It can be formulated with the following linear program. … … 2102 2148 \frac{\vert B \vert - 1}{2}z_B\f] */ 2103 2149 /// 2104 /// The algorithm can be executed with the run() function. 2150 /// The algorithm can be executed with the run() function. 2105 2151 /// 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. 2109 2155 /// If the value type is integer, then the dual solution is multiplied 2110 2156 /// by \ref MaxWeightedMatching::dualScale "4". 2111 2157 /// 2112 2158 /// \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 2114 2160 /// \ref concepts::Graph::EdgeMap "GR::EdgeMap<int>". 2115 2161 #ifdef DOXYGEN … … 2222 2268 2223 2269 Value _delta_sum; 2270 int _unmatched; 2271 2272 typedef MaxWeightedPerfectFractionalMatching<Graph, WeightMap> 2273 FractionalMatching; 2274 FractionalMatching *_fractional; 2224 2275 2225 2276 void createStructures() { … … 2283 2334 2284 2335 void destroyStructures() { 2285 _node_num = countNodes(_graph);2286 _blossom_num = _node_num * 3 / 2;2287 2288 2336 if (_matching) { 2289 2337 delete _matching; … … 2958 3006 _delta4_index(0), _delta4(0), 2959 3007 2960 _delta_sum() {} 3008 _delta_sum(), _unmatched(0), 3009 3010 _fractional(0) 3011 {} 2961 3012 2962 3013 ~MaxWeightedPerfectMatching() { 2963 3014 destroyStructures(); 3015 if (_fractional) { 3016 delete _fractional; 3017 } 2964 3018 } 2965 3019 … … 2989 3043 (*_delta4_index)[i] = _delta4->PRE_HEAP; 2990 3044 } 3045 3046 _unmatched = _node_num; 2991 3047 2992 3048 _delta2->clear(); … … 3031 3087 } 3032 3088 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 3033 3232 /// \brief Start the algorithm 3034 3233 /// 3035 3234 /// This function starts the algorithm. 3036 3235 /// 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. 3038 3238 bool start() { 3039 3239 enum OpType { … … 3041 3241 }; 3042 3242 3043 int unmatched = _node_num; 3044 while (unmatched > 0) { 3243 if (_unmatched == -1) return false; 3244 3245 while (_unmatched > 0) { 3045 3246 Value d2 = !_delta2->empty() ? 3046 3247 _delta2->prio() : std::numeric_limits<Value>::max(); … … 3052 3253 _delta4->prio() : std::numeric_limits<Value>::max(); 3053 3254 3054 _delta_sum = d 2; OpType ot = D2;3055 if (d 3 < _delta_sum) { _delta_sum = d3; ot = D3; }3255 _delta_sum = d3; OpType ot = D3; 3256 if (d2 < _delta_sum) { _delta_sum = d2; ot = D2; } 3056 3257 if (d4 < _delta_sum) { _delta_sum = d4; ot = D4; } 3057 3258 … … 3086 3287 } else { 3087 3288 augmentOnEdge(e); 3088 unmatched -= 2;3289 _unmatched -= 2; 3089 3290 } 3090 3291 } … … 3105 3306 /// \note mwpm.run() is just a shortcut of the following code. 3106 3307 /// \code 3107 /// mwpm. init();3308 /// mwpm.fractionalInit(); 3108 3309 /// mwpm.start(); 3109 3310 /// \endcode 3110 3311 bool run() { 3111 init();3312 fractionalInit(); 3112 3313 return start(); 3113 3314 } … … 3116 3317 3117 3318 /// \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 3119 3320 /// perfect matching.\n 3120 3321 /// Either \ref run() or \ref start() function should be called before … … 3135 3336 } 3136 3337 } 3137 return sum / =2;3338 return sum / 2; 3138 3339 } 3139 3340 3140 3341 /// \brief Return \c true if the given edge is in the matching. 3141 3342 /// 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 3143 3344 /// matching. 3144 3345 /// … … 3151 3352 /// 3152 3353 /// 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 3154 3355 /// not covered by the matching. 3155 3356 /// … … 3169 3370 /// \brief Return the mate of the given node. 3170 3371 /// 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 3172 3373 /// matching or \c INVALID if the node is not covered by the matching. 3173 3374 /// … … 3188 3389 /// \brief Return the value of the dual solution. 3189 3390 /// 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 3192 3393 /// "dual scale". 3193 3394 /// … … 3244 3445 /// \brief Iterator for obtaining the nodes of a blossom. 3245 3446 /// 3246 /// This class provides an iterator for obtaining the nodes of the 3447 /// This class provides an iterator for obtaining the nodes of the 3247 3448 /// 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 3249 3450 /// MaxWeightedPerfectMatching class and execute it. 3250 3451 class BlossomIt { … … 3255 3456 /// Constructor to get the nodes of the given variable. 3256 3457 /// 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()" 3259 3460 /// must be called before initializing this iterator. 3260 3461 BlossomIt(const MaxWeightedPerfectMatching& algorithm, int variable) … … 3302 3503 } //END OF NAMESPACE LEMON 3303 3504 3304 #endif //LEMON_MA X_MATCHING_H3505 #endif //LEMON_MATCHING_H -
TabularUnified lemon/math.h ¶
r558 r956 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 57 57 58 58 ///Check whether the parameter is NaN or not 59 59 60 60 ///This function checks whether the parameter is NaN or not. 61 61 ///Is should be equivalent with std::isnan(), but it is not -
TabularUnified lemon/min_cost_arborescence.h ¶
r672 r956 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 085 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 113 113 /// it is necessary. The default map type is \ref 114 114 /// 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 118 117 /// "MinCostArborescenceDefaultTraits<GR, CM>". 118 /// In most cases, this parameter should not be set directly, 119 /// consider to use the named template parameters instead. 119 120 #ifndef DOXYGEN 120 121 template <typename GR, … … 123 124 MinCostArborescenceDefaultTraits<GR, CM> > 124 125 #else 125 template <typename GR, typename CM, type defTR>126 template <typename GR, typename CM, typename TR> 126 127 #endif 127 128 class MinCostArborescence { 128 129 public: 129 130 130 /// \brief The \ref MinCostArborescenceDefaultTraits "traits class" 131 /// of the algorithm. 131 /// \brief The \ref MinCostArborescenceDefaultTraits "traits class" 132 /// of the algorithm. 132 133 typedef TR Traits; 133 134 /// The type of the underlying digraph. … … 436 437 /// \ref named-templ-param "Named parameter" for setting 437 438 /// \c PredMap type. 438 /// It must meet the \ref concepts::WriteMap "WriteMap" concept, 439 /// It must meet the \ref concepts::WriteMap "WriteMap" concept, 439 440 /// and its value type must be the \c Arc type of the digraph. 440 441 template <class T> … … 489 490 /// The simplest way to execute the algorithm is to use 490 491 /// one of the member functions called \c run(...). \n 491 /// If you need morecontrol on the execution,492 /// first you must call \ref init(), then you can add several492 /// If you need better control on the execution, 493 /// you have to call \ref init() first, then you can add several 493 494 /// source nodes with \ref addSource(). 494 495 /// Finally \ref start() will perform the arborescence -
TabularUnified lemon/network_simplex.h ¶
r976 r978 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 41 41 /// 42 42 /// \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. 47 49 /// 48 /// In general this classis the fastest implementation available49 /// in LEMON for th e minimum cost flowproblem.50 /// Moreover it supports both directions of the supply/demand inequality51 /// 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. 52 54 /// 53 55 /// Most of the parameters of the problem (except for the digraph) … … 57 59 /// 58 60 /// \tparam GR The digraph type the algorithm runs on. 59 /// \tparam V The valuetype used for flow amounts, capacity bounds60 /// and supply values in the algorithm. By default it is \c int.61 /// \tparam C The valuetype used for costs and potentials in the62 /// 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. 63 65 /// 64 /// \warning Both valuetypes must be signed and all input data must66 /// \warning Both number types must be signed and all input data must 65 67 /// be integer. 66 68 /// 67 69 /// \note %NetworkSimplex provides five different pivot rule 68 70 /// 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. 70 72 template <typename GR, typename V = int, typename C = V> 71 73 class NetworkSimplex … … 96 98 UNBOUNDED 97 99 }; 98 100 99 101 /// \brief Constants for selecting the type of the supply constraints. 100 102 /// … … 114 116 LEQ 115 117 }; 116 118 117 119 /// \brief Constants for selecting the pivot rule. 118 120 /// … … 123 125 /// implementations that significantly affect the running time 124 126 /// of the algorithm. 125 /// By default \ref BLOCK_SEARCH "Block Search" is used, which127 /// By default, \ref BLOCK_SEARCH "Block Search" is used, which 126 128 /// 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() 129 131 /// function with the proper parameter. 130 132 enum PivotRule { 131 133 132 /// The FirstEligible pivot rule.134 /// The \e First \e Eligible pivot rule. 133 135 /// The next eligible arc is selected in a wraparound fashion 134 136 /// in every iteration. 135 137 FIRST_ELIGIBLE, 136 138 137 /// The BestEligible pivot rule.139 /// The \e Best \e Eligible pivot rule. 138 140 /// The best eligible arc is selected in every iteration. 139 141 BEST_ELIGIBLE, 140 142 141 /// The BlockSearch pivot rule.143 /// The \e Block \e Search pivot rule. 142 144 /// A specified number of arcs are examined in every iteration 143 145 /// in a wraparound fashion and the best eligible arc is selected … … 145 147 BLOCK_SEARCH, 146 148 147 /// The Candidate List pivot rule.149 /// The \e Candidate \e List pivot rule. 148 150 /// In a major iteration a candidate list is built from eligible arcs 149 151 /// in a wraparound fashion and in the following minor iterations … … 151 153 CANDIDATE_LIST, 152 154 153 /// The Altering Candidate List pivot rule.155 /// The \e Altering \e Candidate \e List pivot rule. 154 156 /// It is a modified version of the Candidate List method. 155 157 /// It keeps only the several best eligible arcs from the former … … 157 159 ALTERING_LIST 158 160 }; 159 161 160 162 private: 161 163 162 164 TEMPLATE_DIGRAPH_TYPEDEFS(GR); 163 165 164 typedef std::vector<Arc> ArcVector;165 typedef std::vector<Node> NodeVector;166 166 typedef std::vector<int> IntVector; 167 typedef std::vector<bool> BoolVector;168 167 typedef std::vector<Value> ValueVector; 169 168 typedef std::vector<Cost> CostVector; 169 typedef std::vector<char> BoolVector; 170 // Note: vector<char> is used instead of vector<bool> for efficiency reasons 170 171 171 172 // State constants for arcs 172 enum ArcState Enum{173 enum ArcState { 173 174 STATE_UPPER = -1, 174 175 STATE_TREE = 0, 175 176 STATE_LOWER = 1 176 177 }; 178 179 typedef std::vector<signed char> StateVector; 180 // Note: vector<signed char> is used instead of vector<ArcState> for 181 // efficiency reasons 177 182 178 183 private: … … 195 200 IntVector _source; 196 201 IntVector _target; 202 bool _arc_mixing; 197 203 198 204 // Node and arc data … … 214 220 IntVector _dirty_revs; 215 221 BoolVector _forward; 216 IntVector _state;222 StateVector _state; 217 223 int _root; 218 224 … … 223 229 Value delta; 224 230 231 const Value MAX; 232 225 233 public: 226 234 227 235 /// \brief Constant for infinite upper bounds (capacities). 228 236 /// … … 243 251 const IntVector &_target; 244 252 const CostVector &_cost; 245 const IntVector&_state;253 const StateVector &_state; 246 254 const CostVector &_pi; 247 255 int &_in_arc; … … 264 272 bool findEnteringArc() { 265 273 Cost c; 266 for (int e = _next_arc; e <_search_arc_num; ++e) {274 for (int e = _next_arc; e != _search_arc_num; ++e) { 267 275 c = _state[e] * (_cost[e] + _pi[_source[e]] - _pi[_target[e]]); 268 276 if (c < 0) { … … 272 280 } 273 281 } 274 for (int e = 0; e <_next_arc; ++e) {282 for (int e = 0; e != _next_arc; ++e) { 275 283 c = _state[e] * (_cost[e] + _pi[_source[e]] - _pi[_target[e]]); 276 284 if (c < 0) { … … 295 303 const IntVector &_target; 296 304 const CostVector &_cost; 297 const IntVector&_state;305 const StateVector &_state; 298 306 const CostVector &_pi; 299 307 int &_in_arc; … … 312 320 bool findEnteringArc() { 313 321 Cost c, min = 0; 314 for (int e = 0; e <_search_arc_num; ++e) {322 for (int e = 0; e != _search_arc_num; ++e) { 315 323 c = _state[e] * (_cost[e] + _pi[_source[e]] - _pi[_target[e]]); 316 324 if (c < min) { … … 334 342 const IntVector &_target; 335 343 const CostVector &_cost; 336 const IntVector&_state;344 const StateVector &_state; 337 345 const CostVector &_pi; 338 346 int &_in_arc; … … 353 361 { 354 362 // The main parameters of the pivot rule 355 const double BLOCK_SIZE_FACTOR = 0.5;363 const double BLOCK_SIZE_FACTOR = 1.0; 356 364 const int MIN_BLOCK_SIZE = 10; 357 365 … … 365 373 Cost c, min = 0; 366 374 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) { 369 377 c = _state[e] * (_cost[e] + _pi[_source[e]] - _pi[_target[e]]); 370 378 if (c < min) { 371 379 min = c; 372 min_arc = e;380 _in_arc = e; 373 381 } 374 382 if (--cnt == 0) { 375 if (min < 0) break;383 if (min < 0) goto search_end; 376 384 cnt = _block_size; 377 385 } 378 386 } 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; 390 396 } 391 397 } 392 398 if (min >= 0) return false; 393 _in_arc = min_arc; 399 400 search_end: 394 401 _next_arc = e; 395 402 return true; … … 408 415 const IntVector &_target; 409 416 const CostVector &_cost; 410 const IntVector&_state;417 const StateVector &_state; 411 418 const CostVector &_pi; 412 419 int &_in_arc; … … 429 436 { 430 437 // The main parameters of the pivot rule 431 const double LIST_LENGTH_FACTOR = 1.0;438 const double LIST_LENGTH_FACTOR = 0.25; 432 439 const int MIN_LIST_LENGTH = 10; 433 440 const double MINOR_LIMIT_FACTOR = 0.1; … … 446 453 bool findEnteringArc() { 447 454 Cost min, c; 448 int e , min_arc = _next_arc;455 int e; 449 456 if (_curr_length > 0 && _minor_count < _minor_limit) { 450 457 // Minor iteration: select the best eligible arc from the … … 457 464 if (c < min) { 458 465 min = c; 459 min_arc = e;466 _in_arc = e; 460 467 } 461 if (c >= 0) {468 else if (c >= 0) { 462 469 _candidates[i--] = _candidates[--_curr_length]; 463 470 } 464 471 } 465 if (min < 0) { 466 _in_arc = min_arc; 467 return true; 468 } 472 if (min < 0) return true; 469 473 } 470 474 … … 472 476 min = 0; 473 477 _curr_length = 0; 474 for (e = _next_arc; e <_search_arc_num; ++e) {478 for (e = _next_arc; e != _search_arc_num; ++e) { 475 479 c = _state[e] * (_cost[e] + _pi[_source[e]] - _pi[_target[e]]); 476 480 if (c < 0) { … … 478 482 if (c < min) { 479 483 min = c; 480 min_arc = e;484 _in_arc = e; 481 485 } 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; 495 496 } 497 if (_curr_length == _list_length) goto search_end; 496 498 } 497 499 } 498 500 if (_curr_length == 0) return false; 501 502 search_end: 499 503 _minor_count = 1; 500 _in_arc = min_arc;501 504 _next_arc = e; 502 505 return true; … … 515 518 const IntVector &_target; 516 519 const CostVector &_cost; 517 const IntVector&_state;520 const StateVector &_state; 518 521 const CostVector &_pi; 519 522 int &_in_arc; … … 550 553 { 551 554 // The main parameters of the pivot rule 552 const double BLOCK_SIZE_FACTOR = 1. 5;555 const double BLOCK_SIZE_FACTOR = 1.0; 553 556 const int MIN_BLOCK_SIZE = 10; 554 557 const double HEAD_LENGTH_FACTOR = 0.1; … … 568 571 // Check the current candidate list 569 572 int e; 570 for (int i = 0; i <_curr_length; ++i) {573 for (int i = 0; i != _curr_length; ++i) { 571 574 e = _candidates[i]; 572 575 _cand_cost[e] = _state[e] * … … 579 582 // Extend the list 580 583 int cnt = _block_size; 581 int last_arc = 0;582 584 int limit = _head_length; 583 585 584 for ( int e = _next_arc; e <_search_arc_num; ++e) {586 for (e = _next_arc; e != _search_arc_num; ++e) { 585 587 _cand_cost[e] = _state[e] * 586 588 (_cost[e] + _pi[_source[e]] - _pi[_target[e]]); 587 589 if (_cand_cost[e] < 0) { 588 590 _candidates[_curr_length++] = e; 589 last_arc = e;590 591 } 591 592 if (--cnt == 0) { 592 if (_curr_length > limit) break;593 if (_curr_length > limit) goto search_end; 593 594 limit = 0; 594 595 cnt = _block_size; 595 596 } 596 597 } 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; 610 608 } 611 609 } 612 610 if (_curr_length == 0) return false; 613 _next_arc = last_arc + 1; 611 612 search_end: 614 613 615 614 // Make heap of the candidate list (approximating a partial sort) … … 619 618 // Pop the first element of the heap 620 619 _in_arc = _candidates[0]; 620 _next_arc = e; 621 621 pop_heap( _candidates.begin(), _candidates.begin() + _curr_length, 622 622 _sort_func ); … … 634 634 /// 635 635 /// \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) : 637 641 _graph(graph), _node_id(graph), _arc_id(graph), 642 _arc_mixing(arc_mixing), 643 MAX(std::numeric_limits<Value>::max()), 638 644 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) 641 646 { 642 // Check the valuetypes647 // Check the number types 643 648 LEMON_ASSERT(std::numeric_limits<Value>::is_signed, 644 649 "The flow type of NetworkSimplex must be signed"); 645 650 LEMON_ASSERT(std::numeric_limits<Cost>::is_signed, 646 651 "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() { 648 897 // Resize vectors 649 898 _node_num = countNodes(_graph); … … 672 921 _state.resize(max_arc_num); 673 922 674 // Copy the graph (store the arcs in a mixed order)923 // Copy the graph 675 924 int i = 0; 676 925 for (NodeIt n(_graph); n != INVALID; ++n, ++i) { 677 926 _node_id[n] = i; 678 927 } 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(); 915 950 return *this; 916 951 } … … 1025 1060 Value c = _lower[i]; 1026 1061 if (c >= 0) { 1027 _cap[i] = _upper[i] < INF? _upper[i] - c : INF;1062 _cap[i] = _upper[i] < MAX ? _upper[i] - c : INF; 1028 1063 } else { 1029 _cap[i] = _upper[i] < INF+ c ? _upper[i] - c : INF;1064 _cap[i] = _upper[i] < MAX + c ? _upper[i] - c : INF; 1030 1065 } 1031 1066 _supply[_source[i]] -= c; … … 1055 1090 _state[i] = STATE_LOWER; 1056 1091 } 1057 1092 1058 1093 // Set data for the artificial root node 1059 1094 _root = _node_num; … … 1219 1254 e = _pred[u]; 1220 1255 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]); 1222 1257 if (d < delta) { 1223 1258 delta = d; … … 1229 1264 for (int u = second; u != join; u = _parent[u]) { 1230 1265 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]; 1233 1268 if (d <= delta) { 1234 1269 delta = d; … … 1331 1366 1332 1367 // 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) { 1334 1369 u = _dirty_revs[i]; 1335 1370 _rev_thread[_thread[u]] = u; … … 1401 1436 _pi[u] += sigma; 1402 1437 } 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; 1403 1532 } 1404 1533 … … 1425 1554 PivotRuleImpl pivot(*this); 1426 1555 1556 // Perform heuristic initial pivots 1557 if (!initialPivots()) return UNBOUNDED; 1558 1427 1559 // Execute the Network Simplex algorithm 1428 1560 while (pivot.findEnteringArc()) { 1429 1561 findJoinNode(); 1430 1562 bool change = findLeavingArc(); 1431 if (delta >= INF) return UNBOUNDED;1563 if (delta >= MAX) return UNBOUNDED; 1432 1564 changeFlow(change); 1433 1565 if (change) { … … 1436 1568 } 1437 1569 } 1438 1570 1439 1571 // Check feasibility 1440 1572 for (int e = _search_arc_num; e != _all_arc_num; ++e) { … … 1453 1585 } 1454 1586 } 1455 1587 1456 1588 // Shift potentials to meet the requirements of the GEQ/LEQ type 1457 1589 // optimality conditions -
TabularUnified lemon/path.h ¶
r867 r956 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 967 967 }; 968 968 969 969 970 970 template <typename From, typename To, 971 971 bool revEnable = RevPathTagIndicator<From>::value> … … 973 973 static void copy(const From& from, To& to) { 974 974 PathCopySelectorForward<From, To>::copy(from, to); 975 } 975 } 976 976 }; 977 977 … … 980 980 static void copy(const From& from, To& to) { 981 981 PathCopySelectorBackward<From, To>::copy(from, to); 982 } 982 } 983 983 }; 984 984 -
TabularUnified lemon/preflow.h ¶
r1027 r1110 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2011 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 53 53 /// The type of the map that stores the flow values. 54 54 /// It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept. 55 #ifdef DOXYGEN 56 typedef GR::ArcMap<Value> FlowMap; 57 #else 55 58 typedef typename Digraph::template ArcMap<Value> FlowMap; 59 #endif 56 60 57 61 /// \brief Instantiates a FlowMap. … … 68 72 /// The elevator type used by Preflow algorithm. 69 73 /// 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 73 80 74 81 /// \brief Instantiates an Elevator. … … 96 103 /// This class provides an implementation of Goldberg-Tarjan's \e preflow 97 104 /// \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. 99 107 /// The preflow algorithms are the fastest known maximum 100 /// flow algorithms. The current implementation use a mixture of the108 /// flow algorithms. The current implementation uses a mixture of the 101 109 /// \e "highest label" and the \e "bound decrease" heuristics. 102 110 /// The worst case time complexity of the algorithm is \f$O(n^2\sqrt{e})\f$. … … 106 114 /// second phase constructs a feasible maximum flow on each arc. 107 115 /// 116 /// \warning This implementation cannot handle infinite or very large 117 /// capacities (e.g. the maximum value of \c CAP::Value). 118 /// 108 119 /// \tparam GR The type of the digraph the algorithm runs on. 109 120 /// \tparam CAP The type of the capacity map. The default map 110 121 /// 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. 111 127 #ifdef DOXYGEN 112 128 template <typename GR, typename CAP, typename TR> … … 258 274 /// able to automatically created by the algorithm (i.e. the 259 275 /// digraph and the maximum level should be passed to it). 260 /// However an external elevator object could also be passed to the276 /// However, an external elevator object could also be passed to the 261 277 /// algorithm with the \ref elevator(Elevator&) "elevator()" function 262 278 /// before calling \ref run() or \ref init(). … … 372 388 } 373 389 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> 377 394 Preflow& tolerance(const Tolerance& tolerance) { 378 395 _tolerance = tolerance; … … 382 399 /// \brief Returns a const reference to the tolerance. 383 400 /// 384 /// Returns a const reference to the tolerance. 401 /// Returns a const reference to the tolerance object used by 402 /// the algorithm. 385 403 const Tolerance& tolerance() const { 386 404 return _tolerance; … … 390 408 /// The simplest way to execute the preflow algorithm is to use 391 409 /// \ref run() or \ref runMinCut().\n 392 /// If you need morecontrol on the initial solution or the execution,393 /// first you have to call one of the \ref init() functions, then410 /// 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 394 412 /// \ref startFirstPhase() and if you need it \ref startSecondPhase(). 395 413 … … 537 555 } 538 556 } 539 for (NodeIt n(_graph); n != INVALID; ++n) 557 for (NodeIt n(_graph); n != INVALID; ++n) 540 558 if(n!=_source && n!=_target && _tolerance.positive((*_excess)[n])) 541 559 _level->activate(n); 542 560 543 561 return true; 544 562 } … … 568 586 level = _level->highestActiveLevel(); 569 587 --num; 570 588 571 589 Value excess = (*_excess)[n]; 572 590 int new_level = _level->maxLevel(); -
TabularUnified lemon/radix_heap.h ¶
r730 r758 20 20 #define LEMON_RADIX_HEAP_H 21 21 22 ///\ingroup auxdat22 ///\ingroup heaps 23 23 ///\file 24 ///\brief Radix Heap implementation.24 ///\brief Radix heap implementation. 25 25 26 26 #include <vector> … … 30 30 31 31 32 /// \ingroup auxdata32 /// \ingroup heaps 33 33 /// 34 /// \brief A Radix Heap implementation.34 /// \brief Radix heap data structure. 35 35 /// 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. 43 41 /// 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. 49 44 template <typename IM> 50 45 class RadixHeap { 51 46 52 47 public: 53 typedef typename IM::Key Item; 48 49 /// Type of the item-int map. 50 typedef IM ItemIntMap; 51 /// Type of the priorities. 54 52 typedef int Prio; 55 typedef IM ItemIntMap; 53 /// Type of the items stored in the heap. 54 typedef typename ItemIntMap::Key Item; 56 55 57 56 /// \brief Exception thrown by RadixHeap. 58 57 /// 59 /// This Exception is thrown when a smaller priority60 /// 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. 61 60 /// \see RadixHeap 62 63 class UnderFlowPriorityError : public Exception { 61 class PriorityUnderflowError : public Exception { 64 62 public: 65 63 virtual const char* what() const throw() { 66 return "lemon::RadixHeap:: UnderFlowPriorityError";64 return "lemon::RadixHeap::PriorityUnderflowError"; 67 65 } 68 66 }; 69 67 70 /// \brief Type to represent the items states.71 /// 72 /// Each Item element have a state associated to it. It maybe "in heap",73 /// "pre heap" or "postheap". The latter two are indifferent from the68 /// \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 74 72 /// heap's point of view, but may be useful to the user. 75 73 /// 76 /// The ItemIntMap \e should be initialized in such way that it maps77 /// 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. 78 76 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. 82 80 }; 83 81 … … 97 95 }; 98 96 99 std::vector<RadixItem> data;100 std::vector<RadixBox> boxes;97 std::vector<RadixItem> _data; 98 std::vector<RadixBox> _boxes; 101 99 102 100 ItemIntMap &_iim; 103 101 104 105 102 public: 106 /// \brief The constructor. 107 /// 108 /// The constructor.109 /// 110 /// \param map It should be given to the constructor, since it is used111 /// internally to handle the cross references. The value of the map112 /// should be PRE_HEAP (-1) for each element.113 /// 114 /// \param minimal The initial minimal valueof 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)) { 121 118 extend(); 122 119 } 123 120 } 124 121 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)) { 145 146 extend(); 146 147 } … … 150 151 151 152 bool upper(int box, Prio pr) { 152 return pr < boxes[box].min;153 return pr < _boxes[box].min; 153 154 } 154 155 155 156 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 160 161 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; 163 164 } 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 172 173 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; 176 177 } 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 186 187 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 // / \briefMove 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; 195 196 remove(index); 196 int box = findUp( data[index].box,data[index].prio);197 int box = findUp(_data[index].box, _data[index].prio); 197 198 insert(box, index); 198 199 } 199 200 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 201 202 int findUp(int start, int pr) { 202 203 while (lower(start, pr)) { 203 if (++start == int( boxes.size())) {204 if (++start == int(_boxes.size())) { 204 205 extend(); 205 206 } … … 208 209 } 209 210 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; 213 214 remove(index); 214 int box = findDown( data[index].box,data[index].prio);215 int box = findDown(_data[index].box, _data[index].prio); 215 216 insert(box, index); 216 217 } 217 218 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 219 220 int findDown(int start, int pr) { 220 221 while (upper(start, pr)) { 221 if (--start < 0) throw UnderFlowPriorityError();222 if (--start < 0) throw PriorityUnderflowError(); 222 223 } 223 224 return start; 224 225 } 225 226 226 // / \brief Find the first not empty box.227 // Find the first non-empty box 227 228 int findFirst() { 228 229 int first = 0; 229 while ( boxes[first].first == -1) ++first;230 while (_boxes[first].first == -1) ++first; 230 231 return first; 231 232 } 232 233 233 // / \brief Gives back the minimal prio of the box.234 // Gives back the minimum priority of the given box 234 235 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; 238 239 } 239 240 return min; 240 241 } 241 242 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 244 244 void moveDown() { 245 245 int box = findFirst(); … … 247 247 int min = minValue(box); 248 248 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; 253 253 while (curr != -1) { 254 next = data[curr].next;255 bubble _down(curr);254 next = _data[curr].next; 255 bubbleDown(curr); 256 256 curr = next; 257 257 } 258 258 } 259 259 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; 265 265 } else { 266 boxes[data[index].box].first = index;266 _boxes[_data[index].box].first = index; 267 267 } 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; 270 270 } 271 _iim[ data[index].item] = index;272 } 273 data.pop_back();271 _iim[_data[index].item] = index; 272 } 273 _data.pop_back(); 274 274 } 275 275 … … 278 278 /// \brief Insert an item into the heap with the given priority. 279 279 /// 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. 281 282 /// \param i The item to insert. 282 283 /// \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. 283 286 void push(const Item &i, const Prio &p) { 284 int n = data.size();287 int n = _data.size(); 285 288 _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)) { 288 291 extend(); 289 292 } 290 int box = findDown( boxes.size() - 1, p);293 int box = findDown(_boxes.size() - 1, p); 291 294 insert(box, n); 292 295 } 293 296 294 /// \brief Return s the item withminimum priority.295 /// 296 /// This method returns the item withminimum priority.297 /// \pre The heap must be non empty.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. 298 301 Item top() const { 299 302 const_cast<RadixHeap<ItemIntMap>&>(*this).moveDown(); 300 return data[boxes[0].first].item;301 } 302 303 /// \brief Returns the minimum priority.304 /// 305 /// Itreturns the minimum priority.306 /// \pre The heap must be non empty.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. 307 310 Prio prio() const { 308 311 const_cast<RadixHeap<ItemIntMap>&>(*this).moveDown(); 309 return data[boxes[0].first].prio;312 return _data[_boxes[0].first].prio; 310 313 } 311 314 312 /// \brief Deletes the item withminimum priority.313 /// 314 /// This method deletes the item withminimum priority.315 /// \brief Remove the item having minimum priority. 316 /// 317 /// This function removes the item having minimum priority. 315 318 /// \pre The heap must be non-empty. 316 319 void pop() { 317 320 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; 320 323 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. 329 333 void erase(const Item &i) { 330 334 int index = _iim[i]; 331 335 _iim[i] = POST_HEAP; 332 336 remove(index); 333 relocate _last(index);337 relocateLast(index); 334 338 } 335 339 336 /// \brief Returns the priority of \c i.337 /// 338 /// This function returns the priority of item \c i.339 /// \p re \c i must be in the heap.340 /// \p aram 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. 341 345 Prio operator[](const Item &i) const { 342 346 int idx = _iim[i]; 343 return data[idx].prio;344 } 345 346 /// \brief \c i gets to the heap with priority \c p independently347 /// if \c i was already there.348 /// 349 /// This method calls \ref push(\c i, \c p) if \c i is not stored350 /// 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. 352 356 /// \param i The item. 353 357 /// \param p The priority. 358 /// \pre \e i must be in the heap. 359 /// \warning This method may throw an \c UnderFlowPriorityException. 354 360 void set(const Item &i, const Prio &p) { 355 361 int idx = _iim[i]; … … 357 363 push(i, p); 358 364 } 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); 362 368 } 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. 374 377 /// \param i The item. 375 378 /// \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. 376 381 void decrease(const Item &i, const Prio &p) { 377 382 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. 386 390 /// \param i The item. 387 391 /// \param p The priority. 392 /// \pre \e i must be stored in the heap with priority at most \e p. 388 393 void increase(const Item &i, const Prio &p) { 389 394 int idx = _iim[i]; 390 data[idx].prio = p;391 bubble _up(idx);392 } 393 394 /// \brief Return s if \c item is in, has already been in, or has395 /// never been in the heap.396 /// 397 /// This method returns PRE_HEAP if \c item has never been in the398 /// heap, IN_HEAP if it is in the heap at the moment, and POST_HEAP399 /// otherwise. In the latter case it is possible that \c item will400 /// get backto 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. 401 406 /// \param i The item. 402 407 State state(const Item &i) const { … … 406 411 } 407 412 408 /// \brief Set s the state of the \citem in the heap.409 /// 410 /// Sets the state of the \c item in the heap. It can be used to411 /// manually clear the heap when it is important to achive the412 /// 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. 413 418 /// \param i The item. 414 419 /// \param st The state. It should not be \c IN_HEAP. -
TabularUnified lemon/smart_graph.h ¶
r664 r956 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 33 33 34 34 class SmartDigraph; 35 ///Base of SmartDigraph 36 37 ///Base of SmartDigraph 38 /// 35 39 36 class SmartDigraphBase { 40 37 protected: … … 188 185 ///\brief A smart directed graph class. 189 186 /// 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 197 201 class SmartDigraph : public ExtendedSmartDigraphBase { 198 202 typedef ExtendedSmartDigraphBase Parent; 199 203 200 204 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. 206 206 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. 212 209 void operator=(const SmartDigraph &) {} 213 210 … … 222 219 ///Add a new node to the digraph. 223 220 224 /// Adda new node to the digraph.225 /// 221 ///This function adds a new node to the digraph. 222 ///\return The new node. 226 223 Node addNode() { return Parent::addNode(); } 227 224 228 225 ///Add a new arc to the digraph. 229 226 230 /// Adda new arc to the digraph with source node \c s227 ///This function adds a new arc to the digraph with source node \c s 231 228 ///and target node \c t. 232 229 ///\return The new arc. 233 Arc addArc( const Node& s, const Node&t) {230 Arc addArc(Node s, Node t) { 234 231 return Parent::addArc(s, t); 235 232 } 236 233 237 /// \brief Using this it is possible to avoid the superfluous memory238 /// allocation.239 240 /// Using this it is possible to avoid the superfluous memory241 /// allocation: if you know that the digraph you want to build will242 /// 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 starting244 /// to build the digraph.245 /// \sa reserveArc246 void reserveNode(int n) { nodes.reserve(n); };247 248 /// \brief Using this it is possible to avoid the superfluous memory249 /// allocation.250 251 /// Using this it is possible to avoid the superfluous memory252 /// allocation: if you know that the digraph you want to build will253 /// 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 starting255 /// to build the digraph.256 /// \sa reserveNode257 void reserveArc(int m) { arcs.reserve(m); };258 259 234 /// \brief Node validity check 260 235 /// 261 /// This function gives back true if the given node is valid,262 /// i e. it is a real node of thegraph.236 /// This function gives back \c true if the given node is valid, 237 /// i.e. it is a real node of the digraph. 263 238 /// 264 239 /// \warning A removed node (using Snapshot) could become valid again 265 /// when new nodes are added to thegraph.240 /// if new nodes are added to the digraph. 266 241 bool valid(Node n) const { return Parent::valid(n); } 267 242 268 243 /// \brief Arc validity check 269 244 /// 270 /// This function gives back true if the given arc is valid,271 /// i e. it is a real arc of thegraph.245 /// This function gives back \c true if the given arc is valid, 246 /// i.e. it is a real arc of the digraph. 272 247 /// 273 248 /// \warning A removed arc (using Snapshot) could become valid again 274 /// whennew arcs are added to the graph.249 /// if new arcs are added to the graph. 275 250 bool valid(Arc a) const { return Parent::valid(a); } 276 251 277 ///Clear the digraph.278 279 ///Erase all the nodes and arcs from the digraph.280 ///281 void clear() {282 Parent::clear();283 }284 285 252 ///Split a node. 286 253 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. 291 260 ///\return The newly created node. 292 261 /// 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 /// 297 264 ///\warning This functionality cannot be used together with the Snapshot 298 265 ///feature. … … 309 276 } 310 277 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 311 306 public: 312 307 … … 333 328 public: 334 329 335 ///Class to make a snapshot of the digraph and to rest rore toit later.336 337 ///Class to make a snapshot of the digraph and to rest rore toit 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. 338 333 /// 339 334 ///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. 349 347 class Snapshot 350 348 { … … 358 356 359 357 ///Default constructor. 360 ///To actually make a snapshot you must call save(). 361 /// 358 ///You have to call save() to actually make a snapshot. 362 359 Snapshot() : _graph(0) {} 363 360 ///Constructor that immediately makes a snapshot 364 361 365 ///This constructor immediately makes a snapshot of the digraph.366 /// \param graph The digraph we make a snapshot of.367 Snapshot(SmartDigraph &gr aph) : _graph(&graph) {362 ///This constructor immediately makes a snapshot of the given digraph. 363 /// 364 Snapshot(SmartDigraph &gr) : _graph(&gr) { 368 365 node_num=_graph->nodes.size(); 369 366 arc_num=_graph->arcs.size(); … … 372 369 ///Make a snapshot. 373 370 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 377 373 ///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; 382 376 node_num=_graph->nodes.size(); 383 377 arc_num=_graph->arcs.size(); … … 386 380 ///Undo the changes until a snapshot. 387 381 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&). 393 384 void restore() 394 385 { … … 509 500 } 510 501 511 void next(Node& node) const{502 static void next(Node& node) { 512 503 --node._id; 513 504 } … … 517 508 } 518 509 519 void next(Arc& arc) const{510 static void next(Arc& arc) { 520 511 --arc._id; 521 512 } … … 525 516 } 526 517 527 void next(Edge& arc) const{518 static void next(Edge& arc) { 528 519 --arc._id; 529 520 } … … 622 613 /// \brief A smart undirected graph class. 623 614 /// 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 631 629 class SmartGraph : public ExtendedSmartGraphBase { 632 630 typedef ExtendedSmartGraphBase Parent; 633 631 634 632 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. 640 634 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. 647 637 void operator=(const SmartGraph &) {} 648 638 … … 655 645 SmartGraph() {} 656 646 657 /// Add a new node to the graph.658 659 /// Adda 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. 660 650 /// \return The new node. 661 651 Node addNode() { return Parent::addNode(); } 662 652 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); 670 661 } 671 662 672 663 /// \brief Node validity check 673 664 /// 674 /// This function gives back true if the given node is valid,675 /// i e. 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. 676 667 /// 677 668 /// \warning A removed node (using Snapshot) could become valid again 678 /// whennew nodes are added to the graph.669 /// if new nodes are added to the graph. 679 670 bool valid(Node n) const { return Parent::valid(n); } 680 671 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 681 681 /// \brief Arc validity check 682 682 /// 683 /// This function gives back true if the given arc is valid,684 /// i e. 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. 685 685 /// 686 686 /// \warning A removed arc (using Snapshot) could become valid again 687 /// whennew edges are added to the graph.687 /// if new edges are added to the graph. 688 688 bool valid(Arc a) const { return Parent::valid(a); } 689 689 690 /// \brief Edge validity check691 ///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 again696 /// when new edges are added to the graph.697 bool valid(Edge e) const { return Parent::valid(e); }698 699 690 ///Clear the graph. 700 691 701 /// Erase all the nodes and edges from the graph.692 ///This function erases all nodes and arcs from the graph. 702 693 /// 703 694 void clear() { 704 695 Parent::clear(); 705 696 } 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); }; 706 717 707 718 public: … … 743 754 public: 744 755 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. 760 772 class Snapshot 761 773 { … … 769 781 770 782 ///Default constructor. 771 ///To actually make a snapshot you must call save(). 772 /// 783 ///You have to call save() to actually make a snapshot. 773 784 Snapshot() : _graph(0) {} 774 785 ///Constructor that immediately makes a snapshot 775 786 776 /// This constructor immediately makes a snapshot of the digraph.777 /// \param graph The digraph we make a snapshot of.778 Snapshot(SmartGraph &gr aph) {779 gr aph.saveSnapshot(*this);787 /// This constructor immediately makes a snapshot of the given graph. 788 /// 789 Snapshot(SmartGraph &gr) { 790 gr.saveSnapshot(*this); 780 791 } 781 792 782 793 ///Make a snapshot. 783 794 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 787 797 ///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) 790 799 { 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&). 801 807 void restore() 802 808 { -
TabularUnified lemon/soplex.cc ¶
r623 r956 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 085 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 92 92 } 93 93 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 94 107 95 108 void SoplexLp::_eraseCol(int i) { … … 275 288 276 289 _clear_temporals(); 277 290 278 291 _applyMessageLevel(); 279 292 -
TabularUnified lemon/soplex.h ¶
r623 r956 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 085 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 85 85 virtual int _addCol(); 86 86 virtual int _addRow(); 87 virtual int _addRow(Value l, ExprIterator b, ExprIterator e, Value u); 87 88 88 89 virtual void _eraseCol(int i); -
TabularUnified lemon/suurballe.h ¶
r925 r956 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 30 30 #include <lemon/path.h> 31 31 #include <lemon/list_graph.h> 32 #include <lemon/dijkstra.h> 32 33 #include <lemon/maps.h> 33 34 34 35 namespace 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 }; 35 79 36 80 /// \addtogroup shortest_path … … 47 91 /// "minimum cost flow problem". This implementation is actually an 48 92 /// 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. 50 94 /// Therefore this class provides query functions for flow values and 51 95 /// node potentials (the dual solution) just like the minimum cost flow … … 58 102 /// \warning Length values should be \e non-negative. 59 103 /// 60 /// \note For finding node-disjoint pathsthis algorithm can be used104 /// \note For finding \e node-disjoint paths, this algorithm can be used 61 105 /// along with the \ref SplitNodes adaptor. 62 106 #ifdef DOXYGEN 63 template <typename GR, typename LEN >107 template <typename GR, typename LEN, typename TR> 64 108 #else 65 109 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> > 67 112 #endif 68 113 class Suurballe … … 75 120 public: 76 121 77 /// The type of the digraph the algorithm runs on.78 typedef GRDigraph;122 /// The type of the digraph. 123 typedef typename TR::Digraph Digraph; 79 124 /// The type of the length map. 80 typedef LENLengthMap;125 typedef typename TR::LengthMap LengthMap; 81 126 /// The type of the lengths. 82 typedef typename LengthMap::ValueLength;83 #ifdef DOXYGEN 127 typedef typename TR::Length Length; 128 84 129 /// The type of the flow map. 85 typedef GR::ArcMap<int>FlowMap;130 typedef typename TR::FlowMap FlowMap; 86 131 /// 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; 95 133 /// 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; 97 142 98 143 private: … … 105 150 class ResidualDijkstra 106 151 { 107 typedef typename Digraph::template NodeMap<int> HeapCrossRef;108 typedef BinHeap<Length, HeapCrossRef> Heap;109 110 152 private: 111 153 112 // The digraph the algorithm runs on113 154 const Digraph &_graph; 114 115 // The main maps 155 const LengthMap &_length; 116 156 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; 123 158 PredMap &_pred; 124 // The processed (i.e. permanently labeled) nodes125 std::vector<Node> _proc_nodes;126 127 159 Node _s; 128 160 Node _t; 129 161 162 PotentialMap _dist; 163 std::vector<Node> _proc_nodes; 164 130 165 public: 131 166 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() { 145 184 HeapCrossRef heap_cross_ref(_graph, Heap::PRE_HEAP); 146 185 Heap heap(heap_cross_ref); … … 152 191 while (!heap.empty() && heap.top() != _t) { 153 192 Node u = heap.top(), v; 154 Length d = heap.prio() + _potential[u], nd;193 Length d = heap.prio(), dn; 155 194 _dist[u] = heap.prio(); 195 _proc_nodes.push_back(u); 156 196 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(); 157 240 _proc_nodes.push_back(u); 241 heap.pop(); 158 242 159 243 // Traverse outgoing arcs … … 162 246 v = _graph.target(e); 163 247 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]); 172 250 _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; 177 261 } 178 262 } … … 184 268 v = _graph.source(e); 185 269 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]); 194 272 _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; 199 283 } 200 284 } … … 206 290 Length t_dist = heap.prio(); 207 291 for (int i = 0; i < int(_proc_nodes.size()); ++i) 208 _p otential[_proc_nodes[i]] += _dist[_proc_nodes[i]] - t_dist;292 _pi[_proc_nodes[i]] += _dist[_proc_nodes[i]] - t_dist; 209 293 return true; 210 294 } 211 295 212 296 }; //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 /// @} 213 374 214 375 private: … … 227 388 228 389 // The source node 229 Node _s ource;390 Node _s; 230 391 // The target node 231 Node _t arget;392 Node _t; 232 393 233 394 // Container to store the found paths 234 std::vector< SimplePath<Digraph> >paths;395 std::vector<Path> _paths; 235 396 int _path_num; 236 397 237 398 // The pred arc map 238 399 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() {} 242 409 243 410 public: … … 252 419 const LengthMap &length ) : 253 420 _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) 255 423 {} 256 424 … … 259 427 if (_local_flow) delete _flow; 260 428 if (_local_potential) delete _potential; 261 delete _dijkstra; 429 delete _init_dist; 430 delete _init_pred; 262 431 } 263 432 … … 304 473 /// \name Execution Control 305 474 /// 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 308 479 /// 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(). 310 482 311 483 /// @{ … … 327 499 /// \code 328 500 /// s.init(s); 329 /// s.findFlow(t, k); 330 /// s.findPaths(); 501 /// s.start(t, k); 331 502 /// \endcode 332 503 int run(const Node& s, const Node& t, int k = 2) { 333 504 init(s); 334 findFlow(t, k); 335 findPaths(); 505 start(t, k); 336 506 return _path_num; 337 507 } … … 339 509 /// \brief Initialize the algorithm. 340 510 /// 341 /// This function initializes the algorithm .511 /// This function initializes the algorithm with the given source node. 342 512 /// 343 513 /// \param s The source node. 344 514 void init(const Node& s) { 345 _s ource= s;515 _s = s; 346 516 347 517 // Initialize maps … … 354 524 _local_potential = true; 355 525 } 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; 358 583 } 359 584 … … 373 598 /// \pre \ref init() must be called before using this function. 374 599 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 } 379 624 380 625 // Find shortest paths 381 _path_num = 0;382 626 while (_path_num < k) { 383 627 // Run Dijkstra 384 if (! _dijkstra->run()) break;628 if (!dijkstra.run(_path_num)) break; 385 629 ++_path_num; 386 630 387 631 // Set the flow along the found shortest path 388 Node u = _t arget;632 Node u = _t; 389 633 Arc e; 390 634 while ((e = _pred[u]) != INVALID) { … … 403 647 /// \brief Compute the paths from the flow. 404 648 /// 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. 407 651 /// 408 652 /// \pre \ref init() and \ref findFlow() must be called before using … … 412 656 for(ArcIt a(_graph); a != INVALID; ++a) res_flow[a] = (*_flow)[a]; 413 657 414 paths.clear();415 paths.resize(_path_num);658 _paths.clear(); 659 _paths.resize(_path_num); 416 660 for (int i = 0; i < _path_num; ++i) { 417 Node n = _s ource;418 while (n != _t arget) {661 Node n = _s; 662 while (n != _t) { 419 663 OutArcIt e(_graph, n); 420 664 for ( ; res_flow[e] == 0; ++e) ; 421 665 n = _graph.target(e); 422 paths[i].addBack(e);666 _paths[i].addBack(e); 423 667 res_flow[e] = 0; 424 668 } … … 519 763 /// this function. 520 764 const Path& path(int i) const { 521 return paths[i];765 return _paths[i]; 522 766 } 523 767 -
TabularUnified lemon/time_measure.h ¶
r631 r833 376 376 ///This function returns the number of stop() exections that is 377 377 ///necessary to really stop the timer. 378 ///For example the timer378 ///For example, the timer 379 379 ///is running if and only if the return value is \c true 380 380 ///(i.e. greater than -
TabularUnified lemon/unionfind.h ¶
r945 r956 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 44 44 /// This is a very simple but efficient implementation, providing 45 45 /// 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. 47 47 /// 48 48 /// It is primarily used in Kruskal algorithm for finding minimal -
TabularUnified scripts/chg-len.py ¶
r439 r780 1 1 #! /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. 2 16 3 17 import sys -
TabularUnified scripts/mk-release.sh ¶
r611 r780 1 1 #!/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. 2 16 3 17 set -e -
TabularUnified scripts/unify-sources.sh ¶
r702 r780 1 1 #!/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. 2 16 3 17 YEAR=`date +%Y` -
TabularUnified test/CMakeLists.txt ¶
r1119 r1122 14 14 SET(TESTS 15 15 adaptors_test 16 bellman_ford_test 16 17 bfs_test 17 18 circulation_test … … 25 26 error_test 26 27 euler_test 28 fractional_matching_test 27 29 gomory_hu_test 28 30 graph_copy_test … … 37 39 min_cost_arborescence_test 38 40 min_cost_flow_test 41 min_mean_cycle_test 39 42 path_test 43 planarity_test 40 44 preflow_test 41 45 radix_sort_test -
TabularUnified test/Makefile.am ¶
r1102 r1110 1 if USE_VALGRIND 2 TESTS_ENVIRONMENT=$(top_srcdir)/scripts/valgrind-wrapper.sh 3 endif 4 1 5 EXTRA_DIST += \ 2 6 test/CMakeLists.txt … … 8 12 check_PROGRAMS += \ 9 13 test/adaptors_test \ 14 test/bellman_ford_test \ 10 15 test/bfs_test \ 11 16 test/circulation_test \ … … 19 24 test/error_test \ 20 25 test/euler_test \ 26 test/fractional_matching_test \ 21 27 test/gomory_hu_test \ 22 28 test/graph_copy_test \ … … 31 37 test/min_cost_arborescence_test \ 32 38 test/min_cost_flow_test \ 39 test/min_mean_cycle_test \ 33 40 test/path_test \ 41 test/planarity_test \ 34 42 test/preflow_test \ 35 43 test/radix_sort_test \ … … 54 62 55 63 test_adaptors_test_SOURCES = test/adaptors_test.cc 64 test_bellman_ford_test_SOURCES = test/bellman_ford_test.cc 56 65 test_bfs_test_SOURCES = test/bfs_test.cc 57 66 test_circulation_test_SOURCES = test/circulation_test.cc … … 65 74 test_error_test_SOURCES = test/error_test.cc 66 75 test_euler_test_SOURCES = test/euler_test.cc 76 test_fractional_matching_test_SOURCES = test/fractional_matching_test.cc 67 77 test_gomory_hu_test_SOURCES = test/gomory_hu_test.cc 68 78 test_graph_copy_test_SOURCES = test/graph_copy_test.cc 69 79 test_graph_test_SOURCES = test/graph_test.cc 70 80 test_graph_utils_test_SOURCES = test/graph_utils_test.cc 81 test_hao_orlin_test_SOURCES = test/hao_orlin_test.cc 71 82 test_heap_test_SOURCES = test/heap_test.cc 72 83 test_kruskal_test_SOURCES = test/kruskal_test.cc 73 test_hao_orlin_test_SOURCES = test/hao_orlin_test.cc74 84 test_lgf_test_SOURCES = test/lgf_test.cc 75 85 test_lp_test_SOURCES = test/lp_test.cc … … 79 89 test_min_cost_arborescence_test_SOURCES = test/min_cost_arborescence_test.cc 80 90 test_min_cost_flow_test_SOURCES = test/min_cost_flow_test.cc 91 test_min_mean_cycle_test_SOURCES = test/min_mean_cycle_test.cc 81 92 test_path_test_SOURCES = test/path_test.cc 93 test_planarity_test_SOURCES = test/planarity_test.cc 82 94 test_preflow_test_SOURCES = test/preflow_test.cc 83 95 test_radix_sort_test_SOURCES = test/radix_sort_test.cc -
TabularUnified test/adaptors_test.cc ¶
r488 r550 1372 1372 1373 1373 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; 1378 1378 1379 1379 // 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; 1384 1382 typedef Undirector<const SplitGridGraph> USplitGridGraph; 1385 typedef Undirector<const USplitGridGraph> UUSplitGridGraph;1386 checkConcept<concepts::Digraph, RevSplitGridGraph>();1387 1383 checkConcept<concepts::Digraph, SplitGridGraph>(); 1388 1384 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)); 1394 1387 USplitGridGraph uadaptor = undirector(adaptor); 1395 UUSplitGridGraph uuadaptor = undirector(uadaptor);1396 1388 1397 1389 // Check adaptor … … 1400 1392 checkGraphConArcList(adaptor, 8); 1401 1393 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); 1419 1411 1420 1412 checkNodeIds(adaptor); … … 1439 1431 checkGraphArcMap(uadaptor); 1440 1432 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); 1464 1441 } 1465 1442 -
TabularUnified test/bfs_test.cc ¶
r632 r956 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 84 84 b = const_bfs_test.emptyQueue(); 85 85 i = const_bfs_test.queueSize(); 86 86 87 87 bfs_test.start(); 88 88 bfs_test.start(t); … … 105 105 ::SetProcessedMap<concepts::WriteMap<Node,bool> > 106 106 ::Create bfs_test(G); 107 107 108 108 concepts::ReadWriteMap<Node,Arc> pred_map; 109 109 concepts::ReadWriteMap<Node,int> dist_map; 110 110 concepts::ReadWriteMap<Node,bool> reached_map; 111 111 concepts::WriteMap<Node,bool> processed_map; 112 112 113 113 bfs_test 114 114 .predMap(pred_map) … … 120 120 bfs_test.run(s,t); 121 121 bfs_test.run(); 122 122 123 123 bfs_test.init(); 124 124 bfs_test.addSource(s); … … 129 129 b = bfs_test.emptyQueue(); 130 130 i = bfs_test.queueSize(); 131 131 132 132 bfs_test.start(); 133 133 bfs_test.start(t); -
TabularUnified test/circulation_test.cc ¶
r658 r956 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 82 82 CirculationType circ_test(g, lcap, ucap, supply); 83 83 const CirculationType& const_circ_test = circ_test; 84 84 85 85 circ_test 86 86 .lowerMap(lcap) … … 88 88 .supplyMap(supply) 89 89 .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); 90 95 91 96 circ_test.init(); … … 98 103 b = const_circ_test.barrier(n); 99 104 const_circ_test.barrierMap(bar); 100 105 101 106 ignore_unused_variable_warning(fm); 102 107 } -
TabularUnified test/connectivity_test.cc ¶
r696 r956 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 30 30 typedef ListDigraph Digraph; 31 31 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 38 38 check(stronglyConnected(d), "The empty digraph is strongly connected"); 39 39 check(countStronglyConnectedComponents(d) == 0, … … 49 49 check(countBiEdgeConnectedComponents(g) == 0, 50 50 "The empty graph has 0 bi-edge-connected component"); 51 51 52 52 check(dag(d), "The empty digraph is DAG."); 53 53 check(checkedTopologicalSort(d, order), "The empty digraph is DAG."); … … 83 83 check(countBiEdgeConnectedComponents(g) == 1, 84 84 "This graph has 1 bi-edge-connected component"); 85 85 86 86 check(dag(d), "This digraph is DAG."); 87 87 check(checkedTopologicalSort(d, order), "This digraph is DAG."); … … 102 102 Digraph::NodeMap<int> order(d); 103 103 Graph g(d); 104 104 105 105 Digraph::Node n1 = d.addNode(); 106 106 Digraph::Node n2 = d.addNode(); … … 109 109 Digraph::Node n5 = d.addNode(); 110 110 Digraph::Node n6 = d.addNode(); 111 111 112 112 d.addArc(n1, n3); 113 113 d.addArc(n3, n2); … … 137 137 check(!parallelFree(g), "This graph is not parallel-free."); 138 138 check(!simpleGraph(g), "This graph is not simple."); 139 139 140 140 d.addArc(n3, n3); 141 141 142 142 check(!loopFree(d), "This digraph is not loop-free."); 143 143 check(!loopFree(g), "This graph is not loop-free."); 144 144 check(!simpleGraph(d), "This digraph is not simple."); 145 145 146 146 d.addArc(n3, n2); 147 147 148 148 check(!parallelFree(d), "This digraph is not parallel-free."); 149 149 } 150 150 151 151 { 152 152 Digraph d; 153 153 Digraph::ArcMap<bool> cutarcs(d, false); 154 154 Graph g(d); 155 155 156 156 Digraph::Node n1 = d.addNode(); 157 157 Digraph::Node n2 = d.addNode(); … … 173 173 d.addArc(n6, n7); 174 174 d.addArc(n7, n6); 175 175 176 176 check(!stronglyConnected(d), "This digraph is not strongly connected"); 177 177 check(countStronglyConnectedComponents(d) == 3, … … 236 236 Digraph d; 237 237 Digraph::NodeMap<int> order(d); 238 238 239 239 Digraph::Node belt = d.addNode(); 240 240 Digraph::Node trousers = d.addNode(); … … 256 256 d.addArc(shirt, necktie); 257 257 d.addArc(necktie, coat); 258 258 259 259 check(dag(d), "This digraph is DAG."); 260 260 topologicalSort(d, order); … … 268 268 ListGraph g; 269 269 ListGraph::NodeMap<bool> map(g); 270 270 271 271 ListGraph::Node n1 = g.addNode(); 272 272 ListGraph::Node n2 = g.addNode(); … … 284 284 g.addEdge(n4, n7); 285 285 g.addEdge(n5, n7); 286 286 287 287 check(bipartite(g), "This graph is bipartite"); 288 288 check(bipartitePartitions(g, map), "This graph is bipartite"); 289 289 290 290 check(map[n1] == map[n2] && map[n1] == map[n6] && map[n1] == map[n7], 291 291 "Wrong bipartitePartitions()"); -
TabularUnified test/dfs_test.cc ¶
r1009 r1110 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2011 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 87 87 b = const_dfs_test.emptyQueue(); 88 88 i = const_dfs_test.queueSize(); 89 89 90 90 dfs_test.start(); 91 91 dfs_test.start(t); … … 113 113 concepts::ReadWriteMap<Node,bool> reached_map; 114 114 concepts::WriteMap<Node,bool> processed_map; 115 115 116 116 dfs_test 117 117 .predMap(pred_map) … … 130 130 b = dfs_test.emptyQueue(); 131 131 i = dfs_test.queueSize(); 132 132 133 133 dfs_test.start(); 134 134 dfs_test.start(t); … … 220 220 check(dfs.run(s1,t1) && dfs.reached(t1),"Node 3 is reachable from Node 6."); 221 221 } 222 222 223 223 { 224 224 NullMap<Node,Arc> myPredMap; -
TabularUnified test/digraph_test.cc ¶
r463 r956 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 20 20 #include <lemon/list_graph.h> 21 21 #include <lemon/smart_graph.h> 22 #include <lemon/static_graph.h> 22 23 #include <lemon/full_graph.h> 23 24 … … 35 36 checkGraphNodeList(G, 0); 36 37 checkGraphArcList(G, 0); 38 39 G.reserveNode(3); 40 G.reserveArc(4); 37 41 38 42 Node … … 284 288 285 289 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(); 286 298 287 299 checkGraphNodeList(G, 4); … … 318 330 checkConcept<ClearableDigraphComponent<>, SmartDigraph>(); 319 331 } 332 { // Checking StaticDigraph 333 checkConcept<Digraph, StaticDigraph>(); 334 checkConcept<ClearableDigraphComponent<>, StaticDigraph>(); 335 } 320 336 { // Checking FullDigraph 321 337 checkConcept<Digraph, FullDigraph>(); … … 373 389 } 374 390 391 void 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 375 498 void checkFullDigraph(int num) { 376 499 typedef FullDigraph Digraph; 377 500 DIGRAPH_TYPEDEFS(Digraph); 501 378 502 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"); 379 507 380 508 checkGraphNodeList(G, num); … … 420 548 checkDigraphValidity<SmartDigraph>(); 421 549 } 550 { // Checking StaticDigraph 551 checkStaticDigraph(); 552 } 422 553 { // Checking FullDigraph 423 554 checkFullDigraph(8); -
TabularUnified test/dijkstra_test.cc ¶
r632 r956 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 86 86 b = const_dijkstra_test.emptyQueue(); 87 87 i = const_dijkstra_test.queueSize(); 88 88 89 89 dijkstra_test.start(); 90 90 dijkstra_test.start(t); … … 110 110 ::SetHeap<BinHeap<VType, concepts::ReadWriteMap<Node,int> > > 111 111 ::SetStandardHeap<BinHeap<VType, concepts::ReadWriteMap<Node,int> > > 112 ::SetHeap<BinHeap<VType, concepts::ReadWriteMap<Node,int> >, 112 ::SetHeap<BinHeap<VType, concepts::ReadWriteMap<Node,int> >, 113 113 concepts::ReadWriteMap<Node,int> > 114 114 ::Create dijkstra_test(G,length); … … 120 120 concepts::ReadWriteMap<Node,int> heap_cross_ref; 121 121 BinHeap<VType, concepts::ReadWriteMap<Node,int> > heap(heap_cross_ref); 122 122 123 123 dijkstra_test 124 124 .lengthMap(length_map) … … 137 137 b = dijkstra_test.emptyQueue(); 138 138 i = dijkstra_test.queueSize(); 139 139 140 140 dijkstra_test.start(); 141 141 dijkstra_test.start(t); -
TabularUnified test/edge_set_test.cc ¶
r559 r956 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 085 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). -
TabularUnified test/euler_test.cc ¶
r639 r956 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 86 86 typedef ListDigraph Digraph; 87 87 typedef Undirector<Digraph> Graph; 88 89 { 90 Digraph d; 91 Graph g(d); 92 88 89 { 90 Digraph d; 91 Graph g(d); 92 93 93 checkDiEulerIt(d); 94 94 checkDiEulerIt(g); … … 129 129 Digraph::Node n2 = d.addNode(); 130 130 Digraph::Node n3 = d.addNode(); 131 131 132 132 d.addArc(n1, n2); 133 133 d.addArc(n2, n1); … … 154 154 Digraph::Node n5 = d.addNode(); 155 155 Digraph::Node n6 = d.addNode(); 156 156 157 157 d.addArc(n1, n2); 158 158 d.addArc(n2, n4); … … 190 190 Digraph::Node n4 = d.addNode(); 191 191 Digraph::Node n5 = d.addNode(); 192 192 193 193 d.addArc(n1, n2); 194 194 d.addArc(n2, n3); … … 212 212 Digraph::Node n2 = d.addNode(); 213 213 Digraph::Node n3 = d.addNode(); 214 214 215 215 d.addArc(n1, n2); 216 216 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 1 19 #include <iostream> 2 20 … … 34 52 "source 0\n" 35 53 "target 3\n"; 36 54 37 55 void checkGomoryHuCompile() 38 56 { … … 70 88 71 89 int cutValue(const Graph& graph, const BoolNodeMap& cut, 72 90 const IntEdgeMap& capacity) { 73 91 74 92 int sum = 0; … … 108 126 int sum=0; 109 127 for(GomoryHu<Graph>::MinCutEdgeIt a(ght, u, v);a!=INVALID;++a) 110 sum+=capacity[a]; 128 sum+=capacity[a]; 111 129 check(sum == ght.minCutValue(u, v), "Problem with MinCutEdgeIt"); 112 130 … … 119 137 } 120 138 } 121 139 122 140 return 0; 123 141 } -
TabularUnified test/graph_copy_test.cc ¶
r984 r1081 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2011 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 71 71 nodeCrossRef(ncr).arcCrossRef(ecr). 72 72 node(fn, tn).arc(fa, ta).run(); 73 73 74 74 check(countNodes(from) == countNodes(to), "Wrong copy."); 75 75 check(countArcs(from) == countArcs(to), "Wrong copy."); … … 99 99 // Test repeated copy 100 100 digraphCopy(from, to).run(); 101 101 102 102 check(countNodes(from) == countNodes(to), "Wrong copy."); 103 103 check(countArcs(from) == countArcs(to), "Wrong copy."); … … 201 201 // Test repeated copy 202 202 graphCopy(from, to).run(); 203 203 204 204 check(countNodes(from) == countNodes(to), "Wrong copy."); 205 205 check(countEdges(from) == countEdges(to), "Wrong copy."); -
TabularUnified test/graph_test.cc ¶
r463 r956 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 39 39 checkGraphArcList(G, 0); 40 40 41 G.reserveNode(3); 42 G.reserveEdge(3); 43 41 44 Node 42 45 n1 = G.addNode(), … … 257 260 258 261 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(); 259 271 260 272 checkGraphNodeList(G, 4); … … 268 280 269 281 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 270 289 checkGraphNodeList(G, num); 271 290 checkGraphEdgeList(G, num * (num - 1) / 2); … … 412 431 check(G.height() == height, "Wrong row number"); 413 432 433 G.resize(width, height); 434 check(G.width() == width, "Wrong column number"); 435 check(G.height() == height, "Wrong row number"); 436 414 437 for (int i = 0; i < width; ++i) { 415 438 for (int j = 0; j < height; ++j) { … … 487 510 488 511 HypercubeGraph G(dim); 512 check(G.dimension() == dim, "Wrong dimension"); 513 514 G.resize(dim); 515 check(G.dimension() == dim, "Wrong dimension"); 516 489 517 checkGraphNodeList(G, 1 << dim); 490 518 checkGraphEdgeList(G, dim * (1 << (dim-1))); -
TabularUnified test/hao_orlin_test.cc ¶
r644 r956 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 84 84 85 85 template <typename Graph, typename CapMap, typename CutMap> 86 typename CapMap::Value 86 typename CapMap::Value 87 87 cutValue(const Graph& graph, const CapMap& cap, const CutMap& cut) 88 88 { … … 111 111 ho.run(); 112 112 ho.minCutMap(cut); 113 113 114 114 check(ho.minCutValue() == 1, "Wrong cut value"); 115 115 check(ho.minCutValue() == cutValue(graph, cap1, cut), "Wrong cut value"); … … 127 127 ho.run(); 128 128 ho.minCutMap(cut); 129 129 130 130 check(ho.minCutValue() == 1, "Wrong cut value"); 131 131 check(ho.minCutValue() == cutValue(graph, cap3, cut), "Wrong cut value"); 132 132 } 133 133 134 134 typedef Undirector<SmartDigraph> UGraph; 135 135 UGraph ugraph(graph); 136 136 137 137 { 138 138 HaoOrlin<UGraph, SmartDigraph::ArcMap<int> > ho(ugraph, cap1); 139 139 ho.run(); 140 140 ho.minCutMap(cut); 141 141 142 142 check(ho.minCutValue() == 2, "Wrong cut value"); 143 143 check(ho.minCutValue() == cutValue(ugraph, cap1, cut), "Wrong cut value"); … … 147 147 ho.run(); 148 148 ho.minCutMap(cut); 149 149 150 150 check(ho.minCutValue() == 5, "Wrong cut value"); 151 151 check(ho.minCutValue() == cutValue(ugraph, cap2, cut), "Wrong cut value"); … … 155 155 ho.run(); 156 156 ho.minCutMap(cut); 157 157 158 158 check(ho.minCutValue() == 5, "Wrong cut value"); 159 159 check(ho.minCutValue() == cutValue(ugraph, cap3, cut), "Wrong cut value"); -
TabularUnified test/heap_test.cc ¶
r728 r1084 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2011 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 26 26 27 27 #include <lemon/smart_graph.h> 28 29 28 #include <lemon/lgf_reader.h> 30 29 #include <lemon/dijkstra.h> … … 32 31 33 32 #include <lemon/bin_heap.h> 33 #include <lemon/quad_heap.h> 34 #include <lemon/dheap.h> 34 35 #include <lemon/fib_heap.h> 36 #include <lemon/pairing_heap.h> 35 37 #include <lemon/radix_heap.h> 38 #include <lemon/binomial_heap.h> 36 39 #include <lemon/bucket_heap.h> 37 40 … … 90 93 void heapSortTest() { 91 94 RangeMap<int> map(test_len, -1); 92 93 95 Heap heap(map); 94 96 95 97 std::vector<int> v(test_len); 96 97 98 for (int i = 0; i < test_len; ++i) { 98 99 v[i] = test_seq[i]; … … 101 102 std::sort(v.begin(), v.end()); 102 103 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."); 104 105 heap.pop(); 105 106 } … … 113 114 114 115 std::vector<int> v(test_len); 115 116 116 for (int i = 0; i < test_len; ++i) { 117 117 v[i] = test_seq[i]; … … 124 124 std::sort(v.begin(), v.end()); 125 125 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."); 127 127 heap.pop(); 128 128 } 129 129 } 130 131 132 130 133 131 template <typename Heap> … … 145 143 if (dijkstra.reached(s)) { 146 144 check( dijkstra.dist(t) - dijkstra.dist(s) <= length[a], 147 "Error in a shortest path tree!");145 "Error in shortest path tree."); 148 146 } 149 147 } … … 154 152 Node s = digraph.source(a); 155 153 check( dijkstra.dist(n) - dijkstra.dist(s) == length[a], 156 "Error in a shortest path tree!");154 "Error in shortest path tree."); 157 155 } 158 156 } … … 176 174 run(); 177 175 176 // BinHeap 178 177 { 179 178 typedef BinHeap<Prio, ItemIntMap> IntHeap; … … 185 184 checkConcept<Heap<Prio, IntNodeMap >, NodeHeap>(); 186 185 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>(); 187 273 } 188 274 -
TabularUnified test/lgf_test.cc ¶
r1087 r1097 64 64 65 65 66 int main() 66 int main() 67 67 { 68 68 { 69 ListDigraph d; 69 ListDigraph d; 70 70 ListDigraph::Node s,t; 71 71 ListDigraph::ArcMap<int> label(d); … … 94 94 95 95 { 96 ListDigraph d; 96 ListDigraph d; 97 97 std::istringstream input(test_lgf_nomap); 98 98 digraphReader(d, input). … … 111 111 112 112 { 113 ListDigraph d; 113 ListDigraph d; 114 114 std::istringstream input(test_lgf_bad1); 115 115 bool ok=false; … … 118 118 run(); 119 119 } 120 catch (FormatError&) 120 catch (FormatError&) 121 121 { 122 122 ok = true; … … 140 140 141 141 { 142 ListDigraph d; 142 ListDigraph d; 143 143 std::istringstream input(test_lgf_bad2); 144 144 bool ok=false; -
TabularUnified test/lp_test.cc ¶
r1092 r1097 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2011 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). -
TabularUnified test/maps_test.cc ¶
r731 r1084 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2011 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 24 24 #include <lemon/maps.h> 25 25 #include <lemon/list_graph.h> 26 #include <lemon/smart_graph.h> 27 #include <lemon/adaptors.h> 28 #include <lemon/dfs.h> 29 #include <algorithm> 26 30 27 31 #include "test_tools.h" … … 35 39 36 40 class C { 37 int x;41 int _x; 38 42 public: 39 C(int _x) : x(_x) {} 43 C(int x) : _x(x) {} 44 int get() const { return _x; } 45 }; 46 inline bool operator<(C c1, C c2) { return c1.get() < c2.get(); } 47 inline bool operator==(C c1, C c2) { return c1.get() == c2.get(); } 48 49 C createC(int x) { return C(x); } 50 51 template <typename T> 52 class Less { 53 T _t; 54 public: 55 Less(T t): _t(t) {} 56 bool operator()(const T& t) const { return t < _t; } 40 57 }; 41 58 … … 53 70 54 71 int binc(int a, B) { return a+1; } 72 73 template <typename T> 74 class Sum { 75 T& _sum; 76 public: 77 Sum(T& sum) : _sum(sum) {} 78 void operator()(const T& t) { _sum += t; } 79 }; 55 80 56 81 typedef ReadMap<A, double> DoubleMap; … … 201 226 202 227 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>()); 204 230 205 231 check(functorToMap(&func)[A()] == 3, … … 330 356 { 331 357 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 332 362 vec v1; 333 363 vec v2(10); … … 349 379 it != map2.end(); ++it ) 350 380 check(v1[i++] == *it, "Something is wrong with LoggerBoolMap"); 351 } 352 353 // CrossRefMap 354 { 381 355 382 typedef ListDigraph Graph; 356 383 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); 357 537 358 538 checkConcept<ReadWriteMap<Node, int>, 359 539 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 361 608 Graph gr; 362 609 typedef CrossRefMap<Graph, Node, char> CRMap; 363 610 typedef CRMap::ValueIterator ValueIt; 364 611 CRMap map(gr); 365 612 366 613 Node n0 = gr.addNode(); 367 614 Node n1 = gr.addNode(); 368 615 Node n2 = gr.addNode(); 369 616 370 617 map.set(n0, 'A'); 371 618 map.set(n1, 'B'); … … 385 632 } 386 633 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 /* 934 These 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 387 1002 return 0; 388 1003 } -
TabularUnified test/matching_test.cc ¶
r641 r956 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 135 135 mat_test.startDense(); 136 136 mat_test.run(); 137 137 138 138 const_mat_test.matchingSize(); 139 139 const_mat_test.matching(e); … … 144 144 const_mat_test.mate(n); 145 145 146 MaxMatching<Graph>::Status stat = 146 MaxMatching<Graph>::Status stat = 147 147 const_mat_test.status(n); 148 148 const MaxMatching<Graph>::StatusMap& smap = … … 171 171 mat_test.start(); 172 172 mat_test.run(); 173 173 174 174 const_mat_test.matchingWeight(); 175 175 const_mat_test.matchingSize(); … … 180 180 e = mmap[n]; 181 181 const_mat_test.mate(n); 182 182 183 183 int k = 0; 184 184 const_mat_test.dualValue(); … … 208 208 mat_test.start(); 209 209 mat_test.run(); 210 210 211 211 const_mat_test.matchingWeight(); 212 212 const_mat_test.matching(e); … … 216 216 e = mmap[n]; 217 217 const_mat_test.mate(n); 218 218 219 219 int k = 0; 220 220 const_mat_test.dualValue(); … … 402 402 edgeMap("weight", weight).run(); 403 403 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 } 420 444 } 421 445 } -
TabularUnified test/min_cost_arborescence_test.cc ¶
r672 r956 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 085 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 111 111 b = const_mcarb_test.emptyQueue(); 112 112 i = const_mcarb_test.queueSize(); 113 113 114 114 c = const_mcarb_test.arborescenceCost(); 115 115 b = const_mcarb_test.arborescence(e); … … 121 121 b = const_mcarb_test.reached(n); 122 122 b = const_mcarb_test.processed(n); 123 123 124 124 i = const_mcarb_test.dualNum(); 125 125 c = const_mcarb_test.dualValue(); 126 126 i = const_mcarb_test.dualSize(i); 127 127 c = const_mcarb_test.dualValue(i); 128 128 129 129 ignore_unused_variable_warning(am); 130 130 ignore_unused_variable_warning(pm); -
TabularUnified test/min_cost_flow_test.cc ¶
r716 r956 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 25 25 26 26 #include <lemon/network_simplex.h> 27 #include <lemon/capacity_scaling.h> 28 #include <lemon/cost_scaling.h> 29 #include <lemon/cycle_canceling.h> 27 30 28 31 #include <lemon/concepts/digraph.h> 32 #include <lemon/concepts/heap.h> 29 33 #include <lemon/concept_check.h> 30 34 … … 33 37 using namespace lemon; 34 38 39 // Test networks 35 40 char test_lgf[] = 36 41 "@nodes\n" … … 48 53 " 11 0 0 0 0 -10 0\n" 49 54 " 12 -20 -27 0 -30 -30 -20\n" 50 "\n" 55 "\n" 51 56 "@arcs\n" 52 57 " cost cap low1 low2 low3\n" … … 77 82 "target 12\n"; 78 83 84 char 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 106 char 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 117 typedef ListDigraph Digraph; 118 DIGRAPH_TYPEDEFS(ListDigraph); 119 120 Digraph gr; 121 Digraph::ArcMap<int> c(gr), l1(gr), l2(gr), l3(gr), u(gr); 122 Digraph::NodeMap<int> s1(gr), s2(gr), s3(gr), s4(gr), s5(gr), s6(gr); 123 ConstMap<Arc, int> cc(1), cu(std::numeric_limits<int>::max()); 124 Node v, w; 125 126 Digraph neg1_gr; 127 Digraph::ArcMap<int> neg1_c(neg1_gr), neg1_l1(neg1_gr), neg1_l2(neg1_gr); 128 ConstMap<Arc, int> neg1_u1(std::numeric_limits<int>::max()), neg1_u2(5000); 129 Digraph::NodeMap<int> neg1_s(neg1_gr); 130 131 Digraph neg2_gr; 132 Digraph::ArcMap<int> neg2_c(neg2_gr); 133 ConstMap<Arc, int> neg2_l(0), neg2_u(1000); 134 Digraph::NodeMap<int> neg2_s(neg2_gr); 135 79 136 80 137 enum SupplyType { … … 84 141 }; 85 142 143 86 144 // Check the interface of an MCF algorithm 87 145 template <typename GR, typename Value, typename Cost> … … 94 152 void constraints() { 95 153 checkConcept<concepts::Digraph, GR>(); 96 154 97 155 const Constraints& me = *this; 98 156 … … 100 158 const MCF& const_mcf = mcf; 101 159 102 b = mcf.reset() 160 b = mcf.reset().resetParams() 103 161 .lowerMap(me.lower) 104 162 .upperMap(me.upper) … … 123 181 typedef concepts::WriteMap<Arc, Value> FlowMap; 124 182 typedef concepts::WriteMap<Node, Cost> PotMap; 125 183 126 184 GR g; 127 185 VAM lower; … … 177 235 typename CM, typename SM, typename FM, typename PM > 178 236 bool 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, 180 238 const PM& pi, SupplyType type ) 181 239 { … … 190 248 (red_cost < 0 && flow[e] == upper[e]); 191 249 } 192 250 193 251 for (NodeIt n(gr); opt && n != INVALID; ++n) { 194 252 typename SM::Value sum = 0; … … 203 261 } 204 262 } 205 263 206 264 return opt; 207 265 } … … 228 286 } 229 287 } 230 288 231 289 for (NodeIt n(gr); n != INVALID; ++n) { 232 290 dual_cost -= red_supply[n] * pi[n]; … … 237 295 dual_cost -= (upper[a] - lower[a]) * std::max(-red_cost, 0); 238 296 } 239 297 240 298 return dual_cost == total; 241 299 } … … 269 327 } 270 328 329 template < typename MCF, typename Param > 330 void 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 400 template < typename MCF, typename Param > 401 void 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 271 419 int main() 272 420 { 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 295 422 std::istringstream input(test_lgf); 296 423 DigraphReader<Digraph>(gr, input) … … 309 436 .node("target", w) 310 437 .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"); 447 539 } 448 540 -
TabularUnified test/preflow_test.cc ¶
r1027 r1084 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2011 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 96 96 const PreflowType& const_preflow_test = preflow_test; 97 97 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 98 103 preflow_test 99 104 .capacityMap(cap) … … 114 119 b = const_preflow_test.minCut(n); 115 120 const_preflow_test.minCutMap(cut); 116 121 117 122 ignore_unused_variable_warning(fm); 118 123 } … … 155 160 { 156 161 DIGRAPH_TYPEDEFS(SmartDigraph); 157 162 158 163 SmartDigraph g; 159 164 SmartDigraph::ArcMap<int> cap(g),iflow(g); … … 267 272 268 273 initFlowTest(); 269 274 270 275 return 0; 271 276 } -
TabularUnified test/suurballe_test.cc ¶
r670 r956 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 24 24 #include <lemon/suurballe.h> 25 25 #include <lemon/concepts/digraph.h> 26 #include <lemon/concepts/heap.h> 26 27 27 28 #include "test_tools.h" … … 81 82 typedef Digraph::Arc Arc; 82 83 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; 85 92 86 93 Digraph g; … … 102 109 k = suurb_test.run(n, n, k); 103 110 suurb_test.init(n); 111 suurb_test.fullInit(n); 112 suurb_test.start(n); 113 suurb_test.start(n, k); 104 114 k = suurb_test.findFlow(n); 105 115 k = suurb_test.findFlow(n, k); 106 116 suurb_test.findPaths(); 107 117 108 118 int f; 109 119 VType c; … … 117 127 k = const_suurb_test.pathNum(); 118 128 Path<Digraph> p = const_suurb_test.path(k); 119 129 120 130 ignore_unused_variable_warning(fm); 121 131 ignore_unused_variable_warning(pm); … … 196 206 run(); 197 207 198 // Find 2 paths208 // Check run() 199 209 { 200 210 Suurballe<ListDigraph> suurballe(digraph, length); 211 212 // Find 2 paths 201 213 check(suurballe.run(s, t) == 2, "Wrong number of paths"); 202 214 check(checkFlow(digraph, suurballe.flowMap(), s, t, 2), … … 208 220 for (int i = 0; i < suurballe.pathNum(); ++i) 209 221 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 215 224 check(suurballe.run(s, t, 3) == 3, "Wrong number of paths"); 216 225 check(checkFlow(digraph, suurballe.flowMap(), s, t, 3), … … 222 231 for (int i = 0; i < suurballe.pathNum(); ++i) 223 232 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) 229 235 check(suurballe.run(s, t, 5) == 3, "Wrong number of paths"); 230 236 check(checkFlow(digraph, suurballe.flowMap(), s, t, 3), … … 238 244 } 239 245 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 240 264 return 0; 241 265 } -
TabularUnified test/test_tools.h ¶
r463 r956 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 38 38 ///print something like this (and then exits). 39 39 ///\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 45 49 46 50 #endif -
TabularUnified tools/dimacs-solver.cc ¶
r691 r956 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 89 89 pre.run(); 90 90 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 94 template<class Value, class LargeValue> 95 95 void solve_min(ArgParser &ap, std::istream &is, std::ostream &, 96 96 Value infty, DimacsDescriptor &desc) … … 128 128 std::cerr << "Run NetworkSimplex: " << ti << "\n\n"; 129 129 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'; 131 132 } 132 133 } … … 148 149 if(report) std::cerr << "Run MaxMatching: " << ti << '\n'; 149 150 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 155 template<class Value, class LargeValue> 155 156 void solve(ArgParser &ap, std::istream &is, std::ostream &os, 156 157 DimacsDescriptor &desc) … … 166 167 exit(1); 167 168 } 168 169 169 170 switch(desc.type) 170 171 { 171 172 case DimacsDescriptor::MIN: 172 solve_min<Value >(ap,is,os,infty,desc);173 solve_min<Value, LargeValue>(ap,is,os,infty,desc); 173 174 break; 174 175 case DimacsDescriptor::MAX: … … 238 239 239 240 DimacsDescriptor desc = dimacsType(is); 240 241 241 242 if(!ap.given("q")) 242 243 { … … 263 264 std::cout << "\n\n"; 264 265 } 265 266 266 267 if(ap.given("double")) 267 solve<double >(ap,is,os,desc);268 solve<double, double>(ap,is,os,desc); 268 269 else if(ap.given("ldouble")) 269 solve<long double >(ap,is,os,desc);270 solve<long double, long double>(ap,is,os,desc); 270 271 #ifdef LEMON_HAVE_LONG_LONG 271 272 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); 273 277 #endif 274 else solve<int>(ap,is,os,desc);275 278 276 279 return 0; -
TabularUnified tools/lemon-0.x-to-1.x.sh ¶
r621 r738 36 36 -e "s/Edge\>/_Ar_c_label_/g"\ 37 37 -e "s/\<edge\>/_ar_c_label_/g"\ 38 -e "s/_edge\>/_ ar_c_label_/g"\38 -e "s/_edge\>/__ar_c_label_/g"\ 39 39 -e "s/Edges\>/_Ar_c_label_s/g"\ 40 40 -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"\ 42 42 -e "s/\([Ee]\)dge\([a-z]\)/_\1d_ge_label_\2/g"\ 43 43 -e "s/\([a-z]\)edge/\1_ed_ge_label_/g"\ … … 69 69 -e "s/_GR_APH_TY_PEDE_FS_label_/GRAPH_TYPEDEFS/g"\ 70 70 -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"\ 71 76 -e "s/DigraphToEps/GraphToEps/g"\ 72 77 -e "s/digraphToEps/graphToEps/g"\
Note: See TracChangeset
for help on using the changeset viewer.