alpar@906: /* -*- C++ -*- alpar@921: * src/lemon/skeletons/graph.h - Part of LEMON, a generic C++ optimization library alpar@906: * alpar@906: * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport alpar@906: * (Egervary Combinatorial Optimization Research Group, EGRES). alpar@906: * alpar@906: * Permission to use, modify and distribute this software is granted alpar@906: * provided that this copyright notice appears in all copies. For alpar@906: * precise terms see the accompanying LICENSE file. alpar@906: * alpar@906: * This software is provided "AS IS" with no warranty of any kind, alpar@906: * express or implied, and with no claim as to its suitability for any alpar@906: * purpose. alpar@906: * alpar@906: */ alpar@906: alpar@921: #ifndef LEMON_SKELETON_GRAPH_H alpar@921: #define LEMON_SKELETON_GRAPH_H alpar@52: alpar@794: ///\ingroup skeletons alpar@242: ///\file alpar@880: ///\brief Declaration of Graph. alpar@242: alpar@921: #include alpar@921: #include klao@946: #include klao@946: #include alpar@145: alpar@921: namespace lemon { alpar@732: namespace skeleton { alpar@732: alpar@794: /// \addtogroup skeletons alpar@794: /// @{ alpar@163: klao@946: // /// An empty static graph class. alpar@732: klao@946: // /// This class provides all the common features of a graph structure, klao@946: // /// however completely without implementations and real data structures klao@946: // /// behind the interface. klao@946: // /// All graph algorithms should compile with this class, but it will not klao@946: // /// run properly, of course. klao@946: // /// klao@946: // /// It can be used for checking the interface compatibility, klao@946: // /// or it can serve as a skeleton of a new graph structure. klao@946: // /// klao@946: // /// Also, you will find here the full documentation of a certain graph klao@946: // /// feature, the documentation of a real graph imlementation klao@946: // /// like @ref ListGraph or klao@946: // /// @ref SmartGraph will just refer to this structure. klao@946: // /// klao@946: // /// \todo A pages describing the concept of concept description would klao@946: // /// be nice. klao@946: // class StaticGraph klao@946: // { klao@946: // public: klao@946: // /// Defalult constructor. klao@946: klao@946: // /// Defalult constructor. klao@946: // /// klao@946: // StaticGraph() { } klao@946: // ///Copy consructor. klao@946: klao@946: // // ///\todo It is not clear, what we expect from a copy constructor. klao@946: // // ///E.g. How to assign the nodes/edges to each other? What about maps? klao@946: // // StaticGraph(const StaticGraph& g) { } klao@946: klao@946: // /// The base type of node iterators, klao@946: // /// or in other words, the trivial node iterator. klao@946: klao@946: // /// This is the base type of each node iterator, klao@946: // /// thus each kind of node iterator converts to this. klao@946: // /// More precisely each kind of node iterator should be inherited klao@946: // /// from the trivial node iterator. klao@946: // class Node { klao@946: // public: klao@946: // /// Default constructor klao@946: klao@946: // /// @warning The default constructor sets the iterator klao@946: // /// to an undefined value. klao@946: // Node() { } klao@946: // /// Copy constructor. klao@946: klao@946: // /// Copy constructor. klao@946: // /// klao@946: // Node(const Node&) { } klao@946: klao@946: // /// Invalid constructor \& conversion. klao@946: klao@946: // /// This constructor initializes the iterator to be invalid. klao@946: // /// \sa Invalid for more details. klao@946: // Node(Invalid) { } klao@946: // /// Equality operator klao@946: klao@946: // /// Two iterators are equal if and only if they point to the klao@946: // /// same object or both are invalid. klao@946: // bool operator==(Node) const { return true; } klao@946: klao@946: // /// Inequality operator klao@946: klao@946: // /// \sa operator==(Node n) klao@946: // /// klao@946: // bool operator!=(Node) const { return true; } klao@946: klao@946: // ///Comparison operator. klao@946: klao@946: // ///This is a strict ordering between the nodes. klao@946: // /// klao@946: // ///This ordering can be different from the order in which NodeIt klao@946: // ///goes through the nodes. klao@946: // ///\todo Possibly we don't need it. klao@946: // bool operator<(Node) const { return true; } klao@946: // }; klao@946: klao@946: // /// This iterator goes through each node. klao@946: klao@946: // /// This iterator goes through each node. klao@946: // /// Its usage is quite simple, for example you can count the number klao@946: // /// of nodes in graph \c g of type \c Graph like this: klao@946: // /// \code klao@946: // /// int count=0; klao@946: // /// for (Graph::NodeIt n(g); n!=INVALID ++n) ++count; klao@946: // /// \endcode klao@946: // class NodeIt : public Node { klao@946: // public: klao@946: // /// Default constructor klao@946: klao@946: // /// @warning The default constructor sets the iterator klao@946: // /// to an undefined value. klao@946: // NodeIt() { } klao@946: // /// Copy constructor. klao@946: klao@946: // /// Copy constructor. klao@946: // /// klao@946: // NodeIt(const NodeIt&) { } klao@946: // /// Invalid constructor \& conversion. klao@946: klao@946: // /// Initialize the iterator to be invalid. klao@946: // /// \sa Invalid for more details. klao@946: // NodeIt(Invalid) { } klao@946: // /// Sets the iterator to the first node. klao@946: klao@946: // /// Sets the iterator to the first node of \c g. klao@946: // /// klao@946: // NodeIt(const StaticGraph& g) { } klao@946: // /// Node -> NodeIt conversion. klao@946: klao@946: // /// Sets the iterator to the node of \c g pointed by the trivial klao@946: // /// iterator n. klao@946: // /// This feature necessitates that each time we klao@946: // /// iterate the edge-set, the iteration order is the same. klao@946: // NodeIt(const StaticGraph& g, const Node& n) { } klao@946: // /// Next node. klao@946: klao@946: // /// Assign the iterator to the next node. klao@946: // /// klao@946: // NodeIt& operator++() { return *this; } klao@946: // }; klao@946: klao@946: klao@946: // /// The base type of the edge iterators. klao@946: klao@946: // /// The base type of the edge iterators. klao@946: // /// klao@946: // class Edge { klao@946: // public: klao@946: // /// Default constructor klao@946: klao@946: // /// @warning The default constructor sets the iterator klao@946: // /// to an undefined value. klao@946: // Edge() { } klao@946: // /// Copy constructor. klao@946: klao@946: // /// Copy constructor. klao@946: // /// klao@946: // Edge(const Edge&) { } klao@946: // /// Initialize the iterator to be invalid. klao@946: klao@946: // /// Initialize the iterator to be invalid. klao@946: // /// klao@946: // Edge(Invalid) { } klao@946: // /// Equality operator klao@946: klao@946: // /// Two iterators are equal if and only if they point to the klao@946: // /// same object or both are invalid. klao@946: // bool operator==(Edge) const { return true; } klao@946: // /// Inequality operator klao@946: klao@946: // /// \sa operator==(Node n) klao@946: // /// klao@946: // bool operator!=(Edge) const { return true; } klao@946: // ///Comparison operator. klao@946: klao@946: // ///This is a strict ordering between the nodes. klao@946: // /// klao@946: // ///This ordering can be different from the order in which NodeIt klao@946: // ///goes through the nodes. klao@946: // ///\todo Possibly we don't need it. klao@946: // bool operator<(Edge) const { return true; } klao@946: // }; klao@946: klao@946: // /// This iterator goes trough the outgoing edges of a node. klao@946: klao@946: // /// This iterator goes trough the \e outgoing edges of a certain node klao@946: // /// of a graph. klao@946: // /// Its usage is quite simple, for example you can count the number klao@946: // /// of outgoing edges of a node \c n klao@946: // /// in graph \c g of type \c Graph as follows. klao@946: // /// \code klao@946: // /// int count=0; klao@946: // /// for (Graph::OutEdgeIt e(g, n); e!=INVALID; ++e) ++count; klao@946: // /// \endcode klao@946: klao@946: // class OutEdgeIt : public Edge { klao@946: // public: klao@946: // /// Default constructor klao@946: klao@946: // /// @warning The default constructor sets the iterator klao@946: // /// to an undefined value. klao@946: // OutEdgeIt() { } klao@946: // /// Copy constructor. klao@946: klao@946: // /// Copy constructor. klao@946: // /// klao@946: // OutEdgeIt(const OutEdgeIt&) { } klao@946: // /// Initialize the iterator to be invalid. klao@946: klao@946: // /// Initialize the iterator to be invalid. klao@946: // /// klao@946: // OutEdgeIt(Invalid) { } klao@946: // /// This constructor sets the iterator to first outgoing edge. klao@946: klao@946: // /// This constructor set the iterator to the first outgoing edge of klao@946: // /// node klao@946: // ///@param n the node klao@946: // ///@param g the graph klao@946: // OutEdgeIt(const StaticGraph& g, const Node& n) { } klao@946: // /// Edge -> OutEdgeIt conversion klao@946: klao@946: // /// Sets the iterator to the value of the trivial iterator \c e. klao@946: // /// This feature necessitates that each time we klao@946: // /// iterate the edge-set, the iteration order is the same. klao@946: // OutEdgeIt(const StaticGraph& g, const Edge& e) { } klao@946: // ///Next outgoing edge klao@946: klao@946: // /// Assign the iterator to the next klao@946: // /// outgoing edge of the corresponding node. klao@946: // OutEdgeIt& operator++() { return *this; } klao@946: // }; klao@946: klao@946: // /// This iterator goes trough the incoming edges of a node. klao@946: klao@946: // /// This iterator goes trough the \e incoming edges of a certain node klao@946: // /// of a graph. klao@946: // /// Its usage is quite simple, for example you can count the number klao@946: // /// of outgoing edges of a node \c n klao@946: // /// in graph \c g of type \c Graph as follows. klao@946: // /// \code klao@946: // /// int count=0; klao@946: // /// for(Graph::InEdgeIt e(g, n); e!=INVALID; ++e) ++count; klao@946: // /// \endcode klao@946: klao@946: // class InEdgeIt : public Edge { klao@946: // public: klao@946: // /// Default constructor klao@946: klao@946: // /// @warning The default constructor sets the iterator klao@946: // /// to an undefined value. klao@946: // InEdgeIt() { } klao@946: // /// Copy constructor. klao@946: klao@946: // /// Copy constructor. klao@946: // /// klao@946: // InEdgeIt(const InEdgeIt&) { } klao@946: // /// Initialize the iterator to be invalid. klao@946: klao@946: // /// Initialize the iterator to be invalid. klao@946: // /// klao@946: // InEdgeIt(Invalid) { } klao@946: // /// This constructor sets the iterator to first incoming edge. klao@946: klao@946: // /// This constructor set the iterator to the first incoming edge of klao@946: // /// node klao@946: // ///@param n the node klao@946: // ///@param g the graph klao@946: // InEdgeIt(const StaticGraph& g, const Node& n) { } klao@946: // /// Edge -> InEdgeIt conversion klao@946: klao@946: // /// Sets the iterator to the value of the trivial iterator \c e. klao@946: // /// This feature necessitates that each time we klao@946: // /// iterate the edge-set, the iteration order is the same. klao@946: // InEdgeIt(const StaticGraph& g, const Edge& n) { } klao@946: // /// Next incoming edge klao@946: klao@946: // /// Assign the iterator to the next inedge of the corresponding node. klao@946: // /// klao@946: // InEdgeIt& operator++() { return *this; } klao@946: // }; klao@946: // /// This iterator goes through each edge. klao@946: klao@946: // /// This iterator goes through each edge of a graph. klao@946: // /// Its usage is quite simple, for example you can count the number klao@946: // /// of edges in a graph \c g of type \c Graph as follows: klao@946: // /// \code klao@946: // /// int count=0; klao@946: // /// for(Graph::EdgeIt e(g); e!=INVALID; ++e) ++count; klao@946: // /// \endcode klao@946: // class EdgeIt : public Edge { klao@946: // public: klao@946: // /// Default constructor klao@946: klao@946: // /// @warning The default constructor sets the iterator klao@946: // /// to an undefined value. klao@946: // EdgeIt() { } klao@946: // /// Copy constructor. klao@946: klao@946: // /// Copy constructor. klao@946: // /// klao@946: // EdgeIt(const EdgeIt&) { } klao@946: // /// Initialize the iterator to be invalid. klao@946: klao@946: // /// Initialize the iterator to be invalid. klao@946: // /// klao@946: // EdgeIt(Invalid) { } klao@946: // /// This constructor sets the iterator to first edge. klao@946: klao@946: // /// This constructor set the iterator to the first edge of klao@946: // /// node klao@946: // ///@param g the graph klao@946: // EdgeIt(const StaticGraph& g) { } klao@946: // /// Edge -> EdgeIt conversion klao@946: klao@946: // /// Sets the iterator to the value of the trivial iterator \c e. klao@946: // /// This feature necessitates that each time we klao@946: // /// iterate the edge-set, the iteration order is the same. klao@946: // EdgeIt(const StaticGraph&, const Edge&) { } klao@946: // ///Next edge klao@946: klao@946: // /// Assign the iterator to the next klao@946: // /// edge of the corresponding node. klao@946: // EdgeIt& operator++() { return *this; } klao@946: // }; klao@946: klao@946: // /// First node of the graph. klao@946: klao@946: // /// \retval i the first node. klao@946: // /// \return the first node. klao@946: // /// klao@946: // NodeIt& first(NodeIt& i) const { return i; } klao@946: klao@946: // /// The first incoming edge. klao@946: klao@946: // /// The first incoming edge. klao@946: // /// klao@946: // InEdgeIt& first(InEdgeIt &i, Node) const { return i; } klao@946: // /// The first outgoing edge. klao@946: klao@946: // /// The first outgoing edge. klao@946: // /// klao@946: // OutEdgeIt& first(OutEdgeIt& i, Node) const { return i; } klao@946: // /// The first edge of the Graph. klao@946: klao@946: // /// The first edge of the Graph. klao@946: // /// klao@946: // EdgeIt& first(EdgeIt& i) const { return i; } klao@946: klao@946: // ///Gives back the head node of an edge. klao@946: klao@946: // ///Gives back the head node of an edge. klao@946: // /// klao@946: // Node head(Edge) const { return INVALID; } klao@946: // ///Gives back the tail node of an edge. klao@946: klao@946: // ///Gives back the tail node of an edge. klao@946: // /// klao@946: // Node tail(Edge) const { return INVALID; } klao@946: klao@946: // ///Gives back the \e id of a node. klao@946: klao@946: // ///\warning Not all graph structures provide this feature. klao@946: // /// klao@946: // ///\todo Should each graph provide \c id? klao@946: // int id(const Node&) const { return 0; } klao@946: // ///Gives back the \e id of an edge. klao@946: klao@946: // ///\warning Not all graph structures provide this feature. klao@946: // /// klao@946: // ///\todo Should each graph provide \c id? klao@946: // int id(const Edge&) const { return 0; } klao@946: klao@946: // ///\e klao@946: klao@946: // ///\todo Should it be in the concept? klao@946: // /// klao@946: // int nodeNum() const { return 0; } klao@946: // ///\e klao@946: klao@946: // ///\todo Should it be in the concept? klao@946: // /// klao@946: // int edgeNum() const { return 0; } klao@946: klao@946: klao@946: // ///Reference map of the nodes to type \c T. klao@946: klao@946: // /// \ingroup skeletons klao@946: // ///Reference map of the nodes to type \c T. klao@946: // /// \sa Reference klao@946: // /// \warning Making maps that can handle bool type (NodeMap) klao@946: // /// needs some extra attention! klao@946: // template class NodeMap : public ReferenceMap< Node, T > klao@946: // { klao@946: // public: klao@946: klao@946: // ///\e klao@946: // NodeMap(const StaticGraph&) { } klao@946: // ///\e klao@946: // NodeMap(const StaticGraph&, T) { } klao@946: klao@946: // ///Copy constructor klao@946: // template NodeMap(const NodeMap&) { } klao@946: // ///Assignment operator klao@946: // template NodeMap& operator=(const NodeMap&) klao@946: // { return *this; } klao@946: // }; klao@946: klao@946: // ///Reference map of the edges to type \c T. klao@946: klao@946: // /// \ingroup skeletons klao@946: // ///Reference map of the edges to type \c T. klao@946: // /// \sa Reference klao@946: // /// \warning Making maps that can handle bool type (EdgeMap) klao@946: // /// needs some extra attention! klao@946: // template class EdgeMap klao@946: // : public ReferenceMap klao@946: // { klao@946: // public: klao@946: klao@946: // ///\e klao@946: // EdgeMap(const StaticGraph&) { } klao@946: // ///\e klao@946: // EdgeMap(const StaticGraph&, T) { } klao@946: klao@946: // ///Copy constructor klao@946: // template EdgeMap(const EdgeMap&) { } klao@946: // ///Assignment operator klao@946: // template EdgeMap &operator=(const EdgeMap&) klao@946: // { return *this; } klao@946: // }; klao@946: // }; klao@946: klao@946: // struct DummyType { klao@946: // int value; klao@946: // DummyType() {} klao@946: // DummyType(int p) : value(p) {} klao@946: // DummyType& operator=(int p) { value = p; return *this;} klao@946: // }; klao@946: klao@946: // ///\brief Checks whether \c G meets the klao@946: // ///\ref lemon::skeleton::StaticGraph "StaticGraph" concept klao@946: // template void checkCompileStaticGraph(Graph &G) klao@946: // { klao@946: // typedef typename Graph::Node Node; klao@946: // typedef typename Graph::NodeIt NodeIt; klao@946: // typedef typename Graph::Edge Edge; klao@946: // typedef typename Graph::EdgeIt EdgeIt; klao@946: // typedef typename Graph::InEdgeIt InEdgeIt; klao@946: // typedef typename Graph::OutEdgeIt OutEdgeIt; klao@946: klao@946: // { klao@946: // Node i; Node j(i); Node k(INVALID); klao@946: // i=j; klao@946: // bool b; b=true; klao@946: // b=(i==INVALID); b=(i!=INVALID); klao@946: // b=(i==j); b=(i!=j); b=(iNodeIt conversion klao@946: // NodeIt ni(G,n); klao@946: // } klao@946: // { klao@946: // Edge i; Edge j(i); Edge k(INVALID); klao@946: // i=j; klao@946: // bool b; b=true; klao@946: // b=(i==INVALID); b=(i!=INVALID); klao@946: // b=(i==j); b=(i!=j); b=(iEdgeIt conversion klao@946: // EdgeIt ei(G,e); klao@946: // } klao@946: // { klao@946: // Node n; klao@946: // InEdgeIt i; InEdgeIt j(i); InEdgeIt k(INVALID); InEdgeIt l(G,n); klao@946: // i=j; klao@946: // j=G.first(i,n); klao@946: // j=++i; klao@946: // bool b; b=true; klao@946: // b=(i==INVALID); b=(i!=INVALID); klao@946: // Edge e(i); klao@946: // e=i; klao@946: // b=(i==j); b=(i!=j); b=(iInEdgeIt conversion klao@946: // InEdgeIt ei(G,e); klao@946: // } klao@946: // { klao@946: // Node n; klao@946: // OutEdgeIt i; OutEdgeIt j(i); OutEdgeIt k(INVALID); OutEdgeIt l(G,n); klao@946: // i=j; klao@946: // j=G.first(i,n); klao@946: // j=++i; klao@946: // bool b; b=true; klao@946: // b=(i==INVALID); b=(i!=INVALID); klao@946: // Edge e(i); klao@946: // e=i; klao@946: // b=(i==j); b=(i!=j); b=(iOutEdgeIt conversion klao@946: // OutEdgeIt ei(G,e); klao@946: // } klao@946: // { klao@946: // Node n,m; klao@946: // n=m=INVALID; klao@946: // Edge e; klao@946: // e=INVALID; klao@946: // n=G.tail(e); klao@946: // n=G.head(e); klao@946: // } klao@946: // // id tests klao@946: // { Node n; int i=G.id(n); i=i; } klao@946: // { Edge e; int i=G.id(e); i=i; } klao@946: // //NodeMap tests klao@946: // { klao@946: // Node k; klao@946: // typename Graph::template NodeMap m(G); klao@946: // //Const map klao@946: // typename Graph::template NodeMap const &cm = m; klao@946: // //Inicialize with default value klao@946: // typename Graph::template NodeMap mdef(G,12); klao@946: // //Copy klao@946: // typename Graph::template NodeMap mm(cm); klao@946: // //Copy from another type klao@946: // typename Graph::template NodeMap dm(cm); klao@946: // //Copy to more complex type klao@946: // typename Graph::template NodeMap em(cm); klao@946: // int v; klao@946: // v=m[k]; m[k]=v; m.set(k,v); klao@946: // v=cm[k]; klao@946: klao@946: // m=cm; klao@946: // dm=cm; //Copy from another type klao@946: // em=cm; //Copy to more complex type klao@946: // { klao@946: // //Check the typedef's klao@946: // typename Graph::template NodeMap::ValueType val; klao@946: // val=1; klao@946: // typename Graph::template NodeMap::KeyType key; klao@946: // key = typename Graph::NodeIt(G); klao@946: // } klao@946: // } klao@946: // { //bool NodeMap klao@946: // Node k; klao@946: // typename Graph::template NodeMap m(G); klao@946: // typename Graph::template NodeMap const &cm = m; //Const map klao@946: // //Inicialize with default value klao@946: // typename Graph::template NodeMap mdef(G,12); klao@946: // typename Graph::template NodeMap mm(cm); //Copy klao@946: // typename Graph::template NodeMap dm(cm); //Copy from another type klao@946: // bool v; klao@946: // v=m[k]; m[k]=v; m.set(k,v); klao@946: // v=cm[k]; klao@946: klao@946: // m=cm; klao@946: // dm=cm; //Copy from another type klao@946: // m=dm; //Copy to another type klao@946: klao@946: // { klao@946: // //Check the typedef's klao@946: // typename Graph::template NodeMap::ValueType val; klao@946: // val=true; klao@946: // typename Graph::template NodeMap::KeyType key; klao@946: // key= typename Graph::NodeIt(G); klao@946: // } klao@946: // } klao@946: // //EdgeMap tests klao@946: // { klao@946: // Edge k; klao@946: // typename Graph::template EdgeMap m(G); klao@946: // typename Graph::template EdgeMap const &cm = m; //Const map klao@946: // //Inicialize with default value klao@946: // typename Graph::template EdgeMap mdef(G,12); klao@946: // typename Graph::template EdgeMap mm(cm); //Copy klao@946: // typename Graph::template EdgeMap dm(cm);//Copy from another type klao@946: // int v; klao@946: // v=m[k]; m[k]=v; m.set(k,v); klao@946: // v=cm[k]; klao@946: klao@946: // m=cm; klao@946: // dm=cm; //Copy from another type klao@946: // { klao@946: // //Check the typedef's klao@946: // typename Graph::template EdgeMap::ValueType val; klao@946: // val=1; klao@946: // typename Graph::template EdgeMap::KeyType key; klao@946: // key= typename Graph::EdgeIt(G); klao@946: // } klao@946: // } klao@946: // { //bool EdgeMap klao@946: // Edge k; klao@946: // typename Graph::template EdgeMap m(G); klao@946: // typename Graph::template EdgeMap const &cm = m; //Const map klao@946: // //Inicialize with default value klao@946: // typename Graph::template EdgeMap mdef(G,12); klao@946: // typename Graph::template EdgeMap mm(cm); //Copy klao@946: // typename Graph::template EdgeMap dm(cm); //Copy from another type klao@946: // bool v; klao@946: // v=m[k]; m[k]=v; m.set(k,v); klao@946: // v=cm[k]; klao@946: klao@946: // m=cm; klao@946: // dm=cm; //Copy from another type klao@946: // m=dm; //Copy to another type klao@946: // { klao@946: // //Check the typedef's klao@946: // typename Graph::template EdgeMap::ValueType val; klao@946: // val=true; klao@946: // typename Graph::template EdgeMap::KeyType key; klao@946: // key= typename Graph::EdgeIt(G); klao@946: // } klao@946: // } klao@946: // } klao@946: klao@946: // /// An empty non-static graph class. klao@946: klao@946: // /// This class provides everything that \ref StaticGraph klao@946: // /// with additional functionality which enables to build a klao@946: // /// graph from scratch. klao@946: // class ExtendableGraph : public StaticGraph klao@946: // { klao@946: // public: klao@946: // /// Defalult constructor. klao@946: klao@946: // /// Defalult constructor. klao@946: // /// klao@946: // ExtendableGraph() { } klao@946: // ///Add a new node to the graph. klao@946: klao@946: // /// \return the new node. klao@946: // /// klao@946: // Node addNode() { return INVALID; } klao@946: // ///Add a new edge to the graph. klao@946: klao@946: // ///Add a new edge to the graph with tail node \c t klao@946: // ///and head node \c h. klao@946: // ///\return the new edge. klao@946: // Edge addEdge(Node h, Node t) { return INVALID; } klao@946: klao@946: // /// Resets the graph. klao@946: klao@946: // /// This function deletes all edges and nodes of the graph. klao@946: // /// It also frees the memory allocated to store them. klao@946: // /// \todo It might belong to \ref ErasableGraph. klao@946: // void clear() { } klao@946: // }; klao@946: klao@946: klao@946: // ///\brief Checks whether \c G meets the klao@946: // ///\ref lemon::skeleton::ExtendableGraph "ExtendableGraph" concept klao@946: // template void checkCompileExtendableGraph(Graph &G) klao@946: // { klao@946: // checkCompileStaticGraph(G); klao@946: klao@946: // typedef typename Graph::Node Node; klao@946: // typedef typename Graph::NodeIt NodeIt; klao@946: // typedef typename Graph::Edge Edge; klao@946: // typedef typename Graph::EdgeIt EdgeIt; klao@946: // typedef typename Graph::InEdgeIt InEdgeIt; klao@946: // typedef typename Graph::OutEdgeIt OutEdgeIt; klao@946: klao@946: // Node n,m; klao@946: // n=G.addNode(); klao@946: // m=G.addNode(); klao@946: // Edge e; klao@946: // e=G.addEdge(n,m); klao@946: klao@946: // // G.clear(); klao@946: // } klao@946: klao@946: klao@946: // /// An empty erasable graph class. klao@946: klao@946: // /// This class is an extension of \ref ExtendableGraph. It also makes it klao@946: // /// possible to erase edges or nodes. klao@946: // class ErasableGraph : public ExtendableGraph klao@946: // { klao@946: // public: klao@946: // /// Defalult constructor. klao@946: klao@946: // /// Defalult constructor. klao@946: // /// klao@946: // ErasableGraph() { } klao@946: // /// Deletes a node. klao@946: klao@946: // /// Deletes node \c n node. klao@946: // /// klao@946: // void erase(Node n) { } klao@946: // /// Deletes an edge. klao@946: klao@946: // /// Deletes edge \c e edge. klao@946: // /// klao@946: // void erase(Edge e) { } klao@946: // }; klao@946: klao@946: // template void checkCompileGraphEraseEdge(Graph &G) klao@946: // { klao@946: // typename Graph::Edge e; klao@946: // G.erase(e); klao@946: // } klao@946: klao@946: // template void checkCompileGraphEraseNode(Graph &G) klao@946: // { klao@946: // typename Graph::Node n; klao@946: // G.erase(n); klao@946: // } klao@946: klao@946: // ///\brief Checks whether \c G meets the klao@946: // ///\ref lemon::skeleton::EresableGraph "EresableGraph" concept klao@946: // template void checkCompileErasableGraph(Graph &G) klao@946: // { klao@946: // checkCompileExtendableGraph(G); klao@946: // checkCompileGraphEraseNode(G); klao@946: // checkCompileGraphEraseEdge(G); klao@946: // } klao@946: klao@946: // ///Checks whether a graph has findEdge() member function. klao@946: klao@946: // ///\todo findEdge() might be a global function. klao@946: // /// klao@946: // template void checkCompileGraphFindEdge(Graph &G) klao@946: // { klao@946: // typedef typename Graph::NodeIt Node; klao@946: // typedef typename Graph::NodeIt NodeIt; klao@946: klao@946: // G.findEdge(NodeIt(G),++NodeIt(G),G.findEdge(NodeIt(G),++NodeIt(G))); klao@946: // G.findEdge(Node(),Node(),G.findEdge(Node(),Node())); klao@946: // } klao@946: klao@946: klao@946: klao@946: /************* New GraphBase stuff **************/ klao@946: klao@946: klao@946: /// \bug The nodes and edges are not allowed to inherit from the klao@946: /// same baseclass. klao@946: klao@946: class BaseGraphItem { alpar@732: public: klao@946: BaseGraphItem() {} klao@946: BaseGraphItem(Invalid) {} alpar@801: klao@946: // We explicitely list these: klao@946: BaseGraphItem(BaseGraphItem const&) {} klao@946: BaseGraphItem& operator=(BaseGraphItem const&) { return *this; } alpar@163: klao@946: bool operator==(BaseGraphItem) const { return false; } klao@946: bool operator!=(BaseGraphItem) const { return false; } alpar@732: klao@946: // Technical requirement. Do we really need this? klao@946: bool operator<(BaseGraphItem) const { return false; } alpar@163: }; alpar@163: klao@946: klao@946: /// A minimal GraphBase concept klao@946: klao@946: /// This class describes a minimal concept which can be extended to a klao@946: /// full-featured graph with \ref GraphFactory. klao@946: class GraphBase { klao@946: public: klao@946: klao@946: GraphBase() {} klao@946: klao@946: klao@946: /// \bug Nodes and Edges are comparable each other klao@946: klao@946: class Node : public BaseGraphItem {}; klao@946: class Edge : public BaseGraphItem {}; klao@946: klao@946: // Graph operation klao@946: void firstNode(Node &n) const { } klao@946: void firstEdge(Edge &e) const { } klao@946: klao@946: void firstOutEdge(Edge &e, Node) const { } klao@946: void firstInEdge(Edge &e, Node) const { } klao@946: klao@946: void nextNode(Node &n) const { } klao@946: void nextEdge(Edge &e) const { } klao@946: klao@946: klao@946: // Question: isn't it reasonable if this methods have a Node klao@946: // parameter? Like this: klao@946: // Edge& nextOut(Edge &e, Node) const { return e; } klao@946: void nextOutEdge(Edge &e) const { } klao@946: void nextInEdge(Edge &e) const { } klao@946: klao@946: Node head(Edge) const { return Node(); } klao@946: Node tail(Edge) const { return Node(); } klao@946: klao@946: klao@946: // Do we need id, nodeNum, edgeNum and co. in this basic graphbase klao@946: // concept? klao@946: klao@946: klao@946: // Maps. klao@946: // klao@946: // We need a special slimer concept which does not provide maps (it klao@946: // wouldn't be strictly slimer, cause for map-factory id() & friends klao@946: // a required...) klao@946: klao@946: template klao@946: class NodeMap : public GraphMap {}; klao@946: klao@946: template klao@946: class EdgeMap : public GraphMap {}; alpar@938: }; alpar@186: klao@946: klao@946: klao@946: /**************** Concept checking classes ****************/ klao@946: klao@946: template klao@946: struct BaseGraphItemConcept { klao@946: void constraints() { klao@946: BGI i1; klao@946: BGI i2 = i1; klao@946: BGI i3 = INVALID; klao@946: klao@946: i1 = i3; klao@946: if( i1 == i3 ) { klao@946: if ( i2 != i3 && i3 < i2 ) klao@946: return; alpar@938: } alpar@938: } alpar@163: }; alpar@163: alpar@938: klao@946: klao@946: class StaticGraph klao@946: : virtual public BaseGraphComponent, public IterableGraphComponent, public MappableGraphComponent { klao@946: public: klao@946: typedef BaseGraphComponent::Node Node; klao@946: typedef BaseGraphComponent::Edge Edge; klao@946: }; alpar@938: klao@946: template klao@946: struct StaticGraphConcept { klao@946: void constraints() { klao@946: function_requires >(); klao@946: function_requires >(); klao@946: function_requires >(); klao@946: } klao@946: Graph& graph; klao@946: }; alpar@938: klao@946: class ExtendableGraph klao@946: : virtual public BaseGraphComponent, public StaticGraph, public ExtendableGraphComponent, public ClearableGraphComponent { klao@946: public: klao@946: typedef BaseGraphComponent::Node Node; klao@946: typedef BaseGraphComponent::Edge Edge; klao@946: }; alpar@938: klao@946: template klao@946: struct ExtendableGraphConcept { klao@946: void constraints() { klao@946: function_requires >(); klao@946: function_requires >(); klao@946: function_requires >(); klao@946: } klao@946: Graph& graph; klao@946: }; klao@946: klao@946: class ErasableGraph klao@946: : virtual public BaseGraphComponent, public ExtendableGraph, public ErasableGraphComponent { alpar@163: public: klao@946: typedef BaseGraphComponent::Node Node; klao@946: typedef BaseGraphComponent::Edge Edge; klao@946: }; alpar@801: klao@946: template klao@946: struct ErasableGraphConcept { klao@946: void constraints() { klao@946: function_requires >(); klao@946: function_requires >(); klao@946: } klao@946: Graph& graph; klao@946: }; alpar@801: alpar@732: // @} alpar@801: } //namespace skeleton alpar@921: } //namespace lemon alpar@52: alpar@145: alpar@145: alpar@921: #endif // LEMON_SKELETON_GRAPH_H