function [X] = testLAD(example)

switch example 
    case 'BSL08' % Example of Beck, Stoica, and Li (2008)
           % deterministic case (1 source)
           % sigma is not used. However, the noise is a realization
           % of a Gaussian distributed random variable with mu=0, sigma=0.1
           % m =5, s = 1, 
        m = 5; n = 6; r=2;
        PP =[6 4; 0 -10; 5 -3; 1 -4; 3 -3; -2 3]'; % the unknown source location is: (-2 3)
        D = zeros(6,6);
        for j = 2:5
            tmp = PP(:, j)*ones(1, j-1) - PP(:, 1:j-1);
            rr  = sqrt(sum(tmp.*tmp));
            D(1:j-1, j) = rr';
        end
        %%% (1) the original case
%         D(1:5, 6) = ([8.0051 13.0112 9.1138 7.7924 8.0210])';
%         D = D+D';
%         I =[1 1 1 1 2 2 2 3 3 4]';
%         J =[2 3 4 5 3 4 5 4 5 5]';
%         b =[D(2:5, 1); D(3:5, 2); D(4:5, 3); D(5, 4)];
%         %%%
%         %%% (2) fix the distances from $x$ to the first two anchors
%         %%% it will accurately recover x = [-2 3];
        D(1:5, 6) = ([sqrt(65) sqrt(173) 9.1138 7.7924 8.0210])';
        D = D+D';
        I =[1 1 1 1 2 2 2 3 3 4 1 2]';
        J =[2 3 4 5 3 4 5 4 5 5 6 6]';
        b =[D(2:5, 1); D(3:5, 2); D(4:5, 3); D(5, 4); D(1,6); D(2,6)];
        %%%
        %%% (3) fix the largest distances from $x$ to the 2nd anchor
        %%% resulting x = [-1.9982 3.0003];
%         D(1:5, 6) = ([8.0051 sqrt(173) 9.1138 7.7924 8.0210])';
%         D = D+D';
%         I =[1 1 1 1 2 2 2 3 3 4 2]';
%         J =[2 3 4 5 3 4 5 4 5 5 6]';
%         b =[D(2:5, 1); D(3:5, 2); D(4:5, 3); D(5, 4); D(2,6)];
%  D =  [0   232  2    89   58   8.0051^2
%        232  0   194  37   58   13.0112^2
%        2   194  0    65   40   9.1138^2
%        89  37   65   0    5    7.7924^2
%        58  58   40   5    0    8.0210^2
%        8.0051   13.0112   9.1138   7.7924    8.0210    0]

case 'YeTseng08' % Example of Ye and used by Tseng
           % m = 3, n=50, nf =0, radiorange = 0.2
        m = 20;
        n = 200;
        r = 2;
        Radius = 0.3;
       % radiorange = 0.2;
        %rand('state', 0);
        PP = -0.5 + rand(2,n); % in [-0.5 0.5] x [-0.5 0.5] square
        D = sparse(n,n);
        nf = 0.1; % noisefactor
        nA = 0; % number of nodes in \A in Tseng's example
                % number of known distances that are perturbed
        % first m points are fixed
        % It is those distances from the remaining m+1:n that are to be
        % perturbed
        for j = (m+1):n % generate {\cal N} and {\cal M}
            tmp = PP(:, j)*ones(1, j-1) - PP(:, 1:j-1);
            rr  = sqrt(sum(tmp.*tmp));
            %D(1:j-1, j) = rr';
            radiorange = Radius;
            idx = find(rr < radiorange);
            if (~isempty(idx))
                rr2 = rr(idx);
                rr3 = rr2.*abs(1+ randn(1, length(idx))*nf);
                % abs is used by Tseng (07) so that the below lines are not
                % needed
%                 idxtmp = find(rr3 <= 0); 
%                   if (~isempty(idxtmp)) % unlikely to happen
%                      rr3(idxtmp) = rr2(idxtmp); % use the true distance
%                   end
               D(idx, j) = rr3;
               nA = nA + length(idx);
%                length(idxtmp)
%                length(idxtmp) - length(idx)
%                pause
            end
        end
       
        % calculate the leading mxm block of D for the fixed sensors
        for j = 2:m
            tmp = PP(:, j)*ones(1, j-1) - PP(:, 1:j-1);
            rr  = sqrt(sum(tmp.*tmp));
            D(1:j-1, j) = rr';
        end
        D = D+D';
        I = []; J =[]; b =[];
         for i = 1:m-1
            I =[I; i*ones(m-i, 1)];
            J =[J; (i+1:m)'];
            b = [b; (D(i, i+1:m)')];   
         end
%%%%%
case 'BLTWY06' % Example of Biswas, Liang, Toh, Wang and Ye
           % m = 4, s= 60, n = 64, nf =0, radiorange = 0.2
           % 4 inner anchors at [+-0.2, +-0.2]; 60 random sensors
        m = 4; s = 60; n = m+s; r =2; nf = 0.2; Radius = 0.3;
        rand('state', 0);
        PP = -0.5 + rand(2,s); % in [-0.5 0.5] x [-0.5 0.5] square
        %B =[0.2 0.2 -0.2 -0.2; 0.2 -0.2 0.2 -0.2];
        B = [0.45 0.45 -0.45 -0.45; 0.45 -0.45 0.45 -0.45];
        PP = [B PP];
        D = sparse(n,n);
        nA = 0; % number of nodes in \A in Tseng's example
                % number of known distances that are perturbed
        % first m points are fixed
        % It is those distances from the remaining m+1:n that are to be
        % perturbed
        for j = (m+1):n
            tmp = PP(:, j)*ones(1, j-1) - PP(:, 1:j-1);
            rr  = sqrt(sum(tmp.*tmp));
            %D(1:j-1, j) = rr';
            radiorange = Radius;
            idx = find(rr <= radiorange);
            if (~isempty(idx))
                rr2 = rr(idx);
                rr3 = rr2.*abs(1+ randn(1, length(idx))*nf);
                %rr3 = rr2.*abs(1+ nf*(-sqrt(3) + 2*sqrt(3)*rand(1, length(idx))));
                % abs is used by Tseng (07) so that the below lines are not
                % needed
%                 idxtmp = find(rr3 <= 0); 
%                   if (~isempty(idxtmp)) % unlikely to happen
%                      rr3(idxtmp) = rr2(idxtmp); % use the true distance
%                   end
               D(idx, j) = rr3;
               nA = nA + length(idx);
%                length(idxtmp)
%                length(idxtmp) - length(idx)
%                pause
            end
        end
        % calculate the leading mxm block of D for the fixed sensors
        for j = 2:m
            tmp = PP(:, j)*ones(1, j-1) - PP(:, 1:j-1);
            rr  = sqrt(sum(tmp.*tmp));
            D(1:j-1, j) = rr';
        end
        D = D+D';
        I = []; J =[]; b =[];
         for i = 1:m-1
            I =[I; i*ones(m-i, 1)];
            J =[J; (i+1:m)'];
            b = [b; (D(i, i+1:m)')];   
         end

    otherwise
        disp('Input a Problem Name:');
        
end

DD = [D((m+1):end, (m+1):end), D(1:m, (m+1):end)'];

%%%% set parameters for LagDu.m
pars.m = m;
pars.I = I;
pars.J = J;
pars.b = b.^2;
pars.DD = DD;
pars.PP = PP;
pars.plotyes = 1;
pars.Refinement = 1;

[~, X, ~] = LAD(D, r, pars);
end


