Top Banner
1 Computer Group Engineering Department University of Science and Culture S. H. Davarpanah [email protected]. ir
29

1 Computer Group Engineering Department University of Science and Culture S. H. Davarpanah [email protected].

Dec 16, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 1 Computer Group Engineering Department University of Science and Culture S. H. Davarpanah Davarpanah@usc.ac.ir.

1

Computer GroupEngineering Department

University of Science and Culture

S. H. Davarpanah

[email protected]

Page 2: 1 Computer Group Engineering Department University of Science and Culture S. H. Davarpanah Davarpanah@usc.ac.ir.

2

A problem is represented by a triple (I, O, G) where: I - initial state, O - a set of operators on states (successor function), G - goal states.

A solution to the problem is a finite sequence of applications of operators that changes the initial state into a goal state.

The state-space representation of a problemThe state-space representation of a problem

I

G

O3

O5

O1

O3

O2

O6

Which is a solution for this (I, O, G) problem?

Page 3: 1 Computer Group Engineering Department University of Science and Culture S. H. Davarpanah Davarpanah@usc.ac.ir.

3

جستجو؟ جستجو؟ چرا چرا

آيند، جستجو روندهاي مي بكار مصنوعي هوش زمينه‌هاي از بسياري درمسائل اين كننده حل كه كامپيوترهايي سرياليتي خصوصيت كه چرا

جواب‌ها يافتن جهت جستجو الگوريتم‌هاي از كه مي‌كند ايجاب مي‌باشند، . شود استفاده مسائل از وسيعي بسيار بازه در

رو این از از مجموعه‌اي و هدف يك مثابه به مي‌تواند مسئله يك . باشد هدف آن به رسيدن جهت در شده گرفته خدمت به لذا فعاليت‌هاي

. باشد می مسئله آن حاالت فضای در جستجحو چیزی مسئله آن حل راه

Page 4: 1 Computer Group Engineering Department University of Science and Culture S. H. Davarpanah Davarpanah@usc.ac.ir.

4

مسائل مسائل انواع انواع

