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