資源簡介
利用局部搜索算法解決一個國外課程中的經典最優化問題,附題目和matlab代碼,可運行出結果。
代碼片段和文件信息
clc
clear?all
tic
Y?=[0.529?0.712?0.382?0.755?0.228?0.521?0.68?0.349?0.656?0.639?0.422?0.182...
????0.072?0.278?0.154?0.148?1.51?0.343?0.232?0.717?0.764?0.756?0.207?0.275?...
????0.268?0.76?0.192?0.458?0.14?0.49?0.564?0.876?0.64?1.372?0.259?0.189?1.067...
????0.458?0.305?0.249?1.237?0.964?1.136?0.698?0.452?0.241?0.324?0.256?0.159?...
????0.865?0.326?0.993?0.769?0.158?0.007?1.981?0.349?0.213?0.622?0.368?0.555?0.973?1.793?0.348];
tau1?=?randperm(64);%初始tau1,隨機排列
tau2?=?randperm(64);%初始tau2,隨機排列
?All_ex?=?nchoosek(1:642);?%C64_2的所有組合
Optobject?=?sum(?Y.*Y(tau1)+Y.*Y(tau2)+Y(tau1).*Y(tau2));%優化目標,令其最小
flag?=?1;
while?flag==1
?length(Optobject)
????
for?i=1:length(All_ex)
?????temp?=?tau1(All_ex(i1));
?tau1_neighbour(i:)?=?tau1;
?tau1_neighbour(iAll_ex(i1))=tau1_neighbour(iAll_ex(i2));
?tau1_neighbour(iAll_ex(i2))=temp;
?
??????temp?=?tau2(All_ex(i1));
?tau2_neighbour(i:)?=?tau2;
?tau2_neighbour(iAll_ex(i1))=tau2_neighbour(iAll_ex(i2));
?tau2_neighbour(iAll_ex(i2))=temp;
end
??
Neighbour_object?=?sum((???repmat(Ylength(All_ex)1).*Y(tau1_neighbour)...
????+repmat(Ylength(All_ex)1).*repmat(Y(tau2)length(All_ex)1)+Y(tau1_neighbour).*repmat(Y(tau2)length(All_ex)1)???)‘);
????if?min(Neighbour_object)ject(end)
????????Optobject?=[Optobject?min(Neighbour_object)];
????????
????????id?=?find(Neighbour_object==min(Neighbour_object));
????????tau1?=?tau1_neighbour(id(1):);
??flag1?=1;
????else
????????flag1?=0;
????????
????end
Neighbour_object?=?sum((???repmat(Ylength(All_ex)1).*Y(tau2_neighbour)...
????+repmat(Ylength(All_ex)1).*repmat(Y(tau1)length(All_ex)1)+Y(tau2_neighbour).*repmat(Y(tau1)length(All_ex)1)???)‘);
????if?min(Neighbour_object)ject(end)
????????Optobject?=[Optobject?min(Neighbour_object)];
???????????????
????????id?=?find(Neighbour_object==min(Neighbour_object));
????????tau2?=?tau2_neighbour(id(1):);
??flag2?=1;
????else
????????flag2?=0;
????end???
????
????
????flag?=?flag1?|?flag2;
???
????
end?
????outcome?=?[tau1;tau2];
????Optobject(end)
????toc
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????2146??2016-10-14?19:27??局部搜索最優化問題程序\LogalSearch.m
?????文件???????26214??2016-10-14?23:08??局部搜索最優化問題程序\題目.jpg
?????目錄???????????0??2016-10-15?17:19??局部搜索最優化問題程序\
- 上一篇:多自由度體系中心差分法matlab編程
- 下一篇:平坦衰落信道的仿真
評論
共有 條評論