src/test/min_length_paths_test.cc
author deba
Wed, 22 Sep 2004 08:04:31 +0000
changeset 897 ef09eee53b09
permissions -rw-r--r--
The default constructors are removed from the maps.
The ArrayMap is the map structure of the graphs.
alpar@896
     1
#include <iostream>
alpar@896
     2
#include <hugo/list_graph.h>
alpar@896
     3
#include <hugo/min_length_paths.h>
alpar@896
     4
//#include <path.h>
alpar@896
     5
#include "test_tools.h"
alpar@896
     6
alpar@896
     7
using namespace std;
alpar@896
     8
using namespace hugo;
alpar@896
     9
alpar@896
    10
alpar@896
    11
alpar@896
    12
bool passed = true;
alpar@896
    13
alpar@896
    14
alpar@896
    15
int main()
alpar@896
    16
{
alpar@896
    17
alpar@896
    18
  typedef ListGraph::Node Node;
alpar@896
    19
  typedef ListGraph::Edge Edge;
alpar@896
    20
alpar@896
    21
  ListGraph graph;
alpar@896
    22
alpar@896
    23
  //Ahuja könyv példája
alpar@896
    24
alpar@896
    25
  Node s=graph.addNode();
alpar@896
    26
  Node v1=graph.addNode();  
alpar@896
    27
  Node v2=graph.addNode();
alpar@896
    28
  Node v3=graph.addNode();
alpar@896
    29
  Node v4=graph.addNode();
alpar@896
    30
  Node v5=graph.addNode();
alpar@896
    31
  Node t=graph.addNode();
alpar@896
    32
alpar@896
    33
  Edge s_v1=graph.addEdge(s, v1);
alpar@896
    34
  Edge v1_v2=graph.addEdge(v1, v2);
alpar@896
    35
  Edge s_v3=graph.addEdge(s, v3);
alpar@896
    36
  Edge v2_v4=graph.addEdge(v2, v4);
alpar@896
    37
  Edge v2_v5=graph.addEdge(v2, v5);
alpar@896
    38
  Edge v3_v5=graph.addEdge(v3, v5);
alpar@896
    39
  Edge v4_t=graph.addEdge(v4, t);
alpar@896
    40
  Edge v5_t=graph.addEdge(v5, t);
alpar@896
    41
  
alpar@896
    42
alpar@896
    43
  ListGraph::EdgeMap<int> length(graph);
alpar@896
    44
alpar@896
    45
  length.set(s_v1, 6);
alpar@896
    46
  length.set(v1_v2, 4);
alpar@896
    47
  length.set(s_v3, 10);
alpar@896
    48
  length.set(v2_v4, 5);
alpar@896
    49
  length.set(v2_v5, 1);
alpar@896
    50
  length.set(v3_v5, 5);
alpar@896
    51
  length.set(v4_t, 8);
alpar@896
    52
  length.set(v5_t, 8);
alpar@896
    53
alpar@896
    54
  std::cout << "Minlengthpaths algorithm test..." << std::endl;
alpar@896
    55
alpar@896
    56
  
alpar@896
    57
  int k=3;
alpar@896
    58
  MinLengthPaths< ListGraph, ListGraph::EdgeMap<int> >
alpar@896
    59
    surb_test(graph, length);
alpar@896
    60
alpar@896
    61
  check(  surb_test.run(s,t,k) == 2 && surb_test.totalLength() == 46,
alpar@896
    62
	  "Two paths, total length should be 46");
alpar@896
    63
alpar@896
    64
  check(  surb_test.checkComplementarySlackness(),
alpar@896
    65
	  "Complementary slackness conditions are not met.");
alpar@896
    66
alpar@896
    67
  //  typedef DirPath<ListGraph> DPath;
alpar@896
    68
  //  DPath P(graph);
alpar@896
    69
alpar@896
    70
  /*
alpar@896
    71
  surb_test.getPath(P,0);
alpar@896
    72
  check(P.length() == 4, "First path should contain 4 edges.");  
alpar@896
    73
  cout<<P.length()<<endl;
alpar@896
    74
  surb_test.getPath(P,1);
alpar@896
    75
  check(P.length() == 3, "Second path: 3 edges.");
alpar@896
    76
  cout<<P.length()<<endl;
alpar@896
    77
  */  
alpar@896
    78
alpar@896
    79
  k=1;
alpar@896
    80
  check(  surb_test.run(s,t,k) == 1 && surb_test.totalLength() == 19,
alpar@896
    81
	  "One path, total length should be 19");
alpar@896
    82
alpar@896
    83
  check(  surb_test.checkComplementarySlackness(),
alpar@896
    84
	  "Complementary slackness conditions are not met.");
alpar@896
    85
 
alpar@896
    86
  //  surb_test.getPath(P,0);
alpar@896
    87
  //  check(P.length() == 4, "First path should contain 4 edges.");  
alpar@896
    88
alpar@896
    89
  cout << (passed ? "All tests passed." : "Some of the tests failed!!!")
alpar@896
    90
       << endl;
alpar@896
    91
alpar@896
    92
  return passed ? 0 : 1;
alpar@896
    93
alpar@896
    94
}