Test script
n = 10;
maxDeg = 4;
M=rand(n);
M=0.5*(M+M');
S1=sort(M,1,'descend');
S2=sort(M,2,'descend');
T=max(S1(maxDeg,:),S2(:,maxDeg));
A=M>=T;
G=graph(A);
plot(G);
st = randperm(n,2);
p = AllPath(A, st(1), st(2)); ;
fprintf('--- test ---\n');
for k=1:size(p,1)
fprintf('path #%d: %s\n', k, mat2str(p{k}));
end
Result for this graph, s=1, and t=10:
path #1: [1 6 10]
path #2: [1 9 3 4 5 8 10]
path #3: [1 9 3 8 10]
path #4: [1 9 8 10]
The result is still managable for n<=30, I get about few thousand paths listed with such random generated graph. Hard to know how the number of path scaled up with N if the degree of the graphe is bounded. My intuition is the number of paths more or less the number of partitions of N, according to Maranujan, it's ~ exp(sqrt(N)).
Put this on the mfile AllPath.m or at end of the test script above
function p = AllPath(A, s, t)
if s == t
p = {s};
return
end
p = {};
As = A(:,s)';
As(s) = 0;
neig = find(As);
if isempty(neig)
return
end
A(:,s) = [];
A(s,:) = [];
neig = neig-(neig>=s);
t = t-(t>=s);
for n=neig
p = [p; AllPath(A,n,t)];
end
p = cellfun(@(a) [s, a+(a>=s)], p, 'unif', 0);
end
Best Answer