src/work/athos/minlengthpaths_test.cc
author marci
Tue, 11 May 2004 12:09:06 +0000
changeset 605 b3c57602c516
child 607 327f7cf13843
permissions -rw-r--r--
docs
athos@520
     1
#include <iostream>
athos@520
     2
#include <list_graph.h>
athos@520
     3
#include <minlengthpaths.h>
athos@520
     4
#include <path.h>
athos@520
     5
athos@520
     6
using namespace std;
athos@520
     7
using namespace hugo;
athos@520
     8
athos@520
     9
athos@520
    10
athos@520
    11
bool passed = true;
athos@520
    12
athos@520
    13
void check(bool rc, char *msg="") {
athos@520
    14
  passed = passed && rc;
athos@520
    15
  if(!rc) {
athos@520
    16
    std::cerr << "Test failed! ("<< msg << ")" << std::endl; \
athos@520
    17
 
athos@520
    18
athos@520
    19
  }
athos@520
    20
}
athos@520
    21
athos@520
    22
athos@520
    23
athos@520
    24
int main()
athos@520
    25
{
athos@520
    26
athos@520
    27
  typedef ListGraph::Node Node;
athos@520
    28
  typedef ListGraph::Edge Edge;
athos@520
    29
athos@520
    30
  ListGraph graph;
athos@520
    31
athos@520
    32
  //Ahuja könyv példája
athos@520
    33
athos@520
    34
  Node s=graph.addNode();
athos@520
    35
  Node v1=graph.addNode();  
athos@520
    36
  Node v2=graph.addNode();
athos@520
    37
  Node v3=graph.addNode();
athos@520
    38
  Node v4=graph.addNode();
athos@520
    39
  Node v5=graph.addNode();
athos@520
    40
  Node t=graph.addNode();
athos@520
    41
athos@520
    42
  Edge s_v1=graph.addEdge(s, v1);
athos@520
    43
  Edge v1_v2=graph.addEdge(v1, v2);
athos@520
    44
  Edge s_v3=graph.addEdge(s, v3);
athos@520
    45
  Edge v2_v4=graph.addEdge(v2, v4);
athos@520
    46
  Edge v2_v5=graph.addEdge(v2, v5);
athos@520
    47
  Edge v3_v5=graph.addEdge(v3, v5);
athos@520
    48
  Edge v4_t=graph.addEdge(v4, t);
athos@520
    49
  Edge v5_t=graph.addEdge(v5, t);
athos@520
    50
  
athos@520
    51
athos@520
    52
  ListGraph::EdgeMap<int> length(graph);
athos@520
    53
athos@520
    54
  length.set(s_v1, 6);
athos@520
    55
  length.set(v1_v2, 4);
athos@520
    56
  length.set(s_v3, 10);
athos@520
    57
  length.set(v2_v4, 5);
athos@520
    58
  length.set(v2_v5, 1);
athos@520
    59
  length.set(v3_v5, 5);
athos@520
    60
  length.set(v4_t, 8);
athos@520
    61
  length.set(v5_t, 8);
athos@520
    62
athos@520
    63
  std::cout << "Minlengthpaths algorithm test..." << std::endl;
athos@520
    64
athos@520
    65
  
athos@520
    66
  int k=3;
athos@520
    67
  MinLengthPaths< ListGraph, ListGraph::EdgeMap<int> >
athos@520
    68
    surb_test(graph, length);
athos@520
    69
athos@520
    70
  check(  surb_test.run(s,t,k) == 2 && surb_test.totalLength() == 46,"Two paths, total length should be 46");
athos@520
    71
athos@520
    72
  typedef DirPath<ListGraph> DPath;
athos@520
    73
  DPath P(graph);
athos@520
    74
athos@520
    75
  surb_test.getPath(P,0);
athos@520
    76
  check(P.length() == 4, "First path should contain 4 edges.");  
athos@520
    77
athos@520
    78
  surb_test.getPath(P,1);
athos@520
    79
  check(P.length() == 3, "Second path: 3 edges.");
athos@520
    80
  
athos@520
    81
  k=1;
athos@520
    82
  check(  surb_test.run(s,t,k) == 1 && surb_test.totalLength() == 19,"One path, total length should be 19");
athos@520
    83
 
athos@520
    84
  surb_test.getPath(P,0);
athos@520
    85
  check(P.length() == 4, "First path should contain 4 edges.");  
athos@520
    86
athos@520
    87
  cout << (passed ? "All tests passed." : "Some of the tests failed!!!")
athos@520
    88
       << endl;
athos@520
    89
athos@520
    90
  return passed ? 0 : 1;
athos@520
    91
athos@520
    92
}