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@1030: ///\ingroup graph_concepts 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 { deba@1136: klao@959: klao@1030: /// \addtogroup graph_concepts klao@959: /// @{ klao@959: klao@961: /**************** The full-featured graph concepts ****************/ klao@959: deba@1136: deba@1136: /// \brief Modular builded static graph class. deba@1136: /// deba@1136: /// It should be the same as the \c StaticGraph class. deba@1136: 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: deba@1136: /// \brief Modular builded extendable graph class. deba@1136: /// deba@1136: /// It should be the same as the \c ExtendableGraph class. deba@1136: class _ExtendableGraph deba@1136: : 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@1136: checkConcept<_StaticGraph, _Graph >(); deba@989: checkConcept(); deba@989: checkConcept(); deba@989: } deba@989: }; klao@959: }; klao@959: deba@1136: /// \brief Modular builded erasable graph class. deba@1136: /// deba@1136: /// It should be the same as the \c ErasableGraph class. deba@1136: class _ErasableGraph deba@1136: : 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@1136: checkConcept<_ExtendableGraph, _Graph >(); deba@989: checkConcept(); deba@989: } deba@989: }; klao@959: }; klao@959: deba@1136: /// An empty static graph class. deba@1136: deba@1136: /// This class provides all the common features of a graph structure, deba@1136: /// however completely without implementations and real data structures deba@1136: /// behind the interface. deba@1136: /// All graph algorithms should compile with this class, but it will not deba@1136: /// run properly, of course. deba@1136: /// deba@1136: /// It can be used for checking the interface compatibility, deba@1136: /// or it can serve as a skeleton of a new graph structure. deba@1136: /// deba@1136: /// Also, you will find here the full documentation of a certain graph deba@1136: /// feature, the documentation of a real graph imlementation deba@1136: /// like @ref ListGraph or deba@1136: /// @ref SmartGraph will just refer to this structure. deba@1136: /// deba@1136: /// \todo A pages describing the concept of concept description would deba@1136: /// be nice. deba@1136: class StaticGraph deba@1136: { deba@1136: public: deba@1136: /// Defalult constructor. deba@1136: deba@1136: /// Defalult constructor. deba@1136: /// deba@1136: StaticGraph() { } deba@1136: ///Copy consructor. deba@1136: deba@1136: // ///\todo It is not clear, what we expect from a copy constructor. deba@1136: // ///E.g. How to assign the nodes/edges to each other? What about maps? deba@1136: // StaticGraph(const StaticGraph& g) { } deba@1136: deba@1136: /// The base type of node iterators, deba@1136: /// or in other words, the trivial node iterator. deba@1136: deba@1136: /// This is the base type of each node iterator, deba@1136: /// thus each kind of node iterator converts to this. deba@1136: /// More precisely each kind of node iterator should be inherited deba@1136: /// from the trivial node iterator. deba@1136: class Node { deba@1136: public: deba@1136: /// Default constructor deba@1136: deba@1136: /// @warning The default constructor sets the iterator deba@1136: /// to an undefined value. deba@1136: Node() { } deba@1136: /// Copy constructor. deba@1136: deba@1136: /// Copy constructor. deba@1136: /// deba@1136: Node(const Node&) { } deba@1136: deba@1136: /// Invalid constructor \& conversion. deba@1136: deba@1136: /// This constructor initializes the iterator to be invalid. deba@1136: /// \sa Invalid for more details. deba@1136: Node(Invalid) { } deba@1136: /// Equality operator deba@1136: deba@1136: /// Two iterators are equal if and only if they point to the deba@1136: /// same object or both are invalid. deba@1136: bool operator==(Node) const { return true; } deba@1136: deba@1136: /// Inequality operator deba@1136: deba@1136: /// \sa operator==(Node n) deba@1136: /// deba@1136: bool operator!=(Node) const { return true; } deba@1136: deba@1136: }; deba@1136: deba@1136: /// This iterator goes through each node. deba@1136: deba@1136: /// This iterator goes through each node. deba@1136: /// Its usage is quite simple, for example you can count the number deba@1136: /// of nodes in graph \c g of type \c Graph like this: deba@1136: /// \code deba@1136: /// int count=0; deba@1136: /// for (Graph::NodeIt n(g); n!=INVALID ++n) ++count; deba@1136: /// \endcode deba@1136: class NodeIt : public Node { deba@1136: public: deba@1136: /// Default constructor deba@1136: deba@1136: /// @warning The default constructor sets the iterator deba@1136: /// to an undefined value. deba@1136: NodeIt() { } deba@1136: /// Copy constructor. deba@1136: deba@1136: /// Copy constructor. deba@1136: /// deba@1136: NodeIt(const NodeIt&) { } deba@1136: /// Invalid constructor \& conversion. deba@1136: deba@1136: /// Initialize the iterator to be invalid. deba@1136: /// \sa Invalid for more details. deba@1136: NodeIt(Invalid) { } deba@1136: /// Sets the iterator to the first node. deba@1136: deba@1136: /// Sets the iterator to the first node of \c g. deba@1136: /// deba@1136: NodeIt(const StaticGraph& g) { } deba@1136: /// Node -> NodeIt conversion. deba@1136: deba@1136: /// Sets the iterator to the node of \c g pointed by the trivial deba@1136: /// iterator n. deba@1136: /// This feature necessitates that each time we deba@1136: /// iterate the edge-set, the iteration order is the same. deba@1136: NodeIt(const StaticGraph& g, const Node& n) { } deba@1136: /// Next node. deba@1136: deba@1136: /// Assign the iterator to the next node. deba@1136: /// deba@1136: NodeIt& operator++() { return *this; } deba@1136: }; deba@1136: deba@1136: deba@1136: /// The base type of the edge iterators. deba@1136: deba@1136: /// The base type of the edge iterators. deba@1136: /// deba@1136: class Edge { deba@1136: public: deba@1136: /// Default constructor deba@1136: deba@1136: /// @warning The default constructor sets the iterator deba@1136: /// to an undefined value. deba@1136: Edge() { } deba@1136: /// Copy constructor. deba@1136: deba@1136: /// Copy constructor. deba@1136: /// deba@1136: Edge(const Edge&) { } deba@1136: /// Initialize the iterator to be invalid. deba@1136: deba@1136: /// Initialize the iterator to be invalid. deba@1136: /// deba@1136: Edge(Invalid) { } deba@1136: /// Equality operator deba@1136: deba@1136: /// Two iterators are equal if and only if they point to the deba@1136: /// same object or both are invalid. deba@1136: bool operator==(Edge) const { return true; } deba@1136: /// Inequality operator deba@1136: deba@1136: /// \sa operator==(Node n) deba@1136: /// deba@1136: bool operator!=(Edge) const { return true; } deba@1136: }; deba@1136: deba@1136: /// This iterator goes trough the outgoing edges of a node. deba@1136: deba@1136: /// This iterator goes trough the \e outgoing edges of a certain node deba@1136: /// of a graph. deba@1136: /// Its usage is quite simple, for example you can count the number deba@1136: /// of outgoing edges of a node \c n deba@1136: /// in graph \c g of type \c Graph as follows. deba@1136: /// \code deba@1136: /// int count=0; deba@1136: /// for (Graph::OutEdgeIt e(g, n); e!=INVALID; ++e) ++count; deba@1136: /// \endcode deba@1136: deba@1136: class OutEdgeIt : public Edge { deba@1136: public: deba@1136: /// Default constructor deba@1136: deba@1136: /// @warning The default constructor sets the iterator deba@1136: /// to an undefined value. deba@1136: OutEdgeIt() { } deba@1136: /// Copy constructor. deba@1136: deba@1136: /// Copy constructor. deba@1136: /// deba@1136: OutEdgeIt(const OutEdgeIt&) { } deba@1136: /// Initialize the iterator to be invalid. deba@1136: deba@1136: /// Initialize the iterator to be invalid. deba@1136: /// deba@1136: OutEdgeIt(Invalid) { } deba@1136: /// This constructor sets the iterator to first outgoing edge. deba@1136: deba@1136: /// This constructor set the iterator to the first outgoing edge of deba@1136: /// node deba@1136: ///@param n the node deba@1136: ///@param g the graph deba@1136: OutEdgeIt(const StaticGraph& g, const Node& n) { } deba@1136: /// Edge -> OutEdgeIt conversion deba@1136: deba@1136: /// Sets the iterator to the value of the trivial iterator \c e. deba@1136: /// This feature necessitates that each time we deba@1136: /// iterate the edge-set, the iteration order is the same. deba@1136: OutEdgeIt(const StaticGraph& g, const Edge& e) { } deba@1136: ///Next outgoing edge deba@1136: deba@1136: /// Assign the iterator to the next deba@1136: /// outgoing edge of the corresponding node. deba@1136: OutEdgeIt& operator++() { return *this; } deba@1136: }; deba@1136: deba@1136: /// This iterator goes trough the incoming edges of a node. deba@1136: deba@1136: /// This iterator goes trough the \e incoming edges of a certain node deba@1136: /// of a graph. deba@1136: /// Its usage is quite simple, for example you can count the number deba@1136: /// of outgoing edges of a node \c n deba@1136: /// in graph \c g of type \c Graph as follows. deba@1136: /// \code deba@1136: /// int count=0; deba@1136: /// for(Graph::InEdgeIt e(g, n); e!=INVALID; ++e) ++count; deba@1136: /// \endcode deba@1136: deba@1136: class InEdgeIt : public Edge { deba@1136: public: deba@1136: /// Default constructor deba@1136: deba@1136: /// @warning The default constructor sets the iterator deba@1136: /// to an undefined value. deba@1136: InEdgeIt() { } deba@1136: /// Copy constructor. deba@1136: deba@1136: /// Copy constructor. deba@1136: /// deba@1136: InEdgeIt(const InEdgeIt&) { } deba@1136: /// Initialize the iterator to be invalid. deba@1136: deba@1136: /// Initialize the iterator to be invalid. deba@1136: /// deba@1136: InEdgeIt(Invalid) { } deba@1136: /// This constructor sets the iterator to first incoming edge. deba@1136: deba@1136: /// This constructor set the iterator to the first incoming edge of deba@1136: /// node deba@1136: ///@param n the node deba@1136: ///@param g the graph deba@1136: InEdgeIt(const StaticGraph& g, const Node& n) { } deba@1136: /// Edge -> InEdgeIt conversion deba@1136: deba@1136: /// Sets the iterator to the value of the trivial iterator \c e. deba@1136: /// This feature necessitates that each time we deba@1136: /// iterate the edge-set, the iteration order is the same. deba@1136: InEdgeIt(const StaticGraph& g, const Edge& n) { } deba@1136: /// Next incoming edge deba@1136: deba@1136: /// Assign the iterator to the next inedge of the corresponding node. deba@1136: /// deba@1136: InEdgeIt& operator++() { return *this; } deba@1136: }; deba@1136: /// This iterator goes through each edge. deba@1136: deba@1136: /// This iterator goes through each edge of a graph. deba@1136: /// Its usage is quite simple, for example you can count the number deba@1136: /// of edges in a graph \c g of type \c Graph as follows: deba@1136: /// \code deba@1136: /// int count=0; deba@1136: /// for(Graph::EdgeIt e(g); e!=INVALID; ++e) ++count; deba@1136: /// \endcode deba@1136: class EdgeIt : public Edge { deba@1136: public: deba@1136: /// Default constructor deba@1136: deba@1136: /// @warning The default constructor sets the iterator deba@1136: /// to an undefined value. deba@1136: EdgeIt() { } deba@1136: /// Copy constructor. deba@1136: deba@1136: /// Copy constructor. deba@1136: /// deba@1136: EdgeIt(const EdgeIt&) { } deba@1136: /// Initialize the iterator to be invalid. deba@1136: deba@1136: /// Initialize the iterator to be invalid. deba@1136: /// deba@1136: EdgeIt(Invalid) { } deba@1136: /// This constructor sets the iterator to first edge. deba@1136: deba@1136: /// This constructor set the iterator to the first edge of deba@1136: /// node deba@1136: ///@param g the graph deba@1136: EdgeIt(const StaticGraph& g) { } deba@1136: /// Edge -> EdgeIt conversion deba@1136: deba@1136: /// Sets the iterator to the value of the trivial iterator \c e. deba@1136: /// This feature necessitates that each time we deba@1136: /// iterate the edge-set, the iteration order is the same. deba@1136: EdgeIt(const StaticGraph&, const Edge&) { } deba@1136: ///Next edge deba@1136: deba@1136: /// Assign the iterator to the next deba@1136: /// edge of the corresponding node. deba@1136: EdgeIt& operator++() { return *this; } deba@1136: }; deba@1136: ///Gives back the target node of an edge. deba@1136: deba@1136: ///Gives back the target node of an edge. deba@1136: /// deba@1136: Node target(Edge) const { return INVALID; } deba@1136: ///Gives back the source node of an edge. deba@1136: deba@1136: ///Gives back the source node of an edge. deba@1136: /// deba@1136: Node source(Edge) const { return INVALID; } deba@1136: /// Read write map of the nodes to type \c T. deba@1136: deba@1136: /// \ingroup concept deba@1136: /// ReadWrite map of the nodes to type \c T. deba@1136: /// \sa Reference deba@1136: /// \warning Making maps that can handle bool type (NodeMap) deba@1136: /// needs some extra attention! deba@1136: template deba@1136: class NodeMap : public ReadWriteMap< Node, T > deba@1136: { deba@1136: public: deba@1136: deba@1136: ///\e deba@1136: NodeMap(const StaticGraph&) { } deba@1136: ///\e deba@1136: NodeMap(const StaticGraph&, T) { } deba@1136: deba@1136: ///Copy constructor deba@1136: NodeMap(const NodeMap&) { } deba@1136: ///Assignment operator deba@1136: NodeMap& operator=(const NodeMap&) { return *this; } deba@1136: // \todo fix this concept deba@1136: }; deba@1136: deba@1136: /// Read write map of the edges to type \c T. deba@1136: deba@1136: /// \ingroup concept deba@1136: ///Reference map of the edges to type \c T. deba@1136: /// \sa Reference deba@1136: /// \warning Making maps that can handle bool type (EdgeMap) deba@1136: /// needs some extra attention! deba@1136: template deba@1136: class EdgeMap : public ReadWriteMap deba@1136: { deba@1136: public: deba@1136: deba@1136: ///\e deba@1136: EdgeMap(const StaticGraph&) { } deba@1136: ///\e deba@1136: EdgeMap(const StaticGraph&, T) { } deba@1136: ///Copy constructor deba@1136: EdgeMap(const EdgeMap&) { } deba@1136: ///Assignment operator deba@1136: EdgeMap& operator=(const EdgeMap&) { return *this; } deba@1136: // \todo fix this concept deba@1136: }; deba@1136: deba@1136: template deba@1136: struct Constraints : public _StaticGraph::Constraints<_Graph> {}; deba@1136: deba@1136: }; deba@1136: deba@1136: /// An empty non-static graph class. deba@1136: deba@1136: /// This class provides everything that \ref StaticGraph deba@1136: /// with additional functionality which enables to build a deba@1136: /// graph from scratch. deba@1136: class ExtendableGraph : public StaticGraph deba@1136: { deba@1136: public: deba@1136: /// Defalult constructor. deba@1136: deba@1136: /// Defalult constructor. deba@1136: /// deba@1136: ExtendableGraph() { } deba@1136: ///Add a new node to the graph. deba@1136: deba@1136: /// \return the new node. deba@1136: /// deba@1136: Node addNode() { return INVALID; } deba@1136: ///Add a new edge to the graph. deba@1136: deba@1136: ///Add a new edge to the graph with source node \c s deba@1136: ///and target node \c t. deba@1136: ///\return the new edge. deba@1136: Edge addEdge(Node s, Node t) { return INVALID; } deba@1136: deba@1136: /// Resets the graph. deba@1136: deba@1136: /// This function deletes all edges and nodes of the graph. deba@1136: /// It also frees the memory allocated to store them. deba@1136: /// \todo It might belong to \ref ErasableGraph. deba@1136: void clear() { } deba@1136: deba@1136: template deba@1136: struct Constraints : public _ExtendableGraph::Constraints<_Graph> {}; deba@1136: deba@1136: }; deba@1136: deba@1136: /// An empty erasable graph class. deba@1136: deba@1136: /// This class is an extension of \ref ExtendableGraph. It also makes it deba@1136: /// possible to erase edges or nodes. deba@1136: class ErasableGraph : public ExtendableGraph deba@1136: { deba@1136: public: deba@1136: /// Defalult constructor. deba@1136: deba@1136: /// Defalult constructor. deba@1136: /// deba@1136: ErasableGraph() { } deba@1136: /// Deletes a node. deba@1136: deba@1136: /// Deletes node \c n node. deba@1136: /// deba@1136: void erase(Node n) { } deba@1136: /// Deletes an edge. deba@1136: deba@1136: /// Deletes edge \c e edge. deba@1136: /// deba@1136: void erase(Edge e) { } deba@1136: deba@1136: template deba@1136: struct Constraints : public _ErasableGraph::Constraints<_Graph> {}; deba@1136: deba@1136: }; deba@1136: deba@1136: deba@1136: /************* New GraphBase stuff **************/ deba@1136: deba@1136: deba@1136: // /// A minimal GraphBase concept deba@1136: deba@1136: // /// This class describes a minimal concept which can be extended to a deba@1136: // /// full-featured graph with \ref GraphFactory. deba@1136: // class GraphBase { deba@1136: // public: deba@1136: deba@1136: // GraphBase() {} deba@1136: deba@1136: // /// \bug Should we demand that Node and Edge be subclasses of the deba@1136: // /// Graph class??? deba@1136: deba@1136: // typedef GraphItem<'n'> Node; deba@1136: // typedef GraphItem<'e'> Edge; deba@1136: deba@1136: // // class Node : public BaseGraphItem<'n'> {}; deba@1136: // // class Edge : public BaseGraphItem<'e'> {}; deba@1136: deba@1136: // // Graph operation deba@1136: // void firstNode(Node &n) const { } deba@1136: // void firstEdge(Edge &e) const { } deba@1136: deba@1136: // void firstOutEdge(Edge &e, Node) const { } deba@1136: // void firstInEdge(Edge &e, Node) const { } deba@1136: deba@1136: // void nextNode(Node &n) const { } deba@1136: // void nextEdge(Edge &e) const { } deba@1136: deba@1136: deba@1136: // // Question: isn't it reasonable if this methods have a Node deba@1136: // // parameter? Like this: deba@1136: // // Edge& nextOut(Edge &e, Node) const { return e; } deba@1136: // void nextOutEdge(Edge &e) const { } deba@1136: // void nextInEdge(Edge &e) const { } deba@1136: deba@1136: // Node target(Edge) const { return Node(); } deba@1136: // Node source(Edge) const { return Node(); } deba@1136: deba@1136: deba@1136: // // Do we need id, nodeNum, edgeNum and co. in this basic graphbase deba@1136: // // concept? deba@1136: deba@1136: deba@1136: // // Maps. deba@1136: // // deba@1136: // // We need a special slimer concept which does not provide maps (it deba@1136: // // wouldn't be strictly slimer, cause for map-factory id() & friends deba@1136: // // a required...) deba@1136: deba@1136: // template deba@1136: // class NodeMap : public GraphMap {}; deba@1136: deba@1136: // template deba@1136: // class EdgeMap : public GraphMap {}; deba@1136: // }; deba@1136: klao@959: // @} klao@959: } //namespace concept klao@959: } //namespace lemon klao@959: klao@959: klao@959: klao@959: #endif // LEMON_CONCEPT_GRAPH_H