資源簡介
該算法用matlab工具實現粒子群(鳥群)算法收斂的動態過程
代碼片段和文件信息
%?粒子群算法
%?標準函數測試
%?2005年10月
function?PSO_test()
?
????clear;
????%?select?an?optimization?problem
????NP_problem?=?1;
????switch?NP_problem
????????case?0??????????????????????????????????????????????????????????????%?F6
????????????%?Shaffer‘?2s?F6?-100~100在x=0和y=0的條件下有fitness_max=1
????????????uplimit?=?10;
????????????dnlimit?=?-10;
????????case?1
????????????%?Ras?函數,在x=0和y=0的條件下有最小值ras=0
????????????uplimit?=?1;
????????????dnlimit?=?-1;
????????case?2
????????????%?Rosenbrock?函數,在x=1和y=1的條件下有最小值ros=0
????????????uplimit?=?2;??????????????????????????????%?uplimit?of?each?bit
????????????dnlimit?=?-2;?????????????????????????????%?dnlimit?of?each?bit
????end
????%?----------?Initilization?----------
????num_state?=?2;??????????????????????????????%?number?of?vectors
????popsize?=?30;????????????????????????????????%?number?of?particles
????max_gen?=?400;??????????????????????????????%?generation?of?evolution
????max_v?=?1;??????????????????????????????????%?maximum?velocity
????c1?=?2;?????????????????????????????????????%?self?learning?factor
????c2?=?0;?????????????????????????????????????%?social?learning?factor
????w_max?=?0.9;????????????????????????????????%?The?maximum?velocity?coefficient
????w_min?=?0.4;????????????????????????????????%?The?minimum?velocity?coefficient????
????pbest?=?zeros(popsize1);???????????????????%?the?best?fitness?among?all?selves
????gbest?=?0;??????????????????????????????????%?the?best?fitness?among?all?
????pid?=?[];???????????????????????????????????%?the?particle?corresponding?to?pbest
????pgd?=?[];???????????????????????????????????%?the?particle?corresponding?to?gbest
%????rand(‘seed‘1111);??????????????????????????%?remember?the?random?seed
????p?=?rand(popsizenum_state)*(uplimit-dnlimit)+dnlimit;????????????%?particle?positions
%????rand(‘seed‘2222);??????????????????????????%?remember?the?random?seed
????v?=?rand(popsizenum_state);????????????????%?particle?velocities
????????????
????%?start?the?inherit?operation
????t0?=?clock;
????%?----------?PSO?Calculation?Comparison?and?
評論
共有 條評論