COIN-OR::LEMON - Graph Library

Changeset 893:bb871cb8ac06 in lemon-1.2


Ignore:
Timestamp:
06/22/10 15:39:26 (14 years ago)
Author:
Peter Kovacs <kpeter@…>
Branch:
default
Children:
896:e958855b8186, 899:e24922c56bc2
Phase:
public
Message:

Bug fix in (di)graphCopy() (#371)

The target graph is cleared before adding nodes and arcs/edges.

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • lemon/core.h

    r501 r893  
    385385      static void copy(const From& from, Digraph &to,
    386386                       NodeRefMap& nodeRefMap, ArcRefMap& arcRefMap) {
     387        to.clear();
    387388        for (typename From::NodeIt it(from); it != INVALID; ++it) {
    388389          nodeRefMap[it] = to.addNode();
     
    412413      static void copy(const From& from, Graph &to,
    413414                       NodeRefMap& nodeRefMap, EdgeRefMap& edgeRefMap) {
     415        to.clear();
    414416        for (typename From::NodeIt it(from); it != INVALID; ++it) {
    415417          nodeRefMap[it] = to.addNode();
  • test/graph_copy_test.cc

    r282 r893  
    3030  const int nn = 10;
    3131
     32  // Build a digraph
    3233  SmartDigraph from;
    3334  SmartDigraph::NodeMap<int> fnm(from);
     
    5253  }
    5354
     55  // Test digraph copy
    5456  ListDigraph to;
    5557  ListDigraph::NodeMap<int> tnm(to);
     
    6971    nodeCrossRef(ncr).arcCrossRef(ecr).
    7072    node(fn, tn).arc(fa, ta).run();
     73 
     74  check(countNodes(from) == countNodes(to), "Wrong copy.");
     75  check(countArcs(from) == countArcs(to), "Wrong copy.");
    7176
    7277  for (SmartDigraph::NodeIt it(from); it != INVALID; ++it) {
     
    9196  check(tn == nr[fn], "Wrong copy.");
    9297  check(ta == er[fa], "Wrong copy.");
     98
     99  // Test repeated copy
     100  digraphCopy(from, to).run();
     101 
     102  check(countNodes(from) == countNodes(to), "Wrong copy.");
     103  check(countArcs(from) == countArcs(to), "Wrong copy.");
    93104}
    94105
     
    96107  const int nn = 10;
    97108
     109  // Build a graph
    98110  SmartGraph from;
    99111  SmartGraph::NodeMap<int> fnm(from);
     
    123135  }
    124136
     137  // Test graph copy
    125138  ListGraph to;
    126139  ListGraph::NodeMap<int> tnm(to);
     
    144157    nodeCrossRef(ncr).arcCrossRef(acr).edgeCrossRef(ecr).
    145158    node(fn, tn).arc(fa, ta).edge(fe, te).run();
     159
     160  check(countNodes(from) == countNodes(to), "Wrong copy.");
     161  check(countEdges(from) == countEdges(to), "Wrong copy.");
     162  check(countArcs(from) == countArcs(to), "Wrong copy.");
    146163
    147164  for (SmartGraph::NodeIt it(from); it != INVALID; ++it) {
     
    181198  check(ta == ar[fa], "Wrong copy.");
    182199  check(te == er[fe], "Wrong copy.");
     200
     201  // Test repeated copy
     202  graphCopy(from, to).run();
     203 
     204  check(countNodes(from) == countNodes(to), "Wrong copy.");
     205  check(countEdges(from) == countEdges(to), "Wrong copy.");
     206  check(countArcs(from) == countArcs(to), "Wrong copy.");
    183207}
    184208
Note: See TracChangeset for help on using the changeset viewer.