src/test/mincostflows_test.cc
author alpar
Thu, 22 Jul 2004 19:59:18 +0000
changeset 732 33cbc0635e92
parent 611 83530dad618a
permissions -rw-r--r--
Skeletons have been simplified.
"Optional features" have been deleted.
Map skeletons have been renamed.
athos@611
     1
#include <iostream>
athos@611
     2
#include "test_tools.h"
athos@611
     3
#include <hugo/list_graph.h>
athos@611
     4
#include <hugo/mincostflows.h>
athos@611
     5
//#include <path.h>
athos@611
     6
//#include <maps.h>
athos@611
     7
athos@611
     8
using namespace std;
athos@611
     9
using namespace hugo;
athos@611
    10
athos@611
    11
athos@611
    12
athos@611
    13
bool passed = true;
athos@611
    14
/*
athos@611
    15
void check(bool rc, char *msg="") {
athos@611
    16
  passed = passed && rc;
athos@611
    17
  if(!rc) {
athos@611
    18
    std::cerr << "Test failed! ("<< msg << ")" << std::endl; \
athos@611
    19
 
athos@611
    20
athos@611
    21
  }
athos@611
    22
}
athos@611
    23
*/
athos@611
    24
athos@611
    25
athos@611
    26
int main()
athos@611
    27
{
athos@611
    28
athos@611
    29
  typedef ListGraph::Node Node;
athos@611
    30
  typedef ListGraph::Edge Edge;
athos@611
    31
athos@611
    32
  ListGraph graph;
athos@611
    33
athos@611
    34
  //Ahuja könyv példája
athos@611
    35
athos@611
    36
  Node s=graph.addNode();
athos@611
    37
  Node v1=graph.addNode();  
athos@611
    38
  Node v2=graph.addNode();
athos@611
    39
  Node v3=graph.addNode();
athos@611
    40
  Node v4=graph.addNode();
athos@611
    41
  Node v5=graph.addNode();
athos@611
    42
  Node t=graph.addNode();
athos@611
    43
athos@611
    44
  Edge s_v1=graph.addEdge(s, v1);
athos@611
    45
  Edge v1_v2=graph.addEdge(v1, v2);
athos@611
    46
  Edge s_v3=graph.addEdge(s, v3);
athos@611
    47
  Edge v2_v4=graph.addEdge(v2, v4);
athos@611
    48
  Edge v2_v5=graph.addEdge(v2, v5);
athos@611
    49
  Edge v3_v5=graph.addEdge(v3, v5);
athos@611
    50
  Edge v4_t=graph.addEdge(v4, t);
athos@611
    51
  Edge v5_t=graph.addEdge(v5, t);
athos@611
    52
  
athos@611
    53
athos@611
    54
  ListGraph::EdgeMap<int> length(graph);
athos@611
    55
athos@611
    56
  length.set(s_v1, 6);
athos@611
    57
  length.set(v1_v2, 4);
athos@611
    58
  length.set(s_v3, 10);
athos@611
    59
  length.set(v2_v4, 5);
athos@611
    60
  length.set(v2_v5, 1);
athos@630
    61
  length.set(v3_v5, 4);
athos@611
    62
  length.set(v4_t, 8);
athos@611
    63
  length.set(v5_t, 8);
athos@611
    64
athos@630
    65
  ListGraph::EdgeMap<int> capacity(graph);
athos@630
    66
athos@630
    67
  capacity.set(s_v1, 2);
athos@630
    68
  capacity.set(v1_v2, 2);
athos@630
    69
  capacity.set(s_v3, 1);
athos@630
    70
  capacity.set(v2_v4, 1);
athos@630
    71
  capacity.set(v2_v5, 1);
athos@630
    72
  capacity.set(v3_v5, 1);
athos@630
    73
  capacity.set(v4_t, 1);
athos@630
    74
  capacity.set(v5_t, 2);
athos@630
    75
athos@630
    76
  //  ConstMap<Edge, int> const1map(1);
athos@611
    77
  std::cout << "Mincostflows algorithm test..." << std::endl;
athos@611
    78
athos@630
    79
  MinCostFlows< ListGraph, ListGraph::EdgeMap<int>, ListGraph::EdgeMap<int> >
athos@630
    80
    surb_test(graph, length, capacity);
athos@611
    81
athos@630
    82
  int k=1;
athos@611
    83
athos@611
    84
  check(  surb_test.run(s,t,k) == 1 && surb_test.totalLength() == 19,"One path, total length should be 19");
athos@611
    85
athos@611
    86
  check(surb_test.checkComplementarySlackness(), "Is the primal-dual solution pair really optimal?");
athos@611
    87
  
athos@630
    88
  k=2;
athos@630
    89
  
athos@630
    90
  check(  surb_test.run(s,t,k) == 2 && surb_test.totalLength() == 41,"Two paths, total length should be 41");
athos@630
    91
athos@630
    92
  check(surb_test.checkComplementarySlackness(), "Is the primal-dual solution pair really optimal?");
athos@630
    93
  
athos@630
    94
  
athos@630
    95
  k=4;
athos@630
    96
athos@630
    97
  check(  surb_test.run(s,t,k) == 3 && surb_test.totalLength() == 64,"Three paths, total length should be 64");
athos@630
    98
athos@630
    99
  check(surb_test.checkComplementarySlackness(), "Is the primal-dual solution pair really optimal?");
athos@630
   100
athos@611
   101
athos@611
   102
  cout << (passed ? "All tests passed." : "Some of the tests failed!!!")
athos@611
   103
       << endl;
athos@611
   104
athos@611
   105
  return passed ? 0 : 1;
athos@611
   106
athos@611
   107
}