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