-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathBoundAdjust.m
58 lines (49 loc) · 1.76 KB
/
BoundAdjust.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
function [WolfPops, Tracks] = BoundAdjust(WolfPops, ProbPoints, UAV)
%BOUNDADJUST 约束处理
Tracks = Pops2Tracks(WolfPops, UAV);
% ① 不满足约束:"删除"航迹点,即取前后平均值
dim = UAV.PointDim; % 维度
for agent = 1 : size(WolfPops.Pos, 1)
Track = Tracks{agent}; % 轨迹 (struct结构)
ProbPoint = ProbPoints{agent}; % 问题点
Position = []; % 新狼群编码
for i =1:UAV.num
PointNum = UAV.PointNum(i);
% 删除一条航迹上的问题点
for k = 1 : PointNum
flag = ProbPoint{i}(k);
if flag == 1
if k == 1
P1 = UAV.S(i, :)' ;
else
P1 = Track.P{i}(:, k-1);
end
if k == PointNum
P2 = UAV.G(i, :)' ;
else
P2 = Track.P{i}(:, k+1);
end
Track.P{i}(:, k) = (P1+P2) / 2; % 删除航迹点
end
end
% 转换为狼群编码形式
p = Track.P{i} ;
p = reshape(p, 1, dim*PointNum);
Position = [Position, p];
end
V = Track.V';
Position = [Position, V];
% 新的位置信息
WolfPops.Pos(agent, :) = Position;
end
% ② 边界处理:越界取边界值
WolfPops.Pos = BoundClamp(WolfPops.Pos, WolfPops.lb, WolfPops.ub);
% 生成新航迹
Tracks = Pops2Tracks(WolfPops, UAV);
end
% 边界裁剪
function x = BoundClamp(x, lb, ub)
Flag4ub = x > ub;
Flag4lb = x < lb;
x = x .* ( ~(Flag4ub + Flag4lb) ) + ub .* Flag4ub + lb .* Flag4lb;
end