Missing header file added.
3 * This file is a part of LEMON, a generic C++ optimization library
5 * Copyright (C) 2003-2007
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
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.
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
19 ///\ingroup graph_concepts
21 ///\brief The concept of Undirected Graphs.
23 #ifndef LEMON_CONCEPT_UGRAPH_H
24 #define LEMON_CONCEPT_UGRAPH_H
26 #include <lemon/concepts/graph_components.h>
27 #include <lemon/concepts/graph.h>
28 #include <lemon/bits/utility.h>
33 /// \addtogroup graph_concepts
36 /// \brief Class describing the concept of Undirected Graphs.
38 /// This class describes the common interface of all Undirected
41 /// As all concept describing classes it provides only interface
42 /// without any sensible implementation. So any algorithm for
43 /// undirected graph should compile with this class, but it will not
44 /// run properly, of course.
46 /// The LEMON undirected graphs also fulfill the concept of
47 /// directed graphs (\ref lemon::concepts::Graph "Graph
48 /// Concept"). Each undirected edges can be seen as two opposite
49 /// directed edge and consequently the undirected graph can be
50 /// seen as the direceted graph of these directed edges. The
51 /// UGraph has the UEdge inner class for the undirected edges and
52 /// the Edge type for the directed edges. The Edge type is
53 /// convertible to UEdge or inherited from it so from a directed
54 /// edge we can get the represented undirected edge.
56 /// In the sense of the LEMON each undirected edge has a default
57 /// direction (it should be in every computer implementation,
58 /// because the order of undirected edge's nodes defines an
59 /// orientation). With the default orientation we can define that
60 /// the directed edge is forward or backward directed. With the \c
61 /// direction() and \c direct() function we can get the direction
62 /// of the directed edge and we can direct an undirected edge.
64 /// The UEdgeIt is an iterator for the undirected edges. We can use
65 /// the UEdgeMap to map values for the undirected edges. The InEdgeIt and
66 /// OutEdgeIt iterates on the same undirected edges but with opposite
67 /// direction. The IncEdgeIt iterates also on the same undirected edges
68 /// as the OutEdgeIt and InEdgeIt but it is not convertible to Edge just
72 /// \brief The undirected graph should be tagged by the
75 /// The undirected graph should be tagged by the UndirectedTag. This
76 /// tag helps the enable_if technics to make compile time
77 /// specializations for undirected graphs.
78 typedef True UndirectedTag;
80 /// \brief The base type of node iterators,
81 /// or in other words, the trivial node iterator.
83 /// This is the base type of each node iterator,
84 /// thus each kind of node iterator converts to this.
85 /// More precisely each kind of node iterator should be inherited
86 /// from the trivial node iterator.
89 /// Default constructor
91 /// @warning The default constructor sets the iterator
92 /// to an undefined value.
100 /// Invalid constructor \& conversion.
102 /// This constructor initializes the iterator to be invalid.
103 /// \sa Invalid for more details.
105 /// Equality operator
107 /// Two iterators are equal if and only if they point to the
108 /// same object or both are invalid.
109 bool operator==(Node) const { return true; }
111 /// Inequality operator
113 /// \sa operator==(Node n)
115 bool operator!=(Node) const { return true; }
117 /// Artificial ordering operator.
119 /// To allow the use of graph descriptors as key type in std::map or
120 /// similar associative container we require this.
122 /// \note This operator only have to define some strict ordering of
123 /// the items; this order has nothing to do with the iteration
124 /// ordering of the items.
125 bool operator<(Node) const { return false; }
129 /// This iterator goes through each node.
131 /// This iterator goes through each node.
132 /// Its usage is quite simple, for example you can count the number
133 /// of nodes in graph \c g of type \c Graph like this:
136 /// for (Graph::NodeIt n(g); n!=INVALID; ++n) ++count;
138 class NodeIt : public Node {
140 /// Default constructor
142 /// @warning The default constructor sets the iterator
143 /// to an undefined value.
145 /// Copy constructor.
147 /// Copy constructor.
149 NodeIt(const NodeIt& n) : Node(n) { }
150 /// Invalid constructor \& conversion.
152 /// Initialize the iterator to be invalid.
153 /// \sa Invalid for more details.
155 /// Sets the iterator to the first node.
157 /// Sets the iterator to the first node of \c g.
159 NodeIt(const UGraph&) { }
160 /// Node -> NodeIt conversion.
162 /// Sets the iterator to the node of \c the graph pointed by
163 /// the trivial iterator.
164 /// This feature necessitates that each time we
165 /// iterate the edge-set, the iteration order is the same.
166 NodeIt(const UGraph&, const Node&) { }
169 /// Assign the iterator to the next node.
171 NodeIt& operator++() { return *this; }
175 /// The base type of the undirected edge iterators.
177 /// The base type of the undirected edge iterators.
181 /// Default constructor
183 /// @warning The default constructor sets the iterator
184 /// to an undefined value.
186 /// Copy constructor.
188 /// Copy constructor.
190 UEdge(const UEdge&) { }
191 /// Initialize the iterator to be invalid.
193 /// Initialize the iterator to be invalid.
196 /// Equality operator
198 /// Two iterators are equal if and only if they point to the
199 /// same object or both are invalid.
200 bool operator==(UEdge) const { return true; }
201 /// Inequality operator
203 /// \sa operator==(UEdge n)
205 bool operator!=(UEdge) const { return true; }
207 /// Artificial ordering operator.
209 /// To allow the use of graph descriptors as key type in std::map or
210 /// similar associative container we require this.
212 /// \note This operator only have to define some strict ordering of
213 /// the items; this order has nothing to do with the iteration
214 /// ordering of the items.
215 bool operator<(UEdge) const { return false; }
218 /// This iterator goes through each undirected edge.
220 /// This iterator goes through each undirected edge of a graph.
221 /// Its usage is quite simple, for example you can count the number
222 /// of undirected edges in a graph \c g of type \c Graph as follows:
225 /// for(Graph::UEdgeIt e(g); e!=INVALID; ++e) ++count;
227 class UEdgeIt : public UEdge {
229 /// Default constructor
231 /// @warning The default constructor sets the iterator
232 /// to an undefined value.
234 /// Copy constructor.
236 /// Copy constructor.
238 UEdgeIt(const UEdgeIt& e) : UEdge(e) { }
239 /// Initialize the iterator to be invalid.
241 /// Initialize the iterator to be invalid.
244 /// This constructor sets the iterator to the first undirected edge.
246 /// This constructor sets the iterator to the first undirected edge.
247 UEdgeIt(const UGraph&) { }
248 /// UEdge -> UEdgeIt conversion
250 /// Sets the iterator to the value of the trivial iterator.
251 /// This feature necessitates that each time we
252 /// iterate the undirected edge-set, the iteration order is the
254 UEdgeIt(const UGraph&, const UEdge&) { }
255 /// Next undirected edge
257 /// Assign the iterator to the next undirected edge.
258 UEdgeIt& operator++() { return *this; }
261 /// \brief This iterator goes trough the incident undirected
264 /// This iterator goes trough the incident undirected edges
265 /// of a certain node of a graph. You should assume that the
266 /// loop edges will be iterated twice.
268 /// Its usage is quite simple, for example you can compute the
269 /// degree (i.e. count the number of incident edges of a node \c n
270 /// in graph \c g of type \c Graph as follows.
274 /// for(Graph::IncEdgeIt e(g, n); e!=INVALID; ++e) ++count;
276 class IncEdgeIt : public UEdge {
278 /// Default constructor
280 /// @warning The default constructor sets the iterator
281 /// to an undefined value.
283 /// Copy constructor.
285 /// Copy constructor.
287 IncEdgeIt(const IncEdgeIt& e) : UEdge(e) { }
288 /// Initialize the iterator to be invalid.
290 /// Initialize the iterator to be invalid.
292 IncEdgeIt(Invalid) { }
293 /// This constructor sets the iterator to first incident edge.
295 /// This constructor set the iterator to the first incident edge of
297 IncEdgeIt(const UGraph&, const Node&) { }
298 /// UEdge -> IncEdgeIt conversion
300 /// Sets the iterator to the value of the trivial iterator \c e.
301 /// This feature necessitates that each time we
302 /// iterate the edge-set, the iteration order is the same.
303 IncEdgeIt(const UGraph&, const UEdge&) { }
304 /// Next incident edge
306 /// Assign the iterator to the next incident edge
307 /// of the corresponding node.
308 IncEdgeIt& operator++() { return *this; }
311 /// The directed edge type.
313 /// The directed edge type. It can be converted to the
314 /// undirected edge or it should be inherited from the undirected
316 class Edge : public UEdge {
318 /// Default constructor
320 /// @warning The default constructor sets the iterator
321 /// to an undefined value.
323 /// Copy constructor.
325 /// Copy constructor.
327 Edge(const Edge& e) : UEdge(e) { }
328 /// Initialize the iterator to be invalid.
330 /// Initialize the iterator to be invalid.
333 /// Equality operator
335 /// Two iterators are equal if and only if they point to the
336 /// same object or both are invalid.
337 bool operator==(Edge) const { return true; }
338 /// Inequality operator
340 /// \sa operator==(Edge n)
342 bool operator!=(Edge) const { return true; }
344 /// Artificial ordering operator.
346 /// To allow the use of graph descriptors as key type in std::map or
347 /// similar associative container we require this.
349 /// \note This operator only have to define some strict ordering of
350 /// the items; this order has nothing to do with the iteration
351 /// ordering of the items.
352 bool operator<(Edge) const { return false; }
355 /// This iterator goes through each directed edge.
357 /// This iterator goes through each edge of a graph.
358 /// Its usage is quite simple, for example you can count the number
359 /// of edges in a graph \c g of type \c Graph as follows:
362 /// for(Graph::EdgeIt e(g); e!=INVALID; ++e) ++count;
364 class EdgeIt : public Edge {
366 /// Default constructor
368 /// @warning The default constructor sets the iterator
369 /// to an undefined value.
371 /// Copy constructor.
373 /// Copy constructor.
375 EdgeIt(const EdgeIt& e) : Edge(e) { }
376 /// Initialize the iterator to be invalid.
378 /// Initialize the iterator to be invalid.
381 /// This constructor sets the iterator to the first edge.
383 /// This constructor sets the iterator to the first edge of \c g.
384 ///@param g the graph
385 EdgeIt(const UGraph &g) { ignore_unused_variable_warning(g); }
386 /// Edge -> EdgeIt conversion
388 /// Sets the iterator to the value of the trivial iterator \c e.
389 /// This feature necessitates that each time we
390 /// iterate the edge-set, the iteration order is the same.
391 EdgeIt(const UGraph&, const Edge&) { }
394 /// Assign the iterator to the next edge.
395 EdgeIt& operator++() { return *this; }
398 /// This iterator goes trough the outgoing directed edges of a node.
400 /// This iterator goes trough the \e outgoing edges of a certain node
402 /// Its usage is quite simple, for example you can count the number
403 /// of outgoing edges of a node \c n
404 /// in graph \c g of type \c Graph as follows.
407 /// for (Graph::OutEdgeIt e(g, n); e!=INVALID; ++e) ++count;
410 class OutEdgeIt : public Edge {
412 /// Default constructor
414 /// @warning The default constructor sets the iterator
415 /// to an undefined value.
417 /// Copy constructor.
419 /// Copy constructor.
421 OutEdgeIt(const OutEdgeIt& e) : Edge(e) { }
422 /// Initialize the iterator to be invalid.
424 /// Initialize the iterator to be invalid.
426 OutEdgeIt(Invalid) { }
427 /// This constructor sets the iterator to the first outgoing edge.
429 /// This constructor sets the iterator to the first outgoing edge of
432 ///@param g the graph
433 OutEdgeIt(const UGraph& n, const Node& g) {
434 ignore_unused_variable_warning(n);
435 ignore_unused_variable_warning(g);
437 /// Edge -> OutEdgeIt conversion
439 /// Sets the iterator to the value of the trivial iterator.
440 /// This feature necessitates that each time we
441 /// iterate the edge-set, the iteration order is the same.
442 OutEdgeIt(const UGraph&, const Edge&) { }
443 ///Next outgoing edge
445 /// Assign the iterator to the next
446 /// outgoing edge of the corresponding node.
447 OutEdgeIt& operator++() { return *this; }
450 /// This iterator goes trough the incoming directed edges of a node.
452 /// This iterator goes trough the \e incoming edges of a certain node
454 /// Its usage is quite simple, for example you can count the number
455 /// of outgoing edges of a node \c n
456 /// in graph \c g of type \c Graph as follows.
459 /// for(Graph::InEdgeIt e(g, n); e!=INVALID; ++e) ++count;
462 class InEdgeIt : public Edge {
464 /// Default constructor
466 /// @warning The default constructor sets the iterator
467 /// to an undefined value.
469 /// Copy constructor.
471 /// Copy constructor.
473 InEdgeIt(const InEdgeIt& e) : Edge(e) { }
474 /// Initialize the iterator to be invalid.
476 /// Initialize the iterator to be invalid.
478 InEdgeIt(Invalid) { }
479 /// This constructor sets the iterator to first incoming edge.
481 /// This constructor set the iterator to the first incoming edge of
484 ///@param g the graph
485 InEdgeIt(const UGraph& g, const Node& n) {
486 ignore_unused_variable_warning(n);
487 ignore_unused_variable_warning(g);
489 /// Edge -> InEdgeIt conversion
491 /// Sets the iterator to the value of the trivial iterator \c e.
492 /// This feature necessitates that each time we
493 /// iterate the edge-set, the iteration order is the same.
494 InEdgeIt(const UGraph&, const Edge&) { }
495 /// Next incoming edge
497 /// Assign the iterator to the next inedge of the corresponding node.
499 InEdgeIt& operator++() { return *this; }
502 /// \brief Read write map of the nodes to type \c T.
504 /// ReadWrite map of the nodes to type \c T.
507 class NodeMap : public ReadWriteMap< Node, T >
512 NodeMap(const UGraph&) { }
514 NodeMap(const UGraph&, T) { }
517 NodeMap(const NodeMap& nm) : ReadWriteMap< Node, T >(nm) { }
518 ///Assignment operator
519 template <typename CMap>
520 NodeMap& operator=(const CMap&) {
521 checkConcept<ReadMap<Node, T>, CMap>();
526 /// \brief Read write map of the directed edges to type \c T.
528 /// Reference map of the directed edges to type \c T.
531 class EdgeMap : public ReadWriteMap<Edge,T>
536 EdgeMap(const UGraph&) { }
538 EdgeMap(const UGraph&, T) { }
540 EdgeMap(const EdgeMap& em) : ReadWriteMap<Edge,T>(em) { }
541 ///Assignment operator
542 template <typename CMap>
543 EdgeMap& operator=(const CMap&) {
544 checkConcept<ReadMap<Edge, T>, CMap>();
549 /// Read write map of the undirected edges to type \c T.
551 /// Reference map of the edges to type \c T.
554 class UEdgeMap : public ReadWriteMap<UEdge,T>
559 UEdgeMap(const UGraph&) { }
561 UEdgeMap(const UGraph&, T) { }
563 UEdgeMap(const UEdgeMap& em) : ReadWriteMap<UEdge,T>(em) {}
564 ///Assignment operator
565 template <typename CMap>
566 UEdgeMap& operator=(const CMap&) {
567 checkConcept<ReadMap<UEdge, T>, CMap>();
572 /// \brief Direct the given undirected edge.
574 /// Direct the given undirected edge. The returned edge source
575 /// will be the given node.
576 Edge direct(const UEdge&, const Node&) const {
580 /// \brief Direct the given undirected edge.
582 /// Direct the given undirected edge. The returned edge
583 /// represents the given undirected edge and the direction comes
584 /// from the given bool. The source of the undirected edge and
585 /// the directed edge is the same when the given bool is true.
586 Edge direct(const UEdge&, bool) const {
590 /// \brief Returns true if the edge has default orientation.
592 /// Returns whether the given directed edge is same orientation as
593 /// the corresponding undirected edge's default orientation.
594 bool direction(Edge) const { return true; }
596 /// \brief Returns the opposite directed edge.
598 /// Returns the opposite directed edge.
599 Edge oppositeEdge(Edge) const { return INVALID; }
601 /// \brief Opposite node on an edge
603 /// \return the opposite of the given Node on the given UEdge
604 Node oppositeNode(Node, UEdge) const { return INVALID; }
606 /// \brief First node of the undirected edge.
608 /// \return the first node of the given UEdge.
610 /// Naturally undirected edges don't have direction and thus
611 /// don't have source and target node. But we use these two methods
612 /// to query the two nodes of the edge. The direction of the edge
613 /// which arises this way is called the inherent direction of the
614 /// undirected edge, and is used to define the "default" direction
615 /// of the directed versions of the edges.
617 Node source(UEdge) const { return INVALID; }
619 /// \brief Second node of the undirected edge.
620 Node target(UEdge) const { return INVALID; }
622 /// \brief Source node of the directed edge.
623 Node source(Edge) const { return INVALID; }
625 /// \brief Target node of the directed edge.
626 Node target(Edge) const { return INVALID; }
628 void first(Node&) const {}
629 void next(Node&) const {}
631 void first(UEdge&) const {}
632 void next(UEdge&) const {}
634 void first(Edge&) const {}
635 void next(Edge&) const {}
637 void firstOut(Edge&, Node) const {}
638 void nextOut(Edge&) const {}
640 void firstIn(Edge&, Node) const {}
641 void nextIn(Edge&) const {}
644 void firstInc(UEdge &, bool &, const Node &) const {}
645 void nextInc(UEdge &, bool &) const {}
647 /// \brief Base node of the iterator
649 /// Returns the base node (the source in this case) of the iterator
650 Node baseNode(OutEdgeIt e) const {
653 /// \brief Running node of the iterator
655 /// Returns the running node (the target in this case) of the
657 Node runningNode(OutEdgeIt e) const {
661 /// \brief Base node of the iterator
663 /// Returns the base node (the target in this case) of the iterator
664 Node baseNode(InEdgeIt e) const {
667 /// \brief Running node of the iterator
669 /// Returns the running node (the source in this case) of the
671 Node runningNode(InEdgeIt e) const {
675 /// \brief Base node of the iterator
677 /// Returns the base node of the iterator
678 Node baseNode(IncEdgeIt) const {
682 /// \brief Running node of the iterator
684 /// Returns the running node of the iterator
685 Node runningNode(IncEdgeIt) const {
689 template <typename Graph>
692 checkConcept<IterableUGraphComponent<>, Graph>();
693 checkConcept<MappableUGraphComponent<>, Graph>();