src/test/mincostflows_test.cc
changeset 660 edb42cb9d352
parent 611 83530dad618a
equal deleted inserted replaced
0:dc044773ca07 1:c700e70e004f
    56   length.set(s_v1, 6);
    56   length.set(s_v1, 6);
    57   length.set(v1_v2, 4);
    57   length.set(v1_v2, 4);
    58   length.set(s_v3, 10);
    58   length.set(s_v3, 10);
    59   length.set(v2_v4, 5);
    59   length.set(v2_v4, 5);
    60   length.set(v2_v5, 1);
    60   length.set(v2_v5, 1);
    61   length.set(v3_v5, 5);
    61   length.set(v3_v5, 4);
    62   length.set(v4_t, 8);
    62   length.set(v4_t, 8);
    63   length.set(v5_t, 8);
    63   length.set(v5_t, 8);
    64 
    64 
    65   ConstMap<Edge, int> const1map(1);
    65   ListGraph::EdgeMap<int> capacity(graph);
       
    66 
       
    67   capacity.set(s_v1, 2);
       
    68   capacity.set(v1_v2, 2);
       
    69   capacity.set(s_v3, 1);
       
    70   capacity.set(v2_v4, 1);
       
    71   capacity.set(v2_v5, 1);
       
    72   capacity.set(v3_v5, 1);
       
    73   capacity.set(v4_t, 1);
       
    74   capacity.set(v5_t, 2);
       
    75 
       
    76   //  ConstMap<Edge, int> const1map(1);
    66   std::cout << "Mincostflows algorithm test..." << std::endl;
    77   std::cout << "Mincostflows algorithm test..." << std::endl;
    67 
    78 
    68   
    79   MinCostFlows< ListGraph, ListGraph::EdgeMap<int>, ListGraph::EdgeMap<int> >
    69   int k=3;
    80     surb_test(graph, length, capacity);
    70   MinCostFlows< ListGraph, ListGraph::EdgeMap<int>, ConstMap<Edge, int> >
       
    71     surb_test(graph, length, const1map);
       
    72 
    81 
    73   check(  surb_test.run(s,t,k) == 2 && surb_test.totalLength() == 46,"Two paths, total length should be 46");
    82   int k=1;
    74 
    83 
    75   check(surb_test.checkComplementarySlackness(), "Is the primal-dual solution pair really optimal?");
       
    76 
       
    77   k=1;
       
    78   check(  surb_test.run(s,t,k) == 1 && surb_test.totalLength() == 19,"One path, total length should be 19");
    84   check(  surb_test.run(s,t,k) == 1 && surb_test.totalLength() == 19,"One path, total length should be 19");
    79 
    85 
    80   check(surb_test.checkComplementarySlackness(), "Is the primal-dual solution pair really optimal?");
    86   check(surb_test.checkComplementarySlackness(), "Is the primal-dual solution pair really optimal?");
    81   
    87   
       
    88   k=2;
       
    89   
       
    90   check(  surb_test.run(s,t,k) == 2 && surb_test.totalLength() == 41,"Two paths, total length should be 41");
       
    91 
       
    92   check(surb_test.checkComplementarySlackness(), "Is the primal-dual solution pair really optimal?");
       
    93   
       
    94   
       
    95   k=4;
       
    96 
       
    97   check(  surb_test.run(s,t,k) == 3 && surb_test.totalLength() == 64,"Three paths, total length should be 64");
       
    98 
       
    99   check(surb_test.checkComplementarySlackness(), "Is the primal-dual solution pair really optimal?");
       
   100 
    82 
   101 
    83   cout << (passed ? "All tests passed." : "Some of the tests failed!!!")
   102   cout << (passed ? "All tests passed." : "Some of the tests failed!!!")
    84        << endl;
   103        << endl;
    85 
   104 
    86   return passed ? 0 : 1;
   105   return passed ? 0 : 1;