10/8/2021

## Rat Maze

41

The Rat in a maze is a famous problem in which we have a N x N matrix (the maze) which consists of two types of cells - one the rat can pass through and the other that the rat cannot pass through. The objective of this probleem is that the rat will be at a particular cell and we have to find all the possible paths that the rat can take to reach. The best-known rule for traversing mazes is the wall follower, also known as either the left-hand rule or the right-hand rule.If the maze is 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. How to Build Creative Labyrinth for RatIn this video I show you how to build family friendly creative maze labyrinth for your pet rat or hamster.

Robot in a wooden maze

There are a number of different maze solving algorithms, that is, automated methods for the solving of mazes. The random mouse, wall follower, Pledge, and Trémaux's algorithms are designed to be used inside the maze by a traveler with no prior knowledge of the maze, whereas the dead-end filling and shortest path algorithms are designed to be used by a person or computer program that can see the whole maze at once.

Mazes containing no loops are known as 'simply connected', or 'perfect' mazes, and are equivalent to a tree in graph theory. Thus many maze solving algorithms are closely related to graph theory. Intuitively, if one pulled and stretched out the paths in the maze in the proper way, the result could be made to resemble a tree.[1]

## Random mouse algorithm

This is a trivial method that can be implemented by a very unintelligent robot or perhaps a mouse. It is simply to proceed following the current passage until a junction is reached, and then to make a random decision about the next direction to follow. Although such a method would always eventually find the right solution, this algorithm can be extremely slow.

## Wall follower

The best-known rule for traversing mazes is the wall follower, also known as either the left-hand rule or the right-hand rule. If the maze is 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, the algorithm will return to the entrance having traversed every corridor next to that connected section of walls at least once. The algorithm is a depth-first in-order tree traversal.

Another perspective into why wall following works is topological. If the walls are connected, then they may be deformed into a loop or circle.[2] Then wall following reduces to walking around a circle from start to finish. To further this idea, notice that by grouping together connected components of the maze walls, the boundaries between these are precisely the solutions, even if there is more than one solution (see figures on the right).

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 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 Northwest, and 'down' passages can be assumed to lead southeast, then standard wall following rules can apply. However, unlike in 2D, this requires that the current orientation is known, to determine which direction is the first on the left or right.

## Pledge algorithm

Left: Left-turn solver trapped
Right: Pledge algorithm solution

Disjoint[clarification needed] mazes can be solved with the wall follower method, so long as the entrance and exit to the maze are on the outer walls of the maze. If however, the solver starts inside the maze, it might be on a section disjoint from the exit, and wall followers will continually go around their ring. The Pledge algorithm (named after Jon Pledge of Exeter) can solve this problem.[3][4]

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 turn is positive, counter-clockwise turn is negative). When the solver is facing the original preferential direction again, and the angular sum of the turns made is 0, the solver leaves the obstacle and continues moving in its original direction.

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 degrees 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 degrees is not equal to 0 degrees). It follows the wall all the way around, finally leaving it heading left outside and just underneath the letter shape.

This algorithm allows a person with a compass to find their way from any point inside to an outer exit of any finite two-dimensional maze, regardless of the initial position of the solver. However, this algorithm will not work in doing the reverse, namely finding the way from an entrance on the outside of a maze to some end goal within it.

## Trémaux's algorithm

Trémaux's algorithm. The large green dot shows the current position, the small blue dots show single marks on paths, and the red crosses show double marks. Once the exit is found, the route is traced through the singly-marked paths.

Trémaux's algorithm, invented by Charles Pierre Trémaux,[5] 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,[6] but it is not guaranteed to find the shortest route.

A path from a junction is either unvisited, marked once or marked twice. The algorithm works according to the following rules:

• Mark each path once, when you follow it. The marks need to be visible at both ends of the path. Therefore, if they are being made as physical marks, rather than stored as part of a computer algorithm, the same mark should be made at both ends of the path.
• Never enter a path which has two marks on it.
• If you arrive at a junction that has no marks (except possibly for the one on the path by which you entered), choose an arbitrary unmarked path, follow it, and mark it.
• Otherwise:
• If the path you came in on has only one mark, turn around and return along that path, marking it again. In particular this case should occur whenever you reach a dead end.
• If not, choose arbitrarily one of the remaining paths with the fewest marks (zero if possible, else one), follow that path, and mark it.

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 follow another path.

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.In this case each path is walked down exactly twice, once in each direction. The resulting walk is called a bidirectional double-tracing.[7]

