You are on page 1of 48

ARTIFICIAL INTELLIGENCE

Indah Werdiningsih

Search Algorithms
Blind search BFS, DFS, uniform cost
no notion concept of the right direction
can only recognize goal once its achieved

Heuristic search we have rough idea of how good


various states are, and use this knowledge to guide our
search

Fringe
Set of search nodes that have not been
expanded yet
Implemented as a queue FRINGE
INSERT(node,FRINGE)
REMOVE(FRINGE)

The ordering of the nodes in FRINGE


defines the search strategy

Breadth-First Strategy
New nodes are inserted at the end of FRINGE
1
2
4

FRINGE = (1)

3
5

Breadth-First Strategy
New nodes are inserted at the end of FRINGE
1
2
4

FRINGE = (2, 3)

3
5

Breadth-First Strategy
New nodes are inserted at the end of FRINGE
1
2
4

FRINGE = (3, 4, 5)

3
5

Breadth-First Strategy
New nodes are inserted at the end of FRINGE
1
2
4

FRINGE = (4, 5, 6, 7)

3
5

Depth-First Strategy
New nodes are inserted at the front of FRINGE
1
2
4

FRINGE = (1)

Depth-First Strategy
New nodes are inserted at the front of FRINGE
1
2
4

FRINGE = (2, 3)

Depth-First Strategy
New nodes are inserted at the front of FRINGE
1
2
4

FRINGE = (4, 5, 3)

10

Depth-First Strategy
New nodes are inserted at the front of FRINGE
1
2
4

3
5

11

Depth-First Strategy
New nodes are inserted at the front of FRINGE
1
2
4

3
5

12

Depth-First Strategy
New nodes are inserted at the front of FRINGE
1
2
4

3
5

13

Depth-First Strategy
New nodes are inserted at the front of FRINGE
1
2
4

3
5

14

Depth-First Strategy
New nodes are inserted at the front of FRINGE
1
2
4

3
5

15

Depth-First Strategy
New nodes are inserted at the front of FRINGE
1
2
4

3
5

16

Depth-First Strategy
New nodes are inserted at the front of FRINGE
1
2
4

3
5

17

Depth-First Strategy
New nodes are inserted at the front of FRINGE
1
2
4

3
5

18

Contoh Kasus

Uniform-Cost Strategy
Each step has some cost > 0.
The cost of the path to each fringe node N is
g(N) = costs of all steps.
The goal is to generate a solution path of minimal
The queue FRINGE is sorted in increasing cost.
S

1
S

10
5 B 5 G

15

15

11

10

20

Informed (Heuristic) Search

Search with Domain


Knowledge added
Uninformed (blind) searches are normally
very inefficient
Adding domain knowledge can improve
the search process.

22

Concept of informed
(heuristic) search
Heuristic (informed) search -> explore the
node that is most likely to be the nearest
to a goal state.
There is no guarantee that the heuristic
provided most likely node will get you
closer to a goal state than any other.

23

Knowledge/info
Example:
Visit the doctor
Symptoms: fever, nausea, headache,
Leading questions: how long?, traveled?,
(Malaria, typhoid, meningitis, flu,..)
x Blood test, y test,...

24

Knowledge/info
Example:
Climbing a hill in thick Fog
Heuristic function: check the change in altitude in 4
directions; the strongest increase is the direction in
which to move next.

25

Heuristic Search Methods


Methods that use a heuristic function to
provide specific knowledge about the
problem:

Heuristic Functions
Hill climbing
Greedy search
A* search algorithm

26

Hill climbing on a surface of


states

Height Defined by
Evaluation
27
Function

Hill climbing
Steepest descent (~ greedy best-first with
no search) may get stuck into local
minimum

28

Robot Navigation
Local-minimum problem

f(N) = h(N) = straight distance to the goal


29

Hill climbing example


start

1
h = -4

-5
8

1
7

3
4

h=0

-2

3
4

8
7

-5
2

goal

1
h = -3

h = -1

-4

-3
2

h = -3

-4

f(n) = -(number of tiles out of place)

h = -2

30

