Set the proper version for CMAKE in the tarballs (made by autotools).
1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
3 * This file is a part of LEMON, a generic C++ optimization library.
5 * Copyright (C) 2003-2008
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.
24 #ifndef LEMON_CONCEPT_GRAPH_COMPONENTS_H
25 #define LEMON_CONCEPT_GRAPH_COMPONENTS_H
27 #include <lemon/core.h>
28 #include <lemon/concepts/maps.h>
30 #include <lemon/bits/alteration_notifier.h>
35 /// \brief Skeleton class for graph Node and Arc types
37 /// This class describes the interface of Node and Arc (and Edge
38 /// in undirected graphs) subtypes of graph types.
40 /// \note This class is a template class so that we can use it to
41 /// create graph skeleton classes. The reason for this is than Node
42 /// and Arc types should \em not derive from the same base class.
43 /// For Node you should instantiate it with character 'n' and for Arc
47 template <char _selector = '0'>
51 /// \brief Default constructor.
53 /// \warning The default constructor is not required to set
54 /// the item to some well-defined value. So you should consider it
57 /// \brief Copy constructor.
61 GraphItem(const GraphItem &) {}
62 /// \brief Invalid constructor \& conversion.
64 /// This constructor initializes the item to be invalid.
65 /// \sa Invalid for more details.
67 /// \brief Assign operator for nodes.
69 /// The nodes are assignable.
71 GraphItem& operator=(GraphItem const&) { return *this; }
72 /// \brief Equality operator.
74 /// Two iterators are equal if and only if they represents the
75 /// same node in the graph or both are invalid.
76 bool operator==(GraphItem) const { return false; }
77 /// \brief Inequality operator.
79 /// \sa operator==(const Node& n)
81 bool operator!=(GraphItem) const { return false; }
83 /// \brief Artificial ordering operator.
85 /// To allow the use of graph descriptors as key type in std::map or
86 /// similar associative container we require this.
88 /// \note This operator only have to define some strict ordering of
89 /// the items; this order has nothing to do with the iteration
90 /// ordering of the items.
91 bool operator<(GraphItem) const { return false; }
93 template<typename _GraphItem>
98 _GraphItem i3 = INVALID;
103 // b = (ia == ib) && (ia != ib) && (ia < ib);
104 b = (ia == ib) && (ia != ib);
105 b = (ia == INVALID) && (ib != INVALID);
109 const _GraphItem &ia;
110 const _GraphItem &ib;
114 /// \brief An empty base directed graph class.
116 /// This class provides the minimal set of features needed for a
117 /// directed graph structure. All digraph concepts have to be
118 /// conform to this base directed graph. It just provides types
119 /// for nodes and arcs and functions to get the source and the
120 /// target of the arcs.
121 class BaseDigraphComponent {
124 typedef BaseDigraphComponent Digraph;
126 /// \brief Node class of the digraph.
128 /// This class represents the Nodes of the digraph.
130 typedef GraphItem<'n'> Node;
132 /// \brief Arc class of the digraph.
134 /// This class represents the Arcs of the digraph.
136 typedef GraphItem<'e'> Arc;
138 /// \brief Gives back the target node of an arc.
140 /// Gives back the target node of an arc.
142 Node target(const Arc&) const { return INVALID;}
144 /// \brief Gives back the source node of an arc.
146 /// Gives back the source node of an arc.
148 Node source(const Arc&) const { return INVALID;}
150 /// \brief Gives back the opposite node on the given arc.
152 /// Gives back the opposite node on the given arc.
153 Node oppositeNode(const Node&, const Arc&) const {
157 template <typename _Digraph>
159 typedef typename _Digraph::Node Node;
160 typedef typename _Digraph::Arc Arc;
163 checkConcept<GraphItem<'n'>, Node>();
164 checkConcept<GraphItem<'a'>, Arc>();
168 n = digraph.source(e);
169 n = digraph.target(e);
170 n = digraph.oppositeNode(n, e);
174 const _Digraph& digraph;
178 /// \brief An empty base undirected graph class.
180 /// This class provides the minimal set of features needed for an
181 /// undirected graph structure. All undirected graph concepts have
182 /// to be conform to this base graph. It just provides types for
183 /// nodes, arcs and edges and functions to get the
184 /// source and the target of the arcs and edges,
185 /// conversion from arcs to edges and function to get
186 /// both direction of the edges.
187 class BaseGraphComponent : public BaseDigraphComponent {
189 typedef BaseDigraphComponent::Node Node;
190 typedef BaseDigraphComponent::Arc Arc;
191 /// \brief Undirected arc class of the graph.
193 /// This class represents the edges of the graph.
194 /// The undirected graphs can be used as a directed graph which
195 /// for each arc contains the opposite arc too so the graph is
196 /// bidirected. The edge represents two opposite
198 class Edge : public GraphItem<'u'> {
200 typedef GraphItem<'u'> Parent;
201 /// \brief Default constructor.
203 /// \warning The default constructor is not required to set
204 /// the item to some well-defined value. So you should consider it
205 /// as uninitialized.
207 /// \brief Copy constructor.
209 /// Copy constructor.
211 Edge(const Edge &) : Parent() {}
212 /// \brief Invalid constructor \& conversion.
214 /// This constructor initializes the item to be invalid.
215 /// \sa Invalid for more details.
217 /// \brief Converter from arc to edge.
219 /// Besides the core graph item functionality each arc should
220 /// be convertible to the represented edge.
222 /// \brief Assign arc to edge.
224 /// Besides the core graph item functionality each arc should
225 /// be convertible to the represented edge.
226 Edge& operator=(const Arc&) { return *this; }
229 /// \brief Returns the direction of the arc.
231 /// Returns the direction of the arc. Each arc represents an
232 /// edge with a direction. It gives back the
234 bool direction(const Arc&) const { return true; }
236 /// \brief Returns the directed arc.
238 /// Returns the directed arc from its direction and the
239 /// represented edge.
240 Arc direct(const Edge&, bool) const { return INVALID;}
242 /// \brief Returns the directed arc.
244 /// Returns the directed arc from its source and the
245 /// represented edge.
246 Arc direct(const Edge&, const Node&) const { return INVALID;}
248 /// \brief Returns the opposite arc.
250 /// Returns the opposite arc. It is the arc representing the
251 /// same edge and has opposite direction.
252 Arc oppositeArc(const Arc&) const { return INVALID;}
254 /// \brief Gives back one ending of an edge.
256 /// Gives back one ending of an edge.
257 Node u(const Edge&) const { return INVALID;}
259 /// \brief Gives back the other ending of an edge.
261 /// Gives back the other ending of an edge.
262 Node v(const Edge&) const { return INVALID;}
264 template <typename _Graph>
266 typedef typename _Graph::Node Node;
267 typedef typename _Graph::Arc Arc;
268 typedef typename _Graph::Edge Edge;
271 checkConcept<BaseDigraphComponent, _Graph>();
272 checkConcept<GraphItem<'u'>, Edge>();
279 e = graph.direct(ue, true);
280 e = graph.direct(ue, n);
281 e = graph.oppositeArc(e);
283 bool d = graph.direction(e);
284 ignore_unused_variable_warning(d);
293 /// \brief An empty idable base digraph class.
295 /// This class provides beside the core digraph features
296 /// core id functions for the digraph structure.
297 /// The most of the base digraphs should be conform to this concept.
298 /// The id's are unique and immutable.
299 template <typename _Base = BaseDigraphComponent>
300 class IDableDigraphComponent : public _Base {
304 typedef typename Base::Node Node;
305 typedef typename Base::Arc Arc;
307 /// \brief Gives back an unique integer id for the Node.
309 /// Gives back an unique integer id for the Node.
311 int id(const Node&) const { return -1;}
313 /// \brief Gives back the node by the unique id.
315 /// Gives back the node by the unique id.
316 /// If the digraph does not contain node with the given id
317 /// then the result of the function is undetermined.
318 Node nodeFromId(int) const { return INVALID;}
320 /// \brief Gives back an unique integer id for the Arc.
322 /// Gives back an unique integer id for the Arc.
324 int id(const Arc&) const { return -1;}
326 /// \brief Gives back the arc by the unique id.
328 /// Gives back the arc by the unique id.
329 /// If the digraph does not contain arc with the given id
330 /// then the result of the function is undetermined.
331 Arc arcFromId(int) const { return INVALID;}
333 /// \brief Gives back an integer greater or equal to the maximum
336 /// Gives back an integer greater or equal to the maximum Node
338 int maxNodeId() const { return -1;}
340 /// \brief Gives back an integer greater or equal to the maximum
343 /// Gives back an integer greater or equal to the maximum Arc
345 int maxArcId() const { return -1;}
347 template <typename _Digraph>
351 checkConcept<Base, _Digraph >();
352 typename _Digraph::Node node;
353 int nid = digraph.id(node);
354 nid = digraph.id(node);
355 node = digraph.nodeFromId(nid);
356 typename _Digraph::Arc arc;
357 int eid = digraph.id(arc);
358 eid = digraph.id(arc);
359 arc = digraph.arcFromId(eid);
361 nid = digraph.maxNodeId();
362 ignore_unused_variable_warning(nid);
363 eid = digraph.maxArcId();
364 ignore_unused_variable_warning(eid);
367 const _Digraph& digraph;
371 /// \brief An empty idable base undirected graph class.
373 /// This class provides beside the core undirected graph features
374 /// core id functions for the undirected graph structure. The
375 /// most of the base undirected graphs should be conform to this
376 /// concept. The id's are unique and immutable.
377 template <typename _Base = BaseGraphComponent>
378 class IDableGraphComponent : public IDableDigraphComponent<_Base> {
382 typedef typename Base::Edge Edge;
384 using IDableDigraphComponent<_Base>::id;
386 /// \brief Gives back an unique integer id for the Edge.
388 /// Gives back an unique integer id for the Edge.
390 int id(const Edge&) const { return -1;}
392 /// \brief Gives back the edge by the unique id.
394 /// Gives back the edge by the unique id. If the
395 /// graph does not contain arc with the given id then the
396 /// result of the function is undetermined.
397 Edge edgeFromId(int) const { return INVALID;}
399 /// \brief Gives back an integer greater or equal to the maximum
402 /// Gives back an integer greater or equal to the maximum Edge
404 int maxEdgeId() const { return -1;}
406 template <typename _Graph>
410 checkConcept<Base, _Graph >();
411 checkConcept<IDableDigraphComponent<Base>, _Graph >();
412 typename _Graph::Edge edge;
413 int ueid = graph.id(edge);
414 ueid = graph.id(edge);
415 edge = graph.edgeFromId(ueid);
416 ueid = graph.maxEdgeId();
417 ignore_unused_variable_warning(ueid);
424 /// \brief Skeleton class for graph NodeIt and ArcIt
426 /// Skeleton class for graph NodeIt and ArcIt.
428 template <typename _Graph, typename _Item>
429 class GraphItemIt : public _Item {
431 /// \brief Default constructor.
433 /// @warning The default constructor sets the iterator
434 /// to an undefined value.
436 /// \brief Copy constructor.
438 /// Copy constructor.
440 GraphItemIt(const GraphItemIt& ) {}
441 /// \brief Sets the iterator to the first item.
443 /// Sets the iterator to the first item of \c the graph.
445 explicit GraphItemIt(const _Graph&) {}
446 /// \brief Invalid constructor \& conversion.
448 /// This constructor initializes the item to be invalid.
449 /// \sa Invalid for more details.
450 GraphItemIt(Invalid) {}
451 /// \brief Assign operator for items.
453 /// The items are assignable.
455 GraphItemIt& operator=(const GraphItemIt&) { return *this; }
456 /// \brief Next item.
458 /// Assign the iterator to the next item.
460 GraphItemIt& operator++() { return *this; }
461 /// \brief Equality operator
463 /// Two iterators are equal if and only if they point to the
464 /// same object or both are invalid.
465 bool operator==(const GraphItemIt&) const { return true;}
466 /// \brief Inequality operator
468 /// \sa operator==(Node n)
470 bool operator!=(const GraphItemIt&) const { return true;}
472 template<typename _GraphItemIt>
489 /// \brief Skeleton class for graph InArcIt and OutArcIt
491 /// \note Because InArcIt and OutArcIt may not inherit from the same
492 /// base class, the _selector is a additional template parameter. For
493 /// InArcIt you should instantiate it with character 'i' and for
494 /// OutArcIt with 'o'.
495 template <typename _Graph,
496 typename _Item = typename _Graph::Arc,
497 typename _Base = typename _Graph::Node,
498 char _selector = '0'>
499 class GraphIncIt : public _Item {
501 /// \brief Default constructor.
503 /// @warning The default constructor sets the iterator
504 /// to an undefined value.
506 /// \brief Copy constructor.
508 /// Copy constructor.
510 GraphIncIt(GraphIncIt const& gi) : _Item(gi) {}
511 /// \brief Sets the iterator to the first arc incoming into or outgoing
514 /// Sets the iterator to the first arc incoming into or outgoing
517 explicit GraphIncIt(const _Graph&, const _Base&) {}
518 /// \brief Invalid constructor \& conversion.
520 /// This constructor initializes the item to be invalid.
521 /// \sa Invalid for more details.
522 GraphIncIt(Invalid) {}
523 /// \brief Assign operator for iterators.
525 /// The iterators are assignable.
527 GraphIncIt& operator=(GraphIncIt const&) { return *this; }
528 /// \brief Next item.
530 /// Assign the iterator to the next item.
532 GraphIncIt& operator++() { return *this; }
534 /// \brief Equality operator
536 /// Two iterators are equal if and only if they point to the
537 /// same object or both are invalid.
538 bool operator==(const GraphIncIt&) const { return true;}
540 /// \brief Inequality operator
542 /// \sa operator==(Node n)
544 bool operator!=(const GraphIncIt&) const { return true;}
546 template <typename _GraphIncIt>
549 checkConcept<GraphItem<_selector>, _GraphIncIt>();
550 _GraphIncIt it1(graph, node);
569 /// \brief An empty iterable digraph class.
571 /// This class provides beside the core digraph features
572 /// iterator based iterable interface for the digraph structure.
573 /// This concept is part of the Digraph concept.
574 template <typename _Base = BaseDigraphComponent>
575 class IterableDigraphComponent : public _Base {
580 typedef typename Base::Node Node;
581 typedef typename Base::Arc Arc;
583 typedef IterableDigraphComponent Digraph;
585 /// \name Base iteration
587 /// This interface provides functions for iteration on digraph items
591 /// \brief Gives back the first node in the iterating order.
593 /// Gives back the first node in the iterating order.
595 void first(Node&) const {}
597 /// \brief Gives back the next node in the iterating order.
599 /// Gives back the next node in the iterating order.
601 void next(Node&) const {}
603 /// \brief Gives back the first arc in the iterating order.
605 /// Gives back the first arc in the iterating order.
607 void first(Arc&) const {}
609 /// \brief Gives back the next arc in the iterating order.
611 /// Gives back the next arc in the iterating order.
613 void next(Arc&) const {}
616 /// \brief Gives back the first of the arcs point to the given
619 /// Gives back the first of the arcs point to the given node.
621 void firstIn(Arc&, const Node&) const {}
623 /// \brief Gives back the next of the arcs points to the given
626 /// Gives back the next of the arcs points to the given node.
628 void nextIn(Arc&) const {}
630 /// \brief Gives back the first of the arcs start from the
633 /// Gives back the first of the arcs start from the given node.
635 void firstOut(Arc&, const Node&) const {}
637 /// \brief Gives back the next of the arcs start from the given
640 /// Gives back the next of the arcs start from the given node.
642 void nextOut(Arc&) const {}
646 /// \name Class based iteration
648 /// This interface provides functions for iteration on digraph items
652 /// \brief This iterator goes through each node.
654 /// This iterator goes through each node.
656 typedef GraphItemIt<Digraph, Node> NodeIt;
658 /// \brief This iterator goes through each node.
660 /// This iterator goes through each node.
662 typedef GraphItemIt<Digraph, Arc> ArcIt;
664 /// \brief This iterator goes trough the incoming arcs of a node.
666 /// This iterator goes trough the \e inccoming arcs of a certain node
668 typedef GraphIncIt<Digraph, Arc, Node, 'i'> InArcIt;
670 /// \brief This iterator goes trough the outgoing arcs of a node.
672 /// This iterator goes trough the \e outgoing arcs of a certain node
674 typedef GraphIncIt<Digraph, Arc, Node, 'o'> OutArcIt;
676 /// \brief The base node of the iterator.
678 /// Gives back the base node of the iterator.
679 /// It is always the target of the pointed arc.
680 Node baseNode(const InArcIt&) const { return INVALID; }
682 /// \brief The running node of the iterator.
684 /// Gives back the running node of the iterator.
685 /// It is always the source of the pointed arc.
686 Node runningNode(const InArcIt&) const { return INVALID; }
688 /// \brief The base node of the iterator.
690 /// Gives back the base node of the iterator.
691 /// It is always the source of the pointed arc.
692 Node baseNode(const OutArcIt&) const { return INVALID; }
694 /// \brief The running node of the iterator.
696 /// Gives back the running node of the iterator.
697 /// It is always the target of the pointed arc.
698 Node runningNode(const OutArcIt&) const { return INVALID; }
702 template <typename _Digraph>
705 checkConcept<Base, _Digraph>();
708 typename _Digraph::Node node(INVALID);
709 typename _Digraph::Arc arc(INVALID);
719 digraph.firstIn(arc, node);
723 digraph.firstOut(arc, node);
724 digraph.nextOut(arc);
729 checkConcept<GraphItemIt<_Digraph, typename _Digraph::Arc>,
730 typename _Digraph::ArcIt >();
731 checkConcept<GraphItemIt<_Digraph, typename _Digraph::Node>,
732 typename _Digraph::NodeIt >();
733 checkConcept<GraphIncIt<_Digraph, typename _Digraph::Arc,
734 typename _Digraph::Node, 'i'>, typename _Digraph::InArcIt>();
735 checkConcept<GraphIncIt<_Digraph, typename _Digraph::Arc,
736 typename _Digraph::Node, 'o'>, typename _Digraph::OutArcIt>();
738 typename _Digraph::Node n;
739 typename _Digraph::InArcIt ieit(INVALID);
740 typename _Digraph::OutArcIt oeit(INVALID);
741 n = digraph.baseNode(ieit);
742 n = digraph.runningNode(ieit);
743 n = digraph.baseNode(oeit);
744 n = digraph.runningNode(oeit);
745 ignore_unused_variable_warning(n);
749 const _Digraph& digraph;
754 /// \brief An empty iterable undirected graph class.
756 /// This class provides beside the core graph features iterator
757 /// based iterable interface for the undirected graph structure.
758 /// This concept is part of the Graph concept.
759 template <typename _Base = BaseGraphComponent>
760 class IterableGraphComponent : public IterableDigraphComponent<_Base> {
764 typedef typename Base::Node Node;
765 typedef typename Base::Arc Arc;
766 typedef typename Base::Edge Edge;
769 typedef IterableGraphComponent Graph;
771 /// \name Base iteration
773 /// This interface provides functions for iteration on graph items
776 using IterableDigraphComponent<_Base>::first;
777 using IterableDigraphComponent<_Base>::next;
779 /// \brief Gives back the first edge in the iterating
782 /// Gives back the first edge in the iterating order.
784 void first(Edge&) const {}
786 /// \brief Gives back the next edge in the iterating
789 /// Gives back the next edge in the iterating order.
791 void next(Edge&) const {}
794 /// \brief Gives back the first of the edges from the
797 /// Gives back the first of the edges from the given
798 /// node. The bool parameter gives back that direction which
799 /// gives a good direction of the edge so the source of the
800 /// directed arc is the given node.
801 void firstInc(Edge&, bool&, const Node&) const {}
803 /// \brief Gives back the next of the edges from the
806 /// Gives back the next of the edges from the given
807 /// node. The bool parameter should be used as the \c firstInc()
809 void nextInc(Edge&, bool&) const {}
811 using IterableDigraphComponent<_Base>::baseNode;
812 using IterableDigraphComponent<_Base>::runningNode;
816 /// \name Class based iteration
818 /// This interface provides functions for iteration on graph items
822 /// \brief This iterator goes through each node.
824 /// This iterator goes through each node.
825 typedef GraphItemIt<Graph, Edge> EdgeIt;
826 /// \brief This iterator goes trough the incident arcs of a
829 /// This iterator goes trough the incident arcs of a certain
831 typedef GraphIncIt<Graph, Edge, Node, 'u'> IncEdgeIt;
832 /// \brief The base node of the iterator.
834 /// Gives back the base node of the iterator.
835 Node baseNode(const IncEdgeIt&) const { return INVALID; }
837 /// \brief The running node of the iterator.
839 /// Gives back the running node of the iterator.
840 Node runningNode(const IncEdgeIt&) const { return INVALID; }
844 template <typename _Graph>
847 checkConcept<IterableDigraphComponent<Base>, _Graph>();
850 typename _Graph::Node node(INVALID);
851 typename _Graph::Edge edge(INVALID);
858 graph.firstInc(edge, dir, node);
859 graph.nextInc(edge, dir);
865 checkConcept<GraphItemIt<_Graph, typename _Graph::Edge>,
866 typename _Graph::EdgeIt >();
867 checkConcept<GraphIncIt<_Graph, typename _Graph::Edge,
868 typename _Graph::Node, 'u'>, typename _Graph::IncEdgeIt>();
870 typename _Graph::Node n;
871 typename _Graph::IncEdgeIt ueit(INVALID);
872 n = graph.baseNode(ueit);
873 n = graph.runningNode(ueit);
882 /// \brief An empty alteration notifier digraph class.
884 /// This class provides beside the core digraph features alteration
885 /// notifier interface for the digraph structure. This implements
886 /// an observer-notifier pattern for each digraph item. More
887 /// obsevers can be registered into the notifier and whenever an
888 /// alteration occured in the digraph all the observers will
889 /// notified about it.
890 template <typename _Base = BaseDigraphComponent>
891 class AlterableDigraphComponent : public _Base {
895 typedef typename Base::Node Node;
896 typedef typename Base::Arc Arc;
899 /// The node observer registry.
900 typedef AlterationNotifier<AlterableDigraphComponent, Node>
902 /// The arc observer registry.
903 typedef AlterationNotifier<AlterableDigraphComponent, Arc>
906 /// \brief Gives back the node alteration notifier.
908 /// Gives back the node alteration notifier.
909 NodeNotifier& notifier(Node) const {
910 return NodeNotifier();
913 /// \brief Gives back the arc alteration notifier.
915 /// Gives back the arc alteration notifier.
916 ArcNotifier& notifier(Arc) const {
917 return ArcNotifier();
920 template <typename _Digraph>
923 checkConcept<Base, _Digraph>();
924 typename _Digraph::NodeNotifier& nn
925 = digraph.notifier(typename _Digraph::Node());
927 typename _Digraph::ArcNotifier& en
928 = digraph.notifier(typename _Digraph::Arc());
930 ignore_unused_variable_warning(nn);
931 ignore_unused_variable_warning(en);
934 const _Digraph& digraph;
940 /// \brief An empty alteration notifier undirected graph class.
942 /// This class provides beside the core graph features alteration
943 /// notifier interface for the graph structure. This implements
944 /// an observer-notifier pattern for each graph item. More
945 /// obsevers can be registered into the notifier and whenever an
946 /// alteration occured in the graph all the observers will
947 /// notified about it.
948 template <typename _Base = BaseGraphComponent>
949 class AlterableGraphComponent : public AlterableDigraphComponent<_Base> {
953 typedef typename Base::Edge Edge;
956 /// The arc observer registry.
957 typedef AlterationNotifier<AlterableGraphComponent, Edge>
960 /// \brief Gives back the arc alteration notifier.
962 /// Gives back the arc alteration notifier.
963 EdgeNotifier& notifier(Edge) const {
964 return EdgeNotifier();
967 template <typename _Graph>
970 checkConcept<AlterableGraphComponent<Base>, _Graph>();
971 typename _Graph::EdgeNotifier& uen
972 = graph.notifier(typename _Graph::Edge());
973 ignore_unused_variable_warning(uen);
982 /// \brief Class describing the concept of graph maps
984 /// This class describes the common interface of the graph maps
985 /// (NodeMap, ArcMap), that is maps that can be used to
986 /// associate data to graph descriptors (nodes or arcs).
987 template <typename _Graph, typename _Item, typename _Value>
988 class GraphMap : public ReadWriteMap<_Item, _Value> {
991 typedef ReadWriteMap<_Item, _Value> Parent;
993 /// The graph type of the map.
994 typedef _Graph Graph;
995 /// The key type of the map.
997 /// The value type of the map.
998 typedef _Value Value;
1000 /// \brief Construct a new map.
1002 /// Construct a new map for the graph.
1003 explicit GraphMap(const Graph&) {}
1004 /// \brief Construct a new map with default value.
1006 /// Construct a new map for the graph and initalise the values.
1007 GraphMap(const Graph&, const Value&) {}
1010 /// \brief Copy constructor.
1012 /// Copy Constructor.
1013 GraphMap(const GraphMap&) : Parent() {}
1015 /// \brief Assign operator.
1017 /// Assign operator. It does not mofify the underlying graph,
1018 /// it just iterates on the current item set and set the map
1019 /// with the value returned by the assigned map.
1020 template <typename CMap>
1021 GraphMap& operator=(const CMap&) {
1022 checkConcept<ReadMap<Key, Value>, CMap>();
1027 template<typename _Map>
1028 struct Constraints {
1029 void constraints() {
1030 checkConcept<ReadWriteMap<Key, Value>, _Map >();
1031 // Construction with a graph parameter
1033 // Constructor with a graph and a default value parameter
1035 // Copy constructor.
1038 // ReadMap<Key, Value> cmap;
1041 ignore_unused_variable_warning(a);
1042 ignore_unused_variable_warning(a2);
1043 // ignore_unused_variable_warning(b);
1048 const typename GraphMap::Value &t;
1053 /// \brief An empty mappable digraph class.
1055 /// This class provides beside the core digraph features
1056 /// map interface for the digraph structure.
1057 /// This concept is part of the Digraph concept.
1058 template <typename _Base = BaseDigraphComponent>
1059 class MappableDigraphComponent : public _Base {
1063 typedef typename Base::Node Node;
1064 typedef typename Base::Arc Arc;
1066 typedef MappableDigraphComponent Digraph;
1068 /// \brief ReadWrite map of the nodes.
1070 /// ReadWrite map of the nodes.
1072 template <typename _Value>
1073 class NodeMap : public GraphMap<Digraph, Node, _Value> {
1075 typedef GraphMap<MappableDigraphComponent, Node, _Value> Parent;
1077 /// \brief Construct a new map.
1079 /// Construct a new map for the digraph.
1080 explicit NodeMap(const MappableDigraphComponent& digraph)
1081 : Parent(digraph) {}
1083 /// \brief Construct a new map with default value.
1085 /// Construct a new map for the digraph and initalise the values.
1086 NodeMap(const MappableDigraphComponent& digraph, const _Value& value)
1087 : Parent(digraph, value) {}
1090 /// \brief Copy constructor.
1092 /// Copy Constructor.
1093 NodeMap(const NodeMap& nm) : Parent(nm) {}
1095 /// \brief Assign operator.
1097 /// Assign operator.
1098 template <typename CMap>
1099 NodeMap& operator=(const CMap&) {
1100 checkConcept<ReadMap<Node, _Value>, CMap>();
1106 /// \brief ReadWrite map of the arcs.
1108 /// ReadWrite map of the arcs.
1110 template <typename _Value>
1111 class ArcMap : public GraphMap<Digraph, Arc, _Value> {
1113 typedef GraphMap<MappableDigraphComponent, Arc, _Value> Parent;
1115 /// \brief Construct a new map.
1117 /// Construct a new map for the digraph.
1118 explicit ArcMap(const MappableDigraphComponent& digraph)
1119 : Parent(digraph) {}
1121 /// \brief Construct a new map with default value.
1123 /// Construct a new map for the digraph and initalise the values.
1124 ArcMap(const MappableDigraphComponent& digraph, const _Value& value)
1125 : Parent(digraph, value) {}
1128 /// \brief Copy constructor.
1130 /// Copy Constructor.
1131 ArcMap(const ArcMap& nm) : Parent(nm) {}
1133 /// \brief Assign operator.
1135 /// Assign operator.
1136 template <typename CMap>
1137 ArcMap& operator=(const CMap&) {
1138 checkConcept<ReadMap<Arc, _Value>, CMap>();
1145 template <typename _Digraph>
1146 struct Constraints {
1150 Dummy() : value(0) {}
1151 Dummy(int _v) : value(_v) {}
1154 void constraints() {
1155 checkConcept<Base, _Digraph>();
1157 typedef typename _Digraph::template NodeMap<int> IntNodeMap;
1158 checkConcept<GraphMap<_Digraph, typename _Digraph::Node, int>,
1160 } { // bool map test
1161 typedef typename _Digraph::template NodeMap<bool> BoolNodeMap;
1162 checkConcept<GraphMap<_Digraph, typename _Digraph::Node, bool>,
1164 } { // Dummy map test
1165 typedef typename _Digraph::template NodeMap<Dummy> DummyNodeMap;
1166 checkConcept<GraphMap<_Digraph, typename _Digraph::Node, Dummy>,
1171 typedef typename _Digraph::template ArcMap<int> IntArcMap;
1172 checkConcept<GraphMap<_Digraph, typename _Digraph::Arc, int>,
1174 } { // bool map test
1175 typedef typename _Digraph::template ArcMap<bool> BoolArcMap;
1176 checkConcept<GraphMap<_Digraph, typename _Digraph::Arc, bool>,
1178 } { // Dummy map test
1179 typedef typename _Digraph::template ArcMap<Dummy> DummyArcMap;
1180 checkConcept<GraphMap<_Digraph, typename _Digraph::Arc, Dummy>,
1189 /// \brief An empty mappable base bipartite graph class.
1191 /// This class provides beside the core graph features
1192 /// map interface for the graph structure.
1193 /// This concept is part of the Graph concept.
1194 template <typename _Base = BaseGraphComponent>
1195 class MappableGraphComponent : public MappableDigraphComponent<_Base> {
1199 typedef typename Base::Edge Edge;
1201 typedef MappableGraphComponent Graph;
1203 /// \brief ReadWrite map of the edges.
1205 /// ReadWrite map of the edges.
1207 template <typename _Value>
1208 class EdgeMap : public GraphMap<Graph, Edge, _Value> {
1210 typedef GraphMap<MappableGraphComponent, Edge, _Value> Parent;
1212 /// \brief Construct a new map.
1214 /// Construct a new map for the graph.
1215 explicit EdgeMap(const MappableGraphComponent& graph)
1218 /// \brief Construct a new map with default value.
1220 /// Construct a new map for the graph and initalise the values.
1221 EdgeMap(const MappableGraphComponent& graph, const _Value& value)
1222 : Parent(graph, value) {}
1225 /// \brief Copy constructor.
1227 /// Copy Constructor.
1228 EdgeMap(const EdgeMap& nm) : Parent(nm) {}
1230 /// \brief Assign operator.
1232 /// Assign operator.
1233 template <typename CMap>
1234 EdgeMap& operator=(const CMap&) {
1235 checkConcept<ReadMap<Edge, _Value>, CMap>();
1242 template <typename _Graph>
1243 struct Constraints {
1247 Dummy() : value(0) {}
1248 Dummy(int _v) : value(_v) {}
1251 void constraints() {
1252 checkConcept<MappableGraphComponent<Base>, _Graph>();
1255 typedef typename _Graph::template EdgeMap<int> IntEdgeMap;
1256 checkConcept<GraphMap<_Graph, typename _Graph::Edge, int>,
1258 } { // bool map test
1259 typedef typename _Graph::template EdgeMap<bool> BoolEdgeMap;
1260 checkConcept<GraphMap<_Graph, typename _Graph::Edge, bool>,
1262 } { // Dummy map test
1263 typedef typename _Graph::template EdgeMap<Dummy> DummyEdgeMap;
1264 checkConcept<GraphMap<_Graph, typename _Graph::Edge, Dummy>,
1273 /// \brief An empty extendable digraph class.
1275 /// This class provides beside the core digraph features digraph
1276 /// extendable interface for the digraph structure. The main
1277 /// difference between the base and this interface is that the
1278 /// digraph alterations should handled already on this level.
1279 template <typename _Base = BaseDigraphComponent>
1280 class ExtendableDigraphComponent : public _Base {
1284 typedef typename _Base::Node Node;
1285 typedef typename _Base::Arc Arc;
1287 /// \brief Adds a new node to the digraph.
1289 /// Adds a new node to the digraph.
1295 /// \brief Adds a new arc connects the given two nodes.
1297 /// Adds a new arc connects the the given two nodes.
1298 Arc addArc(const Node&, const Node&) {
1302 template <typename _Digraph>
1303 struct Constraints {
1304 void constraints() {
1305 checkConcept<Base, _Digraph>();
1306 typename _Digraph::Node node_a, node_b;
1307 node_a = digraph.addNode();
1308 node_b = digraph.addNode();
1309 typename _Digraph::Arc arc;
1310 arc = digraph.addArc(node_a, node_b);
1317 /// \brief An empty extendable base undirected graph class.
1319 /// This class provides beside the core undirected graph features
1320 /// core undircted graph extend interface for the graph structure.
1321 /// The main difference between the base and this interface is
1322 /// that the graph alterations should handled already on this
1324 template <typename _Base = BaseGraphComponent>
1325 class ExtendableGraphComponent : public _Base {
1329 typedef typename _Base::Node Node;
1330 typedef typename _Base::Edge Edge;
1332 /// \brief Adds a new node to the graph.
1334 /// Adds a new node to the graph.
1340 /// \brief Adds a new arc connects the given two nodes.
1342 /// Adds a new arc connects the the given two nodes.
1343 Edge addArc(const Node&, const Node&) {
1347 template <typename _Graph>
1348 struct Constraints {
1349 void constraints() {
1350 checkConcept<Base, _Graph>();
1351 typename _Graph::Node node_a, node_b;
1352 node_a = graph.addNode();
1353 node_b = graph.addNode();
1354 typename _Graph::Edge edge;
1355 edge = graph.addEdge(node_a, node_b);
1362 /// \brief An empty erasable digraph class.
1364 /// This class provides beside the core digraph features core erase
1365 /// functions for the digraph structure. The main difference between
1366 /// the base and this interface is that the digraph alterations
1367 /// should handled already on this level.
1368 template <typename _Base = BaseDigraphComponent>
1369 class ErasableDigraphComponent : public _Base {
1373 typedef typename Base::Node Node;
1374 typedef typename Base::Arc Arc;
1376 /// \brief Erase a node from the digraph.
1378 /// Erase a node from the digraph. This function should
1379 /// erase all arcs connecting to the node.
1380 void erase(const Node&) {}
1382 /// \brief Erase an arc from the digraph.
1384 /// Erase an arc from the digraph.
1386 void erase(const Arc&) {}
1388 template <typename _Digraph>
1389 struct Constraints {
1390 void constraints() {
1391 checkConcept<Base, _Digraph>();
1392 typename _Digraph::Node node;
1393 digraph.erase(node);
1394 typename _Digraph::Arc arc;
1402 /// \brief An empty erasable base undirected graph class.
1404 /// This class provides beside the core undirected graph features
1405 /// core erase functions for the undirceted graph structure. The
1406 /// main difference between the base and this interface is that
1407 /// the graph alterations should handled already on this level.
1408 template <typename _Base = BaseGraphComponent>
1409 class ErasableGraphComponent : public _Base {
1413 typedef typename Base::Node Node;
1414 typedef typename Base::Edge Edge;
1416 /// \brief Erase a node from the graph.
1418 /// Erase a node from the graph. This function should erase
1419 /// arcs connecting to the node.
1420 void erase(const Node&) {}
1422 /// \brief Erase an arc from the graph.
1424 /// Erase an arc from the graph.
1426 void erase(const Edge&) {}
1428 template <typename _Graph>
1429 struct Constraints {
1430 void constraints() {
1431 checkConcept<Base, _Graph>();
1432 typename _Graph::Node node;
1434 typename _Graph::Edge edge;
1442 /// \brief An empty clearable base digraph class.
1444 /// This class provides beside the core digraph features core clear
1445 /// functions for the digraph structure. The main difference between
1446 /// the base and this interface is that the digraph alterations
1447 /// should handled already on this level.
1448 template <typename _Base = BaseDigraphComponent>
1449 class ClearableDigraphComponent : public _Base {
1454 /// \brief Erase all nodes and arcs from the digraph.
1456 /// Erase all nodes and arcs from the digraph.
1460 template <typename _Digraph>
1461 struct Constraints {
1462 void constraints() {
1463 checkConcept<Base, _Digraph>();
1471 /// \brief An empty clearable base undirected graph class.
1473 /// This class provides beside the core undirected graph features
1474 /// core clear functions for the undirected graph structure. The
1475 /// main difference between the base and this interface is that
1476 /// the graph alterations should handled already on this level.
1477 template <typename _Base = BaseGraphComponent>
1478 class ClearableGraphComponent : public ClearableDigraphComponent<_Base> {
1483 template <typename _Graph>
1484 struct Constraints {
1485 void constraints() {
1486 checkConcept<ClearableGraphComponent<Base>, _Graph>();