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);
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
1.版本:matlab2021a,包含仿真操作录像,操作录像使用windows media player播放。 2.领域:OSPF协议网络最优路由 3.内容:基于GA遗传优化的OSPF协议网络最优路由matlab仿真 step1. 当有连接请求时,算法开始,考察源节点S是否为域的边界节点,不是的话在域内使用最短跳算法路由至此域的边界节点 域的边界节点用U表示(图中A, B),下一跳接口为[D, N, r(U, N)],D为宿节点,N为下一跳结点,r(U, N) = {wU, wN, hU-N},wU, wN为U,N结点间波长,hU-N 是U,N间的代价,再到下一跳r(N, E),E为下一个域的边界节点。 step2. 根据OSPF 协议规范,在请求连接的两点之间,用Dijkstra 算法计算出所有路径,尽量消除冗余存储和冗余计算,挑选出代价最少的路径,hU-D = hU-N+ hN-E + …+h*-D, 总代价为各跳路径相加, 4.注意事项:注意MATLAB左侧当前文件夹路径,必须是程序所在文件夹位置,具体可以参考视频录。
资源推荐
资源详情
资源评论
收起资源包目录
基于GA遗传优化的OSPF协议网络最优路由matlab仿真.rar (11个子文件)
untitled2.jpg 15KB
matlab
Runme.m 4KB
func
select.m 458B
tsp.m 3KB
initialize.m 125B
crossover.m 2KB
mutation.m 439B
adapt.m 232B
drawTSP.m 729B
untitled1.jpg 29KB
操作录像0039.avi 12.69MB
共 11 条
- 1
fpga和matlab
- 粉丝: 17w+
- 资源: 2629
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页