-
Notifications
You must be signed in to change notification settings - Fork 1
/
Neighbour sequential
73 lines (64 loc) · 2.78 KB
/
Neighbour sequential
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
int main()
{
int nodes = 10;
vector<vector<float>> adjacency_matrix = {{0, 1.0, 0.7, 0, 0, 0, 0, 0, 0, 0},
{1.0, 0, 0.8, 0, 0, 0, 0.2, 0, 0, 0},
{0.7, 0.8, 0, 0.3, 0, 0, 0, 0, 0, 0},
{0, 0, 0.3, 0, 0.7, 0.8, 0, 0, 0, 0},
{0, 0, 0, 0.7, 0, 0.9, 0, 0, 0, 0},
{0, 0, 0, 0.8, 0.9, 0, 0, 0, 0, 0.3},
{0, 0.2, 0, 0, 0, 0, 0, 0.9, 0.7, 0.8},
{0, 0, 0, 0, 0, 0, 0.9, 0, 0.5, 0.6},
{0, 0, 0, 0, 0, 0, 0.7, 0.5, 0, 0.4},
{0, 0, 0, 0, 0, 0.3, 0.8, 0.6, 0.4, 0}};
vector<int> all_neigh_count(nodes);
vector<vector<float>> added_neigh_count(nodes, vector<float>(nodes));
vector<vector<float>> prod_neigh_count(nodes, vector<float>(nodes));
for (int i = 0; i < nodes; i++)
{
int c = 0;
vector<int> int_neigh_count(nodes);
for (int j = 0; j < nodes; j++)
if (adjacency_matrix[i][j] != 0)
{
c++;
int_neigh_count[j] = 1;
}
all_neigh_count[i] = c;
for (int j = 0; j < nodes; j++)
if (j != i && adjacency_matrix[i][j] != 0)
for (int k = 0; k < nodes; k++)
if (adjacency_matrix[j][k] != 0 && int_neigh_count[k] != 0)
int_neigh_count[j] += 1;
for (int j = 0; j < nodes; j++)
if (i != j)
{
float wtd_neigh_count = int_neigh_count[j] * 1.0 / all_neigh_count[i];
added_neigh_count[i][j] = adjacency_matrix[i][j] * 1.0 + wtd_neigh_count;
prod_neigh_count[i][j] = adjacency_matrix[i][j] * 1.0 * wtd_neigh_count;
}
}
cout << "\nAltered Added Neighbour Count : \n\n";
for (int i = 0; i < nodes; i++)
{
for (int j = 0; j < nodes; j++)
cout << added_neigh_count[i][j] << " ";
cout << endl;
}
cout << endl;
cout << "\nAltered Multiplied Neighbour Count : \n\n";
for (int i = 0; i < nodes; i++) {
for (int j = 0; j < nodes; j++) {
cout << prod_neigh_count[i][j] << " ";
}
cout << endl;
}
cout << endl;
cout<<"\n\n* * * Execution using vanilla matrix * * *\n\n";
MemLPA(adjacency_matrix);
cout<<"\n\n* * * Execution using added-weighted matrix * * *\n\n";
MemLPA(added_neigh_count);
cout<<"\n\n* * * Execution using product-weighted matrix * * *\n\n";
MemLPA(prod_neigh_count);
return 0;
}