当前位置: 首页 > news >正文

深圳企业网站建设报价网上能注册公司吗怎么注册

深圳企业网站建设报价,网上能注册公司吗怎么注册,怎么免费建网站,vs2010 c 建设网站目录 0 本节关键词#xff1a;栅格地图、算法、路径规划 1 Dijkstra算法详解 2 Dijkstra代码详解 0 本节关键词#xff1a;栅格地图、算法、路径规划 1 Dijkstra算法详解 用于图中寻找最短路径。节点是地点#xff0c;边是权重。 从起点开始逐步扩展#xff0c;每一步为一…目录 0 本节关键词栅格地图、算法、路径规划 1 Dijkstra算法详解 2 Dijkstra代码详解 0 本节关键词栅格地图、算法、路径规划 1 Dijkstra算法详解 用于图中寻找最短路径。节点是地点边是权重。         从起点开始逐步扩展每一步为一个节点找到最短路径         While True:                 1.从未访问的节点选择距离最小的节点收录贪心思想                 2.收录节点后遍历该节点的邻接节点,更新距离         我们举例子说明一下在机器人路径规划中通常用open list、closed list表达         open list 表示从该节点到起点已经有路径的节点         closed list 表示已经找到最短路径的节点         Step1从起点开始将起点放入open list中选择距离最短的节点进行收录。 open list 1(0)(min) closed list| |open list closed list 1(0)         Step2遍历1号节点的邻接节点4、2号节点 open list 2(2)(1--2) 4(1)(1--4)(min) closed list 1(0)| |open list 2(2)(1--2) closed list 1(0) 4(1)(1--4)         4号节点收录后我们需要对其邻接节点更新距离。3、6、7号节点         Step33号节点我们找到1-4-3路径6号节点我们找到1-4-6路径7号节点我们找到1-4-7路径。 open list 2(2)(1--2)(min) 3(3)(1--4--3) 6(9)(1--4--6) 7(5)(1--4--7) closed list 1(0)| |open list 3(3)(1--4--3) 6(9)(1--4--6) 7(5)(1--4--7) closed list 1(0) 4(1)(1--4) 2(2)(1--2)         Step4遍历2的邻接节点我们发现4号节点已经在close list中不需要被更新我们更新5号节点。 open list 3(3)(1--4--3)(min) 6(9)(1--4--6) 7(5)(1--4--7) 5(13)(1-2--5) closed list 1(0)| |open list 6(9)(1--4--6) 7(5)(1--4--7) 5(13)(1-2--5) closed list 1(0) 4(1)(1--4) 2(2)(1--2) 3(3)(1--4--3)         Step5遍历3的邻接节点3--1无需更新更新3--6  1436(8) (因为我们有到3的最短距离),而我们已经为6号节点找到路径6(9)(146)更新6号节点的路径。 open list 6(9)(1--4--6)(1-4-3--6 7) 7(5)(1--4--7)(min) 5(13)(1-2--5) closed list 1(0) 4(1)(1--4) 2(2)(1--2) 3(3)(1--4--3)| |open list 6(8)(1-4-3--6) 5(13)(1-2--5) closed list 1(0) 4(1)(1--4) 2(2)(1--2) 3(3)(1--4--3) 7(5)(1--4--7)         Step6遍历7的邻接节点(6号节点)1 4 7 6 6比之前的8小对6号距离再次更新。 open list 6(8)(1-4-3--6)(1-4-7--6 6)(min) 5(13)(1-2--5) closed list 1(0) 4(1)(1--4) 2(2)(1--2) 3(3)(1--4--3) 7(5)(1--4--7) | |open list 5(13)(1-2--5) closed list 1(0) 4(1)(1--4) 2(2)(1--2) 3(3)(1--4--3) 7(5)(1--4--7) 6(6)(1--4--7--6)         Step7遍历6的邻接节点(6号节点)结束         栅格地图初介绍         假设图中灰色的是障碍物红色的是机器人。在避障时我们的常用做法是通过膨胀障碍物将机器人视为质点来规划路径然后对地图进行栅格化将地图弄成一块一块的。最后将栅格地图转化为有权地图。我们可以把栅格地图的每个栅格看作是有权图的节点机器人的运动范围可以看作是有权图的节点和节点之间的连接。 2 Dijkstra代码详解 这里我们先配置下代码环境最好是在python3.9下我们创建conda虚拟环境 conda create -n nav python3.9         安装所需库 pip install numpy scipy matplotlib pandas cvxpy pytest -i https://pypi.tuna.tsinghua.edu.cn/simple         我们的代码如下 Grid based Dijkstra planningauthor: Atsushi Sakai(Atsushi_twi)import matplotlib.pyplot as plt import mathshow_animation Trueclass Dijkstra:def __init__(self, ox, oy, resolution, robot_radius):Initialize map for planningox: x position list of Obstacles [m]oy: y position list of Obstacles [m]resolution: grid resolution [m]rr: robot radius[m]self.min_x Noneself.min_y Noneself.max_x Noneself.max_y Noneself.x_width Noneself.y_width Noneself.obstacle_map Noneself.resolution resolutionself.robot_radius robot_radiusself.calc_obstacle_map(ox, oy)self.motion self.get_motion_model()class Node:def __init__(self, x, y, cost, parent_index):self.x x # index of gridself.y y # index of gridself.cost cost # g(n)self.parent_index parent_index # index of previous Nodedef __str__(self):return str(self.x) , str(self.y) , str(self.cost) , str(self.parent_index)def planning(self, sx, sy, gx, gy):dijkstra path searchinput:s_x: start x position [m]s_y: start y position [m]gx: goal x position [m]gx: goal x position [m]output:rx: x position list of the final pathry: y position list of the final pathstart_node self.Node(self.calc_xy_index(sx, self.min_x),self.calc_xy_index(sy, self.min_y), 0.0, -1) # round((position - minp) / self.resolution)goal_node self.Node(self.calc_xy_index(gx, self.min_x),self.calc_xy_index(gy, self.min_y), 0.0, -1)open_set, closed_set dict(), dict() # key - value: hash表open_set[self.calc_index(start_node)] start_nodewhile 1:c_id min(open_set, keylambda o: open_set[o].cost) # 取cost最小的节点current open_set[c_id]# show graphif show_animation: # pragma: no coverplt.plot(self.calc_position(current.x, self.min_x),self.calc_position(current.y, self.min_y), xc)# for stopping simulation with the esc key.plt.gcf().canvas.mpl_connect(key_release_event,lambda event: [exit(0) if event.key escape else None])if len(closed_set.keys()) % 10 0:plt.pause(0.001)# 判断是否是终点if current.x goal_node.x and current.y goal_node.y:print(Find goal)goal_node.parent_index current.parent_indexgoal_node.cost current.costbreak# Remove the item from the open setdel open_set[c_id]# Add it to the closed setclosed_set[c_id] current# expand search grid based on motion modelfor move_x, move_y, move_cost in self.motion:node self.Node(current.x move_x,current.y move_y,current.cost move_cost, c_id)n_id self.calc_index(node)if n_id in closed_set:continueif not self.verify_node(node):continueif n_id not in open_set:open_set[n_id] node # Discover a new nodeelse:if open_set[n_id].cost node.cost:# This path is the best until now. record it!open_set[n_id] noderx, ry self.calc_final_path(goal_node, closed_set)return rx, rydef calc_final_path(self, goal_node, closed_set):# generate final courserx, ry [self.calc_position(goal_node.x, self.min_x)], [self.calc_position(goal_node.y, self.min_y)]parent_index goal_node.parent_indexwhile parent_index ! -1:n closed_set[parent_index]rx.append(self.calc_position(n.x, self.min_x))ry.append(self.calc_position(n.y, self.min_y))parent_index n.parent_indexreturn rx, rydef calc_position(self, index, minp):pos index * self.resolution minpreturn posdef calc_xy_index(self, position, minp):return round((position - minp) / self.resolution)def calc_index(self, node):return node.y * self.x_width node.xdef verify_node(self, node):px self.calc_position(node.x, self.min_x)py self.calc_position(node.y, self.min_y)if px self.min_x:return Falseif py self.min_y:return Falseif px self.max_x:return Falseif py self.max_y:return Falseif self.obstacle_map[node.x][node.y]:return Falsereturn Truedef calc_obstacle_map(self, ox, oy): 第1步构建栅格地图 self.min_x round(min(ox))self.min_y round(min(oy))self.max_x round(max(ox))self.max_y round(max(oy))print(min_x:, self.min_x)print(min_y:, self.min_y)print(max_x:, self.max_x)print(max_y:, self.max_y)self.x_width round((self.max_x - self.min_x) / self.resolution)self.y_width round((self.max_y - self.min_y) / self.resolution)print(x_width:, self.x_width)print(y_width:, self.y_width)# obstacle map generation# 初始化地图self.obstacle_map [[False for _ in range(self.y_width)]for _ in range(self.x_width)]# 设置障碍物for ix in range(self.x_width):x self.calc_position(ix, self.min_x)for iy in range(self.y_width):y self.calc_position(iy, self.min_y)for iox, ioy in zip(ox, oy):d math.hypot(iox - x, ioy - y)if d self.robot_radius:self.obstacle_map[ix][iy] Truebreakstaticmethoddef get_motion_model():# dx, dy, costmotion [[1, 0, 1],[0, 1, 1],[-1, 0, 1],[0, -1, 1],[-1, -1, math.sqrt(2)],[-1, 1, math.sqrt(2)],[1, -1, math.sqrt(2)],[1, 1, math.sqrt(2)]]return motiondef main():# start and goal positionsx -5.0 # [m]sy -5.0 # [m]gx 50.0 # [m]gy 50.0 # [m]grid_size 2.0 # [m]robot_radius 1.0 # [m]# set obstacle positionsox, oy [], []for i in range(-10, 60):ox.append(i)oy.append(-10.0)for i in range(-10, 60):ox.append(60.0)oy.append(i)for i in range(-10, 61):ox.append(i)oy.append(60.0)for i in range(-10, 61):ox.append(-10.0)oy.append(i)for i in range(-10, 40):ox.append(20.0)oy.append(i)for i in range(0, 40):ox.append(40.0)oy.append(60.0 - i)if show_animation: # pragma: no coverplt.plot(ox, oy, .k)plt.plot(sx, sy, og)plt.plot(gx, gy, xb)plt.grid(True)plt.axis(equal)dijkstra Dijkstra(ox, oy, grid_size, robot_radius)rx, ry dijkstra.planning(sx, sy, gx, gy)if show_animation: # pragma: no coverplt.plot(rx, ry, -r)plt.pause(0.01)plt.show()if __name__ __main__:main()         先执行一下看看效果         我们现在来详解一下         我们从main函数开始 # 1. 设置起点和终点sx -5.0 # [m]sy -5.0 # [m]gx 50.0 # [m]gy 50.0 # [m]# 2. 设置珊格的大小和机器人的半径grid_size 2.0 # [m]robot_radius 1.0 # [m]# 3. 设置障碍物的位置图中的黑点就是ox, oy [], []# 3.1 设置外围的四堵墙 (-10,-10) -- (60,-10) 最下面的一条线for i in range(-10, 60):ox.append(i)oy.append(-10.0)# 3.1 设置外围的四堵墙 (60,-10) -- (60,60) 最右面的一条线for i in range(-10, 60):ox.append(60.0)oy.append(i)# 3.1 设置外围的四堵墙 (-10,60) -- (61,60) 最上面的一条线for i in range(-10, 61):ox.append(i)oy.append(60.0)# 3.1 设置外围的四堵墙 (-10,-10) -- (-10,61) 最左面的一条线for i in range(-10, 61):ox.append(-10.0)oy.append(i)# 3.2 障碍物for i in range(-10, 40):ox.append(20.0)oy.append(i)for i in range(0, 40):ox.append(40.0)oy.append(60.0 - i)# 4 画图 起点、终点、障碍物都画出来if show_animation: # pragma: no coverplt.plot(ox, oy, .k)plt.plot(sx, sy, og)plt.plot(gx, gy, xb)plt.grid(True)plt.axis(equal)         这段代码就设置了边框和障碍物区域并把他们可视化了         就是我图中画的区域。 #生成了Dijkstra的对象 调用其中的方法障碍物信息、珊格大小、机器人半径dijkstra Dijkstra(ox, oy, grid_size, robot_radius)         生成了Dijkstra的对象。我们来看这个类的构造函数进入一个类首先执行构造函数 def __init__(self, ox, oy, resolution, robot_radius):Initialize map for planningox: x position list of Obstacles [m]oy: y position list of Obstacles [m]resolution: grid resolution [m]rr: robot radius[m]self.min_x Noneself.min_y Noneself.max_x Noneself.max_y Noneself.x_width Noneself.y_width Noneself.obstacle_map None# 珊格大小self.resolution resolution# 机器人半径self.robot_radius robot_radius# 构建珊格地图self.calc_obstacle_map(ox, oy)self.motion self.get_motion_model()         我们先来看是怎么创建珊格地图的 def calc_obstacle_map(self, ox, oy): 第1步构建栅格地图 # 1. 获得地图的边界值self.min_x round(min(ox))self.min_y round(min(oy))self.max_x round(max(ox))self.max_y round(max(oy))print(min_x:, self.min_x)print(min_y:, self.min_y)print(max_x:, self.max_x)print(max_y:, self.max_y)# 2.计算x、y方向珊格个数self.x_width round((self.max_x - self.min_x) / self.resolution)self.y_width round((self.max_y - self.min_y) / self.resolution)print(x_width:, self.x_width)print(y_width:, self.y_width)# obstacle map generation# 3.初始化地图 都设置为false 表示还没有设置障碍物self.obstacle_map [[False for _ in range(self.y_width)]for _ in range(self.x_width)]# 4.设置障碍物 遍历每一个栅格for ix in range(self.x_width):# 通过下标计算珊格位置x self.calc_position(ix, self.min_x)for iy in range(self.y_width):y self.calc_position(iy, self.min_y)# 遍历障碍物for iox, ioy in zip(ox, oy):# 计算障碍物到珊格的距离d math.hypot(iox - x, ioy - y)# 膨胀障碍物 如果距离比机器人半径小 机器人不能通行if d self.robot_radius:# 设置为trueself.obstacle_map[ix][iy] Truebreak         首先我们获得了地图的边界值算出了每一个方向上有多少珊格数量。         比如我们的长是100mself.max_x - self.min_x 100珊格大小为3那么我们每一行不就是有33个珊格啦。         我们初始化obstacle_map这个大小为珊格长 * 珊格宽的大小我们将他们初始化为false表示这个地方没有障碍物。         然后我们遍历每一个珊格for ix in range(self.x_width)、for iy in range(self.y_width)。我们来看看calc_position这个方法做了什么。 def calc_position(self, index, minp):pos index * self.resolution minpreturn pos         其实就计算了珊格所在位置的真实(x,y)坐标比如我们的self.minx 10ix 0那么他的pos 0 * 2 10 10比如我们的self.minx 10ix 1那么他的pos 1 * 2 10 12。我们遍历所有障碍物体的坐标计算障碍物体真实坐标与这个机器人的距离如果这个距离比机器人自身的大小小的话我们将这个地方的珊格标志置为false表示有东西。         那么在完成这个函数calc_obstacle_map时候我们有了一张珊格地图里面充斥着false和true如果为true的话那么机器人是过不去的这块也就是设置成了障碍物区域。         我们接着往下看构造函数 self.calc_obstacle_map(ox, oy)self.motion self.get_motion_model()          self.motion self.get_motion_model()这段代码建立了机器人的运动模型和运动代价 def get_motion_model():# dx, dy, costmotion [[1, 0, 1], #x增加1,y不变 代价为1[0, 1, 1],[-1, 0, 1],[0, -1, 1],[-1, -1, math.sqrt(2)],[-1, 1, math.sqrt(2)],[1, -1, math.sqrt(2)],[1, 1, math.sqrt(2)]]return motion         这里也就是机器人向左走(x1,y0)代价为1斜着走代价为根号2。到此为止我们构造函数讲解完了。我们返回主函数。 open_set         这里开始正式进入路径规划了。传入的参数为起点坐标和终点坐标 自动驾驶算法一Dijkstra算法讲解与代码实现         我们先看下node类。 class Node:def __init__(self, x, y, cost, parent_index):self.x x # index of gridself.y y # index of gridself.cost cost # g(n)self.parent_index parent_index # index of previous Nodedef __str__(self):return str(self.x) , str(self.y) , str(self.cost) , str(self.parent_index)         首先执行构造函数我们发现就是把珊格的(x,y)坐标并非真实坐标是珊格的还有cost后文说以及父节点的ID赋值了。so easy                 我们在看一下calc_xy_index函数 def calc_xy_index(self, position, minp):return round((position - minp) / self.resolution)         它就是计算出真实世界的点点属于哪一个珊格的某一维度的坐标我们举个例子 self.calc_xy_index(sx, self.min_x) sx 30 minx 20         这就代表我们的地图边界的 x 坐标为20这个点的坐标x30我们用30-20/2 5那么这个珊格坐标的x方向的坐标就是5。 start_node self.Node(self.calc_xy_index(sx, self.min_x),self.calc_xy_index(sy, self.min_y), 0.0, -1) # round((position - minp) / self.resolution)goal_node self.Node(self.calc_xy_index(gx, self.min_x),self.calc_xy_index(gy, self.min_y), 0.0, -1)         因此这段代码的含义就是我们计算出了起始和终止点的珊格坐标并且将代价置为0且他们的父节点为-1没有父亲节点。封装成了node。         下面进入算法部分我们看流程图         代码部分和流程图是一样的         1.首先我们把起点放入openlist中 # 设置openlist closelist 基于哈希表open_set, closed_set dict(), dict() # key - value: hash表# 将startnode放进openset里面 索引为一维数组open_set[self.calc_index(start_node)] start_node         看一下calc_index函数这里将珊格地图映射成了一个一维数组返回数组的ID类似C中的二维数组降维。这里openset是一个字典里面的key是珊格地图点的IDvalue是这个珊格节点。 def calc_index(self, node):return node.y * self.x_width node.x         2.while True进入循环 while 1:2.1 取openlist cost最小的节点作为当前节点 c_id min(open_set, keylambda o: open_set[o].cost)current open_set[c_id]         2.2.1 判断当前是否为终点如果是终点如果是终点的话把终点的cost修改为当前点的cost值且终点的父亲节点为当前点的父亲节点。 # 判断是否是终点if current.x goal_node.x and current.y goal_node.y:print(Find goal)# 当前节点的信息赋值给终点goal_node.parent_index current.parent_indexgoal_node.cost current.costbreak         2.2.2 不是最终节点的话从openlist删除加入到closelist # 把当前节点从openset里面删掉del open_set[c_id]# 加入到closed setclosed_set[c_id] current         2.3 遍历其9个邻接运动节点 for move_x, move_y, move_cost in self.motion:2.3.1 封装邻接节点 node self.Node(current.x move_x,current.y move_y,current.cost move_cost, c_id)         这个点到邻接节点的移动就是 x -( 1或-1或根号2或-根号2)然后移动上下的话它的代价值需要1斜着移动需要 根号2这样递归的进行我们就求出来所有点的代价值了同样这个新走的点是通过我们这个点走过来的因此新点的父节点就是我们这个点。         2.3.2 求当前节点的一维索引判断是否收录到closelist并判断是否可行如果收录了那么已经有最小路径了不需要我们再去处理了还需要判断这个节点是否在珊格地图标记为false点上珊格地图就是这么用的....如果这个地方有障碍物那么我们也走不了。 # 求当前节点的keyn_id self.calc_index(node)# 是否已经收录到close set里面if n_id in closed_set:continue# 邻接节点是否可行if not self.verify_node(node):continue         2.3.3 如果不在openset里面我们就将她作为一个新节点加入如果在openset比较值是否是最优更新是否和之前的最优路径有重叠。 if n_id not in open_set:open_set[n_id] node # Discover a new nodeelse:if open_set[n_id].cost node.cost:# This path is the best until now. record it!open_set[n_id] node         到这里我们的算法就结束了。我们迭代找到最终点后算法就break掉了。         最后我们计算路径 def calc_final_path(self, goal_node, closed_set):# generate final courserx, ry [self.calc_position(goal_node.x, self.min_x)], [self.calc_position(goal_node.y, self.min_y)]parent_index goal_node.parent_indexwhile parent_index ! -1:n closed_set[parent_index]rx.append(self.calc_position(n.x, self.min_x))ry.append(self.calc_position(n.y, self.min_y))parent_index n.parent_indexreturn rx, ry         我们将最终节点的珊格坐标还原成真实的三维坐标并向前找他们的父亲节点直到起始节点parent_index -1我们就出来这个路径了。
http://www.hkea.cn/news/14278723/

