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