hegyi@677
|
1 |
// -*- c++ -*-
|
alpar@921
|
2 |
#ifndef LEMON_NET_GRAPH_H
|
alpar@921
|
3 |
#define LEMON_NET_GRAPH_H
|
hegyi@677
|
4 |
|
hegyi@677
|
5 |
///\file
|
hegyi@677
|
6 |
///\brief Declaration of HierarchyGraph.
|
hegyi@677
|
7 |
|
alpar@921
|
8 |
#include <lemon/invalid.h>
|
alpar@921
|
9 |
#include <lemon/maps.h>
|
hegyi@677
|
10 |
|
alpar@921
|
11 |
/// The namespace of LEMON
|
alpar@921
|
12 |
namespace lemon
|
hegyi@691
|
13 |
{
|
hegyi@677
|
14 |
|
hegyi@677
|
15 |
// @defgroup empty_graph The HierarchyGraph class
|
hegyi@677
|
16 |
// @{
|
hegyi@677
|
17 |
|
hegyi@677
|
18 |
/// A graph class in that a simple edge can represent a path.
|
hegyi@690
|
19 |
|
hegyi@677
|
20 |
/// This class provides common features of a graph structure
|
hegyi@677
|
21 |
/// that represents a network. You can handle with it layers. This
|
hegyi@677
|
22 |
/// means that a node in one layer can be a complete network in a nother
|
hegyi@677
|
23 |
/// layer.
|
hegyi@677
|
24 |
|
hegyi@691
|
25 |
template < class Gact, class Gsub > class HierarchyGraph
|
hegyi@677
|
26 |
{
|
hegyi@677
|
27 |
|
hegyi@677
|
28 |
public:
|
hegyi@677
|
29 |
|
hegyi@677
|
30 |
/// The actual layer
|
hegyi@677
|
31 |
Gact actuallayer;
|
hegyi@677
|
32 |
|
hegyi@677
|
33 |
|
hegyi@690
|
34 |
/// Map of the subnetworks in the sublayer
|
hegyi@690
|
35 |
/// The appropriate edge nodes are also stored here
|
hegyi@677
|
36 |
|
hegyi@690
|
37 |
class SubNetwork
|
hegyi@690
|
38 |
{
|
hegyi@690
|
39 |
|
hegyi@690
|
40 |
struct actedgesubnodestruct
|
hegyi@690
|
41 |
{
|
hegyi@691
|
42 |
typename Gact::Edge actedge;
|
hegyi@691
|
43 |
typename Gsub::Node subnode;
|
hegyi@690
|
44 |
};
|
hegyi@690
|
45 |
|
hegyi@690
|
46 |
int edgenumber;
|
hegyi@690
|
47 |
bool connectable;
|
hegyi@691
|
48 |
Gact *actuallayer;
|
hegyi@690
|
49 |
typename Gact::Node * actuallayernode;
|
hegyi@691
|
50 |
Gsub *subnetwork;
|
hegyi@691
|
51 |
actedgesubnodestruct *assignments;
|
hegyi@690
|
52 |
|
hegyi@690
|
53 |
public:
|
hegyi@690
|
54 |
|
hegyi@691
|
55 |
int addAssignment (typename Gact::Edge actedge,
|
hegyi@691
|
56 |
typename Gsub::Node subnode)
|
hegyi@690
|
57 |
{
|
hegyi@691
|
58 |
if (!(actuallayer->valid (actedge)))
|
hegyi@691
|
59 |
{
|
hegyi@691
|
60 |
cerr << "The given edge is not in the given network!" << endl;
|
hegyi@691
|
61 |
return -1;
|
hegyi@691
|
62 |
}
|
alpar@986
|
63 |
else if ((actuallayer->id (actuallayer->source (actedge)) !=
|
hegyi@691
|
64 |
actuallayer->id (*actuallayernode))
|
alpar@986
|
65 |
&& (actuallayer->id (actuallayer->target (actedge)) !=
|
hegyi@691
|
66 |
actuallayer->id (*actuallayernode)))
|
hegyi@691
|
67 |
{
|
hegyi@691
|
68 |
cerr << "The given edge does not connect to the given node!" <<
|
hegyi@691
|
69 |
endl;
|
hegyi@691
|
70 |
return -1;
|
hegyi@691
|
71 |
}
|
hegyi@690
|
72 |
|
hegyi@691
|
73 |
if (!(subnetwork->valid (subnode)))
|
hegyi@691
|
74 |
{
|
hegyi@691
|
75 |
cerr << "The given node is not in the given network!" << endl;
|
hegyi@691
|
76 |
return -1;
|
hegyi@691
|
77 |
}
|
hegyi@690
|
78 |
|
hegyi@691
|
79 |
int i = 0;
|
hegyi@690
|
80 |
//while in the array there is valid note that is not equvivalent with the one that would be noted increase i
|
hegyi@691
|
81 |
while ((i < edgenumber)
|
hegyi@691
|
82 |
&& (actuallayer->valid (assignments[i].actedge))
|
hegyi@691
|
83 |
&& (assignments[i].actedge != actedge))
|
hegyi@691
|
84 |
i++;
|
hegyi@691
|
85 |
if (assignments[i].actedge == actedge)
|
hegyi@691
|
86 |
{
|
hegyi@691
|
87 |
cout << "Warning: Redefinement of assigment!!!" << endl;
|
hegyi@691
|
88 |
}
|
hegyi@691
|
89 |
if (i == edgenumber)
|
hegyi@691
|
90 |
{
|
hegyi@691
|
91 |
cout <<
|
hegyi@691
|
92 |
"This case can't be!!! (because there should be the guven edge in the array already and the cycle had to stop)"
|
hegyi@691
|
93 |
<< endl;
|
hegyi@691
|
94 |
}
|
hegyi@690
|
95 |
//if(!(actuallayer->valid(assignments[i].actedge))) //this condition is necessary if we do not obey redefinition
|
hegyi@690
|
96 |
{
|
hegyi@691
|
97 |
assignments[i].actedge = actedge;
|
hegyi@691
|
98 |
assignments[i].subnode = subnode;
|
hegyi@690
|
99 |
}
|
hegyi@690
|
100 |
|
hegyi@690
|
101 |
/// If to all of the edges a subnode is assigned then the subnetwork is connectable (attachable?)
|
hegyi@690
|
102 |
/// We do not need to check for further attributes, because to notice an assignment we need
|
hegyi@690
|
103 |
/// all of them to be correctly initialised before.
|
hegyi@691
|
104 |
if (i == edgenumber - 1)
|
hegyi@691
|
105 |
connectable = 1;
|
hegyi@690
|
106 |
|
hegyi@690
|
107 |
return 0;
|
hegyi@690
|
108 |
}
|
hegyi@690
|
109 |
|
hegyi@691
|
110 |
int setSubNetwork (Gsub * sn)
|
hegyi@690
|
111 |
{
|
hegyi@691
|
112 |
subnetwork = sn;
|
hegyi@690
|
113 |
return 0;
|
hegyi@690
|
114 |
}
|
hegyi@690
|
115 |
|
hegyi@691
|
116 |
int setActualLayer (Gact * al)
|
hegyi@690
|
117 |
{
|
hegyi@691
|
118 |
actuallayer = al;
|
hegyi@690
|
119 |
return 0;
|
hegyi@690
|
120 |
}
|
hegyi@690
|
121 |
|
hegyi@691
|
122 |
int setActualLayerNode (typename Gact::Node * aln)
|
hegyi@690
|
123 |
{
|
hegyi@690
|
124 |
typename Gact::InEdgeIt iei;
|
hegyi@690
|
125 |
typename Gact::OutEdgeIt oei;
|
hegyi@690
|
126 |
|
hegyi@691
|
127 |
actuallayernode = aln;
|
hegyi@690
|
128 |
|
hegyi@691
|
129 |
edgenumber = 0;
|
hegyi@690
|
130 |
|
hegyi@691
|
131 |
if (actuallayer)
|
hegyi@690
|
132 |
{
|
hegyi@691
|
133 |
for (iei = actuallayer->first (iei, (*actuallayernode));
|
hegyi@691
|
134 |
((actuallayer->valid (iei))
|
alpar@986
|
135 |
&& (actuallayer->target (iei) == (*actuallayernode)));
|
hegyi@691
|
136 |
actuallayer->next (iei))
|
hegyi@691
|
137 |
{
|
hegyi@691
|
138 |
cout << actuallayer->id (actuallayer->
|
alpar@986
|
139 |
source (iei)) << " " << actuallayer->
|
alpar@986
|
140 |
id (actuallayer->target (iei)) << endl;
|
hegyi@691
|
141 |
edgenumber++;
|
hegyi@691
|
142 |
}
|
hegyi@691
|
143 |
//cout << "Number of in-edges: " << edgenumber << endl;
|
hegyi@691
|
144 |
for (oei = actuallayer->first (oei, (*actuallayernode));
|
hegyi@691
|
145 |
((actuallayer->valid (oei))
|
alpar@986
|
146 |
&& (actuallayer->source (oei) == (*actuallayernode)));
|
hegyi@691
|
147 |
actuallayer->next (oei))
|
hegyi@691
|
148 |
{
|
hegyi@691
|
149 |
cout << actuallayer->id (actuallayer->
|
alpar@986
|
150 |
source (oei)) << " " << actuallayer->
|
alpar@986
|
151 |
id (actuallayer->target (oei)) << endl;
|
hegyi@691
|
152 |
edgenumber++;
|
hegyi@691
|
153 |
}
|
hegyi@691
|
154 |
//cout << "Number of in+out-edges: " << edgenumber << endl;
|
hegyi@691
|
155 |
assignments = new actedgesubnodestruct[edgenumber];
|
hegyi@691
|
156 |
for (int i = 0; i < edgenumber; i++)
|
hegyi@691
|
157 |
{
|
hegyi@691
|
158 |
assignments[i].actedge = INVALID;
|
hegyi@691
|
159 |
assignments[i].subnode = INVALID;
|
hegyi@691
|
160 |
}
|
hegyi@690
|
161 |
}
|
hegyi@691
|
162 |
else
|
hegyi@690
|
163 |
{
|
hegyi@691
|
164 |
cerr << "There is no actual layer defined yet!" << endl;
|
hegyi@691
|
165 |
return -1;
|
hegyi@690
|
166 |
}
|
hegyi@690
|
167 |
|
hegyi@690
|
168 |
return 0;
|
hegyi@690
|
169 |
}
|
hegyi@690
|
170 |
|
hegyi@691
|
171 |
SubNetwork ():edgenumber (0), connectable (false), actuallayer (NULL),
|
hegyi@691
|
172 |
actuallayernode (NULL), subnetwork (NULL),
|
hegyi@691
|
173 |
assignments (NULL)
|
hegyi@690
|
174 |
{
|
hegyi@690
|
175 |
}
|
hegyi@690
|
176 |
|
hegyi@690
|
177 |
};
|
hegyi@690
|
178 |
|
hegyi@691
|
179 |
typename Gact::template NodeMap < SubNetwork > subnetworks;
|
hegyi@677
|
180 |
|
hegyi@677
|
181 |
|
hegyi@677
|
182 |
/// Defalult constructor.
|
hegyi@677
|
183 |
/// We don't need any extra lines, because the actuallayer
|
hegyi@677
|
184 |
/// variable has run its constructor, when we have created this class
|
hegyi@677
|
185 |
/// So only the two maps has to be initialised here.
|
hegyi@691
|
186 |
HierarchyGraph ():subnetworks (actuallayer)
|
hegyi@677
|
187 |
{
|
hegyi@677
|
188 |
}
|
hegyi@677
|
189 |
|
hegyi@677
|
190 |
|
hegyi@677
|
191 |
///Copy consructor.
|
hegyi@691
|
192 |
HierarchyGraph (const HierarchyGraph < Gact, Gsub > &HG):actuallayer (HG.actuallayer),
|
hegyi@691
|
193 |
subnetworks
|
hegyi@691
|
194 |
(actuallayer)
|
hegyi@677
|
195 |
{
|
hegyi@677
|
196 |
}
|
hegyi@677
|
197 |
|
hegyi@690
|
198 |
|
hegyi@677
|
199 |
/// The base type of the node iterators.
|
hegyi@677
|
200 |
|
hegyi@677
|
201 |
/// This is the base type of each node iterators,
|
hegyi@677
|
202 |
/// thus each kind of node iterator will convert to this.
|
hegyi@677
|
203 |
/// The Node type of the HierarchyGraph is the Node type of the actual layer.
|
hegyi@677
|
204 |
typedef typename Gact::Node Node;
|
hegyi@677
|
205 |
|
hegyi@690
|
206 |
|
hegyi@677
|
207 |
/// This iterator goes through each node.
|
hegyi@677
|
208 |
|
hegyi@677
|
209 |
/// Its usage is quite simple, for example you can count the number
|
hegyi@677
|
210 |
/// of nodes in graph \c G of type \c Graph like this:
|
hegyi@677
|
211 |
/// \code
|
hegyi@677
|
212 |
///int count=0;
|
hegyi@677
|
213 |
///for(Graph::NodeIt n(G);G.valid(n);G.next(n)) count++;
|
hegyi@677
|
214 |
/// \endcode
|
hegyi@677
|
215 |
/// The NodeIt type of the HierarchyGraph is the NodeIt type of the actual layer.
|
hegyi@677
|
216 |
typedef typename Gact::NodeIt NodeIt;
|
hegyi@690
|
217 |
|
hegyi@690
|
218 |
|
hegyi@677
|
219 |
/// The base type of the edge iterators.
|
hegyi@677
|
220 |
/// The Edge type of the HierarchyGraph is the Edge type of the actual layer.
|
hegyi@691
|
221 |
typedef typename Gact::Edge Edge;
|
hegyi@677
|
222 |
|
hegyi@690
|
223 |
|
hegyi@677
|
224 |
/// This iterator goes trough the outgoing edges of a node.
|
hegyi@677
|
225 |
|
hegyi@677
|
226 |
/// This iterator goes trough the \e outgoing edges of a certain node
|
hegyi@677
|
227 |
/// of a graph.
|
hegyi@677
|
228 |
/// Its usage is quite simple, for example you can count the number
|
hegyi@677
|
229 |
/// of outgoing edges of a node \c n
|
hegyi@677
|
230 |
/// in graph \c G of type \c Graph as follows.
|
hegyi@677
|
231 |
/// \code
|
hegyi@677
|
232 |
///int count=0;
|
hegyi@677
|
233 |
///for(Graph::OutEdgeIt e(G,n);G.valid(e);G.next(e)) count++;
|
hegyi@677
|
234 |
/// \endcode
|
hegyi@677
|
235 |
/// The OutEdgeIt type of the HierarchyGraph is the OutEdgeIt type of the actual layer.
|
hegyi@677
|
236 |
typedef typename Gact::OutEdgeIt OutEdgeIt;
|
hegyi@677
|
237 |
|
hegyi@677
|
238 |
|
hegyi@677
|
239 |
/// This iterator goes trough the incoming edges of a node.
|
hegyi@677
|
240 |
|
hegyi@677
|
241 |
/// This iterator goes trough the \e incoming edges of a certain node
|
hegyi@677
|
242 |
/// of a graph.
|
hegyi@677
|
243 |
/// Its usage is quite simple, for example you can count the number
|
hegyi@677
|
244 |
/// of outgoing edges of a node \c n
|
hegyi@677
|
245 |
/// in graph \c G of type \c Graph as follows.
|
hegyi@677
|
246 |
/// \code
|
hegyi@677
|
247 |
///int count=0;
|
hegyi@677
|
248 |
///for(Graph::InEdgeIt e(G,n);G.valid(e);G.next(e)) count++;
|
hegyi@677
|
249 |
/// \endcode
|
hegyi@677
|
250 |
/// The InEdgeIt type of the HierarchyGraph is the InEdgeIt type of the actual layer.
|
hegyi@677
|
251 |
typedef typename Gact::InEdgeIt InEdgeIt;
|
hegyi@677
|
252 |
|
hegyi@677
|
253 |
|
hegyi@677
|
254 |
/// This iterator goes through each edge.
|
hegyi@677
|
255 |
|
hegyi@677
|
256 |
/// This iterator goes through each edge of a graph.
|
hegyi@677
|
257 |
/// Its usage is quite simple, for example you can count the number
|
hegyi@677
|
258 |
/// of edges in a graph \c G of type \c Graph as follows:
|
hegyi@677
|
259 |
/// \code
|
hegyi@677
|
260 |
///int count=0;
|
hegyi@677
|
261 |
///for(Graph::EdgeIt e(G);G.valid(e);G.next(e)) count++;
|
hegyi@677
|
262 |
/// \endcode
|
hegyi@677
|
263 |
/// The EdgeIt type of the HierarchyGraph is the EdgeIt type of the actual layer.
|
hegyi@677
|
264 |
typedef typename Gact::EdgeIt EdgeIt;
|
hegyi@677
|
265 |
|
hegyi@677
|
266 |
|
hegyi@677
|
267 |
/// First node of the graph.
|
hegyi@677
|
268 |
|
hegyi@677
|
269 |
/// \retval i the first node.
|
hegyi@677
|
270 |
/// \return the first node.
|
hegyi@691
|
271 |
typename Gact::NodeIt & first (typename Gact::NodeIt & i) const
|
hegyi@691
|
272 |
{
|
hegyi@691
|
273 |
return actuallayer.first (i);
|
hegyi@691
|
274 |
}
|
hegyi@677
|
275 |
|
hegyi@677
|
276 |
|
hegyi@677
|
277 |
/// The first incoming edge.
|
hegyi@691
|
278 |
typename Gact::InEdgeIt & first (typename Gact::InEdgeIt & i,
|
hegyi@691
|
279 |
typename Gact::Node) const
|
hegyi@691
|
280 |
{
|
hegyi@691
|
281 |
return actuallayer.first (i);
|
hegyi@691
|
282 |
}
|
hegyi@677
|
283 |
|
hegyi@677
|
284 |
|
hegyi@677
|
285 |
/// The first outgoing edge.
|
hegyi@691
|
286 |
typename Gact::OutEdgeIt & first (typename Gact::OutEdgeIt & i,
|
hegyi@691
|
287 |
typename Gact::Node) const
|
hegyi@691
|
288 |
{
|
hegyi@691
|
289 |
return actuallayer.first (i);
|
hegyi@691
|
290 |
}
|
hegyi@677
|
291 |
|
hegyi@677
|
292 |
|
hegyi@677
|
293 |
// SymEdgeIt &first(SymEdgeIt &, Node) const { return i;}
|
hegyi@677
|
294 |
/// The first edge of the Graph.
|
hegyi@691
|
295 |
typename Gact::EdgeIt & first (typename Gact::EdgeIt & i) const
|
hegyi@691
|
296 |
{
|
hegyi@691
|
297 |
return actuallayer.first (i);
|
hegyi@691
|
298 |
}
|
hegyi@677
|
299 |
|
hegyi@677
|
300 |
|
hegyi@677
|
301 |
// Node getNext(Node) const {}
|
hegyi@677
|
302 |
// InEdgeIt getNext(InEdgeIt) const {}
|
hegyi@677
|
303 |
// OutEdgeIt getNext(OutEdgeIt) const {}
|
hegyi@677
|
304 |
// //SymEdgeIt getNext(SymEdgeIt) const {}
|
hegyi@677
|
305 |
// EdgeIt getNext(EdgeIt) const {}
|
hegyi@677
|
306 |
|
hegyi@677
|
307 |
|
hegyi@677
|
308 |
/// Go to the next node.
|
hegyi@691
|
309 |
typename Gact::NodeIt & next (typename Gact::NodeIt & i) const
|
hegyi@691
|
310 |
{
|
hegyi@691
|
311 |
return actuallayer.next (i);
|
hegyi@691
|
312 |
}
|
hegyi@677
|
313 |
/// Go to the next incoming edge.
|
hegyi@691
|
314 |
typename Gact::InEdgeIt & next (typename Gact::InEdgeIt & i) const
|
hegyi@691
|
315 |
{
|
hegyi@691
|
316 |
return actuallayer.next (i);
|
hegyi@691
|
317 |
}
|
hegyi@677
|
318 |
/// Go to the next outgoing edge.
|
hegyi@691
|
319 |
typename Gact::OutEdgeIt & next (typename Gact::OutEdgeIt & i) const
|
hegyi@691
|
320 |
{
|
hegyi@691
|
321 |
return actuallayer.next (i);
|
hegyi@691
|
322 |
}
|
hegyi@677
|
323 |
//SymEdgeIt &next(SymEdgeIt &) const {}
|
hegyi@677
|
324 |
/// Go to the next edge.
|
hegyi@691
|
325 |
typename Gact::EdgeIt & next (typename Gact::EdgeIt & i) const
|
hegyi@691
|
326 |
{
|
hegyi@691
|
327 |
return actuallayer.next (i);
|
hegyi@691
|
328 |
}
|
hegyi@677
|
329 |
|
alpar@986
|
330 |
///Gives back the target node of an edge.
|
alpar@986
|
331 |
typename Gact::Node target (typename Gact::Edge edge) const
|
hegyi@691
|
332 |
{
|
alpar@986
|
333 |
return actuallayer.target (edge);
|
hegyi@691
|
334 |
}
|
alpar@986
|
335 |
///Gives back the source node of an edge.
|
alpar@986
|
336 |
typename Gact::Node source (typename Gact::Edge edge) const
|
hegyi@691
|
337 |
{
|
alpar@986
|
338 |
return actuallayer.source (edge);
|
hegyi@691
|
339 |
}
|
hegyi@690
|
340 |
|
hegyi@677
|
341 |
// Node aNode(InEdgeIt) const {}
|
hegyi@677
|
342 |
// Node aNode(OutEdgeIt) const {}
|
hegyi@677
|
343 |
// Node aNode(SymEdgeIt) const {}
|
hegyi@677
|
344 |
|
hegyi@677
|
345 |
// Node bNode(InEdgeIt) const {}
|
hegyi@677
|
346 |
// Node bNode(OutEdgeIt) const {}
|
hegyi@677
|
347 |
// Node bNode(SymEdgeIt) const {}
|
hegyi@677
|
348 |
|
hegyi@677
|
349 |
/// Checks if a node iterator is valid
|
hegyi@677
|
350 |
|
hegyi@677
|
351 |
///\todo Maybe, it would be better if iterator converted to
|
hegyi@677
|
352 |
///bool directly, as Jacint prefers.
|
hegyi@691
|
353 |
bool valid (const typename Gact::Node & node) const
|
hegyi@691
|
354 |
{
|
hegyi@691
|
355 |
return actuallayer.valid (node);
|
hegyi@691
|
356 |
}
|
hegyi@677
|
357 |
/// Checks if an edge iterator is valid
|
hegyi@677
|
358 |
|
hegyi@677
|
359 |
///\todo Maybe, it would be better if iterator converted to
|
hegyi@677
|
360 |
///bool directly, as Jacint prefers.
|
hegyi@691
|
361 |
bool valid (const typename Gact::Edge & edge) const
|
hegyi@691
|
362 |
{
|
hegyi@691
|
363 |
return actuallayer.valid (edge);
|
hegyi@691
|
364 |
}
|
hegyi@677
|
365 |
|
hegyi@677
|
366 |
///Gives back the \e id of a node.
|
hegyi@677
|
367 |
|
hegyi@677
|
368 |
///\warning Not all graph structures provide this feature.
|
hegyi@677
|
369 |
///
|
hegyi@691
|
370 |
int id (const typename Gact::Node & node) const
|
hegyi@691
|
371 |
{
|
hegyi@691
|
372 |
return actuallayer.id (node);
|
hegyi@691
|
373 |
}
|
hegyi@677
|
374 |
///Gives back the \e id of an edge.
|
hegyi@677
|
375 |
|
hegyi@677
|
376 |
///\warning Not all graph structures provide this feature.
|
hegyi@677
|
377 |
///
|
hegyi@691
|
378 |
int id (const typename Gact::Edge & edge) const
|
hegyi@691
|
379 |
{
|
hegyi@691
|
380 |
return actuallayer.id (edge);
|
hegyi@691
|
381 |
}
|
hegyi@677
|
382 |
|
hegyi@677
|
383 |
//void setInvalid(Node &) const {};
|
hegyi@677
|
384 |
//void setInvalid(Edge &) const {};
|
hegyi@690
|
385 |
|
hegyi@677
|
386 |
///Add a new node to the graph.
|
hegyi@677
|
387 |
|
hegyi@677
|
388 |
/// \return the new node.
|
hegyi@677
|
389 |
///
|
hegyi@691
|
390 |
typename Gact::Node addNode ()
|
hegyi@691
|
391 |
{
|
hegyi@691
|
392 |
return actuallayer.addNode ();
|
hegyi@691
|
393 |
}
|
hegyi@677
|
394 |
///Add a new edge to the graph.
|
hegyi@677
|
395 |
|
alpar@986
|
396 |
///Add a new edge to the graph with source node \c source
|
alpar@986
|
397 |
///and target node \c target.
|
hegyi@677
|
398 |
///\return the new edge.
|
hegyi@691
|
399 |
typename Gact::Edge addEdge (typename Gact::Node node1,
|
hegyi@691
|
400 |
typename Gact::Node node2)
|
hegyi@691
|
401 |
{
|
hegyi@691
|
402 |
return actuallayer.addEdge (node1, node2);
|
hegyi@691
|
403 |
}
|
hegyi@690
|
404 |
|
hegyi@677
|
405 |
/// Resets the graph.
|
hegyi@677
|
406 |
|
hegyi@677
|
407 |
/// This function deletes all edges and nodes of the graph.
|
hegyi@677
|
408 |
/// It also frees the memory allocated to store them.
|
hegyi@691
|
409 |
void clear ()
|
hegyi@691
|
410 |
{
|
hegyi@691
|
411 |
actuallayer.clear ();
|
hegyi@691
|
412 |
}
|
hegyi@677
|
413 |
|
hegyi@691
|
414 |
int nodeNum () const
|
hegyi@691
|
415 |
{
|
hegyi@691
|
416 |
return actuallayer.nodeNum ();
|
hegyi@691
|
417 |
}
|
hegyi@691
|
418 |
int edgeNum () const
|
hegyi@691
|
419 |
{
|
hegyi@691
|
420 |
return actuallayer.edgeNum ();
|
hegyi@691
|
421 |
}
|
hegyi@677
|
422 |
|
hegyi@677
|
423 |
///Read/write/reference map of the nodes to type \c T.
|
hegyi@677
|
424 |
|
hegyi@677
|
425 |
///Read/write/reference map of the nodes to type \c T.
|
alpar@880
|
426 |
/// \sa MemoryMap
|
hegyi@677
|
427 |
/// \todo We may need copy constructor
|
hegyi@677
|
428 |
/// \todo We may need conversion from other nodetype
|
hegyi@677
|
429 |
/// \todo We may need operator=
|
hegyi@677
|
430 |
/// \warning Making maps that can handle bool type (NodeMap<bool>)
|
hegyi@677
|
431 |
/// needs extra attention!
|
hegyi@677
|
432 |
|
hegyi@691
|
433 |
template < class T > class NodeMap
|
hegyi@677
|
434 |
{
|
hegyi@677
|
435 |
public:
|
hegyi@677
|
436 |
typedef T ValueType;
|
hegyi@677
|
437 |
typedef Node KeyType;
|
hegyi@677
|
438 |
|
hegyi@691
|
439 |
NodeMap (const HierarchyGraph &)
|
hegyi@691
|
440 |
{
|
hegyi@691
|
441 |
}
|
hegyi@691
|
442 |
NodeMap (const HierarchyGraph &, T)
|
hegyi@691
|
443 |
{
|
hegyi@691
|
444 |
}
|
hegyi@677
|
445 |
|
hegyi@691
|
446 |
template < typename TT > NodeMap (const NodeMap < TT > &)
|
hegyi@691
|
447 |
{
|
hegyi@691
|
448 |
}
|
hegyi@677
|
449 |
|
hegyi@677
|
450 |
/// Sets the value of a node.
|
hegyi@677
|
451 |
|
hegyi@677
|
452 |
/// Sets the value associated with node \c i to the value \c t.
|
hegyi@677
|
453 |
///
|
hegyi@691
|
454 |
void set (Node, T)
|
hegyi@691
|
455 |
{
|
hegyi@691
|
456 |
}
|
hegyi@677
|
457 |
// Gets the value of a node.
|
hegyi@677
|
458 |
//T get(Node i) const {return *(T*)0;} //FIXME: Is it necessary?
|
hegyi@691
|
459 |
T & operator[](Node)
|
hegyi@691
|
460 |
{
|
hegyi@691
|
461 |
return *(T *) 0;
|
hegyi@691
|
462 |
}
|
hegyi@691
|
463 |
const T & operator[] (Node) const
|
hegyi@691
|
464 |
{
|
hegyi@691
|
465 |
return *(T *) 0;
|
hegyi@691
|
466 |
}
|
hegyi@677
|
467 |
|
hegyi@677
|
468 |
/// Updates the map if the graph has been changed
|
hegyi@677
|
469 |
|
hegyi@677
|
470 |
/// \todo Do we need this?
|
hegyi@677
|
471 |
///
|
hegyi@691
|
472 |
void update ()
|
hegyi@691
|
473 |
{
|
hegyi@691
|
474 |
}
|
hegyi@691
|
475 |
void update (T a)
|
hegyi@691
|
476 |
{
|
hegyi@691
|
477 |
} //FIXME: Is it necessary
|
hegyi@677
|
478 |
};
|
hegyi@677
|
479 |
|
hegyi@677
|
480 |
///Read/write/reference map of the edges to type \c T.
|
hegyi@677
|
481 |
|
hegyi@677
|
482 |
///Read/write/reference map of the edges to type \c T.
|
hegyi@677
|
483 |
///It behaves exactly in the same way as \ref NodeMap.
|
hegyi@677
|
484 |
/// \sa NodeMap
|
alpar@880
|
485 |
/// \sa MemoryMap
|
hegyi@677
|
486 |
/// \todo We may need copy constructor
|
hegyi@677
|
487 |
/// \todo We may need conversion from other edgetype
|
hegyi@677
|
488 |
/// \todo We may need operator=
|
hegyi@691
|
489 |
template < class T > class EdgeMap
|
hegyi@677
|
490 |
{
|
hegyi@677
|
491 |
public:
|
hegyi@677
|
492 |
typedef T ValueType;
|
hegyi@677
|
493 |
typedef Edge KeyType;
|
hegyi@677
|
494 |
|
hegyi@691
|
495 |
EdgeMap (const HierarchyGraph &)
|
hegyi@691
|
496 |
{
|
hegyi@691
|
497 |
}
|
hegyi@691
|
498 |
EdgeMap (const HierarchyGraph &, T)
|
hegyi@691
|
499 |
{
|
hegyi@691
|
500 |
}
|
hegyi@690
|
501 |
|
hegyi@677
|
502 |
///\todo It can copy between different types.
|
hegyi@677
|
503 |
///
|
hegyi@691
|
504 |
template < typename TT > EdgeMap (const EdgeMap < TT > &)
|
hegyi@691
|
505 |
{
|
hegyi@691
|
506 |
}
|
hegyi@677
|
507 |
|
hegyi@691
|
508 |
void set (Edge, T)
|
hegyi@691
|
509 |
{
|
hegyi@691
|
510 |
}
|
hegyi@677
|
511 |
//T get(Edge) const {return *(T*)0;}
|
hegyi@691
|
512 |
T & operator[](Edge)
|
hegyi@691
|
513 |
{
|
hegyi@691
|
514 |
return *(T *) 0;
|
hegyi@691
|
515 |
}
|
hegyi@691
|
516 |
const T & operator[] (Edge) const
|
hegyi@691
|
517 |
{
|
hegyi@691
|
518 |
return *(T *) 0;
|
hegyi@691
|
519 |
}
|
hegyi@690
|
520 |
|
hegyi@691
|
521 |
void update ()
|
hegyi@691
|
522 |
{
|
hegyi@691
|
523 |
}
|
hegyi@691
|
524 |
void update (T a)
|
hegyi@691
|
525 |
{
|
hegyi@691
|
526 |
} //FIXME: Is it necessary
|
hegyi@677
|
527 |
};
|
hegyi@677
|
528 |
};
|
hegyi@677
|
529 |
|
alpar@826
|
530 |
/// An empty erasable graph class.
|
hegyi@690
|
531 |
|
alpar@826
|
532 |
/// This class provides all the common features of an \e erasable graph
|
hegyi@677
|
533 |
/// structure,
|
hegyi@677
|
534 |
/// however completely without implementations and real data structures
|
hegyi@677
|
535 |
/// behind the interface.
|
hegyi@677
|
536 |
/// All graph algorithms should compile with this class, but it will not
|
hegyi@677
|
537 |
/// run properly, of course.
|
hegyi@677
|
538 |
///
|
hegyi@677
|
539 |
/// \todo This blabla could be replaced by a sepatate description about
|
alpar@880
|
540 |
/// s.
|
hegyi@677
|
541 |
///
|
hegyi@677
|
542 |
/// It can be used for checking the interface compatibility,
|
hegyi@677
|
543 |
/// or it can serve as a skeleton of a new graph structure.
|
hegyi@690
|
544 |
///
|
hegyi@677
|
545 |
/// Also, you will find here the full documentation of a certain graph
|
hegyi@677
|
546 |
/// feature, the documentation of a real graph imlementation
|
hegyi@677
|
547 |
/// like @ref ListGraph or
|
hegyi@677
|
548 |
/// @ref SmartGraph will just refer to this structure.
|
alpar@826
|
549 |
template < typename Gact, typename Gsub > class ErasableHierarchyGraph:public HierarchyGraph < Gact,
|
hegyi@691
|
550 |
Gsub
|
hegyi@691
|
551 |
>
|
hegyi@677
|
552 |
{
|
hegyi@677
|
553 |
public:
|
hegyi@677
|
554 |
/// Deletes a node.
|
hegyi@691
|
555 |
void erase (typename Gact::Node n)
|
hegyi@691
|
556 |
{
|
hegyi@691
|
557 |
actuallayer.erase (n);
|
hegyi@691
|
558 |
}
|
hegyi@677
|
559 |
/// Deletes an edge.
|
hegyi@691
|
560 |
void erase (typename Gact::Edge e)
|
hegyi@691
|
561 |
{
|
hegyi@691
|
562 |
actuallayer.erase (e);
|
hegyi@691
|
563 |
}
|
hegyi@677
|
564 |
|
hegyi@677
|
565 |
/// Defalult constructor.
|
alpar@826
|
566 |
ErasableHierarchyGraph ()
|
hegyi@691
|
567 |
{
|
hegyi@691
|
568 |
}
|
hegyi@677
|
569 |
///Copy consructor.
|
alpar@826
|
570 |
ErasableHierarchyGraph (const HierarchyGraph < Gact, Gsub > &EPG)
|
hegyi@691
|
571 |
{
|
hegyi@691
|
572 |
}
|
hegyi@677
|
573 |
};
|
hegyi@677
|
574 |
|
hegyi@690
|
575 |
|
hegyi@677
|
576 |
// @}
|
hegyi@677
|
577 |
|
alpar@921
|
578 |
} //namespace lemon
|
hegyi@677
|
579 |
|
hegyi@677
|
580 |
|
alpar@921
|
581 |
#endif // LEMON_SKELETON_GRAPH_H
|