Page 1

Rush Hour is PSPACE-complete J.N. van Rijn Leiden Institute of Advanced Computer Science Universiteit Leiden jvrijn@liacs.nl May 24, 2011 Abstract In this report we give a formal definition of the sliding block puzzle Rush Hour and we report on the proof showing that Rush Hour is PSPACE-complete from “The nondeterministic constraint logic model of computation: Reductions and applications” by Hearn and Demaine (Proceedings ICALP 2002).

1

Introduction

Rush Hour is a sliding block puzzle invented by Nob Yoshigahara in the late 1970s [7]. The game is played on a 6 × 6 grid, on which various cars are situated which can be moved forward and backward an unlimited number of times with the restriction that a car can not move through another car. An example of the game is shown in Figure 1. The goal is to move a certain car out of the grid by moving it to a certain position on the grid which is defined to be the exit. In this particular example, the red car needs to be moved two units to the right. In order to do so, first the yellow truck has to be moved elsewhere since it blocks the route of the red car. The route of the yellow truck in its turn is blocked by a gray and a black car, both of which need to be moved before the yellow truck can make space for the red car. This chain of jam-ups can make a particular instance of Rush Hour quite complex, and in fact that is what we are going to prove in this report. Note that the red

1


Figure 1: An example of the puzzle Rush Hour, taken from [8]. The goal is to move the red car out of the grid. car is the only one that has the potential to arrive at the exit in the proper orientation. Our main contribution will be to elucidate various aspects of the work done by [1], who proved Rush Hour to be PSPACE-complete. In Section 2 a formal definition of the game is given. In Section 3 the proof constructed by [1] is presented. Finally, in Section 4 a conclusion is drawn and some suggestions for future research are mentioned.

2

Rush Hour

