deba@1911: /* -*- C++ -*- deba@1911: * deba@1911: * lemon/concept/ugraph_component.h - Part of LEMON, a generic deba@1911: * C++ optimization library deba@1911: * deba@1911: * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi deba@1911: * Kutatocsoport (Egervary Research Group on Combinatorial Optimization, deba@1911: * EGRES). deba@1911: * deba@1911: * Permission to use, modify and distribute this software is granted deba@1911: * provided that this copyright notice appears in all copies. For deba@1911: * precise terms see the accompanying LICENSE file. deba@1911: * deba@1911: * This software is provided "AS IS" with no warranty of any kind, deba@1911: * express or implied, and with no claim as to its suitability for any deba@1911: * purpose. deba@1911: * deba@1911: */ deba@1911: deba@1911: /// \ingroup graph_concepts deba@1911: /// \file deba@1911: /// \brief Undirected bipartite graphs and components of. deba@1911: deba@1911: deba@1911: #ifndef LEMON_CONCEPT_BPUGRAPH_H deba@1911: #define LEMON_CONCEPT_BPUGRAPH_H deba@1911: deba@1911: #include deba@1911: deba@1911: #include deba@1911: #include deba@1911: deba@1911: #include deba@1911: deba@1911: namespace lemon { deba@1911: namespace concept { deba@1911: deba@1911: /// \addtogroup graph_concepts deba@1911: /// @{ deba@1911: deba@1911: deba@1911: /// \brief Class describing the concept of Bipartite Undirected Graphs. deba@1911: /// deba@1911: /// This class describes the common interface of all deba@1911: /// Undirected Bipartite Graphs. deba@1911: /// deba@1911: /// As all concept describing classes it provides only interface deba@1911: /// without any sensible implementation. So any algorithm for deba@1911: /// bipartite undirected graph should compile with this class, but it deba@1911: /// will not run properly, of course. deba@1911: /// deba@1911: /// In LEMON bipartite undirected graphs also fulfill the concept of deba@1911: /// the undirected graphs (\ref lemon::concept::UGraph "UGraph Concept"). deba@1911: /// deba@1911: /// You can assume that all undirected bipartite graph can be handled deba@1911: /// as an undirected graph and consequently as a static graph. deba@1911: /// deba@1911: /// The bipartite graph stores two types of nodes which are named deba@1933: /// ANode and BNode. The graph type contains two types ANode and BNode deba@1933: /// which are inherited from Node type. Moreover they have deba@1933: /// constructor which converts Node to either ANode or BNode when it is deba@1933: /// possible. Therefor everywhere the Node type can be used instead of deba@1933: /// ANode and BNode. So the usage of the ANode and BNode is suggested. deba@1911: /// deba@1911: /// The iteration on the partition can be done with the ANodeIt and deba@1911: /// BNodeIt classes. The node map can be used to map values to the nodes deba@1911: /// and similarly we can use to map values for just the ANodes and deba@1911: /// BNodes the ANodeMap and BNodeMap template classes. deba@1911: deba@1911: class BpUGraph { deba@1911: public: deba@1911: /// \todo undocumented deba@1911: /// deba@1911: typedef True UTag; deba@1911: deba@1911: /// \brief The base type of node iterators, deba@1911: /// or in other words, the trivial node iterator. deba@1911: /// deba@1911: /// This is the base type of each node iterator, deba@1911: /// thus each kind of node iterator converts to this. deba@1911: /// More precisely each kind of node iterator should be inherited deba@1911: /// from the trivial node iterator. The Node class represents deba@1911: /// both of two types of nodes. deba@1911: class Node { deba@1911: public: deba@1911: /// Default constructor deba@1911: deba@1911: /// @warning The default constructor sets the iterator deba@1911: /// to an undefined value. deba@1911: Node() { } deba@1911: /// Copy constructor. deba@1911: deba@1911: /// Copy constructor. deba@1911: /// deba@1911: Node(const Node&) { } deba@1911: deba@1911: /// Invalid constructor \& conversion. deba@1911: deba@1911: /// This constructor initializes the iterator to be invalid. deba@1911: /// \sa Invalid for more details. deba@1911: Node(Invalid) { } deba@1911: /// Equality operator deba@1911: deba@1911: /// Two iterators are equal if and only if they point to the deba@1911: /// same object or both are invalid. deba@1911: bool operator==(Node) const { return true; } deba@1911: deba@1911: /// Inequality operator deba@1911: deba@1911: /// \sa operator==(Node n) deba@1911: /// deba@1911: bool operator!=(Node) const { return true; } deba@1911: deba@1911: /// Artificial ordering operator. deba@1911: deba@1911: /// To allow the use of graph descriptors as key type in std::map or deba@1911: /// similar associative container we require this. deba@1911: /// deba@1911: /// \note This operator only have to define some strict ordering of deba@1911: /// the items; this order has nothing to do with the iteration deba@1911: /// ordering of the items. deba@1911: /// deba@1911: /// \bug This is a technical requirement. Do we really need this? deba@1911: bool operator<(Node) const { return false; } deba@1911: deba@1911: }; deba@1933: deba@1933: /// \brief The base type of anode iterators, deba@1933: /// or in other words, the trivial anode iterator. deba@1933: /// deba@1933: /// This is the base type of each anode iterator, deba@1933: /// thus each kind of anode iterator converts to this. deba@1933: /// More precisely each kind of node iterator should be inherited deba@1933: /// from the trivial anode iterator. The ANode class should be used deba@1933: /// only in special cases. Usually the Node type should be used insted deba@1933: /// of it. deba@1933: class ANode { deba@1933: public: deba@1933: /// Default constructor deba@1933: deba@1933: /// @warning The default constructor sets the iterator deba@1933: /// to an undefined value. deba@1933: ANode() { } deba@1933: /// Copy constructor. deba@1933: deba@1933: /// Copy constructor. deba@1933: /// deba@1933: ANode(const ANode&) { } deba@1933: deba@1933: /// Construct the same node as ANode. deba@1933: deba@1933: /// Construct the same node as ANode. It may throws assertion deba@1933: /// when the given node is from the BNode set. deba@1933: ANode(const Node&) { } deba@1933: deba@1933: /// Invalid constructor \& conversion. deba@1933: deba@1933: /// This constructor initializes the iterator to be invalid. deba@1933: /// \sa Invalid for more details. deba@1933: ANode(Invalid) { } deba@1933: /// Equality operator deba@1933: deba@1933: /// Two iterators are equal if and only if they point to the deba@1933: /// same object or both are invalid. deba@1933: bool operator==(ANode) const { return true; } deba@1933: deba@1933: /// Inequality operator deba@1933: deba@1933: /// \sa operator==(ANode n) deba@1933: /// deba@1933: bool operator!=(ANode) const { return true; } deba@1933: deba@1933: /// Artificial ordering operator. deba@1933: deba@1933: /// To allow the use of graph descriptors as key type in std::map or deba@1933: /// similar associative container we require this. deba@1933: /// deba@1933: /// \note This operator only have to define some strict ordering of deba@1933: /// the items; this order has nothing to do with the iteration deba@1933: /// ordering of the items. deba@1933: bool operator<(ANode) const { return false; } deba@1933: deba@1933: }; deba@1933: deba@1933: /// \brief The base type of bnode iterators, deba@1933: /// or in other words, the trivial bnode iterator. deba@1933: /// deba@1933: /// This is the base type of each anode iterator, deba@1933: /// thus each kind of anode iterator converts to this. deba@1933: /// More precisely each kind of node iterator should be inherited deba@1933: /// from the trivial anode iterator. The BNode class should be used deba@1933: /// only in special cases. Usually the Node type should be used insted deba@1933: /// of it. deba@1933: class BNode { deba@1933: public: deba@1933: /// Default constructor deba@1933: deba@1933: /// @warning The default constructor sets the iterator deba@1933: /// to an undefined value. deba@1933: BNode() { } deba@1933: /// Copy constructor. deba@1933: deba@1933: /// Copy constructor. deba@1933: /// deba@1933: BNode(const BNode&) { } deba@1933: deba@1933: /// Construct the same node as BNode. deba@1933: deba@1933: /// Construct the same node as BNode. It may throws assertion deba@1933: /// when the given node is from the ANode set. deba@1933: BNode(const Node&) { } deba@1933: deba@1933: /// Invalid constructor \& conversion. deba@1933: deba@1933: /// This constructor initializes the iterator to be invalid. deba@1933: /// \sa Invalid for more details. deba@1933: BNode(Invalid) { } deba@1933: /// Equality operator deba@1933: deba@1933: /// Two iterators are equal if and only if they point to the deba@1933: /// same object or both are invalid. deba@1933: bool operator==(BNode) const { return true; } deba@1933: deba@1933: /// Inequality operator deba@1933: deba@1933: /// \sa operator==(BNode n) deba@1933: /// deba@1933: bool operator!=(BNode) const { return true; } deba@1933: deba@1933: /// Artificial ordering operator. deba@1933: deba@1933: /// To allow the use of graph descriptors as key type in std::map or deba@1933: /// similar associative container we require this. deba@1933: /// deba@1933: /// \note This operator only have to define some strict ordering of deba@1933: /// the items; this order has nothing to do with the iteration deba@1933: /// ordering of the items. deba@1933: bool operator<(BNode) const { return false; } deba@1933: deba@1933: }; deba@1911: deba@1911: /// This iterator goes through each node. deba@1911: deba@1911: /// This iterator goes through each node. deba@1911: /// Its usage is quite simple, for example you can count the number deba@1911: /// of nodes in graph \c g of type \c Graph like this: alpar@1946: ///\code deba@1911: /// int count=0; deba@1911: /// for (Graph::NodeIt n(g); n!=INVALID; ++n) ++count; alpar@1946: ///\endcode deba@1911: class NodeIt : public Node { deba@1911: public: deba@1911: /// Default constructor deba@1911: deba@1911: /// @warning The default constructor sets the iterator deba@1911: /// to an undefined value. deba@1911: NodeIt() { } deba@1911: /// Copy constructor. deba@1911: deba@1911: /// Copy constructor. deba@1911: /// deba@1911: NodeIt(const NodeIt& n) : Node(n) { } deba@1911: /// Invalid constructor \& conversion. deba@1911: deba@1911: /// Initialize the iterator to be invalid. deba@1911: /// \sa Invalid for more details. deba@1911: NodeIt(Invalid) { } deba@1911: /// Sets the iterator to the first node. deba@1911: deba@1911: /// Sets the iterator to the first node of \c g. deba@1911: /// deba@1911: NodeIt(const BpUGraph&) { } deba@1911: /// Node -> NodeIt conversion. deba@1911: deba@1911: /// Sets the iterator to the node of \c the graph pointed by deba@1911: /// the trivial iterator. deba@1911: /// This feature necessitates that each time we deba@1911: /// iterate the edge-set, the iteration order is the same. deba@1911: NodeIt(const BpUGraph&, const Node&) { } deba@1911: /// Next node. deba@1911: deba@1911: /// Assign the iterator to the next node. deba@1911: /// deba@1911: NodeIt& operator++() { return *this; } deba@1911: }; deba@1911: deba@1911: /// This iterator goes through each ANode. deba@1911: deba@1911: /// This iterator goes through each ANode. deba@1911: /// Its usage is quite simple, for example you can count the number deba@1911: /// of nodes in graph \c g of type \c Graph like this: alpar@1946: ///\code deba@1911: /// int count=0; deba@1911: /// for (Graph::ANodeIt n(g); n!=INVALID; ++n) ++count; alpar@1946: ///\endcode deba@1933: class ANodeIt : public ANode { deba@1911: public: deba@1911: /// Default constructor deba@1911: deba@1911: /// @warning The default constructor sets the iterator deba@1911: /// to an undefined value. deba@1911: ANodeIt() { } deba@1911: /// Copy constructor. deba@1911: deba@1911: /// Copy constructor. deba@1911: /// deba@1911: ANodeIt(const ANodeIt& n) : Node(n) { } deba@1911: /// Invalid constructor \& conversion. deba@1911: deba@1911: /// Initialize the iterator to be invalid. deba@1911: /// \sa Invalid for more details. deba@1911: ANodeIt(Invalid) { } deba@1911: /// Sets the iterator to the first node. deba@1911: deba@1911: /// Sets the iterator to the first node of \c g. deba@1911: /// deba@1911: ANodeIt(const BpUGraph&) { } deba@1911: /// Node -> ANodeIt conversion. deba@1911: deba@1911: /// Sets the iterator to the node of \c the graph pointed by deba@1911: /// the trivial iterator. deba@1911: /// This feature necessitates that each time we deba@1911: /// iterate the edge-set, the iteration order is the same. deba@1911: ANodeIt(const BpUGraph&, const Node&) { } deba@1911: /// Next node. deba@1911: deba@1911: /// Assign the iterator to the next node. deba@1911: /// deba@1911: ANodeIt& operator++() { return *this; } deba@1911: }; deba@1911: deba@1911: /// This iterator goes through each BNode. deba@1911: deba@1911: /// This iterator goes through each BNode. deba@1911: /// Its usage is quite simple, for example you can count the number deba@1911: /// of nodes in graph \c g of type \c Graph like this: alpar@1946: ///\code deba@1911: /// int count=0; deba@1911: /// for (Graph::BNodeIt n(g); n!=INVALID; ++n) ++count; alpar@1946: ///\endcode deba@1933: class BNodeIt : public BNode { deba@1911: public: deba@1911: /// Default constructor deba@1911: deba@1911: /// @warning The default constructor sets the iterator deba@1911: /// to an undefined value. deba@1911: BNodeIt() { } deba@1911: /// Copy constructor. deba@1911: deba@1911: /// Copy constructor. deba@1911: /// deba@1911: BNodeIt(const BNodeIt& n) : Node(n) { } deba@1911: /// Invalid constructor \& conversion. deba@1911: deba@1911: /// Initialize the iterator to be invalid. deba@1911: /// \sa Invalid for more details. deba@1911: BNodeIt(Invalid) { } deba@1911: /// Sets the iterator to the first node. deba@1911: deba@1911: /// Sets the iterator to the first node of \c g. deba@1911: /// deba@1911: BNodeIt(const BpUGraph&) { } deba@1911: /// Node -> BNodeIt conversion. deba@1911: deba@1911: /// Sets the iterator to the node of \c the graph pointed by deba@1911: /// the trivial iterator. deba@1911: /// This feature necessitates that each time we deba@1911: /// iterate the edge-set, the iteration order is the same. deba@1911: BNodeIt(const BpUGraph&, const Node&) { } deba@1911: /// Next node. deba@1911: deba@1911: /// Assign the iterator to the next node. deba@1911: /// deba@1911: BNodeIt& operator++() { return *this; } deba@1911: }; deba@1911: deba@1911: deba@1911: /// The base type of the undirected edge iterators. deba@1911: deba@1911: /// The base type of the undirected edge iterators. deba@1911: /// deba@1911: class UEdge { deba@1911: public: deba@1911: /// Default constructor deba@1911: deba@1911: /// @warning The default constructor sets the iterator deba@1911: /// to an undefined value. deba@1911: UEdge() { } deba@1911: /// Copy constructor. deba@1911: deba@1911: /// Copy constructor. deba@1911: /// deba@1911: UEdge(const UEdge&) { } deba@1911: /// Initialize the iterator to be invalid. deba@1911: deba@1911: /// Initialize the iterator to be invalid. deba@1911: /// deba@1911: UEdge(Invalid) { } deba@1911: /// Equality operator deba@1911: deba@1911: /// Two iterators are equal if and only if they point to the deba@1911: /// same object or both are invalid. deba@1911: bool operator==(UEdge) const { return true; } deba@1911: /// Inequality operator deba@1911: deba@1911: /// \sa operator==(UEdge n) deba@1911: /// deba@1911: bool operator!=(UEdge) const { return true; } deba@1911: deba@1911: /// Artificial ordering operator. deba@1911: deba@1911: /// To allow the use of graph descriptors as key type in std::map or deba@1911: /// similar associative container we require this. deba@1911: /// deba@1911: /// \note This operator only have to define some strict ordering of deba@1911: /// the items; this order has nothing to do with the iteration deba@1911: /// ordering of the items. deba@1911: /// deba@1911: /// \bug This is a technical requirement. Do we really need this? deba@1911: bool operator<(UEdge) const { return false; } deba@1911: }; deba@1911: deba@1911: /// This iterator goes through each undirected edge. deba@1911: deba@1911: /// This iterator goes through each undirected edge of a graph. deba@1911: /// Its usage is quite simple, for example you can count the number deba@1911: /// of undirected edges in a graph \c g of type \c Graph as follows: alpar@1946: ///\code deba@1911: /// int count=0; deba@1911: /// for(Graph::UEdgeIt e(g); e!=INVALID; ++e) ++count; alpar@1946: ///\endcode deba@1911: class UEdgeIt : public UEdge { deba@1911: public: deba@1911: /// Default constructor deba@1911: deba@1911: /// @warning The default constructor sets the iterator deba@1911: /// to an undefined value. deba@1911: UEdgeIt() { } deba@1911: /// Copy constructor. deba@1911: deba@1911: /// Copy constructor. deba@1911: /// deba@1911: UEdgeIt(const UEdgeIt& e) : UEdge(e) { } deba@1911: /// Initialize the iterator to be invalid. deba@1911: deba@1911: /// Initialize the iterator to be invalid. deba@1911: /// deba@1911: UEdgeIt(Invalid) { } deba@1911: /// This constructor sets the iterator to the first undirected edge. deba@1911: deba@1911: /// This constructor sets the iterator to the first undirected edge. deba@1911: UEdgeIt(const BpUGraph&) { } deba@1911: /// UEdge -> UEdgeIt conversion deba@1911: deba@1911: /// Sets the iterator to the value of the trivial iterator. deba@1911: /// This feature necessitates that each time we deba@1911: /// iterate the undirected edge-set, the iteration order is the deba@1911: /// same. deba@1911: UEdgeIt(const BpUGraph&, const UEdge&) { } deba@1911: /// Next undirected edge deba@1911: deba@1911: /// Assign the iterator to the next undirected edge. deba@1911: UEdgeIt& operator++() { return *this; } deba@1911: }; deba@1911: deba@1911: /// \brief This iterator goes trough the incident undirected deba@1911: /// edges of a node. deba@1911: /// deba@1911: /// This iterator goes trough the incident undirected edges deba@1911: /// of a certain node deba@1911: /// of a graph. deba@1911: /// Its usage is quite simple, for example you can compute the deba@1911: /// degree (i.e. count the number deba@1911: /// of incident edges of a node \c n deba@1911: /// in graph \c g of type \c Graph as follows. alpar@1946: ///\code deba@1911: /// int count=0; deba@1911: /// for(Graph::IncEdgeIt e(g, n); e!=INVALID; ++e) ++count; alpar@1946: ///\endcode deba@1911: class IncEdgeIt : public UEdge { deba@1911: public: deba@1911: /// Default constructor deba@1911: deba@1911: /// @warning The default constructor sets the iterator deba@1911: /// to an undefined value. deba@1911: IncEdgeIt() { } deba@1911: /// Copy constructor. deba@1911: deba@1911: /// Copy constructor. deba@1911: /// deba@1911: IncEdgeIt(const IncEdgeIt& e) : UEdge(e) { } deba@1911: /// Initialize the iterator to be invalid. deba@1911: deba@1911: /// Initialize the iterator to be invalid. deba@1911: /// deba@1911: IncEdgeIt(Invalid) { } deba@1911: /// This constructor sets the iterator to first incident edge. deba@1911: deba@1911: /// This constructor set the iterator to the first incident edge of deba@1911: /// the node. deba@1911: IncEdgeIt(const BpUGraph&, const Node&) { } deba@1911: /// UEdge -> IncEdgeIt conversion deba@1911: deba@1911: /// Sets the iterator to the value of the trivial iterator \c e. deba@1911: /// This feature necessitates that each time we deba@1911: /// iterate the edge-set, the iteration order is the same. deba@1911: IncEdgeIt(const BpUGraph&, const UEdge&) { } deba@1911: /// Next incident edge deba@1911: deba@1911: /// Assign the iterator to the next incident edge deba@1911: /// of the corresponding node. deba@1911: IncEdgeIt& operator++() { return *this; } deba@1911: }; deba@1911: deba@1911: /// The directed edge type. deba@1911: deba@1911: /// The directed edge type. It can be converted to the deba@1911: /// undirected edge. deba@1911: class Edge : public UEdge { deba@1911: public: deba@1911: /// Default constructor deba@1911: deba@1911: /// @warning The default constructor sets the iterator deba@1911: /// to an undefined value. deba@1911: Edge() { } deba@1911: /// Copy constructor. deba@1911: deba@1911: /// Copy constructor. deba@1911: /// deba@1911: Edge(const Edge& e) : UEdge(e) { } deba@1911: /// Initialize the iterator to be invalid. deba@1911: deba@1911: /// Initialize the iterator to be invalid. deba@1911: /// deba@1911: Edge(Invalid) { } deba@1911: /// Equality operator deba@1911: deba@1911: /// Two iterators are equal if and only if they point to the deba@1911: /// same object or both are invalid. deba@1911: bool operator==(Edge) const { return true; } deba@1911: /// Inequality operator deba@1911: deba@1911: /// \sa operator==(Edge n) deba@1911: /// deba@1911: bool operator!=(Edge) const { return true; } deba@1911: deba@1911: /// Artificial ordering operator. deba@1911: deba@1911: /// To allow the use of graph descriptors as key type in std::map or deba@1911: /// similar associative container we require this. deba@1911: /// deba@1911: /// \note This operator only have to define some strict ordering of deba@1911: /// the items; this order has nothing to do with the iteration deba@1911: /// ordering of the items. deba@1911: /// deba@1911: /// \bug This is a technical requirement. Do we really need this? deba@1911: bool operator<(Edge) const { return false; } deba@1911: deba@1911: }; deba@1911: /// This iterator goes through each directed edge. deba@1911: deba@1911: /// This iterator goes through each edge of a graph. deba@1911: /// Its usage is quite simple, for example you can count the number deba@1911: /// of edges in a graph \c g of type \c Graph as follows: alpar@1946: ///\code deba@1911: /// int count=0; deba@1911: /// for(Graph::EdgeIt e(g); e!=INVALID; ++e) ++count; alpar@1946: ///\endcode deba@1911: class EdgeIt : public Edge { deba@1911: public: deba@1911: /// Default constructor deba@1911: deba@1911: /// @warning The default constructor sets the iterator deba@1911: /// to an undefined value. deba@1911: EdgeIt() { } deba@1911: /// Copy constructor. deba@1911: deba@1911: /// Copy constructor. deba@1911: /// deba@1911: EdgeIt(const EdgeIt& e) : Edge(e) { } deba@1911: /// Initialize the iterator to be invalid. deba@1911: deba@1911: /// Initialize the iterator to be invalid. deba@1911: /// deba@1911: EdgeIt(Invalid) { } deba@1911: /// This constructor sets the iterator to the first edge. deba@1911: deba@1911: /// This constructor sets the iterator to the first edge of \c g. deba@1911: ///@param g the graph deba@1911: EdgeIt(const BpUGraph &g) { ignore_unused_variable_warning(g); } deba@1911: /// Edge -> EdgeIt conversion deba@1911: deba@1911: /// Sets the iterator to the value of the trivial iterator \c e. deba@1911: /// This feature necessitates that each time we deba@1911: /// iterate the edge-set, the iteration order is the same. deba@1911: EdgeIt(const BpUGraph&, const Edge&) { } deba@1911: ///Next edge deba@1911: deba@1911: /// Assign the iterator to the next edge. deba@1911: EdgeIt& operator++() { return *this; } deba@1911: }; deba@1911: deba@1911: /// This iterator goes trough the outgoing directed edges of a node. deba@1911: deba@1911: /// This iterator goes trough the \e outgoing edges of a certain node deba@1911: /// of a graph. deba@1911: /// Its usage is quite simple, for example you can count the number deba@1911: /// of outgoing edges of a node \c n deba@1911: /// in graph \c g of type \c Graph as follows. alpar@1946: ///\code deba@1911: /// int count=0; deba@1911: /// for (Graph::OutEdgeIt e(g, n); e!=INVALID; ++e) ++count; alpar@1946: ///\endcode deba@1911: deba@1911: class OutEdgeIt : public Edge { deba@1911: public: deba@1911: /// Default constructor deba@1911: deba@1911: /// @warning The default constructor sets the iterator deba@1911: /// to an undefined value. deba@1911: OutEdgeIt() { } deba@1911: /// Copy constructor. deba@1911: deba@1911: /// Copy constructor. deba@1911: /// deba@1911: OutEdgeIt(const OutEdgeIt& e) : Edge(e) { } deba@1911: /// Initialize the iterator to be invalid. deba@1911: deba@1911: /// Initialize the iterator to be invalid. deba@1911: /// deba@1911: OutEdgeIt(Invalid) { } deba@1911: /// This constructor sets the iterator to the first outgoing edge. deba@1911: deba@1911: /// This constructor sets the iterator to the first outgoing edge of deba@1911: /// the node. deba@1911: ///@param n the node deba@1911: ///@param g the graph deba@1911: OutEdgeIt(const BpUGraph& n, const Node& g) { deba@1911: ignore_unused_variable_warning(n); deba@1911: ignore_unused_variable_warning(g); deba@1911: } deba@1911: /// Edge -> OutEdgeIt conversion deba@1911: deba@1911: /// Sets the iterator to the value of the trivial iterator. deba@1911: /// This feature necessitates that each time we deba@1911: /// iterate the edge-set, the iteration order is the same. deba@1911: OutEdgeIt(const BpUGraph&, const Edge&) { } deba@1911: ///Next outgoing edge deba@1911: deba@1911: /// Assign the iterator to the next deba@1911: /// outgoing edge of the corresponding node. deba@1911: OutEdgeIt& operator++() { return *this; } deba@1911: }; deba@1911: deba@1911: /// This iterator goes trough the incoming directed edges of a node. deba@1911: deba@1911: /// This iterator goes trough the \e incoming edges of a certain node deba@1911: /// of a graph. deba@1911: /// Its usage is quite simple, for example you can count the number deba@1911: /// of outgoing edges of a node \c n deba@1911: /// in graph \c g of type \c Graph as follows. alpar@1946: ///\code deba@1911: /// int count=0; deba@1911: /// for(Graph::InEdgeIt e(g, n); e!=INVALID; ++e) ++count; alpar@1946: ///\endcode deba@1911: deba@1911: class InEdgeIt : public Edge { deba@1911: public: deba@1911: /// Default constructor deba@1911: deba@1911: /// @warning The default constructor sets the iterator deba@1911: /// to an undefined value. deba@1911: InEdgeIt() { } deba@1911: /// Copy constructor. deba@1911: deba@1911: /// Copy constructor. deba@1911: /// deba@1911: InEdgeIt(const InEdgeIt& e) : Edge(e) { } deba@1911: /// Initialize the iterator to be invalid. deba@1911: deba@1911: /// Initialize the iterator to be invalid. deba@1911: /// deba@1911: InEdgeIt(Invalid) { } deba@1911: /// This constructor sets the iterator to first incoming edge. deba@1911: deba@1911: /// This constructor set the iterator to the first incoming edge of deba@1911: /// the node. deba@1911: ///@param n the node deba@1911: ///@param g the graph deba@1911: InEdgeIt(const BpUGraph& g, const Node& n) { deba@1911: ignore_unused_variable_warning(n); deba@1911: ignore_unused_variable_warning(g); deba@1911: } deba@1911: /// Edge -> InEdgeIt conversion deba@1911: deba@1911: /// Sets the iterator to the value of the trivial iterator \c e. deba@1911: /// This feature necessitates that each time we deba@1911: /// iterate the edge-set, the iteration order is the same. deba@1911: InEdgeIt(const BpUGraph&, const Edge&) { } deba@1911: /// Next incoming edge deba@1911: deba@1911: /// Assign the iterator to the next inedge of the corresponding node. deba@1911: /// deba@1911: InEdgeIt& operator++() { return *this; } deba@1911: }; deba@1911: deba@1911: /// \brief Read write map of the nodes to type \c T. deba@1911: /// deba@1911: /// ReadWrite map of the nodes to type \c T. deba@1911: /// \sa Reference deba@1911: /// \warning Making maps that can handle bool type (NodeMap) deba@1911: /// needs some extra attention! deba@1911: /// \todo Wrong documentation deba@1911: template deba@1911: class NodeMap : public ReadWriteMap< Node, T > deba@1911: { deba@1911: public: deba@1911: deba@1911: ///\e deba@1911: NodeMap(const BpUGraph&) { } deba@1911: ///\e deba@1911: NodeMap(const BpUGraph&, T) { } deba@1911: deba@1911: ///Copy constructor deba@1911: NodeMap(const NodeMap& nm) : ReadWriteMap< Node, T >(nm) { } deba@1911: ///Assignment operator deba@1911: NodeMap& operator=(const NodeMap&) { return *this; } deba@1911: // \todo fix this concept deba@1911: }; deba@1911: deba@1911: /// \brief Read write map of the ANodes to type \c T. deba@1911: /// deba@1911: /// ReadWrite map of the ANodes to type \c T. deba@1911: /// \sa Reference deba@1911: /// \warning Making maps that can handle bool type (NodeMap) deba@1911: /// needs some extra attention! deba@1911: /// \todo Wrong documentation deba@1911: template deba@1911: class ANodeMap : public ReadWriteMap< Node, T > deba@1911: { deba@1911: public: deba@1911: deba@1911: ///\e deba@1911: ANodeMap(const BpUGraph&) { } deba@1911: ///\e deba@1911: ANodeMap(const BpUGraph&, T) { } deba@1911: deba@1911: ///Copy constructor deba@1911: ANodeMap(const NodeMap& nm) : ReadWriteMap< Node, T >(nm) { } deba@1911: ///Assignment operator deba@1911: ANodeMap& operator=(const NodeMap&) { return *this; } deba@1911: // \todo fix this concept deba@1911: }; deba@1911: deba@1911: /// \brief Read write map of the BNodes to type \c T. deba@1911: /// deba@1911: /// ReadWrite map of the BNodes to type \c T. deba@1911: /// \sa Reference deba@1911: /// \warning Making maps that can handle bool type (NodeMap) deba@1911: /// needs some extra attention! deba@1911: /// \todo Wrong documentation deba@1911: template deba@1911: class BNodeMap : public ReadWriteMap< Node, T > deba@1911: { deba@1911: public: deba@1911: deba@1911: ///\e deba@1911: BNodeMap(const BpUGraph&) { } deba@1911: ///\e deba@1911: BNodeMap(const BpUGraph&, T) { } deba@1911: deba@1911: ///Copy constructor deba@1911: BNodeMap(const NodeMap& nm) : ReadWriteMap< Node, T >(nm) { } deba@1911: ///Assignment operator deba@1911: BNodeMap& operator=(const NodeMap&) { return *this; } deba@1911: // \todo fix this concept deba@1911: }; deba@1911: deba@1911: /// \brief Read write map of the directed edges to type \c T. deba@1911: /// deba@1911: /// Reference map of the directed edges to type \c T. deba@1911: /// \sa Reference deba@1911: /// \warning Making maps that can handle bool type (EdgeMap) deba@1911: /// needs some extra attention! deba@1911: /// \todo Wrong documentation deba@1911: template deba@1911: class EdgeMap : public ReadWriteMap deba@1911: { deba@1911: public: deba@1911: deba@1911: ///\e deba@1911: EdgeMap(const BpUGraph&) { } deba@1911: ///\e deba@1911: EdgeMap(const BpUGraph&, T) { } deba@1911: ///Copy constructor deba@1911: EdgeMap(const EdgeMap& em) : ReadWriteMap(em) { } deba@1911: ///Assignment operator deba@1911: EdgeMap& operator=(const EdgeMap&) { return *this; } deba@1911: // \todo fix this concept deba@1911: }; deba@1911: deba@1911: /// Read write map of the undirected edges to type \c T. deba@1911: deba@1911: /// Reference map of the edges to type \c T. deba@1911: /// \sa Reference deba@1911: /// \warning Making maps that can handle bool type (UEdgeMap) deba@1911: /// needs some extra attention! deba@1911: /// \todo Wrong documentation deba@1911: template deba@1911: class UEdgeMap : public ReadWriteMap deba@1911: { deba@1911: public: deba@1911: deba@1911: ///\e deba@1911: UEdgeMap(const BpUGraph&) { } deba@1911: ///\e deba@1911: UEdgeMap(const BpUGraph&, T) { } deba@1911: ///Copy constructor deba@1911: UEdgeMap(const UEdgeMap& em) : ReadWriteMap(em) {} deba@1911: ///Assignment operator deba@1911: UEdgeMap &operator=(const UEdgeMap&) { return *this; } deba@1911: // \todo fix this concept deba@1911: }; deba@1911: deba@1911: /// \brief Direct the given undirected edge. deba@1911: /// deba@1911: /// Direct the given undirected edge. The returned edge source deba@1911: /// will be the given edge. deba@1911: Edge direct(const UEdge&, const Node&) const { deba@1911: return INVALID; deba@1911: } deba@1911: deba@1911: /// \brief Direct the given undirected edge. deba@1911: /// deba@1911: /// Direct the given undirected edge. The returned edge source deba@1911: /// will be the source of the undirected edge if the given bool deba@1911: /// is true. deba@1911: Edge direct(const UEdge&, bool) const { deba@1911: return INVALID; deba@1911: } deba@1911: deba@1911: /// \brief Returns true when the given node is an ANode. deba@1911: /// deba@1911: /// Returns true when the given node is an ANode. deba@1911: bool aNode(Node) const { return true;} deba@1911: deba@1911: /// \brief Returns true when the given node is an BNode. deba@1911: /// deba@1911: /// Returns true when the given node is an BNode. deba@1911: bool bNode(Node) const { return true;} deba@1911: deba@1911: /// \brief Returns the edge's end node which is in the ANode set. deba@1911: /// deba@1911: /// Returns the edge's end node which is in the ANode set. deba@1911: Node aNode(UEdge) const { return INVALID;} deba@1911: deba@1911: /// \brief Returns the edge's end node which is in the BNode set. deba@1911: /// deba@1911: /// Returns the edge's end node which is in the BNode set. deba@1911: Node bNode(UEdge) const { return INVALID;} deba@1911: deba@1911: /// \brief Returns true if the edge has default orientation. deba@1911: /// deba@1911: /// Returns whether the given directed edge is same orientation as deba@1911: /// the corresponding undirected edge. deba@1911: bool direction(Edge) const { return true; } deba@1911: deba@1911: /// \brief Returns the opposite directed edge. deba@1911: /// deba@1911: /// Returns the opposite directed edge. deba@1911: Edge oppositeEdge(Edge) const { return INVALID; } deba@1911: deba@1911: /// \brief Opposite node on an edge deba@1911: /// deba@1911: /// \return the opposite of the given Node on the given Edge deba@1911: Node oppositeNode(Node, UEdge) const { return INVALID; } deba@1911: deba@1911: /// \brief First node of the undirected edge. deba@1911: /// deba@1911: /// \return the first node of the given UEdge. deba@1911: /// deba@1911: /// Naturally uectected edges don't have direction and thus deba@1911: /// don't have source and target node. But we use these two methods deba@1911: /// to query the two endnodes of the edge. The direction of the edge deba@1911: /// which arises this way is called the inherent direction of the deba@1911: /// undirected edge, and is used to define the "default" direction deba@1911: /// of the directed versions of the edges. deba@1911: /// \sa direction deba@1911: Node source(UEdge) const { return INVALID; } deba@1911: deba@1911: /// \brief Second node of the undirected edge. deba@1911: Node target(UEdge) const { return INVALID; } deba@1911: deba@1911: /// \brief Source node of the directed edge. deba@1911: Node source(Edge) const { return INVALID; } deba@1911: deba@1911: /// \brief Target node of the directed edge. deba@1911: Node target(Edge) const { return INVALID; } deba@1911: deba@1911: /// \brief Base node of the iterator deba@1911: /// deba@1911: /// Returns the base node (the source in this case) of the iterator deba@1911: Node baseNode(OutEdgeIt e) const { deba@1911: return source(e); deba@1911: } deba@1911: deba@1911: /// \brief Running node of the iterator deba@1911: /// deba@1911: /// Returns the running node (the target in this case) of the deba@1911: /// iterator deba@1911: Node runningNode(OutEdgeIt e) const { deba@1911: return target(e); deba@1911: } deba@1911: deba@1911: /// \brief Base node of the iterator deba@1911: /// deba@1911: /// Returns the base node (the target in this case) of the iterator deba@1911: Node baseNode(InEdgeIt e) const { deba@1911: return target(e); deba@1911: } deba@1911: /// \brief Running node of the iterator deba@1911: /// deba@1911: /// Returns the running node (the source in this case) of the deba@1911: /// iterator deba@1911: Node runningNode(InEdgeIt e) const { deba@1911: return source(e); deba@1911: } deba@1911: deba@1911: /// \brief Base node of the iterator deba@1911: /// deba@1911: /// Returns the base node of the iterator deba@1911: Node baseNode(IncEdgeIt) const { deba@1911: return INVALID; deba@1911: } deba@1911: deba@1911: /// \brief Running node of the iterator deba@1911: /// deba@1911: /// Returns the running node of the iterator deba@1911: Node runningNode(IncEdgeIt) const { deba@1911: return INVALID; deba@1911: } deba@1911: deba@1911: template deba@1911: struct Constraints { deba@1911: void constraints() { deba@1911: } deba@1911: }; deba@1911: deba@1911: }; deba@1911: deba@1911: /// \brief An empty non-static undirected graph class. deba@1911: /// deba@1911: /// This class provides everything that \ref BpUGraph does. deba@1911: /// Additionally it enables building graphs from scratch. deba@1911: class ExtendableBpUGraph : public BpUGraph { deba@1911: public: deba@1911: deba@1911: /// \brief Add a new ANode to the graph. deba@1911: /// deba@1911: /// Add a new ANode to the graph. deba@1911: /// \return the new node. deba@1911: Node addANode(); deba@1911: deba@1911: /// \brief Add a new ANode to the graph. deba@1911: /// deba@1911: /// Add a new ANode to the graph. deba@1911: /// \return the new node. deba@1911: Node addBNode(); deba@1911: deba@1911: /// \brief Add a new undirected edge to the graph. deba@1911: /// deba@1911: /// Add a new undirected edge to the graph. One of the nodes deba@1911: /// should be ANode and the other should be BNode. deba@1911: /// \pre The nodes are not in the same nodeset. deba@1911: /// \return the new edge. deba@1911: UEdge addEdge(const Node& from, const Node& to); deba@1911: deba@1911: /// \brief Resets the graph. deba@1911: /// deba@1911: /// This function deletes all undirected edges and nodes of the graph. deba@1911: /// It also frees the memory allocated to store them. deba@1911: void clear() { } deba@1911: deba@1911: template deba@1911: struct Constraints { deba@1911: void constraints() {} deba@1911: }; deba@1911: deba@1911: }; deba@1911: deba@1911: /// \brief An empty erasable undirected graph class. deba@1911: /// deba@1911: /// This class is an extension of \ref ExtendableBpUGraph. It makes it deba@1911: /// possible to erase undirected edges or nodes. deba@1911: class ErasableBpUGraph : public ExtendableBpUGraph { deba@1911: public: deba@1911: deba@1911: /// \brief Deletes a node. deba@1911: /// deba@1911: /// Deletes a node. deba@1911: /// deba@1911: void erase(Node) { } deba@1911: /// \brief Deletes an undirected edge. deba@1911: /// deba@1911: /// Deletes an undirected edge. deba@1911: /// deba@1911: void erase(UEdge) { } deba@1911: deba@1911: template deba@1911: struct Constraints { deba@1911: void constraints() {} deba@1911: }; deba@1911: deba@1911: }; deba@1911: deba@1911: /// @} deba@1911: deba@1911: } deba@1911: deba@1911: } deba@1911: deba@1911: #endif