Essentially, this algorithm, which was discovered in the 19th century, has been used about a hundred years later as depth-first search.[8][9]

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: [1][2].

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. [3]

## 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.

This is in effect a depth-first search expressed in term of grid points. The omniscient view prevents entering loops by memoization. Here is a sample code in Java:

## Maze-routing algorithm

The maze-routing algorithm [10] is a low overhead method to find the way between any two locations of the maze. The algorithm is initially proposed for chip multiprocessors (CMPs) domain and guarantees to work for any grid-based maze. In addition to finding paths between two location of the grid (maze), the algorithm can detect when there is no path between the source and destination. Also, the algorithm is to be used by an inside traveler with no prior knowledge of the maze with fixed memory complexity regardless of the maze size; requiring 4 variables in total for finding the path and detecting the unreachable locations. Nevertheless, the algorithm is not to find the shortest path.

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.

## Shortest path algorithm

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 such algorithm finds the shortest path by implementing a breadth-first search, while another, the A* algorithm, uses a heuristic technique. The breadth-first search algorithm uses a queue to visit cells in increasing distance order from the start until the finish is reached. Each visited cell needs to keep track of its distance from the start or which adjacent cell nearer to the start caused it to be added to the queue. When the finish location is found, follow the path of cells backwards to the start, which is the shortest path. The breadth-first search in its simplest form has its limitations, like finding the shortest path in weighted graphs.

## References

1. ^Maze to Tree on YouTube
3. ^Abelson; diSessa (1980), Turtle Geometry: the computer as a medium for exploring mathematics, ISBN9780262510370
4. ^Seymour Papert, 'Uses of Technology to Enhance Education', MIT Artificial Intelligence Memo No. 298, June 1973
5. ^Public conference, December 2, 2010 – by professor Jean Pelletier-Thibert in Academie de Macon (Burgundy – France) – (Abstract published in the Annals academic, March 2011 – ISSN0980-6032)
Charles Tremaux (° 1859 – † 1882) Ecole Polytechnique of Paris (X:1876), French engineer of the telegraph
6. ^Édouard Lucas: Récréations Mathématiques Volume I, 1882.
7. ^H. Fleischner: Eulerian Graphs and related Topics. In: Annals of Discrete Mathematics No. 50 Part 1 Volume 2, 1991, page X20.
8. ^Even, Shimon (2011), Graph Algorithms (2nd ed.), Cambridge University Press, pp. 46–48, ISBN978-0-521-73653-4.
9. ^Sedgewick, Robert (2002), Algorithms in C++: Graph Algorithms (3rd ed.), Pearson Education, ISBN978-0-201-36118-6.
10. ^Fattah, Mohammad; et, al. (2015-09-28). 'A Low-Overhead, Fully-Distributed, Guaranteed-Delivery Routing Algorithm for Faulty Network-on-Chips'. NOCS '15 Proceedings of the 9th International Symposium on Networks-on-Chip: 1–8. doi:10.1145/2786572.2786591. ISBN9781450333962. S2CID17741498.

• Think Labyrinth: Maze algorithms (details on these and other maze solving algorithms)
• Simon Ayrinhac, Electric current solves mazes, © 2014 IOP Publishing Ltd.
Rats and Mazes
• Different kinds of mazes and what they're used for:
Different types of mazes and what they're used for

Rats have been used in experimental mazes since at least the early 20th century. Thousands of studies have examined how rats run different types of mazes, from T-mazes to radial arm mazes to water mazes. These maze studies are used to study spatial learning and memory in rats. Maze studies helped uncover general principles about learning that can be applied to many species, including humans. Today, mazes are used to determine whether different treatments or conditions affect learning and memory in rats.

Rats are particularly gifted at running mazes. Their maze-running ability comes from their evolutionary history: rats are small burrowing rodents that have spent millenia digging and finding their way around underground tunnels. It's no wonder they have a knack with mazes.

The Classic maze

This is the kind of maze everyone thinks of when they think of rats and mazes. The maze consists of a large platform with a series of vertical walls and a transparent ceiling. The rat starts in one location, runs through the maze, and finishes at a reward in another location.

How many trials does it take for a hungry rat to run the maze to the food reward at the end with no mistakes? How quickly does the rat complete the maze each time? Does the rat get faster over multiple trials? Over time, rats tend to run the maze with fewer and fewer errors, more and more quickly. By graphing the number of errors over time, you can generate a learning curve for the rats.

 Fun projectsMazes look pretty simple to us. After all, we humans have a top-down view and can easily spot the solution of a small maze like the one pictured above. But a rat down in the maze can't see the whole thing: he can only see the corridors in front, behind, and to either side of him. The solution is not obvious at all! To experience what a maze might be like for a rat, try the projects below:Try running a maze on the Rat Maze Simulator.You can also make a Paper and Pencil Maze yourself.
The T-maze

The T-maze is shaped like a T. The test animal starts at the base of the T. A reward may be placed in one arm of the maze, or different rewards may be placed in each arm. The rat walks foward and chooses the left or right arm of the maze.

What kinds of questions can you answer with a T-maze?

Side preferences: The simplest question one can ask in a T-maze is whether a rat has a natural side preference. With no reward in either arm, does a rat prefer to go right or left?

Alternation: You can study natural alternation by running a rat in a T-maze over multiple trials with no reward. Do rats alternate between left and right arms? You can also train rats to alternate by rewarding first one arm, then the other, over many trials. The rat should learn to choose the arm that was not visited on the previous trial.

Learning: T-mazes are also used to study simple learning. You can place a reward at the end of one of the arms, then run a hungry rat through the maze multiple times. How many trials does it take before the rat chooses the correct arm most of the time? Further, if the reward is removed, and the rat is run through the maze multiple times, for how many trials does the rat continue to prefer the now empty arm? If the reward is replaced, how many trials does it take for the rat to re-establish a preference for that arm?

Preference: T-mazes are used to ask rats to choose between two options. A different reward is placed in each arm of the maze. Rewards can be anything: different foods, another rat in a small cage, shelter, an odor. The rat is allowed to explore the whole maze. Then the rat is placed in the start location, and the researcher records the rat's choice: for example, the amount of time the rat spends at the end of each arm over a period of time (say, 5 minutes). You can ask the rat all sorts of questions, like:

• Whether a rat prefers chocolate cake to peas
• Whether a rat prefers familiar-smelling bedding to fresh, unsoiled bedding
• Whether a female rat in heat prefers one male rat or another
• Whether a male rat prefers a strange or familiar female
• Whether a young rat prefers an adult male or an adult female
• Whether a rat prefers to eat food from a bowl other rats have already visited, or identical food from a new, clean bowl.
The Multiple T-maze

The multiple T-maze is a complex maze made of many T-junctions. Performance in the multiple T-maze is easy to measure because each intersection is identical and has a clear right or wrong answer. The multiple T-maze is also quite challenging for rats.

What kinds of questions can you ask with a multiple T-maze?

Multiple T-mazes were used to answer questions of place vs. response learning and cognitive maps.

Cognitive maps and latent learning: do rats learn a maze by choosing the corridors that lead to a reward, or do they generate an internal map of the maze even without a reward (called latent learning)? To answer this question, researchers placed a rat in a maze and let it explore the maze with no reward. The rat simply wandered about. Then the researchers started placing food in the reward corner. Rats who were already familiar with the maze learned to solve the maze more quickly and acheived better scores than rats who had never been given exploration time. Their proficiency indicated that the rats had generated a cognitive map of the maze during their explorations (Tolman and Honzik 1930).

Place learning vs. response learning: Do rats solve the maze by learning that the goal box is in a particular place in space, relative to cues outside the maze? For example, they might learn to go toward the place closest to the room's window or under an overhead lamp. This is called place learning, and is the chief form of learning in cognitive map theory. Alternatively, rats might learn a particular response to a maze, like 'left, right, left, left, right.' This is called response learning and belongs to stimulus-response theory. In this theory, rats choose to go left or right depending on which choice led them to the food in previous trials. The food reward reinforces the correct choices.

