Multi-unit pathfinding algorithm for finding the optimal solution

Source: Internet
Author: User

A * algorithm can be used for pathfinding of a single unit. However, in practical applications, multiple units are often moved at the same time, and they will affect each other and hinder the movement of each other. So once the conflict, the path calculated for each unit will be invalidated.

A popular solution is to recalculate the path when a conflict is found. There are regular recalculation and so on. These are dynamic adjustment schemes, and the resulting paths are not optimal. Although these suboptimal solutions can meet the needs of most scenarios, is there a way to calculate the optimal solution? After all, many dynamically tuned algorithms have the potential to fail.

We can list the possible movements of each unit in a minimum time unit (round) as a node, put it into the search tree, and then search with a A * algorithm. However, in a grid map, a unit can have a maximum of 5 or 9 (with a slash) of different moving methods, including static. 2 units will have a 5x5 or 9x9 combination. As the number of units to be considered increases, the number of combinations explodes. At this point we can split a turn into a series of individual units of movement, the individual movement as a node. In this way, if some conditions are found not satisfied, such as two units have conflict, you can close the current node, do not continue to generate a combination, so that the search tree pruning. Since the movement of all units in a round does not have a priority, and we are dealing with a unit one unit at a time, so the unit that is processed first does not need to check and the rear unit conflict, only the rear unit needs to check and the front unit conflict. Of course, in order to successfully prune, prioritize which units are also worth considering. Can be sorted by some priority, such as the closer to the target can be prioritized.

For example, suppose a 2x2 map with two units A at coordinates 1, 0, b at coordinates 0, 1, want to move to coordinates 1, 1. Then we will generate the node in the order of processing B after processing a first. Assume that [] represents a scheduled move list, and {} represents an unplanned list of units. Then the search tree can be represented as follows:

[]{A10,B01}//Initial state

/ \ \

[A Down]{b01} [A does not move] {B01}       not expanded [A left] {B01} not expanded

/                     | \

[a downward B to the right] {} conflict, pruning [a Down B fixed]{} [a Down B up]{} not expanded

|

[]{a11,b01}     - []{b01} Round 1 ends, settlement position, a arrives at the destination, is removed, and then the next round.

/                   \                     \

[b right]{} [B does not move] {} not expanded [b up]{} not expanded

|

[]{} Round 2 ends, settlement position, B arrives at destination, is removed. The list is empty and the target status is reached.

Another optimization is that although we can generate all the moving methods of a unit, we are not in a hurry to put all of the moves as nodes into the open list, and only select one or two of the most likely to succeed. The current node does not close, and maintains a list of which moves have been expanded. This can effectively reduce the number of nodes in the open list. Assuming that <> is an unfolded move, the above example can be represented as follows:

[]{A10,B01}//Initial status --[]<a not moving, a left >{}

/

[a downward]{b01} [A Down]<b up >{}

/                     |       

[a downward B to the right] {} conflict, pruning [a Down B fixed]{}

|

[]{a11,b01}      - []{b01} , []<b, B up > Turn 1 end, settlement position, a arrives at the destination, is removed, and then the next round.

       |

[b right]{}

|

[]{} Round 2 ends, settlement position, B arrives at destination, is removed. The list is empty and the target status is reached.

As for the heuristic function of a * search, we can certainly find the Manhattan distance, diagonal distance, or duclidean distance for each unit, and then sum as the heuristic value for each node. Better heuristic values can be obtained using the rra* (Reverse resumable A *) algorithm. An ordinary A * search is performed on the target point to the current point to obtain the actual distance (regardless of the obstacle of the moving unit). This distance is much more accurate than the previously mentioned estimation algorithm. The open list generated by the rra* search can be reused, which is actually not very expensive. Of course for multiple target points, we need to maintain the respective open list.

Specific implementations can refer to examples in github.com/silmerusse/fudge_pathfinding. For relatively simple maps and fewer units, the optimal solution can be quickly calculated. But for maps with high complexity and more units, it takes more time and memory space.

Multi-unit pathfinding algorithm for finding the optimal solution

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.