klao@962: /* -*- C++ -*- klao@962: * alpar@1956: * This file is a part of LEMON, a generic C++ optimization library klao@962: * alpar@1956: * Copyright (C) 2003-2006 alpar@1956: * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport alpar@1956: * (Egervary Research Group on Combinatorial Optimization, EGRES). klao@962: * klao@962: * Permission to use, modify and distribute this software is granted klao@962: * provided that this copyright notice appears in all copies. For klao@962: * precise terms see the accompanying LICENSE file. klao@962: * klao@962: * This software is provided "AS IS" with no warranty of any kind, klao@962: * express or implied, and with no claim as to its suitability for any klao@962: * purpose. klao@962: * klao@962: */ klao@962: klao@1030: ///\ingroup graph_concepts klao@962: ///\file klao@962: ///\brief Undirected graphs and components of. klao@962: klao@962: deba@1910: #ifndef LEMON_CONCEPT_UGRAPH_H deba@1910: #define LEMON_CONCEPT_UGRAPH_H klao@962: klao@962: #include alpar@1620: #include deba@1993: #include klao@962: klao@962: namespace lemon { klao@962: namespace concept { klao@962: alpar@1630: // /// Skeleton class which describes an edge with direction in \ref klao@1909: // /// UGraph "undirected graph". klao@1909: template klao@1909: class UGraphEdge : public UGraph::UEdge { klao@1909: typedef typename UGraph::UEdge UEdge; klao@1909: typedef typename UGraph::Node Node; klao@1030: public: klao@1030: klao@1030: /// \e klao@1909: UGraphEdge() {} klao@1030: klao@1030: /// \e klao@1909: UGraphEdge(const UGraphEdge& e) : UGraph::UEdge(e) {} klao@1030: klao@1030: /// \e klao@1909: UGraphEdge(Invalid) {} klao@1030: klao@1158: /// \brief Directed edge from undirected edge and a source node. klao@1030: /// klao@1158: /// Constructs a directed edge from undirected edge and a source node. klao@1158: /// klao@1158: /// \note You have to specify the graph for this constructor. klao@1909: UGraphEdge(const UGraph &g, klao@1909: UEdge u_edge, Node n) { klao@1909: ignore_unused_variable_warning(u_edge); klao@1158: ignore_unused_variable_warning(g); klao@1158: ignore_unused_variable_warning(n); klao@1030: } klao@1030: klao@1030: /// \e klao@1909: UGraphEdge& operator=(UGraphEdge) { return *this; } klao@1030: klao@1030: /// \e klao@1909: bool operator==(UGraphEdge) const { return true; } klao@1030: /// \e klao@1909: bool operator!=(UGraphEdge) const { return false; } klao@1030: klao@1030: /// \e klao@1909: bool operator<(UGraphEdge) const { return false; } klao@1030: klao@1030: template klao@1030: struct Constraints { klao@1030: void constraints() { klao@1158: const_constraints(); klao@1158: } klao@1158: void const_constraints() const { klao@1030: /// \bug This should be is_base_and_derived ... klao@1909: UEdge ue = e; klao@1030: ue = e; klao@1030: klao@1158: Edge e_with_source(graph,ue,n); klao@1158: ignore_unused_variable_warning(e_with_source); klao@1030: } klao@1030: Edge e; klao@1909: UEdge ue; klao@1909: UGraph graph; klao@1158: Node n; klao@1030: }; klao@1030: }; klao@1030: klao@962: klao@1909: struct BaseIterableUGraphConcept { deba@989: klao@1022: template klao@1022: struct Constraints { klao@962: klao@1909: typedef typename Graph::UEdge UEdge; klao@1022: typedef typename Graph::Edge Edge; klao@1022: typedef typename Graph::Node Node; klao@962: klao@1022: void constraints() { klao@1022: checkConcept(); klao@1909: checkConcept, UEdge>(); klao@1909: //checkConcept, Edge>(); klao@962: klao@1030: graph.first(ue); klao@1030: graph.next(ue); klao@1022: klao@1030: const_constraints(); klao@1030: } klao@1030: void const_constraints() { klao@1022: Node n; klao@1022: n = graph.target(ue); klao@1022: n = graph.source(ue); klao@1030: n = graph.oppositeNode(n0, ue); klao@1022: klao@1030: bool b; deba@1627: b = graph.direction(e); klao@1909: Edge e = graph.direct(UEdge(), true); klao@1909: e = graph.direct(UEdge(), n); deba@1627: klao@1030: ignore_unused_variable_warning(b); klao@1022: } klao@1030: klao@1030: Graph graph; klao@1022: Edge e; klao@1030: Node n0; klao@1909: UEdge ue; klao@1022: }; klao@1022: klao@962: }; klao@962: klao@1022: klao@1909: struct IterableUGraphConcept { klao@962: klao@1022: template klao@1022: struct Constraints { klao@1022: void constraints() { klao@1022: /// \todo we don't need the iterable component to be base iterable klao@1022: /// Don't we really??? klao@1909: //checkConcept< BaseIterableUGraphConcept, Graph > (); klao@962: klao@1022: checkConcept (); klao@1021: klao@1909: typedef typename Graph::UEdge UEdge; klao@1909: typedef typename Graph::UEdgeIt UEdgeIt; klao@1030: typedef typename Graph::IncEdgeIt IncEdgeIt; klao@1022: klao@1909: checkConcept, UEdgeIt>(); klao@1909: checkConcept, IncEdgeIt>(); klao@1022: } klao@1022: }; klao@1022: klao@1022: }; klao@1022: klao@1909: struct MappableUGraphConcept { klao@1022: klao@1022: template klao@1022: struct Constraints { klao@1022: klao@1022: struct Dummy { klao@1022: int value; klao@1022: Dummy() : value(0) {} klao@1022: Dummy(int _v) : value(_v) {} klao@1022: }; klao@1022: klao@1022: void constraints() { klao@1022: checkConcept(); klao@1022: klao@1909: typedef typename Graph::template UEdgeMap IntMap; klao@1909: checkConcept, klao@1022: IntMap >(); klao@1022: klao@1909: typedef typename Graph::template UEdgeMap BoolMap; klao@1909: checkConcept, klao@1022: BoolMap >(); klao@1022: klao@1909: typedef typename Graph::template UEdgeMap DummyMap; klao@1909: checkConcept, klao@1022: DummyMap >(); klao@1022: } klao@1022: }; klao@1022: klao@1022: }; klao@1022: klao@1909: struct ExtendableUGraphConcept { klao@1022: klao@1022: template klao@1022: struct Constraints { klao@1022: void constraints() { klao@1022: node_a = graph.addNode(); klao@1022: uedge = graph.addEdge(node_a, node_b); klao@1022: } klao@1022: typename Graph::Node node_a, node_b; klao@1909: typename Graph::UEdge uedge; klao@1022: Graph graph; klao@1022: }; klao@1022: klao@1022: }; klao@1022: klao@1909: struct ErasableUGraphConcept { klao@1022: klao@1022: template klao@1022: struct Constraints { klao@1022: void constraints() { klao@1022: graph.erase(n); klao@1022: graph.erase(e); klao@1022: } klao@1022: Graph graph; klao@1022: typename Graph::Node n; klao@1909: typename Graph::UEdge e; klao@1022: }; klao@1022: klao@1022: }; klao@1022: alpar@1620: /// \addtogroup graph_concepts alpar@1620: /// @{ alpar@1620: alpar@1620: klao@1030: /// Class describing the concept of Undirected Graphs. klao@1030: klao@1030: /// This class describes the common interface of all Undirected klao@1030: /// Graphs. klao@1030: /// klao@1030: /// As all concept describing classes it provides only interface klao@1030: /// without any sensible implementation. So any algorithm for klao@1030: /// undirected graph should compile with this class, but it will not klao@1030: /// run properly, of couse. klao@1030: /// klao@1030: /// In LEMON undirected graphs also fulfill the concept of directed alpar@1631: /// graphs (\ref lemon::concept::StaticGraph "Graph Concept"). For klao@1909: /// explanation of this and more see also the page \ref ugraphs, klao@1030: /// a tutorial about undirected graphs. deba@1627: /// deba@1627: /// You can assume that all undirected graph can be handled deba@1627: /// as a static directed graph. This way it is fully conform deba@1627: /// to the StaticGraph concept. klao@1030: klao@1909: class UGraph { klao@1022: public: alpar@1448: ///\e alpar@1448: alpar@1448: ///\todo undocumented alpar@1448: /// deba@1979: typedef True UndirectedTag; klao@1022: deba@1669: /// \brief The base type of node iterators, deba@1627: /// or in other words, the trivial node iterator. deba@1669: /// deba@1627: /// This is the base type of each node iterator, deba@1627: /// thus each kind of node iterator converts to this. deba@1627: /// More precisely each kind of node iterator should be inherited deba@1627: /// from the trivial node iterator. deba@1627: class Node { deba@1627: public: deba@1627: /// Default constructor deba@1627: deba@1627: /// @warning The default constructor sets the iterator deba@1627: /// to an undefined value. deba@1627: Node() { } deba@1627: /// Copy constructor. deba@1627: deba@1627: /// Copy constructor. deba@1627: /// deba@1627: Node(const Node&) { } deba@1627: deba@1627: /// Invalid constructor \& conversion. deba@1627: deba@1627: /// This constructor initializes the iterator to be invalid. deba@1627: /// \sa Invalid for more details. deba@1627: Node(Invalid) { } deba@1627: /// Equality operator deba@1627: deba@1627: /// Two iterators are equal if and only if they point to the deba@1627: /// same object or both are invalid. deba@1627: bool operator==(Node) const { return true; } deba@1627: deba@1627: /// Inequality operator deba@1627: deba@1627: /// \sa operator==(Node n) deba@1627: /// deba@1627: bool operator!=(Node) const { return true; } deba@1627: deba@1627: /// Artificial ordering operator. deba@1627: deba@1627: /// To allow the use of graph descriptors as key type in std::map or deba@1627: /// similar associative container we require this. deba@1627: /// deba@1627: /// \note This operator only have to define some strict ordering of deba@1627: /// the items; this order has nothing to do with the iteration deba@1627: /// ordering of the items. deba@1627: /// deba@1627: /// \bug This is a technical requirement. Do we really need this? deba@1627: bool operator<(Node) const { return false; } deba@1627: deba@1627: }; deba@1627: deba@1627: /// This iterator goes through each node. deba@1627: deba@1627: /// This iterator goes through each node. deba@1627: /// Its usage is quite simple, for example you can count the number deba@1627: /// of nodes in graph \c g of type \c Graph like this: alpar@1946: ///\code deba@1627: /// int count=0; deba@1627: /// for (Graph::NodeIt n(g); n!=INVALID; ++n) ++count; alpar@1946: ///\endcode deba@1627: class NodeIt : public Node { deba@1627: public: deba@1627: /// Default constructor deba@1627: deba@1627: /// @warning The default constructor sets the iterator deba@1627: /// to an undefined value. deba@1627: NodeIt() { } deba@1627: /// Copy constructor. deba@1627: deba@1627: /// Copy constructor. deba@1627: /// deba@1627: NodeIt(const NodeIt& n) : Node(n) { } deba@1627: /// Invalid constructor \& conversion. deba@1627: deba@1627: /// Initialize the iterator to be invalid. deba@1627: /// \sa Invalid for more details. deba@1627: NodeIt(Invalid) { } deba@1627: /// Sets the iterator to the first node. deba@1627: deba@1627: /// Sets the iterator to the first node of \c g. deba@1627: /// klao@1909: NodeIt(const UGraph&) { } deba@1627: /// Node -> NodeIt conversion. deba@1627: deba@1627: /// Sets the iterator to the node of \c the graph pointed by deba@1627: /// the trivial iterator. deba@1627: /// This feature necessitates that each time we deba@1627: /// iterate the edge-set, the iteration order is the same. klao@1909: NodeIt(const UGraph&, const Node&) { } deba@1627: /// Next node. deba@1627: deba@1627: /// Assign the iterator to the next node. deba@1627: /// deba@1627: NodeIt& operator++() { return *this; } deba@1627: }; deba@1627: deba@1627: alpar@1620: /// The base type of the undirected edge iterators. deba@1627: alpar@1620: /// The base type of the undirected edge iterators. alpar@1620: /// klao@1909: class UEdge { alpar@1620: public: alpar@1620: /// Default constructor klao@1030: alpar@1620: /// @warning The default constructor sets the iterator alpar@1620: /// to an undefined value. klao@1909: UEdge() { } alpar@1620: /// Copy constructor. klao@1030: alpar@1620: /// Copy constructor. alpar@1620: /// klao@1909: UEdge(const UEdge&) { } alpar@1620: /// Initialize the iterator to be invalid. klao@1030: alpar@1620: /// Initialize the iterator to be invalid. alpar@1620: /// klao@1909: UEdge(Invalid) { } alpar@1620: /// Equality operator klao@1030: alpar@1620: /// Two iterators are equal if and only if they point to the alpar@1620: /// same object or both are invalid. klao@1909: bool operator==(UEdge) const { return true; } alpar@1620: /// Inequality operator klao@1030: klao@1909: /// \sa operator==(UEdge n) alpar@1620: /// klao@1909: bool operator!=(UEdge) const { return true; } klao@1030: deba@1627: /// Artificial ordering operator. deba@1627: deba@1627: /// To allow the use of graph descriptors as key type in std::map or deba@1627: /// similar associative container we require this. deba@1627: /// deba@1627: /// \note This operator only have to define some strict ordering of deba@1627: /// the items; this order has nothing to do with the iteration deba@1627: /// ordering of the items. deba@1627: /// deba@1627: /// \bug This is a technical requirement. Do we really need this? klao@1909: bool operator<(UEdge) const { return false; } deba@1627: }; klao@1030: alpar@1620: /// This iterator goes through each undirected edge. klao@1030: alpar@1620: /// This iterator goes through each undirected edge of a graph. alpar@1620: /// Its usage is quite simple, for example you can count the number deba@1627: /// of undirected edges in a graph \c g of type \c Graph as follows: alpar@1946: ///\code alpar@1620: /// int count=0; klao@1909: /// for(Graph::UEdgeIt e(g); e!=INVALID; ++e) ++count; alpar@1946: ///\endcode klao@1909: class UEdgeIt : public UEdge { alpar@1620: public: alpar@1620: /// Default constructor deba@1627: alpar@1620: /// @warning The default constructor sets the iterator alpar@1620: /// to an undefined value. klao@1909: UEdgeIt() { } alpar@1620: /// Copy constructor. deba@1627: alpar@1620: /// Copy constructor. alpar@1620: /// klao@1909: UEdgeIt(const UEdgeIt& e) : UEdge(e) { } alpar@1620: /// Initialize the iterator to be invalid. klao@1030: alpar@1620: /// Initialize the iterator to be invalid. alpar@1620: /// klao@1909: UEdgeIt(Invalid) { } deba@1627: /// This constructor sets the iterator to the first undirected edge. alpar@1620: deba@1627: /// This constructor sets the iterator to the first undirected edge. klao@1909: UEdgeIt(const UGraph&) { } klao@1909: /// UEdge -> UEdgeIt conversion klao@1030: deba@1627: /// Sets the iterator to the value of the trivial iterator. deba@1627: /// This feature necessitates that each time we deba@1627: /// iterate the undirected edge-set, the iteration order is the deba@1627: /// same. klao@1909: UEdgeIt(const UGraph&, const UEdge&) { } deba@1627: /// Next undirected edge alpar@1620: deba@1627: /// Assign the iterator to the next undirected edge. klao@1909: UEdgeIt& operator++() { return *this; } alpar@1620: }; klao@1030: deba@1627: /// \brief This iterator goes trough the incident undirected deba@1627: /// edges of a node. deba@1627: /// alpar@1620: /// This iterator goes trough the incident undirected edges deba@2021: /// of a certain node of a graph. You should assume that the deba@2021: /// loop edges will be iterated twice. deba@2021: /// alpar@1620: /// Its usage is quite simple, for example you can compute the deba@2021: /// degree (i.e. count the number of incident edges of a node \c n deba@2021: /// in graph \c g of type \c Graph as follows. deba@2021: /// alpar@1946: ///\code alpar@1620: /// int count=0; alpar@1620: /// for(Graph::IncEdgeIt e(g, n); e!=INVALID; ++e) ++count; alpar@1946: ///\endcode klao@1909: class IncEdgeIt : public UEdge { alpar@1620: public: alpar@1620: /// Default constructor klao@1030: alpar@1620: /// @warning The default constructor sets the iterator alpar@1620: /// to an undefined value. alpar@1620: IncEdgeIt() { } alpar@1620: /// Copy constructor. alpar@1620: alpar@1620: /// Copy constructor. alpar@1620: /// klao@1909: IncEdgeIt(const IncEdgeIt& e) : UEdge(e) { } alpar@1620: /// Initialize the iterator to be invalid. alpar@1620: alpar@1620: /// Initialize the iterator to be invalid. alpar@1620: /// alpar@1620: IncEdgeIt(Invalid) { } alpar@1620: /// This constructor sets the iterator to first incident edge. alpar@1620: alpar@1620: /// This constructor set the iterator to the first incident edge of alpar@1620: /// the node. klao@1909: IncEdgeIt(const UGraph&, const Node&) { } klao@1909: /// UEdge -> IncEdgeIt conversion alpar@1620: alpar@1620: /// Sets the iterator to the value of the trivial iterator \c e. alpar@1620: /// This feature necessitates that each time we alpar@1620: /// iterate the edge-set, the iteration order is the same. klao@1909: IncEdgeIt(const UGraph&, const UEdge&) { } alpar@1620: /// Next incident edge alpar@1620: alpar@1620: /// Assign the iterator to the next incident edge alpar@1620: /// of the corresponding node. alpar@1620: IncEdgeIt& operator++() { return *this; } alpar@1620: }; alpar@1620: deba@1627: /// The directed edge type. deba@1627: deba@1627: /// The directed edge type. It can be converted to the deba@1627: /// undirected edge. klao@1909: class Edge : public UEdge { deba@1627: public: deba@1627: /// Default constructor deba@1627: deba@1627: /// @warning The default constructor sets the iterator deba@1627: /// to an undefined value. deba@1627: Edge() { } deba@1627: /// Copy constructor. deba@1627: deba@1627: /// Copy constructor. deba@1627: /// klao@1909: Edge(const Edge& e) : UEdge(e) { } deba@1627: /// Initialize the iterator to be invalid. deba@1627: deba@1627: /// Initialize the iterator to be invalid. deba@1627: /// deba@1627: Edge(Invalid) { } deba@1627: /// Equality operator deba@1627: deba@1627: /// Two iterators are equal if and only if they point to the deba@1627: /// same object or both are invalid. deba@1627: bool operator==(Edge) const { return true; } deba@1627: /// Inequality operator deba@1627: deba@1627: /// \sa operator==(Edge n) deba@1627: /// deba@1627: bool operator!=(Edge) const { return true; } deba@1627: deba@1627: /// Artificial ordering operator. deba@1627: deba@1627: /// To allow the use of graph descriptors as key type in std::map or deba@1627: /// similar associative container we require this. deba@1627: /// deba@1627: /// \note This operator only have to define some strict ordering of deba@1627: /// the items; this order has nothing to do with the iteration deba@1627: /// ordering of the items. deba@1627: /// deba@1627: /// \bug This is a technical requirement. Do we really need this? deba@1627: bool operator<(Edge) const { return false; } deba@1627: deba@1627: }; deba@1627: /// This iterator goes through each directed edge. deba@1627: deba@1627: /// This iterator goes through each edge of a graph. deba@1627: /// Its usage is quite simple, for example you can count the number deba@1627: /// of edges in a graph \c g of type \c Graph as follows: alpar@1946: ///\code deba@1627: /// int count=0; deba@1627: /// for(Graph::EdgeIt e(g); e!=INVALID; ++e) ++count; alpar@1946: ///\endcode deba@1627: class EdgeIt : public Edge { deba@1627: public: deba@1627: /// Default constructor deba@1627: deba@1627: /// @warning The default constructor sets the iterator deba@1627: /// to an undefined value. deba@1627: EdgeIt() { } deba@1627: /// Copy constructor. deba@1627: deba@1627: /// Copy constructor. deba@1627: /// deba@1627: EdgeIt(const EdgeIt& e) : Edge(e) { } deba@1627: /// Initialize the iterator to be invalid. deba@1627: deba@1627: /// Initialize the iterator to be invalid. deba@1627: /// deba@1627: EdgeIt(Invalid) { } deba@1627: /// This constructor sets the iterator to the first edge. deba@1627: deba@1627: /// This constructor sets the iterator to the first edge of \c g. deba@1627: ///@param g the graph klao@1909: EdgeIt(const UGraph &g) { ignore_unused_variable_warning(g); } deba@1627: /// Edge -> EdgeIt conversion deba@1627: deba@1627: /// Sets the iterator to the value of the trivial iterator \c e. deba@1627: /// This feature necessitates that each time we deba@1627: /// iterate the edge-set, the iteration order is the same. klao@1909: EdgeIt(const UGraph&, const Edge&) { } deba@1627: ///Next edge deba@1627: deba@1627: /// Assign the iterator to the next edge. deba@1627: EdgeIt& operator++() { return *this; } deba@1627: }; deba@1627: deba@1627: /// This iterator goes trough the outgoing directed edges of a node. deba@1627: deba@1627: /// This iterator goes trough the \e outgoing edges of a certain node deba@1627: /// of a graph. deba@1627: /// Its usage is quite simple, for example you can count the number deba@1627: /// of outgoing edges of a node \c n deba@1627: /// in graph \c g of type \c Graph as follows. alpar@1946: ///\code deba@1627: /// int count=0; deba@1627: /// for (Graph::OutEdgeIt e(g, n); e!=INVALID; ++e) ++count; alpar@1946: ///\endcode deba@1627: deba@1627: class OutEdgeIt : public Edge { deba@1627: public: deba@1627: /// Default constructor deba@1627: deba@1627: /// @warning The default constructor sets the iterator deba@1627: /// to an undefined value. deba@1627: OutEdgeIt() { } deba@1627: /// Copy constructor. deba@1627: deba@1627: /// Copy constructor. deba@1627: /// deba@1627: OutEdgeIt(const OutEdgeIt& e) : Edge(e) { } deba@1627: /// Initialize the iterator to be invalid. deba@1627: deba@1627: /// Initialize the iterator to be invalid. deba@1627: /// deba@1627: OutEdgeIt(Invalid) { } deba@1627: /// This constructor sets the iterator to the first outgoing edge. deba@1627: deba@1627: /// This constructor sets the iterator to the first outgoing edge of deba@1627: /// the node. deba@1627: ///@param n the node deba@1627: ///@param g the graph klao@1909: OutEdgeIt(const UGraph& n, const Node& g) { alpar@1643: ignore_unused_variable_warning(n); alpar@1643: ignore_unused_variable_warning(g); alpar@1643: } deba@1627: /// Edge -> OutEdgeIt conversion deba@1627: deba@1627: /// Sets the iterator to the value of the trivial iterator. deba@1627: /// This feature necessitates that each time we deba@1627: /// iterate the edge-set, the iteration order is the same. klao@1909: OutEdgeIt(const UGraph&, const Edge&) { } deba@1627: ///Next outgoing edge deba@1627: deba@1627: /// Assign the iterator to the next deba@1627: /// outgoing edge of the corresponding node. deba@1627: OutEdgeIt& operator++() { return *this; } deba@1627: }; deba@1627: deba@1627: /// This iterator goes trough the incoming directed edges of a node. deba@1627: deba@1627: /// This iterator goes trough the \e incoming edges of a certain node deba@1627: /// of a graph. deba@1627: /// Its usage is quite simple, for example you can count the number deba@1627: /// of outgoing edges of a node \c n deba@1627: /// in graph \c g of type \c Graph as follows. alpar@1946: ///\code deba@1627: /// int count=0; deba@1627: /// for(Graph::InEdgeIt e(g, n); e!=INVALID; ++e) ++count; alpar@1946: ///\endcode deba@1627: deba@1627: class InEdgeIt : public Edge { deba@1627: public: deba@1627: /// Default constructor deba@1627: deba@1627: /// @warning The default constructor sets the iterator deba@1627: /// to an undefined value. deba@1627: InEdgeIt() { } deba@1627: /// Copy constructor. deba@1627: deba@1627: /// Copy constructor. deba@1627: /// deba@1627: InEdgeIt(const InEdgeIt& e) : Edge(e) { } deba@1627: /// Initialize the iterator to be invalid. deba@1627: deba@1627: /// Initialize the iterator to be invalid. deba@1627: /// deba@1627: InEdgeIt(Invalid) { } deba@1627: /// This constructor sets the iterator to first incoming edge. deba@1627: deba@1627: /// This constructor set the iterator to the first incoming edge of deba@1627: /// the node. deba@1627: ///@param n the node deba@1627: ///@param g the graph klao@1909: InEdgeIt(const UGraph& g, const Node& n) { alpar@1643: ignore_unused_variable_warning(n); alpar@1643: ignore_unused_variable_warning(g); alpar@1643: } deba@1627: /// Edge -> InEdgeIt conversion deba@1627: deba@1627: /// Sets the iterator to the value of the trivial iterator \c e. deba@1627: /// This feature necessitates that each time we deba@1627: /// iterate the edge-set, the iteration order is the same. klao@1909: InEdgeIt(const UGraph&, const Edge&) { } deba@1627: /// Next incoming edge deba@1627: deba@1627: /// Assign the iterator to the next inedge of the corresponding node. deba@1627: /// deba@1627: InEdgeIt& operator++() { return *this; } deba@1627: }; deba@1627: deba@1627: /// \brief Read write map of the nodes to type \c T. deba@1627: /// deba@1627: /// ReadWrite map of the nodes to type \c T. deba@1627: /// \sa Reference deba@1627: /// \warning Making maps that can handle bool type (NodeMap) deba@1627: /// needs some extra attention! alpar@1630: /// \todo Wrong documentation deba@1627: template deba@1627: class NodeMap : public ReadWriteMap< Node, T > deba@1627: { deba@1627: public: deba@1627: deba@1627: ///\e klao@1909: NodeMap(const UGraph&) { } deba@1627: ///\e klao@1909: NodeMap(const UGraph&, T) { } deba@1627: deba@1627: ///Copy constructor deba@1627: NodeMap(const NodeMap& nm) : ReadWriteMap< Node, T >(nm) { } deba@1627: ///Assignment operator deba@1627: NodeMap& operator=(const NodeMap&) { return *this; } deba@1627: // \todo fix this concept deba@1627: }; deba@1627: deba@1627: /// \brief Read write map of the directed edges to type \c T. deba@1627: /// deba@1627: /// Reference map of the directed edges to type \c T. deba@1627: /// \sa Reference deba@1627: /// \warning Making maps that can handle bool type (EdgeMap) deba@1627: /// needs some extra attention! alpar@1630: /// \todo Wrong documentation deba@1627: template deba@1627: class EdgeMap : public ReadWriteMap deba@1627: { deba@1627: public: deba@1627: deba@1627: ///\e klao@1909: EdgeMap(const UGraph&) { } deba@1627: ///\e klao@1909: EdgeMap(const UGraph&, T) { } deba@1627: ///Copy constructor deba@1627: EdgeMap(const EdgeMap& em) : ReadWriteMap(em) { } deba@1627: ///Assignment operator deba@1627: EdgeMap& operator=(const EdgeMap&) { return *this; } deba@1627: // \todo fix this concept deba@1627: }; deba@1627: alpar@1620: /// Read write map of the undirected edges to type \c T. alpar@1620: alpar@1620: /// Reference map of the edges to type \c T. alpar@1620: /// \sa Reference klao@1909: /// \warning Making maps that can handle bool type (UEdgeMap) alpar@1620: /// needs some extra attention! alpar@1630: /// \todo Wrong documentation alpar@1620: template klao@1909: class UEdgeMap : public ReadWriteMap alpar@1620: { klao@1030: public: klao@1030: alpar@1620: ///\e klao@1909: UEdgeMap(const UGraph&) { } alpar@1620: ///\e klao@1909: UEdgeMap(const UGraph&, T) { } alpar@1620: ///Copy constructor klao@1909: UEdgeMap(const UEdgeMap& em) : ReadWriteMap(em) {} alpar@1620: ///Assignment operator klao@1909: UEdgeMap &operator=(const UEdgeMap&) { return *this; } alpar@1620: // \todo fix this concept klao@1030: }; klao@1030: deba@1627: /// \brief Direct the given undirected edge. deba@1627: /// deba@1627: /// Direct the given undirected edge. The returned edge source deba@1627: /// will be the given edge. klao@1909: Edge direct(const UEdge&, const Node&) const { deba@1627: return INVALID; deba@1627: } klao@1030: deba@1627: /// \brief Direct the given undirected edge. deba@1627: /// deba@1627: /// Direct the given undirected edge. The returned edge source deba@1627: /// will be the source of the undirected edge if the given bool deba@1627: /// is true. klao@1909: Edge direct(const UEdge&, bool) const { deba@1627: return INVALID; deba@1627: } deba@1627: deba@1627: /// \brief Returns true if the edge has default orientation. deba@1627: /// klao@1030: /// Returns whether the given directed edge is same orientation as klao@1030: /// the corresponding undirected edge. deba@1627: bool direction(Edge) const { return true; } deba@1627: deba@1627: /// \brief Returns the opposite directed edge. klao@1030: /// deba@1627: /// Returns the opposite directed edge. deba@1627: Edge oppositeEdge(Edge) const { return INVALID; } klao@1030: deba@1627: /// \brief Opposite node on an edge deba@1627: /// klao@1030: /// \return the opposite of the given Node on the given Edge klao@1909: Node oppositeNode(Node, UEdge) const { return INVALID; } klao@1030: deba@1627: /// \brief First node of the undirected edge. deba@1627: /// klao@1909: /// \return the first node of the given UEdge. klao@1030: /// klao@1909: /// Naturally uectected edges don't have direction and thus klao@1030: /// don't have source and target node. But we use these two methods klao@1030: /// to query the two endnodes of the edge. The direction of the edge klao@1030: /// which arises this way is called the inherent direction of the deba@1627: /// undirected edge, and is used to define the "default" direction klao@1030: /// of the directed versions of the edges. deba@1627: /// \sa direction klao@1909: Node source(UEdge) const { return INVALID; } klao@1030: deba@1627: /// \brief Second node of the undirected edge. klao@1909: Node target(UEdge) const { return INVALID; } klao@1030: deba@1627: /// \brief Source node of the directed edge. klao@1030: Node source(Edge) const { return INVALID; } klao@1030: deba@1627: /// \brief Target node of the directed edge. klao@1030: Node target(Edge) const { return INVALID; } klao@1030: alpar@1630: // /// \brief First node of the graph alpar@1630: // /// alpar@1630: // /// \note This method is part of so called \ref alpar@1630: // /// developpers_interface "Developpers' interface", so it shouldn't alpar@1630: // /// be used in an end-user program. klao@1030: void first(Node&) const {} alpar@1630: // /// \brief Next node of the graph alpar@1630: // /// alpar@1630: // /// \note This method is part of so called \ref alpar@1630: // /// developpers_interface "Developpers' interface", so it shouldn't alpar@1630: // /// be used in an end-user program. klao@1030: void next(Node&) const {} klao@1030: alpar@1630: // /// \brief First undirected edge of the graph alpar@1630: // /// alpar@1630: // /// \note This method is part of so called \ref alpar@1630: // /// developpers_interface "Developpers' interface", so it shouldn't alpar@1630: // /// be used in an end-user program. klao@1909: void first(UEdge&) const {} alpar@1630: // /// \brief Next undirected edge of the graph alpar@1630: // /// alpar@1630: // /// \note This method is part of so called \ref alpar@1630: // /// developpers_interface "Developpers' interface", so it shouldn't alpar@1630: // /// be used in an end-user program. klao@1909: void next(UEdge&) const {} klao@1030: alpar@1630: // /// \brief First directed edge of the graph alpar@1630: // /// alpar@1630: // /// \note This method is part of so called \ref alpar@1630: // /// developpers_interface "Developpers' interface", so it shouldn't alpar@1630: // /// be used in an end-user program. klao@1030: void first(Edge&) const {} alpar@1630: // /// \brief Next directed edge of the graph alpar@1630: // /// alpar@1630: // /// \note This method is part of so called \ref alpar@1630: // /// developpers_interface "Developpers' interface", so it shouldn't alpar@1630: // /// be used in an end-user program. klao@1030: void next(Edge&) const {} klao@1030: alpar@1630: // /// \brief First outgoing edge from a given node alpar@1630: // /// alpar@1630: // /// \note This method is part of so called \ref alpar@1630: // /// developpers_interface "Developpers' interface", so it shouldn't alpar@1630: // /// be used in an end-user program. klao@1030: void firstOut(Edge&, Node) const {} alpar@1630: // /// \brief Next outgoing edge to a node alpar@1630: // /// alpar@1630: // /// \note This method is part of so called \ref alpar@1630: // /// developpers_interface "Developpers' interface", so it shouldn't alpar@1630: // /// be used in an end-user program. klao@1030: void nextOut(Edge&) const {} klao@1030: alpar@1630: // /// \brief First incoming edge to a given node alpar@1630: // /// alpar@1630: // /// \note This method is part of so called \ref alpar@1630: // /// developpers_interface "Developpers' interface", so it shouldn't alpar@1630: // /// be used in an end-user program. klao@1030: void firstIn(Edge&, Node) const {} alpar@1630: // /// \brief Next incoming edge to a node alpar@1630: // /// alpar@1630: // /// \note This method is part of so called \ref alpar@1630: // /// developpers_interface "Developpers' interface", so it shouldn't alpar@1630: // /// be used in an end-user program. klao@1030: void nextIn(Edge&) const {} klao@1030: klao@1030: deba@1980: void firstInc(UEdge &, bool &, const Node &) const {} deba@1980: deba@1980: void nextInc(UEdge &, bool &) const {} deba@1980: deba@1627: /// \brief Base node of the iterator klao@1158: /// klao@1158: /// Returns the base node (the source in this case) of the iterator klao@1158: Node baseNode(OutEdgeIt e) const { klao@1158: return source(e); klao@1158: } deba@1627: /// \brief Running node of the iterator klao@1158: /// klao@1158: /// Returns the running node (the target in this case) of the klao@1158: /// iterator klao@1158: Node runningNode(OutEdgeIt e) const { klao@1158: return target(e); klao@1158: } klao@1158: deba@1627: /// \brief Base node of the iterator klao@1158: /// klao@1158: /// Returns the base node (the target in this case) of the iterator klao@1158: Node baseNode(InEdgeIt e) const { klao@1158: return target(e); klao@1158: } deba@1627: /// \brief Running node of the iterator klao@1158: /// klao@1158: /// Returns the running node (the source in this case) of the klao@1158: /// iterator klao@1158: Node runningNode(InEdgeIt e) const { klao@1158: return source(e); klao@1158: } klao@1158: deba@1627: /// \brief Base node of the iterator klao@1158: /// klao@1158: /// Returns the base node of the iterator alpar@1367: Node baseNode(IncEdgeIt) const { klao@1158: return INVALID; klao@1158: } deba@1627: deba@1627: /// \brief Running node of the iterator klao@1158: /// klao@1158: /// Returns the running node of the iterator alpar@1367: Node runningNode(IncEdgeIt) const { klao@1158: return INVALID; klao@1158: } klao@1158: klao@1022: template klao@1022: struct Constraints { klao@1022: void constraints() { klao@1909: checkConcept(); klao@1909: checkConcept(); klao@1909: checkConcept(); klao@1022: } klao@1022: }; klao@1022: klao@1022: }; klao@1022: deba@1627: /// \brief An empty non-static undirected graph class. deba@1627: /// klao@1909: /// This class provides everything that \ref UGraph does. deba@1627: /// Additionally it enables building graphs from scratch. klao@1909: class ExtendableUGraph : public UGraph { klao@1022: public: deba@1627: deba@1627: /// \brief Add a new node to the graph. deba@1627: /// deba@1627: /// Add a new node to the graph. deba@1627: /// \return the new node. deba@1627: Node addNode(); deba@1627: deba@1627: /// \brief Add a new undirected edge to the graph. deba@1627: /// deba@1627: /// Add a new undirected edge to the graph. deba@1627: /// \return the new edge. klao@1909: UEdge addEdge(const Node& from, const Node& to); deba@1627: deba@1627: /// \brief Resets the graph. deba@1627: /// deba@1627: /// This function deletes all undirected edges and nodes of the graph. deba@1627: /// It also frees the memory allocated to store them. deba@1627: void clear() { } klao@1022: klao@1022: template klao@1022: struct Constraints { klao@1022: void constraints() { klao@1909: checkConcept(); klao@1909: checkConcept(); klao@1909: checkConcept(); klao@1022: klao@1909: checkConcept(); klao@1909: checkConcept(); klao@1022: checkConcept(); klao@1022: } klao@1022: }; klao@1022: klao@1022: }; klao@1022: deba@1627: /// \brief An empty erasable undirected graph class. deba@1627: /// klao@1909: /// This class is an extension of \ref ExtendableUGraph. It makes it deba@1627: /// possible to erase undirected edges or nodes. klao@1909: class ErasableUGraph : public ExtendableUGraph { klao@1022: public: klao@1022: deba@1627: /// \brief Deletes a node. deba@1627: /// deba@1627: /// Deletes a node. deba@1627: /// deba@1627: void erase(Node) { } deba@1627: /// \brief Deletes an undirected edge. deba@1627: /// deba@1627: /// Deletes an undirected edge. deba@1627: /// klao@1909: void erase(UEdge) { } deba@1627: klao@1022: template klao@1022: struct Constraints { klao@1022: void constraints() { klao@1909: checkConcept(); klao@1909: checkConcept(); klao@1022: } klao@1022: }; klao@1022: klao@962: }; klao@962: klao@1030: /// @} klao@1030: klao@962: } klao@962: klao@962: } klao@962: klao@962: #endif