diff --git a/main.m b/main.m index 1ff6f70..065f62c 100644 --- a/main.m +++ b/main.m @@ -3,10 +3,12 @@ clear close all %先形成初始点 center=[1,1,1,1,1;10,10,10,10,10;100,100,100,100,100;1000,1000,1000,1000,1000]; -center=[1;10;100;1000]; -dataN=50;% 生成多少个数据 -Dim=1; +% center=[1;10;100;1000]; +dataN=100;% 生成多少个数据 +Dim=5; +clusterN=5; data=zeros(Dim,dataN); +% data=[11,101,1001,1,2,3]; for I=1:dataN i=round(1+(4-1)*rand()); data(:,I)=center(i)*( -1+(1+1)*rand(Dim,1)); @@ -15,7 +17,7 @@ end SetS=[1;]; -for clusterI=1:3 +for clusterI=1:clusterN-1 maxG=-100*ones(dataN,1); for cluster=1:dataN if sum(ismember(cluster,SetS))>0 @@ -48,4 +50,71 @@ for clusterI=1:3 end maxGInd=find(maxG==max(maxG)); SetS=[SetS;maxGInd(1)]; +end +SetS +%% 进入SWAP部分 +% SetS=[1;2;3]; +USetS=setxor(1:dataN,SetS); + +while 1 + minKjih=1e20; + for I=1:length(SetS) + for H=1:length(USetS) + %交换两个集合的元素 + cadSetS=SetS; + cadUSetS=USetS; + swap=cadSetS(I); + cadSetS(I)=cadUSetS(H); + cadUSetS(H)=swap; + sumKjih=0; + for D=1:length(cadUSetS) + J=cadUSetS(D); + d=data(:,J); + if J==cadSetS(I) + continue + end + minD=1e20; + min2D=minD; + for G=1:length(SetS)%between j and the closest object in S. + distance=sum((d-data(:,SetS(G))).^2).^.5; + if distanceminD + Kjih=min([distanceHJ-minD,0]); + end + if distanceIJ