% runcode for D_criterion

% real data

% rmpath('./D_criterion_with_K');
path('./D_criterion',path);

fid = fopen('D_real.txt','w');
fclose(fid);

maxiter = 10000;

feas2 = [];


for design = 1:4
  
  if design ~= 3
    
    for m = [10000 50000 100000]
      
      [M, K, w0] = real_data(design,m);
      
      tic
      [w fval2] = multiplicatived(M,w0,10000,2e-4,maxiter);
      time2 = toc;
      
      feas2 = [feas2; sum(w) min(w)];
      
      tic
      [w fval3] = IPM_D(M,1e-10,inf);
      time3 = toc;
      
      feas2 = [feas2; sum(w) min(w)];
      
      [w fval4 time4] = D_criterion_SDPT3(M);
      
      feas2 = [feas2; sum(w) min(w)];
      
      Table = [time2 time3 time4 fval2 fval3 fval4];
      
      fid = fopen('D_real.txt','a');
      fprintf(fid, '%3d & %3d &  %5.2f  &  %5.2f  &  %5.2f  &  %13.6g  &  %13.6g  &  %13.6g\n', design, m, Table);
      fclose(fid);
      
    end
    
  else 
    
    for m = [100 200 300]
      
      [M, K, w0] = real_data(design,m);
      
      tic
      [w fval2] = multiplicatived(M,w0,10000,2e-4,maxiter);
      time2 = toc;
      
      feas2 = [feas2; sum(w) min(w)];
      
      tic
      [w fval3] = IPM_D(M,1e-10,inf);
      time3 = toc;
      
      feas2 = [feas2; sum(w) min(w)];
      
      [w fval4 time4] = D_criterion_SDPT3(M);
      
      feas2 = [feas2; sum(w) min(w)];
      
      Table = [time2 time3 time4 fval2 fval3 fval4];
      
      fid = fopen('D_real.txt','a');
      fprintf(fid, '%3d & %3d &  %5.2f  &  %5.2f  &  %5.2f  &  %13.6g  &  %13.6g  &  %13.6g\n', design, m, Table);
      fclose(fid);
      
    end
    
  end
   
end