-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_adjacency_matrix.m
30 lines (29 loc) · 1.01 KB
/
generate_adjacency_matrix.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
function W = generate_adjacency_matrix(ncols,boxsize,nnodes)
W = zeros(nnodes,nnodes);
for i=1:ncols
for j=1:ncols
% Rows
for xx=1:ncols
if xx~=j
W(sub2ind([ncols,ncols],i,j), sub2ind([ncols,ncols],i,xx)) = 1;
end
end
for yy=1:ncols
if yy~=i
W(sub2ind([ncols,ncols],i,j), sub2ind([ncols,ncols],yy,j)) = 1;
end
end
% Boxes
xbox = ceil(j/boxsize);
ybox = ceil(i/boxsize);
for yy=ybox*boxsize-(boxsize-1):ybox*boxsize
for xx=xbox*boxsize-(boxsize-1):xbox*boxsize
if xx~=j && yy~=i
W(sub2ind([ncols,ncols],i,j), sub2ind([ncols,ncols],yy,xx)) = 1;
W(sub2ind([ncols,ncols],yy,xx), sub2ind([ncols,ncols],i,j)) = 1;
end
end
end
end
end
end