klao@959: /* -*- C++ -*- klao@959: * alpar@1956: * This file is a part of LEMON, a generic C++ optimization library alpar@1956: * alpar@1956: * Copyright (C) 2003-2006 alpar@1956: * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport alpar@1359: * (Egervary Research Group on Combinatorial Optimization, 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@1030: ///\ingroup graph_concepts klao@959: ///\file klao@959: ///\brief The graph components. klao@959: klao@959: klao@959: #ifndef LEMON_CONCEPT_GRAPH_COMPONENT_H klao@959: #define LEMON_CONCEPT_GRAPH_COMPONENT_H klao@959: deba@1993: #include klao@959: #include klao@959: deba@1307: #include deba@1134: klao@959: namespace lemon { klao@959: namespace concept { klao@959: klao@961: /**************** Graph iterator concepts ****************/ klao@961: klao@1030: /// Skeleton class for graph Node and Edge types klao@961: klao@1909: /// This class describes the interface of Node and Edge (and UEdge klao@1030: /// in undirected graphs) subtypes of graph types. klao@1030: /// klao@1030: /// \note This class is a template class so that we can use it to klao@1030: /// create graph skeleton classes. The reason for this is than Node klao@1030: /// and Edge types should \em not derive from the same base class. klao@1030: /// For Node you should instantiate it with character 'n' and for Edge klao@1030: /// with 'e'. klao@961: klao@1030: #ifndef DOXYGEN klao@1030: template klao@1030: #endif klao@961: class GraphItem { klao@961: public: deba@989: /// Default constructor. deba@989: klao@1030: /// \warning The default constructor is not required to set klao@1030: /// the item to some well-defined value. So you should consider it klao@1030: /// as uninitialized. klao@961: GraphItem() {} deba@989: /// Copy constructor. deba@989: deba@989: /// Copy constructor. deba@989: /// deba@989: GraphItem(GraphItem const&) {} deba@989: /// Invalid constructor \& conversion. deba@989: deba@989: /// This constructor initializes the item to be invalid. deba@989: /// \sa Invalid for more details. klao@961: GraphItem(Invalid) {} deba@989: /// Assign operator for nodes. klao@961: deba@989: /// The nodes are assignable. deba@989: /// klao@961: GraphItem& operator=(GraphItem const&) { return *this; } deba@989: /// Equality operator. deba@989: deba@989: /// Two iterators are equal if and only if they represents the deba@989: /// same node in the graph or both are invalid. klao@961: bool operator==(GraphItem) const { return false; } deba@989: /// Inequality operator. deba@989: deba@989: /// \sa operator==(const Node& n) deba@989: /// klao@961: bool operator!=(GraphItem) const { return false; } klao@961: klao@1030: /// Artificial ordering operator. deba@989: klao@1030: /// To allow the use of graph descriptors as key type in std::map or klao@1030: /// similar associative container we require this. klao@1030: /// klao@1030: /// \note This operator only have to define some strict ordering of klao@1030: /// the items; this order has nothing to do with the iteration klao@1030: /// ordering of the items. klao@1030: /// klao@1030: /// \bug This is a technical requirement. Do we really need this? klao@1030: bool operator<(GraphItem) const { return false; } deba@989: deba@989: template deba@989: struct Constraints { deba@989: void constraints() { deba@989: _GraphItem i1; deba@989: _GraphItem i2 = i1; deba@989: _GraphItem i3 = INVALID; deba@989: deba@989: i1 = i2 = i3; deba@989: deba@989: bool b; deba@989: // b = (ia == ib) && (ia != ib) && (ia < ib); deba@989: b = (ia == ib) && (ia != ib); deba@989: b = (ia == INVALID) && (ib != INVALID); deba@1136: // b = (ia < ib); deba@989: } deba@989: deba@989: const _GraphItem &ia; deba@989: const _GraphItem &ib; deba@989: }; klao@961: }; klao@961: klao@1030: /// A type describing the concept of graph node klao@1030: klao@1030: /// This is an instantiation of \ref GraphItem which can be used as a klao@1030: /// Node subtype in graph skeleton definitions klao@1030: typedef GraphItem<'n'> GraphNode; klao@1030: klao@1030: /// A type describing the concept of graph edge klao@1030: klao@1030: /// This is an instantiation of \ref GraphItem which can be used as a klao@1030: /// Edge subtype in graph skeleton definitions klao@1030: typedef GraphItem<'e'> GraphEdge; klao@1030: klao@1030: klao@1030: /**************** Basic features of graphs ****************/ klao@1030: klao@959: /// An empty base graph class. klao@959: klao@961: /// This class provides the minimal set of features needed for a graph klao@961: /// structure. All graph concepts have to be conform to this base klao@961: /// graph. klao@961: /// klao@961: /// \bug This is not true. The minimal graph concept is the klao@961: /// BaseIterableGraphComponent. klao@959: klao@959: class BaseGraphComponent { klao@959: public: klao@959: klao@959: typedef BaseGraphComponent Graph; klao@959: klao@959: /// Node class of the graph. klao@959: klao@959: /// This class represents the Nodes of the graph. klao@959: /// deba@989: typedef GraphItem<'n'> Node; klao@959: klao@959: /// Edge class of the graph. klao@959: klao@959: /// This class represents the Edges of the graph. klao@959: /// deba@989: typedef GraphItem<'e'> Edge; 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(const Edge&) const { return INVALID;} klao@959: 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(const Edge&) const { return INVALID;} klao@959: klao@961: deba@989: template deba@989: struct Constraints { deba@989: typedef typename _Graph::Node Node; deba@989: typedef typename _Graph::Edge Edge; klao@959: deba@989: void constraints() { deba@989: checkConcept, Node>(); deba@989: checkConcept, Edge>(); deba@989: { deba@989: Node n; alpar@1644: Edge e(INVALID); deba@989: n = graph.source(e); deba@989: n = graph.target(e); deba@989: } deba@989: } klao@959: deba@989: const _Graph& graph; deba@989: }; klao@959: }; klao@959: klao@959: /// An empty iterable base graph class. klao@959: klao@959: /// This class provides beside the core graph features klao@959: /// core iterable interface for the graph structure. klao@959: /// Most of the base graphs should be conform to this concept. klao@959: klao@959: class BaseIterableGraphComponent : virtual public BaseGraphComponent { klao@959: public: klao@959: klao@959: typedef BaseGraphComponent::Node Node; klao@959: typedef BaseGraphComponent::Edge Edge; klao@959: klao@959: /// Gives back the first Node in the iterating order. klao@959: klao@959: /// Gives back the first Node in the iterating order. klao@959: /// klao@959: void first(Node&) const {} klao@959: klao@959: /// Gives back the next Node in the iterating order. klao@959: klao@959: /// Gives back the next Node in the iterating order. klao@959: /// klao@959: void next(Node&) const {} klao@959: klao@959: /// Gives back the first Edge in the iterating order. klao@959: klao@959: /// Gives back the first Edge in the iterating order. klao@959: /// klao@959: void first(Edge&) const {} klao@959: /// Gives back the next Edge in the iterating order. klao@959: klao@959: /// Gives back the next Edge in the iterating order. klao@959: /// klao@959: void next(Edge&) const {} klao@959: klao@959: klao@959: /// Gives back the first of the Edges point to the given Node. klao@959: klao@959: /// Gives back the first of the Edges point to the given Node. klao@959: /// klao@959: void firstIn(Edge&, const Node&) const {} klao@959: klao@959: /// Gives back the next of the Edges points to the given Node. klao@959: klao@959: klao@959: /// Gives back the next of the Edges points to the given Node. klao@959: /// klao@959: void nextIn(Edge&) const {} klao@959: klao@959: /// Gives back the first of the Edges start from the given Node. klao@959: klao@959: /// Gives back the first of the Edges start from the given Node. klao@959: /// klao@959: void firstOut(Edge&, const Node&) const {} klao@959: klao@959: /// Gives back the next of the Edges start from the given Node. klao@959: klao@959: /// Gives back the next of the Edges start from the given Node. klao@959: /// klao@959: void nextOut(Edge&) const {} klao@959: klao@959: deba@989: template deba@989: struct Constraints { deba@989: deba@989: void constraints() { deba@989: checkConcept< BaseGraphComponent, _Graph >(); deba@989: typename _Graph::Node node; deba@989: typename _Graph::Edge edge; deba@989: { deba@989: graph.first(node); deba@989: graph.next(node); deba@989: } deba@989: { deba@989: graph.first(edge); deba@989: graph.next(edge); deba@989: } deba@989: { deba@989: graph.firstIn(edge, node); deba@989: graph.nextIn(edge); deba@989: } deba@989: { deba@989: graph.firstOut(edge, node); deba@989: graph.nextOut(edge); deba@989: } deba@989: } klao@959: deba@989: const _Graph& graph; deba@989: }; klao@959: }; klao@959: klao@959: /// An empty idable base graph class. klao@959: klao@959: /// This class provides beside the core graph features klao@959: /// core id functions for the graph structure. klao@959: /// The most of the base graphs should be conform to this concept. klao@959: /// The id's are unique and immutable. klao@959: class IDableGraphComponent : virtual public BaseGraphComponent { klao@959: public: klao@959: klao@959: typedef BaseGraphComponent::Node Node; klao@959: typedef BaseGraphComponent::Edge Edge; klao@959: klao@959: /// Gives back an unique integer id for the Node. klao@959: klao@959: /// Gives back an unique integer id for the Node. klao@959: /// klao@959: int id(const Node&) const { return -1;} klao@959: deba@1106: /// \brief Gives back the node by the unique id. deba@1106: /// deba@1106: /// Gives back the node by the unique id. deba@1106: /// If the graph does not contain node with the given id deba@1106: /// then the result of the function is undetermined. alpar@1367: Node fromId(int , Node) const { return INVALID;} klao@959: deba@1106: /// \brief Gives back an unique integer id for the Edge. deba@1106: /// klao@959: /// Gives back an unique integer id for the Edge. klao@959: /// klao@959: int id(const Edge&) const { return -1;} klao@959: deba@1106: /// \brief Gives back the edge by the unique id. deba@1106: /// deba@1106: /// Gives back the edge by the unique id. deba@1106: /// If the graph does not contain edge with the given id deba@1106: /// then the result of the function is undetermined. alpar@1367: Edge fromId(int, Edge) const { return INVALID;} deba@1106: deba@989: template deba@989: struct Constraints { klao@959: deba@989: void constraints() { deba@989: checkConcept< BaseGraphComponent, _Graph >(); deba@989: typename _Graph::Node node; deba@989: int nid = graph.id(node); deba@989: nid = graph.id(node); deba@1106: node = graph.fromId(nid, Node()); deba@989: typename _Graph::Edge edge; deba@989: int eid = graph.id(edge); deba@989: eid = graph.id(edge); deba@1106: edge = graph.fromId(eid, Edge()); deba@989: } klao@959: deba@989: const _Graph& graph; deba@989: }; klao@959: }; klao@959: klao@959: klao@959: /// An empty max-idable base graph class. klao@959: klao@959: /// This class provides beside the core graph features klao@959: /// core max id functions for the graph structure. klao@959: /// The most of the base graphs should be conform to this concept. klao@959: /// The id's are unique and immutable. klao@959: class MaxIDableGraphComponent : virtual public BaseGraphComponent { klao@959: public: klao@959: klao@959: /// Gives back an integer greater or equal to the maximum Node id. klao@959: klao@959: /// Gives back an integer greater or equal to the maximum Node id. klao@959: /// deba@980: int maxId(Node = INVALID) const { return -1;} klao@959: klao@959: /// Gives back an integer greater or equal to the maximum Edge id. klao@959: klao@959: /// Gives back an integer greater or equal to the maximum Edge id. klao@959: /// deba@980: int maxId(Edge = INVALID) const { return -1;} klao@959: deba@989: template deba@989: struct Constraints { klao@959: deba@989: void constraints() { deba@989: checkConcept(); deba@989: int nid = graph.maxId(typename _Graph::Node()); deba@989: ignore_unused_variable_warning(nid); deba@989: int eid = graph.maxId(typename _Graph::Edge()); deba@989: ignore_unused_variable_warning(eid); deba@989: } deba@989: deba@989: const _Graph& graph; deba@989: }; klao@959: }; klao@959: klao@959: /// An empty extendable base graph class. klao@959: klao@959: /// This class provides beside the core graph features klao@959: /// core graph extend interface for the graph structure. klao@959: /// The most of the base graphs should be conform to this concept. klao@959: class BaseExtendableGraphComponent : virtual public BaseGraphComponent { klao@959: public: klao@959: klao@959: typedef BaseGraphComponent::Node Node; klao@959: typedef BaseGraphComponent::Edge Edge; klao@959: klao@959: /// Adds a new Node to the graph. klao@959: klao@959: /// Adds a new Node to the graph. klao@959: /// klao@959: Node addNode() { klao@959: return INVALID; klao@959: } klao@959: klao@959: /// Adds a new Edge connects the two Nodes to the graph. klao@959: klao@959: /// Adds a new Edge connects the two Nodes to the graph. klao@959: /// alpar@1367: Edge addEdge(const Node&, const Node&) { klao@959: return INVALID; klao@959: } klao@959: deba@989: template deba@989: struct Constraints { deba@989: void constraints() { deba@989: checkConcept(); deba@989: typename _Graph::Node node_a, node_b; deba@989: node_a = graph.addNode(); alpar@1494: node_b = graph.addNode(); deba@989: typename _Graph::Edge edge; deba@989: edge = graph.addEdge(node_a, node_b); deba@989: } klao@959: deba@989: _Graph& graph; deba@989: }; klao@959: }; klao@959: klao@959: /// An empty erasable base graph class. klao@959: klao@959: /// This class provides beside the core graph features klao@959: /// core erase functions for the graph structure. klao@959: /// The most of the base graphs should be conform to this concept. klao@959: class BaseErasableGraphComponent : virtual public BaseGraphComponent { klao@959: public: klao@959: klao@959: typedef BaseGraphComponent::Node Node; klao@959: typedef BaseGraphComponent::Edge Edge; klao@959: klao@959: /// Erase a Node from the graph. klao@959: klao@959: /// Erase a Node from the graph. This function should not klao@959: /// erase edges connecting to the Node. klao@959: void erase(const Node&) {} klao@959: klao@959: /// Erase an Edge from the graph. klao@959: klao@959: /// Erase an Edge from the graph. klao@959: /// klao@959: void erase(const Edge&) {} klao@959: deba@989: template deba@989: struct Constraints { deba@989: void constraints() { deba@989: checkConcept(); deba@989: typename _Graph::Node node; deba@989: graph.erase(node); deba@989: typename _Graph::Edge edge; deba@989: graph.erase(edge); deba@989: } klao@959: deba@989: _Graph& graph; deba@989: }; klao@959: }; klao@959: klao@959: /// An empty clearable base graph class. klao@959: klao@959: /// This class provides beside the core graph features klao@959: /// core clear functions for the graph structure. klao@959: /// The most of the base graphs should be conform to this concept. klao@1022: class ClearableGraphComponent : virtual public BaseGraphComponent { klao@959: public: klao@959: klao@959: /// Erase all the Nodes and Edges from the graph. klao@959: klao@959: /// Erase all the Nodes and Edges from the graph. klao@959: /// klao@959: void clear() {} deba@989: deba@989: template deba@989: struct Constraints { deba@989: void constraints() { klao@1022: checkConcept(); deba@989: graph.clear(); deba@989: } deba@989: klao@1022: _Graph graph; deba@989: }; klao@959: }; klao@959: klao@959: deba@989: /// Skeleton class for graph NodeIt and EdgeIt deba@989: deba@989: /// Skeleton class for graph NodeIt and EdgeIt. klao@959: /// deba@989: template deba@989: class GraphIterator : public _Item { deba@989: public: deba@989: /// \todo Don't we need the Item type as typedef? klao@959: deba@989: /// Default constructor. deba@989: deba@989: /// @warning The default constructor sets the iterator deba@989: /// to an undefined value. deba@989: GraphIterator() {} deba@989: /// Copy constructor. deba@989: deba@989: /// Copy constructor. deba@989: /// deba@989: GraphIterator(GraphIterator const&) {} deba@989: /// Sets the iterator to the first item. deba@989: deba@989: /// Sets the iterator to the first item of \c the graph. deba@989: /// deba@989: explicit GraphIterator(const _Graph&) {} deba@989: /// Invalid constructor \& conversion. deba@989: deba@989: /// This constructor initializes the item to be invalid. deba@989: /// \sa Invalid for more details. deba@989: GraphIterator(Invalid) {} deba@989: /// Assign operator for items. deba@989: deba@989: /// The items are assignable. deba@989: /// deba@989: GraphIterator& operator=(GraphIterator const&) { return *this; } deba@989: /// Next item. deba@989: deba@989: /// Assign the iterator to the next item. deba@989: /// deba@989: GraphIterator& operator++() { return *this; } deba@989: // Node operator*() const { return INVALID; } deba@989: /// Equality operator deba@989: deba@989: /// Two iterators are equal if and only if they point to the deba@989: /// same object or both are invalid. deba@989: bool operator==(const GraphIterator&) const { return true;} deba@989: /// Inequality operator deba@989: deba@989: /// \sa operator==(Node n) deba@989: /// deba@989: bool operator!=(const GraphIterator&) const { return true;} deba@989: deba@989: template deba@989: struct Constraints { deba@989: void constraints() { deba@989: // checkConcept< Item, _GraphIterator >(); deba@989: _GraphIterator it1(g); deba@989: deba@989: /// \todo Do we need NodeIt(Node) kind of constructor? deba@989: // _GraphIterator it2(bj); deba@989: _GraphIterator it2; deba@989: deba@989: it2 = ++it1; deba@989: ++it2 = it1; deba@989: ++(++it1); deba@989: /// \bug This should be: is_base_and_derived deba@989: _Item bi = it1; deba@989: bi = it2; deba@989: } deba@989: _Graph& g; deba@989: }; klao@959: }; klao@959: deba@989: /// Skeleton class for graph InEdgeIt and OutEdgeIt klao@959: deba@989: /// \note Because InEdgeIt and OutEdgeIt may not inherit from the same deba@989: /// base class, the _selector is a additional template parameter. For deba@989: /// InEdgeIt you should instantiate it with character 'i' and for deba@989: /// OutEdgeIt with 'o'. klao@1021: /// \todo Is this a good name for this concept? klao@1021: template klao@1021: class GraphIncIterator : public Edge { deba@989: public: deba@989: /// Default constructor. deba@989: deba@989: /// @warning The default constructor sets the iterator deba@989: /// to an undefined value. klao@1021: GraphIncIterator() {} deba@989: /// Copy constructor. deba@989: deba@989: /// Copy constructor. deba@989: /// alpar@1375: GraphIncIterator(GraphIncIterator const& gi) :Edge(gi) {} deba@1134: /// Sets the iterator to the first edge incoming into or outgoing deba@1134: /// from the node. deba@989: deba@1134: /// Sets the iterator to the first edge incoming into or outgoing deba@1134: /// from the node. deba@989: /// klao@1021: explicit GraphIncIterator(const Graph&, const typename Graph::Node&) {} deba@989: /// Invalid constructor \& conversion. deba@989: deba@989: /// This constructor initializes the item to be invalid. deba@989: /// \sa Invalid for more details. klao@1021: GraphIncIterator(Invalid) {} deba@989: /// Assign operator for nodes. deba@989: deba@989: /// The nodes are assignable. deba@989: /// klao@1021: GraphIncIterator& operator=(GraphIncIterator const&) { return *this; } deba@989: /// Next edge. deba@989: deba@989: /// Assign the iterator to the next node. deba@989: /// klao@1021: GraphIncIterator& operator++() { return *this; } klao@1021: deba@989: // Node operator*() const { return INVALID; } klao@1021: deba@989: /// Equality operator deba@989: deba@989: /// Two iterators are equal if and only if they point to the deba@989: /// same object or both are invalid. klao@1021: bool operator==(const GraphIncIterator&) const { return true;} klao@1021: deba@989: /// Inequality operator deba@989: deba@989: /// \sa operator==(Node n) deba@989: /// klao@1021: bool operator!=(const GraphIncIterator&) const { return true;} deba@989: klao@1021: template deba@989: struct Constraints { klao@1021: typedef typename Graph::Node Node; deba@989: void constraints() { klao@1021: checkConcept, _GraphIncIterator>(); klao@1021: _GraphIncIterator it1(graph, node); deba@989: /// \todo Do we need OutEdgeIt(Edge) kind of constructor? klao@1021: // _GraphIncIterator it2(edge); klao@1021: _GraphIncIterator it2; deba@989: deba@989: it2 = ++it1; deba@989: ++it2 = it1; deba@989: ++(++it1); deba@989: Edge e = it1; deba@989: e = it2; klao@1158: klao@1158: const_constraits(); deba@989: } deba@989: klao@1158: void const_constraits() { klao@1158: Node n = graph.baseNode(it); klao@1158: n = graph.runningNode(it); klao@1158: } klao@1158: klao@1158: Edge edge; klao@1158: Node node; klao@1158: Graph graph; klao@1158: _GraphIncIterator it; deba@989: }; deba@989: }; klao@1021: klao@1021: deba@989: /// An empty iterable base graph class. deba@989: deba@989: /// This class provides beside the core graph features deba@989: /// iterator based iterable interface for the graph structure. deba@989: /// This concept is part of the StaticGraphConcept. deba@989: class IterableGraphComponent : virtual public BaseGraphComponent { klao@959: klao@959: public: klao@959: klao@959: typedef IterableGraphComponent Graph; klao@959: klao@959: typedef BaseGraphComponent::Node Node; klao@959: typedef BaseGraphComponent::Edge Edge; klao@959: deba@989: /// This iterator goes through each node. klao@959: deba@989: /// This iterator goes through each node. deba@989: /// deba@989: typedef GraphIterator NodeIt; deba@989: /// This iterator goes through each node. klao@959: deba@989: /// This iterator goes through each node. deba@989: /// deba@989: typedef GraphIterator EdgeIt; deba@989: /// This iterator goes trough the incoming edges of a node. klao@959: deba@989: /// This iterator goes trough the \e inccoming edges of a certain node deba@989: /// of a graph. klao@1021: typedef GraphIncIterator InEdgeIt; deba@989: /// This iterator goes trough the outgoing edges of a node. klao@959: deba@989: /// This iterator goes trough the \e outgoing edges of a certain node deba@989: /// of a graph. klao@1021: typedef GraphIncIterator OutEdgeIt; deba@1563: deba@1563: /// \brief The base node of the iterator. deba@1563: /// deba@1563: /// Gives back the base node of the iterator. deba@1627: /// It is always the target of the pointed edge. deba@1563: Node baseNode(const InEdgeIt&) const { return INVALID; } deba@1563: deba@1563: /// \brief The running node of the iterator. deba@1563: /// deba@1563: /// Gives back the running node of the iterator. deba@1627: /// It is always the source of the pointed edge. deba@1563: Node runningNode(const InEdgeIt&) const { return INVALID; } deba@1563: deba@1563: /// \brief The base node of the iterator. deba@1563: /// deba@1563: /// Gives back the base node of the iterator. deba@1627: /// It is always the source of the pointed edge. deba@1563: Node baseNode(const OutEdgeIt&) const { return INVALID; } deba@1563: deba@1563: /// \brief The running node of the iterator. deba@1563: /// deba@1563: /// Gives back the running node of the iterator. deba@1627: /// It is always the target of the pointed edge. deba@1563: Node runningNode(const OutEdgeIt&) const { return INVALID; } deba@1563: deba@1627: /// \brief The opposite node on the given edge. deba@1627: /// deba@1627: /// Gives back the opposite on the given edge. deba@1627: /// \todo It should not be here. deba@1627: Node oppositeNode(const Node&, const Edge&) const { return INVALID; } deba@1627: deba@989: deba@1563: template deba@1563: struct Constraints { deba@1563: void constraints() { deba@1563: checkConcept< BaseGraphComponent, _Graph>(); deba@1563: deba@1563: checkConcept, deba@1563: typename _Graph::EdgeIt >(); deba@1563: checkConcept, deba@1563: typename _Graph::NodeIt >(); deba@1563: checkConcept, typename _Graph::InEdgeIt>(); deba@1563: checkConcept, typename _Graph::OutEdgeIt>(); deba@1627: alpar@1644: typename _Graph::Node n(INVALID); alpar@1644: typename _Graph::Edge e(INVALID); deba@1627: n = graph.oppositeNode(n, e); deba@1563: } deba@1627: deba@1627: const _Graph& graph; deba@1627: deba@1563: }; deba@989: }; klao@959: deba@1134: /// An empty alteration notifier base graph class. deba@1134: deba@1134: /// This class provides beside the core graph features deba@1134: /// alteration notifier interface for the graph structure. deba@1134: /// This is an observer-notifier pattern. More Obsevers can deba@1134: /// be registered into the notifier and whenever an alteration deba@1134: /// occured in the graph all the observers will notified about it. deba@1999: class AlterableGraphComponent : virtual public BaseIterableGraphComponent { deba@1134: public: deba@1134: deba@1134: /// The edge observer registry. deba@1999: typedef AlterationNotifier deba@1999: EdgeNotifier; deba@1134: /// The node observer registry. deba@1999: typedef AlterationNotifier deba@1999: NodeNotifier; deba@1134: deba@1134: /// \brief Gives back the edge alteration notifier. deba@1134: /// deba@1134: /// Gives back the edge alteration notifier. deba@1134: EdgeNotifier getNotifier(Edge) const { deba@1134: return EdgeNotifier(); deba@1134: } deba@1134: deba@1134: /// \brief Gives back the node alteration notifier. deba@1134: /// deba@1134: /// Gives back the node alteration notifier. deba@1134: NodeNotifier getNotifier(Node) const { deba@1134: return NodeNotifier(); deba@1134: } deba@1134: deba@1134: }; deba@1134: klao@959: klao@1030: /// Class describing the concept of graph maps klao@1030: klao@1030: /// This class describes the common interface of the graph maps alpar@1631: /// (NodeMap, EdgeMap), that is \ref maps-page "maps" which can be used to klao@1030: /// associate data to graph descriptors (nodes or edges). deba@989: template deba@989: class GraphMap : public ReadWriteMap { deba@989: protected: deba@989: GraphMap() {} deba@989: public: deba@1134: /// \brief Construct a new map. deba@1134: /// deba@1134: /// Construct a new map for the graph. deba@989: explicit GraphMap(const Graph&) {} deba@1134: /// \brief Construct a new map with default value. deba@1134: /// deba@1134: /// Construct a new map for the graph and initalise the values. deba@989: GraphMap(const Graph&, const _Value&) {} deba@1134: /// \brief Copy constructor. deba@1134: /// deba@1134: /// Copy Constructor. alpar@1367: GraphMap(const GraphMap& gm) :ReadWriteMap(gm) {} deba@989: deba@1134: /// \brief Assign operator. deba@1134: /// deba@1134: /// Assign operator. deba@989: GraphMap& operator=(const GraphMap&) { return *this;} klao@959: deba@989: template deba@989: struct Constraints { deba@989: void constraints() { deba@989: checkConcept, _Map >(); deba@989: // Construction with a graph parameter deba@989: _Map a(g); deba@989: // Constructor with a graph and a default value parameter deba@989: _Map a2(g,t); deba@989: // Copy constructor. Do we need it? deba@989: _Map b=c; klao@959: deba@989: ignore_unused_variable_warning(a2); deba@989: } klao@959: deba@989: const _Map &c; deba@989: const Graph &g; deba@989: const typename GraphMap::Value &t; klao@959: }; klao@959: klao@959: }; klao@961: deba@989: /// An empty mappable base graph class. klao@959: deba@989: /// This class provides beside the core graph features deba@989: /// map interface for the graph structure. deba@989: /// This concept is part of the StaticGraphConcept. klao@959: class MappableGraphComponent : virtual public BaseGraphComponent { klao@959: public: klao@959: klao@959: typedef MappableGraphComponent Graph; klao@959: klao@959: typedef BaseGraphComponent::Node Node; klao@959: typedef BaseGraphComponent::Edge Edge; klao@959: deba@989: /// ReadWrite map of the nodes. deba@989: deba@989: /// ReadWrite map of the nodes. deba@989: /// alpar@987: template deba@989: class NodeMap : public GraphMap { deba@989: private: deba@989: NodeMap(); klao@959: public: deba@1134: /// \brief Construct a new map. deba@1134: /// deba@1134: /// Construct a new map for the graph. deba@1134: /// \todo call the right parent class constructor deba@989: explicit NodeMap(const Graph&) {} deba@1134: /// \brief Construct a new map with default value. deba@1134: /// deba@1134: /// Construct a new map for the graph and initalise the values. alpar@987: NodeMap(const Graph&, const _Value&) {} deba@1134: /// \brief Copy constructor. deba@1134: /// deba@1134: /// Copy Constructor. alpar@1367: NodeMap(const NodeMap& nm) : GraphMap(nm) {} klao@959: deba@1134: /// \brief Assign operator. deba@1134: /// deba@1134: /// Assign operator. klao@959: NodeMap& operator=(const NodeMap&) { return *this;} deba@989: klao@959: }; klao@959: deba@989: /// ReadWrite map of the edges. deba@989: deba@989: /// ReadWrite map of the edges. deba@989: /// alpar@987: template deba@989: class EdgeMap : public GraphMap { deba@989: private: deba@989: EdgeMap(); klao@959: public: deba@1134: /// \brief Construct a new map. deba@1134: /// deba@1134: /// Construct a new map for the graph. deba@1134: /// \todo call the right parent class constructor deba@989: explicit EdgeMap(const Graph&) {} deba@1134: /// \brief Construct a new map with default value. deba@1134: /// deba@1134: /// Construct a new map for the graph and initalise the values. alpar@987: EdgeMap(const Graph&, const _Value&) {} deba@1134: /// \brief Copy constructor. deba@1134: /// deba@1134: /// Copy Constructor. alpar@1367: EdgeMap(const EdgeMap& em) :GraphMap(em) {} klao@959: deba@1134: /// \brief Assign operator. deba@1134: /// deba@1134: /// Assign operator. klao@959: EdgeMap& operator=(const EdgeMap&) { return *this;} deba@989: klao@959: }; klao@959: deba@989: template deba@989: struct Constraints { klao@959: deba@989: struct Type { deba@989: int value; deba@989: Type() : value(0) {} deba@989: Type(int _v) : value(_v) {} deba@989: }; klao@959: deba@989: void constraints() { deba@989: checkConcept(); deba@989: { // int map test deba@989: typedef typename _Graph::template NodeMap IntNodeMap; deba@1134: checkConcept, deba@1134: IntNodeMap >(); deba@989: } { // bool map test deba@989: typedef typename _Graph::template NodeMap BoolNodeMap; deba@1134: checkConcept, deba@1134: BoolNodeMap >(); deba@989: } { // Type map test deba@989: typedef typename _Graph::template NodeMap TypeNodeMap; deba@1134: checkConcept, deba@1134: TypeNodeMap >(); deba@989: } deba@989: deba@989: { // int map test deba@989: typedef typename _Graph::template EdgeMap IntEdgeMap; deba@1134: checkConcept, deba@1134: IntEdgeMap >(); deba@989: } { // bool map test deba@989: typedef typename _Graph::template EdgeMap BoolEdgeMap; deba@1134: checkConcept, deba@1134: BoolEdgeMap >(); deba@989: } { // Type map test deba@989: typedef typename _Graph::template EdgeMap TypeEdgeMap; deba@1134: checkConcept, deba@1134: TypeEdgeMap >(); deba@989: } deba@989: } deba@989: deba@989: _Graph& graph; klao@959: }; klao@959: }; klao@959: deba@1134: /// \brief An empty extendable extended graph class. deba@1134: /// deba@1134: /// This class provides beside the core graph features deba@1134: /// item addition interface for the graph structure. deba@1134: /// The difference between this class and the deba@1134: /// \c BaseExtendableGraphComponent is that it should deba@1134: /// notify the item alteration observers. klao@959: class ExtendableGraphComponent : virtual public BaseGraphComponent { klao@959: public: klao@959: klao@959: typedef ExtendableGraphComponent Graph; klao@959: klao@959: typedef BaseGraphComponent::Node Node; klao@959: typedef BaseGraphComponent::Edge Edge; klao@959: deba@1134: /// \brief Add a node to the graph. deba@1134: /// deba@1134: /// Add a node to the graph and notify the observers. klao@959: Node addNode() { klao@959: return INVALID; klao@959: } klao@959: deba@1134: /// \brief Add an edge to the graph. deba@1134: /// deba@1134: /// Add an edge to the graph and notify the observers. alpar@1367: Edge addEdge(const Node&, const Node&) { klao@959: return INVALID; klao@959: } klao@959: deba@989: template deba@989: struct Constraints { deba@989: void constraints() { deba@989: checkConcept(); deba@989: typename _Graph::Node node_a, node_b; deba@989: node_a = graph.addNode(); alpar@1494: node_b = graph.addNode(); deba@989: typename _Graph::Edge edge; deba@989: edge = graph.addEdge(node_a, node_b); deba@989: } deba@989: _Graph& graph; deba@989: }; klao@959: }; deba@1134: deba@1134: /// \brief An empty erasable extended graph class. deba@1134: /// deba@1134: /// This class provides beside the core graph features deba@1134: /// item erase interface for the graph structure. deba@1134: /// The difference between this class and the deba@1134: /// \c BaseErasableGraphComponent is that it should deba@1134: /// notify the item alteration observers. klao@959: class ErasableGraphComponent : virtual public BaseGraphComponent { klao@959: public: klao@959: klao@959: typedef ErasableGraphComponent Graph; klao@959: klao@959: typedef BaseGraphComponent::Node Node; klao@959: typedef BaseGraphComponent::Edge Edge; klao@959: deba@1134: /// \brief Erase the Node and notify the node alteration observers. deba@1134: /// deba@1134: /// Erase the Node and notify the node alteration observers. klao@959: void erase(const Node&) {} deba@1134: deba@1134: /// \brief Erase the Edge and notify the edge alteration observers. deba@1134: /// deba@1134: /// Erase the Edge and notify the edge alteration observers. klao@959: void erase(const Edge&) {} klao@959: deba@989: template deba@989: struct Constraints { deba@989: void constraints() { deba@989: checkConcept(); deba@989: typename _Graph::Node node; deba@989: graph.erase(node); deba@989: typename _Graph::Edge edge; deba@989: graph.erase(edge); deba@989: } klao@959: deba@989: _Graph& graph; deba@989: }; klao@959: }; klao@959: klao@959: } klao@959: klao@959: } klao@959: klao@959: #endif