t1_maze_branching
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
t1_maze_branching [2024/06/07 12:17] – [Methodology] fpalustre | t1_maze_branching [2024/06/07 12:31] (current) – fpalustre | ||
---|---|---|---|
Line 129: | Line 129: | ||
END FUNCTION | END FUNCTION | ||
</ | </ | ||
- | ==== Path Accumulator ==== | + | ==== Path Accumulator |
<code c++> | <code c++> | ||
FUNCTION pathAccumulation(change, | FUNCTION pathAccumulation(change, | ||
Line 217: | Line 217: | ||
| | ||
| | ||
+ | | ||
+ | END FUNCTION | ||
+ | </ | ||
+ | ==== Path Accumulator (Python) ==== | ||
+ | <code python> | ||
+ | FUNCTION pathAccumulation(graph, | ||
+ | | ||
+ | | ||
+ | |||
+ | SET furthestNode TO farthestNode(graph, | ||
+ | SET primaryPath TO BFS(graph, startingNode, | ||
+ | |||
+ | | ||
+ | stack <- deque #best to use the deque module from collections | ||
+ | |||
+ | FOR EACH node IN primaryPath | ||
+ | ADD node TO finalPath | ||
+ | ADD node TO stack | ||
+ | | ||
+ | WHILE stack IS NOT EMPTY | ||
+ | | ||
+ | SET currNode TO last index of stack | ||
+ | |||
+ | added <- bool | ||
+ | SET added TO FALSE | ||
+ | |||
+ | FOR EACH adjNode IN graph[currNode] | ||
+ | IF adjNode NOT IN primaryPath AND removedNodes AND finalPath AND stack | ||
+ | ADD neighbor TO stack | ||
+ | SET added TO TRUE | ||
+ | | ||
+ | IF added IS FALSE | ||
+ | | ||
+ | |||
+ | IF stack IS NOT EMPTY | ||
+ | branchPath <- List | ||
+ | SET branchPath to BFS(graph, currNode, stack[-1], removedNodes) | ||
+ | SET AND ADD branchPath TO finalPath | ||
+ | | ||
+ | IF finalPath[-1] DOES NOT EQUAL TO node | ||
+ | | ||
+ | SET branchPath to BFS(graph, finalPath[-1], | ||
+ | SET AND ADD branchPath TO finalPath | ||
+ | | ||
+ | | ||
| | ||
END FUNCTION | END FUNCTION | ||
</ | </ | ||
===== MATLAB Result ===== | ===== MATLAB Result ===== | ||
- | Once the code has been made, the output would be the desired path of your maze. To visually see it, the following is a MATLAB implementation of this maze-branching algorithm. | + | Once the code has been made, the output would be the desired path of your maze. To visually see it, the following is a MATLAB implementation of the queue version of the maze-branching algorithm. |
* Green: Start Node | * Green: Start Node | ||
* Red: End Node | * Red: End Node |
t1_maze_branching.txt · Last modified: 2024/06/07 12:31 by fpalustre