21 #include <grass/dgl/graph.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;
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++)
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
void G_percent_reset(void)
Reset G_percent() to 0%; do not add newline.
dglInt32_t * dglGetNode(dglGraph_s *pGraph, dglInt32_t nNodeId)
int Vect_reset_list(struct ilist *)
Reset ilist structure.
dglInt32_t dglNodeGet_Id(dglGraph_s *pGraph, dglInt32_t *pnNode)
void dglNode_T_Release(dglNodeTraverser_s *pT)
dglInt32_t dglEdgeGet_Cost(dglGraph_s *pGraph, dglInt32_t *pnEdge)
void dglHeapFree(dglHeap_s *pheap, dglHeapCancelItem_fn pfnCancelItem)
int n_values
Number of values in the list.
void G_free(void *)
Free allocated memory.
int dglGet_NodeCount(dglGraph_s *pgraph)
void dglHeapInit(dglHeap_s *pheap)
dglInt32_t * dglEdgeGet_Tail(dglGraph_s *pGraph, dglInt32_t *pnEdge)
dglInt32_t * dglNode_T_First(dglNodeTraverser_s *pT)
void Vect_destroy_list(struct ilist *)
Frees all memory associated with a struct ilist, including the struct itself.
dglInt32_t * dglEdgeset_T_First(dglEdgesetTraverser_s *pT)
void dglEdgeset_T_Release(dglEdgesetTraverser_s *pT)
int NetA_eigenvector_centrality(dglGraph_s *graph, int iterations, double error, double *eigenvector)
Computes eigenvector centrality using edge costs as weights.
void G_percent(long, long, int)
Print percent complete messages.
void NetA_degree_centrality(dglGraph_s *graph, double *degree)
Computes degree centrality measure.
struct ilist * Vect_new_list(void)
Creates and initializes a struct ilist.
int Vect_list_append(struct ilist *, int)
Append new item to the end of list if not yet present.
int dglNodeGet_OutDegree(dglGraph_s *pGraph, dglInt32_t *pnNode)
int * value
Array of values.
int dglHeapInsertMin(dglHeap_s *pheap, long key, unsigned char flags, dglHeapData_u value)
int dglHeapExtractMin(dglHeap_s *pheap, dglHeapNode_s *pnoderet)
int dglNode_T_Initialize(dglNodeTraverser_s *pT, dglGraph_s *pGraph)
dglInt32_t * dglEdgeset_T_Next(dglEdgesetTraverser_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)
dglInt32_t * dglNode_T_Next(dglNodeTraverser_s *pT)
int NetA_betweenness_closeness(dglGraph_s *graph, double *betweenness, double *closeness)
Computes betweenness and closeness centrality measure using Brandes algorithm.