简体   繁体   English

具有障碍物和特定中途点的最短路径的寻路算法

[英]Pathing algorithm for shortest path with obstacles and specific mid-way points

I have a 12x12 grid represented by a 2-d array.我有一个由二维数组表示的 12x12 网格。

0 c b 0 0 0 c 0 b 0 b 0
0 c c c 0 0 c 0 c c c 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
a 0 0 0 0 0 0 0 0 0 0 d
0 0 0 0 0 0 c 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
c c c c c c 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 c 0 c 0 0 0 0 0 0 0

a = Starting point a = 起点

d = Ending point d = 终点

c = Obstacle c = 障碍物

b = Required point (still an obstacle) b = 所需点(仍然是一个障碍)

I need to write an algorithm that will return all the b points in the optimal order, such that I'm starting at the a tile, then need to move next to all b tiles taking into consideration you can't pass through 'b' or 'c' tiles, then finally ending at d .我需要编写一个算法,以最佳顺序返回所有 b 点,这样我就从a瓷砖开始,然后需要移动到所有b瓷砖旁边,考虑到您不能通过 'b'或 'c' 块,然后最终以d结束。

For the example given, I would want the return to be 3 points,对于给出的例子,我希望回报是 3 分,

[Point(0,2), Point(0,8), Point(0,10)]

As I know I want to start at a already and end at d I want to return the order to visit b 's most optimally.据我所知,我想从a开始并在d结束,我想返回以最佳方式访问b的订单。 Are there any libraries that can help with this?有没有图书馆可以帮助解决这个问题? If not, what type of algorithm am I looking to build?如果不是,我希望构建什么类型的算法? If anyone could recommend some reading or something to help get me started that would be much appreciated.如果有人可以推荐一些阅读或帮助我入门的东西,我将不胜感激。

Start by giving all open fields numbers.首先给所有开放字段编号。 all adjacent fields to a get 1, all adjacent fields to 1 get 2, etc. Note that you do this only for free field You do this until you have reached all nodes. a 的所有相邻字段都得到 1,1 的所有相邻字段都得到 2,等等。请注意,您只对自由字段执行此操作直到到达所有节点。 this becomes part of your path Graph.这成为你的路径图的一部分。

在此处输入图像描述

you repeat this numbering for all nodes.您为所有节点重复此编号。 so for B2 it will look like:所以对于 B2 它看起来像: 在此处输入图像描述 The above gives the following Graph:上面给出了以下图表:

在此处输入图像描述

Now you can use eg Dijksta's algorithm, to solve shortest path.现在您可以使用例如Dijksta 的算法来求解最短路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM