Commit e2ed322e authored by Thomas Roy's avatar Thomas Roy
Browse files

working code

parent 4f2e019a
function path_min = shortest_path( n )
function [A,x] = shortest_path( n )
% We generate n uniformly random points in [0,1]x[0,1]
x = rand(n,2);
% Initialise Adjacency mantrix
......@@ -10,24 +10,31 @@ A(1,2) = norm(x(1,:)-x(2,:));
for i=3:n
distances = sqrt(sum(abs(x(1:i-1,:)-x(i,:)).^2,2));
[distances, nodes] = sort(distances);
cross = 0;
cross = 1;
node = nodes(1);
d_min = distances(1);
j = 1;
while cross == 1
[I,J] = find(A(1:i-1,1:i-1));
% Remove node included in current segment
J = J(I ~= node);
I = I(I ~= node);
I = I(J ~= node);
J = J(J ~= node);
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
if cross==1 && ~isempty(I)
j = j+1;
node = nodes(j);
d_min = distances(j);
else
A(node,i) = d_min;
break
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