2  * lemon/concept/graph.h - Part of LEMON, a generic C++ optimization library
 
     4  * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
 
     5  * (Egervary Research Group on Combinatorial Optimization, EGRES).
 
     7  * Permission to use, modify and distribute this software is granted
 
     8  * provided that this copyright notice appears in all copies. For
 
     9  * precise terms see the accompanying LICENSE file.
 
    11  * This software is provided "AS IS" with no warranty of any kind,
 
    12  * express or implied, and with no claim as to its suitability for any
 
    17 #ifndef LEMON_CONCEPT_GRAPH_H
 
    18 #define LEMON_CONCEPT_GRAPH_H
 
    20 ///\ingroup graph_concepts
 
    22 ///\brief Declaration of Graph.
 
    24 #include <lemon/invalid.h>
 
    25 #include <lemon/utility.h>
 
    26 #include <lemon/concept/maps.h>
 
    27 #include <lemon/concept_check.h>
 
    28 #include <lemon/concept/graph_component.h>
 
    34     /**************** The full-featured graph concepts ****************/
 
    37     /// \brief Modular static graph class.
 
    39     /// It should be the same as the \c StaticGraph class.
 
    41       :  virtual public BaseGraphComponent,
 
    42          public IterableGraphComponent, public MappableGraphComponent {
 
    48       typedef False UndirTag;
 
    50       typedef BaseGraphComponent::Node Node;
 
    51       typedef BaseGraphComponent::Edge Edge;
 
    53       template <typename _Graph>
 
    56           checkConcept<IterableGraphComponent, _Graph>();
 
    57           checkConcept<MappableGraphComponent, _Graph>();
 
    62     /// \brief Modular extendable graph class.
 
    64     /// It should be the same as the \c ExtendableGraph class.
 
    65     class _ExtendableGraph 
 
    66       :  virtual public BaseGraphComponent, public _StaticGraph,
 
    67          public ExtendableGraphComponent, public ClearableGraphComponent {
 
    69       typedef BaseGraphComponent::Node Node;
 
    70       typedef BaseGraphComponent::Edge Edge;
 
    72       template <typename _Graph>
 
    75           checkConcept<_StaticGraph, _Graph >();
 
    76           checkConcept<ExtendableGraphComponent, _Graph >();
 
    77           checkConcept<ClearableGraphComponent, _Graph >();
 
    82     /// \brief Modular erasable graph class.
 
    84     /// It should be the same as the \c ErasableGraph class.
 
    86       :  virtual public BaseGraphComponent, public _ExtendableGraph,
 
    87          public ErasableGraphComponent {
 
    89       typedef BaseGraphComponent::Node Node;
 
    90       typedef BaseGraphComponent::Edge Edge;
 
    92       template <typename _Graph>
 
    95           checkConcept<_ExtendableGraph, _Graph >();
 
    96           checkConcept<ErasableGraphComponent, _Graph >();
 
   101     /// \addtogroup graph_concepts
 
   104     /// An empty static graph class.
 
   106     /// This class provides all the common features of a graph structure,
 
   107     /// however completely without implementations and real data structures
 
   108     /// behind the interface.
 
   109     /// All graph algorithms should compile with this class, but it will not
 
   110     /// run properly, of course.
 
   112     /// It can be used for checking the interface compatibility,
 
   113     /// or it can serve as a skeleton of a new graph structure.
 
   115     /// Also, you will find here the full documentation of a certain graph
 
   116     /// feature, the documentation of a real graph imlementation
 
   117     /// like @ref ListGraph or
 
   118     /// @ref SmartGraph will just refer to this structure.
 
   120     /// \todo A pages describing the concept of concept description would
 
   127       ///\todo undocumented
 
   129       typedef False UndirTag;
 
   131       /// Defalult constructor.
 
   133       /// Defalult constructor.
 
   138 //       ///\todo It is not clear, what we expect from a copy constructor.
 
   139 //       ///E.g. How to assign the nodes/edges to each other? What about maps?
 
   140 //       StaticGraph(const StaticGraph& g) { }
 
   142       /// The base type of node iterators, 
 
   143       /// or in other words, the trivial node iterator.
 
   145       /// This is the base type of each node iterator,
 
   146       /// thus each kind of node iterator converts to this.
 
   147       /// More precisely each kind of node iterator should be inherited 
 
   148       /// from the trivial node iterator.
 
   151         /// Default constructor
 
   153         /// @warning The default constructor sets the iterator
 
   154         /// to an undefined value.
 
   156         /// Copy constructor.
 
   158         /// Copy constructor.
 
   160         Node(const Node&) { }
 
   162         /// Invalid constructor \& conversion.
 
   164         /// This constructor initializes the iterator to be invalid.
 
   165         /// \sa Invalid for more details.
 
   167         /// Equality operator
 
   169         /// Two iterators are equal if and only if they point to the
 
   170         /// same object or both are invalid.
 
   171         bool operator==(Node) const { return true; }
 
   173         /// Inequality operator
 
   175         /// \sa operator==(Node n)
 
   177         bool operator!=(Node) const { return true; }
 
   179 	/// Artificial ordering operator.
 
   181 	/// To allow the use of graph descriptors as key type in std::map or
 
   182 	/// similar associative container we require this.
 
   184 	/// \note This operator only have to define some strict ordering of
 
   185 	/// the items; this order has nothing to do with the iteration
 
   186 	/// ordering of the items.
 
   188 	/// \bug This is a technical requirement. Do we really need this?
 
   189 	bool operator<(Node) const { return false; }
 
   193       /// This iterator goes through each node.
 
   195       /// This iterator goes through each node.
 
   196       /// Its usage is quite simple, for example you can count the number
 
   197       /// of nodes in graph \c g of type \c Graph like this:
 
   200       /// for (Graph::NodeIt n(g); n!=INVALID; ++n) ++count;
 
   202       class NodeIt : public Node {
 
   204         /// Default constructor
 
   206         /// @warning The default constructor sets the iterator
 
   207         /// to an undefined value.
 
   209         /// Copy constructor.
 
   211         /// Copy constructor.
 
   213         NodeIt(const NodeIt& n) : Node(n) { }
 
   214         /// Invalid constructor \& conversion.
 
   216         /// Initialize the iterator to be invalid.
 
   217         /// \sa Invalid for more details.
 
   219         /// Sets the iterator to the first node.
 
   221         /// Sets the iterator to the first node of \c g.
 
   223         NodeIt(const StaticGraph&) { }
 
   224         /// Node -> NodeIt conversion.
 
   226         /// Sets the iterator to the node of \c the graph pointed by 
 
   227 	/// the trivial iterator.
 
   228         /// This feature necessitates that each time we 
 
   229         /// iterate the edge-set, the iteration order is the same.
 
   230         NodeIt(const StaticGraph&, const Node&) { }
 
   233         /// Assign the iterator to the next node.
 
   235         NodeIt& operator++() { return *this; }
 
   239       /// The base type of the edge iterators.
 
   241       /// The base type of the edge iterators.
 
   245         /// Default constructor
 
   247         /// @warning The default constructor sets the iterator
 
   248         /// to an undefined value.
 
   250         /// Copy constructor.
 
   252         /// Copy constructor.
 
   254         Edge(const Edge&) { }
 
   255         /// Initialize the iterator to be invalid.
 
   257         /// Initialize the iterator to be invalid.
 
   260         /// Equality operator
 
   262         /// Two iterators are equal if and only if they point to the
 
   263         /// same object or both are invalid.
 
   264         bool operator==(Edge) const { return true; }
 
   265         /// Inequality operator
 
   267         /// \sa operator==(Edge n)
 
   269         bool operator!=(Edge) const { return true; }
 
   271 	/// Artificial ordering operator.
 
   273 	/// To allow the use of graph descriptors as key type in std::map or
 
   274 	/// similar associative container we require this.
 
   276 	/// \note This operator only have to define some strict ordering of
 
   277 	/// the items; this order has nothing to do with the iteration
 
   278 	/// ordering of the items.
 
   280 	/// \bug This is a technical requirement. Do we really need this?
 
   281 	bool operator<(Edge) const { return false; }
 
   284       /// This iterator goes trough the outgoing edges of a node.
 
   286       /// This iterator goes trough the \e outgoing edges of a certain node
 
   288       /// Its usage is quite simple, for example you can count the number
 
   289       /// of outgoing edges of a node \c n
 
   290       /// in graph \c g of type \c Graph as follows.
 
   293       /// for (Graph::OutEdgeIt e(g, n); e!=INVALID; ++e) ++count;
 
   296       class OutEdgeIt : public Edge {
 
   298         /// Default constructor
 
   300         /// @warning The default constructor sets the iterator
 
   301         /// to an undefined value.
 
   303         /// Copy constructor.
 
   305         /// Copy constructor.
 
   307         OutEdgeIt(const OutEdgeIt& e) : Edge(e) { }
 
   308         /// Initialize the iterator to be invalid.
 
   310         /// Initialize the iterator to be invalid.
 
   312         OutEdgeIt(Invalid) { }
 
   313         /// This constructor sets the iterator to the first outgoing edge.
 
   315         /// This constructor sets the iterator to the first outgoing edge of
 
   317         OutEdgeIt(const StaticGraph&, const Node&) { }
 
   318         /// Edge -> OutEdgeIt conversion
 
   320         /// Sets the iterator to the value of the trivial iterator.
 
   321 	/// This feature necessitates that each time we 
 
   322         /// iterate the edge-set, the iteration order is the same.
 
   323         OutEdgeIt(const StaticGraph&, const Edge&) { }
 
   324         ///Next outgoing edge
 
   326         /// Assign the iterator to the next 
 
   327         /// outgoing edge of the corresponding node.
 
   328         OutEdgeIt& operator++() { return *this; }
 
   331       /// This iterator goes trough the incoming edges of a node.
 
   333       /// This iterator goes trough the \e incoming edges of a certain node
 
   335       /// Its usage is quite simple, for example you can count the number
 
   336       /// of outgoing edges of a node \c n
 
   337       /// in graph \c g of type \c Graph as follows.
 
   340       /// for(Graph::InEdgeIt e(g, n); e!=INVALID; ++e) ++count;
 
   343       class InEdgeIt : public Edge {
 
   345         /// Default constructor
 
   347         /// @warning The default constructor sets the iterator
 
   348         /// to an undefined value.
 
   350         /// Copy constructor.
 
   352         /// Copy constructor.
 
   354         InEdgeIt(const InEdgeIt& e) : Edge(e) { }
 
   355         /// Initialize the iterator to be invalid.
 
   357         /// Initialize the iterator to be invalid.
 
   359         InEdgeIt(Invalid) { }
 
   360         /// This constructor sets the iterator to first incoming edge.
 
   362         /// This constructor set the iterator to the first incoming edge of
 
   364         InEdgeIt(const StaticGraph&, const Node&) { }
 
   365         /// Edge -> InEdgeIt conversion
 
   367         /// Sets the iterator to the value of the trivial iterator \c e.
 
   368         /// This feature necessitates that each time we 
 
   369         /// iterate the edge-set, the iteration order is the same.
 
   370         InEdgeIt(const StaticGraph&, const Edge&) { }
 
   371         /// Next incoming edge
 
   373         /// Assign the iterator to the next inedge of the corresponding node.
 
   375         InEdgeIt& operator++() { return *this; }
 
   377       /// This iterator goes through each edge.
 
   379       /// This iterator goes through each edge of a graph.
 
   380       /// Its usage is quite simple, for example you can count the number
 
   381       /// of edges in a graph \c g of type \c Graph as follows:
 
   384       /// for(Graph::EdgeIt e(g); e!=INVALID; ++e) ++count;
 
   386       class EdgeIt : public Edge {
 
   388         /// Default constructor
 
   390         /// @warning The default constructor sets the iterator
 
   391         /// to an undefined value.
 
   393         /// Copy constructor.
 
   395         /// Copy constructor.
 
   397         EdgeIt(const EdgeIt& e) : Edge(e) { }
 
   398         /// Initialize the iterator to be invalid.
 
   400         /// Initialize the iterator to be invalid.
 
   403         /// This constructor sets the iterator to the first edge.
 
   405         /// This constructor sets the iterator to the first edge of \c g.
 
   406         ///@param g the graph
 
   407         EdgeIt(const StaticGraph& g) { ignore_unused_variable_warning(g); }
 
   408         /// Edge -> EdgeIt conversion
 
   410         /// Sets the iterator to the value of the trivial iterator \c e.
 
   411         /// This feature necessitates that each time we 
 
   412         /// iterate the edge-set, the iteration order is the same.
 
   413         EdgeIt(const StaticGraph&, const Edge&) { } 
 
   416         /// Assign the iterator to the next edge.
 
   417         EdgeIt& operator++() { return *this; }
 
   419       ///Gives back the target node of an edge.
 
   421       ///Gives back the target node of an edge.
 
   423       Node target(Edge) const { return INVALID; }
 
   424       ///Gives back the source node of an edge.
 
   426       ///Gives back the source node of an edge.
 
   428       Node source(Edge) const { return INVALID; }
 
   430 //       /// Gives back the first Node in the iterating order.
 
   432 //       /// Gives back the first Node in the iterating order.
 
   434       void first(Node&) const {}
 
   436 //       /// Gives back the next Node in the iterating order.
 
   438 //       /// Gives back the next Node in the iterating order.
 
   440       void next(Node&) const {}
 
   442 //       /// Gives back the first Edge in the iterating order.
 
   444 //       /// Gives back the first Edge in the iterating order.
 
   446       void first(Edge&) const {}
 
   447 //       /// Gives back the next Edge in the iterating order.
 
   449 //       /// Gives back the next Edge in the iterating order.
 
   451       void next(Edge&) const {}
 
   454 //       /// Gives back the first of the Edges point to the given Node.
 
   456 //       /// Gives back the first of the Edges point to the given Node.
 
   458       void firstIn(Edge&, const Node&) const {}
 
   460 //       /// Gives back the next of the Edges points to the given Node.
 
   463 //       /// Gives back the next of the Edges points to the given Node.
 
   465       void nextIn(Edge&) const {}
 
   467 //       /// Gives back the first of the Edges start from the given Node.
 
   469 //       /// Gives back the first of the Edges start from the given Node.
 
   471       void firstOut(Edge&, const Node&) const {}
 
   473 //       /// Gives back the next of the Edges start from the given Node.
 
   475 //       /// Gives back the next of the Edges start from the given Node.
 
   477       void nextOut(Edge&) const {}
 
   479       /// \brief The base node of the iterator.
 
   481       /// Gives back the base node of the iterator.
 
   482       /// It is always the target of the pointed edge.
 
   483       Node baseNode(const InEdgeIt&) const { return INVALID; }
 
   485       /// \brief The running node of the iterator.
 
   487       /// Gives back the running node of the iterator.
 
   488       /// It is always the source of the pointed edge.
 
   489       Node runningNode(const InEdgeIt&) const { return INVALID; }
 
   491       /// \brief The base node of the iterator.
 
   493       /// Gives back the base node of the iterator.
 
   494       /// It is always the source of the pointed edge.
 
   495       Node baseNode(const OutEdgeIt&) const { return INVALID; }
 
   497       /// \brief The running node of the iterator.
 
   499       /// Gives back the running node of the iterator.
 
   500       /// It is always the target of the pointed edge.
 
   501       Node runningNode(const OutEdgeIt&) const { return INVALID; }
 
   503       /// \brief The opposite node on the given edge.
 
   505       /// Gives back the opposite node on the given edge.
 
   506       Node oppositeNode(const Node&, const Edge&) const { return INVALID; }
 
   508       /// \brief Read write map of the nodes to type \c T.
 
   510       /// ReadWrite map of the nodes to type \c T.
 
   512       /// \warning Making maps that can handle bool type (NodeMap<bool>)
 
   513       /// needs some extra attention!
 
   514       /// \todo Wrong documentation
 
   516       class NodeMap : public ReadWriteMap< Node, T >
 
   521         NodeMap(const StaticGraph&) { }
 
   523         NodeMap(const StaticGraph&, T) { }
 
   526         NodeMap(const NodeMap& nm) : ReadWriteMap< Node, T >(nm) { }
 
   527         ///Assignment operator
 
   528         NodeMap& operator=(const NodeMap&) { return *this; }
 
   529         // \todo fix this concept
 
   532       /// \brief Read write map of the edges to type \c T.
 
   534       /// Reference map of the edges to type \c T.
 
   536       /// \warning Making maps that can handle bool type (EdgeMap<bool>)
 
   537       /// needs some extra attention!
 
   538       /// \todo Wrong documentation
 
   540       class EdgeMap : public ReadWriteMap<Edge,T>
 
   545         EdgeMap(const StaticGraph&) { }
 
   547         EdgeMap(const StaticGraph&, T) { }
 
   549         EdgeMap(const EdgeMap& em) : ReadWriteMap<Edge,T>(em) { }
 
   550         ///Assignment operator
 
   551         EdgeMap& operator=(const EdgeMap&) { return *this; }
 
   552         // \todo fix this concept    
 
   555       template <typename _Graph>
 
   556       struct Constraints : public _StaticGraph::Constraints<_Graph> {};
 
   560     /// An empty non-static graph class.
 
   562     /// This class provides everything that \ref StaticGraph does.
 
   563     /// Additionally it enables building graphs from scratch.
 
   564     class ExtendableGraph : public StaticGraph
 
   567       /// Defalult constructor.
 
   569       /// Defalult constructor.
 
   571       ExtendableGraph() { }
 
   572       ///Add a new node to the graph.
 
   574       /// \return the new node.
 
   576       Node addNode() { return INVALID; }
 
   577       ///Add a new edge to the graph.
 
   579       ///Add a new edge to the graph with source node \c s
 
   580       ///and target node \c t.
 
   581       ///\return the new edge.
 
   582       Edge addEdge(Node, Node) { return INVALID; }
 
   584       /// Resets the graph.
 
   586       /// This function deletes all edges and nodes of the graph.
 
   587       /// It also frees the memory allocated to store them.
 
   588       /// \todo It might belong to \ref ErasableGraph.
 
   591       template <typename _Graph>
 
   592       struct Constraints : public _ExtendableGraph::Constraints<_Graph> {};
 
   596     /// An empty erasable graph class.
 
   598     /// This class is an extension of \ref ExtendableGraph. It makes it
 
   599     /// possible to erase edges or nodes.
 
   600     class ErasableGraph : public ExtendableGraph
 
   603       /// Defalult constructor.
 
   605       /// Defalult constructor.
 
   610       /// Deletes node \c n node.
 
   615       /// Deletes edge \c e edge.
 
   619       template <typename _Graph>
 
   620       struct Constraints : public _ErasableGraph::Constraints<_Graph> {};
 
   625   } //namespace concept  
 
   630 #endif // LEMON_CONCEPT_GRAPH_H