diff -r cd72eae05bdf -r 3c00344f49c9 test/graph_copy_test.cc --- a/test/graph_copy_test.cc Mon Jul 16 16:21:40 2018 +0200 +++ b/test/graph_copy_test.cc Wed Oct 17 19:14:07 2018 +0200 @@ -2,7 +2,7 @@ * * This file is a part of LEMON, a generic C++ optimization library. * - * Copyright (C) 2003-2009 + * Copyright (C) 2003-2013 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport * (Egervary Research Group on Combinatorial Optimization, EGRES). * @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -26,6 +27,7 @@ using namespace std; using namespace lemon; +template void digraph_copy_test() { const int nn = 10; @@ -53,24 +55,24 @@ } // Test digraph copy - ListDigraph to; - ListDigraph::NodeMap tnm(to); - ListDigraph::ArcMap tam(to); - ListDigraph::Node tn; - ListDigraph::Arc ta; + GR to; + typename GR::template NodeMap tnm(to); + typename GR::template ArcMap tam(to); + typename GR::Node tn; + typename GR::Arc ta; - SmartDigraph::NodeMap nr(from); - SmartDigraph::ArcMap er(from); + SmartDigraph::NodeMap nr(from); + SmartDigraph::ArcMap er(from); - ListDigraph::NodeMap ncr(to); - ListDigraph::ArcMap ecr(to); + typename GR::template NodeMap ncr(to); + typename GR::template ArcMap ecr(to); digraphCopy(from, to). nodeMap(fnm, tnm).arcMap(fam, tam). nodeRef(nr).arcRef(er). nodeCrossRef(ncr).arcCrossRef(ecr). node(fn, tn).arc(fa, ta).run(); - + check(countNodes(from) == countNodes(to), "Wrong copy."); check(countArcs(from) == countArcs(to), "Wrong copy."); @@ -86,11 +88,11 @@ check(nr[from.target(it)] == to.target(er[it]), "Wrong copy."); } - for (ListDigraph::NodeIt it(to); it != INVALID; ++it) { + for (typename GR::NodeIt it(to); it != INVALID; ++it) { check(nr[ncr[it]] == it, "Wrong copy."); } - for (ListDigraph::ArcIt it(to); it != INVALID; ++it) { + for (typename GR::ArcIt it(to); it != INVALID; ++it) { check(er[ecr[it]] == it, "Wrong copy."); } check(tn == nr[fn], "Wrong copy."); @@ -98,11 +100,12 @@ // Test repeated copy digraphCopy(from, to).run(); - + check(countNodes(from) == countNodes(to), "Wrong copy."); check(countArcs(from) == countArcs(to), "Wrong copy."); } +template void graph_copy_test() { const int nn = 10; @@ -135,21 +138,21 @@ } // Test graph copy - ListGraph to; - ListGraph::NodeMap tnm(to); - ListGraph::ArcMap tam(to); - ListGraph::EdgeMap tem(to); - ListGraph::Node tn; - ListGraph::Arc ta; - ListGraph::Edge te; + GR to; + typename GR::template NodeMap tnm(to); + typename GR::template ArcMap tam(to); + typename GR::template EdgeMap tem(to); + typename GR::Node tn; + typename GR::Arc ta; + typename GR::Edge te; - SmartGraph::NodeMap nr(from); - SmartGraph::ArcMap ar(from); - SmartGraph::EdgeMap er(from); + SmartGraph::NodeMap nr(from); + SmartGraph::ArcMap ar(from); + SmartGraph::EdgeMap er(from); - ListGraph::NodeMap ncr(to); - ListGraph::ArcMap acr(to); - ListGraph::EdgeMap ecr(to); + typename GR::template NodeMap ncr(to); + typename GR::template ArcMap acr(to); + typename GR::template EdgeMap ecr(to); graphCopy(from, to). nodeMap(fnm, tnm).arcMap(fam, tam).edgeMap(fem, tem). @@ -184,14 +187,14 @@ "Wrong copy."); } - for (ListGraph::NodeIt it(to); it != INVALID; ++it) { + for (typename GR::NodeIt it(to); it != INVALID; ++it) { check(nr[ncr[it]] == it, "Wrong copy."); } - for (ListGraph::ArcIt it(to); it != INVALID; ++it) { + for (typename GR::ArcIt it(to); it != INVALID; ++it) { check(ar[acr[it]] == it, "Wrong copy."); } - for (ListGraph::EdgeIt it(to); it != INVALID; ++it) { + for (typename GR::EdgeIt it(to); it != INVALID; ++it) { check(er[ecr[it]] == it, "Wrong copy."); } check(tn == nr[fn], "Wrong copy."); @@ -200,16 +203,186 @@ // Test repeated copy graphCopy(from, to).run(); - + check(countNodes(from) == countNodes(to), "Wrong copy."); check(countEdges(from) == countEdges(to), "Wrong copy."); check(countArcs(from) == countArcs(to), "Wrong copy."); } +template +void bpgraph_copy_test() { + const int nn = 10; + + // Build a graph + SmartBpGraph from; + SmartBpGraph::NodeMap fnm(from); + SmartBpGraph::RedNodeMap frnm(from); + SmartBpGraph::BlueNodeMap fbnm(from); + SmartBpGraph::ArcMap fam(from); + SmartBpGraph::EdgeMap fem(from); + SmartBpGraph::Node fn = INVALID; + SmartBpGraph::RedNode frn = INVALID; + SmartBpGraph::BlueNode fbn = INVALID; + SmartBpGraph::Arc fa = INVALID; + SmartBpGraph::Edge fe = INVALID; + + std::vector frnv; + for (int i = 0; i < nn; ++i) { + SmartBpGraph::RedNode node = from.addRedNode(); + frnv.push_back(node); + fnm[node] = i * i; + frnm[node] = i + i; + if (i == 0) { + fn = node; + frn = node; + } + } + + std::vector fbnv; + for (int i = 0; i < nn; ++i) { + SmartBpGraph::BlueNode node = from.addBlueNode(); + fbnv.push_back(node); + fnm[node] = i * i; + fbnm[node] = i + i; + if (i == 0) fbn = node; + } + + for (int i = 0; i < nn; ++i) { + for (int j = 0; j < nn; ++j) { + SmartBpGraph::Edge edge = from.addEdge(frnv[i], fbnv[j]); + fem[edge] = i * i + j * j; + fam[from.direct(edge, true)] = i + j * j; + fam[from.direct(edge, false)] = i * i + j; + if (i == 0 && j == 0) fa = from.direct(edge, true); + if (i == 0 && j == 0) fe = edge; + } + } + + // Test graph copy + GR to; + typename GR::template NodeMap tnm(to); + typename GR::template RedNodeMap trnm(to); + typename GR::template BlueNodeMap tbnm(to); + typename GR::template ArcMap tam(to); + typename GR::template EdgeMap tem(to); + typename GR::Node tn; + typename GR::RedNode trn; + typename GR::BlueNode tbn; + typename GR::Arc ta; + typename GR::Edge te; + + SmartBpGraph::NodeMap nr(from); + SmartBpGraph::RedNodeMap rnr(from); + SmartBpGraph::BlueNodeMap bnr(from); + SmartBpGraph::ArcMap ar(from); + SmartBpGraph::EdgeMap er(from); + + typename GR::template NodeMap ncr(to); + typename GR::template RedNodeMap rncr(to); + typename GR::template BlueNodeMap bncr(to); + typename GR::template ArcMap acr(to); + typename GR::template EdgeMap ecr(to); + + bpGraphCopy(from, to). + nodeMap(fnm, tnm). + redNodeMap(frnm, trnm).blueNodeMap(fbnm, tbnm). + arcMap(fam, tam).edgeMap(fem, tem). + nodeRef(nr).redRef(rnr).blueRef(bnr). + arcRef(ar).edgeRef(er). + nodeCrossRef(ncr).redCrossRef(rncr).blueCrossRef(bncr). + arcCrossRef(acr).edgeCrossRef(ecr). + node(fn, tn).redNode(frn, trn).blueNode(fbn, tbn). + arc(fa, ta).edge(fe, te).run(); + + check(countNodes(from) == countNodes(to), "Wrong copy."); + check(countRedNodes(from) == countRedNodes(to), "Wrong copy."); + check(countBlueNodes(from) == countBlueNodes(to), "Wrong copy."); + check(countEdges(from) == countEdges(to), "Wrong copy."); + check(countArcs(from) == countArcs(to), "Wrong copy."); + + for (SmartBpGraph::NodeIt it(from); it != INVALID; ++it) { + check(ncr[nr[it]] == it, "Wrong copy."); + check(fnm[it] == tnm[nr[it]], "Wrong copy."); + } + + for (SmartBpGraph::RedNodeIt it(from); it != INVALID; ++it) { + check(ncr[nr[it]] == it, "Wrong copy."); + check(fnm[it] == tnm[nr[it]], "Wrong copy."); + check(rnr[it] == nr[it], "Wrong copy."); + check(rncr[rnr[it]] == it, "Wrong copy."); + check(frnm[it] == trnm[rnr[it]], "Wrong copy."); + check(to.red(rnr[it]), "Wrong copy."); + } + + for (SmartBpGraph::BlueNodeIt it(from); it != INVALID; ++it) { + check(ncr[nr[it]] == it, "Wrong copy."); + check(fnm[it] == tnm[nr[it]], "Wrong copy."); + check(bnr[it] == nr[it], "Wrong copy."); + check(bncr[bnr[it]] == it, "Wrong copy."); + check(fbnm[it] == tbnm[bnr[it]], "Wrong copy."); + check(to.blue(bnr[it]), "Wrong copy."); + } + + for (SmartBpGraph::ArcIt it(from); it != INVALID; ++it) { + check(acr[ar[it]] == it, "Wrong copy."); + check(fam[it] == tam[ar[it]], "Wrong copy."); + check(nr[from.source(it)] == to.source(ar[it]), "Wrong copy."); + check(nr[from.target(it)] == to.target(ar[it]), "Wrong copy."); + } + + for (SmartBpGraph::EdgeIt it(from); it != INVALID; ++it) { + check(ecr[er[it]] == it, "Wrong copy."); + check(fem[it] == tem[er[it]], "Wrong copy."); + check(nr[from.u(it)] == to.u(er[it]) || nr[from.u(it)] == to.v(er[it]), + "Wrong copy."); + check(nr[from.v(it)] == to.u(er[it]) || nr[from.v(it)] == to.v(er[it]), + "Wrong copy."); + check((from.u(it) != from.v(it)) == (to.u(er[it]) != to.v(er[it])), + "Wrong copy."); + } + + for (typename GR::NodeIt it(to); it != INVALID; ++it) { + check(nr[ncr[it]] == it, "Wrong copy."); + } + for (typename GR::RedNodeIt it(to); it != INVALID; ++it) { + check(rncr[it] == ncr[it], "Wrong copy."); + check(rnr[rncr[it]] == it, "Wrong copy."); + } + for (typename GR::BlueNodeIt it(to); it != INVALID; ++it) { + check(bncr[it] == ncr[it], "Wrong copy."); + check(bnr[bncr[it]] == it, "Wrong copy."); + } + for (typename GR::ArcIt it(to); it != INVALID; ++it) { + check(ar[acr[it]] == it, "Wrong copy."); + } + for (typename GR::EdgeIt it(to); it != INVALID; ++it) { + check(er[ecr[it]] == it, "Wrong copy."); + } + check(tn == nr[fn], "Wrong copy."); + check(trn == rnr[frn], "Wrong copy."); + check(tbn == bnr[fbn], "Wrong copy."); + check(ta == ar[fa], "Wrong copy."); + check(te == er[fe], "Wrong copy."); + + // Test repeated copy + bpGraphCopy(from, to).run(); + + check(countNodes(from) == countNodes(to), "Wrong copy."); + check(countRedNodes(from) == countRedNodes(to), "Wrong copy."); + check(countBlueNodes(from) == countBlueNodes(to), "Wrong copy."); + check(countEdges(from) == countEdges(to), "Wrong copy."); + check(countArcs(from) == countArcs(to), "Wrong copy."); +} + int main() { - digraph_copy_test(); - graph_copy_test(); + digraph_copy_test(); + digraph_copy_test(); + digraph_copy_test(); + graph_copy_test(); + graph_copy_test(); + bpgraph_copy_test(); + bpgraph_copy_test(); return 0; }