[209] | 1 | /* -*- mode: C++; indent-tabs-mode: nil; -*- |
---|
[57] | 2 | * |
---|
[209] | 3 | * This file is a part of LEMON, a generic C++ optimization library. |
---|
[57] | 4 | * |
---|
[1092] | 5 | * Copyright (C) 2003-2013 |
---|
[57] | 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 |
---|
[734] | 21 | ///\brief The concept of undirected graphs. |
---|
[57] | 22 | |
---|
[529] | 23 | #ifndef LEMON_CONCEPTS_GRAPH_H |
---|
| 24 | #define LEMON_CONCEPTS_GRAPH_H |
---|
[57] | 25 | |
---|
| 26 | #include <lemon/concepts/graph_components.h> |
---|
[734] | 27 | #include <lemon/concepts/maps.h> |
---|
| 28 | #include <lemon/concept_check.h> |
---|
[220] | 29 | #include <lemon/core.h> |
---|
[57] | 30 | |
---|
| 31 | namespace lemon { |
---|
| 32 | namespace concepts { |
---|
| 33 | |
---|
| 34 | /// \ingroup graph_concepts |
---|
| 35 | /// |
---|
[734] | 36 | /// \brief Class describing the concept of undirected graphs. |
---|
[57] | 37 | /// |
---|
[734] | 38 | /// This class describes the common interface of all undirected |
---|
| 39 | /// graphs. |
---|
[57] | 40 | /// |
---|
[734] | 41 | /// Like all concept classes, it only provides an interface |
---|
| 42 | /// without any sensible implementation. So any general algorithm for |
---|
| 43 | /// undirected graphs should compile with this class, but it will not |
---|
[57] | 44 | /// run properly, of course. |
---|
[734] | 45 | /// An actual graph implementation like \ref ListGraph or |
---|
[877] | 46 | /// \ref SmartGraph may have additional functionality. |
---|
[57] | 47 | /// |
---|
[734] | 48 | /// The undirected graphs also fulfill the concept of \ref Digraph |
---|
| 49 | /// "directed graphs", since each edge can also be regarded as two |
---|
| 50 | /// oppositely directed arcs. |
---|
| 51 | /// Undirected graphs provide an Edge type for the undirected edges and |
---|
| 52 | /// an Arc type for the directed arcs. The Arc type is convertible to |
---|
| 53 | /// Edge or inherited from it, i.e. the corresponding edge can be |
---|
| 54 | /// obtained from an arc. |
---|
| 55 | /// EdgeIt and EdgeMap classes can be used for the edges, while ArcIt |
---|
| 56 | /// and ArcMap classes can be used for the arcs (just like in digraphs). |
---|
| 57 | /// Both InArcIt and OutArcIt iterates on the same edges but with |
---|
| 58 | /// opposite direction. IncEdgeIt also iterates on the same edges |
---|
| 59 | /// as OutArcIt and InArcIt, but it is not convertible to Arc, |
---|
| 60 | /// only to Edge. |
---|
[57] | 61 | /// |
---|
[734] | 62 | /// In LEMON, each undirected edge has an inherent orientation. |
---|
| 63 | /// Thus it can defined if an arc is forward or backward oriented in |
---|
| 64 | /// an undirected graph with respect to this default oriantation of |
---|
| 65 | /// the represented edge. |
---|
| 66 | /// With the direction() and direct() functions the direction |
---|
| 67 | /// of an arc can be obtained and set, respectively. |
---|
[57] | 68 | /// |
---|
[734] | 69 | /// Only nodes and edges can be added to or removed from an undirected |
---|
| 70 | /// graph and the corresponding arcs are added or removed automatically. |
---|
| 71 | /// |
---|
| 72 | /// \sa Digraph |
---|
[57] | 73 | class Graph { |
---|
[734] | 74 | private: |
---|
[1018] | 75 | /// Graphs are \e not copy constructible. Use GraphCopy instead. |
---|
[734] | 76 | Graph(const Graph&) {} |
---|
| 77 | /// \brief Assignment of a graph to another one is \e not allowed. |
---|
[1018] | 78 | /// Use GraphCopy instead. |
---|
[734] | 79 | void operator=(const Graph&) {} |
---|
| 80 | |
---|
[57] | 81 | public: |
---|
[734] | 82 | /// Default constructor. |
---|
| 83 | Graph() {} |
---|
| 84 | |
---|
| 85 | /// \brief Undirected graphs should be tagged with \c UndirectedTag. |
---|
[57] | 86 | /// |
---|
[734] | 87 | /// Undirected graphs should be tagged with \c UndirectedTag. |
---|
[877] | 88 | /// |
---|
[734] | 89 | /// This tag helps the \c enable_if technics to make compile time |
---|
[209] | 90 | /// specializations for undirected graphs. |
---|
[57] | 91 | typedef True UndirectedTag; |
---|
| 92 | |
---|
[734] | 93 | /// The node type of the graph |
---|
| 94 | |
---|
| 95 | /// This class identifies a node of the graph. It also serves |
---|
| 96 | /// as a base class of the node iterators, |
---|
| 97 | /// thus they convert to this type. |
---|
[57] | 98 | class Node { |
---|
| 99 | public: |
---|
| 100 | /// Default constructor |
---|
| 101 | |
---|
[734] | 102 | /// Default constructor. |
---|
| 103 | /// \warning It sets the object to an undefined value. |
---|
[57] | 104 | Node() { } |
---|
| 105 | /// Copy constructor. |
---|
| 106 | |
---|
| 107 | /// Copy constructor. |
---|
| 108 | /// |
---|
| 109 | Node(const Node&) { } |
---|
| 110 | |
---|
[734] | 111 | /// %Invalid constructor \& conversion. |
---|
[57] | 112 | |
---|
[734] | 113 | /// Initializes the object to be invalid. |
---|
[57] | 114 | /// \sa Invalid for more details. |
---|
| 115 | Node(Invalid) { } |
---|
| 116 | /// Equality operator |
---|
| 117 | |
---|
[734] | 118 | /// Equality operator. |
---|
| 119 | /// |
---|
[57] | 120 | /// Two iterators are equal if and only if they point to the |
---|
[734] | 121 | /// same object or both are \c INVALID. |
---|
[57] | 122 | bool operator==(Node) const { return true; } |
---|
| 123 | |
---|
| 124 | /// Inequality operator |
---|
[209] | 125 | |
---|
[734] | 126 | /// Inequality operator. |
---|
[57] | 127 | bool operator!=(Node) const { return true; } |
---|
| 128 | |
---|
[209] | 129 | /// Artificial ordering operator. |
---|
| 130 | |
---|
[734] | 131 | /// Artificial ordering operator. |
---|
[209] | 132 | /// |
---|
[734] | 133 | /// \note This operator only has to define some strict ordering of |
---|
[209] | 134 | /// the items; this order has nothing to do with the iteration |
---|
| 135 | /// ordering of the items. |
---|
| 136 | bool operator<(Node) const { return false; } |
---|
[57] | 137 | |
---|
| 138 | }; |
---|
[209] | 139 | |
---|
[734] | 140 | /// Iterator class for the nodes. |
---|
[57] | 141 | |
---|
[734] | 142 | /// This iterator goes through each node of the graph. |
---|
[786] | 143 | /// Its usage is quite simple, for example, you can count the number |
---|
[734] | 144 | /// of nodes in a graph \c g of type \c %Graph like this: |
---|
[57] | 145 | ///\code |
---|
| 146 | /// int count=0; |
---|
| 147 | /// for (Graph::NodeIt n(g); n!=INVALID; ++n) ++count; |
---|
| 148 | ///\endcode |
---|
| 149 | class NodeIt : public Node { |
---|
| 150 | public: |
---|
| 151 | /// Default constructor |
---|
| 152 | |
---|
[734] | 153 | /// Default constructor. |
---|
| 154 | /// \warning It sets the iterator to an undefined value. |
---|
[57] | 155 | NodeIt() { } |
---|
| 156 | /// Copy constructor. |
---|
[209] | 157 | |
---|
[57] | 158 | /// Copy constructor. |
---|
| 159 | /// |
---|
| 160 | NodeIt(const NodeIt& n) : Node(n) { } |
---|
[734] | 161 | /// %Invalid constructor \& conversion. |
---|
[57] | 162 | |
---|
[734] | 163 | /// Initializes the iterator to be invalid. |
---|
[57] | 164 | /// \sa Invalid for more details. |
---|
| 165 | NodeIt(Invalid) { } |
---|
| 166 | /// Sets the iterator to the first node. |
---|
| 167 | |
---|
[734] | 168 | /// Sets the iterator to the first node of the given digraph. |
---|
[57] | 169 | /// |
---|
[734] | 170 | explicit NodeIt(const Graph&) { } |
---|
| 171 | /// Sets the iterator to the given node. |
---|
[57] | 172 | |
---|
[734] | 173 | /// Sets the iterator to the given node of the given digraph. |
---|
| 174 | /// |
---|
[57] | 175 | NodeIt(const Graph&, const Node&) { } |
---|
| 176 | /// Next node. |
---|
| 177 | |
---|
| 178 | /// Assign the iterator to the next node. |
---|
| 179 | /// |
---|
| 180 | NodeIt& operator++() { return *this; } |
---|
| 181 | }; |
---|
[209] | 182 | |
---|
| 183 | |
---|
[734] | 184 | /// The edge type of the graph |
---|
[57] | 185 | |
---|
[734] | 186 | /// This class identifies an edge of the graph. It also serves |
---|
| 187 | /// as a base class of the edge iterators, |
---|
| 188 | /// thus they will convert to this type. |
---|
[57] | 189 | class Edge { |
---|
| 190 | public: |
---|
| 191 | /// Default constructor |
---|
| 192 | |
---|
[734] | 193 | /// Default constructor. |
---|
| 194 | /// \warning It sets the object to an undefined value. |
---|
[57] | 195 | Edge() { } |
---|
| 196 | /// Copy constructor. |
---|
| 197 | |
---|
| 198 | /// Copy constructor. |
---|
| 199 | /// |
---|
| 200 | Edge(const Edge&) { } |
---|
[734] | 201 | /// %Invalid constructor \& conversion. |
---|
[57] | 202 | |
---|
[734] | 203 | /// Initializes the object to be invalid. |
---|
| 204 | /// \sa Invalid for more details. |
---|
[57] | 205 | Edge(Invalid) { } |
---|
| 206 | /// Equality operator |
---|
| 207 | |
---|
[734] | 208 | /// Equality operator. |
---|
| 209 | /// |
---|
[57] | 210 | /// Two iterators are equal if and only if they point to the |
---|
[734] | 211 | /// same object or both are \c INVALID. |
---|
[57] | 212 | bool operator==(Edge) const { return true; } |
---|
| 213 | /// Inequality operator |
---|
| 214 | |
---|
[734] | 215 | /// Inequality operator. |
---|
[57] | 216 | bool operator!=(Edge) const { return true; } |
---|
| 217 | |
---|
[209] | 218 | /// Artificial ordering operator. |
---|
| 219 | |
---|
[734] | 220 | /// Artificial ordering operator. |
---|
[209] | 221 | /// |
---|
[734] | 222 | /// \note This operator only has to define some strict ordering of |
---|
| 223 | /// the edges; this order has nothing to do with the iteration |
---|
| 224 | /// ordering of the edges. |
---|
[209] | 225 | bool operator<(Edge) const { return false; } |
---|
[57] | 226 | }; |
---|
| 227 | |
---|
[734] | 228 | /// Iterator class for the edges. |
---|
[57] | 229 | |
---|
[734] | 230 | /// This iterator goes through each edge of the graph. |
---|
[786] | 231 | /// Its usage is quite simple, for example, you can count the number |
---|
[734] | 232 | /// of edges in a graph \c g of type \c %Graph as follows: |
---|
[57] | 233 | ///\code |
---|
| 234 | /// int count=0; |
---|
| 235 | /// for(Graph::EdgeIt e(g); e!=INVALID; ++e) ++count; |
---|
| 236 | ///\endcode |
---|
| 237 | class EdgeIt : public Edge { |
---|
| 238 | public: |
---|
| 239 | /// Default constructor |
---|
| 240 | |
---|
[734] | 241 | /// Default constructor. |
---|
| 242 | /// \warning It sets the iterator to an undefined value. |
---|
[57] | 243 | EdgeIt() { } |
---|
| 244 | /// Copy constructor. |
---|
| 245 | |
---|
| 246 | /// Copy constructor. |
---|
| 247 | /// |
---|
| 248 | EdgeIt(const EdgeIt& e) : Edge(e) { } |
---|
[734] | 249 | /// %Invalid constructor \& conversion. |
---|
[57] | 250 | |
---|
[734] | 251 | /// Initializes the iterator to be invalid. |
---|
| 252 | /// \sa Invalid for more details. |
---|
| 253 | EdgeIt(Invalid) { } |
---|
| 254 | /// Sets the iterator to the first edge. |
---|
| 255 | |
---|
| 256 | /// Sets the iterator to the first edge of the given graph. |
---|
[57] | 257 | /// |
---|
[734] | 258 | explicit EdgeIt(const Graph&) { } |
---|
| 259 | /// Sets the iterator to the given edge. |
---|
[209] | 260 | |
---|
[734] | 261 | /// Sets the iterator to the given edge of the given graph. |
---|
| 262 | /// |
---|
[209] | 263 | EdgeIt(const Graph&, const Edge&) { } |
---|
[57] | 264 | /// Next edge |
---|
[209] | 265 | |
---|
[57] | 266 | /// Assign the iterator to the next edge. |
---|
[734] | 267 | /// |
---|
[57] | 268 | EdgeIt& operator++() { return *this; } |
---|
| 269 | }; |
---|
| 270 | |
---|
[734] | 271 | /// Iterator class for the incident edges of a node. |
---|
| 272 | |
---|
| 273 | /// This iterator goes trough the incident undirected edges |
---|
| 274 | /// of a certain node of a graph. |
---|
[786] | 275 | /// Its usage is quite simple, for example, you can compute the |
---|
[734] | 276 | /// degree (i.e. the number of incident edges) of a node \c n |
---|
| 277 | /// in a graph \c g of type \c %Graph as follows. |
---|
[57] | 278 | /// |
---|
| 279 | ///\code |
---|
| 280 | /// int count=0; |
---|
[78] | 281 | /// for(Graph::IncEdgeIt e(g, n); e!=INVALID; ++e) ++count; |
---|
[57] | 282 | ///\endcode |
---|
[734] | 283 | /// |
---|
| 284 | /// \warning Loop edges will be iterated twice. |
---|
[78] | 285 | class IncEdgeIt : public Edge { |
---|
[57] | 286 | public: |
---|
| 287 | /// Default constructor |
---|
| 288 | |
---|
[734] | 289 | /// Default constructor. |
---|
| 290 | /// \warning It sets the iterator to an undefined value. |
---|
[78] | 291 | IncEdgeIt() { } |
---|
[57] | 292 | /// Copy constructor. |
---|
| 293 | |
---|
| 294 | /// Copy constructor. |
---|
| 295 | /// |
---|
[78] | 296 | IncEdgeIt(const IncEdgeIt& e) : Edge(e) { } |
---|
[734] | 297 | /// %Invalid constructor \& conversion. |
---|
[57] | 298 | |
---|
[734] | 299 | /// Initializes the iterator to be invalid. |
---|
| 300 | /// \sa Invalid for more details. |
---|
| 301 | IncEdgeIt(Invalid) { } |
---|
| 302 | /// Sets the iterator to the first incident edge. |
---|
| 303 | |
---|
| 304 | /// Sets the iterator to the first incident edge of the given node. |
---|
[57] | 305 | /// |
---|
[734] | 306 | IncEdgeIt(const Graph&, const Node&) { } |
---|
| 307 | /// Sets the iterator to the given edge. |
---|
[209] | 308 | |
---|
[734] | 309 | /// Sets the iterator to the given edge of the given graph. |
---|
| 310 | /// |
---|
| 311 | IncEdgeIt(const Graph&, const Edge&) { } |
---|
| 312 | /// Next incident edge |
---|
[57] | 313 | |
---|
[734] | 314 | /// Assign the iterator to the next incident edge |
---|
[209] | 315 | /// of the corresponding node. |
---|
[78] | 316 | IncEdgeIt& operator++() { return *this; } |
---|
[57] | 317 | }; |
---|
| 318 | |
---|
[734] | 319 | /// The arc type of the graph |
---|
[57] | 320 | |
---|
[734] | 321 | /// This class identifies a directed arc of the graph. It also serves |
---|
| 322 | /// as a base class of the arc iterators, |
---|
| 323 | /// thus they will convert to this type. |
---|
[657] | 324 | class Arc { |
---|
[57] | 325 | public: |
---|
| 326 | /// Default constructor |
---|
| 327 | |
---|
[734] | 328 | /// Default constructor. |
---|
| 329 | /// \warning It sets the object to an undefined value. |
---|
[57] | 330 | Arc() { } |
---|
| 331 | /// Copy constructor. |
---|
| 332 | |
---|
| 333 | /// Copy constructor. |
---|
| 334 | /// |
---|
[657] | 335 | Arc(const Arc&) { } |
---|
[734] | 336 | /// %Invalid constructor \& conversion. |
---|
[57] | 337 | |
---|
[734] | 338 | /// Initializes the object to be invalid. |
---|
| 339 | /// \sa Invalid for more details. |
---|
[57] | 340 | Arc(Invalid) { } |
---|
| 341 | /// Equality operator |
---|
| 342 | |
---|
[734] | 343 | /// Equality operator. |
---|
| 344 | /// |
---|
[57] | 345 | /// Two iterators are equal if and only if they point to the |
---|
[734] | 346 | /// same object or both are \c INVALID. |
---|
[57] | 347 | bool operator==(Arc) const { return true; } |
---|
| 348 | /// Inequality operator |
---|
| 349 | |
---|
[734] | 350 | /// Inequality operator. |
---|
[57] | 351 | bool operator!=(Arc) const { return true; } |
---|
| 352 | |
---|
[209] | 353 | /// Artificial ordering operator. |
---|
| 354 | |
---|
[734] | 355 | /// Artificial ordering operator. |
---|
[209] | 356 | /// |
---|
[734] | 357 | /// \note This operator only has to define some strict ordering of |
---|
| 358 | /// the arcs; this order has nothing to do with the iteration |
---|
| 359 | /// ordering of the arcs. |
---|
[209] | 360 | bool operator<(Arc) const { return false; } |
---|
| 361 | |
---|
[734] | 362 | /// Converison to \c Edge |
---|
[877] | 363 | |
---|
[734] | 364 | /// Converison to \c Edge. |
---|
| 365 | /// |
---|
[657] | 366 | operator Edge() const { return Edge(); } |
---|
[209] | 367 | }; |
---|
[57] | 368 | |
---|
[734] | 369 | /// Iterator class for the arcs. |
---|
| 370 | |
---|
| 371 | /// This iterator goes through each directed arc of the graph. |
---|
[786] | 372 | /// Its usage is quite simple, for example, you can count the number |
---|
[734] | 373 | /// of arcs in a graph \c g of type \c %Graph as follows: |
---|
[57] | 374 | ///\code |
---|
| 375 | /// int count=0; |
---|
[734] | 376 | /// for(Graph::ArcIt a(g); a!=INVALID; ++a) ++count; |
---|
[57] | 377 | ///\endcode |
---|
| 378 | class ArcIt : public Arc { |
---|
| 379 | public: |
---|
| 380 | /// Default constructor |
---|
| 381 | |
---|
[734] | 382 | /// Default constructor. |
---|
| 383 | /// \warning It sets the iterator to an undefined value. |
---|
[57] | 384 | ArcIt() { } |
---|
| 385 | /// Copy constructor. |
---|
| 386 | |
---|
| 387 | /// Copy constructor. |
---|
| 388 | /// |
---|
| 389 | ArcIt(const ArcIt& e) : Arc(e) { } |
---|
[734] | 390 | /// %Invalid constructor \& conversion. |
---|
[57] | 391 | |
---|
[734] | 392 | /// Initializes the iterator to be invalid. |
---|
| 393 | /// \sa Invalid for more details. |
---|
| 394 | ArcIt(Invalid) { } |
---|
| 395 | /// Sets the iterator to the first arc. |
---|
| 396 | |
---|
| 397 | /// Sets the iterator to the first arc of the given graph. |
---|
[57] | 398 | /// |
---|
[1093] | 399 | explicit ArcIt(const Graph &g) { |
---|
| 400 | ::lemon::ignore_unused_variable_warning(g); |
---|
| 401 | } |
---|
[734] | 402 | /// Sets the iterator to the given arc. |
---|
[209] | 403 | |
---|
[734] | 404 | /// Sets the iterator to the given arc of the given graph. |
---|
| 405 | /// |
---|
[209] | 406 | ArcIt(const Graph&, const Arc&) { } |
---|
[734] | 407 | /// Next arc |
---|
[209] | 408 | |
---|
[57] | 409 | /// Assign the iterator to the next arc. |
---|
[734] | 410 | /// |
---|
[57] | 411 | ArcIt& operator++() { return *this; } |
---|
| 412 | }; |
---|
[209] | 413 | |
---|
[734] | 414 | /// Iterator class for the outgoing arcs of a node. |
---|
[57] | 415 | |
---|
[734] | 416 | /// This iterator goes trough the \e outgoing directed arcs of a |
---|
| 417 | /// certain node of a graph. |
---|
[786] | 418 | /// Its usage is quite simple, for example, you can count the number |
---|
[57] | 419 | /// of outgoing arcs of a node \c n |
---|
[734] | 420 | /// in a graph \c g of type \c %Graph as follows. |
---|
[57] | 421 | ///\code |
---|
| 422 | /// int count=0; |
---|
[734] | 423 | /// for (Digraph::OutArcIt a(g, n); a!=INVALID; ++a) ++count; |
---|
[57] | 424 | ///\endcode |
---|
| 425 | class OutArcIt : public Arc { |
---|
| 426 | public: |
---|
| 427 | /// Default constructor |
---|
| 428 | |
---|
[734] | 429 | /// Default constructor. |
---|
| 430 | /// \warning It sets the iterator to an undefined value. |
---|
[57] | 431 | OutArcIt() { } |
---|
| 432 | /// Copy constructor. |
---|
| 433 | |
---|
| 434 | /// Copy constructor. |
---|
| 435 | /// |
---|
| 436 | OutArcIt(const OutArcIt& e) : Arc(e) { } |
---|
[734] | 437 | /// %Invalid constructor \& conversion. |
---|
[57] | 438 | |
---|
[734] | 439 | /// Initializes the iterator to be invalid. |
---|
| 440 | /// \sa Invalid for more details. |
---|
| 441 | OutArcIt(Invalid) { } |
---|
| 442 | /// Sets the iterator to the first outgoing arc. |
---|
| 443 | |
---|
| 444 | /// Sets the iterator to the first outgoing arc of the given node. |
---|
[57] | 445 | /// |
---|
| 446 | OutArcIt(const Graph& n, const Node& g) { |
---|
[1083] | 447 | ::lemon::ignore_unused_variable_warning(n); |
---|
| 448 | ::lemon::ignore_unused_variable_warning(g); |
---|
[209] | 449 | } |
---|
[734] | 450 | /// Sets the iterator to the given arc. |
---|
[57] | 451 | |
---|
[734] | 452 | /// Sets the iterator to the given arc of the given graph. |
---|
| 453 | /// |
---|
[57] | 454 | OutArcIt(const Graph&, const Arc&) { } |
---|
[734] | 455 | /// Next outgoing arc |
---|
[209] | 456 | |
---|
| 457 | /// Assign the iterator to the next |
---|
[57] | 458 | /// outgoing arc of the corresponding node. |
---|
| 459 | OutArcIt& operator++() { return *this; } |
---|
| 460 | }; |
---|
| 461 | |
---|
[734] | 462 | /// Iterator class for the incoming arcs of a node. |
---|
[57] | 463 | |
---|
[734] | 464 | /// This iterator goes trough the \e incoming directed arcs of a |
---|
| 465 | /// certain node of a graph. |
---|
[786] | 466 | /// Its usage is quite simple, for example, you can count the number |
---|
[734] | 467 | /// of incoming arcs of a node \c n |
---|
| 468 | /// in a graph \c g of type \c %Graph as follows. |
---|
[57] | 469 | ///\code |
---|
| 470 | /// int count=0; |
---|
[734] | 471 | /// for (Digraph::InArcIt a(g, n); a!=INVALID; ++a) ++count; |
---|
[57] | 472 | ///\endcode |
---|
| 473 | class InArcIt : public Arc { |
---|
| 474 | public: |
---|
| 475 | /// Default constructor |
---|
| 476 | |
---|
[734] | 477 | /// Default constructor. |
---|
| 478 | /// \warning It sets the iterator to an undefined value. |
---|
[57] | 479 | InArcIt() { } |
---|
| 480 | /// Copy constructor. |
---|
| 481 | |
---|
| 482 | /// Copy constructor. |
---|
| 483 | /// |
---|
| 484 | InArcIt(const InArcIt& e) : Arc(e) { } |
---|
[734] | 485 | /// %Invalid constructor \& conversion. |
---|
[57] | 486 | |
---|
[734] | 487 | /// Initializes the iterator to be invalid. |
---|
| 488 | /// \sa Invalid for more details. |
---|
| 489 | InArcIt(Invalid) { } |
---|
| 490 | /// Sets the iterator to the first incoming arc. |
---|
| 491 | |
---|
| 492 | /// Sets the iterator to the first incoming arc of the given node. |
---|
[57] | 493 | /// |
---|
[209] | 494 | InArcIt(const Graph& g, const Node& n) { |
---|
[1083] | 495 | ::lemon::ignore_unused_variable_warning(n); |
---|
| 496 | ::lemon::ignore_unused_variable_warning(g); |
---|
[209] | 497 | } |
---|
[734] | 498 | /// Sets the iterator to the given arc. |
---|
[57] | 499 | |
---|
[734] | 500 | /// Sets the iterator to the given arc of the given graph. |
---|
| 501 | /// |
---|
[57] | 502 | InArcIt(const Graph&, const Arc&) { } |
---|
| 503 | /// Next incoming arc |
---|
| 504 | |
---|
[734] | 505 | /// Assign the iterator to the next |
---|
| 506 | /// incoming arc of the corresponding node. |
---|
[57] | 507 | InArcIt& operator++() { return *this; } |
---|
| 508 | }; |
---|
| 509 | |
---|
[734] | 510 | /// \brief Standard graph map type for the nodes. |
---|
[209] | 511 | /// |
---|
[734] | 512 | /// Standard graph map type for the nodes. |
---|
| 513 | /// It conforms to the ReferenceMap concept. |
---|
[209] | 514 | template<class T> |
---|
[580] | 515 | class NodeMap : public ReferenceMap<Node, T, T&, const T&> |
---|
[57] | 516 | { |
---|
| 517 | public: |
---|
| 518 | |
---|
[734] | 519 | /// Constructor |
---|
| 520 | explicit NodeMap(const Graph&) { } |
---|
| 521 | /// Constructor with given initial value |
---|
[57] | 522 | NodeMap(const Graph&, T) { } |
---|
| 523 | |
---|
[263] | 524 | private: |
---|
[57] | 525 | ///Copy constructor |
---|
[580] | 526 | NodeMap(const NodeMap& nm) : |
---|
| 527 | ReferenceMap<Node, T, T&, const T&>(nm) { } |
---|
[57] | 528 | ///Assignment operator |
---|
| 529 | template <typename CMap> |
---|
[209] | 530 | NodeMap& operator=(const CMap&) { |
---|
[57] | 531 | checkConcept<ReadMap<Node, T>, CMap>(); |
---|
[209] | 532 | return *this; |
---|
[57] | 533 | } |
---|
| 534 | }; |
---|
| 535 | |
---|
[734] | 536 | /// \brief Standard graph map type for the arcs. |
---|
[57] | 537 | /// |
---|
[734] | 538 | /// Standard graph map type for the arcs. |
---|
| 539 | /// It conforms to the ReferenceMap concept. |
---|
[209] | 540 | template<class T> |
---|
[580] | 541 | class ArcMap : public ReferenceMap<Arc, T, T&, const T&> |
---|
[57] | 542 | { |
---|
| 543 | public: |
---|
| 544 | |
---|
[734] | 545 | /// Constructor |
---|
| 546 | explicit ArcMap(const Graph&) { } |
---|
| 547 | /// Constructor with given initial value |
---|
[57] | 548 | ArcMap(const Graph&, T) { } |
---|
[734] | 549 | |
---|
[263] | 550 | private: |
---|
[57] | 551 | ///Copy constructor |
---|
[580] | 552 | ArcMap(const ArcMap& em) : |
---|
| 553 | ReferenceMap<Arc, T, T&, const T&>(em) { } |
---|
[57] | 554 | ///Assignment operator |
---|
| 555 | template <typename CMap> |
---|
[209] | 556 | ArcMap& operator=(const CMap&) { |
---|
[57] | 557 | checkConcept<ReadMap<Arc, T>, CMap>(); |
---|
[209] | 558 | return *this; |
---|
[57] | 559 | } |
---|
| 560 | }; |
---|
| 561 | |
---|
[734] | 562 | /// \brief Standard graph map type for the edges. |
---|
| 563 | /// |
---|
| 564 | /// Standard graph map type for the edges. |
---|
| 565 | /// It conforms to the ReferenceMap concept. |
---|
[209] | 566 | template<class T> |
---|
[580] | 567 | class EdgeMap : public ReferenceMap<Edge, T, T&, const T&> |
---|
[57] | 568 | { |
---|
| 569 | public: |
---|
| 570 | |
---|
[734] | 571 | /// Constructor |
---|
| 572 | explicit EdgeMap(const Graph&) { } |
---|
| 573 | /// Constructor with given initial value |
---|
[57] | 574 | EdgeMap(const Graph&, T) { } |
---|
[734] | 575 | |
---|
[263] | 576 | private: |
---|
[57] | 577 | ///Copy constructor |
---|
[580] | 578 | EdgeMap(const EdgeMap& em) : |
---|
| 579 | ReferenceMap<Edge, T, T&, const T&>(em) {} |
---|
[57] | 580 | ///Assignment operator |
---|
| 581 | template <typename CMap> |
---|
[209] | 582 | EdgeMap& operator=(const CMap&) { |
---|
[57] | 583 | checkConcept<ReadMap<Edge, T>, CMap>(); |
---|
[209] | 584 | return *this; |
---|
[57] | 585 | } |
---|
| 586 | }; |
---|
| 587 | |
---|
[734] | 588 | /// \brief The first node of the edge. |
---|
[57] | 589 | /// |
---|
[734] | 590 | /// Returns the first node of the given edge. |
---|
[57] | 591 | /// |
---|
[786] | 592 | /// Edges don't have source and target nodes, however, methods |
---|
[734] | 593 | /// u() and v() are used to query the two end-nodes of an edge. |
---|
| 594 | /// The orientation of an edge that arises this way is called |
---|
| 595 | /// the inherent direction, it is used to define the default |
---|
| 596 | /// direction for the corresponding arcs. |
---|
[559] | 597 | /// \sa v() |
---|
| 598 | /// \sa direction() |
---|
[57] | 599 | Node u(Edge) const { return INVALID; } |
---|
| 600 | |
---|
[734] | 601 | /// \brief The second node of the edge. |
---|
[559] | 602 | /// |
---|
[734] | 603 | /// Returns the second node of the given edge. |
---|
[559] | 604 | /// |
---|
[786] | 605 | /// Edges don't have source and target nodes, however, methods |
---|
[734] | 606 | /// u() and v() are used to query the two end-nodes of an edge. |
---|
| 607 | /// The orientation of an edge that arises this way is called |
---|
| 608 | /// the inherent direction, it is used to define the default |
---|
| 609 | /// direction for the corresponding arcs. |
---|
[559] | 610 | /// \sa u() |
---|
| 611 | /// \sa direction() |
---|
[57] | 612 | Node v(Edge) const { return INVALID; } |
---|
| 613 | |
---|
[734] | 614 | /// \brief The source node of the arc. |
---|
| 615 | /// |
---|
| 616 | /// Returns the source node of the given arc. |
---|
[57] | 617 | Node source(Arc) const { return INVALID; } |
---|
| 618 | |
---|
[734] | 619 | /// \brief The target node of the arc. |
---|
| 620 | /// |
---|
| 621 | /// Returns the target node of the given arc. |
---|
[57] | 622 | Node target(Arc) const { return INVALID; } |
---|
| 623 | |
---|
[734] | 624 | /// \brief The ID of the node. |
---|
| 625 | /// |
---|
| 626 | /// Returns the ID of the given node. |
---|
[209] | 627 | int id(Node) const { return -1; } |
---|
[61] | 628 | |
---|
[734] | 629 | /// \brief The ID of the edge. |
---|
| 630 | /// |
---|
| 631 | /// Returns the ID of the given edge. |
---|
[209] | 632 | int id(Edge) const { return -1; } |
---|
[61] | 633 | |
---|
[734] | 634 | /// \brief The ID of the arc. |
---|
| 635 | /// |
---|
| 636 | /// Returns the ID of the given arc. |
---|
[209] | 637 | int id(Arc) const { return -1; } |
---|
[61] | 638 | |
---|
[734] | 639 | /// \brief The node with the given ID. |
---|
[61] | 640 | /// |
---|
[734] | 641 | /// Returns the node with the given ID. |
---|
| 642 | /// \pre The argument should be a valid node ID in the graph. |
---|
[209] | 643 | Node nodeFromId(int) const { return INVALID; } |
---|
[61] | 644 | |
---|
[734] | 645 | /// \brief The edge with the given ID. |
---|
[61] | 646 | /// |
---|
[734] | 647 | /// Returns the edge with the given ID. |
---|
| 648 | /// \pre The argument should be a valid edge ID in the graph. |
---|
[209] | 649 | Edge edgeFromId(int) const { return INVALID; } |
---|
[61] | 650 | |
---|
[734] | 651 | /// \brief The arc with the given ID. |
---|
[61] | 652 | /// |
---|
[734] | 653 | /// Returns the arc with the given ID. |
---|
| 654 | /// \pre The argument should be a valid arc ID in the graph. |
---|
[209] | 655 | Arc arcFromId(int) const { return INVALID; } |
---|
[61] | 656 | |
---|
[734] | 657 | /// \brief An upper bound on the node IDs. |
---|
| 658 | /// |
---|
| 659 | /// Returns an upper bound on the node IDs. |
---|
[209] | 660 | int maxNodeId() const { return -1; } |
---|
[61] | 661 | |
---|
[734] | 662 | /// \brief An upper bound on the edge IDs. |
---|
| 663 | /// |
---|
| 664 | /// Returns an upper bound on the edge IDs. |
---|
[209] | 665 | int maxEdgeId() const { return -1; } |
---|
[61] | 666 | |
---|
[734] | 667 | /// \brief An upper bound on the arc IDs. |
---|
| 668 | /// |
---|
| 669 | /// Returns an upper bound on the arc IDs. |
---|
[209] | 670 | int maxArcId() const { return -1; } |
---|
[61] | 671 | |
---|
[734] | 672 | /// \brief The direction of the arc. |
---|
| 673 | /// |
---|
| 674 | /// Returns \c true if the direction of the given arc is the same as |
---|
| 675 | /// the inherent orientation of the represented edge. |
---|
| 676 | bool direction(Arc) const { return true; } |
---|
| 677 | |
---|
| 678 | /// \brief Direct the edge. |
---|
| 679 | /// |
---|
| 680 | /// Direct the given edge. The returned arc |
---|
| 681 | /// represents the given edge and its direction comes |
---|
| 682 | /// from the bool parameter. If it is \c true, then the direction |
---|
| 683 | /// of the arc is the same as the inherent orientation of the edge. |
---|
| 684 | Arc direct(Edge, bool) const { |
---|
| 685 | return INVALID; |
---|
| 686 | } |
---|
| 687 | |
---|
| 688 | /// \brief Direct the edge. |
---|
| 689 | /// |
---|
| 690 | /// Direct the given edge. The returned arc represents the given |
---|
| 691 | /// edge and its source node is the given node. |
---|
| 692 | Arc direct(Edge, Node) const { |
---|
| 693 | return INVALID; |
---|
| 694 | } |
---|
| 695 | |
---|
| 696 | /// \brief The oppositely directed arc. |
---|
| 697 | /// |
---|
| 698 | /// Returns the oppositely directed arc representing the same edge. |
---|
| 699 | Arc oppositeArc(Arc) const { return INVALID; } |
---|
| 700 | |
---|
| 701 | /// \brief The opposite node on the edge. |
---|
| 702 | /// |
---|
| 703 | /// Returns the opposite node on the given edge. |
---|
| 704 | Node oppositeNode(Node, Edge) const { return INVALID; } |
---|
| 705 | |
---|
[57] | 706 | void first(Node&) const {} |
---|
| 707 | void next(Node&) const {} |
---|
| 708 | |
---|
| 709 | void first(Edge&) const {} |
---|
| 710 | void next(Edge&) const {} |
---|
| 711 | |
---|
| 712 | void first(Arc&) const {} |
---|
| 713 | void next(Arc&) const {} |
---|
| 714 | |
---|
| 715 | void firstOut(Arc&, Node) const {} |
---|
| 716 | void nextOut(Arc&) const {} |
---|
| 717 | |
---|
| 718 | void firstIn(Arc&, Node) const {} |
---|
| 719 | void nextIn(Arc&) const {} |
---|
| 720 | |
---|
| 721 | void firstInc(Edge &, bool &, const Node &) const {} |
---|
| 722 | void nextInc(Edge &, bool &) const {} |
---|
| 723 | |
---|
[61] | 724 | // The second parameter is dummy. |
---|
| 725 | Node fromId(int, Node) const { return INVALID; } |
---|
| 726 | // The second parameter is dummy. |
---|
| 727 | Edge fromId(int, Edge) const { return INVALID; } |
---|
| 728 | // The second parameter is dummy. |
---|
| 729 | Arc fromId(int, Arc) const { return INVALID; } |
---|
| 730 | |
---|
| 731 | // Dummy parameter. |
---|
[209] | 732 | int maxId(Node) const { return -1; } |
---|
[61] | 733 | // Dummy parameter. |
---|
[209] | 734 | int maxId(Edge) const { return -1; } |
---|
[61] | 735 | // Dummy parameter. |
---|
[209] | 736 | int maxId(Arc) const { return -1; } |
---|
[61] | 737 | |
---|
[734] | 738 | /// \brief The base node of the iterator. |
---|
[57] | 739 | /// |
---|
[734] | 740 | /// Returns the base node of the given incident edge iterator. |
---|
| 741 | Node baseNode(IncEdgeIt) const { return INVALID; } |
---|
| 742 | |
---|
| 743 | /// \brief The running node of the iterator. |
---|
[57] | 744 | /// |
---|
[734] | 745 | /// Returns the running node of the given incident edge iterator. |
---|
| 746 | Node runningNode(IncEdgeIt) const { return INVALID; } |
---|
[57] | 747 | |
---|
[734] | 748 | /// \brief The base node of the iterator. |
---|
[57] | 749 | /// |
---|
[734] | 750 | /// Returns the base node of the given outgoing arc iterator |
---|
| 751 | /// (i.e. the source node of the corresponding arc). |
---|
| 752 | Node baseNode(OutArcIt) const { return INVALID; } |
---|
| 753 | |
---|
| 754 | /// \brief The running node of the iterator. |
---|
[57] | 755 | /// |
---|
[734] | 756 | /// Returns the running node of the given outgoing arc iterator |
---|
| 757 | /// (i.e. the target node of the corresponding arc). |
---|
| 758 | Node runningNode(OutArcIt) const { return INVALID; } |
---|
[57] | 759 | |
---|
[734] | 760 | /// \brief The base node of the iterator. |
---|
[57] | 761 | /// |
---|
[1049] | 762 | /// Returns the base node of the given incoming arc iterator |
---|
[734] | 763 | /// (i.e. the target node of the corresponding arc). |
---|
| 764 | Node baseNode(InArcIt) const { return INVALID; } |
---|
[209] | 765 | |
---|
[734] | 766 | /// \brief The running node of the iterator. |
---|
[57] | 767 | /// |
---|
[1049] | 768 | /// Returns the running node of the given incoming arc iterator |
---|
[734] | 769 | /// (i.e. the source node of the corresponding arc). |
---|
| 770 | Node runningNode(InArcIt) const { return INVALID; } |
---|
[57] | 771 | |
---|
[125] | 772 | template <typename _Graph> |
---|
[57] | 773 | struct Constraints { |
---|
[209] | 774 | void constraints() { |
---|
[580] | 775 | checkConcept<BaseGraphComponent, _Graph>(); |
---|
[209] | 776 | checkConcept<IterableGraphComponent<>, _Graph>(); |
---|
| 777 | checkConcept<IDableGraphComponent<>, _Graph>(); |
---|
| 778 | checkConcept<MappableGraphComponent<>, _Graph>(); |
---|
| 779 | } |
---|
[57] | 780 | }; |
---|
| 781 | |
---|
| 782 | }; |
---|
| 783 | |
---|
| 784 | } |
---|
| 785 | |
---|
| 786 | } |
---|
| 787 | |
---|
| 788 | #endif |
---|