1 / 30

CS 385 Fall 2006 Chapter 6

CS 385 Fall 2006 Chapter 6. Building Control Algorithms for State Space Search Read 6.0- 6.2. Summary of Chapters 3 and 4. Problem solving is search through a set of problem states The state space model uses graph theory to represent the problem as states and transitions

joannwolfe
Download Presentation

CS 385 Fall 2006 Chapter 6

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS 385 Fall 2006Chapter 6 Building Control Algorithms for State Space Search Read 6.0- 6.2

  2. Summary of Chapters 3 and 4 • Problem solving is search through a set of problem states • The state space model uses graph theory to represent the problem as states and transitions • Characteristics of state space search a. Solution is a path from start state to a goal. b. Search systematically tests alternative paths to the goal c. Backtracking allows recovery from paths that fail to reach the goal. d. Lists track states under consideration. e. DFS uses a stack, BFS uses a queue, BFS uses a priority queue

  3. Formal Tools Predicate Calculus: • A language for capturing complex semantic information and for reasoning based on that information. (formal semantics and inference rules). • One could formulate a problem and perform reasoning by hand. State-Space Search: • States of a problem are nodes, problem transitions are arcs, a solution is a path from start node to goal. • Methods of searching state spaces (dfs, bfs, heuristics). • Data-driven versus goal-driven (where on the graph do you start).

  4. Tools (cont) Now: We have a formal way to describe a problem using predicate calculus. Next: Automate the search process via an algorithm (pattern- directed search) which will be applied to a space of logical inferences. • Recursion-based search • Production systems • Blackboard architecture (omit)

  5. 6.1.1 Recursion A natural for search Algorithms are easier to write easier to analyze formally Recursion consists of a base case a recursive component that resolves into a smaller version of the problem and ultimately to the base case

  6. Recursion for List Membership function member(item, tail) //Pascal syntax begin if list is empty then return(fail) else if item = first item of list then return(success) else begin tail=list with first item removed member(item, tail) end end member(X, [X|T]). //PROLOG member(X,[Y|T]) :- member(X,T).

  7. procedure depth-first search open = [start] closed = [ ] while open ≠ [ ] do remove leftmost state of open, call it X if X is goal, return success. generate all children of X put X on closed put children of X not already on open or closed on the left end of open function depthsearch(current_state) if current_state is a goal then return success add current_state to closed while current_state has unexmd children child := next unexmd child if depthsearch(child) = success then return(success) return(fail) DFS without/with Recursion

  8. goal= 6: open closed [1] [ ] [2,3] [1] [4,5,3] [2,1] [5,3] [4,2,1] 1 [3] [5,4,2,1] 2 3 [6, 7] 4 5 6 7 call closed depthsearch(1) [1] depthsearch(2) [2,1] depthsearch(4) [4,2,1] depthsearch(5) [5,4,2,1] depthsearch(3) depthsearch(6) ←success ←success Trace DFS without/with Recursion Notes: 1. The path in maintained in the nested procedure calls. 2. To keep track of the path, retrieve at each successful exit. 3. The open list on left is kept by the procedure activations (e.g. you retain the information necessary to go back to pick up other children). 4. Children are not generated until needed. This is good if it is expensive to generate them.

  9. Represent the state space: % a binary tree move(1, 2). move(1, 3). move(2, 4). move(2, 5). move(3, 6). move(3, 7). %depthfirst with no output dfs1(X, X). dfs1(X, Y) :- move(X, Z), dfs1(Z, Y). Trace: move(1,5)? (1): move(1,2) dfs(2,5)? (3): move(2,4) dfs(4,5) fail (4): move(2,5) dfs(5,5) succeed Problems: no output %depthfirst with output dfs2(X, Y) :- move(X, Z), write('trying node '), write(Z), nl, dfs2(Z, Y). DFS in PROLOG?

  10. 6.1.2 Pattern-Directed Search Apply recursive search to develop a general search procedure for predicate calculus. How is goal-directed search for predicate calculus recursive? identify subgoal(s) that imply the goal recur on the subgoal(s) success if a subgoal matches a fact in the knowledge base

  11. This leaves out two possibilities: • current goal is negated ( p) • - -success if the goal fails • current goal is a disjunction (p..) • -- success if all are satisfied with • consistent bindings • And directions for consistent bindings • Rewritten on p.198

  12. a b c a  b → d a  c → e b  d → f f→ g a  e → h goal(h) (unifies with a conclusion apply to premise e a) goal(e) (unifies with a conclusion apply to premise c  a) goal(c) (unifies with a fact) true goal(a) (unifies with a fact) true ← e is true goal(a) (unifies with a fact) true ← h is true Prove h using pattern_search:

  13. Production Systems Pattern-directed search: based on a set of production rules (similar to but different from a rep. in predicate calculus). Production system: a system for pattern-directed control of problem solving. A production system consists of 1. A set of production rules (productions) 2. Working memory 3. Recognize/act cycle

  14. 6.2 Production Systems 1. A set of production rules (productions) (condition/action) pairs condition: when the action can be applied action: the problem-solving step (add something to known facts or do something) if it is cold or rainy then drive to work p(x)q(x) 2. Working memory the current state of the world what's true production rules can alter this

  15. Production Systems 3. Recognize/act cycle match patterns in working memory against conditions of production rules. conflict set = those rules with matches select one member of conflict set to fire (perform the action) this will change the contents of the working memory Conflict resolution: pick which rule to fire. Often the first whose condition matches current state. Pure production systems: no way to recover from dead ends (backtrack)

  16. Rewrite Rules for Sorting a String Rewrite rules for sorting a string (productions) 1. ba  ab 2. ca  ac 3. cb  bc Task: sort cbaca Iteration Working memory Conflict set Rule fired 0 cbaca 1 2 3 3 1 bcaca 2 2 2 bacca 1 2 2 3 bacac 1 2 2 4 baacc 1 1 5 abacc 1 1 6 aabcc

  17. Using the Rules in in Reverse Order Rewrite rules for sorting a string (productions) 1. ba  ab 2. ca  ac 3. cb  bc Iteration Working memory Conflict set Rule fired 0 cbaca 1 2 3 3 1 bcaca 2 2 2 bacca 1 2 2 3 bacac 1 2 2 4 baacc 1 1 5 abacc 1 1 6 aabcc

  18. Production System: the Knights Tour Can a knight (chess) visit each square on a board once? productions: knight on 1  move knight to 8, ... Is there a path from one square to another? control algorithm: X path(X,X) X,Y path(X,Y) ←  Z [move(X,Z)  path(Z,Y)]

  19. Knights Tour Is there a path from 1 to 3? working memory

  20. Knights Tour Is there a path from 2 to 3? working memory

  21. Production Systems Newell and Simon: production systems are a model for how humans solve problems. Why? rules  long term memory, working memory (state of the world)  short term memory

  22. Control of Search in Production Systems Review: production systems more general than pattern directed search sometimes easier to formulate. This section: production systems allow opportunities to add heuristic control to search. (pattern-directed as implemented by pure PROLOG allowed arrangement and structure of rules, but not much else) 1. Data driven versus goal driven: compare Figures 6.9 and 6.10 on next slides Actually many strategies are combinations. MYCIN: starts with symptoms and forward chains (data driven). If at some point it suspects a disease, backward chain (goal driven).

  23. Figure 6.9: Data-driven search in a production system.

  24. Figure 6.10: Goal-driven search in a production system.

  25. Control of Search in Production Systems 2. Through the rule structure. E.g. the order of premises. Compare gpa_over_3(X)  application_finished(X)  candidate(X) application_finished(X)  gpa_over_3(X)  candidate(X) Harder to finish application than to check the gpa Checking gpa first saves effort. 3. Through conflict resolution. Note, move(1,8) is before move(1.6) in knight’s tour. Often conflict resolution is by order of the rules so that matters. knight0: no control, path(1,7) works, path(1,4) and path(1,9) loop knight1: put a footstep where you have been. knight2: keep a list.

  26. Knights Tour in PROLOG knight0.pro: %productions move(1,6). move(1,8). move(2,7). move(2,9). ... %control path(Z,Z). path(X,Y):- move(X,W), path(W,Y). Trace path(1,7): path(1,7): move(1,6) try path(6,7) move(6,1) try path(7,2) move(7,6) try path(6,2) Whoops.

  27. Knights Tour in PROLOG Resolution (knight1.pro): path(X,Y):- move(X,W), not(been(W)), assert(been(W)), path(W,Y). But this adds been(6) to the database Try path(1,6) twice and the second time fails knight2.pro: path(Z,Z,L). path(X,Y,L):- move(X,Z), not(member(Z, L)), path(Z, Y, [Z|L]).

  28. Trace path(1,7, [1]): path(1, 7, [1]). move(1, 6) not member(6, [1]) succeeds path(6, 7, [6, 1] move(6, 1) not member(1, [1]) fails move(6,7) not member(7, [6,1]) succeeds path(7, 7, [7, 6, 1]) writelist([7, 6, 1]) Ch 15 has a longer one. Try yourself. How does the result get printed in knight2.pro? • knight2.pro • move(1,6). • move(1,8). • move(2,7). • move(2,9). • move(3,4). • move(3,8). • move(4,3). • move(4,9). • path(Z,Z,L). • path(X,Y,L):- • move(X,Z), • not(member(Z, L)), • path(Z, Y, [Z|L]). move(6,1). move(6,7). move(7,2). move(7,6). move(8,1) move(8,3). move(9,2). move(9,4).

  29. Blackboard Architecture (omit) Cooperating knowledge sources that share information and results Communication through a blackboard. Really a way of breaking a problem into smaller ones

  30. Homework 1a 4. Draw the nodes and arcs for the legal moves. Each node will be a 4-tuple indicating who performs each of the four tasks. The tuples should be ordered by decreasing importance (fire, cakes, tea, and poetry). For example, (c s s e) indicates the child is feeding the fire, the servant is serving cakes and pouring tea, and the elder is reading poetry, 5. Complete part a in full detail. For b and c it suffices to list the order in which states are visited and the current list of closed states. Redo 5a. using the production system notation, producing a trace of execution similar to the tables on p. 169 7 for 2, not 8 of the moves. 9 10

More Related