%%%%Code to generate pairwiseDistances.mat
%%%% It is a 276M+ vector. It lists the pairwise rsd distances between each pair of prefix in the pfxListCoding.txt. To save space, this vector does not contain rsd(j,i) if rsd(i,j) is already included but it contains rsd(i,i) pairs.  For instance, if we had 5 prefixes, a,b,c,d,e, the ordering in the vector would be rsd(a,a), rsd(a,b), rsd(a,c), rsd(a,d), rsd(a,e), rsd(b,b), rsd(b,c), rsd(b,d),...,  rsd(d,d), rsd(d,e), rsd(e,e)

%%%%%%%%%%%% Lower bound distance using high coverage set
clear all;

load ('/research/internet-census/as-visibility/routeviews-ripe-workspace/rsd/pfx2AS_matrix.mat');
[numPfx, numCols] = size(R);

s = numPfx * (numPfx-1) / 2 + numPfx;
DLB = int16(zeros(s,1));

matlabpool open 12; 
isOpen = matlabpool('size') == 12

endInd = 0;

for p1 = 1:numPfx
	L1 = R(p1,:);
	distances = int16(zeros(numPfx,1));
	parfor p2 = p1+1:numPfx
		L2 = R(p2,:);
		Ld = L1-L2;
		distances(p2) = length(nonzeros(Ld(and(L1,L2))));
	end
	startInd = endInd + 1;
	endInd = startInd + numPfx - p1;
	DLB(startInd:endInd) = distances(p1:numPfx);

end
save('pairwiseDist_LB_highCov', '-v7.3', 'DLB');

matlabpool close;

