-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9d53a9e
commit 71a71bf
Showing
5 changed files
with
267 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,31 @@ | ||
from pyspla import * | ||
|
||
M = Matrix.from_lists([0, 1, 2, 2], [1, 2, 0, 4], [1, 2, 3, 4], (3, 5), INT) | ||
print(M) | ||
|
||
N = Matrix.from_lists([0, 1, 2, 3], [1, 2, 0, 3], [2, 3, 4, 5], (4, 5), INT) | ||
print(N) | ||
def bfs(s: int, A: Matrix): | ||
v = Vector(A.n_rows, INT) # to store depths | ||
|
||
mask = Matrix.dense((3, 4), INT, fill_value=1) | ||
print(mask) | ||
front = Vector.from_lists([s], [1], A.n_rows, INT) # front of new vertices to study | ||
front_size = 1 # current front size | ||
depth = Scalar(INT, 0) # depth of search | ||
count = 0 # num of reached vertices | ||
|
||
R = M.mxmT(mask, N, INT.MULT, INT.PLUS, INT.GTZERO) | ||
print(R) | ||
while front_size > 0: # while have something to study | ||
depth += 1 | ||
count += front_size | ||
v.assign(front, depth, op_assign=INT.SECOND, op_select=INT.NQZERO) # assign depths | ||
front = front.vxm(v, A, op_mult=INT.LAND, op_add=INT.LOR, op_select=INT.EQZERO) # do traversal | ||
front_size = front.reduce(op_reduce=INT.PLUS).get() # update front count to end algorithm | ||
|
||
R = M.mxmT(mask, N, INT.MULT, INT.PLUS, INT.EQZERO) | ||
print(R) | ||
return v, count, depth.get() | ||
|
||
|
||
I = [0, 1, 2, 2, 3] | ||
J = [1, 2, 0, 3, 2] | ||
V = [1, 1, 1, 1, 1] | ||
A = Matrix.from_lists(I, J, V, shape=(4, 4), dtype=INT) | ||
print(A) | ||
|
||
v, c, d = bfs(0, A) | ||
print(v) | ||
print(c) | ||
print(d) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters