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: deba@2121: /// \brief Skeleton class for graph Node and Edge types deba@2121: /// 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@2121: /// \brief Default constructor. deba@2121: /// 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@2121: /// \brief Copy constructor. deba@2121: /// deba@989: /// Copy constructor. deba@989: /// deba@2121: GraphItem(const GraphItem &) {} deba@2121: /// \brief Invalid constructor \& conversion. deba@2121: /// deba@989: /// This constructor initializes the item to be invalid. deba@989: /// \sa Invalid for more details. klao@961: GraphItem(Invalid) {} deba@2121: /// \brief Assign operator for nodes. deba@2121: /// deba@989: /// The nodes are assignable. deba@989: /// klao@961: GraphItem& operator=(GraphItem const&) { return *this; } deba@2121: /// \brief Equality operator. deba@2121: /// 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@2121: /// \brief Inequality operator. deba@2121: /// deba@989: /// \sa operator==(const Node& n) deba@989: /// klao@961: bool operator!=(GraphItem) const { return false; } klao@961: deba@2121: /// \brief Artificial ordering operator. deba@2121: /// 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: 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@2121: b = (ia < ib); deba@989: } deba@989: deba@989: const _GraphItem &ia; deba@989: const _GraphItem &ib; deba@989: }; klao@961: }; klao@961: deba@2121: /// \brief An empty base graph class. deba@2121: /// 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 deba@2121: /// graph. It just provides types for nodes and edges and functions to deba@2121: /// get the source and the target of the edges. klao@959: class BaseGraphComponent { klao@959: public: klao@959: klao@959: typedef BaseGraphComponent Graph; klao@959: deba@2121: /// \brief Node class of the graph. deba@2121: /// klao@959: /// This class represents the Nodes of the graph. klao@959: /// deba@989: typedef GraphItem<'n'> Node; klao@959: deba@2121: /// \brief Edge class of the graph. deba@2121: /// klao@959: /// This class represents the Edges of the graph. klao@959: /// deba@989: typedef GraphItem<'e'> Edge; klao@959: deba@2121: /// \brief Gives back the target node of an edge. deba@2121: /// deba@2121: /// Gives back the target node of an edge. klao@959: /// alpar@986: Node target(const Edge&) const { return INVALID;} klao@959: deba@2121: /// \brief Gives back the source node of an edge. deba@2121: /// deba@2121: /// Gives back the source node of an edge. klao@959: /// alpar@986: Node source(const Edge&) const { return INVALID;} klao@959: deba@2121: /// \brief Gives back the opposite node on the given edge. deba@2121: /// deba@2121: /// Gives back the opposite node on the given edge. deba@2121: Node oppositeNode(const Node&, const Edge&) const { deba@2121: return INVALID; deba@2121: } 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@2121: n = graph.oppositeNode(n, e); deba@989: } deba@989: } klao@959: deba@989: const _Graph& graph; deba@989: }; klao@959: }; klao@959: deba@2121: /// \brief An empty base undirected graph class. deba@2121: /// deba@2121: /// This class provides the minimal set of features needed for an deba@2121: /// undirected graph structure. All undirected graph concepts have deba@2121: /// to be conform to this base graph. It just provides types for deba@2121: /// nodes, edges and undirected edges and functions to get the deba@2121: /// source and the target of the edges and undirected edges, deba@2121: /// conversion from edges to undirected edges and function to get deba@2121: /// both direction of the undirected edges. deba@2121: class BaseUGraphComponent : public BaseGraphComponent { deba@2121: public: deba@2121: typedef BaseGraphComponent::Node Node; deba@2121: typedef BaseGraphComponent::Edge Edge; deba@2121: /// \brief Undirected edge class of the graph. deba@2121: /// deba@2121: /// This class represents the undirected edges of the graph. deba@2121: /// The undirected graphs can be used as a directed graph which deba@2121: /// for each edge contains the opposite edge too so the graph is deba@2121: /// bidirected. The undirected edge represents two opposite deba@2121: /// directed edges. deba@2121: class UEdge : public GraphItem<'u'> { deba@2121: public: deba@2121: typedef GraphItem<'u'> Parent; deba@2121: /// \brief Default constructor. deba@2121: /// deba@2121: /// \warning The default constructor is not required to set deba@2121: /// the item to some well-defined value. So you should consider it deba@2121: /// as uninitialized. deba@2121: UEdge() {} deba@2121: /// \brief Copy constructor. deba@2121: /// deba@2121: /// Copy constructor. deba@2121: /// deba@2121: UEdge(const UEdge &) : Parent() {} deba@2121: /// \brief Invalid constructor \& conversion. deba@2121: /// deba@2121: /// This constructor initializes the item to be invalid. deba@2121: /// \sa Invalid for more details. deba@2121: UEdge(Invalid) {} deba@2121: /// \brief Converter from edge to undirected edge. deba@2121: /// deba@2121: /// Besides the core graph item functionality each edge should deba@2121: /// be convertible to the represented undirected edge. deba@2121: UEdge(const Edge&) {} deba@2121: }; deba@2121: deba@2121: /// \brief Returns the direction of the edge. deba@2121: /// deba@2121: /// Returns the direction of the edge. Each edge represents an deba@2121: /// undirected edge with a direction. It gives back the deba@2121: /// direction. deba@2121: bool direction(const Edge&) const { return true; } deba@2121: deba@2121: /// \brief Returns the directed edge. deba@2121: /// deba@2121: /// Returns the directed edge from its direction and the deba@2121: /// represented undirected edge. deba@2121: Edge direct(const UEdge&, bool) const { return INVALID;} deba@2121: deba@2121: /// \brief Returns the directed edge. deba@2121: /// deba@2121: /// Returns the directed edge from its source and the deba@2121: /// represented undirected edge. deba@2121: Edge direct(const UEdge&, const Node&) const { return INVALID;} deba@2121: deba@2121: /// \brief Returns the opposite edge. deba@2121: /// deba@2121: /// Returns the opposite edge. It is the edge representing the deba@2121: /// same undirected edge and has opposite direction. deba@2121: Edge oppositeEdge(const Edge&) const { return INVALID;} deba@2121: deba@2121: /// \brief Gives back the target node of an undirected edge. deba@2121: /// deba@2121: /// Gives back the target node of an undirected edge. The name deba@2121: /// target is a little confusing because the undirected edge deba@2121: /// does not have target but it just means that one of the end deba@2121: /// node. deba@2121: Node target(const UEdge&) const { return INVALID;} deba@2121: deba@2121: /// \brief Gives back the source node of an undirected edge. deba@2121: /// deba@2121: /// Gives back the source node of an undirected edge. The name deba@2121: /// source is a little confusing because the undirected edge deba@2121: /// does not have source but it just means that one of the end deba@2121: /// node. deba@2121: Node source(const UEdge&) const { return INVALID;} deba@2121: deba@2121: template deba@2121: struct Constraints { deba@2121: typedef typename _Graph::Node Node; deba@2121: typedef typename _Graph::Edge Edge; deba@2121: typedef typename _Graph::UEdge UEdge; deba@2121: deba@2121: void constraints() { deba@2121: checkConcept(); deba@2121: checkConcept, UEdge>(); deba@2121: { deba@2121: Node n; deba@2121: UEdge ue(INVALID); deba@2121: Edge e; deba@2121: n = graph.source(ue); deba@2121: n = graph.target(ue); deba@2121: e = graph.direct(ue, true); deba@2121: e = graph.direct(ue, n); deba@2121: e = graph.oppositeEdge(e); deba@2121: ue = e; deba@2121: bool d = graph.direction(e); deba@2121: ignore_unused_variable_warning(d); deba@2121: } deba@2121: } deba@2121: deba@2121: const _Graph& graph; deba@2121: }; deba@2121: deba@2121: }; deba@2121: deba@2121: /// \brief An empty iterable base graph class. deba@2121: /// 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. deba@2121: template deba@2121: class BaseIterableGraphComponent : public _Base { klao@959: public: klao@959: deba@2121: typedef _Base Base; deba@2121: typedef typename Base::Node Node; deba@2121: typedef typename Base::Edge Edge; klao@959: deba@2121: /// \brief Gives back the first node in the iterating order. deba@2121: /// deba@2121: /// Gives back the first node in the iterating order. klao@959: /// klao@959: void first(Node&) const {} klao@959: deba@2121: /// \brief Gives back the next node in the iterating order. deba@2121: /// deba@2121: /// Gives back the next node in the iterating order. klao@959: /// klao@959: void next(Node&) const {} klao@959: deba@2121: /// \brief Gives back the first edge in the iterating order. deba@2121: /// deba@2121: /// Gives back the first edge in the iterating order. klao@959: /// klao@959: void first(Edge&) const {} deba@2121: deba@2121: /// \brief Gives back the next edge in the iterating order. deba@2121: /// deba@2121: /// Gives back the next edge in the iterating order. klao@959: /// klao@959: void next(Edge&) const {} klao@959: klao@959: deba@2121: /// \brief Gives back the first of the edges point to the given deba@2121: /// node. deba@2121: /// deba@2121: /// Gives back the first of the edges point to the given node. klao@959: /// klao@959: void firstIn(Edge&, const Node&) const {} klao@959: deba@2121: /// \brief Gives back the next of the edges points to the given deba@2121: /// node. deba@2121: /// deba@2121: /// Gives back the next of the edges points to the given node. klao@959: /// klao@959: void nextIn(Edge&) const {} klao@959: deba@2121: /// \brief Gives back the first of the edges start from the deba@2121: /// given node. deba@2121: /// deba@2121: /// Gives back the first of the edges start from the given node. klao@959: /// klao@959: void firstOut(Edge&, const Node&) const {} klao@959: deba@2121: /// \brief Gives back the next of the edges start from the given deba@2121: /// node. deba@2121: /// deba@2121: /// 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: deba@2121: /// \brief An empty iterable base undirected graph class. deba@2121: /// deba@2121: /// This class provides beside the core undirceted graph features deba@2121: /// core iterable interface for the undirected graph structure. deba@2121: /// Most of the base undirected graphs should be conform to this deba@2121: /// concept. deba@2121: template deba@2121: class BaseIterableUGraphComponent deba@2121: : public BaseIterableGraphComponent<_Base> { deba@2121: public: deba@2121: deba@2121: typedef _Base Base; deba@2121: typedef typename Base::UEdge UEdge; deba@2121: typedef typename Base::Node Node; deba@2121: deba@2121: using BaseIterableGraphComponent<_Base>::first; deba@2121: using BaseIterableGraphComponent<_Base>::next; deba@2121: deba@2121: /// \brief Gives back the first undirected edge in the iterating deba@2121: /// order. deba@2121: /// deba@2121: /// Gives back the first undirected edge in the iterating order. deba@2121: /// deba@2121: void first(UEdge&) const {} deba@2121: deba@2121: /// \brief Gives back the next undirected edge in the iterating deba@2121: /// order. deba@2121: /// deba@2121: /// Gives back the next undirected edge in the iterating order. deba@2121: /// deba@2121: void next(UEdge&) const {} deba@2121: deba@2121: deba@2121: /// \brief Gives back the first of the undirected edges from the deba@2121: /// given node. deba@2121: /// deba@2121: /// Gives back the first of the undirected edges from the given deba@2121: /// node. The bool parameter gives back that direction which deba@2121: /// gives a good direction of the uedge so the source of the deba@2121: /// directed edge is the given node. deba@2121: void firstInc(UEdge&, bool&, const Node&) const {} deba@2121: deba@2121: /// \brief Gives back the next of the undirected edges from the deba@2121: /// given node. deba@2121: /// deba@2121: /// Gives back the next of the undirected edges from the given deba@2121: /// node. The bool parameter should be used as the \c firstInc() deba@2121: /// use it. deba@2121: void nextInc(UEdge&, bool&) const {} deba@2121: deba@2121: template deba@2121: struct Constraints { deba@2121: deba@2121: void constraints() { deba@2121: checkConcept(); deba@2121: checkConcept, _Graph>(); deba@2121: typename _Graph::Node node; deba@2121: typename _Graph::UEdge uedge; deba@2121: bool dir; deba@2121: { deba@2121: graph.first(uedge); deba@2121: graph.next(uedge); deba@2121: } deba@2121: { deba@2121: graph.firstInc(uedge, dir, node); deba@2121: graph.nextInc(uedge, dir); deba@2121: } deba@2121: } deba@2121: deba@2121: const _Graph& graph; deba@2121: }; deba@2121: }; deba@2121: deba@2121: /// \brief An empty idable base graph class. deba@2121: /// 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. deba@2121: template deba@2121: class IDableGraphComponent : public _Base { klao@959: public: klao@959: deba@2121: typedef _Base Base; deba@2121: typedef typename Base::Node Node; deba@2121: typedef typename Base::Edge Edge; klao@959: deba@2121: /// \brief Gives back an unique integer id for the Node. deba@2121: /// 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. deba@2121: Node nodeFromId(int) 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. deba@2121: Edge edgeFromId(int) const { return INVALID;} deba@2121: deba@2121: /// \brief Gives back an integer greater or equal to the maximum deba@2121: /// Node id. deba@2121: /// deba@2121: /// Gives back an integer greater or equal to the maximum Node deba@2121: /// id. deba@2121: int maxNodeId() const { return -1;} deba@2121: deba@2121: /// \brief Gives back an integer greater or equal to the maximum deba@2121: /// Edge id. deba@2121: /// deba@2121: /// Gives back an integer greater or equal to the maximum Edge deba@2121: /// id. deba@2121: int maxEdgeId() const { return -1;} 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@2121: node = graph.nodeFromId(nid); deba@989: typename _Graph::Edge edge; deba@989: int eid = graph.id(edge); deba@989: eid = graph.id(edge); deba@2121: edge = graph.edgeFromId(eid); deba@2121: deba@2121: nid = graph.maxNodeId(); deba@2121: ignore_unused_variable_warning(nid); deba@2121: eid = graph.maxEdgeId(); deba@2121: ignore_unused_variable_warning(eid); deba@989: } klao@959: deba@989: const _Graph& graph; deba@989: }; klao@959: }; klao@959: deba@2121: /// \brief An empty idable base undirected graph class. deba@2121: /// deba@2121: /// This class provides beside the core undirected graph features deba@2121: /// core id functions for the undirected graph structure. The deba@2121: /// most of the base undirected graphs should be conform to this deba@2121: /// concept. The id's are unique and immutable. deba@2121: template deba@2121: class IDableUGraphComponent : public IDableGraphComponent<_Base> { klao@959: public: klao@959: deba@2121: typedef _Base Base; deba@2121: typedef typename Base::UEdge UEdge; klao@959: deba@2121: using IDableGraphComponent<_Base>::id; deba@2121: deba@2121: /// \brief Gives back an unique integer id for the UEdge. klao@959: /// deba@2121: /// Gives back an unique integer id for the UEdge. deba@2121: /// deba@2121: int id(const UEdge&) const { return -1;} klao@959: deba@2121: /// \brief Gives back the undirected edge by the unique id. deba@2121: /// deba@2121: /// Gives back the undirected edge by the unique id. If the deba@2121: /// graph does not contain edge with the given id then the deba@2121: /// result of the function is undetermined. deba@2121: UEdge uEdgeFromId(int) const { return INVALID;} klao@959: deba@2121: /// \brief Gives back an integer greater or equal to the maximum deba@2121: /// UEdge id. klao@959: /// deba@2121: /// Gives back an integer greater or equal to the maximum UEdge deba@2121: /// id. deba@2121: int maxUEdgeId() const { return -1;} klao@959: deba@989: template deba@989: struct Constraints { klao@959: deba@989: void constraints() { deba@2121: checkConcept(); deba@2121: checkConcept, _Graph >(); deba@2121: typename _Graph::UEdge uedge; deba@2121: int ueid = graph.id(uedge); deba@2121: ueid = graph.id(uedge); deba@2121: uedge = graph.uEdgeFromId(ueid); deba@2121: ueid = graph.maxUEdgeId(); deba@2121: ignore_unused_variable_warning(ueid); deba@989: } deba@2121: deba@989: const _Graph& graph; deba@989: }; klao@959: }; klao@959: deba@2121: /// \brief An empty extendable base graph class. deba@2121: /// 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. deba@2121: template deba@2121: class BaseExtendableGraphComponent : public _Base { klao@959: public: klao@959: deba@2121: typedef typename _Base::Node Node; deba@2121: typedef typename _Base::Edge Edge; klao@959: deba@2121: /// \brief Adds a new node to the graph. deba@2121: /// deba@2121: /// Adds a new node to the graph. klao@959: /// klao@959: Node addNode() { klao@959: return INVALID; klao@959: } klao@959: deba@2121: /// \brief Adds a new edge connects the given two nodes. klao@959: /// deba@2121: /// Adds a new edge connects the the given two nodes. 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: 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: deba@2121: /// \brief An empty extendable base undirected graph class. deba@2121: /// deba@2121: /// This class provides beside the core undirected graph features deba@2121: /// core undircted graph extend interface for the graph structure. deba@2121: /// The most of the base graphs should be conform to this concept. deba@2121: template deba@2121: class BaseExtendableUGraphComponent : public _Base { deba@2121: public: deba@2121: deba@2121: typedef typename _Base::Node Node; deba@2121: typedef typename _Base::UEdge UEdge; deba@2121: deba@2121: /// \brief Adds a new node to the graph. deba@2121: /// deba@2121: /// Adds a new node to the graph. deba@2121: /// deba@2121: Node addNode() { deba@2121: return INVALID; deba@2121: } deba@2121: deba@2121: /// \brief Adds a new edge connects the given two nodes. deba@2121: /// deba@2121: /// Adds a new edge connects the the given two nodes. deba@2121: UEdge addEdge(const Node&, const Node&) { deba@2121: return INVALID; deba@2121: } deba@2121: deba@2121: template deba@2121: struct Constraints { deba@2121: void constraints() { deba@2121: typename _Graph::Node node_a, node_b; deba@2121: node_a = graph.addNode(); deba@2121: node_b = graph.addNode(); deba@2121: typename _Graph::UEdge uedge; deba@2121: uedge = graph.addUEdge(node_a, node_b); deba@2121: } deba@2121: deba@2121: _Graph& graph; deba@2121: }; deba@2121: }; deba@2121: deba@2121: /// \brief An empty erasable base graph class. deba@2121: /// 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. deba@2121: template deba@2121: class BaseErasableGraphComponent : public _Base { klao@959: public: klao@959: deba@2121: typedef _Base Base; deba@2121: typedef typename Base::Node Node; deba@2121: typedef typename Base::Edge Edge; klao@959: deba@2121: /// \brief Erase a node from the graph. deba@2121: /// deba@2121: /// 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: deba@2121: /// \brief Erase an edge from the graph. deba@2121: /// deba@2121: /// 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: 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: deba@2121: /// \brief An empty erasable base undirected graph class. deba@2121: /// deba@2121: /// This class provides beside the core undirected graph features deba@2121: /// core erase functions for the undirceted graph structure. deba@2121: template deba@2121: class BaseErasableUGraphComponent : public _Base { deba@2121: public: deba@2121: deba@2121: typedef _Base Base; deba@2121: typedef typename Base::Node Node; deba@2121: typedef typename Base::UEdge UEdge; deba@2121: deba@2121: /// \brief Erase a node from the graph. deba@2121: /// deba@2121: /// Erase a node from the graph. This function should not deba@2121: /// erase edges connecting to the Node. deba@2121: void erase(const Node&) {} deba@2121: deba@2121: /// \brief Erase an edge from the graph. deba@2121: /// deba@2121: /// Erase an edge from the graph. deba@2121: /// deba@2121: void erase(const UEdge&) {} deba@2121: deba@2121: template deba@2121: struct Constraints { deba@2121: void constraints() { deba@2121: typename _Graph::Node node; deba@2121: graph.erase(node); deba@2121: typename _Graph::Edge edge; deba@2121: graph.erase(edge); deba@2121: } deba@2121: deba@2121: _Graph& graph; deba@2121: }; deba@2121: }; deba@2121: deba@2121: /// \brief An empty clearable base graph class. deba@2121: /// 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. deba@2121: template deba@2121: class BaseClearableGraphComponent : public _Base { klao@959: public: klao@959: deba@2121: /// \brief Erase all the nodes and edges from the graph. deba@2121: /// deba@2121: /// 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() { deba@989: graph.clear(); deba@989: } deba@989: klao@1022: _Graph graph; deba@989: }; klao@959: }; klao@959: deba@2121: /// \brief An empty clearable base undirected graph class. deba@2121: /// deba@2121: /// This class provides beside the core undirected graph features deba@2121: /// core clear functions for the undirected graph structure. deba@2121: /// The most of the base graphs should be conform to this concept. deba@2121: template deba@2121: class BaseClearableUGraphComponent : public _Base { deba@2121: public: klao@959: deba@2121: /// \brief Erase all the nodes and undirected edges from the graph. deba@2121: /// deba@2121: /// Erase all the nodes and undirected edges from the graph. deba@2121: /// deba@2121: void clear() {} deba@989: deba@2121: template deba@2121: struct Constraints { deba@2121: void constraints() { deba@2121: graph.clear(); deba@2121: } deba@2121: deba@2121: _Graph graph; deba@2121: }; deba@2121: }; deba@2121: deba@2121: deba@2121: /// \brief Skeleton class for graph NodeIt and EdgeIt deba@2121: /// deba@989: /// Skeleton class for graph NodeIt and EdgeIt. klao@959: /// deba@989: template deba@2121: class GraphItemIt : public _Item { deba@989: public: deba@2121: /// \brief Default constructor. deba@2121: /// deba@989: /// @warning The default constructor sets the iterator deba@989: /// to an undefined value. deba@2121: GraphItemIt() {} deba@2121: /// \brief Copy constructor. deba@2121: /// deba@989: /// Copy constructor. deba@989: /// deba@2121: GraphItemIt(const GraphItemIt& ) {} deba@2121: /// \brief Sets the iterator to the first item. deba@2121: /// deba@989: /// Sets the iterator to the first item of \c the graph. deba@989: /// deba@2121: explicit GraphItemIt(const _Graph&) {} deba@2121: /// \brief Invalid constructor \& conversion. deba@2121: /// deba@989: /// This constructor initializes the item to be invalid. deba@989: /// \sa Invalid for more details. deba@2121: GraphItemIt(Invalid) {} deba@2121: /// \brief Assign operator for items. deba@2121: /// deba@989: /// The items are assignable. deba@989: /// deba@2121: GraphItemIt& operator=(const GraphItemIt&) { return *this; } deba@2121: /// \brief Next item. deba@2121: /// deba@989: /// Assign the iterator to the next item. deba@989: /// deba@2121: GraphItemIt& operator++() { return *this; } deba@2121: /// \brief Equality operator deba@2121: /// deba@989: /// Two iterators are equal if and only if they point to the deba@989: /// same object or both are invalid. deba@2121: bool operator==(const GraphItemIt&) const { return true;} deba@2121: /// \brief Inequality operator deba@2121: /// deba@989: /// \sa operator==(Node n) deba@989: /// deba@2121: bool operator!=(const GraphItemIt&) const { return true;} deba@989: deba@2121: template deba@989: struct Constraints { deba@989: void constraints() { deba@2121: _GraphItemIt it1(g); deba@2121: _GraphItemIt it2; deba@989: deba@989: it2 = ++it1; deba@989: ++it2 = it1; deba@989: ++(++it1); deba@2121: deba@989: _Item bi = it1; deba@989: bi = it2; deba@989: } deba@989: _Graph& g; deba@989: }; klao@959: }; klao@959: deba@2121: /// \brief Skeleton class for graph InEdgeIt and OutEdgeIt deba@2121: /// 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'. deba@2121: template deba@2121: class GraphIncIt : public _Item { deba@989: public: deba@2121: /// \brief Default constructor. deba@2121: /// deba@989: /// @warning The default constructor sets the iterator deba@989: /// to an undefined value. deba@2121: GraphIncIt() {} deba@2121: /// \brief Copy constructor. deba@2121: /// deba@989: /// Copy constructor. deba@989: /// deba@2121: GraphIncIt(GraphIncIt const& gi) : _Item(gi) {} deba@2121: /// \brief Sets the iterator to the first edge incoming into or outgoing deba@1134: /// from the node. deba@2121: /// deba@1134: /// Sets the iterator to the first edge incoming into or outgoing deba@1134: /// from the node. deba@989: /// deba@2121: explicit GraphIncIt(const _Graph&, const _Base&) {} deba@2121: /// \brief Invalid constructor \& conversion. deba@2121: /// deba@989: /// This constructor initializes the item to be invalid. deba@989: /// \sa Invalid for more details. deba@2121: GraphIncIt(Invalid) {} deba@2121: /// \brief Assign operator for iterators. deba@2121: /// deba@2121: /// The iterators are assignable. deba@2121: /// deba@2121: GraphIncIt& operator=(GraphIncIt const&) { return *this; } deba@2121: /// \brief Next item. deba@2121: /// deba@2121: /// Assign the iterator to the next item. deba@2121: /// deba@2121: GraphIncIt& operator++() { return *this; } deba@989: deba@2121: /// \brief 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@2121: bool operator==(const GraphIncIt&) const { return true;} klao@1021: deba@2121: /// \brief Inequality operator deba@2121: /// deba@989: /// \sa operator==(Node n) deba@989: /// deba@2121: bool operator!=(const GraphIncIt&) const { return true;} deba@989: deba@2121: template deba@989: struct Constraints { deba@989: void constraints() { deba@2121: checkConcept, _GraphIncIt>(); deba@2121: _GraphIncIt it1(graph, node); deba@2121: _GraphIncIt it2; deba@989: deba@989: it2 = ++it1; deba@989: ++it2 = it1; deba@989: ++(++it1); deba@2121: _Item e = it1; deba@989: e = it2; klao@1158: deba@989: } deba@989: deba@2121: _Item edge; deba@2121: _Base node; deba@2121: _Graph graph; deba@2121: _GraphIncIt it; deba@989: }; deba@989: }; klao@1021: klao@1021: deba@2121: /// \brief An empty iterable graph class. deba@2121: /// deba@989: /// This class provides beside the core graph features deba@989: /// iterator based iterable interface for the graph structure. deba@2111: /// This concept is part of the GraphConcept. deba@2121: template deba@2121: class IterableGraphComponent : public _Base { klao@959: klao@959: public: klao@959: deba@2121: typedef _Base Base; deba@2121: typedef typename Base::Node Node; deba@2121: typedef typename Base::Edge Edge; deba@2121: klao@959: typedef IterableGraphComponent Graph; klao@959: klao@959: deba@2121: /// \brief This iterator goes through each node. deba@2121: /// deba@989: /// This iterator goes through each node. deba@989: /// deba@2121: typedef GraphItemIt NodeIt; klao@959: deba@2121: /// \brief This iterator goes through each node. deba@2121: /// deba@989: /// This iterator goes through each node. deba@989: /// deba@2121: typedef GraphItemIt EdgeIt; klao@959: deba@2121: /// \brief This iterator goes trough the incoming edges of a node. deba@2121: /// deba@989: /// This iterator goes trough the \e inccoming edges of a certain node deba@989: /// of a graph. deba@2121: typedef GraphIncIt InEdgeIt; klao@959: deba@2121: /// \brief This iterator goes trough the outgoing edges of a node. deba@2121: /// deba@989: /// This iterator goes trough the \e outgoing edges of a certain node deba@989: /// of a graph. deba@2121: typedef GraphIncIt 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@2121: checkConcept(); deba@1563: deba@2121: checkConcept, deba@1563: typename _Graph::EdgeIt >(); deba@2121: checkConcept, deba@1563: typename _Graph::NodeIt >(); deba@2121: checkConcept, typename _Graph::InEdgeIt>(); deba@2121: checkConcept, typename _Graph::OutEdgeIt>(); deba@1627: deba@2121: typename _Graph::Node n; deba@2121: typename _Graph::InEdgeIt ieit(INVALID); deba@2121: typename _Graph::OutEdgeIt oeit(INVALID); deba@2121: n = graph.baseNode(ieit); deba@2121: n = graph.runningNode(ieit); deba@2121: n = graph.baseNode(oeit); deba@2121: n = graph.runningNode(oeit); deba@2121: ignore_unused_variable_warning(n); deba@2121: } deba@2121: deba@2121: const _Graph& graph; deba@2121: deba@2121: }; deba@2121: }; deba@2121: deba@2121: /// \brief An empty iterable undirected graph class. deba@2121: /// deba@2121: /// This class provides beside the core graph features iterator deba@2121: /// based iterable interface for the undirected graph structure. deba@2121: /// This concept is part of the GraphConcept. deba@2121: template deba@2121: class IterableUGraphComponent : public IterableGraphComponent<_Base> { deba@2121: public: deba@2121: deba@2121: typedef _Base Base; deba@2121: typedef typename Base::Node Node; deba@2121: typedef typename Base::Edge Edge; deba@2121: typedef typename Base::UEdge UEdge; deba@2121: deba@2121: deba@2121: typedef IterableUGraphComponent Graph; deba@2121: using IterableGraphComponent<_Base>::baseNode; deba@2121: using IterableGraphComponent<_Base>::runningNode; deba@2121: deba@2121: deba@2121: /// \brief This iterator goes through each node. deba@2121: /// deba@2121: /// This iterator goes through each node. deba@2121: typedef GraphItemIt UEdgeIt; deba@2121: /// \brief This iterator goes trough the incident edges of a deba@2121: /// node. deba@2121: /// deba@2121: /// This iterator goes trough the incident edges of a certain deba@2121: /// node of a graph. deba@2121: typedef GraphIncIt IncEdgeIt; deba@2121: /// \brief The base node of the iterator. deba@2121: /// deba@2121: /// Gives back the base node of the iterator. deba@2121: Node baseNode(const IncEdgeIt&) const { return INVALID; } deba@2121: deba@2121: /// \brief The running node of the iterator. deba@2121: /// deba@2121: /// Gives back the running node of the iterator. deba@2121: Node runningNode(const IncEdgeIt&) const { return INVALID; } deba@2121: deba@2121: template deba@2121: struct Constraints { deba@2121: void constraints() { deba@2121: checkConcept(); deba@2121: checkConcept, _Graph>(); deba@2121: deba@2121: checkConcept, deba@2121: typename _Graph::UEdgeIt >(); deba@2121: checkConcept, typename _Graph::IncEdgeIt>(); deba@2121: deba@2121: typename _Graph::Node n; deba@2121: typename _Graph::IncEdgeIt ueit(INVALID); deba@2121: n = graph.baseNode(ueit); deba@2121: n = graph.runningNode(ueit); deba@1563: } deba@1627: deba@1627: const _Graph& graph; deba@1627: deba@1563: }; deba@989: }; klao@959: deba@2121: /// \brief An empty alteration notifier graph class. deba@2121: /// deba@2121: /// This class provides beside the core graph features alteration deba@2121: /// notifier interface for the graph structure. This implements deba@2121: /// an observer-notifier pattern for each graph item. More deba@2121: /// obsevers can be registered into the notifier and whenever an deba@2121: /// alteration occured in the graph all the observers will deba@2121: /// notified about it. deba@2121: template deba@2121: class AlterableGraphComponent : public _Base { deba@1134: public: deba@1134: deba@2121: typedef _Base Base; deba@2121: typedef typename Base::Node Node; deba@2121: typedef typename Base::Edge Edge; deba@2121: deba@2121: deba@2121: /// The node observer registry. deba@2121: typedef AlterationNotifier deba@2121: NodeNotifier; deba@1134: /// The edge observer registry. deba@1999: typedef AlterationNotifier deba@1999: EdgeNotifier; deba@2121: deba@2121: /// \brief Gives back the node alteration notifier. deba@2121: /// deba@2121: /// Gives back the node alteration notifier. deba@2121: NodeNotifier& getNotifier(Node) const { deba@2121: return NodeNotifier(); deba@2121: } deba@1134: deba@1134: /// \brief Gives back the edge alteration notifier. deba@1134: /// deba@1134: /// Gives back the edge alteration notifier. deba@2121: EdgeNotifier& getNotifier(Edge) const { deba@1134: return EdgeNotifier(); deba@1134: } deba@2121: deba@2121: template deba@2121: struct Constraints { deba@2121: void constraints() { deba@2121: checkConcept(); deba@2121: typename _Graph::NodeNotifier& nn deba@2121: = graph.getNotifier(typename _Graph::Node()); deba@2121: deba@2121: typename _Graph::EdgeNotifier& en deba@2121: = graph.getNotifier(typename _Graph::Edge()); deba@2121: deba@2121: ignore_unused_variable_warning(nn); deba@2121: ignore_unused_variable_warning(en); deba@2121: } deba@2121: deba@2121: const _Graph& graph; deba@2121: deba@2121: }; deba@1134: deba@1134: }; deba@1134: deba@2121: /// \brief An empty alteration notifier undirected graph class. deba@2121: /// deba@2121: /// This class provides beside the core graph features alteration deba@2121: /// notifier interface for the graph structure. This implements deba@2121: /// an observer-notifier pattern for each graph item. More deba@2121: /// obsevers can be registered into the notifier and whenever an deba@2121: /// alteration occured in the graph all the observers will deba@2121: /// notified about it. deba@2121: template deba@2121: class AlterableUGraphComponent : public AlterableGraphComponent<_Base> { deba@2121: public: klao@959: deba@2121: typedef _Base Base; deba@2121: typedef typename Base::UEdge UEdge; klao@1030: deba@2121: deba@2121: /// The edge observer registry. deba@2121: typedef AlterationNotifier deba@2121: UEdgeNotifier; deba@2121: deba@2121: /// \brief Gives back the edge alteration notifier. deba@2121: /// deba@2121: /// Gives back the edge alteration notifier. deba@2121: UEdgeNotifier& getNotifier(UEdge) const { deba@2121: return UEdgeNotifier(); deba@2121: } deba@2121: deba@2121: template deba@2121: struct Constraints { deba@2121: void constraints() { deba@2121: checkConcept(); deba@2121: checkConcept(); deba@2121: typename _Graph::UEdgeNotifier& uen deba@2121: = graph.getNotifier(typename _Graph::UEdge()); deba@2121: ignore_unused_variable_warning(uen); deba@2121: } deba@2121: deba@2121: const _Graph& graph; deba@2121: deba@2121: }; deba@2121: deba@2121: }; deba@2121: deba@2121: deba@2121: /// \brief Class describing the concept of graph maps deba@2121: /// 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@2121: template deba@2121: class GraphMap : public ReadWriteMap<_Item, _Value> { deba@989: public: deba@2121: deba@2121: typedef ReadWriteMap<_Item, _Value> Parent; deba@2121: deba@2121: /// The graph type of the map. deba@2121: typedef _Graph Graph; deba@2121: /// The key type of the map. deba@2121: typedef _Item Key; deba@2121: /// The value type of the map. deba@2121: typedef _Value Value; deba@2121: 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@2121: GraphMap(const Graph&, const Value&) {} deba@1134: /// \brief Copy constructor. deba@1134: /// deba@1134: /// Copy Constructor. deba@2121: GraphMap(const GraphMap&) : Parent() {} deba@989: deba@1134: /// \brief Assign operator. deba@1134: /// deba@2121: /// Assign operator. It does not mofify the underlying graph, deba@2121: /// it just iterates on the current item set and set the map deba@2121: /// with the value returned by the assigned map. deba@2121: template deba@2121: GraphMap& operator=(const CMap&) { deba@2121: checkConcept, CMap>(); deba@2121: return *this; deba@2121: } klao@959: deba@989: template deba@989: struct Constraints { deba@989: void constraints() { deba@2121: 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@2121: // Copy constructor. deba@2121: _Map b(c); deba@2121: deba@2121: ReadMap cmap; deba@2121: b = cmap; klao@959: deba@989: ignore_unused_variable_warning(a2); deba@2121: ignore_unused_variable_warning(b); 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@2121: /// \brief An empty mappable graph class. deba@2121: /// deba@989: /// This class provides beside the core graph features deba@989: /// map interface for the graph structure. deba@2121: /// This concept is part of the Graph concept. deba@2121: template deba@2121: class MappableGraphComponent : public _Base { klao@959: public: klao@959: deba@2121: typedef _Base Base; deba@2121: typedef typename Base::Node Node; deba@2121: typedef typename Base::Edge Edge; deba@2121: klao@959: typedef MappableGraphComponent Graph; klao@959: deba@2121: /// \brief ReadWrite map of the nodes. deba@2121: /// deba@989: /// ReadWrite map of the nodes. deba@989: /// deba@2121: template deba@2121: class NodeMap : public GraphMap { deba@989: private: deba@989: NodeMap(); klao@959: public: deba@2121: typedef GraphMap Parent; deba@2121: 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@2121: explicit NodeMap(const Graph& graph) : Parent(graph) {} deba@2121: 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@2121: NodeMap(const Graph& graph, const Value& value) deba@2121: : Parent(graph, value) {} deba@2121: deba@1134: /// \brief Copy constructor. deba@1134: /// deba@1134: /// Copy Constructor. deba@2121: NodeMap(const NodeMap& nm) : Parent(nm) {} klao@959: deba@1134: /// \brief Assign operator. deba@1134: /// deba@1134: /// Assign operator. deba@2121: template deba@2121: NodeMap& operator=(const CMap&) { deba@2121: checkConcept, CMap>(); deba@2121: return *this; deba@2121: } deba@989: klao@959: }; klao@959: deba@2121: /// \brief ReadWrite map of the edges. deba@2121: /// deba@989: /// ReadWrite map of the edges. deba@989: /// deba@2121: template deba@2121: class EdgeMap : public GraphMap { deba@989: private: deba@989: EdgeMap(); klao@959: public: deba@2121: typedef GraphMap Parent; deba@2121: 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@2121: explicit EdgeMap(const Graph& graph) : Parent(graph) {} deba@2121: 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@2121: EdgeMap(const Graph& graph, const Value& value) deba@2121: : Parent(graph, value) {} deba@2121: deba@1134: /// \brief Copy constructor. deba@1134: /// deba@1134: /// Copy Constructor. deba@2121: EdgeMap(const EdgeMap& nm) : Parent(nm) {} klao@959: deba@1134: /// \brief Assign operator. deba@1134: /// deba@1134: /// Assign operator. deba@2121: template deba@2121: EdgeMap& operator=(const CMap&) { deba@2121: checkConcept, CMap>(); deba@2121: return *this; deba@2121: } deba@989: klao@959: }; klao@959: deba@2121: deba@989: template deba@989: struct Constraints { klao@959: deba@2121: struct Dummy { deba@989: int value; deba@2121: Dummy() : value(0) {} deba@2121: Dummy(int _v) : value(_v) {} deba@989: }; klao@959: deba@989: void constraints() { deba@2121: 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@2121: } { // Dummy map test deba@2121: typedef typename _Graph::template NodeMap DummyNodeMap; deba@2121: checkConcept, deba@2121: DummyNodeMap >(); 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@2121: } { // Dummy map test deba@2121: typedef typename _Graph::template EdgeMap DummyEdgeMap; deba@2121: checkConcept, deba@2121: DummyEdgeMap >(); deba@989: } deba@989: } deba@989: deba@989: _Graph& graph; klao@959: }; klao@959: }; klao@959: deba@2121: /// \brief An empty mappable base graph class. deba@2121: /// deba@2121: /// This class provides beside the core graph features deba@2121: /// map interface for the graph structure. deba@2121: /// This concept is part of the UGraph concept. deba@2121: template deba@2121: class MappableUGraphComponent : public MappableGraphComponent<_Base> { klao@959: public: klao@959: deba@2121: typedef _Base Base; deba@2121: typedef typename Base::UEdge UEdge; klao@959: deba@2121: typedef MappableUGraphComponent Graph; klao@959: deba@2121: /// \brief ReadWrite map of the uedges. deba@2121: /// deba@2121: /// ReadWrite map of the uedges. deba@2121: /// deba@2121: template deba@2121: class UEdgeMap : public GraphMap { deba@2121: public: deba@2121: typedef GraphMap Parent; deba@2111: deba@2121: /// \brief Construct a new map. deba@2121: /// deba@2121: /// Construct a new map for the graph. deba@2121: /// \todo call the right parent class constructor deba@2121: explicit UEdgeMap(const Graph& graph) : Parent(graph) {} klao@959: deba@2121: /// \brief Construct a new map with default value. deba@2121: /// deba@2121: /// Construct a new map for the graph and initalise the values. deba@2121: UEdgeMap(const Graph& graph, const Value& value) deba@2121: : Parent(graph, value) {} deba@2111: deba@2121: /// \brief Copy constructor. deba@2121: /// deba@2121: /// Copy Constructor. deba@2121: UEdgeMap(const UEdgeMap& nm) : Parent(nm) {} deba@2111: deba@2121: /// \brief Assign operator. deba@2121: /// deba@2121: /// Assign operator. deba@2121: template deba@2121: UEdgeMap& operator=(const CMap&) { deba@2121: checkConcept, CMap>(); deba@2121: return *this; deba@2121: } deba@2111: deba@2111: }; deba@2111: deba@2111: deba@2121: template deba@2111: struct Constraints { deba@2111: deba@2111: struct Dummy { deba@2111: int value; deba@2111: Dummy() : value(0) {} deba@2111: Dummy(int _v) : value(_v) {} deba@2111: }; deba@2111: deba@2111: void constraints() { deba@2121: checkConcept(); deba@2121: checkConcept, _Graph>(); deba@2111: deba@2121: { // int map test deba@2121: typedef typename _Graph::template UEdgeMap IntUEdgeMap; deba@2121: checkConcept, deba@2121: IntUEdgeMap >(); deba@2121: } { // bool map test deba@2121: typedef typename _Graph::template UEdgeMap BoolUEdgeMap; deba@2121: checkConcept, deba@2121: BoolUEdgeMap >(); deba@2121: } { // Dummy map test deba@2121: typedef typename _Graph::template UEdgeMap DummyUEdgeMap; deba@2121: checkConcept, deba@2121: DummyUEdgeMap >(); deba@2121: } deba@2121: } deba@2111: deba@2121: _Graph& graph; deba@2121: }; deba@2121: }; deba@2111: deba@2121: deba@2121: /// \brief An empty extendable graph class. deba@2121: /// deba@2121: /// This class provides beside the core graph features graph deba@2121: /// extendable interface for the graph structure. The main deba@2121: /// difference between the base and this interface is that the deba@2121: /// graph alterations should handled already on this level. deba@2121: template deba@2121: class ExtendableGraphComponent : public _Base { deba@2121: public: deba@2121: deba@2121: typedef typename _Base::Node Node; deba@2121: typedef typename _Base::Edge Edge; deba@2121: deba@2121: /// \brief Adds a new node to the graph. deba@2121: /// deba@2121: /// Adds a new node to the graph. deba@2121: /// deba@2121: Node addNode() { deba@2121: return INVALID; deba@2121: } deba@2121: deba@2121: /// \brief Adds a new edge connects the given two nodes. deba@2121: /// deba@2121: /// Adds a new edge connects the the given two nodes. deba@2121: Edge addEdge(const Node&, const Node&) { deba@2121: return INVALID; deba@2121: } deba@2121: deba@2121: template deba@2121: struct Constraints { deba@2121: void constraints() { deba@2121: typename _Graph::Node node_a, node_b; deba@2121: node_a = graph.addNode(); deba@2121: node_b = graph.addNode(); deba@2121: typename _Graph::Edge edge; deba@2121: edge = graph.addEdge(node_a, node_b); deba@2111: } deba@2121: deba@2121: _Graph& graph; deba@989: }; deba@2121: }; deba@2111: deba@2121: /// \brief An empty extendable base undirected graph class. deba@2121: /// deba@2121: /// This class provides beside the core undirected graph features deba@2121: /// core undircted graph extend interface for the graph structure. deba@2121: /// The main difference between the base and this interface is deba@2121: /// that the graph alterations should handled already on this deba@2121: /// level. deba@2121: template deba@2121: class ExtendableUGraphComponent : public _Base { deba@2121: public: deba@2121: deba@2121: typedef typename _Base::Node Node; deba@2121: typedef typename _Base::UEdge UEdge; deba@2121: deba@2121: /// \brief Adds a new node to the graph. deba@2121: /// deba@2121: /// Adds a new node to the graph. deba@2121: /// deba@2121: Node addNode() { deba@2121: return INVALID; deba@2121: } deba@2121: deba@2121: /// \brief Adds a new edge connects the given two nodes. deba@2121: /// deba@2121: /// Adds a new edge connects the the given two nodes. deba@2121: UEdge addEdge(const Node&, const Node&) { deba@2121: return INVALID; deba@2121: } deba@2121: deba@2121: template deba@2121: struct Constraints { deba@2121: void constraints() { deba@2121: typename _Graph::Node node_a, node_b; deba@2121: node_a = graph.addNode(); deba@2121: node_b = graph.addNode(); deba@2121: typename _Graph::UEdge uedge; deba@2121: uedge = graph.addUEdge(node_a, node_b); deba@2121: } deba@2121: deba@2121: _Graph& graph; deba@2121: }; deba@2121: }; deba@2121: deba@2121: /// \brief An empty erasable graph class. deba@2121: /// deba@2121: /// This class provides beside the core graph features core erase deba@2121: /// functions for the graph structure. The main difference between deba@2121: /// the base and this interface is that the graph alterations deba@2121: /// should handled already on this level. deba@2121: template deba@2121: class ErasableGraphComponent : public _Base { deba@2121: public: deba@2121: deba@2121: typedef _Base Base; deba@2121: typedef typename Base::Node Node; deba@2121: typedef typename Base::Edge Edge; deba@2121: deba@2121: /// \brief Erase a node from the graph. deba@2121: /// deba@2121: /// Erase a node from the graph. This function should deba@2121: /// erase all edges connecting to the node. deba@2121: void erase(const Node&) {} deba@2121: deba@2121: /// \brief Erase an edge from the graph. deba@2121: /// deba@2121: /// Erase an edge from the graph. deba@2121: /// deba@2121: void erase(const Edge&) {} deba@2121: deba@2121: template deba@2121: struct Constraints { deba@2121: void constraints() { deba@2121: typename _Graph::Node node; deba@2121: graph.erase(node); deba@2121: typename _Graph::Edge edge; deba@2121: graph.erase(edge); deba@2121: } deba@2121: deba@2121: _Graph& graph; deba@2121: }; deba@2121: }; deba@2121: deba@2121: /// \brief An empty erasable base undirected graph class. deba@2121: /// deba@2121: /// This class provides beside the core undirected graph features deba@2121: /// core erase functions for the undirceted graph structure. The deba@2121: /// main difference between the base and this interface is that deba@2121: /// the graph alterations should handled already on this level. deba@2121: template deba@2121: class ErasableUGraphComponent : public _Base { deba@2121: public: deba@2121: deba@2121: typedef _Base Base; deba@2121: typedef typename Base::Node Node; deba@2121: typedef typename Base::UEdge UEdge; deba@2121: deba@2121: /// \brief Erase a node from the graph. deba@2121: /// deba@2121: /// Erase a node from the graph. This function should erase deba@2121: /// edges connecting to the node. deba@2121: void erase(const Node&) {} deba@2121: deba@2121: /// \brief Erase an edge from the graph. deba@2121: /// deba@2121: /// Erase an edge from the graph. deba@2121: /// deba@2121: void erase(const UEdge&) {} deba@2121: deba@2121: template deba@2121: struct Constraints { deba@2121: void constraints() { deba@2121: typename _Graph::Node node; deba@2121: graph.erase(node); deba@2121: typename _Graph::Edge edge; deba@2121: graph.erase(edge); deba@2121: } deba@2121: deba@2121: _Graph& graph; deba@2121: }; deba@2121: }; deba@2121: deba@2121: /// \brief An empty clearable base graph class. deba@2121: /// deba@2121: /// This class provides beside the core graph features core clear deba@2121: /// functions for the graph structure. The main difference between deba@2121: /// the base and this interface is that the graph alterations deba@2121: /// should handled already on this level. deba@2121: template deba@2121: class ClearableGraphComponent : public _Base { deba@2121: public: deba@2121: deba@2121: /// \brief Erase all nodes and edges from the graph. deba@2121: /// deba@2121: /// Erase all nodes and edges from the graph. deba@2121: /// deba@2121: void clear() {} deba@2121: deba@2121: template deba@2121: struct Constraints { deba@2121: void constraints() { deba@2121: graph.clear(); deba@2121: } deba@2121: deba@2121: _Graph graph; deba@2121: }; deba@2121: }; deba@2121: deba@2121: /// \brief An empty clearable base undirected graph class. deba@2121: /// deba@2121: /// This class provides beside the core undirected graph features deba@2121: /// core clear functions for the undirected graph structure. The deba@2121: /// main difference between the base and this interface is that deba@2121: /// the graph alterations should handled already on this level. deba@2121: template deba@2121: class ClearableUGraphComponent : public _Base { deba@2121: public: deba@2121: deba@2121: /// \brief Erase all nodes and undirected edges from the graph. deba@2121: /// deba@2121: /// Erase all nodes and undirected edges from the graph. deba@2121: /// deba@2121: void clear() {} deba@2121: deba@2121: template deba@2121: struct Constraints { deba@2121: void constraints() { deba@2121: graph.clear(); deba@2121: } deba@2121: deba@2121: _Graph graph; deba@2121: }; klao@959: }; klao@959: klao@959: } klao@959: klao@959: } klao@959: klao@959: #endif