3 * This file is a part of LEMON, a generic C++ optimization library
5 * Copyright (C) 2003-2006
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
9 * Permission to use, modify and distribute this software is granted
10 * provided that this copyright notice appears in all copies. For
11 * precise terms see the accompanying LICENSE file.
13 * This software is provided "AS IS" with no warranty of any kind,
14 * express or implied, and with no claim as to its suitability for any
19 #ifndef LEMON_CONCEPT_GRAPH_H
20 #define LEMON_CONCEPT_GRAPH_H
22 ///\ingroup graph_concepts
24 ///\brief Declaration of Graph.
26 #include <lemon/bits/invalid.h>
27 #include <lemon/bits/utility.h>
28 #include <lemon/concept/maps.h>
29 #include <lemon/concept_check.h>
30 #include <lemon/concept/graph_components.h>
35 /// \addtogroup graph_concepts
38 /// The directed graph concept
40 /// This class describes the \ref concept "concept" of the
41 /// immutable directed graphs.
43 /// Note that actual graph implementation like @ref ListGraph or
44 /// @ref SmartGraph may have several additional functionality.
51 /// Defalult constructor.
53 /// Defalult constructor.
56 /// Class for identifying a node of the graph
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.
63 /// Default constructor
65 /// @warning The default constructor sets the iterator
66 /// to an undefined value.
74 /// Invalid constructor \& conversion.
76 /// This constructor initializes the iterator to be invalid.
77 /// \sa Invalid for more details.
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; }
85 /// Inequality operator
87 /// \sa operator==(Node n)
89 bool operator!=(Node) const { return true; }
91 /// Artificial ordering operator.
93 /// To allow the use of graph descriptors as key type in std::map or
94 /// similar associative container we require this.
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; }
103 /// This iterator goes through each node.
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:
110 /// for (Graph::NodeIt n(g); n!=INVALID; ++n) ++count;
112 class NodeIt : public Node {
114 /// Default constructor
116 /// @warning The default constructor sets the iterator
117 /// to an undefined value.
119 /// Copy constructor.
121 /// Copy constructor.
123 NodeIt(const NodeIt& n) : Node(n) { }
124 /// Invalid constructor \& conversion.
126 /// Initialize the iterator to be invalid.
127 /// \sa Invalid for more details.
129 /// Sets the iterator to the first node.
131 /// Sets the iterator to the first node of \c g.
133 NodeIt(const Graph&) { }
134 /// Node -> NodeIt conversion.
136 /// Sets the iterator to the node of \c the graph pointed by
137 /// the trivial iterator.
138 /// This feature necessitates that each time we
139 /// iterate the edge-set, the iteration order is the same.
140 NodeIt(const Graph&, const Node&) { }
143 /// Assign the iterator to the next node.
145 NodeIt& operator++() { return *this; }
149 /// Class for identifying an edge of the graph
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.
156 /// Default constructor
158 /// @warning The default constructor sets the iterator
159 /// to an undefined value.
161 /// Copy constructor.
163 /// Copy constructor.
165 Edge(const Edge&) { }
166 /// Initialize the iterator to be invalid.
168 /// Initialize the iterator to be invalid.
171 /// Equality operator
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
178 /// \sa operator==(Edge n)
180 bool operator!=(Edge) const { return true; }
182 /// Artificial ordering operator.
184 /// To allow the use of graph descriptors as key type in std::map or
185 /// similar associative container we require this.
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; }
193 /// This iterator goes trough the outgoing edges of a node.
195 /// This iterator goes trough the \e outgoing edges of a certain node
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.
202 /// for (Graph::OutEdgeIt e(g, n); e!=INVALID; ++e) ++count;
205 class OutEdgeIt : public Edge {
207 /// Default constructor
209 /// @warning The default constructor sets the iterator
210 /// to an undefined value.
212 /// Copy constructor.
214 /// Copy constructor.
216 OutEdgeIt(const OutEdgeIt& e) : Edge(e) { }
217 /// Initialize the iterator to be invalid.
219 /// Initialize the iterator to be invalid.
221 OutEdgeIt(Invalid) { }
222 /// This constructor sets the iterator to the first outgoing edge.
224 /// This constructor sets the iterator to the first outgoing edge of
226 OutEdgeIt(const Graph&, const Node&) { }
227 /// Edge -> OutEdgeIt conversion
229 /// Sets the iterator to the value of the trivial iterator.
230 /// This feature necessitates that each time we
231 /// iterate the edge-set, the iteration order is the same.
232 OutEdgeIt(const Graph&, const Edge&) { }
233 ///Next outgoing edge
235 /// Assign the iterator to the next
236 /// outgoing edge of the corresponding node.
237 OutEdgeIt& operator++() { return *this; }
240 /// This iterator goes trough the incoming edges of a node.
242 /// This iterator goes trough the \e incoming edges of a certain node
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.
249 /// for(Graph::InEdgeIt e(g, n); e!=INVALID; ++e) ++count;
252 class InEdgeIt : public Edge {
254 /// Default constructor
256 /// @warning The default constructor sets the iterator
257 /// to an undefined value.
259 /// Copy constructor.
261 /// Copy constructor.
263 InEdgeIt(const InEdgeIt& e) : Edge(e) { }
264 /// Initialize the iterator to be invalid.
266 /// Initialize the iterator to be invalid.
268 InEdgeIt(Invalid) { }
269 /// This constructor sets the iterator to first incoming edge.
271 /// This constructor set the iterator to the first incoming edge of
273 InEdgeIt(const Graph&, const Node&) { }
274 /// Edge -> InEdgeIt conversion
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.
279 InEdgeIt(const Graph&, const Edge&) { }
280 /// Next incoming edge
282 /// Assign the iterator to the next inedge of the corresponding node.
284 InEdgeIt& operator++() { return *this; }
286 /// This iterator goes through each edge.
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:
293 /// for(Graph::EdgeIt e(g); e!=INVALID; ++e) ++count;
295 class EdgeIt : public Edge {
297 /// Default constructor
299 /// @warning The default constructor sets the iterator
300 /// to an undefined value.
302 /// Copy constructor.
304 /// Copy constructor.
306 EdgeIt(const EdgeIt& e) : Edge(e) { }
307 /// Initialize the iterator to be invalid.
309 /// Initialize the iterator to be invalid.
312 /// This constructor sets the iterator to the first edge.
314 /// This constructor sets the iterator to the first edge of \c g.
315 ///@param g the graph
316 EdgeIt(const Graph& g) { ignore_unused_variable_warning(g); }
317 /// Edge -> EdgeIt conversion
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.
322 EdgeIt(const Graph&, const Edge&) { }
325 /// Assign the iterator to the next edge.
326 EdgeIt& operator++() { return *this; }
328 ///Gives back the target node of an edge.
330 ///Gives back the target node of an edge.
332 Node target(Edge) const { return INVALID; }
333 ///Gives back the source node of an edge.
335 ///Gives back the source node of an edge.
337 Node source(Edge) const { return INVALID; }
339 void first(Node&) const {}
340 void next(Node&) const {}
342 void first(Edge&) const {}
343 void next(Edge&) const {}
346 void firstIn(Edge&, const Node&) const {}
347 void nextIn(Edge&) const {}
349 void firstOut(Edge&, const Node&) const {}
350 void nextOut(Edge&) const {}
352 /// \brief The base node of the iterator.
354 /// Gives back the base node of the iterator.
355 /// It is always the target of the pointed edge.
356 Node baseNode(const InEdgeIt&) const { return INVALID; }
358 /// \brief The running node of the iterator.
360 /// Gives back the running node of the iterator.
361 /// It is always the source of the pointed edge.
362 Node runningNode(const InEdgeIt&) const { return INVALID; }
364 /// \brief The base node of the iterator.
366 /// Gives back the base node of the iterator.
367 /// It is always the source of the pointed edge.
368 Node baseNode(const OutEdgeIt&) const { return INVALID; }
370 /// \brief The running node of the iterator.
372 /// Gives back the running node of the iterator.
373 /// It is always the target of the pointed edge.
374 Node runningNode(const OutEdgeIt&) const { return INVALID; }
376 /// \brief The opposite node on the given edge.
378 /// Gives back the opposite node on the given edge.
379 Node oppositeNode(const Node&, const Edge&) const { return INVALID; }
381 /// \brief Read write map of the nodes to type \c T.
383 /// ReadWrite map of the nodes to type \c T.
386 class NodeMap : public ReadWriteMap< Node, T > {
390 NodeMap(const Graph&) { }
392 NodeMap(const Graph&, T) { }
395 NodeMap(const NodeMap& nm) : ReadWriteMap< Node, T >(nm) { }
396 ///Assignment operator
397 template <typename CMap>
398 NodeMap& operator=(const CMap&) {
399 checkConcept<ReadMap<Node, T>, CMap>();
404 /// \brief Read write map of the edges to type \c T.
406 /// Reference map of the edges to type \c T.
409 class EdgeMap : public ReadWriteMap<Edge,T> {
413 EdgeMap(const Graph&) { }
415 EdgeMap(const Graph&, T) { }
417 EdgeMap(const EdgeMap& em) : ReadWriteMap<Edge,T>(em) { }
418 ///Assignment operator
419 template <typename CMap>
420 EdgeMap& operator=(const CMap&) {
421 checkConcept<ReadMap<Edge, T>, CMap>();
426 template <typename RGraph>
429 checkConcept<BaseIterableGraphComponent<>, Graph>();
430 checkConcept<IterableGraphComponent<>, Graph>();
431 checkConcept<MappableGraphComponent<>, Graph>();
438 } //namespace concept
443 #endif // LEMON_CONCEPT_GRAPH_H