deba@2126: /* -*- C++ -*- deba@2126: * deba@2126: * This file is a part of LEMON, a generic C++ optimization library deba@2126: * deba@2126: * Copyright (C) 2003-2006 deba@2126: * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport deba@2126: * (Egervary Research Group on Combinatorial Optimization, EGRES). deba@2126: * deba@2126: * Permission to use, modify and distribute this software is granted deba@2126: * provided that this copyright notice appears in all copies. For deba@2126: * precise terms see the accompanying LICENSE file. deba@2126: * deba@2126: * This software is provided "AS IS" with no warranty of any kind, deba@2126: * express or implied, and with no claim as to its suitability for any deba@2126: * purpose. deba@2126: * deba@2126: */ deba@2126: deba@2126: ///\ingroup graph_concepts deba@2126: ///\file deba@2126: ///\brief The concept of the graph components. deba@2126: deba@2126: deba@2126: #ifndef LEMON_CONCEPT_GRAPH_COMPONENTS_H deba@2126: #define LEMON_CONCEPT_GRAPH_COMPONENTS_H deba@2126: deba@2126: #include deba@2126: #include deba@2126: deba@2126: #include deba@2126: deba@2126: namespace lemon { deba@2126: namespace concept { deba@2126: deba@2126: /// \brief Skeleton class for graph Node and Edge types deba@2126: /// deba@2126: /// This class describes the interface of Node and Edge (and UEdge deba@2126: /// in undirected graphs) subtypes of graph types. deba@2126: /// deba@2126: /// \note This class is a template class so that we can use it to deba@2126: /// create graph skeleton classes. The reason for this is than Node deba@2126: /// and Edge types should \em not derive from the same base class. deba@2126: /// For Node you should instantiate it with character 'n' and for Edge deba@2126: /// with 'e'. deba@2126: deba@2126: #ifndef DOXYGEN deba@2126: template deba@2126: #endif deba@2126: class GraphItem { deba@2126: public: deba@2126: /// \brief Default constructor. deba@2126: /// deba@2126: /// \warning The default constructor is not required to set deba@2126: /// the item to some well-defined value. So you should consider it deba@2126: /// as uninitialized. deba@2126: GraphItem() {} deba@2126: /// \brief Copy constructor. deba@2126: /// deba@2126: /// Copy constructor. deba@2126: /// deba@2126: GraphItem(const GraphItem &) {} deba@2126: /// \brief Invalid constructor \& conversion. deba@2126: /// deba@2126: /// This constructor initializes the item to be invalid. deba@2126: /// \sa Invalid for more details. deba@2126: GraphItem(Invalid) {} deba@2126: /// \brief Assign operator for nodes. deba@2126: /// deba@2126: /// The nodes are assignable. deba@2126: /// deba@2126: GraphItem& operator=(GraphItem const&) { return *this; } deba@2126: /// \brief Equality operator. deba@2126: /// deba@2126: /// Two iterators are equal if and only if they represents the deba@2126: /// same node in the graph or both are invalid. deba@2126: bool operator==(GraphItem) const { return false; } deba@2126: /// \brief Inequality operator. deba@2126: /// deba@2126: /// \sa operator==(const Node& n) deba@2126: /// deba@2126: bool operator!=(GraphItem) const { return false; } deba@2126: deba@2126: /// \brief Artificial ordering operator. deba@2126: /// deba@2126: /// To allow the use of graph descriptors as key type in std::map or deba@2126: /// similar associative container we require this. deba@2126: /// deba@2126: /// \note This operator only have to define some strict ordering of deba@2126: /// the items; this order has nothing to do with the iteration deba@2126: /// ordering of the items. deba@2126: bool operator<(GraphItem) const { return false; } deba@2126: deba@2126: template deba@2126: struct Constraints { deba@2126: void constraints() { deba@2126: _GraphItem i1; deba@2126: _GraphItem i2 = i1; deba@2126: _GraphItem i3 = INVALID; deba@2126: deba@2126: i1 = i2 = i3; deba@2126: deba@2126: bool b; deba@2126: // b = (ia == ib) && (ia != ib) && (ia < ib); deba@2126: b = (ia == ib) && (ia != ib); deba@2126: b = (ia == INVALID) && (ib != INVALID); deba@2126: b = (ia < ib); deba@2126: } deba@2126: deba@2126: const _GraphItem &ia; deba@2126: const _GraphItem &ib; deba@2126: }; deba@2126: }; deba@2126: deba@2126: /// \brief An empty base graph class. deba@2126: /// deba@2126: /// This class provides the minimal set of features needed for a graph deba@2126: /// structure. All graph concepts have to be conform to this base deba@2126: /// graph. It just provides types for nodes and edges and functions to deba@2126: /// get the source and the target of the edges. deba@2126: class BaseGraphComponent { deba@2126: public: deba@2126: deba@2126: typedef BaseGraphComponent Graph; deba@2126: deba@2126: /// \brief Node class of the graph. deba@2126: /// deba@2126: /// This class represents the Nodes of the graph. deba@2126: /// deba@2126: typedef GraphItem<'n'> Node; deba@2126: deba@2126: /// \brief Edge class of the graph. deba@2126: /// deba@2126: /// This class represents the Edges of the graph. deba@2126: /// deba@2126: typedef GraphItem<'e'> Edge; deba@2126: deba@2126: /// \brief Gives back the target node of an edge. deba@2126: /// deba@2126: /// Gives back the target node of an edge. deba@2126: /// deba@2126: Node target(const Edge&) const { return INVALID;} deba@2126: deba@2126: /// \brief Gives back the source node of an edge. deba@2126: /// deba@2126: /// Gives back the source node of an edge. deba@2126: /// deba@2126: Node source(const Edge&) const { return INVALID;} deba@2126: deba@2126: /// \brief Gives back the opposite node on the given edge. deba@2126: /// deba@2126: /// Gives back the opposite node on the given edge. deba@2126: Node oppositeNode(const Node&, const Edge&) const { deba@2126: return INVALID; deba@2126: } deba@2126: deba@2126: template deba@2126: struct Constraints { deba@2126: typedef typename _Graph::Node Node; deba@2126: typedef typename _Graph::Edge Edge; deba@2126: deba@2126: void constraints() { deba@2126: checkConcept, Node>(); deba@2126: checkConcept, Edge>(); deba@2126: { deba@2126: Node n; deba@2126: Edge e(INVALID); deba@2126: n = graph.source(e); deba@2126: n = graph.target(e); deba@2126: n = graph.oppositeNode(n, e); deba@2126: } deba@2126: } deba@2126: deba@2126: const _Graph& graph; deba@2126: }; deba@2126: }; deba@2126: deba@2126: /// \brief An empty base undirected graph class. deba@2126: /// deba@2126: /// This class provides the minimal set of features needed for an deba@2126: /// undirected graph structure. All undirected graph concepts have deba@2126: /// to be conform to this base graph. It just provides types for deba@2126: /// nodes, edges and undirected edges and functions to get the deba@2126: /// source and the target of the edges and undirected edges, deba@2126: /// conversion from edges to undirected edges and function to get deba@2126: /// both direction of the undirected edges. deba@2126: class BaseUGraphComponent : public BaseGraphComponent { deba@2126: public: deba@2126: typedef BaseGraphComponent::Node Node; deba@2126: typedef BaseGraphComponent::Edge Edge; deba@2126: /// \brief Undirected edge class of the graph. deba@2126: /// deba@2126: /// This class represents the undirected edges of the graph. deba@2126: /// The undirected graphs can be used as a directed graph which deba@2126: /// for each edge contains the opposite edge too so the graph is deba@2126: /// bidirected. The undirected edge represents two opposite deba@2126: /// directed edges. deba@2126: class UEdge : public GraphItem<'u'> { deba@2126: public: deba@2126: typedef GraphItem<'u'> Parent; deba@2126: /// \brief Default constructor. deba@2126: /// deba@2126: /// \warning The default constructor is not required to set deba@2126: /// the item to some well-defined value. So you should consider it deba@2126: /// as uninitialized. deba@2126: UEdge() {} deba@2126: /// \brief Copy constructor. deba@2126: /// deba@2126: /// Copy constructor. deba@2126: /// deba@2126: UEdge(const UEdge &) : Parent() {} deba@2126: /// \brief Invalid constructor \& conversion. deba@2126: /// deba@2126: /// This constructor initializes the item to be invalid. deba@2126: /// \sa Invalid for more details. deba@2126: UEdge(Invalid) {} deba@2126: /// \brief Converter from edge to undirected edge. deba@2126: /// deba@2126: /// Besides the core graph item functionality each edge should deba@2126: /// be convertible to the represented undirected edge. deba@2126: UEdge(const Edge&) {} deba@2126: }; deba@2126: deba@2126: /// \brief Returns the direction of the edge. deba@2126: /// deba@2126: /// Returns the direction of the edge. Each edge represents an deba@2126: /// undirected edge with a direction. It gives back the deba@2126: /// direction. deba@2126: bool direction(const Edge&) const { return true; } deba@2126: deba@2126: /// \brief Returns the directed edge. deba@2126: /// deba@2126: /// Returns the directed edge from its direction and the deba@2126: /// represented undirected edge. deba@2126: Edge direct(const UEdge&, bool) const { return INVALID;} deba@2126: deba@2126: /// \brief Returns the directed edge. deba@2126: /// deba@2126: /// Returns the directed edge from its source and the deba@2126: /// represented undirected edge. deba@2126: Edge direct(const UEdge&, const Node&) const { return INVALID;} deba@2126: deba@2126: /// \brief Returns the opposite edge. deba@2126: /// deba@2126: /// Returns the opposite edge. It is the edge representing the deba@2126: /// same undirected edge and has opposite direction. deba@2126: Edge oppositeEdge(const Edge&) const { return INVALID;} deba@2126: deba@2126: /// \brief Gives back the target node of an undirected edge. deba@2126: /// deba@2126: /// Gives back the target node of an undirected edge. The name deba@2126: /// target is a little confusing because the undirected edge deba@2126: /// does not have target but it just means that one of the end deba@2126: /// node. deba@2126: Node target(const UEdge&) const { return INVALID;} deba@2126: deba@2126: /// \brief Gives back the source node of an undirected edge. deba@2126: /// deba@2126: /// Gives back the source node of an undirected edge. The name deba@2126: /// source is a little confusing because the undirected edge deba@2126: /// does not have source but it just means that one of the end deba@2126: /// node. deba@2126: Node source(const UEdge&) const { return INVALID;} deba@2126: deba@2126: template deba@2126: struct Constraints { deba@2126: typedef typename _Graph::Node Node; deba@2126: typedef typename _Graph::Edge Edge; deba@2126: typedef typename _Graph::UEdge UEdge; deba@2126: deba@2126: void constraints() { deba@2126: checkConcept(); deba@2126: checkConcept, UEdge>(); deba@2126: { deba@2126: Node n; deba@2126: UEdge ue(INVALID); deba@2126: Edge e; deba@2126: n = graph.source(ue); deba@2126: n = graph.target(ue); deba@2126: e = graph.direct(ue, true); deba@2126: e = graph.direct(ue, n); deba@2126: e = graph.oppositeEdge(e); deba@2126: ue = e; deba@2126: bool d = graph.direction(e); deba@2126: ignore_unused_variable_warning(d); deba@2126: } deba@2126: } deba@2126: deba@2126: const _Graph& graph; deba@2126: }; deba@2126: deba@2126: }; deba@2126: deba@2126: /// \brief An empty iterable base graph class. deba@2126: /// deba@2126: /// This class provides beside the core graph features deba@2126: /// core iterable interface for the graph structure. deba@2126: /// Most of the base graphs should be conform to this concept. deba@2126: template deba@2126: class BaseIterableGraphComponent : public _Base { deba@2126: public: deba@2126: deba@2126: typedef _Base Base; deba@2126: typedef typename Base::Node Node; deba@2126: typedef typename Base::Edge Edge; deba@2126: deba@2126: /// \brief Gives back the first node in the iterating order. deba@2126: /// deba@2126: /// Gives back the first node in the iterating order. deba@2126: /// deba@2126: void first(Node&) const {} deba@2126: deba@2126: /// \brief Gives back the next node in the iterating order. deba@2126: /// deba@2126: /// Gives back the next node in the iterating order. deba@2126: /// deba@2126: void next(Node&) const {} deba@2126: deba@2126: /// \brief Gives back the first edge in the iterating order. deba@2126: /// deba@2126: /// Gives back the first edge in the iterating order. deba@2126: /// deba@2126: void first(Edge&) const {} deba@2126: deba@2126: /// \brief Gives back the next edge in the iterating order. deba@2126: /// deba@2126: /// Gives back the next edge in the iterating order. deba@2126: /// deba@2126: void next(Edge&) const {} deba@2126: deba@2126: deba@2126: /// \brief Gives back the first of the edges point to the given deba@2126: /// node. deba@2126: /// deba@2126: /// Gives back the first of the edges point to the given node. deba@2126: /// deba@2126: void firstIn(Edge&, const Node&) const {} deba@2126: deba@2126: /// \brief Gives back the next of the edges points to the given deba@2126: /// node. deba@2126: /// deba@2126: /// Gives back the next of the edges points to the given node. deba@2126: /// deba@2126: void nextIn(Edge&) const {} deba@2126: deba@2126: /// \brief Gives back the first of the edges start from the deba@2126: /// given node. deba@2126: /// deba@2126: /// Gives back the first of the edges start from the given node. deba@2126: /// deba@2126: void firstOut(Edge&, const Node&) const {} deba@2126: deba@2126: /// \brief Gives back the next of the edges start from the given deba@2126: /// node. deba@2126: /// deba@2126: /// Gives back the next of the edges start from the given node. deba@2126: /// deba@2126: void nextOut(Edge&) const {} deba@2126: deba@2126: deba@2126: template deba@2126: struct Constraints { deba@2126: deba@2126: void constraints() { deba@2126: checkConcept< BaseGraphComponent, _Graph >(); deba@2129: typename _Graph::Node node(INVALID); deba@2129: typename _Graph::Edge edge(INVALID); deba@2126: { deba@2126: graph.first(node); deba@2126: graph.next(node); deba@2126: } deba@2126: { deba@2126: graph.first(edge); deba@2126: graph.next(edge); deba@2126: } deba@2126: { deba@2126: graph.firstIn(edge, node); deba@2126: graph.nextIn(edge); deba@2126: } deba@2126: { deba@2126: graph.firstOut(edge, node); deba@2126: graph.nextOut(edge); deba@2126: } deba@2126: } deba@2126: deba@2126: const _Graph& graph; deba@2126: }; deba@2126: }; deba@2126: deba@2126: /// \brief An empty iterable base undirected graph class. deba@2126: /// deba@2126: /// This class provides beside the core undirceted graph features deba@2126: /// core iterable interface for the undirected graph structure. deba@2126: /// Most of the base undirected graphs should be conform to this deba@2126: /// concept. deba@2126: template deba@2126: class BaseIterableUGraphComponent deba@2126: : public BaseIterableGraphComponent<_Base> { deba@2126: public: deba@2126: deba@2126: typedef _Base Base; deba@2126: typedef typename Base::UEdge UEdge; deba@2126: typedef typename Base::Node Node; deba@2126: deba@2126: using BaseIterableGraphComponent<_Base>::first; deba@2126: using BaseIterableGraphComponent<_Base>::next; deba@2126: deba@2126: /// \brief Gives back the first undirected edge in the iterating deba@2126: /// order. deba@2126: /// deba@2126: /// Gives back the first undirected edge in the iterating order. deba@2126: /// deba@2126: void first(UEdge&) const {} deba@2126: deba@2126: /// \brief Gives back the next undirected edge in the iterating deba@2126: /// order. deba@2126: /// deba@2126: /// Gives back the next undirected edge in the iterating order. deba@2126: /// deba@2126: void next(UEdge&) const {} deba@2126: deba@2126: deba@2126: /// \brief Gives back the first of the undirected edges from the deba@2126: /// given node. deba@2126: /// deba@2126: /// Gives back the first of the undirected edges from the given deba@2126: /// node. The bool parameter gives back that direction which deba@2126: /// gives a good direction of the uedge so the source of the deba@2126: /// directed edge is the given node. deba@2126: void firstInc(UEdge&, bool&, const Node&) const {} deba@2126: deba@2126: /// \brief Gives back the next of the undirected edges from the deba@2126: /// given node. deba@2126: /// deba@2126: /// Gives back the next of the undirected edges from the given deba@2126: /// node. The bool parameter should be used as the \c firstInc() deba@2126: /// use it. deba@2126: void nextInc(UEdge&, bool&) const {} deba@2126: deba@2126: template deba@2126: struct Constraints { deba@2126: deba@2126: void constraints() { deba@2126: checkConcept(); deba@2126: checkConcept, _Graph>(); deba@2129: typename _Graph::Node node(INVALID); deba@2129: typename _Graph::UEdge uedge(INVALID); deba@2126: bool dir; deba@2126: { deba@2126: graph.first(uedge); deba@2126: graph.next(uedge); deba@2126: } deba@2126: { deba@2126: graph.firstInc(uedge, dir, node); deba@2126: graph.nextInc(uedge, dir); deba@2126: } deba@2126: } deba@2126: deba@2126: const _Graph& graph; deba@2126: }; deba@2126: }; deba@2126: deba@2126: /// \brief An empty idable base graph class. deba@2126: /// deba@2126: /// This class provides beside the core graph features deba@2126: /// core id functions for the graph structure. deba@2126: /// The most of the base graphs should be conform to this concept. deba@2126: /// The id's are unique and immutable. deba@2126: template deba@2126: class IDableGraphComponent : public _Base { deba@2126: public: deba@2126: deba@2126: typedef _Base Base; deba@2126: typedef typename Base::Node Node; deba@2126: typedef typename Base::Edge Edge; deba@2126: deba@2126: /// \brief Gives back an unique integer id for the Node. deba@2126: /// deba@2126: /// Gives back an unique integer id for the Node. deba@2126: /// deba@2126: int id(const Node&) const { return -1;} deba@2126: deba@2126: /// \brief Gives back the node by the unique id. deba@2126: /// deba@2126: /// Gives back the node by the unique id. deba@2126: /// If the graph does not contain node with the given id deba@2126: /// then the result of the function is undetermined. deba@2126: Node nodeFromId(int) const { return INVALID;} deba@2126: deba@2126: /// \brief Gives back an unique integer id for the Edge. deba@2126: /// deba@2126: /// Gives back an unique integer id for the Edge. deba@2126: /// deba@2126: int id(const Edge&) const { return -1;} deba@2126: deba@2126: /// \brief Gives back the edge by the unique id. deba@2126: /// deba@2126: /// Gives back the edge by the unique id. deba@2126: /// If the graph does not contain edge with the given id deba@2126: /// then the result of the function is undetermined. deba@2126: Edge edgeFromId(int) const { return INVALID;} deba@2126: deba@2126: /// \brief Gives back an integer greater or equal to the maximum deba@2126: /// Node id. deba@2126: /// deba@2126: /// Gives back an integer greater or equal to the maximum Node deba@2126: /// id. deba@2126: int maxNodeId() const { return -1;} deba@2126: deba@2126: /// \brief Gives back an integer greater or equal to the maximum deba@2126: /// Edge id. deba@2126: /// deba@2126: /// Gives back an integer greater or equal to the maximum Edge deba@2126: /// id. deba@2126: int maxEdgeId() const { return -1;} deba@2126: deba@2126: template deba@2126: struct Constraints { deba@2126: deba@2126: void constraints() { deba@2126: checkConcept< BaseGraphComponent, _Graph >(); deba@2126: typename _Graph::Node node; deba@2126: int nid = graph.id(node); deba@2126: nid = graph.id(node); deba@2126: node = graph.nodeFromId(nid); deba@2126: typename _Graph::Edge edge; deba@2126: int eid = graph.id(edge); deba@2126: eid = graph.id(edge); deba@2126: edge = graph.edgeFromId(eid); deba@2126: deba@2126: nid = graph.maxNodeId(); deba@2126: ignore_unused_variable_warning(nid); deba@2126: eid = graph.maxEdgeId(); deba@2126: ignore_unused_variable_warning(eid); deba@2126: } deba@2126: deba@2126: const _Graph& graph; deba@2126: }; deba@2126: }; deba@2126: deba@2126: /// \brief An empty idable base undirected graph class. deba@2126: /// deba@2126: /// This class provides beside the core undirected graph features deba@2126: /// core id functions for the undirected graph structure. The deba@2126: /// most of the base undirected graphs should be conform to this deba@2126: /// concept. The id's are unique and immutable. deba@2126: template deba@2126: class IDableUGraphComponent : public IDableGraphComponent<_Base> { deba@2126: public: deba@2126: deba@2126: typedef _Base Base; deba@2126: typedef typename Base::UEdge UEdge; deba@2126: deba@2126: using IDableGraphComponent<_Base>::id; deba@2126: deba@2126: /// \brief Gives back an unique integer id for the UEdge. deba@2126: /// deba@2126: /// Gives back an unique integer id for the UEdge. deba@2126: /// deba@2126: int id(const UEdge&) const { return -1;} deba@2126: deba@2126: /// \brief Gives back the undirected edge by the unique id. deba@2126: /// deba@2126: /// Gives back the undirected edge by the unique id. If the deba@2126: /// graph does not contain edge with the given id then the deba@2126: /// result of the function is undetermined. deba@2126: UEdge uEdgeFromId(int) const { return INVALID;} deba@2126: deba@2126: /// \brief Gives back an integer greater or equal to the maximum deba@2126: /// UEdge id. deba@2126: /// deba@2126: /// Gives back an integer greater or equal to the maximum UEdge deba@2126: /// id. deba@2126: int maxUEdgeId() const { return -1;} deba@2126: deba@2126: template deba@2126: struct Constraints { deba@2126: deba@2126: void constraints() { deba@2126: checkConcept(); deba@2126: checkConcept, _Graph >(); deba@2126: typename _Graph::UEdge uedge; deba@2126: int ueid = graph.id(uedge); deba@2126: ueid = graph.id(uedge); deba@2126: uedge = graph.uEdgeFromId(ueid); deba@2126: ueid = graph.maxUEdgeId(); deba@2126: ignore_unused_variable_warning(ueid); deba@2126: } deba@2126: deba@2126: const _Graph& graph; deba@2126: }; deba@2126: }; deba@2126: deba@2126: /// \brief An empty extendable base graph class. deba@2126: /// deba@2126: /// This class provides beside the core graph features deba@2126: /// core graph extend interface for the graph structure. deba@2126: /// The most of the base graphs should be conform to this concept. deba@2126: template deba@2126: class BaseExtendableGraphComponent : public _Base { deba@2126: public: deba@2126: deba@2126: typedef typename _Base::Node Node; deba@2126: typedef typename _Base::Edge Edge; deba@2126: deba@2126: /// \brief Adds a new node to the graph. deba@2126: /// deba@2126: /// Adds a new node to the graph. deba@2126: /// deba@2126: Node addNode() { deba@2126: return INVALID; deba@2126: } deba@2126: deba@2126: /// \brief Adds a new edge connects the given two nodes. deba@2126: /// deba@2126: /// Adds a new edge connects the the given two nodes. deba@2126: Edge addEdge(const Node&, const Node&) { deba@2126: return INVALID; deba@2126: } deba@2126: deba@2126: template deba@2126: struct Constraints { deba@2126: void constraints() { deba@2126: typename _Graph::Node node_a, node_b; deba@2126: node_a = graph.addNode(); deba@2126: node_b = graph.addNode(); deba@2126: typename _Graph::Edge edge; deba@2126: edge = graph.addEdge(node_a, node_b); deba@2126: } deba@2126: deba@2126: _Graph& graph; deba@2126: }; deba@2126: }; deba@2126: deba@2126: /// \brief An empty extendable base undirected graph class. deba@2126: /// deba@2126: /// This class provides beside the core undirected graph features deba@2126: /// core undircted graph extend interface for the graph structure. deba@2126: /// The most of the base graphs should be conform to this concept. deba@2126: template deba@2126: class BaseExtendableUGraphComponent : public _Base { deba@2126: public: deba@2126: deba@2126: typedef typename _Base::Node Node; deba@2126: typedef typename _Base::UEdge UEdge; deba@2126: deba@2126: /// \brief Adds a new node to the graph. deba@2126: /// deba@2126: /// Adds a new node to the graph. deba@2126: /// deba@2126: Node addNode() { deba@2126: return INVALID; deba@2126: } deba@2126: deba@2126: /// \brief Adds a new edge connects the given two nodes. deba@2126: /// deba@2126: /// Adds a new edge connects the the given two nodes. deba@2126: UEdge addEdge(const Node&, const Node&) { deba@2126: return INVALID; deba@2126: } deba@2126: deba@2126: template deba@2126: struct Constraints { deba@2126: void constraints() { deba@2126: typename _Graph::Node node_a, node_b; deba@2126: node_a = graph.addNode(); deba@2126: node_b = graph.addNode(); deba@2126: typename _Graph::UEdge uedge; deba@2126: uedge = graph.addUEdge(node_a, node_b); deba@2126: } deba@2126: deba@2126: _Graph& graph; deba@2126: }; deba@2126: }; deba@2126: deba@2126: /// \brief An empty erasable base graph class. deba@2126: /// deba@2126: /// This class provides beside the core graph features deba@2126: /// core erase functions for the graph structure. deba@2126: /// The most of the base graphs should be conform to this concept. deba@2126: template deba@2126: class BaseErasableGraphComponent : public _Base { deba@2126: public: deba@2126: deba@2126: typedef _Base Base; deba@2126: typedef typename Base::Node Node; deba@2126: typedef typename Base::Edge Edge; deba@2126: deba@2126: /// \brief Erase a node from the graph. deba@2126: /// deba@2126: /// Erase a node from the graph. This function should not deba@2126: /// erase edges connecting to the Node. deba@2126: void erase(const Node&) {} deba@2126: deba@2126: /// \brief Erase an edge from the graph. deba@2126: /// deba@2126: /// Erase an edge from the graph. deba@2126: /// deba@2126: void erase(const Edge&) {} deba@2126: deba@2126: template deba@2126: struct Constraints { deba@2126: void constraints() { deba@2126: typename _Graph::Node node; deba@2126: graph.erase(node); deba@2126: typename _Graph::Edge edge; deba@2126: graph.erase(edge); deba@2126: } deba@2126: deba@2126: _Graph& graph; deba@2126: }; deba@2126: }; deba@2126: deba@2126: /// \brief An empty erasable base undirected graph class. deba@2126: /// deba@2126: /// This class provides beside the core undirected graph features deba@2126: /// core erase functions for the undirceted graph structure. deba@2126: template deba@2126: class BaseErasableUGraphComponent : public _Base { deba@2126: public: deba@2126: deba@2126: typedef _Base Base; deba@2126: typedef typename Base::Node Node; deba@2126: typedef typename Base::UEdge UEdge; deba@2126: deba@2126: /// \brief Erase a node from the graph. deba@2126: /// deba@2126: /// Erase a node from the graph. This function should not deba@2126: /// erase edges connecting to the Node. deba@2126: void erase(const Node&) {} deba@2126: deba@2126: /// \brief Erase an edge from the graph. deba@2126: /// deba@2126: /// Erase an edge from the graph. deba@2126: /// deba@2126: void erase(const UEdge&) {} deba@2126: deba@2126: template deba@2126: struct Constraints { deba@2126: void constraints() { deba@2126: typename _Graph::Node node; deba@2126: graph.erase(node); deba@2126: typename _Graph::Edge edge; deba@2126: graph.erase(edge); deba@2126: } deba@2126: deba@2126: _Graph& graph; deba@2126: }; deba@2126: }; deba@2126: deba@2126: /// \brief An empty clearable base graph class. deba@2126: /// deba@2126: /// This class provides beside the core graph features deba@2126: /// core clear functions for the graph structure. deba@2126: /// The most of the base graphs should be conform to this concept. deba@2126: template deba@2126: class BaseClearableGraphComponent : public _Base { deba@2126: public: deba@2126: deba@2126: /// \brief Erase all the nodes and edges from the graph. deba@2126: /// deba@2126: /// Erase all the nodes and edges from the graph. deba@2126: /// deba@2126: void clear() {} deba@2126: deba@2126: template deba@2126: struct Constraints { deba@2126: void constraints() { deba@2126: graph.clear(); deba@2126: } deba@2126: deba@2126: _Graph graph; deba@2126: }; deba@2126: }; deba@2126: deba@2126: /// \brief An empty clearable base undirected graph class. deba@2126: /// deba@2126: /// This class provides beside the core undirected graph features deba@2126: /// core clear functions for the undirected graph structure. deba@2126: /// The most of the base graphs should be conform to this concept. deba@2126: template deba@2126: class BaseClearableUGraphComponent : public _Base { deba@2126: public: deba@2126: deba@2126: /// \brief Erase all the nodes and undirected edges from the graph. deba@2126: /// deba@2126: /// Erase all the nodes and undirected edges from the graph. deba@2126: /// deba@2126: void clear() {} deba@2126: deba@2126: template deba@2126: struct Constraints { deba@2126: void constraints() { deba@2126: graph.clear(); deba@2126: } deba@2126: deba@2126: _Graph graph; deba@2126: }; deba@2126: }; deba@2126: deba@2126: deba@2126: /// \brief Skeleton class for graph NodeIt and EdgeIt deba@2126: /// deba@2126: /// Skeleton class for graph NodeIt and EdgeIt. deba@2126: /// deba@2126: template deba@2126: class GraphItemIt : public _Item { deba@2126: public: deba@2126: /// \brief Default constructor. deba@2126: /// deba@2126: /// @warning The default constructor sets the iterator deba@2126: /// to an undefined value. deba@2126: GraphItemIt() {} deba@2126: /// \brief Copy constructor. deba@2126: /// deba@2126: /// Copy constructor. deba@2126: /// deba@2126: GraphItemIt(const GraphItemIt& ) {} deba@2126: /// \brief Sets the iterator to the first item. deba@2126: /// deba@2126: /// Sets the iterator to the first item of \c the graph. deba@2126: /// deba@2126: explicit GraphItemIt(const _Graph&) {} deba@2126: /// \brief Invalid constructor \& conversion. deba@2126: /// deba@2126: /// This constructor initializes the item to be invalid. deba@2126: /// \sa Invalid for more details. deba@2126: GraphItemIt(Invalid) {} deba@2126: /// \brief Assign operator for items. deba@2126: /// deba@2126: /// The items are assignable. deba@2126: /// deba@2126: GraphItemIt& operator=(const GraphItemIt&) { return *this; } deba@2126: /// \brief Next item. deba@2126: /// deba@2126: /// Assign the iterator to the next item. deba@2126: /// deba@2126: GraphItemIt& operator++() { return *this; } deba@2126: /// \brief Equality operator deba@2126: /// deba@2126: /// Two iterators are equal if and only if they point to the deba@2126: /// same object or both are invalid. deba@2126: bool operator==(const GraphItemIt&) const { return true;} deba@2126: /// \brief Inequality operator deba@2126: /// deba@2126: /// \sa operator==(Node n) deba@2126: /// deba@2126: bool operator!=(const GraphItemIt&) const { return true;} deba@2126: deba@2126: template deba@2126: struct Constraints { deba@2126: void constraints() { deba@2126: _GraphItemIt it1(g); deba@2126: _GraphItemIt it2; deba@2126: deba@2126: it2 = ++it1; deba@2126: ++it2 = it1; deba@2126: ++(++it1); deba@2126: deba@2126: _Item bi = it1; deba@2126: bi = it2; deba@2126: } deba@2126: _Graph& g; deba@2126: }; deba@2126: }; deba@2126: deba@2126: /// \brief Skeleton class for graph InEdgeIt and OutEdgeIt deba@2126: /// deba@2126: /// \note Because InEdgeIt and OutEdgeIt may not inherit from the same deba@2126: /// base class, the _selector is a additional template parameter. For deba@2126: /// InEdgeIt you should instantiate it with character 'i' and for deba@2126: /// OutEdgeIt with 'o'. deba@2126: template deba@2126: class GraphIncIt : public _Item { deba@2126: public: deba@2126: /// \brief Default constructor. deba@2126: /// deba@2126: /// @warning The default constructor sets the iterator deba@2126: /// to an undefined value. deba@2126: GraphIncIt() {} deba@2126: /// \brief Copy constructor. deba@2126: /// deba@2126: /// Copy constructor. deba@2126: /// deba@2126: GraphIncIt(GraphIncIt const& gi) : _Item(gi) {} deba@2126: /// \brief Sets the iterator to the first edge incoming into or outgoing deba@2126: /// from the node. deba@2126: /// deba@2126: /// Sets the iterator to the first edge incoming into or outgoing deba@2126: /// from the node. deba@2126: /// deba@2126: explicit GraphIncIt(const _Graph&, const _Base&) {} deba@2126: /// \brief Invalid constructor \& conversion. deba@2126: /// deba@2126: /// This constructor initializes the item to be invalid. deba@2126: /// \sa Invalid for more details. deba@2126: GraphIncIt(Invalid) {} deba@2126: /// \brief Assign operator for iterators. deba@2126: /// deba@2126: /// The iterators are assignable. deba@2126: /// deba@2126: GraphIncIt& operator=(GraphIncIt const&) { return *this; } deba@2126: /// \brief Next item. deba@2126: /// deba@2126: /// Assign the iterator to the next item. deba@2126: /// deba@2126: GraphIncIt& operator++() { return *this; } deba@2126: deba@2126: /// \brief Equality operator deba@2126: /// deba@2126: /// Two iterators are equal if and only if they point to the deba@2126: /// same object or both are invalid. deba@2126: bool operator==(const GraphIncIt&) const { return true;} deba@2126: deba@2126: /// \brief Inequality operator deba@2126: /// deba@2126: /// \sa operator==(Node n) deba@2126: /// deba@2126: bool operator!=(const GraphIncIt&) const { return true;} deba@2126: deba@2126: template deba@2126: struct Constraints { deba@2126: void constraints() { deba@2126: checkConcept, _GraphIncIt>(); deba@2126: _GraphIncIt it1(graph, node); deba@2126: _GraphIncIt it2; deba@2126: deba@2126: it2 = ++it1; deba@2126: ++it2 = it1; deba@2126: ++(++it1); deba@2126: _Item e = it1; deba@2126: e = it2; deba@2126: deba@2126: } deba@2126: deba@2126: _Item edge; deba@2126: _Base node; deba@2126: _Graph graph; deba@2126: _GraphIncIt it; deba@2126: }; deba@2126: }; deba@2126: deba@2126: deba@2126: /// \brief An empty iterable graph class. deba@2126: /// deba@2126: /// This class provides beside the core graph features deba@2126: /// iterator based iterable interface for the graph structure. deba@2126: /// This concept is part of the GraphConcept. deba@2126: template deba@2126: class IterableGraphComponent : public _Base { deba@2126: deba@2126: public: deba@2126: deba@2126: typedef _Base Base; deba@2126: typedef typename Base::Node Node; deba@2126: typedef typename Base::Edge Edge; deba@2126: deba@2126: typedef IterableGraphComponent Graph; deba@2126: deba@2126: deba@2126: /// \brief This iterator goes through each node. deba@2126: /// deba@2126: /// This iterator goes through each node. deba@2126: /// deba@2126: typedef GraphItemIt NodeIt; deba@2126: deba@2126: /// \brief This iterator goes through each node. deba@2126: /// deba@2126: /// This iterator goes through each node. deba@2126: /// deba@2126: typedef GraphItemIt EdgeIt; deba@2126: deba@2126: /// \brief This iterator goes trough the incoming edges of a node. deba@2126: /// deba@2126: /// This iterator goes trough the \e inccoming edges of a certain node deba@2126: /// of a graph. deba@2126: typedef GraphIncIt InEdgeIt; deba@2126: deba@2126: /// \brief This iterator goes trough the outgoing edges of a node. deba@2126: /// deba@2126: /// This iterator goes trough the \e outgoing edges of a certain node deba@2126: /// of a graph. deba@2126: typedef GraphIncIt OutEdgeIt; deba@2126: deba@2126: /// \brief The base node of the iterator. deba@2126: /// deba@2126: /// Gives back the base node of the iterator. deba@2126: /// It is always the target of the pointed edge. deba@2126: Node baseNode(const InEdgeIt&) const { return INVALID; } deba@2126: deba@2126: /// \brief The running node of the iterator. deba@2126: /// deba@2126: /// Gives back the running node of the iterator. deba@2126: /// It is always the source of the pointed edge. deba@2126: Node runningNode(const InEdgeIt&) const { return INVALID; } deba@2126: deba@2126: /// \brief The base node of the iterator. deba@2126: /// deba@2126: /// Gives back the base node of the iterator. deba@2126: /// It is always the source of the pointed edge. deba@2126: Node baseNode(const OutEdgeIt&) const { return INVALID; } deba@2126: deba@2126: /// \brief The running node of the iterator. deba@2126: /// deba@2126: /// Gives back the running node of the iterator. deba@2126: /// It is always the target of the pointed edge. deba@2126: Node runningNode(const OutEdgeIt&) const { return INVALID; } deba@2126: deba@2126: /// \brief The opposite node on the given edge. deba@2126: /// deba@2126: /// Gives back the opposite on the given edge. deba@2126: /// \todo It should not be here. deba@2126: Node oppositeNode(const Node&, const Edge&) const { return INVALID; } deba@2126: deba@2126: deba@2126: template deba@2126: struct Constraints { deba@2126: void constraints() { deba@2126: checkConcept(); deba@2126: deba@2126: checkConcept, deba@2126: typename _Graph::EdgeIt >(); deba@2126: checkConcept, deba@2126: typename _Graph::NodeIt >(); deba@2126: checkConcept, typename _Graph::InEdgeIt>(); deba@2126: checkConcept, typename _Graph::OutEdgeIt>(); deba@2126: deba@2126: typename _Graph::Node n; deba@2126: typename _Graph::InEdgeIt ieit(INVALID); deba@2126: typename _Graph::OutEdgeIt oeit(INVALID); deba@2126: n = graph.baseNode(ieit); deba@2126: n = graph.runningNode(ieit); deba@2126: n = graph.baseNode(oeit); deba@2126: n = graph.runningNode(oeit); deba@2126: ignore_unused_variable_warning(n); deba@2126: } deba@2126: deba@2126: const _Graph& graph; deba@2126: deba@2126: }; deba@2126: }; deba@2126: deba@2126: /// \brief An empty iterable undirected graph class. deba@2126: /// deba@2126: /// This class provides beside the core graph features iterator deba@2126: /// based iterable interface for the undirected graph structure. deba@2126: /// This concept is part of the GraphConcept. deba@2126: template deba@2126: class IterableUGraphComponent : public IterableGraphComponent<_Base> { deba@2126: public: deba@2126: deba@2126: typedef _Base Base; deba@2126: typedef typename Base::Node Node; deba@2126: typedef typename Base::Edge Edge; deba@2126: typedef typename Base::UEdge UEdge; deba@2126: deba@2126: deba@2126: typedef IterableUGraphComponent Graph; deba@2126: using IterableGraphComponent<_Base>::baseNode; deba@2126: using IterableGraphComponent<_Base>::runningNode; deba@2126: deba@2126: deba@2126: /// \brief This iterator goes through each node. deba@2126: /// deba@2126: /// This iterator goes through each node. deba@2126: typedef GraphItemIt UEdgeIt; deba@2126: /// \brief This iterator goes trough the incident edges of a deba@2126: /// node. deba@2126: /// deba@2126: /// This iterator goes trough the incident edges of a certain deba@2126: /// node of a graph. deba@2126: typedef GraphIncIt IncEdgeIt; deba@2126: /// \brief The base node of the iterator. deba@2126: /// deba@2126: /// Gives back the base node of the iterator. deba@2126: Node baseNode(const IncEdgeIt&) const { return INVALID; } deba@2126: deba@2126: /// \brief The running node of the iterator. deba@2126: /// deba@2126: /// Gives back the running node of the iterator. deba@2126: Node runningNode(const IncEdgeIt&) const { return INVALID; } deba@2126: deba@2126: template deba@2126: struct Constraints { deba@2126: void constraints() { deba@2126: checkConcept(); deba@2126: checkConcept, _Graph>(); deba@2126: deba@2126: checkConcept, deba@2126: typename _Graph::UEdgeIt >(); deba@2126: checkConcept, typename _Graph::IncEdgeIt>(); deba@2126: deba@2126: typename _Graph::Node n; deba@2126: typename _Graph::IncEdgeIt ueit(INVALID); deba@2126: n = graph.baseNode(ueit); deba@2126: n = graph.runningNode(ueit); deba@2126: } deba@2126: deba@2126: const _Graph& graph; deba@2126: deba@2126: }; deba@2126: }; deba@2126: deba@2126: /// \brief An empty alteration notifier graph class. deba@2126: /// deba@2126: /// This class provides beside the core graph features alteration deba@2126: /// notifier interface for the graph structure. This implements deba@2126: /// an observer-notifier pattern for each graph item. More deba@2126: /// obsevers can be registered into the notifier and whenever an deba@2126: /// alteration occured in the graph all the observers will deba@2126: /// notified about it. deba@2126: template deba@2126: class AlterableGraphComponent : public _Base { deba@2126: public: deba@2126: deba@2126: typedef _Base Base; deba@2126: typedef typename Base::Node Node; deba@2126: typedef typename Base::Edge Edge; deba@2126: deba@2126: deba@2126: /// The node observer registry. deba@2126: typedef AlterationNotifier deba@2126: NodeNotifier; deba@2126: /// The edge observer registry. deba@2126: typedef AlterationNotifier deba@2126: EdgeNotifier; deba@2126: deba@2126: /// \brief Gives back the node alteration notifier. deba@2126: /// deba@2126: /// Gives back the node alteration notifier. deba@2126: NodeNotifier& getNotifier(Node) const { deba@2126: return NodeNotifier(); deba@2126: } deba@2126: deba@2126: /// \brief Gives back the edge alteration notifier. deba@2126: /// deba@2126: /// Gives back the edge alteration notifier. deba@2126: EdgeNotifier& getNotifier(Edge) const { deba@2126: return EdgeNotifier(); deba@2126: } deba@2126: deba@2126: template deba@2126: struct Constraints { deba@2126: void constraints() { deba@2126: checkConcept(); deba@2126: typename _Graph::NodeNotifier& nn deba@2126: = graph.getNotifier(typename _Graph::Node()); deba@2126: deba@2126: typename _Graph::EdgeNotifier& en deba@2126: = graph.getNotifier(typename _Graph::Edge()); deba@2126: deba@2126: ignore_unused_variable_warning(nn); deba@2126: ignore_unused_variable_warning(en); deba@2126: } deba@2126: deba@2126: const _Graph& graph; deba@2126: deba@2126: }; deba@2126: deba@2126: }; deba@2126: deba@2126: /// \brief An empty alteration notifier undirected graph class. deba@2126: /// deba@2126: /// This class provides beside the core graph features alteration deba@2126: /// notifier interface for the graph structure. This implements deba@2126: /// an observer-notifier pattern for each graph item. More deba@2126: /// obsevers can be registered into the notifier and whenever an deba@2126: /// alteration occured in the graph all the observers will deba@2126: /// notified about it. deba@2126: template deba@2126: class AlterableUGraphComponent : public AlterableGraphComponent<_Base> { deba@2126: public: deba@2126: deba@2126: typedef _Base Base; deba@2126: typedef typename Base::UEdge UEdge; deba@2126: deba@2126: deba@2126: /// The edge observer registry. deba@2126: typedef AlterationNotifier deba@2126: UEdgeNotifier; deba@2126: deba@2126: /// \brief Gives back the edge alteration notifier. deba@2126: /// deba@2126: /// Gives back the edge alteration notifier. deba@2126: UEdgeNotifier& getNotifier(UEdge) const { deba@2126: return UEdgeNotifier(); deba@2126: } deba@2126: deba@2126: template deba@2126: struct Constraints { deba@2126: void constraints() { deba@2126: checkConcept(); deba@2126: checkConcept(); deba@2126: typename _Graph::UEdgeNotifier& uen deba@2126: = graph.getNotifier(typename _Graph::UEdge()); deba@2126: ignore_unused_variable_warning(uen); deba@2126: } deba@2126: deba@2126: const _Graph& graph; deba@2126: deba@2126: }; deba@2126: deba@2126: }; deba@2126: deba@2126: deba@2126: /// \brief Class describing the concept of graph maps deba@2126: /// deba@2126: /// This class describes the common interface of the graph maps deba@2126: /// (NodeMap, EdgeMap), that is \ref maps-page "maps" which can be used to deba@2126: /// associate data to graph descriptors (nodes or edges). deba@2126: template deba@2126: class GraphMap : public ReadWriteMap<_Item, _Value> { deba@2126: public: deba@2126: deba@2126: typedef ReadWriteMap<_Item, _Value> Parent; deba@2126: deba@2126: /// The graph type of the map. deba@2126: typedef _Graph Graph; deba@2126: /// The key type of the map. deba@2126: typedef _Item Key; deba@2126: /// The value type of the map. deba@2126: typedef _Value Value; deba@2126: deba@2126: /// \brief Construct a new map. deba@2126: /// deba@2126: /// Construct a new map for the graph. deba@2126: explicit GraphMap(const Graph&) {} deba@2126: /// \brief Construct a new map with default value. deba@2126: /// deba@2126: /// Construct a new map for the graph and initalise the values. deba@2126: GraphMap(const Graph&, const Value&) {} deba@2126: /// \brief Copy constructor. deba@2126: /// deba@2126: /// Copy Constructor. deba@2126: GraphMap(const GraphMap&) : Parent() {} deba@2126: deba@2126: /// \brief Assign operator. deba@2126: /// deba@2126: /// Assign operator. It does not mofify the underlying graph, deba@2126: /// it just iterates on the current item set and set the map deba@2126: /// with the value returned by the assigned map. deba@2126: template deba@2126: GraphMap& operator=(const CMap&) { deba@2126: checkConcept, CMap>(); deba@2126: return *this; deba@2126: } deba@2126: deba@2126: template deba@2126: struct Constraints { deba@2126: void constraints() { deba@2126: checkConcept, _Map >(); deba@2126: // Construction with a graph parameter deba@2126: _Map a(g); deba@2126: // Constructor with a graph and a default value parameter deba@2126: _Map a2(g,t); deba@2126: // Copy constructor. deba@2126: _Map b(c); deba@2126: deba@2126: ReadMap cmap; deba@2126: b = cmap; deba@2126: deba@2126: ignore_unused_variable_warning(a2); deba@2126: ignore_unused_variable_warning(b); deba@2126: } deba@2126: deba@2126: const _Map &c; deba@2126: const Graph &g; deba@2126: const typename GraphMap::Value &t; deba@2126: }; deba@2126: deba@2126: }; deba@2126: deba@2126: /// \brief An empty mappable graph class. deba@2126: /// deba@2126: /// This class provides beside the core graph features deba@2126: /// map interface for the graph structure. deba@2126: /// This concept is part of the Graph concept. deba@2126: template deba@2126: class MappableGraphComponent : public _Base { deba@2126: public: deba@2126: deba@2126: typedef _Base Base; deba@2126: typedef typename Base::Node Node; deba@2126: typedef typename Base::Edge Edge; deba@2126: deba@2126: typedef MappableGraphComponent Graph; deba@2126: deba@2126: /// \brief ReadWrite map of the nodes. deba@2126: /// deba@2126: /// ReadWrite map of the nodes. deba@2126: /// deba@2126: template deba@2126: class NodeMap : public GraphMap { deba@2126: private: deba@2126: NodeMap(); deba@2126: public: deba@2126: typedef GraphMap Parent; deba@2126: deba@2126: /// \brief Construct a new map. deba@2126: /// deba@2126: /// Construct a new map for the graph. deba@2126: /// \todo call the right parent class constructor deba@2126: explicit NodeMap(const Graph& graph) : Parent(graph) {} deba@2126: deba@2126: /// \brief Construct a new map with default value. deba@2126: /// deba@2126: /// Construct a new map for the graph and initalise the values. deba@2126: NodeMap(const Graph& graph, const Value& value) deba@2126: : Parent(graph, value) {} deba@2126: deba@2126: /// \brief Copy constructor. deba@2126: /// deba@2126: /// Copy Constructor. deba@2126: NodeMap(const NodeMap& nm) : Parent(nm) {} deba@2126: deba@2126: /// \brief Assign operator. deba@2126: /// deba@2126: /// Assign operator. deba@2126: template deba@2126: NodeMap& operator=(const CMap&) { deba@2126: checkConcept, CMap>(); deba@2126: return *this; deba@2126: } deba@2126: deba@2126: }; deba@2126: deba@2126: /// \brief ReadWrite map of the edges. deba@2126: /// deba@2126: /// ReadWrite map of the edges. deba@2126: /// deba@2126: template deba@2126: class EdgeMap : public GraphMap { deba@2126: private: deba@2126: EdgeMap(); deba@2126: public: deba@2126: typedef GraphMap Parent; deba@2126: deba@2126: /// \brief Construct a new map. deba@2126: /// deba@2126: /// Construct a new map for the graph. deba@2126: /// \todo call the right parent class constructor deba@2126: explicit EdgeMap(const Graph& graph) : Parent(graph) {} deba@2126: deba@2126: /// \brief Construct a new map with default value. deba@2126: /// deba@2126: /// Construct a new map for the graph and initalise the values. deba@2126: EdgeMap(const Graph& graph, const Value& value) deba@2126: : Parent(graph, value) {} deba@2126: deba@2126: /// \brief Copy constructor. deba@2126: /// deba@2126: /// Copy Constructor. deba@2126: EdgeMap(const EdgeMap& nm) : Parent(nm) {} deba@2126: deba@2126: /// \brief Assign operator. deba@2126: /// deba@2126: /// Assign operator. deba@2126: template deba@2126: EdgeMap& operator=(const CMap&) { deba@2126: checkConcept, CMap>(); deba@2126: return *this; deba@2126: } deba@2126: deba@2126: }; deba@2126: deba@2126: deba@2126: template deba@2126: struct Constraints { deba@2126: deba@2126: struct Dummy { deba@2126: int value; deba@2126: Dummy() : value(0) {} deba@2126: Dummy(int _v) : value(_v) {} deba@2126: }; deba@2126: deba@2126: void constraints() { deba@2126: checkConcept(); deba@2126: { // int map test deba@2126: typedef typename _Graph::template NodeMap IntNodeMap; deba@2126: checkConcept, deba@2126: IntNodeMap >(); deba@2126: } { // bool map test deba@2126: typedef typename _Graph::template NodeMap BoolNodeMap; deba@2126: checkConcept, deba@2126: BoolNodeMap >(); deba@2126: } { // Dummy map test deba@2126: typedef typename _Graph::template NodeMap DummyNodeMap; deba@2126: checkConcept, deba@2126: DummyNodeMap >(); deba@2126: } deba@2126: deba@2126: { // int map test deba@2126: typedef typename _Graph::template EdgeMap IntEdgeMap; deba@2126: checkConcept, deba@2126: IntEdgeMap >(); deba@2126: } { // bool map test deba@2126: typedef typename _Graph::template EdgeMap BoolEdgeMap; deba@2126: checkConcept, deba@2126: BoolEdgeMap >(); deba@2126: } { // Dummy map test deba@2126: typedef typename _Graph::template EdgeMap DummyEdgeMap; deba@2126: checkConcept, deba@2126: DummyEdgeMap >(); deba@2126: } deba@2126: } deba@2126: deba@2126: _Graph& graph; deba@2126: }; deba@2126: }; deba@2126: deba@2126: /// \brief An empty mappable base graph class. deba@2126: /// deba@2126: /// This class provides beside the core graph features deba@2126: /// map interface for the graph structure. deba@2126: /// This concept is part of the UGraph concept. deba@2126: template deba@2126: class MappableUGraphComponent : public MappableGraphComponent<_Base> { deba@2126: public: deba@2126: deba@2126: typedef _Base Base; deba@2126: typedef typename Base::UEdge UEdge; deba@2126: deba@2126: typedef MappableUGraphComponent Graph; deba@2126: deba@2126: /// \brief ReadWrite map of the uedges. deba@2126: /// deba@2126: /// ReadWrite map of the uedges. deba@2126: /// deba@2126: template deba@2126: class UEdgeMap : public GraphMap { deba@2126: public: deba@2126: typedef GraphMap Parent; deba@2126: deba@2126: /// \brief Construct a new map. deba@2126: /// deba@2126: /// Construct a new map for the graph. deba@2126: /// \todo call the right parent class constructor deba@2126: explicit UEdgeMap(const Graph& graph) : Parent(graph) {} deba@2126: deba@2126: /// \brief Construct a new map with default value. deba@2126: /// deba@2126: /// Construct a new map for the graph and initalise the values. deba@2126: UEdgeMap(const Graph& graph, const Value& value) deba@2126: : Parent(graph, value) {} deba@2126: deba@2126: /// \brief Copy constructor. deba@2126: /// deba@2126: /// Copy Constructor. deba@2126: UEdgeMap(const UEdgeMap& nm) : Parent(nm) {} deba@2126: deba@2126: /// \brief Assign operator. deba@2126: /// deba@2126: /// Assign operator. deba@2126: template deba@2126: UEdgeMap& operator=(const CMap&) { deba@2126: checkConcept, CMap>(); deba@2126: return *this; deba@2126: } deba@2126: deba@2126: }; deba@2126: deba@2126: deba@2126: template deba@2126: struct Constraints { deba@2126: deba@2126: struct Dummy { deba@2126: int value; deba@2126: Dummy() : value(0) {} deba@2126: Dummy(int _v) : value(_v) {} deba@2126: }; deba@2126: deba@2126: void constraints() { deba@2126: checkConcept(); deba@2126: checkConcept, _Graph>(); deba@2126: deba@2126: { // int map test deba@2126: typedef typename _Graph::template UEdgeMap IntUEdgeMap; deba@2126: checkConcept, deba@2126: IntUEdgeMap >(); deba@2126: } { // bool map test deba@2126: typedef typename _Graph::template UEdgeMap BoolUEdgeMap; deba@2126: checkConcept, deba@2126: BoolUEdgeMap >(); deba@2126: } { // Dummy map test deba@2126: typedef typename _Graph::template UEdgeMap DummyUEdgeMap; deba@2126: checkConcept, deba@2126: DummyUEdgeMap >(); deba@2126: } deba@2126: } deba@2126: deba@2126: _Graph& graph; deba@2126: }; deba@2126: }; deba@2126: deba@2126: deba@2126: /// \brief An empty extendable graph class. deba@2126: /// deba@2126: /// This class provides beside the core graph features graph deba@2126: /// extendable interface for the graph structure. The main deba@2126: /// difference between the base and this interface is that the deba@2126: /// graph alterations should handled already on this level. deba@2126: template deba@2126: class ExtendableGraphComponent : public _Base { deba@2126: public: deba@2126: deba@2126: typedef typename _Base::Node Node; deba@2126: typedef typename _Base::Edge Edge; deba@2126: deba@2126: /// \brief Adds a new node to the graph. deba@2126: /// deba@2126: /// Adds a new node to the graph. deba@2126: /// deba@2126: Node addNode() { deba@2126: return INVALID; deba@2126: } deba@2126: deba@2126: /// \brief Adds a new edge connects the given two nodes. deba@2126: /// deba@2126: /// Adds a new edge connects the the given two nodes. deba@2126: Edge addEdge(const Node&, const Node&) { deba@2126: return INVALID; deba@2126: } deba@2126: deba@2126: template deba@2126: struct Constraints { deba@2126: void constraints() { deba@2126: typename _Graph::Node node_a, node_b; deba@2126: node_a = graph.addNode(); deba@2126: node_b = graph.addNode(); deba@2126: typename _Graph::Edge edge; deba@2126: edge = graph.addEdge(node_a, node_b); deba@2126: } deba@2126: deba@2126: _Graph& graph; deba@2126: }; deba@2126: }; deba@2126: deba@2126: /// \brief An empty extendable base undirected graph class. deba@2126: /// deba@2126: /// This class provides beside the core undirected graph features deba@2126: /// core undircted graph extend interface for the graph structure. deba@2126: /// The main difference between the base and this interface is deba@2126: /// that the graph alterations should handled already on this deba@2126: /// level. deba@2126: template deba@2126: class ExtendableUGraphComponent : public _Base { deba@2126: public: deba@2126: deba@2126: typedef typename _Base::Node Node; deba@2126: typedef typename _Base::UEdge UEdge; deba@2126: deba@2126: /// \brief Adds a new node to the graph. deba@2126: /// deba@2126: /// Adds a new node to the graph. deba@2126: /// deba@2126: Node addNode() { deba@2126: return INVALID; deba@2126: } deba@2126: deba@2126: /// \brief Adds a new edge connects the given two nodes. deba@2126: /// deba@2126: /// Adds a new edge connects the the given two nodes. deba@2126: UEdge addEdge(const Node&, const Node&) { deba@2126: return INVALID; deba@2126: } deba@2126: deba@2126: template deba@2126: struct Constraints { deba@2126: void constraints() { deba@2126: typename _Graph::Node node_a, node_b; deba@2126: node_a = graph.addNode(); deba@2126: node_b = graph.addNode(); deba@2126: typename _Graph::UEdge uedge; deba@2126: uedge = graph.addUEdge(node_a, node_b); deba@2126: } deba@2126: deba@2126: _Graph& graph; deba@2126: }; deba@2126: }; deba@2126: deba@2126: /// \brief An empty erasable graph class. deba@2126: /// deba@2126: /// This class provides beside the core graph features core erase deba@2126: /// functions for the graph structure. The main difference between deba@2126: /// the base and this interface is that the graph alterations deba@2126: /// should handled already on this level. deba@2126: template deba@2126: class ErasableGraphComponent : public _Base { deba@2126: public: deba@2126: deba@2126: typedef _Base Base; deba@2126: typedef typename Base::Node Node; deba@2126: typedef typename Base::Edge Edge; deba@2126: deba@2126: /// \brief Erase a node from the graph. deba@2126: /// deba@2126: /// Erase a node from the graph. This function should deba@2126: /// erase all edges connecting to the node. deba@2126: void erase(const Node&) {} deba@2126: deba@2126: /// \brief Erase an edge from the graph. deba@2126: /// deba@2126: /// Erase an edge from the graph. deba@2126: /// deba@2126: void erase(const Edge&) {} deba@2126: deba@2126: template deba@2126: struct Constraints { deba@2126: void constraints() { deba@2126: typename _Graph::Node node; deba@2126: graph.erase(node); deba@2126: typename _Graph::Edge edge; deba@2126: graph.erase(edge); deba@2126: } deba@2126: deba@2126: _Graph& graph; deba@2126: }; deba@2126: }; deba@2126: deba@2126: /// \brief An empty erasable base undirected graph class. deba@2126: /// deba@2126: /// This class provides beside the core undirected graph features deba@2126: /// core erase functions for the undirceted graph structure. The deba@2126: /// main difference between the base and this interface is that deba@2126: /// the graph alterations should handled already on this level. deba@2126: template deba@2126: class ErasableUGraphComponent : public _Base { deba@2126: public: deba@2126: deba@2126: typedef _Base Base; deba@2126: typedef typename Base::Node Node; deba@2126: typedef typename Base::UEdge UEdge; deba@2126: deba@2126: /// \brief Erase a node from the graph. deba@2126: /// deba@2126: /// Erase a node from the graph. This function should erase deba@2126: /// edges connecting to the node. deba@2126: void erase(const Node&) {} deba@2126: deba@2126: /// \brief Erase an edge from the graph. deba@2126: /// deba@2126: /// Erase an edge from the graph. deba@2126: /// deba@2126: void erase(const UEdge&) {} deba@2126: deba@2126: template deba@2126: struct Constraints { deba@2126: void constraints() { deba@2126: typename _Graph::Node node; deba@2126: graph.erase(node); deba@2126: typename _Graph::Edge edge; deba@2126: graph.erase(edge); deba@2126: } deba@2126: deba@2126: _Graph& graph; deba@2126: }; deba@2126: }; deba@2126: deba@2126: /// \brief An empty clearable base graph class. deba@2126: /// deba@2126: /// This class provides beside the core graph features core clear deba@2126: /// functions for the graph structure. The main difference between deba@2126: /// the base and this interface is that the graph alterations deba@2126: /// should handled already on this level. deba@2126: template deba@2126: class ClearableGraphComponent : public _Base { deba@2126: public: deba@2126: deba@2126: /// \brief Erase all nodes and edges from the graph. deba@2126: /// deba@2126: /// Erase all nodes and edges from the graph. deba@2126: /// deba@2126: void clear() {} deba@2126: deba@2126: template deba@2126: struct Constraints { deba@2126: void constraints() { deba@2126: graph.clear(); deba@2126: } deba@2126: deba@2126: _Graph graph; deba@2126: }; deba@2126: }; deba@2126: deba@2126: /// \brief An empty clearable base undirected graph class. deba@2126: /// deba@2126: /// This class provides beside the core undirected graph features deba@2126: /// core clear functions for the undirected graph structure. The deba@2126: /// main difference between the base and this interface is that deba@2126: /// the graph alterations should handled already on this level. deba@2126: template deba@2126: class ClearableUGraphComponent : public _Base { deba@2126: public: deba@2126: deba@2126: /// \brief Erase all nodes and undirected edges from the graph. deba@2126: /// deba@2126: /// Erase all nodes and undirected edges from the graph. deba@2126: /// deba@2126: void clear() {} deba@2126: deba@2126: template deba@2126: struct Constraints { deba@2126: void constraints() { deba@2126: graph.clear(); deba@2126: } deba@2126: deba@2126: _Graph graph; deba@2126: }; deba@2126: }; deba@2126: deba@2126: } deba@2126: deba@2126: } deba@2126: deba@2126: #endif