solving problems by searching

45
Solving problems by searching Chapter 3, part 2 Modified by Vali Derhami

Upload: carsyn

Post on 21-Jan-2016

20 views

Category:

Documents


0 download

DESCRIPTION

Solving problems by searching. Chapter 3, part 2 Modified by Vali Derhami. Implementation: general tree search. انتخاب گره از مجموعه لبه براي گسترش بر اساس استراتژی جستجو. بررسي رسيدن به هدف براي گره انتخابي. بسط گره انتخابي و درج در صف. Implementation: general tree search. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Solving problems by searching

Solving problems by searching

Chapter 3, part 2Modified by Vali Derhami

Page 2: Solving problems by searching

2/45

Implementation: general tree search

بر انتخاب گره از مجموعه لبه براي گسترش

اساس استراتژی جستجو.

.بررسي رسيدن به هدف براي گره انتخابي

بسط گره انتخابي و درج در صف

Page 3: Solving problems by searching

3/45

Implementation: general tree search

The operations on a queue are as follows: MAKE-QUEUE(elemen,...) creates a queue with the

given element(s). EMPTY?(queue) returns true only if there are no more

elements in the queue. FlRST(queue) returns the first element of the queue. REMOVE-FiRST (queue) returns First(queue) and

removes it from the queue. lNSERT(element, queue) inserts an element into the

queue and returns the resulting queue. (We will see that different types of queues insert elements in different orders.)

Insert- ALL(elements, queue) inserts a set of elements into the queue and returns the resulting queue.

Page 4: Solving problems by searching

4/45

Implementation: general tree search

Page 5: Solving problems by searching

5/45

Search strategies

A search strategy is defined by picking the order of node expansion Strategies are evaluated along the following dimensions:

completeness: does it always find a solution if one exists? time complexity: How long does it take to find solution (number of nodes generated) space complexity: How much memory is needed to perform the search? maximum

number of nodes in memory optimality: does it always find a optimal solution?

Time and space complexity are measured in terms of b: maximum branching factor of the search tree

درخت حداكثر تعداد پسين هاي هر d: depth of the least-cost solution

كم ترين عمق هدف. m: maximum depth of the state space (may be ∞)

طوالني ترين مسير در فضاي حالت

Page 6: Solving problems by searching

6/45

Uninformed search strategies

Uninformed search strategies use only the information available in the problem definition

Breadth-first search Uniform-cost search Depth-first search Depth-limited search Iterative deepening search

Page 7: Solving problems by searching

7/45

Breadth-first searchجستجوي اول سطح

Expand shallowest unexpanded nodeگسترش دادن سطحي ترين گره هاي گسترش نيافته

Implementation: fringe is a FIFO queue, i.e., new successors

go at end

Page 8: Solving problems by searching

8/45

Breadth-first searchجستجوي اول سطح

Expand shallowest unexpanded nodeگسترش دادن سطحي ترين گره هاي گسترش نيافته

Implementation: fringe is a FIFO queue, i.e., new successors

go at end

Page 9: Solving problems by searching

9/45

Breadth-first searchجستجوي اول سطح

Expand shallowest unexpanded nodeگسترش دادن سطحي ترين گره هاي گسترش نيافته

Implementation: fringe is a FIFO queue, i.e., new successors

go at end

Page 10: Solving problems by searching

10/45

Breadth-first searchجستجوي اول سطح

Expand shallowest unexpanded nodeگسترش دادن سطحي ترين گره هاي گسترش نيافته

Implementation: fringe is a FIFO queue, i.e., new successors

go at end

Page 11: Solving problems by searching

11/45

Properties of breadth-first search

Complete? Yes (if b is finite) Time?

b+b2+b3+… +bd + b(bd-1) = O(bd+1)تعداد گره هاي توليد شده: Space? O(bd+1) (keeps every node in memory)

Space is the bigger problem (more than time) براي جز به نمايي پيچيدگي جستجوي با مسائل

حل قابل ناآگاهانه روشهاي توسط كوچك هاي نمونهنيستند

Optimal? Yes (if cost = 1 per step)

