21 #include <grass/dgl/graph.h>
37 for (i = 1; i <= nnodes; i++)
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++) {
100 cum_error += (tmp[i] - eigenvector[i]) * (tmp[i] - eigenvector[i]);
101 eigenvector[i] = tmp[i];
103 if (cum_error < error)
128 int i, j, nnodes, stack_size,
count;
143 if (!
dst || !prev || !stack || !cnt || !delta) {
148 for (i = 1; i <= nnodes; i++) {
166 for (i = 1; i <= nnodes; i++)
168 for (i = 1; i <= nnodes; i++) {
183 dist = heap_node.
key;
186 stack[stack_size++] = v;
198 if (
dst[to_id] == -1 ||
dst[to_id] > dist + d) {
199 dst[to_id] = dist + d;
201 heap_data.
ul = to_id;
204 if (
dst[to_id] == dist + d) {
205 cnt[to_id] += cnt[v];
213 for (i = 1; i <= nnodes; i++)
215 for (i = stack_size - 1; i >= 0; i--) {
219 closeness[s] +=
dst[w];
221 for (j = 0; j < prev[w]->
n_values; j++) {
224 delta[v] += (cnt[v] / (double)cnt[w]) * (1.0 + delta[w]);
226 if (w != s && betweenness)
227 betweenness[w] += delta[w];
230 closeness[s] /= (double)stack_size;
234 for (i = 1; i <= nnodes; i++)
int NetA_eigenvector_centrality(dglGraph_s *graph, int iterations, double error, double *eigenvector)
Computes eigenvector centrality using edge costs as weights.
void NetA_degree_centrality(dglGraph_s *graph, double *degree)
Computes degree centrality measure.
int NetA_betweenness_closeness(dglGraph_s *graph, double *betweenness, double *closeness)
Computes betweenness and closeness centrality measure using Brandes algorithm.
void G_percent(long, long, int)
Print percent complete messages.
void G_percent_reset(void)
Reset G_percent() to 0%; do not add newline.
void G_free(void *)
Free allocated memory.
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
void Vect_destroy_list(struct ilist *)
Frees all memory associated with a struct ilist, including the struct itself.
int Vect_list_append(struct ilist *, int)
Append new item to the end of list if not yet present.
struct ilist * Vect_new_list(void)
Creates and initializes a struct ilist.
int Vect_reset_list(struct ilist *)
Reset ilist structure.
void dglHeapInit(dglHeap_s *pheap)
int dglHeapInsertMin(dglHeap_s *pheap, long key, unsigned char flags, dglHeapData_u value)
void dglHeapFree(dglHeap_s *pheap, dglHeapCancelItem_fn pfnCancelItem)
int dglHeapExtractMin(dglHeap_s *pheap, dglHeapNode_s *pnoderet)
int n_values
Number of values in the list.
int * value
Array of values.
dglInt32_t * dglNode_T_First(dglNodeTraverser_s *pT)
dglInt32_t * dglNodeGet_OutEdgeset(dglGraph_s *pGraph, dglInt32_t *pnNode)
int dglEdgeset_T_Initialize(dglEdgesetTraverser_s *pT, dglGraph_s *pGraph, dglInt32_t *pnEdgeset)
int dglNode_T_Initialize(dglNodeTraverser_s *pT, dglGraph_s *pGraph)
dglInt32_t * dglEdgeset_T_Next(dglEdgesetTraverser_s *pT)
dglInt32_t * dglEdgeGet_Tail(dglGraph_s *pGraph, dglInt32_t *pnEdge)
int dglNodeGet_OutDegree(dglGraph_s *pGraph, dglInt32_t *pnNode)
dglInt32_t * dglNode_T_Next(dglNodeTraverser_s *pT)
int dglGet_NodeCount(dglGraph_s *pgraph)
void dglEdgeset_T_Release(dglEdgesetTraverser_s *pT UNUSED)
dglInt32_t dglEdgeGet_Cost(dglGraph_s *pGraph, dglInt32_t *pnEdge)
dglInt32_t * dglEdgeset_T_First(dglEdgesetTraverser_s *pT)
void dglNode_T_Release(dglNodeTraverser_s *pT)
dglInt32_t dglNodeGet_Id(dglGraph_s *pGraph, dglInt32_t *pnNode)
dglInt32_t * dglGetNode(dglGraph_s *pGraph, dglInt32_t nNodeId)