Ticket #325: 0759d974de81-4add05447ca0-72af84645ac2.patch
File 0759d974de81-4add05447ca0-72af84645ac2.patch, 143.9 KB (added by , 10 years ago) |
---|
-
CMakeLists.txt
# HG changeset patch # User Gabor Gevay <ggab90@gmail.com> # Date 1388957096 -3600 # Sun Jan 05 22:24:56 2014 +0100 # Node ID 0759d974de816af3492dff5e02de2d361ad27841 # Parent 39b6e65574c68620fda4e5faa9bd779c29c62190 STL style iterators (#325) For * graph types, * graph adaptors, * paths, * iterable maps, * LP rows/cols and * active nodes is BellmanFord diff --git a/CMakeLists.txt b/CMakeLists.txt
a b 262 262 263 263 ENABLE_TESTING() 264 264 265 266 INCLUDE(CheckCXXCompilerFlag) 267 CHECK_CXX_COMPILER_FLAG("-std=c++11" CXX11FLAG) 268 IF(CXX11FLAG) 269 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") 270 ENDIF() 271 272 265 273 IF(${CMAKE_BUILD_TYPE} STREQUAL "Maintainer") 266 274 ADD_CUSTOM_TARGET(check ALL COMMAND ${CMAKE_CTEST_COMMAND}) 267 275 ELSE() -
lemon/bellman_ford.h
diff --git a/lemon/bellman_ford.h b/lemon/bellman_ford.h
a b 29 29 #include <lemon/error.h> 30 30 #include <lemon/maps.h> 31 31 #include <lemon/path.h> 32 #include <lemon/bits/stl_iterators.h> 32 33 33 34 #include <limits> 34 35 … … 690 691 int _index; 691 692 }; 692 693 694 /// \brief Gets the collection of the active nodes. 695 /// 696 /// This function can be used for iterating on the active nodes of the 697 /// Bellman-Ford algorithm after the last phase. 698 /// These nodes should be checked in the next phase to 699 /// find augmenting arcs outgoing from them. 700 /// It returns a wrapped ActiveIt, which looks 701 /// like an STL container (by having begin() and end()) 702 /// which you can use in range-based for loops, STL algorithms, etc. 703 LemonRangeWrapper1<ActiveIt, BellmanFord> 704 activeNodes(const BellmanFord& algorithm) const { 705 return LemonRangeWrapper1<ActiveIt, BellmanFord>(algorithm); 706 } 707 708 693 709 /// \name Query Functions 694 710 /// The result of the Bellman-Ford algorithm can be obtained using these 695 711 /// functions.\n -
lemon/bits/graph_adaptor_extender.h
diff --git a/lemon/bits/graph_adaptor_extender.h b/lemon/bits/graph_adaptor_extender.h
a b 85 85 86 86 }; 87 87 88 LemonRangeWrapper1<NodeIt, Adaptor> nodes() { 89 return LemonRangeWrapper1<NodeIt, Adaptor>(*this); 90 } 88 91 89 92 class ArcIt : public Arc { 90 93 const Adaptor* _adaptor; … … 108 111 109 112 }; 110 113 114 LemonRangeWrapper1<ArcIt, Adaptor> arcs() { 115 return LemonRangeWrapper1<ArcIt, Adaptor>(*this); 116 } 117 111 118 112 119 class OutArcIt : public Arc { 113 120 const Adaptor* _adaptor; … … 132 139 133 140 }; 134 141 142 LemonRangeWrapper2<OutArcIt, Adaptor, Node> outArcs(const Node& u) const { 143 return LemonRangeWrapper2<OutArcIt, Adaptor, Node>(*this, u); 144 } 145 135 146 136 147 class InArcIt : public Arc { 137 148 const Adaptor* _adaptor; … … 156 167 157 168 }; 158 169 170 LemonRangeWrapper2<InArcIt, Adaptor, Node> inArcs(const Node& u) const { 171 return LemonRangeWrapper2<InArcIt, Adaptor, Node>(*this, u); 172 } 173 159 174 Node baseNode(const OutArcIt &e) const { 160 175 return Parent::source(e); 161 176 } … … 254 269 255 270 }; 256 271 272 LemonRangeWrapper1<NodeIt, Adaptor> nodes() { 273 return LemonRangeWrapper1<NodeIt, Adaptor>(*this); 274 } 275 257 276 258 277 class ArcIt : public Arc { 259 278 const Adaptor* _adaptor; … … 277 296 278 297 }; 279 298 299 LemonRangeWrapper1<ArcIt, Adaptor> arcs() { 300 return LemonRangeWrapper1<ArcIt, Adaptor>(*this); 301 } 302 280 303 281 304 class OutArcIt : public Arc { 282 305 const Adaptor* _adaptor; … … 301 324 302 325 }; 303 326 327 LemonRangeWrapper2<OutArcIt, Adaptor, Node> outArcs(const Node& u) const { 328 return LemonRangeWrapper2<OutArcIt, Adaptor, Node>(*this, u); 329 } 330 304 331 305 332 class InArcIt : public Arc { 306 333 const Adaptor* _adaptor; … … 325 352 326 353 }; 327 354 355 LemonRangeWrapper2<InArcIt, Adaptor, Node> inArcs(const Node& u) const { 356 return LemonRangeWrapper2<InArcIt, Adaptor, Node>(*this, u); 357 } 358 328 359 class EdgeIt : public Parent::Edge { 329 360 const Adaptor* _adaptor; 330 361 public: … … 347 378 348 379 }; 349 380 381 LemonRangeWrapper1<EdgeIt, Adaptor> edges() { 382 return LemonRangeWrapper1<EdgeIt, Adaptor>(*this); 383 } 384 385 350 386 class IncEdgeIt : public Edge { 351 387 friend class GraphAdaptorExtender; 352 388 const Adaptor* _adaptor; … … 372 408 } 373 409 }; 374 410 411 LemonRangeWrapper2<IncEdgeIt, Adaptor, Node> incEdges(const Node& u) const { 412 return LemonRangeWrapper2<IncEdgeIt, Adaptor, Node>(*this, u); 413 } 414 415 375 416 Node baseNode(const OutArcIt &a) const { 376 417 return Parent::source(a); 377 418 } -
lemon/bits/graph_extender.h
diff --git a/lemon/bits/graph_extender.h b/lemon/bits/graph_extender.h
a b 27 27 #include <lemon/concept_check.h> 28 28 #include <lemon/concepts/maps.h> 29 29 30 #include <lemon/bits/stl_iterators.h> 31 30 32 //\ingroup graphbits 31 33 //\file 32 34 //\brief Extenders for the graph types … … 116 118 117 119 }; 118 120 121 LemonRangeWrapper1<NodeIt, Digraph> nodes() const { 122 return LemonRangeWrapper1<NodeIt, Digraph>(*this); 123 } 124 119 125 120 126 class ArcIt : public Arc { 121 127 const Digraph* _digraph; … … 139 145 140 146 }; 141 147 148 LemonRangeWrapper1<ArcIt, Digraph> arcs() const { 149 return LemonRangeWrapper1<ArcIt, Digraph>(*this); 150 } 151 142 152 143 153 class OutArcIt : public Arc { 144 154 const Digraph* _digraph; … … 163 173 164 174 }; 165 175 176 LemonRangeWrapper2<OutArcIt, Digraph, Node> outArcs(const Node& u) const { 177 return LemonRangeWrapper2<OutArcIt, Digraph, Node>(*this, u); 178 } 179 166 180 167 181 class InArcIt : public Arc { 168 182 const Digraph* _digraph; … … 187 201 188 202 }; 189 203 204 LemonRangeWrapper2<InArcIt, Digraph, Node> inArcs(const Node& u) const { 205 return LemonRangeWrapper2<InArcIt, Digraph, Node>(*this, u); 206 } 207 190 208 // \brief Base node of the iterator 191 209 // 192 210 // Returns the base node (i.e. the source in this case) of the iterator … … 436 454 437 455 }; 438 456 457 LemonRangeWrapper1<NodeIt, Graph> nodes() const { 458 return LemonRangeWrapper1<NodeIt, Graph>(*this); 459 } 460 439 461 440 462 class ArcIt : public Arc { 441 463 const Graph* _graph; … … 459 481 460 482 }; 461 483 484 LemonRangeWrapper1<ArcIt, Graph> arcs() const { 485 return LemonRangeWrapper1<ArcIt, Graph>(*this); 486 } 487 462 488 463 489 class OutArcIt : public Arc { 464 490 const Graph* _graph; … … 483 509 484 510 }; 485 511 512 LemonRangeWrapper2<OutArcIt, Graph, Node> outArcs(const Node& u) const { 513 return LemonRangeWrapper2<OutArcIt, Graph, Node>(*this, u); 514 } 515 486 516 487 517 class InArcIt : public Arc { 488 518 const Graph* _graph; … … 507 537 508 538 }; 509 539 540 LemonRangeWrapper2<InArcIt, Graph, Node> inArcs(const Node& u) const { 541 return LemonRangeWrapper2<InArcIt, Graph, Node>(*this, u); 542 } 543 510 544 511 545 class EdgeIt : public Parent::Edge { 512 546 const Graph* _graph; … … 530 564 531 565 }; 532 566 567 LemonRangeWrapper1<EdgeIt, Graph> edges() const { 568 return LemonRangeWrapper1<EdgeIt, Graph>(*this); 569 } 570 571 533 572 class IncEdgeIt : public Parent::Edge { 534 573 friend class GraphExtender; 535 574 const Graph* _graph; … … 555 594 } 556 595 }; 557 596 597 LemonRangeWrapper2<IncEdgeIt, Graph, Node> incEdges(const Node& u) const { 598 return LemonRangeWrapper2<IncEdgeIt, Graph, Node>(*this, u); 599 } 600 601 558 602 // \brief Base node of the iterator 559 603 // 560 604 // Returns the base node (ie. the source in this case) of the iterator … … 903 947 904 948 }; 905 949 950 LemonRangeWrapper1<NodeIt, BpGraph> nodes() const { 951 return LemonRangeWrapper1<NodeIt, BpGraph>(*this); 952 } 953 954 906 955 class RedNodeIt : public RedNode { 907 956 const BpGraph* _graph; 908 957 public: … … 925 974 926 975 }; 927 976 977 LemonRangeWrapper1<RedNodeIt, BpGraph> redNodes() const { 978 return LemonRangeWrapper1<RedNodeIt, BpGraph>(*this); 979 } 980 981 928 982 class BlueNodeIt : public BlueNode { 929 983 const BpGraph* _graph; 930 984 public: … … 947 1001 948 1002 }; 949 1003 1004 LemonRangeWrapper1<BlueNodeIt, BpGraph> blueNodes() const { 1005 return LemonRangeWrapper1<BlueNodeIt, BpGraph>(*this); 1006 } 1007 1008 950 1009 951 1010 class ArcIt : public Arc { 952 1011 const BpGraph* _graph; … … 970 1029 971 1030 }; 972 1031 1032 LemonRangeWrapper1<ArcIt, BpGraph> arcs() const { 1033 return LemonRangeWrapper1<ArcIt, BpGraph>(*this); 1034 } 1035 973 1036 974 1037 class OutArcIt : public Arc { 975 1038 const BpGraph* _graph; … … 994 1057 995 1058 }; 996 1059 1060 LemonRangeWrapper2<OutArcIt, BpGraph, Node> outArcs(const Node& u) const { 1061 return LemonRangeWrapper2<OutArcIt, BpGraph, Node>(*this, u); 1062 } 1063 997 1064 998 1065 class InArcIt : public Arc { 999 1066 const BpGraph* _graph; … … 1018 1085 1019 1086 }; 1020 1087 1088 LemonRangeWrapper2<InArcIt, BpGraph, Node> inArcs(const Node& u) const { 1089 return LemonRangeWrapper2<InArcIt, BpGraph, Node>(*this, u); 1090 } 1091 1021 1092 1022 1093 class EdgeIt : public Parent::Edge { 1023 1094 const BpGraph* _graph; … … 1041 1112 1042 1113 }; 1043 1114 1115 LemonRangeWrapper1<EdgeIt, BpGraph> edges() const { 1116 return LemonRangeWrapper1<EdgeIt, BpGraph>(*this); 1117 } 1118 1119 1044 1120 class IncEdgeIt : public Parent::Edge { 1045 1121 friend class BpGraphExtender; 1046 1122 const BpGraph* _graph; … … 1066 1142 } 1067 1143 }; 1068 1144 1145 LemonRangeWrapper2<IncEdgeIt, BpGraph, Node> incEdges(const Node& u) const { 1146 return LemonRangeWrapper2<IncEdgeIt, BpGraph, Node>(*this, u); 1147 } 1148 1149 1069 1150 // \brief Base node of the iterator 1070 1151 // 1071 1152 // Returns the base node (ie. the source in this case) of the iterator -
new file lemon/bits/stl_iterators.h
diff --git a/lemon/bits/stl_iterators.h b/lemon/bits/stl_iterators.h new file mode 100644
- + 1 /* -*- mode: C++; indent-tabs-mode: nil; -*- 2 */ 3 4 #ifndef STL_ITERATORS_H_ 5 #define STL_ITERATORS_H_ 6 7 #include <lemon/core.h> 8 9 namespace lemon { 10 11 /// \brief Template to make STL iterators from Lemon iterators. 12 /// 13 /// This template makes an STL iterator from a Lemon iterator 14 /// by adding the missing features. 15 /// It inherits from \c std::iterator to make \c iterator_concept work 16 /// (so that STL algorithms work). 17 /// \c T should be the lemon iterator to be decorated. 18 template<class T> 19 struct LemonItWrapper 20 : public T, public std::iterator<std::input_iterator_tag, T> { 21 22 LemonItWrapper(const T &x) : T(x) {} 23 24 //Lemon iterators don't have operator*, (because they rather 25 //inherit from their "value_type"), 26 //so we add one that just returns the object. 27 const T& operator*() const { 28 return static_cast<const T&>(*this); 29 } 30 31 //I can't think of any use case for this with Lemon iterators, 32 //but maybe it should be included for completeness. 33 const T* operator->() { 34 return static_cast<const T*>(this); 35 } 36 37 //Lemon iterators don't have postincrement. 38 void operator++(int) { 39 T::operator++(); 40 } 41 42 using T::operator++; 43 44 }; 45 46 47 /// \brief A generic wrapper for Lemon iterators for range-based for loops. 48 /// 49 /// This template can be used to create a class 50 /// that has begin() and end() from a Lemon iterator 51 /// (with a 1-parameter constructor) 52 /// to make range-based for loops and STL algorithms work. 53 /// 54 /// \c LIT is the Lemon iterator that will be wrapped 55 /// \c P is the type of the parameter of the constructor of \c LIT. 56 template<class LIT, class P> 57 class LemonRangeWrapper1 { 58 const P &_p; 59 typedef LemonItWrapper<LIT> It; 60 public: 61 LemonRangeWrapper1(const P &p) : _p(p) {} 62 It begin() const { 63 return It(LIT(_p)); 64 } 65 It end() const { 66 return It(lemon::INVALID); 67 } 68 }; 69 70 71 /// \brief A generic wrapper for Lemon iterators for range-based for loops. 72 /// 73 /// This template can be used to create a class 74 /// that has begin() and end() from a Lemon iterator 75 /// (with a 2-parameter constructor) 76 /// to make range-based for loops and STL algorithms work. 77 /// 78 /// \c LIT is the Lemon iterator that will be wrapped 79 /// \c P1 and \c P2 are the types of the parameters 80 /// of the constructor of \c LIT. 81 template<class LIT, class P1, class P2> 82 class LemonRangeWrapper2 { 83 const P1 &_p1; 84 const P2 &_p2; 85 typedef LemonItWrapper<LIT> It; 86 public: 87 LemonRangeWrapper2(const P1 &p1, const P2 &p2) : _p1(p1), _p2(p2) {} 88 It begin() const { 89 return It(LIT(_p1, _p2)); 90 } 91 It end() const { 92 return It(lemon::INVALID); 93 } 94 }; 95 96 97 } 98 99 #endif /* STL_ITERATORS_H_ */ -
lemon/cbc.cc
diff --git a/lemon/cbc.cc b/lemon/cbc.cc
a b 111 111 } 112 112 113 113 void CbcMip::_eraseColId(int i) { 114 cols.eraseIndex(i);114 _cols.eraseIndex(i); 115 115 } 116 116 117 117 void CbcMip::_eraseRowId(int i) { 118 rows.eraseIndex(i);118 _rows.eraseIndex(i); 119 119 } 120 120 121 121 void CbcMip::_getColName(int c, std::string& name) const { -
lemon/clp.cc
diff --git a/lemon/clp.cc b/lemon/clp.cc
a b 29 29 30 30 ClpLp::ClpLp(const ClpLp& other) { 31 31 _prob = new ClpSimplex(*other._prob); 32 rows = other.rows;33 cols = other.cols;32 _rows = other._rows; 33 _cols = other._cols; 34 34 _init_temporals(); 35 35 messageLevel(MESSAGE_NOTHING); 36 36 } … … 103 103 } 104 104 105 105 void ClpLp::_eraseColId(int i) { 106 cols.eraseIndex(i);107 cols.shiftIndices(i);106 _cols.eraseIndex(i); 107 _cols.shiftIndices(i); 108 108 } 109 109 110 110 void ClpLp::_eraseRowId(int i) { 111 rows.eraseIndex(i);112 rows.shiftIndices(i);111 _rows.eraseIndex(i); 112 _rows.shiftIndices(i); 113 113 } 114 114 115 115 void ClpLp::_getColName(int c, std::string& name) const { -
lemon/clp.h
diff --git a/lemon/clp.h b/lemon/clp.h
a b 151 151 SolveExitStatus solveBarrier(); 152 152 153 153 ///Returns the constraint identifier understood by CLP. 154 int clpRow(Row r) const { return rows(id(r)); }154 int clpRow(Row r) const { return _rows(id(r)); } 155 155 156 156 ///Returns the variable identifier understood by CLP. 157 int clpCol(Col c) const { return cols(id(c)); }157 int clpCol(Col c) const { return _cols(id(c)); } 158 158 159 159 }; 160 160 -
lemon/concepts/bpgraph.h
diff --git a/lemon/concepts/bpgraph.h b/lemon/concepts/bpgraph.h
a b 27 27 #include <lemon/concepts/maps.h> 28 28 #include <lemon/concept_check.h> 29 29 #include <lemon/core.h> 30 #include <lemon/bits/stl_iterators.h> 30 31 31 32 namespace lemon { 32 33 namespace concepts { … … 221 222 RedNodeIt& operator++() { return *this; } 222 223 }; 223 224 225 /// \brief Gets the collection of the red nodes of the graph. 226 /// 227 /// This function can be used for iterating on 228 /// the red nodes of the graph. It returns a wrapped RedNodeIt, 229 /// which looks like an STL container (by having begin() and end()) 230 /// which you can use in range-based for loops, stl algorithms, etc. 231 /// For example if g is a BpGraph, you can write: 232 ///\code 233 /// for(auto v: g.redNodes()) 234 /// doSomething(v); 235 ///\endcode 236 LemonRangeWrapper1<RedNodeIt, BpGraph> redNodes() const { 237 return LemonRangeWrapper1<RedNodeIt, BpGraph>(*this); 238 } 239 240 224 241 /// Iterator class for the blue nodes. 225 242 226 243 /// This iterator goes through each blue node of the graph. … … 264 281 BlueNodeIt& operator++() { return *this; } 265 282 }; 266 283 284 /// \brief Gets the collection of the blue nodes of the graph. 285 /// 286 /// This function can be used for iterating on 287 /// the blue nodes of the graph. It returns a wrapped BlueNodeIt, 288 /// which looks like an STL container (by having begin() and end()) 289 /// which you can use in range-based for loops, stl algorithms, etc. 290 /// For example if g is a BpGraph, you can write: 291 ///\code 292 /// for(auto v: g.blueNodes()) 293 /// doSomething(v); 294 ///\endcode 295 LemonRangeWrapper1<BlueNodeIt, BpGraph> blueNodes() const { 296 return LemonRangeWrapper1<BlueNodeIt, BpGraph>(*this); 297 } 298 299 267 300 /// Iterator class for the nodes. 268 301 269 302 /// This iterator goes through each node of the graph. … … 307 340 NodeIt& operator++() { return *this; } 308 341 }; 309 342 343 /// \brief Gets the collection of the nodes of the graph. 344 /// 345 /// This function can be used for iterating on 346 /// the nodes of the graph. It returns a wrapped NodeIt, 347 /// which looks like an STL container (by having begin() and end()) 348 /// which you can use in range-based for loops, stl algorithms, etc. 349 /// For example if g is a BpGraph, you can write: 350 ///\code 351 /// for(auto v: g.nodes()) 352 /// doSomething(v); 353 ///\endcode 354 LemonRangeWrapper1<NodeIt, BpGraph> nodes() const { 355 return LemonRangeWrapper1<NodeIt, BpGraph>(*this); 356 } 357 358 310 359 311 360 /// The edge type of the graph 312 361 … … 395 444 EdgeIt& operator++() { return *this; } 396 445 }; 397 446 447 /// \brief Gets the collection of the edges of the graph. 448 /// 449 /// This function can be used for iterating on the 450 /// edges of the graph. It returns a wrapped 451 /// EdgeIt, which looks like an STL container 452 /// (by having begin() and end()) which you can use in range-based 453 /// for loops, stl algorithms, etc. 454 /// For example if g is a BpGraph, you can write: 455 ///\code 456 /// for(auto e: g.edges()) 457 /// doSomething(e); 458 ///\endcode 459 LemonRangeWrapper1<EdgeIt, BpGraph> edges() const { 460 return LemonRangeWrapper1<EdgeIt, BpGraph>(*this); 461 } 462 463 398 464 /// Iterator class for the incident edges of a node. 399 465 400 466 /// This iterator goes trough the incident undirected edges … … 443 509 IncEdgeIt& operator++() { return *this; } 444 510 }; 445 511 512 /// \brief Gets the collection of the incident edges 513 /// of a certain node of the graph. 514 /// 515 /// This function can be used for iterating on the 516 /// incident undirected edges of a certain node of the graph. 517 /// It returns a wrapped 518 /// IncEdgeIt, which looks like an STL container 519 /// (by having begin() and end()) which you can use in range-based 520 /// for loops, stl algorithms, etc. 521 /// For example if g is a BpGraph and u is a Node, you can write: 522 ///\code 523 /// for(auto e: g.incEdges(u)) 524 /// doSomething(e); 525 ///\endcode 526 LemonRangeWrapper2<IncEdgeIt, BpGraph, Node> incEdges(const Node& u) const { 527 return LemonRangeWrapper2<IncEdgeIt, BpGraph, Node>(*this, u); 528 } 529 530 446 531 /// The arc type of the graph 447 532 448 533 /// This class identifies a directed arc of the graph. It also serves … … 539 624 ArcIt& operator++() { return *this; } 540 625 }; 541 626 627 /// \brief Gets the collection of the directed arcs of the graph. 628 /// 629 /// This function can be used for iterating on the 630 /// arcs of the graph. It returns a wrapped 631 /// ArcIt, which looks like an STL container 632 /// (by having begin() and end()) which you can use in range-based 633 /// for loops, stl algorithms, etc. 634 /// For example if g is a BpGraph you can write: 635 ///\code 636 /// for(auto a: g.arcs()) 637 /// doSomething(a); 638 ///\endcode 639 LemonRangeWrapper1<ArcIt, BpGraph> arcs() const { 640 return LemonRangeWrapper1<ArcIt, BpGraph>(*this); 641 } 642 643 542 644 /// Iterator class for the outgoing arcs of a node. 543 645 544 646 /// This iterator goes trough the \e outgoing directed arcs of a … … 587 689 OutArcIt& operator++() { return *this; } 588 690 }; 589 691 692 /// \brief Gets the collection of the outgoing directed arcs of a 693 /// certain node of the graph. 694 /// 695 /// This function can be used for iterating on the 696 /// outgoing arcs of a certain node of the graph. It returns a wrapped 697 /// OutArcIt, which looks like an STL container 698 /// (by having begin() and end()) which you can use in range-based 699 /// for loops, stl algorithms, etc. 700 /// For example if g is a BpGraph and u is a Node, you can write: 701 ///\code 702 /// for(auto a: g.outArcs(u)) 703 /// doSomething(a); 704 ///\endcode 705 LemonRangeWrapper2<OutArcIt, BpGraph, Node> outArcs(const Node& u) const { 706 return LemonRangeWrapper2<OutArcIt, BpGraph, Node>(*this, u); 707 } 708 709 590 710 /// Iterator class for the incoming arcs of a node. 591 711 592 712 /// This iterator goes trough the \e incoming directed arcs of a … … 635 755 InArcIt& operator++() { return *this; } 636 756 }; 637 757 758 /// \brief Gets the collection of the incoming directed arcs of a 759 /// certain node of the graph. 760 /// 761 /// This function can be used for iterating on the 762 /// incoming arcs of a certain node of the graph. It returns a wrapped 763 /// InArcIt, which looks like an STL container 764 /// (by having begin() and end()) which you can use in range-based 765 /// for loops, stl algorithms, etc. 766 /// For example if g is a BpGraph and u is a Node, you can write: 767 ///\code 768 /// for(auto a: g.inArcs(u)) 769 /// doSomething(a); 770 ///\endcode 771 LemonRangeWrapper2<InArcIt, BpGraph, Node> inArcs(const Node& u) const { 772 return LemonRangeWrapper2<InArcIt, BpGraph, Node>(*this, u); 773 } 774 775 638 776 /// \brief Standard graph map type for the nodes. 639 777 /// 640 778 /// Standard graph map type for the nodes. -
lemon/concepts/digraph.h
diff --git a/lemon/concepts/digraph.h b/lemon/concepts/digraph.h
a b 27 27 #include <lemon/concepts/maps.h> 28 28 #include <lemon/concept_check.h> 29 29 #include <lemon/concepts/graph_components.h> 30 #include <lemon/bits/stl_iterators.h> 30 31 31 32 namespace lemon { 32 33 namespace concepts { … … 147 148 NodeIt& operator++() { return *this; } 148 149 }; 149 150 151 /// \brief Gets the collection of the nodes of the digraph. 152 /// 153 /// This function can be used for iterating on 154 /// the nodes of the digraph. It returns a wrapped NodeIt, which looks 155 /// like an STL container (by having begin() and end()) 156 /// which you can use in range-based for loops, STL algorithms, etc. 157 /// For example you can write: 158 ///\code 159 /// ListDigraph g; 160 /// for(auto v: g.nodes()) 161 /// doSomething(v); 162 /// 163 /// //Using an STL algorithm: 164 /// copy(g.nodes().begin(), g.nodes().end(), vect.begin()); 165 ///\endcode 166 LemonRangeWrapper1<NodeIt, Digraph> nodes() const { 167 return LemonRangeWrapper1<NodeIt, Digraph>(*this); 168 } 169 150 170 151 171 /// The arc type of the digraph 152 172 … … 237 257 OutArcIt& operator++() { return *this; } 238 258 }; 239 259 260 /// \brief Gets the collection of the outgoing arcs of a certain node 261 /// of the digraph. 262 /// 263 /// This function can be used for iterating on the 264 /// outgoing arcs of a certain node of the digraph. It returns a wrapped 265 /// OutArcIt, which looks like an STL container 266 /// (by having begin() and end()) which you can use in range-based 267 /// for loops, STL algorithms, etc. 268 /// For example if g is a Digraph and u is a node, you can write: 269 ///\code 270 /// for(auto a: g.outArcs(u)) 271 /// doSomething(a); 272 /// 273 /// //Using an STL algorithm: 274 /// copy(g.outArcs(u).begin(), g.outArcs(u).end(), vect.begin()); 275 ///\endcode 276 LemonRangeWrapper2<OutArcIt, Digraph, Node> outArcs(const Node& u) const { 277 return LemonRangeWrapper2<OutArcIt, Digraph, Node>(*this, u); 278 } 279 280 240 281 /// Iterator class for the incoming arcs of a node. 241 282 242 283 /// This iterator goes trough the \e incoming arcs of a certain node … … 282 323 InArcIt& operator++() { return *this; } 283 324 }; 284 325 326 /// \brief Gets the collection of the incoming arcs of a certain node 327 /// of the digraph. 328 /// 329 /// This function can be used for iterating on the 330 /// incoming arcs of a certain node of the digraph. It returns a wrapped 331 /// InArcIt, which looks like an STL container 332 /// (by having begin() and end()) which you can use in range-based 333 /// for loops, STL algorithms, etc. 334 /// For example if g is a Digraph and u is a node, you can write: 335 ///\code 336 /// for(auto a: g.inArcs(u)) 337 /// doSomething(a); 338 /// 339 /// //Using an STL algorithm: 340 /// copy(g.inArcs(u).begin(), g.inArcs(u).end(), vect.begin()); 341 ///\endcode 342 LemonRangeWrapper2<InArcIt, Digraph, Node> inArcs(const Node& u) const { 343 return LemonRangeWrapper2<InArcIt, Digraph, Node>(*this, u); 344 } 345 346 285 347 /// Iterator class for the arcs. 286 348 287 349 /// This iterator goes through each arc of the digraph. … … 327 389 ArcIt& operator++() { return *this; } 328 390 }; 329 391 392 /// \brief Gets the collection of the arcs of the digraph. 393 /// 394 /// This function can be used for iterating on the 395 /// arcs of the digraph. It returns a wrapped 396 /// ArcIt, which looks like an STL container 397 /// (by having begin() and end()) which you can use in range-based 398 /// for loops, STL algorithms, etc. 399 /// For example you can write: 400 ///\code 401 /// ListDigraph g; 402 /// for(auto a: g.arcs()) 403 /// doSomething(a); 404 /// 405 /// //Using an STL algorithm: 406 /// copy(g.arcs().begin(), g.arcs().end(), vect.begin()); 407 ///\endcode 408 LemonRangeWrapper1<ArcIt, Digraph> arcs() const { 409 return LemonRangeWrapper1<ArcIt, Digraph>(*this); 410 } 411 412 330 413 /// \brief The source node of the arc. 331 414 /// 332 415 /// Returns the source node of the given arc. -
lemon/concepts/graph.h
diff --git a/lemon/concepts/graph.h b/lemon/concepts/graph.h
a b 27 27 #include <lemon/concepts/maps.h> 28 28 #include <lemon/concept_check.h> 29 29 #include <lemon/core.h> 30 #include <lemon/bits/stl_iterators.h> 30 31 31 32 namespace lemon { 32 33 namespace concepts { … … 180 181 NodeIt& operator++() { return *this; } 181 182 }; 182 183 184 /// \brief Gets the collection of the nodes of the graph. 185 /// 186 /// This function can be used for iterating on 187 /// the nodes of the graph. It returns a wrapped NodeIt, which looks 188 /// like an STL container (by having begin() and end()) 189 /// which you can use in range-based for loops, STL algorithms, etc. 190 /// For example you can write: 191 ///\code 192 /// ListGraph g; 193 /// for(auto v: g.nodes()) 194 /// doSomething(v); 195 /// 196 /// //Using an STL algorithm: 197 /// copy(g.nodes().begin(), g.nodes().end(), vect.begin()); 198 ///\endcode 199 LemonRangeWrapper1<NodeIt, Graph> nodes() const { 200 return LemonRangeWrapper1<NodeIt, Graph>(*this); 201 } 202 183 203 184 204 /// The edge type of the graph 185 205 … … 268 288 EdgeIt& operator++() { return *this; } 269 289 }; 270 290 291 /// \brief Gets the collection of the edges of the graph. 292 /// 293 /// This function can be used for iterating on the 294 /// edges of the graph. It returns a wrapped 295 /// EdgeIt, which looks like an STL container 296 /// (by having begin() and end()) which you can use in range-based 297 /// for loops, STL algorithms, etc. 298 /// For example you can write: 299 ///\code 300 /// ListGraph g; 301 /// for(auto e: g.edges()) 302 /// doSomething(e); 303 /// 304 /// //Using an STL algorithm: 305 /// copy(g.edges().begin(), g.edges().end(), vect.begin()); 306 ///\endcode 307 LemonRangeWrapper1<EdgeIt, Graph> edges() const { 308 return LemonRangeWrapper1<EdgeIt, Graph>(*this); 309 } 310 311 271 312 /// Iterator class for the incident edges of a node. 272 313 273 314 /// This iterator goes trough the incident undirected edges … … 316 357 IncEdgeIt& operator++() { return *this; } 317 358 }; 318 359 360 /// \brief Gets the collection of the incident undirected edges 361 /// of a certain node of the graph. 362 /// 363 /// This function can be used for iterating on the 364 /// incident undirected edges of a certain node of the graph. 365 /// It returns a wrapped 366 /// IncEdgeIt, which looks like an STL container 367 /// (by having begin() and end()) which you can use in range-based 368 /// for loops, STL algorithms, etc. 369 /// For example if g is a Graph and u is a Node, you can write: 370 ///\code 371 /// for(auto e: g.incEdges(u)) 372 /// doSomething(e); 373 /// 374 /// //Using an STL algorithm: 375 /// copy(g.incEdges(u).begin(), g.incEdges(u).end(), vect.begin()); 376 ///\endcode 377 LemonRangeWrapper2<IncEdgeIt, Graph, Node> incEdges(const Node& u) const { 378 return LemonRangeWrapper2<IncEdgeIt, Graph, Node>(*this, u); 379 } 380 381 319 382 /// The arc type of the graph 320 383 321 384 /// This class identifies a directed arc of the graph. It also serves … … 411 474 ArcIt& operator++() { return *this; } 412 475 }; 413 476 477 /// \brief Gets the collection of the directed arcs of the graph. 478 /// 479 /// This function can be used for iterating on the 480 /// arcs of the graph. It returns a wrapped 481 /// ArcIt, which looks like an STL container 482 /// (by having begin() and end()) which you can use in range-based 483 /// for loops, STL algorithms, etc. 484 /// For example you can write: 485 ///\code 486 /// ListGraph g; 487 /// for(auto a: g.arcs()) 488 /// doSomething(a); 489 /// 490 /// //Using an STL algorithm: 491 /// copy(g.arcs().begin(), g.arcs().end(), vect.begin()); 492 ///\endcode 493 LemonRangeWrapper1<ArcIt, Graph> arcs() const { 494 return LemonRangeWrapper1<ArcIt, Graph>(*this); 495 } 496 497 414 498 /// Iterator class for the outgoing arcs of a node. 415 499 416 500 /// This iterator goes trough the \e outgoing directed arcs of a … … 459 543 OutArcIt& operator++() { return *this; } 460 544 }; 461 545 546 /// \brief Gets the collection of the outgoing directed arcs of a 547 /// certain node of the graph. 548 /// 549 /// This function can be used for iterating on the 550 /// outgoing arcs of a certain node of the graph. It returns a wrapped 551 /// OutArcIt, which looks like an STL container 552 /// (by having begin() and end()) which you can use in range-based 553 /// for loops, STL algorithms, etc. 554 /// For example if g is a Graph and u is a Node, you can write: 555 ///\code 556 /// for(auto a: g.outArcs(u)) 557 /// doSomething(a); 558 /// 559 /// //Using an STL algorithm: 560 /// copy(g.outArcs(u).begin(), g.outArcs(u).end(), vect.begin()); 561 ///\endcode 562 LemonRangeWrapper2<OutArcIt, Graph, Node> outArcs(const Node& u) const { 563 return LemonRangeWrapper2<OutArcIt, Graph, Node>(*this, u); 564 } 565 566 462 567 /// Iterator class for the incoming arcs of a node. 463 568 464 569 /// This iterator goes trough the \e incoming directed arcs of a … … 507 612 InArcIt& operator++() { return *this; } 508 613 }; 509 614 615 /// \brief Gets the collection of the incoming directed arcs of 616 /// a certain node of the graph. 617 /// 618 /// This function can be used for iterating on the 619 /// incoming directed arcs of a certain node of the graph. It returns 620 /// a wrapped InArcIt, which looks like an STL container 621 /// (by having begin() and end()) which you can use in range-based 622 /// for loops, STL algorithms, etc. 623 /// For example if g is a Graph and u is a Node, you can write: 624 ///\code 625 /// for(auto a: g.inArcs(u)) 626 /// doSomething(a); 627 /// 628 /// //Using an STL algorithm: 629 /// copy(g.inArcs(u).begin(), g.inArcs(u).end(), vect.begin()); 630 ///\endcode 631 LemonRangeWrapper2<InArcIt, Graph, Node> inArcs(const Node& u) const { 632 return LemonRangeWrapper2<InArcIt, Graph, Node>(*this, u); 633 } 634 510 635 /// \brief Standard graph map type for the nodes. 511 636 /// 512 637 /// Standard graph map type for the nodes. -
lemon/concepts/path.h
diff --git a/lemon/concepts/path.h b/lemon/concepts/path.h
a b 26 26 27 27 #include <lemon/core.h> 28 28 #include <lemon/concept_check.h> 29 #include <lemon/bits/stl_iterators.h> 29 30 30 31 namespace lemon { 31 32 namespace concepts { … … 115 116 116 117 }; 117 118 119 /// \brief Gets the collection of the arcs of the path. 120 /// 121 /// This function can be used for iterating on the 122 /// arcs of the path. It returns a wrapped 123 /// ArcIt, which looks like an STL container 124 /// (by having begin() and end()) which you can use in range-based 125 /// for loops, STL algorithms, etc. 126 /// For example you can write: 127 ///\code 128 /// for(auto a: p.arcs()) 129 /// doSomething(a); 130 ///\endcode 131 LemonRangeWrapper1<ArcIt, Path> arcs() const { 132 return LemonRangeWrapper1<ArcIt, Path>(*this); 133 } 134 135 118 136 template <typename _Path> 119 137 struct Constraints { 120 138 void constraints() { … … 264 282 265 283 }; 266 284 285 /// \brief Gets the collection of the arcs of the path. 286 /// 287 /// This function can be used for iterating on the 288 /// arcs of the path. It returns a wrapped 289 /// ArcIt, which looks like an STL container 290 /// (by having begin() and end()) which you can use in range-based 291 /// for loops, STL algorithms, etc. 292 /// For example you can write: 293 ///\code 294 /// for(auto a: p.arcs()) 295 /// doSomething(a); 296 ///\endcode 297 LemonRangeWrapper1<ArcIt, PathDumper> arcs() const { 298 return LemonRangeWrapper1<ArcIt, PathDumper>(*this); 299 } 300 301 267 302 /// \brief LEMON style iterator for enumerating the arcs of a path 268 303 /// in reverse direction. 269 304 /// … … 293 328 294 329 }; 295 330 331 /// \brief Gets the collection of the arcs of the path 332 /// in reverse direction. 333 /// 334 /// This function can be used for iterating on the 335 /// arcs of the path in reverse direction. It returns a wrapped 336 /// RevArcIt, which looks like an STL container 337 /// (by having begin() and end()) which you can use in range-based 338 /// for loops, STL algorithms, etc. 339 /// For example you can write: 340 ///\code 341 /// for(auto a: p.revArcs()) 342 /// doSomething(a); 343 ///\endcode 344 LemonRangeWrapper1<RevArcIt, PathDumper> revArcs() const { 345 return LemonRangeWrapper1<RevArcIt, PathDumper>(*this); 346 } 347 348 296 349 template <typename _Path> 297 350 struct Constraints { 298 351 void constraints() { -
lemon/cplex.cc
diff --git a/lemon/cplex.cc b/lemon/cplex.cc
a b 87 87 : LpBase() { 88 88 int status; 89 89 _prob = CPXcloneprob(cplexEnv(), cplex._prob, &status); 90 rows = cplex.rows;91 cols = cplex.cols;90 _rows = cplex._rows; 91 _cols = cplex._cols; 92 92 messageLevel(MESSAGE_NOTHING); 93 93 } 94 94 … … 158 158 } 159 159 160 160 void CplexBase::_eraseColId(int i) { 161 cols.eraseIndex(i);162 cols.shiftIndices(i);161 _cols.eraseIndex(i); 162 _cols.shiftIndices(i); 163 163 } 164 164 void CplexBase::_eraseRowId(int i) { 165 rows.eraseIndex(i);166 rows.shiftIndices(i);165 _rows.eraseIndex(i); 166 _rows.shiftIndices(i); 167 167 } 168 168 169 169 void CplexBase::_getColName(int col, std::string &name) const { -
lemon/glpk.cc
diff --git a/lemon/glpk.cc b/lemon/glpk.cc
a b 38 38 lp = glp_create_prob(); 39 39 glp_copy_prob(lp, other.lp, GLP_ON); 40 40 glp_create_index(lp); 41 rows = other.rows;42 cols = other.cols;41 _rows = other._rows; 42 _cols = other._cols; 43 43 messageLevel(MESSAGE_NOTHING); 44 44 } 45 45 … … 108 108 } 109 109 110 110 void GlpkBase::_eraseColId(int i) { 111 cols.eraseIndex(i);112 cols.shiftIndices(i);111 _cols.eraseIndex(i); 112 _cols.shiftIndices(i); 113 113 } 114 114 115 115 void GlpkBase::_eraseRowId(int i) { 116 rows.eraseIndex(i);117 rows.shiftIndices(i);116 _rows.eraseIndex(i); 117 _rows.shiftIndices(i); 118 118 } 119 119 120 120 void GlpkBase::_getColName(int c, std::string& name) const { -
lemon/glpk.h
diff --git a/lemon/glpk.h b/lemon/glpk.h
a b 141 141 _solver_bits::VoidPtr lpx() const {return lp;} 142 142 143 143 ///Returns the constraint identifier understood by GLPK. 144 int lpxRow(Row r) const { return rows(id(r)); }144 int lpxRow(Row r) const { return _rows(id(r)); } 145 145 146 146 ///Returns the variable identifier understood by GLPK. 147 int lpxCol(Col c) const { return cols(id(c)); }147 int lpxCol(Col c) const { return _cols(id(c)); } 148 148 149 149 #ifdef DOXYGEN 150 150 /// Write the problem or the solution to a file in the given format -
lemon/list_graph.h
diff --git a/lemon/list_graph.h b/lemon/list_graph.h
a b 48 48 int next_in, next_out; 49 49 }; 50 50 51 std::vector<NodeT> nodes;51 std::vector<NodeT> _nodes; 52 52 53 53 int first_node; 54 54 55 55 int first_free_node; 56 56 57 std::vector<ArcT> arcs;57 std::vector<ArcT> _arcs; 58 58 59 59 int first_free_arc; 60 60 … … 97 97 98 98 99 99 ListDigraphBase() 100 : nodes(), first_node(-1),101 first_free_node(-1), arcs(), first_free_arc(-1) {}102 103 104 int maxNodeId() const { return nodes.size()-1; }105 int maxArcId() const { return arcs.size()-1; }106 107 Node source(Arc e) const { return Node( arcs[e.id].source); }108 Node target(Arc e) const { return Node( arcs[e.id].target); }100 : _nodes(), first_node(-1), 101 first_free_node(-1), _arcs(), first_free_arc(-1) {} 102 103 104 int maxNodeId() const { return _nodes.size()-1; } 105 int maxArcId() const { return _arcs.size()-1; } 106 107 Node source(Arc e) const { return Node(_arcs[e.id].source); } 108 Node target(Arc e) const { return Node(_arcs[e.id].target); } 109 109 110 110 111 111 void first(Node& node) const { … … 113 113 } 114 114 115 115 void next(Node& node) const { 116 node.id = nodes[node.id].next;116 node.id = _nodes[node.id].next; 117 117 } 118 118 119 119 120 120 void first(Arc& arc) const { 121 121 int n; 122 122 for(n = first_node; 123 n != -1 && nodes[n].first_out == -1;124 n = nodes[n].next) {}125 arc.id = (n == -1) ? -1 : nodes[n].first_out;123 n != -1 && _nodes[n].first_out == -1; 124 n = _nodes[n].next) {} 125 arc.id = (n == -1) ? -1 : _nodes[n].first_out; 126 126 } 127 127 128 128 void next(Arc& arc) const { 129 if ( arcs[arc.id].next_out != -1) {130 arc.id = arcs[arc.id].next_out;129 if (_arcs[arc.id].next_out != -1) { 130 arc.id = _arcs[arc.id].next_out; 131 131 } else { 132 132 int n; 133 for(n = nodes[arcs[arc.id].source].next;134 n != -1 && nodes[n].first_out == -1;135 n = nodes[n].next) {}136 arc.id = (n == -1) ? -1 : nodes[n].first_out;133 for(n = _nodes[_arcs[arc.id].source].next; 134 n != -1 && _nodes[n].first_out == -1; 135 n = _nodes[n].next) {} 136 arc.id = (n == -1) ? -1 : _nodes[n].first_out; 137 137 } 138 138 } 139 139 140 140 void firstOut(Arc &e, const Node& v) const { 141 e.id = nodes[v.id].first_out;141 e.id = _nodes[v.id].first_out; 142 142 } 143 143 void nextOut(Arc &e) const { 144 e.id= arcs[e.id].next_out;144 e.id=_arcs[e.id].next_out; 145 145 } 146 146 147 147 void firstIn(Arc &e, const Node& v) const { 148 e.id = nodes[v.id].first_in;148 e.id = _nodes[v.id].first_in; 149 149 } 150 150 void nextIn(Arc &e) const { 151 e.id= arcs[e.id].next_in;151 e.id=_arcs[e.id].next_in; 152 152 } 153 153 154 154 … … 159 159 static Arc arcFromId(int id) { return Arc(id);} 160 160 161 161 bool valid(Node n) const { 162 return n.id >= 0 && n.id < static_cast<int>( nodes.size()) &&163 nodes[n.id].prev != -2;162 return n.id >= 0 && n.id < static_cast<int>(_nodes.size()) && 163 _nodes[n.id].prev != -2; 164 164 } 165 165 166 166 bool valid(Arc a) const { 167 return a.id >= 0 && a.id < static_cast<int>( arcs.size()) &&168 arcs[a.id].prev_in != -2;167 return a.id >= 0 && a.id < static_cast<int>(_arcs.size()) && 168 _arcs[a.id].prev_in != -2; 169 169 } 170 170 171 171 Node addNode() { 172 172 int n; 173 173 174 174 if(first_free_node==-1) { 175 n = nodes.size();176 nodes.push_back(NodeT());175 n = _nodes.size(); 176 _nodes.push_back(NodeT()); 177 177 } else { 178 178 n = first_free_node; 179 first_free_node = nodes[n].next;179 first_free_node = _nodes[n].next; 180 180 } 181 181 182 nodes[n].next = first_node;183 if(first_node != -1) nodes[first_node].prev = n;182 _nodes[n].next = first_node; 183 if(first_node != -1) _nodes[first_node].prev = n; 184 184 first_node = n; 185 nodes[n].prev = -1;186 187 nodes[n].first_in =nodes[n].first_out = -1;185 _nodes[n].prev = -1; 186 187 _nodes[n].first_in = _nodes[n].first_out = -1; 188 188 189 189 return Node(n); 190 190 } … … 193 193 int n; 194 194 195 195 if (first_free_arc == -1) { 196 n = arcs.size();197 arcs.push_back(ArcT());196 n = _arcs.size(); 197 _arcs.push_back(ArcT()); 198 198 } else { 199 199 n = first_free_arc; 200 first_free_arc = arcs[n].next_in;200 first_free_arc = _arcs[n].next_in; 201 201 } 202 202 203 arcs[n].source = u.id;204 arcs[n].target = v.id;205 206 arcs[n].next_out =nodes[u.id].first_out;207 if( nodes[u.id].first_out != -1) {208 arcs[nodes[u.id].first_out].prev_out = n;203 _arcs[n].source = u.id; 204 _arcs[n].target = v.id; 205 206 _arcs[n].next_out = _nodes[u.id].first_out; 207 if(_nodes[u.id].first_out != -1) { 208 _arcs[_nodes[u.id].first_out].prev_out = n; 209 209 } 210 210 211 arcs[n].next_in =nodes[v.id].first_in;212 if( nodes[v.id].first_in != -1) {213 arcs[nodes[v.id].first_in].prev_in = n;211 _arcs[n].next_in = _nodes[v.id].first_in; 212 if(_nodes[v.id].first_in != -1) { 213 _arcs[_nodes[v.id].first_in].prev_in = n; 214 214 } 215 215 216 arcs[n].prev_in =arcs[n].prev_out = -1;217 218 nodes[u.id].first_out =nodes[v.id].first_in = n;216 _arcs[n].prev_in = _arcs[n].prev_out = -1; 217 218 _nodes[u.id].first_out = _nodes[v.id].first_in = n; 219 219 220 220 return Arc(n); 221 221 } … … 223 223 void erase(const Node& node) { 224 224 int n = node.id; 225 225 226 if( nodes[n].next != -1) {227 nodes[nodes[n].next].prev =nodes[n].prev;226 if(_nodes[n].next != -1) { 227 _nodes[_nodes[n].next].prev = _nodes[n].prev; 228 228 } 229 229 230 if( nodes[n].prev != -1) {231 nodes[nodes[n].prev].next =nodes[n].next;230 if(_nodes[n].prev != -1) { 231 _nodes[_nodes[n].prev].next = _nodes[n].next; 232 232 } else { 233 first_node = nodes[n].next;233 first_node = _nodes[n].next; 234 234 } 235 235 236 nodes[n].next = first_free_node;236 _nodes[n].next = first_free_node; 237 237 first_free_node = n; 238 nodes[n].prev = -2;238 _nodes[n].prev = -2; 239 239 240 240 } 241 241 242 242 void erase(const Arc& arc) { 243 243 int n = arc.id; 244 244 245 if( arcs[n].next_in!=-1) {246 arcs[arcs[n].next_in].prev_in =arcs[n].prev_in;245 if(_arcs[n].next_in!=-1) { 246 _arcs[_arcs[n].next_in].prev_in = _arcs[n].prev_in; 247 247 } 248 248 249 if( arcs[n].prev_in!=-1) {250 arcs[arcs[n].prev_in].next_in =arcs[n].next_in;249 if(_arcs[n].prev_in!=-1) { 250 _arcs[_arcs[n].prev_in].next_in = _arcs[n].next_in; 251 251 } else { 252 nodes[arcs[n].target].first_in =arcs[n].next_in;252 _nodes[_arcs[n].target].first_in = _arcs[n].next_in; 253 253 } 254 254 255 255 256 if( arcs[n].next_out!=-1) {257 arcs[arcs[n].next_out].prev_out =arcs[n].prev_out;256 if(_arcs[n].next_out!=-1) { 257 _arcs[_arcs[n].next_out].prev_out = _arcs[n].prev_out; 258 258 } 259 259 260 if( arcs[n].prev_out!=-1) {261 arcs[arcs[n].prev_out].next_out =arcs[n].next_out;260 if(_arcs[n].prev_out!=-1) { 261 _arcs[_arcs[n].prev_out].next_out = _arcs[n].next_out; 262 262 } else { 263 nodes[arcs[n].source].first_out =arcs[n].next_out;263 _nodes[_arcs[n].source].first_out = _arcs[n].next_out; 264 264 } 265 265 266 arcs[n].next_in = first_free_arc;266 _arcs[n].next_in = first_free_arc; 267 267 first_free_arc = n; 268 arcs[n].prev_in = -2;268 _arcs[n].prev_in = -2; 269 269 } 270 270 271 271 void clear() { 272 arcs.clear();273 nodes.clear();272 _arcs.clear(); 273 _nodes.clear(); 274 274 first_node = first_free_node = first_free_arc = -1; 275 275 } 276 276 277 277 protected: 278 278 void changeTarget(Arc e, Node n) 279 279 { 280 if( arcs[e.id].next_in != -1)281 arcs[arcs[e.id].next_in].prev_in =arcs[e.id].prev_in;282 if( arcs[e.id].prev_in != -1)283 arcs[arcs[e.id].prev_in].next_in =arcs[e.id].next_in;284 else nodes[arcs[e.id].target].first_in =arcs[e.id].next_in;285 if ( nodes[n.id].first_in != -1) {286 arcs[nodes[n.id].first_in].prev_in = e.id;280 if(_arcs[e.id].next_in != -1) 281 _arcs[_arcs[e.id].next_in].prev_in = _arcs[e.id].prev_in; 282 if(_arcs[e.id].prev_in != -1) 283 _arcs[_arcs[e.id].prev_in].next_in = _arcs[e.id].next_in; 284 else _nodes[_arcs[e.id].target].first_in = _arcs[e.id].next_in; 285 if (_nodes[n.id].first_in != -1) { 286 _arcs[_nodes[n.id].first_in].prev_in = e.id; 287 287 } 288 arcs[e.id].target = n.id;289 arcs[e.id].prev_in = -1;290 arcs[e.id].next_in =nodes[n.id].first_in;291 nodes[n.id].first_in = e.id;288 _arcs[e.id].target = n.id; 289 _arcs[e.id].prev_in = -1; 290 _arcs[e.id].next_in = _nodes[n.id].first_in; 291 _nodes[n.id].first_in = e.id; 292 292 } 293 293 void changeSource(Arc e, Node n) 294 294 { 295 if( arcs[e.id].next_out != -1)296 arcs[arcs[e.id].next_out].prev_out =arcs[e.id].prev_out;297 if( arcs[e.id].prev_out != -1)298 arcs[arcs[e.id].prev_out].next_out =arcs[e.id].next_out;299 else nodes[arcs[e.id].source].first_out =arcs[e.id].next_out;300 if ( nodes[n.id].first_out != -1) {301 arcs[nodes[n.id].first_out].prev_out = e.id;295 if(_arcs[e.id].next_out != -1) 296 _arcs[_arcs[e.id].next_out].prev_out = _arcs[e.id].prev_out; 297 if(_arcs[e.id].prev_out != -1) 298 _arcs[_arcs[e.id].prev_out].next_out = _arcs[e.id].next_out; 299 else _nodes[_arcs[e.id].source].first_out = _arcs[e.id].next_out; 300 if (_nodes[n.id].first_out != -1) { 301 _arcs[_nodes[n.id].first_out].prev_out = e.id; 302 302 } 303 arcs[e.id].source = n.id;304 arcs[e.id].prev_out = -1;305 arcs[e.id].next_out =nodes[n.id].first_out;306 nodes[n.id].first_out = e.id;303 _arcs[e.id].source = n.id; 304 _arcs[e.id].prev_out = -1; 305 _arcs[e.id].next_out = _nodes[n.id].first_out; 306 _nodes[n.id].first_out = e.id; 307 307 } 308 308 309 309 }; … … 486 486 ///Snapshot feature. 487 487 Node split(Node n, bool connect = true) { 488 488 Node b = addNode(); 489 nodes[b.id].first_out=nodes[n.id].first_out;490 nodes[n.id].first_out=-1;491 for(int i= nodes[b.id].first_out; i!=-1; i=arcs[i].next_out) {492 arcs[i].source=b.id;489 _nodes[b.id].first_out=_nodes[n.id].first_out; 490 _nodes[n.id].first_out=-1; 491 for(int i=_nodes[b.id].first_out; i!=-1; i=_arcs[i].next_out) { 492 _arcs[i].source=b.id; 493 493 } 494 494 if (connect) addArc(n,b); 495 495 return b; … … 532 532 /// then it is worth reserving space for this amount before starting 533 533 /// to build the digraph. 534 534 /// \sa reserveArc() 535 void reserveNode(int n) { nodes.reserve(n); };535 void reserveNode(int n) { _nodes.reserve(n); }; 536 536 537 537 /// Reserve memory for arcs. 538 538 … … 542 542 /// then it is worth reserving space for this amount before starting 543 543 /// to build the digraph. 544 544 /// \sa reserveNode() 545 void reserveArc(int m) { arcs.reserve(m); };545 void reserveArc(int m) { _arcs.reserve(m); }; 546 546 547 547 /// \brief Class to make a snapshot of the digraph and restore 548 548 /// it later. … … 803 803 int prev_out, next_out; 804 804 }; 805 805 806 std::vector<NodeT> nodes;806 std::vector<NodeT> _nodes; 807 807 808 808 int first_node; 809 809 810 810 int first_free_node; 811 811 812 std::vector<ArcT> arcs;812 std::vector<ArcT> _arcs; 813 813 814 814 int first_free_arc; 815 815 … … 867 867 }; 868 868 869 869 ListGraphBase() 870 : nodes(), first_node(-1),871 first_free_node(-1), arcs(), first_free_arc(-1) {}872 873 874 int maxNodeId() const { return nodes.size()-1; }875 int maxEdgeId() const { return arcs.size() / 2 - 1; }876 int maxArcId() const { return arcs.size()-1; }877 878 Node source(Arc e) const { return Node( arcs[e.id ^ 1].target); }879 Node target(Arc e) const { return Node( arcs[e.id].target); }880 881 Node u(Edge e) const { return Node( arcs[2 * e.id].target); }882 Node v(Edge e) const { return Node( arcs[2 * e.id + 1].target); }870 : _nodes(), first_node(-1), 871 first_free_node(-1), _arcs(), first_free_arc(-1) {} 872 873 874 int maxNodeId() const { return _nodes.size()-1; } 875 int maxEdgeId() const { return _arcs.size() / 2 - 1; } 876 int maxArcId() const { return _arcs.size()-1; } 877 878 Node source(Arc e) const { return Node(_arcs[e.id ^ 1].target); } 879 Node target(Arc e) const { return Node(_arcs[e.id].target); } 880 881 Node u(Edge e) const { return Node(_arcs[2 * e.id].target); } 882 Node v(Edge e) const { return Node(_arcs[2 * e.id + 1].target); } 883 883 884 884 static bool direction(Arc e) { 885 885 return (e.id & 1) == 1; … … 894 894 } 895 895 896 896 void next(Node& node) const { 897 node.id = nodes[node.id].next;897 node.id = _nodes[node.id].next; 898 898 } 899 899 900 900 void first(Arc& e) const { 901 901 int n = first_node; 902 while (n != -1 && nodes[n].first_out == -1) {903 n = nodes[n].next;902 while (n != -1 && _nodes[n].first_out == -1) { 903 n = _nodes[n].next; 904 904 } 905 e.id = (n == -1) ? -1 : nodes[n].first_out;905 e.id = (n == -1) ? -1 : _nodes[n].first_out; 906 906 } 907 907 908 908 void next(Arc& e) const { 909 if ( arcs[e.id].next_out != -1) {910 e.id = arcs[e.id].next_out;909 if (_arcs[e.id].next_out != -1) { 910 e.id = _arcs[e.id].next_out; 911 911 } else { 912 int n = nodes[arcs[e.id ^ 1].target].next;913 while(n != -1 && nodes[n].first_out == -1) {914 n = nodes[n].next;912 int n = _nodes[_arcs[e.id ^ 1].target].next; 913 while(n != -1 && _nodes[n].first_out == -1) { 914 n = _nodes[n].next; 915 915 } 916 e.id = (n == -1) ? -1 : nodes[n].first_out;916 e.id = (n == -1) ? -1 : _nodes[n].first_out; 917 917 } 918 918 } 919 919 920 920 void first(Edge& e) const { 921 921 int n = first_node; 922 922 while (n != -1) { 923 e.id = nodes[n].first_out;923 e.id = _nodes[n].first_out; 924 924 while ((e.id & 1) != 1) { 925 e.id = arcs[e.id].next_out;925 e.id = _arcs[e.id].next_out; 926 926 } 927 927 if (e.id != -1) { 928 928 e.id /= 2; 929 929 return; 930 930 } 931 n = nodes[n].next;931 n = _nodes[n].next; 932 932 } 933 933 e.id = -1; 934 934 } 935 935 936 936 void next(Edge& e) const { 937 int n = arcs[e.id * 2].target;938 e.id = arcs[(e.id * 2) | 1].next_out;937 int n = _arcs[e.id * 2].target; 938 e.id = _arcs[(e.id * 2) | 1].next_out; 939 939 while ((e.id & 1) != 1) { 940 e.id = arcs[e.id].next_out;940 e.id = _arcs[e.id].next_out; 941 941 } 942 942 if (e.id != -1) { 943 943 e.id /= 2; 944 944 return; 945 945 } 946 n = nodes[n].next;946 n = _nodes[n].next; 947 947 while (n != -1) { 948 e.id = nodes[n].first_out;948 e.id = _nodes[n].first_out; 949 949 while ((e.id & 1) != 1) { 950 e.id = arcs[e.id].next_out;950 e.id = _arcs[e.id].next_out; 951 951 } 952 952 if (e.id != -1) { 953 953 e.id /= 2; 954 954 return; 955 955 } 956 n = nodes[n].next;956 n = _nodes[n].next; 957 957 } 958 958 e.id = -1; 959 959 } 960 960 961 961 void firstOut(Arc &e, const Node& v) const { 962 e.id = nodes[v.id].first_out;962 e.id = _nodes[v.id].first_out; 963 963 } 964 964 void nextOut(Arc &e) const { 965 e.id = arcs[e.id].next_out;965 e.id = _arcs[e.id].next_out; 966 966 } 967 967 968 968 void firstIn(Arc &e, const Node& v) const { 969 e.id = (( nodes[v.id].first_out) ^ 1);969 e.id = ((_nodes[v.id].first_out) ^ 1); 970 970 if (e.id == -2) e.id = -1; 971 971 } 972 972 void nextIn(Arc &e) const { 973 e.id = (( arcs[e.id ^ 1].next_out) ^ 1);973 e.id = ((_arcs[e.id ^ 1].next_out) ^ 1); 974 974 if (e.id == -2) e.id = -1; 975 975 } 976 976 977 977 void firstInc(Edge &e, bool& d, const Node& v) const { 978 int a = nodes[v.id].first_out;978 int a = _nodes[v.id].first_out; 979 979 if (a != -1 ) { 980 980 e.id = a / 2; 981 981 d = ((a & 1) == 1); … … 985 985 } 986 986 } 987 987 void nextInc(Edge &e, bool& d) const { 988 int a = ( arcs[(e.id * 2) | (d ? 1 : 0)].next_out);988 int a = (_arcs[(e.id * 2) | (d ? 1 : 0)].next_out); 989 989 if (a != -1 ) { 990 990 e.id = a / 2; 991 991 d = ((a & 1) == 1); … … 1004 1004 static Edge edgeFromId(int id) { return Edge(id);} 1005 1005 1006 1006 bool valid(Node n) const { 1007 return n.id >= 0 && n.id < static_cast<int>( nodes.size()) &&1008 nodes[n.id].prev != -2;1007 return n.id >= 0 && n.id < static_cast<int>(_nodes.size()) && 1008 _nodes[n.id].prev != -2; 1009 1009 } 1010 1010 1011 1011 bool valid(Arc a) const { 1012 return a.id >= 0 && a.id < static_cast<int>( arcs.size()) &&1013 arcs[a.id].prev_out != -2;1012 return a.id >= 0 && a.id < static_cast<int>(_arcs.size()) && 1013 _arcs[a.id].prev_out != -2; 1014 1014 } 1015 1015 1016 1016 bool valid(Edge e) const { 1017 return e.id >= 0 && 2 * e.id < static_cast<int>( arcs.size()) &&1018 arcs[2 * e.id].prev_out != -2;1017 return e.id >= 0 && 2 * e.id < static_cast<int>(_arcs.size()) && 1018 _arcs[2 * e.id].prev_out != -2; 1019 1019 } 1020 1020 1021 1021 Node addNode() { 1022 1022 int n; 1023 1023 1024 1024 if(first_free_node==-1) { 1025 n = nodes.size();1026 nodes.push_back(NodeT());1025 n = _nodes.size(); 1026 _nodes.push_back(NodeT()); 1027 1027 } else { 1028 1028 n = first_free_node; 1029 first_free_node = nodes[n].next;1029 first_free_node = _nodes[n].next; 1030 1030 } 1031 1031 1032 nodes[n].next = first_node;1033 if (first_node != -1) nodes[first_node].prev = n;1032 _nodes[n].next = first_node; 1033 if (first_node != -1) _nodes[first_node].prev = n; 1034 1034 first_node = n; 1035 nodes[n].prev = -1;1036 1037 nodes[n].first_out = -1;1035 _nodes[n].prev = -1; 1036 1037 _nodes[n].first_out = -1; 1038 1038 1039 1039 return Node(n); 1040 1040 } … … 1043 1043 int n; 1044 1044 1045 1045 if (first_free_arc == -1) { 1046 n = arcs.size();1047 arcs.push_back(ArcT());1048 arcs.push_back(ArcT());1046 n = _arcs.size(); 1047 _arcs.push_back(ArcT()); 1048 _arcs.push_back(ArcT()); 1049 1049 } else { 1050 1050 n = first_free_arc; 1051 first_free_arc = arcs[n].next_out;1051 first_free_arc = _arcs[n].next_out; 1052 1052 } 1053 1053 1054 arcs[n].target = u.id;1055 arcs[n | 1].target = v.id;1056 1057 arcs[n].next_out =nodes[v.id].first_out;1058 if ( nodes[v.id].first_out != -1) {1059 arcs[nodes[v.id].first_out].prev_out = n;1054 _arcs[n].target = u.id; 1055 _arcs[n | 1].target = v.id; 1056 1057 _arcs[n].next_out = _nodes[v.id].first_out; 1058 if (_nodes[v.id].first_out != -1) { 1059 _arcs[_nodes[v.id].first_out].prev_out = n; 1060 1060 } 1061 arcs[n].prev_out = -1;1062 nodes[v.id].first_out = n;1063 1064 arcs[n | 1].next_out =nodes[u.id].first_out;1065 if ( nodes[u.id].first_out != -1) {1066 arcs[nodes[u.id].first_out].prev_out = (n | 1);1061 _arcs[n].prev_out = -1; 1062 _nodes[v.id].first_out = n; 1063 1064 _arcs[n | 1].next_out = _nodes[u.id].first_out; 1065 if (_nodes[u.id].first_out != -1) { 1066 _arcs[_nodes[u.id].first_out].prev_out = (n | 1); 1067 1067 } 1068 arcs[n | 1].prev_out = -1;1069 nodes[u.id].first_out = (n | 1);1068 _arcs[n | 1].prev_out = -1; 1069 _nodes[u.id].first_out = (n | 1); 1070 1070 1071 1071 return Edge(n / 2); 1072 1072 } … … 1074 1074 void erase(const Node& node) { 1075 1075 int n = node.id; 1076 1076 1077 if( nodes[n].next != -1) {1078 nodes[nodes[n].next].prev =nodes[n].prev;1077 if(_nodes[n].next != -1) { 1078 _nodes[_nodes[n].next].prev = _nodes[n].prev; 1079 1079 } 1080 1080 1081 if( nodes[n].prev != -1) {1082 nodes[nodes[n].prev].next =nodes[n].next;1081 if(_nodes[n].prev != -1) { 1082 _nodes[_nodes[n].prev].next = _nodes[n].next; 1083 1083 } else { 1084 first_node = nodes[n].next;1084 first_node = _nodes[n].next; 1085 1085 } 1086 1086 1087 nodes[n].next = first_free_node;1087 _nodes[n].next = first_free_node; 1088 1088 first_free_node = n; 1089 nodes[n].prev = -2;1089 _nodes[n].prev = -2; 1090 1090 } 1091 1091 1092 1092 void erase(const Edge& edge) { 1093 1093 int n = edge.id * 2; 1094 1094 1095 if ( arcs[n].next_out != -1) {1096 arcs[arcs[n].next_out].prev_out =arcs[n].prev_out;1095 if (_arcs[n].next_out != -1) { 1096 _arcs[_arcs[n].next_out].prev_out = _arcs[n].prev_out; 1097 1097 } 1098 1098 1099 if ( arcs[n].prev_out != -1) {1100 arcs[arcs[n].prev_out].next_out =arcs[n].next_out;1099 if (_arcs[n].prev_out != -1) { 1100 _arcs[_arcs[n].prev_out].next_out = _arcs[n].next_out; 1101 1101 } else { 1102 nodes[arcs[n | 1].target].first_out =arcs[n].next_out;1102 _nodes[_arcs[n | 1].target].first_out = _arcs[n].next_out; 1103 1103 } 1104 1104 1105 if ( arcs[n | 1].next_out != -1) {1106 arcs[arcs[n | 1].next_out].prev_out =arcs[n | 1].prev_out;1105 if (_arcs[n | 1].next_out != -1) { 1106 _arcs[_arcs[n | 1].next_out].prev_out = _arcs[n | 1].prev_out; 1107 1107 } 1108 1108 1109 if ( arcs[n | 1].prev_out != -1) {1110 arcs[arcs[n | 1].prev_out].next_out =arcs[n | 1].next_out;1109 if (_arcs[n | 1].prev_out != -1) { 1110 _arcs[_arcs[n | 1].prev_out].next_out = _arcs[n | 1].next_out; 1111 1111 } else { 1112 nodes[arcs[n].target].first_out =arcs[n | 1].next_out;1112 _nodes[_arcs[n].target].first_out = _arcs[n | 1].next_out; 1113 1113 } 1114 1114 1115 arcs[n].next_out = first_free_arc;1115 _arcs[n].next_out = first_free_arc; 1116 1116 first_free_arc = n; 1117 arcs[n].prev_out = -2;1118 arcs[n | 1].prev_out = -2;1117 _arcs[n].prev_out = -2; 1118 _arcs[n | 1].prev_out = -2; 1119 1119 1120 1120 } 1121 1121 1122 1122 void clear() { 1123 arcs.clear();1124 nodes.clear();1123 _arcs.clear(); 1124 _nodes.clear(); 1125 1125 first_node = first_free_node = first_free_arc = -1; 1126 1126 } 1127 1127 1128 1128 protected: 1129 1129 1130 1130 void changeV(Edge e, Node n) { 1131 if( arcs[2 * e.id].next_out != -1) {1132 arcs[arcs[2 * e.id].next_out].prev_out =arcs[2 * e.id].prev_out;1131 if(_arcs[2 * e.id].next_out != -1) { 1132 _arcs[_arcs[2 * e.id].next_out].prev_out = _arcs[2 * e.id].prev_out; 1133 1133 } 1134 if( arcs[2 * e.id].prev_out != -1) {1135 arcs[arcs[2 * e.id].prev_out].next_out =1136 arcs[2 * e.id].next_out;1134 if(_arcs[2 * e.id].prev_out != -1) { 1135 _arcs[_arcs[2 * e.id].prev_out].next_out = 1136 _arcs[2 * e.id].next_out; 1137 1137 } else { 1138 nodes[arcs[(2 * e.id) | 1].target].first_out =1139 arcs[2 * e.id].next_out;1138 _nodes[_arcs[(2 * e.id) | 1].target].first_out = 1139 _arcs[2 * e.id].next_out; 1140 1140 } 1141 1141 1142 if ( nodes[n.id].first_out != -1) {1143 arcs[nodes[n.id].first_out].prev_out = 2 * e.id;1142 if (_nodes[n.id].first_out != -1) { 1143 _arcs[_nodes[n.id].first_out].prev_out = 2 * e.id; 1144 1144 } 1145 arcs[(2 * e.id) | 1].target = n.id;1146 arcs[2 * e.id].prev_out = -1;1147 arcs[2 * e.id].next_out =nodes[n.id].first_out;1148 nodes[n.id].first_out = 2 * e.id;1145 _arcs[(2 * e.id) | 1].target = n.id; 1146 _arcs[2 * e.id].prev_out = -1; 1147 _arcs[2 * e.id].next_out = _nodes[n.id].first_out; 1148 _nodes[n.id].first_out = 2 * e.id; 1149 1149 } 1150 1150 1151 1151 void changeU(Edge e, Node n) { 1152 if( arcs[(2 * e.id) | 1].next_out != -1) {1153 arcs[arcs[(2 * e.id) | 1].next_out].prev_out =1154 arcs[(2 * e.id) | 1].prev_out;1152 if(_arcs[(2 * e.id) | 1].next_out != -1) { 1153 _arcs[_arcs[(2 * e.id) | 1].next_out].prev_out = 1154 _arcs[(2 * e.id) | 1].prev_out; 1155 1155 } 1156 if( arcs[(2 * e.id) | 1].prev_out != -1) {1157 arcs[arcs[(2 * e.id) | 1].prev_out].next_out =1158 arcs[(2 * e.id) | 1].next_out;1156 if(_arcs[(2 * e.id) | 1].prev_out != -1) { 1157 _arcs[_arcs[(2 * e.id) | 1].prev_out].next_out = 1158 _arcs[(2 * e.id) | 1].next_out; 1159 1159 } else { 1160 nodes[arcs[2 * e.id].target].first_out =1161 arcs[(2 * e.id) | 1].next_out;1160 _nodes[_arcs[2 * e.id].target].first_out = 1161 _arcs[(2 * e.id) | 1].next_out; 1162 1162 } 1163 1163 1164 if ( nodes[n.id].first_out != -1) {1165 arcs[nodes[n.id].first_out].prev_out = ((2 * e.id) | 1);1164 if (_nodes[n.id].first_out != -1) { 1165 _arcs[_nodes[n.id].first_out].prev_out = ((2 * e.id) | 1); 1166 1166 } 1167 arcs[2 * e.id].target = n.id;1168 arcs[(2 * e.id) | 1].prev_out = -1;1169 arcs[(2 * e.id) | 1].next_out =nodes[n.id].first_out;1170 nodes[n.id].first_out = ((2 * e.id) | 1);1167 _arcs[2 * e.id].target = n.id; 1168 _arcs[(2 * e.id) | 1].prev_out = -1; 1169 _arcs[(2 * e.id) | 1].next_out = _nodes[n.id].first_out; 1170 _nodes[n.id].first_out = ((2 * e.id) | 1); 1171 1171 } 1172 1172 1173 1173 }; … … 1344 1344 /// then it is worth reserving space for this amount before starting 1345 1345 /// to build the graph. 1346 1346 /// \sa reserveEdge() 1347 void reserveNode(int n) { nodes.reserve(n); };1347 void reserveNode(int n) { _nodes.reserve(n); }; 1348 1348 1349 1349 /// Reserve memory for edges. 1350 1350 … … 1354 1354 /// then it is worth reserving space for this amount before starting 1355 1355 /// to build the graph. 1356 1356 /// \sa reserveNode() 1357 void reserveEdge(int m) { arcs.reserve(2 * m); };1357 void reserveEdge(int m) { _arcs.reserve(2 * m); }; 1358 1358 1359 1359 /// \brief Class to make a snapshot of the graph and restore 1360 1360 /// it later. … … 1617 1617 int prev_out, next_out; 1618 1618 }; 1619 1619 1620 std::vector<NodeT> nodes;1620 std::vector<NodeT> _nodes; 1621 1621 1622 1622 int first_node, first_red, first_blue; 1623 1623 int max_red, max_blue; 1624 1624 1625 1625 int first_free_red, first_free_blue; 1626 1626 1627 std::vector<ArcT> arcs;1627 std::vector<ArcT> _arcs; 1628 1628 1629 1629 int first_free_arc; 1630 1630 … … 1706 1706 }; 1707 1707 1708 1708 ListBpGraphBase() 1709 : nodes(), first_node(-1),1709 : _nodes(), first_node(-1), 1710 1710 first_red(-1), first_blue(-1), 1711 1711 max_red(-1), max_blue(-1), 1712 1712 first_free_red(-1), first_free_blue(-1), 1713 arcs(), first_free_arc(-1) {}1714 1715 1716 bool red(Node n) const { return nodes[n.id].red; }1717 bool blue(Node n) const { return ! nodes[n.id].red; }1713 _arcs(), first_free_arc(-1) {} 1714 1715 1716 bool red(Node n) const { return _nodes[n.id].red; } 1717 bool blue(Node n) const { return !_nodes[n.id].red; } 1718 1718 1719 1719 static RedNode asRedNodeUnsafe(Node n) { return RedNode(n.id); } 1720 1720 static BlueNode asBlueNodeUnsafe(Node n) { return BlueNode(n.id); } 1721 1721 1722 int maxNodeId() const { return nodes.size()-1; }1722 int maxNodeId() const { return _nodes.size()-1; } 1723 1723 int maxRedId() const { return max_red; } 1724 1724 int maxBlueId() const { return max_blue; } 1725 int maxEdgeId() const { return arcs.size() / 2 - 1; }1726 int maxArcId() const { return arcs.size()-1; }1727 1728 Node source(Arc e) const { return Node( arcs[e.id ^ 1].target); }1729 Node target(Arc e) const { return Node( arcs[e.id].target); }1725 int maxEdgeId() const { return _arcs.size() / 2 - 1; } 1726 int maxArcId() const { return _arcs.size()-1; } 1727 1728 Node source(Arc e) const { return Node(_arcs[e.id ^ 1].target); } 1729 Node target(Arc e) const { return Node(_arcs[e.id].target); } 1730 1730 1731 1731 RedNode redNode(Edge e) const { 1732 return RedNode( arcs[2 * e.id].target);1732 return RedNode(_arcs[2 * e.id].target); 1733 1733 } 1734 1734 BlueNode blueNode(Edge e) const { 1735 return BlueNode( arcs[2 * e.id + 1].target);1735 return BlueNode(_arcs[2 * e.id + 1].target); 1736 1736 } 1737 1737 1738 1738 static bool direction(Arc e) { … … 1748 1748 } 1749 1749 1750 1750 void next(Node& node) const { 1751 node.id = nodes[node.id].next;1751 node.id = _nodes[node.id].next; 1752 1752 } 1753 1753 1754 1754 void first(RedNode& node) const { … … 1756 1756 } 1757 1757 1758 1758 void next(RedNode& node) const { 1759 node.id = nodes[node.id].partition_next;1759 node.id = _nodes[node.id].partition_next; 1760 1760 } 1761 1761 1762 1762 void first(BlueNode& node) const { … … 1764 1764 } 1765 1765 1766 1766 void next(BlueNode& node) const { 1767 node.id = nodes[node.id].partition_next;1767 node.id = _nodes[node.id].partition_next; 1768 1768 } 1769 1769 1770 1770 void first(Arc& e) const { 1771 1771 int n = first_node; 1772 while (n != -1 && nodes[n].first_out == -1) {1773 n = nodes[n].next;1772 while (n != -1 && _nodes[n].first_out == -1) { 1773 n = _nodes[n].next; 1774 1774 } 1775 e.id = (n == -1) ? -1 : nodes[n].first_out;1775 e.id = (n == -1) ? -1 : _nodes[n].first_out; 1776 1776 } 1777 1777 1778 1778 void next(Arc& e) const { 1779 if ( arcs[e.id].next_out != -1) {1780 e.id = arcs[e.id].next_out;1779 if (_arcs[e.id].next_out != -1) { 1780 e.id = _arcs[e.id].next_out; 1781 1781 } else { 1782 int n = nodes[arcs[e.id ^ 1].target].next;1783 while(n != -1 && nodes[n].first_out == -1) {1784 n = nodes[n].next;1782 int n = _nodes[_arcs[e.id ^ 1].target].next; 1783 while(n != -1 && _nodes[n].first_out == -1) { 1784 n = _nodes[n].next; 1785 1785 } 1786 e.id = (n == -1) ? -1 : nodes[n].first_out;1786 e.id = (n == -1) ? -1 : _nodes[n].first_out; 1787 1787 } 1788 1788 } 1789 1789 1790 1790 void first(Edge& e) const { 1791 1791 int n = first_node; 1792 1792 while (n != -1) { 1793 e.id = nodes[n].first_out;1793 e.id = _nodes[n].first_out; 1794 1794 while ((e.id & 1) != 1) { 1795 e.id = arcs[e.id].next_out;1795 e.id = _arcs[e.id].next_out; 1796 1796 } 1797 1797 if (e.id != -1) { 1798 1798 e.id /= 2; 1799 1799 return; 1800 1800 } 1801 n = nodes[n].next;1801 n = _nodes[n].next; 1802 1802 } 1803 1803 e.id = -1; 1804 1804 } 1805 1805 1806 1806 void next(Edge& e) const { 1807 int n = arcs[e.id * 2].target;1808 e.id = arcs[(e.id * 2) | 1].next_out;1807 int n = _arcs[e.id * 2].target; 1808 e.id = _arcs[(e.id * 2) | 1].next_out; 1809 1809 while ((e.id & 1) != 1) { 1810 e.id = arcs[e.id].next_out;1810 e.id = _arcs[e.id].next_out; 1811 1811 } 1812 1812 if (e.id != -1) { 1813 1813 e.id /= 2; 1814 1814 return; 1815 1815 } 1816 n = nodes[n].next;1816 n = _nodes[n].next; 1817 1817 while (n != -1) { 1818 e.id = nodes[n].first_out;1818 e.id = _nodes[n].first_out; 1819 1819 while ((e.id & 1) != 1) { 1820 e.id = arcs[e.id].next_out;1820 e.id = _arcs[e.id].next_out; 1821 1821 } 1822 1822 if (e.id != -1) { 1823 1823 e.id /= 2; 1824 1824 return; 1825 1825 } 1826 n = nodes[n].next;1826 n = _nodes[n].next; 1827 1827 } 1828 1828 e.id = -1; 1829 1829 } 1830 1830 1831 1831 void firstOut(Arc &e, const Node& v) const { 1832 e.id = nodes[v.id].first_out;1832 e.id = _nodes[v.id].first_out; 1833 1833 } 1834 1834 void nextOut(Arc &e) const { 1835 e.id = arcs[e.id].next_out;1835 e.id = _arcs[e.id].next_out; 1836 1836 } 1837 1837 1838 1838 void firstIn(Arc &e, const Node& v) const { 1839 e.id = (( nodes[v.id].first_out) ^ 1);1839 e.id = ((_nodes[v.id].first_out) ^ 1); 1840 1840 if (e.id == -2) e.id = -1; 1841 1841 } 1842 1842 void nextIn(Arc &e) const { 1843 e.id = (( arcs[e.id ^ 1].next_out) ^ 1);1843 e.id = ((_arcs[e.id ^ 1].next_out) ^ 1); 1844 1844 if (e.id == -2) e.id = -1; 1845 1845 } 1846 1846 1847 1847 void firstInc(Edge &e, bool& d, const Node& v) const { 1848 int a = nodes[v.id].first_out;1848 int a = _nodes[v.id].first_out; 1849 1849 if (a != -1 ) { 1850 1850 e.id = a / 2; 1851 1851 d = ((a & 1) == 1); … … 1855 1855 } 1856 1856 } 1857 1857 void nextInc(Edge &e, bool& d) const { 1858 int a = ( arcs[(e.id * 2) | (d ? 1 : 0)].next_out);1858 int a = (_arcs[(e.id * 2) | (d ? 1 : 0)].next_out); 1859 1859 if (a != -1 ) { 1860 1860 e.id = a / 2; 1861 1861 d = ((a & 1) == 1); … … 1866 1866 } 1867 1867 1868 1868 static int id(Node v) { return v.id; } 1869 int id(RedNode v) const { return nodes[v.id].partition_index; }1870 int id(BlueNode v) const { return nodes[v.id].partition_index; }1869 int id(RedNode v) const { return _nodes[v.id].partition_index; } 1870 int id(BlueNode v) const { return _nodes[v.id].partition_index; } 1871 1871 static int id(Arc e) { return e.id; } 1872 1872 static int id(Edge e) { return e.id; } 1873 1873 … … 1876 1876 static Edge edgeFromId(int id) { return Edge(id);} 1877 1877 1878 1878 bool valid(Node n) const { 1879 return n.id >= 0 && n.id < static_cast<int>( nodes.size()) &&1880 nodes[n.id].prev != -2;1879 return n.id >= 0 && n.id < static_cast<int>(_nodes.size()) && 1880 _nodes[n.id].prev != -2; 1881 1881 } 1882 1882 1883 1883 bool valid(Arc a) const { 1884 return a.id >= 0 && a.id < static_cast<int>( arcs.size()) &&1885 arcs[a.id].prev_out != -2;1884 return a.id >= 0 && a.id < static_cast<int>(_arcs.size()) && 1885 _arcs[a.id].prev_out != -2; 1886 1886 } 1887 1887 1888 1888 bool valid(Edge e) const { 1889 return e.id >= 0 && 2 * e.id < static_cast<int>( arcs.size()) &&1890 arcs[2 * e.id].prev_out != -2;1889 return e.id >= 0 && 2 * e.id < static_cast<int>(_arcs.size()) && 1890 _arcs[2 * e.id].prev_out != -2; 1891 1891 } 1892 1892 1893 1893 RedNode addRedNode() { 1894 1894 int n; 1895 1895 1896 1896 if(first_free_red==-1) { 1897 n = nodes.size();1898 nodes.push_back(NodeT());1899 nodes[n].partition_index = ++max_red;1900 nodes[n].red = true;1897 n = _nodes.size(); 1898 _nodes.push_back(NodeT()); 1899 _nodes[n].partition_index = ++max_red; 1900 _nodes[n].red = true; 1901 1901 } else { 1902 1902 n = first_free_red; 1903 first_free_red = nodes[n].next;1903 first_free_red = _nodes[n].next; 1904 1904 } 1905 1905 1906 nodes[n].next = first_node;1907 if (first_node != -1) nodes[first_node].prev = n;1906 _nodes[n].next = first_node; 1907 if (first_node != -1) _nodes[first_node].prev = n; 1908 1908 first_node = n; 1909 nodes[n].prev = -1;1910 1911 nodes[n].partition_next = first_red;1912 if (first_red != -1) nodes[first_red].partition_prev = n;1909 _nodes[n].prev = -1; 1910 1911 _nodes[n].partition_next = first_red; 1912 if (first_red != -1) _nodes[first_red].partition_prev = n; 1913 1913 first_red = n; 1914 nodes[n].partition_prev = -1;1915 1916 nodes[n].first_out = -1;1914 _nodes[n].partition_prev = -1; 1915 1916 _nodes[n].first_out = -1; 1917 1917 1918 1918 return RedNode(n); 1919 1919 } … … 1922 1922 int n; 1923 1923 1924 1924 if(first_free_blue==-1) { 1925 n = nodes.size();1926 nodes.push_back(NodeT());1927 nodes[n].partition_index = ++max_blue;1928 nodes[n].red = false;1925 n = _nodes.size(); 1926 _nodes.push_back(NodeT()); 1927 _nodes[n].partition_index = ++max_blue; 1928 _nodes[n].red = false; 1929 1929 } else { 1930 1930 n = first_free_blue; 1931 first_free_blue = nodes[n].next;1931 first_free_blue = _nodes[n].next; 1932 1932 } 1933 1933 1934 nodes[n].next = first_node;1935 if (first_node != -1) nodes[first_node].prev = n;1934 _nodes[n].next = first_node; 1935 if (first_node != -1) _nodes[first_node].prev = n; 1936 1936 first_node = n; 1937 nodes[n].prev = -1;1938 1939 nodes[n].partition_next = first_blue;1940 if (first_blue != -1) nodes[first_blue].partition_prev = n;1937 _nodes[n].prev = -1; 1938 1939 _nodes[n].partition_next = first_blue; 1940 if (first_blue != -1) _nodes[first_blue].partition_prev = n; 1941 1941 first_blue = n; 1942 nodes[n].partition_prev = -1;1943 1944 nodes[n].first_out = -1;1942 _nodes[n].partition_prev = -1; 1943 1944 _nodes[n].first_out = -1; 1945 1945 1946 1946 return BlueNode(n); 1947 1947 } … … 1950 1950 int n; 1951 1951 1952 1952 if (first_free_arc == -1) { 1953 n = arcs.size();1954 arcs.push_back(ArcT());1955 arcs.push_back(ArcT());1953 n = _arcs.size(); 1954 _arcs.push_back(ArcT()); 1955 _arcs.push_back(ArcT()); 1956 1956 } else { 1957 1957 n = first_free_arc; 1958 first_free_arc = arcs[n].next_out;1958 first_free_arc = _arcs[n].next_out; 1959 1959 } 1960 1960 1961 arcs[n].target = u.id;1962 arcs[n | 1].target = v.id;1963 1964 arcs[n].next_out =nodes[v.id].first_out;1965 if ( nodes[v.id].first_out != -1) {1966 arcs[nodes[v.id].first_out].prev_out = n;1961 _arcs[n].target = u.id; 1962 _arcs[n | 1].target = v.id; 1963 1964 _arcs[n].next_out = _nodes[v.id].first_out; 1965 if (_nodes[v.id].first_out != -1) { 1966 _arcs[_nodes[v.id].first_out].prev_out = n; 1967 1967 } 1968 arcs[n].prev_out = -1;1969 nodes[v.id].first_out = n;1970 1971 arcs[n | 1].next_out =nodes[u.id].first_out;1972 if ( nodes[u.id].first_out != -1) {1973 arcs[nodes[u.id].first_out].prev_out = (n | 1);1968 _arcs[n].prev_out = -1; 1969 _nodes[v.id].first_out = n; 1970 1971 _arcs[n | 1].next_out = _nodes[u.id].first_out; 1972 if (_nodes[u.id].first_out != -1) { 1973 _arcs[_nodes[u.id].first_out].prev_out = (n | 1); 1974 1974 } 1975 arcs[n | 1].prev_out = -1;1976 nodes[u.id].first_out = (n | 1);1975 _arcs[n | 1].prev_out = -1; 1976 _nodes[u.id].first_out = (n | 1); 1977 1977 1978 1978 return Edge(n / 2); 1979 1979 } … … 1981 1981 void erase(const Node& node) { 1982 1982 int n = node.id; 1983 1983 1984 if( nodes[n].next != -1) {1985 nodes[nodes[n].next].prev =nodes[n].prev;1984 if(_nodes[n].next != -1) { 1985 _nodes[_nodes[n].next].prev = _nodes[n].prev; 1986 1986 } 1987 1987 1988 if( nodes[n].prev != -1) {1989 nodes[nodes[n].prev].next =nodes[n].next;1988 if(_nodes[n].prev != -1) { 1989 _nodes[_nodes[n].prev].next = _nodes[n].next; 1990 1990 } else { 1991 first_node = nodes[n].next;1991 first_node = _nodes[n].next; 1992 1992 } 1993 1993 1994 if ( nodes[n].partition_next != -1) {1995 nodes[nodes[n].partition_next].partition_prev =nodes[n].partition_prev;1994 if (_nodes[n].partition_next != -1) { 1995 _nodes[_nodes[n].partition_next].partition_prev = _nodes[n].partition_prev; 1996 1996 } 1997 1997 1998 if ( nodes[n].partition_prev != -1) {1999 nodes[nodes[n].partition_prev].partition_next =nodes[n].partition_next;1998 if (_nodes[n].partition_prev != -1) { 1999 _nodes[_nodes[n].partition_prev].partition_next = _nodes[n].partition_next; 2000 2000 } else { 2001 if ( nodes[n].red) {2002 first_red = nodes[n].partition_next;2001 if (_nodes[n].red) { 2002 first_red = _nodes[n].partition_next; 2003 2003 } else { 2004 first_blue = nodes[n].partition_next;2004 first_blue = _nodes[n].partition_next; 2005 2005 } 2006 2006 } 2007 2007 2008 if ( nodes[n].red) {2009 nodes[n].next = first_free_red;2008 if (_nodes[n].red) { 2009 _nodes[n].next = first_free_red; 2010 2010 first_free_red = n; 2011 2011 } else { 2012 nodes[n].next = first_free_blue;2012 _nodes[n].next = first_free_blue; 2013 2013 first_free_blue = n; 2014 2014 } 2015 nodes[n].prev = -2;2015 _nodes[n].prev = -2; 2016 2016 } 2017 2017 2018 2018 void erase(const Edge& edge) { 2019 2019 int n = edge.id * 2; 2020 2020 2021 if ( arcs[n].next_out != -1) {2022 arcs[arcs[n].next_out].prev_out =arcs[n].prev_out;2021 if (_arcs[n].next_out != -1) { 2022 _arcs[_arcs[n].next_out].prev_out = _arcs[n].prev_out; 2023 2023 } 2024 2024 2025 if ( arcs[n].prev_out != -1) {2026 arcs[arcs[n].prev_out].next_out =arcs[n].next_out;2025 if (_arcs[n].prev_out != -1) { 2026 _arcs[_arcs[n].prev_out].next_out = _arcs[n].next_out; 2027 2027 } else { 2028 nodes[arcs[n | 1].target].first_out =arcs[n].next_out;2028 _nodes[_arcs[n | 1].target].first_out = _arcs[n].next_out; 2029 2029 } 2030 2030 2031 if ( arcs[n | 1].next_out != -1) {2032 arcs[arcs[n | 1].next_out].prev_out =arcs[n | 1].prev_out;2031 if (_arcs[n | 1].next_out != -1) { 2032 _arcs[_arcs[n | 1].next_out].prev_out = _arcs[n | 1].prev_out; 2033 2033 } 2034 2034 2035 if ( arcs[n | 1].prev_out != -1) {2036 arcs[arcs[n | 1].prev_out].next_out =arcs[n | 1].next_out;2035 if (_arcs[n | 1].prev_out != -1) { 2036 _arcs[_arcs[n | 1].prev_out].next_out = _arcs[n | 1].next_out; 2037 2037 } else { 2038 nodes[arcs[n].target].first_out =arcs[n | 1].next_out;2038 _nodes[_arcs[n].target].first_out = _arcs[n | 1].next_out; 2039 2039 } 2040 2040 2041 arcs[n].next_out = first_free_arc;2041 _arcs[n].next_out = first_free_arc; 2042 2042 first_free_arc = n; 2043 arcs[n].prev_out = -2;2044 arcs[n | 1].prev_out = -2;2043 _arcs[n].prev_out = -2; 2044 _arcs[n | 1].prev_out = -2; 2045 2045 2046 2046 } 2047 2047 2048 2048 void clear() { 2049 arcs.clear();2050 nodes.clear();2049 _arcs.clear(); 2050 _nodes.clear(); 2051 2051 first_node = first_free_arc = first_red = first_blue = 2052 2052 max_red = max_blue = first_free_red = first_free_blue = -1; 2053 2053 } … … 2055 2055 protected: 2056 2056 2057 2057 void changeRed(Edge e, RedNode n) { 2058 if( arcs[(2 * e.id) | 1].next_out != -1) {2059 arcs[arcs[(2 * e.id) | 1].next_out].prev_out =2060 arcs[(2 * e.id) | 1].prev_out;2058 if(_arcs[(2 * e.id) | 1].next_out != -1) { 2059 _arcs[_arcs[(2 * e.id) | 1].next_out].prev_out = 2060 _arcs[(2 * e.id) | 1].prev_out; 2061 2061 } 2062 if( arcs[(2 * e.id) | 1].prev_out != -1) {2063 arcs[arcs[(2 * e.id) | 1].prev_out].next_out =2064 arcs[(2 * e.id) | 1].next_out;2062 if(_arcs[(2 * e.id) | 1].prev_out != -1) { 2063 _arcs[_arcs[(2 * e.id) | 1].prev_out].next_out = 2064 _arcs[(2 * e.id) | 1].next_out; 2065 2065 } else { 2066 nodes[arcs[2 * e.id].target].first_out =2067 arcs[(2 * e.id) | 1].next_out;2066 _nodes[_arcs[2 * e.id].target].first_out = 2067 _arcs[(2 * e.id) | 1].next_out; 2068 2068 } 2069 2069 2070 if ( nodes[n.id].first_out != -1) {2071 arcs[nodes[n.id].first_out].prev_out = ((2 * e.id) | 1);2070 if (_nodes[n.id].first_out != -1) { 2071 _arcs[_nodes[n.id].first_out].prev_out = ((2 * e.id) | 1); 2072 2072 } 2073 arcs[2 * e.id].target = n.id;2074 arcs[(2 * e.id) | 1].prev_out = -1;2075 arcs[(2 * e.id) | 1].next_out =nodes[n.id].first_out;2076 nodes[n.id].first_out = ((2 * e.id) | 1);2073 _arcs[2 * e.id].target = n.id; 2074 _arcs[(2 * e.id) | 1].prev_out = -1; 2075 _arcs[(2 * e.id) | 1].next_out = _nodes[n.id].first_out; 2076 _nodes[n.id].first_out = ((2 * e.id) | 1); 2077 2077 } 2078 2078 2079 2079 void changeBlue(Edge e, BlueNode n) { 2080 if( arcs[2 * e.id].next_out != -1) {2081 arcs[arcs[2 * e.id].next_out].prev_out =arcs[2 * e.id].prev_out;2080 if(_arcs[2 * e.id].next_out != -1) { 2081 _arcs[_arcs[2 * e.id].next_out].prev_out = _arcs[2 * e.id].prev_out; 2082 2082 } 2083 if( arcs[2 * e.id].prev_out != -1) {2084 arcs[arcs[2 * e.id].prev_out].next_out =2085 arcs[2 * e.id].next_out;2083 if(_arcs[2 * e.id].prev_out != -1) { 2084 _arcs[_arcs[2 * e.id].prev_out].next_out = 2085 _arcs[2 * e.id].next_out; 2086 2086 } else { 2087 nodes[arcs[(2 * e.id) | 1].target].first_out =2088 arcs[2 * e.id].next_out;2087 _nodes[_arcs[(2 * e.id) | 1].target].first_out = 2088 _arcs[2 * e.id].next_out; 2089 2089 } 2090 2090 2091 if ( nodes[n.id].first_out != -1) {2092 arcs[nodes[n.id].first_out].prev_out = 2 * e.id;2091 if (_nodes[n.id].first_out != -1) { 2092 _arcs[_nodes[n.id].first_out].prev_out = 2 * e.id; 2093 2093 } 2094 arcs[(2 * e.id) | 1].target = n.id;2095 arcs[2 * e.id].prev_out = -1;2096 arcs[2 * e.id].next_out =nodes[n.id].first_out;2097 nodes[n.id].first_out = 2 * e.id;2094 _arcs[(2 * e.id) | 1].target = n.id; 2095 _arcs[2 * e.id].prev_out = -1; 2096 _arcs[2 * e.id].next_out = _nodes[n.id].first_out; 2097 _nodes[n.id].first_out = 2 * e.id; 2098 2098 } 2099 2099 2100 2100 }; … … 2249 2249 /// then it is worth reserving space for this amount before starting 2250 2250 /// to build the graph. 2251 2251 /// \sa reserveEdge() 2252 void reserveNode(int n) { nodes.reserve(n); };2252 void reserveNode(int n) { _nodes.reserve(n); }; 2253 2253 2254 2254 /// Reserve memory for edges. 2255 2255 … … 2259 2259 /// then it is worth reserving space for this amount before starting 2260 2260 /// to build the graph. 2261 2261 /// \sa reserveNode() 2262 void reserveEdge(int m) { arcs.reserve(2 * m); };2262 void reserveEdge(int m) { _arcs.reserve(2 * m); }; 2263 2263 2264 2264 /// \brief Class to make a snapshot of the graph and restore 2265 2265 /// it later. -
lemon/lp_base.h
diff --git a/lemon/lp_base.h b/lemon/lp_base.h
a b 31 31 #include<lemon/core.h> 32 32 #include<lemon/bits/solver_bits.h> 33 33 34 #include<lemon/bits/stl_iterators.h> 35 34 36 ///\file 35 37 ///\brief The interface of the LP solver interface. 36 38 ///\ingroup lp_group … … 45 47 46 48 protected: 47 49 48 _solver_bits::VarIndex rows;49 _solver_bits::VarIndex cols;50 _solver_bits::VarIndex _rows; 51 _solver_bits::VarIndex _cols; 50 52 51 53 public: 52 54 … … 166 168 /// 167 169 ColIt(const LpBase &solver) : _solver(&solver) 168 170 { 169 _solver-> cols.firstItem(_id);171 _solver->_cols.firstItem(_id); 170 172 } 171 173 /// Invalid constructor \& conversion 172 174 … … 179 181 /// 180 182 ColIt &operator++() 181 183 { 182 _solver-> cols.nextItem(_id);184 _solver->_cols.nextItem(_id); 183 185 return *this; 184 186 } 185 187 }; 186 188 189 /// \brief Gets the collection of the columns of the LP problem. 190 /// 191 /// This function can be used for iterating on 192 /// the columns of the LP problem. It returns a wrapped ColIt, which looks 193 /// like an STL container (by having begin() and end()) 194 /// which you can use in range-based for loops, STL algorithms, etc. 195 /// For example you can write: 196 ///\code 197 /// for(auto c: lp.cols()) 198 /// doSomething(c); 199 LemonRangeWrapper1<ColIt, LpBase> cols() { 200 return LemonRangeWrapper1<ColIt, LpBase>(*this); 201 } 202 203 187 204 /// \brief Returns the ID of the column. 188 205 static int id(const Col& col) { return col._id; } 189 206 /// \brief Returns the column with the given ID. … … 261 278 /// 262 279 RowIt(const LpBase &solver) : _solver(&solver) 263 280 { 264 _solver-> rows.firstItem(_id);281 _solver->_rows.firstItem(_id); 265 282 } 266 283 /// Invalid constructor \& conversion 267 284 … … 274 291 /// 275 292 RowIt &operator++() 276 293 { 277 _solver-> rows.nextItem(_id);294 _solver->_rows.nextItem(_id); 278 295 return *this; 279 296 } 280 297 }; 298 299 /// \brief Gets the collection of the rows of the LP problem. 300 /// 301 /// This function can be used for iterating on 302 /// the rows of the LP problem. It returns a wrapped RowIt, which looks 303 /// like an STL container (by having begin() and end()) 304 /// which you can use in range-based for loops, STL algorithms, etc. 305 /// For example you can write: 306 ///\code 307 /// for(auto c: lp.rows()) 308 /// doSomething(c); 309 LemonRangeWrapper1<RowIt, LpBase> rows() { 310 return LemonRangeWrapper1<RowIt, LpBase>(*this); 311 } 312 281 313 282 314 /// \brief Returns the ID of the row. 283 315 static int id(const Row& row) { return row._id; } … … 934 966 935 967 //Abstract virtual functions 936 968 937 virtual int _addColId(int col) { return cols.addIndex(col); }938 virtual int _addRowId(int row) { return rows.addIndex(row); }969 virtual int _addColId(int col) { return _cols.addIndex(col); } 970 virtual int _addRowId(int row) { return _rows.addIndex(row); } 939 971 940 virtual void _eraseColId(int col) { cols.eraseIndex(col); }941 virtual void _eraseRowId(int row) { rows.eraseIndex(row); }972 virtual void _eraseColId(int col) { _cols.eraseIndex(col); } 973 virtual void _eraseRowId(int row) { _rows.eraseIndex(row); } 942 974 943 975 virtual int _addCol() = 0; 944 976 virtual int _addRow() = 0; … … 1003 1035 //Constant component of the objective function 1004 1036 Value obj_const_comp; 1005 1037 1006 LpBase() : rows(),cols(), obj_const_comp(0) {}1038 LpBase() : _rows(), _cols(), obj_const_comp(0) {} 1007 1039 1008 1040 public: 1009 1041 … … 1115 1147 ///a better one. 1116 1148 void col(Col c, const DualExpr &e) { 1117 1149 e.simplify(); 1118 _setColCoeffs( cols(id(c)), ExprIterator(e.comps.begin(),rows),1119 ExprIterator(e.comps.end(), rows));1150 _setColCoeffs(_cols(id(c)), ExprIterator(e.comps.begin(), _rows), 1151 ExprIterator(e.comps.end(), _rows)); 1120 1152 } 1121 1153 1122 1154 ///Get a column (i.e a dual constraint) of the LP … … 1125 1157 ///\return the dual expression associated to the column 1126 1158 DualExpr col(Col c) const { 1127 1159 DualExpr e; 1128 _getColCoeffs( cols(id(c)), InsertIterator(e.comps,rows));1160 _getColCoeffs(_cols(id(c)), InsertIterator(e.comps, _rows)); 1129 1161 return e; 1130 1162 } 1131 1163 … … 1212 1244 ///\param u is the upper bound (\ref INF means no bound) 1213 1245 void row(Row r, Value l, const Expr &e, Value u) { 1214 1246 e.simplify(); 1215 _setRowCoeffs( rows(id(r)), ExprIterator(e.comps.begin(),cols),1216 ExprIterator(e.comps.end(), cols));1217 _setRowLowerBound( rows(id(r)),l - *e);1218 _setRowUpperBound( rows(id(r)),u - *e);1247 _setRowCoeffs(_rows(id(r)), ExprIterator(e.comps.begin(), _cols), 1248 ExprIterator(e.comps.end(), _cols)); 1249 _setRowLowerBound(_rows(id(r)),l - *e); 1250 _setRowUpperBound(_rows(id(r)),u - *e); 1219 1251 } 1220 1252 1221 1253 ///Set a row (i.e a constraint) of the LP … … 1234 1266 ///\return the expression associated to the row 1235 1267 Expr row(Row r) const { 1236 1268 Expr e; 1237 _getRowCoeffs( rows(id(r)), InsertIterator(e.comps,cols));1269 _getRowCoeffs(_rows(id(r)), InsertIterator(e.comps, _cols)); 1238 1270 return e; 1239 1271 } 1240 1272 … … 1247 1279 Row addRow(Value l,const Expr &e, Value u) { 1248 1280 Row r; 1249 1281 e.simplify(); 1250 r._id = _addRowId(_addRow(l - *e, ExprIterator(e.comps.begin(), cols),1251 ExprIterator(e.comps.end(), cols), u - *e));1282 r._id = _addRowId(_addRow(l - *e, ExprIterator(e.comps.begin(), _cols), 1283 ExprIterator(e.comps.end(), _cols), u - *e)); 1252 1284 return r; 1253 1285 } 1254 1286 … … 1260 1292 Row r; 1261 1293 c.expr().simplify(); 1262 1294 r._id = _addRowId(_addRow(c.lowerBounded()?c.lowerBound()-*c.expr():-INF, 1263 ExprIterator(c.expr().comps.begin(), cols),1264 ExprIterator(c.expr().comps.end(), cols),1295 ExprIterator(c.expr().comps.begin(), _cols), 1296 ExprIterator(c.expr().comps.end(), _cols), 1265 1297 c.upperBounded()?c.upperBound()-*c.expr():INF)); 1266 1298 return r; 1267 1299 } … … 1269 1301 1270 1302 ///\param c is the column to be deleted 1271 1303 void erase(Col c) { 1272 _eraseCol( cols(id(c)));1273 _eraseColId( cols(id(c)));1304 _eraseCol(_cols(id(c))); 1305 _eraseColId(_cols(id(c))); 1274 1306 } 1275 1307 ///Erase a row (i.e a constraint) from the LP 1276 1308 1277 1309 ///\param r is the row to be deleted 1278 1310 void erase(Row r) { 1279 _eraseRow( rows(id(r)));1280 _eraseRowId( rows(id(r)));1311 _eraseRow(_rows(id(r))); 1312 _eraseRowId(_rows(id(r))); 1281 1313 } 1282 1314 1283 1315 /// Get the name of a column … … 1286 1318 ///\return The name of the colunm 1287 1319 std::string colName(Col c) const { 1288 1320 std::string name; 1289 _getColName( cols(id(c)), name);1321 _getColName(_cols(id(c)), name); 1290 1322 return name; 1291 1323 } 1292 1324 … … 1295 1327 ///\param c is the coresponding column 1296 1328 ///\param name The name to be given 1297 1329 void colName(Col c, const std::string& name) { 1298 _setColName( cols(id(c)), name);1330 _setColName(_cols(id(c)), name); 1299 1331 } 1300 1332 1301 1333 /// Get the column by its name … … 1304 1336 ///\return the proper column or \c INVALID 1305 1337 Col colByName(const std::string& name) const { 1306 1338 int k = _colByName(name); 1307 return k != -1 ? Col( cols[k]) : Col(INVALID);1339 return k != -1 ? Col(_cols[k]) : Col(INVALID); 1308 1340 } 1309 1341 1310 1342 /// Get the name of a row … … 1313 1345 ///\return The name of the row 1314 1346 std::string rowName(Row r) const { 1315 1347 std::string name; 1316 _getRowName( rows(id(r)), name);1348 _getRowName(_rows(id(r)), name); 1317 1349 return name; 1318 1350 } 1319 1351 … … 1322 1354 ///\param r is the coresponding row 1323 1355 ///\param name The name to be given 1324 1356 void rowName(Row r, const std::string& name) { 1325 _setRowName( rows(id(r)), name);1357 _setRowName(_rows(id(r)), name); 1326 1358 } 1327 1359 1328 1360 /// Get the row by its name … … 1331 1363 ///\return the proper row or \c INVALID 1332 1364 Row rowByName(const std::string& name) const { 1333 1365 int k = _rowByName(name); 1334 return k != -1 ? Row( rows[k]) : Row(INVALID);1366 return k != -1 ? Row(_rows[k]) : Row(INVALID); 1335 1367 } 1336 1368 1337 1369 /// Set an element of the coefficient matrix of the LP … … 1340 1372 ///\param c is the column of the element to be modified 1341 1373 ///\param val is the new value of the coefficient 1342 1374 void coeff(Row r, Col c, Value val) { 1343 _setCoeff( rows(id(r)),cols(id(c)), val);1375 _setCoeff(_rows(id(r)),_cols(id(c)), val); 1344 1376 } 1345 1377 1346 1378 /// Get an element of the coefficient matrix of the LP … … 1349 1381 ///\param c is the column of the element 1350 1382 ///\return the corresponding coefficient 1351 1383 Value coeff(Row r, Col c) const { 1352 return _getCoeff( rows(id(r)),cols(id(c)));1384 return _getCoeff(_rows(id(r)),_cols(id(c))); 1353 1385 } 1354 1386 1355 1387 /// Set the lower bound of a column (i.e a variable) … … 1358 1390 /// extended number of type Value, i.e. a finite number of type 1359 1391 /// Value or -\ref INF. 1360 1392 void colLowerBound(Col c, Value value) { 1361 _setColLowerBound( cols(id(c)),value);1393 _setColLowerBound(_cols(id(c)),value); 1362 1394 } 1363 1395 1364 1396 /// Get the lower bound of a column (i.e a variable) … … 1367 1399 /// (this might be -\ref INF as well). 1368 1400 ///\return The lower bound for column \c c 1369 1401 Value colLowerBound(Col c) const { 1370 return _getColLowerBound( cols(id(c)));1402 return _getColLowerBound(_cols(id(c))); 1371 1403 } 1372 1404 1373 1405 ///\brief Set the lower bound of several columns … … 1413 1445 /// extended number of type Value, i.e. a finite number of type 1414 1446 /// Value or \ref INF. 1415 1447 void colUpperBound(Col c, Value value) { 1416 _setColUpperBound( cols(id(c)),value);1448 _setColUpperBound(_cols(id(c)),value); 1417 1449 }; 1418 1450 1419 1451 /// Get the upper bound of a column (i.e a variable) … … 1422 1454 /// (this might be \ref INF as well). 1423 1455 /// \return The upper bound for column \c c 1424 1456 Value colUpperBound(Col c) const { 1425 return _getColUpperBound( cols(id(c)));1457 return _getColUpperBound(_cols(id(c))); 1426 1458 } 1427 1459 1428 1460 ///\brief Set the upper bound of several columns … … 1469 1501 /// extended number of type Value, i.e. a finite number of type 1470 1502 /// Value, -\ref INF or \ref INF. 1471 1503 void colBounds(Col c, Value lower, Value upper) { 1472 _setColLowerBound( cols(id(c)),lower);1473 _setColUpperBound( cols(id(c)),upper);1504 _setColLowerBound(_cols(id(c)),lower); 1505 _setColUpperBound(_cols(id(c)),upper); 1474 1506 } 1475 1507 1476 1508 ///\brief Set the lower and the upper bound of several columns … … 1515 1547 /// extended number of type Value, i.e. a finite number of type 1516 1548 /// Value or -\ref INF. 1517 1549 void rowLowerBound(Row r, Value value) { 1518 _setRowLowerBound( rows(id(r)),value);1550 _setRowLowerBound(_rows(id(r)),value); 1519 1551 } 1520 1552 1521 1553 /// Get the lower bound of a row (i.e a constraint) … … 1524 1556 /// (this might be -\ref INF as well). 1525 1557 ///\return The lower bound for row \c r 1526 1558 Value rowLowerBound(Row r) const { 1527 return _getRowLowerBound( rows(id(r)));1559 return _getRowLowerBound(_rows(id(r))); 1528 1560 } 1529 1561 1530 1562 /// Set the upper bound of a row (i.e a constraint) … … 1533 1565 /// extended number of type Value, i.e. a finite number of type 1534 1566 /// Value or -\ref INF. 1535 1567 void rowUpperBound(Row r, Value value) { 1536 _setRowUpperBound( rows(id(r)),value);1568 _setRowUpperBound(_rows(id(r)),value); 1537 1569 } 1538 1570 1539 1571 /// Get the upper bound of a row (i.e a constraint) … … 1542 1574 /// (this might be -\ref INF as well). 1543 1575 ///\return The upper bound for row \c r 1544 1576 Value rowUpperBound(Row r) const { 1545 return _getRowUpperBound( rows(id(r)));1577 return _getRowUpperBound(_rows(id(r))); 1546 1578 } 1547 1579 1548 1580 ///Set an element of the objective function 1549 void objCoeff(Col c, Value v) {_setObjCoeff( cols(id(c)),v); };1581 void objCoeff(Col c, Value v) {_setObjCoeff(_cols(id(c)),v); }; 1550 1582 1551 1583 ///Get an element of the objective function 1552 Value objCoeff(Col c) const { return _getObjCoeff( cols(id(c))); };1584 Value objCoeff(Col c) const { return _getObjCoeff(_cols(id(c))); }; 1553 1585 1554 1586 ///Set the objective function 1555 1587 1556 1588 ///\param e is a linear expression of type \ref Expr. 1557 1589 /// 1558 1590 void obj(const Expr& e) { 1559 _setObjCoeffs(ExprIterator(e.comps.begin(), cols),1560 ExprIterator(e.comps.end(), cols));1591 _setObjCoeffs(ExprIterator(e.comps.begin(), _cols), 1592 ExprIterator(e.comps.end(), _cols)); 1561 1593 obj_const_comp = *e; 1562 1594 } 1563 1595 … … 1567 1599 ///Expr. 1568 1600 Expr obj() const { 1569 1601 Expr e; 1570 _getObjCoeffs(InsertIterator(e.comps, cols));1602 _getObjCoeffs(InsertIterator(e.comps, _cols)); 1571 1603 *e = obj_const_comp; 1572 1604 return e; 1573 1605 } … … 1586 1618 void min() { _setSense(MIN); } 1587 1619 1588 1620 ///Clear the problem 1589 void clear() { _clear(); rows.clear();cols.clear(); }1621 void clear() { _clear(); _rows.clear(); _cols.clear(); } 1590 1622 1591 1623 /// Set the message level of the solver 1592 1624 void messageLevel(MessageLevel level) { _messageLevel(level); } … … 1929 1961 1930 1962 /// Return the primal value of the column. 1931 1963 /// \pre The problem is solved. 1932 Value primal(Col c) const { return _getPrimal( cols(id(c))); }1964 Value primal(Col c) const { return _getPrimal(_cols(id(c))); } 1933 1965 1934 1966 /// Return the primal value of the expression 1935 1967 … … 1956 1988 /// \pre The problem is solved and the dual problem is infeasible. 1957 1989 /// \note Some solvers does not provide primal ray calculation 1958 1990 /// functions. 1959 Value primalRay(Col c) const { return _getPrimalRay( cols(id(c))); }1991 Value primalRay(Col c) const { return _getPrimalRay(_cols(id(c))); } 1960 1992 1961 1993 /// Return the dual value of the row 1962 1994 1963 1995 /// Return the dual value of the row. 1964 1996 /// \pre The problem is solved. 1965 Value dual(Row r) const { return _getDual( rows(id(r))); }1997 Value dual(Row r) const { return _getDual(_rows(id(r))); } 1966 1998 1967 1999 /// Return the dual value of the dual expression 1968 2000 … … 1990 2022 /// \pre The problem is solved and the primal problem is infeasible. 1991 2023 /// \note Some solvers does not provide dual ray calculation 1992 2024 /// functions. 1993 Value dualRay(Row r) const { return _getDualRay( rows(id(r))); }2025 Value dualRay(Row r) const { return _getDualRay(_rows(id(r))); } 1994 2026 1995 2027 /// Return the basis status of the column 1996 2028 1997 2029 /// \see VarStatus 1998 VarStatus colStatus(Col c) const { return _getColStatus( cols(id(c))); }2030 VarStatus colStatus(Col c) const { return _getColStatus(_cols(id(c))); } 1999 2031 2000 2032 /// Return the basis status of the row 2001 2033 2002 2034 /// \see VarStatus 2003 VarStatus rowStatus(Row r) const { return _getRowStatus( rows(id(r))); }2035 VarStatus rowStatus(Row r) const { return _getRowStatus(_rows(id(r))); } 2004 2036 2005 2037 ///The value of the objective function 2006 2038 … … 2080 2112 ///Sets the type of the given column to the given type. 2081 2113 /// 2082 2114 void colType(Col c, ColTypes col_type) { 2083 _setColType( cols(id(c)),col_type);2115 _setColType(_cols(id(c)),col_type); 2084 2116 } 2085 2117 2086 2118 ///Gives back the type of the column. … … 2088 2120 ///Gives back the type of the column. 2089 2121 /// 2090 2122 ColTypes colType(Col c) const { 2091 return _getColType( cols(id(c)));2123 return _getColType(_cols(id(c))); 2092 2124 } 2093 2125 ///@} 2094 2126 … … 2105 2137 2106 2138 /// Return the value of the row in the solution. 2107 2139 /// \pre The problem is solved. 2108 Value sol(Col c) const { return _getSol( cols(id(c))); }2140 Value sol(Col c) const { return _getSol(_cols(id(c))); } 2109 2141 2110 2142 /// Return the value of the expression in the solution 2111 2143 -
lemon/maps.h
diff --git a/lemon/maps.h b/lemon/maps.h
a b 25 25 #include <map> 26 26 27 27 #include <lemon/core.h> 28 #include <lemon/bits/stl_iterators.h> 28 29 29 30 ///\file 30 31 ///\ingroup maps … … 2581 2582 const IterableBoolMap* _map; 2582 2583 }; 2583 2584 2585 /// \brief STL style iterator for the keys mapped to \c true. 2586 /// 2587 /// This is an STL style wrapper for \ref TrueIt. 2588 /// It can be used in range-based for loops, STL algorithms, etc. 2589 LemonRangeWrapper1<TrueIt, IterableBoolMap> 2590 trueKeys() { 2591 return LemonRangeWrapper1<TrueIt, IterableBoolMap>(*this); 2592 } 2593 2594 2584 2595 /// \brief Iterator for the keys mapped to \c false. 2585 2596 /// 2586 2597 /// Iterator for the keys mapped to \c false. It works … … 2620 2631 const IterableBoolMap* _map; 2621 2632 }; 2622 2633 2634 /// \brief STL style iterator for the keys mapped to \c false. 2635 /// 2636 /// This is an STL style wrapper for \ref FalseIt. 2637 /// It can be used in range-based for loops, STL algorithms, etc. 2638 LemonRangeWrapper1<FalseIt, IterableBoolMap> 2639 falseKeys() { 2640 return LemonRangeWrapper1<FalseIt, IterableBoolMap>(*this); 2641 } 2642 2643 2623 2644 /// \brief Iterator for the keys mapped to a given value. 2624 2645 /// 2625 2646 /// Iterator for the keys mapped to a given value. It works … … 2664 2685 const IterableBoolMap* _map; 2665 2686 }; 2666 2687 2688 /// \brief STL style iterator for the keys mapped to a given value. 2689 /// 2690 /// This is an STL style wrapper for \ref ItemIt. 2691 /// It can be used in range-based for loops, STL algorithms, etc. 2692 LemonRangeWrapper2<ItemIt, IterableBoolMap, bool> 2693 items(bool value) { 2694 return LemonRangeWrapper2<ItemIt, IterableBoolMap, bool>(*this, value); 2695 } 2696 2667 2697 protected: 2668 2698 2669 2699 virtual void add(const Key& key) { … … 3005 3035 const IterableIntMap* _map; 3006 3036 }; 3007 3037 3038 /// \brief STL style iterator for the keys with the same value. 3039 /// 3040 /// This is an STL style wrapper for \ref ItemIt. 3041 /// It can be used in range-based for loops, STL algorithms, etc. 3042 LemonRangeWrapper2<ItemIt, IterableIntMap, int> 3043 items(int value) { 3044 return LemonRangeWrapper2<ItemIt, IterableIntMap, int>(*this, value); 3045 } 3046 3047 3008 3048 protected: 3009 3049 3010 3050 virtual void erase(const Key& key) { … … 3248 3288 const IterableValueMap* _map; 3249 3289 }; 3250 3290 3291 /// \brief STL style iterator for the keys with the same value. 3292 /// 3293 /// This is an STL style wrapper for \ref ItemIt. 3294 /// It can be used in range-based for loops, STL algorithms, etc. 3295 LemonRangeWrapper2<ItemIt, IterableValueMap, V> 3296 items(const V& value) { 3297 return LemonRangeWrapper2<ItemIt, IterableValueMap, V>(*this, value); 3298 } 3299 3300 3251 3301 protected: 3252 3302 3253 3303 virtual void add(const Key& key) { -
lemon/path.h
diff --git a/lemon/path.h b/lemon/path.h
a b 30 30 #include <lemon/error.h> 31 31 #include <lemon/core.h> 32 32 #include <lemon/concepts/path.h> 33 #include <lemon/bits/stl_iterators.h> 33 34 34 35 namespace lemon { 35 36 … … 140 141 int idx; 141 142 }; 142 143 144 /// \brief Gets the collection of the arcs of the path. 145 /// 146 /// This function can be used for iterating on the 147 /// arcs of the path. It returns a wrapped 148 /// ArcIt, which looks like an STL container 149 /// (by having begin() and end()) which you can use in range-based 150 /// for loops, STL algorithms, etc. 151 /// For example you can write: 152 ///\code 153 /// for(auto a: p.arcs()) 154 /// doSomething(a); 155 ///\endcode 156 LemonRangeWrapper1<ArcIt, Path> arcs() const { 157 return LemonRangeWrapper1<ArcIt, Path>(*this); 158 } 159 160 143 161 /// \brief Length of the path. 144 162 int length() const { return head.size() + tail.size(); } 145 163 /// \brief Return whether the path is empty. … … 345 363 int idx; 346 364 }; 347 365 366 /// \brief Gets the collection of the arcs of the path. 367 /// 368 /// This function can be used for iterating on the 369 /// arcs of the path. It returns a wrapped 370 /// ArcIt, which looks like an STL container 371 /// (by having begin() and end()) which you can use in range-based 372 /// for loops, STL algorithms, etc. 373 /// For example you can write: 374 ///\code 375 /// for(auto a: p.arcs()) 376 /// doSomething(a); 377 ///\endcode 378 LemonRangeWrapper1<ArcIt, SimplePath> arcs() const { 379 return LemonRangeWrapper1<ArcIt, SimplePath>(*this); 380 } 381 382 348 383 /// \brief Length of the path. 349 384 int length() const { return data.size(); } 350 385 /// \brief Return true if the path is empty. … … 543 578 Node *node; 544 579 }; 545 580 581 /// \brief Gets the collection of the arcs of the path. 582 /// 583 /// This function can be used for iterating on the 584 /// arcs of the path. It returns a wrapped 585 /// ArcIt, which looks like an STL container 586 /// (by having begin() and end()) which you can use in range-based 587 /// for loops, STL algorithms, etc. 588 /// For example you can write: 589 ///\code 590 /// for(auto a: p.arcs()) 591 /// doSomething(a); 592 ///\endcode 593 LemonRangeWrapper1<ArcIt, ListPath> arcs() const { 594 return LemonRangeWrapper1<ArcIt, ListPath>(*this); 595 } 596 597 546 598 /// \brief The n-th arc. 547 599 /// 548 600 /// This function looks for the n-th arc in O(n) time. … … 795 847 /// \brief Default constructor 796 848 /// 797 849 /// Default constructor 798 StaticPath() : len(0), arcs(0) {}850 StaticPath() : len(0), _arcs(0) {} 799 851 800 852 /// \brief Copy constructor 801 853 /// 802 StaticPath(const StaticPath& cpath) : arcs(0) {854 StaticPath(const StaticPath& cpath) : _arcs(0) { 803 855 pathCopy(cpath, *this); 804 856 } 805 857 … … 807 859 /// 808 860 /// This path can be initialized from any other path type. 809 861 template <typename CPath> 810 StaticPath(const CPath& cpath) : arcs(0) {862 StaticPath(const CPath& cpath) : _arcs(0) { 811 863 pathCopy(cpath, *this); 812 864 } 813 865 … … 815 867 /// 816 868 /// Destructor of the path 817 869 ~StaticPath() { 818 if ( arcs) delete[]arcs;870 if (_arcs) delete[] _arcs; 819 871 } 820 872 821 873 /// \brief Copy assignment … … 882 934 const StaticPath *path; 883 935 int idx; 884 936 }; 937 938 /// \brief Gets the collection of the arcs of the path. 939 /// 940 /// This function can be used for iterating on the 941 /// arcs of the path. It returns a wrapped 942 /// ArcIt, which looks like an STL container 943 /// (by having begin() and end()) which you can use in range-based 944 /// for loops, STL algorithms, etc. 945 /// For example you can write: 946 ///\code 947 /// for(auto a: p.arcs()) 948 /// doSomething(a); 949 ///\endcode 950 LemonRangeWrapper1<ArcIt, StaticPath> arcs() const { 951 return LemonRangeWrapper1<ArcIt, StaticPath>(*this); 952 } 953 885 954 886 955 /// \brief The n-th arc. 887 956 /// 888 957 /// \pre \c n is in the <tt>[0..length() - 1]</tt> range. 889 958 const Arc& nth(int n) const { 890 return arcs[n];959 return _arcs[n]; 891 960 } 892 961 893 962 /// \brief The arc iterator pointing to the n-th arc. … … 904 973 /// \brief Erase all arcs in the digraph. 905 974 void clear() { 906 975 len = 0; 907 if ( arcs) delete[]arcs;908 arcs = 0;976 if (_arcs) delete[] _arcs; 977 _arcs = 0; 909 978 } 910 979 911 980 /// \brief The first arc of the path. 912 981 const Arc& front() const { 913 return arcs[0];982 return _arcs[0]; 914 983 } 915 984 916 985 /// \brief The last arc of the path. 917 986 const Arc& back() const { 918 return arcs[len - 1];987 return _arcs[len - 1]; 919 988 } 920 989 921 990 … … 924 993 template <typename CPath> 925 994 void build(const CPath& path) { 926 995 len = path.length(); 927 arcs = new Arc[len];996 _arcs = new Arc[len]; 928 997 int index = 0; 929 998 for (typename CPath::ArcIt it(path); it != INVALID; ++it) { 930 arcs[index] = it;999 _arcs[index] = it; 931 1000 ++index; 932 1001 } 933 1002 } … … 935 1004 template <typename CPath> 936 1005 void buildRev(const CPath& path) { 937 1006 len = path.length(); 938 arcs = new Arc[len];1007 _arcs = new Arc[len]; 939 1008 int index = len; 940 1009 for (typename CPath::RevArcIt it(path); it != INVALID; ++it) { 941 1010 --index; 942 arcs[index] = it;1011 _arcs[index] = it; 943 1012 } 944 1013 } 945 1014 946 1015 private: 947 1016 int len; 948 Arc* arcs;1017 Arc* _arcs; 949 1018 }; 950 1019 951 1020 /////////////////////////////////////////////////////////////////////// … … 1157 1226 1158 1227 }; 1159 1228 1229 /// \brief Gets the collection of the nodes of the path. 1230 /// 1231 /// This function can be used for iterating on the 1232 /// nodes of the path. It returns a wrapped 1233 /// PathNodeIt, which looks like an STL container 1234 /// (by having begin() and end()) which you can use in range-based 1235 /// for loops, STL algorithms, etc. 1236 /// For example you can write: 1237 ///\code 1238 /// for(auto u: pathNodes(g,p)) 1239 /// doSomething(u); 1240 ///\endcode 1241 template<typename Path> 1242 LemonRangeWrapper2<PathNodeIt<Path>, typename Path::Digraph, Path> 1243 pathNodes(const typename Path::Digraph &g, const Path &p) { 1244 return 1245 LemonRangeWrapper2<PathNodeIt<Path>, typename Path::Digraph, Path>(g,p); 1246 } 1247 1160 1248 ///@} 1161 1249 1162 1250 } // namespace lemon -
lemon/smart_graph.h
diff --git a/lemon/smart_graph.h b/lemon/smart_graph.h
a b 47 47 ArcT() {} 48 48 }; 49 49 50 std::vector<NodeT> nodes;51 std::vector<ArcT> arcs;50 std::vector<NodeT> _nodes; 51 std::vector<ArcT> _arcs; 52 52 53 53 public: 54 54 … … 59 59 60 60 public: 61 61 62 SmartDigraphBase() : nodes(),arcs() { }62 SmartDigraphBase() : _nodes(), _arcs() { } 63 63 SmartDigraphBase(const SmartDigraphBase &_g) 64 : nodes(_g.nodes), arcs(_g.arcs) { }64 : _nodes(_g._nodes), _arcs(_g._arcs) { } 65 65 66 66 typedef True NodeNumTag; 67 67 typedef True ArcNumTag; 68 68 69 int nodeNum() const { return nodes.size(); }70 int arcNum() const { return arcs.size(); }69 int nodeNum() const { return _nodes.size(); } 70 int arcNum() const { return _arcs.size(); } 71 71 72 int maxNodeId() const { return nodes.size()-1; }73 int maxArcId() const { return arcs.size()-1; }72 int maxNodeId() const { return _nodes.size()-1; } 73 int maxArcId() const { return _arcs.size()-1; } 74 74 75 75 Node addNode() { 76 int n = nodes.size();77 nodes.push_back(NodeT());78 nodes[n].first_in = -1;79 nodes[n].first_out = -1;76 int n = _nodes.size(); 77 _nodes.push_back(NodeT()); 78 _nodes[n].first_in = -1; 79 _nodes[n].first_out = -1; 80 80 return Node(n); 81 81 } 82 82 83 83 Arc addArc(Node u, Node v) { 84 int n = arcs.size();85 arcs.push_back(ArcT());86 arcs[n].source = u._id;87 arcs[n].target = v._id;88 arcs[n].next_out =nodes[u._id].first_out;89 arcs[n].next_in =nodes[v._id].first_in;90 nodes[u._id].first_out =nodes[v._id].first_in = n;84 int n = _arcs.size(); 85 _arcs.push_back(ArcT()); 86 _arcs[n].source = u._id; 87 _arcs[n].target = v._id; 88 _arcs[n].next_out = _nodes[u._id].first_out; 89 _arcs[n].next_in = _nodes[v._id].first_in; 90 _nodes[u._id].first_out = _nodes[v._id].first_in = n; 91 91 92 92 return Arc(n); 93 93 } 94 94 95 95 void clear() { 96 arcs.clear();97 nodes.clear();96 _arcs.clear(); 97 _nodes.clear(); 98 98 } 99 99 100 Node source(Arc a) const { return Node( arcs[a._id].source); }101 Node target(Arc a) const { return Node( arcs[a._id].target); }100 Node source(Arc a) const { return Node(_arcs[a._id].source); } 101 Node target(Arc a) const { return Node(_arcs[a._id].target); } 102 102 103 103 static int id(Node v) { return v._id; } 104 104 static int id(Arc a) { return a._id; } … … 107 107 static Arc arcFromId(int id) { return Arc(id);} 108 108 109 109 bool valid(Node n) const { 110 return n._id >= 0 && n._id < static_cast<int>( nodes.size());110 return n._id >= 0 && n._id < static_cast<int>(_nodes.size()); 111 111 } 112 112 bool valid(Arc a) const { 113 return a._id >= 0 && a._id < static_cast<int>( arcs.size());113 return a._id >= 0 && a._id < static_cast<int>(_arcs.size()); 114 114 } 115 115 116 116 class Node { … … 145 145 }; 146 146 147 147 void first(Node& node) const { 148 node._id = nodes.size() - 1;148 node._id = _nodes.size() - 1; 149 149 } 150 150 151 151 static void next(Node& node) { … … 153 153 } 154 154 155 155 void first(Arc& arc) const { 156 arc._id = arcs.size() - 1;156 arc._id = _arcs.size() - 1; 157 157 } 158 158 159 159 static void next(Arc& arc) { … … 161 161 } 162 162 163 163 void firstOut(Arc& arc, const Node& node) const { 164 arc._id = nodes[node._id].first_out;164 arc._id = _nodes[node._id].first_out; 165 165 } 166 166 167 167 void nextOut(Arc& arc) const { 168 arc._id = arcs[arc._id].next_out;168 arc._id = _arcs[arc._id].next_out; 169 169 } 170 170 171 171 void firstIn(Arc& arc, const Node& node) const { 172 arc._id = nodes[node._id].first_in;172 arc._id = _nodes[node._id].first_in; 173 173 } 174 174 175 175 void nextIn(Arc& arc) const { 176 arc._id = arcs[arc._id].next_in;176 arc._id = _arcs[arc._id].next_in; 177 177 } 178 178 179 179 }; … … 266 266 Node split(Node n, bool connect = true) 267 267 { 268 268 Node b = addNode(); 269 nodes[b._id].first_out=nodes[n._id].first_out;270 nodes[n._id].first_out=-1;271 for(int i= nodes[b._id].first_out; i!=-1; i=arcs[i].next_out) {272 arcs[i].source=b._id;269 _nodes[b._id].first_out=_nodes[n._id].first_out; 270 _nodes[n._id].first_out=-1; 271 for(int i=_nodes[b._id].first_out; i!=-1; i=_arcs[i].next_out) { 272 _arcs[i].source=b._id; 273 273 } 274 274 if(connect) addArc(n,b); 275 275 return b; … … 291 291 /// then it is worth reserving space for this amount before starting 292 292 /// to build the digraph. 293 293 /// \sa reserveArc() 294 void reserveNode(int n) { nodes.reserve(n); };294 void reserveNode(int n) { _nodes.reserve(n); }; 295 295 296 296 /// Reserve memory for arcs. 297 297 … … 301 301 /// then it is worth reserving space for this amount before starting 302 302 /// to build the digraph. 303 303 /// \sa reserveNode() 304 void reserveArc(int m) { arcs.reserve(m); };304 void reserveArc(int m) { _arcs.reserve(m); }; 305 305 306 306 public: 307 307 … … 311 311 312 312 void restoreSnapshot(const Snapshot &s) 313 313 { 314 while(s.arc_num< arcs.size()) {315 Arc arc = arcFromId( arcs.size()-1);314 while(s.arc_num<_arcs.size()) { 315 Arc arc = arcFromId(_arcs.size()-1); 316 316 Parent::notifier(Arc()).erase(arc); 317 nodes[arcs.back().source].first_out=arcs.back().next_out;318 nodes[arcs.back().target].first_in=arcs.back().next_in;319 arcs.pop_back();317 _nodes[_arcs.back().source].first_out=_arcs.back().next_out; 318 _nodes[_arcs.back().target].first_in=_arcs.back().next_in; 319 _arcs.pop_back(); 320 320 } 321 while(s.node_num< nodes.size()) {322 Node node = nodeFromId( nodes.size()-1);321 while(s.node_num<_nodes.size()) { 322 Node node = nodeFromId(_nodes.size()-1); 323 323 Parent::notifier(Node()).erase(node); 324 nodes.pop_back();324 _nodes.pop_back(); 325 325 } 326 326 } 327 327 … … 362 362 ///This constructor immediately makes a snapshot of the given digraph. 363 363 /// 364 364 Snapshot(SmartDigraph &gr) : _graph(&gr) { 365 node_num=_graph-> nodes.size();366 arc_num=_graph-> arcs.size();365 node_num=_graph->_nodes.size(); 366 arc_num=_graph->_arcs.size(); 367 367 } 368 368 369 369 ///Make a snapshot. … … 373 373 ///call, the previous snapshot gets lost. 374 374 void save(SmartDigraph &gr) { 375 375 _graph=&gr; 376 node_num=_graph-> nodes.size();377 arc_num=_graph-> arcs.size();376 node_num=_graph->_nodes.size(); 377 arc_num=_graph->_arcs.size(); 378 378 } 379 379 380 380 ///Undo the changes until a snapshot. … … 402 402 int next_out; 403 403 }; 404 404 405 std::vector<NodeT> nodes;406 std::vector<ArcT> arcs;405 std::vector<NodeT> _nodes; 406 std::vector<ArcT> _arcs; 407 407 408 408 public: 409 409 … … 465 465 466 466 467 467 SmartGraphBase() 468 : nodes(),arcs() {}468 : _nodes(), _arcs() {} 469 469 470 470 typedef True NodeNumTag; 471 471 typedef True EdgeNumTag; 472 472 typedef True ArcNumTag; 473 473 474 int nodeNum() const { return nodes.size(); }475 int edgeNum() const { return arcs.size() / 2; }476 int arcNum() const { return arcs.size(); }474 int nodeNum() const { return _nodes.size(); } 475 int edgeNum() const { return _arcs.size() / 2; } 476 int arcNum() const { return _arcs.size(); } 477 477 478 int maxNodeId() const { return nodes.size()-1; }479 int maxEdgeId() const { return arcs.size() / 2 - 1; }480 int maxArcId() const { return arcs.size()-1; }478 int maxNodeId() const { return _nodes.size()-1; } 479 int maxEdgeId() const { return _arcs.size() / 2 - 1; } 480 int maxArcId() const { return _arcs.size()-1; } 481 481 482 Node source(Arc e) const { return Node( arcs[e._id ^ 1].target); }483 Node target(Arc e) const { return Node( arcs[e._id].target); }482 Node source(Arc e) const { return Node(_arcs[e._id ^ 1].target); } 483 Node target(Arc e) const { return Node(_arcs[e._id].target); } 484 484 485 Node u(Edge e) const { return Node( arcs[2 * e._id].target); }486 Node v(Edge e) const { return Node( arcs[2 * e._id + 1].target); }485 Node u(Edge e) const { return Node(_arcs[2 * e._id].target); } 486 Node v(Edge e) const { return Node(_arcs[2 * e._id + 1].target); } 487 487 488 488 static bool direction(Arc e) { 489 489 return (e._id & 1) == 1; … … 494 494 } 495 495 496 496 void first(Node& node) const { 497 node._id = nodes.size() - 1;497 node._id = _nodes.size() - 1; 498 498 } 499 499 500 500 static void next(Node& node) { … … 502 502 } 503 503 504 504 void first(Arc& arc) const { 505 arc._id = arcs.size() - 1;505 arc._id = _arcs.size() - 1; 506 506 } 507 507 508 508 static void next(Arc& arc) { … … 510 510 } 511 511 512 512 void first(Edge& arc) const { 513 arc._id = arcs.size() / 2 - 1;513 arc._id = _arcs.size() / 2 - 1; 514 514 } 515 515 516 516 static void next(Edge& arc) { … … 518 518 } 519 519 520 520 void firstOut(Arc &arc, const Node& v) const { 521 arc._id = nodes[v._id].first_out;521 arc._id = _nodes[v._id].first_out; 522 522 } 523 523 void nextOut(Arc &arc) const { 524 arc._id = arcs[arc._id].next_out;524 arc._id = _arcs[arc._id].next_out; 525 525 } 526 526 527 527 void firstIn(Arc &arc, const Node& v) const { 528 arc._id = (( nodes[v._id].first_out) ^ 1);528 arc._id = ((_nodes[v._id].first_out) ^ 1); 529 529 if (arc._id == -2) arc._id = -1; 530 530 } 531 531 void nextIn(Arc &arc) const { 532 arc._id = (( arcs[arc._id ^ 1].next_out) ^ 1);532 arc._id = ((_arcs[arc._id ^ 1].next_out) ^ 1); 533 533 if (arc._id == -2) arc._id = -1; 534 534 } 535 535 536 536 void firstInc(Edge &arc, bool& d, const Node& v) const { 537 int de = nodes[v._id].first_out;537 int de = _nodes[v._id].first_out; 538 538 if (de != -1) { 539 539 arc._id = de / 2; 540 540 d = ((de & 1) == 1); … … 544 544 } 545 545 } 546 546 void nextInc(Edge &arc, bool& d) const { 547 int de = ( arcs[(arc._id * 2) | (d ? 1 : 0)].next_out);547 int de = (_arcs[(arc._id * 2) | (d ? 1 : 0)].next_out); 548 548 if (de != -1) { 549 549 arc._id = de / 2; 550 550 d = ((de & 1) == 1); … … 563 563 static Edge edgeFromId(int id) { return Edge(id);} 564 564 565 565 bool valid(Node n) const { 566 return n._id >= 0 && n._id < static_cast<int>( nodes.size());566 return n._id >= 0 && n._id < static_cast<int>(_nodes.size()); 567 567 } 568 568 bool valid(Arc a) const { 569 return a._id >= 0 && a._id < static_cast<int>( arcs.size());569 return a._id >= 0 && a._id < static_cast<int>(_arcs.size()); 570 570 } 571 571 bool valid(Edge e) const { 572 return e._id >= 0 && 2 * e._id < static_cast<int>( arcs.size());572 return e._id >= 0 && 2 * e._id < static_cast<int>(_arcs.size()); 573 573 } 574 574 575 575 Node addNode() { 576 int n = nodes.size();577 nodes.push_back(NodeT());578 nodes[n].first_out = -1;576 int n = _nodes.size(); 577 _nodes.push_back(NodeT()); 578 _nodes[n].first_out = -1; 579 579 580 580 return Node(n); 581 581 } 582 582 583 583 Edge addEdge(Node u, Node v) { 584 int n = arcs.size();585 arcs.push_back(ArcT());586 arcs.push_back(ArcT());584 int n = _arcs.size(); 585 _arcs.push_back(ArcT()); 586 _arcs.push_back(ArcT()); 587 587 588 arcs[n].target = u._id;589 arcs[n | 1].target = v._id;588 _arcs[n].target = u._id; 589 _arcs[n | 1].target = v._id; 590 590 591 arcs[n].next_out =nodes[v._id].first_out;592 nodes[v._id].first_out = n;591 _arcs[n].next_out = _nodes[v._id].first_out; 592 _nodes[v._id].first_out = n; 593 593 594 arcs[n | 1].next_out =nodes[u._id].first_out;595 nodes[u._id].first_out = (n | 1);594 _arcs[n | 1].next_out = _nodes[u._id].first_out; 595 _nodes[u._id].first_out = (n | 1); 596 596 597 597 return Edge(n / 2); 598 598 } 599 599 600 600 void clear() { 601 arcs.clear();602 nodes.clear();601 _arcs.clear(); 602 _nodes.clear(); 603 603 } 604 604 605 605 }; … … 701 701 /// then it is worth reserving space for this amount before starting 702 702 /// to build the graph. 703 703 /// \sa reserveEdge() 704 void reserveNode(int n) { nodes.reserve(n); };704 void reserveNode(int n) { _nodes.reserve(n); }; 705 705 706 706 /// Reserve memory for edges. 707 707 … … 711 711 /// then it is worth reserving space for this amount before starting 712 712 /// to build the graph. 713 713 /// \sa reserveNode() 714 void reserveEdge(int m) { arcs.reserve(2 * m); };714 void reserveEdge(int m) { _arcs.reserve(2 * m); }; 715 715 716 716 public: 717 717 … … 722 722 void saveSnapshot(Snapshot &s) 723 723 { 724 724 s._graph = this; 725 s.node_num = nodes.size();726 s.arc_num = arcs.size();725 s.node_num = _nodes.size(); 726 s.arc_num = _arcs.size(); 727 727 } 728 728 729 729 void restoreSnapshot(const Snapshot &s) 730 730 { 731 while(s.arc_num< arcs.size()) {732 int n= arcs.size()-1;731 while(s.arc_num<_arcs.size()) { 732 int n=_arcs.size()-1; 733 733 Edge arc=edgeFromId(n/2); 734 734 Parent::notifier(Edge()).erase(arc); 735 735 std::vector<Arc> dir; 736 736 dir.push_back(arcFromId(n)); 737 737 dir.push_back(arcFromId(n-1)); 738 738 Parent::notifier(Arc()).erase(dir); 739 nodes[arcs[n-1].target].first_out=arcs[n].next_out;740 nodes[arcs[n].target].first_out=arcs[n-1].next_out;741 arcs.pop_back();742 arcs.pop_back();739 _nodes[_arcs[n-1].target].first_out=_arcs[n].next_out; 740 _nodes[_arcs[n].target].first_out=_arcs[n-1].next_out; 741 _arcs.pop_back(); 742 _arcs.pop_back(); 743 743 } 744 while(s.node_num< nodes.size()) {745 int n= nodes.size()-1;744 while(s.node_num<_nodes.size()) { 745 int n=_nodes.size()-1; 746 746 Node node = nodeFromId(n); 747 747 Parent::notifier(Node()).erase(node); 748 nodes.pop_back();748 _nodes.pop_back(); 749 749 } 750 750 } 751 751 … … 825 825 int next_out; 826 826 }; 827 827 828 std::vector<NodeT> nodes;829 std::vector<ArcT> arcs;828 std::vector<NodeT> _nodes; 829 std::vector<ArcT> _arcs; 830 830 831 831 int first_red, first_blue; 832 832 int max_red, max_blue; … … 915 915 916 916 917 917 SmartBpGraphBase() 918 : nodes(),arcs(), first_red(-1), first_blue(-1),918 : _nodes(), _arcs(), first_red(-1), first_blue(-1), 919 919 max_red(-1), max_blue(-1) {} 920 920 921 921 typedef True NodeNumTag; 922 922 typedef True EdgeNumTag; 923 923 typedef True ArcNumTag; 924 924 925 int nodeNum() const { return nodes.size(); }925 int nodeNum() const { return _nodes.size(); } 926 926 int redNum() const { return max_red + 1; } 927 927 int blueNum() const { return max_blue + 1; } 928 int edgeNum() const { return arcs.size() / 2; }929 int arcNum() const { return arcs.size(); }928 int edgeNum() const { return _arcs.size() / 2; } 929 int arcNum() const { return _arcs.size(); } 930 930 931 int maxNodeId() const { return nodes.size()-1; }931 int maxNodeId() const { return _nodes.size()-1; } 932 932 int maxRedId() const { return max_red; } 933 933 int maxBlueId() const { return max_blue; } 934 int maxEdgeId() const { return arcs.size() / 2 - 1; }935 int maxArcId() const { return arcs.size()-1; }934 int maxEdgeId() const { return _arcs.size() / 2 - 1; } 935 int maxArcId() const { return _arcs.size()-1; } 936 936 937 bool red(Node n) const { return nodes[n._id].red; }938 bool blue(Node n) const { return ! nodes[n._id].red; }937 bool red(Node n) const { return _nodes[n._id].red; } 938 bool blue(Node n) const { return !_nodes[n._id].red; } 939 939 940 940 static RedNode asRedNodeUnsafe(Node n) { return RedNode(n._id); } 941 941 static BlueNode asBlueNodeUnsafe(Node n) { return BlueNode(n._id); } 942 942 943 Node source(Arc a) const { return Node( arcs[a._id ^ 1].target); }944 Node target(Arc a) const { return Node( arcs[a._id].target); }943 Node source(Arc a) const { return Node(_arcs[a._id ^ 1].target); } 944 Node target(Arc a) const { return Node(_arcs[a._id].target); } 945 945 946 946 RedNode redNode(Edge e) const { 947 return RedNode( arcs[2 * e._id].target);947 return RedNode(_arcs[2 * e._id].target); 948 948 } 949 949 BlueNode blueNode(Edge e) const { 950 return BlueNode( arcs[2 * e._id + 1].target);950 return BlueNode(_arcs[2 * e._id + 1].target); 951 951 } 952 952 953 953 static bool direction(Arc a) { … … 959 959 } 960 960 961 961 void first(Node& node) const { 962 node._id = nodes.size() - 1;962 node._id = _nodes.size() - 1; 963 963 } 964 964 965 965 static void next(Node& node) { … … 971 971 } 972 972 973 973 void next(RedNode& node) const { 974 node._id = nodes[node._id].partition_next;974 node._id = _nodes[node._id].partition_next; 975 975 } 976 976 977 977 void first(BlueNode& node) const { … … 979 979 } 980 980 981 981 void next(BlueNode& node) const { 982 node._id = nodes[node._id].partition_next;982 node._id = _nodes[node._id].partition_next; 983 983 } 984 984 985 985 void first(Arc& arc) const { 986 arc._id = arcs.size() - 1;986 arc._id = _arcs.size() - 1; 987 987 } 988 988 989 989 static void next(Arc& arc) { … … 991 991 } 992 992 993 993 void first(Edge& arc) const { 994 arc._id = arcs.size() / 2 - 1;994 arc._id = _arcs.size() / 2 - 1; 995 995 } 996 996 997 997 static void next(Edge& arc) { … … 999 999 } 1000 1000 1001 1001 void firstOut(Arc &arc, const Node& v) const { 1002 arc._id = nodes[v._id].first_out;1002 arc._id = _nodes[v._id].first_out; 1003 1003 } 1004 1004 void nextOut(Arc &arc) const { 1005 arc._id = arcs[arc._id].next_out;1005 arc._id = _arcs[arc._id].next_out; 1006 1006 } 1007 1007 1008 1008 void firstIn(Arc &arc, const Node& v) const { 1009 arc._id = (( nodes[v._id].first_out) ^ 1);1009 arc._id = ((_nodes[v._id].first_out) ^ 1); 1010 1010 if (arc._id == -2) arc._id = -1; 1011 1011 } 1012 1012 void nextIn(Arc &arc) const { 1013 arc._id = (( arcs[arc._id ^ 1].next_out) ^ 1);1013 arc._id = ((_arcs[arc._id ^ 1].next_out) ^ 1); 1014 1014 if (arc._id == -2) arc._id = -1; 1015 1015 } 1016 1016 1017 1017 void firstInc(Edge &arc, bool& d, const Node& v) const { 1018 int de = nodes[v._id].first_out;1018 int de = _nodes[v._id].first_out; 1019 1019 if (de != -1) { 1020 1020 arc._id = de / 2; 1021 1021 d = ((de & 1) == 1); … … 1025 1025 } 1026 1026 } 1027 1027 void nextInc(Edge &arc, bool& d) const { 1028 int de = ( arcs[(arc._id * 2) | (d ? 1 : 0)].next_out);1028 int de = (_arcs[(arc._id * 2) | (d ? 1 : 0)].next_out); 1029 1029 if (de != -1) { 1030 1030 arc._id = de / 2; 1031 1031 d = ((de & 1) == 1); … … 1036 1036 } 1037 1037 1038 1038 static int id(Node v) { return v._id; } 1039 int id(RedNode v) const { return nodes[v._id].partition_index; }1040 int id(BlueNode v) const { return nodes[v._id].partition_index; }1039 int id(RedNode v) const { return _nodes[v._id].partition_index; } 1040 int id(BlueNode v) const { return _nodes[v._id].partition_index; } 1041 1041 static int id(Arc e) { return e._id; } 1042 1042 static int id(Edge e) { return e._id; } 1043 1043 … … 1046 1046 static Edge edgeFromId(int id) { return Edge(id);} 1047 1047 1048 1048 bool valid(Node n) const { 1049 return n._id >= 0 && n._id < static_cast<int>( nodes.size());1049 return n._id >= 0 && n._id < static_cast<int>(_nodes.size()); 1050 1050 } 1051 1051 bool valid(Arc a) const { 1052 return a._id >= 0 && a._id < static_cast<int>( arcs.size());1052 return a._id >= 0 && a._id < static_cast<int>(_arcs.size()); 1053 1053 } 1054 1054 bool valid(Edge e) const { 1055 return e._id >= 0 && 2 * e._id < static_cast<int>( arcs.size());1055 return e._id >= 0 && 2 * e._id < static_cast<int>(_arcs.size()); 1056 1056 } 1057 1057 1058 1058 RedNode addRedNode() { 1059 int n = nodes.size();1060 nodes.push_back(NodeT());1061 nodes[n].first_out = -1;1062 nodes[n].red = true;1063 nodes[n].partition_index = ++max_red;1064 nodes[n].partition_next = first_red;1059 int n = _nodes.size(); 1060 _nodes.push_back(NodeT()); 1061 _nodes[n].first_out = -1; 1062 _nodes[n].red = true; 1063 _nodes[n].partition_index = ++max_red; 1064 _nodes[n].partition_next = first_red; 1065 1065 first_red = n; 1066 1066 1067 1067 return RedNode(n); 1068 1068 } 1069 1069 1070 1070 BlueNode addBlueNode() { 1071 int n = nodes.size();1072 nodes.push_back(NodeT());1073 nodes[n].first_out = -1;1074 nodes[n].red = false;1075 nodes[n].partition_index = ++max_blue;1076 nodes[n].partition_next = first_blue;1071 int n = _nodes.size(); 1072 _nodes.push_back(NodeT()); 1073 _nodes[n].first_out = -1; 1074 _nodes[n].red = false; 1075 _nodes[n].partition_index = ++max_blue; 1076 _nodes[n].partition_next = first_blue; 1077 1077 first_blue = n; 1078 1078 1079 1079 return BlueNode(n); 1080 1080 } 1081 1081 1082 1082 Edge addEdge(RedNode u, BlueNode v) { 1083 int n = arcs.size();1084 arcs.push_back(ArcT());1085 arcs.push_back(ArcT());1083 int n = _arcs.size(); 1084 _arcs.push_back(ArcT()); 1085 _arcs.push_back(ArcT()); 1086 1086 1087 arcs[n].target = u._id;1088 arcs[n | 1].target = v._id;1087 _arcs[n].target = u._id; 1088 _arcs[n | 1].target = v._id; 1089 1089 1090 arcs[n].next_out =nodes[v._id].first_out;1091 nodes[v._id].first_out = n;1090 _arcs[n].next_out = _nodes[v._id].first_out; 1091 _nodes[v._id].first_out = n; 1092 1092 1093 arcs[n | 1].next_out =nodes[u._id].first_out;1094 nodes[u._id].first_out = (n | 1);1093 _arcs[n | 1].next_out = _nodes[u._id].first_out; 1094 _nodes[u._id].first_out = (n | 1); 1095 1095 1096 1096 return Edge(n / 2); 1097 1097 } 1098 1098 1099 1099 void clear() { 1100 arcs.clear();1101 nodes.clear();1100 _arcs.clear(); 1101 _nodes.clear(); 1102 1102 first_red = -1; 1103 1103 first_blue = -1; 1104 1104 max_blue = -1; … … 1213 1213 /// then it is worth reserving space for this amount before starting 1214 1214 /// to build the graph. 1215 1215 /// \sa reserveEdge() 1216 void reserveNode(int n) { nodes.reserve(n); };1216 void reserveNode(int n) { _nodes.reserve(n); }; 1217 1217 1218 1218 /// Reserve memory for edges. 1219 1219 … … 1223 1223 /// then it is worth reserving space for this amount before starting 1224 1224 /// to build the graph. 1225 1225 /// \sa reserveNode() 1226 void reserveEdge(int m) { arcs.reserve(2 * m); };1226 void reserveEdge(int m) { _arcs.reserve(2 * m); }; 1227 1227 1228 1228 public: 1229 1229 … … 1234 1234 void saveSnapshot(Snapshot &s) 1235 1235 { 1236 1236 s._graph = this; 1237 s.node_num = nodes.size();1238 s.arc_num = arcs.size();1237 s.node_num = _nodes.size(); 1238 s.arc_num = _arcs.size(); 1239 1239 } 1240 1240 1241 1241 void restoreSnapshot(const Snapshot &s) 1242 1242 { 1243 while(s.arc_num< arcs.size()) {1244 int n= arcs.size()-1;1243 while(s.arc_num<_arcs.size()) { 1244 int n=_arcs.size()-1; 1245 1245 Edge arc=edgeFromId(n/2); 1246 1246 Parent::notifier(Edge()).erase(arc); 1247 1247 std::vector<Arc> dir; 1248 1248 dir.push_back(arcFromId(n)); 1249 1249 dir.push_back(arcFromId(n-1)); 1250 1250 Parent::notifier(Arc()).erase(dir); 1251 nodes[arcs[n-1].target].first_out=arcs[n].next_out;1252 nodes[arcs[n].target].first_out=arcs[n-1].next_out;1253 arcs.pop_back();1254 arcs.pop_back();1251 _nodes[_arcs[n-1].target].first_out=_arcs[n].next_out; 1252 _nodes[_arcs[n].target].first_out=_arcs[n-1].next_out; 1253 _arcs.pop_back(); 1254 _arcs.pop_back(); 1255 1255 } 1256 while(s.node_num< nodes.size()) {1257 int n= nodes.size()-1;1256 while(s.node_num<_nodes.size()) { 1257 int n=_nodes.size()-1; 1258 1258 Node node = nodeFromId(n); 1259 1259 if (Parent::red(node)) { 1260 first_red = nodes[n].partition_next;1260 first_red = _nodes[n].partition_next; 1261 1261 if (first_red != -1) { 1262 max_red = nodes[first_red].partition_index;1262 max_red = _nodes[first_red].partition_index; 1263 1263 } else { 1264 1264 max_red = -1; 1265 1265 } 1266 1266 Parent::notifier(RedNode()).erase(asRedNodeUnsafe(node)); 1267 1267 } else { 1268 first_blue = nodes[n].partition_next;1268 first_blue = _nodes[n].partition_next; 1269 1269 if (first_blue != -1) { 1270 max_blue = nodes[first_blue].partition_index;1270 max_blue = _nodes[first_blue].partition_index; 1271 1271 } else { 1272 1272 max_blue = -1; 1273 1273 } 1274 1274 Parent::notifier(BlueNode()).erase(asBlueNodeUnsafe(node)); 1275 1275 } 1276 1276 Parent::notifier(Node()).erase(node); 1277 nodes.pop_back();1277 _nodes.pop_back(); 1278 1278 } 1279 1279 } 1280 1280 -
lemon/soplex.cc
diff --git a/lemon/soplex.cc b/lemon/soplex.cc
a b 37 37 } 38 38 39 39 SoplexLp::SoplexLp(const SoplexLp& lp) { 40 rows = lp.rows;41 cols = lp.cols;40 _rows = lp._rows; 41 _cols = lp._cols; 42 42 43 43 soplex = new soplex::SoPlex; 44 44 (*static_cast<soplex::SPxLP*>(soplex)) = *(lp.soplex); … … 122 122 } 123 123 124 124 void SoplexLp::_eraseColId(int i) { 125 cols.eraseIndex(i);126 cols.relocateIndex(i,cols.maxIndex());125 _cols.eraseIndex(i); 126 _cols.relocateIndex(i, _cols.maxIndex()); 127 127 } 128 128 void SoplexLp::_eraseRowId(int i) { 129 rows.eraseIndex(i);130 rows.relocateIndex(i,rows.maxIndex());129 _rows.eraseIndex(i); 130 _rows.relocateIndex(i, _rows.maxIndex()); 131 131 } 132 132 133 133 void SoplexLp::_getColName(int c, std::string &name) const { … … 432 432 _col_names_ref.clear(); 433 433 _row_names.clear(); 434 434 _row_names_ref.clear(); 435 cols.clear();436 rows.clear();435 _cols.clear(); 436 _rows.clear(); 437 437 _clear_temporals(); 438 438 } 439 439 -
CMakeLists.txt
# HG changeset patch # User Alpar Juttner <alpar@cs.elte.hu> # Date 1428993580 -7200 # Tue Apr 14 08:39:40 2015 +0200 # Node ID 4add05447ca00f659a054e88a7e0842a66f8b041 # Parent 0759d974de816af3492dff5e02de2d361ad27841 Tests and bugfixes for the STL style iterators (#325) diff --git a/CMakeLists.txt b/CMakeLists.txt
a b 264 264 265 265 266 266 INCLUDE(CheckCXXCompilerFlag) 267 CHECK_CXX_COMPILER_FLAG("-std=c++11" CXX11FLAG)268 IF( CXX11FLAG)267 CHECK_CXX_COMPILER_FLAG("-std=c++11" LEMON_CXX11) 268 IF(LEMON_CXX11) 269 269 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") 270 270 ENDIF() 271 271 -
lemon/bellman_ford.h
diff --git a/lemon/bellman_ford.h b/lemon/bellman_ford.h
a b 701 701 /// like an STL container (by having begin() and end()) 702 702 /// which you can use in range-based for loops, STL algorithms, etc. 703 703 LemonRangeWrapper1<ActiveIt, BellmanFord> 704 activeNodes(const BellmanFord& algorithm) const {705 return LemonRangeWrapper1<ActiveIt, BellmanFord>( algorithm);704 activeNodes() const { 705 return LemonRangeWrapper1<ActiveIt, BellmanFord>(*this); 706 706 } 707 707 708 708 -
lemon/bits/edge_set_extender.h
diff --git a/lemon/bits/edge_set_extender.h b/lemon/bits/edge_set_extender.h
a b 113 113 114 114 }; 115 115 116 LemonRangeWrapper1<NodeIt, Digraph> nodes() const { 117 return LemonRangeWrapper1<NodeIt, Digraph>(*this); 118 } 116 119 117 120 class ArcIt : public Arc { 118 121 const Digraph* digraph; … … 136 139 137 140 }; 138 141 142 LemonRangeWrapper1<ArcIt, Digraph> arcs() const { 143 return LemonRangeWrapper1<ArcIt, Digraph>(*this); 144 } 139 145 140 146 class OutArcIt : public Arc { 141 147 const Digraph* digraph; … … 160 166 161 167 }; 162 168 169 LemonRangeWrapper2<OutArcIt, Digraph, Node> outArcs(const Node& u) const { 170 return LemonRangeWrapper2<OutArcIt, Digraph, Node>(*this, u); 171 } 163 172 164 173 class InArcIt : public Arc { 165 174 const Digraph* digraph; … … 184 193 185 194 }; 186 195 196 LemonRangeWrapper2<InArcIt, Digraph, Node> inArcs(const Node& u) const { 197 return LemonRangeWrapper2<InArcIt, Digraph, Node>(*this, u); 198 } 199 187 200 // \brief Base node of the iterator 188 201 // 189 202 // Returns the base node (ie. the source in this case) of the iterator … … 372 385 373 386 }; 374 387 388 LemonRangeWrapper1<NodeIt, Graph> nodes() const { 389 return LemonRangeWrapper1<NodeIt, Graph>(*this); 390 } 375 391 376 392 class ArcIt : public Arc { 377 393 const Graph* graph; … … 395 411 396 412 }; 397 413 414 LemonRangeWrapper1<ArcIt, Graph> arcs() const { 415 return LemonRangeWrapper1<ArcIt, Graph>(*this); 416 } 398 417 399 418 class OutArcIt : public Arc { 400 419 const Graph* graph; … … 419 438 420 439 }; 421 440 441 LemonRangeWrapper2<OutArcIt, Graph, Node> outArcs(const Node& u) const { 442 return LemonRangeWrapper2<OutArcIt, Graph, Node>(*this, u); 443 } 422 444 423 445 class InArcIt : public Arc { 424 446 const Graph* graph; … … 443 465 444 466 }; 445 467 468 LemonRangeWrapper2<InArcIt, Graph, Node> inArcs(const Node& u) const { 469 return LemonRangeWrapper2<InArcIt, Graph, Node>(*this, u); 470 } 446 471 447 472 class EdgeIt : public Parent::Edge { 448 473 const Graph* graph; … … 466 491 467 492 }; 468 493 494 LemonRangeWrapper1<EdgeIt, Graph> edges() const { 495 return LemonRangeWrapper1<EdgeIt, Graph>(*this); 496 } 497 469 498 class IncEdgeIt : public Parent::Edge { 470 499 friend class EdgeSetExtender; 471 500 const Graph* graph; … … 491 520 } 492 521 }; 493 522 523 LemonRangeWrapper2<IncEdgeIt, Graph, Node> incEdges(const Node& u) const { 524 return LemonRangeWrapper2<IncEdgeIt, Graph, Node>(*this, u); 525 } 526 494 527 // \brief Base node of the iterator 495 528 // 496 529 // Returns the base node (ie. the source in this case) of the iterator -
lemon/bits/graph_adaptor_extender.h
diff --git a/lemon/bits/graph_adaptor_extender.h b/lemon/bits/graph_adaptor_extender.h
a b 85 85 86 86 }; 87 87 88 LemonRangeWrapper1<NodeIt, Adaptor> nodes() {88 LemonRangeWrapper1<NodeIt, Adaptor> nodes() const { 89 89 return LemonRangeWrapper1<NodeIt, Adaptor>(*this); 90 90 } 91 91 … … 111 111 112 112 }; 113 113 114 LemonRangeWrapper1<ArcIt, Adaptor> arcs() {114 LemonRangeWrapper1<ArcIt, Adaptor> arcs() const { 115 115 return LemonRangeWrapper1<ArcIt, Adaptor>(*this); 116 116 } 117 117 … … 269 269 270 270 }; 271 271 272 LemonRangeWrapper1<NodeIt, Adaptor> nodes() {272 LemonRangeWrapper1<NodeIt, Adaptor> nodes() const { 273 273 return LemonRangeWrapper1<NodeIt, Adaptor>(*this); 274 274 } 275 275 … … 296 296 297 297 }; 298 298 299 LemonRangeWrapper1<ArcIt, Adaptor> arcs() {299 LemonRangeWrapper1<ArcIt, Adaptor> arcs() const { 300 300 return LemonRangeWrapper1<ArcIt, Adaptor>(*this); 301 301 } 302 302 … … 378 378 379 379 }; 380 380 381 LemonRangeWrapper1<EdgeIt, Adaptor> edges() {381 LemonRangeWrapper1<EdgeIt, Adaptor> edges() const { 382 382 return LemonRangeWrapper1<EdgeIt, Adaptor>(*this); 383 383 } 384 384 -
lemon/config.h.in
diff --git a/lemon/config.h.in b/lemon/config.h.in
a b 1 1 #define LEMON_VERSION "@PROJECT_VERSION@" 2 2 #cmakedefine LEMON_HAVE_LONG_LONG 1 3 3 4 #cmakedefine LEMON_CXX11 1 5 4 6 #cmakedefine LEMON_HAVE_LP 1 5 7 #cmakedefine LEMON_HAVE_MIP 1 6 8 #cmakedefine LEMON_HAVE_GLPK 1 -
lemon/list_graph.h
diff --git a/lemon/list_graph.h b/lemon/list_graph.h
a b 1209 1209 /// 1210 1210 ListGraph() {} 1211 1211 1212 typedef Parent:: OutArcIt IncEdgeIt;1212 typedef Parent::IncEdgeIt IncEdgeIt; 1213 1213 1214 1214 /// \brief Add a new node to the graph. 1215 1215 /// … … 2136 2136 /// 2137 2137 ListBpGraph() {} 2138 2138 2139 typedef Parent:: OutArcIt IncEdgeIt;2139 typedef Parent::IncEdgeIt IncEdgeIt; 2140 2140 2141 2141 /// \brief Add a new red node to the graph. 2142 2142 /// -
test/bellman_ford_test.cc
diff --git a/test/bellman_ford_test.cc b/test/bellman_ford_test.cc
a b 101 101 pp = const_bf_test.negativeCycle(); 102 102 103 103 for (BF::ActiveIt it(const_bf_test); it != INVALID; ++it) {} 104 for (auto n: const_bf_test.activeNodes()) { ::lemon::ignore_unused_variable_warning(n); } 105 for (Digraph::Node n: const_bf_test.activeNodes()) { 106 ::lemon::ignore_unused_variable_warning(n); 107 } 104 108 } 105 109 { 106 110 BF::SetPredMap<concepts::ReadWriteMap<Node,Arc> > -
test/graph_test.h
diff --git a/test/graph_test.h b/test/graph_test.h
a b 38 38 } 39 39 check(n==INVALID,"Wrong Node list linking."); 40 40 check(countNodes(G)==cnt,"Wrong Node number."); 41 42 #ifdef LEMON_CXX11 43 { 44 typename Graph::NodeIt n(G); 45 for(auto u: G.nodes()) 46 { 47 check(n==u,"Wrong STL Node iterator."); 48 ++n; 49 } 50 check(n==INVALID,"Wrong STL Node iterator."); 51 } 52 { 53 typename Graph::NodeIt n(G); 54 for(typename Graph::Node u: G.nodes()) 55 { 56 check(n==u,"Wrong STL Node iterator."); 57 ++n; 58 } 59 check(n==INVALID,"Wrong STL Node iterator."); 60 } 61 #endif 41 62 } 42 63 43 64 template<class Graph> … … 56 77 } 57 78 check(n==INVALID,"Wrong red Node list linking."); 58 79 check(countRedNodes(G)==cnt,"Wrong red Node number."); 80 #ifdef LEMON_CXX11 81 { 82 typename Graph::RedNodeIt n(G); 83 for(auto u: G.redNodes()) 84 { 85 check(n==u,"Wrong STL RedNode iterator."); 86 ++n; 87 } 88 check(n==INVALID,"Wrong STL RedNode iterator."); 89 } 90 { 91 typename Graph::RedNodeIt n(G); 92 for(typename Graph::RedNode u: G.redNodes()) 93 { 94 check(n==u,"Wrong STL RedNode iterator."); 95 ++n; 96 } 97 check(n==INVALID,"Wrong STL RedNode iterator."); 98 } 99 #endif 59 100 } 60 101 61 102 template<class Graph> … … 74 115 } 75 116 check(n==INVALID,"Wrong blue Node list linking."); 76 117 check(countBlueNodes(G)==cnt,"Wrong blue Node number."); 118 #ifdef LEMON_CXX11 119 { 120 typename Graph::BlueNodeIt n(G); 121 for(auto u: G.blueNodes()) 122 { 123 check(n==u,"Wrong STL BlueNode iterator."); 124 ++n; 125 } 126 check(n==INVALID,"Wrong STL BlueNode iterator."); 127 } 128 { 129 typename Graph::BlueNodeIt n(G); 130 for(typename Graph::BlueNode u: G.blueNodes()) 131 { 132 check(n==u,"Wrong STL BlueNode iterator."); 133 ++n; 134 } 135 check(n==INVALID,"Wrong STL BlueNode iterator."); 136 } 137 #endif 138 77 139 } 78 140 79 141 template<class Graph> … … 90 152 } 91 153 check(e==INVALID,"Wrong Arc list linking."); 92 154 check(countArcs(G)==cnt,"Wrong Arc number."); 155 #ifdef LEMON_CXX11 156 { 157 typename Graph::ArcIt a(G); 158 for(auto e: G.arcs()) 159 { 160 check(a==e,"Wrong STL Arc iterator."); 161 ++a; 162 } 163 check(a==INVALID,"Wrong STL Arc iterator."); 164 } 165 { 166 typename Graph::ArcIt a(G); 167 for(typename Graph::Arc e: G.arcs()) 168 { 169 check(a==e,"Wrong STL Arc iterator."); 170 ++a; 171 } 172 check(a==INVALID,"Wrong STL Arc iterator."); 173 } 174 #endif 175 93 176 } 94 177 95 178 template<class Graph> … … 105 188 } 106 189 check(e==INVALID,"Wrong OutArc list linking."); 107 190 check(countOutArcs(G,n)==cnt,"Wrong OutArc number."); 191 #ifdef LEMON_CXX11 192 { 193 typename Graph::OutArcIt a(G,n); 194 for(auto e: G.outArcs(n)) 195 { 196 check(a==e,"Wrong STL OutArc iterator."); 197 ++a; 198 } 199 check(a==INVALID,"Wrong STL OutArc iterator."); 200 } 201 { 202 typename Graph::OutArcIt a(G,n); 203 for(typename Graph::Arc e: G.outArcs(n)) 204 { 205 check(a==e,"Wrong STL OutArc iterator."); 206 ++a; 207 } 208 check(a==INVALID,"Wrong STL OutArc iterator."); 209 } 210 #endif 211 108 212 } 109 213 110 214 template<class Graph> … … 120 224 } 121 225 check(e==INVALID,"Wrong InArc list linking."); 122 226 check(countInArcs(G,n)==cnt,"Wrong InArc number."); 227 #ifdef LEMON_CXX11 228 { 229 typename Graph::InArcIt a(G,n); 230 for(auto e: G.inArcs(n)) 231 { 232 check(a==e,"Wrong STL InArc iterator."); 233 ++a; 234 } 235 check(a==INVALID,"Wrong STL InArc iterator."); 236 } 237 { 238 typename Graph::InArcIt a(G,n); 239 for(typename Graph::Arc e: G.inArcs(n)) 240 { 241 check(a==e,"Wrong STL InArc iterator."); 242 ++a; 243 } 244 check(a==INVALID,"Wrong STL InArc iterator."); 245 } 246 #endif 123 247 } 124 248 125 249 template<class Graph> … … 134 258 } 135 259 check(e==INVALID,"Wrong Edge list linking."); 136 260 check(countEdges(G)==cnt,"Wrong Edge number."); 261 #ifdef LEMON_CXX11 262 { 263 typename Graph::EdgeIt a(G); 264 for(auto e: G.edges()) 265 { 266 check(a==e,"Wrong STL Edge iterator."); 267 ++a; 268 } 269 check(a==INVALID,"Wrong STL Edge iterator."); 270 } 271 { 272 typename Graph::EdgeIt a(G); 273 for(typename Graph::Edge e: G.edges()) 274 { 275 check(a==e,"Wrong STL Edge iterator."); 276 ++a; 277 } 278 check(a==INVALID,"Wrong STL Edge iterator."); 279 } 280 #endif 281 137 282 } 138 283 139 284 template<class Graph> … … 150 295 } 151 296 check(e==INVALID,"Wrong IncEdge list linking."); 152 297 check(countIncEdges(G,n)==cnt,"Wrong IncEdge number."); 298 #ifdef LEMON_CXX11 299 { 300 typename Graph::IncEdgeIt a(G,n); 301 for(auto e: G.incEdges(n)) 302 { 303 check(a==e,"Wrong STL IncEdge iterator."); 304 ++a; 305 } 306 check(a==INVALID,"Wrong STL IncEdge iterator."); 307 } 308 { 309 typename Graph::IncEdgeIt a(G,n); 310 for(typename Graph::Edge e: G.incEdges(n)) 311 { 312 check(a==e,"Wrong STL IncEdge iterator."); 313 ++a; 314 } 315 check(a==INVALID,"Wrong STL IncEdge iterator."); 316 } 317 #endif 318 153 319 } 154 320 155 321 template <class Graph> -
test/lp_test.cc
diff --git a/test/lp_test.cc b/test/lp_test.cc
a b 20 20 #include <lemon/lp_skeleton.h> 21 21 #include "test_tools.h" 22 22 #include <lemon/tolerance.h> 23 23 #include <lemon/concept_check.h> 24 24 #include <lemon/config.h> 25 25 26 26 #ifdef LEMON_HAVE_GLPK … … 47 47 int countCols(LpBase & lp) { 48 48 int count=0; 49 49 for (LpBase::ColIt c(lp); c!=INVALID; ++c) ++count; 50 #ifdef LEMON_CXX11 51 int cnt = 0; 52 for(auto c: lp.cols()) { cnt++; ::lemon::ignore_unused_variable_warning(c); } 53 check(count == cnt, "Wrong STL iterator"); 54 #endif 50 55 return count; 51 56 } 52 57 53 58 int countRows(LpBase & lp) { 54 59 int count=0; 55 60 for (LpBase::RowIt r(lp); r!=INVALID; ++r) ++count; 61 #ifdef LEMON_CXX11 62 int cnt = 0; 63 for(auto r: lp.rows()) { cnt++; ::lemon::ignore_unused_variable_warning(r); } 64 check(count == cnt, "Wrong STL iterator"); 65 #endif 56 66 return count; 57 67 } 58 68 -
test/maps_test.cc
diff --git a/test/maps_test.cc b/test/maps_test.cc
a b 730 730 } 731 731 check(n == 3, "Wrong number"); 732 732 check(map1.falseNum() == 3, "Wrong number"); 733 734 #ifdef LEMON_CXX11 735 { 736 int c = 0; 737 for(auto v: map1.items(false)) { c++; ::lemon::ignore_unused_variable_warning(v); } 738 check(c == map1.falseNum(), "Wrong number"); 739 } 740 { 741 int c = 0; 742 for(auto v: map1.items(true)) { c++; ::lemon::ignore_unused_variable_warning(v); } 743 check(c == map1.trueNum(), "Wrong number"); 744 } 745 { 746 int c = 0; 747 for(auto v: map1.falseKeys()) { c++; ::lemon::ignore_unused_variable_warning(v); } 748 check(c == map1.falseNum(), "Wrong number"); 749 } 750 { 751 int c = 0; 752 for(auto v: map1.trueKeys()) { c++; ::lemon::ignore_unused_variable_warning(v); } 753 check(c == map1.trueNum(), "Wrong number"); 754 } 755 #endif 756 733 757 } 734 758 735 759 // Iterable int map … … 780 804 ++n; 781 805 } 782 806 check(n == num, "Wrong number"); 807 #ifdef LEMON_CXX11 808 { 809 int c = 0; 810 for(auto v: map1.items(0)) { c++; ::lemon::ignore_unused_variable_warning(v); } 811 check(c == (num + 1) / 2, "Wrong number"); 812 for(auto v: map1.items(1)) { c++; ::lemon::ignore_unused_variable_warning(v); } 813 check(c == num, "Wrong number"); 814 } 815 #endif 783 816 784 817 } 785 818 … … 839 872 } 840 873 check(n == num, "Wrong number"); 841 874 875 #ifdef LEMON_CXX11 876 { 877 int c = 0; 878 for(auto v: map1.items(0.0)) { c++; ::lemon::ignore_unused_variable_warning(v); } 879 check(c == (num + 1) / 2, "Wrong number"); 880 for(auto v: map1.items(1.0)) { c++; ::lemon::ignore_unused_variable_warning(v); } 881 check(c == num, "Wrong number"); 882 } 883 #endif 884 842 885 } 843 886 844 887 // Graph map utilities: -
lemon/bits/path_dump.h
# HG changeset patch # User Alpar Juttner <alpar@cs.elte.hu> # Date 1429003747 -7200 # Tue Apr 14 11:29:07 2015 +0200 # Node ID 72af84645ac2813057d8328e1eaef630c252ca48 # Parent 4add05447ca00f659a054e88a7e0842a66f8b041 Clang -std=c++11 related fixes (#325) diff --git a/lemon/bits/path_dump.h b/lemon/bits/path_dump.h
a b 61 61 if (path->predMap[current] == INVALID) current = INVALID; 62 62 } 63 63 64 operator consttypename Digraph::Arc() const {64 operator typename Digraph::Arc() const { 65 65 return path->predMap[current]; 66 66 } 67 67 -
lemon/bits/stl_iterators.h
diff --git a/lemon/bits/stl_iterators.h b/lemon/bits/stl_iterators.h
a b 86 86 public: 87 87 LemonRangeWrapper2(const P1 &p1, const P2 &p2) : _p1(p1), _p2(p2) {} 88 88 It begin() const { 89 return It(LIT(_p1, _p2)); 89 LIT lit(_p1,_p2); 90 It it(lit); 91 return it; 90 92 } 91 93 It end() const { 92 94 return It(lemon::INVALID); -
lemon/maps.h
diff --git a/lemon/maps.h b/lemon/maps.h
a b 2658 2658 /// keys mapped to the given value. 2659 2659 /// \param map The IterableBoolMap. 2660 2660 /// \param value The value. 2661 ItemIt(const IterableBoolMap& map, bool value) 2662 : Parent(value ? 2663 (map._sep > 0 ? 2664 map._array[map._sep - 1] : INVALID) : 2665 (map._sep < int(map._array.size()) ? 2666 map._array.back() : INVALID)), _map(&map) {} 2661 ItemIt(const IterableBoolMap& map, bool) 2662 // : Parent(value ? 2663 // (map._sep > 0 ? 2664 // map._array[map._sep - 1] : INVALID) : 2665 // (map._sep < int(map._array.size()) ? 2666 // map._array.back() : INVALID)), _map(&map) {} 2667 : _map(&map) 2668 { 2669 // if(value) 2670 // if(map._sep > 0) 2671 // Parent(*this) = map._array[map._sep - 1]; 2672 // else Parent(*this) = INVALID; 2673 // else if(map._sep < int(map._array.size())) 2674 // Parent(*this) = map._array.back(); 2675 // else 2676 Parent(*this) = INVALID; 2677 } 2667 2678 2668 2679 /// \brief Invalid constructor \& conversion. 2669 2680 /// -
lemon/random.h
diff --git a/lemon/random.h b/lemon/random.h
a b 249 249 250 250 current = state + length; 251 251 252 registerWord *curr = state + length - 1;253 registerlong num;252 Word *curr = state + length - 1; 253 long num; 254 254 255 255 num = length - shift; 256 256 while (num--) {