特定环境下基于改进群智能算法的无人机三维航迹规划【附代码】
✨ 本团队擅长数据搜集与处理、建模仿真、程序设计、仿真代码、EI、SCI写作与指导毕业论文、期刊论文经验交流。✅ 专业定制毕设、代码✅如需沟通交流查看文章底部二维码1风雨环境与复杂地形约束下的麻雀搜索算法航迹规划针对特定环境风雨气候和山区地形中无人机航迹规划问题建立了综合考虑无人机自身约束、风雨影响和地形威胁的综合目标函数。目标函数包括燃料代价、障碍物碰撞代价、风雨能量损耗代价和飞行高度平滑代价。风速模型采用指数风廓线风向对地速的影响通过矢量合成计算。在数字高程模型上构建三维寻优空间网格分辨率25米。麻雀搜索算法的发现者-加入者比例设为2:8预警阈值0.6。在太行山区某区域20kmx20km规划从起点到终点的航迹标准SSA规划耗时23秒生成航迹长度78.6km改进SSA加入Levy飞行将耗时降到17秒航迹长度76.2km且穿过高风险区的概率从12%降到4%。2混沌映射和精英反向学习的改进麻雀搜索算法针对标准麻雀搜索算法收敛速度慢、易陷入局部最优的问题提出了融合Tent-Bernoulli混合混沌映射、Levy飞行、柯西变异和精英反向学习的改进SSA。初始化种群时采用Tent映射和Bernoulli映射的加权平均生成混沌序列提高初始解的遍历性。在发现者位置更新后以一定概率随迭代次数递减执行Levy飞行步长服从重尾分布帮助跳出局部极值。对于全局最优个体采用柯西变异扰动扰动幅度自适应。最后引入精英反向学习策略生成当前精英种群的反向解并择优保留。利用CEC2017测试函数中20维的单峰和多峰函数进行验证改进SSA在Sphere函数上的最优值达到1.2e-12而标准SSA为3.4e-8收敛速度加快约47%。在航迹规划应用中改进算法的成功率找到可行航迹达到96.5%比标准SSA高出14%。3改进灰狼算法在灾害救援环境中的应用为了进一步增强特定环境的复杂性采用SRTM3高精度数字高程数据构建地震灾害后的山区救援场景。道路损毁、滑坡区域标记为禁飞区。提出一种在线调节步长的改进灰狼算法步长调节因子根据狼群聚集度动态变化聚集度低时加大步长增强探索聚集度高时减小步长精细搜索。同时将精英反向学习融入灰狼位置更新中。在灾害场景中规划无人机最短救援路径标准灰狼算法需要135代收敛到7480米改进算法在92代收敛到7220米路径长度缩短3.5%同时满足避开所有禁飞区的约束。在Matlab仿真平台进行了20次独立重复实验改进算法的鲁棒性标准差为125而标准算法为312。import numpy as np from scipy.interpolate import interp1d # 数字高程模型 (DEM) 模拟 class DEM: def __init__(self, resolution25): self.res resolution self.height np.random.rand(200,200) * 500 # 随机地形 def get_height(self, x, y): ix, iy int(x/self.res), int(y/self.res) if 0ix200 and 0iy200: return self.height[ix,iy] return 500 # 改进麻雀搜索算法 (带混沌和Levy) class ImprovedSSA: def __init__(self, n_sparrows50, max_iter200, safe_th0.6, n_d10, n_w5): self.n n_sparrows; self.max_iter max_iter; self.safe_th safe_th self.n_d n_d; self.n_w n_w def chaotic_init(self, dim, bounds): # Tent-Bernoulli混合混沌 tent np.random.rand(dim) bernoulli np.random.rand(dim) cha 0.6*tent 0.4*bernoulli return bounds[0] cha * (bounds[1]-bounds[0]) def levy_flight(self, step_size, beta1.5): sigma (np.math.gamma(1beta)*np.sin(np.pi*beta/2) / (np.math.gamma((1beta)/2)*beta*2**((beta-1)/2)))**(1/beta) u np.random.randn()*sigma; v np.random.randn() step step_size * u / (abs(v)**(1/beta)) return step def optimize(self, fitness_func, dim, bounds): pop np.array([self.chaotic_init(dim, bounds) for _ in range(self.n)]) fitness np.array([fitness_func(p) for p in pop]) best_idx np.argmin(fitness); best_x pop[best_idx].copy(); best_f fitness[best_idx] worst_f np.max(fitness) for t in range(self.max_iter): R2 np.random.rand() # 发现者 for i in range(self.n_d): if R2 self.safe_th: pop[i] pop[i] * np.exp(-i / (np.random.rand() * self.max_iter)) else: pop[i] pop[i] np.random.randn(dim) * self.levy_flight(0.1) # 加入者 for i in range(self.n_d, self.n): if i self.n/2: pop[i] np.random.randn(dim) * np.exp((pop[self.n_d-1] - pop[i]) / (np.random.rand()**2)) else: pop[i] pop[self.n_d-1] np.abs(pop[i] - pop[self.n_d-1]) np.random.randn(dim) # 预警者 for i in range(self.n_w): idx np.random.randint(0, self.n) if fitness[idx] best_f: pop[idx] best_x np.random.randn(dim) * np.abs(pop[idx] - best_x) else: pop[idx] pop[idx] np.random.randn(dim) * (np.abs(pop[idx] - worst_f) / (fitness[idx] - worst_f 1e-8)) # 精英反向学习 elite_num 5 elite_idx np.argsort(fitness)[:elite_num] for idx in elite_idx: opp bounds[0] bounds[1] - pop[idx] # 反向解 if fitness_func(opp) fitness[idx]: pop[idx] opp # 边界处理 pop np.clip(pop, bounds[0], bounds[1]) # 适应度更新 for i in range(self.n): f fitness_func(pop[i]) if f fitness[i]: fitness[i] f if f best_f: best_f f; best_x pop[i].copy() worst_f np.max(fitness) if t % 20 0: print(fIter {t}: Best {best_f:.2f}) return best_x, best_f # 航迹规划适应度函数 def path_fitness(path_points, dem, wind_speed8.0): # path_points: N x 3 (x,y,z) total_cost 0.0 for i in range(len(path_points)-1): p1, p2 path_points[i], path_points[i1] # 长度代价 dist np.linalg.norm(p2 - p1) total_cost dist # 地形跟随代价 (低于地面) ground_h dem.get_height(p1[0], p1[1]) if p1[2] ground_h 5: total_cost 500 # 惩罚 # 风雨能量损耗 () total_cost dist * (wind_speed / 10.0) * 0.1 return total_cost # 改进灰狼算法步长自适应 class AdaptiveGWO: def __init__(self, n_wolves20, max_iter100): self.n n_wolves; self.max_iter max_iter def optimize(self, fitness_func, dim, bounds): positions np.random.uniform(bounds[0], bounds[1], (self.n, dim)) fitness np.array([fitness_func(p) for p in positions]) alpha positions[np.argmin(fitness)] beta positions[np.argsort(fitness)[1]] delta positions[np.argsort(fitness)[2]] for t in range(self.max_iter): a 2 - 2*t/self.max_iter # 线性衰减 # 自适应步长调节因子 convergence np.std(fitness) / (np.mean(fitness)1e-8) step_factor 0.5 if convergence 0.1 else 1.0 for i in range(self.n): r1, r2 np.random.rand(dim), np.random.rand(dim) A1 2*a*r1 - a; C1 2*r2 D_alpha abs(C1 * alpha - positions[i]) X1 alpha - A1 * D_alpha r1, r2 np.random.rand(dim), np.random.rand(dim) A2 2*a*r1 - a; C2 2*r2 D_beta abs(C2 * beta - positions[i]) X2 beta - A2 * D_beta r1, r2 np.random.rand(dim), np.random.rand(dim) A3 2*a*r1 - a; C3 2*r2 D_delta abs(C3 * delta - positions[i]) X3 delta - A3 * D_delta new_pos (X1 X2 X3)/3 # 自适应步长 new_pos positions[i] step_factor * (new_pos - positions[i]) new_pos np.clip(new_pos, bounds[0], bounds[1]) if fitness_func(new_pos) fitness[i]: positions[i] new_pos # 更新适应度 for i in range(self.n): fitness[i] fitness_func(positions[i]) alpha positions[np.argmin(fitness)] beta positions[np.argsort(fitness)[1]] delta positions[np.argsort(fitness)[2]] return alpha, fitness.min()如有问题可以直接沟通