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