Reasoning & Agents: Prof. Dr. Abeer Mahmoud
Reasoning & Agents: Prof. Dr. Abeer Mahmoud
Reasoning & Agents: Prof. Dr. Abeer Mahmoud
(course coordinator)
2 Prof. Dr. Abeer Mahmoud
1 Introduction on Nature of Agents, Performance
Measure and Environment
9 Game Theory
(course coordinator)
Prof. Dr. Abeer Mahmoud
Planning as a
Lec-4 search problem
(course coordinator)
Prof. Dr. Abeer Mahmoud
Search so fare
• Search problem:
• States (configurations of the world)
• Actions and costs
• Successor function (world dynamics)
• Start state and goal test
• Search tree:
• Nodes: represent plans for reaching states
• Plans have costs (sum of action costs)
• Search algorithm:
• Systematically builds a search tree
• Chooses an ordering of the fringe
(unexplored nodes)
• Optimal: finds least-cost plans
(course coordinator)
Prof. Dr. Abeer Mahmoud
Classical Searching algorithm
Uninformed Search Algorithms( Blind Search)
1- Breadth first Search
2- Uniform Cost Search(UCS)
3- Depth First Search
4- Depth limited Search
5- Iterative Deeping Search
6 - Bidirectional Search
Informed Search (Heuristic Search)
Best First Search
Greedy Search
A* Search
(course coordinator)
Prof. Dr. Abeer Mahmoud
6
Informed search
(course coordinator)
Prof. Dr. Abeer Mahmoud
7
Informed search & Exploration
Modified version from blind search algorithm
Implementation:
o Order the nodes in Frontier in decreasing order of
desirability (from low f(n) which means high desirability to
high f(n) which means low desirability. )
(course coordinator)
Prof. Dr. Abeer Mahmoud
10
Greedy Search Straight line distances between cities
Example 1 which are additionally provided
(course coordinator)
Prof. Dr. Abeer Mahmoud
11
(course coordinator)
Prof. Dr. Abeer Mahmoud
The greedy best first search using hSLD finds a
solution without ever expanding a node that is not on
solution path, hence its cost is minimal
(course coordinator)
Prof. Dr. Abeer Mahmoud
13
Greedy Search Straight line distances between cities
Example 2 which are additionally provided
(course coordinator)
Prof. Dr. Abeer Mahmoud
14
Consider the problem of getting from Iasi to Fagras
The heuristic suggests that Neamt be expanded first because it is closes
to Fagaras but it is like dead end
The solution is to go first to Vaslui a step that is actually farther from the
goal according to the heuristic & then continue to Urzicent, Bucharest and
Fagaras.
In this case , then heuristic causes unnecessary needs to be expanded
(course coordinator)
Prof. Dr. Abeer Mahmoud
15
Best-first search Algorithm
(course coordinator)
Prof. Dr. Abeer Mahmoud
17
A* Search
Example
(course coordinator)
Prof. Dr. Abeer Mahmoud
18
A* Search
Example
(course coordinator)
19
Prof. Dr. Abeer Mahmoud
Properties of A*
• Complete? Yes
• Time? Exponential
• Space? Keeps all nodes in memory
• Optimal? Yes
(course coordinator)
Prof. Dr. Abeer Mahmoud
20
Test yourself
(greedy and A*)
(course coordinator)
Prof. Dr. Abeer Mahmoud
21
Test yourself
(greedy and A*)
4 1
2 B E
1 1
1 2
2 A
D G 0
1
2 1 1 3
3
C F
(course coordinator)
Prof. Dr. Abeer Mahmoud
22
Example 2: Implement the greedy algorithm on the following figure,
then write the its solution path.
4 1
2 B E
1 1
1 2
2 A
D G 0
1
2 1 1 3
3
C F
Solution path: A C D F G
1 3 1 3
Path cost : 8 Greedy is not suitable Not optimal
(course coordinator)
Prof. Dr. Abeer Mahmoud
:
Example 2 Implement the A* algorithm on the following figure, then
write the its solution path.
A
F(A)=0+2=2
B C
F(B)=2+4=6 F(C)=1+2=3
D
D
F(D)=4+1=5
F(D)=3+1=4
Solution path:
ABDEG
Path cost : 6 E E F
F
F(E)=5+1=6 F(E)=6+1=7 F(F)=5+1=6
F(F)=3+1+1=5
G G G G
F(G)=6+0=6 F(G)=4+3+0=7 F(G)=7+0=7 F(G)=8+0=8
(course coordinator)
Prof. Dr. Abeer Mahmoud
Beyond classical search
(course coordinator)
Prof. Dr. Abeer Mahmoud
25
LOCAL SEARCH STRATEGY
Hill-Climbing Search.
Simulated Annealing Search.
Local Beam Search.
Genetic Algorithms.
(course coordinator)
Prof. Dr. Abeer Mahmoud
26
Classical search versus Local Search
Classical search Local Search
Examples of BFS,DFS,UCS,IDFS,LDF Simulated Annealing, Genetic
algorithms S, greedy, A* Algorithm, Local Beam, Hill-
Climbing
Search Order systematic Find best state according to
exploration of search some objective function h(s).
space. e.g., n-queens, h(s)= # of attacking
queens.
Solution The path to the goal the goal state itself is the
is a solution solution
What to keep Keeps one or more Keep a single "current" state,
in memory paths in memory and move to neighboring states
27 in order to try improve it.
(course coordinator)
Prof. Dr. Abeer Mahmoud
Example: n-queens
Put n queens on an n ×
n board with no two
queens on the same
row, column, or
diagonal.
(course coordinator)
Prof. Dr. Abeer Mahmoud
28
LOCAL SEARCH STRATEGY
Key idea:
1. Select (random) initial state (generate an initial guess).
(course coordinator)
Prof. Dr. Abeer Mahmoud
29
LOCAL SEARCH STRATEGY
Advantages Drawback:
Use very little memory – Local Search can get stuck in
usually a constant local maxima and not find the
amount. optimal solution.
(course coordinator)
Prof. Dr. Abeer Mahmoud
31
Hill-Climbing Search
(course coordinator)
Prof. Dr. Abeer Mahmoud
32
Hill-Climbing Search
Main Idea: Keep a single current node and move to a neighboring state to
improve it.
Choose the best successor, choose randomly if there is more than one.
(course coordinator)
Prof. Dr. Abeer Mahmoud
33
Hill-Climbing Search
(course coordinator)
Prof. Dr. Abeer Mahmoud
34
Hill-Climbing inAction…
cost
States
(course coordinator)
Prof. Dr. Abeer Mahmoud
35
Hill-Climbing inAction…
Current solution
cost
Local minima
(course coordinator)
Prof. Dr. Abeer Mahmoud
36
Hill-Climbing inAction…
Current
cost solution
Local
minima
Global States
minima
Drawback: Depending on initial state, it can get stuck in
local maxima/minimum or flat local maximum and not find
the solution.
Solution : Random restart.
(course coordinator)
Prof. Dr. Abeer Mahmoud
37
Simulated Annealing Search
(course coordinator)
Prof. Dr. Abeer Mahmoud
38
The Problem
Most minimization strategies find the nearest local minimum
Standard strategy
(course coordinator)
Prof. Dr. Abeer Mahmoud
39
Simulated annealing Search
(course coordinator)
Prof. Dr. Abeer Mahmoud
40
Simulated annealing Search
better)
ΔE Returned Solution
Next Current
d1 = 0.4 ___ _____ _ _____
d2 = - 0.2 ___ _____ ___ ____
d3= -3 __ ______ _______
(course coordinator)
Prof. Dr. Abeer Mahmoud
43
Properties of Simulated Annealing
• Cooling Schedule: determines rate at which the
temperature T is lowered.
(course coordinator)
Prof. Dr. Abeer Mahmoud
44
Local Beam Search
(course coordinator)
Prof. Dr. Abeer Mahmoud
45
Local Beam Search
Main Idea: Keep track of k states rather than just one.
Start with k randomly generated states.
(course coordinator)
Prof. Dr. Abeer Mahmoud
46
Local Beam Search
Cost
States
(course coordinator)
Prof. Dr. Abeer Mahmoud
47
Local Beam Search
(course coordinator)
Prof. Dr. Abeer Mahmoud
48
Thank you !
(course coordinator)
Prof. Dr. Abeer Mahmoud