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 StaticGraph 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 // \brief Modular extendable graph class.
61 // It should be the same as the \c ExtendableGraph class.
62 class _ExtendableGraph
63 : virtual public BaseGraphComponent, public _StaticGraph,
64 public ExtendableGraphComponent, public ClearableGraphComponent {
66 typedef BaseGraphComponent::Node Node;
67 typedef BaseGraphComponent::Edge Edge;
69 template <typename _Graph>
72 checkConcept<_StaticGraph, _Graph >();
73 checkConcept<ExtendableGraphComponent, _Graph >();
74 checkConcept<ClearableGraphComponent, _Graph >();
79 // \brief Modular erasable graph class.
81 // It should be the same as the \c ErasableGraph class.
83 : virtual public BaseGraphComponent, public _ExtendableGraph,
84 public ErasableGraphComponent {
86 typedef BaseGraphComponent::Node Node;
87 typedef BaseGraphComponent::Edge Edge;
89 template <typename _Graph>
92 checkConcept<_ExtendableGraph, _Graph >();
93 checkConcept<ErasableGraphComponent, _Graph >();
98 /// \addtogroup graph_concepts
101 /// An empty static graph class.
103 /// This class provides all the common features of a graph structure,
104 /// however completely without implementations and real data structures
105 /// behind the interface.
106 /// All graph algorithms should compile with this class, but it will not
107 /// run properly, of course.
109 /// It can be used for checking the interface compatibility,
110 /// or it can serve as a skeleton of a new graph structure.
112 /// Also, you will find here the full documentation of a certain graph
113 /// feature, the documentation of a real graph imlementation
114 /// like @ref ListGraph or
115 /// @ref SmartGraph will just refer to this structure.
117 /// \todo A pages describing the concept of concept description would
124 /// Defalult constructor.
126 /// Defalult constructor.
131 // ///\todo It is not clear, what we expect from a copy constructor.
132 // ///E.g. How to assign the nodes/edges to each other? What about maps?
133 // StaticGraph(const StaticGraph& g) { }
135 /// The base type of node iterators,
136 /// or in other words, the trivial node iterator.
138 /// This is the base type of each node iterator,
139 /// thus each kind of node iterator converts to this.
140 /// More precisely each kind of node iterator should be inherited
141 /// from the trivial node iterator.
144 /// Default constructor
146 /// @warning The default constructor sets the iterator
147 /// to an undefined value.
149 /// Copy constructor.
151 /// Copy constructor.
153 Node(const Node&) { }
155 /// Invalid constructor \& conversion.
157 /// This constructor initializes the iterator to be invalid.
158 /// \sa Invalid for more details.
160 /// Equality operator
162 /// Two iterators are equal if and only if they point to the
163 /// same object or both are invalid.
164 bool operator==(Node) const { return true; }
166 /// Inequality operator
168 /// \sa operator==(Node n)
170 bool operator!=(Node) const { return true; }
172 /// Artificial ordering operator.
174 /// To allow the use of graph descriptors as key type in std::map or
175 /// similar associative container we require this.
177 /// \note This operator only have to define some strict ordering of
178 /// the items; this order has nothing to do with the iteration
179 /// ordering of the items.
181 /// \bug This is a technical requirement. Do we really need this?
182 bool operator<(Node) const { return false; }
186 /// This iterator goes through each node.
188 /// This iterator goes through each node.
189 /// Its usage is quite simple, for example you can count the number
190 /// of nodes in graph \c g of type \c Graph like this:
193 /// for (Graph::NodeIt n(g); n!=INVALID; ++n) ++count;
195 class NodeIt : public Node {
197 /// Default constructor
199 /// @warning The default constructor sets the iterator
200 /// to an undefined value.
202 /// Copy constructor.
204 /// Copy constructor.
206 NodeIt(const NodeIt& n) : Node(n) { }
207 /// Invalid constructor \& conversion.
209 /// Initialize the iterator to be invalid.
210 /// \sa Invalid for more details.
212 /// Sets the iterator to the first node.
214 /// Sets the iterator to the first node of \c g.
216 NodeIt(const StaticGraph&) { }
217 /// Node -> NodeIt conversion.
219 /// Sets the iterator to the node of \c the graph pointed by
220 /// the trivial iterator.
221 /// This feature necessitates that each time we
222 /// iterate the edge-set, the iteration order is the same.
223 NodeIt(const StaticGraph&, const Node&) { }
226 /// Assign the iterator to the next node.
228 NodeIt& operator++() { return *this; }
232 /// The base type of the edge iterators.
234 /// The base type of the edge iterators.
238 /// Default constructor
240 /// @warning The default constructor sets the iterator
241 /// to an undefined value.
243 /// Copy constructor.
245 /// Copy constructor.
247 Edge(const Edge&) { }
248 /// Initialize the iterator to be invalid.
250 /// Initialize the iterator to be invalid.
253 /// Equality operator
255 /// Two iterators are equal if and only if they point to the
256 /// same object or both are invalid.
257 bool operator==(Edge) const { return true; }
258 /// Inequality operator
260 /// \sa operator==(Edge n)
262 bool operator!=(Edge) const { return true; }
264 /// Artificial ordering operator.
266 /// To allow the use of graph descriptors as key type in std::map or
267 /// similar associative container we require this.
269 /// \note This operator only have to define some strict ordering of
270 /// the items; this order has nothing to do with the iteration
271 /// ordering of the items.
273 /// \bug This is a technical requirement. Do we really need this?
274 bool operator<(Edge) const { return false; }
277 /// This iterator goes trough the outgoing edges of a node.
279 /// This iterator goes trough the \e outgoing edges of a certain node
281 /// Its usage is quite simple, for example you can count the number
282 /// of outgoing edges of a node \c n
283 /// in graph \c g of type \c Graph as follows.
286 /// for (Graph::OutEdgeIt e(g, n); e!=INVALID; ++e) ++count;
289 class OutEdgeIt : public Edge {
291 /// Default constructor
293 /// @warning The default constructor sets the iterator
294 /// to an undefined value.
296 /// Copy constructor.
298 /// Copy constructor.
300 OutEdgeIt(const OutEdgeIt& e) : Edge(e) { }
301 /// Initialize the iterator to be invalid.
303 /// Initialize the iterator to be invalid.
305 OutEdgeIt(Invalid) { }
306 /// This constructor sets the iterator to the first outgoing edge.
308 /// This constructor sets the iterator to the first outgoing edge of
310 OutEdgeIt(const StaticGraph&, const Node&) { }
311 /// Edge -> OutEdgeIt conversion
313 /// Sets the iterator to the value of the trivial iterator.
314 /// This feature necessitates that each time we
315 /// iterate the edge-set, the iteration order is the same.
316 OutEdgeIt(const StaticGraph&, const Edge&) { }
317 ///Next outgoing edge
319 /// Assign the iterator to the next
320 /// outgoing edge of the corresponding node.
321 OutEdgeIt& operator++() { return *this; }
324 /// This iterator goes trough the incoming edges of a node.
326 /// This iterator goes trough the \e incoming edges of a certain node
328 /// Its usage is quite simple, for example you can count the number
329 /// of outgoing edges of a node \c n
330 /// in graph \c g of type \c Graph as follows.
333 /// for(Graph::InEdgeIt e(g, n); e!=INVALID; ++e) ++count;
336 class InEdgeIt : public Edge {
338 /// Default constructor
340 /// @warning The default constructor sets the iterator
341 /// to an undefined value.
343 /// Copy constructor.
345 /// Copy constructor.
347 InEdgeIt(const InEdgeIt& e) : Edge(e) { }
348 /// Initialize the iterator to be invalid.
350 /// Initialize the iterator to be invalid.
352 InEdgeIt(Invalid) { }
353 /// This constructor sets the iterator to first incoming edge.
355 /// This constructor set the iterator to the first incoming edge of
357 InEdgeIt(const StaticGraph&, const Node&) { }
358 /// Edge -> InEdgeIt conversion
360 /// Sets the iterator to the value of the trivial iterator \c e.
361 /// This feature necessitates that each time we
362 /// iterate the edge-set, the iteration order is the same.
363 InEdgeIt(const StaticGraph&, const Edge&) { }
364 /// Next incoming edge
366 /// Assign the iterator to the next inedge of the corresponding node.
368 InEdgeIt& operator++() { return *this; }
370 /// This iterator goes through each edge.
372 /// This iterator goes through each edge of a graph.
373 /// Its usage is quite simple, for example you can count the number
374 /// of edges in a graph \c g of type \c Graph as follows:
377 /// for(Graph::EdgeIt e(g); e!=INVALID; ++e) ++count;
379 class EdgeIt : public Edge {
381 /// Default constructor
383 /// @warning The default constructor sets the iterator
384 /// to an undefined value.
386 /// Copy constructor.
388 /// Copy constructor.
390 EdgeIt(const EdgeIt& e) : Edge(e) { }
391 /// Initialize the iterator to be invalid.
393 /// Initialize the iterator to be invalid.
396 /// This constructor sets the iterator to the first edge.
398 /// This constructor sets the iterator to the first edge of \c g.
399 ///@param g the graph
400 EdgeIt(const StaticGraph& g) { ignore_unused_variable_warning(g); }
401 /// Edge -> EdgeIt conversion
403 /// Sets the iterator to the value of the trivial iterator \c e.
404 /// This feature necessitates that each time we
405 /// iterate the edge-set, the iteration order is the same.
406 EdgeIt(const StaticGraph&, const Edge&) { }
409 /// Assign the iterator to the next edge.
410 EdgeIt& operator++() { return *this; }
412 ///Gives back the target node of an edge.
414 ///Gives back the target node of an edge.
416 Node target(Edge) const { return INVALID; }
417 ///Gives back the source node of an edge.
419 ///Gives back the source node of an edge.
421 Node source(Edge) const { return INVALID; }
423 // /// Gives back the first Node in the iterating order.
425 // /// Gives back the first Node in the iterating order.
427 void first(Node&) const {}
429 // /// Gives back the next Node in the iterating order.
431 // /// Gives back the next Node in the iterating order.
433 void next(Node&) const {}
435 // /// Gives back the first Edge in the iterating order.
437 // /// Gives back the first Edge in the iterating order.
439 void first(Edge&) const {}
440 // /// Gives back the next Edge in the iterating order.
442 // /// Gives back the next Edge in the iterating order.
444 void next(Edge&) const {}
447 // /// Gives back the first of the Edges point to the given Node.
449 // /// Gives back the first of the Edges point to the given Node.
451 void firstIn(Edge&, const Node&) const {}
453 // /// Gives back the next of the Edges points to the given Node.
456 // /// Gives back the next of the Edges points to the given Node.
458 void nextIn(Edge&) const {}
460 // /// Gives back the first of the Edges start from the given Node.
462 // /// Gives back the first of the Edges start from the given Node.
464 void firstOut(Edge&, const Node&) const {}
466 // /// Gives back the next of the Edges start from the given Node.
468 // /// Gives back the next of the Edges start from the given Node.
470 void nextOut(Edge&) const {}
472 /// \brief The base node of the iterator.
474 /// Gives back the base node of the iterator.
475 /// It is always the target of the pointed edge.
476 Node baseNode(const InEdgeIt&) const { return INVALID; }
478 /// \brief The running node of the iterator.
480 /// Gives back the running node of the iterator.
481 /// It is always the source of the pointed edge.
482 Node runningNode(const InEdgeIt&) const { return INVALID; }
484 /// \brief The base node of the iterator.
486 /// Gives back the base node of the iterator.
487 /// It is always the source of the pointed edge.
488 Node baseNode(const OutEdgeIt&) const { return INVALID; }
490 /// \brief The running node of the iterator.
492 /// Gives back the running node of the iterator.
493 /// It is always the target of the pointed edge.
494 Node runningNode(const OutEdgeIt&) const { return INVALID; }
496 /// \brief The opposite node on the given edge.
498 /// Gives back the opposite node on the given edge.
499 Node oppositeNode(const Node&, const Edge&) const { return INVALID; }
501 /// \brief Read write map of the nodes to type \c T.
503 /// ReadWrite map of the nodes to type \c T.
505 /// \warning Making maps that can handle bool type (NodeMap<bool>)
506 /// needs some extra attention!
507 /// \todo Wrong documentation
509 class NodeMap : public ReadWriteMap< Node, T >
514 NodeMap(const StaticGraph&) { }
516 NodeMap(const StaticGraph&, T) { }
519 NodeMap(const NodeMap& nm) : ReadWriteMap< Node, T >(nm) { }
520 ///Assignment operator
521 NodeMap& operator=(const NodeMap&) { return *this; }
522 // \todo fix this concept
525 /// \brief Read write map of the edges to type \c T.
527 /// Reference map of the edges to type \c T.
529 /// \warning Making maps that can handle bool type (EdgeMap<bool>)
530 /// needs some extra attention!
531 /// \todo Wrong documentation
533 class EdgeMap : public ReadWriteMap<Edge,T>
538 EdgeMap(const StaticGraph&) { }
540 EdgeMap(const StaticGraph&, T) { }
542 EdgeMap(const EdgeMap& em) : ReadWriteMap<Edge,T>(em) { }
543 ///Assignment operator
544 EdgeMap& operator=(const EdgeMap&) { return *this; }
545 // \todo fix this concept
548 template <typename _Graph>
549 struct Constraints : public _StaticGraph::Constraints<_Graph> {};
553 /// An empty non-static graph class.
555 /// This class provides everything that \ref StaticGraph does.
556 /// Additionally it enables building graphs from scratch.
557 class ExtendableGraph : public StaticGraph
560 /// Defalult constructor.
562 /// Defalult constructor.
564 ExtendableGraph() { }
565 ///Add a new node to the graph.
567 /// \return the new node.
569 Node addNode() { return INVALID; }
570 ///Add a new edge to the graph.
572 ///Add a new edge to the graph with source node \c s
573 ///and target node \c t.
574 ///\return the new edge.
575 Edge addEdge(Node, Node) { return INVALID; }
577 /// Resets the graph.
579 /// This function deletes all edges and nodes of the graph.
580 /// It also frees the memory allocated to store them.
581 /// \todo It might belong to \ref ErasableGraph.
584 template <typename _Graph>
585 struct Constraints : public _ExtendableGraph::Constraints<_Graph> {};
589 /// An empty erasable graph class.
591 /// This class is an extension of \ref ExtendableGraph. It makes it
592 /// possible to erase edges or nodes.
593 class ErasableGraph : public ExtendableGraph
596 /// Defalult constructor.
598 /// Defalult constructor.
603 /// Deletes node \c n node.
608 /// Deletes edge \c e edge.
612 template <typename _Graph>
613 struct Constraints : public _ErasableGraph::Constraints<_Graph> {};
618 } //namespace concept
623 #endif // LEMON_CONCEPT_GRAPH_H