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