140 likes | 280 Vues
Algorithmic Software Verification. III. Finite state games and pushdown automata. Finite state games. G = ( V 0 , V 1 , δ) V 0 finite set of player 0 nodes V 1 finite set of player 1 nodes δ ( V 0 x V 1 ) ( V 1 x V 0 ) bipartite transition relation Example: Chess:
E N D
Algorithmic Software Verification III. Finite state games and pushdown automata
Finite state games G = (V0, V1, δ) V0finite set of player 0 nodes V1finite set of player 1 nodes δ (V0x V1) (V1x V0) bipartite transition relation Example: Chess: V0 - positions where white has to play V1 - positions where black has to play δ - encodes valid moves
Plays Game: G = (V0, V1, δ) Play: Any finite or infinite sequence of vertices p0q0 p1q1 p2q2 … Reachability games: Given a target set T V0 V1 A play w is winning for player 0 if it hits T; i.e. there exists some vertex in w which is in T. Example: A particular game played between Kasparov and DeepBlue is a play. T – the set of positions where white has check-mated black.
Strategies Game: G = (V0, V1, δ) Strategy for player 0: Function Str0: (V0. V1)* V0 Strategy for player 1: Function Str1: (V1. V0)* V1 Play according to Str0: p0 q0 p1 q1 p2 q2 … such that p0 Str0( ) p1 Str0(p0 q0) …. pi+1 Str0(p0 q0 … pi qi ) Reachability games: Given T, Str0 is a winning strategyfor player 0 if every play according to Str0 is winning.
The game problem • Given a game G = (V0, V1, δ), a target set T and an initial position p, does Player 0 have a winning strategy to reach T from p? Example: Let T be the set of winning positions for white (i.e positions where white has check-mated black). Find whether starting from the initial board position, player white has a strategy that will win every game. This problem is decidable in linear time.
The attractor-set method • Given a game G = (V0, V1, δ), a target set T and an initial position p, does Player 0 have a winning strategy to reach T from p? Construct the obvious set of positions from which player 0 can win. W0 := T while ( W0 does not change ) { W0 := W0 { v V0 | v’ W0 : v v’ } { v V1 | v’ : v v’, v’ W0} Clearly, player 0 can win from W0.
The attractor-set method Claim: W0 is the exact set of winning positions for player 0. W1 := ( V0 V1 ) \ W0 Note first that W1 T = Ø. For every v V0 in W1, every edge from v stays within W1 For every v V1 in W1, there is some edge from v that stays within W1 Winning strategy for player 1 from W1 : At a position v V1, choose edge that stays within W1 All plays according to this strategy stay in W1 and Player 1 wins.
Properties of reachability games From every position, either player 0 or player has a winning strategy. (Determinacy) A strategy is memoryless if it depends only on the current state of the game and not on the entire history. If player i has a winning strategy from a position, then player i has a memoryless winning strategy from the position as well.
Algorithm to solve games Implement algorithm that computes W0: W0 := T while ( W0 does not change ) { W0 := W0 { v V0 | v’ W0 : v v’ } { v V1 | v’ : v v’, v’ W0 } Naïve algorithm: Each round takes O(|G|) time Each round adds at least one node. Hence O(n2).
Linear-time algorithm Given: G = (V0, V1, δ) and target T Set Pred[v] = { u | (u,v) δ } for every v Set Count[v] = | {v’ | (v,v’) δ } | for every v W0 = Ø; for each v T call add(v); output W0; --------------------------------------- add(v) { if (v is in W0 ) then return else add v to W0; for each u in Pred[v] count[u] := count[u] – 1; if u V0 or (u V1 and count[u] = 0) add(u); }
Pushdown automata (, Q, q_in, E, F) Q – finite set of states q_in -- initial state -- stack alphabet E: { q –a, push e q’ a , e q –a, pop e q’ q –a q’ }
Pushdown automata emptiness Given : A = (, Q, q_in, E, F) Question: Is L(A) empty? Reduces to solving reachability games: Construct game G = (V0, V1, δ) and T and v_in such that player 0 has a winning strategy from v_in iff L(A) is nonempty. V0 = Q x Q V1 = Q x Q x E x E v_in = {q_in } x F T = { (q,q) | q Q}
Pushdown automata emptiness V0 = Q x Q V1 = Q x Q x E x E v_in = {q_in } x F T = { (q,q) | q Q} (q,q’) (q1, q’) if A has transition q –a q1 (q,q’) (q, q’, e1, e2) where e1 is a push-transition of the form q –a, push e q1 and e2 is a pop-transition of the form q1’ --a, pop e q’’ (q, q’, e1, e2) (q1, q1’) | | Player 1 moves (q, q’, e1, e2) (q’’, q’) |
Pushdown automata emptiness Vertices: n2 + m2n Edges: m + m2n + m2n + m2n Solving the game in linear time gives O( |A|3 ) algorithm for emptiness of pushdown automata.