src/hugo/skeletons/graph.h
changeset 539 fb261e3a9a0f
parent 515 a7eeb8af6b34
child 542 69bde1d90c04
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/hugo/skeletons/graph.h	Thu May 06 13:21:24 2004 +0000
     1.3 @@ -0,0 +1,399 @@
     1.4 +// -*- c++ -*-
     1.5 +#ifndef HUGO_SKELETON_GRAPH_H
     1.6 +#define HUGO_SKELETON_GRAPH_H
     1.7 +
     1.8 +///\file
     1.9 +///\brief Declaration of GraphSkeleton.
    1.10 +
    1.11 +#include <invalid.h>
    1.12 +
    1.13 +/// The namespace of HugoLib
    1.14 +namespace hugo {
    1.15 +
    1.16 +  // @defgroup empty_graph The GraphSkeleton class
    1.17 +  // @{
    1.18 +
    1.19 +  /// An empty graph class.
    1.20 +  
    1.21 +  /// This class provides all the common features of a graph structure,
    1.22 +  /// however completely without implementations and real data structures
    1.23 +  /// behind the interface.
    1.24 +  /// All graph algorithms should compile with this class, but it will not
    1.25 +  /// run properly, of course.
    1.26 +  ///
    1.27 +  /// It can be used for checking the interface compatibility,
    1.28 +  /// or it can serve as a skeleton of a new graph structure.
    1.29 +  /// 
    1.30 +  /// Also, you will find here the full documentation of a certain graph
    1.31 +  /// feature, the documentation of a real graph imlementation
    1.32 +  /// like @ref ListGraph or
    1.33 +  /// @ref SmartGraph will just refer to this structure.
    1.34 +  class GraphSkeleton
    1.35 +  {
    1.36 +  public:
    1.37 +    /// Defalult constructor.
    1.38 +    GraphSkeleton() {}
    1.39 +    ///Copy consructor.
    1.40 +
    1.41 +    ///\todo It is not clear, what we expect from a copy constructor.
    1.42 +    ///E.g. How to assign the nodes/edges to each other? What about maps?
    1.43 +    GraphSkeleton(const GraphSkeleton &G) {}
    1.44 +
    1.45 +    /// The base type of the node iterators.
    1.46 +
    1.47 +    /// This is the base type of each node iterators,
    1.48 +    /// thus each kind of node iterator will convert to this.
    1.49 +    class Node {
    1.50 +    public:
    1.51 +      /// @warning The default constructor sets the iterator
    1.52 +      /// to an undefined value.
    1.53 +      Node() {}   //FIXME
    1.54 +      /// Invalid constructor \& conversion.
    1.55 +
    1.56 +      /// This constructor initializes the iterator to be invalid.
    1.57 +      /// \sa Invalid for more details.
    1.58 +
    1.59 +      Node(Invalid) {}
    1.60 +      //Node(const Node &) {}
    1.61 +
    1.62 +      /// Two iterators are equal if and only if they point to the
    1.63 +      /// same object or both are invalid.
    1.64 +      bool operator==(Node) const { return true; }
    1.65 +
    1.66 +      /// \sa \ref operator==(Node n)
    1.67 +      ///
    1.68 +      bool operator!=(Node) const { return true; }
    1.69 +
    1.70 +      bool operator<(Node) const { return true; }
    1.71 +    };
    1.72 +    
    1.73 +    /// This iterator goes through each node.
    1.74 +
    1.75 +    /// This iterator goes through each node.
    1.76 +    /// Its usage is quite simple, for example you can count the number
    1.77 +    /// of nodes in graph \c G of type \c Graph like this:
    1.78 +    /// \code
    1.79 +    ///int count=0;
    1.80 +    ///for(Graph::NodeIt n(G);G.valid(n);G.next(n)) count++;
    1.81 +    /// \endcode
    1.82 +    class NodeIt : public Node {
    1.83 +    public:
    1.84 +      /// @warning The default constructor sets the iterator
    1.85 +      /// to an undefined value.
    1.86 +      NodeIt() {} //FIXME
    1.87 +      /// Invalid constructor \& conversion.
    1.88 +
    1.89 +      /// Initialize the iterator to be invalid
    1.90 +      /// \sa Invalid for more details.
    1.91 +      NodeIt(Invalid) {}
    1.92 +      /// Sets the iterator to the first node of \c G.
    1.93 +      NodeIt(const GraphSkeleton &) {}
    1.94 +      /// @warning The default constructor sets the iterator
    1.95 +      /// to an undefined value.
    1.96 +      NodeIt(const NodeIt &n) : Node(n) {}
    1.97 +    };
    1.98 +    
    1.99 +    
   1.100 +    /// The base type of the edge iterators.
   1.101 +    class Edge {
   1.102 +    public:
   1.103 +      /// @warning The default constructor sets the iterator
   1.104 +      /// to an undefined value.
   1.105 +      Edge() {}   //FIXME
   1.106 +      /// Initialize the iterator to be invalid
   1.107 +      Edge(Invalid) {}
   1.108 +      /// Two iterators are equal if and only if they point to the
   1.109 +      /// same object or both are invalid.
   1.110 +      bool operator==(Edge) const { return true; }
   1.111 +      bool operator!=(Edge) const { return true; }
   1.112 +      bool operator<(Edge) const { return true; }
   1.113 +    };
   1.114 +    
   1.115 +    /// This iterator goes trough the outgoing edges of a node.
   1.116 +
   1.117 +    /// This iterator goes trough the \e outgoing edges of a certain node
   1.118 +    /// of a graph.
   1.119 +    /// Its usage is quite simple, for example you can count the number
   1.120 +    /// of outgoing edges of a node \c n
   1.121 +    /// in graph \c G of type \c Graph as follows.
   1.122 +    /// \code
   1.123 +    ///int count=0;
   1.124 +    ///for(Graph::OutEdgeIt e(G,n);G.valid(e);G.next(e)) count++;
   1.125 +    /// \endcode
   1.126 +    
   1.127 +    class OutEdgeIt : public Edge {
   1.128 +    public:
   1.129 +      /// @warning The default constructor sets the iterator
   1.130 +      /// to an undefined value.
   1.131 +      OutEdgeIt() {}
   1.132 +      /// Initialize the iterator to be invalid
   1.133 +      OutEdgeIt(Invalid) {}
   1.134 +      /// This constructor sets the iterator to first outgoing edge.
   1.135 +    
   1.136 +      /// This constructor set the iterator to the first outgoing edge of
   1.137 +      /// node
   1.138 +      ///@param n the node
   1.139 +      ///@param G the graph
   1.140 +      OutEdgeIt(const GraphSkeleton &, Node) {}
   1.141 +    };
   1.142 +
   1.143 +    /// This iterator goes trough the incoming edges of a node.
   1.144 +
   1.145 +    /// This iterator goes trough the \e incoming edges of a certain node
   1.146 +    /// of a graph.
   1.147 +    /// Its usage is quite simple, for example you can count the number
   1.148 +    /// of outgoing edges of a node \c n
   1.149 +    /// in graph \c G of type \c Graph as follows.
   1.150 +    /// \code
   1.151 +    ///int count=0;
   1.152 +    ///for(Graph::InEdgeIt e(G,n);G.valid(e);G.next(e)) count++;
   1.153 +    /// \endcode
   1.154 +
   1.155 +    class InEdgeIt : public Edge {
   1.156 +    public:
   1.157 +      /// @warning The default constructor sets the iterator
   1.158 +      /// to an undefined value.
   1.159 +      InEdgeIt() {}
   1.160 +      /// Initialize the iterator to be invalid
   1.161 +      InEdgeIt(Invalid) {}
   1.162 +      InEdgeIt(const GraphSkeleton &, Node) {}    
   1.163 +    };
   1.164 +    //  class SymEdgeIt : public Edge {};
   1.165 +
   1.166 +    /// This iterator goes through each edge.
   1.167 +
   1.168 +    /// This iterator goes through each edge of a graph.
   1.169 +    /// Its usage is quite simple, for example you can count the number
   1.170 +    /// of edges in a graph \c G of type \c Graph as follows:
   1.171 +    /// \code
   1.172 +    ///int count=0;
   1.173 +    ///for(Graph::EdgeIt e(G);G.valid(e);G.next(e)) count++;
   1.174 +    /// \endcode
   1.175 +    class EdgeIt : public Edge {
   1.176 +    public:
   1.177 +      /// @warning The default constructor sets the iterator
   1.178 +      /// to an undefined value.
   1.179 +      EdgeIt() {}
   1.180 +      /// Initialize the iterator to be invalid
   1.181 +      EdgeIt(Invalid) {}
   1.182 +      EdgeIt(const GraphSkeleton &) {}
   1.183 +    };
   1.184 +
   1.185 +    /// First node of the graph.
   1.186 +
   1.187 +    /// \retval i the first node.
   1.188 +    /// \return the first node.
   1.189 +    ///
   1.190 +    NodeIt &first(NodeIt &i) const { return i;}
   1.191 +
   1.192 +    /// The first incoming edge.
   1.193 +    InEdgeIt &first(InEdgeIt &i, Node) const { return i;}
   1.194 +    /// The first outgoing edge.
   1.195 +    OutEdgeIt &first(OutEdgeIt &i, Node) const { return i;}
   1.196 +    //  SymEdgeIt &first(SymEdgeIt &, Node) const { return i;}
   1.197 +    /// The first edge of the Graph.
   1.198 +    EdgeIt &first(EdgeIt &i) const { return i;}
   1.199 +
   1.200 +//     Node getNext(Node) const {}
   1.201 +//     InEdgeIt getNext(InEdgeIt) const {}
   1.202 +//     OutEdgeIt getNext(OutEdgeIt) const {}
   1.203 +//     //SymEdgeIt getNext(SymEdgeIt) const {}
   1.204 +//     EdgeIt getNext(EdgeIt) const {}
   1.205 +
   1.206 +    /// Go to the next node.
   1.207 +    NodeIt &next(NodeIt &i) const { return i;}
   1.208 +    /// Go to the next incoming edge.
   1.209 +    InEdgeIt &next(InEdgeIt &i) const { return i;}
   1.210 +    /// Go to the next outgoing edge.
   1.211 +    OutEdgeIt &next(OutEdgeIt &i) const { return i;}
   1.212 +    //SymEdgeIt &next(SymEdgeIt &) const {}
   1.213 +    /// Go to the next edge.
   1.214 +    EdgeIt &next(EdgeIt &i) const { return i;}
   1.215 +
   1.216 +    ///Gives back the head node of an edge.
   1.217 +    Node head(Edge) const { return INVALID; }
   1.218 +    ///Gives back the tail node of an edge.
   1.219 +    Node tail(Edge) const { return INVALID; }
   1.220 +  
   1.221 +    //   Node aNode(InEdgeIt) const {}
   1.222 +    //   Node aNode(OutEdgeIt) const {}
   1.223 +    //   Node aNode(SymEdgeIt) const {}
   1.224 +
   1.225 +    //   Node bNode(InEdgeIt) const {}
   1.226 +    //   Node bNode(OutEdgeIt) const {}
   1.227 +    //   Node bNode(SymEdgeIt) const {}
   1.228 +
   1.229 +    /// Checks if a node iterator is valid
   1.230 +
   1.231 +    ///\todo Maybe, it would be better if iterator converted to
   1.232 +    ///bool directly, as Jacint prefers.
   1.233 +    bool valid(const Node&) const { return true;}
   1.234 +    /// Checks if an edge iterator is valid
   1.235 +
   1.236 +    ///\todo Maybe, it would be better if iterator converted to
   1.237 +    ///bool directly, as Jacint prefers.
   1.238 +    bool valid(const Edge&) const { return true;}
   1.239 +
   1.240 +    ///Gives back the \e id of a node.
   1.241 +
   1.242 +    ///\warning Not all graph structures provide this feature.
   1.243 +    ///
   1.244 +    int id(const Node&) const { return 0;}
   1.245 +    ///Gives back the \e id of an edge.
   1.246 +
   1.247 +    ///\warning Not all graph structures provide this feature.
   1.248 +    ///
   1.249 +    int id(const Edge&) const { return 0;}
   1.250 +
   1.251 +    //void setInvalid(Node &) const {};
   1.252 +    //void setInvalid(Edge &) const {};
   1.253 +  
   1.254 +    ///Add a new node to the graph.
   1.255 +
   1.256 +    /// \return the new node.
   1.257 +    ///
   1.258 +    Node addNode() { return INVALID;}
   1.259 +    ///Add a new edge to the graph.
   1.260 +
   1.261 +    ///Add a new edge to the graph with tail node \c tail
   1.262 +    ///and head node \c head.
   1.263 +    ///\return the new edge.
   1.264 +    Edge addEdge(Node, Node) { return INVALID;}
   1.265 +    
   1.266 +    /// Resets the graph.
   1.267 +
   1.268 +    /// This function deletes all edges and nodes of the graph.
   1.269 +    /// It also frees the memory allocated to store them.
   1.270 +    void clear() {}
   1.271 +
   1.272 +    int nodeNum() const { return 0;}
   1.273 +    int edgeNum() const { return 0;}
   1.274 +
   1.275 +    ///Read/write/reference map of the nodes to type \c T.
   1.276 +
   1.277 +    ///Read/write/reference map of the nodes to type \c T.
   1.278 +    /// \sa MemoryMapSkeleton
   1.279 +    /// \todo We may need copy constructor
   1.280 +    /// \todo We may need conversion from other nodetype
   1.281 +    /// \todo We may need operator=
   1.282 +    /// \warning Making maps that can handle bool type (NodeMap<bool>)
   1.283 +    /// needs extra attention!
   1.284 +
   1.285 +    template<class T> class NodeMap
   1.286 +    {
   1.287 +    public:
   1.288 +      typedef T ValueType;
   1.289 +      typedef Node KeyType;
   1.290 +
   1.291 +      NodeMap(const GraphSkeleton &) {}
   1.292 +      NodeMap(const GraphSkeleton &, T) {}
   1.293 +
   1.294 +      template<typename TT> NodeMap(const NodeMap<TT> &) {}
   1.295 +
   1.296 +      /// Sets the value of a node.
   1.297 +
   1.298 +      /// Sets the value associated with node \c i to the value \c t.
   1.299 +      ///
   1.300 +      void set(Node, T) {}
   1.301 +      // Gets the value of a node.
   1.302 +      //T get(Node i) const {return *(T*)0;}  //FIXME: Is it necessary?
   1.303 +      T &operator[](Node) {return *(T*)0;}
   1.304 +      const T &operator[](Node) const {return *(T*)0;}
   1.305 +
   1.306 +      /// Updates the map if the graph has been changed
   1.307 +
   1.308 +      /// \todo Do we need this?
   1.309 +      ///
   1.310 +      void update() {}
   1.311 +      void update(T a) {}   //FIXME: Is it necessary
   1.312 +    };
   1.313 +
   1.314 +    ///Read/write/reference map of the edges to type \c T.
   1.315 +
   1.316 +    ///Read/write/reference map of the edges to type \c T.
   1.317 +    ///It behaves exactly in the same way as \ref NodeMap.
   1.318 +    /// \sa NodeMap
   1.319 +    /// \sa MemoryMapSkeleton
   1.320 +    /// \todo We may need copy constructor
   1.321 +    /// \todo We may need conversion from other edgetype
   1.322 +    /// \todo We may need operator=
   1.323 +    template<class T> class EdgeMap
   1.324 +    {
   1.325 +    public:
   1.326 +      typedef T ValueType;
   1.327 +      typedef Edge KeyType;
   1.328 +
   1.329 +      EdgeMap(const GraphSkeleton &) {}
   1.330 +      EdgeMap(const GraphSkeleton &, T ) {}
   1.331 +    
   1.332 +      ///\todo It can copy between different types.
   1.333 +      ///
   1.334 +      template<typename TT> EdgeMap(const EdgeMap<TT> &) {}
   1.335 +
   1.336 +      void set(Edge, T) {}
   1.337 +      //T get(Edge) const {return *(T*)0;}
   1.338 +      T &operator[](Edge) {return *(T*)0;}
   1.339 +      const T &operator[](Edge) const {return *(T*)0;}
   1.340 +    
   1.341 +      void update() {}
   1.342 +      void update(T a) {}   //FIXME: Is it necessary
   1.343 +    };
   1.344 +  };
   1.345 +
   1.346 +  /// An empty eraseable graph class.
   1.347 +  
   1.348 +  /// This class provides all the common features of an \e eraseable graph
   1.349 +  /// structure,
   1.350 +  /// however completely without implementations and real data structures
   1.351 +  /// behind the interface.
   1.352 +  /// All graph algorithms should compile with this class, but it will not
   1.353 +  /// run properly, of course.
   1.354 +  ///
   1.355 +  /// \todo This blabla could be replaced by a sepatate description about
   1.356 +  /// Skeletons.
   1.357 +  ///
   1.358 +  /// It can be used for checking the interface compatibility,
   1.359 +  /// or it can serve as a skeleton of a new graph structure.
   1.360 +  /// 
   1.361 +  /// Also, you will find here the full documentation of a certain graph
   1.362 +  /// feature, the documentation of a real graph imlementation
   1.363 +  /// like @ref ListGraph or
   1.364 +  /// @ref SmartGraph will just refer to this structure.
   1.365 +  class EraseableGraphSkeleton : public GraphSkeleton
   1.366 +  {
   1.367 +  public:
   1.368 +    /// Deletes a node.
   1.369 +    void erase(Node n) {}
   1.370 +    /// Deletes an edge.
   1.371 +    void erase(Edge e) {}
   1.372 +
   1.373 +    /// Defalult constructor.
   1.374 +    EraseableGraphSkeleton() {}
   1.375 +    ///Copy consructor.
   1.376 +    EraseableGraphSkeleton(const GraphSkeleton &G) {}
   1.377 +  };
   1.378 +
   1.379 +  
   1.380 +  // @}
   1.381 +
   1.382 +} //namespace hugo
   1.383 +
   1.384 +
   1.385 +
   1.386 +// class EmptyBipGraph : public Graph Skeleton
   1.387 +// {
   1.388 +//   class ANode {};
   1.389 +//   class BNode {};
   1.390 +
   1.391 +//   ANode &next(ANode &) {}
   1.392 +//   BNode &next(BNode &) {}
   1.393 +
   1.394 +//   ANode &getFirst(ANode &) const {}
   1.395 +//   BNode &getFirst(BNode &) const {}
   1.396 +
   1.397 +//   enum NodeClass { A = 0, B = 1 };
   1.398 +//   NodeClass getClass(Node n) {}
   1.399 +
   1.400 +// }
   1.401 +
   1.402 +#endif // HUGO_SKELETON_GRAPH_H