Changes in / [431:9dfaf6efc36f:432:e9a568cc86e3] in lemon-1.2
- Files:
-
- 2 deleted
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
lemon/bfs.h
r405 r420 1742 1742 /// \pre Either \ref run(Node) "run()" or \ref init() 1743 1743 /// must be called before using this function. 1744 bool reached(Node v) { return (*_reached)[v]; }1744 bool reached(Node v) const { return (*_reached)[v]; } 1745 1745 1746 1746 ///@} -
lemon/circulation.h
r402 r420 420 420 /// \pre Either \ref run() or \ref init() must be called before 421 421 /// using this function. 422 const Elevator& elevator() {422 const Elevator& elevator() const { 423 423 return *_level; 424 424 } … … 645 645 /// \pre Either \ref run() or \ref init() must be called before 646 646 /// using this function. 647 const FlowMap& flowMap() {647 const FlowMap& flowMap() const { 648 648 return *_flow; 649 649 } … … 670 670 \sa checkBarrier() 671 671 */ 672 bool barrier(const Node& node) 672 bool barrier(const Node& node) const 673 673 { 674 674 return (*_level)[node] >= _el; … … 693 693 /// \sa checkBarrier() 694 694 template<class BarrierMap> 695 void barrierMap(BarrierMap &bar) 695 void barrierMap(BarrierMap &bar) const 696 696 { 697 697 for(NodeIt n(_g);n!=INVALID;++n) … … 713 713 ///Check if the found flow is a feasible circulation, 714 714 /// 715 bool checkFlow() {715 bool checkFlow() const { 716 716 for(ArcIt e(_g);e!=INVALID;++e) 717 717 if((*_flow)[e]<(*_lo)[e]||(*_flow)[e]>(*_up)[e]) return false; … … 731 731 ///\sa barrier() 732 732 ///\sa barrierMap() 733 bool checkBarrier() 733 bool checkBarrier() const 734 734 { 735 735 Value delta=0; -
lemon/connectivity.h
r417 r425 17 17 */ 18 18 19 #ifndef LEMON_ TOPOLOGY_H20 #define LEMON_ TOPOLOGY_H19 #ifndef LEMON_CONNECTIVITY_H 20 #define LEMON_CONNECTIVITY_H 21 21 22 22 #include <lemon/dfs.h> … … 155 155 } 156 156 157 namespace _ topology_bits {157 namespace _connectivity_bits { 158 158 159 159 template <typename Digraph, typename Iterator > … … 189 189 190 190 template <typename Digraph, typename ArcMap> 191 struct StronglyConnectedCut EdgesVisitor : public DfsVisitor<Digraph> {191 struct StronglyConnectedCutArcsVisitor : public DfsVisitor<Digraph> { 192 192 public: 193 193 typedef typename Digraph::Node Node; 194 194 typedef typename Digraph::Arc Arc; 195 195 196 StronglyConnectedCut EdgesVisitor(const Digraph& digraph,197 198 196 StronglyConnectedCutArcsVisitor(const Digraph& digraph, 197 ArcMap& cutMap, 198 int& cutNum) 199 199 : _digraph(digraph), _cutMap(cutMap), _cutNum(cutNum), 200 _compMap(digraph ), _num(0) {201 } 202 203 void st op(const Node&) {200 _compMap(digraph, -1), _num(-1) { 201 } 202 203 void start(const Node&) { 204 204 ++_num; 205 205 } … … 249 249 if (source == INVALID) return true; 250 250 251 using namespace _ topology_bits;251 using namespace _connectivity_bits; 252 252 253 253 typedef DfsVisitor<Digraph> Visitor; … … 266 266 267 267 typedef ReverseDigraph<const Digraph> RDigraph; 268 typedef typename RDigraph::NodeIt RNodeIt; 268 269 RDigraph rdigraph(digraph); 269 270 … … 276 277 rdfs.start(); 277 278 278 for ( NodeIt it(rdigraph); it != INVALID; ++it) {279 for (RNodeIt it(rdigraph); it != INVALID; ++it) { 279 280 if (!rdfs.reached(it)) { 280 281 return false; … … 295 296 /// direction. 296 297 /// 297 /// \param graph The graph.298 /// \param digraph The graph. 298 299 /// \return The number of components 299 300 /// \note By definition, the empty graph has zero … … 303 304 checkConcept<concepts::Digraph, Digraph>(); 304 305 305 using namespace _ topology_bits;306 using namespace _connectivity_bits; 306 307 307 308 typedef typename Digraph::Node Node; … … 375 376 checkConcept<concepts::WriteMap<Node, int>, NodeMap>(); 376 377 377 using namespace _ topology_bits;378 using namespace _connectivity_bits; 378 379 379 380 typedef std::vector<Node> Container; … … 439 440 checkConcept<concepts::WriteMap<Arc, bool>, ArcMap>(); 440 441 441 using namespace _ topology_bits;442 using namespace _connectivity_bits; 442 443 443 444 typedef std::vector<Node> Container; … … 464 465 int cutNum = 0; 465 466 466 typedef StronglyConnectedCut EdgesVisitor<RDigraph, ArcMap> RVisitor;467 typedef StronglyConnectedCutArcsVisitor<RDigraph, ArcMap> RVisitor; 467 468 RVisitor rvisitor(rgraph, cutMap, cutNum); 468 469 … … 479 480 } 480 481 481 namespace _ topology_bits {482 namespace _connectivity_bits { 482 483 483 484 template <typename Digraph> … … 731 732 typedef typename Graph::NodeIt NodeIt; 732 733 733 using namespace _ topology_bits;734 using namespace _connectivity_bits; 734 735 735 736 typedef CountBiNodeConnectedComponentsVisitor<Graph> Visitor; … … 774 775 checkConcept<concepts::WriteMap<Edge, int>, EdgeMap>(); 775 776 776 using namespace _ topology_bits;777 using namespace _connectivity_bits; 777 778 778 779 typedef BiNodeConnectedComponentsVisitor<Graph, EdgeMap> Visitor; … … 814 815 checkConcept<concepts::WriteMap<Node, bool>, NodeMap>(); 815 816 816 using namespace _ topology_bits;817 using namespace _connectivity_bits; 817 818 818 819 typedef BiNodeConnectedCutNodesVisitor<Graph, NodeMap> Visitor; … … 833 834 } 834 835 835 namespace _ topology_bits {836 namespace _connectivity_bits { 836 837 837 838 template <typename Digraph> … … 1054 1055 typedef typename Graph::NodeIt NodeIt; 1055 1056 1056 using namespace _ topology_bits;1057 using namespace _connectivity_bits; 1057 1058 1058 1059 typedef CountBiEdgeConnectedComponentsVisitor<Graph> Visitor; … … 1096 1097 checkConcept<concepts::WriteMap<Node, int>, NodeMap>(); 1097 1098 1098 using namespace _ topology_bits;1099 using namespace _connectivity_bits; 1099 1100 1100 1101 typedef BiEdgeConnectedComponentsVisitor<Graph, NodeMap> Visitor; … … 1137 1138 checkConcept<concepts::WriteMap<Edge, bool>, EdgeMap>(); 1138 1139 1139 using namespace _ topology_bits;1140 using namespace _connectivity_bits; 1140 1141 1141 1142 typedef BiEdgeConnectedCutEdgesVisitor<Graph, EdgeMap> Visitor; … … 1157 1158 1158 1159 1159 namespace _ topology_bits {1160 namespace _connectivity_bits { 1160 1161 1161 1162 template <typename Digraph, typename IntNodeMap> … … 1194 1195 template <typename Digraph, typename NodeMap> 1195 1196 void topologicalSort(const Digraph& graph, NodeMap& order) { 1196 using namespace _ topology_bits;1197 using namespace _connectivity_bits; 1197 1198 1198 1199 checkConcept<concepts::Digraph, Digraph>(); … … 1225 1226 /// that the given graph is DAG. 1226 1227 /// 1227 /// \param graph The graph. It must be directed and acyclic.1228 /// \param digraph The graph. It must be directed and acyclic. 1228 1229 /// \retval order A readable - writable node map. The values will be set 1229 1230 /// from 0 to the number of the nodes in the graph minus one. Each values … … 1235 1236 /// \see dag 1236 1237 template <typename Digraph, typename NodeMap> 1237 bool checkedTopologicalSort(const Digraph& graph, NodeMap& order) {1238 using namespace _ topology_bits;1238 bool checkedTopologicalSort(const Digraph& digraph, NodeMap& order) { 1239 using namespace _connectivity_bits; 1239 1240 1240 1241 checkConcept<concepts::Digraph, Digraph>(); … … 1246 1247 typedef typename Digraph::Arc Arc; 1247 1248 1248 order = constMap<Node, int, -1>(); 1249 for (NodeIt it(digraph); it != INVALID; ++it) { 1250 order.set(it, -1); 1251 } 1249 1252 1250 1253 TopologicalSortVisitor<Digraph, NodeMap> 1251 visitor(order, countNodes( graph));1254 visitor(order, countNodes(digraph)); 1252 1255 1253 1256 DfsVisit<Digraph, TopologicalSortVisitor<Digraph, NodeMap> > 1254 dfs( graph, visitor);1257 dfs(digraph, visitor); 1255 1258 1256 1259 dfs.init(); 1257 for (NodeIt it( graph); it != INVALID; ++it) {1260 for (NodeIt it(digraph); it != INVALID; ++it) { 1258 1261 if (!dfs.reached(it)) { 1259 1262 dfs.addSource(it); 1260 1263 while (!dfs.emptyQueue()) { 1261 Arc edge= dfs.nextArc();1262 Node target = graph.target(edge);1264 Arc arc = dfs.nextArc(); 1265 Node target = digraph.target(arc); 1263 1266 if (dfs.reached(target) && order[target] == -1) { 1264 1267 return false; … … 1280 1283 /// \see acyclic 1281 1284 template <typename Digraph> 1282 bool dag(const Digraph& graph) {1285 bool dag(const Digraph& digraph) { 1283 1286 1284 1287 checkConcept<concepts::Digraph, Digraph>(); … … 1291 1294 1292 1295 typename Dfs<Digraph>::template SetProcessedMap<ProcessedMap>:: 1293 Create dfs( graph);1294 1295 ProcessedMap processed( graph);1296 Create dfs(digraph); 1297 1298 ProcessedMap processed(digraph); 1296 1299 dfs.processedMap(processed); 1297 1300 1298 1301 dfs.init(); 1299 for (NodeIt it( graph); it != INVALID; ++it) {1302 for (NodeIt it(digraph); it != INVALID; ++it) { 1300 1303 if (!dfs.reached(it)) { 1301 1304 dfs.addSource(it); 1302 1305 while (!dfs.emptyQueue()) { 1303 1306 Arc edge = dfs.nextArc(); 1304 Node target = graph.target(edge);1307 Node target = digraph.target(edge); 1305 1308 if (dfs.reached(target) && !processed[target]) { 1306 1309 return false; … … 1381 1384 } 1382 1385 1383 namespace _ topology_bits {1386 namespace _connectivity_bits { 1384 1387 1385 1388 template <typename Digraph> … … 1450 1453 template<typename Graph> 1451 1454 inline bool bipartite(const Graph &graph){ 1452 using namespace _ topology_bits;1455 using namespace _connectivity_bits; 1453 1456 1454 1457 checkConcept<concepts::Graph, Graph>(); … … 1490 1493 template<typename Graph, typename NodeMap> 1491 1494 inline bool bipartitePartitions(const Graph &graph, NodeMap &partMap){ 1492 using namespace _ topology_bits;1495 using namespace _connectivity_bits; 1493 1496 1494 1497 checkConcept<concepts::Graph, Graph>(); … … 1521 1524 /// Returns true when there are not loop edges in the graph. 1522 1525 template <typename Digraph> 1523 bool loopFree(const Digraph& graph) {1524 for (typename Digraph::ArcIt it( graph); it != INVALID; ++it) {1525 if ( graph.source(it) ==graph.target(it)) return false;1526 bool loopFree(const Digraph& digraph) { 1527 for (typename Digraph::ArcIt it(digraph); it != INVALID; ++it) { 1528 if (digraph.source(it) == digraph.target(it)) return false; 1526 1529 } 1527 1530 return true; … … 1532 1535 /// Returns true when there are not parallel edges in the graph. 1533 1536 template <typename Digraph> 1534 bool parallelFree(const Digraph& graph) {1535 typename Digraph::template NodeMap<bool> reached( graph, false);1536 for (typename Digraph::NodeIt n( graph); n != INVALID; ++n) {1537 for (typename Digraph::OutArcIt e(graph, n); e != INVALID; ++e) {1538 if (reached[ graph.target(e)]) return false;1539 reached.set( graph.target(e), true);1540 } 1541 for (typename Digraph::OutArcIt e(graph, n); e != INVALID; ++e) {1542 reached.set( graph.target(e), false);1537 bool parallelFree(const Digraph& digraph) { 1538 typename Digraph::template NodeMap<bool> reached(digraph, false); 1539 for (typename Digraph::NodeIt n(digraph); n != INVALID; ++n) { 1540 for (typename Digraph::OutArcIt a(digraph, n); a != INVALID; ++a) { 1541 if (reached[digraph.target(a)]) return false; 1542 reached.set(digraph.target(a), true); 1543 } 1544 for (typename Digraph::OutArcIt a(digraph, n); a != INVALID; ++a) { 1545 reached.set(digraph.target(a), false); 1543 1546 } 1544 1547 } … … 1552 1555 /// the graph. 1553 1556 template <typename Digraph> 1554 bool simpleDigraph(const Digraph& graph) {1555 typename Digraph::template NodeMap<bool> reached( graph, false);1556 for (typename Digraph::NodeIt n( graph); n != INVALID; ++n) {1557 bool simpleDigraph(const Digraph& digraph) { 1558 typename Digraph::template NodeMap<bool> reached(digraph, false); 1559 for (typename Digraph::NodeIt n(digraph); n != INVALID; ++n) { 1557 1560 reached.set(n, true); 1558 for (typename Digraph::OutArcIt e(graph, n); e != INVALID; ++e) {1559 if (reached[ graph.target(e)]) return false;1560 reached.set( graph.target(e), true);1561 } 1562 for (typename Digraph::OutArcIt e(graph, n); e != INVALID; ++e) {1563 reached.set( graph.target(e), false);1561 for (typename Digraph::OutArcIt a(digraph, n); a != INVALID; ++a) { 1562 if (reached[digraph.target(a)]) return false; 1563 reached.set(digraph.target(a), true); 1564 } 1565 for (typename Digraph::OutArcIt a(digraph, n); a != INVALID; ++a) { 1566 reached.set(digraph.target(a), false); 1564 1567 } 1565 1568 reached.set(n, false); … … 1570 1573 } //namespace lemon 1571 1574 1572 #endif //LEMON_ TOPOLOGY_H1575 #endif //LEMON_CONNECTIVITY_H -
lemon/dfs.h
r405 r421 1411 1411 } else { 1412 1412 _visitor->leave(s); 1413 _visitor->stop(s); 1413 1414 } 1414 1415 } … … 1626 1627 /// \pre Either \ref run(Node) "run()" or \ref init() 1627 1628 /// must be called before using this function. 1628 bool reached(Node v) { return (*_reached)[v]; }1629 bool reached(Node v) const { return (*_reached)[v]; } 1629 1630 1630 1631 ///@} -
lemon/max_matching.h
r330 r425 417 417 /// \ref init(), \ref greedyInit() or \ref matchingInit() 418 418 /// functions first, then you can start the algorithm with the \ref 419 /// start Parse() or startDense() functions.419 /// startSparse() or startDense() functions. 420 420 421 421 ///@{ -
lemon/preflow.h
r393 r420 367 367 /// \pre Either \ref run() or \ref init() must be called before 368 368 /// using this function. 369 const Elevator& elevator() {369 const Elevator& elevator() const { 370 370 return *_level; 371 371 } … … 919 919 /// \pre Either \ref run() or \ref init() must be called before 920 920 /// using this function. 921 const FlowMap& flowMap() {921 const FlowMap& flowMap() const { 922 922 return *_flow; 923 923 } -
lemon/suurballe.h
r346 r425 52 52 /// 53 53 /// \note For finding node-disjoint paths this algorithm can be used 54 /// with \ref Split DigraphAdaptor.54 /// with \ref SplitNodes. 55 55 #ifdef DOXYGEN 56 56 template <typename Digraph, typename LengthMap> -
scripts/chg-len.py
r376 r422 4 4 5 5 from mercurial import ui, hg 6 from mercurial import util 7 8 util.rcpath = lambda : [] 6 9 7 10 if len(sys.argv)>1 and sys.argv[1] in ["-h","--help"]: -
test/CMakeLists.txt
r410 r424 5 5 SET(TESTS 6 6 bfs_test 7 circulation_test 7 8 counter_test 8 9 dfs_test … … 11 12 dim_test 12 13 error_test 14 graph_adaptor_test 13 15 graph_copy_test 14 16 graph_test … … 19 21 maps_test 20 22 max_matching_test 23 path_test 24 preflow_test 21 25 random_test 22 path_test26 suurballe_test 23 27 time_measure_test 24 28 unionfind_test) -
test/Makefile.am
r418 r424 1 1 EXTRA_DIST += \ 2 test/CMakeLists.txt \ 3 test/min_cost_flow_test.lgf \ 4 test/preflow_graph.lgf 2 test/CMakeLists.txt 5 3 6 4 noinst_HEADERS += \ … … 21 19 test/graph_test \ 22 20 test/graph_utils_test \ 21 test/hao_orlin_test \ 23 22 test/heap_test \ 24 23 test/kruskal_test \ 25 test/hao_orlin_test \26 24 test/maps_test \ 27 25 test/max_matching_test \ 28 test/random_test \29 26 test/path_test \ 30 27 test/preflow_test \ 28 test/random_test \ 31 29 test/suurballe_test \ 32 30 test/test_tools_fail \ -
test/preflow_test.cc
r394 r423 17 17 */ 18 18 19 #include <fstream> 20 #include <string> 19 #include <iostream> 21 20 22 21 #include "test_tools.h" … … 29 28 30 29 using namespace lemon; 30 31 char test_lgf[] = 32 "@nodes\n" 33 "label\n" 34 "0\n" 35 "1\n" 36 "2\n" 37 "3\n" 38 "4\n" 39 "5\n" 40 "6\n" 41 "7\n" 42 "8\n" 43 "9\n" 44 "@arcs\n" 45 " label capacity\n" 46 "0 1 0 20\n" 47 "0 2 1 0\n" 48 "1 1 2 3\n" 49 "1 2 3 8\n" 50 "1 3 4 8\n" 51 "2 5 5 5\n" 52 "3 2 6 5\n" 53 "3 5 7 5\n" 54 "3 6 8 5\n" 55 "4 3 9 3\n" 56 "5 7 10 3\n" 57 "5 6 11 10\n" 58 "5 8 12 10\n" 59 "6 8 13 8\n" 60 "8 9 14 20\n" 61 "8 1 15 5\n" 62 "9 5 16 5\n" 63 "@attributes\n" 64 "source 1\n" 65 "target 8\n"; 31 66 32 67 void checkPreflowCompile() … … 124 159 typedef Preflow<Digraph, CapMap> PType; 125 160 126 std::string f_name;127 if( getenv("srcdir") )128 f_name = std::string(getenv("srcdir"));129 else f_name = ".";130 f_name += "/test/preflow_graph.lgf";131 132 std::ifstream file(f_name.c_str());133 134 check(file, "Input file '" << f_name << "' not found.");135 136 161 Digraph g; 137 162 Node s, t; 138 163 CapMap cap(g); 139 DigraphReader<Digraph>(g,file). 164 std::istringstream input(test_lgf); 165 DigraphReader<Digraph>(g,input). 140 166 arcMap("capacity", cap). 141 167 node("source",s). -
test/suurballe_test.cc
r346 r423 18 18 19 19 #include <iostream> 20 #include <fstream>21 20 22 21 #include <lemon/list_graph.h> … … 28 27 29 28 using namespace lemon; 29 30 char test_lgf[] = 31 "@nodes\n" 32 "label supply1 supply2 supply3\n" 33 "1 0 20 27\n" 34 "2 0 -4 0\n" 35 "3 0 0 0\n" 36 "4 0 0 0\n" 37 "5 0 9 0\n" 38 "6 0 -6 0\n" 39 "7 0 0 0\n" 40 "8 0 0 0\n" 41 "9 0 3 0\n" 42 "10 0 -2 0\n" 43 "11 0 0 0\n" 44 "12 0 -20 -27\n" 45 "@arcs\n" 46 " cost capacity lower1 lower2\n" 47 " 1 2 70 11 0 8\n" 48 " 1 3 150 3 0 1\n" 49 " 1 4 80 15 0 2\n" 50 " 2 8 80 12 0 0\n" 51 " 3 5 140 5 0 3\n" 52 " 4 6 60 10 0 1\n" 53 " 4 7 80 2 0 0\n" 54 " 4 8 110 3 0 0\n" 55 " 5 7 60 14 0 0\n" 56 " 5 11 120 12 0 0\n" 57 " 6 3 0 3 0 0\n" 58 " 6 9 140 4 0 0\n" 59 " 6 10 90 8 0 0\n" 60 " 7 1 30 5 0 0\n" 61 " 8 12 60 16 0 4\n" 62 " 9 12 50 6 0 0\n" 63 "10 12 70 13 0 5\n" 64 "10 2 100 7 0 0\n" 65 "10 7 60 10 0 0\n" 66 "11 10 20 14 0 6\n" 67 "12 11 30 10 0 0\n" 68 "@attributes\n" 69 "source 1\n" 70 "target 12\n" 71 "@end\n"; 30 72 31 73 // Check the feasibility of the flow … … 97 139 Node source, target; 98 140 99 std::string fname; 100 if(getenv("srcdir")) 101 fname = std::string(getenv("srcdir")); 102 else fname = "."; 103 fname += "/test/min_cost_flow_test.lgf"; 104 105 std::ifstream input(fname.c_str()); 106 check(input, "Input file '" << fname << "' not found"); 141 std::istringstream input(test_lgf); 107 142 DigraphReader<ListDigraph>(digraph, input). 108 143 arcMap("cost", length). … … 110 145 node("target", target). 111 146 run(); 112 input.close();113 147 114 148 // Find 2 paths
Note: See TracChangeset
for help on using the changeset viewer.