第二题禁忌搜索代码

第二题禁忌搜索代码main 脚本 第二题 clear all clc x0 5 初始 x jjcd 2 禁忌长度 jjjh zeros 1 jjcd jjjh 1 x0 Nx x0 4 x0 3 x0 2 x0 1 x0 1 x0 2 x0 3 x0 4 l size Nx

大家好,我是讯享网,很高兴认识大家。

main脚本

%第二题% clear all; clc; x0=5;%初始x jjcd=2;%禁忌长度 jjjh=zeros(1,jjcd); jjjh(1)=x0; Nx=[x0-4,x0-3,x0-2,x0-1,x0+1,x0+2,x0+3,x0+4];% [~,l]=size(Nx); BL=hanshu(x0); t=1; bestx=x0; while t<=10 for i=1:jjcd for j=1:l if jjjh(i)==Nx(j) Nx(j)=0; end end end for m=1:length(Nx) if Nx(m)<0||Nx(m)>10 Nx(m)=0; end end Nx(all(Nx==0,1))=[]; u=ceil(rand()*length(Nx)); XZ=Nx(u); xew_j=hanshu(XZ); if xew_j<BL BL=xew_j; bestx=XZ; end if t<=1 jjjh(2)=XZ; else jjjh(1)=jjjh(2); jjjh(2)=XZ; end Nx=[XZ-4,XZ-3,XZ-2,XZ-1,XZ+1,XZ+2,XZ+3,XZ+4]; [~,l]=size(Nx); h(t)=BL; o(t)=XZ; t=t+1; end plot(h); xlabel('Iteration'); ylabel('函数值') axis tight grid on box on legend('TS') 

讯享网

 hanshu


讯享网

讯享网function [f] = hanshu(X) f=0.01172*X^6-0.3185*X^5+3.2044*X^4-14.6906*X^3+29.75625*X^2-19.10625*X; end 

小讯
上一篇 2025-03-04 18:31
下一篇 2025-01-05 15:40

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/24154.html