Check StaticGraphSkeleton, as well.
2 #ifndef HUGO_NET_GRAPH_H
3 #define HUGO_NET_GRAPH_H
6 ///\brief Declaration of EdgePathGraph.
8 #include <hugo/invalid.h>
11 /// The namespace of HugoLib
14 // @defgroup empty_graph The EdgePathGraph class
17 /// A graph class in that a simple edge can represent a path.
19 /// This class provides all the common features of a graph structure
20 /// that represents a network. You can handle with it layers. This
21 /// means that an edge in one layer can be a complete path in a nother
24 template <typename P, class Gact, class Gsub>
34 /// The layer on which the edges in this layer can represent paths.
38 /// Map of nodes that represent the nodes of this layer in the sublayer
39 typename Gact::template NodeMap<typename Gsub::Node *> projection;
42 /// Map of routes that are represented by some edges in this layer
43 typename Gact::template EdgeMap<P *> edgepath;
46 /// Defalult constructor.
47 /// We don't need any extra lines, because the actuallayer
48 /// variable has run its constructor, when we have created this class
49 /// So only the two maps has to be initialised here.
50 EdgePathGraph() : projection(actuallayer), edgepath(actuallayer)
56 EdgePathGraph(const EdgePathGraph<P, Gact, Gsub> & EPG ) : actuallayer(EPG.actuallayer) , edgepath(actuallayer), projection(actuallayer)
63 /// This function gets two edgemaps. One belongs to the actual layer and the
64 /// other belongs to the sublayer.
65 /// The function iterates through all of the edges in the edgemap belonging to the actual layer.
66 /// It gets the value that belongs to the actual edge, and adds it to the value of each edge in the
67 /// path represented by itself in the edgemap that belongs to the sublayer.
69 template <typename T1, typename T2> void addMap (typename Gact::EdgeMap<T1> & actmap, typename Gsub::EdgeMap<T2> & submap)
71 for(EdgeIt e(actuallayer);actuallayer.valid(e);actuallayer.next(e))
73 typedef typename P::EdgeIt PEdgeIt;
76 //dep//cout << "Edge " << id(tail(e)) << " - " << id(head(e)) << " in actual layer is";
78 //cout << incr << endl;
82 //dep//cout << endl << "Path";
83 for(edgepath[e]->first(f); edgepath[e]->valid(f); edgepath[e]->next(f))
85 //dep//cout << " " << sublayer->id(sublayer->tail(f)) << "-" << sublayer->id(sublayer->head(f));
88 //dep////cout << EPGr2.id(EPGr2.head(f)) << endl;
93 //dep//cout << " itself." <<endl;
101 /// This function walks thorugh the edges of the actual layer
102 /// and displays the path represented by the actual edge.
105 for(EdgeIt e(actuallayer);actuallayer.valid(e);actuallayer.next(e))
107 typedef typename P::EdgeIt PEdgeIt;
110 cout << "Edge " << id(tail(e)) << " - " << id(head(e)) << " in actual layer is";
113 cout << endl << "Path";
114 for(edgepath[e]->first(f); edgepath[e]->valid(f); edgepath[e]->next(f))
116 cout << " " << sublayer->id(sublayer->tail(f)) << "-" << sublayer->id(sublayer->head(f));
118 //cout << EPGr2.id(EPGr2.head(f)) << endl;
123 cout << " itself." <<endl;
132 /// The base type of the node iterators.
134 /// This is the base type of each node iterators,
135 /// thus each kind of node iterator will convert to this.
136 /// The Node type of the EdgePathGraph is the Node type of the actual layer.
137 typedef typename Gact::Node Node;
140 /// This iterator goes through each node.
142 /// Its usage is quite simple, for example you can count the number
143 /// of nodes in graph \c G of type \c Graph like this:
146 ///for(Graph::NodeIt n(G);G.valid(n);G.next(n)) count++;
148 /// The NodeIt type of the EdgePathGraph is the NodeIt type of the actual layer.
149 typedef typename Gact::NodeIt NodeIt;
152 /// The base type of the edge iterators.
153 /// The Edge type of the EdgePathGraph is the Edge type of the actual layer.
154 typedef typename Gact::Edge Edge;
157 /// This iterator goes trough the outgoing edges of a node.
159 /// This iterator goes trough the \e outgoing edges of a certain node
161 /// Its usage is quite simple, for example you can count the number
162 /// of outgoing edges of a node \c n
163 /// in graph \c G of type \c Graph as follows.
166 ///for(Graph::OutEdgeIt e(G,n);G.valid(e);G.next(e)) count++;
168 /// The OutEdgeIt type of the EdgePathGraph is the OutEdgeIt type of the actual layer.
169 typedef typename Gact::OutEdgeIt OutEdgeIt;
172 /// This iterator goes trough the incoming edges of a node.
174 /// This iterator goes trough the \e incoming edges of a certain node
176 /// Its usage is quite simple, for example you can count the number
177 /// of outgoing edges of a node \c n
178 /// in graph \c G of type \c Graph as follows.
181 ///for(Graph::InEdgeIt e(G,n);G.valid(e);G.next(e)) count++;
183 /// The InEdgeIt type of the EdgePathGraph is the InEdgeIt type of the actual layer.
184 typedef typename Gact::InEdgeIt InEdgeIt;
187 /// This iterator goes through each edge.
189 /// This iterator goes through each edge of a graph.
190 /// Its usage is quite simple, for example you can count the number
191 /// of edges in a graph \c G of type \c Graph as follows:
194 ///for(Graph::EdgeIt e(G);G.valid(e);G.next(e)) count++;
196 /// The EdgeIt type of the EdgePathGraph is the EdgeIt type of the actual layer.
197 typedef typename Gact::EdgeIt EdgeIt;
200 /// First node of the graph.
202 /// \retval i the first node.
203 /// \return the first node.
204 typename Gact::NodeIt &first(typename Gact::NodeIt &i) const { return actuallayer.first(i);}
207 /// The first incoming edge.
208 typename Gact::InEdgeIt &first(typename Gact::InEdgeIt &i, typename Gact::Node) const { return actuallayer.first(i);}
211 /// The first outgoing edge.
212 typename Gact::OutEdgeIt &first(typename Gact::OutEdgeIt &i, typename Gact::Node) const { return actuallayer.first(i);}
215 // SymEdgeIt &first(SymEdgeIt &, Node) const { return i;}
216 /// The first edge of the Graph.
217 typename Gact::EdgeIt &first(typename Gact::EdgeIt &i) const { return actuallayer.first(i);}
220 // Node getNext(Node) const {}
221 // InEdgeIt getNext(InEdgeIt) const {}
222 // OutEdgeIt getNext(OutEdgeIt) const {}
223 // //SymEdgeIt getNext(SymEdgeIt) const {}
224 // EdgeIt getNext(EdgeIt) const {}
227 /// Go to the next node.
228 typename Gact::NodeIt &next(typename Gact::NodeIt &i) const { return actuallayer.next(i);}
229 /// Go to the next incoming edge.
230 typename Gact::InEdgeIt &next(typename Gact::InEdgeIt &i) const { return actuallayer.next(i);}
231 /// Go to the next outgoing edge.
232 typename Gact::OutEdgeIt &next(typename Gact::OutEdgeIt &i) const { return actuallayer.next(i);}
233 //SymEdgeIt &next(SymEdgeIt &) const {}
234 /// Go to the next edge.
235 typename Gact::EdgeIt &next(typename Gact::EdgeIt &i) const { return actuallayer.next(i);}
237 ///Gives back the head node of an edge.
238 typename Gact::Node head(typename Gact::Edge edge) const { return actuallayer.head(edge); }
239 ///Gives back the tail node of an edge.
240 typename Gact::Node tail(typename Gact::Edge edge) const { return actuallayer.tail(edge); }
242 // Node aNode(InEdgeIt) const {}
243 // Node aNode(OutEdgeIt) const {}
244 // Node aNode(SymEdgeIt) const {}
246 // Node bNode(InEdgeIt) const {}
247 // Node bNode(OutEdgeIt) const {}
248 // Node bNode(SymEdgeIt) const {}
250 /// Checks if a node iterator is valid
252 ///\todo Maybe, it would be better if iterator converted to
253 ///bool directly, as Jacint prefers.
254 bool valid(const typename Gact::Node& node) const { return actuallayer.valid(node);}
255 /// Checks if an edge iterator is valid
257 ///\todo Maybe, it would be better if iterator converted to
258 ///bool directly, as Jacint prefers.
259 bool valid(const typename Gact::Edge& edge) const { return actuallayer.valid(edge);}
261 ///Gives back the \e id of a node.
263 ///\warning Not all graph structures provide this feature.
265 int id(const typename Gact::Node & node) const { return actuallayer.id(node);}
266 ///Gives back the \e id of an edge.
268 ///\warning Not all graph structures provide this feature.
270 int id(const typename Gact::Edge & edge) const { return actuallayer.id(edge);}
272 //void setInvalid(Node &) const {};
273 //void setInvalid(Edge &) const {};
275 ///Add a new node to the graph.
277 /// \return the new node.
279 typename Gact::Node addNode() { return actuallayer.addNode();}
280 ///Add a new edge to the graph.
282 ///Add a new edge to the graph with tail node \c tail
283 ///and head node \c head.
284 ///\return the new edge.
285 typename Gact::Edge addEdge(typename Gact::Node node1, typename Gact::Node node2) { return actuallayer.addEdge(node1, node2);}
287 /// Resets the graph.
289 /// This function deletes all edges and nodes of the graph.
290 /// It also frees the memory allocated to store them.
291 void clear() {actuallayer.clear();}
293 int nodeNum() const { return actuallayer.nodeNum();}
294 int edgeNum() const { return actuallayer.edgeNum();}
296 ///Read/write/reference map of the nodes to type \c T.
298 ///Read/write/reference map of the nodes to type \c T.
299 /// \sa MemoryMapSkeleton
300 /// \todo We may need copy constructor
301 /// \todo We may need conversion from other nodetype
302 /// \todo We may need operator=
303 /// \warning Making maps that can handle bool type (NodeMap<bool>)
304 /// needs extra attention!
306 template<class T> class NodeMap
310 typedef Node KeyType;
312 NodeMap(const EdgePathGraph &) {}
313 NodeMap(const EdgePathGraph &, T) {}
315 template<typename TT> NodeMap(const NodeMap<TT> &) {}
317 /// Sets the value of a node.
319 /// Sets the value associated with node \c i to the value \c t.
322 // Gets the value of a node.
323 //T get(Node i) const {return *(T*)0;} //FIXME: Is it necessary?
324 T &operator[](Node) {return *(T*)0;}
325 const T &operator[](Node) const {return *(T*)0;}
327 /// Updates the map if the graph has been changed
329 /// \todo Do we need this?
332 void update(T a) {} //FIXME: Is it necessary
335 ///Read/write/reference map of the edges to type \c T.
337 ///Read/write/reference map of the edges to type \c T.
338 ///It behaves exactly in the same way as \ref NodeMap.
340 /// \sa MemoryMapSkeleton
341 /// \todo We may need copy constructor
342 /// \todo We may need conversion from other edgetype
343 /// \todo We may need operator=
344 template<class T> class EdgeMap
348 typedef Edge KeyType;
350 EdgeMap(const EdgePathGraph &) {}
351 EdgeMap(const EdgePathGraph &, T ) {}
353 ///\todo It can copy between different types.
355 template<typename TT> EdgeMap(const EdgeMap<TT> &) {}
358 //T get(Edge) const {return *(T*)0;}
359 T &operator[](Edge) {return *(T*)0;}
360 const T &operator[](Edge) const {return *(T*)0;}
363 void update(T a) {} //FIXME: Is it necessary
367 /// An empty eraseable graph class.
369 /// This class provides all the common features of an \e eraseable graph
371 /// however completely without implementations and real data structures
372 /// behind the interface.
373 /// All graph algorithms should compile with this class, but it will not
374 /// run properly, of course.
376 /// \todo This blabla could be replaced by a sepatate description about
379 /// It can be used for checking the interface compatibility,
380 /// or it can serve as a skeleton of a new graph structure.
382 /// Also, you will find here the full documentation of a certain graph
383 /// feature, the documentation of a real graph imlementation
384 /// like @ref ListGraph or
385 /// @ref SmartGraph will just refer to this structure.
386 template <typename P, typename Gact, typename Gsub>
387 class EraseableEdgePathGraph : public EdgePathGraph<P, Gact, Gsub>
391 void erase(typename Gact::Node n) {actuallayer.erase(n);}
393 void erase(typename Gact::Edge e) {actuallayer.erase(e);}
395 /// Defalult constructor.
396 EraseableEdgePathGraph() {}
398 EraseableEdgePathGraph(const EdgePathGraph<P, Gact, Gsub> &EPG) {}
407 #endif // HUGO_SKELETON_GRAPH_H