290 likes | 417 Views
Introduction to Artificial Intelligence. Problem Solving Through Uninformed Search. S. H. Davarpanah Davarpanah@usc.ac.ir. Computer Group Engineering Department University of Science and Culture. The state-space representation of a problem.
E N D
Introduction to Artificial Intelligence Problem Solving Through Uninformed Search S. H. Davarpanah Davarpanah@usc.ac.ir Computer Group Engineering Department University of Science and Culture
The state-space representation of a problem 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. Which is a solution for this (I, O, G) problem?
چرا جستجو؟ روندهاي جستجو در بسياري از زمينههاي هوش مصنوعي بكار مي آيند، چرا كه خصوصيت سرياليتي كامپيوترهايي كه حل كننده اين مسائل ميباشند، ايجاب ميكند كه از الگوريتمهاي جستجو جهت يافتن جوابها در بازه بسيار وسيعي از مسائل استفاده شود. از این رو يك مسئله ميتواند به مثابه يك هدف و مجموعهاي از فعاليتهاي به خدمت گرفته شده در جهت رسيدن به آن هدف باشد. لذا راه حل آن مسئله چیزی جستجحو در فضای حالات آن مسئله می باشد.
انواع مسائل • مسائل به چهار دسته تقسیم می شوند: • مسائل تک حالته (Single State Problems) : • حسگرها کاملا قوی می باشند، بطوریکه تمام محیط را بطور کامل دریافت می کنند. • نتیجه هر عمل دقیقا مشخص می باشد. • مسائل چند حالته (Multiple State Problems) : • حسگرها ضعیف بوده و یا اصلا حسگر نداریم. • نتیجه هر عمل کاملا مشخص است. • مسائل احتمالی (Contingency Problems) : • حسگرها وضعیت کامل محیط را نمی دهند. • عامل از نتیجه عملش نیز مطلع نمی باشد. • نکته : برای حل این مسائل باید از برنامه ریزی استفاده نمود. • مسائل اکتشافی (Exploration Problems) : • حسگرها هیچ نقصی ندارند. • کوچکترین اطلاعی از نتیجه عمل نداریم. • نکته : تنها راه حل کسب تجربه است.
جستجوهاي داده محور يا هدف محور • دو دسته عمده جستجوي يك درخت جستجو وجود دارد. اين دستهبندي تا حدودي بر همان روشهاي پايين به بالا و بالا به پايين منطبق است. • جستجوهاي داده محور(Data-Driven Search) از وضعيت اوليه شروع ميكنند و از عملگرها به منظور پيشروي تا رسيدن به وضعيت هدف استفاده مينمايند. اين روشها همچنين تحت عنوان زنجيره جلورونده (Forward Chaining ) نيز ناميده ميشوند. • در عوض، جستجو ميتواند از وضعيت هدف شورع شود و به عقب برگردد تا به حالت اوليه برسد. در هنگام حركات بايد به سمت حالاتي برگشت كه بدانيم در جهت معكوس به هدف ميرسد. اين يك روش جستجو هدف محور (Goal-Driven Search) است و تحت عنوان زنجيره عقب رونده (Backward Chaining) نيز ناميده ميشود.
جستجوهاي داده محور يا هدف محور • جستجوي هدف محور در مواقعي بيشتر مفيد ميباشد، چرا كه در آنها، هدف كاملاً مشخص است. • جستجوي داده محور زماني مفيد است كه دادههاي اوليه در دسترس باشند و در عين حال مشخص نباشد كه هدف چيست. • الگوریتمهای ارائه شده در این درس جستجوهای داده گرا می باشند.
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?
Measuring the performance of the search methods What performance measures are important for a search method? Completeness Is the algorithm guaranteed to find a solution when there is one? Optimality Does the algorithm find the optimal solution(i.e. a solution with a minimum path cost)? Time complexity How long does it take to find a solution? Space complexity How much memory is needed to perform the search? مقبولیت الگوریتمی مقبول است که بهترین جواب را در بهترین زمان بیابد. برگشت ناپذیری روشهايي كه از برگشت به عقب استفاده ميكنند روشهاي سعي و خطا تلقي ميشوند. روشهايي كه از روش برگشت عقب استفاده نميكنند و فقط يك مسير را امتحان مينمايند، برگشتناپذير ناميده ميشوند.
Complexity estimation factors For a problem represented as an implicit graph (i.e. an initial state and a successor function) 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 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
Another search problem Find a path from the city S to the city G: Two broad classes of search methods: - uninformed (or blind) search methods; - heuristically informed search methods.
جستجوی کور و بینا • اطلاعات الگوریتمهای کور در حد نحوه جابجايي در درخت جستجو مي باشد. در مورد اينكه چطور در داخل درخت جستجو جابجا شود و يا حتي نحوه تعيين برگ و يا هدف بودن يك نود محدود است و بايد بدون هيچ محدوديتي تك تك نودها را به ترتيبي خاص جستجو نمايد تا به هدف برسد. • يك روش جستجو، مكاشفهاي آگاه است اگر اطلاعات اضافي درباره نودهايي كه هنوز بيان و بسط داده نشدهاند داشته باشد تا بتواند تصميم بگيرد كه كدام نود را ابتدا بررسي نمايد. به عبارت ديگر، روشهاي جستجويي كه از مكاشفهها استفاده مينمايند آگاه هستند. لزومی ندارد که مکاشفه ها و در نتیجه نودهای انتخاب شونده کاملا درست باشند.
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!
(Generate and Test) توليد و تستالگوریتم • سادهترين راه براي جستجو، توليد و تست ناميده ميشود. براساس اين روش هر نود در فضاي جستجو توليد ميشود و تست ميگردد كه نود هدف است يا خير. اگر هدف است كه جستجو با موفقيت انجام شده است و نيازي به ادامه كار نيست. در غير اين صورت همين روال براي نود بعدي تكرار خواهد شد. • به منظور موفقت، الگوريتم توليد و تست احتياج به يك توليدكننده مناسب دارد كه داراي سه خاصيت زير باشد: • 1-بايد كامل باشد يعني هر راه حل ممكن را توليد نمايد. چرا كه در غير اين صورت ممكن است يك راه حل مناسب را از دست بدهد. • 2- بايد افزونگي نداشته باشد. يعني يك راه حل را دو مرتبه توليد ننمايد. • 3- بايد مطلع باشد. يعني فقط بايد راهحلهاي مناسب پيشنهاد دهد و هر راه حلي را كه با فضاي جستجو سازگار نيست مورد بررسي قرار ندهد.
(Generate and Test) توليد و تستالگوریتم • در زندگي روزمره مردم نيز در هنگامي كه اطلاعات اضافي در مورد راه حل يك مسئله وجود ندارد، اين روش مورد استفاده قرار ميگيرد.
Uninformed search: Breadth-first 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.
Breadth-first search: Discussion O(bd+1) O(bd+1) Complete?: Yes, if b is finite Optimal?: Yes, if steps costs are identical Time complexity: Space complexity: Where: d - depth of the shallowest goal node b – maximum number of successors of a node
Uninformed 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. S A D B D D F G
Uninformed search: Depth-first with backtracking Expand only one successor of the current node, and backtrack when there is no other successor.
Depth-first search: Discussion Depth-first with backtracking Depth-first Complete?: Yes Yes (if it does not have an unbounded depth) Optimal?: No No Time complexity: O(bm) O(bm) Space complexity: O(bm) O(m) Where: m - maximum length of a path in the graph b – maximum number of successors of a node
Complementarity of Breadth-first and Depth-first search Depth-first Breadth-first Complete?: Yes Yes Optimal?: Yes No Time complexity: O(bd+1) O(bm) Space complexity: O(bd+1) O(bm) Where: d - depth of the shallowest goal node m - maximum length of a path in the graph b – maximum number of successors of a node الگوریتم اول عمق ممکن است در یک شاخه بینهایت گیر کند و هرگز به جوای نرسد. چه کنیم؟
DepthLimitedsearch S A D B D C C E E Depth-limited-first D F L G 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.
Complementarity of Breadth-first and Depth-first search Depth-limited-first Breadth-first Complete?: Yes Yes if L>=d Optimal?: Yes No Time complexity: O(bd+1) O(bL) Space complexity: O(bd+1) O(bL) Where: d - depth of the shallowest goal node m - maximum length of a path in the graph b – maximum number of successors of a node L – limited length of a path in the graph How to define a search strategy that takes advantage of this complementarity?
Iterative deepening depth-first search Performs successive depth-first searches, considering increasing depth searches, until a goal node is reached. Depth 0: S Depth 1: S S A A D Depth 2: S S S S A A A D A D B B D B D A B D A E Depth 3: S S S S A A A A D … B B B D B D A C C E C E E C E E B
Iterative deepening depth-first search: Discussion Complete?: Yes, if b is finite Optimal?: Yes* * if steps costs are all identical Time complexity: O(bd) Space complexity: O(bd) Compare with: Depth-first Breadth-first Complete?: Yes Yes Optimal?: Yes* No Time complexity: O(bd+1) O(bm) Space complexity: O(bd+1) O(bm) Remark: Time complexity is better than for breadth-first search because breadth-first expands also some nodes at level d+1
Iterative deepening depth-first search– Time Complexity • براي يكدرخت از عمقd با فاكتور شاخه شاخه شدن برابر b، مجموع تعداد نودها در روش اول سطح برابر است با • ۱ نود ريشه • bنود در سطح اول • b2نود در سطح دوم • ....نود در سطح nام • از اين رو، مجموع تعداد نودها برابر است با • كه يك تصاعد هندسي است و مجموع آن برابر است با:
Iterative deepening depth-first search– Time Complexity و برای روش الگوریتم گام به گام این مقدار برابر است با مثلازمان مورد نياز براي يك درخت با عمق 4و فاكتور شاخه شاخه شدن 10 برابر است با: نود12345=10000 + 2×1000 + 3×100 + 4×10 + (1+4) DFIDنيز تعداد نودهايي به قرار زير لازم دارد: حداکثر تعداد نودهای بررسی شونده در الگوریتم جدید 10% بیشتر است که با زیاد شدن تعداد سطوح و فاکتورشاخه شاخه شدن از مقدار این تفاوت کاسته می شود.
Uninformed search: Uniform-cost S 3 4 A 3 4 D 4 5 5 2 B 7 8 D A 9 6 E 5 4 4 5 C 11 12 E 11 B F 10 3 G 13 C(i,j) = cost of an arc from node i to node j C(x,z) = C(x,y) + C(y,z) Always expands the node that has the smallest cost to S. Find the minimum cost path from S to G: step 1 step 2 step 3 step 5 step 4 step 6
Uniform-cost search: Discussion Complete?: Yes, if b is finite and all steps have positive costs Optimal?: Yes Time complexity: O(b[C*/e]), where C* is the cost of the optimal solution, and every action costs at least e Space complexity: O(b[C*/e])
Bidirectional Search (if applicable) B B A S A E F G D E D O(bd/2) O(bd/2) Complete?: Yes Optimal?: Yes Time complexity: Space complexity: Where: d - depth of the shallowest goal node b – maximum number of successors of a node