klao@962: /* -*- C++ -*-
klao@962:  *
ladanyi@1435:  * lemon/concept/undir_graph_component.h - Part of LEMON, a generic
klao@962:  * C++ optimization library
klao@962:  *
alpar@1164:  * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi
alpar@1359:  * Kutatocsoport (Egervary Research Group on Combinatorial Optimization,
klao@962:  * 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: 
klao@962: #ifndef LEMON_CONCEPT_UNDIR_GRAPH_H
klao@962: #define LEMON_CONCEPT_UNDIR_GRAPH_H
klao@962: 
klao@962: #include <lemon/concept/graph_component.h>
alpar@1620: #include <lemon/concept/graph.h>
alpar@1448: #include <lemon/utility.h>
klao@962: 
klao@962: namespace lemon {
klao@962:   namespace concept {
klao@962: 
alpar@1630: //     /// Skeleton class which describes an edge with direction in \ref
alpar@1630: //     /// UndirGraph "undirected graph".
klao@1158:     template <typename UndirGraph>
klao@1158:     class UndirGraphEdge : public UndirGraph::UndirEdge {
klao@1158:       typedef typename UndirGraph::UndirEdge UndirEdge;
klao@1158:       typedef typename UndirGraph::Node Node;
klao@1030:     public:
klao@1030: 
klao@1030:       /// \e
klao@1030:       UndirGraphEdge() {}
klao@1030: 
klao@1030:       /// \e
alpar@1367:       UndirGraphEdge(const UndirGraphEdge& e) : UndirGraph::UndirEdge(e) {}
klao@1030: 
klao@1030:       /// \e
klao@1030:       UndirGraphEdge(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@1158:       UndirGraphEdge(const UndirGraph &g,
klao@1158: 		     UndirEdge undir_edge, Node n) {
klao@1030: 	ignore_unused_variable_warning(undir_edge);
klao@1158: 	ignore_unused_variable_warning(g);
klao@1158: 	ignore_unused_variable_warning(n);
klao@1030:       }
klao@1030: 
klao@1030:       /// \e
klao@1030:       UndirGraphEdge& operator=(UndirGraphEdge) { return *this; }
klao@1030: 
klao@1030:       /// \e
klao@1030:       bool operator==(UndirGraphEdge) const { return true; }
klao@1030:       /// \e
klao@1030:       bool operator!=(UndirGraphEdge) const { return false; }
klao@1030: 
klao@1030:       /// \e
klao@1030:       bool operator<(UndirGraphEdge) const { return false; }
klao@1030: 
klao@1030:       template <typename Edge>
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@1030: 	  UndirEdge 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@1158: 	UndirEdge ue;
klao@1158: 	UndirGraph graph;
klao@1158: 	Node n;
klao@1030:       };
klao@1030:     };
klao@1030:     
klao@962: 
klao@962:     struct BaseIterableUndirGraphConcept {
deba@989: 
klao@1022:       template <typename Graph>
klao@1022:       struct Constraints {
klao@962: 
klao@1022: 	typedef typename Graph::UndirEdge UndirEdge;
klao@1022: 	typedef typename Graph::Edge Edge;
klao@1022: 	typedef typename Graph::Node Node;
klao@962: 
klao@1022: 	void constraints() {
klao@1022: 	  checkConcept<BaseIterableGraphComponent, Graph>();
klao@1030: 	  checkConcept<GraphItem<>, UndirEdge>();
alpar@1620: 	  //checkConcept<UndirGraphEdge<Graph>, 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);
deba@1627: 	  Edge e = graph.direct(UndirEdge(), true);
deba@1627: 	  e = graph.direct(UndirEdge(), 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@1030: 	UndirEdge ue;
klao@1022:       };
klao@1022: 
klao@962:     };
klao@962: 
klao@1022: 
klao@962:     struct IterableUndirGraphConcept {
klao@962: 
klao@1022:       template <typename Graph>
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@1022: 	  //checkConcept< BaseIterableUndirGraphConcept, Graph > ();
klao@962: 
klao@1022: 	  checkConcept<IterableGraphComponent, Graph> ();
klao@1021: 
klao@1022: 	  typedef typename Graph::UndirEdge UndirEdge;
klao@1022: 	  typedef typename Graph::UndirEdgeIt UndirEdgeIt;
klao@1030: 	  typedef typename Graph::IncEdgeIt IncEdgeIt;
klao@1022: 
klao@1022: 	  checkConcept<GraphIterator<Graph, UndirEdge>, UndirEdgeIt>();
klao@1030: 	  checkConcept<GraphIncIterator<Graph, UndirEdge>, IncEdgeIt>();
klao@1022: 	}
klao@1022:       };
klao@1022: 
klao@1022:     };
klao@1022: 
klao@1022:     struct MappableUndirGraphConcept {
klao@1022: 
klao@1022:       template <typename Graph>
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<MappableGraphComponent, Graph>();
klao@1022: 
klao@1022: 	  typedef typename Graph::template UndirEdgeMap<int> IntMap;
klao@1022: 	  checkConcept<GraphMap<Graph, typename Graph::UndirEdge, int>,
klao@1022: 	    IntMap >();
klao@1022: 
klao@1022: 	  typedef typename Graph::template UndirEdgeMap<bool> BoolMap;
klao@1022: 	  checkConcept<GraphMap<Graph, typename Graph::UndirEdge, bool>,
klao@1022: 	    BoolMap >();
klao@1022: 
klao@1022: 	  typedef typename Graph::template UndirEdgeMap<Dummy> DummyMap;
klao@1022: 	  checkConcept<GraphMap<Graph, typename Graph::UndirEdge, Dummy>,
klao@1022: 	    DummyMap >();
klao@1022: 	}
klao@1022:       };
klao@1022: 
klao@1022:     };
klao@1022: 
klao@1022:     struct ExtendableUndirGraphConcept {
klao@1022: 
klao@1022:       template <typename Graph>
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@1022: 	typename Graph::UndirEdge uedge;
klao@1022: 	Graph graph;
klao@1022:       };
klao@1022: 
klao@1022:     };
klao@1022: 
klao@1022:     struct ErasableUndirGraphConcept {
klao@1022: 
klao@1022:       template <typename Graph>
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@1022: 	typename Graph::UndirEdge 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@1030:     /// explanation of this and more see also the page \ref undir_graphs,
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: 
deba@1627:     class UndirGraph {
klao@1022:     public:
alpar@1448:       ///\e
alpar@1448: 
alpar@1448:       ///\todo undocumented
alpar@1448:       ///
alpar@1448:       typedef True UndirTag;
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:
deba@1627:       /// \code
deba@1627:       /// int count=0;
deba@1627:       /// for (Graph::NodeIt n(g); n!=INVALID; ++n) ++count;
deba@1627:       /// \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:         ///
deba@1627:         NodeIt(const UndirGraph&) { }
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.
deba@1627:         NodeIt(const UndirGraph&, 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:       ///
alpar@1620:       class UndirEdge {
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:         UndirEdge() { }
alpar@1620:         /// Copy constructor.
klao@1030: 
alpar@1620:         /// Copy constructor.
alpar@1620:         ///
alpar@1620:         UndirEdge(const UndirEdge&) { }
alpar@1620:         /// Initialize the iterator to be invalid.
klao@1030: 
alpar@1620:         /// Initialize the iterator to be invalid.
alpar@1620:         ///
alpar@1620:         UndirEdge(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.
alpar@1620:         bool operator==(UndirEdge) const { return true; }
alpar@1620:         /// Inequality operator
klao@1030: 
alpar@1620:         /// \sa operator==(UndirEdge n)
alpar@1620:         ///
alpar@1620:         bool operator!=(UndirEdge) 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?
deba@1627: 	bool operator<(UndirEdge) 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@1620:       /// \code
alpar@1620:       /// int count=0;
alpar@1620:       /// for(Graph::UndirEdgeIt e(g); e!=INVALID; ++e) ++count;
alpar@1620:       /// \endcode
alpar@1620:       class UndirEdgeIt : public UndirEdge {
alpar@1620:       public:
alpar@1620:         /// Default constructor
deba@1627: 
alpar@1620:         /// @warning The default constructor sets the iterator
alpar@1620:         /// to an undefined value.
alpar@1620:         UndirEdgeIt() { }
alpar@1620:         /// Copy constructor.
deba@1627: 
alpar@1620:         /// Copy constructor.
alpar@1620:         ///
alpar@1620:         UndirEdgeIt(const UndirEdgeIt& e) : UndirEdge(e) { }
alpar@1620:         /// Initialize the iterator to be invalid.
klao@1030: 
alpar@1620:         /// Initialize the iterator to be invalid.
alpar@1620:         ///
alpar@1620:         UndirEdgeIt(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.
alpar@1620:         UndirEdgeIt(const UndirGraph&) { }
alpar@1620:         /// UndirEdge -> UndirEdgeIt 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.
alpar@1620:         UndirEdgeIt(const UndirGraph&, const UndirEdge&) { } 
deba@1627:         /// Next undirected edge
alpar@1620:         
deba@1627:         /// Assign the iterator to the next undirected edge.
alpar@1620:         UndirEdgeIt& 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
alpar@1620:       /// of a certain node
alpar@1620:       /// of a graph.
alpar@1620:       /// Its usage is quite simple, for example you can compute the
alpar@1620:       /// degree (i.e. count the number
alpar@1620:       /// of incident edges of a node \c n
alpar@1620:       /// in graph \c g of type \c Graph as follows.
alpar@1620:       /// \code
alpar@1620:       /// int count=0;
alpar@1620:       /// for(Graph::IncEdgeIt e(g, n); e!=INVALID; ++e) ++count;
alpar@1620:       /// \endcode
alpar@1620:       class IncEdgeIt : public UndirEdge {
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:         ///
alpar@1620:         IncEdgeIt(const IncEdgeIt& e) : UndirEdge(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.
alpar@1620:         IncEdgeIt(const UndirGraph&, const Node&) { }
alpar@1620:         /// UndirEdge -> 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.
alpar@1620:         IncEdgeIt(const UndirGraph&, const UndirEdge&) { }
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.
deba@1627:       class Edge : public UndirEdge {
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:         ///
deba@1627:         Edge(const Edge& e) : UndirEdge(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:
deba@1627:       /// \code
deba@1627:       /// int count=0;
deba@1627:       /// for(Graph::EdgeIt e(g); e!=INVALID; ++e) ++count;
deba@1627:       /// \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
alpar@1643:         EdgeIt(const UndirGraph &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.
deba@1627:         EdgeIt(const UndirGraph&, 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.
deba@1627:       /// \code
deba@1627:       /// int count=0;
deba@1627:       /// for (Graph::OutEdgeIt e(g, n); e!=INVALID; ++e) ++count;
deba@1627:       /// \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
alpar@1643:         OutEdgeIt(const UndirGraph& 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.
deba@1627:         OutEdgeIt(const UndirGraph&, 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.
deba@1627:       /// \code
deba@1627:       /// int count=0;
deba@1627:       /// for(Graph::InEdgeIt e(g, n); e!=INVALID; ++e) ++count;
deba@1627:       /// \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
alpar@1643:         InEdgeIt(const UndirGraph& 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.
deba@1627:         InEdgeIt(const UndirGraph&, 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<bool>)
deba@1627:       /// needs some extra attention!
alpar@1630:       /// \todo Wrong documentation
deba@1627:       template<class T> 
deba@1627:       class NodeMap : public ReadWriteMap< Node, T >
deba@1627:       {
deba@1627:       public:
deba@1627: 
deba@1627:         ///\e
deba@1627:         NodeMap(const UndirGraph&) { }
deba@1627:         ///\e
deba@1627:         NodeMap(const UndirGraph&, 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<bool>)
deba@1627:       /// needs some extra attention!
alpar@1630:       /// \todo Wrong documentation
deba@1627:       template<class T> 
deba@1627:       class EdgeMap : public ReadWriteMap<Edge,T>
deba@1627:       {
deba@1627:       public:
deba@1627: 
deba@1627:         ///\e
deba@1627:         EdgeMap(const UndirGraph&) { }
deba@1627:         ///\e
deba@1627:         EdgeMap(const UndirGraph&, T) { }
deba@1627:         ///Copy constructor
deba@1627:         EdgeMap(const EdgeMap& em) : ReadWriteMap<Edge,T>(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
alpar@1620:       /// \warning Making maps that can handle bool type (UndirEdgeMap<bool>)
alpar@1620:       /// needs some extra attention!
alpar@1630:       /// \todo Wrong documentation
alpar@1620:       template<class T> 
alpar@1620:       class UndirEdgeMap : public ReadWriteMap<UndirEdge,T>
alpar@1620:       {
klao@1030:       public:
klao@1030: 
alpar@1620:         ///\e
alpar@1620:         UndirEdgeMap(const UndirGraph&) { }
alpar@1620:         ///\e
alpar@1620:         UndirEdgeMap(const UndirGraph&, T) { }
alpar@1620:         ///Copy constructor
deba@1627:         UndirEdgeMap(const UndirEdgeMap& em) : ReadWriteMap<UndirEdge,T>(em) {}
alpar@1620:         ///Assignment operator
alpar@1620:         UndirEdgeMap &operator=(const UndirEdgeMap&) { 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.
deba@1627:       Edge direct(const UndirEdge&, 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.
deba@1627:       Edge direct(const UndirEdge&, 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@1030:       Node oppositeNode(Node, UndirEdge) const { return INVALID; }
klao@1030: 
deba@1627:       /// \brief First node of the undirected edge.
deba@1627:       ///
klao@1030:       /// \return the first node of the given UndirEdge.
klao@1030:       ///
klao@1030:       /// Naturally undirectected 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@1030:       Node source(UndirEdge) const { return INVALID; }
klao@1030: 
deba@1627:       /// \brief Second node of the undirected edge.
klao@1030:       Node target(UndirEdge) 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@1030:       void first(UndirEdge&) 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@1030:       void next(UndirEdge&) 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@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 <typename Graph>
klao@1022:       struct Constraints {
klao@1022: 	void constraints() {
klao@1022: 	  checkConcept<BaseIterableUndirGraphConcept, Graph>();
klao@1022: 	  checkConcept<IterableUndirGraphConcept, Graph>();
klao@1022: 	  checkConcept<MappableUndirGraphConcept, Graph>();
klao@1022: 	}
klao@1022:       };
klao@1022: 
klao@1022:     };
klao@1022: 
deba@1627:     /// \brief An empty non-static undirected graph class.
deba@1627:     ///    
deba@1627:     /// This class provides everything that \ref UndirGraph does.
deba@1627:     /// Additionally it enables building graphs from scratch.
klao@1022:     class ExtendableUndirGraph : public UndirGraph {
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.
deba@1627:       UndirEdge 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 <typename Graph>
klao@1022:       struct Constraints {
klao@1022: 	void constraints() {
klao@1022: 	  checkConcept<BaseIterableUndirGraphConcept, Graph>();
klao@1022: 	  checkConcept<IterableUndirGraphConcept, Graph>();
klao@1022: 	  checkConcept<MappableUndirGraphConcept, Graph>();
klao@1022: 
klao@1022: 	  checkConcept<UndirGraph, Graph>();
klao@1022: 	  checkConcept<ExtendableUndirGraphConcept, Graph>();
klao@1022: 	  checkConcept<ClearableGraphComponent, Graph>();
klao@1022: 	}
klao@1022:       };
klao@1022: 
klao@1022:     };
klao@1022: 
deba@1627:     /// \brief An empty erasable undirected graph class.
deba@1627:     ///
deba@1627:     /// This class is an extension of \ref ExtendableUndirGraph. It makes it
deba@1627:     /// possible to erase undirected edges or nodes.
klao@1022:     class ErasableUndirGraph : public ExtendableUndirGraph {
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:       ///
deba@1627:       void erase(UndirEdge) { }
deba@1627: 
klao@1022:       template <typename Graph>
klao@1022:       struct Constraints {
klao@1022: 	void constraints() {
klao@1022: 	  checkConcept<ExtendableUndirGraph, Graph>();
klao@1022: 	  checkConcept<ErasableUndirGraphConcept, Graph>();
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