Mobile robot motion planning --- basic knowledge based on graph search --- breadth-first traversal and depth-first traversal
The direction of graph search optimization is :
according to what rules to visit nodes, according to what rules to pop up nodes, so that we can find the termination node as quickly as possible.
Graph traversal algorithm:
- breadth first search
- depth-first search
Breadth-first search follows the first-in-first-out principle and maintains a queue.
Pop elements are always popped from the head of the queue.
Depth-first search follows the last-in-first-out principle. It maintains a stack
pop from the top, and finally Those that enter the container are the first to be ejected
Breadth First Search (BFS)
Features: Each time the shallowest node is popped up, a queue structure is maintained,
so the search process is carried out layer by layer.
The most intuitive understanding is to proceed layer by layer.
Splitting of BFS steps :
such a graph structure, the steps of BFS are as follows
The initialization container is empty, first put the start node S
and pop up (visit) the S node, and the container becomes empty again.
Expand S,
as can be seen from the figure, S can be expanded by d\e\
p According to the defined rules, the expanded nodes are put into the container in a regular order. The
difference from DFS is that the nodes are popped up from below, the p node is popped up first,
and then the loop is performed
. Finally, the terminal node is found, the loop is ended, and the graph search is completed.
Depth First Search (DFS)
Features: The node that is popped up each time is the deepest node, and a stack is maintained. The
intuitive understanding is that a branch is never taken to the end
Splitting of DFS steps:
Note—the structure of a stack is maintained,
such a graph structure, and the steps of DFS are as follows
The initialization container is empty, first put the start node S
and pop up (visit) the S node, and the container becomes empty again.
Expand S,
as can be seen from the figure, S can be expanded by d\e\
p According to the defined rules, the expanded nodes are put into the container in a regular order,
and then the depth-first search pops up the container, and the last-entered node (the deepest level), that is, the d node,
then expands the d node, and puts the expanded node into The container, and then pop up the popped node, then expand, and then put in the loop operation
Finally find the terminal node, end the loop, and complete the graph search.
BFS vs DFS
From the final traversal result graph, you can see the difference between the two
- BFS expands from the start node layer by layer until it reaches the target node, and then backtracks to find the shortest path.
- DFS goes all the way from the start node to the end to find the target node.
From the results, the path found by BFS is the shortest
Therefore, for mobile robots, when doing path planning to find the shortest path, the best way to do it is BFS