forked from teknasd/RFIM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Clustering.cpp
175 lines (146 loc) · 3.63 KB
/
Clustering.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
#include "Headers.h"
#include "Parameters.h" // >> contains all the req parameters
///*
//* A DFS based function to find all reachable vertices from s.
//*/
void dfs(std::vector <std::vector <int> >& F, long s, std::vector <int>& visited)
{
visited[s] = true;
for (long i = 0; i < V; i++)
{
if (F[s][i] && !visited[i])
{
//std::cout << i << d;
dfs(F, i, visited);
}
}
}
int gotoindex(std::vector <int>& A, int index)
{
if (index == HIGH)
{
return index;
}
else if (A[index] < 0)
{
//std::cout << "\nconflict of" << A[index] << "index changed to" << abs(A[index]) << endl;
gotoindex(A, abs(A[index]));
}
else
{
//std::cout << "\nindex ret: " << index << endl;
return index;
}
}
//
//
int cluster(std::vector<std::vector<int> >& lat, int key, std::vector <int>& clusstats)
{
//finding clusters of 1
int m = 0, n = 0, min = 0, a = 0, b = 0, i=0, j=0, k=0;
std::vector <int> arr;
for (i = 1; i < VER + 1; i++)
{
for (j = 1; j < VER + 1; j++)
{
if (lat[i][j] == key)
{
a = lat[i - 1][j];
b = lat[i][j - 1];
arr.push_back(gotoindex(clusstats, a));
arr.push_back(gotoindex(clusstats, b));
sort(arr.begin(), arr.end());
min = arr[0];
//std::cout << "\n\nbw " << a << "(" << i - 1 << "," << j << ") & " << b << " (" << i << "," << j - 1 << " )\n";
//min = MIN(gotoindex(clusstats, a),gotoindex(clusstats, b));
if (min == HIGH)
{
//std::cout << "rule:" << 1 << d;
m++;
clusstats[m] = 1;
lat[i][j] = m;
//std::cout << "ret:" << m << d;
}
else
{
clusstats[min]++;
lat[i][j] = min;
if (min != HIGH && arr[1] != HIGH)
{
if (min != arr[1])
{
clusstats[min] += clusstats[arr[1]];
clusstats[arr[1]] = -min;
}
}
}
arr.clear();
}
}
}
return 0;
}
void printCluster(std::vector<std::vector<int> >& lat, std::vector <int>& clusstats)
{
//uncomment block below to print cluster on console
for (int i = 0; i <= VER; i++)
{
for (int j = 0; j <= VER; j++)
{
if (lat[i][j] == HIGH)
{
std::cout << ".\t";// << sqlat1[i][j] << " ";
//std::cout << gotoindex(clusstats1, sqlat1[i][j]) << " ";
}
else
{ //std::cout << sqlat0[i][j] << " ";
//std::cout << "" << gotoindex(clusstats, lat[i][j]) << "\t";
std::cout << "" << lat[i][j] << "/" << gotoindex(clusstats, lat[i][j]) << "\t";
}
}std::cout << std::endl;
}
std::cout << std::endl;
std::cout << std::endl;
for (int i = 0; i < clusstats.size(); i++)
{
std::cout << clusstats[i] << ":";
}std::cout << std::endl; std::cout << std::endl;
}
void createAgumentedMatrix(std::vector < std::vector <int> >& sqlat0, std::vector < std::vector <int> >& sqlat1, std::vector <int> & visited)
{
int i = 0, j = 0;
//agumented matrix
for (i = 0; i <= VER; i++)
{
sqlat0[i][0] = HIGH;
sqlat1[i][0] = HIGH;
}
for (j = 0; j <= VER; j++)
{
sqlat0[0][j] = HIGH;
sqlat1[0][j] = HIGH;
}
for (i = 1; i <= VER; i++)
{
for (j = 1; j <= VER; j++)
{
sqlat0[i][j] = visited[(i - 1)*VER + (j - 1) + 1];
sqlat1[i][j] = visited[(i - 1)*VER + (j - 1) + 1];
if (sqlat1[i][j] == 0)sqlat1[i][j] = HIGH;
if (sqlat0[i][j] == 1)sqlat0[i][j] = HIGH;
//std::cout << visited[(i - 1)*VER + (j - 1) + 1];
}
}
}
long no_of_clusters(std::vector <int>& clusstats0, std::vector <int>& clusstats1)
{
long i = 0,counter=0;
for (i = 0; i < V / 2; i++)
{
if ((clusstats0[i] > 0) || (clusstats1[i] > 0))
{
counter++;
}
}
return counter;
}