1 //------------------------------------------------------------------------------
2 // GraphBLAS/Demo/Source/mis_score.c: set random score
3 //------------------------------------------------------------------------------
4 
5 // SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
6 // SPDX-License-Identifier: Apache-2.0
7 
8 //------------------------------------------------------------------------------
9 
10 // Modified from the GraphBLAS C API Specification, by Aydin Buluc, Timothy
11 // Mattson, Scott McMillan, Jose' Moreira, Carl Yang.  Based on "GraphBLAS
12 // Mathematics" by Jeremy Kepner.
13 
14 // No copyright claim is made for this particular file; the above copyright
15 // applies to all of SuiteSparse:GraphBLAS, not this file.
16 
17 #include "GraphBLAS.h"
18 #undef GB_PUBLIC
19 #define GB_LIBRARY
20 #include "graphblas_demos.h"
21 
22 //------------------------------------------------------------------------------
23 // mis_score: set the random score of a node
24 //------------------------------------------------------------------------------
25 
26 // Assign a random number to each element scaled by the inverse of the node's
27 // degree.  This will increase the probability that low degree nodes are
28 // selected and larger sets are selected.
29 
30 // this unary operator was used in V2.3.4, but it is not thread-safe
31 GB_PUBLIC
mis_score(void * result,const void * degree)32 void mis_score (void *result, const void *degree)
33 {
34     // add 1 to prevent divide by zero
35     uint32_t deg = (*((uint32_t *) degree)) ;
36     double x = simple_rand_x ( ) ;
37     (*((double *) result)) = (0.0001 + x / (1. + 2.* deg)) ;
38 }
39 
40 // a binary operator is thread-safe, where xrand is an entry from a
41 // vector of random numbers
42 GB_PUBLIC
mis_score2(void * result,const void * degree,const void * xrand)43 void mis_score2 (void *result, const void *degree, const void *xrand)
44 {
45     uint32_t deg = (*((uint32_t *) degree)) ;
46     double x = (*((double *) xrand)) ;
47     (*((double *) result)) = (0.0001 + x / (1. + 2.* deg)) ;
48 }
49 
50