: شوند می تقسیم دسته چهار به مسائلحالته )1. تک ( :Single State Problemsمسائل

دریافت • کامل بطور را محیط تمام بطوریکه باشند، می قوی کامال حسگرها. کنند می

•. باشد می مشخص دقیقا عمل هر نتیجهحالته )2. چند ( :Multiple State Problemsمسائل

•. نداریم حسگر اصال یا و بوده ضعیف حسگرها•. است مشخص کامال عمل هر نتیجه

احتمالی )3. ( :Contingency Problemsمسائل•. دهند نمی را محیط کامل وضعیت حسگرها•. باشد نمی مطلع نیز عملش نتیجه از عامل

. نمود : استفاده ریزی برنامه از باید مسائل این حل برای نکتهاکتشافی )4. ( :Exploration Problemsمسائل

•. ندارند نقصی هیچ حسگرها•. نداریم عمل نتیجه از اطالعی کوچکترین

. است : تجربه کسب حل راه تنها نکته

Page 5: 1 Computer Group Engineering Department University of Science and Culture S. H. Davarpanah Davarpanah@usc.ac.ir.

5

محور هدف يا محور داده محور جستجوهاي هدف يا محور داده جستجوهاي

. تا دسته‌بندي اين دارد وجود جستجو درخت يك جستجوي عمده دسته دو. است منطبق پايين به باال و باال به پايين روشهاي همان بر حدودي

محور • داده شروع ( Data-Driven Search)جستجوهاي اوليه وضعيت از

هدف وضعيت به رسيدن تا پيش‌روي منظور به عملگرها از و مي‌كنند . جلورونده زنجيره عنوان تحت همچنين روش‌ها اين مي‌نمايند استفاده

(Forward Chaining ) . مي‌شوند ناميده نيز

عقب • به و شود شورع هدف وضعيت از مي‌تواند جستجو عوض، در . حاالتي سمت به بايد حركات هنگام در برسد اوليه حالت به تا برگردد

. روش يك اين مي‌رسد هدف به معكوس جهت در بدانيم كه برگشتمحور هدف عقب (Goal-Driven Search )جستجو زنجيره عنوان تحت و است

. (Backward Chaining )رونده مي‌شود ناميده نيز

Page 6: 1 Computer Group Engineering Department University of Science and Culture S. H. Davarpanah Davarpanah@usc.ac.ir.

6

محور هدف يا محور داده محور جستجوهاي هدف يا محور داده جستجوهاي

آنها، • در كه چرا مي‌باشد، مفيد بيشتر مواقعي در محور هدف جستجوي. است مشخص كامًال\ هدف

دسترس ج • در اوليه داده‌هاي كه است مفيد زماني محور داده ستجوي

. چيست هدف كه نباشد مشخص حال عين در و باشند

•. باشند می گرا داده جستجوهای درس این در شده ارائه الگوریتمهای

Page 7: 1 Computer Group Engineering Department University of Science and Culture S. H. Davarpanah Davarpanah@usc.ac.ir.

Generic search algorithm

• Fringe = set of nodes generated but not expanded

• fringe := {initial state}• loop:

– if fringe empty, declare failure– choose and remove a node v from fringe– check if v’s state s is a goal state; if so, declare success– if not, expand v, insert resulting nodes into fringe

• Key question in search: Which of the generated nodes do we expand next?

Page 8: 1 Computer Group Engineering Department University of Science and Culture S. H. Davarpanah Davarpanah@usc.ac.ir.

8

Measuring the performance of the search methodsMeasuring the performance of the search methods

CompletenessIs the algorithm guaranteed to find a solution when there is one?

OptimalityDoes the algorithm find the optimal solution(i.e. a solution with a minimum path cost)?

Time complexityHow long does it take to find a solution?

Space complexityHow much memory is needed to perform the search?

What performance measures are important for a search method?

مقبولیتبیابد زمان بهترین در را جواب بهترین که است مقبول .الگوریتمی

ناپذیری برگشتو سعي روشهاي مي‌كنند استفاده عقب به برگشت از كه روشهايي . استفاده عقب برگشت روش از كه روشهايي مي‌شوند تلقي خطا

ناميده برگشت‌ناپذير مي‌نمايند، امتحان را مسير يك فقط و نمي‌كنند .مي‌شوند

Page 9: 1 Computer Group Engineering Department University of Science and Culture S. H. Davarpanah Davarpanah@usc.ac.ir.

9

Complexity estimation factorsComplexity estimation factors

Branching factor b – maximum number of successors of a node

Depth d of the shallowest goal node

Maximum length m of a path in the graph

For a problem represented as an implicit graph(i.e. an initial state and a successor function)

Time – measured in terms of the number of nodes generated during search

Space – measured in terms of the maximum number of nodes stored in memory

Search cost – based on time complexity and memory usage

Total cost – combines search cost and path cost

Page 10: 1 Computer Group Engineering Department University of Science and Culture S. H. Davarpanah Davarpanah@usc.ac.ir.

10

Find a path from the city S to the city G:

S

A

D

B

E

C

F

G

34 4

5 5

42

43

Another search problemAnother search problem

Two broad classes of search methods: - uninformed (or blind) search methods; - heuristically informed search methods.

Page 11: 1 Computer Group Engineering Department University of Science and Culture S. H. Davarpanah Davarpanah@usc.ac.ir.

11

بینا و کور بینا جستجوی و کور جستجوی

کور اطًالعات • جستجو الگوریتمهای درخت در جابجايي نحوه حد در . شود جابجا جستجو درخت داخل در چطور اينكه مورد در باشد مي

و است محدود نود يك بودن هدف يا و برگ تعيين نحوه حتي يا وجستجو خاص ترتيبي به را نودها تك تك محدوديتي هيچ بدون بايد

. برسد هدف به تا نمايد

اضافي • اطًالعات اگر است آگاه مكاشفه‌اي جستجو، روش يكتا باشد داشته نشده‌اند داده بسط و بيان هنوز كه نودهايي درباره

. نمايد بررسي ابتدا را نود كدام كه بگيرد تصميم عبارت ببتواند هآگاه مي‌نمايند استفاده مكاشفه‌ها از كه جستجويي روشهاي ديگر،

انتخاب هستند. نودهای نتیجه در و ها مکاشفه که ندارد لزومی. باشند درست کامًال شونده

Page 12: 1 Computer Group Engineering Department University of Science and Culture S. H. Davarpanah Davarpanah@usc.ac.ir.

Uninformed search• Given a state, we only know whether it is a goal state

or not• Cannot say one nongoal state looks better than

another nongoal state• Can only traverse state space blindly in hope of

somehow hitting a goal state at some point– Also called blind search– Blind does not imply unsystematic!

Page 13: 1 Computer Group Engineering Department University of Science and Culture S. H. Davarpanah Davarpanah@usc.ac.ir.

13

(Generate and Test) تست و ) (Generate and Testالگوریتمتوليد تست و الگوریتمتوليد

• . اين براساس مي‌شود ناميده تست و توليد جستجو، براي راه ساده‌تريننود كه مي‌گردد تست و مي‌شود توليد جستجو فضاي در نود هر روش

. است شده انجام موفقيت با جستجو كه است هدف اگر خير يا است هدف . بعدي نود براي روال همين صورت اين غير در نيست كار ادامه به نيازي و

. شد خواهد تكرار

توليدكننده • يك به احتياج تست و توليد الگوريتم موفقت، منظور به : باشد زير خاصيت سه داراي كه دارد مناسب

1 - . غير در كه چرا نمايد توليد را ممكن حل راه هر يعني باشد كامل بايد . بدهد دست از را مناسب حل راه يك است ممكن صورت اين

2 . . ننمايد- توليد مرتبه دو را حل راه يك يعني باشد نداشته افزونگي بايد3 . هر- و دهد پيشنهاد مناسب راه‌حل‌هاي بايد فقط يعني باشد مطلع بايد

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

Page 14: 1 Computer Group Engineering Department University of Science and Culture S. H. Davarpanah Davarpanah@usc.ac.ir.

14

(Generate and Test) تست و ) (Generate and Testالگوریتمتوليد تست و الگوریتمتوليد

مورد • در اضافي اطًالعات كه هنگامي در نيز مردم روزمره زندگي در. مي‌گيرد قرار استفاده مورد روش اين ندارد، وجود مسئله يك حل راه

Page 15: 1 Computer Group Engineering Department University of Science and Culture S. H. Davarpanah Davarpanah@usc.ac.ir.

15

Find a path from S to G: Look for the goal node G among all the nodes at a given level before using the children of those nodes to push on. S

A

D

B

E

C

F

G

34 4

5 5

42

43

Uninformed search: Breadth-firstUninformed search: Breadth-first

S

A D

BE

CF

G

D A

E E B B

A CECFBFD

Page 16: 1 Computer Group Engineering Department University of Science and Culture S. H. Davarpanah Davarpanah@usc.ac.ir.

16

Breadth-first search: DiscussionBreadth-first search: DiscussionS

A D

BE

CF

G

D A

E E B B

A CECFBFD

Complete?:

Optimal?:

Time complexity:

Space complexity:

Yes, if b is finite

Yes, if steps costs are identical

O(bd+1)

O(bd+1)

Where: d - depth of the shallowest goal nodeb – maximum number of successors of a node

Page 17: 1 Computer Group Engineering Department University of Science and Culture S. H. Davarpanah Davarpanah@usc.ac.ir.

17

S

A

D

B

E

C

F

G

34 4

5 5

42

43

S

A D

B D

D F

Uninformed search: Depth-first searchUninformed search: Depth-first search

C E

Find a path from S to G: Look for the goal node among all the children of the current node before using the sibling of this node to push on.

G

Page 18: 1 Computer Group Engineering Department University of Science and Culture S. H. Davarpanah Davarpanah@usc.ac.ir.

18

Uninformed search: Depth-first with backtrackingUninformed search: Depth-first with backtracking

Expand only one successor of the current node, and backtrack when there is no other successor.

S

A

D

B

E

C

F

G

34 4

5 5

42

43

S

A

B

C

G

E

FD

Page 19: 1 Computer Group Engineering Department University of Science and Culture S. H. Davarpanah Davarpanah@usc.ac.ir.

19

Depth-first search: DiscussionDepth-first search: Discussion

S

A

B

C

G

E

FD

Complete?:

Optimal?:

Time complexity:

Space complexity:

Yes

No

O(bm)

O(bm)

Depth-firstDepth-first with

backtracking

O(m)

S

A D

B D

D F

C EC E

G

Yes

No

O(bm)

(if it does not have an unbounded depth)

Where: m - maximum length of a path in the graphb – maximum number of successors of a node

Page 20: 1 Computer Group Engineering Department University of Science and Culture S. H. Davarpanah Davarpanah@usc.ac.ir.

20

Complementarity of Breadth-first and Depth-first searchComplementarity of Breadth-first and Depth-first search

Complete?:

Optimal?:

Time complexity:

Space complexity:

Yes

Yes

O(bd+1)

O(bd+1)

Yes

No

O(bm)

O(bm)

Breadth-first Depth-first

Where: d - depth of the shallowest goal node m - maximum length of a path in the graphb – maximum number of successors of a node

جوای به هرگز و کند گیر بینهایت شاخه یک در است ممکن عمق اول الگوریتمکنیم؟. چه نرسد

Page 21: 1 Computer Group Engineering Department University of Science and Culture S. H. Davarpanah Davarpanah@usc.ac.ir.

21

Depth Limited searchDepth Limited search

Depth-limited-first

S

A D

B D

D F

C EC E

GL

S

A

D

B

E

C

F

G

34 4

5 5

42

43

Find a path from S to G: Look for the goal node among all the children of the current node before using the sibling of this node to push on. The depth of these children nodes must be less than L.

Page 22: 1 Computer Group Engineering Department University of Science and Culture S. H. Davarpanah Davarpanah@usc.ac.ir.

22

Complementarity of Breadth-first and Depth-first searchComplementarity of Breadth-first and Depth-first search

Complete?:

Optimal?:

Time complexity:

Space complexity:

Yes

Yes

O(bd+1)

O(bd+1)

Yes if L>=d

No

O(bL)

O(bL)

Breadth-first Depth-limited-first

Where: d - depth of the shallowest goal node m - maximum length of a path in the graphb – maximum number of successors of a nodeL – limited length of a path in the graph

How to define a search strategy that takes advantage of this complementarity?

Page 23: 1 Computer Group Engineering Department University of Science and Culture S. H. Davarpanah Davarpanah@usc.ac.ir.

23

S

A

D

B

E

C

F

G

34 4

5 5

42

43

Iterative deepening depth-first searchIterative deepening depth-first search

Performs successive depth-first searches, considering increasing depth searches, until a goal node is reached.

Depth 1:

Depth 0:

SD

A E

A

B D

S

SA

SDA

Depth 2: SA

B

SA

B D

SD

A

A

B D

Depth 3: SA

B

C

SA

B

C E

SA

B

C E

D

E

SA

B

C E

D

E

D

A

B

Page 24: 1 Computer Group Engineering Department University of Science and Culture S. H. Davarpanah Davarpanah@usc.ac.ir.

24

Iterative deepening depth-first search: DiscussionIterative deepening depth-first search: Discussion

Complete?:

Optimal?:

Time complexity:

Space complexity:

Yes, if b is finite

Yes*

O(bd)

O(bd)

Complete?:

Optimal?:

Time complexity:

Space complexity:

Yes

O(bd+1)

O(bd+1)

Yes

No

O(bm)

O(bm)

Breadth-first Depth-firstCompare with:

Yes*

* if steps costs are all identical

Remark: Time complexity is better than for breadth-first search because breadth-first expands also some nodes at level d+1

Page 25: 1 Computer Group Engineering Department University of Science and Culture S. H. Davarpanah Davarpanah@usc.ac.ir.

25

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

ريشه ۱ نودb اول سطح در نود

b2 دوم سطح در نودسطح .... در ام nنود

با است برابر نودها تعداد مجموع رو، اين از

: با است برابر آن مجموع و است هندسي تصاعد يك كه

Iterative deepening depth-first search – Time ComplexityIterative deepening depth-first search – Time Complexity

nb...bbb 321

b

bn

1

1 1

Page 26: 1 Computer Group Engineering Department University of Science and Culture S. H. Davarpanah Davarpanah@usc.ac.ir.

26

با است برابر مقدار این گام به گام الگوریتم روش برای و

عمق ز مثًال با درخت يك براي نياز مورد شدن 4مان شاخه شاخه فاكتور 10و: با است برابر

(4+1 + )10×4 + 100×3 + 1000×2 + 10000=12345نود

DFID : دارد الزم زير قرار به نودهايي تعداد نيز

جدید الگوریتم در شونده بررسی نودهای تعداد شدن% 10حداکثر زیاد با که است بیشترشود می کاسته تفاوت این مقدار از شدن شاخه فاکتورشاخه و سطوح .تعداد

Iterative deepening depth-first search – Time ComplexityIterative deepening depth-first search – Time Complexity

db....)d(b)d(b)d(b)d( 211 32

11111101101 5

Page 27: 1 Computer Group Engineering Department University of Science and Culture S. H. Davarpanah Davarpanah@usc.ac.ir.

27

S

A

D

B

E

C

F

G

34 4

5 5

42

43

C(i,j) = cost of an arc from node i to node jC(x,z) = C(x,y) + C(y,z)

Uninformed search: Uniform-costUninformed search: Uniform-cost

Find the minimum cost path from S to G:

S

A D

3 4

3 4

B D

54

87

C E

4 5

11 12

G

3

13

B F

45

1011

A E

5 2

69

step 1

step 2 step 3

step 4step 5

step 6

Always expands the node that has the smallest cost to S.

Page 28: 1 Computer Group Engineering Department University of Science and Culture S. H. Davarpanah Davarpanah@usc.ac.ir.

28

Uniform-cost search: DiscussionUniform-cost search: Discussion

Complete?:

Optimal?:

Time complexity:

Space complexity:

Yes, if b is finite and all steps have positive costs

Yes

O(b[C*/e]), where C* is the cost of the optimal solution,and every action costs at least e

O(b[C*/e])

SS

A D

3 4

3 4A D

3 4

3 4

B D

54

87B D

54

87

C E

4 5

11 12C E

4 5

11 12

G

3

13G

3

13

B F

45

1011 B F

45

1011

A E

5 2

69A E

5 2

69

Page 29: 1 Computer Group Engineering Department University of Science and Culture S. H. Davarpanah Davarpanah@usc.ac.ir.

29

Bidirectional Search (if applicable)Bidirectional Search (if applicable)

Complete?:

Optimal?:

Time complexity:

Space complexity:

Yes

Yes

O(bd/2)

O(bd/2)

Where: d - depth of the shallowest goal nodeb – maximum number of successors of a node

S

A

D

B

E

C

F

G

34 4

5 5

42

43

S

A

D

F G

BB

EA

E D