-
Notifications
You must be signed in to change notification settings - Fork 2
/
nodefunc.c
54 lines (44 loc) · 1.61 KB
/
nodefunc.c
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
/**
* Represents the behavior of single nodes.
*/
#include "nodefunc.h"
nodestate_t process(nodeval_t act_old, nodeval_t slope_old, int number_d_neighbors, nodeval_t *d_neighbors,
int number_id_neighbors, nodeval_t *id_neighbors) {
// calculate mean over all madn nodes
nodeval_t madn = 0;
for (int i = 0; i < number_d_neighbors; ++i) {
madn = madn + d_neighbors[i];
}
madn = madn / number_d_neighbors;
// add direct neighbor factor
madn = madn * D_NEIGHBORFACTOR;
// calculate mean over all maidn nodes
nodeval_t maidn = 0;
for (int i = 0; i < number_id_neighbors; ++i) {
maidn = maidn + id_neighbors[i];
}
maidn = maidn / number_id_neighbors;
// add indirect neighbor factor
maidn = maidn * ID_NEIGHBORFACTOR;
// add factor
nodeval_t act_old_factored = act_old * ENERGY_FACTOR;
// calculate slope
nodeval_t slope_d = madn - act_old_factored;
nodeval_t slope_id = maidn - act_old_factored;
nodeval_t slope_vector = slope_d + slope_id;
// add factor
slope_vector = slope_vector * DELTA_FACTOR;
slope_old = slope_old * SLOPE_FACTOR;
// calculate new slope
nodeval_t slope_new = slope_old + slope_vector;
// add factors
nodeval_t slope_new_weighted = slope_new * SLOPE_WEIGHT;
nodeval_t act_old_weighted = act_old * ENERGY_WEIGHT;
// calculate new energy levels
nodeval_t act_new = act_old_weighted + slope_new_weighted;
// store results
nodestate_t res;
res.act = act_new;
res.slope = slope_new;
return res;
}