1 / 73

Problem Solving

Problem Solving. Topics. Problem Solving Searching Methods Game Playing. Introduction. Problem solving is mostly based on searching.

mabli
Download Presentation

Problem Solving

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. Problem Solving

  2. Topics • Problem Solving • Searching Methods • Game Playing

  3. Introduction • Problem solving is mostly based on searching. • Every search process can be viewed as a traversal of a directed graph in which each node represents a problem state and each arc represents a relationship between the states represented by the nodes it connects. • The search process must find a path through the graph, starting at an initial state and ending in one or more final states. The graph is constructed from the rules that define the allowable moves in the search space. Most search programs represent the graph implicitly in the rules to avoid combinatorial explosion and generate explicitly only those parts that they decide to explore.

  4. Introduction • Goal : a description of a desired solution (may be a state (8-puzzle) or a path (traveling salesman)). • Search space: set of possible steps leading from initial conditions to a goal. • State: a snapshot of the problem at one stage of the solution. The idea is to find a sequence of operators that can be applied to a starting state until a goal state is reached. • A state space: the directed graph whose nodes are states and whose arcs are the operators that lead from one state to another. • Problem solving is carried out by searching through the space of possible solutions for ones that satisfy a goal.

  5. Example: Water jug problem • Given two jugs one 4 gallons and the other 3 gallons. The goal is to get 2 gallons in 4 gallon jug. Assumptions: • You can fill the jug from the pump • You can pour water out of the jug onto the ground • You can pour water from one jug to another

  6. Example: Water jug problem State space representation

  7. Search Five important issues that arise in search techniques are: • The direction of the search • The topology of the search process • Representation of the nodes • Selecting applicable rules • Using heuristic function to guide the search

  8. The Direction of the Search • Forward : Data directed search. Start search from the initial state. To reason forward, the left sides (the preconditions) are matched against the current state and the right sides (the results) are used to generate new nodes until the goal is reached • Backward: Goal directed search. Start search from the goal state. To reason backward the right sides are matched against the current node and the left sides are used to generate new nodes representing new goal states to be achieved.

  9. The Direction of the Search Factors influencing the choice between forward vs. backward chaining are: • relative number of goal states to start states – move from the smaller set of states to the larger • branching factor – move in the direction with the lower branching factor • explanation of reasoning – proceed in the direction that corresponds more closely with the way the user thinks.

  10. The Direction of the SearchExamples Branching factor In theorem proving goal state is the theorem to be proved and the initial state is the set of axioms. • From small set of axioms large number of theorems can be proved. This large set of theorems must go back to the small set of axioms. Branching factor is greater going forward from axioms to theorems. Backward reasoning is more appropriate • If the branching factor is same in both directions then relative number of start states to goal states determine the direction of search. • Bi-directional search, start from both ends and meet somewhere in between. The disadvantage of this technique is search may bypass each other.

  11. Explanation of reasoning MYCIN program that diagnoses infectious diseases uses backward reasoning to determine the cause of patient's illness. A doctor may reason as follows: If an organism has a set of properties (lab results) then it is likely that the organism is X. Even though the evidence is most likely documented in the reverse direction (IF (ORGANISM X) (PROPERTIES Y)) CF • The rules justify why certain tests should be performed.

  12. The Topology of the Search • Trees

  13. The Topology of the Search • Graphs

  14. The topology of the search • Check if the generated node already exists • If not, add the node • If exists, then do: • Set the node that is being expanded to point to the already existing node corresponding to its successor, rather than to the new one. The new one can be thrown away.  • If looking for the best path, check if the new path is better. If worse do nothing. If better record the new path as the correct path to use to get to the node, and propagate the corresponding change in cost down through successor nodes as necessary. Disadvantage of this topology is that cycles may occur and there is no guarantee for termination

  15. Representation of the nodes • Arrays • Ordered pairs • Predicates

  16. Representation of the nodes State: location of 8 number tiles Operators: blank moves left, right, left or down Goal test: state matches the configuration on the right Path cost: each step cost 1, i.e. path length for search tree depth.

  17. Representation of the nodes • Possible state representations in LISP (0 is the blank) • (0 2 3 1 8 4 7 6 5 ) • ((0 2 3) (1 8 4) (7 6 5)) • ((0 1 7) (2 8 6) (3 4 5)) • The representation depends on: how easy to compare,operate on, and store (size).

  18. Goal Test >(defvar *goal-state* ‘(1 2 3 8 0 4 7 6 5 )) >(equal *goal-state* ‘(1 2 3 8 0 4 7 6 5 )) t

  19. Operators Functions from state to subset of states • drive to neighboring city • place piece on chess board • add person to meeting schedule • slide a tile in 8-puzzle Matching Conflict resolution: • order (priority) • recency • Indexing

  20. Using heuristic function to guide the search • It is frequently possible to find rules which will increase the chance of success. Such rules are termed heuristics and a search involving them is termed a heuristic search. • A heuristic function is a function that maps from problem state description to measure of desirability • Heuristics for the 8-puzzle problem could be: • the number of displaced tiles • distance of displaced tiles

  21. Implementing heuristic evaluation functions example: 8-puzzle fails to distinguish 2 8 3 1 6 4 7 5 Start Goal more accurate (1) (2) (3) (1) tiles out of place (2) sum of distance out of place (3) 2*number of direct tile reversals

  22. Evaluation of Search Strategies • Time complexity: how many nodes expanded so far? • Space complexity: how many nodes must be stored in node-list at any given time? • Completeness: if solution exists, guaranteed to be found? • Optimality: guaranteed to find the best solution?

  23. Components of Implicit State-Space Graphs There are three basic components to an implicit representation of a state-space graph. • A description with which to label the start node. This description is some data structure modeling the initial state of the environment. • Functions that transform a state description representing one state of the environment into one that represents the state resulting after an action. These functions are usually called operators. When an operator is applied to a node, it generates one of that node’s successor’s. • A goalcondition, which can be either a True-False valued function on state descriptions or a list of actual instances of state descriptions that correspond to goal states.

  24. Types of Search There are three broad classes of search processes: • Uninformed- Blind Search- • There is no specific reason to prefer one part of the search space to any other, in finding a path from initial state to goal state. • systematic, exhaustive search • depth-first-search • Breadth-first-search

  25. Types of Search 2) Informed – Heuristic search - there is specific information to focus the search. • Hill climbing • Branch and bound • Best first • A* 3) Game playing – there are at least two partners opposing to each other. • Minimax (a, b pruning) • Means ends analysis

  26. Search Algorithms • Task • find solution path thro’ problem space • keep track of paths from start to goal nodes • define optimal path if > 1 solution (circumstances) • avoid loops (prevent reaching goal)

  27. Depth-first search Uses generate and test strategy. Nodes are generated by applying the applicable rules. Then, each generated node is tested if it is the goal. Nodes are generated in a systematic form. It is an exhaustive search of the problem space. • Form a one element queue consisting of the root node • Until the queue is empty or the goal has been reached, determine if the first element in the queue is the goal node. • If the first element is the goal do nothing. • If the first element is not the goal node remove the first element from the queue and add the first element's children if any to the front of the queue. • If the goal node has been found announce success, otherwise announce failure.

  28. Depth-first search - lists: keep track of progress through state space - open states generated but children not examined - closed states already examined begin open := [Start] /initialise close := []; while open <> [] do begin remove leftmost state from open, call it X; if X is a goal then return (success) else begin generate children of X; put X on close; eliminate children of X on open or close; /loop check put remaining children on the left end of open /queue end end; return (failure) /no states left end.

  29. Depth-first search Node visit order: 1 2 4 8 9 5 10 11 3 6 12 13 7 14 15 Queuing function: enqueue at left

  30. Depth-first search • Evolution of the closed and open lists • [1] – [] • [2 3] – [1] • [4 5 3] – [1 2 ] • [8 9 5 3 ] – [1 2 4] • ……………….

  31. Depth-first Evaluation Branching factor b, depth of solutions d, max depth m: • Incomplete: may wonder down the wrong path. Bad for deep and infinite depth state space • Time: bm nodes expanded (worst case) • Space: bm (just along the current path) • Does not guarantee the shortest path. Good when there are many shallow goals.

  32. Breadth-first search • It will first explore all paths of length one, then two and if a solution exists it will find it at the exploration of the paths of length N. There is a guarantee of finding a solution if one exists. • It will find the shortest path from the solution, it may not be the best one.

  33. Breadth-first search The algorithm: 1. Form one element queue consisting of the root node 2. Until the queue is empty or the goal has been reached, determine if the first element in the queue is the goal node. a) If the first element is the goal do nothing. b) If the first element is not the goal node remove the first element from the queue and add the first element's children if any to the back of the queue. 3. If the goal node has been found announce success, otherwise announce failure.

  34. Breadth-first search Breadth-first search procedure begin open := [Start] /initialise close := []; while open <> [] do begin remove leftmost state from open, call it X; if X is a goal then return (success) else begin generate children of X; put X on close; eliminate children of X on open or close; /loop check put remaining children on the right end of open /queue end end; return (failure) /no states left end.

  35. Breadth-first search • Node visit order (goal test): 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 • Queuing function: enqueue at end ( add expanded node at the end of the list)

  36. Breadth-first search • Evolution of the open and closed lists • [1] – [ ] • [2 3 ] – [ 1 ] • [3 4 5 ] – [1 2 ] • [4 5 6 7 ] – [1 2 3 ] …………..

  37. Implementing Breadth-First and Depth-First Search The lisp implementation of breadth first search maintains the open list as a first in first out (FIFO) structure. (defun breadth-first () (cond ((null *open*) nil) (t (let ((state (car *open*))) (cond ((equal state *goal*) ‘success) (t (setq *closed* (cons state *closed*)) (setq *open* (append (cdr *open*) (generate-descendants state *moves*))) ;*moves*:list of the funcs that generate the moves. (breadth-first)))))))

  38. Implementing Breadth-First and Depth-First Search (defun run-breadth (start goal) (setq *open* (list start)) (setq *closed* nil) (setq *qoal* goal) (breadth-first)

  39. Implementing Breadth-First and Depth-First Search generate-descendants takes a state and returns a list of its children. (defun generate-descendants (state moves) (cond ((null moves) nil) (t (let (child (funcall (car moves) state)) (rest (generate-descendants state (cdr *moves*)))) (cond ((null child) rest) ((member child rest :test #‘equal) rest) ((member child *open* :test #‘equal) rest) ((member child *closed* :test #‘equal) rest) (t (cons child rest))))))) By binding the global variable *move* to an appropriate list of move functions this search algorithm may be used to search any state space in breadth first search fashion.

  40. Breadth-first Evaluation • Branching factor b, depth of solution d: • Complete: it will find the solution if it exists • Time. 1 + b + b2 + …+ bd • Space: bkwhere k is the current depth • Space is more problem than time in most cases • Time is also a major problem nonetheless

  41. Heuristic Search Reasons for heuristics - impossible for exact solution, heuristics lead to promising path - no exact solution but an acceptable one - fallible due to limited information Intelligence for a system with limited processing resources consists in making wise choices of what to do next Heuristics = Search Algorithm + Measure

  42. Hill climbing Hill climbing is depth first search with a heuristic measurement that orders choices as nodes are expanded.The algorithm is the same only 2b differs slightly. 1. Form a one element queue consisting of the root node 2. Until the queue is empty or the goal has been reached, determine if the first element in the queue is the goal node. a) If the first element is the goal do nothing. b) If the first element is not the goal node remove the first element from the queue, sort the first elements children, if any by estimated remaining distance, and add the first element's children if any to the front of the queue. 3. If the goal node has been found announce success, otherwise announce failure.

  43. Hill climbing

  44. Hill climbing Problems that may arise: • A local maximum, is a state that is better than all its neighbors, but is not better than some other states farther away. At a local maximum, all moves appear to make things worse. • A plateau, A whole set of neighboring states have the same value.It is not possible to determine the best direction. • A ridge,. Higher than surrounding area but can not be traversed by single move in any one direction.

  45. Hill climbing Some ways of dealing with these: • Backtrack: local maximum • Make a big jump in one direction to try to get to new section of search space (plateau) • Apply two or more rules before doing the test. This corresponds to moving in several directions at once (ridges).

  46. Best-first Search Best-first search is a combination of depth-first and breadth-first search algorithms. Forward motion is from the best open node (most promising) so far, no matter where it is on the partially developed tree. The second step of the algorithm changes as: 2. Until the queue is empty or the goal has been reached, determine if the first element in the queue is the goal node. a) If the first element is the goal do nothing. b) If the first element is not the goal node remove the first element from the queue and add the first element's children if any to the queue and sort the entire queue by estimated remaining distance..

  47. Best-First Search procedure best_first_search; begin open := [Start]; closed = []; while open <> [] do remove leftmost state from open, call it X; if X = goal then return path from Start to X elsebegin generate children of X; for each child of X do case the child is not on open or closed: begin assign child heuristic value; add child to open end; the child is already on open: if the child reached by shorter path then give state on open shorter path the child is already on closed: if child reached shorter path then begin remove state from closed; add child to open end; end case; put X on closed; re-order states on open by heuristic method end; return failure end.

  48. Example of best-first search A-5 1. open = [A5]; closed = [] 2. eval A5; open = [B4, C4, D6]; closed = [A5] 3. eval B4; open = [C4, E5, F5, D6]; closed = [B4, A5] 4. eval C4; open = [H3, G4, E5, F5, D6] closed = [C4, B4, A5] 5. eval H3; open = [O2, P3, G4, E5, F5, D6]; closed = [H3, C4, B4, A5] 6. eval O2; open = [P3, G4, E5, F5, D6] closed = [O2, H3, C4, B4, A5] 7. eval P3; the solution is found! B-4 C-4 D-6 I J E-5 F-5 G-4 H-3 K L M N O-2 P-3 Q R S T

  49. Branch and Bound Search • Shortest path is always chosen for expansion. The path first reaching the destination is optimal • In order to be certain that supposed solution is not longer than one or more incomplete paths, instead of terminating when a path is found, terminate when the shortest incomplete path is longer than the shortest complete path.

  50. Branch and Bound Search To conduct a branch and bound search: 1. Form a queue of partial paths. Let the initial queue consist of the zero length, zero step path from the root node to no where. 2. Until the queue is empty or the goal has been reached, determine if the first path in the queue reaches the goal node. a) If the first path reaches the goal do nothing. b) If the first path does not reach the goal node, i) remove the first path from the queue ii) form new paths from the removed path by extending one step iii) add the new paths to the queue iv) sort the queue by cost accumulated so far, with least cost paths in front 3. If the goal node has been found announce success, otherwise announce failure.

More Related