Heuristic Search
Transcription
Heuristic Search
Heuristic Search Blai Bonet Representation of state spaces Universidad Sim´ on Bol´ıvar, Caracas, Venezuela c 2015 Blai Bonet Goals for the lecture Lecture 2 The representation problem • Learn about the representation problem for state-spaces (graphs) • Introduce three approaches for representation: explicit, black-box How do we represent state spaces in practical terms? (implicit), declarative (implicit) • Learn about different explicit representations and their space How do we cope with the combinatorial explosion of states? requirements • Learn about the black-box representation and API • Learn about declarative representations c 2015 Blai Bonet Lecture 2 c 2015 Blai Bonet Lecture 2 Three approaches for representation Explicit representation States have no “internal” structure: they are opaque objects We consider three representations of state spaces: – Explicit representation The graph can be represented either by an adjacency matrix, by an incidence matrix, or by adjacency lists – Implicit black-box representation In all cases, the representation is – Implicit declarative representation – Flat meaning that states have no structure – Polynomial in size in terms of number of vertices and edges c 2015 Blai Bonet Lecture 2 Explicit representation: example c 2015 Blai Bonet Lecture 2 Explicit representation: adjacency matrix 3 3 4 4 6 2 6 5 2 1 5 1 Multi-graph G = hV, Ei with vertices V = {1, 2, 3, 4, 5, 6} and edges E = {(1, 1), (1, 2), (1, 5), (2, 3), (2, 5), (3, 2), (4, 3), (4, 6), (5, 4), (5, 4), (6, 4)} c 2015 Blai Bonet Lecture 2 1 1 0 0 0 1 Adjacency matrix = 0 0 0 0 0 0 c 2015 Blai Bonet 0 1 0 1 0 0 0 0 0 0 2 1 1 1 0 0 0 0 0 0 0 1 0 0 Lecture 2 Explicit representation: incidence matrix 4 e11 e4 e2 1 e3 e10 e11 5 1 e3 e1 e1 Incidence matrix = 0 −1 −1 0 0 0 0 0 0 0 0 0 1 0 −1 −1 1 0 0 0 0 0 0 0 0 0 1 −1 0 0 1 0 0 0 0 0 0 0 0 −1 1 −1 −1 −1 0 0 1 1 0 0 0 0 0 1 1 0 0 0 0 0 0 1 −1 0 0 0 c 2015 Blai Bonet 6 e8 e4 e2 5 4 e6 2 e10 e7 e9 3 e5 6 e8 e6 2 e7 e9 3 e5 Explicit representation: adjacency lists vertex 1 : vertex 2 : vertex 3 : Adjacency lists = vertex 4 : vertex 5 : vertex 6 : Lecture 2 e1 , e2 , e3 e4 , e5 e6 e7 , e9 e10 , e11 e8 c 2015 Blai Bonet Explicit representation: trade offs Lecture 2 Black-box representation Adjacency matrix: Structure of the graph is wired into functions that provide the necessary information to explore the state space – space = O(V 2 ) – time for scan of vertex successors = O(V ) Incidence matrix: This information is: – space = O(V E) – initial state sinit – time for scan of vertex successors = O(E) – goal states SG Adjacency lists: – applicable actions and successor states for given state – space = O(V + E) – time for scan of vertex successors = O(δ(v)) A succinct and efficient representation is feasible when states are structures that store information All are infeasible for big problems such as the 15-puzzle! c 2015 Blai Bonet Lecture 2 c 2015 Blai Bonet Lecture 2 Black-box representation Black-box representation: API Structure of the graph is wired into functions that provide the necessary information to explore the state space 1 typedef unsigned Action 2 3 4 This information is: 5 6 – init(): provides the initial state 7 tells if state is goal 9 8 – is-goal(): – successors(): struct AbstractState { bool is-goal() list<pair<State, Action> > successors() } struct DerivedState : AbstractState { % ... [internal representation of concrete state] 10 bool is-goal() list<pair<State, Action> > successors() 11 provides successor states and actions 12 13 } 14 15 DerivedState init() % returns initial state A succinct and efficient representation is feasible when states are structures that store information c 2015 Blai Bonet Lecture 2 Black-box representation: example for 15-puzzle 1 2 3 struct State15Puzzle : AbstractState { char pos[16] % pos[i] contains the ’tile’ in ith-position char blank % contains position of blank c 2015 Blai Bonet Lecture 2 Black-box representation: space vs. time trade-offs Typically, states can be represented in two manners: 4 bool is-goal() { for i = 0 to 15 if pos[i] != i return false return true } 5 6 7 8 9 – Space efficient: compact form that permits to store more states in available memory. However, operations need to ‘decode’ and ‘encode’ states and thus consume time 10 list<pair<State, Action> > successors() 11 12 – Time efficient: operations are efficient since there is explicit representation, but states consume more space } This is a space-consuming representation because it requires 17 × 8 = 136 bits per state Best representation depends on the chosen algorithm A state for the 15-puzzle can be stored in 64 bits (16 positions requiring 4 bits each) . . . c 2015 Blai Bonet Lecture 2 c 2015 Blai Bonet Lecture 2 Black-box representation: example for 15-puzzle 1 2 Declarative representation State spaces are described using a high-level and general representation languages struct State15Puzzle2 : AbstractState { uint32 tiles[2] % tiles occupying positions (in order) 3 bool is-goal() { return (tiles[0] == 0x01234567) & (tiles[1] == 0x89ABCDEF) } 4 5 6 – generality and flexibility 7 list<pair<State, Action> > successors() 8 9 Representation languages provide: } – abstraction that hide low-level implementation Space-efficient representation requiring 64 bits per state (not the best though...) Representation languages lack: Space efficiency doesn’t directly translate into time performance Active research topic is to reduce gap in efficiency between black-box and declarative representions c 2015 Blai Bonet – state-of-the-art efficiency on selected problems Lecture 2 c 2015 Blai Bonet Declarative representation: examples Lecture 2 Propositional representation of states States represent situations or configuration of the environment – PSVN: production systems on fixed-length vectors of labels A fixed collection of propositions (atoms) can be used to describe all states in the model – STRIPS: propositional representation of planning problems – SAS+ : multi-valued variable representation of planning problems Each state is described by a valuation of the atoms c 2015 Blai Bonet Lecture 2 c 2015 Blai Bonet Lecture 2 Propositional representation of blocksworld Propositional representation of blocksworld D A B C D A B C Atoms: Atoms: Atoms: Atoms: Atoms: Valuation: Valuation: Valuation: Valuation: Valuation: Clear(A), Clear(B), Clear(C), On(A,A), On(A,B), On(A,C), On(B,A), On(B,B), On(B,C), On(C,A), On(C,B), On(C,C), OnTable(A), OnTable(B), OnTable(C) Clear(A), Clear(B), Clear(C), On(A,A), On(A,B), On(A,C), On(B,A), On(B,B), On(B,C), On(C,A), On(C,B), On(C,C), OnTable(A), OnTable(B), OnTable(C) State s = { Clear(A), Clear(C), On(A,B), OnTable(B), OnTable(C) } c 2015 Blai Bonet Lecture 2 c 2015 Blai Bonet Propositional representation of blocksworld Lecture 2 STRIPS Language based on propositional variables: B C A – finite set F of propositional variables (atoms) – an initial state I ⊆ F – a goal description G ⊆ F – finite set A of operators; each operator a ∈ A given by Valuation: Valuation: Valuation: Valuation: Valuation: Clear(A), Clear(B), Clear(C), On(A,A), On(A,B), On(A,C), On(B,A), On(B,B), On(B,C), On(C,A), On(C,B), On(C,C), OnTable(A), OnTable(B), OnTable(C) I precondition pre ⊆ F tells when action is applicable I positive effects add ⊆ F tells what becomes true I negative effects del ⊆ F tells what becomes false – non-negative costs c(a) for applying actions a ∈ A State s = { Clear(B), On(B,C), On(C,A), OnTable(A) } c 2015 Blai Bonet Lecture 2 c 2015 Blai Bonet Lecture 2 STRIPS: blocksworld STRIPS: blocksworld A B C B C A A B C B C A initial state goal state initial state goal state Atoms: Clear(?x), On(?x,?y), OnTable(?x) I = { Clear(A), Clear(C), On(A,B), OnTable(B), OnTable(C) } Actions: Move(?x,?y,?z), MoveToTable(?x), MoveFromTable(?x,?y) G = { On(B,C), On(C,A) } c 2015 Blai Bonet Lecture 2 c 2015 Blai Bonet STRIPS: blocksworld A B C initial state Lecture 2 STRIPS: state space for blocksworld Init B C A A B C C A B A B C ··· goal state A B C Move(A,B,C): A B C ··· A B C B A C C A B B A C C A B – pre = { Clear(A), Clear(C), On(A,B) } – add = { Clear(B), On(A,C) } ··· ··· ··· – del = { Clear(C), On(A,B) } B C A C A B ··· ··· A B C Goal c 2015 Blai Bonet Lecture 2 c 2015 Blai Bonet Lecture 2 Example: Blocksworld in STRIPS (PDDL) STRIPS: semantics (define (domain Blocksworld) (:types block) (:predicates (clear ?x - block) (on ?x ?y - block) (ontable ?x - block)) (:action move :parameters (?x ?y ?z - block) :precondition (and (clear ?x) (clear ?z) (on ?x ?y)) :effect (and (not (clear ?z)) (not (on ?x ?y)) (on ?x ?z) (clear ?y))) (:action move_to_table :parameters (?x ?y - block) :precondition (and (clear ?x) (on ?x ?y)) :effect (and (not (on ?x ?y)) (clear ?y) (ontable ?x))) Problem P = hF, A, I, G, ci defines model hS, A, sinit , SG , f, ci: – states S are all the 2n valuations to atoms in F , |F | = n – initial state sinit assigns true to all p ∈ I and false to all p ∈ /I – goal states are assignments satisfying the goals in G – executable actions at state s are A(s) = {a : pre ⊆ s} (:action move_from_table :parameters (?x ?y - block) :precondition (and (ontable ?x) (clear ?x) (clear ?y)) :effect (and (not (ontable ?x)) (not (clear ?y)) (on ?x ?y))) – outcome f (s, a) defined by effects: f (s, a) = (s \ del) ∪ add ) – non-negative action costs c(a) (define (problem bw_3_1) (:domain Blocksworld) (:objects A B C - block) (:init (clear A) (clear C) (on A B) (ontable B) (ontable C)) (:goal (and (on B C) (on C A))) ) Model is exponential in size of problem P (e.g. blocksworld) c 2015 Blai Bonet Lecture 2 Summary • Approaches for representation: explicit, black-box, declarative • Explicit representation not generally feasible for state-space models • Black-box reperesentation is efficient and implemented directly into programming language • Required API for black-box representation • STRIPS example on the blocksworld c 2015 Blai Bonet Lecture 2 c 2015 Blai Bonet Lecture 2