相关文章:

  • 做百科的网站注销公司需要多少钱
  • 网站开发 方案 报价单wap网站是什么意思啊
  • 成都网站seo性价比高wordpress网站域名服务器
  • 网站绑定域名建设银行官方网站打不开
  • 网站建设课程设计报告wordpress要装iis吗
  • 景观做文本常用的网站部门网站建设的工作领导小组
  • 伦教九江网站建设免费创建网站的软件
  • 本机可以做网站的服务器吗外贸网站建设智能建站
  • 关于公路建设的网站网站瀑布流怎么做
  • 玉溪网站制作高中制作网站怎么做
  • 外国人做的汉字网站wordpress会员等级下载
  • 织梦摄影网站源码网站开发销售话术
  • 物流网站建设平台分析公司的网站是什么
  • 网站建设必须买数据库么表白网站制作在线
  • 舟山市建设信息港网站打不开多层次网络营销合法吗
  • 系统管理软件下载大连网站推广优化
  • 提供网站建设定制建立中英文网站
  • 江西吉安建设监督网站可以做视频片头的网站
  • 外贸网站设计与推广贵州省建设厅考试网站
  • vshtml5网站开发个人网站源码进一品资源
  • 腾讯做网站上传自动做效果图的网站
  • 网站开发能进入无形资产吗济南网站建设搜q.479185700
  • 心雨在线高端网站建设创新seo是什么的缩写
  • 比利时网站后缀免费wordpress模板下载地址
  • 开发网站的技术风险工控人如何做自己的网站
  • 温州网站建设温州优质网站建设是哪家
  • 备案个人可以做视频网站代理公司注册品牌
  • 杭州做产地证去哪个网站电子商务项目策划书范文
  • 邯郸移动网站建设泰安网络推广培训
  • 搭建网站多少钱crm管理平台