| 1 | /* -*- C++ -*- | 
|---|
| 2 | * | 
|---|
| 3 | * This file is a part of LEMON, a generic C++ optimization library | 
|---|
| 4 | * | 
|---|
| 5 | * Copyright (C) 2003-2006 | 
|---|
| 6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport | 
|---|
| 7 | * (Egervary Research Group on Combinatorial Optimization, EGRES). | 
|---|
| 8 | * | 
|---|
| 9 | * Permission to use, modify and distribute this software is granted | 
|---|
| 10 | * provided that this copyright notice appears in all copies. For | 
|---|
| 11 | * precise terms see the accompanying LICENSE file. | 
|---|
| 12 | * | 
|---|
| 13 | * This software is provided "AS IS" with no warranty of any kind, | 
|---|
| 14 | * express or implied, and with no claim as to its suitability for any | 
|---|
| 15 | * purpose. | 
|---|
| 16 | * | 
|---|
| 17 | */ | 
|---|
| 18 |  | 
|---|
| 19 | ///\ingroup graph_concepts | 
|---|
| 20 | ///\file | 
|---|
| 21 | ///\brief The concept of the undirected graphs. | 
|---|
| 22 |  | 
|---|
| 23 |  | 
|---|
| 24 | #ifndef LEMON_CONCEPT_UGRAPH_H | 
|---|
| 25 | #define LEMON_CONCEPT_UGRAPH_H | 
|---|
| 26 |  | 
|---|
| 27 | #include <lemon/concepts/graph_components.h> | 
|---|
| 28 | #include <lemon/concepts/graph.h> | 
|---|
| 29 | #include <lemon/bits/utility.h> | 
|---|
| 30 |  | 
|---|
| 31 | namespace lemon { | 
|---|
| 32 | namespace concepts { | 
|---|
| 33 |  | 
|---|
| 34 | /// \addtogroup graph_concepts | 
|---|
| 35 | /// @{ | 
|---|
| 36 |  | 
|---|
| 37 |  | 
|---|
| 38 | /// \brief Class describing the concept of Undirected Graphs. | 
|---|
| 39 | /// | 
|---|
| 40 | /// This class describes the common interface of all Undirected | 
|---|
| 41 | /// Graphs. | 
|---|
| 42 | /// | 
|---|
| 43 | /// As all concept describing classes it provides only interface | 
|---|
| 44 | /// without any sensible implementation. So any algorithm for | 
|---|
| 45 | /// undirected graph should compile with this class, but it will not | 
|---|
| 46 | /// run properly, of course. | 
|---|
| 47 | /// | 
|---|
| 48 | /// The LEMON undirected graphs also fulfill the concept of | 
|---|
| 49 | /// directed graphs (\ref lemon::concepts::Graph "Graph | 
|---|
| 50 | /// Concept"). Each undirected edges can be seen as two opposite | 
|---|
| 51 | /// directed edge and consequently the undirected graph can be | 
|---|
| 52 | /// seen as the direceted graph of these directed edges. The | 
|---|
| 53 | /// UGraph has the UEdge inner class for the undirected edges and | 
|---|
| 54 | /// the Edge type for the directed edges. The Edge type is | 
|---|
| 55 | /// convertible to UEdge or inherited from it so from a directed | 
|---|
| 56 | /// edge we can get the represented undirected edge. | 
|---|
| 57 | /// | 
|---|
| 58 | /// In the sense of the LEMON each undirected edge has a default | 
|---|
| 59 | /// direction (it should be in every computer implementation, | 
|---|
| 60 | /// because the order of undirected edge's nodes defines an | 
|---|
| 61 | /// orientation). With the default orientation we can define that | 
|---|
| 62 | /// the directed edge is forward or backward directed. With the \c | 
|---|
| 63 | /// direction() and \c direct() function we can get the direction | 
|---|
| 64 | /// of the directed edge and we can direct an undirected edge. | 
|---|
| 65 | /// | 
|---|
| 66 | /// The UEdgeIt is an iterator for the undirected edges. We can use | 
|---|
| 67 | /// the UEdgeMap to map values for the undirected edges. The InEdgeIt and | 
|---|
| 68 | /// OutEdgeIt iterates on the same undirected edges but with opposite | 
|---|
| 69 | /// direction. The IncEdgeIt iterates also on the same undirected edges | 
|---|
| 70 | /// as the OutEdgeIt and InEdgeIt but it is not convertible to Edge just | 
|---|
| 71 | /// to UEdge. | 
|---|
| 72 | class UGraph { | 
|---|
| 73 | public: | 
|---|
| 74 | /// \brief The undirected graph should be tagged by the | 
|---|
| 75 | /// UndirectedTag. | 
|---|
| 76 | /// | 
|---|
| 77 | /// The undirected graph should be tagged by the UndirectedTag. This | 
|---|
| 78 | /// tag helps the enable_if technics to make compile time | 
|---|
| 79 | /// specializations for undirected graphs. | 
|---|
| 80 | typedef True UndirectedTag; | 
|---|
| 81 |  | 
|---|
| 82 | /// \brief The base type of node iterators, | 
|---|
| 83 | /// or in other words, the trivial node iterator. | 
|---|
| 84 | /// | 
|---|
| 85 | /// This is the base type of each node iterator, | 
|---|
| 86 | /// thus each kind of node iterator converts to this. | 
|---|
| 87 | /// More precisely each kind of node iterator should be inherited | 
|---|
| 88 | /// from the trivial node iterator. | 
|---|
| 89 | class Node { | 
|---|
| 90 | public: | 
|---|
| 91 | /// Default constructor | 
|---|
| 92 |  | 
|---|
| 93 | /// @warning The default constructor sets the iterator | 
|---|
| 94 | /// to an undefined value. | 
|---|
| 95 | Node() { } | 
|---|
| 96 | /// Copy constructor. | 
|---|
| 97 |  | 
|---|
| 98 | /// Copy constructor. | 
|---|
| 99 | /// | 
|---|
| 100 | Node(const Node&) { } | 
|---|
| 101 |  | 
|---|
| 102 | /// Invalid constructor \& conversion. | 
|---|
| 103 |  | 
|---|
| 104 | /// This constructor initializes the iterator to be invalid. | 
|---|
| 105 | /// \sa Invalid for more details. | 
|---|
| 106 | Node(Invalid) { } | 
|---|
| 107 | /// Equality operator | 
|---|
| 108 |  | 
|---|
| 109 | /// Two iterators are equal if and only if they point to the | 
|---|
| 110 | /// same object or both are invalid. | 
|---|
| 111 | bool operator==(Node) const { return true; } | 
|---|
| 112 |  | 
|---|
| 113 | /// Inequality operator | 
|---|
| 114 |  | 
|---|
| 115 | /// \sa operator==(Node n) | 
|---|
| 116 | /// | 
|---|
| 117 | bool operator!=(Node) const { return true; } | 
|---|
| 118 |  | 
|---|
| 119 | /// Artificial ordering operator. | 
|---|
| 120 |  | 
|---|
| 121 | /// To allow the use of graph descriptors as key type in std::map or | 
|---|
| 122 | /// similar associative container we require this. | 
|---|
| 123 | /// | 
|---|
| 124 | /// \note This operator only have to define some strict ordering of | 
|---|
| 125 | /// the items; this order has nothing to do with the iteration | 
|---|
| 126 | /// ordering of the items. | 
|---|
| 127 | bool operator<(Node) const { return false; } | 
|---|
| 128 |  | 
|---|
| 129 | }; | 
|---|
| 130 |  | 
|---|
| 131 | /// This iterator goes through each node. | 
|---|
| 132 |  | 
|---|
| 133 | /// This iterator goes through each node. | 
|---|
| 134 | /// Its usage is quite simple, for example you can count the number | 
|---|
| 135 | /// of nodes in graph \c g of type \c Graph like this: | 
|---|
| 136 | ///\code | 
|---|
| 137 | /// int count=0; | 
|---|
| 138 | /// for (Graph::NodeIt n(g); n!=INVALID; ++n) ++count; | 
|---|
| 139 | ///\endcode | 
|---|
| 140 | class NodeIt : public Node { | 
|---|
| 141 | public: | 
|---|
| 142 | /// Default constructor | 
|---|
| 143 |  | 
|---|
| 144 | /// @warning The default constructor sets the iterator | 
|---|
| 145 | /// to an undefined value. | 
|---|
| 146 | NodeIt() { } | 
|---|
| 147 | /// Copy constructor. | 
|---|
| 148 |  | 
|---|
| 149 | /// Copy constructor. | 
|---|
| 150 | /// | 
|---|
| 151 | NodeIt(const NodeIt& n) : Node(n) { } | 
|---|
| 152 | /// Invalid constructor \& conversion. | 
|---|
| 153 |  | 
|---|
| 154 | /// Initialize the iterator to be invalid. | 
|---|
| 155 | /// \sa Invalid for more details. | 
|---|
| 156 | NodeIt(Invalid) { } | 
|---|
| 157 | /// Sets the iterator to the first node. | 
|---|
| 158 |  | 
|---|
| 159 | /// Sets the iterator to the first node of \c g. | 
|---|
| 160 | /// | 
|---|
| 161 | NodeIt(const UGraph&) { } | 
|---|
| 162 | /// Node -> NodeIt conversion. | 
|---|
| 163 |  | 
|---|
| 164 | /// Sets the iterator to the node of \c the graph pointed by | 
|---|
| 165 | /// the trivial iterator. | 
|---|
| 166 | /// This feature necessitates that each time we | 
|---|
| 167 | /// iterate the edge-set, the iteration order is the same. | 
|---|
| 168 | NodeIt(const UGraph&, const Node&) { } | 
|---|
| 169 | /// Next node. | 
|---|
| 170 |  | 
|---|
| 171 | /// Assign the iterator to the next node. | 
|---|
| 172 | /// | 
|---|
| 173 | NodeIt& operator++() { return *this; } | 
|---|
| 174 | }; | 
|---|
| 175 |  | 
|---|
| 176 |  | 
|---|
| 177 | /// The base type of the undirected edge iterators. | 
|---|
| 178 |  | 
|---|
| 179 | /// The base type of the undirected edge iterators. | 
|---|
| 180 | /// | 
|---|
| 181 | class UEdge { | 
|---|
| 182 | public: | 
|---|
| 183 | /// Default constructor | 
|---|
| 184 |  | 
|---|
| 185 | /// @warning The default constructor sets the iterator | 
|---|
| 186 | /// to an undefined value. | 
|---|
| 187 | UEdge() { } | 
|---|
| 188 | /// Copy constructor. | 
|---|
| 189 |  | 
|---|
| 190 | /// Copy constructor. | 
|---|
| 191 | /// | 
|---|
| 192 | UEdge(const UEdge&) { } | 
|---|
| 193 | /// Initialize the iterator to be invalid. | 
|---|
| 194 |  | 
|---|
| 195 | /// Initialize the iterator to be invalid. | 
|---|
| 196 | /// | 
|---|
| 197 | UEdge(Invalid) { } | 
|---|
| 198 | /// Equality operator | 
|---|
| 199 |  | 
|---|
| 200 | /// Two iterators are equal if and only if they point to the | 
|---|
| 201 | /// same object or both are invalid. | 
|---|
| 202 | bool operator==(UEdge) const { return true; } | 
|---|
| 203 | /// Inequality operator | 
|---|
| 204 |  | 
|---|
| 205 | /// \sa operator==(UEdge n) | 
|---|
| 206 | /// | 
|---|
| 207 | bool operator!=(UEdge) const { return true; } | 
|---|
| 208 |  | 
|---|
| 209 | /// Artificial ordering operator. | 
|---|
| 210 |  | 
|---|
| 211 | /// To allow the use of graph descriptors as key type in std::map or | 
|---|
| 212 | /// similar associative container we require this. | 
|---|
| 213 | /// | 
|---|
| 214 | /// \note This operator only have to define some strict ordering of | 
|---|
| 215 | /// the items; this order has nothing to do with the iteration | 
|---|
| 216 | /// ordering of the items. | 
|---|
| 217 | bool operator<(UEdge) const { return false; } | 
|---|
| 218 | }; | 
|---|
| 219 |  | 
|---|
| 220 | /// This iterator goes through each undirected edge. | 
|---|
| 221 |  | 
|---|
| 222 | /// This iterator goes through each undirected edge of a graph. | 
|---|
| 223 | /// Its usage is quite simple, for example you can count the number | 
|---|
| 224 | /// of undirected edges in a graph \c g of type \c Graph as follows: | 
|---|
| 225 | ///\code | 
|---|
| 226 | /// int count=0; | 
|---|
| 227 | /// for(Graph::UEdgeIt e(g); e!=INVALID; ++e) ++count; | 
|---|
| 228 | ///\endcode | 
|---|
| 229 | class UEdgeIt : public UEdge { | 
|---|
| 230 | public: | 
|---|
| 231 | /// Default constructor | 
|---|
| 232 |  | 
|---|
| 233 | /// @warning The default constructor sets the iterator | 
|---|
| 234 | /// to an undefined value. | 
|---|
| 235 | UEdgeIt() { } | 
|---|
| 236 | /// Copy constructor. | 
|---|
| 237 |  | 
|---|
| 238 | /// Copy constructor. | 
|---|
| 239 | /// | 
|---|
| 240 | UEdgeIt(const UEdgeIt& e) : UEdge(e) { } | 
|---|
| 241 | /// Initialize the iterator to be invalid. | 
|---|
| 242 |  | 
|---|
| 243 | /// Initialize the iterator to be invalid. | 
|---|
| 244 | /// | 
|---|
| 245 | UEdgeIt(Invalid) { } | 
|---|
| 246 | /// This constructor sets the iterator to the first undirected edge. | 
|---|
| 247 |  | 
|---|
| 248 | /// This constructor sets the iterator to the first undirected edge. | 
|---|
| 249 | UEdgeIt(const UGraph&) { } | 
|---|
| 250 | /// UEdge -> UEdgeIt conversion | 
|---|
| 251 |  | 
|---|
| 252 | /// Sets the iterator to the value of the trivial iterator. | 
|---|
| 253 | /// This feature necessitates that each time we | 
|---|
| 254 | /// iterate the undirected edge-set, the iteration order is the | 
|---|
| 255 | /// same. | 
|---|
| 256 | UEdgeIt(const UGraph&, const UEdge&) { } | 
|---|
| 257 | /// Next undirected edge | 
|---|
| 258 |  | 
|---|
| 259 | /// Assign the iterator to the next undirected edge. | 
|---|
| 260 | UEdgeIt& operator++() { return *this; } | 
|---|
| 261 | }; | 
|---|
| 262 |  | 
|---|
| 263 | /// \brief This iterator goes trough the incident undirected | 
|---|
| 264 | /// edges of a node. | 
|---|
| 265 | /// | 
|---|
| 266 | /// This iterator goes trough the incident undirected edges | 
|---|
| 267 | /// of a certain node of a graph. You should assume that the | 
|---|
| 268 | /// loop edges will be iterated twice. | 
|---|
| 269 | /// | 
|---|
| 270 | /// Its usage is quite simple, for example you can compute the | 
|---|
| 271 | /// degree (i.e. count the number of incident edges of a node \c n | 
|---|
| 272 | /// in graph \c g of type \c Graph as follows. | 
|---|
| 273 | /// | 
|---|
| 274 | ///\code | 
|---|
| 275 | /// int count=0; | 
|---|
| 276 | /// for(Graph::IncEdgeIt e(g, n); e!=INVALID; ++e) ++count; | 
|---|
| 277 | ///\endcode | 
|---|
| 278 | class IncEdgeIt : public UEdge { | 
|---|
| 279 | public: | 
|---|
| 280 | /// Default constructor | 
|---|
| 281 |  | 
|---|
| 282 | /// @warning The default constructor sets the iterator | 
|---|
| 283 | /// to an undefined value. | 
|---|
| 284 | IncEdgeIt() { } | 
|---|
| 285 | /// Copy constructor. | 
|---|
| 286 |  | 
|---|
| 287 | /// Copy constructor. | 
|---|
| 288 | /// | 
|---|
| 289 | IncEdgeIt(const IncEdgeIt& e) : UEdge(e) { } | 
|---|
| 290 | /// Initialize the iterator to be invalid. | 
|---|
| 291 |  | 
|---|
| 292 | /// Initialize the iterator to be invalid. | 
|---|
| 293 | /// | 
|---|
| 294 | IncEdgeIt(Invalid) { } | 
|---|
| 295 | /// This constructor sets the iterator to first incident edge. | 
|---|
| 296 |  | 
|---|
| 297 | /// This constructor set the iterator to the first incident edge of | 
|---|
| 298 | /// the node. | 
|---|
| 299 | IncEdgeIt(const UGraph&, const Node&) { } | 
|---|
| 300 | /// UEdge -> IncEdgeIt conversion | 
|---|
| 301 |  | 
|---|
| 302 | /// Sets the iterator to the value of the trivial iterator \c e. | 
|---|
| 303 | /// This feature necessitates that each time we | 
|---|
| 304 | /// iterate the edge-set, the iteration order is the same. | 
|---|
| 305 | IncEdgeIt(const UGraph&, const UEdge&) { } | 
|---|
| 306 | /// Next incident edge | 
|---|
| 307 |  | 
|---|
| 308 | /// Assign the iterator to the next incident edge | 
|---|
| 309 | /// of the corresponding node. | 
|---|
| 310 | IncEdgeIt& operator++() { return *this; } | 
|---|
| 311 | }; | 
|---|
| 312 |  | 
|---|
| 313 | /// The directed edge type. | 
|---|
| 314 |  | 
|---|
| 315 | /// The directed edge type. It can be converted to the | 
|---|
| 316 | /// undirected edge or it should be inherited from the undirected | 
|---|
| 317 | /// edge. | 
|---|
| 318 | class Edge : public UEdge { | 
|---|
| 319 | public: | 
|---|
| 320 | /// Default constructor | 
|---|
| 321 |  | 
|---|
| 322 | /// @warning The default constructor sets the iterator | 
|---|
| 323 | /// to an undefined value. | 
|---|
| 324 | Edge() { } | 
|---|
| 325 | /// Copy constructor. | 
|---|
| 326 |  | 
|---|
| 327 | /// Copy constructor. | 
|---|
| 328 | /// | 
|---|
| 329 | Edge(const Edge& e) : UEdge(e) { } | 
|---|
| 330 | /// Initialize the iterator to be invalid. | 
|---|
| 331 |  | 
|---|
| 332 | /// Initialize the iterator to be invalid. | 
|---|
| 333 | /// | 
|---|
| 334 | Edge(Invalid) { } | 
|---|
| 335 | /// Equality operator | 
|---|
| 336 |  | 
|---|
| 337 | /// Two iterators are equal if and only if they point to the | 
|---|
| 338 | /// same object or both are invalid. | 
|---|
| 339 | bool operator==(Edge) const { return true; } | 
|---|
| 340 | /// Inequality operator | 
|---|
| 341 |  | 
|---|
| 342 | /// \sa operator==(Edge n) | 
|---|
| 343 | /// | 
|---|
| 344 | bool operator!=(Edge) const { return true; } | 
|---|
| 345 |  | 
|---|
| 346 | /// Artificial ordering operator. | 
|---|
| 347 |  | 
|---|
| 348 | /// To allow the use of graph descriptors as key type in std::map or | 
|---|
| 349 | /// similar associative container we require this. | 
|---|
| 350 | /// | 
|---|
| 351 | /// \note This operator only have to define some strict ordering of | 
|---|
| 352 | /// the items; this order has nothing to do with the iteration | 
|---|
| 353 | /// ordering of the items. | 
|---|
| 354 | bool operator<(Edge) const { return false; } | 
|---|
| 355 |  | 
|---|
| 356 | }; | 
|---|
| 357 | /// This iterator goes through each directed edge. | 
|---|
| 358 |  | 
|---|
| 359 | /// This iterator goes through each edge of a graph. | 
|---|
| 360 | /// Its usage is quite simple, for example you can count the number | 
|---|
| 361 | /// of edges in a graph \c g of type \c Graph as follows: | 
|---|
| 362 | ///\code | 
|---|
| 363 | /// int count=0; | 
|---|
| 364 | /// for(Graph::EdgeIt e(g); e!=INVALID; ++e) ++count; | 
|---|
| 365 | ///\endcode | 
|---|
| 366 | class EdgeIt : public Edge { | 
|---|
| 367 | public: | 
|---|
| 368 | /// Default constructor | 
|---|
| 369 |  | 
|---|
| 370 | /// @warning The default constructor sets the iterator | 
|---|
| 371 | /// to an undefined value. | 
|---|
| 372 | EdgeIt() { } | 
|---|
| 373 | /// Copy constructor. | 
|---|
| 374 |  | 
|---|
| 375 | /// Copy constructor. | 
|---|
| 376 | /// | 
|---|
| 377 | EdgeIt(const EdgeIt& e) : Edge(e) { } | 
|---|
| 378 | /// Initialize the iterator to be invalid. | 
|---|
| 379 |  | 
|---|
| 380 | /// Initialize the iterator to be invalid. | 
|---|
| 381 | /// | 
|---|
| 382 | EdgeIt(Invalid) { } | 
|---|
| 383 | /// This constructor sets the iterator to the first edge. | 
|---|
| 384 |  | 
|---|
| 385 | /// This constructor sets the iterator to the first edge of \c g. | 
|---|
| 386 | ///@param g the graph | 
|---|
| 387 | EdgeIt(const UGraph &g) { ignore_unused_variable_warning(g); } | 
|---|
| 388 | /// Edge -> EdgeIt conversion | 
|---|
| 389 |  | 
|---|
| 390 | /// Sets the iterator to the value of the trivial iterator \c e. | 
|---|
| 391 | /// This feature necessitates that each time we | 
|---|
| 392 | /// iterate the edge-set, the iteration order is the same. | 
|---|
| 393 | EdgeIt(const UGraph&, const Edge&) { } | 
|---|
| 394 | ///Next edge | 
|---|
| 395 |  | 
|---|
| 396 | /// Assign the iterator to the next edge. | 
|---|
| 397 | EdgeIt& operator++() { return *this; } | 
|---|
| 398 | }; | 
|---|
| 399 |  | 
|---|
| 400 | /// This iterator goes trough the outgoing directed edges of a node. | 
|---|
| 401 |  | 
|---|
| 402 | /// This iterator goes trough the \e outgoing edges of a certain node | 
|---|
| 403 | /// of a graph. | 
|---|
| 404 | /// Its usage is quite simple, for example you can count the number | 
|---|
| 405 | /// of outgoing edges of a node \c n | 
|---|
| 406 | /// in graph \c g of type \c Graph as follows. | 
|---|
| 407 | ///\code | 
|---|
| 408 | /// int count=0; | 
|---|
| 409 | /// for (Graph::OutEdgeIt e(g, n); e!=INVALID; ++e) ++count; | 
|---|
| 410 | ///\endcode | 
|---|
| 411 |  | 
|---|
| 412 | class OutEdgeIt : public Edge { | 
|---|
| 413 | public: | 
|---|
| 414 | /// Default constructor | 
|---|
| 415 |  | 
|---|
| 416 | /// @warning The default constructor sets the iterator | 
|---|
| 417 | /// to an undefined value. | 
|---|
| 418 | OutEdgeIt() { } | 
|---|
| 419 | /// Copy constructor. | 
|---|
| 420 |  | 
|---|
| 421 | /// Copy constructor. | 
|---|
| 422 | /// | 
|---|
| 423 | OutEdgeIt(const OutEdgeIt& e) : Edge(e) { } | 
|---|
| 424 | /// Initialize the iterator to be invalid. | 
|---|
| 425 |  | 
|---|
| 426 | /// Initialize the iterator to be invalid. | 
|---|
| 427 | /// | 
|---|
| 428 | OutEdgeIt(Invalid) { } | 
|---|
| 429 | /// This constructor sets the iterator to the first outgoing edge. | 
|---|
| 430 |  | 
|---|
| 431 | /// This constructor sets the iterator to the first outgoing edge of | 
|---|
| 432 | /// the node. | 
|---|
| 433 | ///@param n the node | 
|---|
| 434 | ///@param g the graph | 
|---|
| 435 | OutEdgeIt(const UGraph& n, const Node& g) { | 
|---|
| 436 | ignore_unused_variable_warning(n); | 
|---|
| 437 | ignore_unused_variable_warning(g); | 
|---|
| 438 | } | 
|---|
| 439 | /// Edge -> OutEdgeIt conversion | 
|---|
| 440 |  | 
|---|
| 441 | /// Sets the iterator to the value of the trivial iterator. | 
|---|
| 442 | /// This feature necessitates that each time we | 
|---|
| 443 | /// iterate the edge-set, the iteration order is the same. | 
|---|
| 444 | OutEdgeIt(const UGraph&, const Edge&) { } | 
|---|
| 445 | ///Next outgoing edge | 
|---|
| 446 |  | 
|---|
| 447 | /// Assign the iterator to the next | 
|---|
| 448 | /// outgoing edge of the corresponding node. | 
|---|
| 449 | OutEdgeIt& operator++() { return *this; } | 
|---|
| 450 | }; | 
|---|
| 451 |  | 
|---|
| 452 | /// This iterator goes trough the incoming directed edges of a node. | 
|---|
| 453 |  | 
|---|
| 454 | /// This iterator goes trough the \e incoming edges of a certain node | 
|---|
| 455 | /// of a graph. | 
|---|
| 456 | /// Its usage is quite simple, for example you can count the number | 
|---|
| 457 | /// of outgoing edges of a node \c n | 
|---|
| 458 | /// in graph \c g of type \c Graph as follows. | 
|---|
| 459 | ///\code | 
|---|
| 460 | /// int count=0; | 
|---|
| 461 | /// for(Graph::InEdgeIt e(g, n); e!=INVALID; ++e) ++count; | 
|---|
| 462 | ///\endcode | 
|---|
| 463 |  | 
|---|
| 464 | class InEdgeIt : public Edge { | 
|---|
| 465 | public: | 
|---|
| 466 | /// Default constructor | 
|---|
| 467 |  | 
|---|
| 468 | /// @warning The default constructor sets the iterator | 
|---|
| 469 | /// to an undefined value. | 
|---|
| 470 | InEdgeIt() { } | 
|---|
| 471 | /// Copy constructor. | 
|---|
| 472 |  | 
|---|
| 473 | /// Copy constructor. | 
|---|
| 474 | /// | 
|---|
| 475 | InEdgeIt(const InEdgeIt& e) : Edge(e) { } | 
|---|
| 476 | /// Initialize the iterator to be invalid. | 
|---|
| 477 |  | 
|---|
| 478 | /// Initialize the iterator to be invalid. | 
|---|
| 479 | /// | 
|---|
| 480 | InEdgeIt(Invalid) { } | 
|---|
| 481 | /// This constructor sets the iterator to first incoming edge. | 
|---|
| 482 |  | 
|---|
| 483 | /// This constructor set the iterator to the first incoming edge of | 
|---|
| 484 | /// the node. | 
|---|
| 485 | ///@param n the node | 
|---|
| 486 | ///@param g the graph | 
|---|
| 487 | InEdgeIt(const UGraph& g, const Node& n) { | 
|---|
| 488 | ignore_unused_variable_warning(n); | 
|---|
| 489 | ignore_unused_variable_warning(g); | 
|---|
| 490 | } | 
|---|
| 491 | /// Edge -> InEdgeIt conversion | 
|---|
| 492 |  | 
|---|
| 493 | /// Sets the iterator to the value of the trivial iterator \c e. | 
|---|
| 494 | /// This feature necessitates that each time we | 
|---|
| 495 | /// iterate the edge-set, the iteration order is the same. | 
|---|
| 496 | InEdgeIt(const UGraph&, const Edge&) { } | 
|---|
| 497 | /// Next incoming edge | 
|---|
| 498 |  | 
|---|
| 499 | /// Assign the iterator to the next inedge of the corresponding node. | 
|---|
| 500 | /// | 
|---|
| 501 | InEdgeIt& operator++() { return *this; } | 
|---|
| 502 | }; | 
|---|
| 503 |  | 
|---|
| 504 | /// \brief Read write map of the nodes to type \c T. | 
|---|
| 505 | /// | 
|---|
| 506 | /// ReadWrite map of the nodes to type \c T. | 
|---|
| 507 | /// \sa Reference | 
|---|
| 508 | template<class T> | 
|---|
| 509 | class NodeMap : public ReadWriteMap< Node, T > | 
|---|
| 510 | { | 
|---|
| 511 | public: | 
|---|
| 512 |  | 
|---|
| 513 | ///\e | 
|---|
| 514 | NodeMap(const UGraph&) { } | 
|---|
| 515 | ///\e | 
|---|
| 516 | NodeMap(const UGraph&, T) { } | 
|---|
| 517 |  | 
|---|
| 518 | ///Copy constructor | 
|---|
| 519 | NodeMap(const NodeMap& nm) : ReadWriteMap< Node, T >(nm) { } | 
|---|
| 520 | ///Assignment operator | 
|---|
| 521 | template <typename CMap> | 
|---|
| 522 | NodeMap& operator=(const CMap&) { | 
|---|
| 523 | checkConcept<ReadMap<Node, T>, CMap>(); | 
|---|
| 524 | return *this; | 
|---|
| 525 | } | 
|---|
| 526 | }; | 
|---|
| 527 |  | 
|---|
| 528 | /// \brief Read write map of the directed edges to type \c T. | 
|---|
| 529 | /// | 
|---|
| 530 | /// Reference map of the directed edges to type \c T. | 
|---|
| 531 | /// \sa Reference | 
|---|
| 532 | template<class T> | 
|---|
| 533 | class EdgeMap : public ReadWriteMap<Edge,T> | 
|---|
| 534 | { | 
|---|
| 535 | public: | 
|---|
| 536 |  | 
|---|
| 537 | ///\e | 
|---|
| 538 | EdgeMap(const UGraph&) { } | 
|---|
| 539 | ///\e | 
|---|
| 540 | EdgeMap(const UGraph&, T) { } | 
|---|
| 541 | ///Copy constructor | 
|---|
| 542 | EdgeMap(const EdgeMap& em) : ReadWriteMap<Edge,T>(em) { } | 
|---|
| 543 | ///Assignment operator | 
|---|
| 544 | template <typename CMap> | 
|---|
| 545 | EdgeMap& operator=(const CMap&) { | 
|---|
| 546 | checkConcept<ReadMap<Edge, T>, CMap>(); | 
|---|
| 547 | return *this; | 
|---|
| 548 | } | 
|---|
| 549 | }; | 
|---|
| 550 |  | 
|---|
| 551 | /// Read write map of the undirected edges to type \c T. | 
|---|
| 552 |  | 
|---|
| 553 | /// Reference map of the edges to type \c T. | 
|---|
| 554 | /// \sa Reference | 
|---|
| 555 | template<class T> | 
|---|
| 556 | class UEdgeMap : public ReadWriteMap<UEdge,T> | 
|---|
| 557 | { | 
|---|
| 558 | public: | 
|---|
| 559 |  | 
|---|
| 560 | ///\e | 
|---|
| 561 | UEdgeMap(const UGraph&) { } | 
|---|
| 562 | ///\e | 
|---|
| 563 | UEdgeMap(const UGraph&, T) { } | 
|---|
| 564 | ///Copy constructor | 
|---|
| 565 | UEdgeMap(const UEdgeMap& em) : ReadWriteMap<UEdge,T>(em) {} | 
|---|
| 566 | ///Assignment operator | 
|---|
| 567 | template <typename CMap> | 
|---|
| 568 | UEdgeMap& operator=(const CMap&) { | 
|---|
| 569 | checkConcept<ReadMap<UEdge, T>, CMap>(); | 
|---|
| 570 | return *this; | 
|---|
| 571 | } | 
|---|
| 572 | }; | 
|---|
| 573 |  | 
|---|
| 574 | /// \brief Direct the given undirected edge. | 
|---|
| 575 | /// | 
|---|
| 576 | /// Direct the given undirected edge. The returned edge source | 
|---|
| 577 | /// will be the given node. | 
|---|
| 578 | Edge direct(const UEdge&, const Node&) const { | 
|---|
| 579 | return INVALID; | 
|---|
| 580 | } | 
|---|
| 581 |  | 
|---|
| 582 | /// \brief Direct the given undirected edge. | 
|---|
| 583 | /// | 
|---|
| 584 | /// Direct the given undirected edge. The returned edge | 
|---|
| 585 | /// represents the given undirected edge and the direction comes | 
|---|
| 586 | /// from the given bool.  The source of the undirected edge and | 
|---|
| 587 | /// the directed edge is the same when the given bool is true. | 
|---|
| 588 | Edge direct(const UEdge&, bool) const { | 
|---|
| 589 | return INVALID; | 
|---|
| 590 | } | 
|---|
| 591 |  | 
|---|
| 592 | /// \brief Returns true if the edge has default orientation. | 
|---|
| 593 | /// | 
|---|
| 594 | /// Returns whether the given directed edge is same orientation as | 
|---|
| 595 | /// the corresponding undirected edge's default orientation. | 
|---|
| 596 | bool direction(Edge) const { return true; } | 
|---|
| 597 |  | 
|---|
| 598 | /// \brief Returns the opposite directed edge. | 
|---|
| 599 | /// | 
|---|
| 600 | /// Returns the opposite directed edge. | 
|---|
| 601 | Edge oppositeEdge(Edge) const { return INVALID; } | 
|---|
| 602 |  | 
|---|
| 603 | /// \brief Opposite node on an edge | 
|---|
| 604 | /// | 
|---|
| 605 | /// \return the opposite of the given Node on the given UEdge | 
|---|
| 606 | Node oppositeNode(Node, UEdge) const { return INVALID; } | 
|---|
| 607 |  | 
|---|
| 608 | /// \brief First node of the undirected edge. | 
|---|
| 609 | /// | 
|---|
| 610 | /// \return the first node of the given UEdge. | 
|---|
| 611 | /// | 
|---|
| 612 | /// Naturally undirected edges don't have direction and thus | 
|---|
| 613 | /// don't have source and target node. But we use these two methods | 
|---|
| 614 | /// to query the two nodes of the edge. The direction of the edge | 
|---|
| 615 | /// which arises this way is called the inherent direction of the | 
|---|
| 616 | /// undirected edge, and is used to define the "default" direction | 
|---|
| 617 | /// of the directed versions of the edges. | 
|---|
| 618 | /// \sa direction | 
|---|
| 619 | Node source(UEdge) const { return INVALID; } | 
|---|
| 620 |  | 
|---|
| 621 | /// \brief Second node of the undirected edge. | 
|---|
| 622 | Node target(UEdge) const { return INVALID; } | 
|---|
| 623 |  | 
|---|
| 624 | /// \brief Source node of the directed edge. | 
|---|
| 625 | Node source(Edge) const { return INVALID; } | 
|---|
| 626 |  | 
|---|
| 627 | /// \brief Target node of the directed edge. | 
|---|
| 628 | Node target(Edge) const { return INVALID; } | 
|---|
| 629 |  | 
|---|
| 630 | void first(Node&) const {} | 
|---|
| 631 | void next(Node&) const {} | 
|---|
| 632 |  | 
|---|
| 633 | void first(UEdge&) const {} | 
|---|
| 634 | void next(UEdge&) const {} | 
|---|
| 635 |  | 
|---|
| 636 | void first(Edge&) const {} | 
|---|
| 637 | void next(Edge&) const {} | 
|---|
| 638 |  | 
|---|
| 639 | void firstOut(Edge&, Node) const {} | 
|---|
| 640 | void nextOut(Edge&) const {} | 
|---|
| 641 |  | 
|---|
| 642 | void firstIn(Edge&, Node) const {} | 
|---|
| 643 | void nextIn(Edge&) const {} | 
|---|
| 644 |  | 
|---|
| 645 |  | 
|---|
| 646 | void firstInc(UEdge &, bool &, const Node &) const {} | 
|---|
| 647 | void nextInc(UEdge &, bool &) const {} | 
|---|
| 648 |  | 
|---|
| 649 | /// \brief Base node of the iterator | 
|---|
| 650 | /// | 
|---|
| 651 | /// Returns the base node (the source in this case) of the iterator | 
|---|
| 652 | Node baseNode(OutEdgeIt e) const { | 
|---|
| 653 | return source(e); | 
|---|
| 654 | } | 
|---|
| 655 | /// \brief Running node of the iterator | 
|---|
| 656 | /// | 
|---|
| 657 | /// Returns the running node (the target in this case) of the | 
|---|
| 658 | /// iterator | 
|---|
| 659 | Node runningNode(OutEdgeIt e) const { | 
|---|
| 660 | return target(e); | 
|---|
| 661 | } | 
|---|
| 662 |  | 
|---|
| 663 | /// \brief Base node of the iterator | 
|---|
| 664 | /// | 
|---|
| 665 | /// Returns the base node (the target in this case) of the iterator | 
|---|
| 666 | Node baseNode(InEdgeIt e) const { | 
|---|
| 667 | return target(e); | 
|---|
| 668 | } | 
|---|
| 669 | /// \brief Running node of the iterator | 
|---|
| 670 | /// | 
|---|
| 671 | /// Returns the running node (the source in this case) of the | 
|---|
| 672 | /// iterator | 
|---|
| 673 | Node runningNode(InEdgeIt e) const { | 
|---|
| 674 | return source(e); | 
|---|
| 675 | } | 
|---|
| 676 |  | 
|---|
| 677 | /// \brief Base node of the iterator | 
|---|
| 678 | /// | 
|---|
| 679 | /// Returns the base node of the iterator | 
|---|
| 680 | Node baseNode(IncEdgeIt) const { | 
|---|
| 681 | return INVALID; | 
|---|
| 682 | } | 
|---|
| 683 |  | 
|---|
| 684 | /// \brief Running node of the iterator | 
|---|
| 685 | /// | 
|---|
| 686 | /// Returns the running node of the iterator | 
|---|
| 687 | Node runningNode(IncEdgeIt) const { | 
|---|
| 688 | return INVALID; | 
|---|
| 689 | } | 
|---|
| 690 |  | 
|---|
| 691 | template <typename Graph> | 
|---|
| 692 | struct Constraints { | 
|---|
| 693 | void constraints() { | 
|---|
| 694 | checkConcept<IterableUGraphComponent<>, Graph>(); | 
|---|
| 695 | checkConcept<MappableUGraphComponent<>, Graph>(); | 
|---|
| 696 | } | 
|---|
| 697 | }; | 
|---|
| 698 |  | 
|---|
| 699 | }; | 
|---|
| 700 |  | 
|---|
| 701 | /// @} | 
|---|
| 702 |  | 
|---|
| 703 | } | 
|---|
| 704 |  | 
|---|
| 705 | } | 
|---|
| 706 |  | 
|---|
| 707 | #endif | 
|---|