%%-------------------- brute force algorithm
IJ = load('BB');
nz = size(IJ,1);
z = ones(nz,1) ;
B = sparse(IJ(:,1), IJ(:,2), z);
n = size(B,1); 

G = graph(B);
plot(G)

degs = B*ones(n,1);
Cd = degs;
%%-------------------- to hold powers 
B1 = B;
D = B; 
%% D(i,j) = distance i --> j [==length of shortesgt paths]
pow = 1;
%%-------------------- loop
nz = nnz(B1);
%%-------------------- keep going until no edges added

for jj=1:n
  pow = pow+1;
  B1 = B*B1;
  for i=1:n
    for j=1:n      
%%-------------------- 1st time B1(i,j)==non-zero->shortest path
      if (D(i,j)==0) && (B1(i,j)>0)  
%%-------------------- record distance
	D(i,j) = pow;
      end
    end
  end
  nz0 = nz;
  nz = nnz(B1);
  if (nz == nz0), break, end
end

D = spdiags(zeros(n,1),0,D);

disp(' matrix of distances ')
full(D)

disp(' my computed closeness centrality')
mycc =  1.0 ./ (D*ones(n,1))

disp(' matlab-s closeness centrality')
ccm = centrality(G,'closeness')
  
