COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/hugo/skeletons/graph.h @ 881:a9f19f38970b

Last change on this file since 881:a9f19f38970b was 881:a9f19f38970b, checked in by Alpar Juttner, 20 years ago

Right (but still too short) documentation of the namespaces.

File size: 13.3 KB
RevLine 
[174]1// -*- c++ -*-
[503]2#ifndef HUGO_SKELETON_GRAPH_H
3#define HUGO_SKELETON_GRAPH_H
[52]4
[794]5///\ingroup skeletons
[242]6///\file
[880]7///\brief Declaration of Graph.
[242]8
[542]9#include <hugo/invalid.h>
[732]10#include <hugo/skeletons/maps.h>
[145]11
[163]12namespace hugo {
[732]13  namespace skeleton {
14   
[794]15    /// \addtogroup skeletons
16    /// @{
[163]17
[732]18    /// An empty static graph class.
19 
20    /// This class provides all the common features of a graph structure,
21    /// however completely without implementations and real data structures
22    /// behind the interface.
23    /// All graph algorithms should compile with this class, but it will not
24    /// run properly, of course.
25    ///
26    /// It can be used for checking the interface compatibility,
27    /// or it can serve as a skeleton of a new graph structure.
28    ///
29    /// Also, you will find here the full documentation of a certain graph
30    /// feature, the documentation of a real graph imlementation
31    /// like @ref ListGraph or
32    /// @ref SmartGraph will just refer to this structure.
[880]33    class StaticGraph
[732]34    {
35    public:
36      /// Defalult constructor.
[801]37
38      /// Defalult constructor.
39      ///
[880]40      StaticGraph() { }
[732]41      ///Copy consructor.
[163]42
[801]43//       ///\todo It is not clear, what we expect from a copy constructor.
44//       ///E.g. How to assign the nodes/edges to each other? What about maps?
[880]45//       StaticGraph(const StaticGraph& g) { }
[732]46
[774]47      /// The base type of node iterators,
48      /// or in other words, the trivial node iterator.
[732]49
[774]50      /// This is the base type of each node iterator,
51      /// thus each kind of node iterator converts to this.
[801]52      /// More precisely each kind of node iterator should be inherited
[774]53      /// from the trivial node iterator.
[732]54      class Node {
55      public:
[801]56        /// Default constructor
57
[732]58        /// @warning The default constructor sets the iterator
59        /// to an undefined value.
[774]60        Node() { }
61        /// Copy constructor.
[801]62
63        /// Copy constructor.
64        ///
[774]65        Node(const Node&) { }
[801]66
[732]67        /// Invalid constructor \& conversion.
68
69        /// This constructor initializes the iterator to be invalid.
70        /// \sa Invalid for more details.
[774]71        Node(Invalid) { }
[801]72        /// Equality operator
73
[732]74        /// Two iterators are equal if and only if they point to the
75        /// same object or both are invalid.
76        bool operator==(Node) const { return true; }
77
[801]78        /// Inequality operator
79       
[732]80        /// \sa \ref operator==(Node n)
81        ///
82        bool operator!=(Node) const { return true; }
83
[801]84        ///Comparison operator.
85
86        ///This is a strict ordering between the nodes.
87        ///
88        ///This ordering can be different from the order in which NodeIt
89        ///goes through the nodes.
90        ///\todo Possibly we don't need it.
[732]91        bool operator<(Node) const { return true; }
92      };
93   
94      /// This iterator goes through each node.
95
96      /// This iterator goes through each node.
97      /// Its usage is quite simple, for example you can count the number
[774]98      /// of nodes in graph \c g of type \c Graph like this:
[732]99      /// \code
[774]100      /// int count=0;
[801]101      /// for (Graph::NodeIt n(g); n!=INVALID; ++n) ++count;
[732]102      /// \endcode
103      class NodeIt : public Node {
104      public:
[801]105        /// Default constructor
106
[732]107        /// @warning The default constructor sets the iterator
108        /// to an undefined value.
[774]109        NodeIt() { }
110        /// Copy constructor.
[801]111       
112        /// Copy constructor.
113        ///
[774]114        NodeIt(const NodeIt&) { }
[732]115        /// Invalid constructor \& conversion.
116
[774]117        /// Initialize the iterator to be invalid.
[732]118        /// \sa Invalid for more details.
[774]119        NodeIt(Invalid) { }
[801]120        /// Sets the iterator to the first node.
121
[774]122        /// Sets the iterator to the first node of \c g.
[801]123        ///
[880]124        NodeIt(const StaticGraph& g) { }
[801]125        /// Node -> NodeIt conversion.
126
[774]127        /// Sets the iterator to the node of \c g pointed by the trivial
[801]128        /// iterator n.
129        /// This feature necessitates that each time we
130        /// iterate the edge-set, the iteration order is the same.
[880]131        NodeIt(const StaticGraph& g, const Node& n) { }
[801]132        /// Next node.
133
[774]134        /// Assign the iterator to the next node.
[801]135        ///
[774]136        NodeIt& operator++() { return *this; }
[732]137      };
138   
139   
140      /// The base type of the edge iterators.
[801]141
142      /// The base type of the edge iterators.
143      ///
[732]144      class Edge {
145      public:
[801]146        /// Default constructor
147
[732]148        /// @warning The default constructor sets the iterator
149        /// to an undefined value.
[774]150        Edge() { }
151        /// Copy constructor.
[801]152
153        /// Copy constructor.
154        ///
[774]155        Edge(const Edge&) { }
156        /// Initialize the iterator to be invalid.
[801]157
158        /// Initialize the iterator to be invalid.
159        ///
[774]160        Edge(Invalid) { }
[801]161        /// Equality operator
162
[732]163        /// Two iterators are equal if and only if they point to the
164        /// same object or both are invalid.
165        bool operator==(Edge) const { return true; }
[801]166        /// Inequality operator
167
168        /// \sa \ref operator==(Node n)
169        ///
[732]170        bool operator!=(Edge) const { return true; }
[801]171        ///Comparison operator.
172
173        ///This is a strict ordering between the nodes.
174        ///
175        ///This ordering can be different from the order in which NodeIt
176        ///goes through the nodes.
177        ///\todo Possibly we don't need it.
178        bool operator<(Edge) const { return true; }
[732]179      };
180   
181      /// This iterator goes trough the outgoing edges of a node.
182
183      /// This iterator goes trough the \e outgoing edges of a certain node
184      /// of a graph.
185      /// Its usage is quite simple, for example you can count the number
186      /// of outgoing edges of a node \c n
[774]187      /// in graph \c g of type \c Graph as follows.
[732]188      /// \code
[774]189      /// int count=0;
[801]190      /// for (Graph::OutEdgeIt e(g, n); e!=INVALID; ++e) ++count;
[732]191      /// \endcode
192   
193      class OutEdgeIt : public Edge {
194      public:
[801]195        /// Default constructor
196
[732]197        /// @warning The default constructor sets the iterator
198        /// to an undefined value.
[774]199        OutEdgeIt() { }
200        /// Copy constructor.
[801]201
202        /// Copy constructor.
203        ///
[774]204        OutEdgeIt(const OutEdgeIt&) { }
205        /// Initialize the iterator to be invalid.
[801]206
207        /// Initialize the iterator to be invalid.
208        ///
[774]209        OutEdgeIt(Invalid) { }
[732]210        /// This constructor sets the iterator to first outgoing edge.
211   
212        /// This constructor set the iterator to the first outgoing edge of
213        /// node
214        ///@param n the node
[774]215        ///@param g the graph
[880]216        OutEdgeIt(const StaticGraph& g, const Node& n) { }
[801]217        /// Edge -> OutEdgeIt conversion
218
[774]219        /// Sets the iterator to the value of the trivial iterator \c e.
220        /// This feature necessitates that each time we
221        /// iterate the edge-set, the iteration order is the same.
[880]222        OutEdgeIt(const StaticGraph& g, const Edge& e) { }
[801]223        ///Next outgoing edge
224       
225        /// Assign the iterator to the next
226        /// outgoing edge of the corresponding node.
[774]227        OutEdgeIt& operator++() { return *this; }
[732]228      };
229
230      /// This iterator goes trough the incoming edges of a node.
231
232      /// This iterator goes trough the \e incoming edges of a certain node
233      /// of a graph.
234      /// Its usage is quite simple, for example you can count the number
235      /// of outgoing edges of a node \c n
[774]236      /// in graph \c g of type \c Graph as follows.
[732]237      /// \code
[774]238      /// int count=0;
[801]239      /// for(Graph::InEdgeIt e(g, n); e!=INVALID; ++e) ++count;
[732]240      /// \endcode
241
242      class InEdgeIt : public Edge {
243      public:
[801]244        /// Default constructor
245
[732]246        /// @warning The default constructor sets the iterator
247        /// to an undefined value.
[774]248        InEdgeIt() { }
249        /// Copy constructor.
[801]250
251        /// Copy constructor.
252        ///
[774]253        InEdgeIt(const InEdgeIt&) { }
254        /// Initialize the iterator to be invalid.
[801]255
256        /// Initialize the iterator to be invalid.
257        ///
[774]258        InEdgeIt(Invalid) { }
[801]259        /// This constructor sets the iterator to first incoming edge.
260   
261        /// This constructor set the iterator to the first incoming edge of
262        /// node
263        ///@param n the node
264        ///@param g the graph
[880]265        InEdgeIt(const StaticGraph& g, const Node& n) { }
[801]266        /// Edge -> InEdgeIt conversion
267
268        /// Sets the iterator to the value of the trivial iterator \c e.
269        /// This feature necessitates that each time we
270        /// iterate the edge-set, the iteration order is the same.
[880]271        InEdgeIt(const StaticGraph& g, const Edge& n) { }
[801]272        /// Next incoming edge
273
[774]274        /// Assign the iterator to the next inedge of the corresponding node.
[801]275        ///
[774]276        InEdgeIt& operator++() { return *this; }
[732]277      };
278      /// This iterator goes through each edge.
279
280      /// This iterator goes through each edge of a graph.
281      /// Its usage is quite simple, for example you can count the number
[774]282      /// of edges in a graph \c g of type \c Graph as follows:
[732]283      /// \code
[774]284      /// int count=0;
[801]285      /// for(Graph::EdgeIt e(g); e!=INVALID; ++e) ++count;
[732]286      /// \endcode
287      class EdgeIt : public Edge {
288      public:
[801]289        /// Default constructor
290
[732]291        /// @warning The default constructor sets the iterator
292        /// to an undefined value.
[774]293        EdgeIt() { }
294        /// Copy constructor.
[801]295
296        /// Copy constructor.
297        ///
[774]298        EdgeIt(const EdgeIt&) { }
299        /// Initialize the iterator to be invalid.
[801]300
301        /// Initialize the iterator to be invalid.
302        ///
[774]303        EdgeIt(Invalid) { }
[801]304        /// This constructor sets the iterator to first edge.
305   
306        /// This constructor set the iterator to the first edge of
307        /// node
308        ///@param g the graph
[880]309        EdgeIt(const StaticGraph& g) { }
[801]310        /// Edge -> EdgeIt conversion
311
312        /// Sets the iterator to the value of the trivial iterator \c e.
313        /// This feature necessitates that each time we
314        /// iterate the edge-set, the iteration order is the same.
[880]315        EdgeIt(const StaticGraph&, const Edge&) { }
[801]316        ///Next edge
317       
318        /// Assign the iterator to the next
319        /// edge of the corresponding node.
[774]320        EdgeIt& operator++() { return *this; }
[732]321      };
322
323      /// First node of the graph.
324
325      /// \retval i the first node.
326      /// \return the first node.
327      ///
[774]328      NodeIt& first(NodeIt& i) const { return i; }
[732]329
330      /// The first incoming edge.
[801]331
332      /// The first incoming edge.
333      ///
[774]334      InEdgeIt& first(InEdgeIt &i, Node) const { return i; }
[732]335      /// The first outgoing edge.
[801]336
337      /// The first outgoing edge.
338      ///
[774]339      OutEdgeIt& first(OutEdgeIt& i, Node) const { return i; }
[732]340      /// The first edge of the Graph.
[801]341
342      /// The first edge of the Graph.
343      ///
[774]344      EdgeIt& first(EdgeIt& i) const { return i; }
[732]345
[801]346      ///Gives back the head node of an edge.
[732]347
348      ///Gives back the head node of an edge.
[801]349      ///
[732]350      Node head(Edge) const { return INVALID; }
351      ///Gives back the tail node of an edge.
[801]352
353      ///Gives back the tail node of an edge.
354      ///
[732]355      Node tail(Edge) const { return INVALID; }
[163]356 
[732]357      ///Gives back the \e id of a node.
[182]358
[732]359      ///\warning Not all graph structures provide this feature.
360      ///
[801]361      ///\todo Should each graph provide \c id?
[774]362      int id(const Node&) const { return 0; }
[732]363      ///Gives back the \e id of an edge.
[182]364
[732]365      ///\warning Not all graph structures provide this feature.
[182]366      ///
[801]367      ///\todo Should each graph provide \c id?
[774]368      int id(const Edge&) const { return 0; }
[182]369
[801]370      /// .
371     
[880]372      ///\todo Should it be in the concept?
[801]373      ///
[774]374      int nodeNum() const { return 0; }
[801]375      /// .
[880]376
377      ///\todo Should it be in the concept?
[801]378      ///
[774]379      int edgeNum() const { return 0; }
[732]380
381
382      ///Reference map of the nodes to type \c T.
383
[880]384      /// \ingroup skeletons
[732]385      ///Reference map of the nodes to type \c T.
[880]386      /// \sa Reference
[732]387      /// \warning Making maps that can handle bool type (NodeMap<bool>)
[801]388      /// needs some extra attention!
[880]389      template<class T> class NodeMap : public ReferenceMap< Node, T >
[732]390      {
391      public:
392
[801]393        /// .
[880]394        NodeMap(const StaticGraph&) { }
[801]395        /// .
[880]396        NodeMap(const StaticGraph&, T) { }
[732]397
398        ///Copy constructor
[774]399        template<typename TT> NodeMap(const NodeMap<TT>&) { }
[732]400        ///Assignment operator
[774]401        template<typename TT> NodeMap& operator=(const NodeMap<TT>&)
402        { return *this; }
[732]403      };
404
405      ///Reference map of the edges to type \c T.
406
[880]407      /// \ingroup skeletons
[732]408      ///Reference map of the edges to type \c T.
[880]409      /// \sa Reference
[732]410      /// \warning Making maps that can handle bool type (EdgeMap<bool>)
[801]411      /// needs some extra attention!
[732]412      template<class T> class EdgeMap
413        : public ReferenceMap<Edge,T>
414      {
415      public:
416
[801]417        /// .
[880]418        EdgeMap(const StaticGraph&) { }
[801]419        /// .
[880]420        EdgeMap(const StaticGraph&, T) { }
[147]421   
[732]422        ///Copy constructor
[774]423        template<typename TT> EdgeMap(const EdgeMap<TT>&) { }
[732]424        ///Assignment operator
[774]425        template<typename TT> EdgeMap &operator=(const EdgeMap<TT>&)
426        { return *this; }
[732]427      };
[163]428    };
429
[186]430
[732]431 
[801]432    /// An empty non-static graph class.
[186]433
[880]434    /// This class provides everything that \ref StaticGraph
[732]435    /// with additional functionality which enables to build a
436    /// graph from scratch.
[880]437    class ExtendableGraph : public StaticGraph
[732]438    {
[163]439    public:
[732]440      /// Defalult constructor.
[801]441
442      /// Defalult constructor.
443      ///
[880]444      ExtendableGraph() { }
[732]445      ///Add a new node to the graph.
446
447      /// \return the new node.
448      ///
[774]449      Node addNode() { return INVALID; }
[732]450      ///Add a new edge to the graph.
451
[880]452      ///Add a new edge to the graph with tail node \c t
453      ///and head node \c h.
[732]454      ///\return the new edge.
[880]455      Edge addEdge(Node h, Node t) { return INVALID; }
[732]456   
457      /// Resets the graph.
458
459      /// This function deletes all edges and nodes of the graph.
460      /// It also frees the memory allocated to store them.
[880]461      /// \todo It might belong to \ref ErasableGraph.
[774]462      void clear() { }
[163]463    };
464
[826]465    /// An empty erasable graph class.
[52]466 
[880]467    /// This class is an extension of \ref ExtendableGraph. It also makes it
[732]468    /// possible to erase edges or nodes.
[880]469    class ErasableGraph : public ExtendableGraph
[163]470    {
471    public:
[801]472      /// Defalult constructor.
473
474      /// Defalult constructor.
475      ///
[880]476      ErasableGraph() { }
[732]477      /// Deletes a node.
[801]478
479      /// Deletes node \c n node.
480      ///
[774]481      void erase(Node n) { }
[732]482      /// Deletes an edge.
[801]483
484      /// Deletes edge \c e edge.
485      ///
[774]486      void erase(Edge e) { }
[163]487    };
488
[732]489    // @}
[801]490  } //namespace skeleton 
[174]491} //namespace hugo
[52]492
[145]493
494
[503]495#endif // HUGO_SKELETON_GRAPH_H
Note: See TracBrowser for help on using the repository browser.