% Mar 2009
%
% This m-file generates a file Prob.mat that stores the following:
% dim  = 2
% x    = true position of the sensors/anchors
% nd   = number of edges
% d    = a vector storing (noisy) distance of each edge
% head = store the "head" sensor of each edge
% tail = store the "tail" sensor of each edge
% n    = total number of sensors and anchors
% m    = number of anchors
%
% The noise is Gaussian
 
clear
r = input(' enter 1 for 4 anchors at corners, enter 2 for unif distrib. anchors ');
dim = 2;

% input algorithm parameters
if r == 1
  n = input(' enter total number of sensors ');
  nfac = input(' enter noisyfactor (e.g., 0 or .05) ');
  radiorange = input(' enter radio range (e.g., .06) ');
  x = zeros(2,n+4);
  x(1:2,1:n) = rand(dim,n)-.5*ones(dim,n);
  x(1:2,n+1:n+4) = [-0.45 -0.45 0.45 0.45;0.45 -0.45 0.45 -0.45];
  n = n+4;
  m = 4;
else
  n = input(' enter total number of sensors and anchors ');
  m = input(' enter number of anchors ');
  nfac = input(' enter noisyfactor (e.g., 0 or .05) ');
  radiorange = input(' enter radio range (e.g., .06) ');
  x = rand(dim,n)-.5*ones(dim,n);
end

% pdf=input(' enter 1, 2, 3 for normal, uniform, additive-Gaussian noise');

dd = sparse(n,n);
nd = 0;

for i = n-m+1:n
  for j = 1:n-m
    dist = norm(x(1:dim,i)-x(1:dim,j));
    if dist < radiorange
      nd = nd + 1;
      rv = randn(1);			%Gaussian noise
      d(nd) = dist*abs(1 + rv*nfac);
      head(nd) = i;
      tail(nd) = j;
    end
  end
end
 
for i = 1:n-m
  for j = i+1:n-m
    dist = norm(x(1:dim,i)-x(1:dim,j));
    if dist < radiorange
      nd = nd + 1;
      rv = randn(1);			%Gaussian noise
      d(nd) = dist*abs(1 + rv*nfac); 
      head(nd) = i;
      tail(nd) = j; 
    end
  end
end

save Prob dim x nd d head tail n m