function [ disResult,P,Q ] = warping_OrderPermutation( X,Y,w )        %输入X是n维行向量,Y是m维行向量,得到的距离结果OrderPermutation值

item = 100;   % 抽样次数
n = length( X );
m = length( Y ); 
dis = zeros(1,item);
for kk = 1:item
    Pmatrix{kk,1} = warping_OP(X,Y,w);
    Pmatrix{kk,2} = warping_OP(X,Y,w);
    Z1 = Pmatrix{kk,1}*X';
    Z2 = Pmatrix{kk,2}*Y';
    dis(kk) = pdist2( Z1',Z2' );
end
un = find(dis == min(dis));
disResult = min(dis);
P = Pmatrix{un(1),1};
Q = Pmatrix{un(1),2};

end

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

n = length( X );
m = length( 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


