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