2 * src/lemon/concept/graph.h - Part of LEMON, a generic C++ optimization library
4 * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
5 * (Egervary Combinatorial Optimization Research Group, EGRES).
7 * Permission to use, modify and distribute this software is granted
8 * provided that this copyright notice appears in all copies. For
9 * precise terms see the accompanying LICENSE file.
11 * This software is provided "AS IS" with no warranty of any kind,
12 * express or implied, and with no claim as to its suitability for any
17 #ifndef LEMON_CONCEPT_GRAPH_H
18 #define LEMON_CONCEPT_GRAPH_H
20 ///\ingroup graph_concepts
22 ///\brief Declaration of Graph.
24 #include <lemon/invalid.h>
25 #include <lemon/concept/maps.h>
26 #include <lemon/concept_check.h>
27 #include <lemon/concept/graph_component.h>
32 /// \addtogroup graph_concepts
35 // /// An empty static graph class.
37 // /// This class provides all the common features of a graph structure,
38 // /// however completely without implementations and real data structures
39 // /// behind the interface.
40 // /// All graph algorithms should compile with this class, but it will not
41 // /// run properly, of course.
43 // /// It can be used for checking the interface compatibility,
44 // /// or it can serve as a skeleton of a new graph structure.
46 // /// Also, you will find here the full documentation of a certain graph
47 // /// feature, the documentation of a real graph imlementation
48 // /// like @ref ListGraph or
49 // /// @ref SmartGraph will just refer to this structure.
51 // /// \todo A pages describing the concept of concept description would
56 // /// Defalult constructor.
58 // /// Defalult constructor.
61 // ///Copy consructor.
63 // // ///\todo It is not clear, what we expect from a copy constructor.
64 // // ///E.g. How to assign the nodes/edges to each other? What about maps?
65 // // StaticGraph(const StaticGraph& g) { }
67 // /// The base type of node iterators,
68 // /// or in other words, the trivial node iterator.
70 // /// This is the base type of each node iterator,
71 // /// thus each kind of node iterator converts to this.
72 // /// More precisely each kind of node iterator should be inherited
73 // /// from the trivial node iterator.
76 // /// Default constructor
78 // /// @warning The default constructor sets the iterator
79 // /// to an undefined value.
81 // /// Copy constructor.
83 // /// Copy constructor.
85 // Node(const Node&) { }
87 // /// Invalid constructor \& conversion.
89 // /// This constructor initializes the iterator to be invalid.
90 // /// \sa Invalid for more details.
92 // /// Equality operator
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; }
106 // /// This iterator goes through each node.
108 // /// This iterator goes through each node.
109 // /// Its usage is quite simple, for example you can count the number
110 // /// of nodes in graph \c g of type \c Graph like this:
113 // /// for (Graph::NodeIt n(g); n!=INVALID ++n) ++count;
115 // class NodeIt : public Node {
117 // /// Default constructor
119 // /// @warning The default constructor sets the iterator
120 // /// to an undefined value.
122 // /// Copy constructor.
124 // /// Copy constructor.
126 // NodeIt(const NodeIt&) { }
127 // /// Invalid constructor \& conversion.
129 // /// Initialize the iterator to be invalid.
130 // /// \sa Invalid for more details.
131 // NodeIt(Invalid) { }
132 // /// Sets the iterator to the first node.
134 // /// Sets the iterator to the first node of \c g.
136 // NodeIt(const StaticGraph& g) { }
137 // /// Node -> NodeIt conversion.
139 // /// Sets the iterator to the node of \c g pointed by the trivial
141 // /// This feature necessitates that each time we
142 // /// iterate the edge-set, the iteration order is the same.
143 // NodeIt(const StaticGraph& g, const Node& n) { }
146 // /// Assign the iterator to the next node.
148 // NodeIt& operator++() { return *this; }
152 // /// The base type of the edge iterators.
154 // /// The base type of the edge iterators.
158 // /// Default constructor
160 // /// @warning The default constructor sets the iterator
161 // /// to an undefined value.
163 // /// Copy constructor.
165 // /// Copy constructor.
167 // Edge(const Edge&) { }
168 // /// Initialize the iterator to be invalid.
170 // /// Initialize the iterator to be invalid.
173 // /// Equality operator
175 // /// Two iterators are equal if and only if they point to the
176 // /// same object or both are invalid.
177 // bool operator==(Edge) const { return true; }
178 // /// Inequality operator
180 // /// \sa operator==(Node n)
182 // bool operator!=(Edge) const { return true; }
185 // /// This iterator goes trough the outgoing edges of a node.
187 // /// This iterator goes trough the \e outgoing edges of a certain node
189 // /// Its usage is quite simple, for example you can count the number
190 // /// of outgoing edges of a node \c n
191 // /// in graph \c g of type \c Graph as follows.
194 // /// for (Graph::OutEdgeIt e(g, n); e!=INVALID; ++e) ++count;
197 // class OutEdgeIt : public Edge {
199 // /// Default constructor
201 // /// @warning The default constructor sets the iterator
202 // /// to an undefined value.
204 // /// Copy constructor.
206 // /// Copy constructor.
208 // OutEdgeIt(const OutEdgeIt&) { }
209 // /// Initialize the iterator to be invalid.
211 // /// Initialize the iterator to be invalid.
213 // OutEdgeIt(Invalid) { }
214 // /// This constructor sets the iterator to first outgoing edge.
216 // /// This constructor set the iterator to the first outgoing edge of
218 // ///@param n the node
219 // ///@param g the graph
220 // OutEdgeIt(const StaticGraph& g, const Node& n) { }
221 // /// Edge -> OutEdgeIt conversion
223 // /// Sets the iterator to the value of the trivial iterator \c e.
224 // /// This feature necessitates that each time we
225 // /// iterate the edge-set, the iteration order is the same.
226 // OutEdgeIt(const StaticGraph& g, const Edge& e) { }
227 // ///Next outgoing edge
229 // /// Assign the iterator to the next
230 // /// outgoing edge of the corresponding node.
231 // OutEdgeIt& operator++() { return *this; }
234 // /// This iterator goes trough the incoming edges of a node.
236 // /// This iterator goes trough the \e incoming edges of a certain node
238 // /// Its usage is quite simple, for example you can count the number
239 // /// of outgoing edges of a node \c n
240 // /// in graph \c g of type \c Graph as follows.
243 // /// for(Graph::InEdgeIt e(g, n); e!=INVALID; ++e) ++count;
246 // class InEdgeIt : public Edge {
248 // /// Default constructor
250 // /// @warning The default constructor sets the iterator
251 // /// to an undefined value.
253 // /// Copy constructor.
255 // /// Copy constructor.
257 // InEdgeIt(const InEdgeIt&) { }
258 // /// Initialize the iterator to be invalid.
260 // /// Initialize the iterator to be invalid.
262 // InEdgeIt(Invalid) { }
263 // /// This constructor sets the iterator to first incoming edge.
265 // /// This constructor set the iterator to the first incoming edge of
267 // ///@param n the node
268 // ///@param g the graph
269 // InEdgeIt(const StaticGraph& g, const Node& n) { }
270 // /// Edge -> InEdgeIt conversion
272 // /// Sets the iterator to the value of the trivial iterator \c e.
273 // /// This feature necessitates that each time we
274 // /// iterate the edge-set, the iteration order is the same.
275 // InEdgeIt(const StaticGraph& g, const Edge& n) { }
276 // /// Next incoming edge
278 // /// Assign the iterator to the next inedge of the corresponding node.
280 // InEdgeIt& operator++() { return *this; }
282 // /// This iterator goes through each edge.
284 // /// This iterator goes through each edge of a graph.
285 // /// Its usage is quite simple, for example you can count the number
286 // /// of edges in a graph \c g of type \c Graph as follows:
289 // /// for(Graph::EdgeIt e(g); e!=INVALID; ++e) ++count;
291 // class EdgeIt : 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 // EdgeIt(const EdgeIt&) { }
303 // /// Initialize the iterator to be invalid.
305 // /// Initialize the iterator to be invalid.
307 // EdgeIt(Invalid) { }
308 // /// This constructor sets the iterator to first edge.
310 // /// This constructor set the iterator to the first edge of
312 // ///@param g the graph
313 // EdgeIt(const StaticGraph& g) { }
314 // /// Edge -> EdgeIt conversion
316 // /// Sets the iterator to the value of the trivial iterator \c e.
317 // /// This feature necessitates that each time we
318 // /// iterate the edge-set, the iteration order is the same.
319 // EdgeIt(const StaticGraph&, const Edge&) { }
322 // /// Assign the iterator to the next
323 // /// edge of the corresponding node.
324 // EdgeIt& operator++() { return *this; }
326 // ///Gives back the target node of an edge.
328 // ///Gives back the target node of an edge.
330 // Node target(Edge) const { return INVALID; }
331 // ///Gives back the source node of an edge.
333 // ///Gives back the source node of an edge.
335 // Node source(Edge) const { return INVALID; }
336 // /// Read write map of the nodes to type \c T.
338 // /// \ingroup concept
339 // /// ReadWrite map of the nodes to type \c T.
341 // /// \warning Making maps that can handle bool type (NodeMap<bool>)
342 // /// needs some extra attention!
344 // class NodeMap : public ReadWriteMap< Node, T >
349 // NodeMap(const StaticGraph&) { }
351 // NodeMap(const StaticGraph&, T) { }
353 // ///Copy constructor
354 // NodeMap(const NodeMap&) { }
355 // ///Assignment operator
356 // NodeMap& operator=(const NodeMap&) { return *this; }
357 // // \todo fix this concept
360 // /// Read write map of the edges to type \c T.
362 // /// \ingroup concept
363 // ///Reference map of the edges to type \c T.
365 // /// \warning Making maps that can handle bool type (EdgeMap<bool>)
366 // /// needs some extra attention!
368 // class EdgeMap : public ReadWriteMap<Edge,T>
373 // EdgeMap(const StaticGraph&) { }
375 // EdgeMap(const StaticGraph&, T) { }
376 // ///Copy constructor
377 // EdgeMap(const EdgeMap&) { }
378 // ///Assignment operator
379 // EdgeMap& operator=(const EdgeMap&) { return *this; }
380 // // \todo fix this concept
384 // /// An empty non-static graph class.
386 // /// This class provides everything that \ref StaticGraph
387 // /// with additional functionality which enables to build a
388 // /// graph from scratch.
389 // class ExtendableGraph : public StaticGraph
392 // /// Defalult constructor.
394 // /// Defalult constructor.
396 // ExtendableGraph() { }
397 // ///Add a new node to the graph.
399 // /// \return the new node.
401 // Node addNode() { return INVALID; }
402 // ///Add a new edge to the graph.
404 // ///Add a new edge to the graph with source node \c s
405 // ///and target node \c t.
406 // ///\return the new edge.
407 // Edge addEdge(Node s, Node t) { return INVALID; }
409 // /// Resets the graph.
411 // /// This function deletes all edges and nodes of the graph.
412 // /// It also frees the memory allocated to store them.
413 // /// \todo It might belong to \ref ErasableGraph.
417 // /// An empty erasable graph class.
419 // /// This class is an extension of \ref ExtendableGraph. It also makes it
420 // /// possible to erase edges or nodes.
421 // class ErasableGraph : public ExtendableGraph
424 // /// Defalult constructor.
426 // /// Defalult constructor.
428 // ErasableGraph() { }
429 // /// Deletes a node.
431 // /// Deletes node \c n node.
433 // void erase(Node n) { }
434 // /// Deletes an edge.
436 // /// Deletes edge \c e edge.
438 // void erase(Edge e) { }
442 /************* New GraphBase stuff **************/
445 /// A minimal GraphBase concept
447 /// This class describes a minimal concept which can be extended to a
448 /// full-featured graph with \ref GraphFactory.
454 /// \bug Should we demand that Node and Edge be subclasses of the
457 typedef GraphItem<'n'> Node;
458 typedef GraphItem<'e'> Edge;
460 // class Node : public BaseGraphItem<'n'> {};
461 // class Edge : public BaseGraphItem<'e'> {};
464 void firstNode(Node &n) const { }
465 void firstEdge(Edge &e) const { }
467 void firstOutEdge(Edge &e, Node) const { }
468 void firstInEdge(Edge &e, Node) const { }
470 void nextNode(Node &n) const { }
471 void nextEdge(Edge &e) const { }
474 // Question: isn't it reasonable if this methods have a Node
475 // parameter? Like this:
476 // Edge& nextOut(Edge &e, Node) const { return e; }
477 void nextOutEdge(Edge &e) const { }
478 void nextInEdge(Edge &e) const { }
480 Node target(Edge) const { return Node(); }
481 Node source(Edge) const { return Node(); }
484 // Do we need id, nodeNum, edgeNum and co. in this basic graphbase
490 // We need a special slimer concept which does not provide maps (it
491 // wouldn't be strictly slimer, cause for map-factory id() & friends
495 class NodeMap : public GraphMap<GraphBase, Node, T> {};
498 class EdgeMap : public GraphMap<GraphBase, Node, T> {};
504 /**************** The full-featured graph concepts ****************/
508 : virtual public BaseGraphComponent,
509 public IterableGraphComponent, public MappableGraphComponent {
511 typedef BaseGraphComponent::Node Node;
512 typedef BaseGraphComponent::Edge Edge;
514 template <typename _Graph>
517 checkConcept<IterableGraphComponent, _Graph>();
518 checkConcept<MappableGraphComponent, _Graph>();
523 class ExtendableGraph
524 : virtual public BaseGraphComponent, public StaticGraph,
525 public ExtendableGraphComponent, public ClearableGraphComponent {
527 typedef BaseGraphComponent::Node Node;
528 typedef BaseGraphComponent::Edge Edge;
530 template <typename _Graph>
533 checkConcept<StaticGraph, _Graph >();
534 checkConcept<ExtendableGraphComponent, _Graph >();
535 checkConcept<ClearableGraphComponent, _Graph >();
541 : virtual public BaseGraphComponent, public ExtendableGraph,
542 public ErasableGraphComponent {
544 typedef BaseGraphComponent::Node Node;
545 typedef BaseGraphComponent::Edge Edge;
547 template <typename _Graph>
550 checkConcept<ExtendableGraph, _Graph >();
551 checkConcept<ErasableGraphComponent, _Graph >();
557 } //namespace concept
562 #endif // LEMON_CONCEPT_GRAPH_H