COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/hugo/skeletons/graph.h @ 788:c3187cafcabf

Last change on this file since 788:c3187cafcabf was 774:4297098d9677, checked in by Alpar Juttner, 20 years ago

Merge back the whole branches/hugo++ to trunk.

File size: 12.8 KB
Line 
1// -*- c++ -*-
2#ifndef HUGO_SKELETON_GRAPH_H
3#define HUGO_SKELETON_GRAPH_H
4
5///\file
6///\brief Declaration of GraphSkeleton.
7
8#include <hugo/invalid.h>
9#include <hugo/skeletons/maps.h>
10
11/// The namespace of HugoLib
12namespace hugo {
13  namespace skeleton {
14   
15    // @defgroup empty_graph The GraphSkeleton class
16    // @{
17
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.
33    class StaticGraphSkeleton
34    {
35    public:
36      /// Defalult constructor.
37      StaticGraphSkeleton() { }
38      ///Copy consructor.
39
40      ///\todo It is not clear, what we expect from a copy constructor.
41      ///E.g. How to assign the nodes/edges to each other? What about maps?
42      StaticGraphSkeleton(const StaticGraphSkeleton& g) { }
43
44      /// The base type of node iterators,
45      /// or in other words, the trivial node iterator.
46
47      /// This is the base type of each node iterator,
48      /// thus each kind of node iterator converts to this.
49      /// More precisely each kind of node iterator have to be inherited
50      /// from the trivial node iterator.
51      class Node {
52      public:
53        /// @warning The default constructor sets the iterator
54        /// to an undefined value.
55        Node() { }
56        /// Copy constructor.
57        Node(const Node&) { }
58        /// Invalid constructor \& conversion.
59
60        /// This constructor initializes the iterator to be invalid.
61        /// \sa Invalid for more details.
62        Node(Invalid) { }
63        /// Two iterators are equal if and only if they point to the
64        /// same object or both are invalid.
65        bool operator==(Node) const { return true; }
66
67        /// \sa \ref operator==(Node n)
68        ///
69        bool operator!=(Node) const { return true; }
70
71        bool operator<(Node) const { return true; }
72      };
73   
74      /// This iterator goes through each node.
75
76      /// This iterator goes through each node.
77      /// Its usage is quite simple, for example you can count the number
78      /// of nodes in graph \c g of type \c Graph like this:
79      /// \code
80      /// int count=0;
81      /// for (Graph::NodeIt n(g); g.valid(n); ++n) ++count;
82      /// \endcode
83      class NodeIt : public Node {
84      public:
85        /// @warning The default constructor sets the iterator
86        /// to an undefined value.
87        NodeIt() { }
88        /// Copy constructor.
89        NodeIt(const NodeIt&) { }
90        /// Invalid constructor \& conversion.
91
92        /// Initialize the iterator to be invalid.
93        /// \sa Invalid for more details.
94        NodeIt(Invalid) { }
95        /// Sets the iterator to the first node of \c g.
96        NodeIt(const StaticGraphSkeleton& g) { }
97        /// Sets the iterator to the node of \c g pointed by the trivial
98        /// iterator n. This feature necessitates that each time we
99        /// iterate the node-set, the iteration order is the same.
100        NodeIt(const StaticGraphSkeleton& g, const Node& n) { }
101        /// Assign the iterator to the next node.
102        NodeIt& operator++() { return *this; }
103      };
104   
105   
106      /// The base type of the edge iterators.
107      class Edge {
108      public:
109        /// @warning The default constructor sets the iterator
110        /// to an undefined value.
111        Edge() { }
112        /// Copy constructor.
113        Edge(const Edge&) { }
114        /// Initialize the iterator to be invalid.
115        Edge(Invalid) { }
116        /// Two iterators are equal if and only if they point to the
117        /// same object or both are invalid.
118        bool operator==(Edge) const { return true; }
119        bool operator!=(Edge) const { return true; }
120        bool operator<(Edge) const { return true; }
121      };
122   
123      /// This iterator goes trough the outgoing edges of a node.
124
125      /// This iterator goes trough the \e outgoing edges of a certain node
126      /// of a graph.
127      /// Its usage is quite simple, for example you can count the number
128      /// of outgoing edges of a node \c n
129      /// in graph \c g of type \c Graph as follows.
130      /// \code
131      /// int count=0;
132      /// for (Graph::OutEdgeIt e(g, n); g.valid(e); ++e) ++count;
133      /// \endcode
134   
135      class OutEdgeIt : public Edge {
136      public:
137        /// @warning The default constructor sets the iterator
138        /// to an undefined value.
139        OutEdgeIt() { }
140        /// Copy constructor.
141        OutEdgeIt(const OutEdgeIt&) { }
142        /// Initialize the iterator to be invalid.
143        OutEdgeIt(Invalid) { }
144        /// This constructor sets the iterator to first outgoing edge.
145   
146        /// This constructor set the iterator to the first outgoing edge of
147        /// node
148        ///@param n the node
149        ///@param g the graph
150        OutEdgeIt(const StaticGraphSkeleton& g, const Node& n) { }
151        /// Sets the iterator to the value of the trivial iterator \c e.
152        /// This feature necessitates that each time we
153        /// iterate the edge-set, the iteration order is the same.
154        OutEdgeIt(const StaticGraphSkeleton& g, const Edge& e) { }
155        /// Assign the iterator to the next outedge of the corresponding node.
156        OutEdgeIt& operator++() { return *this; }
157      };
158
159      /// This iterator goes trough the incoming edges of a node.
160
161      /// This iterator goes trough the \e incoming edges of a certain node
162      /// of a graph.
163      /// Its usage is quite simple, for example you can count the number
164      /// of outgoing edges of a node \c n
165      /// in graph \c g of type \c Graph as follows.
166      /// \code
167      /// int count=0;
168      /// for(Graph::InEdgeIt e(g, n); g.valid(e); ++) ++count;
169      /// \endcode
170
171      class InEdgeIt : public Edge {
172      public:
173        /// @warning The default constructor sets the iterator
174        /// to an undefined value.
175        InEdgeIt() { }
176        /// Copy constructor.
177        InEdgeIt(const InEdgeIt&) { }
178        /// Initialize the iterator to be invalid.
179        InEdgeIt(Invalid) { }
180        /// .
181        InEdgeIt(const StaticGraphSkeleton&, const Node&) { }
182        /// .
183        InEdgeIt(const StaticGraphSkeleton&, const Edge&) { }
184        /// Assign the iterator to the next inedge of the corresponding node.
185        InEdgeIt& operator++() { return *this; }
186      };
187      //  class SymEdgeIt : public Edge {};
188
189      /// This iterator goes through each edge.
190
191      /// This iterator goes through each edge of a graph.
192      /// Its usage is quite simple, for example you can count the number
193      /// of edges in a graph \c g of type \c Graph as follows:
194      /// \code
195      /// int count=0;
196      /// for(Graph::EdgeIt e(g); g.valid(e); ++e) ++count;
197      /// \endcode
198      class EdgeIt : public Edge {
199      public:
200        /// @warning The default constructor sets the iterator
201        /// to an undefined value.
202        EdgeIt() { }
203        /// Copy constructor.
204        EdgeIt(const EdgeIt&) { }
205        /// Initialize the iterator to be invalid.
206        EdgeIt(Invalid) { }
207        /// .
208        EdgeIt(const StaticGraphSkeleton&) { }
209        /// .
210        EdgeIt(const StaticGraphSkeleton&, const Edge&) { }
211        EdgeIt& operator++() { return *this; }
212      };
213
214      /// First node of the graph.
215
216      /// \retval i the first node.
217      /// \return the first node.
218      ///
219      NodeIt& first(NodeIt& i) const { return i; }
220
221      /// The first incoming edge.
222      InEdgeIt& first(InEdgeIt &i, Node) const { return i; }
223      /// The first outgoing edge.
224      OutEdgeIt& first(OutEdgeIt& i, Node) const { return i; }
225      //  SymEdgeIt& first(SymEdgeIt&, Node) const { return i; }
226      /// The first edge of the Graph.
227      EdgeIt& first(EdgeIt& i) const { return i; }
228
229      //     Node getNext(Node) const {}
230      //     InEdgeIt getNext(InEdgeIt) const {}
231      //     OutEdgeIt getNext(OutEdgeIt) const {}
232      //     //SymEdgeIt getNext(SymEdgeIt) const {}
233      //     EdgeIt getNext(EdgeIt) const {}
234
235      /// Go to the next node.
236      NodeIt& next(NodeIt& i) const { return i; }
237      /// Go to the next incoming edge.
238      InEdgeIt& next(InEdgeIt& i) const { return i; }
239      /// Go to the next outgoing edge.
240      OutEdgeIt& next(OutEdgeIt& i) const { return i; }
241      //SymEdgeIt& next(SymEdgeIt&) const { }
242      /// Go to the next edge.
243      EdgeIt& next(EdgeIt& i) const { return i; }
244
245      ///Gives back the head node of an edge.
246      Node head(Edge) const { return INVALID; }
247      ///Gives back the tail node of an edge.
248      Node tail(Edge) const { return INVALID; }
249 
250      //   Node aNode(InEdgeIt) const {}
251      //   Node aNode(OutEdgeIt) const {}
252      //   Node aNode(SymEdgeIt) const {}
253
254      //   Node bNode(InEdgeIt) const {}
255      //   Node bNode(OutEdgeIt) const {}
256      //   Node bNode(SymEdgeIt) const {}
257
258      /// Checks if a node iterator is valid
259
260      ///\todo Maybe, it would be better if iterator converted to
261      ///bool directly, as Jacint prefers.
262      bool valid(const Node&) const { return true; }
263      /// Checks if an edge iterator is valid
264
265      ///\todo Maybe, it would be better if iterator converted to
266      ///bool directly, as Jacint prefers.
267      bool valid(const Edge&) const { return true; }
268
269      ///Gives back the \e id of a node.
270
271      ///\warning Not all graph structures provide this feature.
272      ///
273      int id(const Node&) const { return 0; }
274      ///Gives back the \e id of an edge.
275
276      ///\warning Not all graph structures provide this feature.
277      ///
278      int id(const Edge&) const { return 0; }
279
280      /// Resets the graph.
281
282      /// This function deletes all edges and nodes of the graph.
283      /// It also frees the memory allocated to store them.
284      void clear() { }
285
286      int nodeNum() const { return 0; }
287      int edgeNum() const { return 0; }
288
289
290      ///Reference map of the nodes to type \c T.
291
292      ///Reference map of the nodes to type \c T.
293      /// \sa ReferenceSkeleton
294      /// \warning Making maps that can handle bool type (NodeMap<bool>)
295      /// needs extra attention!
296
297      template<class T> class NodeMap
298        : public ReferenceMap< Node, T >
299      {
300      public:
301
302        NodeMap(const StaticGraphSkeleton&) { }
303        NodeMap(const StaticGraphSkeleton&, T) { }
304
305        ///Copy constructor
306        template<typename TT> NodeMap(const NodeMap<TT>&) { }
307        ///Assignment operator
308        template<typename TT> NodeMap& operator=(const NodeMap<TT>&)
309        { return *this; }
310      };
311
312      ///Reference map of the edges to type \c T.
313
314      ///Reference map of the edges to type \c T.
315      /// \sa ReferenceSkeleton
316      /// \warning Making maps that can handle bool type (EdgeMap<bool>)
317      /// needs extra attention!
318      template<class T> class EdgeMap
319        : public ReferenceMap<Edge,T>
320      {
321      public:
322        typedef T ValueType;
323        typedef Edge KeyType;
324
325        EdgeMap(const StaticGraphSkeleton&) { }
326        EdgeMap(const StaticGraphSkeleton&, T) { }
327   
328        ///Copy constructor
329        template<typename TT> EdgeMap(const EdgeMap<TT>&) { }
330        ///Assignment operator
331        template<typename TT> EdgeMap &operator=(const EdgeMap<TT>&)
332        { return *this; }
333      };
334    };
335
336
337 
338    /// An empty graph class.
339
340    /// This class provides everything that \c StaticGraphSkeleton
341    /// with additional functionality which enables to build a
342    /// graph from scratch.
343    class GraphSkeleton : public StaticGraphSkeleton
344    {
345    public:
346      /// Defalult constructor.
347      GraphSkeleton() { }
348      ///Copy consructor.
349
350      ///\todo It is not clear, what we expect from a copy constructor.
351      ///E.g. How to assign the nodes/edges to each other? What about maps?
352      GraphSkeleton(const GraphSkeleton&) { }
353
354      ///Add a new node to the graph.
355
356      /// \return the new node.
357      ///
358      Node addNode() { return INVALID; }
359      ///Add a new edge to the graph.
360
361      ///Add a new edge to the graph with tail node \c tail
362      ///and head node \c head.
363      ///\return the new edge.
364      Edge addEdge(Node, Node) { return INVALID; }
365   
366      /// Resets the graph.
367
368      /// This function deletes all edges and nodes of the graph.
369      /// It also frees the memory allocated to store them.
370      /// \todo It might belong to \c EraseableGraphSkeleton.
371      void clear() { }
372    };
373
374    /// An empty eraseable graph class.
375 
376    /// This class is an extension of \c GraphSkeleton. It also makes it
377    /// possible to erase edges or nodes.
378    class EraseableGraphSkeleton : public GraphSkeleton
379    {
380    public:
381      /// Deletes a node.
382      void erase(Node n) { }
383      /// Deletes an edge.
384      void erase(Edge e) { }
385
386      /// Defalult constructor.
387      EraseableGraphSkeleton() { }
388      ///Copy consructor.
389      EraseableGraphSkeleton(const GraphSkeleton&) { }
390    };
391
392    // @}
393  } //namespace skeleton
394 
395} //namespace hugo
396
397
398
399// class EmptyBipGraph : public Graph Skeleton
400// {
401//   class ANode {};
402//   class BNode {};
403
404//   ANode &next(ANode &) {}
405//   BNode &next(BNode &) {}
406
407//   ANode &getFirst(ANode &) const {}
408//   BNode &getFirst(BNode &) const {}
409
410//   enum NodeClass { A = 0, B = 1 };
411//   NodeClass getClass(Node n) {}
412
413// }
414
415#endif // HUGO_SKELETON_GRAPH_H
Note: See TracBrowser for help on using the repository browser.