% runcode for A_criterion

% real data

% rmpath('./A_criterion_with_K');
path('./A_criterion',path);

fid = fopen('A_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] = multiplicativec(M,w0,10000,2e-4,maxiter);
      time2 = toc;
      
      feas2 = [feas2; sum(w) min(w)];
      
      tic
      [w fval3] = IPM_A(M,1e-10,inf);
      time3 = toc;
      
      feas2 = [feas2; sum(w) min(w)];
      
      [w fval4 time4] = A_criterion_SDPT3(M);
      
      feas2 = [feas2; sum(w) min(w)];
      
      Table = [time2 time3 time4 fval2 fval3 fval4];
      
      fid = fopen('A_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] = multiplicativec(M,w0,10000,2e-4,maxiter);
      time2 = toc;
      
      feas2 = [feas2; sum(w) min(w)];
      
      tic
      [w fval3] = IPM_A(M,1e-10,inf);
      time3 = toc;
      
      feas2 = [feas2; sum(w) min(w)];
      
      [w fval4 time4] = A_criterion_SDPT3(M);
      
      feas2 = [feas2; sum(w) min(w)];
      
      Table = [time2 time3 time4 fval2 fval3 fval4];
      
      fid = fopen('A_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
