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