Location: LEMON/LEMON-main/test/min_cost_arborescence_test.cc - annotation
Load file history
Port NetworkSimplex from SVN -r3520 (#234)
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 | r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 r501:7f8560cb9d65 | /* -*- mode: C++; indent-tabs-mode: nil; -*-
*
* This file is a part of LEMON, a generic C++ optimization library.
*
* Copyright (C) 2003-2008
* 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 <iostream>
#include <set>
#include <vector>
#include <iterator>
#include <lemon/smart_graph.h>
#include <lemon/min_cost_arborescence.h>
#include <lemon/lgf_reader.h>
#include "test_tools.h"
using namespace lemon;
using namespace std;
const char test_lgf[] =
"@nodes\n"
"label\n"
"0\n"
"1\n"
"2\n"
"3\n"
"4\n"
"5\n"
"6\n"
"7\n"
"8\n"
"9\n"
"@arcs\n"
" label cost\n"
"1 8 0 107\n"
"0 3 1 70\n"
"2 1 2 46\n"
"4 1 3 28\n"
"4 4 4 91\n"
"3 9 5 76\n"
"9 8 6 61\n"
"8 1 7 39\n"
"9 8 8 74\n"
"8 0 9 39\n"
"4 3 10 45\n"
"2 2 11 34\n"
"0 1 12 100\n"
"6 3 13 95\n"
"4 1 14 22\n"
"1 1 15 31\n"
"7 2 16 51\n"
"2 6 17 29\n"
"8 3 18 115\n"
"6 9 19 32\n"
"1 1 20 60\n"
"0 3 21 40\n"
"@attributes\n"
"source 0\n";
int main() {
typedef SmartDigraph Digraph;
DIGRAPH_TYPEDEFS(Digraph);
typedef Digraph::ArcMap<double> CostMap;
Digraph digraph;
CostMap cost(digraph);
Node source;
std::istringstream is(test_lgf);
digraphReader(digraph, is).
arcMap("cost", cost).
node("source", source).run();
MinCostArborescence<Digraph, CostMap> mca(digraph, cost);
mca.run(source);
vector<pair<double, set<Node> > > dualSolution(mca.dualNum());
for (int i = 0; i < mca.dualNum(); ++i) {
dualSolution[i].first = mca.dualValue(i);
for (MinCostArborescence<Digraph, CostMap>::DualIt it(mca, i);
it != INVALID; ++it) {
dualSolution[i].second.insert(it);
}
}
for (ArcIt it(digraph); it != INVALID; ++it) {
if (mca.reached(digraph.source(it))) {
double sum = 0.0;
for (int i = 0; i < int(dualSolution.size()); ++i) {
if (dualSolution[i].second.find(digraph.target(it))
!= dualSolution[i].second.end() &&
dualSolution[i].second.find(digraph.source(it))
== dualSolution[i].second.end()) {
sum += dualSolution[i].first;
}
}
if (mca.arborescence(it)) {
check(sum == cost[it], "INVALID DUAL");
}
check(sum <= cost[it], "INVALID DUAL");
}
}
check(mca.dualValue() == mca.arborescenceValue(), "INVALID DUAL");
check(mca.reached(source), "INVALID ARBORESCENCE");
for (ArcIt a(digraph); a != INVALID; ++a) {
check(!mca.reached(digraph.source(a)) ||
mca.reached(digraph.target(a)), "INVALID ARBORESCENCE");
}
for (NodeIt n(digraph); n != INVALID; ++n) {
if (!mca.reached(n)) continue;
int cnt = 0;
for (InArcIt a(digraph, n); a != INVALID; ++a) {
if (mca.arborescence(a)) {
check(mca.pred(n) == a, "INVALID ARBORESCENCE");
++cnt;
}
}
check((n == source ? cnt == 0 : cnt == 1), "INVALID ARBORESCENCE");
}
Digraph::ArcMap<bool> arborescence(digraph);
check(mca.arborescenceValue() ==
minCostArborescence(digraph, cost, source, arborescence),
"WRONG FUNCTION");
return 0;
}
|