COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/include/skeletons/graph.h @ 320:190ecba15b33

Last change on this file since 320:190ecba15b33 was 320:190ecba15b33, checked in by marci, 20 years ago

constructor az elejere

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