Intelligent Agents & Search
من صياغة المسألة إلى اتخاذ القرار الذكي
🎯 Learning Objectives
By the end of this lecture, students should be able to:
- Explain the concept of an intelligent agent.
- Describe sensors, actuators, environment, and actions.
- Formulate a problem using states, actions, goals, and costs.
- Understand search trees and state spaces.
- Compare BFS, DFS, and A* search.
- Interpret the functions g(n), h(n), and f(n).
- Apply search concepts to a simple power-system problem.
🎯 أهداف التعلم
بعد الانتهاء من هذه المحاضرة يجب أن يكون الطالب قادرًا على:
- شرح مفهوم الوكيل الذكي.
- توضيح مفهوم الحساسات والمشغلات والبيئة والأفعال.
- صياغة المسألة باستخدام الحالات والأفعال والهدف والكلفة.
- فهم فضاء الحالات وشجرة البحث.
- المقارنة بين BFS وDFS وA*.
- تفسير الدوال g(n) وh(n) وf(n).
- تطبيق مفهوم البحث على مثال مبسط من نظم الطاقة.
1. What is an Intelligent Agent?
An intelligent agent is a system that observes its environment, processes the available information, and chooses an action that helps achieve a desired objective.
1. ما هو الوكيل الذكي؟
الوكيل الذكي هو نظام يراقب البيئة المحيطة، ويعالج المعلومات المتاحة، ثم يختار فعلًا يساعد على الوصول إلى هدف محدد.
2. Agent Components
The world in which the agent operates.
Devices or data channels used to observe the environment.
The decision-making system.
Mechanisms used to execute actions.
2. مكونات الوكيل الذكي
العالم أو النظام الذي يعمل ضمنه الوكيل.
الوسائل المستخدمة للحصول على معلومات عن البيئة.
النظام المسؤول عن اتخاذ القرار.
الوسائل المستخدمة لتنفيذ القرارات أو الأفعال.
3. PEAS Representation
A common way to describe an intelligent agent is the PEAS framework:
| Element | Power-System Example |
|---|---|
| Performance | Low cost, secure voltage, low losses |
| Environment | Electrical distribution network |
| Actuators | Battery inverter, transformer tap, controllable load |
| Sensors | Voltage, current, power, SOC, electricity price |
3. تمثيل PEAS
يمكن توصيف الوكيل الذكي باستخدام إطار PEAS:
أي: معيار الأداء + البيئة + المشغلات + الحساسات.
4. Problem Formulation
Before a computer can search for a solution, the engineering problem must first be represented mathematically.
A search problem can be defined by:
- Initial state
- Set of possible actions
- State-transition model
- Goal condition
- Path cost
where:
- S = set of states
- A = set of actions
- T = transition model
- G = goal condition
- C = cost function
4. صياغة المسألة
قبل أن يتمكن الحاسوب من البحث عن حل، يجب أولًا تمثيل المسألة الهندسية بشكل رياضي.
يمكن توصيف مسألة البحث من خلال:
- الحالة الابتدائية
- مجموعة الأفعال الممكنة
- نموذج الانتقال بين الحالات
- شرط الوصول إلى الهدف
- كلفة المسار
5. State Space
The state space is the set of all possible configurations that may occur during problem solving.
Each action moves the system from one state to another:
This equation simply says that the next state depends on the current state and the selected action.
5. فضاء الحالات
فضاء الحالات هو مجموعة جميع الحالات أو التشكيلات الممكنة التي قد يمر بها النظام أثناء عملية البحث.
ويؤدي تنفيذ فعل معين إلى نقل النظام من حالة إلى أخرى:
أي أن الحالة التالية تعتمد على الحالة الحالية والفعل المختار.
6. Search Tree
A search tree is a graphical representation of possible decisions.
The green node represents a goal state. The numbers along the edges represent transition costs.
6. شجرة البحث
شجرة البحث هي تمثيل رسومي للقرارات الممكنة والانتقالات بين الحالات.
العقدة الخضراء تمثل حالة الهدف، بينما تمثل الأرقام المكتوبة على الأفرع كلفة الانتقال من حالة إلى أخرى.
7. Breadth-First Search — BFS
BFS explores the tree level by level.
BFS is complete when the branching factor and solution depth are finite, but it may require a large amount of memory.
7. البحث بالعرض — BFS
تقوم خوارزمية BFS باستكشاف شجرة البحث مستوى بعد مستوى.
تعد BFS مناسبة عندما نرغب في إيجاد حل قريب من الجذر، لكنها قد تحتاج إلى ذاكرة كبيرة.
8. Depth-First Search — DFS
DFS follows one branch as deeply as possible before returning and exploring another branch.
8. البحث بالعمق — DFS
تتبع خوارزمية DFS أحد الأفرع إلى أكبر عمق ممكن، ثم تعود للخلف لاستكشاف فرع آخر.
9. Search Cost
If every movement has a cost, then the total path cost is the sum of all transition costs.
Here, g(n) represents the actual cost from the initial state to node n.
9. كلفة البحث
إذا كان لكل انتقال كلفة، فإن الكلفة الكلية للمسار تساوي مجموع تكاليف جميع الانتقالات.
وتمثل g(n) الكلفة الفعلية التي دُفعت للوصول من الحالة الابتدائية إلى العقدة n.
10. Heuristic Function
A heuristic function estimates how far a current state is from the goal.
Unlike g(n), the heuristic is not the cost already paid. It is an estimate of the cost that may still be required.
h(n) = estimated future cost
10. الدالة الإرشادية
تستخدم الدالة الإرشادية لتقدير مدى بُعد الحالة الحالية عن الهدف.
h(n) = الكلفة المستقبلية المقدرة
11. A* Search
A* combines the known cost and the heuristic estimate:
The algorithm normally expands the node with the smallest value of f(n).
“How much have I already paid?” + “How much do I expect to pay from here to the goal?”
11. خوارزمية A*
تجمع خوارزمية A* بين الكلفة الفعلية والتقدير المستقبلي:
وتقوم الخوارزمية عادةً باختيار العقدة التي تمتلك أصغر قيمة للدالة f(n).
كم دفعت حتى الآن؟ + كم أتوقع أن أدفع حتى أصل إلى الهدف؟
12. Worked Numerical Example
Assume three candidate nodes:
| Node | g(n) | h(n) | f(n)=g+h |
|---|---|---|---|
| A | 3 | 7 | 10 |
| B | 5 | 2 | 7 |
| C | 2 | 9 | 11 |
A* selects node B because:
and 7 is smaller than 10 and 11.
12. مثال عددي محلول
لدينا ثلاث عقد مرشحة A وB وC.
تحسب A* لكل عقدة:
بالنسبة إلى B:
ولذلك يتم اختيار B لأن القيمة 7 هي الأصغر.
13. Power-System Example: Battery Scheduling
Consider a battery connected to a distribution network.
The current state is:
The possible actions are:
Increase stored energy.
Keep the battery unchanged.
Supply stored energy to the network.
Minimize energy cost while respecting SOC limits.
A simplified state transition may be written as:
The search algorithm evaluates different sequences of actions and chooses the path with the best total cost.
13. مثال من نظم الطاقة: جدولة البطارية
لنفترض وجود بطارية متصلة بشبكة توزيع كهربائية.
الحالة الحالية:
الأفعال الممكنة:
- الشحن
- عدم اتخاذ أي إجراء
- التفريغ
والهدف هو تقليل تكلفة الطاقة مع المحافظة على حدود حالة الشحن.
تقوم خوارزمية البحث بمقارنة مسارات متعددة من الأفعال، ثم تختار المسار الأفضل وفقًا لدالة الكلفة.
14. From Search to Optimization
Search and optimization are closely related.
In search, we explore alternatives. In optimization, we aim to identify the best alternative according to an objective function.
where J(x) is the objective or cost function.
14. من البحث إلى التحسين
يوجد ارتباط وثيق بين البحث والتحسين.
في البحث نستكشف البدائل الممكنة، بينما في التحسين نحاول إيجاد أفضل بديل وفقًا لدالة هدف أو كلفة.
حيث تمثل J(x) دالة الهدف أو دالة الكلفة.
15. MATLAB Concept
A simple search algorithm can be understood computationally as:
2. Evaluate their cost
3. Select one candidate
4. Expand it
5. Repeat until the goal is reached
Later, the MATLAB lab will implement a small search problem step by step.
15. الفكرة البرمجية في MATLAB
يمكن فهم خوارزمية البحث برمجيًا وفق الخطوات التالية:
2. حساب كلفة كل حالة
3. اختيار إحدى الحالات
4. توسيعها وتوليد حالات جديدة
5. تكرار العملية حتى الوصول إلى الهدف
سنقوم لاحقًا في مختبر MATLAB بتنفيذ مسألة بحث بسيطة خطوة بخطوة.
16. Summary
- An intelligent agent perceives, decides, and acts.
- Search problems can be described using states, actions, transitions, goals, and costs.
- BFS explores level by level.
- DFS explores one branch deeply.
- A* combines actual cost g(n) and heuristic cost h(n).
- Search methods can support decision-making in power-system applications.
16. الخلاصة
- يقوم الوكيل الذكي بالاستشعار واتخاذ القرار وتنفيذ الأفعال.
- يمكن تمثيل مسألة البحث باستخدام الحالات والأفعال والانتقالات والهدف والكلفة.
- تبحث BFS مستوى بعد مستوى.
- تبحث DFS بعمق ضمن أحد الأفرع.
- تجمع A* بين الكلفة الفعلية g(n) والكلفة المقدرة h(n).
- يمكن تطبيق خوارزميات البحث في مسائل اتخاذ القرار في نظم الطاقة.
📝 Review Questions
- What is an intelligent agent?
- What do sensors and actuators do?
- What is a state space?
- What is the difference between BFS and DFS?
- What does g(n) represent?
- What does h(n) represent?
- Why does A* use f(n)=g(n)+h(n)?
- How can search be used for battery scheduling?
📝 أسئلة المراجعة
- ما هو الوكيل الذكي؟
- ما وظيفة الحساسات والمشغلات؟
- ما المقصود بفضاء الحالات؟
- ما الفرق بين BFS وDFS؟
- ماذا تمثل g(n)؟
- ماذا تمثل h(n)؟
- لماذا تستخدم A* العلاقة f(n)=g(n)+h(n)؟
- كيف يمكن استخدام البحث في جدولة بطارية تخزين الطاقة؟