资源简介

利用局部搜索算法解决一个国外课程中的经典最优化问题,附题目和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)< Optobject(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)< Optobject(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  局部搜索最优化问题程序\

评论

共有 条评论