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: // }; 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: // }; 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: // }; 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; } deba@989: // /// Read write map of the nodes to type \c T. klao@959: klao@959: // /// \ingroup concept deba@989: // /// ReadWrite 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! deba@989: // template deba@989: // class NodeMap : public ReadWriteMap< 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 deba@989: // NodeMap(const NodeMap&) { } klao@959: // ///Assignment operator deba@989: // NodeMap& operator=(const NodeMap&) { return *this; } deba@989: // // \todo fix this concept klao@959: // }; klao@959: deba@989: // /// Read write 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! deba@989: // template deba@989: // class EdgeMap : public ReadWriteMap 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: // ///Copy constructor deba@989: // EdgeMap(const EdgeMap&) { } klao@959: // ///Assignment operator deba@989: // EdgeMap& operator=(const EdgeMap&) { return *this; } deba@989: // // \todo fix this concept 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: deba@989: // ///Add a new edge to the graph with source node \c s deba@989: // ///and target node \c t. klao@959: // ///\return the new edge. deba@989: // Edge addEdge(Node s, 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 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: // }; deba@989: 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: alpar@986: Node target(Edge) const { return Node(); } alpar@986: Node source(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 deba@989: class NodeMap : public GraphMap {}; klao@959: klao@959: template deba@989: 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: deba@989: template deba@989: struct Constraints { deba@989: void constraints() { deba@989: checkConcept(); deba@989: checkConcept(); deba@989: } deba@989: }; 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: deba@989: template deba@989: struct Constraints { deba@989: void constraints() { deba@989: checkConcept(); deba@989: checkConcept(); deba@989: checkConcept(); deba@989: } deba@989: }; 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: deba@989: template deba@989: struct Constraints { deba@989: void constraints() { deba@989: checkConcept(); deba@989: checkConcept(); deba@989: } deba@989: }; 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