Docs.
2 #ifndef HUGO_LEDA_GRAPH_WRAPPER_H
3 #define HUGO_LEDA_GRAPH_WRAPPER_H
5 #include <LEDA/graph.h>
6 #include <LEDA/node_array.h>
7 #include <LEDA/edge_array.h>
8 #include <LEDA/node_map.h>
9 #include <LEDA/edge_map.h>
10 //#include <LEDA/graph_alg.h>
11 //#include <LEDA/dimacs.h>
13 //#if defined(LEDA_NAMESPACE)
14 //using namespace leda;
19 /// The namespace of HugoLib
22 // @defgroup empty_graph The LedaGraphWrapper class
25 /// A graph wrapperstructure for wrapping LEDA graphs in HUGO.
27 /// This graph wrapper class wraps LEDA graph and LEDA parametrized graph
28 /// and then the generic algorithms and wrappers of HUGO can be used
30 /// This class provides all the common features of a grapf structure,
31 /// however completely without implementations or real data structures
32 /// behind the interface.
33 /// All graph algorithms should compile with this class, but it will not
34 /// run properly, of course.
36 /// It can be used for checking the interface compatibility,
37 /// or it can serve as a skeleton of a new graph structure.
39 /// Also, you will find here the full documentation of a certain graph
40 /// feature, the documentation of a real graph imlementation
41 /// like @ref ListGraph or
42 /// @ref SmartGraph will just refer to this structure.
43 template<typename Graph>
44 class LedaGraphWrapper
49 //LedaGraphWrapper() { }
50 LedaGraphWrapper(Graph& __graph) : _graph(&__graph) { }
51 LedaGraphWrapper(const LedaGraphWrapper &G) : _graph(G._graph) { }
53 template <typename T> class NodeMap;
54 template <typename T> class EdgeMap;
56 /// The base type of the node iterators.
58 friend class LedaGraphWrapper;
61 friend class InEdgeIt;
62 friend class OutEdgeIt;
64 template <typename T> friend class NodeMap;
67 Node(leda_node __n) : _n(__n) { }
69 /// @warning The default constructor sets the iterator
70 /// to an undefined value.
72 /// Initialize the iterator to be invalid
73 Node(Invalid) : _n(0) { }
74 //Node(const Node &) {}
75 bool operator==(Node n) const { return _n==n._n; } //FIXME
76 bool operator!=(Node n) const { return _n!=n._n; } //FIXME
77 operator leda_node () { return _n; }
80 /// This iterator goes through each node.
81 class NodeIt : public Node {
83 /// @warning The default constructor sets the iterator
84 /// to an undefined value.
86 /// Initialize the iterator to be invalid
87 NodeIt(Invalid i) : Node(i) {}
88 /// Sets the iterator to the first node of \c G.
89 NodeIt(const LedaGraphWrapper &G) : Node(G._graph->first_node()) { }
90 //NodeIt(const NodeIt &) {} //FIXME
93 /// The base type of the edge iterators.
95 friend class LedaGraphWrapper;
97 template <typename T> friend class EdgeMap;
100 Edge(leda_edge __e) : _e(__e) { }
102 /// @warning The default constructor sets the iterator
103 /// to an undefined value.
105 /// Initialize the iterator to be invalid
106 Edge(Invalid) : _e(0) {}
107 //Edge(const Edge &) {}
108 bool operator==(Edge e) const { return _e==e._e; } //FIXME
109 bool operator!=(Edge e) const { return _e!=e._e; } //FIXME
110 operator leda_edge () { return _e; }
113 /// This iterator goes trought the outgoing edges of a certain graph.
115 class OutEdgeIt : public Edge {
117 /// @warning The default constructor sets the iterator
118 /// to an undefined value.
120 /// Initialize the iterator to be invalid
121 OutEdgeIt(Invalid i) : Edge(i) {}
122 /// This constructor sets the iterator to first outgoing edge.
124 /// This constructor set the iterator to the first outgoing edge of
127 ///@param G the graph
128 OutEdgeIt(const LedaGraphWrapper & G, Node n) : Edge(G._graph->first_adj_edge(n._n)) { }
131 class InEdgeIt : public Edge {
133 /// @warning The default constructor sets the iterator
134 /// to an undefined value.
136 /// Initialize the iterator to be invalid
137 InEdgeIt(Invalid i) : Edge(i) {}
138 InEdgeIt(const LedaGraphWrapper & G, Node n) : Edge(G._graph->first_in_edge(n._n)) { }
141 // class SymEdgeIt : public Edge {};
142 class EdgeIt : public Edge {
144 /// @warning The default constructor sets the iterator
145 /// to an undefined value.
147 /// Initialize the iterator to be invalid
148 EdgeIt(Invalid i) : Edge(i) {}
149 EdgeIt(const LedaGraphWrapper & G) : Edge(G._graph->first_edge()) { }
152 /// First node of the graph.
154 /// \post \c i and the return value will be the first node.
156 NodeIt &first(NodeIt &i) const { i=NodeIt(*this); return i; }
158 /// The first outgoing edge.
159 InEdgeIt &first(InEdgeIt &i, Node n) const {
160 i=InEdgeIt(*this, n);
163 /// The first incoming edge.
164 OutEdgeIt &first(OutEdgeIt &i, Node n) const {
165 i=OutEdgeIt(*this, n);
168 // SymEdgeIt &first(SymEdgeIt &, Node) const { return i;}
169 /// The first edge of the Graph.
170 EdgeIt &first(EdgeIt &i) const {
174 // Node getNext(Node) const {}
175 // InEdgeIt getNext(InEdgeIt) const {}
176 // OutEdgeIt getNext(OutEdgeIt) const {}
177 // //SymEdgeIt getNext(SymEdgeIt) const {}
178 // EdgeIt getNext(EdgeIt) const {}
180 /// Go to the next node.
181 NodeIt &next(NodeIt &i) const {
182 i._n=_graph->succ_node(i._n);
185 /// Go to the next incoming edge.
186 InEdgeIt &next(InEdgeIt &i) const {
187 i._e=_graph->in_succ(i._e);
190 /// Go to the next outgoing edge.
191 OutEdgeIt &next(OutEdgeIt &i) const {
192 i._e=_graph->adj_succ(i._e);
195 //SymEdgeIt &next(SymEdgeIt &) const {}
196 /// Go to the next edge.
197 EdgeIt &next(EdgeIt &i) const {
198 i._e=_graph->succ_edge(i._e);
202 // template< typename It >
203 // It first() const {
209 // template< typename It >
210 // It first(Node v) const {
216 ///Gives back the head node of an edge.
217 Node head(Edge e) const {
218 return Node(_graph->target(e._e));
220 ///Gives back the tail node of an edge.
221 Node tail(Edge e) const {
222 return Node(_graph->source(e._e));
225 Node aNode(InEdgeIt e) const { return head(e); }
226 Node aNode(OutEdgeIt e) const { return tail(e); }
227 // Node aNode(SymEdgeIt) const {}
229 Node bNode(InEdgeIt e) const { return tail(e); }
230 Node bNode(OutEdgeIt e) const { return head(e); }
231 // Node bNode(SymEdgeIt) const {}
233 /// Checks if a node iterator is valid
234 bool valid(Node n) const { return n._n; }
235 /// Checks if an edge iterator is valid
236 bool valid(Edge e) const { return e._e; }
238 ///Gives back the \e id of a node.
239 int id(Node n) const { return n._n->id(); }
240 ///Gives back the \e id of an edge.
241 int id(Edge e) const { return e._e->id(); }
243 //void setInvalid(Node &) const {};
244 //void setInvalid(Edge &) const {};
246 Node addNode() const { return Node(_graph->new_node()); }
247 Edge addEdge(Node tail, Node head) const {
248 return Edge(_graph->new_edge(tail._n, head._n));
251 void erase(Node n) const { _graph->del_node(n._n); }
252 void erase(Edge e) const { _graph->del_edge(e._e); }
254 void clear() const { _graph->clear(); }
256 int nodeNum() const { return _graph->number_of_nodes(); }
257 int edgeNum() const { return _graph->number_of_edges(); }
259 ///Read/write map from the nodes to type \c T.
260 template<typename T> class NodeMap
262 leda_node_map<T> leda_stuff;
265 typedef Node KeyType;
267 NodeMap(const LedaGraphWrapper &G) : leda_stuff(*(G._graph)) {}
268 NodeMap(const LedaGraphWrapper &G, T t) : leda_stuff(*(G._graph), t) {}
270 void set(Node i, T t) { leda_stuff[i._n]=t; }
271 T get(Node i) const { return leda_stuff[i._n]; } //FIXME: Is it necessary
272 T &operator[](Node i) { return leda_stuff[i._n]; }
273 const T &operator[](Node i) const { return leda_stuff[i._n]; }
275 void update() { /*leda_stuff.init(leda_stuff.get_graph());*/ }
276 //void update(T a) { leda_stuff.init(leda_stuff.get_graph()/**(G._graph)*/, a); } //FIXME: Is it necessary
279 ///Read/write map from the edges to type \c T.
280 template<typename T> class EdgeMap
282 leda_edge_map<T> leda_stuff;
285 typedef Edge KeyType;
287 EdgeMap(const LedaGraphWrapper &G) : leda_stuff(*(G._graph)) {}
288 EdgeMap(const LedaGraphWrapper &G, T t) : leda_stuff(*(G._graph), t) {}
290 void set(Edge i, T t) { leda_stuff[i._e]=t; }
291 T get(Edge i) const { return leda_stuff[i._e]; } //FIXME: Is it necessary
292 T &operator[](Edge i) { return leda_stuff[i._e]; }
293 const T &operator[](Edge i) const { return leda_stuff[i._e]; }
295 void update() { /*leda_stuff.init(leda_stuff.get_graph());*/ }
296 //void update(T a) { leda_stuff.init(leda_stuff.get_graph()/**(G._graph)*/, a); } //FIXME: Is it necessary
307 // class EmptyBipGraph : public EmptyGraph
312 // ANode &next(ANode &) {}
313 // BNode &next(BNode &) {}
315 // ANode &getFirst(ANode &) const {}
316 // BNode &getFirst(BNode &) const {}
318 // enum NodeClass { A = 0, B = 1 };
319 // NodeClass getClass(Node n) {}
323 #endif // HUGO_LEDA_GRAPH_WRAPPER_H