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