1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
3 * This file is a part of LEMON, a generic C++ optimization library.
5 * Copyright (C) 2003-2009
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 graph components.
23 #ifndef LEMON_CONCEPTS_GRAPH_COMPONENTS_H
24 #define LEMON_CONCEPTS_GRAPH_COMPONENTS_H
26 #include <lemon/core.h>
27 #include <lemon/concepts/maps.h>
29 #include <lemon/bits/alteration_notifier.h>
34 /// \brief Concept class for \c Node, \c Arc and \c Edge types.
36 /// This class describes the concept of \c Node, \c Arc and \c Edge
37 /// subtypes of digraph and graph types.
39 /// \note This class is a template class so that we can use it to
40 /// create graph skeleton classes. The reason for this is that \c Node
41 /// and \c Arc (or \c Edge) types should \e not derive from the same
42 /// base class. For \c Node you should instantiate it with character
43 /// \c 'n', for \c Arc with \c 'a' and for \c Edge with \c 'e'.
45 template <char sel = '0'>
49 /// \brief Default constructor.
51 /// Default constructor.
52 /// \warning The default constructor is not required to set
53 /// the item to some well-defined value. So you should consider it
57 /// \brief Copy constructor.
60 GraphItem(const GraphItem &) {}
62 /// \brief Constructor for conversion from \c INVALID.
64 /// Constructor for conversion from \c INVALID.
65 /// It initializes the item to be invalid.
66 /// \sa Invalid for more details.
69 /// \brief Assignment operator.
71 /// Assignment operator for the item.
72 GraphItem& operator=(const GraphItem&) { return *this; }
74 /// \brief Assignment operator for INVALID.
76 /// This operator makes the item invalid.
77 GraphItem& operator=(Invalid) { return *this; }
79 /// \brief Equality operator.
81 /// Equality operator.
82 bool operator==(const GraphItem&) const { return false; }
84 /// \brief Inequality operator.
86 /// Inequality operator.
87 bool operator!=(const GraphItem&) const { return false; }
89 /// \brief Ordering operator.
91 /// This operator defines an ordering of the items.
92 /// It makes possible to use graph item types as key types in
93 /// associative containers (e.g. \c std::map).
95 /// \note This operator only have to define some strict ordering of
96 /// the items; this order has nothing to do with the iteration
97 /// ordering of the items.
98 bool operator<(const GraphItem&) const { return false; }
100 template<typename _GraphItem>
106 _GraphItem i3 = INVALID;
111 ignore_unused_variable_warning(b);
113 b = (ia == ib) && (ia != ib);
114 b = (ia == INVALID) && (ib != INVALID);
118 const _GraphItem &ia;
119 const _GraphItem &ib;
124 /// \brief Base skeleton class for directed graphs.
126 /// This class describes the base interface of directed graph types.
127 /// All digraph %concepts have to conform to this class.
128 /// It just provides types for nodes and arcs and functions
129 /// to get the source and the target nodes of arcs.
130 class BaseDigraphComponent {
133 typedef BaseDigraphComponent Digraph;
135 /// \brief Node class of the digraph.
137 /// This class represents the nodes of the digraph.
138 typedef GraphItem<'n'> Node;
140 /// \brief Arc class of the digraph.
142 /// This class represents the arcs of the digraph.
143 typedef GraphItem<'a'> Arc;
145 /// \brief Return the source node of an arc.
147 /// This function returns the source node of an arc.
148 Node source(const Arc&) const { return INVALID; }
150 /// \brief Return the target node of an arc.
152 /// This function returns the target node of an arc.
153 Node target(const Arc&) const { return INVALID; }
155 /// \brief Return the opposite node on the given arc.
157 /// This function returns the opposite node on the given arc.
158 Node oppositeNode(const Node&, const Arc&) const {
162 template <typename _Digraph>
164 typedef typename _Digraph::Node Node;
165 typedef typename _Digraph::Arc Arc;
168 checkConcept<GraphItem<'n'>, Node>();
169 checkConcept<GraphItem<'a'>, Arc>();
173 n = digraph.source(e);
174 n = digraph.target(e);
175 n = digraph.oppositeNode(n, e);
179 const _Digraph& digraph;
184 /// \brief Base skeleton class for undirected graphs.
186 /// This class describes the base interface of undirected graph types.
187 /// All graph %concepts have to conform to this class.
188 /// It extends the interface of \ref BaseDigraphComponent with an
189 /// \c Edge type and functions to get the end nodes of edges,
190 /// to convert from arcs to edges and to get both direction of edges.
191 class BaseGraphComponent : public BaseDigraphComponent {
194 typedef BaseGraphComponent Graph;
196 typedef BaseDigraphComponent::Node Node;
197 typedef BaseDigraphComponent::Arc Arc;
199 /// \brief Undirected edge class of the graph.
201 /// This class represents the undirected edges of the graph.
202 /// Undirected graphs can be used as directed graphs, each edge is
203 /// represented by two opposite directed arcs.
204 class Edge : public GraphItem<'e'> {
205 typedef GraphItem<'e'> Parent;
208 /// \brief Default constructor.
210 /// Default constructor.
211 /// \warning The default constructor is not required to set
212 /// the item to some well-defined value. So you should consider it
213 /// as uninitialized.
216 /// \brief Copy constructor.
218 /// Copy constructor.
219 Edge(const Edge &) : Parent() {}
221 /// \brief Constructor for conversion from \c INVALID.
223 /// Constructor for conversion from \c INVALID.
224 /// It initializes the item to be invalid.
225 /// \sa Invalid for more details.
228 /// \brief Constructor for conversion from an arc.
230 /// Constructor for conversion from an arc.
231 /// Besides the core graph item functionality each arc should
232 /// be convertible to the represented edge.
236 /// \brief Return one end node of an edge.
238 /// This function returns one end node of an edge.
239 Node u(const Edge&) const { return INVALID; }
241 /// \brief Return the other end node of an edge.
243 /// This function returns the other end node of an edge.
244 Node v(const Edge&) const { return INVALID; }
246 /// \brief Return a directed arc related to an edge.
248 /// This function returns a directed arc from its direction and the
249 /// represented edge.
250 Arc direct(const Edge&, bool) const { return INVALID; }
252 /// \brief Return a directed arc related to an edge.
254 /// This function returns a directed arc from its source node and the
255 /// represented edge.
256 Arc direct(const Edge&, const Node&) const { return INVALID; }
258 /// \brief Return the direction of the arc.
260 /// Returns the direction of the arc. Each arc represents an
261 /// edge with a direction. It gives back the
263 bool direction(const Arc&) const { return true; }
265 /// \brief Return the opposite arc.
267 /// This function returns the opposite arc, i.e. the arc representing
268 /// the same edge and has opposite direction.
269 Arc oppositeArc(const Arc&) const { return INVALID; }
271 template <typename _Graph>
273 typedef typename _Graph::Node Node;
274 typedef typename _Graph::Arc Arc;
275 typedef typename _Graph::Edge Edge;
278 checkConcept<BaseDigraphComponent, _Graph>();
279 checkConcept<GraphItem<'e'>, Edge>();
286 e = graph.direct(ue, true);
287 e = graph.direct(ue, false);
288 e = graph.direct(ue, n);
289 e = graph.oppositeArc(e);
291 bool d = graph.direction(e);
292 ignore_unused_variable_warning(d);
302 /// \brief Skeleton class for \e idable directed graphs.
304 /// This class describes the interface of \e idable directed graphs.
305 /// It extends \ref BaseDigraphComponent with the core ID functions.
306 /// The ids of the items must be unique and immutable.
307 /// This concept is part of the Digraph concept.
308 template <typename BAS = BaseDigraphComponent>
309 class IDableDigraphComponent : public BAS {
313 typedef typename Base::Node Node;
314 typedef typename Base::Arc Arc;
316 /// \brief Return a unique integer id for the given node.
318 /// This function returns a unique integer id for the given node.
319 int id(const Node&) const { return -1; }
321 /// \brief Return the node by its unique id.
323 /// This function returns the node by its unique id.
324 /// If the digraph does not contain a node with the given id,
325 /// then the result of the function is undefined.
326 Node nodeFromId(int) const { return INVALID; }
328 /// \brief Return a unique integer id for the given arc.
330 /// This function returns a unique integer id for the given arc.
331 int id(const Arc&) const { return -1; }
333 /// \brief Return the arc by its unique id.
335 /// This function returns the arc by its unique id.
336 /// If the digraph does not contain an arc with the given id,
337 /// then the result of the function is undefined.
338 Arc arcFromId(int) const { return INVALID; }
340 /// \brief Return an integer greater or equal to the maximum
343 /// This function returns an integer greater or equal to the
345 int maxNodeId() const { return -1; }
347 /// \brief Return an integer greater or equal to the maximum
350 /// This function returns an integer greater or equal to the
352 int maxArcId() const { return -1; }
354 template <typename _Digraph>
358 checkConcept<Base, _Digraph >();
359 typename _Digraph::Node node;
361 int nid = digraph.id(node);
362 nid = digraph.id(node);
363 node = digraph.nodeFromId(nid);
364 typename _Digraph::Arc arc;
366 int eid = digraph.id(arc);
367 eid = digraph.id(arc);
368 arc = digraph.arcFromId(eid);
370 nid = digraph.maxNodeId();
371 ignore_unused_variable_warning(nid);
372 eid = digraph.maxArcId();
373 ignore_unused_variable_warning(eid);
376 const _Digraph& digraph;
381 /// \brief Skeleton class for \e idable undirected graphs.
383 /// This class describes the interface of \e idable undirected
384 /// graphs. It extends \ref IDableDigraphComponent with the core ID
385 /// functions of undirected graphs.
386 /// The ids of the items must be unique and immutable.
387 /// This concept is part of the Graph concept.
388 template <typename BAS = BaseGraphComponent>
389 class IDableGraphComponent : public IDableDigraphComponent<BAS> {
393 typedef typename Base::Edge Edge;
395 using IDableDigraphComponent<Base>::id;
397 /// \brief Return a unique integer id for the given edge.
399 /// This function returns a unique integer id for the given edge.
400 int id(const Edge&) const { return -1; }
402 /// \brief Return the edge by its unique id.
404 /// This function returns the edge by its unique id.
405 /// If the graph does not contain an edge with the given id,
406 /// then the result of the function is undefined.
407 Edge edgeFromId(int) const { return INVALID; }
409 /// \brief Return an integer greater or equal to the maximum
412 /// This function returns an integer greater or equal to the
414 int maxEdgeId() const { return -1; }
416 template <typename _Graph>
420 checkConcept<IDableDigraphComponent<Base>, _Graph >();
421 typename _Graph::Edge edge;
422 int ueid = graph.id(edge);
423 ueid = graph.id(edge);
424 edge = graph.edgeFromId(ueid);
425 ueid = graph.maxEdgeId();
426 ignore_unused_variable_warning(ueid);
434 /// \brief Concept class for \c NodeIt, \c ArcIt and \c EdgeIt types.
436 /// This class describes the concept of \c NodeIt, \c ArcIt and
437 /// \c EdgeIt subtypes of digraph and graph types.
438 template <typename GR, typename Item>
439 class GraphItemIt : public Item {
441 /// \brief Default constructor.
443 /// Default constructor.
444 /// \warning The default constructor is not required to set
445 /// the iterator to some well-defined value. So you should consider it
446 /// as uninitialized.
449 /// \brief Copy constructor.
451 /// Copy constructor.
452 GraphItemIt(const GraphItemIt& it) : Item(it) {}
454 /// \brief Constructor that sets the iterator to the first item.
456 /// Constructor that sets the iterator to the first item.
457 explicit GraphItemIt(const GR&) {}
459 /// \brief Constructor for conversion from \c INVALID.
461 /// Constructor for conversion from \c INVALID.
462 /// It initializes the iterator to be invalid.
463 /// \sa Invalid for more details.
464 GraphItemIt(Invalid) {}
466 /// \brief Assignment operator.
468 /// Assignment operator for the iterator.
469 GraphItemIt& operator=(const GraphItemIt&) { return *this; }
471 /// \brief Increment the iterator.
473 /// This operator increments the iterator, i.e. assigns it to the
475 GraphItemIt& operator++() { return *this; }
477 /// \brief Equality operator
479 /// Equality operator.
480 /// Two iterators are equal if and only if they point to the
481 /// same object or both are invalid.
482 bool operator==(const GraphItemIt&) const { return true;}
484 /// \brief Inequality operator
486 /// Inequality operator.
487 /// Two iterators are equal if and only if they point to the
488 /// same object or both are invalid.
489 bool operator!=(const GraphItemIt&) const { return true;}
491 template<typename _GraphItemIt>
494 checkConcept<GraphItem<>, _GraphItemIt>();
497 _GraphItemIt it3 = it1;
498 _GraphItemIt it4 = INVALID;
499 ignore_unused_variable_warning(it3);
500 ignore_unused_variable_warning(it4);
514 /// \brief Concept class for \c InArcIt, \c OutArcIt and
515 /// \c IncEdgeIt types.
517 /// This class describes the concept of \c InArcIt, \c OutArcIt
518 /// and \c IncEdgeIt subtypes of digraph and graph types.
520 /// \note Since these iterator classes do not inherit from the same
521 /// base class, there is an additional template parameter (selector)
522 /// \c sel. For \c InArcIt you should instantiate it with character
523 /// \c 'i', for \c OutArcIt with \c 'o' and for \c IncEdgeIt with \c 'e'.
524 template <typename GR,
525 typename Item = typename GR::Arc,
526 typename Base = typename GR::Node,
528 class GraphIncIt : public Item {
530 /// \brief Default constructor.
532 /// Default constructor.
533 /// \warning The default constructor is not required to set
534 /// the iterator to some well-defined value. So you should consider it
535 /// as uninitialized.
538 /// \brief Copy constructor.
540 /// Copy constructor.
541 GraphIncIt(const GraphIncIt& it) : Item(it) {}
543 /// \brief Constructor that sets the iterator to the first
544 /// incoming or outgoing arc.
546 /// Constructor that sets the iterator to the first arc
547 /// incoming to or outgoing from the given node.
548 explicit GraphIncIt(const GR&, const Base&) {}
550 /// \brief Constructor for conversion from \c INVALID.
552 /// Constructor for conversion from \c INVALID.
553 /// It initializes the iterator to be invalid.
554 /// \sa Invalid for more details.
555 GraphIncIt(Invalid) {}
557 /// \brief Assignment operator.
559 /// Assignment operator for the iterator.
560 GraphIncIt& operator=(const GraphIncIt&) { return *this; }
562 /// \brief Increment the iterator.
564 /// This operator increments the iterator, i.e. assigns it to the
565 /// next arc incoming to or outgoing from the given node.
566 GraphIncIt& operator++() { return *this; }
568 /// \brief Equality operator
570 /// Equality operator.
571 /// Two iterators are equal if and only if they point to the
572 /// same object or both are invalid.
573 bool operator==(const GraphIncIt&) const { return true;}
575 /// \brief Inequality operator
577 /// Inequality operator.
578 /// Two iterators are equal if and only if they point to the
579 /// same object or both are invalid.
580 bool operator!=(const GraphIncIt&) const { return true;}
582 template <typename _GraphIncIt>
585 checkConcept<GraphItem<sel>, _GraphIncIt>();
586 _GraphIncIt it1(graph, node);
588 _GraphIncIt it3 = it1;
589 _GraphIncIt it4 = INVALID;
590 ignore_unused_variable_warning(it3);
591 ignore_unused_variable_warning(it4);
605 /// \brief Skeleton class for iterable directed graphs.
607 /// This class describes the interface of iterable directed
608 /// graphs. It extends \ref BaseDigraphComponent with the core
609 /// iterable interface.
610 /// This concept is part of the Digraph concept.
611 template <typename BAS = BaseDigraphComponent>
612 class IterableDigraphComponent : public BAS {
617 typedef typename Base::Node Node;
618 typedef typename Base::Arc Arc;
620 typedef IterableDigraphComponent Digraph;
622 /// \name Base Iteration
624 /// This interface provides functions for iteration on digraph items.
628 /// \brief Return the first node.
630 /// This function gives back the first node in the iteration order.
631 void first(Node&) const {}
633 /// \brief Return the next node.
635 /// This function gives back the next node in the iteration order.
636 void next(Node&) const {}
638 /// \brief Return the first arc.
640 /// This function gives back the first arc in the iteration order.
641 void first(Arc&) const {}
643 /// \brief Return the next arc.
645 /// This function gives back the next arc in the iteration order.
646 void next(Arc&) const {}
648 /// \brief Return the first arc incomming to the given node.
650 /// This function gives back the first arc incomming to the
652 void firstIn(Arc&, const Node&) const {}
654 /// \brief Return the next arc incomming to the given node.
656 /// This function gives back the next arc incomming to the
658 void nextIn(Arc&) const {}
660 /// \brief Return the first arc outgoing form the given node.
662 /// This function gives back the first arc outgoing form the
664 void firstOut(Arc&, const Node&) const {}
666 /// \brief Return the next arc outgoing form the given node.
668 /// This function gives back the next arc outgoing form the
670 void nextOut(Arc&) const {}
674 /// \name Class Based Iteration
676 /// This interface provides iterator classes for digraph items.
680 /// \brief This iterator goes through each node.
682 /// This iterator goes through each node.
684 typedef GraphItemIt<Digraph, Node> NodeIt;
686 /// \brief This iterator goes through each arc.
688 /// This iterator goes through each arc.
690 typedef GraphItemIt<Digraph, Arc> ArcIt;
692 /// \brief This iterator goes trough the incoming arcs of a node.
694 /// This iterator goes trough the \e incoming arcs of a certain node
696 typedef GraphIncIt<Digraph, Arc, Node, 'i'> InArcIt;
698 /// \brief This iterator goes trough the outgoing arcs of a node.
700 /// This iterator goes trough the \e outgoing arcs of a certain node
702 typedef GraphIncIt<Digraph, Arc, Node, 'o'> OutArcIt;
704 /// \brief The base node of the iterator.
706 /// This function gives back the base node of the iterator.
707 /// It is always the target node of the pointed arc.
708 Node baseNode(const InArcIt&) const { return INVALID; }
710 /// \brief The running node of the iterator.
712 /// This function gives back the running node of the iterator.
713 /// It is always the source node of the pointed arc.
714 Node runningNode(const InArcIt&) const { return INVALID; }
716 /// \brief The base node of the iterator.
718 /// This function gives back the base node of the iterator.
719 /// It is always the source node of the pointed arc.
720 Node baseNode(const OutArcIt&) const { return INVALID; }
722 /// \brief The running node of the iterator.
724 /// This function gives back the running node of the iterator.
725 /// It is always the target node of the pointed arc.
726 Node runningNode(const OutArcIt&) const { return INVALID; }
730 template <typename _Digraph>
733 checkConcept<Base, _Digraph>();
736 typename _Digraph::Node node(INVALID);
737 typename _Digraph::Arc arc(INVALID);
747 digraph.firstIn(arc, node);
751 digraph.firstOut(arc, node);
752 digraph.nextOut(arc);
757 checkConcept<GraphItemIt<_Digraph, typename _Digraph::Arc>,
758 typename _Digraph::ArcIt >();
759 checkConcept<GraphItemIt<_Digraph, typename _Digraph::Node>,
760 typename _Digraph::NodeIt >();
761 checkConcept<GraphIncIt<_Digraph, typename _Digraph::Arc,
762 typename _Digraph::Node, 'i'>, typename _Digraph::InArcIt>();
763 checkConcept<GraphIncIt<_Digraph, typename _Digraph::Arc,
764 typename _Digraph::Node, 'o'>, typename _Digraph::OutArcIt>();
766 typename _Digraph::Node n;
767 const typename _Digraph::InArcIt iait(INVALID);
768 const typename _Digraph::OutArcIt oait(INVALID);
769 n = digraph.baseNode(iait);
770 n = digraph.runningNode(iait);
771 n = digraph.baseNode(oait);
772 n = digraph.runningNode(oait);
773 ignore_unused_variable_warning(n);
777 const _Digraph& digraph;
782 /// \brief Skeleton class for iterable undirected graphs.
784 /// This class describes the interface of iterable undirected
785 /// graphs. It extends \ref IterableDigraphComponent with the core
786 /// iterable interface of undirected graphs.
787 /// This concept is part of the Graph concept.
788 template <typename BAS = BaseGraphComponent>
789 class IterableGraphComponent : public IterableDigraphComponent<BAS> {
793 typedef typename Base::Node Node;
794 typedef typename Base::Arc Arc;
795 typedef typename Base::Edge Edge;
798 typedef IterableGraphComponent Graph;
800 /// \name Base Iteration
802 /// This interface provides functions for iteration on edges.
806 using IterableDigraphComponent<Base>::first;
807 using IterableDigraphComponent<Base>::next;
809 /// \brief Return the first edge.
811 /// This function gives back the first edge in the iteration order.
812 void first(Edge&) const {}
814 /// \brief Return the next edge.
816 /// This function gives back the next edge in the iteration order.
817 void next(Edge&) const {}
819 /// \brief Return the first edge incident to the given node.
821 /// This function gives back the first edge incident to the given
822 /// node. The bool parameter gives back the direction for which the
823 /// source node of the directed arc representing the edge is the
825 void firstInc(Edge&, bool&, const Node&) const {}
827 /// \brief Gives back the next of the edges from the
830 /// This function gives back the next edge incident to the given
831 /// node. The bool parameter should be used as \c firstInc() use it.
832 void nextInc(Edge&, bool&) const {}
834 using IterableDigraphComponent<Base>::baseNode;
835 using IterableDigraphComponent<Base>::runningNode;
839 /// \name Class Based Iteration
841 /// This interface provides iterator classes for edges.
845 /// \brief This iterator goes through each edge.
847 /// This iterator goes through each edge.
848 typedef GraphItemIt<Graph, Edge> EdgeIt;
850 /// \brief This iterator goes trough the incident edges of a
853 /// This iterator goes trough the incident edges of a certain
855 typedef GraphIncIt<Graph, Edge, Node, 'e'> IncEdgeIt;
857 /// \brief The base node of the iterator.
859 /// This function gives back the base node of the iterator.
860 Node baseNode(const IncEdgeIt&) const { return INVALID; }
862 /// \brief The running node of the iterator.
864 /// This function gives back the running node of the iterator.
865 Node runningNode(const IncEdgeIt&) const { return INVALID; }
869 template <typename _Graph>
872 checkConcept<IterableDigraphComponent<Base>, _Graph>();
875 typename _Graph::Node node(INVALID);
876 typename _Graph::Edge edge(INVALID);
883 graph.firstInc(edge, dir, node);
884 graph.nextInc(edge, dir);
890 checkConcept<GraphItemIt<_Graph, typename _Graph::Edge>,
891 typename _Graph::EdgeIt >();
892 checkConcept<GraphIncIt<_Graph, typename _Graph::Edge,
893 typename _Graph::Node, 'e'>, typename _Graph::IncEdgeIt>();
895 typename _Graph::Node n;
896 const typename _Graph::IncEdgeIt ieit(INVALID);
897 n = graph.baseNode(ieit);
898 n = graph.runningNode(ieit);
907 /// \brief Skeleton class for alterable directed graphs.
909 /// This class describes the interface of alterable directed
910 /// graphs. It extends \ref BaseDigraphComponent with the alteration
911 /// notifier interface. It implements
912 /// an observer-notifier pattern for each digraph item. More
913 /// obsevers can be registered into the notifier and whenever an
914 /// alteration occured in the digraph all the observers will be
915 /// notified about it.
916 template <typename BAS = BaseDigraphComponent>
917 class AlterableDigraphComponent : public BAS {
921 typedef typename Base::Node Node;
922 typedef typename Base::Arc Arc;
925 /// Node alteration notifier class.
926 typedef AlterationNotifier<AlterableDigraphComponent, Node>
928 /// Arc alteration notifier class.
929 typedef AlterationNotifier<AlterableDigraphComponent, Arc>
932 /// \brief Return the node alteration notifier.
934 /// This function gives back the node alteration notifier.
935 NodeNotifier& notifier(Node) const {
936 return NodeNotifier();
939 /// \brief Return the arc alteration notifier.
941 /// This function gives back the arc alteration notifier.
942 ArcNotifier& notifier(Arc) const {
943 return ArcNotifier();
946 template <typename _Digraph>
949 checkConcept<Base, _Digraph>();
950 typename _Digraph::NodeNotifier& nn
951 = digraph.notifier(typename _Digraph::Node());
953 typename _Digraph::ArcNotifier& en
954 = digraph.notifier(typename _Digraph::Arc());
956 ignore_unused_variable_warning(nn);
957 ignore_unused_variable_warning(en);
960 const _Digraph& digraph;
965 /// \brief Skeleton class for alterable undirected graphs.
967 /// This class describes the interface of alterable undirected
968 /// graphs. It extends \ref AlterableDigraphComponent with the alteration
969 /// notifier interface of undirected graphs. It implements
970 /// an observer-notifier pattern for the edges. More
971 /// obsevers can be registered into the notifier and whenever an
972 /// alteration occured in the graph all the observers will be
973 /// notified about it.
974 template <typename BAS = BaseGraphComponent>
975 class AlterableGraphComponent : public AlterableDigraphComponent<BAS> {
979 typedef typename Base::Edge Edge;
982 /// Edge alteration notifier class.
983 typedef AlterationNotifier<AlterableGraphComponent, Edge>
986 /// \brief Return the edge alteration notifier.
988 /// This function gives back the edge alteration notifier.
989 EdgeNotifier& notifier(Edge) const {
990 return EdgeNotifier();
993 template <typename _Graph>
996 checkConcept<AlterableDigraphComponent<Base>, _Graph>();
997 typename _Graph::EdgeNotifier& uen
998 = graph.notifier(typename _Graph::Edge());
999 ignore_unused_variable_warning(uen);
1002 const _Graph& graph;
1007 /// \brief Concept class for standard graph maps.
1009 /// This class describes the concept of standard graph maps, i.e.
1010 /// the \c NodeMap, \c ArcMap and \c EdgeMap subtypes of digraph and
1011 /// graph types, which can be used for associating data to graph items.
1012 /// The standard graph maps must conform to the ReferenceMap concept.
1013 template <typename GR, typename K, typename V>
1014 class GraphMap : public ReferenceMap<K, V, V&, const V&> {
1015 typedef ReferenceMap<K, V, V&, const V&> Parent;
1019 /// The key type of the map.
1021 /// The value type of the map.
1023 /// The reference type of the map.
1024 typedef Value& Reference;
1025 /// The const reference type of the map.
1026 typedef const Value& ConstReference;
1028 // The reference map tag.
1029 typedef True ReferenceMapTag;
1031 /// \brief Construct a new map.
1033 /// Construct a new map for the graph.
1034 explicit GraphMap(const GR&) {}
1035 /// \brief Construct a new map with default value.
1037 /// Construct a new map for the graph and initalize the values.
1038 GraphMap(const GR&, const Value&) {}
1041 /// \brief Copy constructor.
1043 /// Copy Constructor.
1044 GraphMap(const GraphMap&) : Parent() {}
1046 /// \brief Assignment operator.
1048 /// Assignment operator. It does not mofify the underlying graph,
1049 /// it just iterates on the current item set and set the map
1050 /// with the value returned by the assigned map.
1051 template <typename CMap>
1052 GraphMap& operator=(const CMap&) {
1053 checkConcept<ReadMap<Key, Value>, CMap>();
1058 template<typename _Map>
1059 struct Constraints {
1060 void constraints() {
1062 <ReferenceMap<Key, Value, Value&, const Value&>, _Map>();
1069 // Assignment operator
1070 // ReadMap<Key, Value> cmap;
1073 ignore_unused_variable_warning(m1);
1074 ignore_unused_variable_warning(m2);
1075 // ignore_unused_variable_warning(m3);
1080 const typename GraphMap::Value &t;
1086 /// \brief Skeleton class for mappable directed graphs.
1088 /// This class describes the interface of mappable directed graphs.
1089 /// It extends \ref BaseDigraphComponent with the standard digraph
1090 /// map classes, namely \c NodeMap and \c ArcMap.
1091 /// This concept is part of the Digraph concept.
1092 template <typename BAS = BaseDigraphComponent>
1093 class MappableDigraphComponent : public BAS {
1097 typedef typename Base::Node Node;
1098 typedef typename Base::Arc Arc;
1100 typedef MappableDigraphComponent Digraph;
1102 /// \brief Standard graph map for the nodes.
1104 /// Standard graph map for the nodes.
1105 /// It conforms to the ReferenceMap concept.
1106 template <typename V>
1107 class NodeMap : public GraphMap<MappableDigraphComponent, Node, V> {
1108 typedef GraphMap<MappableDigraphComponent, Node, V> Parent;
1111 /// \brief Construct a new map.
1113 /// Construct a new map for the digraph.
1114 explicit NodeMap(const MappableDigraphComponent& digraph)
1115 : Parent(digraph) {}
1117 /// \brief Construct a new map with default value.
1119 /// Construct a new map for the digraph and initalize the values.
1120 NodeMap(const MappableDigraphComponent& digraph, const V& value)
1121 : Parent(digraph, value) {}
1124 /// \brief Copy constructor.
1126 /// Copy Constructor.
1127 NodeMap(const NodeMap& nm) : Parent(nm) {}
1129 /// \brief Assignment operator.
1131 /// Assignment operator.
1132 template <typename CMap>
1133 NodeMap& operator=(const CMap&) {
1134 checkConcept<ReadMap<Node, V>, CMap>();
1140 /// \brief Standard graph map for the arcs.
1142 /// Standard graph map for the arcs.
1143 /// It conforms to the ReferenceMap concept.
1144 template <typename V>
1145 class ArcMap : public GraphMap<MappableDigraphComponent, Arc, V> {
1146 typedef GraphMap<MappableDigraphComponent, Arc, V> Parent;
1149 /// \brief Construct a new map.
1151 /// Construct a new map for the digraph.
1152 explicit ArcMap(const MappableDigraphComponent& digraph)
1153 : Parent(digraph) {}
1155 /// \brief Construct a new map with default value.
1157 /// Construct a new map for the digraph and initalize the values.
1158 ArcMap(const MappableDigraphComponent& digraph, const V& value)
1159 : Parent(digraph, value) {}
1162 /// \brief Copy constructor.
1164 /// Copy Constructor.
1165 ArcMap(const ArcMap& nm) : Parent(nm) {}
1167 /// \brief Assignment operator.
1169 /// Assignment operator.
1170 template <typename CMap>
1171 ArcMap& operator=(const CMap&) {
1172 checkConcept<ReadMap<Arc, V>, CMap>();
1179 template <typename _Digraph>
1180 struct Constraints {
1184 Dummy() : value(0) {}
1185 Dummy(int _v) : value(_v) {}
1188 void constraints() {
1189 checkConcept<Base, _Digraph>();
1191 typedef typename _Digraph::template NodeMap<int> IntNodeMap;
1192 checkConcept<GraphMap<_Digraph, typename _Digraph::Node, int>,
1194 } { // bool map test
1195 typedef typename _Digraph::template NodeMap<bool> BoolNodeMap;
1196 checkConcept<GraphMap<_Digraph, typename _Digraph::Node, bool>,
1198 } { // Dummy map test
1199 typedef typename _Digraph::template NodeMap<Dummy> DummyNodeMap;
1200 checkConcept<GraphMap<_Digraph, typename _Digraph::Node, Dummy>,
1205 typedef typename _Digraph::template ArcMap<int> IntArcMap;
1206 checkConcept<GraphMap<_Digraph, typename _Digraph::Arc, int>,
1208 } { // bool map test
1209 typedef typename _Digraph::template ArcMap<bool> BoolArcMap;
1210 checkConcept<GraphMap<_Digraph, typename _Digraph::Arc, bool>,
1212 } { // Dummy map test
1213 typedef typename _Digraph::template ArcMap<Dummy> DummyArcMap;
1214 checkConcept<GraphMap<_Digraph, typename _Digraph::Arc, Dummy>,
1219 const _Digraph& digraph;
1224 /// \brief Skeleton class for mappable undirected graphs.
1226 /// This class describes the interface of mappable undirected graphs.
1227 /// It extends \ref MappableDigraphComponent with the standard graph
1228 /// map class for edges (\c EdgeMap).
1229 /// This concept is part of the Graph concept.
1230 template <typename BAS = BaseGraphComponent>
1231 class MappableGraphComponent : public MappableDigraphComponent<BAS> {
1235 typedef typename Base::Edge Edge;
1237 typedef MappableGraphComponent Graph;
1239 /// \brief Standard graph map for the edges.
1241 /// Standard graph map for the edges.
1242 /// It conforms to the ReferenceMap concept.
1243 template <typename V>
1244 class EdgeMap : public GraphMap<MappableGraphComponent, Edge, V> {
1245 typedef GraphMap<MappableGraphComponent, Edge, V> Parent;
1248 /// \brief Construct a new map.
1250 /// Construct a new map for the graph.
1251 explicit EdgeMap(const MappableGraphComponent& graph)
1254 /// \brief Construct a new map with default value.
1256 /// Construct a new map for the graph and initalize the values.
1257 EdgeMap(const MappableGraphComponent& graph, const V& value)
1258 : Parent(graph, value) {}
1261 /// \brief Copy constructor.
1263 /// Copy Constructor.
1264 EdgeMap(const EdgeMap& nm) : Parent(nm) {}
1266 /// \brief Assignment operator.
1268 /// Assignment operator.
1269 template <typename CMap>
1270 EdgeMap& operator=(const CMap&) {
1271 checkConcept<ReadMap<Edge, V>, CMap>();
1278 template <typename _Graph>
1279 struct Constraints {
1283 Dummy() : value(0) {}
1284 Dummy(int _v) : value(_v) {}
1287 void constraints() {
1288 checkConcept<MappableDigraphComponent<Base>, _Graph>();
1291 typedef typename _Graph::template EdgeMap<int> IntEdgeMap;
1292 checkConcept<GraphMap<_Graph, typename _Graph::Edge, int>,
1294 } { // bool map test
1295 typedef typename _Graph::template EdgeMap<bool> BoolEdgeMap;
1296 checkConcept<GraphMap<_Graph, typename _Graph::Edge, bool>,
1298 } { // Dummy map test
1299 typedef typename _Graph::template EdgeMap<Dummy> DummyEdgeMap;
1300 checkConcept<GraphMap<_Graph, typename _Graph::Edge, Dummy>,
1305 const _Graph& graph;
1310 /// \brief Skeleton class for extendable directed graphs.
1312 /// This class describes the interface of extendable directed graphs.
1313 /// It extends \ref BaseDigraphComponent with functions for adding
1314 /// nodes and arcs to the digraph.
1315 /// This concept requires \ref AlterableDigraphComponent.
1316 template <typename BAS = BaseDigraphComponent>
1317 class ExtendableDigraphComponent : public BAS {
1321 typedef typename Base::Node Node;
1322 typedef typename Base::Arc Arc;
1324 /// \brief Add a new node to the digraph.
1326 /// This function adds a new node to the digraph.
1331 /// \brief Add a new arc connecting the given two nodes.
1333 /// This function adds a new arc connecting the given two nodes
1335 Arc addArc(const Node&, const Node&) {
1339 template <typename _Digraph>
1340 struct Constraints {
1341 void constraints() {
1342 checkConcept<Base, _Digraph>();
1343 typename _Digraph::Node node_a, node_b;
1344 node_a = digraph.addNode();
1345 node_b = digraph.addNode();
1346 typename _Digraph::Arc arc;
1347 arc = digraph.addArc(node_a, node_b);
1355 /// \brief Skeleton class for extendable undirected graphs.
1357 /// This class describes the interface of extendable undirected graphs.
1358 /// It extends \ref BaseGraphComponent with functions for adding
1359 /// nodes and edges to the graph.
1360 /// This concept requires \ref AlterableGraphComponent.
1361 template <typename BAS = BaseGraphComponent>
1362 class ExtendableGraphComponent : public BAS {
1366 typedef typename Base::Node Node;
1367 typedef typename Base::Edge Edge;
1369 /// \brief Add a new node to the digraph.
1371 /// This function adds a new node to the digraph.
1376 /// \brief Add a new edge connecting the given two nodes.
1378 /// This function adds a new edge connecting the given two nodes
1380 Edge addEdge(const Node&, const Node&) {
1384 template <typename _Graph>
1385 struct Constraints {
1386 void constraints() {
1387 checkConcept<Base, _Graph>();
1388 typename _Graph::Node node_a, node_b;
1389 node_a = graph.addNode();
1390 node_b = graph.addNode();
1391 typename _Graph::Edge edge;
1392 edge = graph.addEdge(node_a, node_b);
1400 /// \brief Skeleton class for erasable directed graphs.
1402 /// This class describes the interface of erasable directed graphs.
1403 /// It extends \ref BaseDigraphComponent with functions for removing
1404 /// nodes and arcs from the digraph.
1405 /// This concept requires \ref AlterableDigraphComponent.
1406 template <typename BAS = BaseDigraphComponent>
1407 class ErasableDigraphComponent : public BAS {
1411 typedef typename Base::Node Node;
1412 typedef typename Base::Arc Arc;
1414 /// \brief Erase a node from the digraph.
1416 /// This function erases the given node from the digraph and all arcs
1417 /// connected to the node.
1418 void erase(const Node&) {}
1420 /// \brief Erase an arc from the digraph.
1422 /// This function erases the given arc from the digraph.
1423 void erase(const Arc&) {}
1425 template <typename _Digraph>
1426 struct Constraints {
1427 void constraints() {
1428 checkConcept<Base, _Digraph>();
1429 const typename _Digraph::Node node(INVALID);
1430 digraph.erase(node);
1431 const typename _Digraph::Arc arc(INVALID);
1440 /// \brief Skeleton class for erasable undirected graphs.
1442 /// This class describes the interface of erasable undirected graphs.
1443 /// It extends \ref BaseGraphComponent with functions for removing
1444 /// nodes and edges from the graph.
1445 /// This concept requires \ref AlterableGraphComponent.
1446 template <typename BAS = BaseGraphComponent>
1447 class ErasableGraphComponent : public BAS {
1451 typedef typename Base::Node Node;
1452 typedef typename Base::Edge Edge;
1454 /// \brief Erase a node from the graph.
1456 /// This function erases the given node from the graph and all edges
1457 /// connected to the node.
1458 void erase(const Node&) {}
1460 /// \brief Erase an edge from the digraph.
1462 /// This function erases the given edge from the digraph.
1463 void erase(const Edge&) {}
1465 template <typename _Graph>
1466 struct Constraints {
1467 void constraints() {
1468 checkConcept<Base, _Graph>();
1469 const typename _Graph::Node node(INVALID);
1471 const typename _Graph::Edge edge(INVALID);
1480 /// \brief Skeleton class for clearable directed graphs.
1482 /// This class describes the interface of clearable directed graphs.
1483 /// It extends \ref BaseDigraphComponent with a function for clearing
1485 /// This concept requires \ref AlterableDigraphComponent.
1486 template <typename BAS = BaseDigraphComponent>
1487 class ClearableDigraphComponent : public BAS {
1492 /// \brief Erase all nodes and arcs from the digraph.
1494 /// This function erases all nodes and arcs from the digraph.
1497 template <typename _Digraph>
1498 struct Constraints {
1499 void constraints() {
1500 checkConcept<Base, _Digraph>();
1509 /// \brief Skeleton class for clearable undirected graphs.
1511 /// This class describes the interface of clearable undirected graphs.
1512 /// It extends \ref BaseGraphComponent with a function for clearing
1514 /// This concept requires \ref AlterableGraphComponent.
1515 template <typename BAS = BaseGraphComponent>
1516 class ClearableGraphComponent : public ClearableDigraphComponent<BAS> {
1521 /// \brief Erase all nodes and edges from the graph.
1523 /// This function erases all nodes and edges from the graph.
1526 template <typename _Graph>
1527 struct Constraints {
1528 void constraints() {
1529 checkConcept<Base, _Graph>();