Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
startpos = [103, 480];
endpos = [110, 400];

[wavefrontmap, path] = wavefront(testimage, startpos, endpos);
[wavefrontmap, path] = wavefront(testimage, startpos, endpos, 'urdl');

% you can just run this function without rebuilding the wavefront map if the
% goal location (or end point) does not change.

path = shortest_wavefront_path(wavefrontmap, startpos);
path = shortest_wavefront_path(wavefrontmap, startpos, 'urdl');
imagesc(wavefrontmap);
hold on
plot(path(:,1), path(:,2), '-r');
Expand Down
46 changes: 23 additions & 23 deletions matlab_simulation/08-planning/shortestpath_mr.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
% upper triangle
% start: index of start node
% finish: index of finish node
% method: (1 = Astar) (2 = Dijkstra's)
% method: (1 = Astar) (2 = BFS) (3 = DFS) (4 = Dijkstra's)
% heuristicDist: 1.Euclidean distance 2.Manhattan distance
% createVideo: (1 = YES) (the others: NO)
% Outputs:
Expand Down Expand Up @@ -50,7 +50,7 @@
n = length(nodes);
switch heuristicDist
case 1
if (method == 3) || (method == 4)
if (method == 2) || (method == 3)
disp('Error, use manhattan distance for breadth and depth first search')
return;
end
Expand Down Expand Up @@ -122,26 +122,6 @@
continue;
end

case 4 %Dijkstra's
% Check if open set is empty
if (isempty(OpenSet(:,1)))
spath = [];
sdist = 0;
return;
end
%--------------------------------
% Reminder: OpenSet(:,4)= distance to neighbours;
[val, best] = min(OpenSet(:,4));
%--------------------------------
bestnode = OpenSet(best,:);
% Check end condition
if (bestnode(1)==finish)
done = 1;
% Move best to closed set
C = [C; bestnode];
continue;
end

case 2 %Breadth-First
if (isempty(OpenSet(:,1)))
done = 1;
Expand Down Expand Up @@ -177,6 +157,26 @@
C = [C;bestnode];
continue;
end

case 4 %Dijkstra's
% Check if open set is empty
if (isempty(OpenSet(:,1)))
spath = [];
sdist = 0;
return;
end
%--------------------------------
% Reminder: OpenSet(:,4)= distance to neighbours;
[val, best] = min(OpenSet(:,4));
%--------------------------------
bestnode = OpenSet(best,:);
% Check end condition
if (bestnode(1)==finish)
done = 1;
% Move best to closed set
C = [C; bestnode];
continue;
end
end

% Move best to closed set
Expand Down Expand Up @@ -244,7 +244,7 @@
switch method
case 1 % Astar
OpenSet = OpenSet([1:best-1 best+1:end],:); % remove best node from open set
case 4 %Dijkstra's
case 4 % Dijkstra's
OpenSet = OpenSet([1:best-1 best+1:end],:); % remove best node from open set
end

Expand Down