COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/work/alpar/emptygraph.h @ 186:47cd1716870e

Last change on this file since 186:47cd1716870e was 186:47cd1716870e, checked in by Alpar Juttner, 16 years ago

.

File size: 10.7 KB
Line 
1// -*- c++ -*-
2#ifndef HUGO_EMPTYGRAPH_H
3#define HUGO_EMPTYGRAPH_H
4
5#include <invalid.h>
6
7/// The namespace of HugoLib
8namespace hugo {
9
10  // @defgroup empty_graph The GraphSkeleton class
11  // @{
12
13  /// An empty graph class.
14 
15  /// This class provides all the common features of a graph structure,
16  /// however completely without implementations and real data structures
17  /// behind the interface.
18  /// All graph algorithms should compile with this class, but it will not
19  /// run properly, of course.
20  ///
21  /// It can be used for checking the interface compatibility,
22  /// or it can serve as a skeleton of a new graph structure.
23  ///
24  /// Also, you will find here the full documentation of a certain graph
25  /// feature, the documentation of a real graph imlementation
26  /// like @ref ListGraph or
27  /// @ref SmartGraph will just refer to this structure.
28  class GraphSkeleton
29  {
30  public:
31   
32    /// The base type of the node iterators.
33
34    /// This is the base type of each node iterators,
35    /// thus each kind of node iterator will convert to this.
36    class Node {
37    public:
38      /// @warning The default constructor sets the iterator
39      /// to an undefined value.
40      Node() {}   //FIXME
41      /// Invalid constructor \& conversion.
42
43      /// This constructor initializes the iterator to be invalid.
44      /// \sa Invalid for more details.
45
46      Node(Invalid) {}
47      //Node(const Node &) {}
48
49      /// Two iterators are equal if and only if they point to the
50      /// same object or both are invalid.
51      bool operator==(Node n) const { return true; }
52
53      /// \sa \ref operator==(Node n)
54      ///
55      bool operator!=(Node n) const { return true; }
56
57      bool operator<(Node n) const { return true; }
58    };
59   
60    /// This iterator goes through each node.
61
62    /// This iterator goes through each node.
63    /// Its usage is quite simple, for example you can count the number
64    /// of nodes in graph \c G of type \c Graph like this:
65    /// \code
66    ///int count=0;
67    ///for(Graph::NodeIt n(G);G.valid(n);G.next(n)) count++;
68    /// \endcode
69    class NodeIt : public Node {
70    public:
71      /// @warning The default constructor sets the iterator
72      /// to an undefined value.
73      NodeIt() {} //FIXME
74      /// Invalid constructor \& conversion.
75
76      /// Initialize the iterator to be invalid
77      /// \sa Invalid for more details.
78      NodeIt(Invalid) {}
79      /// Sets the iterator to the first node of \c G.
80      NodeIt(const GraphSkeleton &G) {}
81      /// @warning The default constructor sets the iterator
82      /// to an undefined value.
83      NodeIt(const NodeIt &) {}
84    };
85   
86   
87    /// The base type of the edge iterators.
88    class Edge {
89    public:
90      /// @warning The default constructor sets the iterator
91      /// to an undefined value.
92      Edge() {}   //FIXME
93      /// Initialize the iterator to be invalid
94      Edge(Invalid) {}
95      /// Two iterators are equal if and only if they point to the
96      /// same object or both are invalid.
97      bool operator==(Edge n) const { return true; }
98      bool operator!=(Edge n) const { return true; }
99      bool operator<(Edge n) const { return true; }
100    };
101   
102    /// This iterator goes trought the outgoing edges of a node.
103
104    /// This iterator goes trought the \e outgoing edges of a certain node
105    /// of a graph.
106    /// Its usage is quite simple, for example you can count the number
107    /// of outgoing edges of a node \c n
108    /// in graph \c G of type \c Graph as follows.
109    /// \code
110    ///int count=0;
111    ///for(Graph::OutEdgeIt e(G,n);G.valid(e);G.next(e)) count++;
112    /// \endcode
113   
114    class OutEdgeIt : public Edge {
115    public:
116      /// @warning The default constructor sets the iterator
117      /// to an undefined value.
118      OutEdgeIt() {}
119      /// Initialize the iterator to be invalid
120      OutEdgeIt(Invalid) {}
121      /// This constructor sets the iterator to first outgoing edge.
122   
123      /// This constructor set the iterator to the first outgoing edge of
124      /// node
125      ///@param n the node
126      ///@param G the graph
127      OutEdgeIt(const GraphSkeleton & G, Node n) {}
128    };
129
130    /// This iterator goes trought the incoming edges of a node.
131
132    /// This iterator goes trought the \e incoming edges of a certain node
133    /// of a graph.
134    /// Its usage is quite simple, for example you can count the number
135    /// of outgoing edges of a node \c n
136    /// in graph \c G of type \c Graph as follows.
137    /// \code
138    ///int count=0;
139    ///for(Graph::InEdgeIt e(G,n);G.valid(e);G.next(e)) count++;
140    /// \endcode
141
142    class InEdgeIt : public Edge {
143    public:
144      /// @warning The default constructor sets the iterator
145      /// to an undefined value.
146      InEdgeIt() {}
147      /// Initialize the iterator to be invalid
148      InEdgeIt(Invalid) {}
149      InEdgeIt(const GraphSkeleton &, Node) {}   
150    };
151    //  class SymEdgeIt : public Edge {};
152
153    /// This iterator goes through each edge.
154
155    /// This iterator goes through each edge of a graph.
156    /// Its usage is quite simple, for example you can count the number
157    /// of edges in a graph \c G of type \c Graph as follows:
158    /// \code
159    ///int count=0;
160    ///for(Graph::EdgeIt e(G);G.valid(e);G.next(e)) count++;
161    /// \endcode
162    class EdgeIt : public Edge {
163    public:
164      /// @warning The default constructor sets the iterator
165      /// to an undefined value.
166      EdgeIt() {}
167      /// Initialize the iterator to be invalid
168      EdgeIt(Invalid) {}
169      EdgeIt(const GraphSkeleton &) {}
170    };
171
172    /// First node of the graph.
173
174    /// \post \c i and the return value will be the first node.
175    ///
176    NodeIt &first(NodeIt &i) const { return i;}
177
178    /// The first outgoing edge.
179    InEdgeIt &first(InEdgeIt &i, Node n) const { return i;}
180    /// The first incoming edge.
181    OutEdgeIt &first(OutEdgeIt &i, Node n) const { return i;}
182    //  SymEdgeIt &first(SymEdgeIt &, Node) const { return i;}
183    /// The first edge of the Graph.
184    EdgeIt &first(EdgeIt &i) const { return i;}
185
186//     Node getNext(Node) const {}
187//     InEdgeIt getNext(InEdgeIt) const {}
188//     OutEdgeIt getNext(OutEdgeIt) const {}
189//     //SymEdgeIt getNext(SymEdgeIt) const {}
190//     EdgeIt getNext(EdgeIt) const {}
191
192    /// Go to the next node.
193    NodeIt &next(NodeIt &i) const { return i;}
194    /// Go to the next incoming edge.
195    InEdgeIt &next(InEdgeIt &i) const { return i;}
196    /// Go to the next outgoing edge.
197    OutEdgeIt &next(OutEdgeIt &i) const { return i;}
198    //SymEdgeIt &next(SymEdgeIt &) const {}
199    /// Go to the next edge.
200    EdgeIt &next(EdgeIt &i) const { return i;}
201
202    ///Gives back the head node of an edge.
203    Node head(Edge) const { return INVALID; }
204    ///Gives back the tail node of an edge.
205    Node tail(Edge) const { return INVALID; }
206 
207    //   Node aNode(InEdgeIt) const {}
208    //   Node aNode(OutEdgeIt) const {}
209    //   Node aNode(SymEdgeIt) const {}
210
211    //   Node bNode(InEdgeIt) const {}
212    //   Node bNode(OutEdgeIt) const {}
213    //   Node bNode(SymEdgeIt) const {}
214
215    /// Checks if a node iterator is valid
216
217    ///\todo Maybe, it would be better if iterator converted to
218    ///bool directly, as Jacint prefers.
219    bool valid(const Node) const { return true;}
220    /// Checks if an edge iterator is valid
221
222    ///\todo Maybe, it would be better if iterator converted to
223    ///bool directly, as Jacint prefers.
224    bool valid(const Edge) const { return true;}
225
226    ///Gives back the \e id of a node.
227
228    ///\warning Not all graph structure provide this feature.
229    ///
230    int id(const Node) const { return 0;}
231    ///Gives back the \e id of an edge.
232
233    ///\warning Not all graph structure provide this feature.
234    ///
235    int id(const Edge) const { return 0;}
236
237    //void setInvalid(Node &) const {};
238    //void setInvalid(Edge &) const {};
239 
240    ///Add a new node to the graph.
241
242    /// \return the new node.
243    ///
244    Node addNode() { return INVALID;}
245    ///Add a new edge to the graph.
246
247    ///Add a new edge to the graph with tail node \c tail
248    ///and head node \c head.
249    ///\return the new edge.
250    Edge addEdge(Node tail, Node head) { return INVALID;}
251   
252    /// Deletes a node.
253   
254    ///\warning Not all graph structure provide this feature.
255    ///
256    void erase(Node n) {}
257    /// Deletes an edge.
258
259    ///\warning Not all graph structure provide this feature.
260    ///
261    void erase(Edge e) {}
262
263    /// Reset the graph.
264
265    /// This function deletes all edges and nodes of the graph.
266    /// It also frees the memory allocated to store them.
267    void clear() {}
268
269    int nodeNum() const { return 0;}
270    int edgeNum() const { return 0;}
271
272    GraphSkeleton() {}
273    GraphSkeleton(const GraphSkeleton &G) {}
274 
275 
276
277    ///Read/write/reference map of the nodes to type \c T.
278
279    ///Read/write/reference map of the nodes to type \c T.
280    /// \sa MemoryMapSkeleton
281    /// \todo We may need copy constructor
282    /// \todo We may need conversion from other nodetype
283    /// \todo We may need operator=
284
285    template<class T> class NodeMap
286    {
287    public:
288      typedef T ValueType;
289      typedef Node KeyType;
290
291      NodeMap(const GraphSkeleton &G) {}
292      NodeMap(const GraphSkeleton &G, T t) {}
293
294      template<typename TT> NodeMap(const NodeMap<TT> &m) {}
295
296      /// Sets the value of a node.
297
298      /// Sets the value associated with node \c i to the value \c t.
299      ///
300      void set(Node i, T t) {}
301      /// Gets the value of a node.
302      T get(Node i) const {return *(T*)0;}  //FIXME: Is it necessary
303      T &operator[](Node i) {return *(T*)0;}
304      const T &operator[](Node i) const {return *(T*)0;}
305
306      /// Updates the map if the graph has been changed
307
308      /// \todo Do we need this?
309      ///
310      void update() {}
311      void update(T a) {}   //FIXME: Is it necessary
312    };
313
314    ///Read/write/reference map of the edges to type \c T.
315
316    ///Read/write/reference map of the edges to type \c T.
317    ///It behaves exactly in the same way as \ref NodeMap.
318    /// \sa NodeMap
319    /// \sa MemoryMapSkeleton
320    /// \todo We may need copy constructor
321    /// \todo We may need conversion from other edgetype
322    /// \todo We may need operator=
323    template<class T> class EdgeMap
324    {
325    public:
326      typedef T ValueType;
327      typedef Edge KeyType;
328
329      EdgeMap(const GraphSkeleton &G) {}
330      EdgeMap(const GraphSkeleton &G, T t) {}
331   
332      void set(Edge i, T t) {}
333      T get(Edge i) const {return *(T*)0;}
334      T &operator[](Edge i) {return *(T*)0;}
335   
336      void update() {}
337      void update(T a) {}   //FIXME: Is it necessary
338    };
339  };
340
341  // @}
342
343} //namespace hugo
344
345
346
347// class EmptyBipGraph : public Graph Skeleton
348// {
349//   class ANode {};
350//   class BNode {};
351
352//   ANode &next(ANode &) {}
353//   BNode &next(BNode &) {}
354
355//   ANode &getFirst(ANode &) const {}
356//   BNode &getFirst(BNode &) const {}
357
358//   enum NodeClass { A = 0, B = 1 };
359//   NodeClass getClass(Node n) {}
360
361// }
362
363#endif // HUGO_EMPTYGRAPH_H
Note: See TracBrowser for help on using the repository browser.