| [174] | 1 | // -*- c++ -*- | 
|---|
| [183] | 2 | #ifndef HUGO_EMPTYGRAPH_H | 
|---|
 | 3 | #define HUGO_EMPTYGRAPH_H | 
|---|
| [52] | 4 |  | 
|---|
| [163] | 5 | #include <invalid.h> | 
|---|
| [145] | 6 |  | 
|---|
| [163] | 7 | /// The namespace of HugoLib | 
|---|
 | 8 | namespace hugo { | 
|---|
 | 9 |  | 
|---|
| [182] | 10 |   // @defgroup empty_graph The GraphSkeleton class | 
|---|
| [163] | 11 |   // @{ | 
|---|
 | 12 |  | 
|---|
 | 13 |   /// An empty graph class. | 
|---|
 | 14 |    | 
|---|
| [187] | 15 |   /// When you read this for the first time, | 
|---|
 | 16 |   /// please send an e-mail to alpar\@cs.elte.hu. | 
|---|
 | 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: | 
|---|
 | 34 |      | 
|---|
| [163] | 35 |     /// The base type of the node iterators. | 
|---|
| [182] | 36 |  | 
|---|
| [186] | 37 |     /// This is the base type of each node iterators, | 
|---|
| [182] | 38 |     /// thus each kind of node iterator will convert to this. | 
|---|
| [163] | 39 |     class Node { | 
|---|
 | 40 |     public: | 
|---|
 | 41 |       /// @warning The default constructor sets the iterator | 
|---|
 | 42 |       /// to an undefined value. | 
|---|
 | 43 |       Node() {}   //FIXME | 
|---|
| [182] | 44 |       /// Invalid constructor \& conversion. | 
|---|
 | 45 |  | 
|---|
 | 46 |       /// This constructor initializes the iterator to be invalid. | 
|---|
 | 47 |       /// \sa Invalid for more details. | 
|---|
 | 48 |  | 
|---|
| [174] | 49 |       Node(Invalid) {} | 
|---|
| [182] | 50 |       //Node(const Node &) {} | 
|---|
 | 51 |  | 
|---|
 | 52 |       /// Two iterators are equal if and only if they point to the | 
|---|
 | 53 |       /// same object or both are invalid. | 
|---|
 | 54 |       bool operator==(Node n) const { return true; } | 
|---|
 | 55 |  | 
|---|
 | 56 |       /// \sa \ref operator==(Node n) | 
|---|
 | 57 |       /// | 
|---|
 | 58 |       bool operator!=(Node n) const { return true; } | 
|---|
 | 59 |  | 
|---|
 | 60 |       bool operator<(Node n) const { return true; } | 
|---|
| [163] | 61 |     }; | 
|---|
| [147] | 62 |      | 
|---|
| [163] | 63 |     /// This iterator goes through each node. | 
|---|
| [186] | 64 |  | 
|---|
 | 65 |     /// This iterator goes through each node. | 
|---|
 | 66 |     /// Its usage is quite simple, for example you can count the number | 
|---|
 | 67 |     /// of nodes in graph \c G of type \c Graph like this: | 
|---|
 | 68 |     /// \code | 
|---|
 | 69 |     ///int count=0; | 
|---|
 | 70 |     ///for(Graph::NodeIt n(G);G.valid(n);G.next(n)) count++; | 
|---|
 | 71 |     /// \endcode | 
|---|
| [163] | 72 |     class NodeIt : public Node { | 
|---|
 | 73 |     public: | 
|---|
 | 74 |       /// @warning The default constructor sets the iterator | 
|---|
 | 75 |       /// to an undefined value. | 
|---|
 | 76 |       NodeIt() {} //FIXME | 
|---|
| [182] | 77 |       /// Invalid constructor \& conversion. | 
|---|
 | 78 |  | 
|---|
| [163] | 79 |       /// Initialize the iterator to be invalid | 
|---|
| [182] | 80 |       /// \sa Invalid for more details. | 
|---|
| [174] | 81 |       NodeIt(Invalid) {} | 
|---|
| [163] | 82 |       /// Sets the iterator to the first node of \c G. | 
|---|
| [182] | 83 |       NodeIt(const GraphSkeleton &G) {} | 
|---|
 | 84 |       /// @warning The default constructor sets the iterator | 
|---|
 | 85 |       /// to an undefined value. | 
|---|
 | 86 |       NodeIt(const NodeIt &) {} | 
|---|
| [163] | 87 |     }; | 
|---|
 | 88 |      | 
|---|
 | 89 |      | 
|---|
 | 90 |     /// The base type of the edge iterators. | 
|---|
 | 91 |     class Edge { | 
|---|
 | 92 |     public: | 
|---|
 | 93 |       /// @warning The default constructor sets the iterator | 
|---|
 | 94 |       /// to an undefined value. | 
|---|
 | 95 |       Edge() {}   //FIXME | 
|---|
 | 96 |       /// Initialize the iterator to be invalid | 
|---|
| [174] | 97 |       Edge(Invalid) {} | 
|---|
| [182] | 98 |       /// Two iterators are equal if and only if they point to the | 
|---|
 | 99 |       /// same object or both are invalid. | 
|---|
 | 100 |       bool operator==(Edge n) const { return true; } | 
|---|
 | 101 |       bool operator!=(Edge n) const { return true; } | 
|---|
 | 102 |       bool operator<(Edge n) const { return true; } | 
|---|
| [163] | 103 |     }; | 
|---|
 | 104 |      | 
|---|
| [186] | 105 |     /// This iterator goes trought the outgoing edges of a node. | 
|---|
 | 106 |  | 
|---|
 | 107 |     /// This iterator goes trought the \e outgoing edges of a certain node | 
|---|
 | 108 |     /// of a graph. | 
|---|
 | 109 |     /// Its usage is quite simple, for example you can count the number | 
|---|
 | 110 |     /// of outgoing edges of a node \c n | 
|---|
 | 111 |     /// in graph \c G of type \c Graph as follows. | 
|---|
 | 112 |     /// \code | 
|---|
 | 113 |     ///int count=0; | 
|---|
 | 114 |     ///for(Graph::OutEdgeIt e(G,n);G.valid(e);G.next(e)) count++; | 
|---|
 | 115 |     /// \endcode | 
|---|
| [163] | 116 |      | 
|---|
 | 117 |     class OutEdgeIt : public Edge { | 
|---|
 | 118 |     public: | 
|---|
 | 119 |       /// @warning The default constructor sets the iterator | 
|---|
 | 120 |       /// to an undefined value. | 
|---|
 | 121 |       OutEdgeIt() {} | 
|---|
 | 122 |       /// Initialize the iterator to be invalid | 
|---|
| [174] | 123 |       OutEdgeIt(Invalid) {} | 
|---|
| [163] | 124 |       /// This constructor sets the iterator to first outgoing edge. | 
|---|
 | 125 |      | 
|---|
 | 126 |       /// This constructor set the iterator to the first outgoing edge of | 
|---|
 | 127 |       /// node | 
|---|
 | 128 |       ///@param n the node | 
|---|
 | 129 |       ///@param G the graph | 
|---|
| [182] | 130 |       OutEdgeIt(const GraphSkeleton & G, Node n) {} | 
|---|
| [163] | 131 |     }; | 
|---|
 | 132 |  | 
|---|
| [186] | 133 |     /// This iterator goes trought the incoming edges of a node. | 
|---|
 | 134 |  | 
|---|
 | 135 |     /// This iterator goes trought the \e incoming edges of a certain node | 
|---|
 | 136 |     /// of a graph. | 
|---|
 | 137 |     /// Its usage is quite simple, for example you can count the number | 
|---|
 | 138 |     /// of outgoing edges of a node \c n | 
|---|
 | 139 |     /// in graph \c G of type \c Graph as follows. | 
|---|
 | 140 |     /// \code | 
|---|
 | 141 |     ///int count=0; | 
|---|
 | 142 |     ///for(Graph::InEdgeIt e(G,n);G.valid(e);G.next(e)) count++; | 
|---|
 | 143 |     /// \endcode | 
|---|
 | 144 |  | 
|---|
| [163] | 145 |     class InEdgeIt : public Edge { | 
|---|
 | 146 |     public: | 
|---|
 | 147 |       /// @warning The default constructor sets the iterator | 
|---|
 | 148 |       /// to an undefined value. | 
|---|
 | 149 |       InEdgeIt() {} | 
|---|
 | 150 |       /// Initialize the iterator to be invalid | 
|---|
| [174] | 151 |       InEdgeIt(Invalid) {} | 
|---|
| [182] | 152 |       InEdgeIt(const GraphSkeleton &, Node) {}     | 
|---|
| [163] | 153 |     }; | 
|---|
 | 154 |     //  class SymEdgeIt : public Edge {}; | 
|---|
| [186] | 155 |  | 
|---|
 | 156 |     /// This iterator goes through each edge. | 
|---|
 | 157 |  | 
|---|
 | 158 |     /// This iterator goes through each edge of a graph. | 
|---|
 | 159 |     /// Its usage is quite simple, for example you can count the number | 
|---|
 | 160 |     /// of edges in a graph \c G of type \c Graph as follows: | 
|---|
 | 161 |     /// \code | 
|---|
 | 162 |     ///int count=0; | 
|---|
 | 163 |     ///for(Graph::EdgeIt e(G);G.valid(e);G.next(e)) count++; | 
|---|
 | 164 |     /// \endcode | 
|---|
| [163] | 165 |     class EdgeIt : public Edge { | 
|---|
 | 166 |     public: | 
|---|
 | 167 |       /// @warning The default constructor sets the iterator | 
|---|
 | 168 |       /// to an undefined value. | 
|---|
 | 169 |       EdgeIt() {} | 
|---|
 | 170 |       /// Initialize the iterator to be invalid | 
|---|
| [174] | 171 |       EdgeIt(Invalid) {} | 
|---|
| [182] | 172 |       EdgeIt(const GraphSkeleton &) {} | 
|---|
| [163] | 173 |     }; | 
|---|
 | 174 |  | 
|---|
 | 175 |     /// First node of the graph. | 
|---|
 | 176 |  | 
|---|
 | 177 |     /// \post \c i and the return value will be the first node. | 
|---|
 | 178 |     /// | 
|---|
 | 179 |     NodeIt &first(NodeIt &i) const { return i;} | 
|---|
 | 180 |  | 
|---|
 | 181 |     /// The first outgoing edge. | 
|---|
 | 182 |     InEdgeIt &first(InEdgeIt &i, Node n) const { return i;} | 
|---|
 | 183 |     /// The first incoming edge. | 
|---|
 | 184 |     OutEdgeIt &first(OutEdgeIt &i, Node n) const { return i;} | 
|---|
 | 185 |     //  SymEdgeIt &first(SymEdgeIt &, Node) const { return i;} | 
|---|
 | 186 |     /// The first edge of the Graph. | 
|---|
 | 187 |     EdgeIt &first(EdgeIt &i) const { return i;} | 
|---|
 | 188 |  | 
|---|
 | 189 | //     Node getNext(Node) const {} | 
|---|
 | 190 | //     InEdgeIt getNext(InEdgeIt) const {} | 
|---|
 | 191 | //     OutEdgeIt getNext(OutEdgeIt) const {} | 
|---|
 | 192 | //     //SymEdgeIt getNext(SymEdgeIt) const {} | 
|---|
 | 193 | //     EdgeIt getNext(EdgeIt) const {} | 
|---|
 | 194 |  | 
|---|
 | 195 |     /// Go to the next node. | 
|---|
| [178] | 196 |     NodeIt &next(NodeIt &i) const { return i;} | 
|---|
| [163] | 197 |     /// Go to the next incoming edge. | 
|---|
 | 198 |     InEdgeIt &next(InEdgeIt &i) const { return i;} | 
|---|
 | 199 |     /// Go to the next outgoing edge. | 
|---|
 | 200 |     OutEdgeIt &next(OutEdgeIt &i) const { return i;} | 
|---|
 | 201 |     //SymEdgeIt &next(SymEdgeIt &) const {} | 
|---|
 | 202 |     /// Go to the next edge. | 
|---|
 | 203 |     EdgeIt &next(EdgeIt &i) const { return i;} | 
|---|
 | 204 |  | 
|---|
 | 205 |     ///Gives back the head node of an edge. | 
|---|
 | 206 |     Node head(Edge) const { return INVALID; } | 
|---|
 | 207 |     ///Gives back the tail node of an edge. | 
|---|
 | 208 |     Node tail(Edge) const { return INVALID; } | 
|---|
| [52] | 209 |    | 
|---|
| [163] | 210 |     //   Node aNode(InEdgeIt) const {} | 
|---|
 | 211 |     //   Node aNode(OutEdgeIt) const {} | 
|---|
 | 212 |     //   Node aNode(SymEdgeIt) const {} | 
|---|
 | 213 |  | 
|---|
 | 214 |     //   Node bNode(InEdgeIt) const {} | 
|---|
 | 215 |     //   Node bNode(OutEdgeIt) const {} | 
|---|
 | 216 |     //   Node bNode(SymEdgeIt) const {} | 
|---|
 | 217 |  | 
|---|
 | 218 |     /// Checks if a node iterator is valid | 
|---|
| [186] | 219 |  | 
|---|
 | 220 |     ///\todo Maybe, it would be better if iterator converted to | 
|---|
 | 221 |     ///bool directly, as Jacint prefers. | 
|---|
| [174] | 222 |     bool valid(const Node) const { return true;} | 
|---|
| [163] | 223 |     /// Checks if an edge iterator is valid | 
|---|
| [186] | 224 |  | 
|---|
 | 225 |     ///\todo Maybe, it would be better if iterator converted to | 
|---|
 | 226 |     ///bool directly, as Jacint prefers. | 
|---|
| [174] | 227 |     bool valid(const Edge) const { return true;} | 
|---|
| [163] | 228 |  | 
|---|
 | 229 |     ///Gives back the \e id of a node. | 
|---|
| [182] | 230 |  | 
|---|
 | 231 |     ///\warning Not all graph structure provide this feature. | 
|---|
 | 232 |     /// | 
|---|
| [174] | 233 |     int id(const Node) const { return 0;} | 
|---|
| [163] | 234 |     ///Gives back the \e id of an edge. | 
|---|
| [182] | 235 |  | 
|---|
 | 236 |     ///\warning Not all graph structure provide this feature. | 
|---|
 | 237 |     /// | 
|---|
| [174] | 238 |     int id(const Edge) const { return 0;} | 
|---|
| [163] | 239 |  | 
|---|
 | 240 |     //void setInvalid(Node &) const {}; | 
|---|
 | 241 |     //void setInvalid(Edge &) const {}; | 
|---|
 | 242 |    | 
|---|
| [182] | 243 |     ///Add a new node to the graph. | 
|---|
 | 244 |  | 
|---|
 | 245 |     /// \return the new node. | 
|---|
| [186] | 246 |     /// | 
|---|
| [163] | 247 |     Node addNode() { return INVALID;} | 
|---|
| [182] | 248 |     ///Add a new edge to the graph. | 
|---|
 | 249 |  | 
|---|
 | 250 |     ///Add a new edge to the graph with tail node \c tail | 
|---|
 | 251 |     ///and head node \c head. | 
|---|
 | 252 |     ///\return the new edge. | 
|---|
| [163] | 253 |     Edge addEdge(Node tail, Node head) { return INVALID;} | 
|---|
 | 254 |      | 
|---|
| [182] | 255 |     /// Deletes a node. | 
|---|
 | 256 |      | 
|---|
 | 257 |     ///\warning Not all graph structure provide this feature. | 
|---|
 | 258 |     /// | 
|---|
| [163] | 259 |     void erase(Node n) {} | 
|---|
| [182] | 260 |     /// Deletes an edge. | 
|---|
 | 261 |  | 
|---|
 | 262 |     ///\warning Not all graph structure provide this feature. | 
|---|
 | 263 |     /// | 
|---|
| [163] | 264 |     void erase(Edge e) {} | 
|---|
 | 265 |  | 
|---|
| [182] | 266 |     /// Reset the graph. | 
|---|
 | 267 |  | 
|---|
 | 268 |     /// This function deletes all edges and nodes of the graph. | 
|---|
 | 269 |     /// It also frees the memory allocated to store them. | 
|---|
| [163] | 270 |     void clear() {} | 
|---|
 | 271 |  | 
|---|
| [179] | 272 |     int nodeNum() const { return 0;} | 
|---|
 | 273 |     int edgeNum() const { return 0;} | 
|---|
| [163] | 274 |  | 
|---|
| [182] | 275 |     GraphSkeleton() {} | 
|---|
 | 276 |     GraphSkeleton(const GraphSkeleton &G) {} | 
|---|
| [163] | 277 |    | 
|---|
 | 278 |    | 
|---|
 | 279 |  | 
|---|
| [186] | 280 |     ///Read/write/reference map of the nodes to type \c T. | 
|---|
| [182] | 281 |  | 
|---|
| [186] | 282 |     ///Read/write/reference map of the nodes to type \c T. | 
|---|
 | 283 |     /// \sa MemoryMapSkeleton | 
|---|
| [182] | 284 |     /// \todo We may need copy constructor | 
|---|
 | 285 |     /// \todo We may need conversion from other nodetype | 
|---|
 | 286 |     /// \todo We may need operator= | 
|---|
 | 287 |  | 
|---|
| [163] | 288 |     template<class T> class NodeMap | 
|---|
 | 289 |     { | 
|---|
 | 290 |     public: | 
|---|
 | 291 |       typedef T ValueType; | 
|---|
 | 292 |       typedef Node KeyType; | 
|---|
 | 293 |  | 
|---|
| [182] | 294 |       NodeMap(const GraphSkeleton &G) {} | 
|---|
 | 295 |       NodeMap(const GraphSkeleton &G, T t) {} | 
|---|
| [163] | 296 |  | 
|---|
| [182] | 297 |       template<typename TT> NodeMap(const NodeMap<TT> &m) {} | 
|---|
 | 298 |  | 
|---|
 | 299 |       /// Sets the value of a node. | 
|---|
 | 300 |  | 
|---|
 | 301 |       /// Sets the value associated with node \c i to the value \c t. | 
|---|
 | 302 |       /// | 
|---|
| [163] | 303 |       void set(Node i, T t) {} | 
|---|
| [182] | 304 |       /// Gets the value of a node. | 
|---|
 | 305 |       T get(Node i) const {return *(T*)0;}  //FIXME: Is it necessary | 
|---|
 | 306 |       T &operator[](Node i) {return *(T*)0;} | 
|---|
 | 307 |       const T &operator[](Node i) const {return *(T*)0;} | 
|---|
| [163] | 308 |  | 
|---|
| [182] | 309 |       /// Updates the map if the graph has been changed | 
|---|
 | 310 |  | 
|---|
 | 311 |       /// \todo Do we need this? | 
|---|
 | 312 |       /// | 
|---|
| [163] | 313 |       void update() {} | 
|---|
 | 314 |       void update(T a) {}   //FIXME: Is it necessary | 
|---|
 | 315 |     }; | 
|---|
 | 316 |  | 
|---|
| [186] | 317 |     ///Read/write/reference map of the edges to type \c T. | 
|---|
| [182] | 318 |  | 
|---|
| [186] | 319 |     ///Read/write/reference map of the edges to type \c T. | 
|---|
 | 320 |     ///It behaves exactly in the same way as \ref NodeMap. | 
|---|
 | 321 |     /// \sa NodeMap | 
|---|
 | 322 |     /// \sa MemoryMapSkeleton | 
|---|
 | 323 |     /// \todo We may need copy constructor | 
|---|
 | 324 |     /// \todo We may need conversion from other edgetype | 
|---|
 | 325 |     /// \todo We may need operator= | 
|---|
| [163] | 326 |     template<class T> class EdgeMap | 
|---|
 | 327 |     { | 
|---|
 | 328 |     public: | 
|---|
 | 329 |       typedef T ValueType; | 
|---|
 | 330 |       typedef Edge KeyType; | 
|---|
 | 331 |  | 
|---|
| [182] | 332 |       EdgeMap(const GraphSkeleton &G) {} | 
|---|
 | 333 |       EdgeMap(const GraphSkeleton &G, T t) {} | 
|---|
| [163] | 334 |      | 
|---|
 | 335 |       void set(Edge i, T t) {} | 
|---|
| [182] | 336 |       T get(Edge i) const {return *(T*)0;} | 
|---|
 | 337 |       T &operator[](Edge i) {return *(T*)0;} | 
|---|
| [163] | 338 |      | 
|---|
 | 339 |       void update() {} | 
|---|
 | 340 |       void update(T a) {}   //FIXME: Is it necessary | 
|---|
 | 341 |     }; | 
|---|
| [147] | 342 |   }; | 
|---|
| [52] | 343 |  | 
|---|
| [163] | 344 |   // @} | 
|---|
| [147] | 345 |  | 
|---|
| [174] | 346 | } //namespace hugo | 
|---|
| [52] | 347 |  | 
|---|
| [145] | 348 |  | 
|---|
 | 349 |  | 
|---|
| [182] | 350 | // class EmptyBipGraph : public Graph Skeleton | 
|---|
| [147] | 351 | // { | 
|---|
| [163] | 352 | //   class ANode {}; | 
|---|
 | 353 | //   class BNode {}; | 
|---|
| [145] | 354 |  | 
|---|
| [163] | 355 | //   ANode &next(ANode &) {} | 
|---|
 | 356 | //   BNode &next(BNode &) {} | 
|---|
| [145] | 357 |  | 
|---|
| [163] | 358 | //   ANode &getFirst(ANode &) const {} | 
|---|
 | 359 | //   BNode &getFirst(BNode &) const {} | 
|---|
| [145] | 360 |  | 
|---|
| [147] | 361 | //   enum NodeClass { A = 0, B = 1 }; | 
|---|
| [163] | 362 | //   NodeClass getClass(Node n) {} | 
|---|
| [147] | 363 |  | 
|---|
 | 364 | // } | 
|---|
| [174] | 365 |  | 
|---|
| [183] | 366 | #endif // HUGO_EMPTYGRAPH_H | 
|---|