-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathAdvancedPrim.jl
More file actions
49 lines (37 loc) · 917 Bytes
/
AdvancedPrim.jl
File metadata and controls
49 lines (37 loc) · 917 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#=
AdvancedPrim:
- Julia version:
- Author: samuel
- Date: 2021-09-10
=#
using SuiteSparseGraphBLAS
using SparseArrays
using LinearAlgebra
function stoppingCondition(m, n)
infinito = true
for i = 1:n
if(m[i] == 0.0)
return false
end
end
return infinito
end
#A is the input matrix, n is the number of nodes, m is the source matrix. Output: minimum spanning tree and minimum spanning tree cost
function a_prim(A, n, m)
d = GBVector{Float64}(n)
weight = 0.0
d = A[1,:]
mst = GBVector{Float64}(n) #minimum spanning tree
while(stoppingCondition(m, n) == false)
u = argmin(m'+d)
m[u[2]] = Inf
push!(mst, d[u[2]])
weight = weight + d[u[2]]
print("WEIGHT: ")
print(weight)
d = emul(d, A[u[1],:], BinaryOps.MIN)
print(" ITERATION FINISHED")
print("\n\n\n")
end
return weight, mst
end