src/test/preflow_test.cc
changeset 858 acc83957ee4a
parent 855 8c44b64dd436
child 859 2570784896d8
equal deleted inserted replaced
3:a2e2efc379af 4:b9c15a1f0969
     1 #include <fstream>
     1 #include <fstream>
       
     2 #include <string>
       
     3 
     2 #include "test_tools.h"
     4 #include "test_tools.h"
     3 #include <hugo/smart_graph.h>
     5 #include <hugo/smart_graph.h>
     4 #include <hugo/dimacs.h>
     6 #include <hugo/dimacs.h>
     5 #include <hugo/preflow.h>
     7 #include <hugo/preflow.h>
     6 #include <hugo/skeletons/graph.h>
     8 #include <hugo/skeletons/graph.h>
     7 #include <hugo/skeletons/maps.h>
     9 #include <hugo/skeletons/maps.h>
     8 
       
     9 #include <string.h>
       
    10 
    10 
    11 using namespace hugo;
    11 using namespace hugo;
    12 
    12 
    13 void check_Preflow() 
    13 void check_Preflow() 
    14 {
    14 {
    67   typedef Graph::EdgeMap<int> FlowMap;
    67   typedef Graph::EdgeMap<int> FlowMap;
    68   typedef Graph::NodeMap<bool> CutMap;
    68   typedef Graph::NodeMap<bool> CutMap;
    69 
    69 
    70   typedef Preflow<Graph, int> PType;
    70   typedef Preflow<Graph, int> PType;
    71 
    71 
    72   char *f_name;
    72   string f_name;
       
    73   if( getenv("srcdir") ) {
       
    74     f_name = string(getenv("srcdir")) + "/preflow_graph.inp";
       
    75   }
       
    76   else {
       
    77     f_name = "preflow_graph.inp";
       
    78   }
    73   
    79   
    74   f_name=new char[strlen(getenv("srcdir"))+50];
    80   std::ifstream file(f_name.c_str());
    75   strcpy(f_name,getenv("srcdir"));
       
    76   strcat(f_name,"/preflow_graph.inp");
       
    77   
    81   
    78   std::ifstream file(f_name);
    82   check(file, "Input file '" << f_name << "' not found.");
    79   
       
    80   check(file,"Input file '" << f_name << "' not found.");
       
    81   
       
    82   delete [] f_name;
       
    83   
    83   
    84   Graph G;
    84   Graph G;
    85   Node s, t;
    85   Node s, t;
    86   CapMap cap(G);
    86   CapMap cap(G);
    87   readDimacs(file, G, cap, s, t);
    87   readDimacs(file, G, cap, s, t);
   178   check(preflow_test.flowValue() == min_cut_value &&
   178   check(preflow_test.flowValue() == min_cut_value &&
   179 	min_cut_value == min_min_cut_value &&
   179 	min_cut_value == min_min_cut_value &&
   180 	min_min_cut_value == max_min_cut_value,
   180 	min_min_cut_value == max_min_cut_value,
   181 	"The max flow value or the three min cut values are incorrect.");
   181 	"The max flow value or the three min cut values are incorrect.");
   182 }
   182 }
   183 
       
   184 
       
   185