COIN-OR::LEMON - Graph Library

Ticket #67: 7a4a426a037e.patch

File 7a4a426a037e.patch, 38.4 KB (added by Balazs Dezso, 11 years ago)

Improvements on adaptors

  • 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  
    2323///\file
    2424///\brief Several digraph adaptors.
    2525///
    26 ///This file contains several useful digraph adaptor functions.
     26///This file contains several useful digraph adaptor classes.
    2727
    2828#include <lemon/core.h>
    2929#include <lemon/maps.h>
     
    3838
    3939namespace lemon {
    4040
    41   ///\brief Base type for the Digraph Adaptors
    42   ///
    43   ///Base type for the Digraph Adaptors
    44   ///
    45   ///This is the base type for most of LEMON digraph adaptors. This
    46   ///class implements a trivial digraph adaptor i.e. it only wraps the
    47   ///functions and types of the digraph. The purpose of this class is
    48   ///to make easier implementing digraph adaptors. E.g. if an adaptor
    49   ///is considered which differs from the wrapped digraph only in some
    50   ///of its functions or types, then it can be derived from
    51   ///DigraphAdaptor, and only the differences should be implemented.
    5241  template<typename _Digraph>
    5342  class DigraphAdaptorBase {
    5443  public:
     
    164153
    165154  };
    166155
    167   ///\ingroup graph_adaptors
    168   ///
    169   ///\brief Trivial Digraph Adaptor
    170   ///
    171   /// This class is an adaptor which does not change the adapted
    172   /// 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 adaptor
    187   ///
    188   /// Just gives back a digraph adaptor which
    189   /// should be provide original digraph
    190   template<typename Digraph>
    191   DigraphAdaptor<const Digraph>
    192   digraphAdaptor(const Digraph& digraph) {
    193     return DigraphAdaptor<const Digraph>(digraph);
    194   }
    195 
    196156
    197157  template <typename _Digraph>
    198158  class RevDigraphAdaptorBase : public DigraphAdaptorBase<_Digraph> {
     
    229189  ///
    230190  /// If \c g is defined as
    231191  ///\code
    232   /// ListDigraph g;
     192  /// ListDigraph dg;
    233193  ///\endcode
    234194  /// then
    235195  ///\code
    236   /// RevDigraphAdaptor<ListDigraph> ga(g);
     196  /// RevDigraphAdaptor<ListDigraph> dga(dg);
    237197  ///\endcode
    238   /// implements the digraph obtained from \c g by
     198  /// implements the digraph obtained from \c dg by
    239199  /// reversing the orientation of its arcs.
    240200  ///
    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.
    250209  ///
    251   /// And look at the code:
    252   ///
     210  /// The implementation:
    253211  ///\code
    254212  /// bool stronglyConnected(const Digraph& digraph) {
    255213  ///   if (NodeIt(digraph) == INVALID) return true;
     
    282240  protected:
    283241    RevDigraphAdaptor() { }
    284242  public:
     243
     244    /// \brief Constructor
     245    ///
     246    /// Creates a reverse graph adaptor for the given digraph
    285247    explicit RevDigraphAdaptor(Digraph& digraph) {
    286248      Parent::setDigraph(digraph);
    287249    }
     
    372334             || !(*_node_filter)[Parent::target(i)])) Parent::nextOut(i);
    373335    }
    374336
    375     ///\e
    376 
    377     /// This function hides \c n in the digraph, i.e. the iteration
    378     /// jumps over it. This is done by simply setting the value of \c n 
    379     /// to be false in the corresponding node-map.
    380337    void hide(const Node& n) const { _node_filter->set(n, false); }
    381 
    382     ///\e
    383 
    384     /// This function hides \c a in the digraph, i.e. the iteration
    385     /// jumps over it. This is done by simply setting the value of \c a
    386     /// to be false in the corresponding arc-map.
    387338    void hide(const Arc& a) const { _arc_filter->set(a, false); }
    388339
    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); }
    401341    void unHide(const Arc& a) const { _arc_filter->set(a, true); }
    402342
    403     /// Returns true if \c n is hidden.
    404    
    405     ///\e
    406     ///
    407343    bool hidden(const Node& n) const { return !(*_node_filter)[n]; }
    408 
    409     /// Returns true if \c a is hidden.
    410    
    411     ///\e
    412     ///
    413344    bool hidden(const Arc& a) const { return !(*_arc_filter)[a]; }
    414345
    415346    typedef False NodeNumTag;
     
    544475      while (i!=INVALID && !(*_arc_filter)[i]) Parent::nextOut(i);
    545476    }
    546477
    547     ///\e
    548 
    549     /// This function hides \c n in the digraph, i.e. the iteration
    550     /// jumps over it. This is done by simply setting the value of \c n 
    551     /// to be false in the corresponding node-map.
    552478    void hide(const Node& n) const { _node_filter->set(n, false); }
    553 
    554     ///\e
    555 
    556     /// This function hides \c e in the digraph, i.e. the iteration
    557     /// jumps over it. This is done by simply setting the value of \c e 
    558     /// to be false in the corresponding arc-map.
    559479    void hide(const Arc& e) const { _arc_filter->set(e, false); }
    560480
    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); }
    573482    void unHide(const Arc& e) const { _arc_filter->set(e, true); }
    574483
    575     /// Returns true if \c n is hidden.
    576    
    577     ///\e
    578     ///
    579484    bool hidden(const Node& n) const { return !(*_node_filter)[n]; }
    580 
    581     /// Returns true if \c n is hidden.
    582    
    583     ///\e
    584     ///
    585485    bool hidden(const Arc& e) const { return !(*_arc_filter)[e]; }
    586486
    587487    typedef False NodeNumTag;
     
    655555  /// \brief A digraph adaptor for hiding nodes and arcs from a digraph.
    656556  ///
    657557  /// 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.
    672560  ///
    673   /// If the \c checked template parameter is false then we have to
    674   /// note that the node-iterator cares only the filter on the
    675   /// node-set, and the arc-iterator cares only the filter on the
    676   /// arc-set.  This way the arc-map should filter all arcs which's
    677   /// source or target is filtered 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.
    678566  ///\code
    679567  /// typedef ListDigraph Digraph;
    680568  /// DIGRAPH_TYPEDEFS(Digraph);
     
    687575  /// nm.set(u, false);
    688576  /// BoolArcMap am(g, true);
    689577  /// am.set(a, false);
    690   /// typedef SubDigraphAdaptor<Digraph, BoolNodeMap, BoolArcMap> SubGA;
    691   /// SubGA ga(g, nm, am);
    692   /// for (SubGA::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)
    693581  ///   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)
    696583  ///   std::cout << g.id(a) << std::endl;
    697584  ///\endcode
    698585  /// The output of the above code is the following.
    699586  ///\code
    700587  /// 1
    701   /// :-)
    702588  /// 1
    703589  ///\endcode
    704   /// Note that \c n is of type \c SubGA::NodeIt, but it can be converted to
     590  /// Note that \c n is of type \c SubDGA::NodeIt, but it can be converted to
    705591  /// \c Digraph::Node that is why \c g.id(n) can be applied.
    706592  ///
    707593  /// For other examples see also the documentation of
     
    722608      SubDigraphAdaptorBase<Digraph, NodeFilterMap, ArcFilterMap, checked> >
    723609    Parent;
    724610
     611    typedef typename Parent::Node Node;
     612    typedef typename Parent::Arc Arc;
     613
    725614  protected:
    726615    SubDigraphAdaptor() { }
    727616  public:
    728617
     618    /// \brief Constructor
     619    ///
     620    /// Creates a sub-digraph-adaptor for the given digraph with
     621    /// given node and arc map filters.
    729622    SubDigraphAdaptor(Digraph& digraph, NodeFilterMap& node_filter,
    730623                      ArcFilterMap& arc_filter) {
    731624      setDigraph(digraph);
     
    733626      setArcFilterMap(arc_filter);
    734627    }
    735628
     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
    736669  };
    737670
    738   /// \brief Just gives back a sub digraph adaptor
     671  /// \brief Just gives back a sub-digraph-adaptor
    739672  ///
    740   /// Just gives back a sub digraph adaptor
     673  /// Just gives back a sub-digraph-adaptor
    741674  template<typename Digraph, typename NodeFilterMap, typename ArcFilterMap>
    742675  SubDigraphAdaptor<const Digraph, NodeFilterMap, ArcFilterMap>
    743676  subDigraphAdaptor(const Digraph& digraph,
     
    768701                   NodeFilterMap& nfm, ArcFilterMap& afm) {
    769702    return SubDigraphAdaptor<const Digraph, const NodeFilterMap,
    770703      const ArcFilterMap>(digraph, nfm, afm);
     704
    771705  }
    772706
    773707
     
    796730                              ConstMap<typename Digraph::Arc, bool>, checked>
    797731    Parent;
    798732
     733    typedef typename Parent::Node Node;
     734
    799735  protected:
    800736    ConstMap<typename Digraph::Arc, bool> const_true_map;
    801737
     
    805741
    806742  public:
    807743
     744    /// \brief Constructor
     745    ///
     746    /// Creates a node-sub-digraph-adaptor for the given digraph with
     747    /// given node map filter.
    808748    NodeSubDigraphAdaptor(Digraph& _digraph, NodeFilterMap& node_filter) :
    809749      Parent(), const_true_map(true) {
    810750      Parent::setDigraph(_digraph);
     
    812752      Parent::setArcFilterMap(const_true_map);
    813753    }
    814754
     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
    815775  };
    816776
    817777
    818   /// \brief Just gives back a \c NodeSubDigraphAdaptor
     778  /// \brief Just gives back a  node-sub-digraph adaptor
    819779  ///
    820   /// Just gives back a \c NodeSubDigraphAdaptor
     780  /// Just gives back a node-sub-digraph adaptor
    821781  template<typename Digraph, typename NodeFilterMap>
    822782  NodeSubDigraphAdaptor<const Digraph, NodeFilterMap>
    823783  nodeSubDigraphAdaptor(const Digraph& digraph, NodeFilterMap& nfm) {
     
    840800  ///can be filtered. The usefulness of this adaptor is demonstrated
    841801  ///in the problem of searching a maximum number of arc-disjoint
    842802  ///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.
    846807  ///
    847808  ///If a single shortest path is to be searched between \c s and \c
    848809  ///t, then this can be done easily by applying the Dijkstra
     
    862823  ///generated by the demo program \ref dim_to_dot.cc.
    863824  ///
    864825  ///\dot
    865   ///didigraph lemon_dot_example {
     826  ///digraph lemon_dot_example {
    866827  ///node [ shape=ellipse, fontname=Helvetica, fontsize=10 ];
    867828  ///n0 [ label="0 (s)" ];
    868829  ///n1 [ label="1" ];
     
    968929
    969930    typedef SubDigraphAdaptor<Digraph, ConstMap<typename Digraph::Node, bool>,
    970931                              ArcFilterMap, false> Parent;
     932
     933    typedef typename Parent::Arc Arc;
     934
    971935  protected:
    972936    ConstMap<typename Digraph::Node, bool> const_true_map;
    973937
     
    977941
    978942  public:
    979943
     944    /// \brief Constructor
     945    ///
     946    /// Creates a arc-sub-digraph-adaptor for the given digraph with
     947    /// given arc map filter.
    980948    ArcSubDigraphAdaptor(Digraph& digraph, ArcFilterMap& arc_filter)
    981949      : Parent(), const_true_map(true) {
    982950      Parent::setDigraph(digraph);
     
    984952      Parent::setArcFilterMap(arc_filter);
    985953    }
    986954
     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
    987975  };
    988976
    989   /// \brief Just gives back an arc sub digraph adaptor
     977  /// \brief Just gives back an arc-sub-digraph adaptor
    990978  ///
    991   /// Just gives back an arc sub digraph adaptor
     979  /// Just gives back an arc-sub-digraph adaptor
    992980  template<typename Digraph, typename ArcFilterMap>
    993981  ArcSubDigraphAdaptor<const Digraph, ArcFilterMap>
    994982  arcSubDigraphAdaptor(const Digraph& digraph, ArcFilterMap& afm) {
     
    13841372
    13851373  ///\ingroup graph_adaptors
    13861374  ///
    1387   /// \brief An graph is made from a directed digraph by an adaptor
     1375  /// \brief A graph is made from a directed digraph by an adaptor
    13881376  ///
    13891377  /// This adaptor makes an undirected graph from a directed
    1390   /// digraph. All arc of the underlying will be showed in the adaptor
    1391   /// as an edge. Let's see an informal example about using
    1392   /// 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.
    13931381  ///
    13941382  /// There is a network of the streets of a town. Of course there are
    13951383  /// some one-way street in the town hence the network is a directed
     
    17931781
    17941782  };
    17951783
    1796   /// \brief Base class for split digraph adaptor
    1797   ///
    1798   /// Base class of split digraph adaptor. In most case you do not need to
    1799   /// use it directly but the documented member functions of this class can
    1800   /// be used with the SplitDigraphAdaptor class.
    1801   /// \sa SplitDigraphAdaptor
    18021784  template <typename _Digraph>
    18031785  class SplitDigraphAdaptorBase {
    18041786  public:
     
    20131995                      (_digraph->maxArcId() << 1) | 1);
    20141996    }
    20151997
    2016     /// \brief Returns true when the node is in-node.
    2017     ///
    2018     /// Returns true when the node is in-node.
    20191998    static bool inNode(const Node& n) {
    20201999      return n._in;
    20212000    }
    20222001
    2023     /// \brief Returns true when the node is out-node.
    2024     ///
    2025     /// Returns true when the node is out-node.
    20262002    static bool outNode(const Node& n) {
    20272003      return !n._in;
    20282004    }
    20292005
    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.
    20332006    static bool origArc(const Arc& e) {
    20342007      return e._item.firstState();
    20352008    }
    20362009
    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.
    20402010    static bool bindArc(const Arc& e) {
    20412011      return e._item.secondState();
    20422012    }
    20432013
    2044     /// \brief Gives back the in-node created from the \c node.
    2045     ///
    2046     /// Gives back the in-node created from the \c node.
    20472014    static Node inNode(const DigraphNode& n) {
    20482015      return Node(n, true);
    20492016    }
    20502017
    2051     /// \brief Gives back the out-node created from the \c node.
    2052     ///
    2053     /// Gives back the out-node created from the \c node.
    20542018    static Node outNode(const DigraphNode& n) {
    20552019      return Node(n, false);
    20562020    }
    20572021
    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.
    20612022    static Arc arc(const DigraphNode& n) {
    20622023      return Arc(n);
    20632024    }
    20642025
    2065     /// \brief Gives back the arc of the original arc.
    2066     ///
    2067     /// Gives back the arc of the original arc.
    20682026    static Arc arc(const DigraphArc& e) {
    20692027      return Arc(e);
    20702028    }
     
    22642222  /// a \c SplitDigraphAdaptor and set the node cost of the digraph to the
    22652223  /// bind arc in the adapted digraph.
    22662224  ///
    2267   /// By example a maximum flow algoritm can compute how many arc
     2225  /// For example a maximum flow algorithm can compute how many arc
    22682226  /// disjoint paths are in the digraph. But we would like to know how
    22692227  /// many node disjoint paths are in the digraph. First we have to
    22702228  /// adapt the digraph with the \c SplitDigraphAdaptor. Then run the flow
     
    23192277    typedef _Digraph Digraph;
    23202278    typedef DigraphAdaptorExtender<SplitDigraphAdaptorBase<Digraph> > Parent;
    23212279
     2280    typedef typename Digraph::Node DigraphNode;
     2281    typedef typename Digraph::Arc DigraphArc;
     2282
    23222283    typedef typename Parent::Node Node;
    23232284    typedef typename Parent::Arc Arc;
    23242285
     
    23272288    /// Constructor of the adaptor.
    23282289    SplitDigraphAdaptor(Digraph& g) {
    23292290      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);
    23302347    }
    23312348
    23322349    /// \brief NodeMap combined from two original NodeMap
  • lemon/graph_adaptor.h

    diff -r e67acd83a9ca -r 7a4a426a037e lemon/graph_adaptor.h
    a b  
    3131
    3232namespace lemon {
    3333
    34   /// \brief Base type for the Graph Adaptors
    35   ///
    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 the
    38   /// functions and types of the graph. The purpose of this class is to
    39   /// make easier implementing graph adaptors. E.g. if an adaptor is
    40   /// considered which differs from the wrapped graph only in some of its
    41   /// functions or types, then it can be derived from GraphAdaptor, and only
    42   /// the differences should be implemented.
    4334  template<typename _Graph>
    4435  class GraphAdaptorBase {
    4536  public:
     
    192183
    193184  };
    194185
    195   /// \ingroup graph_adaptors
    196   ///
    197   /// \brief Trivial graph adaptor
    198   ///
    199   /// This class is an adaptor which does not change the adapted undirected
    200   /// graph. It can be used only to test the graph adaptors.
    201   template <typename _Graph>
    202   class GraphAdaptor
    203     : 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 
    214186  template <typename _Graph, typename NodeFilterMap,
    215187            typename EdgeFilterMap, bool checked = true>
    216188  class SubGraphAdaptorBase : public GraphAdaptorBase<_Graph> {
     
    315287            || !(*_node_filter_map)[Parent::v(i)])) Parent::nextInc(i, d);
    316288    }
    317289
    318     /// \brief Hide the given node in the graph.
    319     ///
    320     /// This function hides \c n in the graph, i.e. the iteration
    321     /// jumps over it. This is done by simply setting the value of \c n 
    322     /// to be false in the corresponding node-map.
    323290    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 iteration
    328     /// jumps over it. This is done by simply setting the value of \c e 
    329     /// to be false in the corresponding edge-map.
    330291    void hide(const Edge& e) const { _edge_filter_map->set(e, false); }
    331292
    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); }
    344294    void unHide(const Edge& e) const { _edge_filter_map->set(e, true); }
    345295
    346     /// \brief Returns true if \c n is hidden.
    347     ///
    348     /// Returns true if \c n is hidden.
    349296    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.
    354297    bool hidden(const Edge& e) const { return !(*_edge_filter_map)[e]; }
    355298
    356299    typedef False NodeNumTag;
     
    537480      while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::nextInc(i, d);
    538481    }
    539482
    540     /// \brief Hide the given node in the graph.
    541     ///
    542     /// This function hides \c n in the graph, i.e. the iteration
    543     /// jumps over it. This is done by simply setting the value of \c n 
    544     /// to be false in the corresponding node-map.
    545483    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 iteration
    550     /// jumps over it. This is done by simply setting the value of \c e 
    551     /// to be false in the corresponding edge-map.
    552484    void hide(const Edge& e) const { _edge_filter_map->set(e, false); }
    553485
    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); }
    566487    void unHide(const Edge& e) const { _edge_filter_map->set(e, true); }
    567488
    568     /// \brief Returns true if \c n is hidden.
    569     ///
    570     /// Returns true if \c n is hidden.
    571489    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.
    576490    bool hidden(const Edge& e) const { return !(*_edge_filter_map)[e]; }
    577491
    578492    typedef False NodeNumTag;
     
    673587
    674588  /// \ingroup graph_adaptors
    675589  ///
    676   /// \brief A graph adaptor for hiding nodes and arcs from an
     590  /// \brief A graph adaptor for hiding nodes and edges from an
    677591  /// undirected graph.
    678592  ///
    679593  /// SubGraphAdaptor shows the graph with filtered node-set and
     
    695609    typedef _Graph Graph;
    696610    typedef GraphAdaptorExtender<
    697611      SubGraphAdaptorBase<_Graph, NodeFilterMap, EdgeFilterMap> > Parent;
     612
     613    typedef typename Parent::Node Node;
     614    typedef typename Parent::Edge Edge;
     615
    698616  protected:
    699617    SubGraphAdaptor() { }
    700618  public:
     619   
     620    /// \brief Constructor
     621    ///
     622    /// Creates a sub-graph-adaptor for the given graph with
     623    /// given node and edge map filters.
    701624    SubGraphAdaptor(Graph& _graph, NodeFilterMap& node_filter_map,
    702625                    EdgeFilterMap& edge_filter_map) {
    703626      setGraph(_graph);
    704627      setNodeFilterMap(node_filter_map);
    705628      setEdgeFilterMap(edge_filter_map);
    706629    }
     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); }
    707670  };
    708671
     672  /// \brief Just gives back a sub-graph adaptor
     673  ///
     674  /// Just gives back a sub-graph adaptor
    709675  template<typename Graph, typename NodeFilterMap, typename ArcFilterMap>
    710676  SubGraphAdaptor<const Graph, NodeFilterMap, ArcFilterMap>
    711677  subGraphAdaptor(const Graph& graph,
     
    756722    typedef _NodeFilterMap NodeFilterMap;
    757723    typedef SubGraphAdaptor<Graph, NodeFilterMap,
    758724                            ConstMap<typename Graph::Edge, bool> > Parent;
     725
     726    typedef typename Parent::Node Node;
    759727  protected:
    760728    ConstMap<typename Graph::Edge, bool> const_true_map;
    761729
     
    764732    }
    765733
    766734  public:
     735
     736    /// \brief Constructor
     737    ///
     738    /// Creates a node-sub-graph-adaptor for the given graph with
     739    /// given node map filters.
    767740    NodeSubGraphAdaptor(Graph& _graph, NodeFilterMap& node_filter_map) :
    768741      Parent(), const_true_map(true) {
    769742      Parent::setGraph(_graph);
    770743      Parent::setNodeFilterMap(node_filter_map);
    771744      Parent::setEdgeFilterMap(const_true_map);
    772745    }
     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
    773767  };
    774768
     769  /// \brief Just gives back a node-sub-graph adaptor
     770  ///
     771  /// Just gives back a node-sub-graph adaptor
    775772  template<typename Graph, typename NodeFilterMap>
    776773  NodeSubGraphAdaptor<const Graph, NodeFilterMap>
    777774  nodeSubGraphAdaptor(const Graph& graph, NodeFilterMap& nfm) {
     
    804801    typedef _EdgeFilterMap EdgeFilterMap;
    805802    typedef SubGraphAdaptor<Graph, ConstMap<typename Graph::Node,bool>,
    806803                            EdgeFilterMap, false> Parent;
     804    typedef typename Parent::Edge Edge;
    807805  protected:
    808806    ConstMap<typename Graph::Node, bool> const_true_map;
    809807
     
    813811
    814812  public:
    815813
     814    /// \brief Constructor
     815    ///
     816    /// Creates a edge-sub-graph-adaptor for the given graph with
     817    /// given node map filters.
    816818    EdgeSubGraphAdaptor(Graph& _graph, EdgeFilterMap& edge_filter_map) :
    817819      Parent(), const_true_map(true) {
    818820      Parent::setGraph(_graph);
     
    820822      Parent::setEdgeFilterMap(edge_filter_map);
    821823    }
    822824
     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
    823845  };
    824846
     847  /// \brief Just gives back an edge-sub-graph adaptor
     848  ///
     849  /// Just gives back an edge-sub-graph adaptor
    825850  template<typename Graph, typename EdgeFilterMap>
    826851  EdgeSubGraphAdaptor<const Graph, EdgeFilterMap>
    827852  edgeSubGraphAdaptor(const Graph& graph, EdgeFilterMap& efm) {
     
    834859    return EdgeSubGraphAdaptor<const Graph, const EdgeFilterMap>(graph, efm);
    835860  }
    836861
    837   /// \brief Base of direct graph adaptor
    838   ///
    839   /// Base class of the direct graph adaptor. All public member
    840   /// of this class can be used with the DirGraphAdaptor too.
    841   /// \sa DirGraphAdaptor
    842862  template <typename _Graph, typename _DirectionMap>
    843863  class DirGraphAdaptorBase {
    844864  public:
     
    10921112    typedef _Graph Graph;
    10931113    typedef DigraphAdaptorExtender<
    10941114      DirGraphAdaptorBase<_Graph, DirectionMap> > Parent;
     1115    typedef typename Parent::Arc Arc;
    10951116  protected:
    10961117    DirGraphAdaptor() { }
    10971118  public:
     
    11021123    DirGraphAdaptor(Graph& graph, DirectionMap& direction) {
    11031124      setGraph(graph);
    11041125      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);
    11051133    }
    11061134  };
    11071135
  • test/graph_adaptor_test.cc

    diff -r e67acd83a9ca -r 7a4a426a037e test/graph_adaptor_test.cc
    a b  
    3636#include"test/graph_test.h"
    3737
    3838using 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 }
    7539
    7640void checkRevDigraphAdaptor() {
    7741  checkConcept<concepts::Digraph, RevDigraphAdaptor<concepts::Digraph> >();
     
    585549  }
    586550}
    587551
    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 
    638552void checkSubGraphAdaptor() {
    639553  checkConcept<concepts::Graph,
    640554    SubGraphAdaptor<concepts::Graph,
     
    1053967
    1054968int main(int, const char **) {
    1055969
    1056   checkDigraphAdaptor();
    1057970  checkRevDigraphAdaptor();
    1058971  checkSubDigraphAdaptor();
    1059972  checkNodeSubDigraphAdaptor();
     
    1062975  checkResDigraphAdaptor();
    1063976  checkSplitDigraphAdaptor();
    1064977
    1065   checkGraphAdaptor();
    1066978  checkSubGraphAdaptor();
    1067979  checkNodeSubGraphAdaptor();
    1068980  checkEdgeSubGraphAdaptor();