Here I present a simple BFS code written in Julia using GraphBLAS. This algorithm is taken straight from the API documentation & may not be the fastest method but it’s just for a simple illustration.
Okay, so first let’s create a SimpleGraph(a LightGraphs type) using the facebook undirected graph from SNAP Datasets and extract it’s adjacency matrix.
Now we’ll extract tuples from this adjacency matrix.
Let’s build a GraphBLAS adjacency matrix using I, J, X. The number of entries will be twice the number of edges in the graph.
Now we write a function which performs the BFS traversal of a graph, given the adjacency matrix A and a source node s. It returns GraphBLAS vector v where v[i] is set to the level in which node i is visited. If i is not reacheable from s, then v[i] = 0. The graph A need not be Boolean on input; if it isn’t Boolean, the semiring will properly typecast it to Boolean.
(GrB_ALLis used to specify all rows/columns of a vector/matrix. The parameter ni/nj is ignored.)
Okay, time to test this.
Levels in this algorithm begin at 1 as opposed to gdistances where levels begin at 0. Hence, we subtract 1 to compare results.
Thus, we see how one can use GraphBLAS to find geodesic distances.