-
Notifications
You must be signed in to change notification settings - Fork 2
/
OPW.m
71 lines (71 loc) · 2.77 KB
/
OPW.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
%约束移动体在障碍栅格对角运动,通过优化邻接矩阵实现
%约束AGV移动方式
function W=OPW(map,W)
% map 地图矩阵 % W 邻接矩阵
n = size(map);
num = n(1)*n(2);
for(j=1:n(1))
for(z=1:n(2))
if(map(j,z)==1)
if(j==1) %若障碍物在第一行
if(z==1) %若障碍物为第一行的第一个
W(j+1,j+n(2)*j)=Inf;
W(j+n(2)*j,j+1)=Inf;
else
if(z==n(2)) %若障碍物为第一行的最后一个
W(n(2)-1,n(2)+n(1)*j)=Inf;
W(n(2)+n(1)*j,n(2)-1)=Inf;
else %若障碍物为第一行的其他
W(z-1,z+j*n(2))=Inf;
W(z+j*n(2),z-1)=Inf;
W(z+1,z+j*n(2))=Inf;
W(z+j*n(2),z+1)=Inf;
end
end
end
if(j==n(1)) %若障碍物在最后一行
if(z==1) %若障碍物为最后一行的第一个
W(z+n(2)*(j-2),z+n(2)*(j-1)+1)=Inf;
W(z+n(2)*(j-1)+1,z+n(2)*(j-2))=Inf;
else
if(z==n(2)) %若障碍物为最后一行的最后一个
W(n(1)*n(2)-1,(n(1)-1)*n(2))=Inf;
W((n(1)-1)*n(2),n(1)*n(2)-1)=Inf;
else %若障碍物为最后一行的其他
W((j-2)*n(2)+z,(j-1)*n(2)+z-1)=Inf;
W((j-1)*n(2)+z-1,(j-2)*n(2)+z)=Inf;
W((j-2)*n(2)+z,(j-1)*n(2)+z+1)=Inf;
W((j-1)*n(2)+z+1,(j-2)*n(2)+z)=Inf;
end
end
end
if(z==1)
if(j~=1&&j~=n(1)) %若障碍物在第一列非边缘位置
W(z+(j-2)*n(2),z+1+(j-1)*n(2))=Inf;
W(z+1+(j-1)*n(2),z+(j-2)*n(2))=Inf;
W(z+1+(j-1)*n(2),z+j*n(2))=Inf;
W(z+j*n(2),z+1+(j-1)*n(2))=Inf;
end
end
if(z==n(2))
if(j~=1&&j~=n(1)) %若障碍物在最后一列非边缘位置
W((j+1)*n(2),j*n(2)-1)=Inf;
W(j*n(2)-1,(j+1)*n(2))=Inf;
W(j*n(2)-1,(j-1)*n(2))=Inf;
W((j-1)*n(2),j*n(2)-1)=Inf;
end
end
if(j~=1&&j~=n(1)&&z~=1&&z~=n(2)) %若障碍物在非边缘位置
W(z+(j-1)*n(2)-1,z+j*n(2))=Inf;
W(z+j*n(2),z+(j-1)*n(2)-1)=Inf;
W(z+j*n(2),z+(j-1)*n(2)+1)=Inf;
W(z+(j-1)*n(2)+1,z+j*n(2))=Inf;
W(z+(j-1)*n(2)-1,z+(j-2)*n(2))=Inf;
W(z+(j-2)*n(2),z+(j-1)*n(2)-1)=Inf;
W(z+(j-2)*n(2),z+(j-1)*n(2)+1)=Inf;
W(z+(j-1)*n(2)+1,z+(j-2)*n(2))=Inf;
end
end
end
end
end