19
19
// LAGr_EdgeBetweennessCentrality: Exact algorithm for computing
20
20
// betweeness centrality.
21
21
22
- // This is an Advanced algorithm (G->AT is required).
22
+ // This is an Advanced algorithm (no self edges allowed)
23
23
24
24
25
25
//------------------------------------------------------------------------------
82
82
// (1+x)/y function for double: z = (1 + x) / y
83
83
//------------------------------------------------------------------------------
84
84
85
- void add_one_divide_function (void * z , const void * x , const void * y )
85
+ void add_one_divide_function (double * z , const double * x , const double * y )
86
86
{
87
- double a = (* (( double * ) x )) ;
88
- double b = (* (( double * ) y )) ;
89
- (* (( double * ) z )) = (1 + a ) / b ;
87
+ double a = (* (x )) ;
88
+ double b = (* (y )) ;
89
+ (* (z )) = (1 + a ) / b ;
90
90
}
91
91
92
92
#define ADD_ONE_DIVIDE_FUNCTION_DEFN \
93
- "void add_one_divide_function (void *z, const void *x, const void *y) \n" \
93
+ "void add_one_divide_function (double *z, const double *x, const double *y)\n" \
94
94
"{ \n" \
95
- " double a = (*((double *) x)) ; \n" \
96
- " double b = (*((double *) y)) ; \n" \
97
- " (*((double *) z)) = (1 + a) / b ; \n" \
95
+ " double a = (*(x)) ; \n" \
96
+ " double b = (*(y)) ; \n" \
97
+ " (*(z)) = (1 + a) / b ; \n" \
98
98
"}"
99
99
100
100
//------------------------------------------------------------------------------
@@ -154,6 +154,7 @@ int LAGr_EdgeBetweennessCentrality
154
154
LG_TRY (LAGraph_CheckGraph (G , msg )) ;
155
155
156
156
GrB_Matrix A = G -> A ;
157
+ #if 0
157
158
GrB_Matrix AT ;
158
159
if (G -> kind == LAGraph_ADJACENCY_UNDIRECTED ||
159
160
G -> is_symmetric_structure == LAGraph_TRUE )
@@ -167,12 +168,14 @@ int LAGr_EdgeBetweennessCentrality
167
168
AT = G -> AT ;
168
169
LG_ASSERT_MSG (AT != NULL , LAGRAPH_NOT_CACHED , "G->AT is required" ) ;
169
170
}
171
+ #endif
170
172
171
173
// =========================================================================
172
174
// === initialization =====================================================
173
175
// =========================================================================
174
176
175
- GRB_TRY (GxB_BinaryOp_new (& Add_One_Divide , add_one_divide_function ,
177
+ GRB_TRY (GxB_BinaryOp_new (& Add_One_Divide ,
178
+ (GxB_binary_function ) add_one_divide_function ,
176
179
GrB_FP64 , GrB_FP64 , GrB_FP64 ,
177
180
"add_one_divide_function" , ADD_ONE_DIVIDE_FUNCTION_DEFN )) ;
178
181
@@ -214,10 +217,12 @@ int LAGr_EdgeBetweennessCentrality
214
217
215
218
GRB_TRY (GrB_Matrix_clear (Update )) ;
216
219
217
- // Extract row root from A into frontier vector: frontier = AT(root,:)
218
- GRB_TRY (GrB_Col_extract (frontier , NULL , NULL , AT , GrB_ALL , n , root ,
219
- NULL )) ;
220
+ // Extract row root from A into frontier vector: frontier = A(root,:)
221
+ GRB_TRY (GrB_Col_extract (frontier , NULL , NULL , A , GrB_ALL , n , root ,
222
+ GrB_DESC_T0 )) ;
223
+
220
224
GRB_TRY (GrB_Vector_nvals (& frontier_size , frontier )) ;
225
+ GRB_TRY (GrB_assign (frontier , frontier , NULL , 1.0 , GrB_ALL , n , GrB_DESC_S )) ;
221
226
222
227
while (frontier_size != 0 )
223
228
{
@@ -242,7 +247,8 @@ int LAGr_EdgeBetweennessCentrality
242
247
//----------------------------------------------------------------------
243
248
244
249
GRB_TRY (LG_SET_FORMAT_HINT (frontier , LG_SPARSE )) ;
245
- GRB_TRY (GrB_vxm (frontier , paths , NULL , GxB_PLUS_FIRST_FP64 , frontier ,
250
+ GRB_TRY (GrB_vxm (frontier , paths , NULL , /* LAGraph_plus_first_fp64 */
251
+ GxB_PLUS_FIRST_FP64 , frontier ,
246
252
A , GrB_DESC_RSC )) ;
247
253
248
254
//----------------------------------------------------------------------
@@ -269,8 +275,12 @@ int LAGr_EdgeBetweennessCentrality
269
275
270
276
// Backtrack through the BFS and compute centrality updates for each vertex
271
277
// GrB_Index fd1_size;
278
+
279
+ // printf ("\n----------------------------- backtrack:\n") ;
280
+
272
281
while (depth >= 1 )
273
282
{
283
+ // printf ("\n----------------------------- backtrack depth : %" PRId64 "\n", depth) ;
274
284
GrB_Vector f_d = Search [depth ] ;
275
285
GrB_Vector f_d1 = Search [depth - 1 ] ;
276
286
@@ -291,20 +301,20 @@ int LAGr_EdgeBetweennessCentrality
291
301
// combine
292
302
293
303
// intermediate matrix for Fd1 * A
294
- // GRB_TRY (GrB_eWiseMult(Fd1A, NULL, NULL, GrB_TIMES_FP64, I_matrix, AT, NULL)) ;
295
- GRB_TRY (GrB_mxm (Fd1A , NULL , NULL , GrB_PLUS_TIMES_SEMIRING_FP64 ,
304
+ GRB_TRY (GrB_mxm (Fd1A , NULL , NULL , LAGraph_plus_first_fp64 ,
296
305
I_matrix , A , NULL )) ;
297
306
298
- // GRB_TRY (GrB_eWiseMult(U, NULL, NULL, GrB_TIMES_FP64, Fd1A, J_matrix, NULL)) ;
299
307
GRB_TRY (GrB_mxm (Update , NULL , NULL , GrB_PLUS_TIMES_SEMIRING_FP64 ,
300
308
Fd1A , J_matrix , NULL )) ;
301
309
302
-
303
- // 22 centrality = centrality + Update
304
- // GRB_TRY (GrB_assign(centrality, centrality, GrB_PLUS_FP64, Update, GrB_ALL, n, GrB_ALL, n,
305
- // GrB_DESC_S)) ;
310
+ #if 1
311
+ // 22 centrality{A} += Update, using assign
312
+ GRB_TRY (GrB_assign (* centrality , A , GrB_PLUS_FP64 , Update , GrB_ALL , n , GrB_ALL , n ,
313
+ GrB_DESC_S )) ;
314
+ #else
315
+ // 22 centrality = centrality + Update using eWiseAdd
306
316
GRB_TRY (GrB_eWiseAdd (* centrality , NULL , NULL , GrB_PLUS_FP64 , * centrality , Update , NULL )) ;
307
-
317
+ #endif
308
318
309
319
// 23 v = Update +.
310
320
0 commit comments