Tải bản đầy đủ (.pdf) (50 trang)

trí tuệ nhân tạo cao hoàng trứ chương ter2 problems and search sinhvienzone com

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (169.45 KB, 50 trang )

om

nh
Vi
en

Zo

ne

.C

Problems and Search

Si

Chapter 2

SinhVienZone.com

/>

ne
Zo

Search strategies

.C

State space search


nh
Vi
en

Problem characteristics

Design of search programs

Si






om

Outline

Cao Hoang Tru
CSE Faculty - HCMUT
SinhVienZone.com

2
13 February, 2009
/>

om

State Space Search


Si

nh
Vi
en

Zo

ne

.C

Problem solving = Searching for a goal state

Cao Hoang Tru
CSE Faculty - HCMUT
SinhVienZone.com

3
13 February, 2009
/>

om

State Space Search: Playing Chess

Zo

ne


.C

• Each position can be described by an 8-by-8 array.
• Initial position is the game opening position.
• Goal position is any position in which the opponent

nh
Vi
en

does not have a legal move and his or her king is
under attack.

• Legal moves can be described by a set of rules:

Si

− Left sides are matched against the current state.
− Right sides describe the new resulting state.

Cao Hoang Tru
CSE Faculty - HCMUT
SinhVienZone.com

4
13 February, 2009
/>

om


State Space Search: Playing Chess

Zo

ne

.C

• State space is a set of legal positions.
• Starting at the initial state.
another.

nh
Vi
en

• Using the set of rules to move from one state to

Si

• Attempting to end up in a goal state.

Cao Hoang Tru
CSE Faculty - HCMUT
SinhVienZone.com

5
13 February, 2009
/>


om

State Space Search: Water Jug Problem

Si

nh
Vi
en

Zo

ne

.C

“You are given two jugs, a 4-litre one and a 3-litre one.
Neither has any measuring markers on it. There is a
pump that can be used to fill the jugs with water. How
can you get exactly 2 litres of water into 4-litre jug.”

Cao Hoang Tru
CSE Faculty - HCMUT
SinhVienZone.com

6
13 February, 2009
/>


om

State Space Search: Water Jug Problem
y = 0, 1, 2, 3

nh
Vi
en

• Start state: (0, 0).

Zo

x = 0, 1, 2, 3, or 4

ne

.C

• State: (x, y)

Si

• Goal state: (2, n) for any n.
• Attempting to end up in a goal state.

Cao Hoang Tru
CSE Faculty - HCMUT
SinhVienZone.com


7
13 February, 2009
/>

3. (x, y)
if x > 0

Cao Hoang Tru
CSE Faculty - HCMUT
SinhVienZone.com

.C

Zo

Si

4. (x, y)
if y > 0

→ (x, 3)

nh
Vi
en

2. (x, y)
if y < 3

→ (4, y)


ne

1. (x, y)
if x < 4

om

State Space Search: Water Jug Problem

→ (x − d, y)
→ (x, y − d)

8
13 February, 2009
/>

.C

Zo

→ (x, 0)

nh
Vi
en

6. (x, y)
if y > 0


→ (0, y)

ne

5. (x, y)
if x > 0

om

State Space Search: Water Jug Problem

7. (x, y)
→ (4, y − (4 − x))
if x + y ≥ 4, y > 0

Si

8. (x, y)
→ (x − (3 − y), 3)
if x + y ≥ 3, x > 0

Cao Hoang Tru
CSE Faculty - HCMUT
SinhVienZone.com

9
13 February, 2009
/>

ne


.C

9. (x, y)
→ (x + y, 0)
if x + y ≤ 4, y > 0

om

State Space Search: Water Jug Problem

nh
Vi
en

Zo

10. (x, y)
→ (0, x + y)
if x + y ≤ 3, x > 0
12. (2, y)

→ (2, 0)

Si

11. (0, 2)

Cao Hoang Tru
CSE Faculty - HCMUT

SinhVienZone.com

→ (0, y)

10
13 February, 2009
/>

om

State Space Search: Water Jug Problem

.C

1. current state = (0, 0)

ne

2. Loop until reaching the goal state (2, 0)

Si

(0, 0)
(0, 3)
(3, 0)
(3, 3)
(4, 2)
(0, 2)
(2, 0)


nh
Vi
en

Zo

− Apply a rule whose left side matches the current state
− Set the new current state to be the resulting state

Cao Hoang Tru
CSE Faculty - HCMUT
SinhVienZone.com

11
13 February, 2009
/>

om

State Space Search: Water Jug Problem

→ (x, 3)

Si

2. (x, y)
if y < 3

→ (4, y)


nh
Vi
en

1. (x, y)
if x < 4

Zo

ne

.C

The role of the condition in the left side of a rule
⇒ restrict the application of the rule
⇒ more efficient

Cao Hoang Tru
CSE Faculty - HCMUT
SinhVienZone.com

12
13 February, 2009
/>

om

State Space Search: Water Jug Problem

Zo


ne

.C

