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