-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathmain.m
56 lines (36 loc) · 1.6 KB
/
main.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
clear
close all
clc
% number of nodes
ns=100;
map=map_definition();
%
% generate random nodes
[map, nodelocation]= generate_node(map,ns);
% create undirected graph and its edges
[undirectedGraph,unedges]=generate_undirected_graph(map,nodelocation);
% define start and end point of simulation
startp=[5, 29];
endp=[29, 20];
% add start and end location as a new 2 nodes in undirected map.
% n+1 th node is start point, n+2th node is end point
[extungraph,exnodelocation,exunedges ]=addstartendpoint2ungraph(map,undirectedGraph,nodelocation,unedges,startp,endp);
exundnodIndex=[1:ns+2];
snodeund=ns+1;
enodeund=ns+2;
% optimal path with dijkstra on un-directional map
[Route Cost] = dijkstra(extungraph,exnodelocation,snodeund);
rt=Route{enodeund};
dijkstra_route=exnodelocation(rt,:);
cost=pathcost(dijkstra_route);
drawRoute('dijkstra on undirected map',snodeund,enodeund,exnodelocation,exundnodIndex,exunedges,rt,cost);
% optimal path with astar on un-directional map
[Route] = astar(extungraph,exnodelocation,snodeund,enodeund);
astar_route=exnodelocation(Route,:);
cost=pathcost(astar_route);
drawRoute('Astar on undirected map',snodeund,enodeund,exnodelocation,exundnodIndex,exunedges,Route,cost);
% optimal path with dynamic programming on un-directional map
[parent, Route]=dynamicpathplanning(extungraph,exnodelocation,exundnodIndex,snodeund,enodeund);
dpundirected_route=exnodelocation(Route,:);
cost=pathcost(dpundirected_route);
drawRoute('Dynamic Programming on undirected map',snodeund,enodeund,exnodelocation,exundnodIndex,exunedges,Route,cost);