klao@959: /* -*- C++ -*- ladanyi@1435: * lemon/concept/graph.h - Part of LEMON, a generic C++ optimization library klao@959: * alpar@1164: * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport alpar@1359: * (Egervary Research Group on Combinatorial Optimization, EGRES). klao@959: * klao@959: * Permission to use, modify and distribute this software is granted klao@959: * provided that this copyright notice appears in all copies. For klao@959: * precise terms see the accompanying LICENSE file. klao@959: * klao@959: * This software is provided "AS IS" with no warranty of any kind, klao@959: * express or implied, and with no claim as to its suitability for any klao@959: * purpose. klao@959: * klao@959: */ klao@959: klao@959: #ifndef LEMON_CONCEPT_SYM_GRAPH_H klao@959: #define LEMON_CONCEPT_SYM_GRAPH_H klao@959: klao@959: ///\ingroup concept klao@959: ///\file klao@959: ///\brief Declaration of SymGraph. klao@959: klao@959: #include klao@959: #include klao@959: #include klao@959: klao@959: namespace lemon { klao@959: namespace concept { klao@959: klao@959: /// \addtogroup concept klao@959: /// @{ klao@959: klao@959: /// An empty static graph class. klao@959: klao@959: /// This class provides all the common features of a symmetric klao@959: /// graph structure, however completely without implementations and klao@959: /// real data structures behind the interface. klao@959: /// All graph algorithms should compile with this class, but it will not klao@959: /// run properly, of course. klao@959: /// klao@959: /// It can be used for checking the interface compatibility, klao@959: /// or it can serve as a skeleton of a new symmetric graph structure. klao@959: /// klao@959: /// Also, you will find here the full documentation of a certain graph klao@959: /// feature, the documentation of a real symmetric graph imlementation klao@959: /// like @ref SymListGraph or klao@959: /// @ref lemon::SymSmartGraph will just refer to this structure. klao@959: class StaticSymGraph klao@959: { klao@959: public: klao@959: /// Defalult constructor. klao@959: klao@959: /// Defalult constructor. klao@959: /// klao@959: StaticSymGraph() { } klao@959: ///Copy consructor. klao@959: klao@959: // ///\todo It is not clear, what we expect from a copy constructor. klao@959: // ///E.g. How to assign the nodes/edges to each other? What about maps? klao@959: // StaticGraph(const StaticGraph& g) { } klao@959: klao@959: /// The base type of node iterators, klao@959: /// or in other words, the trivial node iterator. klao@959: klao@959: /// This is the base type of each node iterator, klao@959: /// thus each kind of node iterator converts to this. klao@959: /// More precisely each kind of node iterator should be inherited klao@959: /// from the trivial node iterator. klao@959: class Node { klao@959: public: klao@959: /// Default constructor klao@959: klao@959: /// @warning The default constructor sets the iterator klao@959: /// to an undefined value. klao@959: Node() { } klao@959: /// Copy constructor. klao@959: klao@959: /// Copy constructor. klao@959: /// klao@959: Node(const Node&) { } klao@959: klao@959: /// Invalid constructor \& conversion. klao@959: klao@959: /// This constructor initializes the iterator to be invalid. klao@959: /// \sa Invalid for more details. klao@959: Node(Invalid) { } klao@959: /// Equality operator klao@959: klao@959: /// Two iterators are equal if and only if they point to the klao@959: /// same object or both are invalid. klao@959: bool operator==(Node) const { return true; } klao@959: klao@959: /// Inequality operator klao@959: klao@959: /// \sa operator==(Node n) klao@959: /// klao@959: bool operator!=(Node) const { return true; } klao@959: klao@959: ///Comparison operator. klao@959: klao@959: ///This is a strict ordering between the nodes. klao@959: /// klao@959: ///This ordering can be different from the order in which NodeIt klao@959: ///goes through the nodes. klao@959: ///\todo Possibly we don't need it. klao@959: bool operator<(Node) const { return true; } klao@959: }; klao@959: klao@959: /// This iterator goes through each node. klao@959: klao@959: /// This iterator goes through each node. klao@959: /// Its usage is quite simple, for example you can count the number klao@959: /// of nodes in graph \c g of type \c Graph like this: klao@959: /// \code klao@959: /// int count=0; klao@959: /// for (Graph::NodeIt n(g); n!=INVALID; ++n) ++count; klao@959: /// \endcode klao@959: class NodeIt : public Node { klao@959: public: klao@959: /// Default constructor klao@959: klao@959: /// @warning The default constructor sets the iterator klao@959: /// to an undefined value. klao@959: NodeIt() { } klao@959: /// Copy constructor. klao@959: klao@959: /// Copy constructor. klao@959: /// klao@959: NodeIt(const NodeIt&) { } klao@959: /// Invalid constructor \& conversion. klao@959: klao@959: /// Initialize the iterator to be invalid. klao@959: /// \sa Invalid for more details. klao@959: NodeIt(Invalid) { } klao@959: /// Sets the iterator to the first node. klao@959: klao@959: /// Sets the iterator to the first node of \c g. klao@959: /// klao@959: NodeIt(const StaticSymGraph& g) { } klao@959: /// Node -> NodeIt conversion. klao@959: klao@959: /// Sets the iterator to the node of \c g pointed by the trivial klao@959: /// iterator n. klao@959: /// This feature necessitates that each time we klao@959: /// iterate the edge-set, the iteration order is the same. klao@959: NodeIt(const StaticSymGraph& g, const Node& n) { } klao@959: /// Next node. klao@959: klao@959: /// Assign the iterator to the next node. klao@959: /// klao@959: NodeIt& operator++() { return *this; } klao@959: }; klao@959: klao@959: klao@959: /// The base type of the symmetric edge iterators. klao@959: klao@959: /// The base type of the symmetric edge iterators. klao@959: /// klao@959: class SymEdge { klao@959: public: klao@959: /// Default constructor klao@959: klao@959: /// @warning The default constructor sets the iterator klao@959: /// to an undefined value. klao@959: SymEdge() { } klao@959: /// Copy constructor. klao@959: klao@959: /// Copy constructor. klao@959: /// klao@959: SymEdge(const SymEdge&) { } klao@959: /// Initialize the iterator to be invalid. klao@959: klao@959: /// Initialize the iterator to be invalid. klao@959: /// klao@959: SymEdge(Invalid) { } klao@959: /// Equality operator klao@959: klao@959: /// Two iterators are equal if and only if they point to the klao@959: /// same object or both are invalid. klao@959: bool operator==(SymEdge) const { return true; } klao@959: /// Inequality operator klao@959: klao@959: /// \sa operator==(Node n) klao@959: /// klao@959: bool operator!=(SymEdge) const { return true; } klao@959: ///Comparison operator. klao@959: klao@959: ///This is a strict ordering between the nodes. klao@959: /// klao@959: ///This ordering can be different from the order in which NodeIt klao@959: ///goes through the nodes. klao@959: ///\todo Possibly we don't need it. klao@959: bool operator<(SymEdge) const { return true; } klao@959: }; klao@959: klao@959: klao@959: /// The base type of the edge iterators. klao@959: klao@959: /// The base type of the edge iterators. klao@959: /// klao@959: class Edge : public SymEdge { klao@959: public: klao@959: /// Default constructor klao@959: klao@959: /// @warning The default constructor sets the iterator klao@959: /// to an undefined value. klao@959: Edge() { } klao@959: /// Copy constructor. klao@959: klao@959: /// Copy constructor. klao@959: /// klao@959: Edge(const Edge&) { } klao@959: /// Initialize the iterator to be invalid. klao@959: klao@959: /// Initialize the iterator to be invalid. klao@959: /// klao@959: Edge(Invalid) { } klao@959: /// Equality operator klao@959: klao@959: /// Two iterators are equal if and only if they point to the klao@959: /// same object or both are invalid. klao@959: bool operator==(Edge) const { return true; } klao@959: /// Inequality operator klao@959: klao@959: /// \sa operator==(Node n) klao@959: /// klao@959: bool operator!=(Edge) const { return true; } klao@959: ///Comparison operator. klao@959: klao@959: ///This is a strict ordering between the nodes. klao@959: /// klao@959: ///This ordering can be different from the order in which NodeIt klao@959: ///goes through the nodes. klao@959: ///\todo Possibly we don't need it. klao@959: bool operator<(Edge) const { return true; } klao@959: }; klao@959: klao@959: /// This iterator goes trough the outgoing edges of a node. klao@959: klao@959: /// This iterator goes trough the \e outgoing edges of a certain node klao@959: /// of a graph. klao@959: /// Its usage is quite simple, for example you can count the number klao@959: /// of outgoing edges of a node \c n klao@959: /// in graph \c g of type \c Graph as follows. klao@959: /// \code klao@959: /// int count=0; klao@959: /// for (Graph::OutEdgeIt e(g, n); e!=INVALID; ++e) ++count; klao@959: /// \endcode klao@959: klao@959: class OutEdgeIt : public Edge { klao@959: public: klao@959: /// Default constructor klao@959: klao@959: /// @warning The default constructor sets the iterator klao@959: /// to an undefined value. klao@959: OutEdgeIt() { } klao@959: /// Copy constructor. klao@959: klao@959: /// Copy constructor. klao@959: /// klao@959: OutEdgeIt(const OutEdgeIt&) { } klao@959: /// Initialize the iterator to be invalid. klao@959: klao@959: /// Initialize the iterator to be invalid. klao@959: /// klao@959: OutEdgeIt(Invalid) { } klao@959: /// This constructor sets the iterator to first outgoing edge. klao@959: klao@959: /// This constructor set the iterator to the first outgoing edge of klao@959: /// node klao@959: ///@param n the node klao@959: ///@param g the graph klao@959: OutEdgeIt(const StaticSymGraph& g, const Node& n) { } klao@959: /// Edge -> OutEdgeIt conversion klao@959: klao@959: /// Sets the iterator to the value of the trivial iterator \c e. klao@959: /// This feature necessitates that each time we klao@959: /// iterate the edge-set, the iteration order is the same. klao@959: OutEdgeIt(const StaticSymGraph& g, const Edge& e) { } klao@959: ///Next outgoing edge klao@959: klao@959: /// Assign the iterator to the next klao@959: /// outgoing edge of the corresponding node. klao@959: OutEdgeIt& operator++() { return *this; } klao@959: }; klao@959: klao@959: /// This iterator goes trough the incoming edges of a node. klao@959: klao@959: /// This iterator goes trough the \e incoming edges of a certain node klao@959: /// of a graph. klao@959: /// Its usage is quite simple, for example you can count the number klao@959: /// of outgoing edges of a node \c n klao@959: /// in graph \c g of type \c Graph as follows. klao@959: /// \code klao@959: /// int count=0; klao@959: /// for(Graph::InEdgeIt e(g, n); e!=INVALID; ++e) ++count; klao@959: /// \endcode klao@959: klao@959: class InEdgeIt : public Edge { klao@959: public: klao@959: /// Default constructor klao@959: klao@959: /// @warning The default constructor sets the iterator klao@959: /// to an undefined value. klao@959: InEdgeIt() { } klao@959: /// Copy constructor. klao@959: klao@959: /// Copy constructor. klao@959: /// klao@959: InEdgeIt(const InEdgeIt&) { } klao@959: /// Initialize the iterator to be invalid. klao@959: klao@959: /// Initialize the iterator to be invalid. klao@959: /// klao@959: InEdgeIt(Invalid) { } klao@959: /// This constructor sets the iterator to first incoming edge. klao@959: klao@959: /// This constructor set the iterator to the first incoming edge of klao@959: /// node klao@959: ///@param n the node klao@959: ///@param g the graph klao@959: InEdgeIt(const StaticSymGraph& g, const Node& n) { } klao@959: /// Edge -> InEdgeIt conversion klao@959: klao@959: /// Sets the iterator to the value of the trivial iterator \c e. klao@959: /// This feature necessitates that each time we klao@959: /// iterate the edge-set, the iteration order is the same. klao@959: InEdgeIt(const StaticSymGraph& g, const Edge& n) { } klao@959: /// Next incoming edge klao@959: klao@959: /// Assign the iterator to the next inedge of the corresponding node. klao@959: /// klao@959: InEdgeIt& operator++() { return *this; } klao@959: }; klao@959: /// This iterator goes through each symmetric edge. klao@959: klao@959: /// This iterator goes through each symmetric edge of a graph. klao@959: /// Its usage is quite simple, for example you can count the number klao@959: /// of symmetric edges in a graph \c g of type \c Graph as follows: klao@959: /// \code klao@959: /// int count=0; klao@959: /// for(Graph::SymEdgeIt e(g); e!=INVALID; ++e) ++count; klao@959: /// \endcode klao@959: class SymEdgeIt : public SymEdge { klao@959: public: klao@959: /// Default constructor klao@959: klao@959: /// @warning The default constructor sets the iterator klao@959: /// to an undefined value. klao@959: SymEdgeIt() { } klao@959: /// Copy constructor. klao@959: klao@959: /// Copy constructor. klao@959: /// klao@959: SymEdgeIt(const SymEdgeIt&) { } klao@959: /// Initialize the iterator to be invalid. klao@959: klao@959: /// Initialize the iterator to be invalid. klao@959: /// klao@959: SymEdgeIt(Invalid) { } klao@959: /// This constructor sets the iterator to first edge. klao@959: klao@959: /// This constructor set the iterator to the first edge of klao@959: /// node klao@959: ///@param g the graph klao@959: SymEdgeIt(const StaticSymGraph& g) { } klao@959: /// Edge -> EdgeIt conversion klao@959: klao@959: /// Sets the iterator to the value of the trivial iterator \c e. klao@959: /// This feature necessitates that each time we klao@959: /// iterate the edge-set, the iteration order is the same. klao@959: SymEdgeIt(const StaticSymGraph&, const SymEdge&) { } klao@959: ///Next edge klao@959: klao@959: /// Assign the iterator to the next klao@959: /// edge of the corresponding node. klao@959: SymEdgeIt& operator++() { return *this; } klao@959: }; klao@959: /// This iterator goes through each edge. klao@959: klao@959: /// This iterator goes through each edge of a graph. klao@959: /// Its usage is quite simple, for example you can count the number klao@959: /// of edges in a graph \c g of type \c Graph as follows: klao@959: /// \code klao@959: /// int count=0; klao@959: /// for(Graph::EdgeIt e(g); e!=INVALID; ++e) ++count; klao@959: /// \endcode klao@959: class EdgeIt : public Edge { klao@959: public: klao@959: /// Default constructor klao@959: klao@959: /// @warning The default constructor sets the iterator klao@959: /// to an undefined value. klao@959: EdgeIt() { } klao@959: /// Copy constructor. klao@959: klao@959: /// Copy constructor. klao@959: /// klao@959: EdgeIt(const EdgeIt&) { } klao@959: /// Initialize the iterator to be invalid. klao@959: klao@959: /// Initialize the iterator to be invalid. klao@959: /// klao@959: EdgeIt(Invalid) { } klao@959: /// This constructor sets the iterator to first edge. klao@959: klao@959: /// This constructor set the iterator to the first edge of klao@959: /// node klao@959: ///@param g the graph klao@959: EdgeIt(const StaticSymGraph& g) { } klao@959: /// Edge -> EdgeIt conversion klao@959: klao@959: /// Sets the iterator to the value of the trivial iterator \c e. klao@959: /// This feature necessitates that each time we klao@959: /// iterate the edge-set, the iteration order is the same. klao@959: EdgeIt(const StaticSymGraph&, const Edge&) { } klao@959: ///Next edge klao@959: klao@959: /// Assign the iterator to the next klao@959: /// edge of the corresponding node. klao@959: EdgeIt& operator++() { return *this; } klao@959: }; klao@959: klao@959: /// First node of the graph. klao@959: klao@959: /// \retval i the first node. klao@959: /// \return the first node. klao@959: /// klao@959: NodeIt& first(NodeIt& i) const { return i; } klao@959: klao@959: /// The first incoming edge. klao@959: klao@959: /// The first incoming edge. klao@959: /// klao@959: InEdgeIt& first(InEdgeIt &i, Node) const { return i; } klao@959: /// The first outgoing edge. klao@959: klao@959: /// The first outgoing edge. klao@959: /// klao@959: OutEdgeIt& first(OutEdgeIt& i, Node) const { return i; } klao@959: /// The first edge of the Graph. klao@959: klao@959: /// The first edge of the Graph. klao@959: /// klao@959: EdgeIt& first(EdgeIt& i) const { return i; } klao@959: /// The first symmetric edge of the Graph. klao@959: klao@959: /// The first symmetric edge of the Graph. klao@959: /// klao@959: SymEdgeIt& first(SymEdgeIt& i) const { return i; } klao@959: alpar@986: ///Gives back the target node of an edge. klao@959: alpar@986: ///Gives back the target node of an edge. klao@959: /// alpar@986: Node target(Edge) const { return INVALID; } alpar@986: ///Gives back the source node of an edge. klao@959: alpar@986: ///Gives back the source node of an edge. klao@959: /// alpar@986: Node source(Edge) const { return INVALID; } klao@959: klao@959: ///Gives back the first node of an symmetric edge. klao@959: klao@959: ///Gives back the first node of an symmetric edge. klao@959: /// alpar@986: Node target(SymEdge) const { return INVALID; } klao@959: ///Gives back the second node of an symmetric edge. klao@959: klao@959: ///Gives back the second node of an symmetric edge. klao@959: /// alpar@986: Node source(SymEdge) const { return INVALID; } klao@959: ///Gives back the \e id of a node. klao@959: klao@959: ///\warning Not all graph structures provide this feature. klao@959: /// klao@959: ///\todo Should each graph provide \c id? klao@959: int id(const Node&) const { return 0; } klao@959: ///Gives back the \e id of an edge. klao@959: klao@959: ///\warning Not all graph structures provide this feature. klao@959: /// klao@959: ///\todo Should each graph provide \c id? klao@959: int id(const Edge&) const { return 0; } klao@959: klao@959: ///\warning Not all graph structures provide this feature. klao@959: /// klao@959: ///\todo Should each graph provide \c id? klao@959: int id(const SymEdge&) const { return 0; } klao@959: klao@959: ///\e klao@959: klao@959: ///\todo Should it be in the concept? klao@959: /// klao@959: int nodeNum() const { return 0; } klao@959: ///\e klao@959: klao@959: ///\todo Should it be in the concept? klao@959: /// klao@959: int edgeNum() const { return 0; } klao@959: klao@959: ///\todo Should it be in the concept? klao@959: /// klao@959: int symEdgeNum() const { return 0; } klao@959: klao@959: klao@959: /// Gives back the forward directed edge of the symmetric edge. klao@959: Edge forward(SymEdge) const {return INVALID;} klao@959: klao@959: /// Gives back the backward directed edge of the symmetric edge. klao@959: Edge backward(SymEdge) const {return INVALID;}; klao@959: klao@959: /// Gives back the opposite of the edge. klao@959: Edge opposite(Edge) const {return INVALID;} klao@959: klao@959: ///Reference map of the nodes to type \c T. klao@959: /// \ingroup concept klao@959: ///Reference map of the nodes to type \c T. klao@959: /// \sa Reference klao@959: /// \warning Making maps that can handle bool type (NodeMap) klao@959: /// needs some extra attention! klao@959: template class NodeMap : public ReferenceMap< Node, T > klao@959: { klao@959: public: klao@959: klao@959: ///\e klao@959: NodeMap(const StaticSymGraph&) { } klao@959: ///\e klao@959: NodeMap(const StaticSymGraph&, T) { } klao@959: klao@959: ///Copy constructor klao@959: template NodeMap(const NodeMap&) { } klao@959: ///Assignment operator klao@959: template NodeMap& operator=(const NodeMap&) klao@959: { return *this; } klao@959: }; klao@959: klao@959: ///Reference map of the edges to type \c T. klao@959: klao@959: /// \ingroup concept klao@959: ///Reference map of the edges to type \c T. klao@959: /// \sa Reference klao@959: /// \warning Making maps that can handle bool type (EdgeMap) klao@959: /// needs some extra attention! klao@959: template class EdgeMap klao@959: : public ReferenceMap klao@959: { klao@959: public: klao@959: klao@959: ///\e klao@959: EdgeMap(const StaticSymGraph&) { } klao@959: ///\e klao@959: EdgeMap(const StaticSymGraph&, T) { } klao@959: klao@959: ///Copy constructor klao@959: template EdgeMap(const EdgeMap&) { } klao@959: ///Assignment operator klao@959: template EdgeMap &operator=(const EdgeMap&) klao@959: { return *this; } klao@959: }; klao@959: klao@959: ///Reference map of the edges to type \c T. klao@959: klao@959: /// \ingroup concept klao@959: ///Reference map of the symmetric edges to type \c T. klao@959: /// \sa Reference klao@959: /// \warning Making maps that can handle bool type (EdgeMap) klao@959: /// needs some extra attention! klao@959: template class SymEdgeMap klao@959: : public ReferenceMap klao@959: { klao@959: public: klao@959: klao@959: ///\e klao@959: SymEdgeMap(const StaticSymGraph&) { } klao@959: ///\e klao@959: SymEdgeMap(const StaticSymGraph&, T) { } klao@959: klao@959: ///Copy constructor klao@959: template SymEdgeMap(const SymEdgeMap&) { } klao@959: ///Assignment operator klao@959: template SymEdgeMap &operator=(const SymEdgeMap&) klao@959: { return *this; } klao@959: }; klao@959: }; klao@959: klao@959: klao@959: klao@959: /// An empty non-static graph class. klao@959: klao@959: /// This class provides everything that \ref StaticGraph klao@959: /// with additional functionality which enables to build a klao@959: /// graph from scratch. klao@959: class ExtendableSymGraph : public StaticSymGraph klao@959: { klao@959: public: klao@959: /// Defalult constructor. klao@959: klao@959: /// Defalult constructor. klao@959: /// klao@959: ExtendableSymGraph() { } klao@959: ///Add a new node to the graph. klao@959: klao@959: /// \return the new node. klao@959: /// klao@959: Node addNode() { return INVALID; } klao@959: ///Add a new edge to the graph. klao@959: alpar@986: ///Add a new symmetric edge to the graph with source node \c t alpar@986: ///and target node \c h. klao@959: ///\return the new edge. klao@959: SymEdge addEdge(Node h, Node t) { return INVALID; } klao@959: klao@959: /// Resets the graph. klao@959: klao@959: /// This function deletes all edges and nodes of the graph. klao@959: /// It also frees the memory allocated to store them. klao@959: /// \todo It might belong to \ref ErasableGraph. klao@959: void clear() { } klao@959: }; klao@959: klao@959: /// An empty erasable graph class. klao@959: klao@959: /// This class is an extension of \ref ExtendableGraph. It also makes it klao@959: /// possible to erase edges or nodes. klao@959: class ErasableSymGraph : public ExtendableSymGraph klao@959: { klao@959: public: klao@959: /// Defalult constructor. klao@959: klao@959: /// Defalult constructor. klao@959: /// klao@959: ErasableSymGraph() { } klao@959: /// Deletes a node. klao@959: klao@959: /// Deletes node \c n node. klao@959: /// klao@959: void erase(Node n) { } klao@959: /// Deletes an edge. klao@959: klao@959: /// Deletes edge \c e edge. klao@959: /// klao@959: void erase(SymEdge e) { } klao@959: }; klao@959: klao@959: // @} klao@959: } //namespace concept klao@959: } //namespace lemon klao@959: klao@959: klao@959: klao@959: #endif // LEMON_CONCEPT_GRAPH_H