%% User:   
%%       global variables must be used
clear all
profile on
global Xu Q q2kron indsu ;
itercnt=[];
dimcnt=[];
normZXcnt=[];
nnzQcnt=[];
mineigcnt=[];
cpucnt=[];
optvalcnt=[];
crossitercnt=[];
crossindex=1;
!rm outputtestmcps
for i=1:1,        % 1 files
% for i=2:13,        % 13 files
  diary outputtestmcps
  tforrQ=cputime;
  if i==1, mcp100; makeQ;
  elseif i==2, mcp124_1; makeQ;
  elseif i==3, mcp124_2; makeQ;
  elseif i==4, mcp124_3; makeQ;
  elseif i==5, mcp124_4; makeQ;
  elseif i==6, mcp250_1; makeQ;
  elseif i==7, mcp250_2; makeQ;
  elseif i==8, mcp250_3; makeQ;
  elseif i==9, mcp250_4; makeQ;
  elseif i==10, mcp500_1; makeQ;
  elseif i==11, mcp500_2; makeQ;
  elseif i==12, mcp500_3; makeQ;
  elseif i==13, mcp500_4; makeQ;
  end
  tforrQ=cputime-tforrQ;
  disp(['time for generating Q:  ',num2str(tforrQ)]);
  nnzQ=nnz(Q);
  nnzQcnt=[nnzQcnt nnzQ];
  disp(['number nonzeros in  Q:  ',num2str(nnzQ)]);
  [m,n]=size(Q);
%%%%%%%%%%%%%%%%%%call to solve max-cut using sdp relax%%%%%%%%%%%%%%
  toler=10^(-10);
  crosstoler=10^(-crossindex);
  disp(['solve Q dim, crosstoler :  ',num2str(n),...
          '  ',num2str(crosstoler)]);
  tcpusolve=cputime;
  [X,y,Z,mu,itersinfo,meritfn]=mcsdp(toler,crosstoler);
  tcpusolve=cputime-tcpusolve;
%%%%%%%%%%%%%%%%%%%%%% end of call to MCSDP
  mineig=min(min(eig(X)),min(eig(Z)));
  mineigcnt=[mineigcnt mineig];
  itercnt=[itercnt itersinfo(1)];
  crossitercnt=[crossitercnt itersinfo(2)];
  dimcnt=[dimcnt n];
  normZXcnt=[normZXcnt norm(Z*X,'fro')];
  cpucnt=[cpucnt tcpusolve];
  optvalcnt=[optvalcnt trace(Q*X)];
  save sdpdata itercnt dimcnt nnzQcnt mineigcnt cpucnt optvalcnt normZXcnt n crossitercnt
  diary off
end

profile report