Page 12: Solving problems by searching

12/45

Page 13: Solving problems by searching

13/45

Uniform-cost searchجستجوي هزينه يكنواخت

Expand least-cost unexpanded node fringe = queue ordered by path cost

Equivalent to breadth-first if step costs all equal O(b[1+(C*/ ε)]) can be much greater than O(bd) Space? # of nodes with g ≤ cost of optimal solution, O(b [(C*/ ε)]) Optimal? Yes –if step cost ≥ ε

Complete? Yes, if step cost ≥ ε Time? # of nodes with g ≤ cost of optimal solution,

O(b[1+(C*/ ε)]) where C* is the cost of the optimal solution

Implementation:

Page 14: Solving problems by searching

14/45

Depth-first searchجستجوي عمق اول

Expand deepest unexpanded node Implementation:

fringe = LIFO queue, i.e., put successors at front

نيافته گسترش گره ترين عميق گسترش

Page 15: Solving problems by searching

15/45

Depth-first search

Expand deepest unexpanded node fringe = LIFO queue, i.e., put successors at front

Implementation:

Page 16: Solving problems by searching

16/45

Depth-first search

Expand deepest unexpanded node fringe = LIFO queue, i.e., put successors at front

Implementation:

Page 17: Solving problems by searching

17/45

Depth-first search

Expand deepest unexpanded node fringe = LIFO queue, i.e., put successors at front

Implementation:

Page 18: Solving problems by searching

18/45

Depth-first search

Expand deepest unexpanded node fringe = LIFO queue, i.e., put successors at front

Implementation:

Page 19: Solving problems by searching

19/45

Depth-first search

Expand deepest unexpanded node fringe = LIFO queue, i.e., put successors at front

Implementation:

اين سه گره مشكي ازحافظه پاك مي

.شود

Page 20: Solving problems by searching

20/45

Depth-first search

Expand deepest unexpanded node fringe = LIFO queue, i.e., put successors at front

Implementation:

Page 21: Solving problems by searching

21/45

Depth-first search

Expand deepest unexpanded node fringe = LIFO queue, i.e., put successors at front

Implementation:

Page 22: Solving problems by searching

22/45

Depth-first search

Expand deepest unexpanded node fringe = LIFO queue, i.e., put successors at front

Implementation:

Page 23: Solving problems by searching

23/45

Depth-first search

Expand deepest unexpanded node fringe = LIFO queue, i.e., put successors at front

Implementation:

Page 24: Solving problems by searching

24/45

Depth-first search

Expand deepest unexpanded node fringe = LIFO queue, i.e., put successors at front

Implementation:

Page 25: Solving problems by searching

25/45

Depth-first search

Expand deepest unexpanded node fringe = LIFO queue, i.e., put successors at front

Implementation:

Page 26: Solving problems by searching

26/45

Properties of depth-first search

Complete? No: fails in infinite-depth spaces, spaces with loops Modify to avoid repeated states along path

complete in finite spaces

Time? O(bm): terrible if m is much larger than dmحداكثر عمق هر گره

but if solutions are dense, may be much faster than breadth-first

Space? bm+1, O(bm), i.e., linear space! Optimal? No

Page 27: Solving problems by searching

27/45

Depth-first search

Back tracking search: A type of Depth- firt

search

Back Traking: only one successor is

generated at a time rather than all

successors Space: O(m)

Page 28: Solving problems by searching

28/45

Depth-limited search

= depth-first search with depth limit l,i.e., nodes at depth l

محدود باشد m آنگاه كامل نيست حتي اگر d>lاگر انتخاب شود غير بهينه است. d<lاگر

Time? O(b l ), Space? bl+1, O(bl), L=∞ => Depth firth

Page 29: Solving problems by searching

29/45

Depth-limited search

Recursive implementation:

Page 30: Solving problems by searching

30/45

Iterative deepening searchجستجوي عميق شونده تكراري

جستجوي اول عمق كه بهترين محدوديت عمق را با افزايش تدريجي محدوديت تا زماني كه

به هدف رسد ،مي يابد. مزاياي هر دو روش اول عمق و جستجوي

