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_component.h>
36 /**************** The full-featured graph concepts ****************/
39 // \brief Modular static graph class.
41 // It should be the same as the \c Graph class.
43 : virtual public BaseGraphComponent,
44 public IterableGraphComponent, public MappableGraphComponent {
47 typedef BaseGraphComponent::Node Node;
48 typedef BaseGraphComponent::Edge Edge;
50 template <typename _Graph>
53 checkConcept<IterableGraphComponent, _Graph>();
54 checkConcept<MappableGraphComponent, _Graph>();
59 /// \addtogroup graph_concepts
62 /// An empty graph class.
64 /// This class provides all the common features of a graph structure,
65 /// however completely without implementations and real data structures
66 /// behind the interface.
67 /// All graph algorithms should compile with this class, but it will not
68 /// run properly, of course.
70 /// It can be used for checking the interface compatibility,
71 /// or it can serve as a skeleton of a new graph structure.
73 /// Also, you will find here the full documentation of a certain graph
74 /// feature, the documentation of a real graph imlementation
75 /// like @ref ListGraph or
76 /// @ref SmartGraph will just refer to this structure.
78 /// \todo A pages describing the concept of concept description would
84 /// Defalult constructor.
86 /// Defalult constructor.
90 /// The base type of node iterators,
91 /// or in other words, the trivial node iterator.
93 /// This is the base type of each node iterator,
94 /// thus each kind of node iterator converts to this.
95 /// More precisely each kind of node iterator should be inherited
96 /// from the trivial node iterator.
99 /// Default constructor
101 /// @warning The default constructor sets the iterator
102 /// to an undefined value.
104 /// Copy constructor.
106 /// Copy constructor.
108 Node(const Node&) { }
110 /// Invalid constructor \& conversion.
112 /// This constructor initializes the iterator to be invalid.
113 /// \sa Invalid for more details.
115 /// Equality operator
117 /// Two iterators are equal if and only if they point to the
118 /// same object or both are invalid.
119 bool operator==(Node) const { return true; }
121 /// Inequality operator
123 /// \sa operator==(Node n)
125 bool operator!=(Node) const { return true; }
127 /// Artificial ordering operator.
129 /// To allow the use of graph descriptors as key type in std::map or
130 /// similar associative container we require this.
132 /// \note This operator only have to define some strict ordering of
133 /// the items; this order has nothing to do with the iteration
134 /// ordering of the items.
136 /// \bug This is a technical requirement. Do we really need this?
137 bool operator<(Node) const { return false; }
141 /// This iterator goes through each node.
143 /// This iterator goes through each node.
144 /// Its usage is quite simple, for example you can count the number
145 /// of nodes in graph \c g of type \c Graph like this:
148 /// for (Graph::NodeIt n(g); n!=INVALID; ++n) ++count;
150 class NodeIt : public Node {
152 /// Default constructor
154 /// @warning The default constructor sets the iterator
155 /// to an undefined value.
157 /// Copy constructor.
159 /// Copy constructor.
161 NodeIt(const NodeIt& n) : Node(n) { }
162 /// Invalid constructor \& conversion.
164 /// Initialize the iterator to be invalid.
165 /// \sa Invalid for more details.
167 /// Sets the iterator to the first node.
169 /// Sets the iterator to the first node of \c g.
171 NodeIt(const Graph&) { }
172 /// Node -> NodeIt conversion.
174 /// Sets the iterator to the node of \c the graph pointed by
175 /// the trivial iterator.
176 /// This feature necessitates that each time we
177 /// iterate the edge-set, the iteration order is the same.
178 NodeIt(const Graph&, const Node&) { }
181 /// Assign the iterator to the next node.
183 NodeIt& operator++() { return *this; }
187 /// The base type of the edge iterators.
189 /// The base type of the edge iterators.
193 /// Default constructor
195 /// @warning The default constructor sets the iterator
196 /// to an undefined value.
198 /// Copy constructor.
200 /// Copy constructor.
202 Edge(const Edge&) { }
203 /// Initialize the iterator to be invalid.
205 /// Initialize the iterator to be invalid.
208 /// Equality operator
210 /// Two iterators are equal if and only if they point to the
211 /// same object or both are invalid.
212 bool operator==(Edge) const { return true; }
213 /// Inequality operator
215 /// \sa operator==(Edge n)
217 bool operator!=(Edge) const { return true; }
219 /// Artificial ordering operator.
221 /// To allow the use of graph descriptors as key type in std::map or
222 /// similar associative container we require this.
224 /// \note This operator only have to define some strict ordering of
225 /// the items; this order has nothing to do with the iteration
226 /// ordering of the items.
228 /// \bug This is a technical requirement. Do we really need this?
229 bool operator<(Edge) const { return false; }
232 /// This iterator goes trough the outgoing edges of a node.
234 /// This iterator goes trough the \e outgoing edges of a certain node
236 /// Its usage is quite simple, for example you can count the number
237 /// of outgoing edges of a node \c n
238 /// in graph \c g of type \c Graph as follows.
241 /// for (Graph::OutEdgeIt e(g, n); e!=INVALID; ++e) ++count;
244 class OutEdgeIt : public Edge {
246 /// Default constructor
248 /// @warning The default constructor sets the iterator
249 /// to an undefined value.
251 /// Copy constructor.
253 /// Copy constructor.
255 OutEdgeIt(const OutEdgeIt& e) : Edge(e) { }
256 /// Initialize the iterator to be invalid.
258 /// Initialize the iterator to be invalid.
260 OutEdgeIt(Invalid) { }
261 /// This constructor sets the iterator to the first outgoing edge.
263 /// This constructor sets the iterator to the first outgoing edge of
265 OutEdgeIt(const Graph&, const Node&) { }
266 /// Edge -> OutEdgeIt conversion
268 /// Sets the iterator to the value of the trivial iterator.
269 /// This feature necessitates that each time we
270 /// iterate the edge-set, the iteration order is the same.
271 OutEdgeIt(const Graph&, const Edge&) { }
272 ///Next outgoing edge
274 /// Assign the iterator to the next
275 /// outgoing edge of the corresponding node.
276 OutEdgeIt& operator++() { return *this; }
279 /// This iterator goes trough the incoming edges of a node.
281 /// This iterator goes trough the \e incoming edges of a certain node
283 /// Its usage is quite simple, for example you can count the number
284 /// of outgoing edges of a node \c n
285 /// in graph \c g of type \c Graph as follows.
288 /// for(Graph::InEdgeIt e(g, n); e!=INVALID; ++e) ++count;
291 class InEdgeIt : public Edge {
293 /// Default constructor
295 /// @warning The default constructor sets the iterator
296 /// to an undefined value.
298 /// Copy constructor.
300 /// Copy constructor.
302 InEdgeIt(const InEdgeIt& e) : Edge(e) { }
303 /// Initialize the iterator to be invalid.
305 /// Initialize the iterator to be invalid.
307 InEdgeIt(Invalid) { }
308 /// This constructor sets the iterator to first incoming edge.
310 /// This constructor set the iterator to the first incoming edge of
312 InEdgeIt(const Graph&, const Node&) { }
313 /// Edge -> InEdgeIt conversion
315 /// Sets the iterator to the value of the trivial iterator \c e.
316 /// This feature necessitates that each time we
317 /// iterate the edge-set, the iteration order is the same.
318 InEdgeIt(const Graph&, const Edge&) { }
319 /// Next incoming edge
321 /// Assign the iterator to the next inedge of the corresponding node.
323 InEdgeIt& operator++() { return *this; }
325 /// This iterator goes through each edge.
327 /// This iterator goes through each edge of a graph.
328 /// Its usage is quite simple, for example you can count the number
329 /// of edges in a graph \c g of type \c Graph as follows:
332 /// for(Graph::EdgeIt e(g); e!=INVALID; ++e) ++count;
334 class EdgeIt : public Edge {
336 /// Default constructor
338 /// @warning The default constructor sets the iterator
339 /// to an undefined value.
341 /// Copy constructor.
343 /// Copy constructor.
345 EdgeIt(const EdgeIt& e) : Edge(e) { }
346 /// Initialize the iterator to be invalid.
348 /// Initialize the iterator to be invalid.
351 /// This constructor sets the iterator to the first edge.
353 /// This constructor sets the iterator to the first edge of \c g.
354 ///@param g the graph
355 EdgeIt(const Graph& g) { ignore_unused_variable_warning(g); }
356 /// Edge -> EdgeIt conversion
358 /// Sets the iterator to the value of the trivial iterator \c e.
359 /// This feature necessitates that each time we
360 /// iterate the edge-set, the iteration order is the same.
361 EdgeIt(const Graph&, const Edge&) { }
364 /// Assign the iterator to the next edge.
365 EdgeIt& operator++() { return *this; }
367 ///Gives back the target node of an edge.
369 ///Gives back the target node of an edge.
371 Node target(Edge) const { return INVALID; }
372 ///Gives back the source node of an edge.
374 ///Gives back the source node of an edge.
376 Node source(Edge) const { return INVALID; }
378 void first(Node&) const {}
379 void next(Node&) const {}
381 void first(Edge&) const {}
382 void next(Edge&) const {}
385 void firstIn(Edge&, const Node&) const {}
386 void nextIn(Edge&) const {}
388 void firstOut(Edge&, const Node&) const {}
389 void nextOut(Edge&) const {}
391 /// \brief The base node of the iterator.
393 /// Gives back the base node of the iterator.
394 /// It is always the target of the pointed edge.
395 Node baseNode(const InEdgeIt&) const { return INVALID; }
397 /// \brief The running node of the iterator.
399 /// Gives back the running node of the iterator.
400 /// It is always the source of the pointed edge.
401 Node runningNode(const InEdgeIt&) const { return INVALID; }
403 /// \brief The base node of the iterator.
405 /// Gives back the base node of the iterator.
406 /// It is always the source of the pointed edge.
407 Node baseNode(const OutEdgeIt&) const { return INVALID; }
409 /// \brief The running node of the iterator.
411 /// Gives back the running node of the iterator.
412 /// It is always the target of the pointed edge.
413 Node runningNode(const OutEdgeIt&) const { return INVALID; }
415 /// \brief The opposite node on the given edge.
417 /// Gives back the opposite node on the given edge.
418 Node oppositeNode(const Node&, const Edge&) const { return INVALID; }
420 /// \brief Read write map of the nodes to type \c T.
422 /// ReadWrite map of the nodes to type \c T.
424 /// \warning Making maps that can handle bool type (NodeMap<bool>)
425 /// needs some extra attention!
426 /// \todo Wrong documentation
428 class NodeMap : public ReadWriteMap< Node, T >
433 NodeMap(const Graph&) { }
435 NodeMap(const Graph&, T) { }
438 NodeMap(const NodeMap& nm) : ReadWriteMap< Node, T >(nm) { }
439 ///Assignment operator
440 NodeMap& operator=(const NodeMap&) { return *this; }
441 // \todo fix this concept
444 /// \brief Read write map of the edges to type \c T.
446 /// Reference map of the edges to type \c T.
448 /// \warning Making maps that can handle bool type (EdgeMap<bool>)
449 /// needs some extra attention!
450 /// \todo Wrong documentation
452 class EdgeMap : public ReadWriteMap<Edge,T>
457 EdgeMap(const Graph&) { }
459 EdgeMap(const Graph&, T) { }
461 EdgeMap(const EdgeMap& em) : ReadWriteMap<Edge,T>(em) { }
462 ///Assignment operator
463 EdgeMap& operator=(const EdgeMap&) { return *this; }
464 // \todo fix this concept
467 template <typename RGraph>
468 struct Constraints : public _Graph::Constraints<RGraph> {};
473 } //namespace concept
478 #endif // LEMON_CONCEPT_GRAPH_H