COIN-OR::LEMON - Graph Library

Changeset 1627:3fd1ba6e9872 in lemon-0.x


Ignore:
Timestamp:
08/11/05 17:55:17 (14 years ago)
Author:
Balazs Dezso
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@2135
Message:

Some modification on the undirected graph interface.
Doc improvments

Location:
lemon
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • lemon/bits/erasable_graph_extender.h

    r1435 r1627  
    7171    void erase(const UndirEdge& uedge) {
    7272      std::vector<Edge> edges;
    73       edges.push_back(Edge(uedge,true));
    74       edges.push_back(Edge(uedge,false));
     73      edges.push_back(Parent::direct(uedge,true));
     74      edges.push_back(Parent::direct(uedge,false));
    7575      Parent::getNotifier(Edge()).erase(edges);
    7676      Parent::getNotifier(UndirEdge()).erase(uedge);
  • lemon/bits/extendable_graph_extender.h

    r1435 r1627  
    5252
    5353      std::vector<Edge> edges;
    54       edges.push_back(Edge(uedge, true));
    55       edges.push_back(Edge(uedge, false));
     54      edges.push_back(Parent::direct(uedge, true));
     55      edges.push_back(Parent::direct(uedge, false));
    5656      Parent::getNotifier(Edge()).add(edges);
    5757
  • lemon/bits/iterable_graph_extender.h

    r1564 r1627  
    119119    };
    120120
    121     /// Base node of the iterator
     121    /// \brief Base node of the iterator
    122122    ///
    123123    /// Returns the base node (ie. the source in this case) of the iterator
    124     ///
    125     /// \todo Document in the concept!
    126124    Node baseNode(const OutEdgeIt &e) const {
    127125      return Parent::source((Edge)e);
    128126    }
    129     /// Running node of the iterator
     127    /// \brief Running node of the iterator
    130128    ///
    131129    /// Returns the running node (ie. the target in this case) of the
    132130    /// iterator
    133     ///
    134     /// \todo Document in the concept!
    135131    Node runningNode(const OutEdgeIt &e) const {
    136132      return Parent::target((Edge)e);
    137133    }
    138134
    139     /// Base node of the iterator
     135    /// \brief Base node of the iterator
    140136    ///
    141137    /// Returns the base node (ie. the target in this case) of the iterator
    142     ///
    143     /// \todo Document in the concept!
    144138    Node baseNode(const InEdgeIt &e) const {
    145139      return Parent::target((Edge)e);
    146140    }
    147     /// Running node of the iterator
     141    /// \brief Running node of the iterator
    148142    ///
    149143    /// Returns the running node (ie. the source in this case) of the
    150144    /// iterator
    151     ///
    152     /// \todo Document in the concept!
    153145    Node runningNode(const InEdgeIt &e) const {
    154146      return Parent::source((Edge)e);
     
    157149    using Parent::first;
    158150
     151    /// \brief The opposite node on the given edge.
     152    ///
     153    /// Gives back the opposite on the given edge.
     154    Node oppositeNode(const Node& n, const Edge& e) const {
     155      if (Parent::source(e) == n) {
     156        return Parent::target(e);
     157      } else {
     158        return Parent::source(e);
     159      }
     160    }
     161
    159162  private:
    160 
    161     // /// \todo When (and if) we change the iterators concept to use operator*,
    162     // /// then the following shadowed methods will become superfluous.
    163     // /// But for now these are important safety measures.
    164163
    165164    // void first(NodeIt &) const;
     
    191190    typedef IterableUndirGraphExtender<_Base> Graph;
    192191    typedef typename Parent::Node Node;
    193 
     192    typedef typename Parent::Edge Edge;
    194193    typedef typename Parent::UndirEdge UndirEdge;
    195194
     
    262261    }
    263262
     263    /// \brief The opposite node on the given undirected edge.
     264    ///
     265    /// Gives back the opposite on the given undirected edge.
     266    Node oppositeNode(const Node& n, const UndirEdge& e) const {
     267      if (Parent::source(e) == n) {
     268        return Parent::target(e);
     269      } else {
     270        return Parent::source(e);
     271      }
     272    }
     273
    264274  };
    265275}
  • lemon/bits/undir_graph_extender.h

    r1435 r1627  
    4343      bool forward;
    4444
     45      Edge(const UndirEdge &ue, bool _forward) :
     46        UndirEdge(ue), forward(_forward) {}
     47
    4548    public:
    4649      Edge() {}
    47 
    48       /// \brief Directed edge from undirected edge and a direction.
    49       ///
    50       /// This constructor is not a part of the concept interface of
    51       /// undirected graph, so please avoid using it if possible!
    52       Edge(const UndirEdge &ue, bool _forward) :
    53         UndirEdge(ue), forward(_forward) {}
    54 
    55       /// \brief Directed edge from undirected edge and a source node.
    56       ///
    57       /// Constructs a directed edge from undirected edge and a source node.
    58       ///
    59       /// \note You have to specify the graph for this constructor.
    60       Edge(const Graph &g, const UndirEdge &ue, const Node &n) :
    61         UndirEdge(ue) { forward = (g.source(ue) == n); }
    6250
    6351      /// Invalid edge constructor
     
    8068    ///
    8169    /// Returns the Edge of opposite direction.
    82     Edge opposite(const Edge &e) const {
     70    Edge oppositeEdge(const Edge &e) const {
    8371      return Edge(e,!e.forward);
    8472    }
     
    114102      return _dirTarget(e);
    115103    }
    116 
    117     /// Returns whether the given directed edge is same orientation as the
    118     /// corresponding undirected edge.
    119     ///
    120     /// \todo reference to the corresponding point of the undirected graph
    121     /// concept. "What does the direction of an undirected edge mean?"
    122     bool forward(const Edge &e) const { return e.forward; }
    123104
    124105    Node oppositeNode(const Node &n, const UndirEdge &e) const {
     
    131112    }
    132113
    133     /// Directed edge from an undirected edge and a source node.
     114    /// \brief Directed edge from an undirected edge and a source node.
    134115    ///
    135116    /// Returns a (directed) Edge corresponding to the specified UndirEdge
    136117    /// and source Node.
    137118    ///
    138     ///\todo Do we need this?
    139     ///
    140     ///\todo Better name...
    141     Edge edgeWithSource(const UndirEdge &ue, const Node &s) const {
    142       return Edge(*this, ue, s);
    143     }
     119    Edge direct(const UndirEdge &ue, const Node &s) const {
     120      return Edge(ue, s == source(ue));
     121    }
     122
     123    /// \brief Directed edge from an undirected edge.
     124    ///
     125    /// Returns a directed edge corresponding to the specified UndirEdge.
     126    /// If the given bool is true the given undirected edge and the
     127    /// returned edge have the same source node.
     128    Edge direct(const UndirEdge &ue, bool d) const {
     129      return Edge(ue, d);
     130    }
     131
     132    /// Returns whether the given directed edge is same orientation as the
     133    /// corresponding undirected edge.
     134    ///
     135    /// \todo reference to the corresponding point of the undirected graph
     136    /// concept. "What does the direction of an undirected edge mean?"
     137    bool direction(const Edge &e) const { return e.forward; }
     138
    144139
    145140    using Parent::first;
  • lemon/concept/graph.h

    r1624 r1627  
    480480      ///
    481481      /// Gives back the base node of the iterator.
     482      /// It is always the target of the pointed edge.
    482483      Node baseNode(const InEdgeIt&) const { return INVALID; }
    483484
     
    485486      ///
    486487      /// Gives back the running node of the iterator.
     488      /// It is always the source of the pointed edge.
    487489      Node runningNode(const InEdgeIt&) const { return INVALID; }
    488490
     
    490492      ///
    491493      /// Gives back the base node of the iterator.
     494      /// It is always the source of the pointed edge.
    492495      Node baseNode(const OutEdgeIt&) const { return INVALID; }
    493496
     
    495498      ///
    496499      /// Gives back the running node of the iterator.
     500      /// It is always the target of the pointed edge.
    497501      Node runningNode(const OutEdgeIt&) const { return INVALID; }
    498       /// Read write map of the nodes to type \c T.
    499 
    500       /// \ingroup concept
     502
     503      /// \brief The opposite node on the given edge.
     504      ///
     505      /// Gives back the opposite node on the given edge.
     506      Node oppositeNode(const Node&, const Edge&) const { return INVALID; }
     507
     508      /// \brief Read write map of the nodes to type \c T.
     509      ///
    501510      /// ReadWrite map of the nodes to type \c T.
    502511      /// \sa Reference
     
    520529      };
    521530
    522       /// Read write map of the edges to type \c T.
    523 
    524       /// \ingroup concept
    525       ///Reference map of the edges to type \c T.
     531      /// \brief Read write map of the edges to type \c T.
     532      ///
     533      /// Reference map of the edges to type \c T.
    526534      /// \sa Reference
    527535      /// \warning Making maps that can handle bool type (EdgeMap<bool>)
     
    611619
    612620    };
    613 
    614    
    615     /************* New GraphBase stuff **************/
    616 
    617 
    618 //     /// A minimal GraphBase concept
    619 
    620 //     /// This class describes a minimal concept which can be extended to a
    621 //     /// full-featured graph with \ref GraphFactory.
    622 //     class GraphBase {
    623 //     public:
    624 
    625 //       GraphBase() {}
    626 
    627 //       /// \bug Should we demand that Node and Edge be subclasses of the
    628 //       /// Graph class???
    629 
    630 //       typedef GraphItem<'n'> Node;
    631 //       typedef GraphItem<'e'> Edge;
    632 
    633 // //       class Node : public BaseGraphItem<'n'> {};
    634 // //       class Edge : public BaseGraphItem<'e'> {};
    635 
    636 //       // Graph operation
    637 //       void firstNode(Node &n) const { }
    638 //       void firstEdge(Edge &e) const { }
    639 
    640 //       void firstOutEdge(Edge &e, Node) const { }
    641 //       void firstInEdge(Edge &e, Node) const { }
    642 
    643 //       void nextNode(Node &n) const { }
    644 //       void nextEdge(Edge &e) const { }
    645 
    646 
    647 //       // Question: isn't it reasonable if this methods have a Node
    648 //       // parameter? Like this:
    649 //       // Edge& nextOut(Edge &e, Node) const { return e; }
    650 //       void nextOutEdge(Edge &e) const { }
    651 //       void nextInEdge(Edge &e) const { }
    652 
    653 //       Node target(Edge) const { return Node(); }
    654 //       Node source(Edge) const { return Node(); }
    655      
    656 
    657 //       // Do we need id, nodeNum, edgeNum and co. in this basic graphbase
    658 //       // concept?
    659 
    660 
    661 //       // Maps.
    662 //       //
    663 //       // We need a special slimer concept which does not provide maps (it
    664 //       // wouldn't be strictly slimer, cause for map-factory id() & friends
    665 //       // a required...)
    666 
    667 //       template<typename T>
    668 //       class NodeMap : public GraphMap<GraphBase, Node, T> {};
    669 
    670 //       template<typename T>
    671 //       class EdgeMap : public GraphMap<GraphBase, Node, T> {};
    672 //     };
    673 
     621   
    674622    // @}
    675623  } //namespace concept 
  • lemon/concept/graph_component.h

    r1620 r1627  
    679679      ///
    680680      /// Gives back the base node of the iterator.
     681      /// It is always the target of the pointed edge.
    681682      Node baseNode(const InEdgeIt&) const { return INVALID; }
    682683
     
    684685      ///
    685686      /// Gives back the running node of the iterator.
     687      /// It is always the source of the pointed edge.
    686688      Node runningNode(const InEdgeIt&) const { return INVALID; }
    687689
     
    689691      ///
    690692      /// Gives back the base node of the iterator.
     693      /// It is always the source of the pointed edge.
    691694      Node baseNode(const OutEdgeIt&) const { return INVALID; }
    692695
     
    694697      ///
    695698      /// Gives back the running node of the iterator.
     699      /// It is always the target of the pointed edge.
    696700      Node runningNode(const OutEdgeIt&) const { return INVALID; }
     701
     702      /// \brief The opposite node on the given edge.
     703      ///
     704      /// Gives back the opposite on the given edge.
     705      /// \todo It should not be here.
     706      Node oppositeNode(const Node&, const Edge&) const { return INVALID; }
    697707
    698708   
     
    708718          checkConcept<GraphIncIterator<_Graph>, typename _Graph::InEdgeIt>();
    709719          checkConcept<GraphIncIterator<_Graph>, typename _Graph::OutEdgeIt>();
    710         }
     720
     721          typename _Graph::Node n;
     722          typename _Graph::Edge e;
     723          n = graph.oppositeNode(n, e);
     724        }
     725       
     726        const _Graph& graph;
     727       
    711728      };
    712729    };
  • lemon/concept/undir_graph.h

    r1624 r1627  
    120120
    121121          bool b;
    122           b = graph.forward(e);
     122          b = graph.direction(e);
     123          Edge e = graph.direct(UndirEdge(), true);
     124          e = graph.direct(UndirEdge(), n);
     125 
    123126          ignore_unused_variable_warning(b);
    124127        }
     
    233236    /// explanation of this and more see also the page \ref undir_graphs,
    234237    /// a tutorial about undirected graphs.
    235 
    236     class UndirGraph : public StaticGraph {
     238    ///
     239    /// You can assume that all undirected graph can be handled
     240    /// as a static directed graph. This way it is fully conform
     241    /// to the StaticGraph concept.
     242
     243    class UndirGraph {
    237244    public:
    238245      ///\e
     
    242249      typedef True UndirTag;
    243250
     251      /// The base type of node iterators,
     252      /// or in other words, the trivial node iterator.
     253
     254      /// This is the base type of each node iterator,
     255      /// thus each kind of node iterator converts to this.
     256      /// More precisely each kind of node iterator should be inherited
     257      /// from the trivial node iterator.
     258      class Node {
     259      public:
     260        /// Default constructor
     261
     262        /// @warning The default constructor sets the iterator
     263        /// to an undefined value.
     264        Node() { }
     265        /// Copy constructor.
     266
     267        /// Copy constructor.
     268        ///
     269        Node(const Node&) { }
     270
     271        /// Invalid constructor \& conversion.
     272
     273        /// This constructor initializes the iterator to be invalid.
     274        /// \sa Invalid for more details.
     275        Node(Invalid) { }
     276        /// Equality operator
     277
     278        /// Two iterators are equal if and only if they point to the
     279        /// same object or both are invalid.
     280        bool operator==(Node) const { return true; }
     281
     282        /// Inequality operator
     283       
     284        /// \sa operator==(Node n)
     285        ///
     286        bool operator!=(Node) const { return true; }
     287
     288        /// Artificial ordering operator.
     289       
     290        /// To allow the use of graph descriptors as key type in std::map or
     291        /// similar associative container we require this.
     292        ///
     293        /// \note This operator only have to define some strict ordering of
     294        /// the items; this order has nothing to do with the iteration
     295        /// ordering of the items.
     296        ///
     297        /// \bug This is a technical requirement. Do we really need this?
     298        bool operator<(Node) const { return false; }
     299
     300      };
     301   
     302      /// This iterator goes through each node.
     303
     304      /// This iterator goes through each node.
     305      /// Its usage is quite simple, for example you can count the number
     306      /// of nodes in graph \c g of type \c Graph like this:
     307      /// \code
     308      /// int count=0;
     309      /// for (Graph::NodeIt n(g); n!=INVALID; ++n) ++count;
     310      /// \endcode
     311      class NodeIt : public Node {
     312      public:
     313        /// Default constructor
     314
     315        /// @warning The default constructor sets the iterator
     316        /// to an undefined value.
     317        NodeIt() { }
     318        /// Copy constructor.
     319       
     320        /// Copy constructor.
     321        ///
     322        NodeIt(const NodeIt& n) : Node(n) { }
     323        /// Invalid constructor \& conversion.
     324
     325        /// Initialize the iterator to be invalid.
     326        /// \sa Invalid for more details.
     327        NodeIt(Invalid) { }
     328        /// Sets the iterator to the first node.
     329
     330        /// Sets the iterator to the first node of \c g.
     331        ///
     332        NodeIt(const UndirGraph&) { }
     333        /// Node -> NodeIt conversion.
     334
     335        /// Sets the iterator to the node of \c the graph pointed by
     336        /// the trivial iterator.
     337        /// This feature necessitates that each time we
     338        /// iterate the edge-set, the iteration order is the same.
     339        NodeIt(const UndirGraph&, const Node&) { }
     340        /// Next node.
     341
     342        /// Assign the iterator to the next node.
     343        ///
     344        NodeIt& operator++() { return *this; }
     345      };
     346   
     347   
    244348      /// The base type of the undirected edge iterators.
    245      
     349
    246350      /// The base type of the undirected edge iterators.
    247351      ///
     
    258362        ///
    259363        UndirEdge(const UndirEdge&) { }
    260         /// Edge -> UndirEdge conversion
    261 
    262         /// Edge -> UndirEdge conversion
    263         ///
    264         UndirEdge(const Edge&) { }
    265364        /// Initialize the iterator to be invalid.
    266365
     
    279378        bool operator!=(UndirEdge) const { return true; }
    280379
    281         ///\e
    282 
    283         ///\todo Do we need this?
     380        /// Artificial ordering operator.
     381       
     382        /// To allow the use of graph descriptors as key type in std::map or
     383        /// similar associative container we require this.
    284384        ///
    285         bool operator<(const UndirEdge &that) const { return true; }
    286       };
    287    
     385        /// \note This operator only have to define some strict ordering of
     386        /// the items; this order has nothing to do with the iteration
     387        /// ordering of the items.
     388        ///
     389        /// \bug This is a technical requirement. Do we really need this?
     390        bool operator<(UndirEdge) const { return false; }
     391      };
     392
    288393      /// This iterator goes through each undirected edge.
    289394
    290395      /// This iterator goes through each undirected edge of a graph.
    291396      /// Its usage is quite simple, for example you can count the number
    292       /// of edges in a graph \c g of type \c Graph as follows:
     397      /// of undirected edges in a graph \c g of type \c Graph as follows:
    293398      /// \code
    294399      /// int count=0;
     
    298403      public:
    299404        /// Default constructor
    300        
     405
    301406        /// @warning The default constructor sets the iterator
    302407        /// to an undefined value.
    303408        UndirEdgeIt() { }
    304409        /// Copy constructor.
    305        
     410
    306411        /// Copy constructor.
    307412        ///
     
    312417        ///
    313418        UndirEdgeIt(Invalid) { }
    314         /// This constructor sets the iterator to the first edge.
     419        /// This constructor sets the iterator to the first undirected edge.
    315420   
    316         /// This constructor sets the iterator to the first edge of \c g.
     421        /// This constructor sets the iterator to the first undirected edge.
    317422        UndirEdgeIt(const UndirGraph&) { }
    318423        /// UndirEdge -> UndirEdgeIt conversion
    319424
    320         /// Sets the iterator to the value of the trivial iterator \c e.
    321         /// This feature necessitates that each time we
    322         /// iterate the edge-set, the iteration order is the same.
     425        /// Sets the iterator to the value of the trivial iterator.
     426        /// This feature necessitates that each time we
     427        /// iterate the undirected edge-set, the iteration order is the
     428        /// same.
    323429        UndirEdgeIt(const UndirGraph&, const UndirEdge&) { }
    324         ///Next edge
     430        /// Next undirected edge
    325431       
    326         /// Assign the iterator to the next edge.
     432        /// Assign the iterator to the next undirected edge.
    327433        UndirEdgeIt& operator++() { return *this; }
    328434      };
    329435
    330       /// This iterator goes trough the incident undirected edges of a node.
    331 
     436      /// \brief This iterator goes trough the incident undirected
     437      /// edges of a node.
     438      ///
    332439      /// This iterator goes trough the incident undirected edges
    333440      /// of a certain node
     
    376483      };
    377484
     485      /// The directed edge type.
     486
     487      /// The directed edge type. It can be converted to the
     488      /// undirected edge.
     489      class Edge : public UndirEdge {
     490      public:
     491        /// Default constructor
     492
     493        /// @warning The default constructor sets the iterator
     494        /// to an undefined value.
     495        Edge() { }
     496        /// Copy constructor.
     497
     498        /// Copy constructor.
     499        ///
     500        Edge(const Edge& e) : UndirEdge(e) { }
     501        /// Initialize the iterator to be invalid.
     502
     503        /// Initialize the iterator to be invalid.
     504        ///
     505        Edge(Invalid) { }
     506        /// Equality operator
     507
     508        /// Two iterators are equal if and only if they point to the
     509        /// same object or both are invalid.
     510        bool operator==(Edge) const { return true; }
     511        /// Inequality operator
     512
     513        /// \sa operator==(Edge n)
     514        ///
     515        bool operator!=(Edge) const { return true; }
     516
     517        /// Artificial ordering operator.
     518       
     519        /// To allow the use of graph descriptors as key type in std::map or
     520        /// similar associative container we require this.
     521        ///
     522        /// \note This operator only have to define some strict ordering of
     523        /// the items; this order has nothing to do with the iteration
     524        /// ordering of the items.
     525        ///
     526        /// \bug This is a technical requirement. Do we really need this?
     527        bool operator<(Edge) const { return false; }
     528       
     529      };
     530      /// This iterator goes through each directed edge.
     531
     532      /// This iterator goes through each edge of a graph.
     533      /// Its usage is quite simple, for example you can count the number
     534      /// of edges in a graph \c g of type \c Graph as follows:
     535      /// \code
     536      /// int count=0;
     537      /// for(Graph::EdgeIt e(g); e!=INVALID; ++e) ++count;
     538      /// \endcode
     539      class EdgeIt : public Edge {
     540      public:
     541        /// Default constructor
     542
     543        /// @warning The default constructor sets the iterator
     544        /// to an undefined value.
     545        EdgeIt() { }
     546        /// Copy constructor.
     547
     548        /// Copy constructor.
     549        ///
     550        EdgeIt(const EdgeIt& e) : Edge(e) { }
     551        /// Initialize the iterator to be invalid.
     552
     553        /// Initialize the iterator to be invalid.
     554        ///
     555        EdgeIt(Invalid) { }
     556        /// This constructor sets the iterator to the first edge.
     557   
     558        /// This constructor sets the iterator to the first edge of \c g.
     559        ///@param g the graph
     560        EdgeIt(const UndirGraph&) { }
     561        /// Edge -> EdgeIt conversion
     562
     563        /// Sets the iterator to the value of the trivial iterator \c e.
     564        /// This feature necessitates that each time we
     565        /// iterate the edge-set, the iteration order is the same.
     566        EdgeIt(const UndirGraph&, const Edge&) { }
     567        ///Next edge
     568       
     569        /// Assign the iterator to the next edge.
     570        EdgeIt& operator++() { return *this; }
     571      };
     572   
     573      /// This iterator goes trough the outgoing directed edges of a node.
     574
     575      /// This iterator goes trough the \e outgoing edges of a certain node
     576      /// of a graph.
     577      /// Its usage is quite simple, for example you can count the number
     578      /// of outgoing edges of a node \c n
     579      /// in graph \c g of type \c Graph as follows.
     580      /// \code
     581      /// int count=0;
     582      /// for (Graph::OutEdgeIt e(g, n); e!=INVALID; ++e) ++count;
     583      /// \endcode
     584   
     585      class OutEdgeIt : public Edge {
     586      public:
     587        /// Default constructor
     588
     589        /// @warning The default constructor sets the iterator
     590        /// to an undefined value.
     591        OutEdgeIt() { }
     592        /// Copy constructor.
     593
     594        /// Copy constructor.
     595        ///
     596        OutEdgeIt(const OutEdgeIt& e) : Edge(e) { }
     597        /// Initialize the iterator to be invalid.
     598
     599        /// Initialize the iterator to be invalid.
     600        ///
     601        OutEdgeIt(Invalid) { }
     602        /// This constructor sets the iterator to the first outgoing edge.
     603   
     604        /// This constructor sets the iterator to the first outgoing edge of
     605        /// the node.
     606        ///@param n the node
     607        ///@param g the graph
     608        OutEdgeIt(const UndirGraph&, const Node&) { }
     609        /// Edge -> OutEdgeIt conversion
     610
     611        /// Sets the iterator to the value of the trivial iterator.
     612        /// This feature necessitates that each time we
     613        /// iterate the edge-set, the iteration order is the same.
     614        OutEdgeIt(const UndirGraph&, const Edge&) { }
     615        ///Next outgoing edge
     616       
     617        /// Assign the iterator to the next
     618        /// outgoing edge of the corresponding node.
     619        OutEdgeIt& operator++() { return *this; }
     620      };
     621
     622      /// This iterator goes trough the incoming directed edges of a node.
     623
     624      /// This iterator goes trough the \e incoming edges of a certain node
     625      /// of a graph.
     626      /// Its usage is quite simple, for example you can count the number
     627      /// of outgoing edges of a node \c n
     628      /// in graph \c g of type \c Graph as follows.
     629      /// \code
     630      /// int count=0;
     631      /// for(Graph::InEdgeIt e(g, n); e!=INVALID; ++e) ++count;
     632      /// \endcode
     633
     634      class InEdgeIt : public Edge {
     635      public:
     636        /// Default constructor
     637
     638        /// @warning The default constructor sets the iterator
     639        /// to an undefined value.
     640        InEdgeIt() { }
     641        /// Copy constructor.
     642
     643        /// Copy constructor.
     644        ///
     645        InEdgeIt(const InEdgeIt& e) : Edge(e) { }
     646        /// Initialize the iterator to be invalid.
     647
     648        /// Initialize the iterator to be invalid.
     649        ///
     650        InEdgeIt(Invalid) { }
     651        /// This constructor sets the iterator to first incoming edge.
     652   
     653        /// This constructor set the iterator to the first incoming edge of
     654        /// the node.
     655        ///@param n the node
     656        ///@param g the graph
     657        InEdgeIt(const UndirGraph&, const Node&) { }
     658        /// Edge -> InEdgeIt conversion
     659
     660        /// Sets the iterator to the value of the trivial iterator \c e.
     661        /// This feature necessitates that each time we
     662        /// iterate the edge-set, the iteration order is the same.
     663        InEdgeIt(const UndirGraph&, const Edge&) { }
     664        /// Next incoming edge
     665
     666        /// Assign the iterator to the next inedge of the corresponding node.
     667        ///
     668        InEdgeIt& operator++() { return *this; }
     669      };
     670
     671      /// \brief Read write map of the nodes to type \c T.
     672      ///
     673      /// ReadWrite map of the nodes to type \c T.
     674      /// \sa Reference
     675      /// \warning Making maps that can handle bool type (NodeMap<bool>)
     676      /// needs some extra attention!
     677      template<class T>
     678      class NodeMap : public ReadWriteMap< Node, T >
     679      {
     680      public:
     681
     682        ///\e
     683        NodeMap(const UndirGraph&) { }
     684        ///\e
     685        NodeMap(const UndirGraph&, T) { }
     686
     687        ///Copy constructor
     688        NodeMap(const NodeMap& nm) : ReadWriteMap< Node, T >(nm) { }
     689        ///Assignment operator
     690        NodeMap& operator=(const NodeMap&) { return *this; }
     691        // \todo fix this concept
     692      };
     693
     694      /// \brief Read write map of the directed edges to type \c T.
     695      ///
     696      /// Reference map of the directed edges to type \c T.
     697      /// \sa Reference
     698      /// \warning Making maps that can handle bool type (EdgeMap<bool>)
     699      /// needs some extra attention!
     700      template<class T>
     701      class EdgeMap : public ReadWriteMap<Edge,T>
     702      {
     703      public:
     704
     705        ///\e
     706        EdgeMap(const UndirGraph&) { }
     707        ///\e
     708        EdgeMap(const UndirGraph&, T) { }
     709        ///Copy constructor
     710        EdgeMap(const EdgeMap& em) : ReadWriteMap<Edge,T>(em) { }
     711        ///Assignment operator
     712        EdgeMap& operator=(const EdgeMap&) { return *this; }
     713        // \todo fix this concept   
     714      };
     715
    378716      /// Read write map of the undirected edges to type \c T.
    379717
     
    392730        UndirEdgeMap(const UndirGraph&, T) { }
    393731        ///Copy constructor
    394         UndirEdgeMap(const UndirEdgeMap& em) : ReadWriteMap<UndirEdge,T>(em) { }
     732        UndirEdgeMap(const UndirEdgeMap& em) : ReadWriteMap<UndirEdge,T>(em) {}
    395733        ///Assignment operator
    396734        UndirEdgeMap &operator=(const UndirEdgeMap&) { return *this; }
     
    398736      };
    399737
    400       /// Is the Edge oriented "forward"?
    401 
     738      /// \brief Direct the given undirected edge.
     739      ///
     740      /// Direct the given undirected edge. The returned edge source
     741      /// will be the given edge.
     742      Edge direct(const UndirEdge&, const Node&) const {
     743        return INVALID;
     744      }
     745
     746      /// \brief Direct the given undirected edge.
     747      ///
     748      /// Direct the given undirected edge. The returned edge source
     749      /// will be the source of the undirected edge if the given bool
     750      /// is true.
     751      Edge direct(const UndirEdge&, bool) const {
     752        return INVALID;
     753      }
     754
     755      /// \brief Returns true if the edge has default orientation.
     756      ///
    402757      /// Returns whether the given directed edge is same orientation as
    403758      /// the corresponding undirected edge.
    404       ///
    405       /// \todo "What does the direction of an undirected edge mean?"
    406       bool forward(Edge) const { return true; }
    407 
    408       /// Opposite node on an edge
    409 
     759      bool direction(Edge) const { return true; }
     760
     761      /// \brief Returns the opposite directed edge.
     762      ///
     763      /// Returns the opposite directed edge.
     764      Edge oppositeEdge(Edge) const { return INVALID; }
     765
     766      /// \brief Opposite node on an edge
     767      ///
    410768      /// \return the opposite of the given Node on the given Edge
    411       ///
    412       /// \todo What should we do if given Node and Edge are not incident?
    413769      Node oppositeNode(Node, UndirEdge) const { return INVALID; }
    414770
    415       /// First node of the undirected edge.
    416 
     771      /// \brief First node of the undirected edge.
     772      ///
    417773      /// \return the first node of the given UndirEdge.
    418774      ///
     
    421777      /// to query the two endnodes of the edge. The direction of the edge
    422778      /// which arises this way is called the inherent direction of the
    423       /// undirected edge, and is used to define the "forward" direction
     779      /// undirected edge, and is used to define the "default" direction
    424780      /// of the directed versions of the edges.
    425       /// \sa forward
     781      /// \sa direction
    426782      Node source(UndirEdge) const { return INVALID; }
    427783
    428       /// Second node of the undirected edge.
     784      /// \brief Second node of the undirected edge.
    429785      Node target(UndirEdge) const { return INVALID; }
    430786
    431       /// Source node of the directed edge.
     787      /// \brief Source node of the directed edge.
    432788      Node source(Edge) const { return INVALID; }
    433789
    434       /// Target node of the directed edge.
     790      /// \brief Target node of the directed edge.
    435791      Node target(Edge) const { return INVALID; }
    436792
    437       /// First node of the graph
    438 
     793      /// \brief First node of the graph
     794      ///
    439795      /// \note This method is part of so called \ref
    440796      /// developpers_interface "Developpers' interface", so it shouldn't
    441797      /// be used in an end-user program.
    442798      void first(Node&) const {}
    443       /// Next node of the graph
    444 
     799      /// \brief Next node of the graph
     800      ///
    445801      /// \note This method is part of so called \ref
    446802      /// developpers_interface "Developpers' interface", so it shouldn't
     
    448804      void next(Node&) const {}
    449805
    450       /// First undirected edge of the graph
    451 
     806      /// \brief First undirected edge of the graph
     807      ///
    452808      /// \note This method is part of so called \ref
    453809      /// developpers_interface "Developpers' interface", so it shouldn't
    454810      /// be used in an end-user program.
    455811      void first(UndirEdge&) const {}
    456       /// Next undirected edge of the graph
    457 
     812      /// \brief Next undirected edge of the graph
     813      ///
    458814      /// \note This method is part of so called \ref
    459815      /// developpers_interface "Developpers' interface", so it shouldn't
     
    461817      void next(UndirEdge&) const {}
    462818
    463       /// First directed edge of the graph
    464 
     819      /// \brief First directed edge of the graph
     820      ///
    465821      /// \note This method is part of so called \ref
    466822      /// developpers_interface "Developpers' interface", so it shouldn't
    467823      /// be used in an end-user program.
    468824      void first(Edge&) const {}
    469       /// Next directed edge of the graph
    470 
     825      /// \brief Next directed edge of the graph
     826      ///
    471827      /// \note This method is part of so called \ref
    472828      /// developpers_interface "Developpers' interface", so it shouldn't
     
    474830      void next(Edge&) const {}
    475831
    476       /// First outgoing edge from a given node
    477 
     832      /// \brief First outgoing edge from a given node
     833      ///
    478834      /// \note This method is part of so called \ref
    479835      /// developpers_interface "Developpers' interface", so it shouldn't
    480836      /// be used in an end-user program.
    481837      void firstOut(Edge&, Node) const {}
    482       /// Next outgoing edge to a node
    483 
     838      /// \brief Next outgoing edge to a node
     839      ///
    484840      /// \note This method is part of so called \ref
    485841      /// developpers_interface "Developpers' interface", so it shouldn't
     
    487843      void nextOut(Edge&) const {}
    488844
    489       /// First incoming edge to a given node
    490 
     845      /// \brief First incoming edge to a given node
     846      ///
    491847      /// \note This method is part of so called \ref
    492848      /// developpers_interface "Developpers' interface", so it shouldn't
    493849      /// be used in an end-user program.
    494850      void firstIn(Edge&, Node) const {}
    495       /// Next incoming edge to a node
    496 
     851      /// \brief Next incoming edge to a node
     852      ///
    497853      /// \note This method is part of so called \ref
    498854      /// developpers_interface "Developpers' interface", so it shouldn't
     
    501857
    502858
    503       /// Base node of the iterator
     859      /// \brief Base node of the iterator
    504860      ///
    505861      /// Returns the base node (the source in this case) of the iterator
     
    507863        return source(e);
    508864      }
    509       /// Running node of the iterator
     865      /// \brief Running node of the iterator
    510866      ///
    511867      /// Returns the running node (the target in this case) of the
     
    515871      }
    516872
    517       /// Base node of the iterator
     873      /// \brief Base node of the iterator
    518874      ///
    519875      /// Returns the base node (the target in this case) of the iterator
     
    521877        return target(e);
    522878      }
    523       /// Running node of the iterator
     879      /// \brief Running node of the iterator
    524880      ///
    525881      /// Returns the running node (the source in this case) of the
     
    529885      }
    530886
    531       /// Base node of the iterator
     887      /// \brief Base node of the iterator
    532888      ///
    533889      /// Returns the base node of the iterator
     
    535891        return INVALID;
    536892      }
    537       /// Running node of the iterator
     893     
     894      /// \brief Running node of the iterator
    538895      ///
    539896      /// Returns the running node of the iterator
     
    541898        return INVALID;
    542899      }
    543 
    544900
    545901      template <typename Graph>
     
    554910    };
    555911
     912    /// \brief An empty non-static undirected graph class.
     913    ///   
     914    /// This class provides everything that \ref UndirGraph does.
     915    /// Additionally it enables building graphs from scratch.
    556916    class ExtendableUndirGraph : public UndirGraph {
    557917    public:
     918     
     919      /// \brief Add a new node to the graph.
     920      ///
     921      /// Add a new node to the graph.
     922      /// \return the new node.
     923      Node addNode();
     924
     925      /// \brief Add a new undirected edge to the graph.
     926      ///
     927      /// Add a new undirected edge to the graph.
     928      /// \return the new edge.
     929      UndirEdge addEdge(const Node& from, const Node& to);
     930
     931      /// \brief Resets the graph.
     932      ///
     933      /// This function deletes all undirected edges and nodes of the graph.
     934      /// It also frees the memory allocated to store them.
     935      void clear() { }
    558936
    559937      template <typename Graph>
     
    572950    };
    573951
     952    /// \brief An empty erasable undirected graph class.
     953    ///
     954    /// This class is an extension of \ref ExtendableUndirGraph. It makes it
     955    /// possible to erase undirected edges or nodes.
    574956    class ErasableUndirGraph : public ExtendableUndirGraph {
    575957    public:
     958
     959      /// \brief Deletes a node.
     960      ///
     961      /// Deletes a node.
     962      ///
     963      void erase(Node) { }
     964      /// \brief Deletes an undirected edge.
     965      ///
     966      /// Deletes an undirected edge.
     967      ///
     968      void erase(UndirEdge) { }
    576969
    577970      template <typename Graph>
  • lemon/graph_adaptor.h

    r1576 r1627  
    106106    void clear() const { graph->clear(); }
    107107   
    108     bool forward(const Edge& e) const { return graph->forward(e); }
    109     bool backward(const Edge& e) const { return graph->backward(e); }
    110 
    111108    int id(const Node& v) const { return graph->id(v); }
    112109    int id(const Edge& e) const { return graph->id(e); }
    113110   
    114     Edge opposite(const Edge& e) const { return Edge(graph->opposite(e)); }
     111    Edge oppositeNode(const Edge& e) const {
     112      return Edge(graph->opposite(e));
     113    }
    115114
    116115    template <typename _Value>
     
    609608     
    610609      void set(Edge e, T a) {
    611         if (g->forward(e))
     610        if (g->direction(e))
    612611          forward_map.set(e, a);
    613612        else
     
    616615
    617616      T operator[](Edge e) const {
    618         if (g->forward(e))
     617        if (g->direction(e))
    619618          return forward_map[e];
    620619        else
  • lemon/graph_utils.h

    r1591 r1627  
    996996    /// \return The "forward" directed edge view of undirected edge
    997997    Value operator[](const Key& key) const {
    998       return graph.edgeWithSource(key, graph.source(key));
     998      return graph.direct(key, true);
    999999    }
    10001000
     
    10361036    /// \return The "backward" directed edge view of undirected edge
    10371037    Value operator[](const Key& key) const {
    1038       return graph.edgeWithSource(key, graph.target(key));
     1038      return graph.direct(key, false);
    10391039    }
    10401040
  • lemon/lemon_reader.h

    r1494 r1627  
    13231323      UndirEdge undirEdge = inverter->read(is);
    13241324      if (c == '+') {
    1325         edge = graph.edgeWithSource(undirEdge, graph.source(undirEdge));
     1325        edge = graph.direct(undirEdge, true);
    13261326      } else if (c == '-') {
    1327         edge = graph.edgeWithSource(undirEdge, graph.target(undirEdge));
     1327        edge = graph.direct(undirEdge, false);
    13281328      } else {
    13291329        throw DataFormatError("Wrong id format for edge "
Note: See TracChangeset for help on using the changeset viewer.