Presentation is loading. Please wait.

Presentation is loading. Please wait.

Algorithmic Software Verification III. Finite state games and pushdown automata.

Similar presentations


Presentation on theme: "Algorithmic Software Verification III. Finite state games and pushdown automata."— Presentation transcript:

1 Algorithmic Software Verification III. Finite state games and pushdown automata

2 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: V 0 - positions where white has to play V 1 - positions where black has to play δ - encodes valid moves

3 Plays Game: G = (V 0, V 1, δ) Play: Any finite or infinite sequence of vertices p 0 q 0 p 1 q 1 p 2 q 2 … Reachability games: Given a target set T  V 0  V 1 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.

4 Strategies Game: G = (V 0, V 1, δ) Strategy for player 0: Function Str 0 : (V 0. V 1 )*  V 0 Strategy for player 1: Function Str 1 : (V 1. V 0 )*  V 1 Play according to Str 0 : p 0 q 0 p 1 q 1 p 2 q 2 … such that p 0  Str 0 (  ) p 1  Str 0 (p 0 q 0 ) …. p i+1  Str 0 (p 0 q 0 … p i q i ) Reachability games: Given T, Str 0 is a winning strategy for player 0 if every play according to Str 0 is winning.

5 The game problem Given a game G = (V 0, V 1, δ), 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.

6 The attractor-set method Given a game G = (V 0, V 1, δ), 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. W 0 := T while ( W 0 does not change ) { W 0 := W 0  { v  V 0 |  v’  W 0 : v  v’ }  { v  V 1 |  v’ : v  v’, v’  W 0 } Clearly, player 0 can win from W 0.

7 The attractor-set method Claim: W 0 is the exact set of winning positions for player 0. W 1 := ( V 0  V 1 ) \ W 0 Note first that W 1  T = Ø. For every v  V 0 in W 1, every edge from v stays within W 1 For every v  V 1 in W 1, there is some edge from v that stays within W 1 Winning strategy for player 1 from W 1 : At a position v  V 1, choose edge that stays within W 1 All plays according to this strategy stay in W 1 and Player 1 wins.

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

9 Algorithm to solve games Implement algorithm that computes W 0 : W 0 := T while ( W 0 does not change ) { W 0 := W 0  { v  V 0 |  v’  W 0 : v  v’ }  { v  V 1 |  v’ : v  v’, v’  W 0 } Naïve algorithm: Each round takes O(|G|) time Each round adds at least one node. Hence O(n 2 ).

10 Linear-time algorithm Given: G = (V 0, V 1, δ) and target T Set Pred[v] = { u | (u,v)  δ } for every v Set Count[v] = | {v’ | (v,v’)  δ } | for every v W 0 = Ø; for each v  T call add(v); output W 0 ; --------------------------------------- add(v) { if (v is in W 0 ) then return else add v to W 0 ; for each u in Pred[v] count[u] := count[u] – 1; if u  V 0 or (u  V 1 and count[u] = 0) add(u); }

11 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’ }

12 Pushdown automata emptiness Given : A = ( , Q, q_in, E, F) Question: Is L(A) empty? Reduces to solving reachability games: Construct game G = (V 0, V 1, δ) and T and v_in such that player 0 has a winning strategy from v_in iff L(A) is nonempty. V 0 = Q x Q V 1 = Q x Q x E x E v_in = {q_in } x F T = { (q,q) | q  Q}

13 Pushdown automata emptiness V 0 = Q x Q V 1 = 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’) |

14 Pushdown automata emptiness Vertices: n 2 + m 2 n Edges: m + m 2 n + m 2 n + m 2 n Solving the game in linear time gives O( |A| 3 ) algorithm for emptiness of pushdown automata.


Download ppt "Algorithmic Software Verification III. Finite state games and pushdown automata."

Similar presentations


Ads by Google