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