0% found this document useful (0 votes)
16 views

2. Search Algorithms

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

2. Search Algorithms

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

Introduction to

Artificial Intelligent (AI)


2. Problem solving by
Searching
Define a problem

A problem can be defined by 5 components:


• Initial state
• Possible Actions: a set of actions that can be executed in
each state
• Transition (successor) function: returns the state that
results from doing an action, but does not tell which action to
use
• Goal test: check if the current state is goal state
• Cost: a cost function that reflects its own performance
measure
2
Define a problem
Problem: find path from Arad to Bucharest

3
Define a problem
Problem: 8 - Puzzle

4
Define a problem
Problem: 8 - Puzzle
How many states 8-puzzle has?
9!/2 = 181,440 states

Transition (successor) function returns


state/alternatives.
5
Define a problem
Problem: 15 - Puzzle

In 1878, Sam Loyd offered $1,000 to the first


Sam Loyd (1841-1911)
person who would solve the following problem America’s greatest
puzzle-expert
But no one ever won the prize!!
6
Define a problem
Problem: 15 - Puzzle

Search methods are


used to explore and
find the optimal
alternatives

15-puzzle has 16!/2 ~ 1.04 x 1013 states


→ too large to store and would take too
long to learn

7
Define a problem as a search
problem
Search problem’s components:
• Initial state
• State space S
• Successor function:
x ∈ S → SUCCESSORS(x) ∈ 2S
• Goal test: x ∈ S → GOAL?(x) =T or F
• Arc Cost

8
State Graph

• Each state is represent by a


node
• An arc connects a node s to
node s’ if s’ ∈ SUCCESSORS(s)
• A solution is a path
connecting the initial node to a
goal node
• The cost is the sum of the arc
costs along a path
• An optimal solution is a
solution path of minimum cost
• There might be no solution !
9
Problem formulation

A problem can be formulated in different ways.

Problem: path finding

10
#1 #2 #3
Problem formulation

#1 #2 #3

11
State space

How big is the state space of the (n2 - 1)-puzzle?


• 8-puzzle → 9! = 362,880 states 0.036s
• 15-puzzle → 16! ~ 2.09 x 1013 states 55 hours
• 24-puzzle → 25! ~ 1025 states 109 years
If a computer can do
100 million state/sec

It is often not feasible (or too expensive) to build a complete


state graph

A problem solver must construct a solution by exploring a


small portion of the graph
12
Searching the State Space

13
Search Algorithms

14
a G
b c
Blind search e
d f
Breath First Search S h
Strategy: expand a shallowest p r
q
node first
S

d e p
Search
b c e h r q
Tiers
15

a a h r p q f

p q f q c G

q c a
G
a
Blind search
Breath First Search
Strategy: expand a shallowest node first

Visited
S

Queue
1 2
First Last

First In First Out


(FIFO)
Blind search
Breath First Search
Strategy: expand a shallowest node first

Visited
S 1

Queue
2 3
First Last

First In First Out


(FIFO)
Blind search
Breath First Search
Strategy: expand a shallowest node first

Visited
S 1 2

Queue
3 4
First Last

First In First Out


(FIFO)
Blind search
Breath First Search
Strategy: expand a shallowest node first

Visited
S 1 2

Queue
4 5
First Last

First In First Out


(FIFO)
Blind search
Breath First Search
Strategy: expand a shallowest node first

Visited
S 1 2 3 4

Queue
5
First Last

First In First Out


(FIFO)
Blind search
Breath First Search
Strategy: expand a shallowest node first

Visited
S 1 2 3 4 5

Queue

Shortest Path
S 2 3 5
Blind search
Breath First Search
Strategy: expand a shallowest node first
Blind search
Breath First Search
Strategy: expand a shallowest node first

Exercise: Rat in a Maze Problem


a G
Blind search b c

Depth First Search e


d f
Strategy: expand a deepest S h
node first
p q r
S

d e p

b c e h r q

a a h r p q f

p q f q c G

q c a
G
a
2 a G
b 8 c
Blind search 1
2 2
3 e
d 9 2 f
Uniform Cost Search S h 8
1
Strategy: expand a cheapest node first: 1 p r
q
15
S 0

d 3 e 9 p 1

b 4 c e 5 h 17 r 11 q 16
11
25
a 6 a h 13 r 7 p q f
Cost
contours q c
p q f 8 G

q c a
11 G 10
a
Heuristic search

Heuristic function h(n) is a function used to estimates how close a


state is to the goal. h(n) is always positive
Heuristic search find node/path based on their heuristic value h(n).
Heuristic search uses 2 lists:
- OPEN: nodes which have yet been expanded
- CLOSED: nodes which have already expanded
On each iteration, node n with the lowest heuristic value is
expanded and generates all its successors, after that n is placed to the
closed list.
2 main heuristic search algorithms:
- Greedy search
- A* search
26
Heuristic search
Greedy Search : selects the path which appears best at that moment by
combination of DFS and BFS.

h(x) 27
Heuristic search
Greedy Search

28
Heuristic search
Greedy Search

10

5
11.2

29
Heuristic search
A* Search : find the shortest path by combine heuristic cost and cost to
reach node n from start state

Uniform-cost Greedy search


search

30
Heuristic search
A* Search : find the shortest path by combine heuristic cost and cost to
reach node n from start state

http://theory.stanford.edu/~amitp/GameProgramming/Heuristics.html 31
Heuristic search

Greedy

A*
Uniform Cost
32
Heuristic search
A* Search

33

You might also like