1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
3 * This file is a part of LEMON, a generic C++ optimization library.
5 * Copyright (C) 2003-2013
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 concepts 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 has 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 ::lemon::ignore_unused_variable_warning(i2);
107 _GraphItem i3 = INVALID;
112 ::lemon::ignore_unused_variable_warning(b);
114 b = (ia == ib) && (ia != ib);
115 b = (ia == INVALID) && (ib != INVALID);
119 const _GraphItem &ia;
120 const _GraphItem &ib;
125 /// \brief Base skeleton class for directed graphs.
127 /// This class describes the base interface of directed graph types.
128 /// All digraph %concepts have to conform to this class.
129 /// It just provides types for nodes and arcs and functions
130 /// to get the source and the target nodes of arcs.
131 class BaseDigraphComponent {
134 typedef BaseDigraphComponent Digraph;
136 /// \brief Node class of the digraph.
138 /// This class represents the nodes of the digraph.
139 typedef GraphItem<'n'> Node;
141 /// \brief Arc class of the digraph.
143 /// This class represents the arcs of the digraph.
144 typedef GraphItem<'a'> Arc;
146 /// \brief Return the source node of an arc.
148 /// This function returns the source node of an arc.
149 Node source(const Arc&) const { return INVALID; }
151 /// \brief Return the target node of an arc.
153 /// This function returns the target node of an arc.
154 Node target(const Arc&) const { return INVALID; }
156 /// \brief Return the opposite node on the given arc.
158 /// This function returns the opposite node on the given arc.
159 Node oppositeNode(const Node&, const Arc&) const {
163 template <typename _Digraph>
165 typedef typename _Digraph::Node Node;
166 typedef typename _Digraph::Arc Arc;
169 checkConcept<GraphItem<'n'>, Node>();
170 checkConcept<GraphItem<'a'>, Arc>();
174 n = digraph.source(e);
175 n = digraph.target(e);
176 n = digraph.oppositeNode(n, e);
180 const _Digraph& digraph;
185 /// \brief Base skeleton class for undirected graphs.
187 /// This class describes the base interface of undirected graph types.
188 /// All graph %concepts have to conform to this class.
189 /// It extends the interface of \ref BaseDigraphComponent with an
190 /// \c Edge type and functions to get the end nodes of edges,
191 /// to convert from arcs to edges and to get both direction of edges.
192 class BaseGraphComponent : public BaseDigraphComponent {
195 typedef BaseGraphComponent Graph;
197 typedef BaseDigraphComponent::Node Node;
198 typedef BaseDigraphComponent::Arc Arc;
200 /// \brief Undirected edge class of the graph.
202 /// This class represents the undirected edges of the graph.
203 /// Undirected graphs can be used as directed graphs, each edge is
204 /// represented by two opposite directed arcs.
205 class Edge : public GraphItem<'e'> {
206 typedef GraphItem<'e'> Parent;
209 /// \brief Default constructor.
211 /// Default constructor.
212 /// \warning The default constructor is not required to set
213 /// the item to some well-defined value. So you should consider it
214 /// as uninitialized.
217 /// \brief Copy constructor.
219 /// Copy constructor.
220 Edge(const Edge &) : Parent() {}
222 /// \brief Constructor for conversion from \c INVALID.
224 /// Constructor for conversion from \c INVALID.
225 /// It initializes the item to be invalid.
226 /// \sa Invalid for more details.
229 /// \brief Constructor for conversion from an arc.
231 /// Constructor for conversion from an arc.
232 /// Besides the core graph item functionality each arc should
233 /// be convertible to the represented edge.
237 /// \brief Return one end node of an edge.
239 /// This function returns one end node of an edge.
240 Node u(const Edge&) const { return INVALID; }
242 /// \brief Return the other end node of an edge.
244 /// This function returns the other end node of an edge.
245 Node v(const Edge&) const { return INVALID; }
247 /// \brief Return a directed arc related to an edge.
249 /// This function returns a directed arc from its direction and the
250 /// represented edge.
251 Arc direct(const Edge&, bool) const { return INVALID; }
253 /// \brief Return a directed arc related to an edge.
255 /// This function returns a directed arc from its source node and the
256 /// represented edge.
257 Arc direct(const Edge&, const Node&) const { return INVALID; }
259 /// \brief Return the direction of the arc.
261 /// Returns the direction of the arc. Each arc represents an
262 /// edge with a direction. It gives back the
264 bool direction(const Arc&) const { return true; }
266 /// \brief Return the opposite arc.
268 /// This function returns the opposite arc, i.e. the arc representing
269 /// the same edge and has opposite direction.
270 Arc oppositeArc(const Arc&) const { return INVALID; }
272 template <typename _Graph>
274 typedef typename _Graph::Node Node;
275 typedef typename _Graph::Arc Arc;
276 typedef typename _Graph::Edge Edge;
279 checkConcept<BaseDigraphComponent, _Graph>();
280 checkConcept<GraphItem<'e'>, Edge>();
287 e = graph.direct(ue, true);
288 e = graph.direct(ue, false);
289 e = graph.direct(ue, n);
290 e = graph.oppositeArc(e);
292 bool d = graph.direction(e);
293 ::lemon::ignore_unused_variable_warning(d);
303 /// \brief Base skeleton class for undirected bipartite graphs.
305 /// This class describes the base interface of undirected
306 /// bipartite graph types. All bipartite graph %concepts have to
307 /// conform to this class. It extends the interface of \ref
308 /// BaseGraphComponent with an \c Edge type and functions to get
309 /// the end nodes of edges, to convert from arcs to edges and to
310 /// get both direction of edges.
311 class BaseBpGraphComponent : public BaseGraphComponent {
314 typedef BaseBpGraphComponent BpGraph;
316 typedef BaseDigraphComponent::Node Node;
317 typedef BaseDigraphComponent::Arc Arc;
319 /// \brief Class to represent red nodes.
321 /// This class represents the red nodes of the graph. The red
322 /// nodes can also be used as normal nodes.
323 class RedNode : public Node {
327 /// \brief Default constructor.
329 /// Default constructor.
330 /// \warning The default constructor is not required to set
331 /// the item to some well-defined value. So you should consider it
332 /// as uninitialized.
335 /// \brief Copy constructor.
337 /// Copy constructor.
338 RedNode(const RedNode &) : Parent() {}
340 /// \brief Constructor for conversion from \c INVALID.
342 /// Constructor for conversion from \c INVALID.
343 /// It initializes the item to be invalid.
344 /// \sa Invalid for more details.
348 /// \brief Class to represent blue nodes.
350 /// This class represents the blue nodes of the graph. The blue
351 /// nodes can also be used as normal nodes.
352 class BlueNode : public Node {
356 /// \brief Default constructor.
358 /// Default constructor.
359 /// \warning The default constructor is not required to set
360 /// the item to some well-defined value. So you should consider it
361 /// as uninitialized.
364 /// \brief Copy constructor.
366 /// Copy constructor.
367 BlueNode(const BlueNode &) : Parent() {}
369 /// \brief Constructor for conversion from \c INVALID.
371 /// Constructor for conversion from \c INVALID.
372 /// It initializes the item to be invalid.
373 /// \sa Invalid for more details.
376 /// \brief Constructor for conversion from a node.
378 /// Constructor for conversion from a node. The conversion can
379 /// be invalid, since the Node can be member of the red
381 BlueNode(const Node&) {}
384 /// \brief Gives back %true for red nodes.
386 /// Gives back %true for red nodes.
387 bool red(const Node&) const { return true; }
389 /// \brief Gives back %true for blue nodes.
391 /// Gives back %true for blue nodes.
392 bool blue(const Node&) const { return true; }
394 /// \brief Gives back the red end node of the edge.
396 /// Gives back the red end node of the edge.
397 RedNode redNode(const Edge&) const { return RedNode(); }
399 /// \brief Gives back the blue end node of the edge.
401 /// Gives back the blue end node of the edge.
402 BlueNode blueNode(const Edge&) const { return BlueNode(); }
404 /// \brief Converts the node to red node object.
406 /// This function converts unsafely the node to red node
407 /// object. It should be called only if the node is from the red
408 /// partition or INVALID.
409 RedNode asRedNodeUnsafe(const Node&) const { return RedNode(); }
411 /// \brief Converts the node to blue node object.
413 /// This function converts unsafely the node to blue node
414 /// object. It should be called only if the node is from the red
415 /// partition or INVALID.
416 BlueNode asBlueNodeUnsafe(const Node&) const { return BlueNode(); }
418 /// \brief Converts the node to red node object.
420 /// This function converts safely the node to red node
421 /// object. If the node is not from the red partition, then it
423 RedNode asRedNode(const Node&) const { return RedNode(); }
425 /// \brief Converts the node to blue node object.
427 /// This function converts unsafely the node to blue node
428 /// object. If the node is not from the blue partition, then it
430 BlueNode asBlueNode(const Node&) const { return BlueNode(); }
432 template <typename _BpGraph>
434 typedef typename _BpGraph::Node Node;
435 typedef typename _BpGraph::RedNode RedNode;
436 typedef typename _BpGraph::BlueNode BlueNode;
437 typedef typename _BpGraph::Arc Arc;
438 typedef typename _BpGraph::Edge Edge;
441 checkConcept<BaseGraphComponent, _BpGraph>();
442 checkConcept<GraphItem<'n'>, RedNode>();
443 checkConcept<GraphItem<'n'>, BlueNode>();
452 b = bpgraph.red(rnan);
453 b = bpgraph.blue(bnan);
454 rn = bpgraph.redNode(e);
455 bn = bpgraph.blueNode(e);
456 rn = bpgraph.asRedNodeUnsafe(rnan);
457 bn = bpgraph.asBlueNodeUnsafe(bnan);
458 rn = bpgraph.asRedNode(rnan);
459 bn = bpgraph.asBlueNode(bnan);
460 ::lemon::ignore_unused_variable_warning(b);
464 const _BpGraph& bpgraph;
469 /// \brief Skeleton class for \e idable directed graphs.
471 /// This class describes the interface of \e idable directed graphs.
472 /// It extends \ref BaseDigraphComponent with the core ID functions.
473 /// The ids of the items must be unique and immutable.
474 /// This concept is part of the Digraph concept.
475 template <typename BAS = BaseDigraphComponent>
476 class IDableDigraphComponent : public BAS {
480 typedef typename Base::Node Node;
481 typedef typename Base::Arc Arc;
483 /// \brief Return a unique integer id for the given node.
485 /// This function returns a unique integer id for the given node.
486 int id(const Node&) const { return -1; }
488 /// \brief Return the node by its unique id.
490 /// This function returns the node by its unique id.
491 /// If the digraph does not contain a node with the given id,
492 /// then the result of the function is undefined.
493 Node nodeFromId(int) const { return INVALID; }
495 /// \brief Return a unique integer id for the given arc.
497 /// This function returns a unique integer id for the given arc.
498 int id(const Arc&) const { return -1; }
500 /// \brief Return the arc by its unique id.
502 /// This function returns the arc by its unique id.
503 /// If the digraph does not contain an arc with the given id,
504 /// then the result of the function is undefined.
505 Arc arcFromId(int) const { return INVALID; }
507 /// \brief Return an integer greater or equal to the maximum
510 /// This function returns an integer greater or equal to the
512 int maxNodeId() const { return -1; }
514 /// \brief Return an integer greater or equal to the maximum
517 /// This function returns an integer greater or equal to the
519 int maxArcId() const { return -1; }
521 template <typename _Digraph>
525 checkConcept<Base, _Digraph >();
526 typename _Digraph::Node node;
528 int nid = digraph.id(node);
529 nid = digraph.id(node);
530 node = digraph.nodeFromId(nid);
531 typename _Digraph::Arc arc;
533 int eid = digraph.id(arc);
534 eid = digraph.id(arc);
535 arc = digraph.arcFromId(eid);
537 nid = digraph.maxNodeId();
538 ::lemon::ignore_unused_variable_warning(nid);
539 eid = digraph.maxArcId();
540 ::lemon::ignore_unused_variable_warning(eid);
543 const _Digraph& digraph;
548 /// \brief Skeleton class for \e idable undirected graphs.
550 /// This class describes the interface of \e idable undirected
551 /// graphs. It extends \ref IDableDigraphComponent with the core ID
552 /// functions of undirected graphs.
553 /// The ids of the items must be unique and immutable.
554 /// This concept is part of the Graph concept.
555 template <typename BAS = BaseGraphComponent>
556 class IDableGraphComponent : public IDableDigraphComponent<BAS> {
560 typedef typename Base::Edge Edge;
562 using IDableDigraphComponent<Base>::id;
564 /// \brief Return a unique integer id for the given edge.
566 /// This function returns a unique integer id for the given edge.
567 int id(const Edge&) const { return -1; }
569 /// \brief Return the edge by its unique id.
571 /// This function returns the edge by its unique id.
572 /// If the graph does not contain an edge with the given id,
573 /// then the result of the function is undefined.
574 Edge edgeFromId(int) const { return INVALID; }
576 /// \brief Return an integer greater or equal to the maximum
579 /// This function returns an integer greater or equal to the
581 int maxEdgeId() const { return -1; }
583 template <typename _Graph>
587 checkConcept<IDableDigraphComponent<Base>, _Graph >();
588 typename _Graph::Edge edge;
589 int ueid = graph.id(edge);
590 ueid = graph.id(edge);
591 edge = graph.edgeFromId(ueid);
592 ueid = graph.maxEdgeId();
593 ::lemon::ignore_unused_variable_warning(ueid);
601 /// \brief Skeleton class for \e idable undirected bipartite graphs.
603 /// This class describes the interface of \e idable undirected
604 /// bipartite graphs. It extends \ref IDableGraphComponent with
605 /// the core ID functions of undirected bipartite graphs. Beside
606 /// the regular node ids, this class also provides ids within the
607 /// the red and blue sets of the nodes. This concept is part of
608 /// the BpGraph concept.
609 template <typename BAS = BaseBpGraphComponent>
610 class IDableBpGraphComponent : public IDableGraphComponent<BAS> {
614 typedef IDableGraphComponent<BAS> Parent;
615 typedef typename Base::Node Node;
616 typedef typename Base::RedNode RedNode;
617 typedef typename Base::BlueNode BlueNode;
621 /// \brief Return a unique integer id for the given node in the red set.
623 /// Return a unique integer id for the given node in the red set.
624 int id(const RedNode&) const { return -1; }
626 /// \brief Return a unique integer id for the given node in the blue set.
628 /// Return a unique integer id for the given node in the blue set.
629 int id(const BlueNode&) const { return -1; }
631 /// \brief Return an integer greater or equal to the maximum
632 /// node id in the red set.
634 /// Return an integer greater or equal to the maximum
635 /// node id in the red set.
636 int maxRedId() const { return -1; }
638 /// \brief Return an integer greater or equal to the maximum
639 /// node id in the blue set.
641 /// Return an integer greater or equal to the maximum
642 /// node id in the blue set.
643 int maxBlueId() const { return -1; }
645 template <typename _BpGraph>
649 checkConcept<IDableGraphComponent<Base>, _BpGraph>();
650 typename _BpGraph::Node node;
651 typename _BpGraph::RedNode red;
652 typename _BpGraph::BlueNode blue;
653 int rid = bpgraph.id(red);
654 int bid = bpgraph.id(blue);
655 rid = bpgraph.maxRedId();
656 bid = bpgraph.maxBlueId();
657 ::lemon::ignore_unused_variable_warning(rid);
658 ::lemon::ignore_unused_variable_warning(bid);
661 const _BpGraph& bpgraph;
665 /// \brief Concept class for \c NodeIt, \c ArcIt and \c EdgeIt types.
667 /// This class describes the concept of \c NodeIt, \c ArcIt and
668 /// \c EdgeIt subtypes of digraph and graph types.
669 template <typename GR, typename Item>
670 class GraphItemIt : public Item {
672 /// \brief Default constructor.
674 /// Default constructor.
675 /// \warning The default constructor is not required to set
676 /// the iterator to some well-defined value. So you should consider it
677 /// as uninitialized.
680 /// \brief Copy constructor.
682 /// Copy constructor.
683 GraphItemIt(const GraphItemIt& it) : Item(it) {}
685 /// \brief Constructor that sets the iterator to the first item.
687 /// Constructor that sets the iterator to the first item.
688 explicit GraphItemIt(const GR&) {}
690 /// \brief Constructor for conversion from \c INVALID.
692 /// Constructor for conversion from \c INVALID.
693 /// It initializes the iterator to be invalid.
694 /// \sa Invalid for more details.
695 GraphItemIt(Invalid) {}
697 /// \brief Assignment operator.
699 /// Assignment operator for the iterator.
700 GraphItemIt& operator=(const GraphItemIt&) { return *this; }
702 /// \brief Increment the iterator.
704 /// This operator increments the iterator, i.e. assigns it to the
706 GraphItemIt& operator++() { return *this; }
708 /// \brief Equality operator
710 /// Equality operator.
711 /// Two iterators are equal if and only if they point to the
712 /// same object or both are invalid.
713 bool operator==(const GraphItemIt&) const { return true;}
715 /// \brief Inequality operator
717 /// Inequality operator.
718 /// Two iterators are equal if and only if they point to the
719 /// same object or both are invalid.
720 bool operator!=(const GraphItemIt&) const { return true;}
722 template<typename _GraphItemIt>
725 checkConcept<GraphItem<>, _GraphItemIt>();
728 _GraphItemIt it3 = it1;
729 _GraphItemIt it4 = INVALID;
730 ::lemon::ignore_unused_variable_warning(it3);
731 ::lemon::ignore_unused_variable_warning(it4);
738 ::lemon::ignore_unused_variable_warning(bi);
746 /// \brief Concept class for \c InArcIt, \c OutArcIt and
747 /// \c IncEdgeIt types.
749 /// This class describes the concept of \c InArcIt, \c OutArcIt
750 /// and \c IncEdgeIt subtypes of digraph and graph types.
752 /// \note Since these iterator classes do not inherit from the same
753 /// base class, there is an additional template parameter (selector)
754 /// \c sel. For \c InArcIt you should instantiate it with character
755 /// \c 'i', for \c OutArcIt with \c 'o' and for \c IncEdgeIt with \c 'e'.
756 template <typename GR,
757 typename Item = typename GR::Arc,
758 typename Base = typename GR::Node,
760 class GraphIncIt : public Item {
762 /// \brief Default constructor.
764 /// Default constructor.
765 /// \warning The default constructor is not required to set
766 /// the iterator to some well-defined value. So you should consider it
767 /// as uninitialized.
770 /// \brief Copy constructor.
772 /// Copy constructor.
773 GraphIncIt(const GraphIncIt& it) : Item(it) {}
775 /// \brief Constructor that sets the iterator to the first
776 /// incoming or outgoing arc.
778 /// Constructor that sets the iterator to the first arc
779 /// incoming to or outgoing from the given node.
780 explicit GraphIncIt(const GR&, const Base&) {}
782 /// \brief Constructor for conversion from \c INVALID.
784 /// Constructor for conversion from \c INVALID.
785 /// It initializes the iterator to be invalid.
786 /// \sa Invalid for more details.
787 GraphIncIt(Invalid) {}
789 /// \brief Assignment operator.
791 /// Assignment operator for the iterator.
792 GraphIncIt& operator=(const GraphIncIt&) { return *this; }
794 /// \brief Increment the iterator.
796 /// This operator increments the iterator, i.e. assigns it to the
797 /// next arc incoming to or outgoing from the given node.
798 GraphIncIt& operator++() { return *this; }
800 /// \brief Equality operator
802 /// Equality operator.
803 /// Two iterators are equal if and only if they point to the
804 /// same object or both are invalid.
805 bool operator==(const GraphIncIt&) const { return true;}
807 /// \brief Inequality operator
809 /// Inequality operator.
810 /// Two iterators are equal if and only if they point to the
811 /// same object or both are invalid.
812 bool operator!=(const GraphIncIt&) const { return true;}
814 template <typename _GraphIncIt>
817 checkConcept<GraphItem<sel>, _GraphIncIt>();
818 _GraphIncIt it1(graph, node);
820 _GraphIncIt it3 = it1;
821 _GraphIncIt it4 = INVALID;
822 ::lemon::ignore_unused_variable_warning(it3);
823 ::lemon::ignore_unused_variable_warning(it4);
829 ::lemon::ignore_unused_variable_warning(e);
838 /// \brief Skeleton class for iterable directed graphs.
840 /// This class describes the interface of iterable directed
841 /// graphs. It extends \ref BaseDigraphComponent with the core
842 /// iterable interface.
843 /// This concept is part of the Digraph concept.
844 template <typename BAS = BaseDigraphComponent>
845 class IterableDigraphComponent : public BAS {
850 typedef typename Base::Node Node;
851 typedef typename Base::Arc Arc;
853 typedef IterableDigraphComponent Digraph;
855 /// \name Base Iteration
857 /// This interface provides functions for iteration on digraph items.
861 /// \brief Return the first node.
863 /// This function gives back the first node in the iteration order.
864 void first(Node&) const {}
866 /// \brief Return the next node.
868 /// This function gives back the next node in the iteration order.
869 void next(Node&) const {}
871 /// \brief Return the first arc.
873 /// This function gives back the first arc in the iteration order.
874 void first(Arc&) const {}
876 /// \brief Return the next arc.
878 /// This function gives back the next arc in the iteration order.
879 void next(Arc&) const {}
881 /// \brief Return the first arc incoming to the given node.
883 /// This function gives back the first arc incoming to the
885 void firstIn(Arc&, const Node&) const {}
887 /// \brief Return the next arc incoming to the given node.
889 /// This function gives back the next arc incoming to the
891 void nextIn(Arc&) const {}
893 /// \brief Return the first arc outgoing form the given node.
895 /// This function gives back the first arc outgoing form the
897 void firstOut(Arc&, const Node&) const {}
899 /// \brief Return the next arc outgoing form the given node.
901 /// This function gives back the next arc outgoing form the
903 void nextOut(Arc&) const {}
907 /// \name Class Based Iteration
909 /// This interface provides iterator classes for digraph items.
913 /// \brief This iterator goes through each node.
915 /// This iterator goes through each node.
917 typedef GraphItemIt<Digraph, Node> NodeIt;
919 /// \brief This iterator goes through each arc.
921 /// This iterator goes through each arc.
923 typedef GraphItemIt<Digraph, Arc> ArcIt;
925 /// \brief This iterator goes trough the incoming arcs of a node.
927 /// This iterator goes trough the \e incoming arcs of a certain node
929 typedef GraphIncIt<Digraph, Arc, Node, 'i'> InArcIt;
931 /// \brief This iterator goes trough the outgoing arcs of a node.
933 /// This iterator goes trough the \e outgoing arcs of a certain node
935 typedef GraphIncIt<Digraph, Arc, Node, 'o'> OutArcIt;
937 /// \brief The base node of the iterator.
939 /// This function gives back the base node of the iterator.
940 /// It is always the target node of the pointed arc.
941 Node baseNode(const InArcIt&) const { return INVALID; }
943 /// \brief The running node of the iterator.
945 /// This function gives back the running node of the iterator.
946 /// It is always the source node of the pointed arc.
947 Node runningNode(const InArcIt&) const { return INVALID; }
949 /// \brief The base node of the iterator.
951 /// This function gives back the base node of the iterator.
952 /// It is always the source node of the pointed arc.
953 Node baseNode(const OutArcIt&) const { return INVALID; }
955 /// \brief The running node of the iterator.
957 /// This function gives back the running node of the iterator.
958 /// It is always the target node of the pointed arc.
959 Node runningNode(const OutArcIt&) const { return INVALID; }
963 template <typename _Digraph>
966 checkConcept<Base, _Digraph>();
969 typename _Digraph::Node node(INVALID);
970 typename _Digraph::Arc arc(INVALID);
980 digraph.firstIn(arc, node);
984 digraph.firstOut(arc, node);
985 digraph.nextOut(arc);
990 checkConcept<GraphItemIt<_Digraph, typename _Digraph::Arc>,
991 typename _Digraph::ArcIt >();
992 checkConcept<GraphItemIt<_Digraph, typename _Digraph::Node>,
993 typename _Digraph::NodeIt >();
994 checkConcept<GraphIncIt<_Digraph, typename _Digraph::Arc,
995 typename _Digraph::Node, 'i'>, typename _Digraph::InArcIt>();
996 checkConcept<GraphIncIt<_Digraph, typename _Digraph::Arc,
997 typename _Digraph::Node, 'o'>, typename _Digraph::OutArcIt>();
999 typename _Digraph::Node n;
1000 const typename _Digraph::InArcIt iait(INVALID);
1001 const typename _Digraph::OutArcIt oait(INVALID);
1002 n = digraph.baseNode(iait);
1003 n = digraph.runningNode(iait);
1004 n = digraph.baseNode(oait);
1005 n = digraph.runningNode(oait);
1006 ::lemon::ignore_unused_variable_warning(n);
1010 const _Digraph& digraph;
1015 /// \brief Skeleton class for iterable undirected graphs.
1017 /// This class describes the interface of iterable undirected
1018 /// graphs. It extends \ref IterableDigraphComponent with the core
1019 /// iterable interface of undirected graphs.
1020 /// This concept is part of the Graph concept.
1021 template <typename BAS = BaseGraphComponent>
1022 class IterableGraphComponent : public IterableDigraphComponent<BAS> {
1026 typedef typename Base::Node Node;
1027 typedef typename Base::Arc Arc;
1028 typedef typename Base::Edge Edge;
1031 typedef IterableGraphComponent Graph;
1033 /// \name Base Iteration
1035 /// This interface provides functions for iteration on edges.
1039 using IterableDigraphComponent<Base>::first;
1040 using IterableDigraphComponent<Base>::next;
1042 /// \brief Return the first edge.
1044 /// This function gives back the first edge in the iteration order.
1045 void first(Edge&) const {}
1047 /// \brief Return the next edge.
1049 /// This function gives back the next edge in the iteration order.
1050 void next(Edge&) const {}
1052 /// \brief Return the first edge incident to the given node.
1054 /// This function gives back the first edge incident to the given
1055 /// node. The bool parameter gives back the direction for which the
1056 /// source node of the directed arc representing the edge is the
1058 void firstInc(Edge&, bool&, const Node&) const {}
1060 /// \brief Gives back the next of the edges from the
1063 /// This function gives back the next edge incident to the given
1064 /// node. The bool parameter should be used as \c firstInc() use it.
1065 void nextInc(Edge&, bool&) const {}
1067 using IterableDigraphComponent<Base>::baseNode;
1068 using IterableDigraphComponent<Base>::runningNode;
1072 /// \name Class Based Iteration
1074 /// This interface provides iterator classes for edges.
1078 /// \brief This iterator goes through each edge.
1080 /// This iterator goes through each edge.
1081 typedef GraphItemIt<Graph, Edge> EdgeIt;
1083 /// \brief This iterator goes trough the incident edges of a
1086 /// This iterator goes trough the incident edges of a certain
1087 /// node of a graph.
1088 typedef GraphIncIt<Graph, Edge, Node, 'e'> IncEdgeIt;
1090 /// \brief The base node of the iterator.
1092 /// This function gives back the base node of the iterator.
1093 Node baseNode(const IncEdgeIt&) const { return INVALID; }
1095 /// \brief The running node of the iterator.
1097 /// This function gives back the running node of the iterator.
1098 Node runningNode(const IncEdgeIt&) const { return INVALID; }
1102 template <typename _Graph>
1103 struct Constraints {
1104 void constraints() {
1105 checkConcept<IterableDigraphComponent<Base>, _Graph>();
1108 typename _Graph::Node node(INVALID);
1109 typename _Graph::Edge edge(INVALID);
1116 graph.firstInc(edge, dir, node);
1117 graph.nextInc(edge, dir);
1123 checkConcept<GraphItemIt<_Graph, typename _Graph::Edge>,
1124 typename _Graph::EdgeIt >();
1125 checkConcept<GraphIncIt<_Graph, typename _Graph::Edge,
1126 typename _Graph::Node, 'e'>, typename _Graph::IncEdgeIt>();
1128 typename _Graph::Node n;
1129 const typename _Graph::IncEdgeIt ieit(INVALID);
1130 n = graph.baseNode(ieit);
1131 n = graph.runningNode(ieit);
1135 const _Graph& graph;
1140 /// \brief Skeleton class for iterable undirected bipartite graphs.
1142 /// This class describes the interface of iterable undirected
1143 /// bipartite graphs. It extends \ref IterableGraphComponent with
1144 /// the core iterable interface of undirected bipartite graphs.
1145 /// This concept is part of the BpGraph concept.
1146 template <typename BAS = BaseBpGraphComponent>
1147 class IterableBpGraphComponent : public IterableGraphComponent<BAS> {
1151 typedef typename Base::Node Node;
1152 typedef typename Base::RedNode RedNode;
1153 typedef typename Base::BlueNode BlueNode;
1154 typedef typename Base::Arc Arc;
1155 typedef typename Base::Edge Edge;
1157 typedef IterableBpGraphComponent BpGraph;
1159 using IterableGraphComponent<BAS>::first;
1160 using IterableGraphComponent<BAS>::next;
1162 /// \name Base Iteration
1164 /// This interface provides functions for iteration on red and blue nodes.
1168 /// \brief Return the first red node.
1170 /// This function gives back the first red node in the iteration order.
1171 void first(RedNode&) const {}
1173 /// \brief Return the next red node.
1175 /// This function gives back the next red node in the iteration order.
1176 void next(RedNode&) const {}
1178 /// \brief Return the first blue node.
1180 /// This function gives back the first blue node in the iteration order.
1181 void first(BlueNode&) const {}
1183 /// \brief Return the next blue node.
1185 /// This function gives back the next blue node in the iteration order.
1186 void next(BlueNode&) const {}
1191 /// \name Class Based Iteration
1193 /// This interface provides iterator classes for red and blue nodes.
1197 /// \brief This iterator goes through each red node.
1199 /// This iterator goes through each red node.
1200 typedef GraphItemIt<BpGraph, RedNode> RedNodeIt;
1202 /// \brief This iterator goes through each blue node.
1204 /// This iterator goes through each blue node.
1205 typedef GraphItemIt<BpGraph, BlueNode> BlueNodeIt;
1209 template <typename _BpGraph>
1210 struct Constraints {
1211 void constraints() {
1212 checkConcept<IterableGraphComponent<Base>, _BpGraph>();
1214 typename _BpGraph::RedNode rn(INVALID);
1217 typename _BpGraph::BlueNode bn(INVALID);
1221 checkConcept<GraphItemIt<_BpGraph, typename _BpGraph::RedNode>,
1222 typename _BpGraph::RedNodeIt>();
1223 checkConcept<GraphItemIt<_BpGraph, typename _BpGraph::BlueNode>,
1224 typename _BpGraph::BlueNodeIt>();
1227 const _BpGraph& bpgraph;
1231 /// \brief Skeleton class for alterable directed graphs.
1233 /// This class describes the interface of alterable directed
1234 /// graphs. It extends \ref BaseDigraphComponent with the alteration
1235 /// notifier interface. It implements
1236 /// an observer-notifier pattern for each digraph item. More
1237 /// obsevers can be registered into the notifier and whenever an
1238 /// alteration occured in the digraph all the observers will be
1239 /// notified about it.
1240 template <typename BAS = BaseDigraphComponent>
1241 class AlterableDigraphComponent : public BAS {
1245 typedef typename Base::Node Node;
1246 typedef typename Base::Arc Arc;
1249 /// Node alteration notifier class.
1250 typedef AlterationNotifier<AlterableDigraphComponent, Node>
1252 /// Arc alteration notifier class.
1253 typedef AlterationNotifier<AlterableDigraphComponent, Arc>
1256 mutable NodeNotifier node_notifier;
1257 mutable ArcNotifier arc_notifier;
1259 /// \brief Return the node alteration notifier.
1261 /// This function gives back the node alteration notifier.
1262 NodeNotifier& notifier(Node) const {
1263 return node_notifier;
1266 /// \brief Return the arc alteration notifier.
1268 /// This function gives back the arc alteration notifier.
1269 ArcNotifier& notifier(Arc) const {
1270 return arc_notifier;
1273 template <typename _Digraph>
1274 struct Constraints {
1275 void constraints() {
1276 checkConcept<Base, _Digraph>();
1277 typename _Digraph::NodeNotifier& nn
1278 = digraph.notifier(typename _Digraph::Node());
1280 typename _Digraph::ArcNotifier& en
1281 = digraph.notifier(typename _Digraph::Arc());
1283 ::lemon::ignore_unused_variable_warning(nn);
1284 ::lemon::ignore_unused_variable_warning(en);
1287 const _Digraph& digraph;
1292 /// \brief Skeleton class for alterable undirected graphs.
1294 /// This class describes the interface of alterable undirected
1295 /// graphs. It extends \ref AlterableDigraphComponent with the alteration
1296 /// notifier interface of undirected graphs. It implements
1297 /// an observer-notifier pattern for the edges. More
1298 /// obsevers can be registered into the notifier and whenever an
1299 /// alteration occured in the graph all the observers will be
1300 /// notified about it.
1301 template <typename BAS = BaseGraphComponent>
1302 class AlterableGraphComponent : public AlterableDigraphComponent<BAS> {
1306 typedef AlterableDigraphComponent<Base> Parent;
1307 typedef typename Base::Edge Edge;
1310 /// Edge alteration notifier class.
1311 typedef AlterationNotifier<AlterableGraphComponent, Edge>
1314 mutable EdgeNotifier edge_notifier;
1316 using Parent::notifier;
1318 /// \brief Return the edge alteration notifier.
1320 /// This function gives back the edge alteration notifier.
1321 EdgeNotifier& notifier(Edge) const {
1322 return edge_notifier;
1325 template <typename _Graph>
1326 struct Constraints {
1327 void constraints() {
1328 checkConcept<AlterableDigraphComponent<Base>, _Graph>();
1329 typename _Graph::EdgeNotifier& uen
1330 = graph.notifier(typename _Graph::Edge());
1331 ::lemon::ignore_unused_variable_warning(uen);
1334 const _Graph& graph;
1339 /// \brief Skeleton class for alterable undirected bipartite graphs.
1341 /// This class describes the interface of alterable undirected
1342 /// bipartite graphs. It extends \ref AlterableGraphComponent with
1343 /// the alteration notifier interface of bipartite graphs. It
1344 /// implements an observer-notifier pattern for the red and blue
1345 /// nodes. More obsevers can be registered into the notifier and
1346 /// whenever an alteration occured in the graph all the observers
1347 /// will be notified about it.
1348 template <typename BAS = BaseBpGraphComponent>
1349 class AlterableBpGraphComponent : public AlterableGraphComponent<BAS> {
1353 typedef AlterableGraphComponent<Base> Parent;
1354 typedef typename Base::RedNode RedNode;
1355 typedef typename Base::BlueNode BlueNode;
1358 /// Red node alteration notifier class.
1359 typedef AlterationNotifier<AlterableBpGraphComponent, RedNode>
1362 /// Blue node alteration notifier class.
1363 typedef AlterationNotifier<AlterableBpGraphComponent, BlueNode>
1366 mutable RedNodeNotifier red_node_notifier;
1367 mutable BlueNodeNotifier blue_node_notifier;
1369 using Parent::notifier;
1371 /// \brief Return the red node alteration notifier.
1373 /// This function gives back the red node alteration notifier.
1374 RedNodeNotifier& notifier(RedNode) const {
1375 return red_node_notifier;
1378 /// \brief Return the blue node alteration notifier.
1380 /// This function gives back the blue node alteration notifier.
1381 BlueNodeNotifier& notifier(BlueNode) const {
1382 return blue_node_notifier;
1385 template <typename _BpGraph>
1386 struct Constraints {
1387 void constraints() {
1388 checkConcept<AlterableGraphComponent<Base>, _BpGraph>();
1389 typename _BpGraph::RedNodeNotifier& rnn
1390 = bpgraph.notifier(typename _BpGraph::RedNode());
1391 typename _BpGraph::BlueNodeNotifier& bnn
1392 = bpgraph.notifier(typename _BpGraph::BlueNode());
1393 ::lemon::ignore_unused_variable_warning(rnn);
1394 ::lemon::ignore_unused_variable_warning(bnn);
1397 const _BpGraph& bpgraph;
1401 /// \brief Concept class for standard graph maps.
1403 /// This class describes the concept of standard graph maps, i.e.
1404 /// the \c NodeMap, \c ArcMap and \c EdgeMap subtypes of digraph and
1405 /// graph types, which can be used for associating data to graph items.
1406 /// The standard graph maps must conform to the ReferenceMap concept.
1407 template <typename GR, typename K, typename V>
1408 class GraphMap : public ReferenceMap<K, V, V&, const V&> {
1409 typedef ReferenceMap<K, V, V&, const V&> Parent;
1413 /// The key type of the map.
1415 /// The value type of the map.
1417 /// The reference type of the map.
1418 typedef Value& Reference;
1419 /// The const reference type of the map.
1420 typedef const Value& ConstReference;
1422 // The reference map tag.
1423 typedef True ReferenceMapTag;
1425 /// \brief Construct a new map.
1427 /// Construct a new map for the graph.
1428 explicit GraphMap(const GR&) {}
1429 /// \brief Construct a new map with default value.
1431 /// Construct a new map for the graph and initalize the values.
1432 GraphMap(const GR&, const Value&) {}
1435 /// \brief Copy constructor.
1437 /// Copy Constructor.
1438 GraphMap(const GraphMap&) : Parent() {}
1440 /// \brief Assignment operator.
1442 /// Assignment operator. It does not mofify the underlying graph,
1443 /// it just iterates on the current item set and set the map
1444 /// with the value returned by the assigned map.
1445 template <typename CMap>
1446 GraphMap& operator=(const CMap&) {
1447 checkConcept<ReadMap<Key, Value>, CMap>();
1452 template<typename _Map>
1453 struct Constraints {
1454 void constraints() {
1456 <ReferenceMap<Key, Value, Value&, const Value&>, _Map>();
1463 // Assignment operator
1464 // ReadMap<Key, Value> cmap;
1467 ::lemon::ignore_unused_variable_warning(m1);
1468 ::lemon::ignore_unused_variable_warning(m2);
1469 // ::lemon::ignore_unused_variable_warning(m3);
1474 const typename GraphMap::Value &t;
1480 /// \brief Skeleton class for mappable directed graphs.
1482 /// This class describes the interface of mappable directed graphs.
1483 /// It extends \ref BaseDigraphComponent with the standard digraph
1484 /// map classes, namely \c NodeMap and \c ArcMap.
1485 /// This concept is part of the Digraph concept.
1486 template <typename BAS = BaseDigraphComponent>
1487 class MappableDigraphComponent : public BAS {
1491 typedef typename Base::Node Node;
1492 typedef typename Base::Arc Arc;
1494 typedef MappableDigraphComponent Digraph;
1496 /// \brief Standard graph map for the nodes.
1498 /// Standard graph map for the nodes.
1499 /// It conforms to the ReferenceMap concept.
1500 template <typename V>
1501 class NodeMap : public GraphMap<MappableDigraphComponent, Node, V> {
1502 typedef GraphMap<MappableDigraphComponent, Node, V> Parent;
1505 /// \brief Construct a new map.
1507 /// Construct a new map for the digraph.
1508 explicit NodeMap(const MappableDigraphComponent& digraph)
1509 : Parent(digraph) {}
1511 /// \brief Construct a new map with default value.
1513 /// Construct a new map for the digraph and initalize the values.
1514 NodeMap(const MappableDigraphComponent& digraph, const V& value)
1515 : Parent(digraph, value) {}
1518 /// \brief Copy constructor.
1520 /// Copy Constructor.
1521 NodeMap(const NodeMap& nm) : Parent(nm) {}
1523 /// \brief Assignment operator.
1525 /// Assignment operator.
1526 template <typename CMap>
1527 NodeMap& operator=(const CMap&) {
1528 checkConcept<ReadMap<Node, V>, CMap>();
1534 /// \brief Standard graph map for the arcs.
1536 /// Standard graph map for the arcs.
1537 /// It conforms to the ReferenceMap concept.
1538 template <typename V>
1539 class ArcMap : public GraphMap<MappableDigraphComponent, Arc, V> {
1540 typedef GraphMap<MappableDigraphComponent, Arc, V> Parent;
1543 /// \brief Construct a new map.
1545 /// Construct a new map for the digraph.
1546 explicit ArcMap(const MappableDigraphComponent& digraph)
1547 : Parent(digraph) {}
1549 /// \brief Construct a new map with default value.
1551 /// Construct a new map for the digraph and initalize the values.
1552 ArcMap(const MappableDigraphComponent& digraph, const V& value)
1553 : Parent(digraph, value) {}
1556 /// \brief Copy constructor.
1558 /// Copy Constructor.
1559 ArcMap(const ArcMap& nm) : Parent(nm) {}
1561 /// \brief Assignment operator.
1563 /// Assignment operator.
1564 template <typename CMap>
1565 ArcMap& operator=(const CMap&) {
1566 checkConcept<ReadMap<Arc, V>, CMap>();
1573 template <typename _Digraph>
1574 struct Constraints {
1578 Dummy() : value(0) {}
1579 Dummy(int _v) : value(_v) {}
1582 void constraints() {
1583 checkConcept<Base, _Digraph>();
1585 typedef typename _Digraph::template NodeMap<int> IntNodeMap;
1586 checkConcept<GraphMap<_Digraph, typename _Digraph::Node, int>,
1588 } { // bool map test
1589 typedef typename _Digraph::template NodeMap<bool> BoolNodeMap;
1590 checkConcept<GraphMap<_Digraph, typename _Digraph::Node, bool>,
1592 } { // Dummy map test
1593 typedef typename _Digraph::template NodeMap<Dummy> DummyNodeMap;
1594 checkConcept<GraphMap<_Digraph, typename _Digraph::Node, Dummy>,
1599 typedef typename _Digraph::template ArcMap<int> IntArcMap;
1600 checkConcept<GraphMap<_Digraph, typename _Digraph::Arc, int>,
1602 } { // bool map test
1603 typedef typename _Digraph::template ArcMap<bool> BoolArcMap;
1604 checkConcept<GraphMap<_Digraph, typename _Digraph::Arc, bool>,
1606 } { // Dummy map test
1607 typedef typename _Digraph::template ArcMap<Dummy> DummyArcMap;
1608 checkConcept<GraphMap<_Digraph, typename _Digraph::Arc, Dummy>,
1613 const _Digraph& digraph;
1618 /// \brief Skeleton class for mappable undirected graphs.
1620 /// This class describes the interface of mappable undirected graphs.
1621 /// It extends \ref MappableDigraphComponent with the standard graph
1622 /// map class for edges (\c EdgeMap).
1623 /// This concept is part of the Graph concept.
1624 template <typename BAS = BaseGraphComponent>
1625 class MappableGraphComponent : public MappableDigraphComponent<BAS> {
1629 typedef typename Base::Edge Edge;
1631 typedef MappableGraphComponent Graph;
1633 /// \brief Standard graph map for the edges.
1635 /// Standard graph map for the edges.
1636 /// It conforms to the ReferenceMap concept.
1637 template <typename V>
1638 class EdgeMap : public GraphMap<MappableGraphComponent, Edge, V> {
1639 typedef GraphMap<MappableGraphComponent, Edge, V> Parent;
1642 /// \brief Construct a new map.
1644 /// Construct a new map for the graph.
1645 explicit EdgeMap(const MappableGraphComponent& graph)
1648 /// \brief Construct a new map with default value.
1650 /// Construct a new map for the graph and initalize the values.
1651 EdgeMap(const MappableGraphComponent& graph, const V& value)
1652 : Parent(graph, value) {}
1655 /// \brief Copy constructor.
1657 /// Copy Constructor.
1658 EdgeMap(const EdgeMap& nm) : Parent(nm) {}
1660 /// \brief Assignment operator.
1662 /// Assignment operator.
1663 template <typename CMap>
1664 EdgeMap& operator=(const CMap&) {
1665 checkConcept<ReadMap<Edge, V>, CMap>();
1672 template <typename _Graph>
1673 struct Constraints {
1677 Dummy() : value(0) {}
1678 Dummy(int _v) : value(_v) {}
1681 void constraints() {
1682 checkConcept<MappableDigraphComponent<Base>, _Graph>();
1685 typedef typename _Graph::template EdgeMap<int> IntEdgeMap;
1686 checkConcept<GraphMap<_Graph, typename _Graph::Edge, int>,
1688 } { // bool map test
1689 typedef typename _Graph::template EdgeMap<bool> BoolEdgeMap;
1690 checkConcept<GraphMap<_Graph, typename _Graph::Edge, bool>,
1692 } { // Dummy map test
1693 typedef typename _Graph::template EdgeMap<Dummy> DummyEdgeMap;
1694 checkConcept<GraphMap<_Graph, typename _Graph::Edge, Dummy>,
1699 const _Graph& graph;
1704 /// \brief Skeleton class for mappable undirected bipartite graphs.
1706 /// This class describes the interface of mappable undirected
1707 /// bipartite graphs. It extends \ref MappableGraphComponent with
1708 /// the standard graph map class for red and blue nodes (\c
1709 /// RedNodeMap and BlueNodeMap). This concept is part of the
1710 /// BpGraph concept.
1711 template <typename BAS = BaseBpGraphComponent>
1712 class MappableBpGraphComponent : public MappableGraphComponent<BAS> {
1716 typedef typename Base::Node Node;
1718 typedef MappableBpGraphComponent BpGraph;
1720 /// \brief Standard graph map for the red nodes.
1722 /// Standard graph map for the red nodes.
1723 /// It conforms to the ReferenceMap concept.
1724 template <typename V>
1725 class RedNodeMap : public GraphMap<MappableBpGraphComponent, Node, V> {
1726 typedef GraphMap<MappableBpGraphComponent, Node, V> Parent;
1729 /// \brief Construct a new map.
1731 /// Construct a new map for the graph.
1732 explicit RedNodeMap(const MappableBpGraphComponent& graph)
1735 /// \brief Construct a new map with default value.
1737 /// Construct a new map for the graph and initalize the values.
1738 RedNodeMap(const MappableBpGraphComponent& graph, const V& value)
1739 : Parent(graph, value) {}
1742 /// \brief Copy constructor.
1744 /// Copy Constructor.
1745 RedNodeMap(const RedNodeMap& nm) : Parent(nm) {}
1747 /// \brief Assignment operator.
1749 /// Assignment operator.
1750 template <typename CMap>
1751 RedNodeMap& operator=(const CMap&) {
1752 checkConcept<ReadMap<Node, V>, CMap>();
1758 /// \brief Standard graph map for the blue nodes.
1760 /// Standard graph map for the blue nodes.
1761 /// It conforms to the ReferenceMap concept.
1762 template <typename V>
1763 class BlueNodeMap : public GraphMap<MappableBpGraphComponent, Node, V> {
1764 typedef GraphMap<MappableBpGraphComponent, Node, V> Parent;
1767 /// \brief Construct a new map.
1769 /// Construct a new map for the graph.
1770 explicit BlueNodeMap(const MappableBpGraphComponent& graph)
1773 /// \brief Construct a new map with default value.
1775 /// Construct a new map for the graph and initalize the values.
1776 BlueNodeMap(const MappableBpGraphComponent& graph, const V& value)
1777 : Parent(graph, value) {}
1780 /// \brief Copy constructor.
1782 /// Copy Constructor.
1783 BlueNodeMap(const BlueNodeMap& nm) : Parent(nm) {}
1785 /// \brief Assignment operator.
1787 /// Assignment operator.
1788 template <typename CMap>
1789 BlueNodeMap& operator=(const CMap&) {
1790 checkConcept<ReadMap<Node, V>, CMap>();
1797 template <typename _BpGraph>
1798 struct Constraints {
1802 Dummy() : value(0) {}
1803 Dummy(int _v) : value(_v) {}
1806 void constraints() {
1807 checkConcept<MappableGraphComponent<Base>, _BpGraph>();
1810 typedef typename _BpGraph::template RedNodeMap<int>
1812 checkConcept<GraphMap<_BpGraph, typename _BpGraph::RedNode, int>,
1814 } { // bool map test
1815 typedef typename _BpGraph::template RedNodeMap<bool>
1817 checkConcept<GraphMap<_BpGraph, typename _BpGraph::RedNode, bool>,
1819 } { // Dummy map test
1820 typedef typename _BpGraph::template RedNodeMap<Dummy>
1822 checkConcept<GraphMap<_BpGraph, typename _BpGraph::RedNode, Dummy>,
1823 DummyRedNodeMap >();
1827 typedef typename _BpGraph::template BlueNodeMap<int>
1829 checkConcept<GraphMap<_BpGraph, typename _BpGraph::BlueNode, int>,
1831 } { // bool map test
1832 typedef typename _BpGraph::template BlueNodeMap<bool>
1834 checkConcept<GraphMap<_BpGraph, typename _BpGraph::BlueNode, bool>,
1835 BoolBlueNodeMap >();
1836 } { // Dummy map test
1837 typedef typename _BpGraph::template BlueNodeMap<Dummy>
1839 checkConcept<GraphMap<_BpGraph, typename _BpGraph::BlueNode, Dummy>,
1840 DummyBlueNodeMap >();
1844 const _BpGraph& bpgraph;
1848 /// \brief Skeleton class for extendable directed graphs.
1850 /// This class describes the interface of extendable directed graphs.
1851 /// It extends \ref BaseDigraphComponent with functions for adding
1852 /// nodes and arcs to the digraph.
1853 /// This concept requires \ref AlterableDigraphComponent.
1854 template <typename BAS = BaseDigraphComponent>
1855 class ExtendableDigraphComponent : public BAS {
1859 typedef typename Base::Node Node;
1860 typedef typename Base::Arc Arc;
1862 /// \brief Add a new node to the digraph.
1864 /// This function adds a new node to the digraph.
1869 /// \brief Add a new arc connecting the given two nodes.
1871 /// This function adds a new arc connecting the given two nodes
1873 Arc addArc(const Node&, const Node&) {
1877 template <typename _Digraph>
1878 struct Constraints {
1879 void constraints() {
1880 checkConcept<Base, _Digraph>();
1881 typename _Digraph::Node node_a, node_b;
1882 node_a = digraph.addNode();
1883 node_b = digraph.addNode();
1884 typename _Digraph::Arc arc;
1885 arc = digraph.addArc(node_a, node_b);
1893 /// \brief Skeleton class for extendable undirected graphs.
1895 /// This class describes the interface of extendable undirected graphs.
1896 /// It extends \ref BaseGraphComponent with functions for adding
1897 /// nodes and edges to the graph.
1898 /// This concept requires \ref AlterableGraphComponent.
1899 template <typename BAS = BaseGraphComponent>
1900 class ExtendableGraphComponent : public BAS {
1904 typedef typename Base::Node Node;
1905 typedef typename Base::Edge Edge;
1907 /// \brief Add a new node to the digraph.
1909 /// This function adds a new node to the digraph.
1914 /// \brief Add a new edge connecting the given two nodes.
1916 /// This function adds a new edge connecting the given two nodes
1918 Edge addEdge(const Node&, const Node&) {
1922 template <typename _Graph>
1923 struct Constraints {
1924 void constraints() {
1925 checkConcept<Base, _Graph>();
1926 typename _Graph::Node node_a, node_b;
1927 node_a = graph.addNode();
1928 node_b = graph.addNode();
1929 typename _Graph::Edge edge;
1930 edge = graph.addEdge(node_a, node_b);
1938 /// \brief Skeleton class for extendable undirected bipartite graphs.
1940 /// This class describes the interface of extendable undirected
1941 /// bipartite graphs. It extends \ref BaseGraphComponent with
1942 /// functions for adding nodes and edges to the graph. This
1943 /// concept requires \ref AlterableBpGraphComponent.
1944 template <typename BAS = BaseBpGraphComponent>
1945 class ExtendableBpGraphComponent : public BAS {
1949 typedef typename Base::Node Node;
1950 typedef typename Base::RedNode RedNode;
1951 typedef typename Base::BlueNode BlueNode;
1952 typedef typename Base::Edge Edge;
1954 /// \brief Add a new red node to the digraph.
1956 /// This function adds a red new node to the digraph.
1957 RedNode addRedNode() {
1961 /// \brief Add a new blue node to the digraph.
1963 /// This function adds a blue new node to the digraph.
1964 BlueNode addBlueNode() {
1968 /// \brief Add a new edge connecting the given two nodes.
1970 /// This function adds a new edge connecting the given two nodes
1971 /// of the graph. The first node has to be a red node, and the
1972 /// second one a blue node.
1973 Edge addEdge(const RedNode&, const BlueNode&) {
1976 Edge addEdge(const BlueNode&, const RedNode&) {
1980 template <typename _BpGraph>
1981 struct Constraints {
1982 void constraints() {
1983 checkConcept<Base, _BpGraph>();
1984 typename _BpGraph::RedNode red_node;
1985 typename _BpGraph::BlueNode blue_node;
1986 red_node = bpgraph.addRedNode();
1987 blue_node = bpgraph.addBlueNode();
1988 typename _BpGraph::Edge edge;
1989 edge = bpgraph.addEdge(red_node, blue_node);
1990 edge = bpgraph.addEdge(blue_node, red_node);
1997 /// \brief Skeleton class for erasable directed graphs.
1999 /// This class describes the interface of erasable directed graphs.
2000 /// It extends \ref BaseDigraphComponent with functions for removing
2001 /// nodes and arcs from the digraph.
2002 /// This concept requires \ref AlterableDigraphComponent.
2003 template <typename BAS = BaseDigraphComponent>
2004 class ErasableDigraphComponent : public BAS {
2008 typedef typename Base::Node Node;
2009 typedef typename Base::Arc Arc;
2011 /// \brief Erase a node from the digraph.
2013 /// This function erases the given node from the digraph and all arcs
2014 /// connected to the node.
2015 void erase(const Node&) {}
2017 /// \brief Erase an arc from the digraph.
2019 /// This function erases the given arc from the digraph.
2020 void erase(const Arc&) {}
2022 template <typename _Digraph>
2023 struct Constraints {
2024 void constraints() {
2025 checkConcept<Base, _Digraph>();
2026 const typename _Digraph::Node node(INVALID);
2027 digraph.erase(node);
2028 const typename _Digraph::Arc arc(INVALID);
2037 /// \brief Skeleton class for erasable undirected graphs.
2039 /// This class describes the interface of erasable undirected graphs.
2040 /// It extends \ref BaseGraphComponent with functions for removing
2041 /// nodes and edges from the graph.
2042 /// This concept requires \ref AlterableGraphComponent.
2043 template <typename BAS = BaseGraphComponent>
2044 class ErasableGraphComponent : public BAS {
2048 typedef typename Base::Node Node;
2049 typedef typename Base::Edge Edge;
2051 /// \brief Erase a node from the graph.
2053 /// This function erases the given node from the graph and all edges
2054 /// connected to the node.
2055 void erase(const Node&) {}
2057 /// \brief Erase an edge from the digraph.
2059 /// This function erases the given edge from the digraph.
2060 void erase(const Edge&) {}
2062 template <typename _Graph>
2063 struct Constraints {
2064 void constraints() {
2065 checkConcept<Base, _Graph>();
2066 const typename _Graph::Node node(INVALID);
2068 const typename _Graph::Edge edge(INVALID);
2077 /// \brief Skeleton class for erasable undirected graphs.
2079 /// This class describes the interface of erasable undirected
2080 /// bipartite graphs. It extends \ref BaseBpGraphComponent with
2081 /// functions for removing nodes and edges from the graph. This
2082 /// concept requires \ref AlterableBpGraphComponent.
2083 template <typename BAS = BaseBpGraphComponent>
2084 class ErasableBpGraphComponent : public ErasableGraphComponent<BAS> {};
2086 /// \brief Skeleton class for clearable directed graphs.
2088 /// This class describes the interface of clearable directed graphs.
2089 /// It extends \ref BaseDigraphComponent with a function for clearing
2091 /// This concept requires \ref AlterableDigraphComponent.
2092 template <typename BAS = BaseDigraphComponent>
2093 class ClearableDigraphComponent : public BAS {
2098 /// \brief Erase all nodes and arcs from the digraph.
2100 /// This function erases all nodes and arcs from the digraph.
2103 template <typename _Digraph>
2104 struct Constraints {
2105 void constraints() {
2106 checkConcept<Base, _Digraph>();
2115 /// \brief Skeleton class for clearable undirected graphs.
2117 /// This class describes the interface of clearable undirected graphs.
2118 /// It extends \ref BaseGraphComponent with a function for clearing
2120 /// This concept requires \ref AlterableGraphComponent.
2121 template <typename BAS = BaseGraphComponent>
2122 class ClearableGraphComponent : public ClearableDigraphComponent<BAS> {};
2124 /// \brief Skeleton class for clearable undirected biparite graphs.
2126 /// This class describes the interface of clearable undirected
2127 /// bipartite graphs. It extends \ref BaseBpGraphComponent with a
2128 /// function for clearing the graph. This concept requires \ref
2129 /// AlterableBpGraphComponent.
2130 template <typename BAS = BaseBpGraphComponent>
2131 class ClearableBpGraphComponent : public ClearableGraphComponent<BAS> {};