| ... | ... |
@@ -557,124 +557,124 @@ |
| 557 | 557 |
Item _item; |
| 558 | 558 |
}; |
| 559 | 559 |
|
| 560 | 560 |
template <typename Digraph, typename Item, typename RefMap, typename Ref> |
| 561 | 561 |
class RefCopy : public MapCopyBase<Digraph, Item, RefMap> {
|
| 562 | 562 |
public: |
| 563 | 563 |
|
| 564 | 564 |
RefCopy(Ref& map) : _map(map) {}
|
| 565 | 565 |
|
| 566 | 566 |
virtual void copy(const Digraph& digraph, const RefMap& refMap) {
|
| 567 | 567 |
typedef typename ItemSetTraits<Digraph, Item>::ItemIt ItemIt; |
| 568 | 568 |
for (ItemIt it(digraph); it != INVALID; ++it) {
|
| 569 | 569 |
_map.set(it, refMap[it]); |
| 570 | 570 |
} |
| 571 | 571 |
} |
| 572 | 572 |
|
| 573 | 573 |
private: |
| 574 | 574 |
Ref& _map; |
| 575 | 575 |
}; |
| 576 | 576 |
|
| 577 | 577 |
template <typename Digraph, typename Item, typename RefMap, |
| 578 | 578 |
typename CrossRef> |
| 579 | 579 |
class CrossRefCopy : public MapCopyBase<Digraph, Item, RefMap> {
|
| 580 | 580 |
public: |
| 581 | 581 |
|
| 582 | 582 |
CrossRefCopy(CrossRef& cmap) : _cmap(cmap) {}
|
| 583 | 583 |
|
| 584 | 584 |
virtual void copy(const Digraph& digraph, const RefMap& refMap) {
|
| 585 | 585 |
typedef typename ItemSetTraits<Digraph, Item>::ItemIt ItemIt; |
| 586 | 586 |
for (ItemIt it(digraph); it != INVALID; ++it) {
|
| 587 | 587 |
_cmap.set(refMap[it], it); |
| 588 | 588 |
} |
| 589 | 589 |
} |
| 590 | 590 |
|
| 591 | 591 |
private: |
| 592 | 592 |
CrossRef& _cmap; |
| 593 | 593 |
}; |
| 594 | 594 |
|
| 595 | 595 |
template <typename Digraph, typename Enable = void> |
| 596 | 596 |
struct DigraphCopySelector {
|
| 597 | 597 |
template <typename From, typename NodeRefMap, typename ArcRefMap> |
| 598 | 598 |
static void copy(Digraph &to, const From& from, |
| 599 | 599 |
NodeRefMap& nodeRefMap, ArcRefMap& arcRefMap) {
|
| 600 | 600 |
for (typename From::NodeIt it(from); it != INVALID; ++it) {
|
| 601 | 601 |
nodeRefMap[it] = to.addNode(); |
| 602 | 602 |
} |
| 603 | 603 |
for (typename From::ArcIt it(from); it != INVALID; ++it) {
|
| 604 | 604 |
arcRefMap[it] = to.addArc(nodeRefMap[from.source(it)], |
| 605 |
|
|
| 605 |
nodeRefMap[from.target(it)]); |
|
| 606 | 606 |
} |
| 607 | 607 |
} |
| 608 | 608 |
}; |
| 609 | 609 |
|
| 610 | 610 |
template <typename Digraph> |
| 611 | 611 |
struct DigraphCopySelector< |
| 612 | 612 |
Digraph, |
| 613 | 613 |
typename enable_if<typename Digraph::BuildTag, void>::type> |
| 614 | 614 |
{
|
| 615 | 615 |
template <typename From, typename NodeRefMap, typename ArcRefMap> |
| 616 | 616 |
static void copy(Digraph &to, const From& from, |
| 617 | 617 |
NodeRefMap& nodeRefMap, ArcRefMap& arcRefMap) {
|
| 618 | 618 |
to.build(from, nodeRefMap, arcRefMap); |
| 619 | 619 |
} |
| 620 | 620 |
}; |
| 621 | 621 |
|
| 622 | 622 |
template <typename Graph, typename Enable = void> |
| 623 | 623 |
struct GraphCopySelector {
|
| 624 | 624 |
template <typename From, typename NodeRefMap, typename EdgeRefMap> |
| 625 | 625 |
static void copy(Graph &to, const From& from, |
| 626 | 626 |
NodeRefMap& nodeRefMap, EdgeRefMap& edgeRefMap) {
|
| 627 | 627 |
for (typename From::NodeIt it(from); it != INVALID; ++it) {
|
| 628 | 628 |
nodeRefMap[it] = to.addNode(); |
| 629 | 629 |
} |
| 630 | 630 |
for (typename From::EdgeIt it(from); it != INVALID; ++it) {
|
| 631 |
edgeRefMap[it] = to.addArc(nodeRefMap[from.source(it)], |
|
| 632 |
nodeRefMap[from.target(it)]); |
|
| 631 |
edgeRefMap[it] = to.addEdge(nodeRefMap[from.u(it)], |
|
| 632 |
nodeRefMap[from.v(it)]); |
|
| 633 | 633 |
} |
| 634 | 634 |
} |
| 635 | 635 |
}; |
| 636 | 636 |
|
| 637 | 637 |
template <typename Graph> |
| 638 | 638 |
struct GraphCopySelector< |
| 639 | 639 |
Graph, |
| 640 | 640 |
typename enable_if<typename Graph::BuildTag, void>::type> |
| 641 | 641 |
{
|
| 642 | 642 |
template <typename From, typename NodeRefMap, typename EdgeRefMap> |
| 643 | 643 |
static void copy(Graph &to, const From& from, |
| 644 | 644 |
NodeRefMap& nodeRefMap, EdgeRefMap& edgeRefMap) {
|
| 645 | 645 |
to.build(from, nodeRefMap, edgeRefMap); |
| 646 | 646 |
} |
| 647 | 647 |
}; |
| 648 | 648 |
|
| 649 | 649 |
} |
| 650 | 650 |
|
| 651 | 651 |
/// \brief Class to copy a digraph. |
| 652 | 652 |
/// |
| 653 | 653 |
/// Class to copy a digraph to another digraph (duplicate a digraph). The |
| 654 | 654 |
/// simplest way of using it is through the \c copyDigraph() function. |
| 655 | 655 |
/// |
| 656 | 656 |
/// This class not just make a copy of a graph, but it can create |
| 657 | 657 |
/// references and cross references between the nodes and arcs of |
| 658 | 658 |
/// the two graphs, it can copy maps for use with the newly created |
| 659 | 659 |
/// graph and copy nodes and arcs. |
| 660 | 660 |
/// |
| 661 | 661 |
/// To make a copy from a graph, first an instance of DigraphCopy |
| 662 | 662 |
/// should be created, then the data belongs to the graph should |
| 663 | 663 |
/// assigned to copy. In the end, the \c run() member should be |
| 664 | 664 |
/// called. |
| 665 | 665 |
/// |
| 666 | 666 |
/// The next code copies a graph with several data: |
| 667 | 667 |
///\code |
| 668 | 668 |
/// DigraphCopy<NewGraph, OrigGraph> dc(new_graph, orig_graph); |
| 669 | 669 |
/// // create a reference for the nodes |
| 670 | 670 |
/// OrigGraph::NodeMap<NewGraph::Node> nr(orig_graph); |
| 671 | 671 |
/// dc.nodeRef(nr); |
| 672 | 672 |
/// // create a cross reference (inverse) for the arcs |
| 673 | 673 |
/// NewGraph::ArcMap<OrigGraph::Arc> acr(new_graph); |
| 674 | 674 |
/// dc.arcCrossRef(acr); |
| 675 | 675 |
/// // copy an arc map |
| 676 | 676 |
/// OrigGraph::ArcMap<double> oamap(orig_graph); |
| 677 | 677 |
/// NewGraph::ArcMap<double> namap(new_graph); |
| 678 | 678 |
/// dc.arcMap(namap, oamap); |
| 679 | 679 |
/// // copy a node |
| 680 | 680 |
/// OrigGraph::Node on; |
| ... | ... |
@@ -880,99 +880,100 @@ |
| 880 | 880 |
/// The next code copies a graph with several data: |
| 881 | 881 |
///\code |
| 882 | 882 |
/// GraphCopy<NewGraph, OrigGraph> dc(new_graph, orig_graph); |
| 883 | 883 |
/// // create a reference for the nodes |
| 884 | 884 |
/// OrigGraph::NodeMap<NewGraph::Node> nr(orig_graph); |
| 885 | 885 |
/// dc.nodeRef(nr); |
| 886 | 886 |
/// // create a cross reference (inverse) for the edges |
| 887 | 887 |
/// NewGraph::EdgeMap<OrigGraph::Arc> ecr(new_graph); |
| 888 | 888 |
/// dc.edgeCrossRef(ecr); |
| 889 | 889 |
/// // copy an arc map |
| 890 | 890 |
/// OrigGraph::ArcMap<double> oamap(orig_graph); |
| 891 | 891 |
/// NewGraph::ArcMap<double> namap(new_graph); |
| 892 | 892 |
/// dc.arcMap(namap, oamap); |
| 893 | 893 |
/// // copy a node |
| 894 | 894 |
/// OrigGraph::Node on; |
| 895 | 895 |
/// NewGraph::Node nn; |
| 896 | 896 |
/// dc.node(nn, on); |
| 897 | 897 |
/// // Executions of copy |
| 898 | 898 |
/// dc.run(); |
| 899 | 899 |
///\endcode |
| 900 | 900 |
template <typename To, typename From> |
| 901 | 901 |
class GraphCopy {
|
| 902 | 902 |
private: |
| 903 | 903 |
|
| 904 | 904 |
typedef typename From::Node Node; |
| 905 | 905 |
typedef typename From::NodeIt NodeIt; |
| 906 | 906 |
typedef typename From::Arc Arc; |
| 907 | 907 |
typedef typename From::ArcIt ArcIt; |
| 908 | 908 |
typedef typename From::Edge Edge; |
| 909 | 909 |
typedef typename From::EdgeIt EdgeIt; |
| 910 | 910 |
|
| 911 | 911 |
typedef typename To::Node TNode; |
| 912 | 912 |
typedef typename To::Arc TArc; |
| 913 | 913 |
typedef typename To::Edge TEdge; |
| 914 | 914 |
|
| 915 | 915 |
typedef typename From::template NodeMap<TNode> NodeRefMap; |
| 916 | 916 |
typedef typename From::template EdgeMap<TEdge> EdgeRefMap; |
| 917 | 917 |
|
| 918 | 918 |
struct ArcRefMap {
|
| 919 | 919 |
ArcRefMap(const To& to, const From& from, |
| 920 | 920 |
const EdgeRefMap& edge_ref, const NodeRefMap& node_ref) |
| 921 | 921 |
: _to(to), _from(from), |
| 922 | 922 |
_edge_ref(edge_ref), _node_ref(node_ref) {}
|
| 923 | 923 |
|
| 924 | 924 |
typedef typename From::Arc Key; |
| 925 | 925 |
typedef typename To::Arc Value; |
| 926 | 926 |
|
| 927 | 927 |
Value operator[](const Key& key) const {
|
| 928 |
bool forward = |
|
| 929 |
(_from.direction(key) == |
|
| 930 |
|
|
| 928 |
bool forward = _from.u(key) != _from.v(key) ? |
|
| 929 |
_node_ref[_from.source(key)] == |
|
| 930 |
_to.source(_to.direct(_edge_ref[key], true)) : |
|
| 931 |
_from.direction(key); |
|
| 931 | 932 |
return _to.direct(_edge_ref[key], forward); |
| 932 | 933 |
} |
| 933 | 934 |
|
| 934 | 935 |
const To& _to; |
| 935 | 936 |
const From& _from; |
| 936 | 937 |
const EdgeRefMap& _edge_ref; |
| 937 | 938 |
const NodeRefMap& _node_ref; |
| 938 | 939 |
}; |
| 939 | 940 |
|
| 940 | 941 |
|
| 941 | 942 |
public: |
| 942 | 943 |
|
| 943 | 944 |
|
| 944 | 945 |
/// \brief Constructor for the GraphCopy. |
| 945 | 946 |
/// |
| 946 | 947 |
/// It copies the content of the \c _from graph into the |
| 947 | 948 |
/// \c _to graph. |
| 948 | 949 |
GraphCopy(To& to, const From& from) |
| 949 | 950 |
: _from(from), _to(to) {}
|
| 950 | 951 |
|
| 951 | 952 |
/// \brief Destructor of the GraphCopy |
| 952 | 953 |
/// |
| 953 | 954 |
/// Destructor of the GraphCopy |
| 954 | 955 |
~GraphCopy() {
|
| 955 | 956 |
for (int i = 0; i < int(_node_maps.size()); ++i) {
|
| 956 | 957 |
delete _node_maps[i]; |
| 957 | 958 |
} |
| 958 | 959 |
for (int i = 0; i < int(_arc_maps.size()); ++i) {
|
| 959 | 960 |
delete _arc_maps[i]; |
| 960 | 961 |
} |
| 961 | 962 |
for (int i = 0; i < int(_edge_maps.size()); ++i) {
|
| 962 | 963 |
delete _edge_maps[i]; |
| 963 | 964 |
} |
| 964 | 965 |
|
| 965 | 966 |
} |
| 966 | 967 |
|
| 967 | 968 |
/// \brief Copies the node references into the given map. |
| 968 | 969 |
/// |
| 969 | 970 |
/// Copies the node references into the given map. |
| 970 | 971 |
template <typename NodeRef> |
| 971 | 972 |
GraphCopy& nodeRef(NodeRef& map) {
|
| 972 | 973 |
_node_maps.push_back(new _graph_utils_bits::RefCopy<From, Node, |
| 973 | 974 |
NodeRefMap, NodeRef>(map)); |
| 974 | 975 |
return *this; |
| 975 | 976 |
} |
| 976 | 977 |
|
| 977 | 978 |
/// \brief Copies the node cross references into the given map. |
| 978 | 979 |
/// |
0 comments (0 inline)