forked from teknasd/RFIM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RFIM_2D_main.cpp
183 lines (134 loc) · 5.05 KB
/
RFIM_2D_main.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
// RFIM for 2D without OPENCV
// making use of stl vectors instead of new
// with clustering implementation
// for raw visited node output
//
// author: Teknas
//#define _HAS_ITERATOR_DEBUGGING 0
#include <fstream>
#include "Headers.h"
#include "Parameters.h"
#include "Clustering.h"
#include "PushRelabel.h"
#include "LatticeStuff.h"
using namespace std;
ofstream f;
int main(void) {
f.open("log.dat",ios::app);
//Mat image(VER, VER, CV_8UC3);
time_t time_begin, time_end, time_1, time_2;
long t1, t2, tdiff[iter] = { 0 }, l = 0, sum = 0, i, j, cap = 0, clusters = 0;
for (l = 0; l < iter; l++)
{
f << "iter: " << l <<endl;
cout << "\n\n*****ITER: " << l << "****\n\n";
/* ==================== INITIALISING 2D VECTORS ================*/
vector < vector <int> > flow(V, vector<int>(V, 0))
, CapacityMat(V, vector<int>(V, 0))
, Exmat(N, vector<int>(N, 0))
, sqlat0(VER + 1, vector<int>(VER + 1, 0))
, sqlat1(VER + 1, vector<int>(VER + 1, 0));
/* ==================== INITIALISING 1D VECTORS ================*/
vector <int> visited(V, 0), Wmat(N, 0), latt(N, 1), Bmat(N, 0), clusstats0(V / 2, 0), clusstats1(V / 2, 0);
/* =========================== BETA MATRIX (Bmat)======================= */
//create_Bmat_bimodal(Bmat); // UNCOMMENT FOR BIMODAL DISTRIBUTION
create_Bmat_gaussian(Bmat);
cout << "Bmat created" << endl;
/* ====================== CREATING EXISTANCE MATRIX (Exmat)============= */
create_Exmat(Exmat, latt);
cout << "Exmat created" << endl;
/* ================= CREATING CAPACITY MATRIX (CapacityMat)============= */
create_CapacityMat(CapacityMat, Exmat);
cout << "created CapacityMatrix" << endl;
/* =================== LOOP TO ITERATE OVER RANGE OF DELTA ============= */
for (int del = del_beg; del <= del_end; del += del_inc)
{
f << "del: " << del << endl;
//open
cout << "\ndEL: " << float(del) / 10 << tab;
create_Wmat(Wmat, CapacityMat, Bmat, del);
/* =========== AGUMENTING CAPACITY MATRIX WITH WMAT ============= */
create_Augumented_CapacityMat(Wmat, CapacityMat);
t1 = time(&time_1); /* get current time;*/
/*================================================================================================*/
/* ladies and gentlemen its honour to present you the most important stuff in this awesome code */
/* ===================== CALLING PUSH RELABEL(CapacityMat)======================================= */
pushRelabel(CapacityMat, flow, 0, V - 1);
/*====================================================================================*/
t2 = time(&time_2); /* get current time;*/
/* ====================== CREATE RESIDUAL GRAPH ================== */
create_Residual_graph(CapacityMat, flow);
/*======================================================*/
/*============ CLUSTERIZATION ======================= */
/*======================================================*/
/* ================= DEPTH FIRST SEARCH ON FLOW ================== */
dfs(flow, 0, visited);
/* ============ CREATE AGUMENTED MATRIX AROUND LATTICE =========== */
createAgumentedMatrix(sqlat0, sqlat1, visited);
/* ====================== HK CLUSTER ALGO ================== */
cluster(sqlat1, 1, clusstats1);
cluster(sqlat0, 0, clusstats0);
/* ====================== PRINT CLUSTERS ================== */
//printCluster(sqlat1, clusstats1);
//printCluster(sqlat0, clusstats0);
/* ====================== COUNT CLUSTERS ================== */
clusters = no_of_clusters(clusstats0, clusstats1);
cout << "clusters: " << clusters << "\n\n";
f << "clusters: " << clusters << endl;
tdiff[l] = t2 - t1;
sum += tdiff[l];
//re_init
for (i = 0; i < V; i++)
{
for (j = 0; j < V; j++)
{
if (i < VER + 1 && j < VER + 1)
{
sqlat0[i][j] = 0;
sqlat1[i][j] = 0;
}
flow[i][j] = 0;
}
if (i < V / 2)
{
clusstats0[i] = 0;
clusstats1[i] = 0;
}
if (i < N)
{
Wmat[i] = 0;
}visited[i] = 0;
}
//close
}
//
//flow.erase(flow.begin(), flow.end());
//CapacityMat.erase(CapacityMat.begin(), CapacityMat.end());
//Exmat.erase(Exmat.begin(), Exmat.end());
//visited.erase(visited.begin(), visited.end());
//Wmat.erase(Wmat.begin(), Wmat.end());
//sqlat0.erase(sqlat0.begin(), sqlat0.end());
//sqlat1.erase(sqlat1.begin(), sqlat1.end());
//clusstats0.erase(clusstats0.begin(), clusstats0.end());
//clusstats1.erase(clusstats1.begin(), clusstats1.end());
flow.clear();
CapacityMat.clear();
Exmat.clear();
visited.clear();
Wmat.clear();
sqlat0.clear();
sqlat1.clear();
clusstats0.clear();
clusstats1.clear();
f << endl;
}
cout << "\n\n\nAVERAGE TIME for " << VER << " ver : " << sum / iter << endl;
// print time req for each iter
for (l = 0; l < iter; l++)
{
cout << "-" << tdiff[l];
}
f.close();
//system("PAUSE");
return 0;
}