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