-
Notifications
You must be signed in to change notification settings - Fork 0
/
Searchalgorithm.m
92 lines (82 loc) · 2.79 KB
/
Searchalgorithm.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
close all
clc
% Initialize the Plan with input values
% Obstacle=-1,Target = 0,Robot=1,Space=1
X_max=10;
Y_max=10;
figure
Plan=CreateScenario(X_max,Y_max);
title(' Sceanrio ')
% Generation of Map_plan2node
n=0;
for j=1:Y_max;
for i=1:X_max
n=n+1;
Map_plan2node(i,j)=n;
end
end
% Generation of NodeList
[NodeList] =IncidentList(Map_plan2node,Plan,X_max,Y_max);
% Generation of Nodes
[Nodes] = IncidentMatrix(Map_plan2node,Plan,X_max,Y_max);
% Identification of TargetNode and RootNode
[target_x,target_y]=find(Plan==-2);
TargetNode=Map_plan2node(target_x,target_y);
[root_x,root_y]=find(Plan==0);
RootNode=Map_plan2node(root_x,root_y);
%% Breadh First Search :
tic;[Path_BFS , NodeNumber_BFS ]= BFS( Nodes, NodeList , RootNode , TargetNode);temps_execution_largeur = toc;
Path_BFS=fliplr(Path_BFS);
AnimatePath(Path_BFS,Map_plan2node,'b');
legend(' BFS ')
h=msgbox('BFS is Finished , tap OK to continue ');
uiwait(h,40);
if ishandle(h) == 1
delete(h);
end
%hold on
%% Depth :
tic;[Path_DFS , NodeNumber_DFS ]= DFS( Nodes, NodeList , RootNode , TargetNode);temps_execution_profondeur=toc;
Path_DFS=fliplr(Path_DFS);
AnimatePath(Path_DFS,Map_plan2node,'r');
legend(' DFS ')
h=msgbox('DFS is Finished , tap OK to continue');
uiwait(h,40);
if ishandle(h) == 1
delete(h);
end
%hold on
%% A Star (Euclidian Distance ) :
[NodeList(:).x] = deal(X_max*Y_max);
[NodeList(:).y] = deal(X_max*Y_max); % avoir les coordonnees
[NodeList(:).g] = deal(X_max*Y_max); % Cout
[NodeList(:).h] = deal(X_max*Y_max); % Heuristique
[NodeList(:).parent] = deal(X_max*Y_max); % Stocker parent
tic;[Astar_Chemin , NodeNumber_AStar_Euc ]= Astar( Nodes,NodeList,RootNode,TargetNode,Map_plan2node);temps_execution_Asatr=toc;
AnimatePath(Astar_Chemin,Map_plan2node,'y');
legend(' A * ')
h=msgbox('A* Euclidien distance is Finished, tap OK to continue');
uiwait(h,40);
if ishandle(h) == 1
delete(h);
end
%% A Star Manhattan Distance :
tic;[Astar_man_Chemin , NodeNumber_AStar_Man ]= AstarMan( Nodes,NodeList,RootNode,TargetNode,Map_plan2node);temps_execution_Asatr_man=toc;
AnimatePath(Astar_man_Chemin,Map_plan2node,'g*');
legend(' A* Manhatan')
h=msgbox('A* Manhattan is Finished, tap OK to continue ');
uiwait(h,40);
if ishandle(h) == 1
delete(h);
end
%% Astar ( Variables costs ) :
[Nodes] = IncidentMatrix2(Map_plan2node,Plan,X_max,Y_max);
[NodeList] = IncidentList2(Map_plan2node,Plan,X_max,Y_max);
tic;[Astar_cout_Chemin , NodeNumber_AStar_Euc ]= Astar( Nodes,NodeList,RootNode,TargetNode,Map_plan2node);temps_execution_Asatr_c=toc;
AnimatePath(Astar_cout_Chemin,Map_plan2node,'p');
legend('A* Variable Cost')
h=msgbox('A* Variable Cost is Finished, tap OK to continue ');
uiwait(h,40);
if ishandle(h) == 1
delete(h);
end