% Group of Liya, Anjan, Peiyi

function [PLL, PLU, PUL, PUU, True_LL, m_record_PUL, z_UU, last_choose] = m_ssl2(PLL, PLU, PUL, PUU, True_LL, m_record_PUL, z_UU, last_choose)

% [tmp,x]=max(PUL,[],1);
% [tmp_max,y]=max(tmp);
% x=x(y);
[tmp,x]=max(PUL,[],1);
[~,y]=max(tmp);
x=x(y);
% [~,tmp_sort_id]=sort(PUL(x,:));
tmp_i=1;
while find(last_choose == True_LL(y))
    [~,y]=sort(tmp);
    y=y(end-tmp_i);
    [~,x]=max(PUL(:,y));
    tmp_i=tmp_i+1;
%     fprintf('.');
end
% if True_LL(tmp_sort_id(end))~=True_LL(tmp_sort_id(end-1))
%     if True_LL(tmp_sort_id(end-1))==True_LL(tmp_sort_id(end-2))
%         y=tmp_sort_id(end-1);
% %         fprintf('.');
%     end
% end
tmp_max=PUL(x,y);
last_choose=[last_choose True_LL(y)];
if length(last_choose)>=10
    last_choose(1)=[];
end

% z_UU(x)=True_LL(y);
% m_record=[m_record x];
[tmp_x tmp_y]=find(m_record_PUL==tmp_max);
z_UU(tmp_x)=True_LL(y);
%-------------------------------------------------
% Following are update for PLL,PUL,PUU etc. for the next loop
%-------------------------------------------------
W_norm=PUU;
% PLL = W_norm(Random_Objects, Random_Objects);
PLL=[PLL PLU(:,x)];
PLL=[PLL; [PUL(x,:) PUU(x,x)]];
% True_LL = True(Random_Objects, 1);
True_LL=[True_LL; True_LL(y)];
% PUU = W_norm;
% PUU(Random_Objects,:) = [];
% PUU(:,Random_Objects) = [];
PUU(:,x)=[];
PUU(x,:)=[];
% PLU = W_norm(Random_Objects, :);
% PLU(:,Random_Objects) = []; 
PLU=[PLU; W_norm(x,:)];
PLU(:,x)=[];
% PUL = W_norm(:, Random_Objects);
% PUL(Random_Objects,:) = [];
PUL=[PUL W_norm(:,x)];
PUL(x,:)=[];

% [x y]
% PUL;
% PUU;
% z_UU(400:500)
% True_LL
% pause();
% z_UU
% fprintf('%d\n',length(True_LL));


% m_len=length(True_LL);
% tmp=zeros(m_len,1);
% for i=1:m_len
%     [~,tmp(i)]=max(PUL(:,i));
%     z_UU(tmp(i))=True_LL(i);
%     for j=1:i
%         if tmp(j)==tmp(i) && max(PUL(:,j))>=max(PUL(:,i))
%             tmp(i)=[];
%             z_UU(tmp(j))=True_LL(j);
%             i=i-1;
%             m_len=m_len-1;
%         end
%         if tmp(j)==tmp(i) && max(PUL(:,j))<max(PUL(:,i))
%             tmp(j)=[];
%             z_UU(tmp(i))=True_LL(i);
%             i=i-1;
%             m_len=m_len-1;
%         end
%     end
% end




end