【免费】多无人机路径规划,三种灰狼优化算法实现不同障碍物航迹规划代码(matlab)

多无人机路径规划:三种灰狼优化算法实现不同障碍物航迹规划(matlab)
实现三种灰狼算法:1、GWO算法,2、MP-GWO算法,3、CS-GWO算法。
障碍物有三种:平面内圆形障碍物、三维空间圆柱、球形障碍物。完美中文注释,起点、终点均可修改,可二次开发。

获取方式:https://pan.quark.cn/s/25d4b1fd26ac


 获取方式:



https://pan.quark.cn/s/25d4b1fd26ac

  • 4
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的用于灰狼优化算法无人机路径规划的 Python 代码示例。该代码使用了 Pygame 和 Matplotlib 库来可视化路径和地图。地图中的障碍物为高度不同的圆柱体,且较多。 ```python import numpy as np import matplotlib.pyplot as plt import pygame # 灰狼优化算法实现 def gray_wolf_optimizer(cost_function, bounds, max_iterations, population_size): alpha, beta, delta = np.zeros((3, len(bounds))) alpha_score, beta_score, delta_score = float("inf"), float("inf"), float("inf") population = np.zeros((population_size, len(bounds))) for i in range(population_size): population[i] = np.random.uniform(bounds[:, 0], bounds[:, 1]) for iteration in range(max_iterations): for i in range(population_size): cost = cost_function(population[i]) if cost < alpha_score: delta_score = beta_score delta = beta.copy() beta_score = alpha_score beta = alpha.copy() alpha_score = cost alpha = population[i].copy() elif cost < beta_score: delta_score = beta_score delta = beta.copy() beta_score = cost beta = population[i].copy() elif cost < delta_score: delta_score = cost delta = population[i].copy() x1 = (alpha + beta) / 2 x2 = (alpha + delta) / 2 x3 = (beta + delta) / 2 population[0] = alpha population[1] = beta population[2] = delta for i in range(3, population_size): population[i] = np.random.uniform(bounds[:, 0], bounds[:, 1]) population[3] = x1 population[4] = x2 population[5] = x3 return alpha # 地图类 class Map: def __init__(self, width, height, num_obstacles): self.width = width self.height = height self.obstacles = np.zeros((num_obstacles, 4)) for i in range(num_obstacles): x = np.random.randint(0, width) y = np.random.randint(0, height) r = np.random.randint(20, 40) h = np.random.randint(10, 30) self.obstacles[i] = [x, y, r, h] # 判断某个点是否在障碍物内部 def is_point_in_obstacle(self, point): for obstacle in self.obstacles: x, y, r, h = obstacle if (point[0] - x)**2 + (point[1] - y)**2 <= r**2 and point[2] <= h: return True return False # 可视化地图和路径 def visualize(self, path=None): fig = plt.figure() ax = fig.add_subplot(111, projection="3d") ax.set_xlim([0, self.width]) ax.set_ylim([0, self.height]) ax.set_zlim([0, 50]) for obstacle in self.obstacles: x, y, r, h = obstacle u, v = np.mgrid[0:2*np.pi:20j, 0:h:10j] x += r*np.cos(u)*np.sin(v) y += r*np.sin(u)*np.sin(v) z = obstacle[3]*np.cos(v) ax.plot_surface(x, y, z, color="gray", alpha=0.5) if path is not None: path = np.array(path) ax.plot(path[:, 0], path[:, 1], path[:, 2], color="blue") ax.scatter(path[0, 0], path[0, 1], path[0, 2], color="green", s=50) ax.scatter(path[-1, 0], path[-1, 1], path[-1, 2], color="red", s=50) plt.show() # 无人机路径规划器类 class DronePathPlanner: def __init__(self, map, start, goal): self.map = map self.start = start self.goal = goal # 计算路径的代价函数 def cost_function(self, path): cost = 0 for i in range(len(path) - 1): cost += np.linalg.norm(path[i+1] - path[i]) return cost # 执行路径规划 def plan(self): bounds = np.array([[0, self.map.width], [0, self.map.height], [0, 50]]) max_iterations = 100 population_size = 20 result = gray_wolf_optimizer(self.cost_function, bounds, max_iterations, population_size) return result # 可视化路径和地图 def visualize(self, path): self.map.visualize(path) # 主函数 def main(): map = Map(500, 500, 20) planner = DronePathPlanner(map, np.array([50, 50, 0]), np.array([450, 450, 0])) path = planner.plan() planner.visualize(path) if __name__ == "__main__": main() ``` 在这个示例中,我们使用了一个 `Map` 类来表示地图,并在其中定义了一个用于判断某个点是否在障碍物内部的方法。我们还定义了一个 `DronePathPlanner` 类来执行无人机路径规划,并使用灰狼优化算法来搜索最优路径。最后,我们使用 Pygame 和 Matplotlib 库来可视化路径和地图。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值