klao@959: /* -*- C++ -*- klao@959: * src/lemon/concept/graph.h - Part of LEMON, a generic C++ optimization library klao@959: * klao@959: * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport klao@959: * (Egervary Combinatorial Optimization Research Group, 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_GRAPH_H klao@959: #define LEMON_CONCEPT_GRAPH_H klao@959: klao@959: ///\ingroup concept klao@959: ///\file klao@959: ///\brief Declaration of Graph. klao@959: klao@959: #include 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 graph structure, klao@959: // /// however completely without implementations and real data structures klao@959: // /// 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 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 graph imlementation klao@959: // /// like @ref ListGraph or klao@959: // /// @ref SmartGraph will just refer to this structure. klao@959: // /// klao@959: // /// \todo A pages describing the concept of concept description would klao@959: // /// be nice. klao@959: // class StaticGraph klao@959: // { klao@959: // public: klao@959: // /// Defalult constructor. klao@959: klao@959: // /// Defalult constructor. klao@959: // /// klao@959: // StaticGraph() { } 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 StaticGraph& 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 StaticGraph& 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 edge iterators. klao@959: klao@959: // /// The base type of the edge iterators. klao@959: // /// klao@959: // class 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: // 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 StaticGraph& 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 StaticGraph& 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 StaticGraph& 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 StaticGraph& 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 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 StaticGraph& 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 StaticGraph&, 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: klao@959: // ///Gives back the head node of an edge. klao@959: klao@959: // ///Gives back the head node of an edge. klao@959: // /// klao@959: // Node head(Edge) const { return INVALID; } klao@959: // ///Gives back the tail node of an edge. klao@959: klao@959: // ///Gives back the tail node of an edge. klao@959: // /// klao@959: // Node tail(Edge) const { return INVALID; } klao@959: 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: // ///\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: klao@959: // ///Reference map of the nodes to type \c T. klao@959: 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 StaticGraph&) { } klao@959: // ///\e klao@959: // NodeMap(const StaticGraph&, 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 StaticGraph&) { } klao@959: // ///\e klao@959: // EdgeMap(const StaticGraph&, 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: klao@959: // struct DummyType { klao@959: // int value; klao@959: // DummyType() {} klao@959: // DummyType(int p) : value(p) {} klao@959: // DummyType& operator=(int p) { value = p; return *this;} klao@959: // }; klao@959: klao@959: // ///\brief Checks whether \c G meets the klao@959: // ///\ref lemon::concept::StaticGraph "StaticGraph" concept klao@959: // template void checkCompileStaticGraph(Graph &G) klao@959: // { klao@959: // typedef typename Graph::Node Node; klao@959: // typedef typename Graph::NodeIt NodeIt; klao@959: // typedef typename Graph::Edge Edge; klao@959: // typedef typename Graph::EdgeIt EdgeIt; klao@959: // typedef typename Graph::InEdgeIt InEdgeIt; klao@959: // typedef typename Graph::OutEdgeIt OutEdgeIt; klao@959: klao@959: // { klao@959: // Node i; Node j(i); Node k(INVALID); klao@959: // i=j; klao@959: // bool b; b=true; klao@959: // b=(i==INVALID); b=(i!=INVALID); klao@959: // b=(i==j); b=(i!=j); b=(iNodeIt conversion klao@959: // NodeIt ni(G,n); klao@959: // } klao@959: // { klao@959: // Edge i; Edge j(i); Edge k(INVALID); klao@959: // i=j; klao@959: // bool b; b=true; klao@959: // b=(i==INVALID); b=(i!=INVALID); klao@959: // b=(i==j); b=(i!=j); b=(iEdgeIt conversion klao@959: // EdgeIt ei(G,e); klao@959: // } klao@959: // { klao@959: // Node n; klao@959: // InEdgeIt i; InEdgeIt j(i); InEdgeIt k(INVALID); InEdgeIt l(G,n); klao@959: // i=j; klao@959: // j=G.first(i,n); klao@959: // j=++i; klao@959: // bool b; b=true; klao@959: // b=(i==INVALID); b=(i!=INVALID); klao@959: // Edge e(i); klao@959: // e=i; klao@959: // b=(i==j); b=(i!=j); b=(iInEdgeIt conversion klao@959: // InEdgeIt ei(G,e); klao@959: // } klao@959: // { klao@959: // Node n; klao@959: // OutEdgeIt i; OutEdgeIt j(i); OutEdgeIt k(INVALID); OutEdgeIt l(G,n); klao@959: // i=j; klao@959: // j=G.first(i,n); klao@959: // j=++i; klao@959: // bool b; b=true; klao@959: // b=(i==INVALID); b=(i!=INVALID); klao@959: // Edge e(i); klao@959: // e=i; klao@959: // b=(i==j); b=(i!=j); b=(iOutEdgeIt conversion klao@959: // OutEdgeIt ei(G,e); klao@959: // } klao@959: // { klao@959: // Node n,m; klao@959: // n=m=INVALID; klao@959: // Edge e; klao@959: // e=INVALID; klao@959: // n=G.tail(e); klao@959: // n=G.head(e); klao@959: // } klao@959: // // id tests klao@959: // { Node n; int i=G.id(n); i=i; } klao@959: // { Edge e; int i=G.id(e); i=i; } klao@959: // //NodeMap tests klao@959: // { klao@959: // Node k; klao@959: // typename Graph::template NodeMap m(G); klao@959: // //Const map klao@959: // typename Graph::template NodeMap const &cm = m; klao@959: // //Inicialize with default value klao@959: // typename Graph::template NodeMap mdef(G,12); klao@959: // //Copy klao@959: // typename Graph::template NodeMap mm(cm); klao@959: // //Copy from another type klao@959: // typename Graph::template NodeMap dm(cm); klao@959: // //Copy to more complex type klao@959: // typename Graph::template NodeMap em(cm); klao@959: // int v; klao@959: // v=m[k]; m[k]=v; m.set(k,v); klao@959: // v=cm[k]; klao@959: klao@959: // m=cm; klao@959: // dm=cm; //Copy from another type klao@959: // em=cm; //Copy to more complex type klao@959: // { klao@959: // //Check the typedef's klao@959: // typename Graph::template NodeMap::ValueType val; klao@959: // val=1; klao@959: // typename Graph::template NodeMap::KeyType key; klao@959: // key = typename Graph::NodeIt(G); klao@959: // } klao@959: // } klao@959: // { //bool NodeMap klao@959: // Node k; klao@959: // typename Graph::template NodeMap m(G); klao@959: // typename Graph::template NodeMap const &cm = m; //Const map klao@959: // //Inicialize with default value klao@959: // typename Graph::template NodeMap mdef(G,12); klao@959: // typename Graph::template NodeMap mm(cm); //Copy klao@959: // typename Graph::template NodeMap dm(cm); //Copy from another type klao@959: // bool v; klao@959: // v=m[k]; m[k]=v; m.set(k,v); klao@959: // v=cm[k]; klao@959: klao@959: // m=cm; klao@959: // dm=cm; //Copy from another type klao@959: // m=dm; //Copy to another type klao@959: klao@959: // { klao@959: // //Check the typedef's klao@959: // typename Graph::template NodeMap::ValueType val; klao@959: // val=true; klao@959: // typename Graph::template NodeMap::KeyType key; klao@959: // key= typename Graph::NodeIt(G); klao@959: // } klao@959: // } klao@959: // //EdgeMap tests klao@959: // { klao@959: // Edge k; klao@959: // typename Graph::template EdgeMap m(G); klao@959: // typename Graph::template EdgeMap const &cm = m; //Const map klao@959: // //Inicialize with default value klao@959: // typename Graph::template EdgeMap mdef(G,12); klao@959: // typename Graph::template EdgeMap mm(cm); //Copy klao@959: // typename Graph::template EdgeMap dm(cm);//Copy from another type klao@959: // int v; klao@959: // v=m[k]; m[k]=v; m.set(k,v); klao@959: // v=cm[k]; klao@959: klao@959: // m=cm; klao@959: // dm=cm; //Copy from another type klao@959: // { klao@959: // //Check the typedef's klao@959: // typename Graph::template EdgeMap::ValueType val; klao@959: // val=1; klao@959: // typename Graph::template EdgeMap::KeyType key; klao@959: // key= typename Graph::EdgeIt(G); klao@959: // } klao@959: // } klao@959: // { //bool EdgeMap klao@959: // Edge k; klao@959: // typename Graph::template EdgeMap m(G); klao@959: // typename Graph::template EdgeMap const &cm = m; //Const map klao@959: // //Inicialize with default value klao@959: // typename Graph::template EdgeMap mdef(G,12); klao@959: // typename Graph::template EdgeMap mm(cm); //Copy klao@959: // typename Graph::template EdgeMap dm(cm); //Copy from another type klao@959: // bool v; klao@959: // v=m[k]; m[k]=v; m.set(k,v); klao@959: // v=cm[k]; klao@959: klao@959: // m=cm; klao@959: // dm=cm; //Copy from another type klao@959: // m=dm; //Copy to another type klao@959: // { klao@959: // //Check the typedef's klao@959: // typename Graph::template EdgeMap::ValueType val; klao@959: // val=true; klao@959: // typename Graph::template EdgeMap::KeyType key; klao@959: // key= typename Graph::EdgeIt(G); 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 ExtendableGraph : public StaticGraph klao@959: // { klao@959: // public: klao@959: // /// Defalult constructor. klao@959: klao@959: // /// Defalult constructor. klao@959: // /// klao@959: // ExtendableGraph() { } 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: klao@959: // ///Add a new edge to the graph with tail node \c t klao@959: // ///and head node \c h. klao@959: // ///\return the new edge. klao@959: // Edge 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: klao@959: // ///\brief Checks whether \c G meets the klao@959: // ///\ref lemon::concept::ExtendableGraph "ExtendableGraph" concept klao@959: // template void checkCompileExtendableGraph(Graph &G) klao@959: // { klao@959: // checkCompileStaticGraph(G); klao@959: klao@959: // typedef typename Graph::Node Node; klao@959: // typedef typename Graph::NodeIt NodeIt; klao@959: // typedef typename Graph::Edge Edge; klao@959: // typedef typename Graph::EdgeIt EdgeIt; klao@959: // typedef typename Graph::InEdgeIt InEdgeIt; klao@959: // typedef typename Graph::OutEdgeIt OutEdgeIt; klao@959: klao@959: // Node n,m; klao@959: // n=G.addNode(); klao@959: // m=G.addNode(); klao@959: // Edge e; klao@959: // e=G.addEdge(n,m); klao@959: klao@959: // // G.clear(); klao@959: // } 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 ErasableGraph : public ExtendableGraph klao@959: // { klao@959: // public: klao@959: // /// Defalult constructor. klao@959: klao@959: // /// Defalult constructor. klao@959: // /// klao@959: // ErasableGraph() { } 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(Edge e) { } klao@959: // }; klao@959: klao@959: // template void checkCompileGraphEraseEdge(Graph &G) klao@959: // { klao@959: // typename Graph::Edge e; klao@959: // G.erase(e); klao@959: // } klao@959: klao@959: // template void checkCompileGraphEraseNode(Graph &G) klao@959: // { klao@959: // typename Graph::Node n; klao@959: // G.erase(n); klao@959: // } klao@959: klao@959: // ///\brief Checks whether \c G meets the klao@959: // ///\ref lemon::concept::EresableGraph "EresableGraph" concept klao@959: // template void checkCompileErasableGraph(Graph &G) klao@959: // { klao@959: // checkCompileExtendableGraph(G); klao@959: // checkCompileGraphEraseNode(G); klao@959: // checkCompileGraphEraseEdge(G); klao@959: // } klao@959: klao@959: // ///Checks whether a graph has findEdge() member function. klao@959: klao@959: // ///\todo findEdge() might be a global function. klao@959: // /// klao@959: // template void checkCompileGraphFindEdge(Graph &G) klao@959: // { klao@959: // typedef typename Graph::NodeIt Node; klao@959: // typedef typename Graph::NodeIt NodeIt; klao@959: klao@959: // G.findEdge(NodeIt(G),++NodeIt(G),G.findEdge(NodeIt(G),++NodeIt(G))); klao@959: // G.findEdge(Node(),Node(),G.findEdge(Node(),Node())); klao@959: // } klao@959: klao@959: klao@959: klao@959: /************* New GraphBase stuff **************/ klao@959: klao@959: klao@959: /// A minimal GraphBase concept klao@959: klao@959: /// This class describes a minimal concept which can be extended to a klao@959: /// full-featured graph with \ref GraphFactory. klao@959: class GraphBase { klao@959: public: klao@959: klao@959: GraphBase() {} klao@959: klao@961: /// \bug Should we demand that Node and Edge be subclasses of the klao@961: /// Graph class??? klao@959: klao@961: typedef GraphItem<'n'> Node; klao@961: typedef GraphItem<'e'> Edge; klao@961: klao@961: // class Node : public BaseGraphItem<'n'> {}; klao@961: // class Edge : public BaseGraphItem<'e'> {}; klao@959: klao@959: // Graph operation klao@959: void firstNode(Node &n) const { } klao@959: void firstEdge(Edge &e) const { } klao@959: klao@959: void firstOutEdge(Edge &e, Node) const { } klao@959: void firstInEdge(Edge &e, Node) const { } klao@959: klao@959: void nextNode(Node &n) const { } klao@959: void nextEdge(Edge &e) const { } klao@959: klao@959: klao@959: // Question: isn't it reasonable if this methods have a Node klao@959: // parameter? Like this: klao@959: // Edge& nextOut(Edge &e, Node) const { return e; } klao@959: void nextOutEdge(Edge &e) const { } klao@959: void nextInEdge(Edge &e) const { } klao@959: klao@959: Node head(Edge) const { return Node(); } klao@959: Node tail(Edge) const { return Node(); } klao@959: klao@959: klao@959: // Do we need id, nodeNum, edgeNum and co. in this basic graphbase klao@959: // concept? klao@959: klao@959: klao@959: // Maps. klao@959: // klao@959: // We need a special slimer concept which does not provide maps (it klao@959: // wouldn't be strictly slimer, cause for map-factory id() & friends klao@959: // a required...) klao@959: klao@959: template klao@959: class NodeMap : public GraphMap {}; klao@959: klao@959: template klao@959: class EdgeMap : public GraphMap {}; klao@959: }; klao@959: klao@959: klao@959: klao@959: klao@961: /**************** The full-featured graph concepts ****************/ klao@959: klao@959: klao@959: class StaticGraph klao@961: : virtual public BaseGraphComponent, klao@961: public IterableGraphComponent, public MappableGraphComponent { klao@959: public: klao@959: typedef BaseGraphComponent::Node Node; klao@959: typedef BaseGraphComponent::Edge Edge; klao@959: }; klao@959: klao@959: template klao@959: struct StaticGraphConcept { klao@959: void constraints() { klao@959: function_requires >(); klao@959: function_requires >(); klao@959: } klao@959: }; klao@959: klao@959: class ExtendableGraph klao@961: : virtual public BaseGraphComponent, public StaticGraph, klao@961: public ExtendableGraphComponent, public ClearableGraphComponent { klao@959: public: klao@959: typedef BaseGraphComponent::Node Node; klao@959: typedef BaseGraphComponent::Edge Edge; klao@959: }; klao@959: klao@959: template klao@959: struct ExtendableGraphConcept { klao@959: void constraints() { klao@959: function_requires >(); klao@959: function_requires >(); klao@959: function_requires >(); klao@959: } klao@959: }; klao@959: klao@959: class ErasableGraph klao@961: : virtual public BaseGraphComponent, public ExtendableGraph, klao@961: public ErasableGraphComponent { klao@959: public: klao@959: typedef BaseGraphComponent::Node Node; klao@959: typedef BaseGraphComponent::Edge Edge; klao@959: }; klao@959: klao@959: template klao@959: struct ErasableGraphConcept { klao@959: void constraints() { klao@959: function_requires >(); klao@959: function_requires >(); klao@959: } 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