1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/work/marci/graph_concept.h Wed Apr 14 20:57:58 2004 +0000
1.3 @@ -0,0 +1,422 @@
1.4 +// -*- c++ -*-
1.5 +#ifndef HUGO_GRAPH_H
1.6 +#define HUGO_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 n) const { return true; }
1.65 +
1.66 + /// \sa \ref operator==(Node n)
1.67 + ///
1.68 + bool operator!=(Node n) const { return true; }
1.69 +
1.70 + bool operator<(Node n) 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 &G) {}
1.94 + /// @warning The default constructor sets the iterator
1.95 + /// to an undefined value.
1.96 + NodeIt(const NodeIt &) {}
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 n) const { return true; }
1.111 + bool operator!=(Edge n) const { return true; }
1.112 + bool operator<(Edge n) 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 & G, Node n) {}
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 + /// \post \c i and the return value will be the first node.
1.188 + ///
1.189 + NodeIt &first(NodeIt &i) const { return i;}
1.190 +
1.191 + /// The first incoming edge.
1.192 + InEdgeIt &first(InEdgeIt &i, Node n) const { return i;}
1.193 + /// The first outgoing edge.
1.194 + OutEdgeIt &first(OutEdgeIt &i, Node n) const { return i;}
1.195 + // SymEdgeIt &first(SymEdgeIt &, Node) const { return i;}
1.196 + /// The first edge of the Graph.
1.197 + EdgeIt &first(EdgeIt &i) const { return i;}
1.198 +
1.199 +// Node getNext(Node) const {}
1.200 +// InEdgeIt getNext(InEdgeIt) const {}
1.201 +// OutEdgeIt getNext(OutEdgeIt) const {}
1.202 +// //SymEdgeIt getNext(SymEdgeIt) const {}
1.203 +// EdgeIt getNext(EdgeIt) const {}
1.204 +
1.205 + /// Go to the next node.
1.206 + NodeIt &next(NodeIt &i) const { return i;}
1.207 + /// Go to the next incoming edge.
1.208 + InEdgeIt &next(InEdgeIt &i) const { return i;}
1.209 + /// Go to the next outgoing edge.
1.210 + OutEdgeIt &next(OutEdgeIt &i) const { return i;}
1.211 + //SymEdgeIt &next(SymEdgeIt &) const {}
1.212 + /// Go to the next edge.
1.213 + EdgeIt &next(EdgeIt &i) const { return i;}
1.214 +
1.215 + ///Gives back the head node of an edge.
1.216 + Node head(Edge) const { return INVALID; }
1.217 + ///Gives back the tail node of an edge.
1.218 + Node tail(Edge) const { return INVALID; }
1.219 +
1.220 + // Node aNode(InEdgeIt) const {}
1.221 + // Node aNode(OutEdgeIt) const {}
1.222 + // Node aNode(SymEdgeIt) const {}
1.223 +
1.224 + // Node bNode(InEdgeIt) const {}
1.225 + // Node bNode(OutEdgeIt) const {}
1.226 + // Node bNode(SymEdgeIt) const {}
1.227 +
1.228 + /// Checks if a node iterator is valid
1.229 +
1.230 + ///\todo Maybe, it would be better if iterator converted to
1.231 + ///bool directly, as Jacint prefers.
1.232 + bool valid(const Node&) const { return true;}
1.233 + /// Checks if an edge iterator is valid
1.234 +
1.235 + ///\todo Maybe, it would be better if iterator converted to
1.236 + ///bool directly, as Jacint prefers.
1.237 + bool valid(const Edge&) const { return true;}
1.238 +
1.239 + ///Gives back the \e id of a node.
1.240 +
1.241 + ///\warning Not all graph structures provide this feature.
1.242 + ///
1.243 + int id(const Node&) const { return 0;}
1.244 + ///Gives back the \e id of an edge.
1.245 +
1.246 + ///\warning Not all graph structures provide this feature.
1.247 + ///
1.248 + int id(const Edge&) const { return 0;}
1.249 +
1.250 + //void setInvalid(Node &) const {};
1.251 + //void setInvalid(Edge &) const {};
1.252 +
1.253 + ///Add a new node to the graph.
1.254 +
1.255 + /// \return the new node.
1.256 + ///
1.257 + Node addNode() { return INVALID;}
1.258 + ///Add a new edge to the graph.
1.259 +
1.260 + ///Add a new edge to the graph with tail node \c tail
1.261 + ///and head node \c head.
1.262 + ///\return the new edge.
1.263 + Edge addEdge(Node tail, Node head) { return INVALID;}
1.264 +
1.265 + /// Resets the graph.
1.266 +
1.267 + /// This function deletes all edges and nodes of the graph.
1.268 + /// It also frees the memory allocated to store them.
1.269 + void clear() {}
1.270 +
1.271 + ///Read/write/reference map of the nodes to type \c T.
1.272 +
1.273 + ///Read/write/reference map of the nodes to type \c T.
1.274 + /// \sa MemoryMapSkeleton
1.275 + /// \todo We may need copy constructor
1.276 + /// \todo We may need conversion from other nodetype
1.277 + /// \todo We may need operator=
1.278 + /// \warning Making maps that can handle bool type (NodeMap<bool>)
1.279 + /// needs extra attention!
1.280 +
1.281 + template<class T> class NodeMap
1.282 + {
1.283 + public:
1.284 + typedef T ValueType;
1.285 + typedef Node KeyType;
1.286 +
1.287 + NodeMap(const GraphSkeleton &G) {}
1.288 + NodeMap(const GraphSkeleton &G, T t) {}
1.289 +
1.290 + template<typename TT> NodeMap(const NodeMap<TT> &m) {}
1.291 +
1.292 + /// Sets the value of a node.
1.293 +
1.294 + /// Sets the value associated with node \c i to the value \c t.
1.295 + ///
1.296 + void set(Node i, T t) {}
1.297 + /// Gets the value of a node.
1.298 + T get(Node i) const {return *(T*)0;} //FIXME: Is it necessary
1.299 + T &operator[](Node i) {return *(T*)0;}
1.300 + const T &operator[](Node i) const {return *(T*)0;}
1.301 +
1.302 + /// Updates the map if the graph has been changed
1.303 +
1.304 + /// \todo Do we need this?
1.305 + ///
1.306 + void update() {}
1.307 + void update(T a) {} //FIXME: Is it necessary
1.308 + };
1.309 +
1.310 + ///Read/write/reference map of the edges to type \c T.
1.311 +
1.312 + ///Read/write/reference map of the edges to type \c T.
1.313 + ///It behaves exactly in the same way as \ref NodeMap.
1.314 + /// \sa NodeMap
1.315 + /// \sa MemoryMapSkeleton
1.316 + /// \todo We may need copy constructor
1.317 + /// \todo We may need conversion from other edgetype
1.318 + /// \todo We may need operator=
1.319 + template<class T> class EdgeMap
1.320 + {
1.321 + public:
1.322 + typedef T ValueType;
1.323 + typedef Edge KeyType;
1.324 +
1.325 + EdgeMap(const GraphSkeleton &G) {}
1.326 + EdgeMap(const GraphSkeleton &G, T t) {}
1.327 +
1.328 + void set(Edge i, T t) {}
1.329 + T get(Edge i) const {return *(T*)0;}
1.330 + T &operator[](Edge i) {return *(T*)0;}
1.331 +
1.332 + void update() {}
1.333 + void update(T a) {} //FIXME: Is it necessary
1.334 + };
1.335 + };
1.336 +
1.337 + /// An empty eraseable graph class.
1.338 +
1.339 + /// This class provides all the common features of an \e eraseable graph
1.340 + /// structure,
1.341 + /// however completely without implementations and real data structures
1.342 + /// behind the interface.
1.343 + /// All graph algorithms should compile with this class, but it will not
1.344 + /// run properly, of course.
1.345 + ///
1.346 + /// \todo This blabla could be replaced by a sepatate description about
1.347 + /// Skeletons.
1.348 + ///
1.349 + /// It can be used for checking the interface compatibility,
1.350 + /// or it can serve as a skeleton of a new graph structure.
1.351 + ///
1.352 + /// Also, you will find here the full documentation of a certain graph
1.353 + /// feature, the documentation of a real graph imlementation
1.354 + /// like @ref ListGraph or
1.355 + /// @ref SmartGraph will just refer to this structure.
1.356 + class EraseableGraphSkeleton : public GraphSkeleton
1.357 + {
1.358 + public:
1.359 + /// Deletes a node.
1.360 + void erase(Node n) {}
1.361 + /// Deletes an edge.
1.362 + void erase(Edge e) {}
1.363 +
1.364 + /// Defalult constructor.
1.365 + GraphSkeleton() {}
1.366 + ///Copy consructor.
1.367 + GraphSkeleton(const GraphSkeleton &G) {}
1.368 + };
1.369 +
1.370 +
1.371 + // @}
1.372 +
1.373 +
1.374 + /// An empty graph class which provides a function to get the number
1.375 + /// of its nodes.
1.376 +
1.377 + /// This graph class provides a function for getting the number of its
1.378 + /// nodes.
1.379 + /// Clearly, for physical graph structures it can be expected to have such a
1.380 + /// function. For wrappers or graphs which are given in an implicit way,
1.381 + /// the implementation can be circumstantial, that is why this composes a
1.382 + /// separate concept.
1.383 + class NodeCountingGraphSkeleton
1.384 + {
1.385 + public:
1.386 + /// Returns the number of nodes.
1.387 + int nodeNum() const { return 0;}
1.388 + };
1.389 +
1.390 + /// An empty graph class which provides a function to get the number of its
1.391 + /// edges.
1.392 +
1.393 + /// This graph class provides a function for getting the number of its
1.394 + /// edges.
1.395 + /// Clearly, for physical graph structures it can be expected to have such a
1.396 + /// function. For wrappers or graphs which are given in an implicit way,
1.397 + /// the implementation can be circumstantial, that is why this composes a
1.398 + /// separate concept.
1.399 + class EdgeCountingGraphSkeleton
1.400 + {
1.401 + public:
1.402 + /// Returns the number of edges.
1.403 + int edgeNum() const { return 0;}
1.404 + };
1.405 +
1.406 +} //namespace hugo
1.407 +
1.408 +
1.409 +// class EmptyBipGraph : public Graph Skeleton
1.410 +// {
1.411 +// class ANode {};
1.412 +// class BNode {};
1.413 +
1.414 +// ANode &next(ANode &) {}
1.415 +// BNode &next(BNode &) {}
1.416 +
1.417 +// ANode &getFirst(ANode &) const {}
1.418 +// BNode &getFirst(BNode &) const {}
1.419 +
1.420 +// enum NodeClass { A = 0, B = 1 };
1.421 +// NodeClass getClass(Node n) {}
1.422 +
1.423 +// }
1.424 +
1.425 +#endif // HUGO_GRAPH_H