资源简介
一种用matlab开发出来的禁忌算法解决TSP问题

代码片段和文件信息
% Travelling Sales man problem using Tabu Search
% This assumes the distance matrix is symmetric
% Tour always starts from node 1
% **********Read distance (cost) matrix from Excel sheet “data.xls“******
clearclc;
d = xlsread(‘tsp_data.xls‘);
d_orig = d;
start_time = cputime;
dim1 = size(d1);
dim12 = size(d);
for i=1:dim1
d(ii)=10e+06;
end
% *****************Initialise all parameters**********************
d1=d;
tour = zeros(dim12);
cost = 0;
min_dist=[ ];
short_path=[ ];
best_nbr_cost = 0;
best_nbr = [ ];
% *******Generate Initial solution - find shortest path from each node****
% if node pair 1-2 is selected make distance from 2 to each of earlier
%visited nodes very high to avoid a subtour
k = 1;
for i=1:dim1-1
min_dist(i) = min(d1(k:));
short_path(i) = find((d1(k:)==min_dist(i))1);
cost = cost+min_dist(i);
k = short_path(i);
% prohibit all paths from current visited node to all earlier visited nodes
d1(k1)=10e+06;
for visited_node = 1:length(short_path);
d1(kshort_path(visited_node))=10e+06;
end
end
tour(1short_path(1))=1;
for i=2:dim1-1
tour(short_path(i-1)short_path(i))=1;
end
%Last visited node is k;
%shortest path from last visited node is always 1 where the tour
%originally started from
last_indx = length(short_path)+1;
short_path(last_indx)=1;
tour(kshort_path(last_indx))=1;
cost = cost+d(k1);
% A tour is represented as a sequence of nodes startig from second node (as
% node 1 is always fixed to be 1
crnt_tour = short_path;
best_tour = short_path;
best_obj =cost;
crnt_tour_cost = cost;
fprintf(‘\nInitial solution\n‘);
crnt_tour
fprintf(‘\nInitial tour cost = %d\t‘ crnt_tour_cost);
nbr_cost=[ ];
% Initialize Tabu List “tabu_tenure“ giving the number of iterations for
% which a particular pair of nodes are forbidden from exchange
tabu_tenure = zeros(dim12);
max_tabu_tenure = round(sqrt(dim1));
%max_tabu_tenure = dim1;
penalty = zeros(1(dim1-1)*(dim1-2)/2);
frequency = zeros(dim12);
frequency(1:)=100000;
frequency(:1)=100000;
for i=1:dim1
frequency(ii)=100000;
end
iter_snc_last_imprv = 0;
%*********Perform the iteration until one of the criteria is met***********
%1. Max number of iterations reached***************************************
%2. Iterations since last improvement in the best objective found so far
% reaches a threshold******************************************************
best_nbr = crnt_tour;
for iter=1:10000
fprintf(‘\n*****iteration number = %d*****\n‘ iter);
nbr =[];
% *******************Find all neighbours to current tour by an exchange
%******************between each pair of nodes***********************
% ****Calculate the object value (cost) for each of the neighbours******
nbr_cost = inf(dim12);
for i=1:dim1-2
for j=i+1:dim1-1
if i==1
if j-i==1
nbr_cost(crnt_tour(i)crnt_tour(j))=crnt_tour_cost-d(1crnt_tour(i))+...
d(1crnt_tour(j))- d(crnt_tour(j)crnt_tour(j+1))+d(crnt_tour(i)crnt_tour(j+1));
best_i=i;
best_
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 24576 2011-10-16 21:42 tsp_data.xls
文件 9111 2011-10-16 22:11 taboo_tsp.m
- 上一篇:数字多波束形成 matlab
- 下一篇:Sudoku-九宫格-数独matlab代码
相关资源
- matlab_OFDM调制解调(来自剑桥大学)
- Matlab路面裂缝识别69319
- 高灵敏度GPS接收机MATLAB仿真,附捕获
- 基于MATLAB的质点弹道计算与外弹道优
- 阵列天线的matlab仿真
- MATLAB 经典程序源代码大全
- MATLAB小波软阈值去噪代码33473
- 天线阵的波束形成在MATLAB仿真程序及
- 非线性SVM算法-matlab实现
- 《MATLAB 智能算法超级学习手册》-程序
- 组合导航matlab程序
- 读取txt文件内容matlab代码实现
- Matlab实现基于相关的模板匹配程序
- matlab优化工具箱讲解
- 基于MATLAB的快速傅里叶变换
- 光纤传输中的分布傅立叶算法matlab实
- 基于matlab的图像处理源程序
- matlab 椭圆拟合程序
- 算术编码解码matlab源代码
- optical_flow 光流法 matlab 实现程序
- 引导图像滤波器 Matlab实现
- 分形几何中一些经典图形的Matlab画法
- OFDM系统MATLAB仿真代码
- SVM工具箱(matlab中运行)
- 图像小波变换MatLab源代码
- LU分解的MATLAB实现
- 冈萨雷斯数字图像处理matlab版(第三
- 替代数据法的matlab程序
- 用matlab实现的多站定位系统性能仿真
- 通过不同方法进行粗糙集属性约简m
评论
共有 条评论