function [ disResult,P ] = SimpleSide_vOP( X,Y,w )  %输入X是n维行向量,Y是p*m维矩阵,得到的距离结果OrderPermutation是一个p维列向量

item = 100;   % 抽样次数
n = length( X );
[p,m] = size( Y ); 
dis = zeros(item,p);
for kk = 1:item
    Pmatrix{kk,1} = vector_OP(X,Y,w);   % 算法核心是，一次 Selection 共用一个P
    Z1 = Pmatrix{kk,1}*X';
    dis(kk,:) = pdist2(Z1',Y);        % p 维行向量
end
for i=1:p
    un = find(dis(:,i) == min(dis(:,i)));
    P{i,1} = Pmatrix{un(1),1};
end
disResult = min(dis)'; % p 维列向量

end

function [ Po ] = vector_OP( X,Y,w )  % 一次随机 Selection

n = length( X );
[p,m] = size( Y );
Po = zeros(m,n);  % P X' - Y'
Po(m,n)=1;
num(1)=n;
for k=1:m-1
    a = min( num(k)-m+k,w );
    temp = round( rand(1,1)*a )+m-k;
    Po(m-k,temp) = 1;
    num(k+1) = temp;
end

end


