Commit 4f2e019a authored by Thomas Roy's avatar Thomas Roy
Browse files

graph

parent a7a55e5f
function path_min = shortest_path( n )
% We generate n uniformly random points in [0,1]x[0,1]
x = rand(n,2);
% Initialise Adjacency mantrix
A = zeros(n); % Only do upper triangular since symmetric
% First Line
A(1,2) = norm(x(1,:)-x(2,:));
% Construct the graph
for i=3:n
distances = sqrt(sum(abs(x(1:i-1,:)-x(i,:)).^2,2));
[distances, nodes] = sort(distances);
cross = 0;
node = nodes(1);
d_min = distances(1);
j = 1;
while cross == 1
[I,J] = find(A(1:i-1,1:i-1));
for k=1:length(I)
cross = checkCrossedLines(x(i,:),x(node,:),x(I(k),:),x(J(k),:));
if cross==1
break
end
end
if cross==1
j = j+1;
node = nodes(j);
d_min = distances(j);
else
A(node,i) = d_min;
end
end
end
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment