AI Ch3
AI Ch3
Page 1 of 31
By: Muhammad Mahmoud
How human beings think?
• Human beings do not search the entire state space (exha ustive search).
• Only alternatives that experience has shown to be effective are explored.
• Human problem solving is based on judgmental rules that limit the exploration of
search space to those portions of state space that seem somehow promising.
• These judgmental rules are known as “heuristics”.
كيف يفكر البشر؟
.)• البشر ال يبحثون في جميع مساحة الحالة (البحث الشامل
.• يتم استكشاف البدائل فقط التي أظهرت التجربة أنها فّعالة
• حل مشاكل البشر يعتمد على قواعد استداللية تقّيد استكشاف مساحة البحث إلى تلك األجزاء من
.مساحة الحالة التي تبدو واعدة بطريقة ما
."• ُتعرف هذه القواعد االستداللية باسم "الخوارزميات االستداللية
All AI is search ?
• Not totally true (obviously) but more true than you might think.
• All life is problem solving !!
Finding a good/best solution to a problem between many possible solutions
هل كل الذكاء الصناعي هو بحث؟
.• ليس صحيًح ا تماًم ا (بوضوح) ولكنه أكثر صحة مما قد تعتقد
!• جميع الحياة هي حل مشكالت
. أفضل لمشكلة بين العديد من الحلول الممكنة/ البحث عن حل جيد
Problem-Solving Agents
• Goals help to organize behavior by limiting the objectives that the agent is trying to
achieve.
وكالء حل المشكالت
• نوع من الوكالء المبنيين على األهداف يقررون ما يجب فعله عن طريق العثور على سالسل من
.األفعال التي تؤدي إلى حاالت مرغوب فيها
.• تساعد األهداف في تنظيم السلوك من خالل تحديد األهداف التي يحاول الوكيل تحقيقها
Page 2 of 31
By: Muhammad Mahmoud
Example: Romania
Formulate problem:
states: various cities
actions: drive between cities
Find solution:
sequence of cities, e.g.,
Arad, Sibiu, Fagaras, Bucharest
رومانيا:مثال
. الرحلة تغادر غًدا من بوخارست،في عطلة في رومانيا؛ حالًيا في أراد
المدن بوخارست،فاجاراس
Problem formulation is the process of deciding what actions and states to consider,
given the goal formulation.
وكيل حل المشكالت
صياغة الهدف هي الخطوة األولى في-
استناًدا إلى الوضع الحالي،حل المشكالت
.وقياس أداء الوكيل
Page 3 of 31
By: Muhammad Mahmoud
Problem Solving Agent (cont.)
• An agent with several immediate options of unknown value can decide what to do by
first examining different possible sequences of actions that lead to states of known
value, and then choosing the best sequences.
The process of looking for a sequence of actions that reaches
the goal is called search.
A search algorithm takes a problem as input and returns a
solution in the form of an action sequence.
Once a solution is found, the actions it recommends can be carried out through
the execution phase.
Thus, the agent design is simply consists of “formulate, search, execute”
phases.
• Once the solution has been executed, the agent will formulate a new
goal.
• الوكيل الذي يمتلك عدة خيارات فورية ذات قيمة غير معروفة يمكنه اتخاذ قرار حول ما
يجب القيام به من خالل دراسة مختلف سالسل األفعال الممكنة التي تؤدي إلى حاالت ذات
. ثم اختيار أفضل السالسل،قيمة معروفة
. العملية التي يتم فيها البحث عن سلسلة من األفعال التي تصل إلى الهدف تسمى بالبحث-
. خوارزمية البحث تأخذ مشكلة كمدخالت وتعيد حًال في شكل سلسلة من األفعال-
. يمكن تنفيذ اإلجراءات التي يوصي بها من خالل مرحلة التنفيذ، بمجرد العثور على الحل-
." تنفيذ، بحث، تصميم الوكيل يتكون ببساطة من مراحل "صياغة، بالتالي-
. سيقوم الوكيل بصياغة هدف جديد،بمجرد تنفيذ الحل
Page 4 of 31
By: Muhammad Mahmoud
Problem Solving Agent (cont.)
• The agent must find a sequence of actions that reaches the goal.
• The performance measure is defined by:
(a) reaching the goal, and …
(b) how “expensive” the path to the goal is.
.سننظر في مشكلة تصميم الوكالء المبنية على األهداف في بيئات معروفة تماًما ومحددة وغير مستمرة
. يجب على الوكيل أن يجد سلسلة من األفعال التي تصل إلى الهدف-
: تحدد قياسات األداء عن طريق-
... و،) الوصول إلى الهدفa(
.) كيفية "تكلفة" المسار إلى الهدفb(
4. The goal test, which determines whether a given state is a goal state.
المشكلة في الواقع هي مجموعة من المعلومات التي سيستخدمها الوكيل التخاذ قرار بما
.يجب القيام به
:يمكن تعريف المشكلة رسمًيا من خالل خمس مكونات
. الحالة االبتدائية التي يبدأ الوكيل فيها.1
. وصف لألفعال الممكنة المتاحة للوكيل.2
. وصف لما يقوم به كل فعل؛ نموذج االنتقال المسمى.3
. الذي يحدد ما إذا كانت حالة معينة هي حالة هدف، اختبار الهدف.4
. وظيفة تكلفة المسار التي تعين تكلفة عددية لكل مسار.5
A solution is a sequence of actions leading from the initial state (Arad) to a goal
state (Bucharest).
صياغة مشكلة تنقل الخريطة
Page 6 of 31
By: Muhammad Mahmoud
يتم تعريف المشكلة بخمس عناصر.1 :الحالة االبتدائية
» "في أراد"
.2األفعال
» على سبيل المثال ،من الحالة "في أراد"،
األفعال المطبقة هي {االنتقال إلى سيبيو ،االنتقال إلى تيميشوارا ،االنتقال إلى زيريند}.
.3النموذج االنتقالي:
» لدينا نموذج (RESULTفي أراد ،االنتقال إلى زيريند) = في زيريند
» أو دالة الخطوة التالية ) = Succ(xمجموعة من أزواج الفعل والحالة مثاًل (Succ ،في أراد) = {<االنتقال إلى
زيريند ،في زيريند>}... ،
.4اختبار الهدف ،ويمكن أن يكون
» صريًح ا ،على سبيل المثال" = x ،في بوخارست"
» ضمنًيا ،على سبيل المثال ،اختبار الخسارة ())Checkmate(x
.5تكلفة المسار (إضافية)
» على سبيل المثال ،مجموع المسافات ،عدد اإلجراءات التنفيذية ،وما إلى ذلك.
» ) c(x، a، yهو تكلفة الخطوة ،وُيفترض أن تكون ≥ 0
الحل هو تسلسل من األفعال الذي يقود من الحالة االبتدائية (أراد) إلى حالة هدف (بوخارست)
formulation
Agent location and dirt location o
?o How many possible states
?o What if there are n possible locations
o The size of the state space grows exponentially
!o with the “size” of the world
– Let the world contain just two locations.
– Each location may or may not contain dirt.
– The agent may be in one location or the other.
– Then, there are 8 possible world states.
Page 7 of 31
By: Muhammad Mahmoud
– A larger environment with n locations has States.
?Actions
• The agent has three possible actions: Left, Right, and Suck.
?Goal
• The goal is to clean up all the dirt - set of goal states is{7,8}.
Page 8 of 31
By: Muhammad Mahmoud
Ex: The 8-puzzle
Page 9 of 31
By: Muhammad Mahmoud
• states? real-valued coordinates of robot joint angles parts of the object to be
assembled (angles, displacements).
• actions? continuous motions of robot joints
• goal test? complete assembly , Configuration in which object is grasped.
• path cost? time to execute
.) انحرافات،• الحاالت؟ إحداثيات حقيقية لزوايا مفاصل الروبوت وأجزاء الكائن المراد تجميعه (زوايا
.• األفعال؟ حركات مستمرة لمفاصل الروبوت
. تكوين يتم فيه إمساك الكائن،• اختبار الهدف؟ تجميع كامل
.• تكلفة المسار؟ الوقت الالزم للتنفيذ
Example: Tic-Tac-Toe
• Nodes(N): all the different configuration of Xs and Os that the game can have.
• Arcs (A): generated by legal moves by placing an X or an O in unused location.
• Start state (S): an empty board.
• Goal states (GD): a board state having three Xs in a row, column, or diagonal.
• The arcs are directed, then no cycles in the state space, directed acyclic graph
(DAG).
• Complexity: 9! Different paths can be generated.
. التي يمكن أن تتبعها اللعبةOs وXs جميع التكوينات المختلفة لـ:)N( • العقد
. في الموقع الغير مستخدمO أوX ُتولد بواسطة الحركات القانونية عن طريق وضع:)A( • األسهم
. لوح فارغ:)S( • الحالة االبتدائية
. في صف أو عمود أو قطرXs حالة لوح تحتوي على ثالثة:)GD( • حاالت الهدف
.)DAG( مخطط موجه دائري، ثم ال توجد دورات في مساحة الحالة،• األسهم موجهة
.! يمكن توليد مسارات مختلفة9 :• التعقيد
1. Single-state problems
3. Contingency problems
4. Exploration problems
1- Single-State Problem
Single-state problems
» The agent’s sensors provide enough information for the agent to tell exactly which
state it is in Fully observable.
» The agent knows exactly the effects of all its actions Deterministic.
» Then, the agent can calculate exactly which state it will be in after any sequence of
actions.
:المشكالت ذات الحالة الواحدة
حيث توفر أجهزة االستشعار للوكيل ما يكفي من المعلومات ليعرف بالضبط في أي حالة-
.يتواجد => مرئي بالكامل
. يعرف الوكيل تماًما تأثيرات جميع أفعاله => قطعي-
. يمكن للوكيل حساب بالضبط في أي حالة سيكون بعد أي تسلسل من األفعال، بعد ذلك-
.
initial state: 5.
Solution?
-The action sequence [Right, Suck] will
get to a goal state
2- Multiple-State Problem
Page 11 of 31
By: Muhammad Mahmoud
Multiple-state (sensorless)
problems
» The agent is not certain about which state in a given set of states it is in (has limited
access to the world state) Non-observable.
» The agent knows exactly the effects of all its actions Deterministic.
» the agent must reason about sets of states that it might get to, rather than single
states.
:)المشكالت ذات الحاالت المتعددة (بدون استشعار
الوكيل غير متأكد من الحالة التي يتواجد فيها ضمن مجموعة معينة من الحاالت (لديه وصول-
.محدود إلى حالة العالم) => غير مرئي
. الوكيل يعرف تماًما تأثيرات جميع أفعاله => قطعي-
. بدًال من حاالت فردية، يجب على الوكيل التفكير في مجموعات من الحاالت التي قد يصل إليها-
q Initial state:
start with one of the set {1, 2, 3, 4, 5, 6, 7,
8}.
q Goal: {7,8}.
3- Contingency problems
Page 12 of 31
By: Muhammad Mahmoud
Contingency problems
» Nondeterministic and/or partially observable
» The agent must now calculate a whole tree of actions, rather than a single
action sequence.
Each branch of the tree deals with a possible contingency that
might arise.
:مشكالت الظروف
.أو جزئيًا مرئية/ قد تكون غير قطعية و-
. حل هذه المشكلة يتطلب االستشعار خالل مرحلة التنفيذ-
. اإلدراكات توفر معلومات جديدة حول الحالة الحالية-
. بدًال من تسلسل اإلجراء الفردي، يجب على الوكيل اآلن حساب شجرة كاملة من اإلجراءات-
. كل فرع من الشجرة يتعامل مع ظروف محتملة قد تنشأ-
Goal: {7,8}.
Solution?
[Right, if dirt then Suck].
4-Exploration problems
Page 13 of 31
By: Muhammad Mahmoud
Exploration problems:
» Unknown state space (as lost in a desert without a map)
» The agent must experiment, gradually discovering what its actions do and what sorts
of states exist.
» This is a kind of search, but a search in the real world rather than in a model there of.
» If it survives, the agent learns a "map" of the environment, which it can then use to
solve subsequent problems.
:مشكالت االستكشاف
.) مساحة الحالة غير معروفة (مثل الضياع في الصحراء بدون خريطة-
. واكتشاف تدريجي لما تقوم به أفعاله وأنواع الحاالت الموجودة، يجب على الوكيل التجريب-
. ولكن بحث في العالم الحقيقي بدًال من نموذج له، هذا نوع من البحث-
التي يمكنه بعد ذلك استخدامها لحل المشاكل، يتعلم الوكيل "خريطة" للبيئة، إذا نجا-
.الالحقة
Basic Idea
Page 14 of 31
By: Muhammad Mahmoud
• Let’s begin at the start state and expand it by making a list of all possible
successor states.
• Maintain a frontier or a list of unexpanded states (open list).
idea
Search: Basic
Page 15 of 31
By: Muhammad Mahmoud
Search: Basic idea Search: Basic
idea
Search: Basic
idea
Page 16 of 31
By: Muhammad Mahmoud
where:
The root of the tree is start state;
The branches are actions ;and
– Else expand the node and add its children to the frontier.
Page 17 of 31
By: Muhammad Mahmoud
Tree search: Example
Frontier
New
frontiers
Page 18 of 31
By: Muhammad Mahmoud
Tree Search Algorithm
Search algorithms all share this basic structure; they vary primarily
according to how they choose which state to expand next—the so-
called search strategy.
خوارزميات البحث تشترك جميعها في هذا الهيكل األساسي؛ وتختلف أساسًا وفًقا لكيفية
. ما ُيعرف باستراتيجية البحث- اختيارها للحالة التي ستوسع بعدها
Page 19 of 31
By: Muhammad Mahmoud
Repeated states
• In(Arad) is a repeated state in the search tree, generated in this case by a loopy
path.
• Considering such loopy paths means that the complete search tree for Romania
is infinite.
• loops can cause certain algorithms to fail.
• The way to avoid exploring redundant paths that caused by repeated states is to
remember where state has been.
–To do this, we enhance the TREE-SEARCH algorithm with a data structure called the
explored set (also known as the closed list), which remembers every expanded node.
–Newly generated nodes that match previously generated nodes can be discarded instead
of being added to the frontier.
• The new algorithm is called GRAPH-SEARCH and it is more efficient on problems with
many repeated states.
• الطريقة لتجنب استكشاف المسارات الزائدة التي تسببت فيها الحاالت المتكررة هي تذكر مواقع تلك
.الحاالت
نعزز خوارزمية البحث في الشجرة ببنية بيانات ُتسمى مجموعة االستكشاف (المعروفة، للقيام بذلك-
. التي تذكر كل عقد تم توسيعه،)أيًض ا باسم القائمة المغلقة
. يمكن التخلص من العقد الجديدة التي تطابق العقد السابقة المولدة بدًال من إضافتها إلى الحافة-
وهي أكثر كفاءة في المشكالت التي تحتوي على العديدGRAPH-SEARCH • ُتسمى الخوارزمية الجديدة
.من الحاالت المتكررة
Page 20 of 31
By: Muhammad Mahmoud
Graph-Search Algorithm
• For each node n of the tree, we have a structure that contains four components:
• n.STATE: the state in the state space to which the node corresponds;
• n.PARENT: the node in the search tree that generated this node;
• n.ACTION: the action that was applied to the parent to generate the node;
• n.PATH-COST: the cost, traditionally denoted by g(n), of the path from the initial state to
the node, as indicated by the parent pointers.
: لدينا هيكل يحتوي على أربع مكونات، في الشجرةn • لكل عقد
. الحالة في مساحة الحالة التي يتوافق معها العقد:n.STATE •
. العقد في شجرة البحث الذي أنشأ هذا العقد:n.PARENT •
. اإلجراء الذي تم تطبيقه على األب إلنشاء العقد:n.ACTION •
. كما ُيشير إليه مؤشرات األب، للمسار من الحالة االبتدائية إلى العقد،g(n) المعتادة تمييزًا ب، التكلفة:n.PATH-COST •
Graph-Search Algorithm
Page 21 of 31
By: Muhammad Mahmoud
Infrastructure for search algorithms
• For each node n of the tree, we have a structure that contains four components:
• n.STATE: the state in the state space to which the node corresponds;
• n.PARENT: the node in the search tree that generated this node;
• n.ACTION: the action that was applied to the parent to generate the node;
• n.PATH-COST: the cost, traditionally denoted by g(n), of the path from the initial state to
the node, as indicated by the parent pointers.
: لدينا هيكل يحتوي على أربع مكونات، في الشجرةn • لكل عقد
. الحالة في مساحة الحالة التي يتوافق معها العقد:n.STATE •
. العقد في شجرة البحث الذي أنشأ هذا العقد:n.PARENT •
. اإلجراء الذي تم تطبيقه على األب إلنشاء العقد:n.ACTION •
كما ُيشير، للمسار من الحالة االبتدائية إلى العقد،g(n) المعتادة تمييزًا ب، التكلفة:n.PATH-COST •
.إليه مؤشرات األب
Search strategies
Page 22 of 31
By: Muhammad Mahmoud
optimality: does it always find a least-cost solution?
Page 23 of 31
By: Muhammad Mahmoud
• Game playing
– An adversarial search: Mini-max algorithm, alpha-beta pruning
MCQ Chapter 3
1. Which phase of problem-solving involves deciding what actions and states to consider, given the goal
formulation?
a) Goal formulation
b) Problem formulation
c) Solution execution
d) Problem-solving agent design
2. What are the judgmental rules limiting the exploration of search space in human problem-solving
known as?
a) Algorithms
b) Heuristics
c) State space
d) Goal states
3. In problem-solving agents, what is the first step in problem-solving based on the current situation and
performance measure?
a) Goal formulation
b) Problem formulation
c) Solution execution
d) Problem-solving agent design
4. Which problem-solving agent decides what to do by finding sequences of actions leading to desirable
states?
a) Reactive agents
b) Deliberative agents
c) Goal-based agents
d) Utility-based agents
5. In the context of problem formulation, what determines whether a given state is a goal state?
a) Initial state
b) Transition model
c) Goal test
d) Path cost function
Page 24 of 31
By: Muhammad Mahmoud
6. Which type of problem-solving problem requires sensing during the execution phase?
a) Single-state problems
b) Multiple-state problems
c) Contingency problems
d) Exploration problems
7. In the context of search algorithms, what is the process of considering various possible action
sequences called?
a) Execution
b) Expansion
c) Search
d) Evaluation
10. Which search strategy evaluates nodes based on an evaluation function and guides the search
towards the goal?
a) Uninformed search
b) Heuristic search
c) Optimization search
d) Game-playing search
11. Which type of problem-solving agent is most appropriate for game-playing scenarios?
a) Goal-based agents
b) Reactive agents
c) Utility-based agents
d) Deliberative agents
Page 25 of 31
By: Muhammad Mahmoud
12. What type of problem-solving problem involves reasoning about sets of states rather than single
states?
a) Single-state problems
b) Multiple-state problems
c) Contingency problems
d) Exploration problems
13. Which algorithm efficiently handles problems with many repeated states by maintaining an explored
set?
a) Graph-Search
b) Depth-Limited Search
c) Uniform-Cost Search
d) Bidirectional Search
14. In problem formulation, what determines the numeric cost assigned to each path?
a) Initial state
b) Transition model
c) Goal test
d) Path cost function
15. What dimension evaluates search strategies based on whether they always find a solution if one
exists?
a) Completeness b) Time complexity
c) Space complexity d) Optimality
16. Which algorithm expands nodes based on the least-cost solution path?
a) A*
b) Greedy best-first
c) Depth-First Search
d) Breadth-First Search
17. In the context of problem-solving agents, what is the process of deciding what actions and states to
consider, given the goal formulation?
a) Goal formulation
b) Problem formulation
c) Solution execution
d) Problem-solving agent design
18. Which type of problem-solving problem involves reasoning about sets of states rather than single
Page 26 of 31
By: Muhammad Mahmoud
states?
a) Single-state problems
b) Multiple-state problems
c) Contingency problems
d) Exploration problems
19. What dimension evaluates search strategies based on the number of nodes generated?
a) Completeness
b) Time complexity
c) Space complexity
d) Optimality
20. Which search strategy does not have additional information about states beyond that provided in the
problem definition?
a) Uninformed search
b) Heuristic search
c) Optimization search
d) Game-playing search
21. Which algorithm efficiently handles problems with many repeated states by maintaining an explored
set?
a) Graph-Search
b) Depth-First Search
c) Uniform-Cost Search
d) Bidirectional Search
22. In problem formulation, what determines the numeric cost assigned to each path?
a) Initial state
b) Transition model
c) Goal test
d) Path cost function
23. What dimension evaluates search strategies based on whether they always find a solution if one
exists?
a) Completeness
b) Time complexity
c) Space complexity
d) Optimality
24. Which algorithm expands nodes based on the least-cost solution path?
a) A*
b) Greedy best-first
Page 27 of 31
By: Muhammad Mahmoud
c) Depth-First Search
d) Breadth-First Search
25. What is the process of considering various possible action sequences in problem-solving called?
a) Execution
b) Expansion
c) Search
d) Evaluation
26. Which search strategy evaluates nodes based on an evaluation function and guides the search
towards the goal?
a) Uninformed search
b) Heuristic search
c) Optimization search
d) Game-playing search
27. In problem-solving agents, what is the first step in problem-solving based on the current situation and
performance measure?
a) Goal formulation
b) Problem formulation
c) Solution execution
d) Problem-solving agent design
28. Which type of problem-solving problem involves reasoning about sets of states rather than single
states?
a) Single-state problems
b) Multiple-state problems
c) Contingency problems
d) Exploration problems
29. What dimension evaluates search strategies based on the number of nodes generated?
a) Completeness
b) Time complexity
c) Space complexity
d) Optimality
30. Which search strategy does not have additional information about states beyond that provided in the
problem definition?
a) Uninformed search
b) Heuristic search
c) Optimization search
Page 28 of 31
By: Muhammad Mahmoud
d) Game-playing search
31. Which algorithm efficiently handles problems with many repeated states by maintaining an explored
set?
a) Graph-Search
b) Depth-First Search
c) Uniform-Cost Search
d) Bidirectional Search
32. In problem formulation, what determines the numeric cost assigned to each path?
a) Initial state
b) Transition model
c) Goal test
d) Path cost function
33. What dimension evaluates search strategies based on whether they always find a solution if one
exists?
a) Completeness
b) Time complexity
c) Space complexity
d) Optimality
34. Which algorithm expands nodes based on the least-cost solution path?
a) A*
b) Greedy best-first
c) Depth-First Search
d) Breadth-First Search
35. What dimension evaluates search strategies based on whether they always find a solution if one
exists?
a) Completeness
b) Time complexity
c) Space complexity
d) Optimality
36. Which search strategy evaluates nodes based on an evaluation function and guides the search
towards the goal?
a) Uninformed search
b) Heuristic search
c) Optimization search
d) Game-playing search
Page 29 of 31
By: Muhammad Mahmoud
37. In problem-solving agents, what is the first step in problem-solving based on the current situation and
performance measure?
a) Goal formulation
b) Problem formulation
c) Solution execution
d) Problem-solving agent design
38. Which type of problem-solving problem involves reasoning about sets of states rather than single
states?
a) Single-state problems
b) Multiple-state problems
c) Contingency problems
d) Exploration problems
39. What dimension evaluates search strategies based on the number of nodes generated?
a) Completeness
b) Time complexity
c) Space complexity
d) Optimality
40. Which search strategy does not have additional information about states beyond that provided in the
problem definition?
a) Uninformed search
b) Heuristic search
c) Optimization search
d) Game-playing search
Ans)
1. b) Problem formulation 22. d) Path cost function
2. b) Heuristics 23. a) Completeness
3. a) Goal formulation 24. a) A*
4. c) Goal-based agents 25. c) Search
5. c) Goal test 26. b) Heuristic search
6. c) Contingency problems 27. a) Goal formulation
28. d) Exploration problems
Page 30 of 31
By: Muhammad Mahmoud 29. c) Space complexity
30. a) Uninformed search
31. a) Graph-Search
7. c) Search
8. a) Graph-Search
9. b) State, parent, action, path cost
10. b) Heuristic search
11. d) Deliberative agents
12. b) Multiple-state problems
13. a) Graph-Search
14. d) Path cost function
15. a) Completeness
16. a) A*
17. b) Problem formulation
18. d) Exploration problems
19. b) Time complexity
20. a) Uninformed search
21. a) Graph-Search
Page 31 of 31
By: Muhammad Mahmoud