clear
D=[0 1 0 1
1 0 1 1
0 1 0 1
1 1 1 0];
route=[];
for i=1:4
route=findRouting(D,i,route);
end
n=length(route);
for i=1:n
for j=1:length(route{i})-1
fprintf('%d -> ',route{i}(j));
end
fprintf('%d \n',route{i}(end));
end
function route=findRouting(D,troute,route)
N=size(D,1);
p=troute(end);
for i=1:N
if i~=p && D(p,i)==1
a=find(troute==i);
if isempty(a)
troute1=[troute,i];
n=length(route);
flag=0;
for j=1:n
if length(route{j})==length(troute1) && sum(abs(route{j}-troute1))==0
flag=1;
end
end
if flag==0
route{n+1}=troute1;
route=findRouting(D,troute1,route);
end
end
end
end
路由匹配的问题