Changes in / [839:f3bc4e9b5f3a:840:2914b6f0fde0] in lemon-main
- Files:
-
- 1 added
- 23 edited
Legend:
- Unmodified
- Added
- Removed
-
INSTALL
r568 r824 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"'. -
doc/CMakeLists.txt
r744 r827 27 27 COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r18 -sOutputFile=gen-images/nodeshape_3.png ${CMAKE_CURRENT_SOURCE_DIR}/images/nodeshape_3.eps 28 28 COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r18 -sOutputFile=gen-images/nodeshape_4.png ${CMAKE_CURRENT_SOURCE_DIR}/images/nodeshape_4.eps 29 COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r18 -sOutputFile=gen-images/planar.png ${CMAKE_CURRENT_SOURCE_DIR}/images/planar.eps 29 30 COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r18 -sOutputFile=gen-images/strongly_connected_components.png ${CMAKE_CURRENT_SOURCE_DIR}/images/strongly_connected_components.eps 30 31 COMMAND ${CMAKE_COMMAND} -E remove_directory html -
doc/Makefile.am
r744 r827 29 29 edge_biconnected_components.eps \ 30 30 node_biconnected_components.eps \ 31 planar.eps \ 31 32 strongly_connected_components.eps 32 33 -
lemon/bellman_ford.h
r804 r825 172 172 /// the lengths of the arcs. The default map type is 173 173 /// \ref concepts::Digraph::ArcMap "GR::ArcMap<int>". 174 /// \tparam TR The traits class that defines various types used by the 175 /// algorithm. By default, it is \ref BellmanFordDefaultTraits 176 /// "BellmanFordDefaultTraits<GR, LEN>". 177 /// In most cases, this parameter should not be set directly, 178 /// consider to use the named template parameters instead. 174 179 #ifdef DOXYGEN 175 180 template <typename GR, typename LEN, typename TR> … … 934 939 /// This class should only be used through the \ref bellmanFord() 935 940 /// function, which makes it easier to use the algorithm. 941 /// 942 /// \tparam TR The traits class that defines various types used by the 943 /// algorithm. 936 944 template<class TR> 937 945 class BellmanFordWizard : public TR { -
lemon/bfs.h
r788 r825 122 122 ///\tparam GR The type of the digraph the algorithm runs on. 123 123 ///The default type is \ref ListDigraph. 124 ///\tparam TR The traits class that defines various types used by the 125 ///algorithm. By default, it is \ref BfsDefaultTraits 126 ///"BfsDefaultTraits<GR>". 127 ///In most cases, this parameter should not be set directly, 128 ///consider to use the named template parameters instead. 124 129 #ifdef DOXYGEN 125 130 template <typename GR, … … 958 963 /// This class should only be used through the \ref bfs() function, 959 964 /// which makes it easier to use the algorithm. 965 /// 966 /// \tparam TR The traits class that defines various types used by the 967 /// algorithm. 960 968 template<class TR> 961 969 class BfsWizard : public TR … … 1296 1304 /// does not observe the BFS events. If you want to observe the BFS 1297 1305 /// events, you should implement your own visitor class. 1298 /// \tparam TR T raits class to set various datatypes used by the1299 /// algorithm. The default traits class is1300 /// \ref BfsVisitDefaultTraits"BfsVisitDefaultTraits<GR>".1301 /// See \ref BfsVisitDefaultTraits for the documentation of1302 /// a BFS visit traits class.1306 /// \tparam TR The traits class that defines various types used by the 1307 /// algorithm. By default, it is \ref BfsVisitDefaultTraits 1308 /// "BfsVisitDefaultTraits<GR>". 1309 /// In most cases, this parameter should not be set directly, 1310 /// consider to use the named template parameters instead. 1303 1311 #ifdef DOXYGEN 1304 1312 template <typename GR, typename VS, typename TR> -
lemon/capacity_scaling.h
r839 r840 78 78 /// \tparam GR The digraph type the algorithm runs on. 79 79 /// \tparam V The number type used for flow amounts, capacity bounds 80 /// and supply values in the algorithm. By default it is \c int.80 /// and supply values in the algorithm. By default, it is \c int. 81 81 /// \tparam C The number type used for costs and potentials in the 82 /// algorithm. By default it is the same as \c V. 82 /// algorithm. By default, it is the same as \c V. 83 /// \tparam TR The traits class that defines various types used by the 84 /// algorithm. By default, it is \ref CapacityScalingDefaultTraits 85 /// "CapacityScalingDefaultTraits<GR, V, C>". 86 /// In most cases, this parameter should not be set directly, 87 /// consider to use the named template parameters instead. 83 88 /// 84 89 /// \warning Both number types must be signed and all input data must … … 316 321 "The cost type of CapacityScaling must be signed"); 317 322 323 // Reset data structures 324 reset(); 325 } 326 327 /// \name Parameters 328 /// The parameters of the algorithm can be specified using these 329 /// functions. 330 331 /// @{ 332 333 /// \brief Set the lower bounds on the arcs. 334 /// 335 /// This function sets the lower bounds on the arcs. 336 /// If it is not used before calling \ref run(), the lower bounds 337 /// will be set to zero on all arcs. 338 /// 339 /// \param map An arc map storing the lower bounds. 340 /// Its \c Value type must be convertible to the \c Value type 341 /// of the algorithm. 342 /// 343 /// \return <tt>(*this)</tt> 344 template <typename LowerMap> 345 CapacityScaling& lowerMap(const LowerMap& map) { 346 _have_lower = true; 347 for (ArcIt a(_graph); a != INVALID; ++a) { 348 _lower[_arc_idf[a]] = map[a]; 349 _lower[_arc_idb[a]] = map[a]; 350 } 351 return *this; 352 } 353 354 /// \brief Set the upper bounds (capacities) on the arcs. 355 /// 356 /// This function sets the upper bounds (capacities) on the arcs. 357 /// If it is not used before calling \ref run(), the upper bounds 358 /// will be set to \ref INF on all arcs (i.e. the flow value will be 359 /// unbounded from above). 360 /// 361 /// \param map An arc map storing the upper bounds. 362 /// Its \c Value type must be convertible to the \c Value type 363 /// of the algorithm. 364 /// 365 /// \return <tt>(*this)</tt> 366 template<typename UpperMap> 367 CapacityScaling& upperMap(const UpperMap& map) { 368 for (ArcIt a(_graph); a != INVALID; ++a) { 369 _upper[_arc_idf[a]] = map[a]; 370 } 371 return *this; 372 } 373 374 /// \brief Set the costs of the arcs. 375 /// 376 /// This function sets the costs of the arcs. 377 /// If it is not used before calling \ref run(), the costs 378 /// will be set to \c 1 on all arcs. 379 /// 380 /// \param map An arc map storing the costs. 381 /// Its \c Value type must be convertible to the \c Cost type 382 /// of the algorithm. 383 /// 384 /// \return <tt>(*this)</tt> 385 template<typename CostMap> 386 CapacityScaling& costMap(const CostMap& map) { 387 for (ArcIt a(_graph); a != INVALID; ++a) { 388 _cost[_arc_idf[a]] = map[a]; 389 _cost[_arc_idb[a]] = -map[a]; 390 } 391 return *this; 392 } 393 394 /// \brief Set the supply values of the nodes. 395 /// 396 /// This function sets the supply values of the nodes. 397 /// If neither this function nor \ref stSupply() is used before 398 /// calling \ref run(), the supply of each node will be set to zero. 399 /// 400 /// \param map A node map storing the supply values. 401 /// Its \c Value type must be convertible to the \c Value type 402 /// of the algorithm. 403 /// 404 /// \return <tt>(*this)</tt> 405 template<typename SupplyMap> 406 CapacityScaling& supplyMap(const SupplyMap& map) { 407 for (NodeIt n(_graph); n != INVALID; ++n) { 408 _supply[_node_id[n]] = map[n]; 409 } 410 return *this; 411 } 412 413 /// \brief Set single source and target nodes and a supply value. 414 /// 415 /// This function sets a single source node and a single target node 416 /// and the required flow value. 417 /// If neither this function nor \ref supplyMap() is used before 418 /// calling \ref run(), the supply of each node will be set to zero. 419 /// 420 /// Using this function has the same effect as using \ref supplyMap() 421 /// with such a map in which \c k is assigned to \c s, \c -k is 422 /// assigned to \c t and all other nodes have zero supply value. 423 /// 424 /// \param s The source node. 425 /// \param t The target node. 426 /// \param k The required amount of flow from node \c s to node \c t 427 /// (i.e. the supply of \c s and the demand of \c t). 428 /// 429 /// \return <tt>(*this)</tt> 430 CapacityScaling& stSupply(const Node& s, const Node& t, Value k) { 431 for (int i = 0; i != _node_num; ++i) { 432 _supply[i] = 0; 433 } 434 _supply[_node_id[s]] = k; 435 _supply[_node_id[t]] = -k; 436 return *this; 437 } 438 439 /// @} 440 441 /// \name Execution control 442 /// The algorithm can be executed using \ref run(). 443 444 /// @{ 445 446 /// \brief Run the algorithm. 447 /// 448 /// This function runs the algorithm. 449 /// The paramters can be specified using functions \ref lowerMap(), 450 /// \ref upperMap(), \ref costMap(), \ref supplyMap(), \ref stSupply(). 451 /// For example, 452 /// \code 453 /// CapacityScaling<ListDigraph> cs(graph); 454 /// cs.lowerMap(lower).upperMap(upper).costMap(cost) 455 /// .supplyMap(sup).run(); 456 /// \endcode 457 /// 458 /// This function can be called more than once. All the given parameters 459 /// are kept for the next call, unless \ref resetParams() or \ref reset() 460 /// is used, thus only the modified parameters have to be set again. 461 /// If the underlying digraph was also modified after the construction 462 /// of the class (or the last \ref reset() call), then the \ref reset() 463 /// function must be called. 464 /// 465 /// \param factor The capacity scaling factor. It must be larger than 466 /// one to use scaling. If it is less or equal to one, then scaling 467 /// will be disabled. 468 /// 469 /// \return \c INFEASIBLE if no feasible flow exists, 470 /// \n \c OPTIMAL if the problem has optimal solution 471 /// (i.e. it is feasible and bounded), and the algorithm has found 472 /// optimal flow and node potentials (primal and dual solutions), 473 /// \n \c UNBOUNDED if the digraph contains an arc of negative cost 474 /// and infinite upper bound. It means that the objective function 475 /// is unbounded on that arc, however, note that it could actually be 476 /// bounded over the feasible flows, but this algroithm cannot handle 477 /// these cases. 478 /// 479 /// \see ProblemType 480 /// \see resetParams(), reset() 481 ProblemType run(int factor = 4) { 482 _factor = factor; 483 ProblemType pt = init(); 484 if (pt != OPTIMAL) return pt; 485 return start(); 486 } 487 488 /// \brief Reset all the parameters that have been given before. 489 /// 490 /// This function resets all the paramaters that have been given 491 /// before using functions \ref lowerMap(), \ref upperMap(), 492 /// \ref costMap(), \ref supplyMap(), \ref stSupply(). 493 /// 494 /// It is useful for multiple \ref run() calls. Basically, all the given 495 /// parameters are kept for the next \ref run() call, unless 496 /// \ref resetParams() or \ref reset() is used. 497 /// If the underlying digraph was also modified after the construction 498 /// of the class or the last \ref reset() call, then the \ref reset() 499 /// function must be used, otherwise \ref resetParams() is sufficient. 500 /// 501 /// For example, 502 /// \code 503 /// CapacityScaling<ListDigraph> cs(graph); 504 /// 505 /// // First run 506 /// cs.lowerMap(lower).upperMap(upper).costMap(cost) 507 /// .supplyMap(sup).run(); 508 /// 509 /// // Run again with modified cost map (resetParams() is not called, 510 /// // so only the cost map have to be set again) 511 /// cost[e] += 100; 512 /// cs.costMap(cost).run(); 513 /// 514 /// // Run again from scratch using resetParams() 515 /// // (the lower bounds will be set to zero on all arcs) 516 /// cs.resetParams(); 517 /// cs.upperMap(capacity).costMap(cost) 518 /// .supplyMap(sup).run(); 519 /// \endcode 520 /// 521 /// \return <tt>(*this)</tt> 522 /// 523 /// \see reset(), run() 524 CapacityScaling& resetParams() { 525 for (int i = 0; i != _node_num; ++i) { 526 _supply[i] = 0; 527 } 528 for (int j = 0; j != _res_arc_num; ++j) { 529 _lower[j] = 0; 530 _upper[j] = INF; 531 _cost[j] = _forward[j] ? 1 : -1; 532 } 533 _have_lower = false; 534 return *this; 535 } 536 537 /// \brief Reset the internal data structures and all the parameters 538 /// that have been given before. 539 /// 540 /// This function resets the internal data structures and all the 541 /// paramaters that have been given before using functions \ref lowerMap(), 542 /// \ref upperMap(), \ref costMap(), \ref supplyMap(), \ref stSupply(). 543 /// 544 /// It is useful for multiple \ref run() calls. Basically, all the given 545 /// parameters are kept for the next \ref run() call, unless 546 /// \ref resetParams() or \ref reset() is used. 547 /// If the underlying digraph was also modified after the construction 548 /// of the class or the last \ref reset() call, then the \ref reset() 549 /// function must be used, otherwise \ref resetParams() is sufficient. 550 /// 551 /// See \ref resetParams() for examples. 552 /// 553 /// \return <tt>(*this)</tt> 554 /// 555 /// \see resetParams(), run() 556 CapacityScaling& reset() { 318 557 // Resize vectors 319 558 _node_num = countNodes(_graph); … … 379 618 380 619 // Reset parameters 381 reset(); 382 } 383 384 /// \name Parameters 385 /// The parameters of the algorithm can be specified using these 386 /// functions. 387 388 /// @{ 389 390 /// \brief Set the lower bounds on the arcs. 391 /// 392 /// This function sets the lower bounds on the arcs. 393 /// If it is not used before calling \ref run(), the lower bounds 394 /// will be set to zero on all arcs. 395 /// 396 /// \param map An arc map storing the lower bounds. 397 /// Its \c Value type must be convertible to the \c Value type 398 /// of the algorithm. 399 /// 400 /// \return <tt>(*this)</tt> 401 template <typename LowerMap> 402 CapacityScaling& lowerMap(const LowerMap& map) { 403 _have_lower = true; 404 for (ArcIt a(_graph); a != INVALID; ++a) { 405 _lower[_arc_idf[a]] = map[a]; 406 _lower[_arc_idb[a]] = map[a]; 407 } 408 return *this; 409 } 410 411 /// \brief Set the upper bounds (capacities) on the arcs. 412 /// 413 /// This function sets the upper bounds (capacities) on the arcs. 414 /// If it is not used before calling \ref run(), the upper bounds 415 /// will be set to \ref INF on all arcs (i.e. the flow value will be 416 /// unbounded from above). 417 /// 418 /// \param map An arc map storing the upper bounds. 419 /// Its \c Value type must be convertible to the \c Value type 420 /// of the algorithm. 421 /// 422 /// \return <tt>(*this)</tt> 423 template<typename UpperMap> 424 CapacityScaling& upperMap(const UpperMap& map) { 425 for (ArcIt a(_graph); a != INVALID; ++a) { 426 _upper[_arc_idf[a]] = map[a]; 427 } 428 return *this; 429 } 430 431 /// \brief Set the costs of the arcs. 432 /// 433 /// This function sets the costs of the arcs. 434 /// If it is not used before calling \ref run(), the costs 435 /// will be set to \c 1 on all arcs. 436 /// 437 /// \param map An arc map storing the costs. 438 /// Its \c Value type must be convertible to the \c Cost type 439 /// of the algorithm. 440 /// 441 /// \return <tt>(*this)</tt> 442 template<typename CostMap> 443 CapacityScaling& costMap(const CostMap& map) { 444 for (ArcIt a(_graph); a != INVALID; ++a) { 445 _cost[_arc_idf[a]] = map[a]; 446 _cost[_arc_idb[a]] = -map[a]; 447 } 448 return *this; 449 } 450 451 /// \brief Set the supply values of the nodes. 452 /// 453 /// This function sets the supply values of the nodes. 454 /// If neither this function nor \ref stSupply() is used before 455 /// calling \ref run(), the supply of each node will be set to zero. 456 /// 457 /// \param map A node map storing the supply values. 458 /// Its \c Value type must be convertible to the \c Value type 459 /// of the algorithm. 460 /// 461 /// \return <tt>(*this)</tt> 462 template<typename SupplyMap> 463 CapacityScaling& supplyMap(const SupplyMap& map) { 464 for (NodeIt n(_graph); n != INVALID; ++n) { 465 _supply[_node_id[n]] = map[n]; 466 } 467 return *this; 468 } 469 470 /// \brief Set single source and target nodes and a supply value. 471 /// 472 /// This function sets a single source node and a single target node 473 /// and the required flow value. 474 /// If neither this function nor \ref supplyMap() is used before 475 /// calling \ref run(), the supply of each node will be set to zero. 476 /// 477 /// Using this function has the same effect as using \ref supplyMap() 478 /// with such a map in which \c k is assigned to \c s, \c -k is 479 /// assigned to \c t and all other nodes have zero supply value. 480 /// 481 /// \param s The source node. 482 /// \param t The target node. 483 /// \param k The required amount of flow from node \c s to node \c t 484 /// (i.e. the supply of \c s and the demand of \c t). 485 /// 486 /// \return <tt>(*this)</tt> 487 CapacityScaling& stSupply(const Node& s, const Node& t, Value k) { 488 for (int i = 0; i != _node_num; ++i) { 489 _supply[i] = 0; 490 } 491 _supply[_node_id[s]] = k; 492 _supply[_node_id[t]] = -k; 493 return *this; 494 } 495 496 /// @} 497 498 /// \name Execution control 499 /// The algorithm can be executed using \ref run(). 500 501 /// @{ 502 503 /// \brief Run the algorithm. 504 /// 505 /// This function runs the algorithm. 506 /// The paramters can be specified using functions \ref lowerMap(), 507 /// \ref upperMap(), \ref costMap(), \ref supplyMap(), \ref stSupply(). 508 /// For example, 509 /// \code 510 /// CapacityScaling<ListDigraph> cs(graph); 511 /// cs.lowerMap(lower).upperMap(upper).costMap(cost) 512 /// .supplyMap(sup).run(); 513 /// \endcode 514 /// 515 /// This function can be called more than once. All the parameters 516 /// that have been given are kept for the next call, unless 517 /// \ref reset() is called, thus only the modified parameters 518 /// have to be set again. See \ref reset() for examples. 519 /// However, the underlying digraph must not be modified after this 520 /// class have been constructed, since it copies and extends the graph. 521 /// 522 /// \param factor The capacity scaling factor. It must be larger than 523 /// one to use scaling. If it is less or equal to one, then scaling 524 /// will be disabled. 525 /// 526 /// \return \c INFEASIBLE if no feasible flow exists, 527 /// \n \c OPTIMAL if the problem has optimal solution 528 /// (i.e. it is feasible and bounded), and the algorithm has found 529 /// optimal flow and node potentials (primal and dual solutions), 530 /// \n \c UNBOUNDED if the digraph contains an arc of negative cost 531 /// and infinite upper bound. It means that the objective function 532 /// is unbounded on that arc, however, note that it could actually be 533 /// bounded over the feasible flows, but this algroithm cannot handle 534 /// these cases. 535 /// 536 /// \see ProblemType 537 ProblemType run(int factor = 4) { 538 _factor = factor; 539 ProblemType pt = init(); 540 if (pt != OPTIMAL) return pt; 541 return start(); 542 } 543 544 /// \brief Reset all the parameters that have been given before. 545 /// 546 /// This function resets all the paramaters that have been given 547 /// before using functions \ref lowerMap(), \ref upperMap(), 548 /// \ref costMap(), \ref supplyMap(), \ref stSupply(). 549 /// 550 /// It is useful for multiple run() calls. If this function is not 551 /// used, all the parameters given before are kept for the next 552 /// \ref run() call. 553 /// However, the underlying digraph must not be modified after this 554 /// class have been constructed, since it copies and extends the graph. 555 /// 556 /// For example, 557 /// \code 558 /// CapacityScaling<ListDigraph> cs(graph); 559 /// 560 /// // First run 561 /// cs.lowerMap(lower).upperMap(upper).costMap(cost) 562 /// .supplyMap(sup).run(); 563 /// 564 /// // Run again with modified cost map (reset() is not called, 565 /// // so only the cost map have to be set again) 566 /// cost[e] += 100; 567 /// cs.costMap(cost).run(); 568 /// 569 /// // Run again from scratch using reset() 570 /// // (the lower bounds will be set to zero on all arcs) 571 /// cs.reset(); 572 /// cs.upperMap(capacity).costMap(cost) 573 /// .supplyMap(sup).run(); 574 /// \endcode 575 /// 576 /// \return <tt>(*this)</tt> 577 CapacityScaling& reset() { 578 for (int i = 0; i != _node_num; ++i) { 579 _supply[i] = 0; 580 } 581 for (int j = 0; j != _res_arc_num; ++j) { 582 _lower[j] = 0; 583 _upper[j] = INF; 584 _cost[j] = _forward[j] ? 1 : -1; 585 } 586 _have_lower = false; 620 resetParams(); 587 621 return *this; 588 622 } -
lemon/circulation.h
r786 r825 174 174 \tparam SM The type of the supply map. The default map type is 175 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. 176 181 */ 177 182 #ifdef DOXYGEN -
lemon/cost_scaling.h
r839 r840 105 105 /// \tparam GR The digraph type the algorithm runs on. 106 106 /// \tparam V The number type used for flow amounts, capacity bounds 107 /// and supply values in the algorithm. By default it is \c int.107 /// and supply values in the algorithm. By default, it is \c int. 108 108 /// \tparam C The number type used for costs and potentials in the 109 /// algorithm. By default it is the same as \c V. 109 /// algorithm. By default, it is the same as \c V. 110 /// \tparam TR The traits class that defines various types used by the 111 /// algorithm. By default, it is \ref CostScalingDefaultTraits 112 /// "CostScalingDefaultTraits<GR, V, C>". 113 /// In most cases, this parameter should not be set directly, 114 /// consider to use the named template parameters instead. 110 115 /// 111 116 /// \warning Both number types must be signed and all input data must … … 137 142 /// 138 143 /// The large cost type used for internal computations. 139 /// Using the \ref CostScalingDefaultTraits "default traits class", 140 /// it is \c long \c long if the \c Cost type is integer, 144 /// By default, it is \c long \c long if the \c Cost type is integer, 141 145 /// otherwise it is \c double. 142 146 typedef typename TR::LargeCost LargeCost; … … 341 345 LEMON_ASSERT(std::numeric_limits<Cost>::is_signed, 342 346 "The cost type of CostScaling must be signed"); 343 347 348 // Reset data structures 349 reset(); 350 } 351 352 /// \name Parameters 353 /// The parameters of the algorithm can be specified using these 354 /// functions. 355 356 /// @{ 357 358 /// \brief Set the lower bounds on the arcs. 359 /// 360 /// This function sets the lower bounds on the arcs. 361 /// If it is not used before calling \ref run(), the lower bounds 362 /// will be set to zero on all arcs. 363 /// 364 /// \param map An arc map storing the lower bounds. 365 /// Its \c Value type must be convertible to the \c Value type 366 /// of the algorithm. 367 /// 368 /// \return <tt>(*this)</tt> 369 template <typename LowerMap> 370 CostScaling& lowerMap(const LowerMap& map) { 371 _have_lower = true; 372 for (ArcIt a(_graph); a != INVALID; ++a) { 373 _lower[_arc_idf[a]] = map[a]; 374 _lower[_arc_idb[a]] = map[a]; 375 } 376 return *this; 377 } 378 379 /// \brief Set the upper bounds (capacities) on the arcs. 380 /// 381 /// This function sets the upper bounds (capacities) on the arcs. 382 /// If it is not used before calling \ref run(), the upper bounds 383 /// will be set to \ref INF on all arcs (i.e. the flow value will be 384 /// unbounded from above). 385 /// 386 /// \param map An arc map storing the upper bounds. 387 /// Its \c Value type must be convertible to the \c Value type 388 /// of the algorithm. 389 /// 390 /// \return <tt>(*this)</tt> 391 template<typename UpperMap> 392 CostScaling& upperMap(const UpperMap& map) { 393 for (ArcIt a(_graph); a != INVALID; ++a) { 394 _upper[_arc_idf[a]] = map[a]; 395 } 396 return *this; 397 } 398 399 /// \brief Set the costs of the arcs. 400 /// 401 /// This function sets the costs of the arcs. 402 /// If it is not used before calling \ref run(), the costs 403 /// will be set to \c 1 on all arcs. 404 /// 405 /// \param map An arc map storing the costs. 406 /// Its \c Value type must be convertible to the \c Cost type 407 /// of the algorithm. 408 /// 409 /// \return <tt>(*this)</tt> 410 template<typename CostMap> 411 CostScaling& costMap(const CostMap& map) { 412 for (ArcIt a(_graph); a != INVALID; ++a) { 413 _scost[_arc_idf[a]] = map[a]; 414 _scost[_arc_idb[a]] = -map[a]; 415 } 416 return *this; 417 } 418 419 /// \brief Set the supply values of the nodes. 420 /// 421 /// This function sets the supply values of the nodes. 422 /// If neither this function nor \ref stSupply() is used before 423 /// calling \ref run(), the supply of each node will be set to zero. 424 /// 425 /// \param map A node map storing the supply values. 426 /// Its \c Value type must be convertible to the \c Value type 427 /// of the algorithm. 428 /// 429 /// \return <tt>(*this)</tt> 430 template<typename SupplyMap> 431 CostScaling& supplyMap(const SupplyMap& map) { 432 for (NodeIt n(_graph); n != INVALID; ++n) { 433 _supply[_node_id[n]] = map[n]; 434 } 435 return *this; 436 } 437 438 /// \brief Set single source and target nodes and a supply value. 439 /// 440 /// This function sets a single source node and a single target node 441 /// and the required flow value. 442 /// If neither this function nor \ref supplyMap() is used before 443 /// calling \ref run(), the supply of each node will be set to zero. 444 /// 445 /// Using this function has the same effect as using \ref supplyMap() 446 /// with such a map in which \c k is assigned to \c s, \c -k is 447 /// assigned to \c t and all other nodes have zero supply value. 448 /// 449 /// \param s The source node. 450 /// \param t The target node. 451 /// \param k The required amount of flow from node \c s to node \c t 452 /// (i.e. the supply of \c s and the demand of \c t). 453 /// 454 /// \return <tt>(*this)</tt> 455 CostScaling& stSupply(const Node& s, const Node& t, Value k) { 456 for (int i = 0; i != _res_node_num; ++i) { 457 _supply[i] = 0; 458 } 459 _supply[_node_id[s]] = k; 460 _supply[_node_id[t]] = -k; 461 return *this; 462 } 463 464 /// @} 465 466 /// \name Execution control 467 /// The algorithm can be executed using \ref run(). 468 469 /// @{ 470 471 /// \brief Run the algorithm. 472 /// 473 /// This function runs the algorithm. 474 /// The paramters can be specified using functions \ref lowerMap(), 475 /// \ref upperMap(), \ref costMap(), \ref supplyMap(), \ref stSupply(). 476 /// For example, 477 /// \code 478 /// CostScaling<ListDigraph> cs(graph); 479 /// cs.lowerMap(lower).upperMap(upper).costMap(cost) 480 /// .supplyMap(sup).run(); 481 /// \endcode 482 /// 483 /// This function can be called more than once. All the given parameters 484 /// are kept for the next call, unless \ref resetParams() or \ref reset() 485 /// is used, thus only the modified parameters have to be set again. 486 /// If the underlying digraph was also modified after the construction 487 /// of the class (or the last \ref reset() call), then the \ref reset() 488 /// function must be called. 489 /// 490 /// \param method The internal method that will be used in the 491 /// algorithm. For more information, see \ref Method. 492 /// \param factor The cost scaling factor. It must be larger than one. 493 /// 494 /// \return \c INFEASIBLE if no feasible flow exists, 495 /// \n \c OPTIMAL if the problem has optimal solution 496 /// (i.e. it is feasible and bounded), and the algorithm has found 497 /// optimal flow and node potentials (primal and dual solutions), 498 /// \n \c UNBOUNDED if the digraph contains an arc of negative cost 499 /// and infinite upper bound. It means that the objective function 500 /// is unbounded on that arc, however, note that it could actually be 501 /// bounded over the feasible flows, but this algroithm cannot handle 502 /// these cases. 503 /// 504 /// \see ProblemType, Method 505 /// \see resetParams(), reset() 506 ProblemType run(Method method = PARTIAL_AUGMENT, int factor = 8) { 507 _alpha = factor; 508 ProblemType pt = init(); 509 if (pt != OPTIMAL) return pt; 510 start(method); 511 return OPTIMAL; 512 } 513 514 /// \brief Reset all the parameters that have been given before. 515 /// 516 /// This function resets all the paramaters that have been given 517 /// before using functions \ref lowerMap(), \ref upperMap(), 518 /// \ref costMap(), \ref supplyMap(), \ref stSupply(). 519 /// 520 /// It is useful for multiple \ref run() calls. Basically, all the given 521 /// parameters are kept for the next \ref run() call, unless 522 /// \ref resetParams() or \ref reset() is used. 523 /// If the underlying digraph was also modified after the construction 524 /// of the class or the last \ref reset() call, then the \ref reset() 525 /// function must be used, otherwise \ref resetParams() is sufficient. 526 /// 527 /// For example, 528 /// \code 529 /// CostScaling<ListDigraph> cs(graph); 530 /// 531 /// // First run 532 /// cs.lowerMap(lower).upperMap(upper).costMap(cost) 533 /// .supplyMap(sup).run(); 534 /// 535 /// // Run again with modified cost map (resetParams() is not called, 536 /// // so only the cost map have to be set again) 537 /// cost[e] += 100; 538 /// cs.costMap(cost).run(); 539 /// 540 /// // Run again from scratch using resetParams() 541 /// // (the lower bounds will be set to zero on all arcs) 542 /// cs.resetParams(); 543 /// cs.upperMap(capacity).costMap(cost) 544 /// .supplyMap(sup).run(); 545 /// \endcode 546 /// 547 /// \return <tt>(*this)</tt> 548 /// 549 /// \see reset(), run() 550 CostScaling& resetParams() { 551 for (int i = 0; i != _res_node_num; ++i) { 552 _supply[i] = 0; 553 } 554 int limit = _first_out[_root]; 555 for (int j = 0; j != limit; ++j) { 556 _lower[j] = 0; 557 _upper[j] = INF; 558 _scost[j] = _forward[j] ? 1 : -1; 559 } 560 for (int j = limit; j != _res_arc_num; ++j) { 561 _lower[j] = 0; 562 _upper[j] = INF; 563 _scost[j] = 0; 564 _scost[_reverse[j]] = 0; 565 } 566 _have_lower = false; 567 return *this; 568 } 569 570 /// \brief Reset all the parameters that have been given before. 571 /// 572 /// This function resets all the paramaters that have been given 573 /// before using functions \ref lowerMap(), \ref upperMap(), 574 /// \ref costMap(), \ref supplyMap(), \ref stSupply(). 575 /// 576 /// It is useful for multiple run() calls. If this function is not 577 /// used, all the parameters given before are kept for the next 578 /// \ref run() call. 579 /// However, the underlying digraph must not be modified after this 580 /// class have been constructed, since it copies and extends the graph. 581 /// \return <tt>(*this)</tt> 582 CostScaling& reset() { 344 583 // Resize vectors 345 584 _node_num = countNodes(_graph); … … 409 648 410 649 // Reset parameters 411 reset(); 412 } 413 414 /// \name Parameters 415 /// The parameters of the algorithm can be specified using these 416 /// functions. 417 418 /// @{ 419 420 /// \brief Set the lower bounds on the arcs. 421 /// 422 /// This function sets the lower bounds on the arcs. 423 /// If it is not used before calling \ref run(), the lower bounds 424 /// will be set to zero on all arcs. 425 /// 426 /// \param map An arc map storing the lower bounds. 427 /// Its \c Value type must be convertible to the \c Value type 428 /// of the algorithm. 429 /// 430 /// \return <tt>(*this)</tt> 431 template <typename LowerMap> 432 CostScaling& lowerMap(const LowerMap& map) { 433 _have_lower = true; 434 for (ArcIt a(_graph); a != INVALID; ++a) { 435 _lower[_arc_idf[a]] = map[a]; 436 _lower[_arc_idb[a]] = map[a]; 437 } 438 return *this; 439 } 440 441 /// \brief Set the upper bounds (capacities) on the arcs. 442 /// 443 /// This function sets the upper bounds (capacities) on the arcs. 444 /// If it is not used before calling \ref run(), the upper bounds 445 /// will be set to \ref INF on all arcs (i.e. the flow value will be 446 /// unbounded from above). 447 /// 448 /// \param map An arc map storing the upper bounds. 449 /// Its \c Value type must be convertible to the \c Value type 450 /// of the algorithm. 451 /// 452 /// \return <tt>(*this)</tt> 453 template<typename UpperMap> 454 CostScaling& upperMap(const UpperMap& map) { 455 for (ArcIt a(_graph); a != INVALID; ++a) { 456 _upper[_arc_idf[a]] = map[a]; 457 } 458 return *this; 459 } 460 461 /// \brief Set the costs of the arcs. 462 /// 463 /// This function sets the costs of the arcs. 464 /// If it is not used before calling \ref run(), the costs 465 /// will be set to \c 1 on all arcs. 466 /// 467 /// \param map An arc map storing the costs. 468 /// Its \c Value type must be convertible to the \c Cost type 469 /// of the algorithm. 470 /// 471 /// \return <tt>(*this)</tt> 472 template<typename CostMap> 473 CostScaling& costMap(const CostMap& map) { 474 for (ArcIt a(_graph); a != INVALID; ++a) { 475 _scost[_arc_idf[a]] = map[a]; 476 _scost[_arc_idb[a]] = -map[a]; 477 } 478 return *this; 479 } 480 481 /// \brief Set the supply values of the nodes. 482 /// 483 /// This function sets the supply values of the nodes. 484 /// If neither this function nor \ref stSupply() is used before 485 /// calling \ref run(), the supply of each node will be set to zero. 486 /// 487 /// \param map A node map storing the supply values. 488 /// Its \c Value type must be convertible to the \c Value type 489 /// of the algorithm. 490 /// 491 /// \return <tt>(*this)</tt> 492 template<typename SupplyMap> 493 CostScaling& supplyMap(const SupplyMap& map) { 494 for (NodeIt n(_graph); n != INVALID; ++n) { 495 _supply[_node_id[n]] = map[n]; 496 } 497 return *this; 498 } 499 500 /// \brief Set single source and target nodes and a supply value. 501 /// 502 /// This function sets a single source node and a single target node 503 /// and the required flow value. 504 /// If neither this function nor \ref supplyMap() is used before 505 /// calling \ref run(), the supply of each node will be set to zero. 506 /// 507 /// Using this function has the same effect as using \ref supplyMap() 508 /// with such a map in which \c k is assigned to \c s, \c -k is 509 /// assigned to \c t and all other nodes have zero supply value. 510 /// 511 /// \param s The source node. 512 /// \param t The target node. 513 /// \param k The required amount of flow from node \c s to node \c t 514 /// (i.e. the supply of \c s and the demand of \c t). 515 /// 516 /// \return <tt>(*this)</tt> 517 CostScaling& stSupply(const Node& s, const Node& t, Value k) { 518 for (int i = 0; i != _res_node_num; ++i) { 519 _supply[i] = 0; 520 } 521 _supply[_node_id[s]] = k; 522 _supply[_node_id[t]] = -k; 523 return *this; 524 } 525 526 /// @} 527 528 /// \name Execution control 529 /// The algorithm can be executed using \ref run(). 530 531 /// @{ 532 533 /// \brief Run the algorithm. 534 /// 535 /// This function runs the algorithm. 536 /// The paramters can be specified using functions \ref lowerMap(), 537 /// \ref upperMap(), \ref costMap(), \ref supplyMap(), \ref stSupply(). 538 /// For example, 539 /// \code 540 /// CostScaling<ListDigraph> cs(graph); 541 /// cs.lowerMap(lower).upperMap(upper).costMap(cost) 542 /// .supplyMap(sup).run(); 543 /// \endcode 544 /// 545 /// This function can be called more than once. All the parameters 546 /// that have been given are kept for the next call, unless 547 /// \ref reset() is called, thus only the modified parameters 548 /// have to be set again. See \ref reset() for examples. 549 /// However, the underlying digraph must not be modified after this 550 /// class have been constructed, since it copies and extends the graph. 551 /// 552 /// \param method The internal method that will be used in the 553 /// algorithm. For more information, see \ref Method. 554 /// \param factor The cost scaling factor. It must be larger than one. 555 /// 556 /// \return \c INFEASIBLE if no feasible flow exists, 557 /// \n \c OPTIMAL if the problem has optimal solution 558 /// (i.e. it is feasible and bounded), and the algorithm has found 559 /// optimal flow and node potentials (primal and dual solutions), 560 /// \n \c UNBOUNDED if the digraph contains an arc of negative cost 561 /// and infinite upper bound. It means that the objective function 562 /// is unbounded on that arc, however, note that it could actually be 563 /// bounded over the feasible flows, but this algroithm cannot handle 564 /// these cases. 565 /// 566 /// \see ProblemType, Method 567 ProblemType run(Method method = PARTIAL_AUGMENT, int factor = 8) { 568 _alpha = factor; 569 ProblemType pt = init(); 570 if (pt != OPTIMAL) return pt; 571 start(method); 572 return OPTIMAL; 573 } 574 575 /// \brief Reset all the parameters that have been given before. 576 /// 577 /// This function resets all the paramaters that have been given 578 /// before using functions \ref lowerMap(), \ref upperMap(), 579 /// \ref costMap(), \ref supplyMap(), \ref stSupply(). 580 /// 581 /// It is useful for multiple run() calls. If this function is not 582 /// used, all the parameters given before are kept for the next 583 /// \ref run() call. 584 /// However, the underlying digraph must not be modified after this 585 /// class have been constructed, since it copies and extends the graph. 586 /// 587 /// For example, 588 /// \code 589 /// CostScaling<ListDigraph> cs(graph); 590 /// 591 /// // First run 592 /// cs.lowerMap(lower).upperMap(upper).costMap(cost) 593 /// .supplyMap(sup).run(); 594 /// 595 /// // Run again with modified cost map (reset() is not called, 596 /// // so only the cost map have to be set again) 597 /// cost[e] += 100; 598 /// cs.costMap(cost).run(); 599 /// 600 /// // Run again from scratch using reset() 601 /// // (the lower bounds will be set to zero on all arcs) 602 /// cs.reset(); 603 /// cs.upperMap(capacity).costMap(cost) 604 /// .supplyMap(sup).run(); 605 /// \endcode 606 /// 607 /// \return <tt>(*this)</tt> 608 CostScaling& reset() { 609 for (int i = 0; i != _res_node_num; ++i) { 610 _supply[i] = 0; 611 } 612 int limit = _first_out[_root]; 613 for (int j = 0; j != limit; ++j) { 614 _lower[j] = 0; 615 _upper[j] = INF; 616 _scost[j] = _forward[j] ? 1 : -1; 617 } 618 for (int j = limit; j != _res_arc_num; ++j) { 619 _lower[j] = 0; 620 _upper[j] = INF; 621 _scost[j] = 0; 622 _scost[_reverse[j]] = 0; 623 } 624 _have_lower = false; 650 resetParams(); 625 651 return *this; 626 652 } -
lemon/cycle_canceling.h
r839 r840 252 252 "The cost type of CycleCanceling must be signed"); 253 253 254 // Reset data structures 255 reset(); 256 } 257 258 /// \name Parameters 259 /// The parameters of the algorithm can be specified using these 260 /// functions. 261 262 /// @{ 263 264 /// \brief Set the lower bounds on the arcs. 265 /// 266 /// This function sets the lower bounds on the arcs. 267 /// If it is not used before calling \ref run(), the lower bounds 268 /// will be set to zero on all arcs. 269 /// 270 /// \param map An arc map storing the lower bounds. 271 /// Its \c Value type must be convertible to the \c Value type 272 /// of the algorithm. 273 /// 274 /// \return <tt>(*this)</tt> 275 template <typename LowerMap> 276 CycleCanceling& lowerMap(const LowerMap& map) { 277 _have_lower = true; 278 for (ArcIt a(_graph); a != INVALID; ++a) { 279 _lower[_arc_idf[a]] = map[a]; 280 _lower[_arc_idb[a]] = map[a]; 281 } 282 return *this; 283 } 284 285 /// \brief Set the upper bounds (capacities) on the arcs. 286 /// 287 /// This function sets the upper bounds (capacities) on the arcs. 288 /// If it is not used before calling \ref run(), the upper bounds 289 /// will be set to \ref INF on all arcs (i.e. the flow value will be 290 /// unbounded from above). 291 /// 292 /// \param map An arc map storing the upper bounds. 293 /// Its \c Value type must be convertible to the \c Value type 294 /// of the algorithm. 295 /// 296 /// \return <tt>(*this)</tt> 297 template<typename UpperMap> 298 CycleCanceling& upperMap(const UpperMap& map) { 299 for (ArcIt a(_graph); a != INVALID; ++a) { 300 _upper[_arc_idf[a]] = map[a]; 301 } 302 return *this; 303 } 304 305 /// \brief Set the costs of the arcs. 306 /// 307 /// This function sets the costs of the arcs. 308 /// If it is not used before calling \ref run(), the costs 309 /// will be set to \c 1 on all arcs. 310 /// 311 /// \param map An arc map storing the costs. 312 /// Its \c Value type must be convertible to the \c Cost type 313 /// of the algorithm. 314 /// 315 /// \return <tt>(*this)</tt> 316 template<typename CostMap> 317 CycleCanceling& costMap(const CostMap& map) { 318 for (ArcIt a(_graph); a != INVALID; ++a) { 319 _cost[_arc_idf[a]] = map[a]; 320 _cost[_arc_idb[a]] = -map[a]; 321 } 322 return *this; 323 } 324 325 /// \brief Set the supply values of the nodes. 326 /// 327 /// This function sets the supply values of the nodes. 328 /// If neither this function nor \ref stSupply() is used before 329 /// calling \ref run(), the supply of each node will be set to zero. 330 /// 331 /// \param map A node map storing the supply values. 332 /// Its \c Value type must be convertible to the \c Value type 333 /// of the algorithm. 334 /// 335 /// \return <tt>(*this)</tt> 336 template<typename SupplyMap> 337 CycleCanceling& supplyMap(const SupplyMap& map) { 338 for (NodeIt n(_graph); n != INVALID; ++n) { 339 _supply[_node_id[n]] = map[n]; 340 } 341 return *this; 342 } 343 344 /// \brief Set single source and target nodes and a supply value. 345 /// 346 /// This function sets a single source node and a single target node 347 /// and the required flow value. 348 /// If neither this function nor \ref supplyMap() is used before 349 /// calling \ref run(), the supply of each node will be set to zero. 350 /// 351 /// Using this function has the same effect as using \ref supplyMap() 352 /// with such a map in which \c k is assigned to \c s, \c -k is 353 /// assigned to \c t and all other nodes have zero supply value. 354 /// 355 /// \param s The source node. 356 /// \param t The target node. 357 /// \param k The required amount of flow from node \c s to node \c t 358 /// (i.e. the supply of \c s and the demand of \c t). 359 /// 360 /// \return <tt>(*this)</tt> 361 CycleCanceling& stSupply(const Node& s, const Node& t, Value k) { 362 for (int i = 0; i != _res_node_num; ++i) { 363 _supply[i] = 0; 364 } 365 _supply[_node_id[s]] = k; 366 _supply[_node_id[t]] = -k; 367 return *this; 368 } 369 370 /// @} 371 372 /// \name Execution control 373 /// The algorithm can be executed using \ref run(). 374 375 /// @{ 376 377 /// \brief Run the algorithm. 378 /// 379 /// This function runs the algorithm. 380 /// The paramters can be specified using functions \ref lowerMap(), 381 /// \ref upperMap(), \ref costMap(), \ref supplyMap(), \ref stSupply(). 382 /// For example, 383 /// \code 384 /// CycleCanceling<ListDigraph> cc(graph); 385 /// cc.lowerMap(lower).upperMap(upper).costMap(cost) 386 /// .supplyMap(sup).run(); 387 /// \endcode 388 /// 389 /// This function can be called more than once. All the given parameters 390 /// are kept for the next call, unless \ref resetParams() or \ref reset() 391 /// is used, thus only the modified parameters have to be set again. 392 /// If the underlying digraph was also modified after the construction 393 /// of the class (or the last \ref reset() call), then the \ref reset() 394 /// function must be called. 395 /// 396 /// \param method The cycle-canceling method that will be used. 397 /// For more information, see \ref Method. 398 /// 399 /// \return \c INFEASIBLE if no feasible flow exists, 400 /// \n \c OPTIMAL if the problem has optimal solution 401 /// (i.e. it is feasible and bounded), and the algorithm has found 402 /// optimal flow and node potentials (primal and dual solutions), 403 /// \n \c UNBOUNDED if the digraph contains an arc of negative cost 404 /// and infinite upper bound. It means that the objective function 405 /// is unbounded on that arc, however, note that it could actually be 406 /// bounded over the feasible flows, but this algroithm cannot handle 407 /// these cases. 408 /// 409 /// \see ProblemType, Method 410 /// \see resetParams(), reset() 411 ProblemType run(Method method = CANCEL_AND_TIGHTEN) { 412 ProblemType pt = init(); 413 if (pt != OPTIMAL) return pt; 414 start(method); 415 return OPTIMAL; 416 } 417 418 /// \brief Reset all the parameters that have been given before. 419 /// 420 /// This function resets all the paramaters that have been given 421 /// before using functions \ref lowerMap(), \ref upperMap(), 422 /// \ref costMap(), \ref supplyMap(), \ref stSupply(). 423 /// 424 /// It is useful for multiple \ref run() calls. Basically, all the given 425 /// parameters are kept for the next \ref run() call, unless 426 /// \ref resetParams() or \ref reset() is used. 427 /// If the underlying digraph was also modified after the construction 428 /// of the class or the last \ref reset() call, then the \ref reset() 429 /// function must be used, otherwise \ref resetParams() is sufficient. 430 /// 431 /// For example, 432 /// \code 433 /// CycleCanceling<ListDigraph> cs(graph); 434 /// 435 /// // First run 436 /// cc.lowerMap(lower).upperMap(upper).costMap(cost) 437 /// .supplyMap(sup).run(); 438 /// 439 /// // Run again with modified cost map (resetParams() is not called, 440 /// // so only the cost map have to be set again) 441 /// cost[e] += 100; 442 /// cc.costMap(cost).run(); 443 /// 444 /// // Run again from scratch using resetParams() 445 /// // (the lower bounds will be set to zero on all arcs) 446 /// cc.resetParams(); 447 /// cc.upperMap(capacity).costMap(cost) 448 /// .supplyMap(sup).run(); 449 /// \endcode 450 /// 451 /// \return <tt>(*this)</tt> 452 /// 453 /// \see reset(), run() 454 CycleCanceling& resetParams() { 455 for (int i = 0; i != _res_node_num; ++i) { 456 _supply[i] = 0; 457 } 458 int limit = _first_out[_root]; 459 for (int j = 0; j != limit; ++j) { 460 _lower[j] = 0; 461 _upper[j] = INF; 462 _cost[j] = _forward[j] ? 1 : -1; 463 } 464 for (int j = limit; j != _res_arc_num; ++j) { 465 _lower[j] = 0; 466 _upper[j] = INF; 467 _cost[j] = 0; 468 _cost[_reverse[j]] = 0; 469 } 470 _have_lower = false; 471 return *this; 472 } 473 474 /// \brief Reset the internal data structures and all the parameters 475 /// that have been given before. 476 /// 477 /// This function resets the internal data structures and all the 478 /// paramaters that have been given before using functions \ref lowerMap(), 479 /// \ref upperMap(), \ref costMap(), \ref supplyMap(), \ref stSupply(). 480 /// 481 /// It is useful for multiple \ref run() calls. Basically, all the given 482 /// parameters are kept for the next \ref run() call, unless 483 /// \ref resetParams() or \ref reset() is used. 484 /// If the underlying digraph was also modified after the construction 485 /// of the class or the last \ref reset() call, then the \ref reset() 486 /// function must be used, otherwise \ref resetParams() is sufficient. 487 /// 488 /// See \ref resetParams() for examples. 489 /// 490 /// \return <tt>(*this)</tt> 491 /// 492 /// \see resetParams(), run() 493 CycleCanceling& reset() { 254 494 // Resize vectors 255 495 _node_num = countNodes(_graph); … … 317 557 318 558 // Reset parameters 319 reset(); 320 } 321 322 /// \name Parameters 323 /// The parameters of the algorithm can be specified using these 324 /// functions. 325 326 /// @{ 327 328 /// \brief Set the lower bounds on the arcs. 329 /// 330 /// This function sets the lower bounds on the arcs. 331 /// If it is not used before calling \ref run(), the lower bounds 332 /// will be set to zero on all arcs. 333 /// 334 /// \param map An arc map storing the lower bounds. 335 /// Its \c Value type must be convertible to the \c Value type 336 /// of the algorithm. 337 /// 338 /// \return <tt>(*this)</tt> 339 template <typename LowerMap> 340 CycleCanceling& lowerMap(const LowerMap& map) { 341 _have_lower = true; 342 for (ArcIt a(_graph); a != INVALID; ++a) { 343 _lower[_arc_idf[a]] = map[a]; 344 _lower[_arc_idb[a]] = map[a]; 345 } 346 return *this; 347 } 348 349 /// \brief Set the upper bounds (capacities) on the arcs. 350 /// 351 /// This function sets the upper bounds (capacities) on the arcs. 352 /// If it is not used before calling \ref run(), the upper bounds 353 /// will be set to \ref INF on all arcs (i.e. the flow value will be 354 /// unbounded from above). 355 /// 356 /// \param map An arc map storing the upper bounds. 357 /// Its \c Value type must be convertible to the \c Value type 358 /// of the algorithm. 359 /// 360 /// \return <tt>(*this)</tt> 361 template<typename UpperMap> 362 CycleCanceling& upperMap(const UpperMap& map) { 363 for (ArcIt a(_graph); a != INVALID; ++a) { 364 _upper[_arc_idf[a]] = map[a]; 365 } 366 return *this; 367 } 368 369 /// \brief Set the costs of the arcs. 370 /// 371 /// This function sets the costs of the arcs. 372 /// If it is not used before calling \ref run(), the costs 373 /// will be set to \c 1 on all arcs. 374 /// 375 /// \param map An arc map storing the costs. 376 /// Its \c Value type must be convertible to the \c Cost type 377 /// of the algorithm. 378 /// 379 /// \return <tt>(*this)</tt> 380 template<typename CostMap> 381 CycleCanceling& costMap(const CostMap& map) { 382 for (ArcIt a(_graph); a != INVALID; ++a) { 383 _cost[_arc_idf[a]] = map[a]; 384 _cost[_arc_idb[a]] = -map[a]; 385 } 386 return *this; 387 } 388 389 /// \brief Set the supply values of the nodes. 390 /// 391 /// This function sets the supply values of the nodes. 392 /// If neither this function nor \ref stSupply() is used before 393 /// calling \ref run(), the supply of each node will be set to zero. 394 /// 395 /// \param map A node map storing the supply values. 396 /// Its \c Value type must be convertible to the \c Value type 397 /// of the algorithm. 398 /// 399 /// \return <tt>(*this)</tt> 400 template<typename SupplyMap> 401 CycleCanceling& supplyMap(const SupplyMap& map) { 402 for (NodeIt n(_graph); n != INVALID; ++n) { 403 _supply[_node_id[n]] = map[n]; 404 } 405 return *this; 406 } 407 408 /// \brief Set single source and target nodes and a supply value. 409 /// 410 /// This function sets a single source node and a single target node 411 /// and the required flow value. 412 /// If neither this function nor \ref supplyMap() is used before 413 /// calling \ref run(), the supply of each node will be set to zero. 414 /// 415 /// Using this function has the same effect as using \ref supplyMap() 416 /// with such a map in which \c k is assigned to \c s, \c -k is 417 /// assigned to \c t and all other nodes have zero supply value. 418 /// 419 /// \param s The source node. 420 /// \param t The target node. 421 /// \param k The required amount of flow from node \c s to node \c t 422 /// (i.e. the supply of \c s and the demand of \c t). 423 /// 424 /// \return <tt>(*this)</tt> 425 CycleCanceling& stSupply(const Node& s, const Node& t, Value k) { 426 for (int i = 0; i != _res_node_num; ++i) { 427 _supply[i] = 0; 428 } 429 _supply[_node_id[s]] = k; 430 _supply[_node_id[t]] = -k; 431 return *this; 432 } 433 434 /// @} 435 436 /// \name Execution control 437 /// The algorithm can be executed using \ref run(). 438 439 /// @{ 440 441 /// \brief Run the algorithm. 442 /// 443 /// This function runs the algorithm. 444 /// The paramters can be specified using functions \ref lowerMap(), 445 /// \ref upperMap(), \ref costMap(), \ref supplyMap(), \ref stSupply(). 446 /// For example, 447 /// \code 448 /// CycleCanceling<ListDigraph> cc(graph); 449 /// cc.lowerMap(lower).upperMap(upper).costMap(cost) 450 /// .supplyMap(sup).run(); 451 /// \endcode 452 /// 453 /// This function can be called more than once. All the parameters 454 /// that have been given are kept for the next call, unless 455 /// \ref reset() is called, thus only the modified parameters 456 /// have to be set again. See \ref reset() for examples. 457 /// However, the underlying digraph must not be modified after this 458 /// class have been constructed, since it copies and extends the graph. 459 /// 460 /// \param method The cycle-canceling method that will be used. 461 /// For more information, see \ref Method. 462 /// 463 /// \return \c INFEASIBLE if no feasible flow exists, 464 /// \n \c OPTIMAL if the problem has optimal solution 465 /// (i.e. it is feasible and bounded), and the algorithm has found 466 /// optimal flow and node potentials (primal and dual solutions), 467 /// \n \c UNBOUNDED if the digraph contains an arc of negative cost 468 /// and infinite upper bound. It means that the objective function 469 /// is unbounded on that arc, however, note that it could actually be 470 /// bounded over the feasible flows, but this algroithm cannot handle 471 /// these cases. 472 /// 473 /// \see ProblemType, Method 474 ProblemType run(Method method = CANCEL_AND_TIGHTEN) { 475 ProblemType pt = init(); 476 if (pt != OPTIMAL) return pt; 477 start(method); 478 return OPTIMAL; 479 } 480 481 /// \brief Reset all the parameters that have been given before. 482 /// 483 /// This function resets all the paramaters that have been given 484 /// before using functions \ref lowerMap(), \ref upperMap(), 485 /// \ref costMap(), \ref supplyMap(), \ref stSupply(). 486 /// 487 /// It is useful for multiple run() calls. If this function is not 488 /// used, all the parameters given before are kept for the next 489 /// \ref run() call. 490 /// However, the underlying digraph must not be modified after this 491 /// class have been constructed, since it copies and extends the graph. 492 /// 493 /// For example, 494 /// \code 495 /// CycleCanceling<ListDigraph> cs(graph); 496 /// 497 /// // First run 498 /// cc.lowerMap(lower).upperMap(upper).costMap(cost) 499 /// .supplyMap(sup).run(); 500 /// 501 /// // Run again with modified cost map (reset() is not called, 502 /// // so only the cost map have to be set again) 503 /// cost[e] += 100; 504 /// cc.costMap(cost).run(); 505 /// 506 /// // Run again from scratch using reset() 507 /// // (the lower bounds will be set to zero on all arcs) 508 /// cc.reset(); 509 /// cc.upperMap(capacity).costMap(cost) 510 /// .supplyMap(sup).run(); 511 /// \endcode 512 /// 513 /// \return <tt>(*this)</tt> 514 CycleCanceling& reset() { 515 for (int i = 0; i != _res_node_num; ++i) { 516 _supply[i] = 0; 517 } 518 int limit = _first_out[_root]; 519 for (int j = 0; j != limit; ++j) { 520 _lower[j] = 0; 521 _upper[j] = INF; 522 _cost[j] = _forward[j] ? 1 : -1; 523 } 524 for (int j = limit; j != _res_arc_num; ++j) { 525 _lower[j] = 0; 526 _upper[j] = INF; 527 _cost[j] = 0; 528 _cost[_reverse[j]] = 0; 529 } 530 _have_lower = false; 559 resetParams(); 531 560 return *this; 532 561 } -
lemon/dfs.h
r788 r825 122 122 ///\tparam GR The type of the digraph the algorithm runs on. 123 123 ///The default type is \ref ListDigraph. 124 ///\tparam TR The traits class that defines various types used by the 125 ///algorithm. By default, it is \ref DfsDefaultTraits 126 ///"DfsDefaultTraits<GR>". 127 ///In most cases, this parameter should not be set directly, 128 ///consider to use the named template parameters instead. 124 129 #ifdef DOXYGEN 125 130 template <typename GR, … … 888 893 /// This class should only be used through the \ref dfs() function, 889 894 /// which makes it easier to use the algorithm. 895 /// 896 /// \tparam TR The traits class that defines various types used by the 897 /// algorithm. 890 898 template<class TR> 891 899 class DfsWizard : public TR … … 1238 1246 /// does not observe the DFS events. If you want to observe the DFS 1239 1247 /// events, you should implement your own visitor class. 1240 /// \tparam TR T raits class to set various datatypes used by the1241 /// algorithm. The default traits class is1242 /// \ref DfsVisitDefaultTraits"DfsVisitDefaultTraits<GR>".1243 /// See \ref DfsVisitDefaultTraits for the documentation of1244 /// a DFS visit traits class.1248 /// \tparam TR The traits class that defines various types used by the 1249 /// algorithm. By default, it is \ref DfsVisitDefaultTraits 1250 /// "DfsVisitDefaultTraits<GR>". 1251 /// In most cases, this parameter should not be set directly, 1252 /// consider to use the named template parameters instead. 1245 1253 #ifdef DOXYGEN 1246 1254 template <typename GR, typename VS, typename TR> -
lemon/dijkstra.h
r788 r825 193 193 ///it is necessary. The default map type is \ref 194 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. 195 200 #ifdef DOXYGEN 196 201 template <typename GR, typename LEN, typename TR> … … 1093 1098 /// This class should only be used through the \ref dijkstra() function, 1094 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. 1095 1103 template<class TR> 1096 1104 class DijkstraWizard : public TR -
lemon/glpk.h
r746 r833 26 26 #include <lemon/lp_base.h> 27 27 28 // forward declaration29 #if !defined _GLP_PROB && !defined GLP_PROB30 #define _GLP_PROB31 #define GLP_PROB32 typedef struct { double _opaque_prob; } glp_prob;33 /* LP/MIP problem object */34 #endif35 36 28 namespace lemon { 37 29 30 namespace _solver_bits { 31 class VoidPtr { 32 private: 33 void *_ptr; 34 public: 35 VoidPtr() : _ptr(0) {} 36 37 template <typename T> 38 VoidPtr(T* ptr) : _ptr(reinterpret_cast<void*>(ptr)) {} 39 40 template <typename T> 41 VoidPtr& operator=(T* ptr) { 42 _ptr = reinterpret_cast<void*>(ptr); 43 return *this; 44 } 45 46 template <typename T> 47 operator T*() const { return reinterpret_cast<T*>(_ptr); } 48 }; 49 } 38 50 39 51 /// \brief Base interface for the GLPK LP and MIP solver … … 44 56 protected: 45 57 46 typedef glp_prob LPX; 47 glp_prob* lp; 58 _solver_bits::VoidPtr lp; 48 59 49 60 GlpkBase(); … … 124 135 125 136 ///Pointer to the underlying GLPK data structure. 126 LPX *lpx() {return lp;}137 _solver_bits::VoidPtr lpx() {return lp;} 127 138 ///Const pointer to the underlying GLPK data structure. 128 const LPX *lpx() const {return lp;}139 _solver_bits::VoidPtr lpx() const {return lp;} 129 140 130 141 ///Returns the constraint identifier understood by GLPK. -
lemon/graph_to_eps.h
r786 r838 685 685 #else 686 686 os << bits::getWinFormattedDate(); 687 os << std::endl; 687 688 #endif 688 689 } 689 os << std::endl;690 690 691 691 if (_autoArcWidthScale) { -
lemon/hartmann_orlin.h
r795 r825 107 107 /// \tparam LEN The type of the length map. The default 108 108 /// map type is \ref concepts::Digraph::ArcMap "GR::ArcMap<int>". 109 /// \tparam TR The traits class that defines various types used by the 110 /// algorithm. By default, it is \ref HartmannOrlinDefaultTraits 111 /// "HartmannOrlinDefaultTraits<GR, LEN>". 112 /// In most cases, this parameter should not be set directly, 113 /// consider to use the named template parameters instead. 109 114 #ifdef DOXYGEN 110 115 template <typename GR, typename LEN, typename TR> … … 128 133 /// 129 134 /// The large value type used for internal computations. 130 /// Using the \ref HartmannOrlinDefaultTraits "default traits class", 131 /// it is \c long \c long if the \c Value type is integer, 135 /// By default, it is \c long \c long if the \c Value type is integer, 132 136 /// otherwise it is \c double. 133 137 typedef typename TR::LargeValue LargeValue; -
lemon/howard.h
r771 r825 107 107 /// \tparam LEN The type of the length map. The default 108 108 /// map type is \ref concepts::Digraph::ArcMap "GR::ArcMap<int>". 109 /// \tparam TR The traits class that defines various types used by the 110 /// algorithm. By default, it is \ref HowardDefaultTraits 111 /// "HowardDefaultTraits<GR, LEN>". 112 /// In most cases, this parameter should not be set directly, 113 /// consider to use the named template parameters instead. 109 114 #ifdef DOXYGEN 110 115 template <typename GR, typename LEN, typename TR> … … 128 133 /// 129 134 /// The large value type used for internal computations. 130 /// Using the \ref HowardDefaultTraits "default traits class", 131 /// it is \c long \c long if the \c Value type is integer, 135 /// By default, it is \c long \c long if the \c Value type is integer, 132 136 /// otherwise it is \c double. 133 137 typedef typename TR::LargeValue LargeValue; -
lemon/karp.h
r772 r825 105 105 /// \tparam LEN The type of the length map. The default 106 106 /// map type is \ref concepts::Digraph::ArcMap "GR::ArcMap<int>". 107 /// \tparam TR The traits class that defines various types used by the 108 /// algorithm. By default, it is \ref KarpDefaultTraits 109 /// "KarpDefaultTraits<GR, LEN>". 110 /// In most cases, this parameter should not be set directly, 111 /// consider to use the named template parameters instead. 107 112 #ifdef DOXYGEN 108 113 template <typename GR, typename LEN, typename TR> … … 126 131 /// 127 132 /// The large value type used for internal computations. 128 /// Using the \ref KarpDefaultTraits "default traits class", 129 /// it is \c long \c long if the \c Value type is integer, 133 /// By default, it is \c long \c long if the \c Value type is integer, 130 134 /// otherwise it is \c double. 131 135 typedef typename TR::LargeValue LargeValue; -
lemon/lp_base.h
r786 r834 1230 1230 Row r; 1231 1231 c.expr().simplify(); 1232 r._id = _addRowId(_addRow(c.lowerBounded()?c.lowerBound() :-INF,1232 r._id = _addRowId(_addRow(c.lowerBounded()?c.lowerBound()-*c.expr():-INF, 1233 1233 ExprIterator(c.expr().comps.begin(), cols), 1234 1234 ExprIterator(c.expr().comps.end(), cols), 1235 c.upperBounded()?c.upperBound() :INF));1235 c.upperBounded()?c.upperBound()-*c.expr():INF)); 1236 1236 return r; 1237 1237 } -
lemon/min_cost_arborescence.h
r713 r825 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 { -
lemon/network_simplex.h
r839 r840 196 196 IntVector _source; 197 197 IntVector _target; 198 bool _arc_mixing; 198 199 199 200 // Node and arc data … … 635 636 NetworkSimplex(const GR& graph, bool arc_mixing = false) : 636 637 _graph(graph), _node_id(graph), _arc_id(graph), 638 _arc_mixing(arc_mixing), 637 639 MAX(std::numeric_limits<Value>::max()), 638 640 INF(std::numeric_limits<Value>::has_infinity ? … … 645 647 "The cost type of NetworkSimplex must be signed"); 646 648 647 // Resize vectors 648 _node_num = countNodes(_graph); 649 _arc_num = countArcs(_graph); 650 int all_node_num = _node_num + 1; 651 int max_arc_num = _arc_num + 2 * _node_num; 652 653 _source.resize(max_arc_num); 654 _target.resize(max_arc_num); 655 656 _lower.resize(_arc_num); 657 _upper.resize(_arc_num); 658 _cap.resize(max_arc_num); 659 _cost.resize(max_arc_num); 660 _supply.resize(all_node_num); 661 _flow.resize(max_arc_num); 662 _pi.resize(all_node_num); 663 664 _parent.resize(all_node_num); 665 _pred.resize(all_node_num); 666 _forward.resize(all_node_num); 667 _thread.resize(all_node_num); 668 _rev_thread.resize(all_node_num); 669 _succ_num.resize(all_node_num); 670 _last_succ.resize(all_node_num); 671 _state.resize(max_arc_num); 672 673 // Copy the graph 674 int i = 0; 675 for (NodeIt n(_graph); n != INVALID; ++n, ++i) { 676 _node_id[n] = i; 677 } 678 if (arc_mixing) { 679 // Store the arcs in a mixed order 680 int k = std::max(int(std::sqrt(double(_arc_num))), 10); 681 int i = 0, j = 0; 682 for (ArcIt a(_graph); a != INVALID; ++a) { 683 _arc_id[a] = i; 684 _source[i] = _node_id[_graph.source(a)]; 685 _target[i] = _node_id[_graph.target(a)]; 686 if ((i += k) >= _arc_num) i = ++j; 687 } 688 } else { 689 // Store the arcs in the original order 690 int i = 0; 691 for (ArcIt a(_graph); a != INVALID; ++a, ++i) { 692 _arc_id[a] = i; 693 _source[i] = _node_id[_graph.source(a)]; 694 _target[i] = _node_id[_graph.target(a)]; 695 } 696 } 697 698 // Reset parameters 649 // Reset data structures 699 650 reset(); 700 651 } … … 844 795 /// \endcode 845 796 /// 846 /// This function can be called more than once. All the parameters847 /// that have been given are kept for the next call, unless848 /// \ref reset() is called, thus only the modified parameters849 /// have to be set again. See \ref reset() for examples.850 /// However, the underlying digraph must not be modified after this851 /// class have been constructed, since it copies and extends the graph.797 /// This function can be called more than once. All the given parameters 798 /// are kept for the next call, unless \ref resetParams() or \ref reset() 799 /// is used, thus only the modified parameters have to be set again. 800 /// If the underlying digraph was also modified after the construction 801 /// of the class (or the last \ref reset() call), then the \ref reset() 802 /// function must be called. 852 803 /// 853 804 /// \param pivot_rule The pivot rule that will be used during the … … 863 814 /// 864 815 /// \see ProblemType, PivotRule 816 /// \see resetParams(), reset() 865 817 ProblemType run(PivotRule pivot_rule = BLOCK_SEARCH) { 866 818 if (!init()) return INFEASIBLE; … … 874 826 /// \ref costMap(), \ref supplyMap(), \ref stSupply(), \ref supplyType(). 875 827 /// 876 /// It is useful for multiple run() calls. If this function is not 877 /// used, all the parameters given before are kept for the next 878 /// \ref run() call. 879 /// However, the underlying digraph must not be modified after this 880 /// class have been constructed, since it copies and extends the graph. 828 /// It is useful for multiple \ref run() calls. Basically, all the given 829 /// parameters are kept for the next \ref run() call, unless 830 /// \ref resetParams() or \ref reset() is used. 831 /// If the underlying digraph was also modified after the construction 832 /// of the class or the last \ref reset() call, then the \ref reset() 833 /// function must be used, otherwise \ref resetParams() is sufficient. 881 834 /// 882 835 /// For example, … … 888 841 /// .supplyMap(sup).run(); 889 842 /// 890 /// // Run again with modified cost map (reset () is not called,843 /// // Run again with modified cost map (resetParams() is not called, 891 844 /// // so only the cost map have to be set again) 892 845 /// cost[e] += 100; 893 846 /// ns.costMap(cost).run(); 894 847 /// 895 /// // Run again from scratch using reset ()848 /// // Run again from scratch using resetParams() 896 849 /// // (the lower bounds will be set to zero on all arcs) 897 /// ns.reset ();850 /// ns.resetParams(); 898 851 /// ns.upperMap(capacity).costMap(cost) 899 852 /// .supplyMap(sup).run(); … … 901 854 /// 902 855 /// \return <tt>(*this)</tt> 903 NetworkSimplex& reset() { 856 /// 857 /// \see reset(), run() 858 NetworkSimplex& resetParams() { 904 859 for (int i = 0; i != _node_num; ++i) { 905 860 _supply[i] = 0; … … 915 870 } 916 871 872 /// \brief Reset the internal data structures and all the parameters 873 /// that have been given before. 874 /// 875 /// This function resets the internal data structures and all the 876 /// paramaters that have been given before using functions \ref lowerMap(), 877 /// \ref upperMap(), \ref costMap(), \ref supplyMap(), \ref stSupply(), 878 /// \ref supplyType(). 879 /// 880 /// It is useful for multiple \ref run() calls. Basically, all the given 881 /// parameters are kept for the next \ref run() call, unless 882 /// \ref resetParams() or \ref reset() is used. 883 /// If the underlying digraph was also modified after the construction 884 /// of the class or the last \ref reset() call, then the \ref reset() 885 /// function must be used, otherwise \ref resetParams() is sufficient. 886 /// 887 /// See \ref resetParams() for examples. 888 /// 889 /// \return <tt>(*this)</tt> 890 /// 891 /// \see resetParams(), run() 892 NetworkSimplex& reset() { 893 // Resize vectors 894 _node_num = countNodes(_graph); 895 _arc_num = countArcs(_graph); 896 int all_node_num = _node_num + 1; 897 int max_arc_num = _arc_num + 2 * _node_num; 898 899 _source.resize(max_arc_num); 900 _target.resize(max_arc_num); 901 902 _lower.resize(_arc_num); 903 _upper.resize(_arc_num); 904 _cap.resize(max_arc_num); 905 _cost.resize(max_arc_num); 906 _supply.resize(all_node_num); 907 _flow.resize(max_arc_num); 908 _pi.resize(all_node_num); 909 910 _parent.resize(all_node_num); 911 _pred.resize(all_node_num); 912 _forward.resize(all_node_num); 913 _thread.resize(all_node_num); 914 _rev_thread.resize(all_node_num); 915 _succ_num.resize(all_node_num); 916 _last_succ.resize(all_node_num); 917 _state.resize(max_arc_num); 918 919 // Copy the graph 920 int i = 0; 921 for (NodeIt n(_graph); n != INVALID; ++n, ++i) { 922 _node_id[n] = i; 923 } 924 if (_arc_mixing) { 925 // Store the arcs in a mixed order 926 int k = std::max(int(std::sqrt(double(_arc_num))), 10); 927 int i = 0, j = 0; 928 for (ArcIt a(_graph); a != INVALID; ++a) { 929 _arc_id[a] = i; 930 _source[i] = _node_id[_graph.source(a)]; 931 _target[i] = _node_id[_graph.target(a)]; 932 if ((i += k) >= _arc_num) i = ++j; 933 } 934 } else { 935 // Store the arcs in the original order 936 int i = 0; 937 for (ArcIt a(_graph); a != INVALID; ++a, ++i) { 938 _arc_id[a] = i; 939 _source[i] = _node_id[_graph.source(a)]; 940 _target[i] = _node_id[_graph.target(a)]; 941 } 942 } 943 944 // Reset parameters 945 resetParams(); 946 return *this; 947 } 948 917 949 /// @} 918 950 -
lemon/planarity.h
r798 r828 519 519 /// 520 520 /// This function implements the Boyer-Myrvold algorithm for 521 /// planarity checking of an undirected graph. It is a simplified521 /// planarity checking of an undirected simple graph. It is a simplified 522 522 /// version of the PlanarEmbedding algorithm class because neither 523 /// the embedding nor the kuratowski subdivisons are notcomputed.523 /// the embedding nor the Kuratowski subdivisons are computed. 524 524 template <typename GR> 525 525 bool checkPlanarity(const GR& graph) { … … 533 533 /// 534 534 /// This class implements the Boyer-Myrvold algorithm for planar 535 /// embedding of an undirected graph. The planar embedding is an535 /// embedding of an undirected simple graph. The planar embedding is an 536 536 /// ordering of the outgoing edges of the nodes, which is a possible 537 537 /// configuration to draw the graph in the plane. If there is not 538 /// such ordering then the graph contains a \f$ K_5 \f$(full graph539 /// with 5 nodes) or a \f$ K_{3,3} \f$(complete bipartite graph on540 /// 3 ANode and 3 BNode) subdivision.538 /// such ordering then the graph contains a K<sub>5</sub> (full graph 539 /// with 5 nodes) or a K<sub>3,3</sub> (complete bipartite graph on 540 /// 3 Red and 3 Blue nodes) subdivision. 541 541 /// 542 542 /// The current implementation calculates either an embedding or a 543 /// Kuratowski subdivision. The running time of the algorithm is 544 /// \f$ O(n) \f$. 543 /// Kuratowski subdivision. The running time of the algorithm is O(n). 544 /// 545 /// \see PlanarDrawing, checkPlanarity() 545 546 template <typename Graph> 546 547 class PlanarEmbedding { … … 592 593 public: 593 594 594 /// \brief The map for store of embedding 595 /// \brief The map type for storing the embedding 596 /// 597 /// The map type for storing the embedding. 598 /// \see embeddingMap() 595 599 typedef typename Graph::template ArcMap<Arc> EmbeddingMap; 596 600 597 601 /// \brief Constructor 598 602 /// 599 /// \note The graph should be simple, i.e. parallel and loop arc 600 /// free. 603 /// Constructor. 604 /// \pre The graph must be simple, i.e. it should not 605 /// contain parallel or loop arcs. 601 606 PlanarEmbedding(const Graph& graph) 602 607 : _graph(graph), _embedding(_graph), _kuratowski(graph, false) {} 603 608 604 /// \brief Run sthe algorithm.609 /// \brief Run the algorithm. 605 610 /// 606 /// Runs the algorithm.607 /// \param kuratowski If th e parameter isfalse, then the611 /// This function runs the algorithm. 612 /// \param kuratowski If this parameter is set to \c false, then the 608 613 /// algorithm does not compute a Kuratowski subdivision. 609 /// \return %True whenthe graph is planar.614 /// \return \c true if the graph is planar. 610 615 bool run(bool kuratowski = true) { 611 616 typedef _planarity_bits::PlanarityVisitor<Graph> Visitor; … … 700 705 } 701 706 702 /// \brief Give sback the successor of an arc707 /// \brief Give back the successor of an arc 703 708 /// 704 /// Gives back the successor of an arc. This functionmakes709 /// This function gives back the successor of an arc. It makes 705 710 /// possible to query the cyclic order of the outgoing arcs from 706 711 /// a node. … … 709 714 } 710 715 711 /// \brief Give sback the calculated embedding map716 /// \brief Give back the calculated embedding map 712 717 /// 713 /// The returned map contains the successor of each arc in the 714 /// graph. 718 /// This function gives back the calculated embedding map, which 719 /// contains the successor of each arc in the cyclic order of the 720 /// outgoing arcs of its source node. 715 721 const EmbeddingMap& embeddingMap() const { 716 722 return _embedding; 717 723 } 718 724 719 /// \brief Give s back true if the undirected arc is in the720 /// kuratowskisubdivision725 /// \brief Give back \c true if the given edge is in the Kuratowski 726 /// subdivision 721 727 /// 722 /// Gives back true if the undirected arc is in the kuratowski 723 /// subdivision 724 /// \note The \c run() had to be called with true value. 725 bool kuratowski(const Edge& edge) { 728 /// This function gives back \c true if the given edge is in the found 729 /// Kuratowski subdivision. 730 /// \pre The \c run() function must be called with \c true parameter 731 /// before using this function. 732 bool kuratowski(const Edge& edge) const { 726 733 return _kuratowski[edge]; 727 734 } … … 2060 2067 /// 2061 2068 /// The planar drawing algorithm calculates positions for the nodes 2062 /// in the plane which coordinates satisfy that if the arcs are2063 /// represented with straight lines then they will not intersect2069 /// in the plane. These coordinates satisfy that if the edges are 2070 /// represented with straight lines, then they will not intersect 2064 2071 /// each other. 2065 2072 /// 2066 /// Scnyder's algorithm embeds the graph on \c (n-2,n-2) size grid,2067 /// i.e. each node will be located in the \c [0 ,n-2]x[0,n-2] square.2073 /// Scnyder's algorithm embeds the graph on an \c (n-2)x(n-2) size grid, 2074 /// i.e. each node will be located in the \c [0..n-2]x[0..n-2] square. 2068 2075 /// The time complexity of the algorithm is O(n). 2076 /// 2077 /// \see PlanarEmbedding 2069 2078 template <typename Graph> 2070 2079 class PlanarDrawing { … … 2073 2082 TEMPLATE_GRAPH_TYPEDEFS(Graph); 2074 2083 2075 /// \brief The point type for stor ecoordinates2084 /// \brief The point type for storing coordinates 2076 2085 typedef dim2::Point<int> Point; 2077 /// \brief The map type for stor e coordinates2086 /// \brief The map type for storing the coordinates of the nodes 2078 2087 typedef typename Graph::template NodeMap<Point> PointMap; 2079 2088 … … 2082 2091 /// 2083 2092 /// Constructor 2084 /// \pre The graph should be simple, i.e. loop and parallel arc free. 2093 /// \pre The graph must be simple, i.e. it should not 2094 /// contain parallel or loop arcs. 2085 2095 PlanarDrawing(const Graph& graph) 2086 2096 : _graph(graph), _point_map(graph) {} … … 2367 2377 public: 2368 2378 2369 /// \brief Calculate sthe node positions2379 /// \brief Calculate the node positions 2370 2380 /// 2371 /// This function calculates the node positions .2372 /// \return %True if the graph is planar.2381 /// This function calculates the node positions on the plane. 2382 /// \return \c true if the graph is planar. 2373 2383 bool run() { 2374 2384 PlanarEmbedding<Graph> pe(_graph); … … 2379 2389 } 2380 2390 2381 /// \brief Calculate sthe node positions according to a2391 /// \brief Calculate the node positions according to a 2382 2392 /// combinatorical embedding 2383 2393 /// 2384 /// This function calculates the node locations. The \c embedding 2385 /// parameter should contain a valid combinatorical embedding, i.e. 2386 /// a valid cyclic order of the arcs. 2394 /// This function calculates the node positions on the plane. 2395 /// The given \c embedding map should contain a valid combinatorical 2396 /// embedding, i.e. a valid cyclic order of the arcs. 2397 /// It can be computed using PlanarEmbedding. 2387 2398 template <typename EmbeddingMap> 2388 2399 void run(const EmbeddingMap& embedding) { … … 2424 2435 /// \brief The coordinate of the given node 2425 2436 /// 2426 /// Th e coordinate of the given node.2437 /// This function returns the coordinate of the given node. 2427 2438 Point operator[](const Node& node) const { 2428 2439 return _point_map[node]; 2429 2440 } 2430 2441 2431 /// \brief Return s the grid embedding in a \e NodeMap.2442 /// \brief Return the grid embedding in a node map 2432 2443 /// 2433 /// Returns the grid embedding in a \e NodeMap of \c dim2::Point<int> . 2444 /// This function returns the grid embedding in a node map of 2445 /// \c dim2::Point<int> coordinates. 2434 2446 const PointMap& coords() const { 2435 2447 return _point_map; … … 2471 2483 /// 2472 2484 /// The graph coloring problem is the coloring of the graph nodes 2473 /// that there are notadjacent nodes with the same color. The2474 /// planar graphs can be always colored with four colors, itis2475 /// proved by Appel and Haken and their proofs provide a quadratic2485 /// so that there are no adjacent nodes with the same color. The 2486 /// planar graphs can always be colored with four colors, which is 2487 /// proved by Appel and Haken. Their proofs provide a quadratic 2476 2488 /// time algorithm for four coloring, but it could not be used to 2477 /// implement efficient algorithm. The five and six coloring can be2478 /// made in linear time, but in this class the five coloring has2489 /// implement an efficient algorithm. The five and six coloring can be 2490 /// made in linear time, but in this class, the five coloring has 2479 2491 /// quadratic worst case time complexity. The two coloring (if 2480 2492 /// possible) is solvable with a graph search algorithm and it is 2481 2493 /// implemented in \ref bipartitePartitions() function in LEMON. To 2482 /// decide whether the planar graph is three colorable is 2483 /// NP-complete. 2494 /// decide whether a planar graph is three colorable is NP-complete. 2484 2495 /// 2485 2496 /// This class contains member functions for calculate colorings 2486 2497 /// with five and six colors. The six coloring algorithm is a simple 2487 2498 /// greedy coloring on the backward minimum outgoing order of nodes. 2488 /// This order can be computed as in each phasethe node with least2489 /// outgoing arcs to unprocessed nodes i s chosen. This order2499 /// This order can be computed by selecting the node with least 2500 /// outgoing arcs to unprocessed nodes in each phase. This order 2490 2501 /// guarantees that when a node is chosen for coloring it has at 2491 2502 /// most five already colored adjacents. The five coloring algorithm … … 2500 2511 TEMPLATE_GRAPH_TYPEDEFS(Graph); 2501 2512 2502 /// \brief The map type for stor e color indexes2513 /// \brief The map type for storing color indices 2503 2514 typedef typename Graph::template NodeMap<int> IndexMap; 2504 /// \brief The map type for store colors 2515 /// \brief The map type for storing colors 2516 /// 2517 /// The map type for storing colors. 2518 /// \see Palette, Color 2505 2519 typedef ComposeMap<Palette, IndexMap> ColorMap; 2506 2520 2507 2521 /// \brief Constructor 2508 2522 /// 2509 /// Constructor 2510 /// \pre The graph should be simple, i.e. loop and parallel arc free. 2523 /// Constructor. 2524 /// \pre The graph must be simple, i.e. it should not 2525 /// contain parallel or loop arcs. 2511 2526 PlanarColoring(const Graph& graph) 2512 2527 : _graph(graph), _color_map(graph), _palette(0) { … … 2519 2534 } 2520 2535 2521 /// \brief Return s the \e NodeMap of color indexes2536 /// \brief Return the node map of color indices 2522 2537 /// 2523 /// Returns the \e NodeMap of color indexes. The values are in the2524 /// range \c [0..4] or \c [0..5] according to the coloring method.2538 /// This function returns the node map of color indices. The values are 2539 /// in the range \c [0..4] or \c [0..5] according to the coloring method. 2525 2540 IndexMap colorIndexMap() const { 2526 2541 return _color_map; 2527 2542 } 2528 2543 2529 /// \brief Return s the \e NodeMap of colors2544 /// \brief Return the node map of colors 2530 2545 /// 2531 /// Returns the \e NodeMap of colors. The values are five or six2532 /// distinct \ref lemon::Color "colors".2546 /// This function returns the node map of colors. The values are among 2547 /// five or six distinct \ref lemon::Color "colors". 2533 2548 ColorMap colorMap() const { 2534 2549 return composeMap(_palette, _color_map); 2535 2550 } 2536 2551 2537 /// \brief Return sthe color index of the node2552 /// \brief Return the color index of the node 2538 2553 /// 2539 /// Returns the color index of the node. The values are in the2540 /// range \c [0..4] or \c [0..5] according to the coloring method.2554 /// This function returns the color index of the given node. The value is 2555 /// in the range \c [0..4] or \c [0..5] according to the coloring method. 2541 2556 int colorIndex(const Node& node) const { 2542 2557 return _color_map[node]; 2543 2558 } 2544 2559 2545 /// \brief Return sthe color of the node2560 /// \brief Return the color of the node 2546 2561 /// 2547 /// Returns the color of the node. The values are five or six2548 /// distinct \ref lemon::Color "colors".2562 /// This function returns the color of the given node. The value is among 2563 /// five or six distinct \ref lemon::Color "colors". 2549 2564 Color color(const Node& node) const { 2550 2565 return _palette[_color_map[node]]; … … 2552 2567 2553 2568 2554 /// \brief Calculate sa coloring with at most six colors2569 /// \brief Calculate a coloring with at most six colors 2555 2570 /// 2556 2571 /// This function calculates a coloring with at most six colors. The time 2557 2572 /// complexity of this variant is linear in the size of the graph. 2558 /// \return %True when the algorithm could color the graph with six color.2559 /// If the algorithm fails, then the graph could not beplanar.2560 /// \note This function can return true if the graph is not2561 /// planar but it can be colored with 6colors.2573 /// \return \c true if the algorithm could color the graph with six colors. 2574 /// If the algorithm fails, then the graph is not planar. 2575 /// \note This function can return \c true if the graph is not 2576 /// planar, but it can be colored with at most six colors. 2562 2577 bool runSixColoring() { 2563 2578 … … 2661 2676 public: 2662 2677 2663 /// \brief Calculate sa coloring with at most five colors2678 /// \brief Calculate a coloring with at most five colors 2664 2679 /// 2665 2680 /// This function calculates a coloring with at most five 2666 2681 /// colors. The worst case time complexity of this variant is 2667 2682 /// quadratic in the size of the graph. 2683 /// \param embedding This map should contain a valid combinatorical 2684 /// embedding, i.e. a valid cyclic order of the arcs. 2685 /// It can be computed using PlanarEmbedding. 2668 2686 template <typename EmbeddingMap> 2669 2687 void runFiveColoring(const EmbeddingMap& embedding) { … … 2712 2730 } 2713 2731 2714 /// \brief Calculate sa coloring with at most five colors2732 /// \brief Calculate a coloring with at most five colors 2715 2733 /// 2716 2734 /// This function calculates a coloring with at most five 2717 2735 /// colors. The worst case time complexity of this variant is 2718 2736 /// quadratic in the size of the graph. 2719 /// \return %True whenthe graph is planar.2737 /// \return \c true if the graph is planar. 2720 2738 bool runFiveColoring() { 2721 2739 PlanarEmbedding<Graph> pe(_graph); -
lemon/preflow.h
r823 r825 120 120 /// \tparam CAP The type of the capacity map. The default map 121 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. 122 127 #ifdef DOXYGEN 123 128 template <typename GR, typename CAP, typename TR> -
scripts/bib2dox.py
r754 r836 1 #! /usr/bin/env /usr/local/Python/bin/python2.11 #! /usr/bin/env python 2 2 """ 3 3 BibTeX to Doxygen converter 4 4 Usage: python bib2dox.py bibfile.bib > bibfile.dox 5 5 6 This file is a part of LEMON, a generic C++ optimization library. 7 8 ********************************************************************** 9 6 10 This code is the modification of the BibTeX to XML converter 7 by Vidar Bronken Gundersen et al. See the original copyright notices below. 11 by Vidar Bronken Gundersen et al. 12 See the original copyright notices below. 8 13 9 14 ********************************************************************** -
test/min_cost_flow_test.cc
r819 r830 158 158 const MCF& const_mcf = mcf; 159 159 160 b = mcf.reset() 160 b = mcf.reset().resetParams() 161 161 .lowerMap(me.lower) 162 162 .upperMap(me.upper) … … 347 347 checkMcf(mcf1, mcf1.run(param), gr, l2, u, c, s2, 348 348 mcf1.OPTIMAL, true, 8010, test_str + "-4"); 349 mcf1.reset ().supplyMap(s1);349 mcf1.resetParams().supplyMap(s1); 350 350 checkMcf(mcf1, mcf1.run(param), gr, l1, cu, cc, s1, 351 351 mcf1.OPTIMAL, true, 74, test_str + "-5"); … … 364 364 365 365 // Tests for the GEQ form 366 mcf1.reset ().upperMap(u).costMap(c).supplyMap(s5);366 mcf1.resetParams().upperMap(u).costMap(c).supplyMap(s5); 367 367 checkMcf(mcf1, mcf1.run(param), gr, l1, u, c, s5, 368 368 mcf1.OPTIMAL, true, 3530, test_str + "-10", GEQ); … … 381 381 checkMcf(mcf2, mcf2.run(param), neg1_gr, neg1_l1, neg1_u2, neg1_c, neg1_s, 382 382 mcf2.OPTIMAL, true, -40000, test_str + "-14"); 383 mcf2.reset ().lowerMap(neg1_l2).costMap(neg1_c).supplyMap(neg1_s);383 mcf2.resetParams().lowerMap(neg1_l2).costMap(neg1_c).supplyMap(neg1_s); 384 384 checkMcf(mcf2, mcf2.run(param), neg1_gr, neg1_l2, neg1_u1, neg1_c, neg1_s, 385 385 mcf2.UNBOUNDED, false, 0, test_str + "-15");
Note: See TracChangeset
for help on using the changeset viewer.