Open
Description
Hi guys,
I'm trying to implement the BFS-Level algorithm defined in this presentation but I'm facing several problems regarding any pairs semiring and nothing values. I'm quite new to the language as well but this is the implementation i tried
#A is the input matrix, s is the source node, and n is the number of nodes
function bfs_level(A, s, n)
#frontier init
frontier = GBVector{Bool}(n)
for i = 1:n
frontier[i] = false
end
#init result vector
distance = GBVector{Int64}(n)
for i = 1:n
distance[i] = 0
end
#putting source node inside the frontier
frontier[s]= true
print("starting from source node\n\n")
for level = 1:n
print(frontier)
distance[frontier] .= level
frontier = mul(frontier, A, Semirings.ANY_PAIR, mask=distance, desc=Descriptors.C)
print(distance)
end
end
i tried the algorithm against this input
#0, 1, 1, 1, 0, 0, 0,
#0, 0, 0, 0, 0, 0, 0,
#0, 0, 0, 0, 0, 0, 0,
#0, 0, 0, 0, 0, 1, 0,
#0, 0, 0, 0, 0, 0, 0,
#0, 0, 0, 0, 0, 0, 1,
#0, 0, 0, 0, 1, 0, 0,
matrix = GBMatrix([[0, 0, 0, 0, 0, 0, 0] [1, 0, 0, 0, 0, 0, 0] [1, 0, 0, 0, 0, 0, 0] [1, 0, 0, 0, 0, 0, 0] [0, 0, 0, 0, 0, 0, 1] [0, 0, 0, 1, 0, 0, 0] [0, 0, 0, 0, 0, 1, 0]])
bfs_level(matrix, 1, 7)
the Any_Pairs semirings should return 0, 1, 1, 1, 0, 0, 0 according to the matrix above but i'm getting [nothing, 1, 1, 1, 1, 1, 1]
I think I didn't understand quite well how to implement masking even if I succeded in implementing the Bellman Ford algorithm. Sorry again to bother you for this kind of issues
Metadata
Metadata
Assignees
Labels
No labels