[10] | 1 | #include <benchmark_tools.h> |
---|
[9] | 2 | #include <lemon/circulation.h> |
---|
| 3 | #include <lemon/smart_graph.h> |
---|
| 4 | #include <lemon/lgf_reader.h> |
---|
| 5 | #include <lemon/dimacs.h> |
---|
| 6 | #include <lemon/error.h> |
---|
[11] | 7 | #include <istream> |
---|
[9] | 8 | |
---|
[11] | 9 | std::string test_name = "circulation"; |
---|
[9] | 10 | |
---|
| 11 | using namespace lemon; |
---|
| 12 | |
---|
[11] | 13 | int testMain(std::istream &input) |
---|
[9] | 14 | { |
---|
| 15 | typedef int Value; |
---|
| 16 | |
---|
| 17 | SmartDigraph g; |
---|
| 18 | |
---|
| 19 | SmartDigraph::ArcMap<Value> lo_cap(g); |
---|
| 20 | SmartDigraph::ArcMap<Value> up_cap(g); |
---|
| 21 | SmartDigraph::ArcMap<Value> cost(g); |
---|
| 22 | SmartDigraph::NodeMap<Value> sup(g); |
---|
| 23 | |
---|
| 24 | Timer ti; |
---|
| 25 | try { |
---|
| 26 | readDimacsMin(input, g, lo_cap, up_cap, cost, sup); |
---|
| 27 | } catch (FormatError& error) { |
---|
| 28 | std::cerr << error.what() << std::endl; |
---|
| 29 | return 1; |
---|
| 30 | } |
---|
[11] | 31 | logTime("fread",ti); |
---|
[10] | 32 | |
---|
| 33 | Timer tf; |
---|
[9] | 34 | ti.restart(); |
---|
| 35 | Circulation<SmartDigraph, |
---|
| 36 | SmartDigraph::ArcMap<Value>,SmartDigraph::ArcMap<Value>, |
---|
| 37 | SmartDigraph::NodeMap<Value> > circ(g,lo_cap,up_cap,sup); |
---|
[10] | 38 | logTime("setup",ti); |
---|
[9] | 39 | ti.restart(); |
---|
| 40 | bool res = circ.run(); |
---|
[10] | 41 | logTime("alg",ti); |
---|
| 42 | logTime("full",tf); |
---|
[9] | 43 | if(res) |
---|
| 44 | { |
---|
[10] | 45 | std::cerr << "A feasible circulation is found\n"; |
---|
| 46 | std::cerr << "Checking...\n"; |
---|
[9] | 47 | ti.restart(); |
---|
| 48 | bool res2 = circ.checkFlow(); |
---|
[10] | 49 | logTime("check",ti); |
---|
[9] | 50 | if(res2) |
---|
[10] | 51 | std::cerr << "Success!\n"; |
---|
[9] | 52 | else |
---|
[10] | 53 | std::cerr << "Oops!!!!\n"; |
---|
[9] | 54 | } |
---|
| 55 | else |
---|
| 56 | { |
---|
[10] | 57 | std::cerr << "A dual solution is found\n"; |
---|
| 58 | std::cerr << "Checking...\n"; |
---|
[9] | 59 | ti.restart(); |
---|
| 60 | bool res2 = circ.checkBarrier(); |
---|
[10] | 61 | logTime("check",ti); |
---|
[9] | 62 | if(res2) |
---|
[10] | 63 | std::cerr << "Success!\n"; |
---|
[9] | 64 | else |
---|
[10] | 65 | std::cerr << "Dual-Oops!!!!\n"; |
---|
[9] | 66 | |
---|
| 67 | } |
---|
| 68 | } |
---|
| 69 | |
---|