end
R=inf;
%求哈密顿圈的最佳三分法
fori=2:22
for j=i+1:23
zhixu1=zhixu(1:i);
zhixu2=[zhixu(1),zhixu(i+1:j)];
zhixu3=[zhixu(1),zhixu(j+1:24)];
%第二种分割思想只需把相关语句修改如下:
%for i=2:23
% for j=i+1:24
% zhixu1=zhixu(1:i);
% zhixu2=[zhixu(1),zhixu(i:j)];
% zhixu3=[zhixu(1),zhixu(j:24)];
l1=juli(zhixu1,D);
l2=juli(zhixu2,D);
l3=juli(zhixu3,D);
%按最大最小化原则逐步筛选
r=max([l1,l2,l3]);
if r R=r; fval=[l1,l2,l3,R]; L1=zhixu1;L2=zhixu2;L3=zhixu3; end end end 计算巡视路线的函数文件: functiondd=juli(zhixu,D) %计算巡视路线的权值 length=size(zhixu,2); s=0; fori=2:length s=s+D(zhixu(i-1),zhixu(i)); end if length~=2 s=s+D(zhixu(1),zhixu(length)); end dd=s;