forked from xtaci/algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelabel_to_front_demo.cpp
75 lines (60 loc) · 1.79 KB
/
relabel_to_front_demo.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "edmonds_karp.h"
#include "relabel_to_front.h"
using namespace alg;
int main(void)
{
using namespace alg;
srand(time(NULL));
int NVERTEX = 300;
clock_t ek_start, ek_end, pr_start, pr_end;
DirectedGraph * g = DirectedGraph::randgraph(NVERTEX);
// g->printdot();
printf("finding Maximal Flow from 0 to %d: \n", NVERTEX-1);
printf("The graph containing %d edges.\n", g->edge_count());
ek_start = clock();
EdmondsKarp ek(*g);
uint32_t maxflow = ek.run(0, NVERTEX-1);
ek_end = clock();
printf("Max Flow calculated by edmonds-karp algorithm is %d\n", maxflow);
// printf("the residual network\n");
// printf("\t");
// for(uint32_t i=0;i<g->vertex_count();i++) {
// printf("%d\t", ek2.rmap()[i]);
// }
// printf("\n");
// for(uint32_t i=0;i<g->vertex_count();i++) {
// printf("%d\t",ek2.rmap()[i]);
// for(uint32_t j=0;j<g->vertex_count();j++) {
// printf("%d\t", ek2.residual()(i,j));
// }
// printf("\n");
// }
pr_start = clock();
RelabelToFront pr2(*g);
uint32_t maxflow_pr = pr2.run(0, NVERTEX-1);
pr_end = clock();
printf("Max Flow calculated by push-relabel is %d\n", maxflow_pr);
// printf("the residual and preflow network\n");
// printf("\t");
// for(uint32_t i=0; i<g->vertex_count(); i++) {
// printf("%d\t", pr2.rmap()[i]);
// }
// printf("\n");
// for (uint32_t i=0; i<g->vertex_count(); i++){
// printf("%d\t", pr2.rmap()[i]);
// for (uint32_t j=0; j<g->vertex_count(); j++){
// printf("%d\t", pr2.residual()(i,j));
// }
// printf("\n");
// }
// printf("\n");
long ek_time = ek_end - ek_start;
long pr_time = pr_end - pr_start;
printf("The number of clock tick consumed by edmonds-karp is %ld\n", ek_time);
printf("--------------------------------- by push-relabel is %ld\n", pr_time);
delete g;
return 0;
}