Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 24 additions & 27 deletions SubgraphIsomorphism/ktruss/code/julia/ktruss.jl
Original file line number Diff line number Diff line change
@@ -1,37 +1,34 @@
function calcx(E, m, n, k)
tmp = E.'*E;
R = E * ( tmp - spdiagm( diag(tmp) ) );
r,c,v = findnz(R);
id = v.==2;
A = sparse( r[id], c[id], 1, m, n);
s = sum(A, 2);
x = s .< (k-2);
return(x, !x);
function calcx(Et, k)
n, m = size(Et)
tmp = Et*Et'
Rt = ( tmp - Diagonal( diag(tmp) ) )*Et
s = vec(sum(t -> t == 2, Rt, 1))
x = find(t -> t < (k - 2), s)
return x
end

function ktruss(inc_mtx_file, k)
if ~isfile( inc_mtx_file )
println("unable to open input file");
return (-1);
function ktruss(inc_mtx_file, k; time = true)
if !isfile( inc_mtx_file )
println("unable to open input file")
return (-1)
end

# load input data
t_read_inc=@elapsed ii = readdlm( inc_mtx_file, '\t', Int64);
println("incidence matrix read time : ", t_read_inc);
# load input data
t_read_inc = @elapsed ii = readdlm( inc_mtx_file, '\t', Int64)
time && println("incidence matrix read time : ", t_read_inc)

t_create_inc=@elapsed E = sparse( ii[:,1], ii[:,2], ii[:,3] );
println("sparse adj. matrix creation time : ", t_create_inc);
t_create_inc = @elapsed Et = sparse( ii[:,2], ii[:,1], ii[:,3] )
time && println("sparse adj. matrix creation time : ", t_create_inc)

#
tic();
m,n = size(E);
x, xc = calcx(E, m, n, k);
while sum(xc) != sum( any(E,2) )
E[find(x), :] = 0
x, xc = calcx(E, m, n, k);
time && tic()
m = size(Et, 2)
x = calcx(Et, k)
while (m - length(x)) != sum( any(Et,1) )
Et[:, x] = 0
x = calcx(Et, k)
end

return E
time && toc()
return Et'
end


Expand Down
13 changes: 7 additions & 6 deletions SubgraphIsomorphism/ktruss/code/julia/runKtrussBenchmark.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

include("ktruss.jl");
include("ktruss.jl")

inc_mtx_file = "../../../data/ktruss_example.tsv"

Expand All @@ -8,16 +8,17 @@ E_expected = [1 1 0 0 0
1 0 0 1 0
0 0 1 1 0
1 0 1 0 0
0 0 0 0 0];
0 0 0 0 0]


@time E = ktruss(inc_mtx_file, 3);
E = ktruss(inc_mtx_file, 3, time = false)
@time E = ktruss(inc_mtx_file, 3)

if sum( E - E_expected ) > 0
println("Unable to verify results");
println("Unable to verify results")
else
println("passed");
println(E);
println("passed")
println(E)
end

#######################################################
Expand Down