% runcode for p_criterion

% real data

% rmpath('./p_criterion_with_K');
path('./p_criterion',path);

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

maxiter = 10000;

feas2 = [];


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