%禁忌搜索求解0-1背包问题
clear all;close all;
%global a;
%global c;
a=[4,43,83,84,68,92,82,6,44,32,18, 56,83,25,96,70,48,14,58,92];
c=[46,90,72,91,40,75,35,8,54,78,40,77,15,61,17,75,29,75,63,44];
n=20;
b=878;
listlength=15;%禁忌长度
num=1;
bnum=1;
%初始化禁忌表
list=round(rand(1,20));
for i=1:20
list(i)=0;
end
fxbest(bnum)=0;%记录每次迭代最好的值
fxlbest(num)=0;%记录当前最好的值
%m=200;
for j=1:200
k=1;%选择初始可行解
while(k)
x0=round(rand(20,1));%产生初始x(1)->x(20)
x0(1)=1;%以x(1)为起点
w=a*x0;
if w<=b
k=0;
end
end
if (c*x0)>fxbest(num)
fxbest(num)=c*x0;
xbest=x0;
end
end
if fxbest(num)>fxlbest(bnum)
fxlbest(bnum)=fxbest(num);
end
x1=x0;
%nlist=list;
%产生邻域解 禁忌对象选择x的分量,并选择最佳解,
while(num<=500)
[x,p1,p2]=near(x1,list);
%更新禁忌表
list=newlist(p1,p2,list);
x1=x;
num=num+1;
fxbest(num)=c*x1;
if fxbest(num)>fxlbest(bnum)
bnum=bnum+1;
fxlbest(bnum)=fxbest(num);
xbest=x1;
list(p1)=0;
list(p2)=0;
end
end
subplot(2,1,1)
plot([1:num],fxbest); grid;
axis([0 num 0 2000]); xlabel('num'); ylabel('fxbest'); title('每一代最值变化序列');
subplot(2,1,2)
plot([1:bnum],fxlbest); grid;
axis([0 bnum 0 2000]); xlabel('bnum'); ylabel('fxlbest'); title('当前最佳值变化序列');


海神之光
- 粉丝: 6w+
最新资源
- 网站设计专业技术方案及报价.doc
- 项目管理中的关注点.doc
- 计算机教学实习报告范文参考.doc
- 施工进度计划横道图及网络图.xls
- Period3MakeaspeechaboutChina'saidtoothercountries.pptx
- 有关计算机组装与维护试题及答案.doc
- 门户网站策划书.docx
- 新媒体网络用语自查报告.docx
- 计算机实训工作总结.docx
- 高二物理竞赛课件电路复杂可编程逻辑(CPLD).pptx
- 《3-4算法及其实现》优质课教案.doc
- 三菱plc特殊继电器-.doc
- 软件版本升级服务协议.doc
- 防电信网络诈骗宣传心得体会经典优质范文3篇.docx
- 机械CADCAE技术基础教材机械CADCAE(绪论).doc
- C语言总复习-绝对经典.ppt
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈


