Content deleted Content added
Jonathan Pledge is the correct name of the Exeter schoolboy |
|||
(78 intermediate revisions by 53 users not shown) | |||
Line 1:
{{Short description|Automated method for solving mazes}}
[[File:Cyclope robot.jpg|thumb|right|Robot in a wooden maze]]
Mazes containing no loops are known as "simply connected", or "perfect" mazes, and are equivalent to a [[Tree (graph theory)|''tree'']] in graph theory.
== Random mouse algorithm
This
== Hand On Wall
[[File:maze01-02.
▲The wall follower, the best-known rule for traversing mazes, is also known as either the ''left-hand rule'' or the ''right-hand rule''. If the maze is [[Simply connected space|''simply connected'']], that is, all its walls are connected together or to the maze's outer boundary, then by keeping one hand in contact with one wall of the maze the solver is guaranteed not to get lost and will reach a different exit if there is one; otherwise, he or she will return to the entrance having traversed every corridor next to that connected section of walls at least once.
Another perspective into why wall following works is topological. If the walls are connected, then they may be deformed into a loop or circle.<ref>{{
If the maze is not simply-connected (i.e. if the start or endpoints are in the center of the structure surrounded by passage loops, or the pathways cross over and under each other and such parts of the solution path are surrounded by passage loops), this method will not necessarily reach the goal.
Another concern is that care should be taken to begin wall-following at the entrance to the maze. If the maze is not simply-connected and one begins wall-following at an arbitrary point inside the maze, one could find themselves trapped along a separate wall that loops around on itself and containing no entrances or exits. Should it be the case that wall-following begins late, attempt to mark the position in which wall-following began. Because wall-following will always lead you back to where you started, if you come across your starting point a second time, you can conclude the maze is not simply-connected, and you should switch to an alternative wall not yet followed. See the ''Pledge Algorithm'', below, for an alternative methodology.
Wall-following can be done in 3D or higher-dimensional mazes if its higher-dimensional passages can be projected onto the 2D plane in a deterministic manner. For example, if in a 3D maze "up" passages can be assumed to lead
A simulation of this algorithm working can be found [https://scratch.mit.edu/projects/1049044916/ here].
== Pledge algorithm ==
[[File:Pledge Algorithm.png|left|thumb| Left: Left-turn solver trapped <br /> Right: Pledge algorithm solution]]
Disjoint
The Pledge algorithm, designed to circumvent obstacles, requires an arbitrarily chosen direction to go toward, which will be preferential. When an obstacle is met, one hand (say the right hand) is kept along the obstacle while the angles turned are counted (clockwise
The hand is removed from the wall only when both "sum of turns made" and "current heading" are at zero. This allows the algorithm to avoid traps shaped like an upper case letter "G". Assuming the algorithm turns left at the first wall, one gets turned around a full 360 [[degree (angle)|degree]]s by the walls. An algorithm that only keeps track of "current heading" leads into an infinite loop as it leaves the lower rightmost wall heading left and runs into the curved section on the left hand side again. The Pledge algorithm does not leave the rightmost wall due to the "sum of turns made" not being zero at that point (note 360 [[degree (angle)|degree]]s is not equal to 0 [[degree (angle)|degree]]s). It follows the wall all the way around, finally leaving it heading left outside and just underneath the letter shape.
Line 32 ⟶ 33:
== Trémaux's algorithm ==
[[File:Tremaux Maze Solving Algorithm.gif|thumb|
Trémaux's algorithm, invented by [[Charles Pierre Trémaux]],<ref>Public conference, December 2, 2010 – by professor Jean Pelletier-Thibert in Academie de Macon (Burgundy – France) – (Abstract published in the Annals academic, March 2011 – {{ISSN|0980-6032}}) <br/>Charles Tremaux (° 1859 – † 1882) Ecole Polytechnique of Paris (X:1876), French engineer of the telegraph</ref> is an efficient method to find the way out of a maze that requires drawing lines on the floor to mark a path, and is guaranteed to work for all mazes that have well-defined passages
A path from a junction is either unvisited, marked once or marked twice. The algorithm works according to the following rules:▼
An entrance of a passage is either unvisited, marked once or marked twice. Note that marking an entrance is not the same as marking a junction or a passage, because a junction may have multiple entrances, and a passage has an entrance at both ends. Dead ends can be thought of as junctions with one entrance (imagine there being a room at each dead end).
▲
* Whenever you pass through an entrance of a passage, whether it is to enter or exit a junction, leave a mark at the entrance as you pass.
* When you are at a junction, use the first applicable rule below to pick an entrance to exit through:
*# If only the entrance you just came from is marked, pick an arbitrary unmarked entrance, if any. This rule also applies if you're just starting in the middle of the maze and there are no marked entrances at all.
*# If all entrances are marked, go back through the entrance you just came from, unless it is marked twice. This rule will apply whenever you reach a dead end.
When you finally reach the solution, paths marked exactly once will indicate a way back to the start. If there is no exit, this method will take you back to the start where all paths are marked twice.▼
*# Pick any entrance with the fewest marks (zero if possible, else one).
In this case each path is walked down exactly twice, once in each direction. The resulting [[Glossary of graph theory#Walks|walk]] is called a bidirectional double-tracing.<ref name="Eulerian Graphs and related Topics">H. Fleischner: ''Eulerian Graphs and related Topics.'' In: ''Annals of Discrete Mathematics'' No. 50 Part 1 Volume 2, 1991, page X20.</ref>▼
The "turn around and return" rule effectively transforms any maze with loops into a simply connected one; whenever we find a path that would close a loop, we treat it as a dead end and return. Without this rule, it is possible to cut off one's access to still-unexplored parts of a maze if, instead of turning back, we arbitrarily pick another entrance.
▲When you finally reach the solution,
▲In this case each
Essentially, this algorithm, which was discovered in the 19th century, has been used about a hundred years later as [[depth-first search]].<ref>{{citation|title=Graph Algorithms|first=Shimon|last=Even|authorlink=Shimon Even|edition=2nd|publisher=Cambridge University Press|year=2011|isbn=978-0-521-73653-4|pages=46–48|url=https://books.google.com/books?id=m3QTSMYm5rkC&pg=PA46}}.</ref><ref>{{citation|title=Algorithms in C++: Graph Algorithms|first=Robert|last=Sedgewick|edition=3rd|publisher=Pearson Education|year=2002|isbn=978-0-201-36118-6}}.</ref>
== Dead-end filling ==
{{External media
Dead-end filling is an algorithm for solving mazes that fills all dead ends, leaving only the correct ways unfilled. It can be used for solving mazes on paper or with a computer program, but it is not useful to a person inside an unknown maze since this method looks at the entire maze at once. The method is to 1) find all of the dead-ends in the maze, and then 2) "fill in" the path from each dead-end until the first junction is met. Note that some passages won't become parts of dead end passages until other dead ends are removed first. A video of dead-end filling in action can be seen here: [https://www.youtube.com/watch?v=yqZDYcpCGAI][https://www.youtube.com/watch?v=FkueaIT6RSU].▼
|video1=[https://www.youtube.com/watch?v=yqZDYcpCGAI Maze Strategy: Dead End Filling]
|video2=[https://www.youtube.com/watch?v=FkueaIT6RSU Maze Solving algorithm]
}}
▲Dead-end filling is an algorithm for solving mazes that fills all dead ends, leaving only the correct ways unfilled. It can be used for solving mazes on paper or with a computer program, but it is not useful to a person inside an unknown maze since this method looks at the entire maze at once. The method is to
Dead-end filling cannot accidentally "cut off" the start from the finish since each step of the process preserves the topology of the maze. Furthermore, the process won't stop "too soon" since the end result cannot contain any dead-ends. Thus if dead-end filling is done on a perfect maze (maze with no loops), then only the solution will remain. If it is done on a partially braid maze (maze with some loops), then every possible solution will remain but nothing more. [http://www.astrolog.org/labyrnth/algrithm.htm]▼
# find all of the dead-ends in the maze, and then
# "fill in" the path from each dead-end until the first junction is met.
Note that some passages won't become parts of dead end passages until other dead ends are removed first. A video of dead-end filling in action can be seen to the right.
▲Dead-end filling cannot accidentally "cut off" the start from the finish since each step of the process preserves the topology of the maze. Furthermore, the process won't stop "too soon" since the
== Recursive algorithm ==
If given an omniscient view of the maze, a simple recursive algorithm can tell one how to get to the end. The algorithm will be given a starting X and Y value. If the X and Y values are not on a wall, the method will call itself with all adjacent X and Y values, making sure that it did not already use those X and Y values before. If the X and Y values are those of the end ___location, it will save all the previous instances of the method as the correct path.
<source lang="java">▼
This is in effect a depth-first search expressed in term of grid points. The omniscient view prevents entering loops by memorization. Here is a sample code in [[Java (programming language)|Java]]:
int[][] maze = new int[width][height]; // The maze▼
boolean[][] wasHere = new boolean[width][height];
boolean[][] correctPath = new boolean[width][height]; // The solution to the maze
Line 61 ⟶ 77:
public void solveMaze() {
maze = generateMaze(); // Create Maze (
// Below assignment to false is redundant as Java assigns array elements to false by default, but it is included because other languages may not behave the same.
for (int row = 0; row < maze.length; row++)
// Sets boolean Arrays to default values
Line 75 ⟶ 93:
public boolean recursiveSolve(int x, int y) {
if (x == endX && y == endY) return true; // If you reached the end
if (maze[x][y]
// If you are on a wall or already were here
wasHere[x][y] = true;
Line 100 ⟶ 118:
return false;
}
</syntaxhighlight>
== Maze-routing algorithm ==
The maze-routing algorithm <ref>{{cite
Maze-routing algorithm uses the notion of [[Manhattan distance]] (MD) and relies on the property of grids that the MD increments/decrements ''exactly'' by 1 when moving from one ___location to any 4 neighboring locations. Here is the pseudocode without the capability to detect unreachable locations.
<
Point src, dst;// Source and destination coordinates
// cur also indicates the coordinates of the current ___location
int MD_best = MD(src, dst);// It stores the closest MD we ever had to dst
// A productive path is the one that makes our MD to dst smaller
while (cur != dst) {
if (there exists a productive path) {
Take the productive path;
} else {
MD_best = MD(cur, dst);
Imagine a line between cur and dst;
Take the first path in the left/right of the line; // The left/right selection affects the following hand rule
while (MD(cur, dst) != MD_best || there does not exist a productive path) {
Follow the right-hand/left-hand rule; // The opposite of the selected side of the line
}
}
</syntaxhighlight>
== Shortest path algorithm ==
{{Further|Pathfinding#Algorithms}}
[[File:MAZE 40x20 DFS no deadends.png|thumb|A maze with many solutions and no dead-ends, where it may be useful to find the shortest path]]
When a maze has multiple solutions, the solver may want to find the shortest path from start to finish. There are several algorithms to find shortest paths, most of them coming from [[graph theory]]. One
== Multi-agent maze-solving ==
Collective exploration refers to the exploration of an unknown environment by multiple mobile agents that move at the same speed. This model was introduced
to study the [[Parallel computing|paralellizability]] of maze-solving,<ref name="Fraigniaud2006">{{cite journal | last1=Fraigniaud | first1=Pierre | last2=Gasieniec | first2=Leszek | last3=Kowalski | first3=Dariusz R | last4=Pelc | first4=Andrzej | title=Collective tree exploration | journal=Networks| volume=48 | issue=3 | pages=166–177 | year=2006 | publisher=Wiley Online Library | doi=10.1002/net.20127 }}</ref> especially in the case of [[Tree (graph theory)|trees]]. The study depends on the model of communication between the agents. In the centralized communication model, the agents are allowed to communicate at all times with one another. In the [[Distributed computing|distributed]] communication model, the agents can communicate only by reading and writing on the walls of the maze. For trees with <math>n</math> nodes and depth <math>D</math>, with <math>k</math> robots, the current-best algorithm is in <math>O\left(\frac{n}{k} + kD\right)</math> in the centralized communication model and in <math>O\left(\frac{n}{\log k} + D\right)</math> in the distributed communication model.<ref name="Fraigniaud2006"/>
==See also==
* [[
* [[Maze generation algorithm]]
Line 136 ⟶ 159:
==External links==
* [http://www.astrolog.org/labyrnth/algrithm.htm#solve Think Labyrinth: Maze algorithms] (details on these and other maze
* [http://www.cb.uu.se/~cris/blog/index.php/archives/277 MazeBlog: Solving mazes using image analysis]
* [https://www.youtube.com/watch?v=jhL8uELbVIM Video: Maze solving simulation]
|