# source:lemon-0.x/src/work/athos/mincostflows_test.cc@530:d9c06ac0b3a3

Last change on this file since 530:d9c06ac0b3a3 was 530:d9c06ac0b3a3, checked in by athos, 17 years ago

Minimum cost flows of small values: algorithm from Andras Frank's lecture notes (approximately)

File size: 2.2 KB
Line
1#include <iostream>
2#include <list_graph.h>
3#include <mincostflows.h>
4//#include <path.h>
5#include <maps.h>
6
7using namespace std;
8using namespace hugo;
9
10
11
12bool passed = true;
13
14void check(bool rc, char *msg="") {
15  passed = passed && rc;
16  if(!rc) {
17    std::cerr << "Test failed! ("<< msg << ")" << std::endl; \
18
19
20  }
21}
22
23
24
25int main()
26{
27
28  typedef ListGraph::Node Node;
29  typedef ListGraph::Edge Edge;
30
31  ListGraph graph;
32
33  //Ahuja könyv példája
34
42
51
52
53  ListGraph::EdgeMap<int> length(graph);
54
55  length.set(s_v1, 6);
56  length.set(v1_v2, 4);
57  length.set(s_v3, 10);
58  length.set(v2_v4, 5);
59  length.set(v2_v5, 1);
60  length.set(v3_v5, 5);
61  length.set(v4_t, 8);
62  length.set(v5_t, 8);
63
64  ConstMap<Edge, int> const1map(1);
65  std::cout << "Mincostflows algorithm test..." << std::endl;
66
67
68  int k=3;
69  MinCostFlows< ListGraph, ListGraph::EdgeMap<int>, ConstMap<Edge, int> >
70    surb_test(graph, length, const1map);
71
72  check(  surb_test.run(s,t,k) == 2 && surb_test.totalLength() == 46,"Two paths, total length should be 46");
73
74  k=1;
75  check(  surb_test.run(s,t,k) == 1 && surb_test.totalLength() == 19,"One path, total length should be 19");
76
77  //cout << surb_test.run(s,t,k) << surb_test.totalLength()<<endl;
78  /*
79  typedef DirPath<ListGraph> DPath;
80  DPath P(graph);
81
82  surb_test.getPath(P,0);
83  check(P.length() == 4, "First path should contain 4 edges.");
84
85  surb_test.getPath(P,1);
86  check(P.length() == 3, "Second path: 3 edges.");
87
88  k=1;
89  check(  surb_test.run(s,t,k) == 1 && surb_test.totalLength() == 19,"One path, total length should be 19");
90
91  surb_test.getPath(P,0);
92  check(P.length() == 4, "First path should contain 4 edges.");
93  */
94  cout << (passed ? "All tests passed." : "Some of the tests failed!!!")
95       << endl;
96
97  return passed ? 0 : 1;
98
99}
Note: See TracBrowser for help on using the repository browser.