Rush Hour is a sliding block puzzle, typically played on a 6 Ă— 6 grid. This grid represents a parking lot on which k cars are situated; the goal is to move a certain target car to a certain target position. In order to do so, the player has the possibility to move all cars forward and backward as many times as he wants. Of course, cars can not move sideways. There is only one exit, which has to be in the same row or column as the target car, depending on whether the target car is parked horizontally or vertically. We generalize the game in such a way that it will be played on a n by m grid G. Let C be the collection of all cars, C = {c1 , c2 , . . . , ck }. Let cq (q = {1, 2, . . . , k}) be the tuple (cxq , cyq , c`q , cdq ). Here (cxq , cyq ) are the 2


coordinates of the top-left position of the car, c`q is the length and cdq the direction (cdq ∈ {horizontal , vertical }). From these properties, we can infer all other coordinates on the grid that are occupied by cq . If d = horizontal, cq is of size c`q by 1; if d = vertical, cq is of size 1 by c`q . Let Pq be the set of coordinates (or positions on G) occupied by cq . (

Pq =

{(x, y) ∈ G : cxq ≤ x < cxq + c`q , y = cyq } if cdq = horizontal {(x, y) ∈ G : cyq ≤ y < cyq + c`q , x = cxq } otherwise S

The set of all occupied coordinates of G is defined to be P = q Pq . Let t ∈ {1, 2, . . . , k} be the index of the target car, so ct is the target car. The goal of the game is to move ct to a given target position T ∈ {(x, y) ∈ G : (x = 1 ∨ x = n ∨ y = 1 ∨ y = m), (x = cxt ∨ cdt = vertical ), (y = cyt ∨ cdt = horizontal )}. The first condition assures that T will be on the edge of the grid, this is where ct can leave the parking lot. The second and third condition assure that T will be in the same row as cxt if cdt = horizontal or in the same column if cdt = vertical . The game can not be won if this is not the case, as we will see later. A move is defined as a legal shifting by one of an arbitrary car q over one of the axes. The shifting of cq to position (cxq + 1, cyq ) is legal if and only if / P ), the shifting of (cdq = horizontal ) ∧ (cxq + c`q + 1 < n) ∧ ((cxq + c`q + 1, cyq ) ∈ d y x cq to position (cq − 1, cq ) is legal if and only if (cq = horizontal ) ∧ (cxq − 1 > 0) ∧ ((cxq − 1, cyq ) ∈ / P ). Similar conditions hold for vertical cars. After each move, Pq and P have to be updated. The game is won if and only if a sequence of legal moves can transform the original P in P 0 with T ∈ Pt0 .

3

PSPACE-completeness

In [1, 3] it is proven that Rush Hour is PSPACE-complete. In this section, we will elaborate upon the proof provided in [1]. To prove a problem PSPACEcomplete, we must both show that this problem is in PSPACE and that it is PSPACE-hard. The latter is done by reduction from Nondeterministic Constraint Logic, from here on abbreviated as NCL. NCL is a graph game, which is played on a constraint graph CG = (V, E). A constraint graph is a weighted directed graph, where each edge has a weight in {1, 2}. Each vertex has a maximal degree of 3. The inflow of a vertex is defined to be the sum of all weights of the edges that are directed 3


(a) AND

(b) OR

Figure 2: NCL vertices. inward. Each vertex has a nonnegative minimum inflow. A configuration of a constraint graph is legal if and only if for each vertex holds that the inflow is equal to or bigger than its minimum inflow. A move of the player consists of the reversal of a single edge, such that it results in a legal configuration. The goal is to reverse a certain target edge, after a series of moves. In [1] it is proven that NCL is PSPACE complete, when the CG consists of only the gadgets shown in Figure 2. In this figure an edge is drawn blue if and only if it has a weight of 2; an edge is drawn red if and only if it has a weight of 1. We will stick to this convention for the rest of this report. The vertex shown in Figure 2(a) behaves like a logical AND-gate. The blue edge can be directed outward if and only if both red edges are directed inward. Hence we call this an AND vertex. The vertex shown in Figure 2(b) behaves like a logical OR-gate. For each blue edge it holds that it can only be directed outward, if and only if at least one of the other edges is directed inward. Hence we call this an OR vertex. It is not hard to see that an OR vertex exists, such that due to global constraints two edges can not be directed inward at the same time. An example of this is shown in Figure 3. Here we see two AND vertexes and one OR vertex. It is impossible for the edges B and C to be directed inward to the OR vertex at the same time, since then it would be impossible to satisfy the constraints for both AND vertexes. We will refer to such an OR vertex as a protected OR vertex. The edges that can not be directed inward at the same time are referred to as the protected edges. Locally, this has the following consequence: If we want to go from the state [Ain , Bout , Cout ] to ei4


Figure 3: A NCL Graph consisting of two AND vertices and an OR vertex. The OR vertex obeys the definition of a protected OR vertex. ther [Aout , Bin , Cout ] or [Aout , Bout , Cin ] this is possible (through respectively [Ain , Bin , Cout ] or [Ain , Bout , Cin ]), but when we are in one of the desired states it is impossible switch between them, which would be possible in a true OR vertex by going through [Aout , Bin , Cin ]. In [2] it is shown that using merely AND vertexes and protected OR vertexes, a subgraph with the same functionality as an OR vertex can be constructed. From this fact, the authors conclude that NCL is PSPACE-complete, even when CG consists of only AND vertices and protected OR vertices. In order to prove a problem PSPACE-hard, it suffices to create a gadget which simulates the AND vertex and a gadget which either simulates the OR vertex or the protected OR vertex. Intuitively, it seems easier to construct a protected OR gadget. In this case, we do not need to simulate all functionality of an OR vertex. In Appendix A this is shown in more detail. Besides that a gadget which simulates the behavior of the target edge needs to be constructed and a way to link the gadgets needs to be provided. For NCL this is trivial, since we can use edges and if necessary the crossover gadget, as constructed by [1]. The overall layout and gadgets, created by [1], are shown in Figure 4. The target car is denoted by T, the game is won if it can be moved down. Dark-colored cars represent the borders of each gadget, hence they are called the border cars. These are arranged in such a way, that due to global constraints they can never be moved. Medium-gray cars are fillers. Some of them may move, but they never disrupt the verticesâ&#x20AC;&#x2122; operation. Yellow (light-colored) cars are the triggers, whose motion serves to satisfy the vertex constraints. The cars A, B and C represent the edges adjacent to the vertex, these are called the edge cars. An edge car can either be positioned entirely 5


(a) Layout

(b) AND

(c) Protected OR

Figure 4: Rush Hour vertex gadgets. within the gadget like A and B, or point out one unit like C. An edge car being entirely within the gadget corresponds with an NCL edge directed outward, an edge car pointing out one unit corresponds with a NCL edge pointing inward. The layout as shown in Figure 4(a) ensures that none of the border cars can ever move and that none of the edge cars can ever slide out into an adjacent vertex. Lemma 3.1 The construction in Figure 4(b) satisfies the same constraints as a NCL AND vertex, with A and B corresponding to the red edges, and C to the blue edge. Proof We need to show that C may move down if and only if first A moves left and B moves down in some order. For C to be able to move one unit 6


down, first F has to move two units to the left. F can move two units to the left if and only if both D and E are moved down one unit. For D to be able to move down, A must be moved one unit out of the gadget. For E to be able to move one unit down, G has to move two units to the right, which is only possible when B is moved one unit out of the gadget. From this we can conclude that C can not move within the gadget if and only if either A or B is within the gadget. On the other hand when C is inside the gadget, neither A nor B can be moved within the gadget unless C is moved out first. Lemma 3.2 The construction in Figure 4(c) satisfies the same constraints as a NCL protected OR vertex, with A and B corresponding to the protected edges. Proof We need to show that C may move down if and only if either A first moves left or B first moves right. Moving either A or B out will respectively give room for E or F to move down, which is turn gives D the opportunity to move either left (in case B was moved out) or right (in case A was moved out). It also works the other way around, moving C back out will give D the opportunity to move back to the middle, after which either respectively F and B or E and A can be moved back. Note that we are using the protected OR property. Once C is in, one of A and B must stay out, and you can not switch between them as prescribed in a true OR gadget. In a protected OR, we are guaranteed due to global constraints that A and B never need to be simultaneously moved out. In Appendix B it is shown how we can use the AND gadget and the protected OR gadget to create a true OR gadget. Lemma 3.3 The reduction from NCL can be done using a number of cars that is bounded by a polynomial function over the number of vertices. Proof In [5] it is proven that a graph with degree 3 can always be stored in a square grid of width v, where v is the number of vertices contained by the graph. Since all our gadgets satisfy the condition that they have a maximum degree of three, we can expand the entire construction on a grid of size c â&#x2C6;&#x2014; v 2 , where v is the number of vertices in NCL, and c is a constant which represents the space needed for our most extensive gadget. Inherent to this, having a polynomial bound on the size of the grid in only two dimensions where cars can not overlap, we can never have more cars than cells. 7


Theorem 3.4 Rush Hour is PSPACE-complete. Proof We show Rush Hour PSPACE-hard by a reduction from planar Nondeterministic Constraint Logic using the layout, the AND gadget and the protected OR gadget which we explained in this section. Linking gadgets can easily be constructed; an example of these can be found in Figure 8. The target car can move down if and only if the target vertex can be reversed. Rush Hour is also in PSPACE. We can nondeterministically traverse the state space, at each step nondeterministically choosing a move to make, and maintaining the current state but not the previously visited states. Savitch’s Theorem [6] says that this NPSPACE algorithm can be converted into a PSPACE algorithm. Hence Rush Hour is PSPACE-complete.

4

Conclusion

We have verified and reported on the proof constructed in [1] that Rush Hour is PSPACE-complete. In addition to that, we have given a formal definition of the game Rush Hour, and elaborated on some aspects of the proof that were not mentioned by [1]. As a future work recommendation in the overlapping fields of Rush Hour and NCL, NCL gadgets could be constructed in order to reproduce the proof constructed by [4] which states that Rush Hour is PSPACE-complete, even when all cars are of size 2. In our construction cars of size 2 and 3 were used.

References [1] Hearn, R. A., and Demaine, E., The nondeterministic constraint logic model of computation: Reductions and applications, In Proceedings of ICALP, volume 2380 of Lecture Notes in Computer Science, pages 401–413. Springer, 2002. [2] Hearn, R. A., and Demaine, E., PSPACE-completeness of sliding-block puzzles and other problems through the nondeterministic constraint logic model of computation, Theoretical Computer Science, 343(1– 2):72–96, 2005.

8


[3] Flake, G.W. and Baum, E. B., Rush Hour is PSPACE-complete, or “Why you should generously tip parking lot attendants”, Theoretical Computer Science, 270(1–2):895–911, 2002. [4] Tromp, J. and Cilibrasi, R., Limits of Rush Hour logic complexity, Manuscript, June 2004, http://www.cwi.nl/tromp/rh.ps [retrieved April 2, 2011] [5] Di Battista, G., Eades, P., Tamassia, R., and Tollis, I. G., Algorithms for drawing graphs: an annotated bibliography, Computational Geometry, 4(5):235–284, 1994. [6] Savitch, W.J., Relationships between nondeterministic and deterministic tape complexities, Journal of Computer and System Sciences, 4(2):177–192, 1970. [7] The Wikimedia Foundation, Rush Hour (board game), http://en. wikipedia.org/wiki/Rush_Hour_(board_game) [retrieved April 4, 2011] [8] Hiard, S., Rush Hour, http://www.montefiore.ulg.ac.be/~hiard/ RushHourEng.html [retrieved March 22, 2011]

A

Requirements for simulating a vertex

In this appendix we will show which states of a vertex must be simulated, in order to create a gadget which simulates the behavior of a certain vert tex type. In each table, Em stands for edge, where m ∈ {1, 2, 3} and t ∈ {b, r, p}. Here, b means that the edge is a blue edge, r means that the edge is a red edge and p means that the edge is a protected blue edge. The state of each edge is an element from {outward, inward} which indicates whether the edge is directed inward or outward. In simulate, an element from {Yes, Forbidden, Not necessary}, it is stated respectively whether this state must be simulated, may not occur or we don’t care whether it occurs locally, since it will be impossible due to global constraints. Figures 5, 6 and 7 show the legal state transitions that need to be simulated by respectively the AND-vertex, OR-vertex and protected OR-vertex.

9


E1r outward outward outward outward inward inward inward inward

E2r outward outward inward inward outward outward inward inward

E3b outward inward outward inward outward inward outward inward

simulate Forbidden Yes Forbidden Yes Forbidden Yes Yes Yes

Table 1: All configurations that need to be simulated in order to obtain an AND vertex.

Figure 5: State action diagram for an AND vertex.

10


E1b outward outward outward outward inward inward inward inward

E2b outward outward inward inward outward outward inward inward

E3b outward inward outward inward outward inward outward inward

simulate Forbidden Yes Yes Yes Yes Yes Yes Yes

Table 2: All configurations that need to be simulated in order to obtain an OR vertex.

Figure 6: State action diagram for an OR vertex.

11


E1p outward outward outward outward inward inward inward inward

E2p outward outward inward inward outward outward inward inward

E3b outward inward outward inward outward inward outward inward

simulate Forbidden Yes Yes Yes Yes Yes Not necessary Not necessary

Table 3: All configurations that need to be simulated in order to obtain an protected OR vertex.

Figure 7: State action diagram for a protected OR vertex. 12


B

OR gadget

Figure 8 shows a Rush Hour OR gadget, created using AND gadgets, protected OR gadgets and filler gadgets. The equivalent NCL graph can be found in [2], page 10.

Figure 8: OR gadget.

13


Rush Hour  

In this report we give a formal definition of the sliding block puzzle Rush Hour and we report on the proof showing that Rush Hour is PSPACE...

Read more
Read more
Similar to
Popular now
Just for you