some minor changes, docs, etc.
2 * src/lemon/concept/graph.h - Part of LEMON, a generic C++ optimization library
4 * Copyright (C) 2005 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_SYM_GRAPH_H
18 #define LEMON_CONCEPT_SYM_GRAPH_H
22 ///\brief Declaration of SymGraph.
24 #include <lemon/invalid.h>
25 #include <lemon/concept/graph.h>
26 #include <lemon/concept/maps.h>
31 /// \addtogroup concept
34 /// An empty static graph class.
36 /// This class provides all the common features of a symmetric
37 /// graph structure, however completely without implementations and
38 /// real data structures behind the interface.
39 /// All graph algorithms should compile with this class, but it will not
40 /// run properly, of course.
42 /// It can be used for checking the interface compatibility,
43 /// or it can serve as a skeleton of a new symmetric graph structure.
45 /// Also, you will find here the full documentation of a certain graph
46 /// feature, the documentation of a real symmetric graph imlementation
47 /// like @ref SymListGraph or
48 /// @ref lemon::SymSmartGraph will just refer to this structure.
52 /// Defalult constructor.
54 /// Defalult constructor.
59 // ///\todo It is not clear, what we expect from a copy constructor.
60 // ///E.g. How to assign the nodes/edges to each other? What about maps?
61 // StaticGraph(const StaticGraph& g) { }
63 /// The base type of node iterators,
64 /// or in other words, the trivial node iterator.
66 /// This is the base type of each node iterator,
67 /// thus each kind of node iterator converts to this.
68 /// More precisely each kind of node iterator should be inherited
69 /// from the trivial node iterator.
72 /// Default constructor
74 /// @warning The default constructor sets the iterator
75 /// to an undefined value.
83 /// Invalid constructor \& conversion.
85 /// This constructor initializes the iterator to be invalid.
86 /// \sa Invalid for more details.
90 /// Two iterators are equal if and only if they point to the
91 /// same object or both are invalid.
92 bool operator==(Node) const { return true; }
94 /// Inequality operator
96 /// \sa operator==(Node n)
98 bool operator!=(Node) const { return true; }
100 ///Comparison operator.
102 ///This is a strict ordering between the nodes.
104 ///This ordering can be different from the order in which NodeIt
105 ///goes through the nodes.
106 ///\todo Possibly we don't need it.
107 bool operator<(Node) const { return true; }
110 /// This iterator goes through each node.
112 /// This iterator goes through each node.
113 /// Its usage is quite simple, for example you can count the number
114 /// of nodes in graph \c g of type \c Graph like this:
117 /// for (Graph::NodeIt n(g); n!=INVALID; ++n) ++count;
119 class NodeIt : public Node {
121 /// Default constructor
123 /// @warning The default constructor sets the iterator
124 /// to an undefined value.
126 /// Copy constructor.
128 /// Copy constructor.
130 NodeIt(const NodeIt&) { }
131 /// Invalid constructor \& conversion.
133 /// Initialize the iterator to be invalid.
134 /// \sa Invalid for more details.
136 /// Sets the iterator to the first node.
138 /// Sets the iterator to the first node of \c g.
140 NodeIt(const StaticSymGraph& g) { }
141 /// Node -> NodeIt conversion.
143 /// Sets the iterator to the node of \c g pointed by the trivial
145 /// This feature necessitates that each time we
146 /// iterate the edge-set, the iteration order is the same.
147 NodeIt(const StaticSymGraph& g, const Node& n) { }
150 /// Assign the iterator to the next node.
152 NodeIt& operator++() { return *this; }
156 /// The base type of the symmetric edge iterators.
158 /// The base type of the symmetric edge iterators.
162 /// Default constructor
164 /// @warning The default constructor sets the iterator
165 /// to an undefined value.
167 /// Copy constructor.
169 /// Copy constructor.
171 SymEdge(const SymEdge&) { }
172 /// Initialize the iterator to be invalid.
174 /// Initialize the iterator to be invalid.
177 /// Equality operator
179 /// Two iterators are equal if and only if they point to the
180 /// same object or both are invalid.
181 bool operator==(SymEdge) const { return true; }
182 /// Inequality operator
184 /// \sa operator==(Node n)
186 bool operator!=(SymEdge) const { return true; }
187 ///Comparison operator.
189 ///This is a strict ordering between the nodes.
191 ///This ordering can be different from the order in which NodeIt
192 ///goes through the nodes.
193 ///\todo Possibly we don't need it.
194 bool operator<(SymEdge) const { return true; }
198 /// The base type of the edge iterators.
200 /// The base type of the edge iterators.
202 class Edge : public SymEdge {
204 /// Default constructor
206 /// @warning The default constructor sets the iterator
207 /// to an undefined value.
209 /// Copy constructor.
211 /// Copy constructor.
213 Edge(const Edge&) { }
214 /// Initialize the iterator to be invalid.
216 /// Initialize the iterator to be invalid.
219 /// Equality operator
221 /// Two iterators are equal if and only if they point to the
222 /// same object or both are invalid.
223 bool operator==(Edge) const { return true; }
224 /// Inequality operator
226 /// \sa operator==(Node n)
228 bool operator!=(Edge) const { return true; }
229 ///Comparison operator.
231 ///This is a strict ordering between the nodes.
233 ///This ordering can be different from the order in which NodeIt
234 ///goes through the nodes.
235 ///\todo Possibly we don't need it.
236 bool operator<(Edge) const { return true; }
239 /// This iterator goes trough the outgoing edges of a node.
241 /// This iterator goes trough the \e outgoing edges of a certain node
243 /// Its usage is quite simple, for example you can count the number
244 /// of outgoing edges of a node \c n
245 /// in graph \c g of type \c Graph as follows.
248 /// for (Graph::OutEdgeIt e(g, n); e!=INVALID; ++e) ++count;
251 class OutEdgeIt : public Edge {
253 /// Default constructor
255 /// @warning The default constructor sets the iterator
256 /// to an undefined value.
258 /// Copy constructor.
260 /// Copy constructor.
262 OutEdgeIt(const OutEdgeIt&) { }
263 /// Initialize the iterator to be invalid.
265 /// Initialize the iterator to be invalid.
267 OutEdgeIt(Invalid) { }
268 /// This constructor sets the iterator to first outgoing edge.
270 /// This constructor set the iterator to the first outgoing edge of
273 ///@param g the graph
274 OutEdgeIt(const StaticSymGraph& g, const Node& n) { }
275 /// Edge -> OutEdgeIt conversion
277 /// Sets the iterator to the value of the trivial iterator \c e.
278 /// This feature necessitates that each time we
279 /// iterate the edge-set, the iteration order is the same.
280 OutEdgeIt(const StaticSymGraph& g, const Edge& e) { }
281 ///Next outgoing edge
283 /// Assign the iterator to the next
284 /// outgoing edge of the corresponding node.
285 OutEdgeIt& operator++() { return *this; }
288 /// This iterator goes trough the incoming edges of a node.
290 /// This iterator goes trough the \e incoming edges of a certain node
292 /// Its usage is quite simple, for example you can count the number
293 /// of outgoing edges of a node \c n
294 /// in graph \c g of type \c Graph as follows.
297 /// for(Graph::InEdgeIt e(g, n); e!=INVALID; ++e) ++count;
300 class InEdgeIt : public Edge {
302 /// Default constructor
304 /// @warning The default constructor sets the iterator
305 /// to an undefined value.
307 /// Copy constructor.
309 /// Copy constructor.
311 InEdgeIt(const InEdgeIt&) { }
312 /// Initialize the iterator to be invalid.
314 /// Initialize the iterator to be invalid.
316 InEdgeIt(Invalid) { }
317 /// This constructor sets the iterator to first incoming edge.
319 /// This constructor set the iterator to the first incoming edge of
322 ///@param g the graph
323 InEdgeIt(const StaticSymGraph& g, const Node& n) { }
324 /// Edge -> InEdgeIt conversion
326 /// Sets the iterator to the value of the trivial iterator \c e.
327 /// This feature necessitates that each time we
328 /// iterate the edge-set, the iteration order is the same.
329 InEdgeIt(const StaticSymGraph& g, const Edge& n) { }
330 /// Next incoming edge
332 /// Assign the iterator to the next inedge of the corresponding node.
334 InEdgeIt& operator++() { return *this; }
336 /// This iterator goes through each symmetric edge.
338 /// This iterator goes through each symmetric edge of a graph.
339 /// Its usage is quite simple, for example you can count the number
340 /// of symmetric edges in a graph \c g of type \c Graph as follows:
343 /// for(Graph::SymEdgeIt e(g); e!=INVALID; ++e) ++count;
345 class SymEdgeIt : public SymEdge {
347 /// Default constructor
349 /// @warning The default constructor sets the iterator
350 /// to an undefined value.
352 /// Copy constructor.
354 /// Copy constructor.
356 SymEdgeIt(const SymEdgeIt&) { }
357 /// Initialize the iterator to be invalid.
359 /// Initialize the iterator to be invalid.
361 SymEdgeIt(Invalid) { }
362 /// This constructor sets the iterator to first edge.
364 /// This constructor set the iterator to the first edge of
366 ///@param g the graph
367 SymEdgeIt(const StaticSymGraph& g) { }
368 /// Edge -> EdgeIt conversion
370 /// Sets the iterator to the value of the trivial iterator \c e.
371 /// This feature necessitates that each time we
372 /// iterate the edge-set, the iteration order is the same.
373 SymEdgeIt(const StaticSymGraph&, const SymEdge&) { }
376 /// Assign the iterator to the next
377 /// edge of the corresponding node.
378 SymEdgeIt& operator++() { return *this; }
380 /// This iterator goes through each edge.
382 /// This iterator goes through each edge of a graph.
383 /// Its usage is quite simple, for example you can count the number
384 /// of edges in a graph \c g of type \c Graph as follows:
387 /// for(Graph::EdgeIt e(g); e!=INVALID; ++e) ++count;
389 class EdgeIt : public Edge {
391 /// Default constructor
393 /// @warning The default constructor sets the iterator
394 /// to an undefined value.
396 /// Copy constructor.
398 /// Copy constructor.
400 EdgeIt(const EdgeIt&) { }
401 /// Initialize the iterator to be invalid.
403 /// Initialize the iterator to be invalid.
406 /// This constructor sets the iterator to first edge.
408 /// This constructor set the iterator to the first edge of
410 ///@param g the graph
411 EdgeIt(const StaticSymGraph& g) { }
412 /// Edge -> EdgeIt conversion
414 /// Sets the iterator to the value of the trivial iterator \c e.
415 /// This feature necessitates that each time we
416 /// iterate the edge-set, the iteration order is the same.
417 EdgeIt(const StaticSymGraph&, const Edge&) { }
420 /// Assign the iterator to the next
421 /// edge of the corresponding node.
422 EdgeIt& operator++() { return *this; }
425 /// First node of the graph.
427 /// \retval i the first node.
428 /// \return the first node.
430 NodeIt& first(NodeIt& i) const { return i; }
432 /// The first incoming edge.
434 /// The first incoming edge.
436 InEdgeIt& first(InEdgeIt &i, Node) const { return i; }
437 /// The first outgoing edge.
439 /// The first outgoing edge.
441 OutEdgeIt& first(OutEdgeIt& i, Node) const { return i; }
442 /// The first edge of the Graph.
444 /// The first edge of the Graph.
446 EdgeIt& first(EdgeIt& i) const { return i; }
447 /// The first symmetric edge of the Graph.
449 /// The first symmetric edge of the Graph.
451 SymEdgeIt& first(SymEdgeIt& i) const { return i; }
453 ///Gives back the target node of an edge.
455 ///Gives back the target node of an edge.
457 Node target(Edge) const { return INVALID; }
458 ///Gives back the source node of an edge.
460 ///Gives back the source node of an edge.
462 Node source(Edge) const { return INVALID; }
464 ///Gives back the first node of an symmetric edge.
466 ///Gives back the first node of an symmetric edge.
468 Node target(SymEdge) const { return INVALID; }
469 ///Gives back the second node of an symmetric edge.
471 ///Gives back the second node of an symmetric edge.
473 Node source(SymEdge) const { return INVALID; }
474 ///Gives back the \e id of a node.
476 ///\warning Not all graph structures provide this feature.
478 ///\todo Should each graph provide \c id?
479 int id(const Node&) const { return 0; }
480 ///Gives back the \e id of an edge.
482 ///\warning Not all graph structures provide this feature.
484 ///\todo Should each graph provide \c id?
485 int id(const Edge&) const { return 0; }
487 ///\warning Not all graph structures provide this feature.
489 ///\todo Should each graph provide \c id?
490 int id(const SymEdge&) const { return 0; }
494 ///\todo Should it be in the concept?
496 int nodeNum() const { return 0; }
499 ///\todo Should it be in the concept?
501 int edgeNum() const { return 0; }
503 ///\todo Should it be in the concept?
505 int symEdgeNum() const { return 0; }
508 /// Gives back the forward directed edge of the symmetric edge.
509 Edge forward(SymEdge) const {return INVALID;}
511 /// Gives back the backward directed edge of the symmetric edge.
512 Edge backward(SymEdge) const {return INVALID;};
514 /// Gives back the opposite of the edge.
515 Edge opposite(Edge) const {return INVALID;}
517 ///Reference map of the nodes to type \c T.
519 ///Reference map of the nodes to type \c T.
521 /// \warning Making maps that can handle bool type (NodeMap<bool>)
522 /// needs some extra attention!
523 template<class T> class NodeMap : public ReferenceMap< Node, T >
528 NodeMap(const StaticSymGraph&) { }
530 NodeMap(const StaticSymGraph&, T) { }
533 template<typename TT> NodeMap(const NodeMap<TT>&) { }
534 ///Assignment operator
535 template<typename TT> NodeMap& operator=(const NodeMap<TT>&)
539 ///Reference map of the edges to type \c T.
542 ///Reference map of the edges to type \c T.
544 /// \warning Making maps that can handle bool type (EdgeMap<bool>)
545 /// needs some extra attention!
546 template<class T> class EdgeMap
547 : public ReferenceMap<Edge,T>
552 EdgeMap(const StaticSymGraph&) { }
554 EdgeMap(const StaticSymGraph&, T) { }
557 template<typename TT> EdgeMap(const EdgeMap<TT>&) { }
558 ///Assignment operator
559 template<typename TT> EdgeMap &operator=(const EdgeMap<TT>&)
563 ///Reference map of the edges to type \c T.
566 ///Reference map of the symmetric edges to type \c T.
568 /// \warning Making maps that can handle bool type (EdgeMap<bool>)
569 /// needs some extra attention!
570 template<class T> class SymEdgeMap
571 : public ReferenceMap<SymEdge,T>
576 SymEdgeMap(const StaticSymGraph&) { }
578 SymEdgeMap(const StaticSymGraph&, T) { }
581 template<typename TT> SymEdgeMap(const SymEdgeMap<TT>&) { }
582 ///Assignment operator
583 template<typename TT> SymEdgeMap &operator=(const SymEdgeMap<TT>&)
590 /// An empty non-static graph class.
592 /// This class provides everything that \ref StaticGraph
593 /// with additional functionality which enables to build a
594 /// graph from scratch.
595 class ExtendableSymGraph : public StaticSymGraph
598 /// Defalult constructor.
600 /// Defalult constructor.
602 ExtendableSymGraph() { }
603 ///Add a new node to the graph.
605 /// \return the new node.
607 Node addNode() { return INVALID; }
608 ///Add a new edge to the graph.
610 ///Add a new symmetric edge to the graph with source node \c t
611 ///and target node \c h.
612 ///\return the new edge.
613 SymEdge addEdge(Node h, Node t) { return INVALID; }
615 /// Resets the graph.
617 /// This function deletes all edges and nodes of the graph.
618 /// It also frees the memory allocated to store them.
619 /// \todo It might belong to \ref ErasableGraph.
623 /// An empty erasable graph class.
625 /// This class is an extension of \ref ExtendableGraph. It also makes it
626 /// possible to erase edges or nodes.
627 class ErasableSymGraph : public ExtendableSymGraph
630 /// Defalult constructor.
632 /// Defalult constructor.
634 ErasableSymGraph() { }
637 /// Deletes node \c n node.
639 void erase(Node n) { }
642 /// Deletes edge \c e edge.
644 void erase(SymEdge e) { }
648 } //namespace concept
653 #endif // LEMON_CONCEPT_GRAPH_H