Special-purpose rules to capture special-case
knowledge that can be used at some stage in solving a
problem
→ (2, 0)

nh
Vi
en

11. (0, 2)

→ (0, y)

Si

12. (2, y)

Cao Hoang Tru
CSE Faculty - HCMUT
SinhVienZone.com

13
13 February, 2009
/>


om

State Space Search: Summary

ne

.C

1. Define a state space that contains all the possible
configurations of the relevant objects.

Zo

2. Specify the initial states.

nh
Vi
en

3. Specify the goal states.
4. Specify a set of rules:

Si

− What are unstated assumptions?
− How general should the rules be?
− How much knowledge for solutions should be in the
rules?

Cao Hoang Tru

CSE Faculty - HCMUT
SinhVienZone.com

14
13 February, 2009
/>

om

Search Strategies

.C

Requirements of a good search strategy:

ne

1. It causes motion

nh
Vi
en

2. It is systematic

Zo

Otherwise, it will never lead to a solution.
Otherwise, it may use more steps than necessary.


3. It is efficient

Si

Find a good, but not necessarily the best, answer.

Cao Hoang Tru
CSE Faculty - HCMUT
SinhVienZone.com

15
13 February, 2009
/>

om

Search Strategies

.C

1. Uninformed search (blind search)

Zo

ne

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

2. Informed search (heuristic search)


Si

nh
Vi
en

More efficient than uninformed search.

Cao Hoang Tru
CSE Faculty - HCMUT
SinhVienZone.com

16
13 February, 2009
/>

Zo

nh
Vi
en

(4, 0)

ne

(0, 0)

(0, 0)


(1, 3)

(4, 3)

(0, 3)

(0, 0)

(3, 0)

Si

(4, 3)

.C

om

Search Strategies

Cao Hoang Tru
CSE Faculty - HCMUT
SinhVienZone.com

17
13 February, 2009
/>

om


Search Strategies: Blind Search

ne

nh
Vi
en

Zo

Expand all the nodes of
one level first.

.C

• Breadth-first search

• Depth-first search

Si

Expand one of the nodes at
the deepest level.

Cao Hoang Tru
CSE Faculty - HCMUT
SinhVienZone.com

18

13 February, 2009
/>

Time

nh
Vi
en

Space

Si

Optimal?
Complete?

DepthFirst

ne

BreadthFirst

Zo

Criterion

.C

om


Search Strategies: Blind Search

b: branching factor
Cao Hoang Tru
CSE Faculty - HCMUT
SinhVienZone.com

d: solution depth

m: maximum depth
19
13 February, 2009
/>

DepthFirst

bd

bm

bd

Time

nh
Vi
en

Space


Yes

No

Yes

No

Si

Optimal?
Complete?

bm

ne

BreadthFirst

Zo

Criterion

.C

om

Search Strategies: Blind Search

b: branching factor

Cao Hoang Tru
CSE Faculty - HCMUT
SinhVienZone.com

d: solution depth

m: maximum depth
20
13 February, 2009
/>

om

Search Strategies: Heuristic Search

.C

• Heuristic: involving or serving as an aid to learning,

Zo

ne

discovery, or problem-solving by experimental and
especially trial-and-error methods.
(Merriam-Webster’s dictionary)

nh
Vi
en


• Heuristic technique improves the efficiency of a

Si

search process, possibly by sacrificing claims of
completeness or optimality.

Cao Hoang Tru
CSE Faculty - HCMUT
SinhVienZone.com

21
13 February, 2009
/>

om

Search Strategies: Heuristic Search

ne

.C

• Heuristic is for combinatorial explosion.

Si

nh
Vi

en

Zo

• Optimal solutions are rarely needed.

Cao Hoang Tru
CSE Faculty - HCMUT
SinhVienZone.com

22
13 February, 2009
/>

.C

The Travelling Salesman Problem

om

Search Strategies: Heuristic Search

Si

nh
Vi
en

Zo


ne

“A salesman has a list of cities, each of which he must
visit exactly once. There are direct roads between each
pair of cities on the list. Find the route the salesman
should follow for the shortest possible round trip that
both starts and finishes at any one of the cities.”
1

D

15
Cao Hoang Tru
CSE Faculty - HCMUT
SinhVienZone.com

A

5

B
C

10
5

E
5
23
13 February, 2009

/>

.C

1. Select a starting city.

ne

Nearest neighbour heuristic:

om

Search Strategies: Heuristic Search

Zo

2. Select the one closest to the current city.

Si

nh
Vi
en

3. Repeat step 2 until all cities have been visited.

Cao Hoang Tru
CSE Faculty - HCMUT
SinhVienZone.com


24
13 February, 2009
/>

.C

1. Select a starting city.

ne

Nearest neighbour heuristic:

om

Search Strategies: Heuristic Search

Zo

2. Select the one closest to the current city.

Si

nh
Vi
en

3. Repeat step 2 until all cities have been visited.

Cao Hoang Tru
CSE Faculty - HCMUT

SinhVienZone.com

O(n2) vs. O(n!)

25
13 February, 2009
/>

×