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