Circulation test code added
authorAlpar Juttner <alpar@cs.elte.hu>
Sun, 11 Dec 2011 06:55:47 +0100
changeset 97768d68909e8
parent 8 3c30bd0f9ccc
child 10 d7ce0311ece2
Circulation test code added
CMakeLists.txt
tests/CMakeLists.txt
tests/circulation.cc
     1.1 --- a/CMakeLists.txt	Sun Dec 11 06:53:16 2011 +0100
     1.2 +++ b/CMakeLists.txt	Sun Dec 11 06:55:47 2011 +0100
     1.3 @@ -87,6 +87,8 @@
     1.4  ADD_SUBDIRECTORY(generators/netgen)
     1.5  ADD_SUBDIRECTORY(data)
     1.6  
     1.7 +ADD_SUBDIRECTORY(tests)
     1.8 +
     1.9  #######################################################################
    1.10  ## CPACK configuration
    1.11  ##
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/tests/CMakeLists.txt	Sun Dec 11 06:55:47 2011 +0100
     2.3 @@ -0,0 +1,28 @@
     2.4 +INCLUDE_DIRECTORIES(
     2.5 +  ${CMAKE_SOURCE_DIR}/tests
     2.6 +  # ${CMAKE_BINARY_DIR}/src
     2.7 +)
     2.8 +
     2.9 +LINK_DIRECTORIES(
    2.10 +  # ${CMAKE_BINARY_DIR}/lemon
    2.11 +)
    2.12 +
    2.13 +ADD_EXECUTABLE(circulation
    2.14 +        circulation.cc
    2.15 +)
    2.16 +
    2.17 +TARGET_LINK_LIBRARIES(circulation
    2.18 +  lemon
    2.19 +)
    2.20 +
    2.21 +
    2.22 +## This tells cmake to install 'lemon-project' to $PREFIX/bin when
    2.23 +## 'make install' is executed. You can give more targets separated
    2.24 +## by whitespaces.
    2.25 +
    2.26 +INSTALL(
    2.27 +  TARGETS
    2.28 +  RUNTIME DESTINATION ${INSTALL_BIN_DIR}
    2.29 +  COMPONENT bin
    2.30 +)
    2.31 + 
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/tests/circulation.cc	Sun Dec 11 06:55:47 2011 +0100
     3.3 @@ -0,0 +1,67 @@
     3.4 +#include <lemon/circulation.h>
     3.5 +#include <lemon/smart_graph.h>
     3.6 +#include <lemon/lgf_reader.h>
     3.7 +#include <lemon/dimacs.h>
     3.8 +#include <lemon/time_measure.h>
     3.9 +#include <lemon/error.h>
    3.10 +
    3.11 +const char test_name[] = "circulation";
    3.12 +
    3.13 +using namespace lemon;
    3.14 +
    3.15 +int main(int argc, char **argv)
    3.16 +{
    3.17 +  if(argc!=2) exit(1);
    3.18 +
    3.19 +  typedef int Value;
    3.20 +  
    3.21 +  SmartDigraph g;
    3.22 +  
    3.23 +  SmartDigraph::ArcMap<Value> lo_cap(g);
    3.24 +  SmartDigraph::ArcMap<Value> up_cap(g);
    3.25 +  SmartDigraph::ArcMap<Value> cost(g);
    3.26 +  SmartDigraph::NodeMap<Value> sup(g);
    3.27 +  
    3.28 +  Timer ti;
    3.29 +  try {
    3.30 +    std::ifstream input;
    3.31 +    input.open(argv[1]);
    3.32 +    readDimacsMin(input, g, lo_cap, up_cap, cost, sup);
    3.33 +  } catch (FormatError& error) {
    3.34 +    std::cerr << error.what() << std::endl;
    3.35 +    return 1;
    3.36 +  }
    3.37 +  std::cerr << "Read the file: " << ti << '\n';
    3.38 +  ti.restart();
    3.39 +  
    3.40 +  Circulation<SmartDigraph,
    3.41 +    SmartDigraph::ArcMap<Value>,SmartDigraph::ArcMap<Value>,
    3.42 +    SmartDigraph::NodeMap<Value> > circ(g,lo_cap,up_cap,sup);
    3.43 +  std::cerr << "Setup Circulation class: " << ti << '\n';
    3.44 +  ti.restart();
    3.45 +  bool res = circ.run();
    3.46 +  if(res)
    3.47 +    {
    3.48 +      std::cerr << "A feasible circulation is found: " << ti << "\n";
    3.49 +      ti.restart();
    3.50 +      bool res2 = circ.checkFlow();
    3.51 +      std::cerr << "Checked in time " << ti << "\n";
    3.52 +      if(res2)
    3.53 +        std::cerr << "Success!\nn";
    3.54 +      else
    3.55 +        std::cerr << "Oops!!!!\n\n";
    3.56 +    }
    3.57 +  else
    3.58 +    {
    3.59 +      std::cerr << "A dual solution is found: " << ti << "\n";
    3.60 +      ti.restart();
    3.61 +      bool res2 = circ.checkBarrier();
    3.62 +      std::cerr << "Checked in time " << ti << "\n";
    3.63 +      if(res2)
    3.64 +        std::cerr << "Success!\nn";
    3.65 +      else
    3.66 +        std::cerr << "Dual-Oops!!!!\n\n";
    3.67 +
    3.68 +    }
    3.69 +}
    3.70 +