alpar@2260: /* -*- C++ -*- alpar@2260: * alpar@2260: * This file is a part of LEMON, a generic C++ optimization library alpar@2260: * alpar@2391: * Copyright (C) 2003-2007 alpar@2260: * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport alpar@2260: * (Egervary Research Group on Combinatorial Optimization, EGRES). alpar@2260: * alpar@2260: * Permission to use, modify and distribute this software is granted alpar@2260: * provided that this copyright notice appears in all copies. For alpar@2260: * precise terms see the accompanying LICENSE file. alpar@2260: * alpar@2260: * This software is provided "AS IS" with no warranty of any kind, alpar@2260: * express or implied, and with no claim as to its suitability for any alpar@2260: * purpose. alpar@2260: * alpar@2260: */ alpar@2260: alpar@2260: #ifndef LEMON_CONCEPT_GRAPH_H alpar@2260: #define LEMON_CONCEPT_GRAPH_H alpar@2260: alpar@2260: ///\ingroup graph_concepts alpar@2260: ///\file kpeter@2474: ///\brief The concept of Directed Graphs. alpar@2260: alpar@2260: #include alpar@2260: #include alpar@2260: #include alpar@2260: #include alpar@2260: #include alpar@2260: alpar@2260: namespace lemon { alpar@2260: namespace concepts { alpar@2260: alpar@2260: /// \addtogroup graph_concepts alpar@2260: /// @{ kpeter@2474: /// kpeter@2474: /// \brief Class describing the concept of Directed Graphs. kpeter@2474: /// alpar@2260: /// This class describes the \ref concept "concept" of the alpar@2260: /// immutable directed graphs. alpar@2260: /// alpar@2260: /// Note that actual graph implementation like @ref ListGraph or alpar@2260: /// @ref SmartGraph may have several additional functionality. alpar@2260: /// alpar@2260: /// \sa concept alpar@2260: class Graph { alpar@2260: private: alpar@2260: ///Graphs are \e not copy constructible. Use GraphCopy() instead. alpar@2260: alpar@2260: ///Graphs are \e not copy constructible. Use GraphCopy() instead. alpar@2260: /// alpar@2260: Graph(const Graph &) {}; alpar@2260: ///\brief Assignment of \ref Graph "Graph"s to another ones are alpar@2260: ///\e not allowed. Use GraphCopy() instead. alpar@2260: alpar@2260: ///Assignment of \ref Graph "Graph"s to another ones are alpar@2260: ///\e not allowed. Use GraphCopy() instead. alpar@2260: alpar@2260: void operator=(const Graph &) {} alpar@2260: public: alpar@2260: ///\e alpar@2260: alpar@2260: /// Defalult constructor. alpar@2260: alpar@2260: /// Defalult constructor. alpar@2260: /// alpar@2260: Graph() { } alpar@2260: /// Class for identifying a node of the graph alpar@2260: alpar@2260: /// This class identifies a node of the graph. It also serves alpar@2260: /// as a base class of the node iterators, alpar@2260: /// thus they will convert to this type. alpar@2260: class Node { alpar@2260: public: alpar@2260: /// Default constructor alpar@2260: alpar@2260: /// @warning The default constructor sets the iterator alpar@2260: /// to an undefined value. alpar@2260: Node() { } alpar@2260: /// Copy constructor. alpar@2260: alpar@2260: /// Copy constructor. alpar@2260: /// alpar@2260: Node(const Node&) { } alpar@2260: alpar@2260: /// Invalid constructor \& conversion. alpar@2260: alpar@2260: /// This constructor initializes the iterator to be invalid. alpar@2260: /// \sa Invalid for more details. alpar@2260: Node(Invalid) { } alpar@2260: /// Equality operator alpar@2260: alpar@2260: /// Two iterators are equal if and only if they point to the alpar@2260: /// same object or both are invalid. alpar@2260: bool operator==(Node) const { return true; } alpar@2260: alpar@2260: /// Inequality operator alpar@2260: alpar@2260: /// \sa operator==(Node n) alpar@2260: /// alpar@2260: bool operator!=(Node) const { return true; } alpar@2260: alpar@2260: /// Artificial ordering operator. alpar@2260: alpar@2260: /// To allow the use of graph descriptors as key type in std::map or alpar@2260: /// similar associative container we require this. alpar@2260: /// alpar@2260: /// \note This operator only have to define some strict ordering of alpar@2260: /// the items; this order has nothing to do with the iteration alpar@2260: /// ordering of the items. alpar@2260: bool operator<(Node) const { return false; } alpar@2260: alpar@2260: }; alpar@2260: alpar@2260: /// This iterator goes through each node. alpar@2260: alpar@2260: /// This iterator goes through each node. alpar@2260: /// Its usage is quite simple, for example you can count the number alpar@2260: /// of nodes in graph \c g of type \c Graph like this: alpar@2260: ///\code alpar@2260: /// int count=0; alpar@2260: /// for (Graph::NodeIt n(g); n!=INVALID; ++n) ++count; alpar@2260: ///\endcode alpar@2260: class NodeIt : public Node { alpar@2260: public: alpar@2260: /// Default constructor alpar@2260: alpar@2260: /// @warning The default constructor sets the iterator alpar@2260: /// to an undefined value. alpar@2260: NodeIt() { } alpar@2260: /// Copy constructor. alpar@2260: alpar@2260: /// Copy constructor. alpar@2260: /// alpar@2260: NodeIt(const NodeIt& n) : Node(n) { } alpar@2260: /// Invalid constructor \& conversion. alpar@2260: alpar@2260: /// Initialize the iterator to be invalid. alpar@2260: /// \sa Invalid for more details. alpar@2260: NodeIt(Invalid) { } alpar@2260: /// Sets the iterator to the first node. alpar@2260: alpar@2260: /// Sets the iterator to the first node of \c g. alpar@2260: /// alpar@2260: NodeIt(const Graph&) { } alpar@2260: /// Node -> NodeIt conversion. alpar@2260: alpar@2260: /// Sets the iterator to the node of \c the graph pointed by alpar@2260: /// the trivial iterator. alpar@2260: /// This feature necessitates that each time we alpar@2260: /// iterate the edge-set, the iteration order is the same. alpar@2260: NodeIt(const Graph&, const Node&) { } alpar@2260: /// Next node. alpar@2260: alpar@2260: /// Assign the iterator to the next node. alpar@2260: /// alpar@2260: NodeIt& operator++() { return *this; } alpar@2260: }; alpar@2260: alpar@2260: alpar@2260: /// Class for identifying an edge of the graph alpar@2260: alpar@2260: /// This class identifies an edge of the graph. It also serves alpar@2260: /// as a base class of the edge iterators, alpar@2260: /// thus they will convert to this type. alpar@2260: class Edge { alpar@2260: public: alpar@2260: /// Default constructor alpar@2260: alpar@2260: /// @warning The default constructor sets the iterator alpar@2260: /// to an undefined value. alpar@2260: Edge() { } alpar@2260: /// Copy constructor. alpar@2260: alpar@2260: /// Copy constructor. alpar@2260: /// alpar@2260: Edge(const Edge&) { } alpar@2260: /// Initialize the iterator to be invalid. alpar@2260: alpar@2260: /// Initialize the iterator to be invalid. alpar@2260: /// alpar@2260: Edge(Invalid) { } alpar@2260: /// Equality operator alpar@2260: alpar@2260: /// Two iterators are equal if and only if they point to the alpar@2260: /// same object or both are invalid. alpar@2260: bool operator==(Edge) const { return true; } alpar@2260: /// Inequality operator alpar@2260: alpar@2260: /// \sa operator==(Edge n) alpar@2260: /// alpar@2260: bool operator!=(Edge) const { return true; } alpar@2260: alpar@2260: /// Artificial ordering operator. alpar@2260: alpar@2260: /// To allow the use of graph descriptors as key type in std::map or alpar@2260: /// similar associative container we require this. alpar@2260: /// alpar@2260: /// \note This operator only have to define some strict ordering of alpar@2260: /// the items; this order has nothing to do with the iteration alpar@2260: /// ordering of the items. alpar@2260: bool operator<(Edge) const { return false; } alpar@2260: }; alpar@2260: alpar@2260: /// This iterator goes trough the outgoing edges of a node. alpar@2260: alpar@2260: /// This iterator goes trough the \e outgoing edges of a certain node alpar@2260: /// of a graph. alpar@2260: /// Its usage is quite simple, for example you can count the number alpar@2260: /// of outgoing edges of a node \c n alpar@2260: /// in graph \c g of type \c Graph as follows. alpar@2260: ///\code alpar@2260: /// int count=0; alpar@2260: /// for (Graph::OutEdgeIt e(g, n); e!=INVALID; ++e) ++count; alpar@2260: ///\endcode alpar@2260: alpar@2260: class OutEdgeIt : public Edge { alpar@2260: public: alpar@2260: /// Default constructor alpar@2260: alpar@2260: /// @warning The default constructor sets the iterator alpar@2260: /// to an undefined value. alpar@2260: OutEdgeIt() { } alpar@2260: /// Copy constructor. alpar@2260: alpar@2260: /// Copy constructor. alpar@2260: /// alpar@2260: OutEdgeIt(const OutEdgeIt& e) : Edge(e) { } alpar@2260: /// Initialize the iterator to be invalid. alpar@2260: alpar@2260: /// Initialize the iterator to be invalid. alpar@2260: /// alpar@2260: OutEdgeIt(Invalid) { } alpar@2260: /// This constructor sets the iterator to the first outgoing edge. alpar@2260: alpar@2260: /// This constructor sets the iterator to the first outgoing edge of alpar@2260: /// the node. alpar@2260: OutEdgeIt(const Graph&, const Node&) { } alpar@2260: /// Edge -> OutEdgeIt conversion alpar@2260: alpar@2260: /// Sets the iterator to the value of the trivial iterator. alpar@2260: /// This feature necessitates that each time we alpar@2260: /// iterate the edge-set, the iteration order is the same. alpar@2260: OutEdgeIt(const Graph&, const Edge&) { } alpar@2260: ///Next outgoing edge alpar@2260: alpar@2260: /// Assign the iterator to the next alpar@2260: /// outgoing edge of the corresponding node. alpar@2260: OutEdgeIt& operator++() { return *this; } alpar@2260: }; alpar@2260: alpar@2260: /// This iterator goes trough the incoming edges of a node. alpar@2260: alpar@2260: /// This iterator goes trough the \e incoming edges of a certain node alpar@2260: /// of a graph. alpar@2260: /// Its usage is quite simple, for example you can count the number alpar@2260: /// of outgoing edges of a node \c n alpar@2260: /// in graph \c g of type \c Graph as follows. alpar@2260: ///\code alpar@2260: /// int count=0; alpar@2260: /// for(Graph::InEdgeIt e(g, n); e!=INVALID; ++e) ++count; alpar@2260: ///\endcode alpar@2260: alpar@2260: class InEdgeIt : public Edge { alpar@2260: public: alpar@2260: /// Default constructor alpar@2260: alpar@2260: /// @warning The default constructor sets the iterator alpar@2260: /// to an undefined value. alpar@2260: InEdgeIt() { } alpar@2260: /// Copy constructor. alpar@2260: alpar@2260: /// Copy constructor. alpar@2260: /// alpar@2260: InEdgeIt(const InEdgeIt& e) : Edge(e) { } alpar@2260: /// Initialize the iterator to be invalid. alpar@2260: alpar@2260: /// Initialize the iterator to be invalid. alpar@2260: /// alpar@2260: InEdgeIt(Invalid) { } alpar@2260: /// This constructor sets the iterator to first incoming edge. alpar@2260: alpar@2260: /// This constructor set the iterator to the first incoming edge of alpar@2260: /// the node. alpar@2260: InEdgeIt(const Graph&, const Node&) { } alpar@2260: /// Edge -> InEdgeIt conversion alpar@2260: alpar@2260: /// Sets the iterator to the value of the trivial iterator \c e. alpar@2260: /// This feature necessitates that each time we alpar@2260: /// iterate the edge-set, the iteration order is the same. alpar@2260: InEdgeIt(const Graph&, const Edge&) { } alpar@2260: /// Next incoming edge alpar@2260: alpar@2260: /// Assign the iterator to the next inedge of the corresponding node. alpar@2260: /// alpar@2260: InEdgeIt& operator++() { return *this; } alpar@2260: }; alpar@2260: /// This iterator goes through each edge. alpar@2260: alpar@2260: /// This iterator goes through each edge of a graph. alpar@2260: /// Its usage is quite simple, for example you can count the number alpar@2260: /// of edges in a graph \c g of type \c Graph as follows: alpar@2260: ///\code alpar@2260: /// int count=0; alpar@2260: /// for(Graph::EdgeIt e(g); e!=INVALID; ++e) ++count; alpar@2260: ///\endcode alpar@2260: class EdgeIt : public Edge { alpar@2260: public: alpar@2260: /// Default constructor alpar@2260: alpar@2260: /// @warning The default constructor sets the iterator alpar@2260: /// to an undefined value. alpar@2260: EdgeIt() { } alpar@2260: /// Copy constructor. alpar@2260: alpar@2260: /// Copy constructor. alpar@2260: /// alpar@2260: EdgeIt(const EdgeIt& e) : Edge(e) { } alpar@2260: /// Initialize the iterator to be invalid. alpar@2260: alpar@2260: /// Initialize the iterator to be invalid. alpar@2260: /// alpar@2260: EdgeIt(Invalid) { } alpar@2260: /// This constructor sets the iterator to the first edge. alpar@2260: alpar@2260: /// This constructor sets the iterator to the first edge of \c g. alpar@2260: ///@param g the graph alpar@2260: EdgeIt(const Graph& g) { ignore_unused_variable_warning(g); } alpar@2260: /// Edge -> EdgeIt conversion alpar@2260: alpar@2260: /// Sets the iterator to the value of the trivial iterator \c e. alpar@2260: /// This feature necessitates that each time we alpar@2260: /// iterate the edge-set, the iteration order is the same. alpar@2260: EdgeIt(const Graph&, const Edge&) { } alpar@2260: ///Next edge alpar@2260: alpar@2260: /// Assign the iterator to the next edge. alpar@2260: EdgeIt& operator++() { return *this; } alpar@2260: }; alpar@2260: ///Gives back the target node of an edge. alpar@2260: alpar@2260: ///Gives back the target node of an edge. alpar@2260: /// alpar@2260: Node target(Edge) const { return INVALID; } alpar@2260: ///Gives back the source node of an edge. alpar@2260: alpar@2260: ///Gives back the source node of an edge. alpar@2260: /// alpar@2260: Node source(Edge) const { return INVALID; } alpar@2260: alpar@2260: void first(Node&) const {} alpar@2260: void next(Node&) const {} alpar@2260: alpar@2260: void first(Edge&) const {} alpar@2260: void next(Edge&) const {} alpar@2260: alpar@2260: alpar@2260: void firstIn(Edge&, const Node&) const {} alpar@2260: void nextIn(Edge&) const {} alpar@2260: alpar@2260: void firstOut(Edge&, const Node&) const {} alpar@2260: void nextOut(Edge&) const {} alpar@2260: alpar@2260: /// \brief The base node of the iterator. alpar@2260: /// alpar@2260: /// Gives back the base node of the iterator. alpar@2260: /// It is always the target of the pointed edge. alpar@2260: Node baseNode(const InEdgeIt&) const { return INVALID; } alpar@2260: alpar@2260: /// \brief The running node of the iterator. alpar@2260: /// alpar@2260: /// Gives back the running node of the iterator. alpar@2260: /// It is always the source of the pointed edge. alpar@2260: Node runningNode(const InEdgeIt&) const { return INVALID; } alpar@2260: alpar@2260: /// \brief The base node of the iterator. alpar@2260: /// alpar@2260: /// Gives back the base node of the iterator. alpar@2260: /// It is always the source of the pointed edge. alpar@2260: Node baseNode(const OutEdgeIt&) const { return INVALID; } alpar@2260: alpar@2260: /// \brief The running node of the iterator. alpar@2260: /// alpar@2260: /// Gives back the running node of the iterator. alpar@2260: /// It is always the target of the pointed edge. alpar@2260: Node runningNode(const OutEdgeIt&) const { return INVALID; } alpar@2260: alpar@2260: /// \brief The opposite node on the given edge. alpar@2260: /// alpar@2260: /// Gives back the opposite node on the given edge. alpar@2260: Node oppositeNode(const Node&, const Edge&) const { return INVALID; } alpar@2260: alpar@2260: /// \brief Read write map of the nodes to type \c T. alpar@2260: /// alpar@2260: /// ReadWrite map of the nodes to type \c T. alpar@2260: /// \sa Reference alpar@2260: template alpar@2260: class NodeMap : public ReadWriteMap< Node, T > { alpar@2260: public: alpar@2260: alpar@2260: ///\e alpar@2260: NodeMap(const Graph&) { } alpar@2260: ///\e alpar@2260: NodeMap(const Graph&, T) { } alpar@2260: alpar@2260: ///Copy constructor alpar@2260: NodeMap(const NodeMap& nm) : ReadWriteMap< Node, T >(nm) { } alpar@2260: ///Assignment operator alpar@2260: template alpar@2260: NodeMap& operator=(const CMap&) { alpar@2260: checkConcept, CMap>(); alpar@2260: return *this; alpar@2260: } alpar@2260: }; alpar@2260: alpar@2260: /// \brief Read write map of the edges to type \c T. alpar@2260: /// alpar@2260: /// Reference map of the edges to type \c T. alpar@2260: /// \sa Reference alpar@2260: template alpar@2260: class EdgeMap : public ReadWriteMap { alpar@2260: public: alpar@2260: alpar@2260: ///\e alpar@2260: EdgeMap(const Graph&) { } alpar@2260: ///\e alpar@2260: EdgeMap(const Graph&, T) { } alpar@2260: ///Copy constructor alpar@2260: EdgeMap(const EdgeMap& em) : ReadWriteMap(em) { } alpar@2260: ///Assignment operator alpar@2260: template alpar@2260: EdgeMap& operator=(const CMap&) { alpar@2260: checkConcept, CMap>(); alpar@2260: return *this; alpar@2260: } alpar@2260: }; alpar@2260: alpar@2260: template alpar@2260: struct Constraints { alpar@2260: void constraints() { alpar@2260: checkConcept, Graph>(); alpar@2260: checkConcept, Graph>(); alpar@2260: } alpar@2260: }; alpar@2260: alpar@2260: }; alpar@2260: alpar@2260: // @} alpar@2260: } //namespace concepts alpar@2260: } //namespace lemon alpar@2260: alpar@2260: alpar@2260: alpar@2260: #endif // LEMON_CONCEPT_GRAPH_H