% 初始化无人机数量和位置
num_drones = 4;
start_positions = [0, 0; 10, 0; 20, 0; 30, 0];
goal_positions = [40, 40; 30, 40; 20, 40; 10, 40];
% 参数设置
max_iter = 100; % 最大迭代次数
pop_size = 50; % 种群规模
c1 = 2; % 个体学习因子
c2 = 2; % 社会学习因子
w = 0.6; % 惯性权重
max_speed = 1; % 最大速度
min_speed = 0.1; % 最小速度
max_turn_angle = pi/4; % 最大转角
min_turn_angle = -pi/4; % 最小转角
% 初始化种群
positions = zeros(pop_size, num_drones, 2);
speeds = zeros(pop_size, num_drones, 2);
pbest_positions = positions;
gbest_position = zeros(1, num_drones, 2);
pbest_fitness = inf(1, pop_size);
gbest_fitness = inf;
% 初始化路径规划参数
path_cost_weight = 1;
height_cost_weight = 1;
threat_cost_weight = 1;
turn_cost_weight = 1;
% 开始迭代
for iter = 1:max_iter
% 更新速度和位置
for i = 1:pop_size
for j = 1:num_drones
% 计算个体学习项
pbest_diff = pbest_positions(i, j,