% This part generates table for type II.
% repeats: number of samples to be taken
% tol    : this determines the threshold to declare a sensor to be accurate

clear

Table = zeros(3,12);
Table2 = zeros(3,12);
Table3 = zeros(3,12);
repeats = 50 % number of samples
tol = 5e-3;

R = [0.9 1 1.1];
N = [60 80 100];

for i=1:3
  for j=1:3
    n=N(1,i); % rows for varying number of sensors
    r=R(1,j)*sqrt(log(n+4)/(n+4)); % columns for varying radio range
    for k=1:repeats
      D_ind = 0;
      while D_ind == 0
        radiogen(n,r); % generate random graph
        D_ind = sensor_check;
      end
      load Prob
      [PP,m,dd] = new_component(PP,m,dd);
      
      tic;[count,RMSD,t]=ESDPDcode(PP,m,dd,tol);t1=toc; % run ESDP and record RMSD/apsensors
      Table(i,4*j-3)=Table(i,4*j-3)+t;
      Table(i,4*j-2)=Table(i,4*j-2)+t1;
      Table(i,4*j-1)=Table(i,4*j-1)+count;
      Table(i,4*j)=Table(i,4*j)+RMSD;      
      fprintf(' haha ESDP %g %g\n', i,j)
      
      tic;[count,RMSD,t]=FULLSDPDcode_sub2(PP,m,dd,tol);t2=toc; % run ESDP and record RMSD/apsensors
      Table2(i,4*j-3)=Table2(i,4*j-3)+t;
      Table2(i,4*j-2)=Table2(i,4*j-2)+t2;
      Table2(i,4*j-1)=Table2(i,4*j-1)+count;
      Table2(i,4*j)=Table2(i,4*j)+RMSD;      
      fprintf(' haha SDP %g %g\n', i,j)
      
      tic;[count,RMSD,t]=FULLSOSDcode(PP,m,dd,tol);t3=toc; % run ESDP and record RMSD/apsensors
      Table3(i,4*j-3)=Table3(i,4*j-3)+t;
      Table3(i,4*j-2)=Table3(i,4*j-2)+t3;
      Table3(i,4*j-1)=Table3(i,4*j-1)+count;
      Table3(i,4*j)=Table3(i,4*j)+RMSD;   
      fprintf(' haha SOS %g %g\n', i,j)
    end
  end
end
Table=Table/repeats;
Table2=Table2/repeats;
Table3=Table3/repeats;

fprintf(' *************   DONE   *************\n')