So, do rats use place learning or response learning? This question was tested by letting rats familiarize themselves with a maze. After a certain number of trials, the whole maze was rotated in the room. How well the rats performed after the rotation depended on (1) how many external cues were available, and (2) how many practice runs the rats got ahead of time. If rats were given lots of external cues (windows, overhead lamps, a clock on the wall) and ran the maze only a handful of times before testing, then they used place learning and made choices that brought them to the place in the room where the food reward was usually located. However, if external cues were few, and rats ran the maze hundreds of times before testing, then they used response learning. They consistently chose the same path regardless of how the maze was rotated (see Malone 1991 for more).

The Y-maze

The Y-maze is similar to the T-maze, but it has three identical arms. The rat starts at the end of one arm, then chooses one of the other two. The Y-maze is a little easier than a T-maze because gradual turns decrease learning time as compared to the sharp turns of the T-maze.

What kinds of questions can you answer with a Y-maze?

Y-mazes can be used to ask all the same questions as T-mazes. For example:

Alternation: if rats are left in the Y-maze for 5 minutes, how do they explore it? Do they explore each arm in turn? Do they remember which arm they entered last?

Novelty and memory: Do rats prefer to spend time in new or known areas? To test this, one arm of the Y-maze is blocked off and the rat is allowed to explore the other two arms for about 15 minutes. Then the rat is placed in the start arm and the blocked arm is uncovered. Does the rat prefer the new arm or the known one? To test the rat's memory there might be a delay of several hours between the familiariazation phase and the test phase. The rats' memory function might then be tested under different conditions, like under the influence of drugs that may inpair or enhance memory.

The most interesting Y-maze I've ever seen was a giant underwater Y-maze used to test preferences in sharks!

The radial arm maze has a center platform with eight, twelve, or sixteen spokes radiating out from a central core (Olton and Honig 1978).

What kinds of questions can you answer with a radial arm maze?

Short-term memory: Do rats remember which arms of the maze they've already visited? To test this, a single food pellet is placed at the end of each arm. A rat is placed on the central platform. The rat visits each arm and eats the pellet. To successfully complete the maze, the rat must go down each arm only once. He must use short-term memory and spatial cues to remember which arms he's already visited. If a rat goes down an arm twice, this counts as an error. The rat's performance on the maze is considered a test of short-term memory. Short-term memory can then be tested in different rats or under different treatment conditions. For example, do males perform better than females? What about young vs. old rats?

### Rat Maze Diy

Behavioral neuroscience: The rats might be given particular drugs (like alcohol) to see if these impair or enhance short-term memory. Different brain areas might also be impaired to see how important they are in short-term memory tasks.

The Morris water maze

The Morris water maze (Morris et al. 1982) is a large round tub of opaque water (made white with powdered milk) with two small hidden platforms located 1-2 cm under the water's surface. The rat is placed on a start platform. The rat swims around until it finds the other platform to stand on. External cues, such as patterns or the standing researcher, are placed around the pool in the same spot every time to help the rat learn where the end platform is. The researcher measures how long it takes for a rat to find hidden platform.

What kinds of questions can you answer with a Morris water maze?

Spatial learning, place learning, cognitive maps and memory: How many trials does it take for the rat to locate the hidden platform? What kinds of spatial cues does a rat use to find the hidden platform? What happens if these cues are changed or moved?

### Rat Maze Study

Behavioral neuroscience: What parts of the brain are used for spatial learning and memory? The Morris water maze is very popular for studies of behavioral neuroscience (D'Hooge and De Deyn 2001). For example, how does a trained rat's performance change after manipulation of different parts of its brain, like the hippocampus (e.g. Burwell et al. 2004, Harker and Whishaw 2004)? How does performance change after a rat receives certain drugs or enzymes (e.g. Dash et al. 2004)? How well do different strains of rats perform?

Home • Rat Behavior • The Rat's Sensory World • Rat Biology • Rat Systematics • Wild Rats • Rat Health Notes • Rat Humor • References • Updates • About