Ticket #67: 7a4a426a037e.patch
File 7a4a426a037e.patch, 38.4 KB (added by , 16 years ago) |
---|
-
lemon/digraph_adaptor.h
# HG changeset patch # User Balazs Dezso <deba@inf.elte.hu> # Date 1227287720 -3600 # Node ID 7a4a426a037e22194bf240a2d349021bd70662cb # Parent e67acd83a9ca0c54b66d8a127273e0301d7cdea8 Improvments in graph adaptors Remove DigraphAdaptor and GraphAdaptor Remove docs of base classes Moving the member documentations to real adaptors Minor improvements in documentation diff -r e67acd83a9ca -r 7a4a426a037e lemon/digraph_adaptor.h
a b 23 23 ///\file 24 24 ///\brief Several digraph adaptors. 25 25 /// 26 ///This file contains several useful digraph adaptor functions.26 ///This file contains several useful digraph adaptor classes. 27 27 28 28 #include <lemon/core.h> 29 29 #include <lemon/maps.h> … … 38 38 39 39 namespace lemon { 40 40 41 ///\brief Base type for the Digraph Adaptors42 ///43 ///Base type for the Digraph Adaptors44 ///45 ///This is the base type for most of LEMON digraph adaptors. This46 ///class implements a trivial digraph adaptor i.e. it only wraps the47 ///functions and types of the digraph. The purpose of this class is48 ///to make easier implementing digraph adaptors. E.g. if an adaptor49 ///is considered which differs from the wrapped digraph only in some50 ///of its functions or types, then it can be derived from51 ///DigraphAdaptor, and only the differences should be implemented.52 41 template<typename _Digraph> 53 42 class DigraphAdaptorBase { 54 43 public: … … 164 153 165 154 }; 166 155 167 ///\ingroup graph_adaptors168 ///169 ///\brief Trivial Digraph Adaptor170 ///171 /// This class is an adaptor which does not change the adapted172 /// digraph. It can be used only to test the digraph adaptors.173 template <typename _Digraph>174 class DigraphAdaptor :175 public DigraphAdaptorExtender<DigraphAdaptorBase<_Digraph> > {176 public:177 typedef _Digraph Digraph;178 typedef DigraphAdaptorExtender<DigraphAdaptorBase<_Digraph> > Parent;179 protected:180 DigraphAdaptor() : Parent() { }181 182 public:183 explicit DigraphAdaptor(Digraph& digraph) { setDigraph(digraph); }184 };185 186 /// \brief Just gives back a digraph adaptor187 ///188 /// Just gives back a digraph adaptor which189 /// should be provide original digraph190 template<typename Digraph>191 DigraphAdaptor<const Digraph>192 digraphAdaptor(const Digraph& digraph) {193 return DigraphAdaptor<const Digraph>(digraph);194 }195 196 156 197 157 template <typename _Digraph> 198 158 class RevDigraphAdaptorBase : public DigraphAdaptorBase<_Digraph> { … … 229 189 /// 230 190 /// If \c g is defined as 231 191 ///\code 232 /// ListDigraph g;192 /// ListDigraph dg; 233 193 ///\endcode 234 194 /// then 235 195 ///\code 236 /// RevDigraphAdaptor<ListDigraph> ga(g);196 /// RevDigraphAdaptor<ListDigraph> dga(dg); 237 197 ///\endcode 238 /// implements the digraph obtained from \c g by198 /// implements the digraph obtained from \c dg by 239 199 /// reversing the orientation of its arcs. 240 200 /// 241 /// A good example of using RevDigraphAdaptor is to decide that the 242 /// directed graph is wheter strongly connected or not. If from one 243 /// node each node is reachable and from each node is reachable this 244 /// node then and just then the digraph is strongly 245 /// connected. Instead of this condition we use a little bit 246 /// different. From one node each node ahould be reachable in the 247 /// digraph and in the reversed digraph. Now this condition can be 248 /// checked with the Dfs algorithm class and the RevDigraphAdaptor 249 /// algorithm class. 201 /// A good example of using RevDigraphAdaptor is to decide whether 202 /// the directed graph is strongly connected or not. The digraph is 203 /// strongly connected iff each node is reachable from one node and 204 /// this node is reachable from the others. Instead of this 205 /// condition we use a slightly different, from one node each node 206 /// is reachable both in the digraph and the reversed digraph. Now 207 /// this condition can be checked with the Dfs algorithm and the 208 /// RevDigraphAdaptor class. 250 209 /// 251 /// And look at the code: 252 /// 210 /// The implementation: 253 211 ///\code 254 212 /// bool stronglyConnected(const Digraph& digraph) { 255 213 /// if (NodeIt(digraph) == INVALID) return true; … … 282 240 protected: 283 241 RevDigraphAdaptor() { } 284 242 public: 243 244 /// \brief Constructor 245 /// 246 /// Creates a reverse graph adaptor for the given digraph 285 247 explicit RevDigraphAdaptor(Digraph& digraph) { 286 248 Parent::setDigraph(digraph); 287 249 } … … 372 334 || !(*_node_filter)[Parent::target(i)])) Parent::nextOut(i); 373 335 } 374 336 375 ///\e376 377 /// This function hides \c n in the digraph, i.e. the iteration378 /// jumps over it. This is done by simply setting the value of \c n379 /// to be false in the corresponding node-map.380 337 void hide(const Node& n) const { _node_filter->set(n, false); } 381 382 ///\e383 384 /// This function hides \c a in the digraph, i.e. the iteration385 /// jumps over it. This is done by simply setting the value of \c a386 /// to be false in the corresponding arc-map.387 338 void hide(const Arc& a) const { _arc_filter->set(a, false); } 388 339 389 ///\e 390 391 /// The value of \c n is set to be true in the node-map which stores 392 /// hide information. If \c n was hidden previuosly, then it is shown 393 /// again 394 void unHide(const Node& n) const { _node_filter->set(n, true); } 395 396 ///\e 397 398 /// The value of \c a is set to be true in the arc-map which stores 399 /// hide information. If \c a was hidden previuosly, then it is shown 400 /// again 340 void unHide(const Node& n) const { _node_filter->set(n, true); } 401 341 void unHide(const Arc& a) const { _arc_filter->set(a, true); } 402 342 403 /// Returns true if \c n is hidden.404 405 ///\e406 ///407 343 bool hidden(const Node& n) const { return !(*_node_filter)[n]; } 408 409 /// Returns true if \c a is hidden.410 411 ///\e412 ///413 344 bool hidden(const Arc& a) const { return !(*_arc_filter)[a]; } 414 345 415 346 typedef False NodeNumTag; … … 544 475 while (i!=INVALID && !(*_arc_filter)[i]) Parent::nextOut(i); 545 476 } 546 477 547 ///\e548 549 /// This function hides \c n in the digraph, i.e. the iteration550 /// jumps over it. This is done by simply setting the value of \c n551 /// to be false in the corresponding node-map.552 478 void hide(const Node& n) const { _node_filter->set(n, false); } 553 554 ///\e555 556 /// This function hides \c e in the digraph, i.e. the iteration557 /// jumps over it. This is done by simply setting the value of \c e558 /// to be false in the corresponding arc-map.559 479 void hide(const Arc& e) const { _arc_filter->set(e, false); } 560 480 561 ///\e 562 563 /// The value of \c n is set to be true in the node-map which stores 564 /// hide information. If \c n was hidden previuosly, then it is shown 565 /// again 566 void unHide(const Node& n) const { _node_filter->set(n, true); } 567 568 ///\e 569 570 /// The value of \c e is set to be true in the arc-map which stores 571 /// hide information. If \c e was hidden previuosly, then it is shown 572 /// again 481 void unHide(const Node& n) const { _node_filter->set(n, true); } 573 482 void unHide(const Arc& e) const { _arc_filter->set(e, true); } 574 483 575 /// Returns true if \c n is hidden.576 577 ///\e578 ///579 484 bool hidden(const Node& n) const { return !(*_node_filter)[n]; } 580 581 /// Returns true if \c n is hidden.582 583 ///\e584 ///585 485 bool hidden(const Arc& e) const { return !(*_arc_filter)[e]; } 586 486 587 487 typedef False NodeNumTag; … … 655 555 /// \brief A digraph adaptor for hiding nodes and arcs from a digraph. 656 556 /// 657 557 /// SubDigraphAdaptor shows the digraph with filtered node-set and 658 /// arc-set. If the \c checked parameter is true then it filters the arcset 659 /// to do not get invalid arcs without source or target. 660 /// Let \f$ G=(V, A) \f$ be a directed digraph 661 /// and suppose that the digraph instance \c g of type ListDigraph 662 /// implements \f$ G \f$. 663 /// Let moreover \f$ b_V \f$ and \f$ b_A \f$ be bool-valued functions resp. 664 /// on the node-set and arc-set. 665 /// SubDigraphAdaptor<...>::NodeIt iterates 666 /// on the node-set \f$ \{v\in V : b_V(v)=true\} \f$ and 667 /// SubDigraphAdaptor<...>::ArcIt iterates 668 /// on the arc-set \f$ \{e\in A : b_A(e)=true\} \f$. Similarly, 669 /// SubDigraphAdaptor<...>::OutArcIt and 670 /// SubDigraphAdaptor<...>::InArcIt iterates 671 /// only on arcs leaving and entering a specific node which have true value. 558 /// arc-set. If the \c checked parameter is true then it filters the arc-set 559 /// respect to the source and target. 672 560 /// 673 /// If the \c checked template parameter is false then we have to674 /// no te that the node-iterator cares only the filter onthe675 /// node-set, and the arc-iterator cares only the filter on the676 /// arc-set. This way the arc-map should filter all arcs which's677 /// source or target isfiltered by the node-filter.561 /// If the \c checked template parameter is false then the 562 /// node-iterator cares only the filter on the node-set, and the 563 /// arc-iterator cares only the filter on the arc-set. Therefore 564 /// the arc-map have to filter all arcs which's source or target is 565 /// filtered by the node-filter. 678 566 ///\code 679 567 /// typedef ListDigraph Digraph; 680 568 /// DIGRAPH_TYPEDEFS(Digraph); … … 687 575 /// nm.set(u, false); 688 576 /// BoolArcMap am(g, true); 689 577 /// am.set(a, false); 690 /// typedef SubDigraphAdaptor<Digraph, BoolNodeMap, BoolArcMap> Sub GA;691 /// Sub GA ga(g, nm, am);692 /// for (Sub GA::NodeIt n(ga); n!=INVALID; ++n)578 /// typedef SubDigraphAdaptor<Digraph, BoolNodeMap, BoolArcMap> SubDGA; 579 /// SubDGA ga(g, nm, am); 580 /// for (SubDGA::NodeIt n(ga); n!=INVALID; ++n) 693 581 /// std::cout << g.id(n) << std::endl; 694 /// std::cout << ":-)" << std::endl; 695 /// for (SubGA::ArcIt a(ga); a!=INVALID; ++a) 582 /// for (SubDGA::ArcIt a(ga); a!=INVALID; ++a) 696 583 /// std::cout << g.id(a) << std::endl; 697 584 ///\endcode 698 585 /// The output of the above code is the following. 699 586 ///\code 700 587 /// 1 701 /// :-)702 588 /// 1 703 589 ///\endcode 704 /// Note that \c n is of type \c Sub GA::NodeIt, but it can be converted to590 /// Note that \c n is of type \c SubDGA::NodeIt, but it can be converted to 705 591 /// \c Digraph::Node that is why \c g.id(n) can be applied. 706 592 /// 707 593 /// For other examples see also the documentation of … … 722 608 SubDigraphAdaptorBase<Digraph, NodeFilterMap, ArcFilterMap, checked> > 723 609 Parent; 724 610 611 typedef typename Parent::Node Node; 612 typedef typename Parent::Arc Arc; 613 725 614 protected: 726 615 SubDigraphAdaptor() { } 727 616 public: 728 617 618 /// \brief Constructor 619 /// 620 /// Creates a sub-digraph-adaptor for the given digraph with 621 /// given node and arc map filters. 729 622 SubDigraphAdaptor(Digraph& digraph, NodeFilterMap& node_filter, 730 623 ArcFilterMap& arc_filter) { 731 624 setDigraph(digraph); … … 733 626 setArcFilterMap(arc_filter); 734 627 } 735 628 629 /// \brief Hides the node of the graph 630 /// 631 /// This function hides \c n in the digraph, i.e. the iteration 632 /// jumps over it. This is done by simply setting the value of \c n 633 /// to be false in the corresponding node-map. 634 void hide(const Node& n) const { Parent::hide(n); } 635 636 /// \brief Hides the arc of the graph 637 /// 638 /// This function hides \c a in the digraph, i.e. the iteration 639 /// jumps over it. This is done by simply setting the value of \c a 640 /// to be false in the corresponding arc-map. 641 void hide(const Arc& a) const { Parent::hide(a); } 642 643 /// \brief Unhides the node of the graph 644 /// 645 /// The value of \c n is set to be true in the node-map which stores 646 /// hide information. If \c n was hidden previuosly, then it is shown 647 /// again 648 void unHide(const Node& n) const { Parent::unHide(n); } 649 650 /// \brief Unhides the arc of the graph 651 /// 652 /// The value of \c a is set to be true in the arc-map which stores 653 /// hide information. If \c a was hidden previuosly, then it is shown 654 /// again 655 void unHide(const Arc& a) const { Parent::unHide(a); } 656 657 /// \brief Returns true if \c n is hidden. 658 /// 659 /// Returns true if \c n is hidden. 660 /// 661 bool hidden(const Node& n) const { return Parent::hidden(n); } 662 663 /// \brief Returns true if \c a is hidden. 664 /// 665 /// Returns true if \c a is hidden. 666 /// 667 bool hidden(const Arc& a) const { return Parent::hidden(a); } 668 736 669 }; 737 670 738 /// \brief Just gives back a sub digraphadaptor671 /// \brief Just gives back a sub-digraph-adaptor 739 672 /// 740 /// Just gives back a sub digraphadaptor673 /// Just gives back a sub-digraph-adaptor 741 674 template<typename Digraph, typename NodeFilterMap, typename ArcFilterMap> 742 675 SubDigraphAdaptor<const Digraph, NodeFilterMap, ArcFilterMap> 743 676 subDigraphAdaptor(const Digraph& digraph, … … 768 701 NodeFilterMap& nfm, ArcFilterMap& afm) { 769 702 return SubDigraphAdaptor<const Digraph, const NodeFilterMap, 770 703 const ArcFilterMap>(digraph, nfm, afm); 704 771 705 } 772 706 773 707 … … 796 730 ConstMap<typename Digraph::Arc, bool>, checked> 797 731 Parent; 798 732 733 typedef typename Parent::Node Node; 734 799 735 protected: 800 736 ConstMap<typename Digraph::Arc, bool> const_true_map; 801 737 … … 805 741 806 742 public: 807 743 744 /// \brief Constructor 745 /// 746 /// Creates a node-sub-digraph-adaptor for the given digraph with 747 /// given node map filter. 808 748 NodeSubDigraphAdaptor(Digraph& _digraph, NodeFilterMap& node_filter) : 809 749 Parent(), const_true_map(true) { 810 750 Parent::setDigraph(_digraph); … … 812 752 Parent::setArcFilterMap(const_true_map); 813 753 } 814 754 755 /// \brief Hides the node of the graph 756 /// 757 /// This function hides \c n in the digraph, i.e. the iteration 758 /// jumps over it. This is done by simply setting the value of \c n 759 /// to be false in the corresponding node-map. 760 void hide(const Node& n) const { Parent::hide(n); } 761 762 /// \brief Unhides the node of the graph 763 /// 764 /// The value of \c n is set to be true in the node-map which stores 765 /// hide information. If \c n was hidden previuosly, then it is shown 766 /// again 767 void unHide(const Node& n) const { Parent::unHide(n); } 768 769 /// \brief Returns true if \c n is hidden. 770 /// 771 /// Returns true if \c n is hidden. 772 /// 773 bool hidden(const Node& n) const { return Parent::hidden(n); } 774 815 775 }; 816 776 817 777 818 /// \brief Just gives back a \c NodeSubDigraphAdaptor778 /// \brief Just gives back a node-sub-digraph adaptor 819 779 /// 820 /// Just gives back a \c NodeSubDigraphAdaptor780 /// Just gives back a node-sub-digraph adaptor 821 781 template<typename Digraph, typename NodeFilterMap> 822 782 NodeSubDigraphAdaptor<const Digraph, NodeFilterMap> 823 783 nodeSubDigraphAdaptor(const Digraph& digraph, NodeFilterMap& nfm) { … … 840 800 ///can be filtered. The usefulness of this adaptor is demonstrated 841 801 ///in the problem of searching a maximum number of arc-disjoint 842 802 ///shortest paths between two nodes \c s and \c t. Shortest here 843 ///means being shortest w.r.t. non-negative arc-lengths. Note that 844 ///the comprehension of the presented solution need's some 845 ///elementary knowlarc from combinatorial optimization. 803 ///means being shortest with respect to non-negative 804 ///arc-lengths. Note that the comprehension of the presented 805 ///solution need's some elementary knowledge from combinatorial 806 ///optimization. 846 807 /// 847 808 ///If a single shortest path is to be searched between \c s and \c 848 809 ///t, then this can be done easily by applying the Dijkstra … … 862 823 ///generated by the demo program \ref dim_to_dot.cc. 863 824 /// 864 825 ///\dot 865 ///di digraph lemon_dot_example {826 ///digraph lemon_dot_example { 866 827 ///node [ shape=ellipse, fontname=Helvetica, fontsize=10 ]; 867 828 ///n0 [ label="0 (s)" ]; 868 829 ///n1 [ label="1" ]; … … 968 929 969 930 typedef SubDigraphAdaptor<Digraph, ConstMap<typename Digraph::Node, bool>, 970 931 ArcFilterMap, false> Parent; 932 933 typedef typename Parent::Arc Arc; 934 971 935 protected: 972 936 ConstMap<typename Digraph::Node, bool> const_true_map; 973 937 … … 977 941 978 942 public: 979 943 944 /// \brief Constructor 945 /// 946 /// Creates a arc-sub-digraph-adaptor for the given digraph with 947 /// given arc map filter. 980 948 ArcSubDigraphAdaptor(Digraph& digraph, ArcFilterMap& arc_filter) 981 949 : Parent(), const_true_map(true) { 982 950 Parent::setDigraph(digraph); … … 984 952 Parent::setArcFilterMap(arc_filter); 985 953 } 986 954 955 /// \brief Hides the arc of the graph 956 /// 957 /// This function hides \c a in the digraph, i.e. the iteration 958 /// jumps over it. This is done by simply setting the value of \c a 959 /// to be false in the corresponding arc-map. 960 void hide(const Arc& a) const { Parent::hide(a); } 961 962 /// \brief Unhides the arc of the graph 963 /// 964 /// The value of \c a is set to be true in the arc-map which stores 965 /// hide information. If \c a was hidden previuosly, then it is shown 966 /// again 967 void unHide(const Arc& a) const { Parent::unHide(a); } 968 969 /// \brief Returns true if \c a is hidden. 970 /// 971 /// Returns true if \c a is hidden. 972 /// 973 bool hidden(const Arc& a) const { return Parent::hidden(a); } 974 987 975 }; 988 976 989 /// \brief Just gives back an arc subdigraph adaptor977 /// \brief Just gives back an arc-sub-digraph adaptor 990 978 /// 991 /// Just gives back an arc subdigraph adaptor979 /// Just gives back an arc-sub-digraph adaptor 992 980 template<typename Digraph, typename ArcFilterMap> 993 981 ArcSubDigraphAdaptor<const Digraph, ArcFilterMap> 994 982 arcSubDigraphAdaptor(const Digraph& digraph, ArcFilterMap& afm) { … … 1384 1372 1385 1373 ///\ingroup graph_adaptors 1386 1374 /// 1387 /// \brief A ngraph is made from a directed digraph by an adaptor1375 /// \brief A graph is made from a directed digraph by an adaptor 1388 1376 /// 1389 1377 /// This adaptor makes an undirected graph from a directed 1390 /// digraph. All arc of the underlying will be showed in the adaptor1391 /// a s an edge. Let's see an informal example about using1392 /// this adaptor :1378 /// graph. All arc of the underlying digraph will be showed in the 1379 /// adaptor as an edge. Let's see an informal example about using 1380 /// this adaptor. 1393 1381 /// 1394 1382 /// There is a network of the streets of a town. Of course there are 1395 1383 /// some one-way street in the town hence the network is a directed … … 1793 1781 1794 1782 }; 1795 1783 1796 /// \brief Base class for split digraph adaptor1797 ///1798 /// Base class of split digraph adaptor. In most case you do not need to1799 /// use it directly but the documented member functions of this class can1800 /// be used with the SplitDigraphAdaptor class.1801 /// \sa SplitDigraphAdaptor1802 1784 template <typename _Digraph> 1803 1785 class SplitDigraphAdaptorBase { 1804 1786 public: … … 2013 1995 (_digraph->maxArcId() << 1) | 1); 2014 1996 } 2015 1997 2016 /// \brief Returns true when the node is in-node.2017 ///2018 /// Returns true when the node is in-node.2019 1998 static bool inNode(const Node& n) { 2020 1999 return n._in; 2021 2000 } 2022 2001 2023 /// \brief Returns true when the node is out-node.2024 ///2025 /// Returns true when the node is out-node.2026 2002 static bool outNode(const Node& n) { 2027 2003 return !n._in; 2028 2004 } 2029 2005 2030 /// \brief Returns true when the arc is arc in the original digraph.2031 ///2032 /// Returns true when the arc is arc in the original digraph.2033 2006 static bool origArc(const Arc& e) { 2034 2007 return e._item.firstState(); 2035 2008 } 2036 2009 2037 /// \brief Returns true when the arc binds an in-node and an out-node.2038 ///2039 /// Returns true when the arc binds an in-node and an out-node.2040 2010 static bool bindArc(const Arc& e) { 2041 2011 return e._item.secondState(); 2042 2012 } 2043 2013 2044 /// \brief Gives back the in-node created from the \c node.2045 ///2046 /// Gives back the in-node created from the \c node.2047 2014 static Node inNode(const DigraphNode& n) { 2048 2015 return Node(n, true); 2049 2016 } 2050 2017 2051 /// \brief Gives back the out-node created from the \c node.2052 ///2053 /// Gives back the out-node created from the \c node.2054 2018 static Node outNode(const DigraphNode& n) { 2055 2019 return Node(n, false); 2056 2020 } 2057 2021 2058 /// \brief Gives back the arc binds the two part of the node.2059 ///2060 /// Gives back the arc binds the two part of the node.2061 2022 static Arc arc(const DigraphNode& n) { 2062 2023 return Arc(n); 2063 2024 } 2064 2025 2065 /// \brief Gives back the arc of the original arc.2066 ///2067 /// Gives back the arc of the original arc.2068 2026 static Arc arc(const DigraphArc& e) { 2069 2027 return Arc(e); 2070 2028 } … … 2264 2222 /// a \c SplitDigraphAdaptor and set the node cost of the digraph to the 2265 2223 /// bind arc in the adapted digraph. 2266 2224 /// 2267 /// By example a maximum flow algoritm can compute how many arc2225 /// For example a maximum flow algorithm can compute how many arc 2268 2226 /// disjoint paths are in the digraph. But we would like to know how 2269 2227 /// many node disjoint paths are in the digraph. First we have to 2270 2228 /// adapt the digraph with the \c SplitDigraphAdaptor. Then run the flow … … 2319 2277 typedef _Digraph Digraph; 2320 2278 typedef DigraphAdaptorExtender<SplitDigraphAdaptorBase<Digraph> > Parent; 2321 2279 2280 typedef typename Digraph::Node DigraphNode; 2281 typedef typename Digraph::Arc DigraphArc; 2282 2322 2283 typedef typename Parent::Node Node; 2323 2284 typedef typename Parent::Arc Arc; 2324 2285 … … 2327 2288 /// Constructor of the adaptor. 2328 2289 SplitDigraphAdaptor(Digraph& g) { 2329 2290 Parent::setDigraph(g); 2291 } 2292 2293 /// \brief Returns true when the node is in-node. 2294 /// 2295 /// Returns true when the node is in-node. 2296 static bool inNode(const Node& n) { 2297 return Parent::inNode(n); 2298 } 2299 2300 /// \brief Returns true when the node is out-node. 2301 /// 2302 /// Returns true when the node is out-node. 2303 static bool outNode(const Node& n) { 2304 return Parent::outNode(n); 2305 } 2306 2307 /// \brief Returns true when the arc is arc in the original digraph. 2308 /// 2309 /// Returns true when the arc is arc in the original digraph. 2310 static bool origArc(const Arc& a) { 2311 return Parent::origArc(a); 2312 } 2313 2314 /// \brief Returns true when the arc binds an in-node and an out-node. 2315 /// 2316 /// Returns true when the arc binds an in-node and an out-node. 2317 static bool bindArc(const Arc& a) { 2318 return Parent::bindArc(a); 2319 } 2320 2321 /// \brief Gives back the in-node created from the \c node. 2322 /// 2323 /// Gives back the in-node created from the \c node. 2324 static Node inNode(const DigraphNode& n) { 2325 return Parent::inNode(n); 2326 } 2327 2328 /// \brief Gives back the out-node created from the \c node. 2329 /// 2330 /// Gives back the out-node created from the \c node. 2331 static Node outNode(const DigraphNode& n) { 2332 return Parent::outNode(n); 2333 } 2334 2335 /// \brief Gives back the arc binds the two part of the node. 2336 /// 2337 /// Gives back the arc binds the two part of the node. 2338 static Arc arc(const DigraphNode& n) { 2339 return Parent::arc(n); 2340 } 2341 2342 /// \brief Gives back the arc of the original arc. 2343 /// 2344 /// Gives back the arc of the original arc. 2345 static Arc arc(const DigraphArc& a) { 2346 return Parent::arc(a); 2330 2347 } 2331 2348 2332 2349 /// \brief NodeMap combined from two original NodeMap -
lemon/graph_adaptor.h
diff -r e67acd83a9ca -r 7a4a426a037e lemon/graph_adaptor.h
a b 31 31 32 32 namespace lemon { 33 33 34 /// \brief Base type for the Graph Adaptors35 ///36 /// This is the base type for most of LEMON graph adaptors.37 /// This class implements a trivial graph adaptor i.e. it only wraps the38 /// functions and types of the graph. The purpose of this class is to39 /// make easier implementing graph adaptors. E.g. if an adaptor is40 /// considered which differs from the wrapped graph only in some of its41 /// functions or types, then it can be derived from GraphAdaptor, and only42 /// the differences should be implemented.43 34 template<typename _Graph> 44 35 class GraphAdaptorBase { 45 36 public: … … 192 183 193 184 }; 194 185 195 /// \ingroup graph_adaptors196 ///197 /// \brief Trivial graph adaptor198 ///199 /// This class is an adaptor which does not change the adapted undirected200 /// graph. It can be used only to test the graph adaptors.201 template <typename _Graph>202 class GraphAdaptor203 : public GraphAdaptorExtender< GraphAdaptorBase<_Graph> > {204 public:205 typedef _Graph Graph;206 typedef GraphAdaptorExtender<GraphAdaptorBase<_Graph> > Parent;207 protected:208 GraphAdaptor() : Parent() {}209 210 public:211 explicit GraphAdaptor(Graph& graph) { setGraph(graph); }212 };213 214 186 template <typename _Graph, typename NodeFilterMap, 215 187 typename EdgeFilterMap, bool checked = true> 216 188 class SubGraphAdaptorBase : public GraphAdaptorBase<_Graph> { … … 315 287 || !(*_node_filter_map)[Parent::v(i)])) Parent::nextInc(i, d); 316 288 } 317 289 318 /// \brief Hide the given node in the graph.319 ///320 /// This function hides \c n in the graph, i.e. the iteration321 /// jumps over it. This is done by simply setting the value of \c n322 /// to be false in the corresponding node-map.323 290 void hide(const Node& n) const { _node_filter_map->set(n, false); } 324 325 /// \brief Hide the given edge in the graph.326 ///327 /// This function hides \c e in the graph, i.e. the iteration328 /// jumps over it. This is done by simply setting the value of \c e329 /// to be false in the corresponding edge-map.330 291 void hide(const Edge& e) const { _edge_filter_map->set(e, false); } 331 292 332 /// \brief Unhide the given node in the graph. 333 /// 334 /// The value of \c n is set to be true in the node-map which stores 335 /// hide information. If \c n was hidden previuosly, then it is shown 336 /// again 337 void unHide(const Node& n) const { _node_filter_map->set(n, true); } 338 339 /// \brief Hide the given edge in the graph. 340 /// 341 /// The value of \c e is set to be true in the edge-map which stores 342 /// hide information. If \c e was hidden previuosly, then it is shown 343 /// again 293 void unHide(const Node& n) const { _node_filter_map->set(n, true); } 344 294 void unHide(const Edge& e) const { _edge_filter_map->set(e, true); } 345 295 346 /// \brief Returns true if \c n is hidden.347 ///348 /// Returns true if \c n is hidden.349 296 bool hidden(const Node& n) const { return !(*_node_filter_map)[n]; } 350 351 /// \brief Returns true if \c e is hidden.352 ///353 /// Returns true if \c e is hidden.354 297 bool hidden(const Edge& e) const { return !(*_edge_filter_map)[e]; } 355 298 356 299 typedef False NodeNumTag; … … 537 480 while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::nextInc(i, d); 538 481 } 539 482 540 /// \brief Hide the given node in the graph.541 ///542 /// This function hides \c n in the graph, i.e. the iteration543 /// jumps over it. This is done by simply setting the value of \c n544 /// to be false in the corresponding node-map.545 483 void hide(const Node& n) const { _node_filter_map->set(n, false); } 546 547 /// \brief Hide the given edge in the graph.548 ///549 /// This function hides \c e in the graph, i.e. the iteration550 /// jumps over it. This is done by simply setting the value of \c e551 /// to be false in the corresponding edge-map.552 484 void hide(const Edge& e) const { _edge_filter_map->set(e, false); } 553 485 554 /// \brief Unhide the given node in the graph. 555 /// 556 /// The value of \c n is set to be true in the node-map which stores 557 /// hide information. If \c n was hidden previuosly, then it is shown 558 /// again 559 void unHide(const Node& n) const { _node_filter_map->set(n, true); } 560 561 /// \brief Hide the given edge in the graph. 562 /// 563 /// The value of \c e is set to be true in the edge-map which stores 564 /// hide information. If \c e was hidden previuosly, then it is shown 565 /// again 486 void unHide(const Node& n) const { _node_filter_map->set(n, true); } 566 487 void unHide(const Edge& e) const { _edge_filter_map->set(e, true); } 567 488 568 /// \brief Returns true if \c n is hidden.569 ///570 /// Returns true if \c n is hidden.571 489 bool hidden(const Node& n) const { return !(*_node_filter_map)[n]; } 572 573 /// \brief Returns true if \c e is hidden.574 ///575 /// Returns true if \c e is hidden.576 490 bool hidden(const Edge& e) const { return !(*_edge_filter_map)[e]; } 577 491 578 492 typedef False NodeNumTag; … … 673 587 674 588 /// \ingroup graph_adaptors 675 589 /// 676 /// \brief A graph adaptor for hiding nodes and arcs from an590 /// \brief A graph adaptor for hiding nodes and edges from an 677 591 /// undirected graph. 678 592 /// 679 593 /// SubGraphAdaptor shows the graph with filtered node-set and … … 695 609 typedef _Graph Graph; 696 610 typedef GraphAdaptorExtender< 697 611 SubGraphAdaptorBase<_Graph, NodeFilterMap, EdgeFilterMap> > Parent; 612 613 typedef typename Parent::Node Node; 614 typedef typename Parent::Edge Edge; 615 698 616 protected: 699 617 SubGraphAdaptor() { } 700 618 public: 619 620 /// \brief Constructor 621 /// 622 /// Creates a sub-graph-adaptor for the given graph with 623 /// given node and edge map filters. 701 624 SubGraphAdaptor(Graph& _graph, NodeFilterMap& node_filter_map, 702 625 EdgeFilterMap& edge_filter_map) { 703 626 setGraph(_graph); 704 627 setNodeFilterMap(node_filter_map); 705 628 setEdgeFilterMap(edge_filter_map); 706 629 } 630 631 /// \brief Hides the node of the graph 632 /// 633 /// This function hides \c n in the digraph, i.e. the iteration 634 /// jumps over it. This is done by simply setting the value of \c n 635 /// to be false in the corresponding node-map. 636 void hide(const Node& n) const { Parent::hide(n); } 637 638 /// \brief Hides the edge of the graph 639 /// 640 /// This function hides \c e in the digraph, i.e. the iteration 641 /// jumps over it. This is done by simply setting the value of \c e 642 /// to be false in the corresponding edge-map. 643 void hide(const Edge& e) const { Parent::hide(e); } 644 645 /// \brief Unhides the node of the graph 646 /// 647 /// The value of \c n is set to be true in the node-map which stores 648 /// hide information. If \c n was hidden previuosly, then it is shown 649 /// again 650 void unHide(const Node& n) const { Parent::unHide(n); } 651 652 /// \brief Unhides the edge of the graph 653 /// 654 /// The value of \c e is set to be true in the edge-map which stores 655 /// hide information. If \c e was hidden previuosly, then it is shown 656 /// again 657 void unHide(const Edge& e) const { Parent::unHide(e); } 658 659 /// \brief Returns true if \c n is hidden. 660 /// 661 /// Returns true if \c n is hidden. 662 /// 663 bool hidden(const Node& n) const { return Parent::hidden(n); } 664 665 /// \brief Returns true if \c e is hidden. 666 /// 667 /// Returns true if \c e is hidden. 668 /// 669 bool hidden(const Edge& e) const { return Parent::hidden(e); } 707 670 }; 708 671 672 /// \brief Just gives back a sub-graph adaptor 673 /// 674 /// Just gives back a sub-graph adaptor 709 675 template<typename Graph, typename NodeFilterMap, typename ArcFilterMap> 710 676 SubGraphAdaptor<const Graph, NodeFilterMap, ArcFilterMap> 711 677 subGraphAdaptor(const Graph& graph, … … 756 722 typedef _NodeFilterMap NodeFilterMap; 757 723 typedef SubGraphAdaptor<Graph, NodeFilterMap, 758 724 ConstMap<typename Graph::Edge, bool> > Parent; 725 726 typedef typename Parent::Node Node; 759 727 protected: 760 728 ConstMap<typename Graph::Edge, bool> const_true_map; 761 729 … … 764 732 } 765 733 766 734 public: 735 736 /// \brief Constructor 737 /// 738 /// Creates a node-sub-graph-adaptor for the given graph with 739 /// given node map filters. 767 740 NodeSubGraphAdaptor(Graph& _graph, NodeFilterMap& node_filter_map) : 768 741 Parent(), const_true_map(true) { 769 742 Parent::setGraph(_graph); 770 743 Parent::setNodeFilterMap(node_filter_map); 771 744 Parent::setEdgeFilterMap(const_true_map); 772 745 } 746 747 /// \brief Hides the node of the graph 748 /// 749 /// This function hides \c n in the digraph, i.e. the iteration 750 /// jumps over it. This is done by simply setting the value of \c n 751 /// to be false in the corresponding node-map. 752 void hide(const Node& n) const { Parent::hide(n); } 753 754 /// \brief Unhides the node of the graph 755 /// 756 /// The value of \c n is set to be true in the node-map which stores 757 /// hide information. If \c n was hidden previuosly, then it is shown 758 /// again 759 void unHide(const Node& n) const { Parent::unHide(n); } 760 761 /// \brief Returns true if \c n is hidden. 762 /// 763 /// Returns true if \c n is hidden. 764 /// 765 bool hidden(const Node& n) const { return Parent::hidden(n); } 766 773 767 }; 774 768 769 /// \brief Just gives back a node-sub-graph adaptor 770 /// 771 /// Just gives back a node-sub-graph adaptor 775 772 template<typename Graph, typename NodeFilterMap> 776 773 NodeSubGraphAdaptor<const Graph, NodeFilterMap> 777 774 nodeSubGraphAdaptor(const Graph& graph, NodeFilterMap& nfm) { … … 804 801 typedef _EdgeFilterMap EdgeFilterMap; 805 802 typedef SubGraphAdaptor<Graph, ConstMap<typename Graph::Node,bool>, 806 803 EdgeFilterMap, false> Parent; 804 typedef typename Parent::Edge Edge; 807 805 protected: 808 806 ConstMap<typename Graph::Node, bool> const_true_map; 809 807 … … 813 811 814 812 public: 815 813 814 /// \brief Constructor 815 /// 816 /// Creates a edge-sub-graph-adaptor for the given graph with 817 /// given node map filters. 816 818 EdgeSubGraphAdaptor(Graph& _graph, EdgeFilterMap& edge_filter_map) : 817 819 Parent(), const_true_map(true) { 818 820 Parent::setGraph(_graph); … … 820 822 Parent::setEdgeFilterMap(edge_filter_map); 821 823 } 822 824 825 /// \brief Hides the edge of the graph 826 /// 827 /// This function hides \c e in the digraph, i.e. the iteration 828 /// jumps over it. This is done by simply setting the value of \c e 829 /// to be false in the corresponding edge-map. 830 void hide(const Edge& e) const { Parent::hide(e); } 831 832 /// \brief Unhides the edge of the graph 833 /// 834 /// The value of \c e is set to be true in the edge-map which stores 835 /// hide information. If \c e was hidden previuosly, then it is shown 836 /// again 837 void unHide(const Edge& e) const { Parent::unHide(e); } 838 839 /// \brief Returns true if \c e is hidden. 840 /// 841 /// Returns true if \c e is hidden. 842 /// 843 bool hidden(const Edge& e) const { return Parent::hidden(e); } 844 823 845 }; 824 846 847 /// \brief Just gives back an edge-sub-graph adaptor 848 /// 849 /// Just gives back an edge-sub-graph adaptor 825 850 template<typename Graph, typename EdgeFilterMap> 826 851 EdgeSubGraphAdaptor<const Graph, EdgeFilterMap> 827 852 edgeSubGraphAdaptor(const Graph& graph, EdgeFilterMap& efm) { … … 834 859 return EdgeSubGraphAdaptor<const Graph, const EdgeFilterMap>(graph, efm); 835 860 } 836 861 837 /// \brief Base of direct graph adaptor838 ///839 /// Base class of the direct graph adaptor. All public member840 /// of this class can be used with the DirGraphAdaptor too.841 /// \sa DirGraphAdaptor842 862 template <typename _Graph, typename _DirectionMap> 843 863 class DirGraphAdaptorBase { 844 864 public: … … 1092 1112 typedef _Graph Graph; 1093 1113 typedef DigraphAdaptorExtender< 1094 1114 DirGraphAdaptorBase<_Graph, DirectionMap> > Parent; 1115 typedef typename Parent::Arc Arc; 1095 1116 protected: 1096 1117 DirGraphAdaptor() { } 1097 1118 public: … … 1102 1123 DirGraphAdaptor(Graph& graph, DirectionMap& direction) { 1103 1124 setGraph(graph); 1104 1125 setDirectionMap(direction); 1126 } 1127 1128 /// \brief Reverse arc 1129 /// 1130 /// It reverse the given arc. It simply negate the direction in the map. 1131 void reverseArc(const Arc& a) { 1132 Parent::reverseArc(a); 1105 1133 } 1106 1134 }; 1107 1135 -
test/graph_adaptor_test.cc
diff -r e67acd83a9ca -r 7a4a426a037e test/graph_adaptor_test.cc
a b 36 36 #include"test/graph_test.h" 37 37 38 38 using namespace lemon; 39 40 void checkDigraphAdaptor() {41 checkConcept<concepts::Digraph, DigraphAdaptor<concepts::Digraph> >();42 43 typedef ListDigraph Digraph;44 typedef DigraphAdaptor<Digraph> Adaptor;45 46 Digraph digraph;47 Adaptor adaptor(digraph);48 49 Digraph::Node n1 = digraph.addNode();50 Digraph::Node n2 = digraph.addNode();51 Digraph::Node n3 = digraph.addNode();52 53 Digraph::Arc a1 = digraph.addArc(n1, n2);54 Digraph::Arc a2 = digraph.addArc(n1, n3);55 Digraph::Arc a3 = digraph.addArc(n2, n3);56 57 checkGraphNodeList(adaptor, 3);58 checkGraphArcList(adaptor, 3);59 checkGraphConArcList(adaptor, 3);60 61 checkGraphOutArcList(adaptor, n1, 2);62 checkGraphOutArcList(adaptor, n2, 1);63 checkGraphOutArcList(adaptor, n3, 0);64 65 checkGraphInArcList(adaptor, n1, 0);66 checkGraphInArcList(adaptor, n2, 1);67 checkGraphInArcList(adaptor, n3, 2);68 69 checkNodeIds(adaptor);70 checkArcIds(adaptor);71 72 checkGraphNodeMap(adaptor);73 checkGraphArcMap(adaptor);74 }75 39 76 40 void checkRevDigraphAdaptor() { 77 41 checkConcept<concepts::Digraph, RevDigraphAdaptor<concepts::Digraph> >(); … … 585 549 } 586 550 } 587 551 588 void checkGraphAdaptor() {589 checkConcept<concepts::Graph, GraphAdaptor<concepts::Graph> >();590 591 typedef ListGraph Graph;592 typedef GraphAdaptor<Graph> Adaptor;593 594 Graph graph;595 Adaptor adaptor(graph);596 597 Graph::Node n1 = graph.addNode();598 Graph::Node n2 = graph.addNode();599 Graph::Node n3 = graph.addNode();600 Graph::Node n4 = graph.addNode();601 602 Graph::Edge a1 = graph.addEdge(n1, n2);603 Graph::Edge a2 = graph.addEdge(n1, n3);604 Graph::Edge a3 = graph.addEdge(n2, n3);605 Graph::Edge a4 = graph.addEdge(n3, n4);606 607 checkGraphNodeList(adaptor, 4);608 checkGraphArcList(adaptor, 8);609 checkGraphEdgeList(adaptor, 4);610 checkGraphConArcList(adaptor, 8);611 checkGraphConEdgeList(adaptor, 4);612 613 checkGraphOutArcList(adaptor, n1, 2);614 checkGraphOutArcList(adaptor, n2, 2);615 checkGraphOutArcList(adaptor, n3, 3);616 checkGraphOutArcList(adaptor, n4, 1);617 618 checkGraphInArcList(adaptor, n1, 2);619 checkGraphInArcList(adaptor, n2, 2);620 checkGraphInArcList(adaptor, n3, 3);621 checkGraphInArcList(adaptor, n4, 1);622 623 checkGraphIncEdgeList(adaptor, n1, 2);624 checkGraphIncEdgeList(adaptor, n2, 2);625 checkGraphIncEdgeList(adaptor, n3, 3);626 checkGraphIncEdgeList(adaptor, n4, 1);627 628 629 checkNodeIds(adaptor);630 checkArcIds(adaptor);631 checkEdgeIds(adaptor);632 633 checkGraphNodeMap(adaptor);634 checkGraphArcMap(adaptor);635 checkGraphEdgeMap(adaptor);636 }637 638 552 void checkSubGraphAdaptor() { 639 553 checkConcept<concepts::Graph, 640 554 SubGraphAdaptor<concepts::Graph, … … 1053 967 1054 968 int main(int, const char **) { 1055 969 1056 checkDigraphAdaptor();1057 970 checkRevDigraphAdaptor(); 1058 971 checkSubDigraphAdaptor(); 1059 972 checkNodeSubDigraphAdaptor(); … … 1062 975 checkResDigraphAdaptor(); 1063 976 checkSplitDigraphAdaptor(); 1064 977 1065 checkGraphAdaptor();1066 978 checkSubGraphAdaptor(); 1067 979 checkNodeSubGraphAdaptor(); 1068 980 checkEdgeSubGraphAdaptor();