1 / 24

Using Search in Problem Solving

Using Search in Problem Solving. Part I. Basic Concepts. Initial state Goal/Target state Intermediate states Path from the initial to the target state Operators/rules to get from one state to another All states - search space

idalia
Download Presentation

Using Search in 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. Using Search inProblem Solving Part I

  2. Basic Concepts • Initial state • Goal/Target state • Intermediate states • Path from the initial to the target state • Operators/rules to get from one state to another • All states -search space We search for a path / sequence of operators to go from the initial state to the goal state

  3. Initial state Target state

  4. Search Space • Search problems can be represented as graphs, where the nodes are states and the arcs correspond to operations. • The set of all states: search space

  5. Graphs and Trees 1 • Graph: a set of nodes (vertices) with links(edges) between them. • A link is represented usually as a pair of nodes, connected by the link. • Undirected graphs:the links do not have orientation • Directed graphs:the links have orientation

  6. Graphs and Trees 2 • Path:Sequence of nodes such that each two neighbors represent an edge • Cycle: a path with the first node equal to the last and no other nodes are repeated • Acyclic graph: a graph without cycles • Tree: undirected acyclic graph, where one node is chosen to be the root

  7. Graphs and Trees 3 • Given a graph and a node: • Out-going edges:all edges that start in that node • In-coming edges :all edges that end up in that node • Successors (Children):the end nodes of all out-going edges • Ancestors (Parents):the nodes that are start points of in-coming edges

  8. G1: Undirected graph A B C D E Path: ABDCAE Cycle: CABEC Successors of A: E, C, B Parents of A: E, C, B

  9. A B G2: Directed graph C D E Path: ABDC Cycle: no cycles Successors of A: C, B Parent of A: E

  10. Search Trees • More solutions: More than one path from the initial state to a goal state • Different paths may have common arcs • The search process can be represented by a search tree • In the search tree the different solutions will be represented as different paths from the initial state • One and the same state may be represented by different nodes

  11. Search methods • Basic (uninformed, blind, exhaustive): • breadth-first • depth-first • Heuristic (informed): • hill climbing • best-first • A*

  12. Breadth-First Search Algorithm: using a queue 1. Queue = [initial_node] , FOUND = False 2. While queue not empty and FOUND = False do: Remove the first node N If N = target node then FOUND = true Elsefind all successor nodes of N and put them into the queue. In essence this is Dijkstra's algorithm of finding the shortest path between two nodes in a graph.

  13. Depth-first search Algorithm: using a stack 1. Stack = [initial_node] , FOUND = False 2. While stack not empty and FOUND = False do: Remove the top node N If N = target node then FOUND = true Else find all successor nodes of N and put them onto the stack.

  14. Comparison of depth-first and breadth-first search Breadth-first:without backtracking Depth-first :backtracking. Length of path:breadth-first finds the shortest path first. Memory:depth-first uses less memory Time:If the solution is on a short path - breadth first is better, if the path is long - depth first is better.

  15. Heuristic Search Heuristic search is used to reduce the search space. Basic idea: explore only promising states/paths. We need an evaluation function to estimate each state/path.

  16. Hill climbing Basic idea: always head towards a state which is better than the current one. There is no exhaustive search, so no node list is maintained.

  17. Hill Climbing - Algorithm • Start with current-state = initial-state. • Until current-state = goal-state OR there is no change in current-state do: • Get the successors of the current state and use the evaluation function to assign a score to each successor. • If one of the successors has a better score than the current-state then set the new current-state to be the successor with the best score.

  18. Hill Climbing • Node list is not maintained • No problems with loops since we move to a better node • If a solution is found, it is found for a very short time with minimal memory requirements • Finding a solution is not guaranteed – the local maxima problem

  19. Best First Search • The node with the best score is chosen to be expanded. • Works in breadth-first manner, keeps a data structure (called agenda, based on priority queues) of all successors and their scores. • If a node that has been chosen does not lead to a solution, the next "best" node is chosen, so eventually the solution is found • Always finds a solution, not guaranteed to be the optimal one.

  20. Best First Search Algorithm • 1. Start with agenda = [initial-state]. • 2. While agenda is not empty do • A. Pick the best node on agenda. • B. If it is the goal node then return with success. Otherwise find its successors. • C. Assign the successor nodes a score using the evaluation function and add the scored nodes to the agenda

  21. Comparison with hill-climbing Similarities:best-first always chooses the best node Difference:best-first search keeps an agenda as in breadth-first search, and in case of a dead end it will backtrack, choosing the next-best node.

  22. The A* Algorithm An evaluation function that accounts for - the cost of the paths - the score of the nodes F(Node) = g(Node) + h(Node) g(Node) - the costs from the initial state to the current node h(Node) - future costs, i.e. node score Disadvantage of A* is the memory requirement - the algorithm keeps records for the entire tree.

  23. The A* Algorithm A* always finds the best solution, provided that h(Node) does not overestimate the future costs.

  24. A 4 10 2 9 H : 5 B: 9 D : 10 4 F : 6 2 4 6 C: 8 K: 5 E: 7 8 10 7 8 J: 4 G: 0 Example Start: A Goal: G

More Related