athos@611
|
1 |
#include <iostream>
|
athos@611
|
2 |
#include "test_tools.h"
|
athos@611
|
3 |
#include <hugo/list_graph.h>
|
athos@611
|
4 |
#include <hugo/mincostflows.h>
|
athos@611
|
5 |
//#include <path.h>
|
athos@611
|
6 |
//#include <maps.h>
|
athos@611
|
7 |
|
athos@611
|
8 |
using namespace std;
|
athos@611
|
9 |
using namespace hugo;
|
athos@611
|
10 |
|
athos@611
|
11 |
|
athos@611
|
12 |
|
athos@611
|
13 |
bool passed = true;
|
athos@611
|
14 |
/*
|
athos@611
|
15 |
void check(bool rc, char *msg="") {
|
athos@611
|
16 |
passed = passed && rc;
|
athos@611
|
17 |
if(!rc) {
|
athos@611
|
18 |
std::cerr << "Test failed! ("<< msg << ")" << std::endl; \
|
athos@611
|
19 |
|
athos@611
|
20 |
|
athos@611
|
21 |
}
|
athos@611
|
22 |
}
|
athos@611
|
23 |
*/
|
athos@611
|
24 |
|
athos@611
|
25 |
|
athos@611
|
26 |
int main()
|
athos@611
|
27 |
{
|
athos@611
|
28 |
|
athos@611
|
29 |
typedef ListGraph::Node Node;
|
athos@611
|
30 |
typedef ListGraph::Edge Edge;
|
athos@611
|
31 |
|
athos@611
|
32 |
ListGraph graph;
|
athos@611
|
33 |
|
athos@611
|
34 |
//Ahuja könyv példája
|
athos@611
|
35 |
|
athos@611
|
36 |
Node s=graph.addNode();
|
athos@611
|
37 |
Node v1=graph.addNode();
|
athos@611
|
38 |
Node v2=graph.addNode();
|
athos@611
|
39 |
Node v3=graph.addNode();
|
athos@611
|
40 |
Node v4=graph.addNode();
|
athos@611
|
41 |
Node v5=graph.addNode();
|
athos@611
|
42 |
Node t=graph.addNode();
|
athos@611
|
43 |
|
athos@611
|
44 |
Edge s_v1=graph.addEdge(s, v1);
|
athos@611
|
45 |
Edge v1_v2=graph.addEdge(v1, v2);
|
athos@611
|
46 |
Edge s_v3=graph.addEdge(s, v3);
|
athos@611
|
47 |
Edge v2_v4=graph.addEdge(v2, v4);
|
athos@611
|
48 |
Edge v2_v5=graph.addEdge(v2, v5);
|
athos@611
|
49 |
Edge v3_v5=graph.addEdge(v3, v5);
|
athos@611
|
50 |
Edge v4_t=graph.addEdge(v4, t);
|
athos@611
|
51 |
Edge v5_t=graph.addEdge(v5, t);
|
athos@611
|
52 |
|
athos@611
|
53 |
|
athos@611
|
54 |
ListGraph::EdgeMap<int> length(graph);
|
athos@611
|
55 |
|
athos@611
|
56 |
length.set(s_v1, 6);
|
athos@611
|
57 |
length.set(v1_v2, 4);
|
athos@611
|
58 |
length.set(s_v3, 10);
|
athos@611
|
59 |
length.set(v2_v4, 5);
|
athos@611
|
60 |
length.set(v2_v5, 1);
|
athos@611
|
61 |
length.set(v3_v5, 5);
|
athos@611
|
62 |
length.set(v4_t, 8);
|
athos@611
|
63 |
length.set(v5_t, 8);
|
athos@611
|
64 |
|
athos@611
|
65 |
ConstMap<Edge, int> const1map(1);
|
athos@611
|
66 |
std::cout << "Mincostflows algorithm test..." << std::endl;
|
athos@611
|
67 |
|
athos@611
|
68 |
|
athos@611
|
69 |
int k=3;
|
athos@611
|
70 |
MinCostFlows< ListGraph, ListGraph::EdgeMap<int>, ConstMap<Edge, int> >
|
athos@611
|
71 |
surb_test(graph, length, const1map);
|
athos@611
|
72 |
|
athos@611
|
73 |
check( surb_test.run(s,t,k) == 2 && surb_test.totalLength() == 46,"Two paths, total length should be 46");
|
athos@611
|
74 |
|
athos@611
|
75 |
check(surb_test.checkComplementarySlackness(), "Is the primal-dual solution pair really optimal?");
|
athos@611
|
76 |
|
athos@611
|
77 |
k=1;
|
athos@611
|
78 |
check( surb_test.run(s,t,k) == 1 && surb_test.totalLength() == 19,"One path, total length should be 19");
|
athos@611
|
79 |
|
athos@611
|
80 |
check(surb_test.checkComplementarySlackness(), "Is the primal-dual solution pair really optimal?");
|
athos@611
|
81 |
|
athos@611
|
82 |
|
athos@611
|
83 |
cout << (passed ? "All tests passed." : "Some of the tests failed!!!")
|
athos@611
|
84 |
<< endl;
|
athos@611
|
85 |
|
athos@611
|
86 |
return passed ? 0 : 1;
|
athos@611
|
87 |
|
athos@611
|
88 |
}
|