test/arborescence_test.cc
changeset 2386 81b47fc5c444
parent 2242 16523135943d
child 2391 14a343be7a5a
equal deleted inserted replaced
2:3365c9f25fdd 3:7c8fe7296d03
    17 #include "test_tools.h"
    17 #include "test_tools.h"
    18 
    18 
    19 using namespace lemon;
    19 using namespace lemon;
    20 using namespace std;
    20 using namespace std;
    21 
    21 
    22 const int n = 10;
    22 const int NODES = 10;
    23 const int e = 22;
    23 const int EDGES = 22;
    24 
    24 
    25 int sourceNode = 0;
    25 int sourceNode = 0;
    26 
    26 
    27 int sources[e] = {
    27 int sources[EDGES] = {
    28   1, 0, 2, 4, 4, 3, 9, 8, 9, 8,
    28   1, 0, 2, 4, 4, 3, 9, 8, 9, 8,
    29   4, 2, 0, 6, 4, 1, 7, 2, 8, 6,
    29   4, 2, 0, 6, 4, 1, 7, 2, 8, 6,
    30   1, 0
    30   1, 0
    31 };
    31 };
    32 
    32 
    33 int targets[e] = {
    33 int targets[EDGES] = {
    34   8, 3, 1, 1, 4, 9, 8, 1, 8, 0,
    34   8, 3, 1, 1, 4, 9, 8, 1, 8, 0,
    35   3, 2, 1, 3, 1, 1, 2, 6, 3, 9,
    35   3, 2, 1, 3, 1, 1, 2, 6, 3, 9,
    36   1, 3
    36   1, 3
    37 };
    37 };
    38 
    38 
    39 double costs[e] = {
    39 double costs[EDGES] = {
    40   107.444, 70.3069, 46.0496, 28.3962, 91.4325,
    40   107.444, 70.3069, 46.0496, 28.3962, 91.4325,
    41   76.9443, 61.986, 39.3754, 74.9575, 39.3153,
    41   76.9443, 61.986, 39.3754, 74.9575, 39.3153,
    42   45.7094, 34.6184, 100.156, 95.726, 22.3429,
    42   45.7094, 34.6184, 100.156, 95.726, 22.3429,
    43   31.587, 51.6972, 29.6773, 115.038, 32.4137,
    43   31.587, 51.6972, 29.6773, 115.038, 32.4137,
    44   60.0038, 40.1237
    44   60.0038, 40.1237
    54 
    54 
    55   Graph graph;
    55   Graph graph;
    56   CostMap cost(graph);
    56   CostMap cost(graph);
    57   vector<Node> nodes;
    57   vector<Node> nodes;
    58   
    58   
    59   for (int i = 0; i < n; ++i) {
    59   for (int i = 0; i < NODES; ++i) {
    60     nodes.push_back(graph.addNode());
    60     nodes.push_back(graph.addNode());
    61   }
    61   }
    62 
    62 
    63   for (int i = 0; i < e; ++i) {
    63   for (int i = 0; i < EDGES; ++i) {
    64     Edge edge = graph.addEdge(nodes[sources[i]], nodes[targets[i]]);
    64     Edge edge = graph.addEdge(nodes[sources[i]], nodes[targets[i]]);
    65     cost[edge] = costs[i];
    65     cost[edge] = costs[i];
    66   }
    66   }
    67 
    67 
    68   Node source = nodes[sourceNode];
    68   Node source = nodes[sourceNode];
    83   Tolerance<double> tolerance;
    83   Tolerance<double> tolerance;
    84 
    84 
    85   for (EdgeIt it(graph); it != INVALID; ++it) {
    85   for (EdgeIt it(graph); it != INVALID; ++it) {
    86     if (mca.reached(graph.source(it))) {
    86     if (mca.reached(graph.source(it))) {
    87       double sum = 0.0;
    87       double sum = 0.0;
    88       for (int i = 0; i < (int)dualSolution.size(); ++i) {
    88       for (int i = 0; i < int(dualSolution.size()); ++i) {
    89         if (dualSolution[i].second.find(graph.target(it)) 
    89         if (dualSolution[i].second.find(graph.target(it)) 
    90             != dualSolution[i].second.end() &&
    90             != dualSolution[i].second.end() &&
    91             dualSolution[i].second.find(graph.source(it)) 
    91             dualSolution[i].second.find(graph.source(it)) 
    92             == dualSolution[i].second.end()) {
    92             == dualSolution[i].second.end()) {
    93           sum += dualSolution[i].first;
    93           sum += dualSolution[i].first;