COIN-OR::LEMON - Graph Library

Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • test/graph_copy_test.cc

    r894 r1026  
    210210}
    211211
     212template <typename GR>
     213void bpgraph_copy_test() {
     214  const int nn = 10;
     215
     216  // Build a graph
     217  SmartBpGraph from;
     218  SmartBpGraph::NodeMap<int> fnm(from);
     219  SmartBpGraph::RedNodeMap<int> frnm(from);
     220  SmartBpGraph::BlueNodeMap<int> fbnm(from);
     221  SmartBpGraph::ArcMap<int> fam(from);
     222  SmartBpGraph::EdgeMap<int> fem(from);
     223  SmartBpGraph::Node fn = INVALID;
     224  SmartBpGraph::RedNode frn = INVALID;
     225  SmartBpGraph::BlueNode fbn = INVALID;
     226  SmartBpGraph::Arc fa = INVALID;
     227  SmartBpGraph::Edge fe = INVALID;
     228
     229  std::vector<SmartBpGraph::RedNode> frnv;
     230  for (int i = 0; i < nn; ++i) {
     231    SmartBpGraph::RedNode node = from.addRedNode();
     232    frnv.push_back(node);
     233    fnm[node] = i * i;
     234    frnm[node] = i + i;
     235    if (i == 0) {
     236      fn = node;
     237      frn = node;
     238    }
     239  }
     240
     241  std::vector<SmartBpGraph::BlueNode> fbnv;
     242  for (int i = 0; i < nn; ++i) {
     243    SmartBpGraph::BlueNode node = from.addBlueNode();
     244    fbnv.push_back(node);
     245    fnm[node] = i * i;
     246    fbnm[node] = i + i;
     247    if (i == 0) fbn = node;
     248  }
     249
     250  for (int i = 0; i < nn; ++i) {
     251    for (int j = 0; j < nn; ++j) {
     252      SmartBpGraph::Edge edge = from.addEdge(frnv[i], fbnv[j]);
     253      fem[edge] = i * i + j * j;
     254      fam[from.direct(edge, true)] = i + j * j;
     255      fam[from.direct(edge, false)] = i * i + j;
     256      if (i == 0 && j == 0) fa = from.direct(edge, true);
     257      if (i == 0 && j == 0) fe = edge;
     258    }
     259  }
     260
     261  // Test graph copy
     262  GR to;
     263  typename GR::template NodeMap<int> tnm(to);
     264  typename GR::template RedNodeMap<int> trnm(to);
     265  typename GR::template BlueNodeMap<int> tbnm(to);
     266  typename GR::template ArcMap<int> tam(to);
     267  typename GR::template EdgeMap<int> tem(to);
     268  typename GR::Node tn;
     269  typename GR::RedNode trn;
     270  typename GR::BlueNode tbn;
     271  typename GR::Arc ta;
     272  typename GR::Edge te;
     273
     274  SmartBpGraph::NodeMap<typename GR::Node> nr(from);
     275  SmartBpGraph::RedNodeMap<typename GR::RedNode> rnr(from);
     276  SmartBpGraph::BlueNodeMap<typename GR::BlueNode> bnr(from);
     277  SmartBpGraph::ArcMap<typename GR::Arc> ar(from);
     278  SmartBpGraph::EdgeMap<typename GR::Edge> er(from);
     279
     280  typename GR::template NodeMap<SmartBpGraph::Node> ncr(to);
     281  typename GR::template RedNodeMap<SmartBpGraph::RedNode> rncr(to);
     282  typename GR::template BlueNodeMap<SmartBpGraph::BlueNode> bncr(to);
     283  typename GR::template ArcMap<SmartBpGraph::Arc> acr(to);
     284  typename GR::template EdgeMap<SmartBpGraph::Edge> ecr(to);
     285
     286  bpGraphCopy(from, to).
     287    nodeMap(fnm, tnm).
     288    redNodeMap(frnm, trnm).blueNodeMap(fbnm, tbnm).
     289    arcMap(fam, tam).edgeMap(fem, tem).
     290    nodeRef(nr).redRef(rnr).blueRef(bnr).
     291    arcRef(ar).edgeRef(er).
     292    nodeCrossRef(ncr).redCrossRef(rncr).blueCrossRef(bncr).
     293    arcCrossRef(acr).edgeCrossRef(ecr).
     294    node(fn, tn).redNode(frn, trn).blueNode(fbn, tbn).
     295    arc(fa, ta).edge(fe, te).run();
     296
     297  check(countNodes(from) == countNodes(to), "Wrong copy.");
     298  check(countRedNodes(from) == countRedNodes(to), "Wrong copy.");
     299  check(countBlueNodes(from) == countBlueNodes(to), "Wrong copy.");
     300  check(countEdges(from) == countEdges(to), "Wrong copy.");
     301  check(countArcs(from) == countArcs(to), "Wrong copy.");
     302
     303  for (SmartBpGraph::NodeIt it(from); it != INVALID; ++it) {
     304    check(ncr[nr[it]] == it, "Wrong copy.");
     305    check(fnm[it] == tnm[nr[it]], "Wrong copy.");
     306  }
     307
     308  for (SmartBpGraph::RedNodeIt it(from); it != INVALID; ++it) {
     309    check(ncr[nr[it]] == it, "Wrong copy.");
     310    check(fnm[it] == tnm[nr[it]], "Wrong copy.");
     311    check(rnr[it] == nr[it], "Wrong copy.");
     312    check(rncr[rnr[it]] == it, "Wrong copy.");
     313    check(frnm[it] == trnm[rnr[it]], "Wrong copy.");
     314    check(to.red(rnr[it]), "Wrong copy.");
     315  }
     316
     317  for (SmartBpGraph::BlueNodeIt it(from); it != INVALID; ++it) {
     318    check(ncr[nr[it]] == it, "Wrong copy.");
     319    check(fnm[it] == tnm[nr[it]], "Wrong copy.");
     320    check(bnr[it] == nr[it], "Wrong copy.");
     321    check(bncr[bnr[it]] == it, "Wrong copy.");
     322    check(fbnm[it] == tbnm[bnr[it]], "Wrong copy.");
     323    check(to.blue(bnr[it]), "Wrong copy.");
     324  }
     325
     326  for (SmartBpGraph::ArcIt it(from); it != INVALID; ++it) {
     327    check(acr[ar[it]] == it, "Wrong copy.");
     328    check(fam[it] == tam[ar[it]], "Wrong copy.");
     329    check(nr[from.source(it)] == to.source(ar[it]), "Wrong copy.");
     330    check(nr[from.target(it)] == to.target(ar[it]), "Wrong copy.");
     331  }
     332
     333  for (SmartBpGraph::EdgeIt it(from); it != INVALID; ++it) {
     334    check(ecr[er[it]] == it, "Wrong copy.");
     335    check(fem[it] == tem[er[it]], "Wrong copy.");
     336    check(nr[from.u(it)] == to.u(er[it]) || nr[from.u(it)] == to.v(er[it]),
     337          "Wrong copy.");
     338    check(nr[from.v(it)] == to.u(er[it]) || nr[from.v(it)] == to.v(er[it]),
     339          "Wrong copy.");
     340    check((from.u(it) != from.v(it)) == (to.u(er[it]) != to.v(er[it])),
     341          "Wrong copy.");
     342  }
     343
     344  for (typename GR::NodeIt it(to); it != INVALID; ++it) {
     345    check(nr[ncr[it]] == it, "Wrong copy.");
     346  }
     347  for (typename GR::RedNodeIt it(to); it != INVALID; ++it) {
     348    check(rncr[it] == ncr[it], "Wrong copy.");
     349    check(rnr[rncr[it]] == it, "Wrong copy.");
     350  }
     351  for (typename GR::BlueNodeIt it(to); it != INVALID; ++it) {
     352    check(bncr[it] == ncr[it], "Wrong copy.");
     353    check(bnr[bncr[it]] == it, "Wrong copy.");
     354  }
     355  for (typename GR::ArcIt it(to); it != INVALID; ++it) {
     356    check(ar[acr[it]] == it, "Wrong copy.");
     357  }
     358  for (typename GR::EdgeIt it(to); it != INVALID; ++it) {
     359    check(er[ecr[it]] == it, "Wrong copy.");
     360  }
     361  check(tn == nr[fn], "Wrong copy.");
     362  check(trn == rnr[frn], "Wrong copy.");
     363  check(tbn == bnr[fbn], "Wrong copy.");
     364  check(ta == ar[fa], "Wrong copy.");
     365  check(te == er[fe], "Wrong copy.");
     366
     367  // Test repeated copy
     368  bpGraphCopy(from, to).run();
     369 
     370  check(countNodes(from) == countNodes(to), "Wrong copy.");
     371  check(countRedNodes(from) == countRedNodes(to), "Wrong copy.");
     372  check(countBlueNodes(from) == countBlueNodes(to), "Wrong copy.");
     373  check(countEdges(from) == countEdges(to), "Wrong copy.");
     374  check(countArcs(from) == countArcs(to), "Wrong copy.");
     375}
     376
    212377
    213378int main() {
     
    217382  graph_copy_test<SmartGraph>();
    218383  graph_copy_test<ListGraph>();
     384  bpgraph_copy_test<SmartBpGraph>();
     385  bpgraph_copy_test<ListBpGraph>();
    219386
    220387  return 0;
Note: See TracChangeset for help on using the changeset viewer.