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/invalid.h>
27 #include <lemon/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 StaticGraph class.
43 : virtual public BaseGraphComponent,
44 public IterableGraphComponent, public MappableGraphComponent {
49 typedef BaseGraphComponent::Node Node;
50 typedef BaseGraphComponent::Edge Edge;
52 template <typename _Graph>
55 checkConcept<IterableGraphComponent, _Graph>();
56 checkConcept<MappableGraphComponent, _Graph>();
61 // \brief Modular extendable graph class.
63 // It should be the same as the \c ExtendableGraph class.
64 class _ExtendableGraph
65 : virtual public BaseGraphComponent, public _StaticGraph,
66 public ExtendableGraphComponent, public ClearableGraphComponent {
68 typedef BaseGraphComponent::Node Node;
69 typedef BaseGraphComponent::Edge Edge;
71 template <typename _Graph>
74 checkConcept<_StaticGraph, _Graph >();
75 checkConcept<ExtendableGraphComponent, _Graph >();
76 checkConcept<ClearableGraphComponent, _Graph >();
81 // \brief Modular erasable graph class.
83 // It should be the same as the \c ErasableGraph class.
85 : virtual public BaseGraphComponent, public _ExtendableGraph,
86 public ErasableGraphComponent {
88 typedef BaseGraphComponent::Node Node;
89 typedef BaseGraphComponent::Edge Edge;
91 template <typename _Graph>
94 checkConcept<_ExtendableGraph, _Graph >();
95 checkConcept<ErasableGraphComponent, _Graph >();
100 /// \addtogroup graph_concepts
103 /// An empty static graph class.
105 /// This class provides all the common features of a graph structure,
106 /// however completely without implementations and real data structures
107 /// behind the interface.
108 /// All graph algorithms should compile with this class, but it will not
109 /// run properly, of course.
111 /// It can be used for checking the interface compatibility,
112 /// or it can serve as a skeleton of a new graph structure.
114 /// Also, you will find here the full documentation of a certain graph
115 /// feature, the documentation of a real graph imlementation
116 /// like @ref ListGraph or
117 /// @ref SmartGraph will just refer to this structure.
119 /// \todo A pages describing the concept of concept description would
126 ///\todo undocumented
130 /// Defalult constructor.
132 /// Defalult constructor.
137 // ///\todo It is not clear, what we expect from a copy constructor.
138 // ///E.g. How to assign the nodes/edges to each other? What about maps?
139 // StaticGraph(const StaticGraph& g) { }
141 /// The base type of node iterators,
142 /// or in other words, the trivial node iterator.
144 /// This is the base type of each node iterator,
145 /// thus each kind of node iterator converts to this.
146 /// More precisely each kind of node iterator should be inherited
147 /// from the trivial node iterator.
150 /// Default constructor
152 /// @warning The default constructor sets the iterator
153 /// to an undefined value.
155 /// Copy constructor.
157 /// Copy constructor.
159 Node(const Node&) { }
161 /// Invalid constructor \& conversion.
163 /// This constructor initializes the iterator to be invalid.
164 /// \sa Invalid for more details.
166 /// Equality operator
168 /// Two iterators are equal if and only if they point to the
169 /// same object or both are invalid.
170 bool operator==(Node) const { return true; }
172 /// Inequality operator
174 /// \sa operator==(Node n)
176 bool operator!=(Node) const { return true; }
178 /// Artificial ordering operator.
180 /// To allow the use of graph descriptors as key type in std::map or
181 /// similar associative container we require this.
183 /// \note This operator only have to define some strict ordering of
184 /// the items; this order has nothing to do with the iteration
185 /// ordering of the items.
187 /// \bug This is a technical requirement. Do we really need this?
188 bool operator<(Node) const { return false; }
192 /// This iterator goes through each node.
194 /// This iterator goes through each node.
195 /// Its usage is quite simple, for example you can count the number
196 /// of nodes in graph \c g of type \c Graph like this:
199 /// for (Graph::NodeIt n(g); n!=INVALID; ++n) ++count;
201 class NodeIt : public Node {
203 /// Default constructor
205 /// @warning The default constructor sets the iterator
206 /// to an undefined value.
208 /// Copy constructor.
210 /// Copy constructor.
212 NodeIt(const NodeIt& n) : Node(n) { }
213 /// Invalid constructor \& conversion.
215 /// Initialize the iterator to be invalid.
216 /// \sa Invalid for more details.
218 /// Sets the iterator to the first node.
220 /// Sets the iterator to the first node of \c g.
222 NodeIt(const StaticGraph&) { }
223 /// Node -> NodeIt conversion.
225 /// Sets the iterator to the node of \c the graph pointed by
226 /// the trivial iterator.
227 /// This feature necessitates that each time we
228 /// iterate the edge-set, the iteration order is the same.
229 NodeIt(const StaticGraph&, const Node&) { }
232 /// Assign the iterator to the next node.
234 NodeIt& operator++() { return *this; }
238 /// The base type of the edge iterators.
240 /// The base type of the edge iterators.
244 /// Default constructor
246 /// @warning The default constructor sets the iterator
247 /// to an undefined value.
249 /// Copy constructor.
251 /// Copy constructor.
253 Edge(const Edge&) { }
254 /// Initialize the iterator to be invalid.
256 /// Initialize the iterator to be invalid.
259 /// Equality operator
261 /// Two iterators are equal if and only if they point to the
262 /// same object or both are invalid.
263 bool operator==(Edge) const { return true; }
264 /// Inequality operator
266 /// \sa operator==(Edge n)
268 bool operator!=(Edge) const { return true; }
270 /// Artificial ordering operator.
272 /// To allow the use of graph descriptors as key type in std::map or
273 /// similar associative container we require this.
275 /// \note This operator only have to define some strict ordering of
276 /// the items; this order has nothing to do with the iteration
277 /// ordering of the items.
279 /// \bug This is a technical requirement. Do we really need this?
280 bool operator<(Edge) const { return false; }
283 /// This iterator goes trough the outgoing edges of a node.
285 /// This iterator goes trough the \e outgoing edges of a certain node
287 /// Its usage is quite simple, for example you can count the number
288 /// of outgoing edges of a node \c n
289 /// in graph \c g of type \c Graph as follows.
292 /// for (Graph::OutEdgeIt e(g, n); e!=INVALID; ++e) ++count;
295 class OutEdgeIt : 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 OutEdgeIt(const OutEdgeIt& e) : Edge(e) { }
307 /// Initialize the iterator to be invalid.
309 /// Initialize the iterator to be invalid.
311 OutEdgeIt(Invalid) { }
312 /// This constructor sets the iterator to the first outgoing edge.
314 /// This constructor sets the iterator to the first outgoing edge of
316 OutEdgeIt(const StaticGraph&, const Node&) { }
317 /// Edge -> OutEdgeIt conversion
319 /// Sets the iterator to the value of the trivial iterator.
320 /// This feature necessitates that each time we
321 /// iterate the edge-set, the iteration order is the same.
322 OutEdgeIt(const StaticGraph&, const Edge&) { }
323 ///Next outgoing edge
325 /// Assign the iterator to the next
326 /// outgoing edge of the corresponding node.
327 OutEdgeIt& operator++() { return *this; }
330 /// This iterator goes trough the incoming edges of a node.
332 /// This iterator goes trough the \e incoming edges of a certain node
334 /// Its usage is quite simple, for example you can count the number
335 /// of outgoing edges of a node \c n
336 /// in graph \c g of type \c Graph as follows.
339 /// for(Graph::InEdgeIt e(g, n); e!=INVALID; ++e) ++count;
342 class InEdgeIt : public Edge {
344 /// Default constructor
346 /// @warning The default constructor sets the iterator
347 /// to an undefined value.
349 /// Copy constructor.
351 /// Copy constructor.
353 InEdgeIt(const InEdgeIt& e) : Edge(e) { }
354 /// Initialize the iterator to be invalid.
356 /// Initialize the iterator to be invalid.
358 InEdgeIt(Invalid) { }
359 /// This constructor sets the iterator to first incoming edge.
361 /// This constructor set the iterator to the first incoming edge of
363 InEdgeIt(const StaticGraph&, const Node&) { }
364 /// Edge -> InEdgeIt conversion
366 /// Sets the iterator to the value of the trivial iterator \c e.
367 /// This feature necessitates that each time we
368 /// iterate the edge-set, the iteration order is the same.
369 InEdgeIt(const StaticGraph&, const Edge&) { }
370 /// Next incoming edge
372 /// Assign the iterator to the next inedge of the corresponding node.
374 InEdgeIt& operator++() { return *this; }
376 /// This iterator goes through each edge.
378 /// This iterator goes through each edge of a graph.
379 /// Its usage is quite simple, for example you can count the number
380 /// of edges in a graph \c g of type \c Graph as follows:
383 /// for(Graph::EdgeIt e(g); e!=INVALID; ++e) ++count;
385 class EdgeIt : public Edge {
387 /// Default constructor
389 /// @warning The default constructor sets the iterator
390 /// to an undefined value.
392 /// Copy constructor.
394 /// Copy constructor.
396 EdgeIt(const EdgeIt& e) : Edge(e) { }
397 /// Initialize the iterator to be invalid.
399 /// Initialize the iterator to be invalid.
402 /// This constructor sets the iterator to the first edge.
404 /// This constructor sets the iterator to the first edge of \c g.
405 ///@param g the graph
406 EdgeIt(const StaticGraph& g) { ignore_unused_variable_warning(g); }
407 /// Edge -> EdgeIt conversion
409 /// Sets the iterator to the value of the trivial iterator \c e.
410 /// This feature necessitates that each time we
411 /// iterate the edge-set, the iteration order is the same.
412 EdgeIt(const StaticGraph&, const Edge&) { }
415 /// Assign the iterator to the next edge.
416 EdgeIt& operator++() { return *this; }
418 ///Gives back the target node of an edge.
420 ///Gives back the target node of an edge.
422 Node target(Edge) const { return INVALID; }
423 ///Gives back the source node of an edge.
425 ///Gives back the source node of an edge.
427 Node source(Edge) const { return INVALID; }
429 // /// Gives back the first Node in the iterating order.
431 // /// Gives back the first Node in the iterating order.
433 void first(Node&) const {}
435 // /// Gives back the next Node in the iterating order.
437 // /// Gives back the next Node in the iterating order.
439 void next(Node&) const {}
441 // /// Gives back the first Edge in the iterating order.
443 // /// Gives back the first Edge in the iterating order.
445 void first(Edge&) const {}
446 // /// Gives back the next Edge in the iterating order.
448 // /// Gives back the next Edge in the iterating order.
450 void next(Edge&) const {}
453 // /// Gives back the first of the Edges point to the given Node.
455 // /// Gives back the first of the Edges point to the given Node.
457 void firstIn(Edge&, const Node&) const {}
459 // /// Gives back the next of the Edges points to the given Node.
462 // /// Gives back the next of the Edges points to the given Node.
464 void nextIn(Edge&) const {}
466 // /// Gives back the first of the Edges start from the given Node.
468 // /// Gives back the first of the Edges start from the given Node.
470 void firstOut(Edge&, const Node&) const {}
472 // /// Gives back the next of the Edges start from the given Node.
474 // /// Gives back the next of the Edges start from the given Node.
476 void nextOut(Edge&) const {}
478 /// \brief The base node of the iterator.
480 /// Gives back the base node of the iterator.
481 /// It is always the target of the pointed edge.
482 Node baseNode(const InEdgeIt&) const { return INVALID; }
484 /// \brief The running node of the iterator.
486 /// Gives back the running node of the iterator.
487 /// It is always the source of the pointed edge.
488 Node runningNode(const InEdgeIt&) const { return INVALID; }
490 /// \brief The base node of the iterator.
492 /// Gives back the base node of the iterator.
493 /// It is always the source of the pointed edge.
494 Node baseNode(const OutEdgeIt&) const { return INVALID; }
496 /// \brief The running node of the iterator.
498 /// Gives back the running node of the iterator.
499 /// It is always the target of the pointed edge.
500 Node runningNode(const OutEdgeIt&) const { return INVALID; }
502 /// \brief The opposite node on the given edge.
504 /// Gives back the opposite node on the given edge.
505 Node oppositeNode(const Node&, const Edge&) const { return INVALID; }
507 /// \brief Read write map of the nodes to type \c T.
509 /// ReadWrite map of the nodes to type \c T.
511 /// \warning Making maps that can handle bool type (NodeMap<bool>)
512 /// needs some extra attention!
513 /// \todo Wrong documentation
515 class NodeMap : public ReadWriteMap< Node, T >
520 NodeMap(const StaticGraph&) { }
522 NodeMap(const StaticGraph&, T) { }
525 NodeMap(const NodeMap& nm) : ReadWriteMap< Node, T >(nm) { }
526 ///Assignment operator
527 NodeMap& operator=(const NodeMap&) { return *this; }
528 // \todo fix this concept
531 /// \brief Read write map of the edges to type \c T.
533 /// Reference map of the edges to type \c T.
535 /// \warning Making maps that can handle bool type (EdgeMap<bool>)
536 /// needs some extra attention!
537 /// \todo Wrong documentation
539 class EdgeMap : public ReadWriteMap<Edge,T>
544 EdgeMap(const StaticGraph&) { }
546 EdgeMap(const StaticGraph&, T) { }
548 EdgeMap(const EdgeMap& em) : ReadWriteMap<Edge,T>(em) { }
549 ///Assignment operator
550 EdgeMap& operator=(const EdgeMap&) { return *this; }
551 // \todo fix this concept
554 template <typename _Graph>
555 struct Constraints : public _StaticGraph::Constraints<_Graph> {};
559 /// An empty non-static graph class.
561 /// This class provides everything that \ref StaticGraph does.
562 /// Additionally it enables building graphs from scratch.
563 class ExtendableGraph : public StaticGraph
566 /// Defalult constructor.
568 /// Defalult constructor.
570 ExtendableGraph() { }
571 ///Add a new node to the graph.
573 /// \return the new node.
575 Node addNode() { return INVALID; }
576 ///Add a new edge to the graph.
578 ///Add a new edge to the graph with source node \c s
579 ///and target node \c t.
580 ///\return the new edge.
581 Edge addEdge(Node, Node) { return INVALID; }
583 /// Resets the graph.
585 /// This function deletes all edges and nodes of the graph.
586 /// It also frees the memory allocated to store them.
587 /// \todo It might belong to \ref ErasableGraph.
590 template <typename _Graph>
591 struct Constraints : public _ExtendableGraph::Constraints<_Graph> {};
595 /// An empty erasable graph class.
597 /// This class is an extension of \ref ExtendableGraph. It makes it
598 /// possible to erase edges or nodes.
599 class ErasableGraph : public ExtendableGraph
602 /// Defalult constructor.
604 /// Defalult constructor.
609 /// Deletes node \c n node.
614 /// Deletes edge \c e edge.
618 template <typename _Graph>
619 struct Constraints : public _ErasableGraph::Constraints<_Graph> {};
624 } //namespace concept
629 #endif // LEMON_CONCEPT_GRAPH_H