... | ... |
@@ -238,256 +238,268 @@ |
238 | 238 |
void erase(const Arc& arc) { |
239 | 239 |
int n = arc.id; |
240 | 240 |
|
241 | 241 |
if(arcs[n].next_in!=-1) { |
242 | 242 |
arcs[arcs[n].next_in].prev_in = arcs[n].prev_in; |
243 | 243 |
} |
244 | 244 |
|
245 | 245 |
if(arcs[n].prev_in!=-1) { |
246 | 246 |
arcs[arcs[n].prev_in].next_in = arcs[n].next_in; |
247 | 247 |
} else { |
248 | 248 |
nodes[arcs[n].target].first_in = arcs[n].next_in; |
249 | 249 |
} |
250 | 250 |
|
251 | 251 |
|
252 | 252 |
if(arcs[n].next_out!=-1) { |
253 | 253 |
arcs[arcs[n].next_out].prev_out = arcs[n].prev_out; |
254 | 254 |
} |
255 | 255 |
|
256 | 256 |
if(arcs[n].prev_out!=-1) { |
257 | 257 |
arcs[arcs[n].prev_out].next_out = arcs[n].next_out; |
258 | 258 |
} else { |
259 | 259 |
nodes[arcs[n].source].first_out = arcs[n].next_out; |
260 | 260 |
} |
261 | 261 |
|
262 | 262 |
arcs[n].next_in = first_free_arc; |
263 | 263 |
first_free_arc = n; |
264 | 264 |
arcs[n].prev_in = -2; |
265 | 265 |
} |
266 | 266 |
|
267 | 267 |
void clear() { |
268 | 268 |
arcs.clear(); |
269 | 269 |
nodes.clear(); |
270 | 270 |
first_node = first_free_node = first_free_arc = -1; |
271 | 271 |
} |
272 | 272 |
|
273 | 273 |
protected: |
274 | 274 |
void changeTarget(Arc e, Node n) |
275 | 275 |
{ |
276 | 276 |
if(arcs[e.id].next_in != -1) |
277 | 277 |
arcs[arcs[e.id].next_in].prev_in = arcs[e.id].prev_in; |
278 | 278 |
if(arcs[e.id].prev_in != -1) |
279 | 279 |
arcs[arcs[e.id].prev_in].next_in = arcs[e.id].next_in; |
280 | 280 |
else nodes[arcs[e.id].target].first_in = arcs[e.id].next_in; |
281 | 281 |
if (nodes[n.id].first_in != -1) { |
282 | 282 |
arcs[nodes[n.id].first_in].prev_in = e.id; |
283 | 283 |
} |
284 | 284 |
arcs[e.id].target = n.id; |
285 | 285 |
arcs[e.id].prev_in = -1; |
286 | 286 |
arcs[e.id].next_in = nodes[n.id].first_in; |
287 | 287 |
nodes[n.id].first_in = e.id; |
288 | 288 |
} |
289 | 289 |
void changeSource(Arc e, Node n) |
290 | 290 |
{ |
291 | 291 |
if(arcs[e.id].next_out != -1) |
292 | 292 |
arcs[arcs[e.id].next_out].prev_out = arcs[e.id].prev_out; |
293 | 293 |
if(arcs[e.id].prev_out != -1) |
294 | 294 |
arcs[arcs[e.id].prev_out].next_out = arcs[e.id].next_out; |
295 | 295 |
else nodes[arcs[e.id].source].first_out = arcs[e.id].next_out; |
296 | 296 |
if (nodes[n.id].first_out != -1) { |
297 | 297 |
arcs[nodes[n.id].first_out].prev_out = e.id; |
298 | 298 |
} |
299 | 299 |
arcs[e.id].source = n.id; |
300 | 300 |
arcs[e.id].prev_out = -1; |
301 | 301 |
arcs[e.id].next_out = nodes[n.id].first_out; |
302 | 302 |
nodes[n.id].first_out = e.id; |
303 | 303 |
} |
304 | 304 |
|
305 | 305 |
}; |
306 | 306 |
|
307 | 307 |
typedef DigraphExtender<ListDigraphBase> ExtendedListDigraphBase; |
308 | 308 |
|
309 | 309 |
/// \addtogroup graphs |
310 | 310 |
/// @{ |
311 | 311 |
|
312 | 312 |
///A general directed graph structure. |
313 | 313 |
|
314 | 314 |
///\ref ListDigraph is a simple and fast <em>directed graph</em> |
315 | 315 |
///implementation based on static linked lists that are stored in |
316 | 316 |
///\c std::vector structures. |
317 | 317 |
/// |
318 | 318 |
///It conforms to the \ref concepts::Digraph "Digraph concept" and it |
319 | 319 |
///also provides several useful additional functionalities. |
320 | 320 |
///Most of the member functions and nested classes are documented |
321 | 321 |
///only in the concept class. |
322 | 322 |
/// |
323 | 323 |
///An important extra feature of this digraph implementation is that |
324 | 324 |
///its maps are real \ref concepts::ReferenceMap "reference map"s. |
325 | 325 |
/// |
326 | 326 |
///\sa concepts::Digraph |
327 | 327 |
|
328 | 328 |
class ListDigraph : public ExtendedListDigraphBase { |
329 | 329 |
private: |
330 | 330 |
///ListDigraph is \e not copy constructible. Use copyDigraph() instead. |
331 | 331 |
|
332 | 332 |
///ListDigraph is \e not copy constructible. Use copyDigraph() instead. |
333 | 333 |
/// |
334 | 334 |
ListDigraph(const ListDigraph &) :ExtendedListDigraphBase() {}; |
335 | 335 |
///\brief Assignment of ListDigraph to another one is \e not allowed. |
336 | 336 |
///Use copyDigraph() instead. |
337 | 337 |
|
338 | 338 |
///Assignment of ListDigraph to another one is \e not allowed. |
339 | 339 |
///Use copyDigraph() instead. |
340 | 340 |
void operator=(const ListDigraph &) {} |
341 | 341 |
public: |
342 | 342 |
|
343 | 343 |
typedef ExtendedListDigraphBase Parent; |
344 | 344 |
|
345 | 345 |
/// Constructor |
346 | 346 |
|
347 | 347 |
/// Constructor. |
348 | 348 |
/// |
349 | 349 |
ListDigraph() {} |
350 | 350 |
|
351 | 351 |
///Add a new node to the digraph. |
352 | 352 |
|
353 | 353 |
///Add a new node to the digraph. |
354 | 354 |
///\return the new node. |
355 | 355 |
Node addNode() { return Parent::addNode(); } |
356 | 356 |
|
357 | 357 |
///Add a new arc to the digraph. |
358 | 358 |
|
359 | 359 |
///Add a new arc to the digraph with source node \c s |
360 | 360 |
///and target node \c t. |
361 | 361 |
///\return the new arc. |
362 | 362 |
Arc addArc(const Node& s, const Node& t) { |
363 | 363 |
return Parent::addArc(s, t); |
364 | 364 |
} |
365 | 365 |
|
366 |
///\brief Erase a node from the digraph. |
|
367 |
/// |
|
368 |
///Erase a node from the digraph. |
|
369 |
/// |
|
370 |
void erase(const Node& n) { Parent::erase(n); } |
|
371 |
|
|
372 |
///\brief Erase an arc from the digraph. |
|
373 |
/// |
|
374 |
///Erase an arc from the digraph. |
|
375 |
/// |
|
376 |
void erase(const Arc& a) { Parent::erase(a); } |
|
377 |
|
|
366 | 378 |
/// Node validity check |
367 | 379 |
|
368 | 380 |
/// This function gives back true if the given node is valid, |
369 | 381 |
/// ie. it is a real node of the graph. |
370 | 382 |
/// |
371 | 383 |
/// \warning A Node pointing to a removed item |
372 | 384 |
/// could become valid again later if new nodes are |
373 | 385 |
/// added to the graph. |
374 | 386 |
bool valid(Node n) const { return Parent::valid(n); } |
375 | 387 |
|
376 | 388 |
/// Arc validity check |
377 | 389 |
|
378 | 390 |
/// This function gives back true if the given arc is valid, |
379 | 391 |
/// ie. it is a real arc of the graph. |
380 | 392 |
/// |
381 | 393 |
/// \warning An Arc pointing to a removed item |
382 | 394 |
/// could become valid again later if new nodes are |
383 | 395 |
/// added to the graph. |
384 | 396 |
bool valid(Arc a) const { return Parent::valid(a); } |
385 | 397 |
|
386 | 398 |
/// Change the target of \c e to \c n |
387 | 399 |
|
388 | 400 |
/// Change the target of \c e to \c n |
389 | 401 |
/// |
390 | 402 |
///\note The <tt>ArcIt</tt>s and <tt>OutArcIt</tt>s referencing |
391 | 403 |
///the changed arc remain valid. However <tt>InArcIt</tt>s are |
392 | 404 |
///invalidated. |
393 | 405 |
/// |
394 | 406 |
///\warning This functionality cannot be used together with the Snapshot |
395 | 407 |
///feature. |
396 | 408 |
void changeTarget(Arc e, Node n) { |
397 | 409 |
Parent::changeTarget(e,n); |
398 | 410 |
} |
399 | 411 |
/// Change the source of \c e to \c n |
400 | 412 |
|
401 | 413 |
/// Change the source of \c e to \c n |
402 | 414 |
/// |
403 | 415 |
///\note The <tt>ArcIt</tt>s and <tt>InArcIt</tt>s referencing |
404 | 416 |
///the changed arc remain valid. However <tt>OutArcIt</tt>s are |
405 | 417 |
///invalidated. |
406 | 418 |
/// |
407 | 419 |
///\warning This functionality cannot be used together with the Snapshot |
408 | 420 |
///feature. |
409 | 421 |
void changeSource(Arc e, Node n) { |
410 | 422 |
Parent::changeSource(e,n); |
411 | 423 |
} |
412 | 424 |
|
413 | 425 |
/// Invert the direction of an arc. |
414 | 426 |
|
415 | 427 |
///\note The <tt>ArcIt</tt>s referencing the changed arc remain |
416 | 428 |
///valid. However <tt>OutArcIt</tt>s and <tt>InArcIt</tt>s are |
417 | 429 |
///invalidated. |
418 | 430 |
/// |
419 | 431 |
///\warning This functionality cannot be used together with the Snapshot |
420 | 432 |
///feature. |
421 | 433 |
void reverseArc(Arc e) { |
422 | 434 |
Node t=target(e); |
423 | 435 |
changeTarget(e,source(e)); |
424 | 436 |
changeSource(e,t); |
425 | 437 |
} |
426 | 438 |
|
427 | 439 |
/// Reserve memory for nodes. |
428 | 440 |
|
429 | 441 |
/// Using this function it is possible to avoid the superfluous memory |
430 | 442 |
/// allocation: if you know that the digraph you want to build will |
431 | 443 |
/// be very large (e.g. it will contain millions of nodes and/or arcs) |
432 | 444 |
/// then it is worth reserving space for this amount before starting |
433 | 445 |
/// to build the digraph. |
434 | 446 |
/// \sa reserveArc |
435 | 447 |
void reserveNode(int n) { nodes.reserve(n); }; |
436 | 448 |
|
437 | 449 |
/// Reserve memory for arcs. |
438 | 450 |
|
439 | 451 |
/// Using this function it is possible to avoid the superfluous memory |
440 | 452 |
/// allocation: if you know that the digraph you want to build will |
441 | 453 |
/// be very large (e.g. it will contain millions of nodes and/or arcs) |
442 | 454 |
/// then it is worth reserving space for this amount before starting |
443 | 455 |
/// to build the digraph. |
444 | 456 |
/// \sa reserveNode |
445 | 457 |
void reserveArc(int m) { arcs.reserve(m); }; |
446 | 458 |
|
447 | 459 |
///Contract two nodes. |
448 | 460 |
|
449 | 461 |
///This function contracts two nodes. |
450 | 462 |
///Node \p b will be removed but instead of deleting |
451 | 463 |
///incident arcs, they will be joined to \p a. |
452 | 464 |
///The last parameter \p r controls whether to remove loops. \c true |
453 | 465 |
///means that loops will be removed. |
454 | 466 |
/// |
455 | 467 |
///\note The <tt>ArcIt</tt>s referencing a moved arc remain |
456 | 468 |
///valid. However <tt>InArcIt</tt>s and <tt>OutArcIt</tt>s |
457 | 469 |
///may be invalidated. |
458 | 470 |
/// |
459 | 471 |
///\warning This functionality cannot be used together with the Snapshot |
460 | 472 |
///feature. |
461 | 473 |
void contract(Node a, Node b, bool r = true) |
462 | 474 |
{ |
463 | 475 |
for(OutArcIt e(*this,b);e!=INVALID;) { |
464 | 476 |
OutArcIt f=e; |
465 | 477 |
++f; |
466 | 478 |
if(r && target(e)==a) erase(e); |
467 | 479 |
else changeSource(e,a); |
468 | 480 |
e=f; |
469 | 481 |
} |
470 | 482 |
for(InArcIt e(*this,b);e!=INVALID;) { |
471 | 483 |
InArcIt f=e; |
472 | 484 |
++f; |
473 | 485 |
if(r && source(e)==a) erase(e); |
474 | 486 |
else changeTarget(e,a); |
475 | 487 |
e=f; |
476 | 488 |
} |
477 | 489 |
erase(b); |
478 | 490 |
} |
479 | 491 |
|
480 | 492 |
///Split a node. |
481 | 493 |
|
482 | 494 |
///This function splits a node. First a new node is added to the digraph, |
483 | 495 |
///then the source of each outgoing arc of \c n is moved to this new node. |
484 | 496 |
///If \c connect is \c true (this is the default value), then a new arc |
485 | 497 |
///from \c n to the newly created node is also added. |
486 | 498 |
///\return The newly created node. |
487 | 499 |
/// |
488 | 500 |
///\note The <tt>ArcIt</tt>s referencing a moved arc remain |
489 | 501 |
///valid. However <tt>InArcIt</tt>s and <tt>OutArcIt</tt>s may |
490 | 502 |
///be invalidated. |
491 | 503 |
/// |
492 | 504 |
///\warning This functionality cannot be used together with the |
493 | 505 |
///Snapshot feature. |
... | ... |
@@ -1082,256 +1094,268 @@ |
1082 | 1094 |
} |
1083 | 1095 |
|
1084 | 1096 |
if (arcs[n | 1].prev_out != -1) { |
1085 | 1097 |
arcs[arcs[n | 1].prev_out].next_out = arcs[n | 1].next_out; |
1086 | 1098 |
} else { |
1087 | 1099 |
nodes[arcs[n].target].first_out = arcs[n | 1].next_out; |
1088 | 1100 |
} |
1089 | 1101 |
|
1090 | 1102 |
arcs[n].next_out = first_free_arc; |
1091 | 1103 |
first_free_arc = n; |
1092 | 1104 |
arcs[n].prev_out = -2; |
1093 | 1105 |
arcs[n | 1].prev_out = -2; |
1094 | 1106 |
|
1095 | 1107 |
} |
1096 | 1108 |
|
1097 | 1109 |
void clear() { |
1098 | 1110 |
arcs.clear(); |
1099 | 1111 |
nodes.clear(); |
1100 | 1112 |
first_node = first_free_node = first_free_arc = -1; |
1101 | 1113 |
} |
1102 | 1114 |
|
1103 | 1115 |
protected: |
1104 | 1116 |
|
1105 | 1117 |
void changeTarget(Edge e, Node n) { |
1106 | 1118 |
if(arcs[2 * e.id].next_out != -1) { |
1107 | 1119 |
arcs[arcs[2 * e.id].next_out].prev_out = arcs[2 * e.id].prev_out; |
1108 | 1120 |
} |
1109 | 1121 |
if(arcs[2 * e.id].prev_out != -1) { |
1110 | 1122 |
arcs[arcs[2 * e.id].prev_out].next_out = |
1111 | 1123 |
arcs[2 * e.id].next_out; |
1112 | 1124 |
} else { |
1113 | 1125 |
nodes[arcs[(2 * e.id) | 1].target].first_out = |
1114 | 1126 |
arcs[2 * e.id].next_out; |
1115 | 1127 |
} |
1116 | 1128 |
|
1117 | 1129 |
if (nodes[n.id].first_out != -1) { |
1118 | 1130 |
arcs[nodes[n.id].first_out].prev_out = 2 * e.id; |
1119 | 1131 |
} |
1120 | 1132 |
arcs[(2 * e.id) | 1].target = n.id; |
1121 | 1133 |
arcs[2 * e.id].prev_out = -1; |
1122 | 1134 |
arcs[2 * e.id].next_out = nodes[n.id].first_out; |
1123 | 1135 |
nodes[n.id].first_out = 2 * e.id; |
1124 | 1136 |
} |
1125 | 1137 |
|
1126 | 1138 |
void changeSource(Edge e, Node n) { |
1127 | 1139 |
if(arcs[(2 * e.id) | 1].next_out != -1) { |
1128 | 1140 |
arcs[arcs[(2 * e.id) | 1].next_out].prev_out = |
1129 | 1141 |
arcs[(2 * e.id) | 1].prev_out; |
1130 | 1142 |
} |
1131 | 1143 |
if(arcs[(2 * e.id) | 1].prev_out != -1) { |
1132 | 1144 |
arcs[arcs[(2 * e.id) | 1].prev_out].next_out = |
1133 | 1145 |
arcs[(2 * e.id) | 1].next_out; |
1134 | 1146 |
} else { |
1135 | 1147 |
nodes[arcs[2 * e.id].target].first_out = |
1136 | 1148 |
arcs[(2 * e.id) | 1].next_out; |
1137 | 1149 |
} |
1138 | 1150 |
|
1139 | 1151 |
if (nodes[n.id].first_out != -1) { |
1140 | 1152 |
arcs[nodes[n.id].first_out].prev_out = ((2 * e.id) | 1); |
1141 | 1153 |
} |
1142 | 1154 |
arcs[2 * e.id].target = n.id; |
1143 | 1155 |
arcs[(2 * e.id) | 1].prev_out = -1; |
1144 | 1156 |
arcs[(2 * e.id) | 1].next_out = nodes[n.id].first_out; |
1145 | 1157 |
nodes[n.id].first_out = ((2 * e.id) | 1); |
1146 | 1158 |
} |
1147 | 1159 |
|
1148 | 1160 |
}; |
1149 | 1161 |
|
1150 | 1162 |
typedef GraphExtender<ListGraphBase> ExtendedListGraphBase; |
1151 | 1163 |
|
1152 | 1164 |
|
1153 | 1165 |
/// \addtogroup graphs |
1154 | 1166 |
/// @{ |
1155 | 1167 |
|
1156 | 1168 |
///A general undirected graph structure. |
1157 | 1169 |
|
1158 | 1170 |
///\ref ListGraph is a simple and fast <em>undirected graph</em> |
1159 | 1171 |
///implementation based on static linked lists that are stored in |
1160 | 1172 |
///\c std::vector structures. |
1161 | 1173 |
/// |
1162 | 1174 |
///It conforms to the \ref concepts::Graph "Graph concept" and it |
1163 | 1175 |
///also provides several useful additional functionalities. |
1164 | 1176 |
///Most of the member functions and nested classes are documented |
1165 | 1177 |
///only in the concept class. |
1166 | 1178 |
/// |
1167 | 1179 |
///An important extra feature of this graph implementation is that |
1168 | 1180 |
///its maps are real \ref concepts::ReferenceMap "reference map"s. |
1169 | 1181 |
/// |
1170 | 1182 |
///\sa concepts::Graph |
1171 | 1183 |
|
1172 | 1184 |
class ListGraph : public ExtendedListGraphBase { |
1173 | 1185 |
private: |
1174 | 1186 |
///ListGraph is \e not copy constructible. Use copyGraph() instead. |
1175 | 1187 |
|
1176 | 1188 |
///ListGraph is \e not copy constructible. Use copyGraph() instead. |
1177 | 1189 |
/// |
1178 | 1190 |
ListGraph(const ListGraph &) :ExtendedListGraphBase() {}; |
1179 | 1191 |
///\brief Assignment of ListGraph to another one is \e not allowed. |
1180 | 1192 |
///Use copyGraph() instead. |
1181 | 1193 |
|
1182 | 1194 |
///Assignment of ListGraph to another one is \e not allowed. |
1183 | 1195 |
///Use copyGraph() instead. |
1184 | 1196 |
void operator=(const ListGraph &) {} |
1185 | 1197 |
public: |
1186 | 1198 |
/// Constructor |
1187 | 1199 |
|
1188 | 1200 |
/// Constructor. |
1189 | 1201 |
/// |
1190 | 1202 |
ListGraph() {} |
1191 | 1203 |
|
1192 | 1204 |
typedef ExtendedListGraphBase Parent; |
1193 | 1205 |
|
1194 | 1206 |
typedef Parent::OutArcIt IncEdgeIt; |
1195 | 1207 |
|
1196 | 1208 |
/// \brief Add a new node to the graph. |
1197 | 1209 |
/// |
1198 | 1210 |
/// Add a new node to the graph. |
1199 | 1211 |
/// \return the new node. |
1200 | 1212 |
Node addNode() { return Parent::addNode(); } |
1201 | 1213 |
|
1202 | 1214 |
/// \brief Add a new edge to the graph. |
1203 | 1215 |
/// |
1204 | 1216 |
/// Add a new edge to the graph with source node \c s |
1205 | 1217 |
/// and target node \c t. |
1206 | 1218 |
/// \return the new edge. |
1207 | 1219 |
Edge addEdge(const Node& s, const Node& t) { |
1208 | 1220 |
return Parent::addEdge(s, t); |
1209 | 1221 |
} |
1222 |
|
|
1223 |
/// \brief Erase a node from the graph. |
|
1224 |
/// |
|
1225 |
/// Erase a node from the graph. |
|
1226 |
/// |
|
1227 |
void erase(const Node& n) { Parent::erase(n); } |
|
1228 |
|
|
1229 |
/// \brief Erase an edge from the graph. |
|
1230 |
/// |
|
1231 |
/// Erase an edge from the graph. |
|
1232 |
/// |
|
1233 |
void erase(const Edge& e) { Parent::erase(e); } |
|
1210 | 1234 |
/// Node validity check |
1211 | 1235 |
|
1212 | 1236 |
/// This function gives back true if the given node is valid, |
1213 | 1237 |
/// ie. it is a real node of the graph. |
1214 | 1238 |
/// |
1215 | 1239 |
/// \warning A Node pointing to a removed item |
1216 | 1240 |
/// could become valid again later if new nodes are |
1217 | 1241 |
/// added to the graph. |
1218 | 1242 |
bool valid(Node n) const { return Parent::valid(n); } |
1219 | 1243 |
/// Arc validity check |
1220 | 1244 |
|
1221 | 1245 |
/// This function gives back true if the given arc is valid, |
1222 | 1246 |
/// ie. it is a real arc of the graph. |
1223 | 1247 |
/// |
1224 | 1248 |
/// \warning An Arc pointing to a removed item |
1225 | 1249 |
/// could become valid again later if new edges are |
1226 | 1250 |
/// added to the graph. |
1227 | 1251 |
bool valid(Arc a) const { return Parent::valid(a); } |
1228 | 1252 |
/// Edge validity check |
1229 | 1253 |
|
1230 | 1254 |
/// This function gives back true if the given edge is valid, |
1231 | 1255 |
/// ie. it is a real arc of the graph. |
1232 | 1256 |
/// |
1233 | 1257 |
/// \warning A Edge pointing to a removed item |
1234 | 1258 |
/// could become valid again later if new edges are |
1235 | 1259 |
/// added to the graph. |
1236 | 1260 |
bool valid(Edge e) const { return Parent::valid(e); } |
1237 | 1261 |
/// \brief Change the source of \c e to \c n |
1238 | 1262 |
/// |
1239 | 1263 |
/// This function changes the source of \c e to \c n. |
1240 | 1264 |
/// |
1241 | 1265 |
///\note The <tt>ArcIt</tt>s and <tt>InArcIt</tt>s |
1242 | 1266 |
///referencing the changed arc remain |
1243 | 1267 |
///valid. However <tt>OutArcIt</tt>s are invalidated. |
1244 | 1268 |
/// |
1245 | 1269 |
///\warning This functionality cannot be used together with the |
1246 | 1270 |
///Snapshot feature. |
1247 | 1271 |
void changeSource(Edge e, Node n) { |
1248 | 1272 |
Parent::changeSource(e,n); |
1249 | 1273 |
} |
1250 | 1274 |
/// \brief Change the target of \c e to \c n |
1251 | 1275 |
/// |
1252 | 1276 |
/// This function changes the target of \c e to \c n. |
1253 | 1277 |
/// |
1254 | 1278 |
/// \note The <tt>ArcIt</tt>s referencing the changed arc remain |
1255 | 1279 |
/// valid. However the other iterators may be invalidated. |
1256 | 1280 |
/// |
1257 | 1281 |
///\warning This functionality cannot be used together with the |
1258 | 1282 |
///Snapshot feature. |
1259 | 1283 |
void changeTarget(Edge e, Node n) { |
1260 | 1284 |
Parent::changeTarget(e,n); |
1261 | 1285 |
} |
1262 | 1286 |
/// \brief Change the source of \c e to \c n |
1263 | 1287 |
/// |
1264 | 1288 |
/// This function changes the source of \c e to \c n. |
1265 | 1289 |
/// It also changes the proper node of the represented edge. |
1266 | 1290 |
/// |
1267 | 1291 |
///\note The <tt>ArcIt</tt>s and <tt>InArcIt</tt>s |
1268 | 1292 |
///referencing the changed arc remain |
1269 | 1293 |
///valid. However <tt>OutArcIt</tt>s are invalidated. |
1270 | 1294 |
/// |
1271 | 1295 |
///\warning This functionality cannot be used together with the |
1272 | 1296 |
///Snapshot feature. |
1273 | 1297 |
void changeSource(Arc e, Node n) { |
1274 | 1298 |
if (Parent::direction(e)) { |
1275 | 1299 |
Parent::changeSource(e,n); |
1276 | 1300 |
} else { |
1277 | 1301 |
Parent::changeTarget(e,n); |
1278 | 1302 |
} |
1279 | 1303 |
} |
1280 | 1304 |
/// \brief Change the target of \c e to \c n |
1281 | 1305 |
/// |
1282 | 1306 |
/// This function changes the target of \c e to \c n. |
1283 | 1307 |
/// It also changes the proper node of the represented edge. |
1284 | 1308 |
/// |
1285 | 1309 |
///\note The <tt>ArcIt</tt>s and <tt>OutArcIt</tt>s |
1286 | 1310 |
///referencing the changed arc remain |
1287 | 1311 |
///valid. However <tt>InArcIt</tt>s are invalidated. |
1288 | 1312 |
/// |
1289 | 1313 |
///\warning This functionality cannot be used together with the |
1290 | 1314 |
///Snapshot feature. |
1291 | 1315 |
void changeTarget(Arc e, Node n) { |
1292 | 1316 |
if (Parent::direction(e)) { |
1293 | 1317 |
Parent::changeTarget(e,n); |
1294 | 1318 |
} else { |
1295 | 1319 |
Parent::changeSource(e,n); |
1296 | 1320 |
} |
1297 | 1321 |
} |
1298 | 1322 |
/// \brief Contract two nodes. |
1299 | 1323 |
/// |
1300 | 1324 |
/// This function contracts two nodes. |
1301 | 1325 |
/// Node \p b will be removed but instead of deleting |
1302 | 1326 |
/// its neighboring arcs, they will be joined to \p a. |
1303 | 1327 |
/// The last parameter \p r controls whether to remove loops. \c true |
1304 | 1328 |
/// means that loops will be removed. |
1305 | 1329 |
/// |
1306 | 1330 |
/// \note The <tt>ArcIt</tt>s referencing a moved arc remain |
1307 | 1331 |
/// valid. |
1308 | 1332 |
/// |
1309 | 1333 |
///\warning This functionality cannot be used together with the |
1310 | 1334 |
///Snapshot feature. |
1311 | 1335 |
void contract(Node a, Node b, bool r = true) { |
1312 | 1336 |
for(IncEdgeIt e(*this, b); e!=INVALID;) { |
1313 | 1337 |
IncEdgeIt f = e; ++f; |
1314 | 1338 |
if (r && runningNode(e) == a) { |
1315 | 1339 |
erase(e); |
1316 | 1340 |
} else if (source(e) == b) { |
1317 | 1341 |
changeSource(e, a); |
1318 | 1342 |
} else { |
1319 | 1343 |
changeTarget(e, a); |
1320 | 1344 |
} |
1321 | 1345 |
e = f; |
1322 | 1346 |
} |
1323 | 1347 |
erase(b); |
1324 | 1348 |
} |
1325 | 1349 |
|
1326 | 1350 |
|
1327 | 1351 |
/// \brief Class to make a snapshot of the graph and restore |
1328 | 1352 |
/// it later. |
1329 | 1353 |
/// |
1330 | 1354 |
/// Class to make a snapshot of the graph and restore it later. |
1331 | 1355 |
/// |
1332 | 1356 |
/// The newly added nodes and edges can be removed |
1333 | 1357 |
/// using the restore() function. |
1334 | 1358 |
/// |
1335 | 1359 |
/// \warning Edge and node deletions and other modifications |
1336 | 1360 |
/// (e.g. changing nodes of edges, contracting nodes) cannot be |
1337 | 1361 |
/// restored. These events invalidate the snapshot. |
0 comments (0 inline)