COIN-OR::LEMON - Graph Library

source: lemon/lemon/concepts/graph_components.h @ 1416:f179aa1045a4

Last change on this file since 1416:f179aa1045a4 was 1416:f179aa1045a4, checked in by Peter Kovacs <kpeter@…>, 6 years ago

Suppress unused typdef warnings (#615)

File size: 69.2 KB
Line 
1/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 *
3 * This file is a part of LEMON, a generic C++ optimization library.
4 *
5 * Copyright (C) 2003-2013
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 *
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.
12 *
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
15 * purpose.
16 *
17 */
18
19///\ingroup graph_concepts
20///\file
21///\brief The concepts of graph components.
22
23#ifndef LEMON_CONCEPTS_GRAPH_COMPONENTS_H
24#define LEMON_CONCEPTS_GRAPH_COMPONENTS_H
25
26#include <lemon/core.h>
27#include <lemon/concepts/maps.h>
28
29#include <lemon/bits/alteration_notifier.h>
30
31namespace lemon {
32  namespace concepts {
33
34    /// \brief Concept class for \c Node, \c Arc and \c Edge types.
35    ///
36    /// This class describes the concept of \c Node, \c Arc and \c Edge
37    /// subtypes of digraph and graph types.
38    ///
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'.
44#ifndef DOXYGEN
45    template <char sel = '0'>
46#endif
47    class GraphItem {
48    public:
49      /// \brief Default constructor.
50      ///
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
54      /// as uninitialized.
55      GraphItem() {}
56
57      /// \brief Copy constructor.
58      ///
59      /// Copy constructor.
60      GraphItem(const GraphItem &) {}
61
62      /// \brief Constructor for conversion from \c INVALID.
63      ///
64      /// Constructor for conversion from \c INVALID.
65      /// It initializes the item to be invalid.
66      /// \sa Invalid for more details.
67      GraphItem(Invalid) {}
68
69      /// \brief Assignment operator.
70      ///
71      /// Assignment operator for the item.
72      GraphItem& operator=(const GraphItem&) { return *this; }
73
74      /// \brief Assignment operator for INVALID.
75      ///
76      /// This operator makes the item invalid.
77      GraphItem& operator=(Invalid) { return *this; }
78
79      /// \brief Equality operator.
80      ///
81      /// Equality operator.
82      bool operator==(const GraphItem&) const { return false; }
83
84      /// \brief Inequality operator.
85      ///
86      /// Inequality operator.
87      bool operator!=(const GraphItem&) const { return false; }
88
89      /// \brief Ordering operator.
90      ///
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).
94      ///
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; }
99
100      template<typename _GraphItem>
101      struct Constraints {
102        void constraints() {
103          _GraphItem i1;
104          i1=INVALID;
105          _GraphItem i2 = i1;
106          ::lemon::ignore_unused_variable_warning(i2);
107          _GraphItem i3 = INVALID;
108
109          i1 = i2 = i3;
110
111          bool b;
112          ::lemon::ignore_unused_variable_warning(b);
113
114          b = (ia == ib) && (ia != ib);
115          b = (ia == INVALID) && (ib != INVALID);
116          b = (ia < ib);
117        }
118
119        const _GraphItem &ia;
120        const _GraphItem &ib;
121        Constraints() {}
122      };
123    };
124
125    /// \brief Base skeleton class for directed graphs.
126    ///
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 {
132    public:
133
134      typedef BaseDigraphComponent Digraph;
135
136      /// \brief Node class of the digraph.
137      ///
138      /// This class represents the nodes of the digraph.
139      typedef GraphItem<'n'> Node;
140
141      /// \brief Arc class of the digraph.
142      ///
143      /// This class represents the arcs of the digraph.
144      typedef GraphItem<'a'> Arc;
145
146      /// \brief Return the source node of an arc.
147      ///
148      /// This function returns the source node of an arc.
149      Node source(const Arc&) const { return INVALID; }
150
151      /// \brief Return the target node of an arc.
152      ///
153      /// This function returns the target node of an arc.
154      Node target(const Arc&) const { return INVALID; }
155
156      /// \brief Return the opposite node on the given arc.
157      ///
158      /// This function returns the opposite node on the given arc.
159      Node oppositeNode(const Node&, const Arc&) const {
160        return INVALID;
161      }
162
163      template <typename _Digraph>
164      struct Constraints {
165        typedef typename _Digraph::Node Node;
166        typedef typename _Digraph::Arc Arc;
167
168        void constraints() {
169          checkConcept<GraphItem<'n'>, Node>();
170          checkConcept<GraphItem<'a'>, Arc>();
171          {
172            Node n;
173            Arc e(INVALID);
174            n = digraph.source(e);
175            n = digraph.target(e);
176            n = digraph.oppositeNode(n, e);
177          }
178        }
179
180        const _Digraph& digraph;
181        Constraints() {}
182      };
183    };
184
185    /// \brief Base skeleton class for undirected graphs.
186    ///
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 {
193    public:
194
195      typedef BaseGraphComponent Graph;
196
197      typedef BaseDigraphComponent::Node Node;
198      typedef BaseDigraphComponent::Arc Arc;
199
200      /// \brief Undirected edge class of the graph.
201      ///
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;
207
208      public:
209        /// \brief Default constructor.
210        ///
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.
215        Edge() {}
216
217        /// \brief Copy constructor.
218        ///
219        /// Copy constructor.
220        Edge(const Edge &) : Parent() {}
221
222        /// \brief Constructor for conversion from \c INVALID.
223        ///
224        /// Constructor for conversion from \c INVALID.
225        /// It initializes the item to be invalid.
226        /// \sa Invalid for more details.
227        Edge(Invalid) {}
228
229        /// \brief Constructor for conversion from an arc.
230        ///
231        /// Constructor for conversion from an arc.
232        /// Besides the core graph item functionality each arc should
233        /// be convertible to the represented edge.
234        Edge(const Arc&) {}
235     };
236
237      /// \brief Return one end node of an edge.
238      ///
239      /// This function returns one end node of an edge.
240      Node u(const Edge&) const { return INVALID; }
241
242      /// \brief Return the other end node of an edge.
243      ///
244      /// This function returns the other end node of an edge.
245      Node v(const Edge&) const { return INVALID; }
246
247      /// \brief Return a directed arc related to an edge.
248      ///
249      /// This function returns a directed arc from its direction and the
250      /// represented edge.
251      Arc direct(const Edge&, bool) const { return INVALID; }
252
253      /// \brief Return a directed arc related to an edge.
254      ///
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; }
258
259      /// \brief Return the direction of the arc.
260      ///
261      /// Returns the direction of the arc. Each arc represents an
262      /// edge with a direction. It gives back the
263      /// direction.
264      bool direction(const Arc&) const { return true; }
265
266      /// \brief Return the opposite arc.
267      ///
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; }
271
272      template <typename _Graph>
273      struct Constraints {
274        typedef typename _Graph::Node Node;
275        typedef typename _Graph::Arc Arc;
276        typedef typename _Graph::Edge Edge;
277
278        void constraints() {
279          checkConcept<BaseDigraphComponent, _Graph>();
280          checkConcept<GraphItem<'e'>, Edge>();
281          {
282            Node n;
283            Edge ue(INVALID);
284            Arc e;
285            n = graph.u(ue);
286            n = graph.v(ue);
287            e = graph.direct(ue, true);
288            e = graph.direct(ue, false);
289            e = graph.direct(ue, n);
290            e = graph.oppositeArc(e);
291            ue = e;
292            bool d = graph.direction(e);
293            ::lemon::ignore_unused_variable_warning(d);
294          }
295        }
296
297        const _Graph& graph;
298      Constraints() {}
299      };
300
301    };
302
303    /// \brief Base skeleton class for undirected bipartite graphs.
304    ///
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 {
312    public:
313
314      typedef BaseBpGraphComponent BpGraph;
315
316      typedef BaseDigraphComponent::Node Node;
317      typedef BaseDigraphComponent::Arc Arc;
318
319      /// \brief Class to represent red nodes.
320      ///
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 {
324        typedef Node Parent;
325
326      public:
327        /// \brief Default constructor.
328        ///
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.
333        RedNode() {}
334
335        /// \brief Copy constructor.
336        ///
337        /// Copy constructor.
338        RedNode(const RedNode &) : Parent() {}
339
340        /// \brief Constructor for conversion from \c INVALID.
341        ///
342        /// Constructor for conversion from \c INVALID.
343        /// It initializes the item to be invalid.
344        /// \sa Invalid for more details.
345        RedNode(Invalid) {}
346      };
347
348      /// \brief Class to represent blue nodes.
349      ///
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 {
353        typedef Node Parent;
354
355      public:
356        /// \brief Default constructor.
357        ///
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.
362        BlueNode() {}
363
364        /// \brief Copy constructor.
365        ///
366        /// Copy constructor.
367        BlueNode(const BlueNode &) : Parent() {}
368
369        /// \brief Constructor for conversion from \c INVALID.
370        ///
371        /// Constructor for conversion from \c INVALID.
372        /// It initializes the item to be invalid.
373        /// \sa Invalid for more details.
374        BlueNode(Invalid) {}
375
376        /// \brief Constructor for conversion from a node.
377        ///
378        /// Constructor for conversion from a node. The conversion can
379        /// be invalid, since the Node can be member of the red
380        /// set.
381        BlueNode(const Node&) {}
382      };
383
384      /// \brief Gives back %true for red nodes.
385      ///
386      /// Gives back %true for red nodes.
387      bool red(const Node&) const { return true; }
388
389      /// \brief Gives back %true for blue nodes.
390      ///
391      /// Gives back %true for blue nodes.
392      bool blue(const Node&) const { return true; }
393
394      /// \brief Gives back the red end node of the edge.
395      ///
396      /// Gives back the red end node of the edge.
397      RedNode redNode(const Edge&) const { return RedNode(); }
398
399      /// \brief Gives back the blue end node of the edge.
400      ///
401      /// Gives back the blue end node of the edge.
402      BlueNode blueNode(const Edge&) const { return BlueNode(); }
403
404      /// \brief Converts the node to red node object.
405      ///
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(); }
410
411      /// \brief Converts the node to blue node object.
412      ///
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(); }
417
418      /// \brief Converts the node to red node object.
419      ///
420      /// This function converts safely the node to red node
421      /// object. If the node is not from the red partition, then it
422      /// returns INVALID.
423      RedNode asRedNode(const Node&) const { return RedNode(); }
424
425      /// \brief Converts the node to blue node object.
426      ///
427      /// This function converts unsafely the node to blue node
428      /// object. If the node is not from the blue partition, then it
429      /// returns INVALID.
430      BlueNode asBlueNode(const Node&) const { return BlueNode(); }
431
432      template <typename _BpGraph>
433      struct Constraints {
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;
439
440        void constraints() {
441          checkConcept<BaseGraphComponent, _BpGraph>();
442          checkConcept<GraphItem<'n'>, RedNode>();
443          checkConcept<GraphItem<'n'>, BlueNode>();
444          {
445            Node n;
446            RedNode rn;
447            BlueNode bn;
448            Node rnan = rn;
449            Node bnan = bn;
450            Edge e;
451            bool b;
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);
461          }
462        }
463
464        const _BpGraph& bpgraph;
465      };
466
467    };
468
469    /// \brief Skeleton class for \e idable directed graphs.
470    ///
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 {
477    public:
478
479      typedef BAS Base;
480      typedef typename Base::Node Node;
481      typedef typename Base::Arc Arc;
482
483      /// \brief Return a unique integer id for the given node.
484      ///
485      /// This function returns a unique integer id for the given node.
486      int id(const Node&) const { return -1; }
487
488      /// \brief Return the node by its unique id.
489      ///
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; }
494
495      /// \brief Return a unique integer id for the given arc.
496      ///
497      /// This function returns a unique integer id for the given arc.
498      int id(const Arc&) const { return -1; }
499
500      /// \brief Return the arc by its unique id.
501      ///
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; }
506
507      /// \brief Return an integer greater or equal to the maximum
508      /// node id.
509      ///
510      /// This function returns an integer greater or equal to the
511      /// maximum node id.
512      int maxNodeId() const { return -1; }
513
514      /// \brief Return an integer greater or equal to the maximum
515      /// arc id.
516      ///
517      /// This function returns an integer greater or equal to the
518      /// maximum arc id.
519      int maxArcId() const { return -1; }
520
521      template <typename _Digraph>
522      struct Constraints {
523
524        void constraints() {
525          checkConcept<Base, _Digraph >();
526          typename _Digraph::Node node;
527          node=INVALID;
528          int nid = digraph.id(node);
529          nid = digraph.id(node);
530          node = digraph.nodeFromId(nid);
531          typename _Digraph::Arc arc;
532          arc=INVALID;
533          int eid = digraph.id(arc);
534          eid = digraph.id(arc);
535          arc = digraph.arcFromId(eid);
536
537          nid = digraph.maxNodeId();
538          ::lemon::ignore_unused_variable_warning(nid);
539          eid = digraph.maxArcId();
540          ::lemon::ignore_unused_variable_warning(eid);
541        }
542
543        const _Digraph& digraph;
544        Constraints() {}
545      };
546    };
547
548    /// \brief Skeleton class for \e idable undirected graphs.
549    ///
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> {
557    public:
558
559      typedef BAS Base;
560      typedef typename Base::Edge Edge;
561
562      using IDableDigraphComponent<Base>::id;
563
564      /// \brief Return a unique integer id for the given edge.
565      ///
566      /// This function returns a unique integer id for the given edge.
567      int id(const Edge&) const { return -1; }
568
569      /// \brief Return the edge by its unique id.
570      ///
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; }
575
576      /// \brief Return an integer greater or equal to the maximum
577      /// edge id.
578      ///
579      /// This function returns an integer greater or equal to the
580      /// maximum edge id.
581      int maxEdgeId() const { return -1; }
582
583      template <typename _Graph>
584      struct Constraints {
585
586        void constraints() {
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);
594        }
595
596        const _Graph& graph;
597        Constraints() {}
598      };
599    };
600
601    /// \brief Skeleton class for \e idable undirected bipartite graphs.
602    ///
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> {
611    public:
612
613      typedef BAS Base;
614      typedef IDableGraphComponent<BAS> Parent;
615      typedef typename Base::Node Node;
616      typedef typename Base::RedNode RedNode;
617      typedef typename Base::BlueNode BlueNode;
618
619      using Parent::id;
620
621      /// \brief Return a unique integer id for the given node in the red set.
622      ///
623      /// Return a unique integer id for the given node in the red set.
624      int id(const RedNode&) const { return -1; }
625
626      /// \brief Return a unique integer id for the given node in the blue set.
627      ///
628      /// Return a unique integer id for the given node in the blue set.
629      int id(const BlueNode&) const { return -1; }
630
631      /// \brief Return an integer greater or equal to the maximum
632      /// node id in the red set.
633      ///
634      /// Return an integer greater or equal to the maximum
635      /// node id in the red set.
636      int maxRedId() const { return -1; }
637
638      /// \brief Return an integer greater or equal to the maximum
639      /// node id in the blue set.
640      ///
641      /// Return an integer greater or equal to the maximum
642      /// node id in the blue set.
643      int maxBlueId() const { return -1; }
644
645      template <typename _BpGraph>
646      struct Constraints {
647
648        void constraints() {
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);
659        }
660
661        const _BpGraph& bpgraph;
662      };
663    };
664
665    /// \brief Concept class for \c NodeIt, \c ArcIt and \c EdgeIt types.
666    ///
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 {
671    public:
672      /// \brief Default constructor.
673      ///
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.
678      GraphItemIt() {}
679
680      /// \brief Copy constructor.
681      ///
682      /// Copy constructor.
683      GraphItemIt(const GraphItemIt& it) : Item(it) {}
684
685      /// \brief Constructor that sets the iterator to the first item.
686      ///
687      /// Constructor that sets the iterator to the first item.
688      explicit GraphItemIt(const GR&) {}
689
690      /// \brief Constructor for conversion from \c INVALID.
691      ///
692      /// Constructor for conversion from \c INVALID.
693      /// It initializes the iterator to be invalid.
694      /// \sa Invalid for more details.
695      GraphItemIt(Invalid) {}
696
697      /// \brief Assignment operator.
698      ///
699      /// Assignment operator for the iterator.
700      GraphItemIt& operator=(const GraphItemIt&) { return *this; }
701
702      /// \brief Increment the iterator.
703      ///
704      /// This operator increments the iterator, i.e. assigns it to the
705      /// next item.
706      GraphItemIt& operator++() { return *this; }
707
708      /// \brief Equality operator
709      ///
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;}
714
715      /// \brief Inequality operator
716      ///
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;}
721
722      template<typename _GraphItemIt>
723      struct Constraints {
724        void constraints() {
725          checkConcept<GraphItem<>, _GraphItemIt>();
726          _GraphItemIt it1(g);
727          _GraphItemIt it2;
728          _GraphItemIt it3 = it1;
729          _GraphItemIt it4 = INVALID;
730          ::lemon::ignore_unused_variable_warning(it3);
731          ::lemon::ignore_unused_variable_warning(it4);
732
733          it2 = ++it1;
734          ++it2 = it1;
735          ++(++it1);
736
737          Item bi = it1;
738          ::lemon::ignore_unused_variable_warning(bi);
739          bi = it2;
740        }
741        const GR& g;
742        Constraints() {}
743      };
744    };
745
746    /// \brief Concept class for \c InArcIt, \c OutArcIt and
747    /// \c IncEdgeIt types.
748    ///
749    /// This class describes the concept of \c InArcIt, \c OutArcIt
750    /// and \c IncEdgeIt subtypes of digraph and graph types.
751    ///
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,
759              char sel = '0'>
760    class GraphIncIt : public Item {
761    public:
762      /// \brief Default constructor.
763      ///
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.
768      GraphIncIt() {}
769
770      /// \brief Copy constructor.
771      ///
772      /// Copy constructor.
773      GraphIncIt(const GraphIncIt& it) : Item(it) {}
774
775      /// \brief Constructor that sets the iterator to the first
776      /// incoming or outgoing arc.
777      ///
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&) {}
781
782      /// \brief Constructor for conversion from \c INVALID.
783      ///
784      /// Constructor for conversion from \c INVALID.
785      /// It initializes the iterator to be invalid.
786      /// \sa Invalid for more details.
787      GraphIncIt(Invalid) {}
788
789      /// \brief Assignment operator.
790      ///
791      /// Assignment operator for the iterator.
792      GraphIncIt& operator=(const GraphIncIt&) { return *this; }
793
794      /// \brief Increment the iterator.
795      ///
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; }
799
800      /// \brief Equality operator
801      ///
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;}
806
807      /// \brief Inequality operator
808      ///
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;}
813
814      template <typename _GraphIncIt>
815      struct Constraints {
816        void constraints() {
817          checkConcept<GraphItem<sel>, _GraphIncIt>();
818          _GraphIncIt it1(graph, node);
819          _GraphIncIt it2;
820          _GraphIncIt it3 = it1;
821          _GraphIncIt it4 = INVALID;
822          ::lemon::ignore_unused_variable_warning(it3);
823          ::lemon::ignore_unused_variable_warning(it4);
824
825          it2 = ++it1;
826          ++it2 = it1;
827          ++(++it1);
828          Item e = it1;
829          ::lemon::ignore_unused_variable_warning(e);
830          e = it2;
831        }
832        const Base& node;
833        const GR& graph;
834        Constraints() {}
835      };
836    };
837
838    /// \brief Skeleton class for iterable directed graphs.
839    ///
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 {
846
847    public:
848
849      typedef BAS Base;
850      typedef typename Base::Node Node;
851      typedef typename Base::Arc Arc;
852
853      typedef IterableDigraphComponent Digraph;
854
855      /// \name Base Iteration
856      ///
857      /// This interface provides functions for iteration on digraph items.
858      ///
859      /// @{
860
861      /// \brief Return the first node.
862      ///
863      /// This function gives back the first node in the iteration order.
864      void first(Node&) const {}
865
866      /// \brief Return the next node.
867      ///
868      /// This function gives back the next node in the iteration order.
869      void next(Node&) const {}
870
871      /// \brief Return the first arc.
872      ///
873      /// This function gives back the first arc in the iteration order.
874      void first(Arc&) const {}
875
876      /// \brief Return the next arc.
877      ///
878      /// This function gives back the next arc in the iteration order.
879      void next(Arc&) const {}
880
881      /// \brief Return the first arc incoming to the given node.
882      ///
883      /// This function gives back the first arc incoming to the
884      /// given node.
885      void firstIn(Arc&, const Node&) const {}
886
887      /// \brief Return the next arc incoming to the given node.
888      ///
889      /// This function gives back the next arc incoming to the
890      /// given node.
891      void nextIn(Arc&) const {}
892
893      /// \brief Return the first arc outgoing form the given node.
894      ///
895      /// This function gives back the first arc outgoing form the
896      /// given node.
897      void firstOut(Arc&, const Node&) const {}
898
899      /// \brief Return the next arc outgoing form the given node.
900      ///
901      /// This function gives back the next arc outgoing form the
902      /// given node.
903      void nextOut(Arc&) const {}
904
905      /// @}
906
907      /// \name Class Based Iteration
908      ///
909      /// This interface provides iterator classes for digraph items.
910      ///
911      /// @{
912
913      /// \brief This iterator goes through each node.
914      ///
915      /// This iterator goes through each node.
916      ///
917      typedef GraphItemIt<Digraph, Node> NodeIt;
918
919      /// \brief This iterator goes through each arc.
920      ///
921      /// This iterator goes through each arc.
922      ///
923      typedef GraphItemIt<Digraph, Arc> ArcIt;
924
925      /// \brief This iterator goes trough the incoming arcs of a node.
926      ///
927      /// This iterator goes trough the \e incoming arcs of a certain node
928      /// of a digraph.
929      typedef GraphIncIt<Digraph, Arc, Node, 'i'> InArcIt;
930
931      /// \brief This iterator goes trough the outgoing arcs of a node.
932      ///
933      /// This iterator goes trough the \e outgoing arcs of a certain node
934      /// of a digraph.
935      typedef GraphIncIt<Digraph, Arc, Node, 'o'> OutArcIt;
936
937      /// \brief The base node of the iterator.
938      ///
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; }
942
943      /// \brief The running node of the iterator.
944      ///
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; }
948
949      /// \brief The base node of the iterator.
950      ///
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; }
954
955      /// \brief The running node of the iterator.
956      ///
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; }
960
961      /// @}
962
963      template <typename _Digraph>
964      struct Constraints {
965        void constraints() {
966          checkConcept<Base, _Digraph>();
967
968          {
969            typename _Digraph::Node node(INVALID);
970            typename _Digraph::Arc arc(INVALID);
971            {
972              digraph.first(node);
973              digraph.next(node);
974            }
975            {
976              digraph.first(arc);
977              digraph.next(arc);
978            }
979            {
980              digraph.firstIn(arc, node);
981              digraph.nextIn(arc);
982            }
983            {
984              digraph.firstOut(arc, node);
985              digraph.nextOut(arc);
986            }
987          }
988
989          {
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>();
998
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);
1007          }
1008        }
1009
1010        const _Digraph& digraph;
1011        Constraints() {}
1012      };
1013    };
1014
1015    /// \brief Skeleton class for iterable undirected graphs.
1016    ///
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> {
1023    public:
1024
1025      typedef BAS Base;
1026      typedef typename Base::Node Node;
1027      typedef typename Base::Arc Arc;
1028      typedef typename Base::Edge Edge;
1029
1030
1031      typedef IterableGraphComponent Graph;
1032
1033      /// \name Base Iteration
1034      ///
1035      /// This interface provides functions for iteration on edges.
1036      ///
1037      /// @{
1038
1039      using IterableDigraphComponent<Base>::first;
1040      using IterableDigraphComponent<Base>::next;
1041
1042      /// \brief Return the first edge.
1043      ///
1044      /// This function gives back the first edge in the iteration order.
1045      void first(Edge&) const {}
1046
1047      /// \brief Return the next edge.
1048      ///
1049      /// This function gives back the next edge in the iteration order.
1050      void next(Edge&) const {}
1051
1052      /// \brief Return the first edge incident to the given node.
1053      ///
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
1057      /// given node.
1058      void firstInc(Edge&, bool&, const Node&) const {}
1059
1060      /// \brief Gives back the next of the edges from the
1061      /// given node.
1062      ///
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 {}
1066
1067      using IterableDigraphComponent<Base>::baseNode;
1068      using IterableDigraphComponent<Base>::runningNode;
1069
1070      /// @}
1071
1072      /// \name Class Based Iteration
1073      ///
1074      /// This interface provides iterator classes for edges.
1075      ///
1076      /// @{
1077
1078      /// \brief This iterator goes through each edge.
1079      ///
1080      /// This iterator goes through each edge.
1081      typedef GraphItemIt<Graph, Edge> EdgeIt;
1082
1083      /// \brief This iterator goes trough the incident edges of a
1084      /// node.
1085      ///
1086      /// This iterator goes trough the incident edges of a certain
1087      /// node of a graph.
1088      typedef GraphIncIt<Graph, Edge, Node, 'e'> IncEdgeIt;
1089
1090      /// \brief The base node of the iterator.
1091      ///
1092      /// This function gives back the base node of the iterator.
1093      Node baseNode(const IncEdgeIt&) const { return INVALID; }
1094
1095      /// \brief The running node of the iterator.
1096      ///
1097      /// This function gives back the running node of the iterator.
1098      Node runningNode(const IncEdgeIt&) const { return INVALID; }
1099
1100      /// @}
1101
1102      template <typename _Graph>
1103      struct Constraints {
1104        void constraints() {
1105          checkConcept<IterableDigraphComponent<Base>, _Graph>();
1106
1107          {
1108            typename _Graph::Node node(INVALID);
1109            typename _Graph::Edge edge(INVALID);
1110            bool dir;
1111            {
1112              graph.first(edge);
1113              graph.next(edge);
1114            }
1115            {
1116              graph.firstInc(edge, dir, node);
1117              graph.nextInc(edge, dir);
1118            }
1119
1120          }
1121
1122          {
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>();
1127
1128            typename _Graph::Node n;
1129            const typename _Graph::IncEdgeIt ieit(INVALID);
1130            n = graph.baseNode(ieit);
1131            n = graph.runningNode(ieit);
1132          }
1133        }
1134
1135        const _Graph& graph;
1136        Constraints() {}
1137      };
1138    };
1139
1140    /// \brief Skeleton class for iterable undirected bipartite graphs.
1141    ///
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> {
1148    public:
1149
1150      typedef BAS Base;
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;
1156
1157      typedef IterableBpGraphComponent BpGraph;
1158
1159      using IterableGraphComponent<BAS>::first;
1160      using IterableGraphComponent<BAS>::next;
1161
1162      /// \name Base Iteration
1163      ///
1164      /// This interface provides functions for iteration on red and blue nodes.
1165      ///
1166      /// @{
1167
1168      /// \brief Return the first red node.
1169      ///
1170      /// This function gives back the first red node in the iteration order.
1171      void first(RedNode&) const {}
1172
1173      /// \brief Return the next red node.
1174      ///
1175      /// This function gives back the next red node in the iteration order.
1176      void next(RedNode&) const {}
1177
1178      /// \brief Return the first blue node.
1179      ///
1180      /// This function gives back the first blue node in the iteration order.
1181      void first(BlueNode&) const {}
1182
1183      /// \brief Return the next blue node.
1184      ///
1185      /// This function gives back the next blue node in the iteration order.
1186      void next(BlueNode&) const {}
1187
1188
1189      /// @}
1190
1191      /// \name Class Based Iteration
1192      ///
1193      /// This interface provides iterator classes for red and blue nodes.
1194      ///
1195      /// @{
1196
1197      /// \brief This iterator goes through each red node.
1198      ///
1199      /// This iterator goes through each red node.
1200      typedef GraphItemIt<BpGraph, RedNode> RedNodeIt;
1201
1202      /// \brief This iterator goes through each blue node.
1203      ///
1204      /// This iterator goes through each blue node.
1205      typedef GraphItemIt<BpGraph, BlueNode> BlueNodeIt;
1206
1207      /// @}
1208
1209      template <typename _BpGraph>
1210      struct Constraints {
1211        void constraints() {
1212          checkConcept<IterableGraphComponent<Base>, _BpGraph>();
1213
1214          typename _BpGraph::RedNode rn(INVALID);
1215          bpgraph.first(rn);
1216          bpgraph.next(rn);
1217          typename _BpGraph::BlueNode bn(INVALID);
1218          bpgraph.first(bn);
1219          bpgraph.next(bn);
1220
1221          checkConcept<GraphItemIt<_BpGraph, typename _BpGraph::RedNode>,
1222            typename _BpGraph::RedNodeIt>();
1223          checkConcept<GraphItemIt<_BpGraph, typename _BpGraph::BlueNode>,
1224            typename _BpGraph::BlueNodeIt>();
1225        }
1226
1227        const _BpGraph& bpgraph;
1228      };
1229    };
1230
1231    /// \brief Skeleton class for alterable directed graphs.
1232    ///
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 {
1242    public:
1243
1244      typedef BAS Base;
1245      typedef typename Base::Node Node;
1246      typedef typename Base::Arc Arc;
1247
1248
1249      /// Node alteration notifier class.
1250      typedef AlterationNotifier<AlterableDigraphComponent, Node>
1251      NodeNotifier;
1252      /// Arc alteration notifier class.
1253      typedef AlterationNotifier<AlterableDigraphComponent, Arc>
1254      ArcNotifier;
1255
1256      mutable NodeNotifier node_notifier;
1257      mutable ArcNotifier arc_notifier;
1258
1259      /// \brief Return the node alteration notifier.
1260      ///
1261      /// This function gives back the node alteration notifier.
1262      NodeNotifier& notifier(Node) const {
1263        return node_notifier;
1264      }
1265
1266      /// \brief Return the arc alteration notifier.
1267      ///
1268      /// This function gives back the arc alteration notifier.
1269      ArcNotifier& notifier(Arc) const {
1270        return arc_notifier;
1271      }
1272
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());
1279
1280          typename _Digraph::ArcNotifier& en
1281            = digraph.notifier(typename _Digraph::Arc());
1282
1283          ::lemon::ignore_unused_variable_warning(nn);
1284          ::lemon::ignore_unused_variable_warning(en);
1285        }
1286
1287        const _Digraph& digraph;
1288        Constraints() {}
1289      };
1290    };
1291
1292    /// \brief Skeleton class for alterable undirected graphs.
1293    ///
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> {
1303    public:
1304
1305      typedef BAS Base;
1306      typedef AlterableDigraphComponent<Base> Parent;
1307      typedef typename Base::Edge Edge;
1308
1309
1310      /// Edge alteration notifier class.
1311      typedef AlterationNotifier<AlterableGraphComponent, Edge>
1312      EdgeNotifier;
1313
1314      mutable EdgeNotifier edge_notifier;
1315
1316      using Parent::notifier;
1317
1318      /// \brief Return the edge alteration notifier.
1319      ///
1320      /// This function gives back the edge alteration notifier.
1321      EdgeNotifier& notifier(Edge) const {
1322        return edge_notifier;
1323      }
1324
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);
1332        }
1333
1334        const _Graph& graph;
1335        Constraints() {}
1336      };
1337    };
1338
1339    /// \brief Skeleton class for alterable undirected bipartite graphs.
1340    ///
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> {
1350    public:
1351
1352      typedef BAS Base;
1353      typedef AlterableGraphComponent<Base> Parent;
1354      typedef typename Base::RedNode RedNode;
1355      typedef typename Base::BlueNode BlueNode;
1356
1357
1358      /// Red node alteration notifier class.
1359      typedef AlterationNotifier<AlterableBpGraphComponent, RedNode>
1360      RedNodeNotifier;
1361
1362      /// Blue node alteration notifier class.
1363      typedef AlterationNotifier<AlterableBpGraphComponent, BlueNode>
1364      BlueNodeNotifier;
1365
1366      mutable RedNodeNotifier red_node_notifier;
1367      mutable BlueNodeNotifier blue_node_notifier;
1368
1369      using Parent::notifier;
1370
1371      /// \brief Return the red node alteration notifier.
1372      ///
1373      /// This function gives back the red node alteration notifier.
1374      RedNodeNotifier& notifier(RedNode) const {
1375        return red_node_notifier;
1376      }
1377
1378      /// \brief Return the blue node alteration notifier.
1379      ///
1380      /// This function gives back the blue node alteration notifier.
1381      BlueNodeNotifier& notifier(BlueNode) const {
1382        return blue_node_notifier;
1383      }
1384
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);
1395        }
1396
1397        const _BpGraph& bpgraph;
1398      };
1399    };
1400
1401    /// \brief Concept class for standard graph maps.
1402    ///
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;
1410
1411    public:
1412
1413      /// The key type of the map.
1414      typedef K Key;
1415      /// The value type of the map.
1416      typedef V Value;
1417      /// The reference type of the map.
1418      typedef Value& Reference;
1419      /// The const reference type of the map.
1420      typedef const Value& ConstReference;
1421
1422      // The reference map tag.
1423      typedef True ReferenceMapTag;
1424
1425      /// \brief Construct a new map.
1426      ///
1427      /// Construct a new map for the graph.
1428      explicit GraphMap(const GR&) {}
1429      /// \brief Construct a new map with default value.
1430      ///
1431      /// Construct a new map for the graph and initalize the values.
1432      GraphMap(const GR&, const Value&) {}
1433
1434    private:
1435      /// \brief Copy constructor.
1436      ///
1437      /// Copy Constructor.
1438      GraphMap(const GraphMap&) : Parent() {}
1439
1440      /// \brief Assignment operator.
1441      ///
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>();
1448        return *this;
1449      }
1450
1451    public:
1452      template<typename _Map>
1453      struct Constraints {
1454        void constraints() {
1455          checkConcept
1456            <ReferenceMap<Key, Value, Value&, const Value&>, _Map>();
1457          _Map m1(g);
1458          _Map m2(g,t);
1459
1460          // Copy constructor
1461          // _Map m3(m);
1462
1463          // Assignment operator
1464          // ReadMap<Key, Value> cmap;
1465          // m3 = cmap;
1466
1467          ::lemon::ignore_unused_variable_warning(m1);
1468          ::lemon::ignore_unused_variable_warning(m2);
1469          // ::lemon::ignore_unused_variable_warning(m3);
1470        }
1471
1472        const _Map &m;
1473        const GR &g;
1474        const typename GraphMap::Value &t;
1475        Constraints() {}
1476      };
1477
1478    };
1479
1480    /// \brief Skeleton class for mappable directed graphs.
1481    ///
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  {
1488    public:
1489
1490      typedef BAS Base;
1491      typedef typename Base::Node Node;
1492      typedef typename Base::Arc Arc;
1493
1494      typedef MappableDigraphComponent Digraph;
1495
1496      /// \brief Standard graph map for the nodes.
1497      ///
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;
1503
1504      public:
1505        /// \brief Construct a new map.
1506        ///
1507        /// Construct a new map for the digraph.
1508        explicit NodeMap(const MappableDigraphComponent& digraph)
1509          : Parent(digraph) {}
1510
1511        /// \brief Construct a new map with default value.
1512        ///
1513        /// Construct a new map for the digraph and initalize the values.
1514        NodeMap(const MappableDigraphComponent& digraph, const V& value)
1515          : Parent(digraph, value) {}
1516
1517      private:
1518        /// \brief Copy constructor.
1519        ///
1520        /// Copy Constructor.
1521        NodeMap(const NodeMap& nm) : Parent(nm) {}
1522
1523        /// \brief Assignment operator.
1524        ///
1525        /// Assignment operator.
1526        template <typename CMap>
1527        NodeMap& operator=(const CMap&) {
1528          checkConcept<ReadMap<Node, V>, CMap>();
1529          return *this;
1530        }
1531
1532      };
1533
1534      /// \brief Standard graph map for the arcs.
1535      ///
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;
1541
1542      public:
1543        /// \brief Construct a new map.
1544        ///
1545        /// Construct a new map for the digraph.
1546        explicit ArcMap(const MappableDigraphComponent& digraph)
1547          : Parent(digraph) {}
1548
1549        /// \brief Construct a new map with default value.
1550        ///
1551        /// Construct a new map for the digraph and initalize the values.
1552        ArcMap(const MappableDigraphComponent& digraph, const V& value)
1553          : Parent(digraph, value) {}
1554
1555      private:
1556        /// \brief Copy constructor.
1557        ///
1558        /// Copy Constructor.
1559        ArcMap(const ArcMap& nm) : Parent(nm) {}
1560
1561        /// \brief Assignment operator.
1562        ///
1563        /// Assignment operator.
1564        template <typename CMap>
1565        ArcMap& operator=(const CMap&) {
1566          checkConcept<ReadMap<Arc, V>, CMap>();
1567          return *this;
1568        }
1569
1570      };
1571
1572
1573      template <typename _Digraph>
1574      struct Constraints {
1575
1576        struct Dummy {
1577          int value;
1578          Dummy() : value(0) {}
1579          Dummy(int _v) : value(_v) {}
1580        };
1581
1582        void constraints() {
1583          checkConcept<Base, _Digraph>();
1584          { // int map test
1585            typedef typename _Digraph::template NodeMap<int> IntNodeMap;
1586            checkConcept<GraphMap<_Digraph, typename _Digraph::Node, int>,
1587              IntNodeMap >();
1588          } { // bool map test
1589            typedef typename _Digraph::template NodeMap<bool> BoolNodeMap;
1590            checkConcept<GraphMap<_Digraph, typename _Digraph::Node, bool>,
1591              BoolNodeMap >();
1592          } { // Dummy map test
1593            typedef typename _Digraph::template NodeMap<Dummy> DummyNodeMap;
1594            checkConcept<GraphMap<_Digraph, typename _Digraph::Node, Dummy>,
1595              DummyNodeMap >();
1596          }
1597
1598          { // int map test
1599            typedef typename _Digraph::template ArcMap<int> IntArcMap;
1600            checkConcept<GraphMap<_Digraph, typename _Digraph::Arc, int>,
1601              IntArcMap >();
1602          } { // bool map test
1603            typedef typename _Digraph::template ArcMap<bool> BoolArcMap;
1604            checkConcept<GraphMap<_Digraph, typename _Digraph::Arc, bool>,
1605              BoolArcMap >();
1606          } { // Dummy map test
1607            typedef typename _Digraph::template ArcMap<Dummy> DummyArcMap;
1608            checkConcept<GraphMap<_Digraph, typename _Digraph::Arc, Dummy>,
1609              DummyArcMap >();
1610          }
1611        }
1612
1613        const _Digraph& digraph;
1614        Constraints() {}
1615      };
1616    };
1617
1618    /// \brief Skeleton class for mappable undirected graphs.
1619    ///
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>  {
1626    public:
1627
1628      typedef BAS Base;
1629      typedef typename Base::Edge Edge;
1630
1631      typedef MappableGraphComponent Graph;
1632
1633      /// \brief Standard graph map for the edges.
1634      ///
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;
1640
1641      public:
1642        /// \brief Construct a new map.
1643        ///
1644        /// Construct a new map for the graph.
1645        explicit EdgeMap(const MappableGraphComponent& graph)
1646          : Parent(graph) {}
1647
1648        /// \brief Construct a new map with default value.
1649        ///
1650        /// Construct a new map for the graph and initalize the values.
1651        EdgeMap(const MappableGraphComponent& graph, const V& value)
1652          : Parent(graph, value) {}
1653
1654      private:
1655        /// \brief Copy constructor.
1656        ///
1657        /// Copy Constructor.
1658        EdgeMap(const EdgeMap& nm) : Parent(nm) {}
1659
1660        /// \brief Assignment operator.
1661        ///
1662        /// Assignment operator.
1663        template <typename CMap>
1664        EdgeMap& operator=(const CMap&) {
1665          checkConcept<ReadMap<Edge, V>, CMap>();
1666          return *this;
1667        }
1668
1669      };
1670
1671
1672      template <typename _Graph>
1673      struct Constraints {
1674
1675        struct Dummy {
1676          int value;
1677          Dummy() : value(0) {}
1678          Dummy(int _v) : value(_v) {}
1679        };
1680
1681        void constraints() {
1682          checkConcept<MappableDigraphComponent<Base>, _Graph>();
1683
1684          { // int map test
1685            typedef typename _Graph::template EdgeMap<int> IntEdgeMap;
1686            checkConcept<GraphMap<_Graph, typename _Graph::Edge, int>,
1687              IntEdgeMap >();
1688          } { // bool map test
1689            typedef typename _Graph::template EdgeMap<bool> BoolEdgeMap;
1690            checkConcept<GraphMap<_Graph, typename _Graph::Edge, bool>,
1691              BoolEdgeMap >();
1692          } { // Dummy map test
1693            typedef typename _Graph::template EdgeMap<Dummy> DummyEdgeMap;
1694            checkConcept<GraphMap<_Graph, typename _Graph::Edge, Dummy>,
1695              DummyEdgeMap >();
1696          }
1697        }
1698
1699        const _Graph& graph;
1700        Constraints() {}
1701      };
1702    };
1703
1704    /// \brief Skeleton class for mappable undirected bipartite graphs.
1705    ///
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>  {
1713    public:
1714
1715      typedef BAS Base;
1716      typedef typename Base::Node Node;
1717
1718      typedef MappableBpGraphComponent BpGraph;
1719
1720      /// \brief Standard graph map for the red nodes.
1721      ///
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;
1727
1728      public:
1729        /// \brief Construct a new map.
1730        ///
1731        /// Construct a new map for the graph.
1732        explicit RedNodeMap(const MappableBpGraphComponent& graph)
1733          : Parent(graph) {}
1734
1735        /// \brief Construct a new map with default value.
1736        ///
1737        /// Construct a new map for the graph and initalize the values.
1738        RedNodeMap(const MappableBpGraphComponent& graph, const V& value)
1739          : Parent(graph, value) {}
1740
1741      private:
1742        /// \brief Copy constructor.
1743        ///
1744        /// Copy Constructor.
1745        RedNodeMap(const RedNodeMap& nm) : Parent(nm) {}
1746
1747        /// \brief Assignment operator.
1748        ///
1749        /// Assignment operator.
1750        template <typename CMap>
1751        RedNodeMap& operator=(const CMap&) {
1752          checkConcept<ReadMap<Node, V>, CMap>();
1753          return *this;
1754        }
1755
1756      };
1757
1758      /// \brief Standard graph map for the blue nodes.
1759      ///
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;
1765
1766      public:
1767        /// \brief Construct a new map.
1768        ///
1769        /// Construct a new map for the graph.
1770        explicit BlueNodeMap(const MappableBpGraphComponent& graph)
1771          : Parent(graph) {}
1772
1773        /// \brief Construct a new map with default value.
1774        ///
1775        /// Construct a new map for the graph and initalize the values.
1776        BlueNodeMap(const MappableBpGraphComponent& graph, const V& value)
1777          : Parent(graph, value) {}
1778
1779      private:
1780        /// \brief Copy constructor.
1781        ///
1782        /// Copy Constructor.
1783        BlueNodeMap(const BlueNodeMap& nm) : Parent(nm) {}
1784
1785        /// \brief Assignment operator.
1786        ///
1787        /// Assignment operator.
1788        template <typename CMap>
1789        BlueNodeMap& operator=(const CMap&) {
1790          checkConcept<ReadMap<Node, V>, CMap>();
1791          return *this;
1792        }
1793
1794      };
1795
1796
1797      template <typename _BpGraph>
1798      struct Constraints {
1799
1800        struct Dummy {
1801          int value;
1802          Dummy() : value(0) {}
1803          Dummy(int _v) : value(_v) {}
1804        };
1805
1806        void constraints() {
1807          checkConcept<MappableGraphComponent<Base>, _BpGraph>();
1808
1809          { // int map test
1810            typedef typename _BpGraph::template RedNodeMap<int>
1811              IntRedNodeMap;
1812            checkConcept<GraphMap<_BpGraph, typename _BpGraph::RedNode, int>,
1813              IntRedNodeMap >();
1814          } { // bool map test
1815            typedef typename _BpGraph::template RedNodeMap<bool>
1816              BoolRedNodeMap;
1817            checkConcept<GraphMap<_BpGraph, typename _BpGraph::RedNode, bool>,
1818              BoolRedNodeMap >();
1819          } { // Dummy map test
1820            typedef typename _BpGraph::template RedNodeMap<Dummy>
1821              DummyRedNodeMap;
1822            checkConcept<GraphMap<_BpGraph, typename _BpGraph::RedNode, Dummy>,
1823              DummyRedNodeMap >();
1824          }
1825
1826          { // int map test
1827            typedef typename _BpGraph::template BlueNodeMap<int>
1828              IntBlueNodeMap;
1829            checkConcept<GraphMap<_BpGraph, typename _BpGraph::BlueNode, int>,
1830              IntBlueNodeMap >();
1831          } { // bool map test
1832            typedef typename _BpGraph::template BlueNodeMap<bool>
1833              BoolBlueNodeMap;
1834            checkConcept<GraphMap<_BpGraph, typename _BpGraph::BlueNode, bool>,
1835              BoolBlueNodeMap >();
1836          } { // Dummy map test
1837            typedef typename _BpGraph::template BlueNodeMap<Dummy>
1838              DummyBlueNodeMap;
1839            checkConcept<GraphMap<_BpGraph, typename _BpGraph::BlueNode, Dummy>,
1840              DummyBlueNodeMap >();
1841          }
1842        }
1843
1844        const _BpGraph& bpgraph;
1845      };
1846    };
1847
1848    /// \brief Skeleton class for extendable directed graphs.
1849    ///
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 {
1856    public:
1857      typedef BAS Base;
1858
1859      typedef typename Base::Node Node;
1860      typedef typename Base::Arc Arc;
1861
1862      /// \brief Add a new node to the digraph.
1863      ///
1864      /// This function adds a new node to the digraph.
1865      Node addNode() {
1866        return INVALID;
1867      }
1868
1869      /// \brief Add a new arc connecting the given two nodes.
1870      ///
1871      /// This function adds a new arc connecting the given two nodes
1872      /// of the digraph.
1873      Arc addArc(const Node&, const Node&) {
1874        return INVALID;
1875      }
1876
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);
1886        }
1887
1888        _Digraph& digraph;
1889        Constraints() {}
1890      };
1891    };
1892
1893    /// \brief Skeleton class for extendable undirected graphs.
1894    ///
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 {
1901    public:
1902
1903      typedef BAS Base;
1904      typedef typename Base::Node Node;
1905      typedef typename Base::Edge Edge;
1906
1907      /// \brief Add a new node to the digraph.
1908      ///
1909      /// This function adds a new node to the digraph.
1910      Node addNode() {
1911        return INVALID;
1912      }
1913
1914      /// \brief Add a new edge connecting the given two nodes.
1915      ///
1916      /// This function adds a new edge connecting the given two nodes
1917      /// of the graph.
1918      Edge addEdge(const Node&, const Node&) {
1919        return INVALID;
1920      }
1921
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);
1931        }
1932
1933        _Graph& graph;
1934        Constraints() {}
1935      };
1936    };
1937
1938    /// \brief Skeleton class for extendable undirected bipartite graphs.
1939    ///
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 {
1946    public:
1947
1948      typedef BAS Base;
1949      typedef typename Base::Node Node;
1950      typedef typename Base::RedNode RedNode;
1951      typedef typename Base::BlueNode BlueNode;
1952      typedef typename Base::Edge Edge;
1953
1954      /// \brief Add a new red node to the digraph.
1955      ///
1956      /// This function adds a red new node to the digraph.
1957      RedNode addRedNode() {
1958        return INVALID;
1959      }
1960
1961      /// \brief Add a new blue node to the digraph.
1962      ///
1963      /// This function adds a blue new node to the digraph.
1964      BlueNode addBlueNode() {
1965        return INVALID;
1966      }
1967
1968      /// \brief Add a new edge connecting the given two nodes.
1969      ///
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&) {
1974        return INVALID;
1975      }
1976      Edge addEdge(const BlueNode&, const RedNode&) {
1977        return INVALID;
1978      }
1979
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);
1991        }
1992
1993        _BpGraph& bpgraph;
1994      };
1995    };
1996
1997    /// \brief Skeleton class for erasable directed graphs.
1998    ///
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 {
2005    public:
2006
2007      typedef BAS Base;
2008      typedef typename Base::Node Node;
2009      typedef typename Base::Arc Arc;
2010
2011      /// \brief Erase a node from the digraph.
2012      ///
2013      /// This function erases the given node from the digraph and all arcs
2014      /// connected to the node.
2015      void erase(const Node&) {}
2016
2017      /// \brief Erase an arc from the digraph.
2018      ///
2019      /// This function erases the given arc from the digraph.
2020      void erase(const Arc&) {}
2021
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);
2029          digraph.erase(arc);
2030        }
2031
2032        _Digraph& digraph;
2033        Constraints() {}
2034      };
2035    };
2036
2037    /// \brief Skeleton class for erasable undirected graphs.
2038    ///
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 {
2045    public:
2046
2047      typedef BAS Base;
2048      typedef typename Base::Node Node;
2049      typedef typename Base::Edge Edge;
2050
2051      /// \brief Erase a node from the graph.
2052      ///
2053      /// This function erases the given node from the graph and all edges
2054      /// connected to the node.
2055      void erase(const Node&) {}
2056
2057      /// \brief Erase an edge from the digraph.
2058      ///
2059      /// This function erases the given edge from the digraph.
2060      void erase(const Edge&) {}
2061
2062      template <typename _Graph>
2063      struct Constraints {
2064        void constraints() {
2065          checkConcept<Base, _Graph>();
2066          const typename _Graph::Node node(INVALID);
2067          graph.erase(node);
2068          const typename _Graph::Edge edge(INVALID);
2069          graph.erase(edge);
2070        }
2071
2072        _Graph& graph;
2073        Constraints() {}
2074      };
2075    };
2076
2077    /// \brief Skeleton class for erasable undirected graphs.
2078    ///
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> {};
2085
2086    /// \brief Skeleton class for clearable directed graphs.
2087    ///
2088    /// This class describes the interface of clearable directed graphs.
2089    /// It extends \ref BaseDigraphComponent with a function for clearing
2090    /// the digraph.
2091    /// This concept requires \ref AlterableDigraphComponent.
2092    template <typename BAS = BaseDigraphComponent>
2093    class ClearableDigraphComponent : public BAS {
2094    public:
2095
2096      typedef BAS Base;
2097
2098      /// \brief Erase all nodes and arcs from the digraph.
2099      ///
2100      /// This function erases all nodes and arcs from the digraph.
2101      void clear() {}
2102
2103      template <typename _Digraph>
2104      struct Constraints {
2105        void constraints() {
2106          checkConcept<Base, _Digraph>();
2107          digraph.clear();
2108        }
2109
2110        _Digraph& digraph;
2111        Constraints() {}
2112      };
2113    };
2114
2115    /// \brief Skeleton class for clearable undirected graphs.
2116    ///
2117    /// This class describes the interface of clearable undirected graphs.
2118    /// It extends \ref BaseGraphComponent with a function for clearing
2119    /// the graph.
2120    /// This concept requires \ref AlterableGraphComponent.
2121    template <typename BAS = BaseGraphComponent>
2122    class ClearableGraphComponent : public ClearableDigraphComponent<BAS> {};
2123
2124    /// \brief Skeleton class for clearable undirected biparite graphs.
2125    ///
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> {};
2132
2133  }
2134
2135}
2136
2137#endif
Note: See TracBrowser for help on using the repository browser.