1.1 --- a/lemon/concepts/graph.h Fri Oct 16 10:21:37 2009 +0200
1.2 +++ b/lemon/concepts/graph.h Thu Nov 05 15:50:01 2009 +0100
1.3 @@ -2,7 +2,7 @@
1.4 *
1.5 * This file is a part of LEMON, a generic C++ optimization library.
1.6 *
1.7 - * Copyright (C) 2003-2008
1.8 + * Copyright (C) 2003-2009
1.9 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
1.10 * (Egervary Research Group on Combinatorial Optimization, EGRES).
1.11 *
1.12 @@ -18,13 +18,14 @@
1.13
1.14 ///\ingroup graph_concepts
1.15 ///\file
1.16 -///\brief The concept of Undirected Graphs.
1.17 +///\brief The concept of undirected graphs.
1.18
1.19 -#ifndef LEMON_CONCEPT_GRAPH_H
1.20 -#define LEMON_CONCEPT_GRAPH_H
1.21 +#ifndef LEMON_CONCEPTS_GRAPH_H
1.22 +#define LEMON_CONCEPTS_GRAPH_H
1.23
1.24 #include <lemon/concepts/graph_components.h>
1.25 -#include <lemon/concepts/graph.h>
1.26 +#include <lemon/concepts/maps.h>
1.27 +#include <lemon/concept_check.h>
1.28 #include <lemon/core.h>
1.29
1.30 namespace lemon {
1.31 @@ -32,63 +33,74 @@
1.32
1.33 /// \ingroup graph_concepts
1.34 ///
1.35 - /// \brief Class describing the concept of Undirected Graphs.
1.36 + /// \brief Class describing the concept of undirected graphs.
1.37 ///
1.38 - /// This class describes the common interface of all Undirected
1.39 - /// Graphs.
1.40 + /// This class describes the common interface of all undirected
1.41 + /// graphs.
1.42 ///
1.43 - /// As all concept describing classes it provides only interface
1.44 - /// without any sensible implementation. So any algorithm for
1.45 - /// undirected graph should compile with this class, but it will not
1.46 + /// Like all concept classes, it only provides an interface
1.47 + /// without any sensible implementation. So any general algorithm for
1.48 + /// undirected graphs should compile with this class, but it will not
1.49 /// run properly, of course.
1.50 + /// An actual graph implementation like \ref ListGraph or
1.51 + /// \ref SmartGraph may have additional functionality.
1.52 ///
1.53 - /// The LEMON undirected graphs also fulfill the concept of
1.54 - /// directed graphs (\ref lemon::concepts::Digraph "Digraph
1.55 - /// Concept"). Each edges can be seen as two opposite
1.56 - /// directed arc and consequently the undirected graph can be
1.57 - /// seen as the direceted graph of these directed arcs. The
1.58 - /// Graph has the Edge inner class for the edges and
1.59 - /// the Arc type for the directed arcs. The Arc type is
1.60 - /// convertible to Edge or inherited from it so from a directed
1.61 - /// arc we can get the represented edge.
1.62 + /// The undirected graphs also fulfill the concept of \ref Digraph
1.63 + /// "directed graphs", since each edge can also be regarded as two
1.64 + /// oppositely directed arcs.
1.65 + /// Undirected graphs provide an Edge type for the undirected edges and
1.66 + /// an Arc type for the directed arcs. The Arc type is convertible to
1.67 + /// Edge or inherited from it, i.e. the corresponding edge can be
1.68 + /// obtained from an arc.
1.69 + /// EdgeIt and EdgeMap classes can be used for the edges, while ArcIt
1.70 + /// and ArcMap classes can be used for the arcs (just like in digraphs).
1.71 + /// Both InArcIt and OutArcIt iterates on the same edges but with
1.72 + /// opposite direction. IncEdgeIt also iterates on the same edges
1.73 + /// as OutArcIt and InArcIt, but it is not convertible to Arc,
1.74 + /// only to Edge.
1.75 ///
1.76 - /// In the sense of the LEMON each edge has a default
1.77 - /// direction (it should be in every computer implementation,
1.78 - /// because the order of edge's nodes defines an
1.79 - /// orientation). With the default orientation we can define that
1.80 - /// the directed arc is forward or backward directed. With the \c
1.81 - /// direction() and \c direct() function we can get the direction
1.82 - /// of the directed arc and we can direct an edge.
1.83 + /// In LEMON, each undirected edge has an inherent orientation.
1.84 + /// Thus it can defined if an arc is forward or backward oriented in
1.85 + /// an undirected graph with respect to this default oriantation of
1.86 + /// the represented edge.
1.87 + /// With the direction() and direct() functions the direction
1.88 + /// of an arc can be obtained and set, respectively.
1.89 ///
1.90 - /// The EdgeIt is an iterator for the edges. We can use
1.91 - /// the EdgeMap to map values for the edges. The InArcIt and
1.92 - /// OutArcIt iterates on the same edges but with opposite
1.93 - /// direction. The IncEdgeIt iterates also on the same edges
1.94 - /// as the OutArcIt and InArcIt but it is not convertible to Arc just
1.95 - /// to Edge.
1.96 + /// Only nodes and edges can be added to or removed from an undirected
1.97 + /// graph and the corresponding arcs are added or removed automatically.
1.98 + ///
1.99 + /// \sa Digraph
1.100 class Graph {
1.101 + private:
1.102 + /// Graphs are \e not copy constructible. Use DigraphCopy instead.
1.103 + Graph(const Graph&) {}
1.104 + /// \brief Assignment of a graph to another one is \e not allowed.
1.105 + /// Use DigraphCopy instead.
1.106 + void operator=(const Graph&) {}
1.107 +
1.108 public:
1.109 - /// \brief The undirected graph should be tagged by the
1.110 - /// UndirectedTag.
1.111 + /// Default constructor.
1.112 + Graph() {}
1.113 +
1.114 + /// \brief Undirected graphs should be tagged with \c UndirectedTag.
1.115 ///
1.116 - /// The undirected graph should be tagged by the UndirectedTag. This
1.117 - /// tag helps the enable_if technics to make compile time
1.118 + /// Undirected graphs should be tagged with \c UndirectedTag.
1.119 + ///
1.120 + /// This tag helps the \c enable_if technics to make compile time
1.121 /// specializations for undirected graphs.
1.122 typedef True UndirectedTag;
1.123
1.124 - /// \brief The base type of node iterators,
1.125 - /// or in other words, the trivial node iterator.
1.126 - ///
1.127 - /// This is the base type of each node iterator,
1.128 - /// thus each kind of node iterator converts to this.
1.129 - /// More precisely each kind of node iterator should be inherited
1.130 - /// from the trivial node iterator.
1.131 + /// The node type of the graph
1.132 +
1.133 + /// This class identifies a node of the graph. It also serves
1.134 + /// as a base class of the node iterators,
1.135 + /// thus they convert to this type.
1.136 class Node {
1.137 public:
1.138 /// Default constructor
1.139
1.140 - /// @warning The default constructor sets the iterator
1.141 - /// to an undefined value.
1.142 + /// Default constructor.
1.143 + /// \warning It sets the object to an undefined value.
1.144 Node() { }
1.145 /// Copy constructor.
1.146
1.147 @@ -96,40 +108,40 @@
1.148 ///
1.149 Node(const Node&) { }
1.150
1.151 - /// Invalid constructor \& conversion.
1.152 + /// %Invalid constructor \& conversion.
1.153
1.154 - /// This constructor initializes the iterator to be invalid.
1.155 + /// Initializes the object to be invalid.
1.156 /// \sa Invalid for more details.
1.157 Node(Invalid) { }
1.158 /// Equality operator
1.159
1.160 + /// Equality operator.
1.161 + ///
1.162 /// Two iterators are equal if and only if they point to the
1.163 - /// same object or both are invalid.
1.164 + /// same object or both are \c INVALID.
1.165 bool operator==(Node) const { return true; }
1.166
1.167 /// Inequality operator
1.168
1.169 - /// \sa operator==(Node n)
1.170 - ///
1.171 + /// Inequality operator.
1.172 bool operator!=(Node) const { return true; }
1.173
1.174 /// Artificial ordering operator.
1.175
1.176 - /// To allow the use of graph descriptors as key type in std::map or
1.177 - /// similar associative container we require this.
1.178 + /// Artificial ordering operator.
1.179 ///
1.180 - /// \note This operator only have to define some strict ordering of
1.181 + /// \note This operator only has to define some strict ordering of
1.182 /// the items; this order has nothing to do with the iteration
1.183 /// ordering of the items.
1.184 bool operator<(Node) const { return false; }
1.185
1.186 };
1.187
1.188 - /// This iterator goes through each node.
1.189 + /// Iterator class for the nodes.
1.190
1.191 - /// This iterator goes through each node.
1.192 + /// This iterator goes through each node of the graph.
1.193 /// Its usage is quite simple, for example you can count the number
1.194 - /// of nodes in graph \c g of type \c Graph like this:
1.195 + /// of nodes in a graph \c g of type \c %Graph like this:
1.196 ///\code
1.197 /// int count=0;
1.198 /// for (Graph::NodeIt n(g); n!=INVALID; ++n) ++count;
1.199 @@ -138,30 +150,28 @@
1.200 public:
1.201 /// Default constructor
1.202
1.203 - /// @warning The default constructor sets the iterator
1.204 - /// to an undefined value.
1.205 + /// Default constructor.
1.206 + /// \warning It sets the iterator to an undefined value.
1.207 NodeIt() { }
1.208 /// Copy constructor.
1.209
1.210 /// Copy constructor.
1.211 ///
1.212 NodeIt(const NodeIt& n) : Node(n) { }
1.213 - /// Invalid constructor \& conversion.
1.214 + /// %Invalid constructor \& conversion.
1.215
1.216 - /// Initialize the iterator to be invalid.
1.217 + /// Initializes the iterator to be invalid.
1.218 /// \sa Invalid for more details.
1.219 NodeIt(Invalid) { }
1.220 /// Sets the iterator to the first node.
1.221
1.222 - /// Sets the iterator to the first node of \c g.
1.223 + /// Sets the iterator to the first node of the given digraph.
1.224 ///
1.225 - NodeIt(const Graph&) { }
1.226 - /// Node -> NodeIt conversion.
1.227 + explicit NodeIt(const Graph&) { }
1.228 + /// Sets the iterator to the given node.
1.229
1.230 - /// Sets the iterator to the node of \c the graph pointed by
1.231 - /// the trivial iterator.
1.232 - /// This feature necessitates that each time we
1.233 - /// iterate the arc-set, the iteration order is the same.
1.234 + /// Sets the iterator to the given node of the given digraph.
1.235 + ///
1.236 NodeIt(const Graph&, const Node&) { }
1.237 /// Next node.
1.238
1.239 @@ -171,54 +181,55 @@
1.240 };
1.241
1.242
1.243 - /// The base type of the edge iterators.
1.244 + /// The edge type of the graph
1.245
1.246 - /// The base type of the edge iterators.
1.247 - ///
1.248 + /// This class identifies an edge of the graph. It also serves
1.249 + /// as a base class of the edge iterators,
1.250 + /// thus they will convert to this type.
1.251 class Edge {
1.252 public:
1.253 /// Default constructor
1.254
1.255 - /// @warning The default constructor sets the iterator
1.256 - /// to an undefined value.
1.257 + /// Default constructor.
1.258 + /// \warning It sets the object to an undefined value.
1.259 Edge() { }
1.260 /// Copy constructor.
1.261
1.262 /// Copy constructor.
1.263 ///
1.264 Edge(const Edge&) { }
1.265 - /// Initialize the iterator to be invalid.
1.266 + /// %Invalid constructor \& conversion.
1.267
1.268 - /// Initialize the iterator to be invalid.
1.269 - ///
1.270 + /// Initializes the object to be invalid.
1.271 + /// \sa Invalid for more details.
1.272 Edge(Invalid) { }
1.273 /// Equality operator
1.274
1.275 + /// Equality operator.
1.276 + ///
1.277 /// Two iterators are equal if and only if they point to the
1.278 - /// same object or both are invalid.
1.279 + /// same object or both are \c INVALID.
1.280 bool operator==(Edge) const { return true; }
1.281 /// Inequality operator
1.282
1.283 - /// \sa operator==(Edge n)
1.284 - ///
1.285 + /// Inequality operator.
1.286 bool operator!=(Edge) const { return true; }
1.287
1.288 /// Artificial ordering operator.
1.289
1.290 - /// To allow the use of graph descriptors as key type in std::map or
1.291 - /// similar associative container we require this.
1.292 + /// Artificial ordering operator.
1.293 ///
1.294 - /// \note This operator only have to define some strict ordering of
1.295 - /// the items; this order has nothing to do with the iteration
1.296 - /// ordering of the items.
1.297 + /// \note This operator only has to define some strict ordering of
1.298 + /// the edges; this order has nothing to do with the iteration
1.299 + /// ordering of the edges.
1.300 bool operator<(Edge) const { return false; }
1.301 };
1.302
1.303 - /// This iterator goes through each edge.
1.304 + /// Iterator class for the edges.
1.305
1.306 - /// This iterator goes through each edge of a graph.
1.307 + /// This iterator goes through each edge of the graph.
1.308 /// Its usage is quite simple, for example you can count the number
1.309 - /// of edges in a graph \c g of type \c Graph as follows:
1.310 + /// of edges in a graph \c g of type \c %Graph as follows:
1.311 ///\code
1.312 /// int count=0;
1.313 /// for(Graph::EdgeIt e(g); e!=INVALID; ++e) ++count;
1.314 @@ -227,294 +238,291 @@
1.315 public:
1.316 /// Default constructor
1.317
1.318 - /// @warning The default constructor sets the iterator
1.319 - /// to an undefined value.
1.320 + /// Default constructor.
1.321 + /// \warning It sets the iterator to an undefined value.
1.322 EdgeIt() { }
1.323 /// Copy constructor.
1.324
1.325 /// Copy constructor.
1.326 ///
1.327 EdgeIt(const EdgeIt& e) : Edge(e) { }
1.328 - /// Initialize the iterator to be invalid.
1.329 + /// %Invalid constructor \& conversion.
1.330
1.331 - /// Initialize the iterator to be invalid.
1.332 + /// Initializes the iterator to be invalid.
1.333 + /// \sa Invalid for more details.
1.334 + EdgeIt(Invalid) { }
1.335 + /// Sets the iterator to the first edge.
1.336 +
1.337 + /// Sets the iterator to the first edge of the given graph.
1.338 ///
1.339 - EdgeIt(Invalid) { }
1.340 - /// This constructor sets the iterator to the first edge.
1.341 + explicit EdgeIt(const Graph&) { }
1.342 + /// Sets the iterator to the given edge.
1.343
1.344 - /// This constructor sets the iterator to the first edge.
1.345 - EdgeIt(const Graph&) { }
1.346 - /// Edge -> EdgeIt conversion
1.347 -
1.348 - /// Sets the iterator to the value of the trivial iterator.
1.349 - /// This feature necessitates that each time we
1.350 - /// iterate the edge-set, the iteration order is the
1.351 - /// same.
1.352 + /// Sets the iterator to the given edge of the given graph.
1.353 + ///
1.354 EdgeIt(const Graph&, const Edge&) { }
1.355 /// Next edge
1.356
1.357 /// Assign the iterator to the next edge.
1.358 + ///
1.359 EdgeIt& operator++() { return *this; }
1.360 };
1.361
1.362 - /// \brief This iterator goes trough the incident undirected
1.363 - /// arcs of a node.
1.364 - ///
1.365 - /// This iterator goes trough the incident edges
1.366 - /// of a certain node of a graph. You should assume that the
1.367 - /// loop arcs will be iterated twice.
1.368 - ///
1.369 + /// Iterator class for the incident edges of a node.
1.370 +
1.371 + /// This iterator goes trough the incident undirected edges
1.372 + /// of a certain node of a graph.
1.373 /// Its usage is quite simple, for example you can compute the
1.374 - /// degree (i.e. count the number of incident arcs of a node \c n
1.375 - /// in graph \c g of type \c Graph as follows.
1.376 + /// degree (i.e. the number of incident edges) of a node \c n
1.377 + /// in a graph \c g of type \c %Graph as follows.
1.378 ///
1.379 ///\code
1.380 /// int count=0;
1.381 /// for(Graph::IncEdgeIt e(g, n); e!=INVALID; ++e) ++count;
1.382 ///\endcode
1.383 + ///
1.384 + /// \warning Loop edges will be iterated twice.
1.385 class IncEdgeIt : public Edge {
1.386 public:
1.387 /// Default constructor
1.388
1.389 - /// @warning The default constructor sets the iterator
1.390 - /// to an undefined value.
1.391 + /// Default constructor.
1.392 + /// \warning It sets the iterator to an undefined value.
1.393 IncEdgeIt() { }
1.394 /// Copy constructor.
1.395
1.396 /// Copy constructor.
1.397 ///
1.398 IncEdgeIt(const IncEdgeIt& e) : Edge(e) { }
1.399 - /// Initialize the iterator to be invalid.
1.400 + /// %Invalid constructor \& conversion.
1.401
1.402 - /// Initialize the iterator to be invalid.
1.403 + /// Initializes the iterator to be invalid.
1.404 + /// \sa Invalid for more details.
1.405 + IncEdgeIt(Invalid) { }
1.406 + /// Sets the iterator to the first incident edge.
1.407 +
1.408 + /// Sets the iterator to the first incident edge of the given node.
1.409 ///
1.410 - IncEdgeIt(Invalid) { }
1.411 - /// This constructor sets the iterator to first incident arc.
1.412 + IncEdgeIt(const Graph&, const Node&) { }
1.413 + /// Sets the iterator to the given edge.
1.414
1.415 - /// This constructor set the iterator to the first incident arc of
1.416 - /// the node.
1.417 - IncEdgeIt(const Graph&, const Node&) { }
1.418 - /// Edge -> IncEdgeIt conversion
1.419 + /// Sets the iterator to the given edge of the given graph.
1.420 + ///
1.421 + IncEdgeIt(const Graph&, const Edge&) { }
1.422 + /// Next incident edge
1.423
1.424 - /// Sets the iterator to the value of the trivial iterator \c e.
1.425 - /// This feature necessitates that each time we
1.426 - /// iterate the arc-set, the iteration order is the same.
1.427 - IncEdgeIt(const Graph&, const Edge&) { }
1.428 - /// Next incident arc
1.429 -
1.430 - /// Assign the iterator to the next incident arc
1.431 + /// Assign the iterator to the next incident edge
1.432 /// of the corresponding node.
1.433 IncEdgeIt& operator++() { return *this; }
1.434 };
1.435
1.436 - /// The directed arc type.
1.437 + /// The arc type of the graph
1.438
1.439 - /// The directed arc type. It can be converted to the
1.440 - /// edge or it should be inherited from the undirected
1.441 - /// arc.
1.442 - class Arc : public Edge {
1.443 + /// This class identifies a directed arc of the graph. It also serves
1.444 + /// as a base class of the arc iterators,
1.445 + /// thus they will convert to this type.
1.446 + class Arc {
1.447 public:
1.448 /// Default constructor
1.449
1.450 - /// @warning The default constructor sets the iterator
1.451 - /// to an undefined value.
1.452 + /// Default constructor.
1.453 + /// \warning It sets the object to an undefined value.
1.454 Arc() { }
1.455 /// Copy constructor.
1.456
1.457 /// Copy constructor.
1.458 ///
1.459 - Arc(const Arc& e) : Edge(e) { }
1.460 - /// Initialize the iterator to be invalid.
1.461 + Arc(const Arc&) { }
1.462 + /// %Invalid constructor \& conversion.
1.463
1.464 - /// Initialize the iterator to be invalid.
1.465 - ///
1.466 + /// Initializes the object to be invalid.
1.467 + /// \sa Invalid for more details.
1.468 Arc(Invalid) { }
1.469 /// Equality operator
1.470
1.471 + /// Equality operator.
1.472 + ///
1.473 /// Two iterators are equal if and only if they point to the
1.474 - /// same object or both are invalid.
1.475 + /// same object or both are \c INVALID.
1.476 bool operator==(Arc) const { return true; }
1.477 /// Inequality operator
1.478
1.479 - /// \sa operator==(Arc n)
1.480 - ///
1.481 + /// Inequality operator.
1.482 bool operator!=(Arc) const { return true; }
1.483
1.484 /// Artificial ordering operator.
1.485
1.486 - /// To allow the use of graph descriptors as key type in std::map or
1.487 - /// similar associative container we require this.
1.488 + /// Artificial ordering operator.
1.489 ///
1.490 - /// \note This operator only have to define some strict ordering of
1.491 - /// the items; this order has nothing to do with the iteration
1.492 - /// ordering of the items.
1.493 + /// \note This operator only has to define some strict ordering of
1.494 + /// the arcs; this order has nothing to do with the iteration
1.495 + /// ordering of the arcs.
1.496 bool operator<(Arc) const { return false; }
1.497
1.498 + /// Converison to \c Edge
1.499 +
1.500 + /// Converison to \c Edge.
1.501 + ///
1.502 + operator Edge() const { return Edge(); }
1.503 };
1.504 - /// This iterator goes through each directed arc.
1.505
1.506 - /// This iterator goes through each arc of a graph.
1.507 + /// Iterator class for the arcs.
1.508 +
1.509 + /// This iterator goes through each directed arc of the graph.
1.510 /// Its usage is quite simple, for example you can count the number
1.511 - /// of arcs in a graph \c g of type \c Graph as follows:
1.512 + /// of arcs in a graph \c g of type \c %Graph as follows:
1.513 ///\code
1.514 /// int count=0;
1.515 - /// for(Graph::ArcIt e(g); e!=INVALID; ++e) ++count;
1.516 + /// for(Graph::ArcIt a(g); a!=INVALID; ++a) ++count;
1.517 ///\endcode
1.518 class ArcIt : public Arc {
1.519 public:
1.520 /// Default constructor
1.521
1.522 - /// @warning The default constructor sets the iterator
1.523 - /// to an undefined value.
1.524 + /// Default constructor.
1.525 + /// \warning It sets the iterator to an undefined value.
1.526 ArcIt() { }
1.527 /// Copy constructor.
1.528
1.529 /// Copy constructor.
1.530 ///
1.531 ArcIt(const ArcIt& e) : Arc(e) { }
1.532 - /// Initialize the iterator to be invalid.
1.533 + /// %Invalid constructor \& conversion.
1.534
1.535 - /// Initialize the iterator to be invalid.
1.536 + /// Initializes the iterator to be invalid.
1.537 + /// \sa Invalid for more details.
1.538 + ArcIt(Invalid) { }
1.539 + /// Sets the iterator to the first arc.
1.540 +
1.541 + /// Sets the iterator to the first arc of the given graph.
1.542 ///
1.543 - ArcIt(Invalid) { }
1.544 - /// This constructor sets the iterator to the first arc.
1.545 + explicit ArcIt(const Graph &g) { ignore_unused_variable_warning(g); }
1.546 + /// Sets the iterator to the given arc.
1.547
1.548 - /// This constructor sets the iterator to the first arc of \c g.
1.549 - ///@param g the graph
1.550 - ArcIt(const Graph &g) { ignore_unused_variable_warning(g); }
1.551 - /// Arc -> ArcIt conversion
1.552 -
1.553 - /// Sets the iterator to the value of the trivial iterator \c e.
1.554 - /// This feature necessitates that each time we
1.555 - /// iterate the arc-set, the iteration order is the same.
1.556 + /// Sets the iterator to the given arc of the given graph.
1.557 + ///
1.558 ArcIt(const Graph&, const Arc&) { }
1.559 - ///Next arc
1.560 + /// Next arc
1.561
1.562 /// Assign the iterator to the next arc.
1.563 + ///
1.564 ArcIt& operator++() { return *this; }
1.565 };
1.566
1.567 - /// This iterator goes trough the outgoing directed arcs of a node.
1.568 + /// Iterator class for the outgoing arcs of a node.
1.569
1.570 - /// This iterator goes trough the \e outgoing arcs of a certain node
1.571 - /// of a graph.
1.572 + /// This iterator goes trough the \e outgoing directed arcs of a
1.573 + /// certain node of a graph.
1.574 /// Its usage is quite simple, for example you can count the number
1.575 /// of outgoing arcs of a node \c n
1.576 - /// in graph \c g of type \c Graph as follows.
1.577 + /// in a graph \c g of type \c %Graph as follows.
1.578 ///\code
1.579 /// int count=0;
1.580 - /// for (Graph::OutArcIt e(g, n); e!=INVALID; ++e) ++count;
1.581 + /// for (Digraph::OutArcIt a(g, n); a!=INVALID; ++a) ++count;
1.582 ///\endcode
1.583 -
1.584 class OutArcIt : public Arc {
1.585 public:
1.586 /// Default constructor
1.587
1.588 - /// @warning The default constructor sets the iterator
1.589 - /// to an undefined value.
1.590 + /// Default constructor.
1.591 + /// \warning It sets the iterator to an undefined value.
1.592 OutArcIt() { }
1.593 /// Copy constructor.
1.594
1.595 /// Copy constructor.
1.596 ///
1.597 OutArcIt(const OutArcIt& e) : Arc(e) { }
1.598 - /// Initialize the iterator to be invalid.
1.599 + /// %Invalid constructor \& conversion.
1.600
1.601 - /// Initialize the iterator to be invalid.
1.602 + /// Initializes the iterator to be invalid.
1.603 + /// \sa Invalid for more details.
1.604 + OutArcIt(Invalid) { }
1.605 + /// Sets the iterator to the first outgoing arc.
1.606 +
1.607 + /// Sets the iterator to the first outgoing arc of the given node.
1.608 ///
1.609 - OutArcIt(Invalid) { }
1.610 - /// This constructor sets the iterator to the first outgoing arc.
1.611 -
1.612 - /// This constructor sets the iterator to the first outgoing arc of
1.613 - /// the node.
1.614 - ///@param n the node
1.615 - ///@param g the graph
1.616 OutArcIt(const Graph& n, const Node& g) {
1.617 ignore_unused_variable_warning(n);
1.618 ignore_unused_variable_warning(g);
1.619 }
1.620 - /// Arc -> OutArcIt conversion
1.621 + /// Sets the iterator to the given arc.
1.622
1.623 - /// Sets the iterator to the value of the trivial iterator.
1.624 - /// This feature necessitates that each time we
1.625 - /// iterate the arc-set, the iteration order is the same.
1.626 + /// Sets the iterator to the given arc of the given graph.
1.627 + ///
1.628 OutArcIt(const Graph&, const Arc&) { }
1.629 - ///Next outgoing arc
1.630 + /// Next outgoing arc
1.631
1.632 /// Assign the iterator to the next
1.633 /// outgoing arc of the corresponding node.
1.634 OutArcIt& operator++() { return *this; }
1.635 };
1.636
1.637 - /// This iterator goes trough the incoming directed arcs of a node.
1.638 + /// Iterator class for the incoming arcs of a node.
1.639
1.640 - /// This iterator goes trough the \e incoming arcs of a certain node
1.641 - /// of a graph.
1.642 + /// This iterator goes trough the \e incoming directed arcs of a
1.643 + /// certain node of a graph.
1.644 /// Its usage is quite simple, for example you can count the number
1.645 - /// of outgoing arcs of a node \c n
1.646 - /// in graph \c g of type \c Graph as follows.
1.647 + /// of incoming arcs of a node \c n
1.648 + /// in a graph \c g of type \c %Graph as follows.
1.649 ///\code
1.650 /// int count=0;
1.651 - /// for(Graph::InArcIt e(g, n); e!=INVALID; ++e) ++count;
1.652 + /// for (Digraph::InArcIt a(g, n); a!=INVALID; ++a) ++count;
1.653 ///\endcode
1.654 -
1.655 class InArcIt : public Arc {
1.656 public:
1.657 /// Default constructor
1.658
1.659 - /// @warning The default constructor sets the iterator
1.660 - /// to an undefined value.
1.661 + /// Default constructor.
1.662 + /// \warning It sets the iterator to an undefined value.
1.663 InArcIt() { }
1.664 /// Copy constructor.
1.665
1.666 /// Copy constructor.
1.667 ///
1.668 InArcIt(const InArcIt& e) : Arc(e) { }
1.669 - /// Initialize the iterator to be invalid.
1.670 + /// %Invalid constructor \& conversion.
1.671
1.672 - /// Initialize the iterator to be invalid.
1.673 + /// Initializes the iterator to be invalid.
1.674 + /// \sa Invalid for more details.
1.675 + InArcIt(Invalid) { }
1.676 + /// Sets the iterator to the first incoming arc.
1.677 +
1.678 + /// Sets the iterator to the first incoming arc of the given node.
1.679 ///
1.680 - InArcIt(Invalid) { }
1.681 - /// This constructor sets the iterator to first incoming arc.
1.682 -
1.683 - /// This constructor set the iterator to the first incoming arc of
1.684 - /// the node.
1.685 - ///@param n the node
1.686 - ///@param g the graph
1.687 InArcIt(const Graph& g, const Node& n) {
1.688 ignore_unused_variable_warning(n);
1.689 ignore_unused_variable_warning(g);
1.690 }
1.691 - /// Arc -> InArcIt conversion
1.692 + /// Sets the iterator to the given arc.
1.693
1.694 - /// Sets the iterator to the value of the trivial iterator \c e.
1.695 - /// This feature necessitates that each time we
1.696 - /// iterate the arc-set, the iteration order is the same.
1.697 + /// Sets the iterator to the given arc of the given graph.
1.698 + ///
1.699 InArcIt(const Graph&, const Arc&) { }
1.700 /// Next incoming arc
1.701
1.702 - /// Assign the iterator to the next inarc of the corresponding node.
1.703 - ///
1.704 + /// Assign the iterator to the next
1.705 + /// incoming arc of the corresponding node.
1.706 InArcIt& operator++() { return *this; }
1.707 };
1.708
1.709 - /// \brief Read write map of the nodes to type \c T.
1.710 + /// \brief Standard graph map type for the nodes.
1.711 ///
1.712 - /// ReadWrite map of the nodes to type \c T.
1.713 - /// \sa Reference
1.714 + /// Standard graph map type for the nodes.
1.715 + /// It conforms to the ReferenceMap concept.
1.716 template<class T>
1.717 - class NodeMap : public ReadWriteMap< Node, T >
1.718 + class NodeMap : public ReferenceMap<Node, T, T&, const T&>
1.719 {
1.720 public:
1.721
1.722 - ///\e
1.723 - NodeMap(const Graph&) { }
1.724 - ///\e
1.725 + /// Constructor
1.726 + explicit NodeMap(const Graph&) { }
1.727 + /// Constructor with given initial value
1.728 NodeMap(const Graph&, T) { }
1.729
1.730 private:
1.731 ///Copy constructor
1.732 - NodeMap(const NodeMap& nm) : ReadWriteMap< Node, T >(nm) { }
1.733 + NodeMap(const NodeMap& nm) :
1.734 + ReferenceMap<Node, T, T&, const T&>(nm) { }
1.735 ///Assignment operator
1.736 template <typename CMap>
1.737 NodeMap& operator=(const CMap&) {
1.738 @@ -523,22 +531,24 @@
1.739 }
1.740 };
1.741
1.742 - /// \brief Read write map of the directed arcs to type \c T.
1.743 + /// \brief Standard graph map type for the arcs.
1.744 ///
1.745 - /// Reference map of the directed arcs to type \c T.
1.746 - /// \sa Reference
1.747 + /// Standard graph map type for the arcs.
1.748 + /// It conforms to the ReferenceMap concept.
1.749 template<class T>
1.750 - class ArcMap : public ReadWriteMap<Arc,T>
1.751 + class ArcMap : public ReferenceMap<Arc, T, T&, const T&>
1.752 {
1.753 public:
1.754
1.755 - ///\e
1.756 - ArcMap(const Graph&) { }
1.757 - ///\e
1.758 + /// Constructor
1.759 + explicit ArcMap(const Graph&) { }
1.760 + /// Constructor with given initial value
1.761 ArcMap(const Graph&, T) { }
1.762 +
1.763 private:
1.764 ///Copy constructor
1.765 - ArcMap(const ArcMap& em) : ReadWriteMap<Arc,T>(em) { }
1.766 + ArcMap(const ArcMap& em) :
1.767 + ReferenceMap<Arc, T, T&, const T&>(em) { }
1.768 ///Assignment operator
1.769 template <typename CMap>
1.770 ArcMap& operator=(const CMap&) {
1.771 @@ -547,22 +557,24 @@
1.772 }
1.773 };
1.774
1.775 - /// Read write map of the edges to type \c T.
1.776 -
1.777 - /// Reference map of the arcs to type \c T.
1.778 - /// \sa Reference
1.779 + /// \brief Standard graph map type for the edges.
1.780 + ///
1.781 + /// Standard graph map type for the edges.
1.782 + /// It conforms to the ReferenceMap concept.
1.783 template<class T>
1.784 - class EdgeMap : public ReadWriteMap<Edge,T>
1.785 + class EdgeMap : public ReferenceMap<Edge, T, T&, const T&>
1.786 {
1.787 public:
1.788
1.789 - ///\e
1.790 - EdgeMap(const Graph&) { }
1.791 - ///\e
1.792 + /// Constructor
1.793 + explicit EdgeMap(const Graph&) { }
1.794 + /// Constructor with given initial value
1.795 EdgeMap(const Graph&, T) { }
1.796 +
1.797 private:
1.798 ///Copy constructor
1.799 - EdgeMap(const EdgeMap& em) : ReadWriteMap<Edge,T>(em) {}
1.800 + EdgeMap(const EdgeMap& em) :
1.801 + ReferenceMap<Edge, T, T&, const T&>(em) {}
1.802 ///Assignment operator
1.803 template <typename CMap>
1.804 EdgeMap& operator=(const CMap&) {
1.805 @@ -571,95 +583,124 @@
1.806 }
1.807 };
1.808
1.809 - /// \brief Direct the given edge.
1.810 + /// \brief The first node of the edge.
1.811 ///
1.812 - /// Direct the given edge. The returned arc source
1.813 - /// will be the given node.
1.814 - Arc direct(const Edge&, const Node&) const {
1.815 + /// Returns the first node of the given edge.
1.816 + ///
1.817 + /// Edges don't have source and target nodes, however methods
1.818 + /// u() and v() are used to query the two end-nodes of an edge.
1.819 + /// The orientation of an edge that arises this way is called
1.820 + /// the inherent direction, it is used to define the default
1.821 + /// direction for the corresponding arcs.
1.822 + /// \sa v()
1.823 + /// \sa direction()
1.824 + Node u(Edge) const { return INVALID; }
1.825 +
1.826 + /// \brief The second node of the edge.
1.827 + ///
1.828 + /// Returns the second node of the given edge.
1.829 + ///
1.830 + /// Edges don't have source and target nodes, however methods
1.831 + /// u() and v() are used to query the two end-nodes of an edge.
1.832 + /// The orientation of an edge that arises this way is called
1.833 + /// the inherent direction, it is used to define the default
1.834 + /// direction for the corresponding arcs.
1.835 + /// \sa u()
1.836 + /// \sa direction()
1.837 + Node v(Edge) const { return INVALID; }
1.838 +
1.839 + /// \brief The source node of the arc.
1.840 + ///
1.841 + /// Returns the source node of the given arc.
1.842 + Node source(Arc) const { return INVALID; }
1.843 +
1.844 + /// \brief The target node of the arc.
1.845 + ///
1.846 + /// Returns the target node of the given arc.
1.847 + Node target(Arc) const { return INVALID; }
1.848 +
1.849 + /// \brief The ID of the node.
1.850 + ///
1.851 + /// Returns the ID of the given node.
1.852 + int id(Node) const { return -1; }
1.853 +
1.854 + /// \brief The ID of the edge.
1.855 + ///
1.856 + /// Returns the ID of the given edge.
1.857 + int id(Edge) const { return -1; }
1.858 +
1.859 + /// \brief The ID of the arc.
1.860 + ///
1.861 + /// Returns the ID of the given arc.
1.862 + int id(Arc) const { return -1; }
1.863 +
1.864 + /// \brief The node with the given ID.
1.865 + ///
1.866 + /// Returns the node with the given ID.
1.867 + /// \pre The argument should be a valid node ID in the graph.
1.868 + Node nodeFromId(int) const { return INVALID; }
1.869 +
1.870 + /// \brief The edge with the given ID.
1.871 + ///
1.872 + /// Returns the edge with the given ID.
1.873 + /// \pre The argument should be a valid edge ID in the graph.
1.874 + Edge edgeFromId(int) const { return INVALID; }
1.875 +
1.876 + /// \brief The arc with the given ID.
1.877 + ///
1.878 + /// Returns the arc with the given ID.
1.879 + /// \pre The argument should be a valid arc ID in the graph.
1.880 + Arc arcFromId(int) const { return INVALID; }
1.881 +
1.882 + /// \brief An upper bound on the node IDs.
1.883 + ///
1.884 + /// Returns an upper bound on the node IDs.
1.885 + int maxNodeId() const { return -1; }
1.886 +
1.887 + /// \brief An upper bound on the edge IDs.
1.888 + ///
1.889 + /// Returns an upper bound on the edge IDs.
1.890 + int maxEdgeId() const { return -1; }
1.891 +
1.892 + /// \brief An upper bound on the arc IDs.
1.893 + ///
1.894 + /// Returns an upper bound on the arc IDs.
1.895 + int maxArcId() const { return -1; }
1.896 +
1.897 + /// \brief The direction of the arc.
1.898 + ///
1.899 + /// Returns \c true if the direction of the given arc is the same as
1.900 + /// the inherent orientation of the represented edge.
1.901 + bool direction(Arc) const { return true; }
1.902 +
1.903 + /// \brief Direct the edge.
1.904 + ///
1.905 + /// Direct the given edge. The returned arc
1.906 + /// represents the given edge and its direction comes
1.907 + /// from the bool parameter. If it is \c true, then the direction
1.908 + /// of the arc is the same as the inherent orientation of the edge.
1.909 + Arc direct(Edge, bool) const {
1.910 return INVALID;
1.911 }
1.912
1.913 - /// \brief Direct the given edge.
1.914 + /// \brief Direct the edge.
1.915 ///
1.916 - /// Direct the given edge. The returned arc
1.917 - /// represents the given edge and the direction comes
1.918 - /// from the bool parameter. The source of the edge and
1.919 - /// the directed arc is the same when the given bool is true.
1.920 - Arc direct(const Edge&, bool) const {
1.921 + /// Direct the given edge. The returned arc represents the given
1.922 + /// edge and its source node is the given node.
1.923 + Arc direct(Edge, Node) const {
1.924 return INVALID;
1.925 }
1.926
1.927 - /// \brief Returns true if the arc has default orientation.
1.928 + /// \brief The oppositely directed arc.
1.929 ///
1.930 - /// Returns whether the given directed arc is same orientation as
1.931 - /// the corresponding edge's default orientation.
1.932 - bool direction(Arc) const { return true; }
1.933 -
1.934 - /// \brief Returns the opposite directed arc.
1.935 - ///
1.936 - /// Returns the opposite directed arc.
1.937 + /// Returns the oppositely directed arc representing the same edge.
1.938 Arc oppositeArc(Arc) const { return INVALID; }
1.939
1.940 - /// \brief Opposite node on an arc
1.941 + /// \brief The opposite node on the edge.
1.942 ///
1.943 - /// \return the opposite of the given Node on the given Edge
1.944 + /// Returns the opposite node on the given edge.
1.945 Node oppositeNode(Node, Edge) const { return INVALID; }
1.946
1.947 - /// \brief First node of the edge.
1.948 - ///
1.949 - /// \return the first node of the given Edge.
1.950 - ///
1.951 - /// Naturally edges don't have direction and thus
1.952 - /// don't have source and target node. But we use these two methods
1.953 - /// to query the two nodes of the arc. The direction of the arc
1.954 - /// which arises this way is called the inherent direction of the
1.955 - /// edge, and is used to define the "default" direction
1.956 - /// of the directed versions of the arcs.
1.957 - /// \sa direction
1.958 - Node u(Edge) const { return INVALID; }
1.959 -
1.960 - /// \brief Second node of the edge.
1.961 - Node v(Edge) const { return INVALID; }
1.962 -
1.963 - /// \brief Source node of the directed arc.
1.964 - Node source(Arc) const { return INVALID; }
1.965 -
1.966 - /// \brief Target node of the directed arc.
1.967 - Node target(Arc) const { return INVALID; }
1.968 -
1.969 - /// \brief Returns the id of the node.
1.970 - int id(Node) const { return -1; }
1.971 -
1.972 - /// \brief Returns the id of the edge.
1.973 - int id(Edge) const { return -1; }
1.974 -
1.975 - /// \brief Returns the id of the arc.
1.976 - int id(Arc) const { return -1; }
1.977 -
1.978 - /// \brief Returns the node with the given id.
1.979 - ///
1.980 - /// \pre The argument should be a valid node id in the graph.
1.981 - Node nodeFromId(int) const { return INVALID; }
1.982 -
1.983 - /// \brief Returns the edge with the given id.
1.984 - ///
1.985 - /// \pre The argument should be a valid edge id in the graph.
1.986 - Edge edgeFromId(int) const { return INVALID; }
1.987 -
1.988 - /// \brief Returns the arc with the given id.
1.989 - ///
1.990 - /// \pre The argument should be a valid arc id in the graph.
1.991 - Arc arcFromId(int) const { return INVALID; }
1.992 -
1.993 - /// \brief Returns an upper bound on the node IDs.
1.994 - int maxNodeId() const { return -1; }
1.995 -
1.996 - /// \brief Returns an upper bound on the edge IDs.
1.997 - int maxEdgeId() const { return -1; }
1.998 -
1.999 - /// \brief Returns an upper bound on the arc IDs.
1.1000 - int maxArcId() const { return -1; }
1.1001 -
1.1002 void first(Node&) const {}
1.1003 void next(Node&) const {}
1.1004
1.1005 @@ -692,51 +733,44 @@
1.1006 // Dummy parameter.
1.1007 int maxId(Arc) const { return -1; }
1.1008
1.1009 - /// \brief Base node of the iterator
1.1010 + /// \brief The base node of the iterator.
1.1011 ///
1.1012 - /// Returns the base node (the source in this case) of the iterator
1.1013 - Node baseNode(OutArcIt e) const {
1.1014 - return source(e);
1.1015 - }
1.1016 - /// \brief Running node of the iterator
1.1017 + /// Returns the base node of the given incident edge iterator.
1.1018 + Node baseNode(IncEdgeIt) const { return INVALID; }
1.1019 +
1.1020 + /// \brief The running node of the iterator.
1.1021 ///
1.1022 - /// Returns the running node (the target in this case) of the
1.1023 - /// iterator
1.1024 - Node runningNode(OutArcIt e) const {
1.1025 - return target(e);
1.1026 - }
1.1027 + /// Returns the running node of the given incident edge iterator.
1.1028 + Node runningNode(IncEdgeIt) const { return INVALID; }
1.1029
1.1030 - /// \brief Base node of the iterator
1.1031 + /// \brief The base node of the iterator.
1.1032 ///
1.1033 - /// Returns the base node (the target in this case) of the iterator
1.1034 - Node baseNode(InArcIt e) const {
1.1035 - return target(e);
1.1036 - }
1.1037 - /// \brief Running node of the iterator
1.1038 + /// Returns the base node of the given outgoing arc iterator
1.1039 + /// (i.e. the source node of the corresponding arc).
1.1040 + Node baseNode(OutArcIt) const { return INVALID; }
1.1041 +
1.1042 + /// \brief The running node of the iterator.
1.1043 ///
1.1044 - /// Returns the running node (the source in this case) of the
1.1045 - /// iterator
1.1046 - Node runningNode(InArcIt e) const {
1.1047 - return source(e);
1.1048 - }
1.1049 + /// Returns the running node of the given outgoing arc iterator
1.1050 + /// (i.e. the target node of the corresponding arc).
1.1051 + Node runningNode(OutArcIt) const { return INVALID; }
1.1052
1.1053 - /// \brief Base node of the iterator
1.1054 + /// \brief The base node of the iterator.
1.1055 ///
1.1056 - /// Returns the base node of the iterator
1.1057 - Node baseNode(IncEdgeIt) const {
1.1058 - return INVALID;
1.1059 - }
1.1060 + /// Returns the base node of the given incomming arc iterator
1.1061 + /// (i.e. the target node of the corresponding arc).
1.1062 + Node baseNode(InArcIt) const { return INVALID; }
1.1063
1.1064 - /// \brief Running node of the iterator
1.1065 + /// \brief The running node of the iterator.
1.1066 ///
1.1067 - /// Returns the running node of the iterator
1.1068 - Node runningNode(IncEdgeIt) const {
1.1069 - return INVALID;
1.1070 - }
1.1071 + /// Returns the running node of the given incomming arc iterator
1.1072 + /// (i.e. the source node of the corresponding arc).
1.1073 + Node runningNode(InArcIt) const { return INVALID; }
1.1074
1.1075 template <typename _Graph>
1.1076 struct Constraints {
1.1077 void constraints() {
1.1078 + checkConcept<BaseGraphComponent, _Graph>();
1.1079 checkConcept<IterableGraphComponent<>, _Graph>();
1.1080 checkConcept<IDableGraphComponent<>, _Graph>();
1.1081 checkConcept<MappableGraphComponent<>, _Graph>();