COIN-OR::LEMON - Graph Library

source: lemon-main/lemon/concepts/digraph.h @ 1093:fb1c7da561ce

Last change on this file since 1093:fb1c7da561ce was 1093:fb1c7da561ce, checked in by Alpar Juttner <alpar@…>, 11 years ago

Remove long lines (from all but one file)

File size: 15.1 KB
RevLine 
[209]1/* -*- mode: C++; indent-tabs-mode: nil; -*-
[57]2 *
[209]3 * This file is a part of LEMON, a generic C++ optimization library.
[57]4 *
[1092]5 * Copyright (C) 2003-2013
[57]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
[529]19#ifndef LEMON_CONCEPTS_DIGRAPH_H
20#define LEMON_CONCEPTS_DIGRAPH_H
[57]21
22///\ingroup graph_concepts
23///\file
24///\brief The concept of directed graphs.
25
[220]26#include <lemon/core.h>
[57]27#include <lemon/concepts/maps.h>
28#include <lemon/concept_check.h>
29#include <lemon/concepts/graph_components.h>
30
31namespace lemon {
32  namespace concepts {
33
34    /// \ingroup graph_concepts
35    ///
36    /// \brief Class describing the concept of directed graphs.
37    ///
[734]38    /// This class describes the common interface of all directed
39    /// graphs (digraphs).
[57]40    ///
[734]41    /// Like all concept classes, it only provides an interface
42    /// without any sensible implementation. So any general algorithm for
43    /// directed graphs should compile with this class, but it will not
44    /// run properly, of course.
45    /// An actual digraph implementation like \ref ListDigraph or
46    /// \ref SmartDigraph may have additional functionality.
[57]47    ///
[734]48    /// \sa Graph
[57]49    class Digraph {
50    private:
[734]51      /// Diraphs are \e not copy constructible. Use DigraphCopy instead.
52      Digraph(const Digraph &) {}
53      /// \brief Assignment of a digraph to another one is \e not allowed.
54      /// Use DigraphCopy instead.
55      void operator=(const Digraph &) {}
[209]56
[734]57    public:
58      /// Default constructor.
59      Digraph() { }
[209]60
[734]61      /// The node type of the digraph
[57]62
63      /// This class identifies a node of the digraph. It also serves
64      /// as a base class of the node iterators,
[734]65      /// thus they convert to this type.
[57]66      class Node {
67      public:
68        /// Default constructor
69
[734]70        /// Default constructor.
71        /// \warning It sets the object to an undefined value.
[57]72        Node() { }
73        /// Copy constructor.
74
75        /// Copy constructor.
76        ///
77        Node(const Node&) { }
78
[734]79        /// %Invalid constructor \& conversion.
[57]80
[734]81        /// Initializes the object to be invalid.
[57]82        /// \sa Invalid for more details.
83        Node(Invalid) { }
84        /// Equality operator
85
[734]86        /// Equality operator.
87        ///
[57]88        /// Two iterators are equal if and only if they point to the
[734]89        /// same object or both are \c INVALID.
[57]90        bool operator==(Node) const { return true; }
91
92        /// Inequality operator
[209]93
[734]94        /// Inequality operator.
[57]95        bool operator!=(Node) const { return true; }
96
[209]97        /// Artificial ordering operator.
98
[734]99        /// Artificial ordering operator.
[209]100        ///
[734]101        /// \note This operator only has to define some strict ordering of
102        /// the nodes; this order has nothing to do with the iteration
103        /// ordering of the nodes.
[209]104        bool operator<(Node) const { return false; }
[57]105      };
[209]106
[734]107      /// Iterator class for the nodes.
[57]108
[734]109      /// This iterator goes through each node of the digraph.
[786]110      /// Its usage is quite simple, for example, you can count the number
[734]111      /// of nodes in a digraph \c g of type \c %Digraph like this:
[57]112      ///\code
113      /// int count=0;
114      /// for (Digraph::NodeIt n(g); n!=INVALID; ++n) ++count;
115      ///\endcode
116      class NodeIt : public Node {
117      public:
118        /// Default constructor
119
[734]120        /// Default constructor.
121        /// \warning It sets the iterator to an undefined value.
[57]122        NodeIt() { }
123        /// Copy constructor.
[209]124
[57]125        /// Copy constructor.
126        ///
127        NodeIt(const NodeIt& n) : Node(n) { }
[734]128        /// %Invalid constructor \& conversion.
[57]129
[734]130        /// Initializes the iterator to be invalid.
[57]131        /// \sa Invalid for more details.
132        NodeIt(Invalid) { }
133        /// Sets the iterator to the first node.
134
[734]135        /// Sets the iterator to the first node of the given digraph.
[57]136        ///
[734]137        explicit NodeIt(const Digraph&) { }
138        /// Sets the iterator to the given node.
[57]139
[734]140        /// Sets the iterator to the given node of the given digraph.
141        ///
[57]142        NodeIt(const Digraph&, const Node&) { }
143        /// Next node.
144
145        /// Assign the iterator to the next node.
146        ///
147        NodeIt& operator++() { return *this; }
148      };
[209]149
150
[734]151      /// The arc type of the digraph
[57]152
153      /// This class identifies an arc of the digraph. It also serves
154      /// as a base class of the arc iterators,
155      /// thus they will convert to this type.
156      class Arc {
157      public:
158        /// Default constructor
159
[734]160        /// Default constructor.
161        /// \warning It sets the object to an undefined value.
[57]162        Arc() { }
163        /// Copy constructor.
164
165        /// Copy constructor.
166        ///
167        Arc(const Arc&) { }
[734]168        /// %Invalid constructor \& conversion.
[57]169
[734]170        /// Initializes the object to be invalid.
171        /// \sa Invalid for more details.
[57]172        Arc(Invalid) { }
173        /// Equality operator
174
[734]175        /// Equality operator.
176        ///
[57]177        /// Two iterators are equal if and only if they point to the
[734]178        /// same object or both are \c INVALID.
[57]179        bool operator==(Arc) const { return true; }
180        /// Inequality operator
181
[734]182        /// Inequality operator.
[57]183        bool operator!=(Arc) const { return true; }
184
[209]185        /// Artificial ordering operator.
186
[734]187        /// Artificial ordering operator.
[209]188        ///
[734]189        /// \note This operator only has to define some strict ordering of
190        /// the arcs; this order has nothing to do with the iteration
191        /// ordering of the arcs.
[209]192        bool operator<(Arc) const { return false; }
[57]193      };
[209]194
[734]195      /// Iterator class for the outgoing arcs of a node.
[57]196
197      /// This iterator goes trough the \e outgoing arcs of a certain node
198      /// of a digraph.
[786]199      /// Its usage is quite simple, for example, you can count the number
[57]200      /// of outgoing arcs of a node \c n
[734]201      /// in a digraph \c g of type \c %Digraph as follows.
[57]202      ///\code
203      /// int count=0;
[734]204      /// for (Digraph::OutArcIt a(g, n); a!=INVALID; ++a) ++count;
[57]205      ///\endcode
206      class OutArcIt : public Arc {
207      public:
208        /// Default constructor
209
[734]210        /// Default constructor.
211        /// \warning It sets the iterator to an undefined value.
[57]212        OutArcIt() { }
213        /// Copy constructor.
214
215        /// Copy constructor.
216        ///
217        OutArcIt(const OutArcIt& e) : Arc(e) { }
[734]218        /// %Invalid constructor \& conversion.
[57]219
[734]220        /// Initializes the iterator to be invalid.
221        /// \sa Invalid for more details.
222        OutArcIt(Invalid) { }
223        /// Sets the iterator to the first outgoing arc.
224
225        /// Sets the iterator to the first outgoing arc of the given node.
[57]226        ///
[734]227        OutArcIt(const Digraph&, const Node&) { }
228        /// Sets the iterator to the given arc.
[209]229
[734]230        /// Sets the iterator to the given arc of the given digraph.
231        ///
[57]232        OutArcIt(const Digraph&, const Arc&) { }
[734]233        /// Next outgoing arc
[209]234
235        /// Assign the iterator to the next
[57]236        /// outgoing arc of the corresponding node.
237        OutArcIt& operator++() { return *this; }
238      };
239
[734]240      /// Iterator class for the incoming arcs of a node.
[57]241
242      /// This iterator goes trough the \e incoming arcs of a certain node
243      /// of a digraph.
[786]244      /// Its usage is quite simple, for example, you can count the number
[734]245      /// of incoming arcs of a node \c n
246      /// in a digraph \c g of type \c %Digraph as follows.
[57]247      ///\code
248      /// int count=0;
[734]249      /// for(Digraph::InArcIt a(g, n); a!=INVALID; ++a) ++count;
[57]250      ///\endcode
251      class InArcIt : public Arc {
252      public:
253        /// Default constructor
254
[734]255        /// Default constructor.
256        /// \warning It sets the iterator to an undefined value.
[57]257        InArcIt() { }
258        /// Copy constructor.
259
260        /// Copy constructor.
261        ///
262        InArcIt(const InArcIt& e) : Arc(e) { }
[734]263        /// %Invalid constructor \& conversion.
[57]264
[734]265        /// Initializes the iterator to be invalid.
266        /// \sa Invalid for more details.
267        InArcIt(Invalid) { }
268        /// Sets the iterator to the first incoming arc.
269
270        /// Sets the iterator to the first incoming arc of the given node.
[57]271        ///
[734]272        InArcIt(const Digraph&, const Node&) { }
273        /// Sets the iterator to the given arc.
[209]274
[734]275        /// Sets the iterator to the given arc of the given digraph.
276        ///
[57]277        InArcIt(const Digraph&, const Arc&) { }
278        /// Next incoming arc
279
[734]280        /// Assign the iterator to the next
281        /// incoming arc of the corresponding node.
[57]282        InArcIt& operator++() { return *this; }
283      };
284
[734]285      /// Iterator class for the arcs.
286
287      /// This iterator goes through each arc of the digraph.
[786]288      /// Its usage is quite simple, for example, you can count the number
[734]289      /// of arcs in a digraph \c g of type \c %Digraph as follows:
[57]290      ///\code
291      /// int count=0;
[734]292      /// for(Digraph::ArcIt a(g); a!=INVALID; ++a) ++count;
[57]293      ///\endcode
294      class ArcIt : public Arc {
295      public:
296        /// Default constructor
297
[734]298        /// Default constructor.
299        /// \warning It sets the iterator to an undefined value.
[57]300        ArcIt() { }
301        /// Copy constructor.
302
303        /// Copy constructor.
304        ///
305        ArcIt(const ArcIt& e) : Arc(e) { }
[734]306        /// %Invalid constructor \& conversion.
[57]307
[734]308        /// Initializes the iterator to be invalid.
309        /// \sa Invalid for more details.
310        ArcIt(Invalid) { }
311        /// Sets the iterator to the first arc.
312
313        /// Sets the iterator to the first arc of the given digraph.
[57]314        ///
[1093]315        explicit ArcIt(const Digraph& g) {
316          ::lemon::ignore_unused_variable_warning(g);
317        }
[734]318        /// Sets the iterator to the given arc.
[209]319
[734]320        /// Sets the iterator to the given arc of the given digraph.
321        ///
[209]322        ArcIt(const Digraph&, const Arc&) { }
[734]323        /// Next arc
[209]324
[57]325        /// Assign the iterator to the next arc.
[734]326        ///
[57]327        ArcIt& operator++() { return *this; }
328      };
329
[734]330      /// \brief The source node of the arc.
[57]331      ///
[734]332      /// Returns the source node of the given arc.
[57]333      Node source(Arc) const { return INVALID; }
334
[734]335      /// \brief The target node of the arc.
336      ///
337      /// Returns the target node of the given arc.
338      Node target(Arc) const { return INVALID; }
339
340      /// \brief The ID of the node.
341      ///
342      /// Returns the ID of the given node.
[209]343      int id(Node) const { return -1; }
[61]344
[734]345      /// \brief The ID of the arc.
346      ///
347      /// Returns the ID of the given arc.
[209]348      int id(Arc) const { return -1; }
[61]349
[734]350      /// \brief The node with the given ID.
[61]351      ///
[734]352      /// Returns the node with the given ID.
353      /// \pre The argument should be a valid node ID in the digraph.
[209]354      Node nodeFromId(int) const { return INVALID; }
[61]355
[734]356      /// \brief The arc with the given ID.
[61]357      ///
[734]358      /// Returns the arc with the given ID.
359      /// \pre The argument should be a valid arc ID in the digraph.
[209]360      Arc arcFromId(int) const { return INVALID; }
[61]361
[734]362      /// \brief An upper bound on the node IDs.
363      ///
364      /// Returns an upper bound on the node IDs.
[209]365      int maxNodeId() const { return -1; }
[61]366
[734]367      /// \brief An upper bound on the arc IDs.
368      ///
369      /// Returns an upper bound on the arc IDs.
[209]370      int maxArcId() const { return -1; }
[61]371
[57]372      void first(Node&) const {}
373      void next(Node&) const {}
374
375      void first(Arc&) const {}
376      void next(Arc&) const {}
377
378
379      void firstIn(Arc&, const Node&) const {}
380      void nextIn(Arc&) const {}
381
382      void firstOut(Arc&, const Node&) const {}
383      void nextOut(Arc&) const {}
384
[61]385      // The second parameter is dummy.
386      Node fromId(int, Node) const { return INVALID; }
387      // The second parameter is dummy.
388      Arc fromId(int, Arc) const { return INVALID; }
389
390      // Dummy parameter.
[209]391      int maxId(Node) const { return -1; }
[61]392      // Dummy parameter.
[209]393      int maxId(Arc) const { return -1; }
[61]394
[734]395      /// \brief The opposite node on the arc.
396      ///
397      /// Returns the opposite node on the given arc.
398      Node oppositeNode(Node, Arc) const { return INVALID; }
399
[57]400      /// \brief The base node of the iterator.
401      ///
[734]402      /// Returns the base node of the given outgoing arc iterator
403      /// (i.e. the source node of the corresponding arc).
404      Node baseNode(OutArcIt) const { return INVALID; }
[57]405
406      /// \brief The running node of the iterator.
407      ///
[734]408      /// Returns the running node of the given outgoing arc iterator
409      /// (i.e. the target node of the corresponding arc).
410      Node runningNode(OutArcIt) const { return INVALID; }
[57]411
412      /// \brief The base node of the iterator.
413      ///
[1049]414      /// Returns the base node of the given incoming arc iterator
[734]415      /// (i.e. the target node of the corresponding arc).
416      Node baseNode(InArcIt) const { return INVALID; }
[57]417
418      /// \brief The running node of the iterator.
419      ///
[1049]420      /// Returns the running node of the given incoming arc iterator
[734]421      /// (i.e. the source node of the corresponding arc).
422      Node runningNode(InArcIt) const { return INVALID; }
[57]423
[734]424      /// \brief Standard graph map type for the nodes.
[57]425      ///
[734]426      /// Standard graph map type for the nodes.
427      /// It conforms to the ReferenceMap concept.
[209]428      template<class T>
[580]429      class NodeMap : public ReferenceMap<Node, T, T&, const T&> {
[57]430      public:
431
[734]432        /// Constructor
433        explicit NodeMap(const Digraph&) { }
434        /// Constructor with given initial value
[57]435        NodeMap(const Digraph&, T) { }
436
[263]437      private:
[57]438        ///Copy constructor
[877]439        NodeMap(const NodeMap& nm) :
[580]440          ReferenceMap<Node, T, T&, const T&>(nm) { }
[57]441        ///Assignment operator
442        template <typename CMap>
[209]443        NodeMap& operator=(const CMap&) {
[57]444          checkConcept<ReadMap<Node, T>, CMap>();
[209]445          return *this;
[57]446        }
447      };
448
[734]449      /// \brief Standard graph map type for the arcs.
[57]450      ///
[734]451      /// Standard graph map type for the arcs.
452      /// It conforms to the ReferenceMap concept.
[209]453      template<class T>
[580]454      class ArcMap : public ReferenceMap<Arc, T, T&, const T&> {
[57]455      public:
456
[734]457        /// Constructor
458        explicit ArcMap(const Digraph&) { }
459        /// Constructor with given initial value
[57]460        ArcMap(const Digraph&, T) { }
[734]461
[263]462      private:
[57]463        ///Copy constructor
[580]464        ArcMap(const ArcMap& em) :
465          ReferenceMap<Arc, T, T&, const T&>(em) { }
[57]466        ///Assignment operator
467        template <typename CMap>
[209]468        ArcMap& operator=(const CMap&) {
[57]469          checkConcept<ReadMap<Arc, T>, CMap>();
[209]470          return *this;
[57]471        }
472      };
473
[125]474      template <typename _Digraph>
[57]475      struct Constraints {
476        void constraints() {
[580]477          checkConcept<BaseDigraphComponent, _Digraph>();
[125]478          checkConcept<IterableDigraphComponent<>, _Digraph>();
[209]479          checkConcept<IDableDigraphComponent<>, _Digraph>();
[125]480          checkConcept<MappableDigraphComponent<>, _Digraph>();
[57]481        }
482      };
483
484    };
[209]485
486  } //namespace concepts
[57]487} //namespace lemon
488
489
490
[529]491#endif
Note: See TracBrowser for help on using the repository browser.