-
Notifications
You must be signed in to change notification settings - Fork 0
/
findTriangles.m
72 lines (47 loc) · 1.22 KB
/
findTriangles.m
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
%
% SCRIPT: FINDTRIANGLES
%
% Download a graph from Sparse Matrix Collection and count the number of
% triangles.
%
%
% AUTHORS
%
% Dimitris Floros [email protected]
%
% VERSION
%
% 0.1 - January 21, 2019
%
%% CLEAN-UP
clear
close all
%% PARAMETERS
basePath = 'http://sparse.tamu.edu/mat';
groupName = 'DIMACS10';
matName = 'auto'; % auto|great-britain_osm|delaunay_n22
%% (BEGIN)
fprintf('\n *** begin %s ***\n\n',mfilename);
%% LOAD INPUT GRAPH
fprintf( '...loading graph...\n' );
fprintf( ' - %s/%s\n', groupName, matName )
fileName = [groupName '_' matName '.mat'];
if ~exist( fileName, 'file' )
fprintf(' - downloading graph...\n')
fileName = websave( fileName, ...
[basePath filesep groupName filesep matName '.mat'] );
fprintf(' DONE\n')
end
ioData = matfile( fileName );
Problem = ioData.Problem;
% keep only adjacency matrix (logical values)
A = Problem.A > 0;
clear Problem;
fprintf( ' - DONE\n');
%% TRIANGLE COUNTING
fprintf( '...triangle counting...\n' );
ticCnt = tic;
nT = full( sum( sum( A^2 .* A ) ) / 6 );
fprintf( ' - DONE: %d triangles found in %.2f sec\n', nT, toc(ticCnt) );
%% (END)
fprintf('\n *** end %s ***\n\n',mfilename);