资源简介
通过禁忌搜索算法求解经典的TSP问题(MATLAB源代码),TSP问题为假设有一个旅行商人要拜访n个城市,他必须选择所要走的路径,路径的限制是每个城市只能拜访一次,而且最后要回到原来出发的城市。路径的选择目标是要求得的路径路程为所有路径之中的最小值。
代码片段和文件信息
% Travelling Sales man problem using Tabu Search使用禁忌搜索的旅行商问题
% This assumes the distance matrix is symmetric假设距离矩阵是对称的
% Tour always starts from node 1旅行总是开始从节点1开始
% **********Read distance (cost) matrix from Excel sheet “data.xls“******读取距离(成本)矩阵从Excel表”数据.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;最后访问节点为K
%shortest path from last visited node is always 1 where the tour旅行商最后一次访问节点的最短路径总是1
%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节点1总是固定为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初始化禁忌表”tabu_tenure”给出的迭代次数
% 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:100%迭代次数
fprintf(‘\n*****iteration number = %d*****\n‘ iter);
nbr =[];
% *******************Find all neighbours to current tour by an exchange通过变换寻找当前位置的所有邻居
%******************between each pair of nodes**************
- 上一篇:串联谐振电路simuli
nk模型 - 下一篇:位置式pid和增量式pid
相关资源
- matlab程序用Hopfield网络解决TSP
- 用蚁群算法求解TSP问题的matlab程序
- 基于遗传算法的旅游全国的路径最优
- 求解多旅行商(MTSP)的遗传算法的
- mtsp源代码MATLAB
- matlab蚁群算法各种经典蚁群算法for
- zw_TSP_matlab_c_高斯去噪.zip
- GA算法解决TSP问题(超完整版)(ma
- 贪婪算法和最小路径算法解决TSP问题
- 邮政运输网络中的邮路规划和邮车调
- 基于遗传算法的TSP问题求解
- MATLAB遗传算法解决旅行商问题TSP、多
- 蚁群算法MATLAB代码287131
- SOM-TSP[Matlab].rar
- 蜂群算法优化旅行商问题
- matlab解决旅行商问题
- hopfield网络解决TSP问题
- 关于MATLAB优化TSP算法的完善及推广
- city_location.mat
- Hopfield解决TSP问题
- 商旅问题TSP代码
- matlab 人工鱼群求解TSP
- 基于遗传算法的TSP问题(matlab)
- 解决灾情巡视TSP问题数模的MATLAB程序
- 模拟退火解决tsp的Matlab程序+设计报告
- MATLAB YALMIP工具箱调用cplex求解TSPTW
- MATLAB粒子群算法PSO解决TSP51个城市问题
- TSP商旅问题MATLAB算法
- 基于Matlab解决TSP问题的蚁群算法
- 人工神经网络Hopfield算法解决TSP最佳路
评论
共有 条评论