... | ... |
@@ -400,96 +400,115 @@ |
400 | 400 |
for (typename From::ArcIt it(from); it != INVALID; ++it) { |
401 | 401 |
arcRefMap[it] = to.addArc(nodeRefMap[from.source(it)], |
402 | 402 |
nodeRefMap[from.target(it)]); |
403 | 403 |
} |
404 | 404 |
} |
405 | 405 |
}; |
406 | 406 |
|
407 | 407 |
template <typename Digraph> |
408 | 408 |
struct DigraphCopySelector< |
409 | 409 |
Digraph, |
410 | 410 |
typename enable_if<typename Digraph::BuildTag, void>::type> |
411 | 411 |
{ |
412 | 412 |
template <typename From, typename NodeRefMap, typename ArcRefMap> |
413 | 413 |
static void copy(const From& from, Digraph &to, |
414 | 414 |
NodeRefMap& nodeRefMap, ArcRefMap& arcRefMap) { |
415 | 415 |
to.build(from, nodeRefMap, arcRefMap); |
416 | 416 |
} |
417 | 417 |
}; |
418 | 418 |
|
419 | 419 |
template <typename Graph, typename Enable = void> |
420 | 420 |
struct GraphCopySelector { |
421 | 421 |
template <typename From, typename NodeRefMap, typename EdgeRefMap> |
422 | 422 |
static void copy(const From& from, Graph &to, |
423 | 423 |
NodeRefMap& nodeRefMap, EdgeRefMap& edgeRefMap) { |
424 | 424 |
for (typename From::NodeIt it(from); it != INVALID; ++it) { |
425 | 425 |
nodeRefMap[it] = to.addNode(); |
426 | 426 |
} |
427 | 427 |
for (typename From::EdgeIt it(from); it != INVALID; ++it) { |
428 | 428 |
edgeRefMap[it] = to.addEdge(nodeRefMap[from.u(it)], |
429 | 429 |
nodeRefMap[from.v(it)]); |
430 | 430 |
} |
431 | 431 |
} |
432 | 432 |
}; |
433 | 433 |
|
434 | 434 |
template <typename Graph> |
435 | 435 |
struct GraphCopySelector< |
436 | 436 |
Graph, |
437 | 437 |
typename enable_if<typename Graph::BuildTag, void>::type> |
438 | 438 |
{ |
439 | 439 |
template <typename From, typename NodeRefMap, typename EdgeRefMap> |
440 | 440 |
static void copy(const From& from, Graph &to, |
441 | 441 |
NodeRefMap& nodeRefMap, EdgeRefMap& edgeRefMap) { |
442 | 442 |
to.build(from, nodeRefMap, edgeRefMap); |
443 | 443 |
} |
444 | 444 |
}; |
445 | 445 |
|
446 | 446 |
} |
447 | 447 |
|
448 |
/// Check whether a graph is undirected. |
|
449 |
/// |
|
450 |
/// This function returns \c true if the given graph is undirected. |
|
451 |
#ifdef DOXYGEN |
|
452 |
template <typename GR> |
|
453 |
bool undirected(const GR& g) { return false; } |
|
454 |
#else |
|
455 |
template <typename GR> |
|
456 |
typename enable_if<UndirectedTagIndicator<GR>, bool>::type |
|
457 |
undirected(const GR&) { |
|
458 |
return true; |
|
459 |
} |
|
460 |
template <typename GR> |
|
461 |
typename disable_if<UndirectedTagIndicator<GR>, bool>::type |
|
462 |
undirected(const GR&) { |
|
463 |
return false; |
|
464 |
} |
|
465 |
#endif |
|
466 |
|
|
448 | 467 |
/// \brief Class to copy a digraph. |
449 | 468 |
/// |
450 | 469 |
/// Class to copy a digraph to another digraph (duplicate a digraph). The |
451 | 470 |
/// simplest way of using it is through the \c digraphCopy() function. |
452 | 471 |
/// |
453 | 472 |
/// This class not only make a copy of a digraph, but it can create |
454 | 473 |
/// references and cross references between the nodes and arcs of |
455 | 474 |
/// the two digraphs, and it can copy maps to use with the newly created |
456 | 475 |
/// digraph. |
457 | 476 |
/// |
458 | 477 |
/// To make a copy from a digraph, first an instance of DigraphCopy |
459 | 478 |
/// should be created, then the data belongs to the digraph should |
460 | 479 |
/// assigned to copy. In the end, the \c run() member should be |
461 | 480 |
/// called. |
462 | 481 |
/// |
463 | 482 |
/// The next code copies a digraph with several data: |
464 | 483 |
///\code |
465 | 484 |
/// DigraphCopy<OrigGraph, NewGraph> cg(orig_graph, new_graph); |
466 | 485 |
/// // Create references for the nodes |
467 | 486 |
/// OrigGraph::NodeMap<NewGraph::Node> nr(orig_graph); |
468 | 487 |
/// cg.nodeRef(nr); |
469 | 488 |
/// // Create cross references (inverse) for the arcs |
470 | 489 |
/// NewGraph::ArcMap<OrigGraph::Arc> acr(new_graph); |
471 | 490 |
/// cg.arcCrossRef(acr); |
472 | 491 |
/// // Copy an arc map |
473 | 492 |
/// OrigGraph::ArcMap<double> oamap(orig_graph); |
474 | 493 |
/// NewGraph::ArcMap<double> namap(new_graph); |
475 | 494 |
/// cg.arcMap(oamap, namap); |
476 | 495 |
/// // Copy a node |
477 | 496 |
/// OrigGraph::Node on; |
478 | 497 |
/// NewGraph::Node nn; |
479 | 498 |
/// cg.node(on, nn); |
480 | 499 |
/// // Execute copying |
481 | 500 |
/// cg.run(); |
482 | 501 |
///\endcode |
483 | 502 |
template <typename From, typename To> |
484 | 503 |
class DigraphCopy { |
485 | 504 |
private: |
486 | 505 |
|
487 | 506 |
typedef typename From::Node Node; |
488 | 507 |
typedef typename From::NodeIt NodeIt; |
489 | 508 |
typedef typename From::Arc Arc; |
490 | 509 |
typedef typename From::ArcIt ArcIt; |
491 | 510 |
|
492 | 511 |
typedef typename To::Node TNode; |
493 | 512 |
typedef typename To::Arc TArc; |
494 | 513 |
|
495 | 514 |
typedef typename From::template NodeMap<TNode> NodeRefMap; |
0 comments (0 inline)