COIN-OR::LEMON - Graph Library

source: lemon-0.x/lemon/concept/ugraph.h @ 1910:f95eea8c34b0

Last change on this file since 1910:f95eea8c34b0 was 1910:f95eea8c34b0, checked in by Balazs Dezso, 18 years ago

Bipartite => Bp
Upper => A
Lower => B

+ some bug fix

File size: 29.8 KB
RevLine 
[962]1/* -*- C++ -*-
2 *
[1909]3 * lemon/concept/ugraph_component.h - Part of LEMON, a generic
[962]4 * C++ optimization library
5 *
[1875]6 * Copyright (C) 2006 Egervary Jeno Kombinatorikus Optimalizalasi
[1359]7 * Kutatocsoport (Egervary Research Group on Combinatorial Optimization,
[962]8 * EGRES).
9 *
10 * Permission to use, modify and distribute this software is granted
11 * provided that this copyright notice appears in all copies. For
12 * precise terms see the accompanying LICENSE file.
13 *
14 * This software is provided "AS IS" with no warranty of any kind,
15 * express or implied, and with no claim as to its suitability for any
16 * purpose.
17 *
18 */
19
[1030]20///\ingroup graph_concepts
[962]21///\file
22///\brief Undirected graphs and components of.
23
24
[1910]25#ifndef LEMON_CONCEPT_UGRAPH_H
26#define LEMON_CONCEPT_UGRAPH_H
[962]27
28#include <lemon/concept/graph_component.h>
[1620]29#include <lemon/concept/graph.h>
[1448]30#include <lemon/utility.h>
[962]31
32namespace lemon {
33  namespace concept {
34
[1630]35//     /// Skeleton class which describes an edge with direction in \ref
[1909]36//     /// UGraph "undirected graph".
37    template <typename UGraph>
38    class UGraphEdge : public UGraph::UEdge {
39      typedef typename UGraph::UEdge UEdge;
40      typedef typename UGraph::Node Node;
[1030]41    public:
42
43      /// \e
[1909]44      UGraphEdge() {}
[1030]45
46      /// \e
[1909]47      UGraphEdge(const UGraphEdge& e) : UGraph::UEdge(e) {}
[1030]48
49      /// \e
[1909]50      UGraphEdge(Invalid) {}
[1030]51
[1158]52      /// \brief Directed edge from undirected edge and a source node.
[1030]53      ///
[1158]54      /// Constructs a directed edge from undirected edge and a source node.
55      ///
56      /// \note You have to specify the graph for this constructor.
[1909]57      UGraphEdge(const UGraph &g,
58                     UEdge u_edge, Node n) {
59        ignore_unused_variable_warning(u_edge);
[1158]60        ignore_unused_variable_warning(g);
61        ignore_unused_variable_warning(n);
[1030]62      }
63
64      /// \e
[1909]65      UGraphEdge& operator=(UGraphEdge) { return *this; }
[1030]66
67      /// \e
[1909]68      bool operator==(UGraphEdge) const { return true; }
[1030]69      /// \e
[1909]70      bool operator!=(UGraphEdge) const { return false; }
[1030]71
72      /// \e
[1909]73      bool operator<(UGraphEdge) const { return false; }
[1030]74
75      template <typename Edge>
76      struct Constraints {
77        void constraints() {
[1158]78          const_constraints();
79        }
80        void const_constraints() const {
[1030]81          /// \bug This should be is_base_and_derived ...
[1909]82          UEdge ue = e;
[1030]83          ue = e;
84
[1158]85          Edge e_with_source(graph,ue,n);
86          ignore_unused_variable_warning(e_with_source);
[1030]87        }
88        Edge e;
[1909]89        UEdge ue;
90        UGraph graph;
[1158]91        Node n;
[1030]92      };
93    };
94   
[962]95
[1909]96    struct BaseIterableUGraphConcept {
[989]97
[1022]98      template <typename Graph>
99      struct Constraints {
[962]100
[1909]101        typedef typename Graph::UEdge UEdge;
[1022]102        typedef typename Graph::Edge Edge;
103        typedef typename Graph::Node Node;
[962]104
[1022]105        void constraints() {
106          checkConcept<BaseIterableGraphComponent, Graph>();
[1909]107          checkConcept<GraphItem<>, UEdge>();
108          //checkConcept<UGraphEdge<Graph>, Edge>();
[962]109
[1030]110          graph.first(ue);
111          graph.next(ue);
[1022]112
[1030]113          const_constraints();
114        }
115        void const_constraints() {
[1022]116          Node n;
117          n = graph.target(ue);
118          n = graph.source(ue);
[1030]119          n = graph.oppositeNode(n0, ue);
[1022]120
[1030]121          bool b;
[1627]122          b = graph.direction(e);
[1909]123          Edge e = graph.direct(UEdge(), true);
124          e = graph.direct(UEdge(), n);
[1627]125 
[1030]126          ignore_unused_variable_warning(b);
[1022]127        }
[1030]128
129        Graph graph;
[1022]130        Edge e;
[1030]131        Node n0;
[1909]132        UEdge ue;
[1022]133      };
134
[962]135    };
136
[1022]137
[1909]138    struct IterableUGraphConcept {
[962]139
[1022]140      template <typename Graph>
141      struct Constraints {
142        void constraints() {
143          /// \todo we don't need the iterable component to be base iterable
144          /// Don't we really???
[1909]145          //checkConcept< BaseIterableUGraphConcept, Graph > ();
[962]146
[1022]147          checkConcept<IterableGraphComponent, Graph> ();
[1021]148
[1909]149          typedef typename Graph::UEdge UEdge;
150          typedef typename Graph::UEdgeIt UEdgeIt;
[1030]151          typedef typename Graph::IncEdgeIt IncEdgeIt;
[1022]152
[1909]153          checkConcept<GraphIterator<Graph, UEdge>, UEdgeIt>();
154          checkConcept<GraphIncIterator<Graph, UEdge>, IncEdgeIt>();
[1022]155        }
156      };
157
158    };
159
[1909]160    struct MappableUGraphConcept {
[1022]161
162      template <typename Graph>
163      struct Constraints {
164
165        struct Dummy {
166          int value;
167          Dummy() : value(0) {}
168          Dummy(int _v) : value(_v) {}
169        };
170
171        void constraints() {
172          checkConcept<MappableGraphComponent, Graph>();
173
[1909]174          typedef typename Graph::template UEdgeMap<int> IntMap;
175          checkConcept<GraphMap<Graph, typename Graph::UEdge, int>,
[1022]176            IntMap >();
177
[1909]178          typedef typename Graph::template UEdgeMap<bool> BoolMap;
179          checkConcept<GraphMap<Graph, typename Graph::UEdge, bool>,
[1022]180            BoolMap >();
181
[1909]182          typedef typename Graph::template UEdgeMap<Dummy> DummyMap;
183          checkConcept<GraphMap<Graph, typename Graph::UEdge, Dummy>,
[1022]184            DummyMap >();
185        }
186      };
187
188    };
189
[1909]190    struct ExtendableUGraphConcept {
[1022]191
192      template <typename Graph>
193      struct Constraints {
194        void constraints() {
195          node_a = graph.addNode();
196          uedge = graph.addEdge(node_a, node_b);
197        }
198        typename Graph::Node node_a, node_b;
[1909]199        typename Graph::UEdge uedge;
[1022]200        Graph graph;
201      };
202
203    };
204
[1909]205    struct ErasableUGraphConcept {
[1022]206
207      template <typename Graph>
208      struct Constraints {
209        void constraints() {
210          graph.erase(n);
211          graph.erase(e);
212        }
213        Graph graph;
214        typename Graph::Node n;
[1909]215        typename Graph::UEdge e;
[1022]216      };
217
218    };
219
[1620]220    /// \addtogroup graph_concepts
221    /// @{
222
223
[1030]224    /// Class describing the concept of Undirected Graphs.
225
226    /// This class describes the common interface of all Undirected
227    /// Graphs.
228    ///
229    /// As all concept describing classes it provides only interface
230    /// without any sensible implementation. So any algorithm for
231    /// undirected graph should compile with this class, but it will not
232    /// run properly, of couse.
233    ///
234    /// In LEMON undirected graphs also fulfill the concept of directed
[1631]235    /// graphs (\ref lemon::concept::StaticGraph "Graph Concept"). For
[1909]236    /// explanation of this and more see also the page \ref ugraphs,
[1030]237    /// a tutorial about undirected graphs.
[1627]238    ///
239    /// You can assume that all undirected graph can be handled
240    /// as a static directed graph. This way it is fully conform
241    /// to the StaticGraph concept.
[1030]242
[1909]243    class UGraph {
[1022]244    public:
[1448]245      ///\e
246
247      ///\todo undocumented
248      ///
[1909]249      typedef True UTag;
[1022]250
[1669]251      /// \brief The base type of node iterators,
[1627]252      /// or in other words, the trivial node iterator.
[1669]253      ///
[1627]254      /// This is the base type of each node iterator,
255      /// thus each kind of node iterator converts to this.
256      /// More precisely each kind of node iterator should be inherited
257      /// from the trivial node iterator.
258      class Node {
259      public:
260        /// Default constructor
261
262        /// @warning The default constructor sets the iterator
263        /// to an undefined value.
264        Node() { }
265        /// Copy constructor.
266
267        /// Copy constructor.
268        ///
269        Node(const Node&) { }
270
271        /// Invalid constructor \& conversion.
272
273        /// This constructor initializes the iterator to be invalid.
274        /// \sa Invalid for more details.
275        Node(Invalid) { }
276        /// Equality operator
277
278        /// Two iterators are equal if and only if they point to the
279        /// same object or both are invalid.
280        bool operator==(Node) const { return true; }
281
282        /// Inequality operator
283       
284        /// \sa operator==(Node n)
285        ///
286        bool operator!=(Node) const { return true; }
287
288        /// Artificial ordering operator.
289       
290        /// To allow the use of graph descriptors as key type in std::map or
291        /// similar associative container we require this.
292        ///
293        /// \note This operator only have to define some strict ordering of
294        /// the items; this order has nothing to do with the iteration
295        /// ordering of the items.
296        ///
297        /// \bug This is a technical requirement. Do we really need this?
298        bool operator<(Node) const { return false; }
299
300      };
301   
302      /// This iterator goes through each node.
303
304      /// This iterator goes through each node.
305      /// Its usage is quite simple, for example you can count the number
306      /// of nodes in graph \c g of type \c Graph like this:
307      /// \code
308      /// int count=0;
309      /// for (Graph::NodeIt n(g); n!=INVALID; ++n) ++count;
310      /// \endcode
311      class NodeIt : public Node {
312      public:
313        /// Default constructor
314
315        /// @warning The default constructor sets the iterator
316        /// to an undefined value.
317        NodeIt() { }
318        /// Copy constructor.
319       
320        /// Copy constructor.
321        ///
322        NodeIt(const NodeIt& n) : Node(n) { }
323        /// Invalid constructor \& conversion.
324
325        /// Initialize the iterator to be invalid.
326        /// \sa Invalid for more details.
327        NodeIt(Invalid) { }
328        /// Sets the iterator to the first node.
329
330        /// Sets the iterator to the first node of \c g.
331        ///
[1909]332        NodeIt(const UGraph&) { }
[1627]333        /// Node -> NodeIt conversion.
334
335        /// Sets the iterator to the node of \c the graph pointed by
336        /// the trivial iterator.
337        /// This feature necessitates that each time we
338        /// iterate the edge-set, the iteration order is the same.
[1909]339        NodeIt(const UGraph&, const Node&) { }
[1627]340        /// Next node.
341
342        /// Assign the iterator to the next node.
343        ///
344        NodeIt& operator++() { return *this; }
345      };
346   
347   
[1620]348      /// The base type of the undirected edge iterators.
[1627]349
[1620]350      /// The base type of the undirected edge iterators.
351      ///
[1909]352      class UEdge {
[1620]353      public:
354        /// Default constructor
[1030]355
[1620]356        /// @warning The default constructor sets the iterator
357        /// to an undefined value.
[1909]358        UEdge() { }
[1620]359        /// Copy constructor.
[1030]360
[1620]361        /// Copy constructor.
362        ///
[1909]363        UEdge(const UEdge&) { }
[1620]364        /// Initialize the iterator to be invalid.
[1030]365
[1620]366        /// Initialize the iterator to be invalid.
367        ///
[1909]368        UEdge(Invalid) { }
[1620]369        /// Equality operator
[1030]370
[1620]371        /// Two iterators are equal if and only if they point to the
372        /// same object or both are invalid.
[1909]373        bool operator==(UEdge) const { return true; }
[1620]374        /// Inequality operator
[1030]375
[1909]376        /// \sa operator==(UEdge n)
[1620]377        ///
[1909]378        bool operator!=(UEdge) const { return true; }
[1030]379
[1627]380        /// Artificial ordering operator.
381       
382        /// To allow the use of graph descriptors as key type in std::map or
383        /// similar associative container we require this.
384        ///
385        /// \note This operator only have to define some strict ordering of
386        /// the items; this order has nothing to do with the iteration
387        /// ordering of the items.
388        ///
389        /// \bug This is a technical requirement. Do we really need this?
[1909]390        bool operator<(UEdge) const { return false; }
[1627]391      };
[1030]392
[1620]393      /// This iterator goes through each undirected edge.
[1030]394
[1620]395      /// This iterator goes through each undirected edge of a graph.
396      /// Its usage is quite simple, for example you can count the number
[1627]397      /// of undirected edges in a graph \c g of type \c Graph as follows:
[1620]398      /// \code
399      /// int count=0;
[1909]400      /// for(Graph::UEdgeIt e(g); e!=INVALID; ++e) ++count;
[1620]401      /// \endcode
[1909]402      class UEdgeIt : public UEdge {
[1620]403      public:
404        /// Default constructor
[1627]405
[1620]406        /// @warning The default constructor sets the iterator
407        /// to an undefined value.
[1909]408        UEdgeIt() { }
[1620]409        /// Copy constructor.
[1627]410
[1620]411        /// Copy constructor.
412        ///
[1909]413        UEdgeIt(const UEdgeIt& e) : UEdge(e) { }
[1620]414        /// Initialize the iterator to be invalid.
[1030]415
[1620]416        /// Initialize the iterator to be invalid.
417        ///
[1909]418        UEdgeIt(Invalid) { }
[1627]419        /// This constructor sets the iterator to the first undirected edge.
[1620]420   
[1627]421        /// This constructor sets the iterator to the first undirected edge.
[1909]422        UEdgeIt(const UGraph&) { }
423        /// UEdge -> UEdgeIt conversion
[1030]424
[1627]425        /// Sets the iterator to the value of the trivial iterator.
426        /// This feature necessitates that each time we
427        /// iterate the undirected edge-set, the iteration order is the
428        /// same.
[1909]429        UEdgeIt(const UGraph&, const UEdge&) { }
[1627]430        /// Next undirected edge
[1620]431       
[1627]432        /// Assign the iterator to the next undirected edge.
[1909]433        UEdgeIt& operator++() { return *this; }
[1620]434      };
[1030]435
[1627]436      /// \brief This iterator goes trough the incident undirected
437      /// edges of a node.
438      ///
[1620]439      /// This iterator goes trough the incident undirected edges
440      /// of a certain node
441      /// of a graph.
442      /// Its usage is quite simple, for example you can compute the
443      /// degree (i.e. count the number
444      /// of incident edges of a node \c n
445      /// in graph \c g of type \c Graph as follows.
446      /// \code
447      /// int count=0;
448      /// for(Graph::IncEdgeIt e(g, n); e!=INVALID; ++e) ++count;
449      /// \endcode
[1909]450      class IncEdgeIt : public UEdge {
[1620]451      public:
452        /// Default constructor
[1030]453
[1620]454        /// @warning The default constructor sets the iterator
455        /// to an undefined value.
456        IncEdgeIt() { }
457        /// Copy constructor.
458
459        /// Copy constructor.
460        ///
[1909]461        IncEdgeIt(const IncEdgeIt& e) : UEdge(e) { }
[1620]462        /// Initialize the iterator to be invalid.
463
464        /// Initialize the iterator to be invalid.
465        ///
466        IncEdgeIt(Invalid) { }
467        /// This constructor sets the iterator to first incident edge.
468   
469        /// This constructor set the iterator to the first incident edge of
470        /// the node.
[1909]471        IncEdgeIt(const UGraph&, const Node&) { }
472        /// UEdge -> IncEdgeIt conversion
[1620]473
474        /// Sets the iterator to the value of the trivial iterator \c e.
475        /// This feature necessitates that each time we
476        /// iterate the edge-set, the iteration order is the same.
[1909]477        IncEdgeIt(const UGraph&, const UEdge&) { }
[1620]478        /// Next incident edge
479
480        /// Assign the iterator to the next incident edge
481        /// of the corresponding node.
482        IncEdgeIt& operator++() { return *this; }
483      };
484
[1627]485      /// The directed edge type.
486
487      /// The directed edge type. It can be converted to the
488      /// undirected edge.
[1909]489      class Edge : public UEdge {
[1627]490      public:
491        /// Default constructor
492
493        /// @warning The default constructor sets the iterator
494        /// to an undefined value.
495        Edge() { }
496        /// Copy constructor.
497
498        /// Copy constructor.
499        ///
[1909]500        Edge(const Edge& e) : UEdge(e) { }
[1627]501        /// Initialize the iterator to be invalid.
502
503        /// Initialize the iterator to be invalid.
504        ///
505        Edge(Invalid) { }
506        /// Equality operator
507
508        /// Two iterators are equal if and only if they point to the
509        /// same object or both are invalid.
510        bool operator==(Edge) const { return true; }
511        /// Inequality operator
512
513        /// \sa operator==(Edge n)
514        ///
515        bool operator!=(Edge) const { return true; }
516
517        /// Artificial ordering operator.
518       
519        /// To allow the use of graph descriptors as key type in std::map or
520        /// similar associative container we require this.
521        ///
522        /// \note This operator only have to define some strict ordering of
523        /// the items; this order has nothing to do with the iteration
524        /// ordering of the items.
525        ///
526        /// \bug This is a technical requirement. Do we really need this?
527        bool operator<(Edge) const { return false; }
528       
529      };
530      /// This iterator goes through each directed edge.
531
532      /// This iterator goes through each edge of a graph.
533      /// Its usage is quite simple, for example you can count the number
534      /// of edges in a graph \c g of type \c Graph as follows:
535      /// \code
536      /// int count=0;
537      /// for(Graph::EdgeIt e(g); e!=INVALID; ++e) ++count;
538      /// \endcode
539      class EdgeIt : public Edge {
540      public:
541        /// Default constructor
542
543        /// @warning The default constructor sets the iterator
544        /// to an undefined value.
545        EdgeIt() { }
546        /// Copy constructor.
547
548        /// Copy constructor.
549        ///
550        EdgeIt(const EdgeIt& e) : Edge(e) { }
551        /// Initialize the iterator to be invalid.
552
553        /// Initialize the iterator to be invalid.
554        ///
555        EdgeIt(Invalid) { }
556        /// This constructor sets the iterator to the first edge.
557   
558        /// This constructor sets the iterator to the first edge of \c g.
559        ///@param g the graph
[1909]560        EdgeIt(const UGraph &g) { ignore_unused_variable_warning(g); }
[1627]561        /// Edge -> EdgeIt conversion
562
563        /// Sets the iterator to the value of the trivial iterator \c e.
564        /// This feature necessitates that each time we
565        /// iterate the edge-set, the iteration order is the same.
[1909]566        EdgeIt(const UGraph&, const Edge&) { }
[1627]567        ///Next edge
568       
569        /// Assign the iterator to the next edge.
570        EdgeIt& operator++() { return *this; }
571      };
572   
573      /// This iterator goes trough the outgoing directed edges of a node.
574
575      /// This iterator goes trough the \e outgoing edges of a certain node
576      /// of a graph.
577      /// Its usage is quite simple, for example you can count the number
578      /// of outgoing edges of a node \c n
579      /// in graph \c g of type \c Graph as follows.
580      /// \code
581      /// int count=0;
582      /// for (Graph::OutEdgeIt e(g, n); e!=INVALID; ++e) ++count;
583      /// \endcode
584   
585      class OutEdgeIt : public Edge {
586      public:
587        /// Default constructor
588
589        /// @warning The default constructor sets the iterator
590        /// to an undefined value.
591        OutEdgeIt() { }
592        /// Copy constructor.
593
594        /// Copy constructor.
595        ///
596        OutEdgeIt(const OutEdgeIt& e) : Edge(e) { }
597        /// Initialize the iterator to be invalid.
598
599        /// Initialize the iterator to be invalid.
600        ///
601        OutEdgeIt(Invalid) { }
602        /// This constructor sets the iterator to the first outgoing edge.
603   
604        /// This constructor sets the iterator to the first outgoing edge of
605        /// the node.
606        ///@param n the node
607        ///@param g the graph
[1909]608        OutEdgeIt(const UGraph& n, const Node& g) {
[1643]609          ignore_unused_variable_warning(n);
610          ignore_unused_variable_warning(g);
611        }
[1627]612        /// Edge -> OutEdgeIt conversion
613
614        /// Sets the iterator to the value of the trivial iterator.
615        /// This feature necessitates that each time we
616        /// iterate the edge-set, the iteration order is the same.
[1909]617        OutEdgeIt(const UGraph&, const Edge&) { }
[1627]618        ///Next outgoing edge
619       
620        /// Assign the iterator to the next
621        /// outgoing edge of the corresponding node.
622        OutEdgeIt& operator++() { return *this; }
623      };
624
625      /// This iterator goes trough the incoming directed edges of a node.
626
627      /// This iterator goes trough the \e incoming edges of a certain node
628      /// of a graph.
629      /// Its usage is quite simple, for example you can count the number
630      /// of outgoing edges of a node \c n
631      /// in graph \c g of type \c Graph as follows.
632      /// \code
633      /// int count=0;
634      /// for(Graph::InEdgeIt e(g, n); e!=INVALID; ++e) ++count;
635      /// \endcode
636
637      class InEdgeIt : public Edge {
638      public:
639        /// Default constructor
640
641        /// @warning The default constructor sets the iterator
642        /// to an undefined value.
643        InEdgeIt() { }
644        /// Copy constructor.
645
646        /// Copy constructor.
647        ///
648        InEdgeIt(const InEdgeIt& e) : Edge(e) { }
649        /// Initialize the iterator to be invalid.
650
651        /// Initialize the iterator to be invalid.
652        ///
653        InEdgeIt(Invalid) { }
654        /// This constructor sets the iterator to first incoming edge.
655   
656        /// This constructor set the iterator to the first incoming edge of
657        /// the node.
658        ///@param n the node
659        ///@param g the graph
[1909]660        InEdgeIt(const UGraph& g, const Node& n) {
[1643]661          ignore_unused_variable_warning(n);
662          ignore_unused_variable_warning(g);
663        }
[1627]664        /// Edge -> InEdgeIt conversion
665
666        /// Sets the iterator to the value of the trivial iterator \c e.
667        /// This feature necessitates that each time we
668        /// iterate the edge-set, the iteration order is the same.
[1909]669        InEdgeIt(const UGraph&, const Edge&) { }
[1627]670        /// Next incoming edge
671
672        /// Assign the iterator to the next inedge of the corresponding node.
673        ///
674        InEdgeIt& operator++() { return *this; }
675      };
676
677      /// \brief Read write map of the nodes to type \c T.
678      ///
679      /// ReadWrite map of the nodes to type \c T.
680      /// \sa Reference
681      /// \warning Making maps that can handle bool type (NodeMap<bool>)
682      /// needs some extra attention!
[1630]683      /// \todo Wrong documentation
[1627]684      template<class T>
685      class NodeMap : public ReadWriteMap< Node, T >
686      {
687      public:
688
689        ///\e
[1909]690        NodeMap(const UGraph&) { }
[1627]691        ///\e
[1909]692        NodeMap(const UGraph&, T) { }
[1627]693
694        ///Copy constructor
695        NodeMap(const NodeMap& nm) : ReadWriteMap< Node, T >(nm) { }
696        ///Assignment operator
697        NodeMap& operator=(const NodeMap&) { return *this; }
698        // \todo fix this concept
699      };
700
701      /// \brief Read write map of the directed edges to type \c T.
702      ///
703      /// Reference map of the directed edges to type \c T.
704      /// \sa Reference
705      /// \warning Making maps that can handle bool type (EdgeMap<bool>)
706      /// needs some extra attention!
[1630]707      /// \todo Wrong documentation
[1627]708      template<class T>
709      class EdgeMap : public ReadWriteMap<Edge,T>
710      {
711      public:
712
713        ///\e
[1909]714        EdgeMap(const UGraph&) { }
[1627]715        ///\e
[1909]716        EdgeMap(const UGraph&, T) { }
[1627]717        ///Copy constructor
718        EdgeMap(const EdgeMap& em) : ReadWriteMap<Edge,T>(em) { }
719        ///Assignment operator
720        EdgeMap& operator=(const EdgeMap&) { return *this; }
721        // \todo fix this concept   
722      };
723
[1620]724      /// Read write map of the undirected edges to type \c T.
725
726      /// Reference map of the edges to type \c T.
727      /// \sa Reference
[1909]728      /// \warning Making maps that can handle bool type (UEdgeMap<bool>)
[1620]729      /// needs some extra attention!
[1630]730      /// \todo Wrong documentation
[1620]731      template<class T>
[1909]732      class UEdgeMap : public ReadWriteMap<UEdge,T>
[1620]733      {
[1030]734      public:
735
[1620]736        ///\e
[1909]737        UEdgeMap(const UGraph&) { }
[1620]738        ///\e
[1909]739        UEdgeMap(const UGraph&, T) { }
[1620]740        ///Copy constructor
[1909]741        UEdgeMap(const UEdgeMap& em) : ReadWriteMap<UEdge,T>(em) {}
[1620]742        ///Assignment operator
[1909]743        UEdgeMap &operator=(const UEdgeMap&) { return *this; }
[1620]744        // \todo fix this concept   
[1030]745      };
746
[1627]747      /// \brief Direct the given undirected edge.
748      ///
749      /// Direct the given undirected edge. The returned edge source
750      /// will be the given edge.
[1909]751      Edge direct(const UEdge&, const Node&) const {
[1627]752        return INVALID;
753      }
[1030]754
[1627]755      /// \brief Direct the given undirected edge.
756      ///
757      /// Direct the given undirected edge. The returned edge source
758      /// will be the source of the undirected edge if the given bool
759      /// is true.
[1909]760      Edge direct(const UEdge&, bool) const {
[1627]761        return INVALID;
762      }
763
764      /// \brief Returns true if the edge has default orientation.
765      ///
[1030]766      /// Returns whether the given directed edge is same orientation as
767      /// the corresponding undirected edge.
[1627]768      bool direction(Edge) const { return true; }
769
770      /// \brief Returns the opposite directed edge.
[1030]771      ///
[1627]772      /// Returns the opposite directed edge.
773      Edge oppositeEdge(Edge) const { return INVALID; }
[1030]774
[1627]775      /// \brief Opposite node on an edge
776      ///
[1030]777      /// \return the opposite of the given Node on the given Edge
[1909]778      Node oppositeNode(Node, UEdge) const { return INVALID; }
[1030]779
[1627]780      /// \brief First node of the undirected edge.
781      ///
[1909]782      /// \return the first node of the given UEdge.
[1030]783      ///
[1909]784      /// Naturally uectected edges don't have direction and thus
[1030]785      /// don't have source and target node. But we use these two methods
786      /// to query the two endnodes of the edge. The direction of the edge
787      /// which arises this way is called the inherent direction of the
[1627]788      /// undirected edge, and is used to define the "default" direction
[1030]789      /// of the directed versions of the edges.
[1627]790      /// \sa direction
[1909]791      Node source(UEdge) const { return INVALID; }
[1030]792
[1627]793      /// \brief Second node of the undirected edge.
[1909]794      Node target(UEdge) const { return INVALID; }
[1030]795
[1627]796      /// \brief Source node of the directed edge.
[1030]797      Node source(Edge) const { return INVALID; }
798
[1627]799      /// \brief Target node of the directed edge.
[1030]800      Node target(Edge) const { return INVALID; }
801
[1630]802//       /// \brief First node of the graph
803//       ///
804//       /// \note This method is part of so called \ref
805//       /// developpers_interface "Developpers' interface", so it shouldn't
806//       /// be used in an end-user program.
[1030]807      void first(Node&) const {}
[1630]808//       /// \brief Next node of the graph
809//       ///
810//       /// \note This method is part of so called \ref
811//       /// developpers_interface "Developpers' interface", so it shouldn't
812//       /// be used in an end-user program.
[1030]813      void next(Node&) const {}
814
[1630]815//       /// \brief First undirected edge of the graph
816//       ///
817//       /// \note This method is part of so called \ref
818//       /// developpers_interface "Developpers' interface", so it shouldn't
819//       /// be used in an end-user program.
[1909]820      void first(UEdge&) const {}
[1630]821//       /// \brief Next undirected edge of the graph
822//       ///
823//       /// \note This method is part of so called \ref
824//       /// developpers_interface "Developpers' interface", so it shouldn't
825//       /// be used in an end-user program.
[1909]826      void next(UEdge&) const {}
[1030]827
[1630]828//       /// \brief First directed edge of the graph
829//       ///
830//       /// \note This method is part of so called \ref
831//       /// developpers_interface "Developpers' interface", so it shouldn't
832//       /// be used in an end-user program.
[1030]833      void first(Edge&) const {}
[1630]834//       /// \brief Next directed edge of the graph
835//       ///
836//       /// \note This method is part of so called \ref
837//       /// developpers_interface "Developpers' interface", so it shouldn't
838//       /// be used in an end-user program.
[1030]839      void next(Edge&) const {}
840
[1630]841//       /// \brief First outgoing edge from a given node
842//       ///
843//       /// \note This method is part of so called \ref
844//       /// developpers_interface "Developpers' interface", so it shouldn't
845//       /// be used in an end-user program.
[1030]846      void firstOut(Edge&, Node) const {}
[1630]847//       /// \brief Next outgoing edge to a node
848//       ///
849//       /// \note This method is part of so called \ref
850//       /// developpers_interface "Developpers' interface", so it shouldn't
851//       /// be used in an end-user program.
[1030]852      void nextOut(Edge&) const {}
853
[1630]854//       /// \brief First incoming edge to a given node
855//       ///
856//       /// \note This method is part of so called \ref
857//       /// developpers_interface "Developpers' interface", so it shouldn't
858//       /// be used in an end-user program.
[1030]859      void firstIn(Edge&, Node) const {}
[1630]860//       /// \brief Next incoming edge to a node
861//       ///
862//       /// \note This method is part of so called \ref
863//       /// developpers_interface "Developpers' interface", so it shouldn't
864//       /// be used in an end-user program.
[1030]865      void nextIn(Edge&) const {}
866
867
[1627]868      /// \brief Base node of the iterator
[1158]869      ///
870      /// Returns the base node (the source in this case) of the iterator
871      Node baseNode(OutEdgeIt e) const {
872        return source(e);
873      }
[1627]874      /// \brief Running node of the iterator
[1158]875      ///
876      /// Returns the running node (the target in this case) of the
877      /// iterator
878      Node runningNode(OutEdgeIt e) const {
879        return target(e);
880      }
881
[1627]882      /// \brief Base node of the iterator
[1158]883      ///
884      /// Returns the base node (the target in this case) of the iterator
885      Node baseNode(InEdgeIt e) const {
886        return target(e);
887      }
[1627]888      /// \brief Running node of the iterator
[1158]889      ///
890      /// Returns the running node (the source in this case) of the
891      /// iterator
892      Node runningNode(InEdgeIt e) const {
893        return source(e);
894      }
895
[1627]896      /// \brief Base node of the iterator
[1158]897      ///
898      /// Returns the base node of the iterator
[1367]899      Node baseNode(IncEdgeIt) const {
[1158]900        return INVALID;
901      }
[1627]902     
903      /// \brief Running node of the iterator
[1158]904      ///
905      /// Returns the running node of the iterator
[1367]906      Node runningNode(IncEdgeIt) const {
[1158]907        return INVALID;
908      }
909
[1022]910      template <typename Graph>
911      struct Constraints {
912        void constraints() {
[1909]913          checkConcept<BaseIterableUGraphConcept, Graph>();
914          checkConcept<IterableUGraphConcept, Graph>();
915          checkConcept<MappableUGraphConcept, Graph>();
[1022]916        }
917      };
918
919    };
920
[1627]921    /// \brief An empty non-static undirected graph class.
922    ///   
[1909]923    /// This class provides everything that \ref UGraph does.
[1627]924    /// Additionally it enables building graphs from scratch.
[1909]925    class ExtendableUGraph : public UGraph {
[1022]926    public:
[1627]927     
928      /// \brief Add a new node to the graph.
929      ///
930      /// Add a new node to the graph.
931      /// \return the new node.
932      Node addNode();
933
934      /// \brief Add a new undirected edge to the graph.
935      ///
936      /// Add a new undirected edge to the graph.
937      /// \return the new edge.
[1909]938      UEdge addEdge(const Node& from, const Node& to);
[1627]939
940      /// \brief Resets the graph.
941      ///
942      /// This function deletes all undirected edges and nodes of the graph.
943      /// It also frees the memory allocated to store them.
944      void clear() { }
[1022]945
946      template <typename Graph>
947      struct Constraints {
948        void constraints() {
[1909]949          checkConcept<BaseIterableUGraphConcept, Graph>();
950          checkConcept<IterableUGraphConcept, Graph>();
951          checkConcept<MappableUGraphConcept, Graph>();
[1022]952
[1909]953          checkConcept<UGraph, Graph>();
954          checkConcept<ExtendableUGraphConcept, Graph>();
[1022]955          checkConcept<ClearableGraphComponent, Graph>();
956        }
957      };
958
959    };
960
[1627]961    /// \brief An empty erasable undirected graph class.
962    ///
[1909]963    /// This class is an extension of \ref ExtendableUGraph. It makes it
[1627]964    /// possible to erase undirected edges or nodes.
[1909]965    class ErasableUGraph : public ExtendableUGraph {
[1022]966    public:
967
[1627]968      /// \brief Deletes a node.
969      ///
970      /// Deletes a node.
971      ///
972      void erase(Node) { }
973      /// \brief Deletes an undirected edge.
974      ///
975      /// Deletes an undirected edge.
976      ///
[1909]977      void erase(UEdge) { }
[1627]978
[1022]979      template <typename Graph>
980      struct Constraints {
981        void constraints() {
[1909]982          checkConcept<ExtendableUGraph, Graph>();
983          checkConcept<ErasableUGraphConcept, Graph>();
[1022]984        }
985      };
986
[962]987    };
988
[1030]989    /// @}
990
[962]991  }
992
993}
994
995#endif
Note: See TracBrowser for help on using the repository browser.