marci@174: // -*- c++ -*- alpar@503: #ifndef HUGO_SKELETON_GRAPH_H alpar@503: #define HUGO_SKELETON_GRAPH_H alpar@52: alpar@794: ///\ingroup skeletons alpar@242: ///\file alpar@242: ///\brief Declaration of GraphSkeleton. alpar@242: ladanyi@542: #include alpar@732: #include alpar@145: alpar@163: /// The namespace of HugoLib alpar@163: namespace hugo { alpar@732: namespace skeleton { alpar@732: alpar@794: /// \addtogroup skeletons alpar@794: /// @{ alpar@163: alpar@732: /// An empty static graph class. alpar@732: alpar@732: /// This class provides all the common features of a graph structure, alpar@732: /// however completely without implementations and real data structures alpar@732: /// behind the interface. alpar@732: /// All graph algorithms should compile with this class, but it will not alpar@732: /// run properly, of course. alpar@732: /// alpar@732: /// It can be used for checking the interface compatibility, alpar@732: /// or it can serve as a skeleton of a new graph structure. alpar@732: /// alpar@732: /// Also, you will find here the full documentation of a certain graph alpar@732: /// feature, the documentation of a real graph imlementation alpar@732: /// like @ref ListGraph or alpar@732: /// @ref SmartGraph will just refer to this structure. alpar@732: class StaticGraphSkeleton alpar@732: { alpar@732: public: alpar@732: /// Defalult constructor. alpar@801: alpar@801: /// Defalult constructor. alpar@801: /// alpar@774: StaticGraphSkeleton() { } alpar@732: ///Copy consructor. alpar@163: alpar@801: // ///\todo It is not clear, what we expect from a copy constructor. alpar@801: // ///E.g. How to assign the nodes/edges to each other? What about maps? alpar@801: // StaticGraphSkeleton(const StaticGraphSkeleton& g) { } alpar@732: alpar@774: /// The base type of node iterators, alpar@774: /// or in other words, the trivial node iterator. alpar@732: alpar@774: /// This is the base type of each node iterator, alpar@774: /// thus each kind of node iterator converts to this. alpar@801: /// More precisely each kind of node iterator should be inherited alpar@774: /// from the trivial node iterator. alpar@732: class Node { alpar@732: public: alpar@801: /// Default constructor alpar@801: alpar@732: /// @warning The default constructor sets the iterator alpar@732: /// to an undefined value. alpar@774: Node() { } alpar@774: /// Copy constructor. alpar@801: alpar@801: /// Copy constructor. alpar@801: /// alpar@774: Node(const Node&) { } alpar@801: alpar@732: /// Invalid constructor \& conversion. alpar@732: alpar@732: /// This constructor initializes the iterator to be invalid. alpar@732: /// \sa Invalid for more details. alpar@774: Node(Invalid) { } alpar@801: /// Equality operator alpar@801: alpar@732: /// Two iterators are equal if and only if they point to the alpar@732: /// same object or both are invalid. alpar@732: bool operator==(Node) const { return true; } alpar@732: alpar@801: /// Inequality operator alpar@801: alpar@732: /// \sa \ref operator==(Node n) alpar@732: /// alpar@732: bool operator!=(Node) const { return true; } alpar@732: alpar@801: ///Comparison operator. alpar@801: alpar@801: ///This is a strict ordering between the nodes. alpar@801: /// alpar@801: ///This ordering can be different from the order in which NodeIt alpar@801: ///goes through the nodes. alpar@801: ///\todo Possibly we don't need it. alpar@732: bool operator<(Node) const { return true; } alpar@732: }; alpar@732: alpar@732: /// This iterator goes through each node. alpar@732: alpar@732: /// This iterator goes through each node. alpar@732: /// Its usage is quite simple, for example you can count the number alpar@774: /// of nodes in graph \c g of type \c Graph like this: alpar@732: /// \code alpar@774: /// int count=0; alpar@801: /// for (Graph::NodeIt n(g); n!=INVALID; ++n) ++count; alpar@732: /// \endcode alpar@732: class NodeIt : public Node { alpar@732: public: alpar@801: /// Default constructor alpar@801: alpar@732: /// @warning The default constructor sets the iterator alpar@732: /// to an undefined value. alpar@774: NodeIt() { } alpar@774: /// Copy constructor. alpar@801: alpar@801: /// Copy constructor. alpar@801: /// alpar@774: NodeIt(const NodeIt&) { } alpar@732: /// Invalid constructor \& conversion. alpar@732: alpar@774: /// Initialize the iterator to be invalid. alpar@732: /// \sa Invalid for more details. alpar@774: NodeIt(Invalid) { } alpar@801: /// Sets the iterator to the first node. alpar@801: alpar@774: /// Sets the iterator to the first node of \c g. alpar@801: /// alpar@774: NodeIt(const StaticGraphSkeleton& g) { } alpar@801: /// Node -> NodeIt conversion. alpar@801: alpar@774: /// Sets the iterator to the node of \c g pointed by the trivial alpar@801: /// iterator n. alpar@801: /// This feature necessitates that each time we alpar@801: /// iterate the edge-set, the iteration order is the same. alpar@774: NodeIt(const StaticGraphSkeleton& g, const Node& n) { } alpar@801: /// Next node. alpar@801: alpar@774: /// Assign the iterator to the next node. alpar@801: /// alpar@774: NodeIt& operator++() { return *this; } alpar@732: }; alpar@732: alpar@732: alpar@732: /// The base type of the edge iterators. alpar@801: alpar@801: /// The base type of the edge iterators. alpar@801: /// alpar@732: class Edge { alpar@732: public: alpar@801: /// Default constructor alpar@801: alpar@732: /// @warning The default constructor sets the iterator alpar@732: /// to an undefined value. alpar@774: Edge() { } alpar@774: /// Copy constructor. alpar@801: alpar@801: /// Copy constructor. alpar@801: /// alpar@774: Edge(const Edge&) { } alpar@774: /// Initialize the iterator to be invalid. alpar@801: alpar@801: /// Initialize the iterator to be invalid. alpar@801: /// alpar@774: Edge(Invalid) { } alpar@801: /// Equality operator alpar@801: alpar@732: /// Two iterators are equal if and only if they point to the alpar@732: /// same object or both are invalid. alpar@732: bool operator==(Edge) const { return true; } alpar@801: /// Inequality operator alpar@801: alpar@801: /// \sa \ref operator==(Node n) alpar@801: /// alpar@732: bool operator!=(Edge) const { return true; } alpar@801: ///Comparison operator. alpar@801: alpar@801: ///This is a strict ordering between the nodes. alpar@801: /// alpar@801: ///This ordering can be different from the order in which NodeIt alpar@801: ///goes through the nodes. alpar@801: ///\todo Possibly we don't need it. alpar@801: bool operator<(Edge) const { return true; } alpar@732: }; alpar@732: alpar@732: /// This iterator goes trough the outgoing edges of a node. alpar@732: alpar@732: /// This iterator goes trough the \e outgoing edges of a certain node alpar@732: /// of a graph. alpar@732: /// Its usage is quite simple, for example you can count the number alpar@732: /// of outgoing edges of a node \c n alpar@774: /// in graph \c g of type \c Graph as follows. alpar@732: /// \code alpar@774: /// int count=0; alpar@801: /// for (Graph::OutEdgeIt e(g, n); e!=INVALID; ++e) ++count; alpar@732: /// \endcode alpar@732: alpar@732: class OutEdgeIt : public Edge { alpar@732: public: alpar@801: /// Default constructor alpar@801: alpar@732: /// @warning The default constructor sets the iterator alpar@732: /// to an undefined value. alpar@774: OutEdgeIt() { } alpar@774: /// Copy constructor. alpar@801: alpar@801: /// Copy constructor. alpar@801: /// alpar@774: OutEdgeIt(const OutEdgeIt&) { } alpar@774: /// Initialize the iterator to be invalid. alpar@801: alpar@801: /// Initialize the iterator to be invalid. alpar@801: /// alpar@774: OutEdgeIt(Invalid) { } alpar@732: /// This constructor sets the iterator to first outgoing edge. alpar@732: alpar@732: /// This constructor set the iterator to the first outgoing edge of alpar@732: /// node alpar@732: ///@param n the node alpar@774: ///@param g the graph alpar@774: OutEdgeIt(const StaticGraphSkeleton& g, const Node& n) { } alpar@801: /// Edge -> OutEdgeIt conversion alpar@801: alpar@774: /// Sets the iterator to the value of the trivial iterator \c e. alpar@774: /// This feature necessitates that each time we alpar@774: /// iterate the edge-set, the iteration order is the same. alpar@774: OutEdgeIt(const StaticGraphSkeleton& g, const Edge& e) { } alpar@801: ///Next outgoing edge alpar@801: alpar@801: /// Assign the iterator to the next alpar@801: /// outgoing edge of the corresponding node. alpar@774: OutEdgeIt& operator++() { return *this; } alpar@732: }; alpar@732: alpar@732: /// This iterator goes trough the incoming edges of a node. alpar@732: alpar@732: /// This iterator goes trough the \e incoming edges of a certain node alpar@732: /// of a graph. alpar@732: /// Its usage is quite simple, for example you can count the number alpar@732: /// of outgoing edges of a node \c n alpar@774: /// in graph \c g of type \c Graph as follows. alpar@732: /// \code alpar@774: /// int count=0; alpar@801: /// for(Graph::InEdgeIt e(g, n); e!=INVALID; ++e) ++count; alpar@732: /// \endcode alpar@732: alpar@732: class InEdgeIt : public Edge { alpar@732: public: alpar@801: /// Default constructor alpar@801: alpar@732: /// @warning The default constructor sets the iterator alpar@732: /// to an undefined value. alpar@774: InEdgeIt() { } alpar@774: /// Copy constructor. alpar@801: alpar@801: /// Copy constructor. alpar@801: /// alpar@774: InEdgeIt(const InEdgeIt&) { } alpar@774: /// Initialize the iterator to be invalid. alpar@801: alpar@801: /// Initialize the iterator to be invalid. alpar@801: /// alpar@774: InEdgeIt(Invalid) { } alpar@801: /// This constructor sets the iterator to first incoming edge. alpar@801: alpar@801: /// This constructor set the iterator to the first incoming edge of alpar@801: /// node alpar@801: ///@param n the node alpar@801: ///@param g the graph alpar@801: InEdgeIt(const StaticGraphSkeleton& g, const Node& n) { } alpar@801: /// Edge -> InEdgeIt conversion alpar@801: alpar@801: /// Sets the iterator to the value of the trivial iterator \c e. alpar@801: /// This feature necessitates that each time we alpar@801: /// iterate the edge-set, the iteration order is the same. alpar@801: InEdgeIt(const StaticGraphSkeleton& g, const Edge& n) { } alpar@801: /// Next incoming edge alpar@801: alpar@774: /// Assign the iterator to the next inedge of the corresponding node. alpar@801: /// alpar@774: InEdgeIt& operator++() { return *this; } alpar@732: }; alpar@732: /// This iterator goes through each edge. alpar@732: alpar@732: /// This iterator goes through each edge of a graph. alpar@732: /// Its usage is quite simple, for example you can count the number alpar@774: /// of edges in a graph \c g of type \c Graph as follows: alpar@732: /// \code alpar@774: /// int count=0; alpar@801: /// for(Graph::EdgeIt e(g); e!=INVALID; ++e) ++count; alpar@732: /// \endcode alpar@732: class EdgeIt : public Edge { alpar@732: public: alpar@801: /// Default constructor alpar@801: alpar@732: /// @warning The default constructor sets the iterator alpar@732: /// to an undefined value. alpar@774: EdgeIt() { } alpar@774: /// Copy constructor. alpar@801: alpar@801: /// Copy constructor. alpar@801: /// alpar@774: EdgeIt(const EdgeIt&) { } alpar@774: /// Initialize the iterator to be invalid. alpar@801: alpar@801: /// Initialize the iterator to be invalid. alpar@801: /// alpar@774: EdgeIt(Invalid) { } alpar@801: /// This constructor sets the iterator to first edge. alpar@801: alpar@801: /// This constructor set the iterator to the first edge of alpar@801: /// node alpar@801: ///@param g the graph alpar@801: EdgeIt(const StaticGraphSkeleton& g) { } alpar@801: /// Edge -> EdgeIt conversion alpar@801: alpar@801: /// Sets the iterator to the value of the trivial iterator \c e. alpar@801: /// This feature necessitates that each time we alpar@801: /// iterate the edge-set, the iteration order is the same. alpar@774: EdgeIt(const StaticGraphSkeleton&, const Edge&) { } alpar@801: ///Next edge alpar@801: alpar@801: /// Assign the iterator to the next alpar@801: /// edge of the corresponding node. alpar@774: EdgeIt& operator++() { return *this; } alpar@732: }; alpar@732: alpar@732: /// First node of the graph. alpar@732: alpar@732: /// \retval i the first node. alpar@732: /// \return the first node. alpar@732: /// alpar@774: NodeIt& first(NodeIt& i) const { return i; } alpar@732: alpar@732: /// The first incoming edge. alpar@801: alpar@801: /// The first incoming edge. alpar@801: /// alpar@774: InEdgeIt& first(InEdgeIt &i, Node) const { return i; } alpar@732: /// The first outgoing edge. alpar@801: alpar@801: /// The first outgoing edge. alpar@801: /// alpar@774: OutEdgeIt& first(OutEdgeIt& i, Node) const { return i; } alpar@732: /// The first edge of the Graph. alpar@801: alpar@801: /// The first edge of the Graph. alpar@801: /// alpar@774: EdgeIt& first(EdgeIt& i) const { return i; } alpar@732: alpar@801: ///Gives back the head node of an edge. alpar@732: alpar@732: ///Gives back the head node of an edge. alpar@801: /// alpar@732: Node head(Edge) const { return INVALID; } alpar@732: ///Gives back the tail node of an edge. alpar@801: alpar@801: ///Gives back the tail node of an edge. alpar@801: /// alpar@732: Node tail(Edge) const { return INVALID; } alpar@163: alpar@732: ///Gives back the \e id of a node. alpar@182: alpar@732: ///\warning Not all graph structures provide this feature. alpar@732: /// alpar@801: ///\todo Should each graph provide \c id? alpar@774: int id(const Node&) const { return 0; } alpar@732: ///Gives back the \e id of an edge. alpar@182: alpar@732: ///\warning Not all graph structures provide this feature. alpar@182: /// alpar@801: ///\todo Should each graph provide \c id? alpar@774: int id(const Edge&) const { return 0; } alpar@182: alpar@801: /// . alpar@801: alpar@801: ///\todo What is this? alpar@801: /// alpar@774: int nodeNum() const { return 0; } alpar@801: /// . alpar@801: ///\todo What is this? alpar@801: /// alpar@774: int edgeNum() const { return 0; } alpar@732: alpar@732: alpar@732: ///Reference map of the nodes to type \c T. alpar@732: alpar@732: ///Reference map of the nodes to type \c T. alpar@732: /// \sa ReferenceSkeleton alpar@732: /// \warning Making maps that can handle bool type (NodeMap) alpar@801: /// needs some extra attention! alpar@801: template class NodeMap: public ReferenceMap< Node, T > alpar@732: { alpar@732: public: alpar@732: alpar@801: /// . alpar@774: NodeMap(const StaticGraphSkeleton&) { } alpar@801: /// . alpar@774: NodeMap(const StaticGraphSkeleton&, T) { } alpar@732: alpar@732: ///Copy constructor alpar@774: template NodeMap(const NodeMap&) { } alpar@732: ///Assignment operator alpar@774: template NodeMap& operator=(const NodeMap&) alpar@774: { return *this; } alpar@732: }; alpar@732: alpar@732: ///Reference map of the edges to type \c T. alpar@732: alpar@732: ///Reference map of the edges to type \c T. alpar@732: /// \sa ReferenceSkeleton alpar@732: /// \warning Making maps that can handle bool type (EdgeMap) alpar@801: /// needs some extra attention! alpar@732: template class EdgeMap alpar@732: : public ReferenceMap alpar@732: { alpar@732: public: alpar@732: alpar@801: /// . alpar@774: EdgeMap(const StaticGraphSkeleton&) { } alpar@801: /// . alpar@774: EdgeMap(const StaticGraphSkeleton&, T) { } alpar@147: alpar@732: ///Copy constructor alpar@774: template EdgeMap(const EdgeMap&) { } alpar@732: ///Assignment operator alpar@774: template EdgeMap &operator=(const EdgeMap&) alpar@774: { return *this; } alpar@732: }; alpar@163: }; alpar@163: alpar@186: alpar@732: alpar@801: /// An empty non-static graph class. alpar@186: alpar@732: /// This class provides everything that \c StaticGraphSkeleton alpar@732: /// with additional functionality which enables to build a alpar@732: /// graph from scratch. alpar@873: class ExtendableGraphSkeleton : public StaticGraphSkeleton alpar@732: { alpar@163: public: alpar@732: /// Defalult constructor. alpar@801: alpar@801: /// Defalult constructor. alpar@801: /// alpar@873: ExtendableGraphSkeleton() { } alpar@732: ///Add a new node to the graph. alpar@732: alpar@732: /// \return the new node. alpar@732: /// alpar@774: Node addNode() { return INVALID; } alpar@732: ///Add a new edge to the graph. alpar@732: alpar@732: ///Add a new edge to the graph with tail node \c tail alpar@732: ///and head node \c head. alpar@732: ///\return the new edge. alpar@774: Edge addEdge(Node, Node) { return INVALID; } alpar@732: alpar@732: /// Resets the graph. alpar@732: alpar@732: /// This function deletes all edges and nodes of the graph. alpar@732: /// It also frees the memory allocated to store them. alpar@826: /// \todo It might belong to \c ErasableGraphSkeleton. alpar@774: void clear() { } alpar@163: }; alpar@163: alpar@826: /// An empty erasable graph class. alpar@52: alpar@732: /// This class is an extension of \c GraphSkeleton. It also makes it alpar@732: /// possible to erase edges or nodes. alpar@873: class ErasableGraphSkeleton : public ExtendableGraphSkeleton alpar@163: { alpar@163: public: alpar@801: /// Defalult constructor. alpar@801: alpar@801: /// Defalult constructor. alpar@801: /// alpar@826: ErasableGraphSkeleton() { } alpar@732: /// Deletes a node. alpar@801: alpar@801: /// Deletes node \c n node. alpar@801: /// alpar@774: void erase(Node n) { } alpar@732: /// Deletes an edge. alpar@801: alpar@801: /// Deletes edge \c e edge. alpar@801: /// alpar@774: void erase(Edge e) { } alpar@163: }; alpar@163: alpar@732: // @} alpar@801: } //namespace skeleton marci@174: } //namespace hugo alpar@52: alpar@145: alpar@145: alpar@503: #endif // HUGO_SKELETON_GRAPH_H