COIN-OR::LEMON - Graph Library

source: lemon-0.x/lemon/concept/graph.h @ 2128:509846825ddf

Last change on this file since 2128:509846825ddf was 2128:509846825ddf, checked in by Alpar Juttner, 18 years ago
  • Disable the copy constructor and operator= of {List|Smart}[U]Graph.
  • Improve graph doc
  • Also put private members into the doc (if they are documented)
File size: 13.5 KB
RevLine 
[959]1/* -*- C++ -*-
2 *
[1956]3 * This file is a part of LEMON, a generic C++ optimization library
4 *
5 * Copyright (C) 2003-2006
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
[1359]7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
[959]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#ifndef LEMON_CONCEPT_GRAPH_H
20#define LEMON_CONCEPT_GRAPH_H
21
[1030]22///\ingroup graph_concepts
[959]23///\file
24///\brief Declaration of Graph.
25
[1993]26#include <lemon/bits/invalid.h>
27#include <lemon/bits/utility.h>
[959]28#include <lemon/concept/maps.h>
29#include <lemon/concept_check.h>
[2126]30#include <lemon/concept/graph_components.h>
[959]31
32namespace lemon {
33  namespace concept {
[1136]34
[1620]35    /// \addtogroup graph_concepts
36    /// @{
37
[2117]38    /// The directed graph concept
39
40    /// This class describes the \ref concept "concept" of the
41    /// immutable directed graphs.
[1136]42    ///
[2117]43    /// Note that actual graph implementation like @ref ListGraph or
44    /// @ref SmartGraph may have several additional functionality.
[1136]45    ///
[2117]46    /// \sa concept
[2111]47    class Graph {
[1136]48    public:
[1448]49      ///\e
50
[1136]51      /// Defalult constructor.
52
53      /// Defalult constructor.
54      ///
[2111]55      Graph() { }
[2128]56      /// Class for identifying a node of the graph
[1136]57
[2128]58      /// This class identifies a node of the graph. It also serves
59      /// as a base class of the node iterators,
60      /// thus they will convert to this type.
[1136]61      class Node {
62      public:
[1426]63        /// Default constructor
[1136]64
[1426]65        /// @warning The default constructor sets the iterator
66        /// to an undefined value.
67        Node() { }
68        /// Copy constructor.
[1136]69
[1426]70        /// Copy constructor.
71        ///
72        Node(const Node&) { }
[1136]73
[1426]74        /// Invalid constructor \& conversion.
[1136]75
[1426]76        /// This constructor initializes the iterator to be invalid.
77        /// \sa Invalid for more details.
78        Node(Invalid) { }
79        /// Equality operator
[1136]80
[1426]81        /// Two iterators are equal if and only if they point to the
82        /// same object or both are invalid.
83        bool operator==(Node) const { return true; }
[1136]84
[1426]85        /// Inequality operator
86       
87        /// \sa operator==(Node n)
88        ///
89        bool operator!=(Node) const { return true; }
[1136]90
[1622]91        /// Artificial ordering operator.
92       
93        /// To allow the use of graph descriptors as key type in std::map or
94        /// similar associative container we require this.
95        ///
96        /// \note This operator only have to define some strict ordering of
97        /// the items; this order has nothing to do with the iteration
98        /// ordering of the items.
99        bool operator<(Node) const { return false; }
100
[1136]101      };
102   
103      /// This iterator goes through each node.
104
105      /// This iterator goes through each node.
106      /// Its usage is quite simple, for example you can count the number
107      /// of nodes in graph \c g of type \c Graph like this:
[1946]108      ///\code
[1136]109      /// int count=0;
[1426]110      /// for (Graph::NodeIt n(g); n!=INVALID; ++n) ++count;
[1946]111      ///\endcode
[1136]112      class NodeIt : public Node {
113      public:
[1426]114        /// Default constructor
[1136]115
[1426]116        /// @warning The default constructor sets the iterator
117        /// to an undefined value.
118        NodeIt() { }
119        /// Copy constructor.
120       
121        /// Copy constructor.
122        ///
123        NodeIt(const NodeIt& n) : Node(n) { }
124        /// Invalid constructor \& conversion.
[1136]125
[1426]126        /// Initialize the iterator to be invalid.
127        /// \sa Invalid for more details.
128        NodeIt(Invalid) { }
129        /// Sets the iterator to the first node.
[1136]130
[1426]131        /// Sets the iterator to the first node of \c g.
132        ///
[2111]133        NodeIt(const Graph&) { }
[1426]134        /// Node -> NodeIt conversion.
[1136]135
[1470]136        /// Sets the iterator to the node of \c the graph pointed by
137        /// the trivial iterator.
[1426]138        /// This feature necessitates that each time we
139        /// iterate the edge-set, the iteration order is the same.
[2111]140        NodeIt(const Graph&, const Node&) { }
[1426]141        /// Next node.
[1136]142
[1426]143        /// Assign the iterator to the next node.
144        ///
145        NodeIt& operator++() { return *this; }
[1136]146      };
147   
148   
[2128]149      /// Class for identifying an edge of the graph
[1136]150
[2128]151      /// This class identifies an edge of the graph. It also serves
152      /// as a base class of the edge iterators,
153      /// thus they will convert to this type.
[1136]154      class Edge {
155      public:
[1426]156        /// Default constructor
[1136]157
[1426]158        /// @warning The default constructor sets the iterator
159        /// to an undefined value.
160        Edge() { }
161        /// Copy constructor.
[1136]162
[1426]163        /// Copy constructor.
164        ///
165        Edge(const Edge&) { }
166        /// Initialize the iterator to be invalid.
[1136]167
[1426]168        /// Initialize the iterator to be invalid.
169        ///
170        Edge(Invalid) { }
171        /// Equality operator
[1136]172
[1426]173        /// Two iterators are equal if and only if they point to the
174        /// same object or both are invalid.
175        bool operator==(Edge) const { return true; }
176        /// Inequality operator
[1136]177
[1620]178        /// \sa operator==(Edge n)
[1426]179        ///
180        bool operator!=(Edge) const { return true; }
[1622]181
182        /// Artificial ordering operator.
183       
184        /// To allow the use of graph descriptors as key type in std::map or
185        /// similar associative container we require this.
186        ///
187        /// \note This operator only have to define some strict ordering of
188        /// the items; this order has nothing to do with the iteration
189        /// ordering of the items.
190        bool operator<(Edge) const { return false; }
[1136]191      };
192   
193      /// This iterator goes trough the outgoing edges of a node.
194
195      /// This iterator goes trough the \e outgoing edges of a certain node
196      /// of a graph.
197      /// Its usage is quite simple, for example you can count the number
198      /// of outgoing edges of a node \c n
199      /// in graph \c g of type \c Graph as follows.
[1946]200      ///\code
[1136]201      /// int count=0;
202      /// for (Graph::OutEdgeIt e(g, n); e!=INVALID; ++e) ++count;
[1946]203      ///\endcode
[1136]204   
205      class OutEdgeIt : public Edge {
206      public:
[1426]207        /// Default constructor
[1136]208
[1426]209        /// @warning The default constructor sets the iterator
210        /// to an undefined value.
211        OutEdgeIt() { }
212        /// Copy constructor.
[1136]213
[1426]214        /// Copy constructor.
215        ///
216        OutEdgeIt(const OutEdgeIt& e) : Edge(e) { }
217        /// Initialize the iterator to be invalid.
[1136]218
[1426]219        /// Initialize the iterator to be invalid.
220        ///
221        OutEdgeIt(Invalid) { }
222        /// This constructor sets the iterator to the first outgoing edge.
[1136]223   
[1426]224        /// This constructor sets the iterator to the first outgoing edge of
225        /// the node.
[2111]226        OutEdgeIt(const Graph&, const Node&) { }
[1426]227        /// Edge -> OutEdgeIt conversion
[1136]228
[1470]229        /// Sets the iterator to the value of the trivial iterator.
230        /// This feature necessitates that each time we
[1426]231        /// iterate the edge-set, the iteration order is the same.
[2111]232        OutEdgeIt(const Graph&, const Edge&) { }
[1426]233        ///Next outgoing edge
234       
235        /// Assign the iterator to the next
236        /// outgoing edge of the corresponding node.
237        OutEdgeIt& operator++() { return *this; }
[1136]238      };
239
240      /// This iterator goes trough the incoming edges of a node.
241
242      /// This iterator goes trough the \e incoming edges of a certain node
243      /// of a graph.
244      /// Its usage is quite simple, for example you can count the number
245      /// of outgoing edges of a node \c n
246      /// in graph \c g of type \c Graph as follows.
[1946]247      ///\code
[1136]248      /// int count=0;
249      /// for(Graph::InEdgeIt e(g, n); e!=INVALID; ++e) ++count;
[1946]250      ///\endcode
[1136]251
252      class InEdgeIt : public Edge {
253      public:
[1426]254        /// Default constructor
[1136]255
[1426]256        /// @warning The default constructor sets the iterator
257        /// to an undefined value.
258        InEdgeIt() { }
259        /// Copy constructor.
[1136]260
[1426]261        /// Copy constructor.
262        ///
263        InEdgeIt(const InEdgeIt& e) : Edge(e) { }
264        /// Initialize the iterator to be invalid.
[1136]265
[1426]266        /// Initialize the iterator to be invalid.
267        ///
268        InEdgeIt(Invalid) { }
269        /// This constructor sets the iterator to first incoming edge.
[1136]270   
[1426]271        /// This constructor set the iterator to the first incoming edge of
272        /// the node.
[2111]273        InEdgeIt(const Graph&, const Node&) { }
[1426]274        /// Edge -> InEdgeIt conversion
[1136]275
[1426]276        /// Sets the iterator to the value of the trivial iterator \c e.
277        /// This feature necessitates that each time we
278        /// iterate the edge-set, the iteration order is the same.
[2111]279        InEdgeIt(const Graph&, const Edge&) { }
[1426]280        /// Next incoming edge
[1136]281
[1426]282        /// Assign the iterator to the next inedge of the corresponding node.
283        ///
284        InEdgeIt& operator++() { return *this; }
[1136]285      };
286      /// This iterator goes through each edge.
287
288      /// This iterator goes through each edge of a graph.
289      /// Its usage is quite simple, for example you can count the number
290      /// of edges in a graph \c g of type \c Graph as follows:
[1946]291      ///\code
[1136]292      /// int count=0;
293      /// for(Graph::EdgeIt e(g); e!=INVALID; ++e) ++count;
[1946]294      ///\endcode
[1136]295      class EdgeIt : public Edge {
296      public:
[1426]297        /// Default constructor
[1136]298
[1426]299        /// @warning The default constructor sets the iterator
300        /// to an undefined value.
301        EdgeIt() { }
302        /// Copy constructor.
[1136]303
[1426]304        /// Copy constructor.
305        ///
306        EdgeIt(const EdgeIt& e) : Edge(e) { }
307        /// Initialize the iterator to be invalid.
[1136]308
[1426]309        /// Initialize the iterator to be invalid.
310        ///
311        EdgeIt(Invalid) { }
312        /// This constructor sets the iterator to the first edge.
[1136]313   
[1426]314        /// This constructor sets the iterator to the first edge of \c g.
315        ///@param g the graph
[2111]316        EdgeIt(const Graph& g) { ignore_unused_variable_warning(g); }
[1426]317        /// Edge -> EdgeIt conversion
[1136]318
[1426]319        /// Sets the iterator to the value of the trivial iterator \c e.
320        /// This feature necessitates that each time we
321        /// iterate the edge-set, the iteration order is the same.
[2111]322        EdgeIt(const Graph&, const Edge&) { }
[1426]323        ///Next edge
324       
325        /// Assign the iterator to the next edge.
326        EdgeIt& operator++() { return *this; }
[1136]327      };
328      ///Gives back the target node of an edge.
329
330      ///Gives back the target node of an edge.
331      ///
332      Node target(Edge) const { return INVALID; }
333      ///Gives back the source node of an edge.
334
335      ///Gives back the source node of an edge.
336      ///
337      Node source(Edge) const { return INVALID; }
[1563]338
339      void first(Node&) const {}
340      void next(Node&) const {}
341
342      void first(Edge&) const {}
343      void next(Edge&) const {}
344
345
346      void firstIn(Edge&, const Node&) const {}
347      void nextIn(Edge&) const {}
348
349      void firstOut(Edge&, const Node&) const {}
350      void nextOut(Edge&) const {}
351
352      /// \brief The base node of the iterator.
353      ///
354      /// Gives back the base node of the iterator.
[1627]355      /// It is always the target of the pointed edge.
[1563]356      Node baseNode(const InEdgeIt&) const { return INVALID; }
357
358      /// \brief The running node of the iterator.
359      ///
360      /// Gives back the running node of the iterator.
[1627]361      /// It is always the source of the pointed edge.
[1563]362      Node runningNode(const InEdgeIt&) const { return INVALID; }
363
364      /// \brief The base node of the iterator.
365      ///
366      /// Gives back the base node of the iterator.
[1627]367      /// It is always the source of the pointed edge.
[1563]368      Node baseNode(const OutEdgeIt&) const { return INVALID; }
369
370      /// \brief The running node of the iterator.
371      ///
372      /// Gives back the running node of the iterator.
[1627]373      /// It is always the target of the pointed edge.
[1563]374      Node runningNode(const OutEdgeIt&) const { return INVALID; }
[1136]375
[1627]376      /// \brief The opposite node on the given edge.
377      ///
378      /// Gives back the opposite node on the given edge.
379      Node oppositeNode(const Node&, const Edge&) const { return INVALID; }
380
381      /// \brief Read write map of the nodes to type \c T.
382      ///
[1136]383      /// ReadWrite map of the nodes to type \c T.
384      /// \sa Reference
385      template<class T>
[2121]386      class NodeMap : public ReadWriteMap< Node, T > {
[1136]387      public:
388
[1426]389        ///\e
[2111]390        NodeMap(const Graph&) { }
[1426]391        ///\e
[2111]392        NodeMap(const Graph&, T) { }
[1136]393
[1426]394        ///Copy constructor
395        NodeMap(const NodeMap& nm) : ReadWriteMap< Node, T >(nm) { }
396        ///Assignment operator
[2121]397        template <typename CMap>
398        NodeMap& operator=(const CMap&) {
399          checkConcept<ReadMap<Node, T>, CMap>();
400          return *this;
401        }
[1136]402      };
403
[1627]404      /// \brief Read write map of the edges to type \c T.
405      ///
406      /// Reference map of the edges to type \c T.
[1136]407      /// \sa Reference
408      template<class T>
[2121]409      class EdgeMap : public ReadWriteMap<Edge,T> {
[1136]410      public:
411
[1426]412        ///\e
[2111]413        EdgeMap(const Graph&) { }
[1426]414        ///\e
[2111]415        EdgeMap(const Graph&, T) { }
[1426]416        ///Copy constructor
417        EdgeMap(const EdgeMap& em) : ReadWriteMap<Edge,T>(em) { }
418        ///Assignment operator
[2121]419        template <typename CMap>
420        EdgeMap& operator=(const CMap&) {
421          checkConcept<ReadMap<Edge, T>, CMap>();
422          return *this;
423        }
[1136]424      };
425
[2111]426      template <typename RGraph>
[2121]427      struct Constraints {
428        void constraints() {
429          checkConcept<BaseIterableGraphComponent<>, Graph>();
430          checkConcept<IterableGraphComponent<>, Graph>();
431          checkConcept<MappableGraphComponent<>, Graph>();
432        }
433      };
[1136]434
435    };
436   
[959]437    // @}
438  } //namespace concept 
439} //namespace lemon
440
441
442
443#endif // LEMON_CONCEPT_GRAPH_H
Note: See TracBrowser for help on using the repository browser.