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

