clc;
clear;
close all;
warning off;
addpath(genpath(pwd));
webpoint=30; %节点数目
[D,M]=tsp(webpoint);
popsize=20;
N=199; %N为迭代次数
pcro=0.85;
pmut=0.5;
gen=1;
minval=inf;
pop=initialize(popsize,webpoint);
while gen<=N
val=adapt(pop,popsize,webpoint,D);
fitval=(1000./val).^15;
[valmin,minind]=min(val);
%保存最优
if valmin<minval
minval=valmin;
minpath=pop(minind,:);
end
minf(gen)=minval; %最短路径长度
pop=select(pop,fitval,popsize,webpoint,minpath); %比例选择
pop=crossover(pop,pcro,popsize,webpoint); %OX交叉
pop=mutation(pop,pmut,popsize,webpoint); %变异
drawTSP(M,minpath,minval,gen,0);
gen=gen+1;
end
drawTSP(M,minpath,minval,gen,1);
hold on
r=0.022;
t=0:pi/180:2*pi;
x=r*cos(t)+0.03;
y=r*sin(t)+0.03;
plot(x,y,'b--');hold on;
plot([0.03,0.01],[0.03,0.03],'b--');hold on;
plot([0.03,0.04],[0.03,0.01],'b--');hold on;
plot([0.03,0.02],[0.03,0.01],'b--');hold on;
plot([0.03,0.05],[0.03,0.03],'b--');hold on;
plot([0.03,0.03],[0.03,0.05],'b--');hold on;
plot([0.02,0.04],[0.01,0.01],'b--');hold on;
plot([0.04,0.05],[0.01,0.03],'b--');hold on;
plot([0.05,0.03],[0.03,0.05],'b--');hold on;
plot([0.03,0.01],[0.05,0.03],'b--');hold on;
plot([0.01,0.02],[0.03,0.01],'b--');hold on;
%================================================
%================================================
hold on
t=0:pi/180:2*pi;
x=r*cos(t)+0.13;
y=r*sin(t)+0.03;
plot(x,y,'b--');hold on
plot([0.13,0.11],[0.03,0.03],'b--');hold on;
plot([0.13,0.14],[0.03,0.01],'b--');hold on;
plot([0.13,0.12],[0.03,0.01],'b--');hold on;
plot([0.13,0.15],[0.03,0.03],'b--');hold on;
plot([0.13,0.13],[0.03,0.05],'b--');hold on;
plot([0.12,0.14],[0.01,0.01],'b--');hold on;
plot([0.14,0.15],[0.01,0.03],'b--');hold on;
plot([0.15,0.13],[0.03,0.05],'b--');hold on;
plot([0.13,0.11],[0.05,0.03],'b--');hold on;
plot([0.11,0.12],[0.03,0.01],'b--');hold on;
%================================================
%================================================
t=0:pi/180:2*pi;
x=r*cos(t)+0.23;
y=r*sin(t)+0.03;
plot(x,y,'b--');hold on
plot([0.23,0.21],[0.03,0.03],'b--');hold on;
plot([0.23,0.24],[0.03,0.01],'b--');hold on;
plot([0.23,0.22],[0.03,0.01],'b--');hold on;
plot([0.23,0.25],[0.03,0.03],'b--');hold on;
plot([0.23,0.23],[0.03,0.05],'b--');hold on;
plot([0.22,0.24],[0.01,0.01],'b--');hold on;
plot([0.24,0.25],[0.01,0.03],'b--');hold on;
plot([0.25,0.23],[0.03,0.05],'b--');hold on;
plot([0.23,0.21],[0.05,0.03],'b--');hold on;
plot([0.21,0.22],[0.03,0.01],'b--');hold on;
%================================================
%================================================
t=0:pi/180:2*pi;
x=r*cos(t)+0.08;
y=r*sin(t)+0.08;
plot(x,y,'b--');hold on
plot([0.08,0.07],[0.08,0.06],'b--');hold on;
plot([0.08,0.09],[0.08,0.06],'b--');hold on;
plot([0.08,0.06],[0.08,0.08],'b--');hold on;
plot([0.08,0.10],[0.08,0.08],'b--');hold on;
plot([0.08,0.08],[0.08,0.10],'b--');hold on;
plot([0.07,0.09],[0.06,0.06],'b--');hold on;
plot([0.09,0.10],[0.06,0.08],'b--');hold on;
plot([0.10,0.08],[0.08,0.1],'b--');hold on;
plot([0.08,0.06],[0.1,0.08],'b--');hold on;
plot([0.06,0.07],[0.08,0.06],'b--');hold on;
%================================================
%================================================
t=0:pi/180:2*pi;
x=r*cos(t)+0.18;
y=r*sin(t)+0.08;
plot(x,y,'b--');hold on;
plot([0.18,0.17],[0.08,0.06],'b--');hold on;
plot([0.18,0.19],[0.08,0.06],'b--');hold on;
plot([0.18,0.16],[0.08,0.08],'b--');hold on;
plot([0.18,0.20],[0.08,0.08],'b--');hold on;
plot([0.18,0.18],[0.08,0.10],'b--');hold on;
plot([0.17,0.19],[0.06,0.06],'b--');hold on;
plot([0.19,0.20],[0.06,0.08],'b--');hold on;
plot([0.20,0.18],[0.08,0.1],'b--');hold on;
plot([0.18,0.16],[0.1,0.08],'b--');hold on;
plot([0.16,0.17],[0.08,0.06],'b--');hold on;
%================================================
%================================================
figure;plot(minf,'-r');xlabel('迭代次数');ylabel('最短路径长度');
disp('最短路径为:');disp(minpath);
disp('最短路径长度为:');disp(minval);
fpga和matlab
- 粉丝: 18w+
- 资源: 2639
最新资源
- 基于小程序的研知识题库小程序源码(小程序毕业设计完整源码).zip
- scratch放烟花 scratch案例 scratch编程案例 scratch创意编程
- 基于小程序的超市售货管理平台小程序源码(小程序毕业设计完整源码+LW).zip
- 基于监督学习的web入侵检测系统源码毕业设计源码
- 基于小程序的大学生党务学习平台小程序源码(小程序毕业设计完整源码+LW).zip
- 基于小程序的大学生校园兼职微信小程序源码(小程序毕业设计完整源码+LW).zip
- 睡岗图像数据集(1400张图片).rar
- 2017 Global Data Challenge Hosted by JD Finance , JDD-2017京东金融全球数据探索者大赛 金融信贷需求预测.zip
- thinkpython配套资源-示例源码
- labview 编写的类teststand多工位并行测试框架,带单独的测试和序列编辑,参数编辑功能,具体的见图片,功能正常,多工位测试,带源码
- 工具变量-中国制造业新质生产力水平指标.xlsx
- 3DMAX书籍生成器插件BookGenerator下载
- 复现基于双向反激变器的SOC估算与主动均衡仿真 1复现硕士lunwen:《锂离子电池SOC估算与主动均衡策略研究-王昊》 2六节电池模型:使用 Simmulink 搭建了六节电池主动均衡仿
- 离线打包报错音频的依赖
- 基于深度学习卷积神经网络的农作物病虫害识别检测系统python源码+数据集(高分毕设)
- Modelsim安装软件
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
前往页