Location: LEMON/LEMON-official/test/graph_copy_test.cc - annotation
Load file history
New heuristics for MCF algorithms (#340)
and some implementation improvements.
- A useful heuristic is added to NetworkSimplex to make the
initial pivots faster.
- A powerful global update heuristic is added to CostScaling
and the implementation is reworked with various improvements.
- Better relabeling in CostScaling to improve numerical stability
and make the code faster.
- A small improvement is made in CapacityScaling for better
delta computation.
- Add notes to the classes about the usage of vector<char> instead
of vector<bool> for efficiency reasons.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | r209:765619b7cbb2 r200:c0e2c043c060 r209:765619b7cbb2 r200:c0e2c043c060 r463:88ed40ad0d4f r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r282:dc9e8d2c0df9 r282:dc9e8d2c0df9 r200:c0e2c043c060 r200:c0e2c043c060 r282:dc9e8d2c0df9 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r209:765619b7cbb2 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r282:dc9e8d2c0df9 r282:dc9e8d2c0df9 r200:c0e2c043c060 r200:c0e2c043c060 r282:dc9e8d2c0df9 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r209:765619b7cbb2 r209:765619b7cbb2 r209:765619b7cbb2 r209:765619b7cbb2 r209:765619b7cbb2 r209:765619b7cbb2 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r200:c0e2c043c060 r209:765619b7cbb2 r200:c0e2c043c060 | /* -*- mode: C++; indent-tabs-mode: nil; -*-
*
* This file is a part of LEMON, a generic C++ optimization library.
*
* Copyright (C) 2003-2009
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
* (Egervary Research Group on Combinatorial Optimization, EGRES).
*
* Permission to use, modify and distribute this software is granted
* provided that this copyright notice appears in all copies. For
* precise terms see the accompanying LICENSE file.
*
* This software is provided "AS IS" with no warranty of any kind,
* express or implied, and with no claim as to its suitability for any
* purpose.
*
*/
#include <lemon/smart_graph.h>
#include <lemon/list_graph.h>
#include <lemon/lgf_reader.h>
#include <lemon/error.h>
#include "test_tools.h"
using namespace std;
using namespace lemon;
void digraph_copy_test() {
const int nn = 10;
SmartDigraph from;
SmartDigraph::NodeMap<int> fnm(from);
SmartDigraph::ArcMap<int> fam(from);
SmartDigraph::Node fn = INVALID;
SmartDigraph::Arc fa = INVALID;
std::vector<SmartDigraph::Node> fnv;
for (int i = 0; i < nn; ++i) {
SmartDigraph::Node node = from.addNode();
fnv.push_back(node);
fnm[node] = i * i;
if (i == 0) fn = node;
}
for (int i = 0; i < nn; ++i) {
for (int j = 0; j < nn; ++j) {
SmartDigraph::Arc arc = from.addArc(fnv[i], fnv[j]);
fam[arc] = i + j * j;
if (i == 0 && j == 0) fa = arc;
}
}
ListDigraph to;
ListDigraph::NodeMap<int> tnm(to);
ListDigraph::ArcMap<int> tam(to);
ListDigraph::Node tn;
ListDigraph::Arc ta;
SmartDigraph::NodeMap<ListDigraph::Node> nr(from);
SmartDigraph::ArcMap<ListDigraph::Arc> er(from);
ListDigraph::NodeMap<SmartDigraph::Node> ncr(to);
ListDigraph::ArcMap<SmartDigraph::Arc> 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();
for (SmartDigraph::NodeIt it(from); it != INVALID; ++it) {
check(ncr[nr[it]] == it, "Wrong copy.");
check(fnm[it] == tnm[nr[it]], "Wrong copy.");
}
for (SmartDigraph::ArcIt it(from); it != INVALID; ++it) {
check(ecr[er[it]] == it, "Wrong copy.");
check(fam[it] == tam[er[it]], "Wrong copy.");
check(nr[from.source(it)] == to.source(er[it]), "Wrong copy.");
check(nr[from.target(it)] == to.target(er[it]), "Wrong copy.");
}
for (ListDigraph::NodeIt it(to); it != INVALID; ++it) {
check(nr[ncr[it]] == it, "Wrong copy.");
}
for (ListDigraph::ArcIt it(to); it != INVALID; ++it) {
check(er[ecr[it]] == it, "Wrong copy.");
}
check(tn == nr[fn], "Wrong copy.");
check(ta == er[fa], "Wrong copy.");
}
void graph_copy_test() {
const int nn = 10;
SmartGraph from;
SmartGraph::NodeMap<int> fnm(from);
SmartGraph::ArcMap<int> fam(from);
SmartGraph::EdgeMap<int> fem(from);
SmartGraph::Node fn = INVALID;
SmartGraph::Arc fa = INVALID;
SmartGraph::Edge fe = INVALID;
std::vector<SmartGraph::Node> fnv;
for (int i = 0; i < nn; ++i) {
SmartGraph::Node node = from.addNode();
fnv.push_back(node);
fnm[node] = i * i;
if (i == 0) fn = node;
}
for (int i = 0; i < nn; ++i) {
for (int j = 0; j < nn; ++j) {
SmartGraph::Edge edge = from.addEdge(fnv[i], fnv[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;
}
}
ListGraph to;
ListGraph::NodeMap<int> tnm(to);
ListGraph::ArcMap<int> tam(to);
ListGraph::EdgeMap<int> tem(to);
ListGraph::Node tn;
ListGraph::Arc ta;
ListGraph::Edge te;
SmartGraph::NodeMap<ListGraph::Node> nr(from);
SmartGraph::ArcMap<ListGraph::Arc> ar(from);
SmartGraph::EdgeMap<ListGraph::Edge> er(from);
ListGraph::NodeMap<SmartGraph::Node> ncr(to);
ListGraph::ArcMap<SmartGraph::Arc> acr(to);
ListGraph::EdgeMap<SmartGraph::Edge> ecr(to);
graphCopy(from, to).
nodeMap(fnm, tnm).arcMap(fam, tam).edgeMap(fem, tem).
nodeRef(nr).arcRef(ar).edgeRef(er).
nodeCrossRef(ncr).arcCrossRef(acr).edgeCrossRef(ecr).
node(fn, tn).arc(fa, ta).edge(fe, te).run();
for (SmartGraph::NodeIt it(from); it != INVALID; ++it) {
check(ncr[nr[it]] == it, "Wrong copy.");
check(fnm[it] == tnm[nr[it]], "Wrong copy.");
}
for (SmartGraph::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 (SmartGraph::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 (ListGraph::NodeIt it(to); it != INVALID; ++it) {
check(nr[ncr[it]] == it, "Wrong copy.");
}
for (ListGraph::ArcIt it(to); it != INVALID; ++it) {
check(ar[acr[it]] == it, "Wrong copy.");
}
for (ListGraph::EdgeIt it(to); it != INVALID; ++it) {
check(er[ecr[it]] == it, "Wrong copy.");
}
check(tn == nr[fn], "Wrong copy.");
check(ta == ar[fa], "Wrong copy.");
check(te == er[fe], "Wrong copy.");
}
int main() {
digraph_copy_test();
graph_copy_test();
return 0;
}
|