1 / 30

COMP 3715 Spring 2005

COMP 3715 Spring 2005. Searching as an AI problem. Many AI problem framed as search General idea You know the individual steps towards solving a problem You need to find out which (combination of) steps lead to the solution So you need to search for the right combination.

edna
Télécharger la présentation

COMP 3715 Spring 2005

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. COMP 3715 Spring 2005

  2. Searching as an AI problem • Many AI problem framed as search • General idea • You know the individual steps towards solving a problem • You need to find out which (combination of) steps lead to the solution • So you need to search for the right combination

  3. Searching as an AI problem • Example: • Playing chess: search for the right moves to move to a winner location • Puzzle: the order to move pieces so that the puzzle is solved • Walking in a maze: making the right moves to get out of the maze

  4. Searching as an AI problem • States: the various situations • Certain position of chess pieces; current location in the maze • Actions: Allowable action at each state • Which chess piece can move where; where can I move in the maze • Initial/Start state: the starting location • Starting position of chess; the entrance of a maze • Final/Goal state: the goal • Position that checkmate; the exit of a maze

  5. Searching as an AI problem • Searching can be generalized as a graph • Graph • Vertices/Nodes: labels • Edges: connecting two vertices • Directed vs. Not directed • Cycles • Acyclic graph: graph without a cycle • Trees

  6. Searching as an AI problem • Searching as a graph problem • States : vertices • Directed Edges : if a action move from one state to another • Start state, goal state: the corresponding vertices • Search problem: find a path from the start vertex to the end vertex

  7. Finding a path in a graph • General idea of a graph search • Start at the initial vertex • Visit the nodes that can be reached by the vertices already visited • Continue until the goal is find or until there is no more vertices to visit • Algorithms differ with • Order of visit • Data structure needed

  8. Finding a path in a graph • Depth first search • Going “deeper” whenever possible • Always pick a vertex that is just visited to visit next • Need a stack • Breadth first search • Going “wider” whenever possible • Pick a vertex based on “first come first visited” principle • Need a queue

  9. Depth first search -- example B C Stack: {I} I D F A Not yet visited E Current G Visited

  10. Depth first search -- example B C Stack: {I, A} I D F A Not yet visited E Current G Visited

  11. Depth first search -- example B C Stack: {I, A, C} I D F A Not yet visited E Current G Visited

  12. Depth first search -- example B C Stack: {I, A, C, D} I D F A Not yet visited E Current G Visited

  13. Depth first search -- example B C Stack: {I, A, C, D} I D F A Not yet visited E Current G Visited A is not put on the stack because it has been visited

  14. Depth first search -- example B C Stack: {I, A, C} I D F A Not yet visited E Current G Visited D has no other vertex to go to, so is popped

  15. Depth first search -- example B C Stack: {I, A, C, F} I D F A Not yet visited E Current G Visited

  16. Depth first search -- example B C Stack: {I, A, C, F, G} I D F A Not yet visited E Current G Visited Goal is reached

  17. Depth first search • Start with an initial vertex • Insert the vertex on the stack • Make the initial vertex as visited • At each step, check if the vertex at the top of the stack has vertex not yet visited • If exist, then pick one of the vertices to put on top of stack • If not, pop the current vertex out of the stack • Repeat until the goal is reached or the stack is empty

  18. Breadth first search -- example B C Queue: {I} I D F A Not yet visited E Current G Visited

  19. Breadth first search -- example B C Queue: {A, B} I D F A Not yet visited E Current G Visited

  20. Breadth first search -- example B C Queue: {B, C} I D F A Not yet visited E Current G Visited A is not put on the queue because it is visited

  21. Breadth first search -- example B C Queue: {C, E} I D F A Not yet visited E Current G Visited

  22. Breadth first search -- example B C Queue: {E, D, F} I D F A Not yet visited E Current G Visited

  23. Breadth first search -- example B C Queue: {D, F, G} I D F A Not yet visited E Current G Visited A is not put on the queue because it is already there

  24. Breadth first search -- example B C Queue: {F, G} I D F A Not yet visited E Current G Visited G is not put on the queue because it is already there

  25. Breadth first search -- example B C Queue: {F, G} I D F A Not yet visited E Current G Visited Goal is found

  26. Breadth first search • Use a (first-in-first-out) queue instead of a stack • The initial vertex is put on the queue • At each step • Look at the top of the queue • Look at all the vertices that the top of the queue points to • Add them to the end of the queue if they have not been visited and are not on the queue already • Remove the top of the queue • Repeat until goal is reached or queue empty

  27. Search – locating the path • For depth first search • Path can be listed by popping from the stack • For breadth first search • We need to keep track of each vertex’s “parent” (which vertex leads to the vertex adding onto the queue)

  28. Depth first/Breadth first search: strength and limitations • Both • Easy to implement (try it yourself!) • Exhaustive – guarantee to find the solution • Depth first search • Very dependent on which vertex to choose • Breadth first search • More likely to find a good path • The queue can grow very big

  29. Depth first/Breadth first search: strength and limitations • In an Artificial Intelligence context • Graphs are too big -- Can’t generate all the vertices • Exhaustive search takes too long • Need faster solutions (e.g. robot can’t wait a day before it moves)

  30. Heuristic search

More Related