gravatar
deba@inf.elte.hu
deba@inf.elte.hu
Bug fix in GraphCopy (ticket #117)
0 1 0
default
1 file changed with 6 insertions and 5 deletions:
↑ Collapse diff ↑
Show white space 48 line context
... ...
@@ -607,50 +607,50 @@
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
... ...
@@ -904,51 +904,52 @@
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
	   (_node_ref[_from.source(key)] == _to.source(_edge_ref[key])));
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() {
0 comments (0 inline)