Linear Time Algorithm for Weak Parity Games
We consider games played on graphs with the winning conditions for the players specified as weak-parity conditions. In weak-parity conditions the winner of a play is decided by looking into the set of states appearing in the play, rather than the set…
Authors: Krishnendu Chatterjee
Linear Time Algorithm for W eak P arit y Games Krishnendu Chatterjee Universit y of California, Berkeley , USA c krish@eecs .berkeley.edu Abstract. W e consider games pla yed on g raph s with the winning conditions for the pla yers sp ecified as we ak-p arity conditions. In w eak-p arit y conditions the winner of a pla y is decided by looking into th e set of states appearing in t h e pla y , rather th an the set of states app earing infinitely often in the pla y . A naive analysis of the classical algorithm for w eak- parity games yields a quadratic time al gorithm. W e presen t a linear time algo rith m for solving weak-parit y games. 1 In tro duction W e consider tw o -play er games on graphs with winning ob jectives formalized as a we ak-p arity ob- jective [2]. In a tw o-player game [1], the s e t o f vertices or states are partitioned into play er 1 states and pla yer 2 s tates. At play er 1 states play er 1 decides the success or and likewise for player 2. W e consider weak-parity ob jectives, where w e hav e a pr iority function that maps every state to an int eg er pr iority . A play is an infinite sequence of sta tes , and in a w eak -parity ob jective the winner of a play is decided b y considering the minimum priority state that appe a r in the play: if the minim um priority is ev e n, then play er 1 wins, and otherwise play er 2 is the winner. The classica l algorithm to solve weak-parity games with a naive running time analys is w or ks in O ( d · m ) time, where d is the n umber of priorities and m is the num b er o f edges of the game graph. Since d can be O ( n ), in the worst case the naive analysis r equires O ( n · m ) time, where n is the num b er of states. W e pr esent an impro ved analysis of the a lg orithm and show that the alg orithm works in O ( m ) time. 2 Definitions W e co nsider turn-ba sed deterministic games play ed by tw o-players with we ak-p arity ob jectives; we call them weak-parity g ames. W e define g ame graphs, plays, strategies, ob jectives and notion of winning b elow. Game graphs. A game gr aph G = (( S, E ) , ( S 1 , S 2 )) co nsists of a directed graph ( S, E ) with a finite state space S and a set E of edges , and a partition ( S 1 , S 2 ) of the state spa ce S into t wo sets. The s tates in S 1 are play er 1 sta tes, and the states in S 2 are player 2 states. F or a state s ∈ S , we write E ( s ) = { t ∈ S | ( s, t ) ∈ E } for the set o f s uccessor sta tes of s . W e assume that every s tate has at least one o ut-going edge, i.e ., E ( s ) is non- empt y for all states s ∈ S . Pla ys. A game is pla yed by tw o pla yers: play er 1 and play er 2 , who form an infinite path in the game graph by moving a token along edg e s . They start b y placing the tok en on an initial state, and then they take mov es indefinitely in the following w ay . If the tok en is o n a state in S 1 , then play er 1 mov es the token along o ne of the edges going out of the state. If the tok e n is on a state in S 2 , then pla yer 2 does lik ew is e. The result is an infinite path in the game gr aph; we refer to such infinite paths as plays. F ormally , a play is an infinite sequence h s 0 , s 1 , s 2 , . . . i of states suc h that ( s k , s k +1 ) ∈ E for all k ≥ 0. W e write Ω for the set of all plays. Strategies. A strategy for a pla yer is a recip e tha t sp ecifies ho w to extend plays. F or mally , a str ate gy σ for pla yer 1 is a function σ : S ∗ · S 1 → S that, given a finite sequence of states (representing the history o f the play so far) which ends in a pla yer 1 state, c ho o ses the next state. The strateg y m us t cho ose only av ailable successors , i.e., for all w ∈ S ∗ and s ∈ S 1 we hav e σ ( w · s ) ∈ E ( s ). The strateg ies for pla yer 2 are defined analogously . W e write Σ and Π for the sets of a ll strategies for play er 1 and pla yer 2, respectively . An imp ortant specia l class of strategies ar e memoryle s s strategies. The memoryles s strategies do not dep end on the history of a play , but only on the current state. Eac h memoryless strateg y for player 1 can b e sp ecified as a function σ : S 1 → S such that σ ( s ) ∈ E ( s ) for all s ∈ S 1 , and a na logously for memory less play er 2 stra teg ies. Given a starting state s ∈ S , a strategy σ ∈ Σ for player 1 , and a strategy π ∈ Π for play er 2, there is a unique pla y , denoted ω ( s, σ , π ) = h s 0 , s 1 , s 2 , . . . i , which is defined as follows: s 0 = s and for all k ≥ 0, if s k ∈ S 1 , then σ ( s 0 , s 1 , . . . , s k ) = s k +1 , and if s k ∈ S 2 , then π ( s 0 , s 1 , . . . , s k ) = s k +1 . W eak-parit y ob jectives. W e consider game gra phs with weak-parity ob jectives for player 1 and the complementary weak-par it y ob jectives for play er 2. F or a play ω = h s 0 , s 1 , s 2 , . . . i ∈ Ω , we define Ocuur( ω ) = { s ∈ S | s k = s for some k ≥ 0 } to b e the set of s ta tes that o ccur in ω . W e also define reachabilit y and s a fet y ob jectives a s they will b e useful in the analysis of the algorithms. 1. R e achab ility and safety obje ct ives. Giv en a set T ⊆ S of states, the reachabilit y ob jective Reach ( T ) requires that some state in T be vis ited, and dually , the safet y ob jective Safe( F ) requires that only states in F be visited. F orma lly , the sets of winning plays are Reac h( T ) = {h s 0 , s 1 , s 2 , . . . i ∈ Ω | ∃ k ≥ 0 . s k ∈ T } and Safe( F ) = {h s 0 , s 1 , s 2 , . . . i ∈ Ω | ∀ k ≥ 0 . s k ∈ F } . The reachabilit y and s afety ob jectives are dual in the sense that Reach ( T ) = Ω \ Safe( S \ T ). 2. We ak-p arity obje ct ives. F or d ∈ N , we let [ d ] = { 0 , 1 , . . . , d − 1 } and [ d ] + = { 1 , 2 , . . . , d } . Let p : S → [ d ] be a function that assigns a priority p ( s ) to every state s ∈ S . The weak-parity ob jective requires that the minimal pr iority occur ring is even . F ormally , the set of winning plays is W eakParityEv en( p ) = { ω ∈ Ω | min( p (Ocuur( ω ))) is even } . The complemen tar y ob jective to W eakParityEven ( p ) is W eakParityOdd ( p ) defined as the set W eakParityOdd ( p ) = { ω ∈ Ω | min( p (Ocuur( ω ))) is o dd } of winning plays. Winning strategie s and sets. Given a ga me graph G and a n ob jectiv e Φ ⊆ Ω for play er 1, a strategy σ ∈ Σ is a winning st r ate gy fo r player 1 from a state s if for a ll player 2 strateg ies π ∈ Π the pla y ω ( s, σ , π ) is winning, i.e., ω ( s, σ , π ) ∈ Φ . The winning strategie s for play er 2 a re defined analogo usly . A s tate s ∈ S is winning for player 1 with resp ect to the ob jective Φ if play er 1 has a winning strateg y from s . F ormally , the set of winning states for play er 1 with res pec t to the ob jective Φ in a ga me graph G is W G 1 ( Φ ) = { s ∈ S | ∃ σ ∈ Σ . ∀ π ∈ Π . ω ( s, σ, π ) ∈ Φ } . Analogous ly , the set of winning states for play er 2 with res p ect to an ob jective Ψ ⊆ Ω is W G 2 ( Ψ ) = { s ∈ S | ∃ π ∈ Π. ∀ σ ∈ Σ . ω ( s, σ , π ) ∈ Ψ } . If the g ame gr aph is clear from the cont e x t we drop the game gr aph from the sup erscript. W e say that there exists a memor yless winning strategy fo r player 1 with resp ect to the ob jective Φ if there exists s uch a str ategy from a ll s ta tes in W 1 ( Φ ); and similarly for play er 2. Theorem 1. F or al l game gr aphs G = (( S, E ) , ( S 1 , S 2 )) , for al l we ak-p arity obje ctives Φ = W eakParit y Even ( p ) for player 1, and the c omplementary obje ctive Ψ = Ω \ Φ for player 2, the fol lowing assertions hol d. 1. We have W 1 ( Φ ) = S \ W 2 ( Ψ ) . 2 2. Ther e exists a memoryless winning str ate gy fo r b oth players. Closed sets and attractors. Some notions that will pla y key roles in the analysis of the algo r ithms are the notion of close d sets and attra ctors . W e define them b elow. Close d sets. A set U ⊆ S of sta tes is a close d set for play er 1 if the following tw o conditions hold: (a) for all states u ∈ ( U ∩ S 1 ), w e hav e E ( u ) ⊆ U , i.e., a ll successors of pla yer 1 states in U a re again in U ; and (b) for all u ∈ ( U ∩ S 2 ), we hav e E ( u ) ∩ U 6 = ∅ , i.e., every player 2 sta te in U has a successor in U . A play er 1 clo sed set is a ls o called a tr ap for player 1 . The clo sed sets for play er 2 are defined analogo usly . Every clo sed set U for play e r ℓ , for ℓ ∈ { 1 , 2 } , induces a sub-ga me graph, denoted G ↾ U . Prop ositio n 1 . Consider a game gr aph G , and a close d s et U for pl ayer 2. F or every obje ctive Φ for pl ayer 1, we have W G ↾ U 1 ( Φ ) ⊆ W G 1 ( Φ ) . Attr actors. Giv en a g ame gr aph G , a set U ⊆ S o f states, and a pla yer ℓ ∈ { 1 , 2 } , the set Attr ℓ ( U, G ) contains the states fro m which play er ℓ has a strateg y to re a ch a sta te in U agains t all stra teg ies of the other play er; that is, Attr ℓ ( U, G ) = W ℓ (Reach( U )). T he set A tt r 1 ( U, G ) can b e computed inductively as follows: let R 0 = U ; let R i +1 = R i ∪ { s ∈ S 1 | E ( s ) ∩ R i 6 = ∅} ∪ { s ∈ S 2 | E ( s ) ⊆ R i } for all i ≥ 0; then Attr 1 ( U, G ) = S i ≥ 0 R i . The inductive computatio n o f Attr 2 ( U, G ) is analo gous. F or all states s ∈ Attr 1 ( U, G ), define r ank ( s ) = i if s ∈ R i \ R i − 1 , tha t is, r ank ( s ) denotes the least i ≥ 0 suc h that s is included in R i . Define a memoryless attracto r stra tegy σ ∈ Σ for player 1 as follows: for each state s ∈ ( Attr 1 ( U, G ) ∩ S 1 ) with r ank ( s ) = i , cho ose a successor σ ( s ) ∈ ( R i − 1 ∩ E ( s )) (such a successor exis ts by the inductiv e definition). It follows that for all states s ∈ Attr 1 ( U, G ) and a ll strategies π ∈ Π for play er 2, the play ω ( s, σ, π ) reaches U in at mos t | Attr 1 ( U, G ) | transitions . Prop ositio n 2 . F or al l ga m e gr aphs G , al l players ℓ ∈ { 1 , 2 } , and al l sets U ⊆ S of states, the set S \ Attr ℓ ( U, G ) is a clo se d set for player ℓ . Notation. F or a game graph G = (( S, E ) , ( S 1 , S 2 )), a set U ⊆ S and ℓ ∈ { 1 , 2 } , we write G \ Attr ℓ ( U, G ) to denote the game g raph G ↾ ( S \ Attr ℓ ( U, G )). Computation of attrac tors. Giv en a g ame gr aph G = ( S, E ) and a set T ⊆ S of sta tes le t us denote by A = Attr ℓ ( T , G ) the attra ctor for a player ℓ ∈ { 1 , 2 } to the set T . A naive analysis of the computation o f attractor sho ws that the computation can be done in O ( m ) time, where m is the nu mber of edg e s. An improv ed analysis can b e done as follows. F or every sta te s ∈ S \ T we k eep a count e r initialized to 0. Whenever a state t is included for the set of states in A , for all states s suc h that ( s, t ) ∈ E w e increase the coun ter by 1. F or a state s ∈ S ℓ if the coun ter is pos itive, then we include it in A , and for a state s ∈ S \ S ℓ if the count e r equa ls the num b er of edges | E ( s ) | , then we include it in A . Let us consider the following set of edges: E A = E ∩ (( S \ T ) × A ). The work of the attractor computation is o nly on edges with the start state in ( S \ T ) a nd e nd state in A . That is the total work of attr a ctor computation on edges is O ( m A ) where m A = | E A | . Also the counter initializatio n pha se do es not requir e to initialize counters for all states, but only initializes a counter for a state s , when some state t ∈ E ( s ) gets inc luded in A for the fir st time. This giv es us the following lemma. Lemma 1. Given a game gr aph G = ( S, E ) and a s et T ⊆ S of states let us denote by A = Attr ℓ ( T , G ) the att r actor for a player ℓ ∈ { 1 , 2 } to the set T . The set A c an b e c ompute d in time O ( | E A | ) , wher e E A = E ∩ (( S \ T ) × A ) . 3 Algorithm 1 Classical algorithm for W eak-parit y Ob jectives Input : A 2-p laye r game graph G = (( S, E ) , ( S 1 , S 2 )) and priority function p : S → [ d ]. Output: A partition ( W 1 , W 2 ) of S . 1. G 0 := G ; W 1 := W 2 := ∅ ; 2. for ( i := 0; i < d ; i := i + 1) 2.1. A i = A ttr ( i mod 2+1) ( p − 1 ( i ) ∩ S i , G i ); 2.2 W ( i mod 2+1) = W ( i mo d 2+ i ) ∪ A i ; 2.3. G i +1 = G i \ A i ; end for 3. return ( W 1 , W 2 ); 3 The Classica l A lgorithm W e first present the classical algor ithm for w eak- parity games and pr esent an improved a nalysis to show that the algorithm has a linear-time co mplexit y . W e first pres ent an informal des cription of the algorithm; and a fo r mal description of the alg orithm is g iven as Algorithm 1. Informal description of the classical algorithm. W e will consider a priority function p : S → [ d ]. The ob jective Φ for play er 1 is the weak-parity ob jective W eakParityEv en( p ) and the ob jective for player 2 is the complemen ta ry ob jective Ψ = W eakParityOdd ( p ). The algor ithm pr o ceeds by computing attractors and removing the attractors from the game graph and pro c e e ds on the subgame graph. At iteration i , we denote the ga me gr aph by G i and the state space as S i and the set o f edg e s of G i as E i . At iteration i , the attractor set to the set of states of priority i in G i (i.e., attractor to p − 1 ( i ) ∩ S i ) is computed. If i is even, the set is included in the winning s et fo r play er 1, and otherwise it is included in the winning set for player 2 and the set is removed from the game graph for the next itera tions. Correctness. The following theorem states the corre c tness of Algorithm 1. Theorem 2 (Correctness). Given a game gr aph G = (( S, E ) , ( S 1 , S 2 )) and priori t y f u nction p : S → [ d ] we have W 1 = W 1 (W eakParit yE ven ( p )); S \ W 1 = W 2 = W 2 (W eakParit yO dd( p )) , wher e ( W 1 , W 2 ) is the output of Algori t hm 1. Pr o of. Observe that in the game gr a ph G i we ha ve S i ⊆ S j ≥ i p − 1 ( j ), i.e., the priorities in G i are at least i . Let us denote by W i 1 and W i 2 the sets W 1 and W 2 at the end of iteration i − 1 of Algorithm 1. Then for a ll s ∈ S i ∩ S 1 we ha ve E ( s ) ⊆ S i ∪ W i 2 and for all s ∈ S i ∩ S 2 we ha ve E ( s ) ⊆ S i ∪ W i 1 . W e prove by inductio n that the following tw o conditions hold W i 1 ⊆ W G 1 W eakParit y Even ( p ) ∩ { ω | min( p (Ocuur( ω ))) < i } ; W i 2 ⊆ W G 2 W eakParit y Odd( p )) ∩ { ω | min( p (Ocuur ( ω ))) < i } . The base case is trivial and w e now prove the inductive case. F o r i ev en, for a state s ∈ A i , the attractor s trategy σ for player 1 in G i to reach p − 1 ( i ) ∩ S i and then choosing edge s in S i , ensures that for all s trategies π for player 2 w e hav e ω ( s, σ , π ) ∈ W eakParit y Even ( p ) ∩ { ω | min( p (Ocuur( ω ))) ≤ i } ∪ Reach ( W i 1 ) . 4 By the inductiv e hypothesis it follows that A i ⊆ W G 1 W eakParit y Even ( p ) ∩ { ω | min( p (Ocuur( ω ))) < i + 1 } . Similarly , it follows for i o dd that A i ⊆ W G 2 W eakParit y Odd( p ) ∩ { ω | min( p (Ocuur ( ω ))) < i + 1 } . The desired result follows. Running time analysis. In the running time analysis w e will denote by n the num b er of s ta tes, and b y m the n umber of edges in the game graph. The naive analysis o f the running time of Algorithm 1 yields a O ( d · m ) running time analysis . This is b eca use the lo op of step 2 runs for d times, a nd each iter ation can be computed in O ( m ) time. Since d can b e O ( n ), the worst case bo und of the naive analysis is O ( n · m ), which is quadratic. W e will no w prese nt a linear-time analysis of the a lgorithm. The t wo key issues in the running time analysis of the algorithm is to analyze the computatio n of the a ttr a ctors (step 2.1 of the algorithm) and o bta ining the target sets p − 1 ( i ) ∩ S i in the a ttr a ctor computation. W e now a nalyze the r unning time of the a lgorithm addressing the t wo a b ove issues. The attractor computations. W e first argue that the attrac to r computation ov er all iteratio ns can b e done in O ( m ) time. T o prove this claim we obse r ve that the sets A i computed at step 2 .1 o f the a lgorithm sa tisfies that A i ∩ A j = ∅ for i 6 = j , (since the set A i once co mputed is removed from the g ame g raph for further iterations). Let us cons ider the set E A i = E i ∩ ( S i × A i ) o f e dg es. Then for i 6 = j we hav e E A i ∩ E A j = ∅ . By Lemma 1 it follows that the i -th iter ation o f the a ttractor ca n be computed in O ( | E A i | ) time. Hence the total time for attractor co mputations over all iterations is d − 1 X i =0 O ( | E A i | ) = O ( | E | ) = O ( m ) , where the first equality fo llows since the edg es E A i and E A j are disjoint for i 6 = j . Obtaining the target sets. W e will now argue that the target sets p − 1 ( i ) ∩ S i can b e computed in O ( n ) time o ver all iter ations. Without loss of genera lity we assume that the set of states S a re nu mber ed 0 , 1 , . . . , n − 1 a nd the priority function p : S → [ d ] is g iven as an arr ay P [0 ..n − 1] of in teger s such that P [ i ] = p ( i ). The proc e dur e for obtaining the target sets will inv o lve several steps. W e present the steps below. 1. R enaming phase. First, we construct a renaming of the states such that sta tes in p − 1 ( i ) are nu mber ed low er than p − 1 ( j ) for i < j . Here is a O ( n ) time pr o cedure for r enaming. (a) Consider an a r ray of counters ct [0 ..d − 1] all initialized to 0, and arrays A [0] , A [1] , . . . , A [ d − 1 ] (each A [ i ] is an array and will cont a in s ta tes of priority i ). (b) The fir st s tep is as follows. for ( i := 0; i < n ; i := i + 1) { k = P [ i ]; j = ct [ k ]; A [ k ][ j ] = i ; ct [ k ] = ct [ k ] + 1; } This step assigns to the arr ay in A [ i ] the set o f states with priority i (in the same relative order) and also works in O ( n ) time. The counter ct [ i ] is the num b er of states with prior it y i . 5 (c) The r enaming step. W e now construct arrays B and C in O ( n ) time to sto r e renaming and the inv ers e rena ming . F o r simplicity let us assume ct [ − 1] = 0 and the pro cedure is as follows. for ( i := 0; i < d ; i := i + 1) for ( j := 0; j < ct [ i ]; j := j + 1) { B [ ct [ i − 1] + j ] = A [ i ][ j ]; C [ A [ i ][ j ]] = ct [ i − 1] + j ; } This crea tes the rena ming suc h that for B [0 .. ct [0] − 1] ar e states of priority 0 , then w e hav e sta tes of priority 1 for B [ ct [0] .. ct [1] − 1], and so on. The array C stores the inverse of the renaming, i.e., if B [ i ] = j , then C [ j ] = i . Moreov e r , though it is a nested lo op, since P d − 1 i =1 ct [ i ] = n this pro cedure also works in O ( n ) time. 2. In the renaming phase we ha ve obtained in O ( n ) time a renaming in the a rray B and the inv erse r enaming in the array C . Since rena ming and its inv erse, for a giv en state, c a n b e obtained in constant time 1 we can move bac k and for th the renaming witho ut increasing the time complexit y other than in constants. W e now obtain the set of states as targets requir ed for the a ttr a ctor computation of step 2.1 of Algo rithm 1 in total O ( n ) time across the whole computation. First, w e create a copy of B as an a rray D , and k e e p a global counter called g initialized to 0. W e modify the attractor computation in step 2.1 such that in the attractor computation when a state j is removed from the game graph, then D [ k ] is set to − 1 suc h that D [ k ] = j , (the en try of the arr ay D that represent state j is set to − 1). This is simply done as fo llows D [ C [ j ]] = − 1. This is a constant work for a state and hence the extra work in the attracto r co mputation of step 2.1 acro ss the who le c omputation is O ( n ). The co mputation to obtain the tar get for priority i (i.e., p − 1 ( i ) ∩ S i ), deno ted as pro cedure ObtainT ar gets , is describ ed b elow. The pro cedure ObtainT ar gets is called by Algorithm 1 with parameter i in step 2.1 to obtain p − 1 ( i ) ∩ S i . (a) W e hav e the global co unter g := 0 (initialized to 0 ) and the v alue of the global counter per sists across calls to the pro cedure ObtainT ar gets . W e present the pseudoco de for the pro cedure ObtainT ar gets to obtain in an arr ay T the set p − 1 ( i ) ∩ S i of states. The pro cedure assumes that when ObtainT ar gets ( i ) is in voked we hav e g = 0, if i = 0, a nd for i > 0, we hav e g = P i − 1 j =0 ct [ j ]. Also, for all j ∈ S \ S i we ha ve D [ C [ j ]] = − 1 (the set of s tates in S \ S i is set to − 1 in the attractor co mputation). The pro cedur e inv oked with i returns T as an array with states in p − 1 ( i ) ∩ S i , a nd sets g = P i j =0 ct [ j ]. ObtainT ar gets ( i ) k := 0; for ( j := 0; j < ct [ i ] − 1; j := j + 1) { if ( D [ j + g ] 6 = − 1) { T [ k ] = D [ j + g ]; k := k + 1; } } g := g + ct [ i ]; return T . 1 W e assume the random acce ss mo del, and an element in the arrays B and C can b e accessed in constan t time. 6 The work for a given i is O ( ct [ i ]) and since P d − 1 i =0 ct i = n , the total work to get the target sets ov er all iterations is O ( n ). This completes the O ( n + m ) = O ( m ) running time ana lysis for Algorithm 1. This yields the following result. Theorem 3 (Running ti me). Given a game gr aph G = (( S, E ) , ( S 1 , S 2 )) and pri ority function p : S → [ d ] , the sets W 1 (W eakParit yE ven ( p )) and W 2 (W eakParit yO dd( p )) c an b e c omput e d in O ( m ) time, wh er e m = | E | . Ac kno wl edgments. I thank Florian Horn fo r useful commen ts. References 1. D.A. Martin. Borel determinacy . Annals of Mathematics , 102(2):36 3–371, 1975. 2. W. Thomas. Languages, automata, and logic. In G. Rozenberg and A . Salomaa, editors, Handb o ok of F ormal L anguages , volume 3, Beyo n d W ords, chapter 7, pages 389–455. Springer, 1997. 7
Original Paper
Loading high-quality paper...
Comments & Academic Discussion
Loading comments...
Leave a Comment