資源簡(jiǎn)介
粒子群算法matlab仿真,幫助研究生學(xué)姐的畢設(shè)寫的
代碼片段和文件信息
function?[fv_GloBestIndv]?=?PSO(nmVMPMtimeIndvNum)%求最小值
%計(jì)算各粒子適應(yīng)度值并尋找GloBestIndv
format?long;
w=1;c1=2;c2=2;
GloBestIndv?=?zeros(timem);
for?i=1:IndvNum
????while(1)
????????[x(i:)v(i:)]?=?Init(nm);
????????for?j=1:m????????????????????????????????%?阻止x?v逸出
????????????while?(x(ij)<1||x(ij)>n)???
????????????????x(ij)=round(rand(11)*(n-1))+1;
????????????end
????????end
????????if?(judge(nmVMPMx(i:)))?break;???????%確定虛擬機(jī)能放入物理機(jī)中
????????end
????end?????????????????????????????
????
????PerBestIndv(i:)?=?x(i:);
????y(i:)?=?x(i:);
end
GloBestIndv(1:)?=?x(1:);
for?i=2:IndvNum
????if?fitness(nmVMPMx(i:)) ????????GloBestIndv(1:)?=?x(i:);
????end
end
for?t=2:time?
????for?i=1:IndvNum
????????%v(i:)?=?v(i:)+(PerBestIndv(i:)-x(i:))*rand()+(GloBestIndv-x(i:))*rand();
????????v(i:)=w*v(i:)+c1*rand*(PerBestIndv(i:)-x(i:))+c2*rand*(GloBestIndv(t-1:)-x(i:));
??
評(píng)論
共有 條評(píng)論