COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/hugo/skeletons/graph.h @ 872:c010b38ea35b

Last change on this file since 872:c010b38ea35b was 826:056fbb112b30, checked in by Alpar Juttner, 20 years ago

Spell checking (Ereasable ->Erasable), affected also the code.

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