Вы находитесь на странице: 1из 28

General problem solving and search methods

Artificial Intelligence

Contents
5.1 Problem Solving by Search 5.2 Search Strategies 5.3 Blind Search 5.4 8-Puzzle Game

5.1 Problem Solving by Search


Problem:
A problem can be considered to consist of a goal and a set of actions that can be taken to lead to the goal.

Search:
Search is a method that can be used by computers to examine a problem in order to find a goal. At any given time we consider the state of the search to represent where we have reached as a result of the actions we have applied so far. A problem can be considered to be a search because in order to solve the problem, we will search for a goal state.

Problem solving ! Searching for a goal state

5.1 Problem Solving by Search


Data Driven or Goal driven search:
Forward Chaining Backward Chaining

Approaches:
Top-Down Search:
Starts from an initial state and uses actions to move forward until a goal is reached. This is known as forward chaining search.

Bottom-Up Search:
Search starts at the goal and work back toward a start state by seeing what moves could have led to the goal state known as backward chaining search.

5.2 Search Strategies


Requirements of a good search strategy:
1. It causes motion Otherwise, it will never lead to a solution. 2. It is systematic Otherwise, it may use more steps than necessary. 3. It is efficient Find a good, but not necessarily the best, answer.

5.2 Search Strategies


There are two search strategies
Blind/uninformed search Informed/Heuristic search
Any path/Non-optimal search Optimal Search

A. Blind/uninformed search
The uninformed or blind search is
The search methodology having no additional information about search states beyond that provided in the problem definitions. In this search total search space is looked for solution

Having no information about the number of steps from the current state to the goal. Zero information search

Example of Mouse and Cheese


Suppose mouse is searching for cheese Without any hint The search is blind It will be purely hit and trial approach Such searching is called Blind or Uninformed searching

B. Informed/Heuristic Search
More efficient than uninformed search Heuristic: involving or serving as an aid to learning, discovery, or
problem-solving by experimental and especially trial-anderror methods. (Merriam-Websters dictionary)

A Heuristic is an operationally-effective piece of


information on how to direct search in a problem space. Heuristics are only approximately correct. Their purpose is to minimize search on average. Heuristic technique improves the efficiency of a search process

B. Informed/Heuristic Search
Best-First Search an algorithm in which a node is selected for expansion based on an evaluation function f(n)
Traditionally the node with the lowest evaluation function is selected Not an accurate nameexpanding the best node first would be a straight march to the goal. Choose the node that appears to be the best A* (A star) is the most widely known form of Best-First search

Example of Mouse and Cheese


For example
Suppose that cheese is fresh and it smells The mouse will use this smell as guide to guess the position of the cheese Will choose the best from the alternative choices. As smell gets stronger he mouse knows that the cheese is closer Hence the mouse is informed about the cheese and thus the search is informed

You might think that informed search is the best solution to the problem But its not true Mouse found the cheese but not from the best optimal path.

B. Informed/Heuristic Search
Any path/Non optimal search
In this search we are concerned with finding any solution As we find the solution we stop the search There could have been a better path which might take lesser time

Optimal path search


We find the solution that are least costly

5.3 Blind Search


Breadth-first search
Expand all the nodes of
one level first.

Depth-first search
Expand one of the nodes
at the deepest level.

5.3 Blind Search


A

B D E F

C G

H L M N O

I P

K Q

Tree Search A tree search starts at the root and explores nodes from there, looking for a goal node For some problems, any goal node is acceptable (N or J); for other problems, you want a minimum-depth goal node, that is, a goal node nearest the root (only J)

Goal nodes

Depth-first searching
A

B D E F

C G

H L M N O

I P

K Q

A depth-first search (DFS) explores a path all the way to a leaf before backtracking and exploring another path For example, after searching A, then B, then D, the search backtracks and tries another path from B Node are explored in the order A B D E H L M N I OPCFGJKQ N will be found before J

Depth First Search


1
SI 2 7

4 6

8 SG

Breadth-First Search
1

10

11

12
SG

Backwards Breadth-First Search


9
SI

1
SG

Bi-Directional Breadth-First Search


1 SI 3 8 13 5 6 2 S G 7 9 10 4 11 12

Breadth-first searching
A

B D E F

C G

H L M N O

I P

K Q

A breadth-first search (BFS) explores nodes nearest the root before exploring nodes further away For example, after searching A, then B, then C, the search proceeds with D, E, F, G Node are explored in the order A B C D E F G
HIJKLMNOPQ J will be found before N

Depth- vs. breadth-first searching


When a breadth-first search succeeds, it finds a minimum-depth (nearest the root) goal node When a depth-first search succeeds, the found goal node is not necessarily minimum depth For a large tree, breadth-first search memory requirements may be excessive For a large tree, a depth-first search may take an excessively long time to find even a very nearby goal node

Depth- vs. breadth-first searching


Breadth-first is complete and optimal, but has high space complexity
Bad when branching factor is high

Depth-first is space efficient, but neither complete nor optimal


Bad when search depth is infinite

How can we combine the advantages (and avoid the disadvantages) of these two search techniques?

Depth-limited searching
Depth-first searches may be performed with a depth limit:
limit = 0; found = false; while (not found) { found = limitedDFS(root, limit, 0); limit = limit + 1; }

This searches to depth 0 (root only), then if that fails it searches to depth 1, then depth 2, etc. If a goal node is found, it is a nearest node and the path to it is on the stack

5.4 8-Puzzle Game


An unsolved 8-Puzzle

24

A Sample Search Tree

25

A Sample Search Tree

26

A Sample Search Tree

27

A Sample Search Tree

28

Оценить