Oops. I did not mean to break the repository.
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/concepts/maps.h>
29 #include <lemon/concept_check.h>
30 #include <lemon/concepts/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.
49 ///Graphs are \e not copy constructible. Use GraphCopy() instead.
51 ///Graphs are \e not copy constructible. Use GraphCopy() instead.
53 Graph(const Graph &) {};
54 ///\brief Assignment of \ref Graph "Graph"s to another ones are
55 ///\e not allowed. Use GraphCopy() instead.
57 ///Assignment of \ref Graph "Graph"s to another ones are
58 ///\e not allowed. Use GraphCopy() instead.
60 void operator=(const Graph &) {}
64 /// Defalult constructor.
66 /// Defalult constructor.
69 /// Class for identifying a node of the graph
71 /// This class identifies a node of the graph. It also serves
72 /// as a base class of the node iterators,
73 /// thus they will convert to this type.
76 /// Default constructor
78 /// @warning The default constructor sets the iterator
79 /// to an undefined value.
87 /// Invalid constructor \& conversion.
89 /// This constructor initializes the iterator to be invalid.
90 /// \sa Invalid for more details.
94 /// Two iterators are equal if and only if they point to the
95 /// same object or both are invalid.
96 bool operator==(Node) const { return true; }
98 /// Inequality operator
100 /// \sa operator==(Node n)
102 bool operator!=(Node) const { return true; }
104 /// Artificial ordering operator.
106 /// To allow the use of graph descriptors as key type in std::map or
107 /// similar associative container we require this.
109 /// \note This operator only have to define some strict ordering of
110 /// the items; this order has nothing to do with the iteration
111 /// ordering of the items.
112 bool operator<(Node) const { return false; }
116 /// This iterator goes through each node.
118 /// This iterator goes through each node.
119 /// Its usage is quite simple, for example you can count the number
120 /// of nodes in graph \c g of type \c Graph like this:
123 /// for (Graph::NodeIt n(g); n!=INVALID; ++n) ++count;
125 class NodeIt : public Node {
127 /// Default constructor
129 /// @warning The default constructor sets the iterator
130 /// to an undefined value.
132 /// Copy constructor.
134 /// Copy constructor.
136 NodeIt(const NodeIt& n) : Node(n) { }
137 /// Invalid constructor \& conversion.
139 /// Initialize the iterator to be invalid.
140 /// \sa Invalid for more details.
142 /// Sets the iterator to the first node.
144 /// Sets the iterator to the first node of \c g.
146 NodeIt(const Graph&) { }
147 /// Node -> NodeIt conversion.
149 /// Sets the iterator to the node of \c the graph pointed by
150 /// the trivial iterator.
151 /// This feature necessitates that each time we
152 /// iterate the edge-set, the iteration order is the same.
153 NodeIt(const Graph&, const Node&) { }
156 /// Assign the iterator to the next node.
158 NodeIt& operator++() { return *this; }
162 /// Class for identifying an edge of the graph
164 /// This class identifies an edge of the graph. It also serves
165 /// as a base class of the edge iterators,
166 /// thus they will convert to this type.
169 /// Default constructor
171 /// @warning The default constructor sets the iterator
172 /// to an undefined value.
174 /// Copy constructor.
176 /// Copy constructor.
178 Edge(const Edge&) { }
179 /// Initialize the iterator to be invalid.
181 /// Initialize the iterator to be invalid.
184 /// Equality operator
186 /// Two iterators are equal if and only if they point to the
187 /// same object or both are invalid.
188 bool operator==(Edge) const { return true; }
189 /// Inequality operator
191 /// \sa operator==(Edge n)
193 bool operator!=(Edge) const { return true; }
195 /// Artificial ordering operator.
197 /// To allow the use of graph descriptors as key type in std::map or
198 /// similar associative container we require this.
200 /// \note This operator only have to define some strict ordering of
201 /// the items; this order has nothing to do with the iteration
202 /// ordering of the items.
203 bool operator<(Edge) const { return false; }
206 /// This iterator goes trough the outgoing edges of a node.
208 /// This iterator goes trough the \e outgoing edges of a certain node
210 /// Its usage is quite simple, for example you can count the number
211 /// of outgoing edges of a node \c n
212 /// in graph \c g of type \c Graph as follows.
215 /// for (Graph::OutEdgeIt e(g, n); e!=INVALID; ++e) ++count;
218 class OutEdgeIt : public Edge {
220 /// Default constructor
222 /// @warning The default constructor sets the iterator
223 /// to an undefined value.
225 /// Copy constructor.
227 /// Copy constructor.
229 OutEdgeIt(const OutEdgeIt& e) : Edge(e) { }
230 /// Initialize the iterator to be invalid.
232 /// Initialize the iterator to be invalid.
234 OutEdgeIt(Invalid) { }
235 /// This constructor sets the iterator to the first outgoing edge.
237 /// This constructor sets the iterator to the first outgoing edge of
239 OutEdgeIt(const Graph&, const Node&) { }
240 /// Edge -> OutEdgeIt conversion
242 /// Sets the iterator to the value of the trivial iterator.
243 /// This feature necessitates that each time we
244 /// iterate the edge-set, the iteration order is the same.
245 OutEdgeIt(const Graph&, const Edge&) { }
246 ///Next outgoing edge
248 /// Assign the iterator to the next
249 /// outgoing edge of the corresponding node.
250 OutEdgeIt& operator++() { return *this; }
253 /// This iterator goes trough the incoming edges of a node.
255 /// This iterator goes trough the \e incoming edges of a certain node
257 /// Its usage is quite simple, for example you can count the number
258 /// of outgoing edges of a node \c n
259 /// in graph \c g of type \c Graph as follows.
262 /// for(Graph::InEdgeIt e(g, n); e!=INVALID; ++e) ++count;
265 class InEdgeIt : public Edge {
267 /// Default constructor
269 /// @warning The default constructor sets the iterator
270 /// to an undefined value.
272 /// Copy constructor.
274 /// Copy constructor.
276 InEdgeIt(const InEdgeIt& e) : Edge(e) { }
277 /// Initialize the iterator to be invalid.
279 /// Initialize the iterator to be invalid.
281 InEdgeIt(Invalid) { }
282 /// This constructor sets the iterator to first incoming edge.
284 /// This constructor set the iterator to the first incoming edge of
286 InEdgeIt(const Graph&, const Node&) { }
287 /// Edge -> InEdgeIt conversion
289 /// Sets the iterator to the value of the trivial iterator \c e.
290 /// This feature necessitates that each time we
291 /// iterate the edge-set, the iteration order is the same.
292 InEdgeIt(const Graph&, const Edge&) { }
293 /// Next incoming edge
295 /// Assign the iterator to the next inedge of the corresponding node.
297 InEdgeIt& operator++() { return *this; }
299 /// This iterator goes through each edge.
301 /// This iterator goes through each edge of a graph.
302 /// Its usage is quite simple, for example you can count the number
303 /// of edges in a graph \c g of type \c Graph as follows:
306 /// for(Graph::EdgeIt e(g); e!=INVALID; ++e) ++count;
308 class EdgeIt : public Edge {
310 /// Default constructor
312 /// @warning The default constructor sets the iterator
313 /// to an undefined value.
315 /// Copy constructor.
317 /// Copy constructor.
319 EdgeIt(const EdgeIt& e) : Edge(e) { }
320 /// Initialize the iterator to be invalid.
322 /// Initialize the iterator to be invalid.
325 /// This constructor sets the iterator to the first edge.
327 /// This constructor sets the iterator to the first edge of \c g.
328 ///@param g the graph
329 EdgeIt(const Graph& g) { ignore_unused_variable_warning(g); }
330 /// Edge -> EdgeIt conversion
332 /// Sets the iterator to the value of the trivial iterator \c e.
333 /// This feature necessitates that each time we
334 /// iterate the edge-set, the iteration order is the same.
335 EdgeIt(const Graph&, const Edge&) { }
338 /// Assign the iterator to the next edge.
339 EdgeIt& operator++() { return *this; }
341 ///Gives back the target node of an edge.
343 ///Gives back the target node of an edge.
345 Node target(Edge) const { return INVALID; }
346 ///Gives back the source node of an edge.
348 ///Gives back the source node of an edge.
350 Node source(Edge) const { return INVALID; }
352 void first(Node&) const {}
353 void next(Node&) const {}
355 void first(Edge&) const {}
356 void next(Edge&) const {}
359 void firstIn(Edge&, const Node&) const {}
360 void nextIn(Edge&) const {}
362 void firstOut(Edge&, const Node&) const {}
363 void nextOut(Edge&) const {}
365 /// \brief The base node of the iterator.
367 /// Gives back the base node of the iterator.
368 /// It is always the target of the pointed edge.
369 Node baseNode(const InEdgeIt&) const { return INVALID; }
371 /// \brief The running node of the iterator.
373 /// Gives back the running node of the iterator.
374 /// It is always the source of the pointed edge.
375 Node runningNode(const InEdgeIt&) const { return INVALID; }
377 /// \brief The base node of the iterator.
379 /// Gives back the base node of the iterator.
380 /// It is always the source of the pointed edge.
381 Node baseNode(const OutEdgeIt&) const { return INVALID; }
383 /// \brief The running node of the iterator.
385 /// Gives back the running node of the iterator.
386 /// It is always the target of the pointed edge.
387 Node runningNode(const OutEdgeIt&) const { return INVALID; }
389 /// \brief The opposite node on the given edge.
391 /// Gives back the opposite node on the given edge.
392 Node oppositeNode(const Node&, const Edge&) const { return INVALID; }
394 /// \brief Read write map of the nodes to type \c T.
396 /// ReadWrite map of the nodes to type \c T.
399 class NodeMap : public ReadWriteMap< Node, T > {
403 NodeMap(const Graph&) { }
405 NodeMap(const Graph&, T) { }
408 NodeMap(const NodeMap& nm) : ReadWriteMap< Node, T >(nm) { }
409 ///Assignment operator
410 template <typename CMap>
411 NodeMap& operator=(const CMap&) {
412 checkConcept<ReadMap<Node, T>, CMap>();
417 /// \brief Read write map of the edges to type \c T.
419 /// Reference map of the edges to type \c T.
422 class EdgeMap : public ReadWriteMap<Edge,T> {
426 EdgeMap(const Graph&) { }
428 EdgeMap(const Graph&, T) { }
430 EdgeMap(const EdgeMap& em) : ReadWriteMap<Edge,T>(em) { }
431 ///Assignment operator
432 template <typename CMap>
433 EdgeMap& operator=(const CMap&) {
434 checkConcept<ReadMap<Edge, T>, CMap>();
439 template <typename RGraph>
442 checkConcept<IterableGraphComponent<>, Graph>();
443 checkConcept<MappableGraphComponent<>, Graph>();
450 } //namespace concepts
455 #endif // LEMON_CONCEPT_GRAPH_H