18 #include <grass/gis.h>
19 #include <grass/Vect.h>
20 #include <grass/glocale.h>
21 #include <grass/dgl/graph.h>
22 #include <grass/neta.h>
37 for (i = 1; i <= nnodes; i++)
55 double error,
double *eigenvector)
61 tmp = (
double *)G_calloc(nnodes + 1,
sizeof(
double));
68 for (i = 1; i <= nnodes; i++)
70 for (iter = 0; iter < iterations; iter++) {
71 for (i = 1; i <= nnodes; i++)
80 double cur_value = eigenvector[node_id];
93 double cum_error = 0, max_value = tmp[1];
95 for (i = 2; i <= nnodes; i++)
96 if (tmp[i] > max_value)
98 for (i = 1; i <= nnodes; i++) {
101 (tmp[i] - eigenvector[i]) * (tmp[i] - eigenvector[i]);
102 eigenvector[i] = tmp[i];
104 if (cum_error < error)
129 int i, j, nnodes, stack_size,
count;
139 prev = (
struct ilist **)G_calloc(nnodes + 1,
sizeof(
struct ilist *));
144 if (!dst || !prev || !stack || !cnt || !delta) {
150 for (i = 1; i <= nnodes; i++) {
168 for (i = 1; i <= nnodes; i++)
170 for (i = 1; i <= nnodes; i++) {
185 dist = heap_node.
key;
188 stack[stack_size++] = v;
202 if (dst[to_id] == -1 || dst[to_id] > dist + d) {
203 dst[to_id] = dist + d;
205 heap_data.
ul = to_id;
208 if (dst[to_id] == dist + d) {
209 cnt[to_id] += cnt[v];
217 for (i = 1; i <= nnodes; i++)
219 for (i = stack_size - 1; i >= 0; i--) {
223 closeness[
s] += dst[
w];
225 for (j = 0; j < prev[
w]->n_values; j++) {
228 delta[v] += (cnt[v] / (double)cnt[w]) * (1.0 + delta[
w]);
230 if (w != s && betweenness)
231 betweenness[
w] += delta[
w];
235 closeness[
s] /= (double)stack_size;
239 for (i = 1; i <= nnodes; i++)
dglInt32_t * dglEdgeGet_Tail(dglGraph_s *pGraph, dglInt32_t *pnEdge)
dglInt32_t dglNodeGet_Id(dglGraph_s *pGraph, dglInt32_t *pnNode)
int Vect_destroy_list(struct ilist *list)
Frees all memory associated with a struct ilist, including the struct itself.
void G_free(void *buf)
Free allocated memory.
int dglEdgeset_T_Initialize(dglEdgesetTraverser_s *pT, dglGraph_s *pGraph, dglInt32_t *pnEdgeset)
struct ilist * Vect_new_list(void)
Creates and initializes a struct ilist.
void dglHeapFree(dglHeap_s *pheap, dglHeapCancelItem_fn pfnCancelItem)
void dglHeapInit(dglHeap_s *pheap)
int dglNode_T_Initialize(dglNodeTraverser_s *pT, dglGraph_s *pGraph)
int dglNodeGet_OutDegree(dglGraph_s *pGraph, dglInt32_t *pnNode)
void dglNode_T_Release(dglNodeTraverser_s *pT)
int G_percent(long n, long d, int s)
Print percent complete messages.
void dglEdgeset_T_Release(dglEdgesetTraverser_s *pT)
int G_percent_reset(void)
Reset G_percent() to 0%; do not add newline.
dglInt32_t * dglEdgeset_T_First(dglEdgesetTraverser_s *pT)
dglInt32_t * dglGetNode(dglGraph_s *pGraph, dglInt32_t nNodeId)
int Vect_reset_list(struct ilist *list)
Reset ilist structure.
int Vect_list_append(struct ilist *list, int val)
Append new item to the end of list if not yet present.
dglInt32_t * dglNode_T_First(dglNodeTraverser_s *pT)
int NetA_eigenvector_centrality(dglGraph_s *graph, int iterations, double error, double *eigenvector)
Computes eigenvector centrality using edge costs as weights.
dglInt32_t * dglNodeGet_OutEdgeset(dglGraph_s *pGraph, dglInt32_t *pnNode)
void NetA_degree_centrality(dglGraph_s *graph, double *degree)
Computes degree centrality measure.
dglInt32_t dglEdgeGet_Cost(dglGraph_s *pGraph, dglInt32_t *pnEdge)
int dglGet_NodeCount(dglGraph_s *pgraph)
int G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
int dglHeapInsertMin(dglHeap_s *pheap, long key, unsigned char flags, dglHeapData_u value)
dglInt32_t * dglNode_T_Next(dglNodeTraverser_s *pT)
int dglHeapExtractMin(dglHeap_s *pheap, dglHeapNode_s *pnoderet)
dglInt32_t * dglEdgeset_T_Next(dglEdgesetTraverser_s *pT)
int NetA_betweenness_closeness(dglGraph_s *graph, double *betweenness, double *closeness)
Computes betweenness and closeness centrality measure using Brandes algorithm.