Example of a local maximum


1

start
1

-3

-4
goal
1
-4
8

-4
31

Greedy Search
f(N) = h(N) greedy best-first

32

Robot Navigation

33

Robot Navigation
f(N) = h(N), with h(N) = Manhattan distance to the goal
8

6
7

6
5

4
5

34

Robot Navigation
f(N) = h(N), with h(N) = Manhattan distance to the goal
8

6
77

5
1

00

What happened???
6

5
5

35

Heuristic Searches - Greedy


search
So named as it takes the biggest bite it can out
of the problem.
That is, it seeks to minimise the estimated cost
to the goal by expanding the node estimated to
be closest to the goal state
in other words,

Always expand the heuristically best nodes first.


36

Greedy search algorithm


1. QUEUE <-- path only containing the root;
2. WHILE

DO

QUEUE is not empty


AND goal is not reached
remove the first path from the QUEUE;
create new paths (to all children);
reject the new paths with loops;
add the new paths and sort the entire QUEUE;

3. IF goal reached
THEN success;
ELSE failure;
37

Heuristic Searches - Greedy


Search
It is only concerned with short term aims
It is possible to get stuck in an infinite loop, unless
you check for repeated states
It is not optimal
It is not complete
Time and space complexity is O(Bm); where m is the
depth of the search tree

38

More informed search


We kept looking at nodes closer and closer to the
goal, but were accumulating costs as we got
further from the initial state
Our goal is not to minimize the distance from the
current head of our path to the goal, we want to
minimize the overall length of the path to the goal!
Let g(N) be the cost of the best
path found so far between the initial
node and N
f(N) = g(N) + h(N)
39

Robot Navigation
f(N) = g(N)+h(N), with h(N) = Manhattan distance to goal
8
7
6
5
4
3
2
3
4
8+3
7+4
6+3
6+5
5+6
4+7
3+8
2+9
3+10
7
7+2
6
6+1

5
4
3
5+6
4+7
3+8
3

2
1
0
1
2+9
1+10
0+11

5
2

7
6
7+0
6+1
8
7
6
5
4
3
2
3
8+1
7+2
6+3
5+4
4+5
3+6
2+7
3+8

5
4

40

A* Search
Evaluation function:
f(N) = g(N) + h(N)
where:
g(N) is the cost of the best path found so far to N
h(N) is an admissible heuristic
Then, best-first search with this evaluation function is
called A* search
Important AI algorithm developed by Fikes and Nilsson in
early 70s. Originally used in Shakey robot.
41

Robot navigation
f(N) = g(N) + h(N), with h(N) = straight-line distance from N to goal

Cost of one horizontal/vertical step = 1


Cost of one diagonal step = 2

42

Example: road map


Imagine the problem of finding a route on a road map
and that the NET below is the road map:
4

S
4

Define f(T) = the straight-line distance from T to G


A
S

10.4

6.7

C 4
The estimate
G can be wrong!

11
D

8.9

E 6.9

43

Road map example:

Re-introduce the costs of paths in the NET


3

A
5

S
4

4
4

B
2

E 4

G
F

3
5

4
4

2
5

G
44

A* Algorithm Example:
road map
Imagine the problem of finding a route on a road map. The
paths distances between nodes define g(n):
4

S
4

Define h(n) = the straight-line distance from node to G


A
S

10.4

6.7

C 4

11
D

8.9

G
E 6.9

45

S
3 + 10.4 = 13.4 A

D 4 + 8.9 = 12.9

S
A 13.4

9 + 10.4 = 19.4 A

E 6 + 6.9 = 12.9

A 13.4

S
A

D
E

11 + 6.7 = 17.7

A 13.4

F 10 + 3.0 = 13.0

S
A

D
17.7 B

STOP!

F
G 13 + 0.0 = 13.0

46

Reference
Russel, Stuart J., Peter Norvig,
"Artificial Intelligence, a modern
approach, Second Edition, Prentice
Hall, New Jersey, 2010.
Winston, Patrick Henry, "Artificial
Intelligence, Addison Wesley.

TERIMA
KASIH

You might also like