.سطح اول

Page 31: Solving problems by searching

31/45

Iterative deepening search l =0

Page 32: Solving problems by searching

32/45

Iterative deepening search l =1

Page 33: Solving problems by searching

33/45

Iterative deepening search l =2

Page 34: Solving problems by searching

34/45

Iterative deepening search l =3

Page 35: Solving problems by searching

35/45

Iterative deepening search Number of nodes generated in a depth-limited search to depth

d with branching factor b: NDLS = b1 + b2 + … + bd-2 + bd-1 + bd

Number of nodes generated in an iterative deepening search to depth d with branching factor b:

NIDS = d b1 + (d-1)b2 + … + 3bd-2 +2bd-1 + 1bd

For b = 10, d = 5, NIDS = 50 + 400 + 3,000 + 20,000 + 100,000 = 123,450 NBFS = 10 + 100 + 1,000 + 10,000 + 100,000 + 999,990 =

1,111,100.

Overhead = (123,456 - 111,111)/111,111 = 11%

Page 36: Solving problems by searching

36/45

Properties of iterative deepening search

Complete? Yes Time? d b1 + (d-1)b2 + … + bd = O(bd) Space? O(bd) Optimal? Yes, if step cost = 1

Page 37: Solving problems by searching

37/45

Bidirectional searchجستجوي دو طرفه

انجام جستجوي همزمان يكي از حالت اوليه به سمتجلو و ديگري از هدف به سمت عقب

.توقف وقتي كه دو جستجو به هم مي رسند Time: O(bd/2)+ O(bd/2)= O(bd/2) << O(bd) Space: O(bd/2)

.مهمترين ضعف هم اين نياز به فضا است Complete and optimal (for uniform step

costs) if both searches are breadth-first; other combinations may sacrifice completeness, optimality, or both.

Page 38: Solving problems by searching

38/45

Summary of algorithms

Page 39: Solving problems by searching

39/45

Repeated states

Failure to detect repeated states can turn a linear problem into an exponential one!

Page 40: Solving problems by searching

40/45

Graph search

Page 41: Solving problems by searching

41/45

انواع مساله

- مسايل تك حالته1 در محيط هاي قطعي و كامال رويت پذيرDeterministic, fully observable عامل اطالعات كامل)Global information( از محيط و اثر عمليات خود را

مي داند.- مسايل بدون حس گر (منطبق) (چند حالته هم ناميده مي شود.)2

در محيطهاي قطعي.عامل وضعيت فعلي خود را نميداند ولي اثر عمليات خود را مي داند

Contingency- مسايل اقتضايي 3محيط نيمه رويت پذير و يا غير قطعي.عامل اثر عمليات خود را نمي داند اگر نايقيني ناشي از اقدام عامل ديگر مساله را تخاصمي)Adversarial (.گويند

exploration Problem- مسايل اكتشافي 4 حالتها و اقدامات ناشناخته

Page 42: Solving problems by searching

42/45

Example: vacuum world

Single-state, start in #5. Solution?

Page 43: Solving problems by searching

43/45

Example: vacuum world

Single-state, start in #5. Solution? [Right, Suck]

Sensorless, start in {1,2,3,4,5,6,7,8} e.g., Right goes to {2,4,6,8} Solution?

Page 44: Solving problems by searching

44/45

Example: vacuum world

Sensorless, start in {1,2,3,4,5,6,7,8} e.g., Right goes to {2,4,6,8} Solution? [Right,Suck,Left,Suck]

Contingency Nondeterministic: Suck may

dirty a clean carpet Partially observable: location, dirt at current location. Percept: [L, Clean], i.e., start in #5 or #7

Solution?

Page 45: Solving problems by searching

45/45

Example: vacuum world

Sensorless, start in {1,2,3,4,5,6,7,8} e.g., Right goes to {2,4,6,8} Solution? [Right,Suck,Left,Suck]

Contingency Nondeterministic: Suck may

dirty a clean carpet Partially observable: location, dirt at current location. Percept: [L, Clean], i.e., start in #5 or #7

Solution? [Right, if dirt then Suck]