0% found this document useful (0 votes)
50 views39 pages

Lec 2 3 Uninformed Search P 1

1. The document discusses problem solving using search algorithms like breadth-first search and uniform-cost search. 2. It provides an example of finding a route from Arad to Bucharest by defining the problem, states, actions, and costs. 3. Breadth-first search is described as exploring all neighbors of each state before moving to the next level, finding the shortest path first. Uniform-cost search prioritizes exploring the lowest-cost path first.

Uploaded by

NBKA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views39 pages

Lec 2 3 Uninformed Search P 1

1. The document discusses problem solving using search algorithms like breadth-first search and uniform-cost search. 2. It provides an example of finding a route from Arad to Bucharest by defining the problem, states, actions, and costs. 3. Breadth-first search is described as exploring all neighbors of each state before moving to the next level, finding the shortest path first. Uniform-cost search prioritizes exploring the lowest-cost path first.

Uploaded by

NBKA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 39

Faculty of Computers and Informatics

MIU

2: Problem Solving

Dr.Diaa Salama
Goal
• The theory and technology of building agents
that can plan ahead to solve problems
• These problems characterized by having many
states.
• Example: navigation problem where there are
many states and you need to pick the right
choice now and in all the following states
streaming together a sequence of actions that
guarantee to reach the goal.
Not covered
• Navigation in fog is a different problem where
the environment is partially observable and the
possible paths are unknown .
Problem
• Find a route from Arad to Bucharest
Problem definition

1. Initial state
2. Actions (state) -> {action1 ,action2 ,action3, …. }
3. Result (state, action) -> new state
4. GoalTeast (state) -> T / F
5. PathCost ( … ) -> cost

In this problem, the cost of the path is sum of the costs of Individual steps. So
we need step cost function.
StepCost( , , ) -> cost #it may be number of KM or number of minuts
Problem definition

• After every action we separate states out into 3 parts:


▫ End of the paths (Frontier states)
▫ Explored states
▫ Unexplored states
Solution

1. TreeSearch(problem)
2.
3. frontiers={initial}
4.
5. loop:
6. if frontier is empty: return Fail
7.
8. path = frontiers.remove() //choose frontier
9. s=path.end
10.
11. if s is a goal: return path // test goal
12.
13. for a in actions(s): //expand the path
14. path.end(result(s,a) )
15. frontiers.add(path)
Breadth First Search
• Shortest path first search A

B C

D E F G
2 2

O
71
151 N 87
1
Z
75
I
140 1
A 92
S 99 F 2

118
80
V
R 2
1 T
2 97 211 142
P 3
111
L 85 98
70 H
146 101 U
M 3 B 86
75 138 4 3
120 90
4 D
C
G E
3 4
Enhance Solution
To avoid repeated paths we replace the tree search by a graph search

1. GraphSearch(problem)
2.
3. frontiers={initial}; explored={}
4.
5. loop:
6. if frontier is empty: return Fail
7.
8. path = frontiers.remove() //choose frontier
9. s=path.end; explored.add(s)
10.
11. if s is a goal: return path // test goal
12.
13. for a in actions(s): //expand the path
14. if result(s,a) ∉ explored and path.end(result(s,a)) ∉ frontiers
15 path.end(result(s,a)) //add to the end of the path
16. frontiers.add(path)
Breadth First Search cont.
• Shortest path first search

2 2

O
71
151 N 87
1
Z
75
I
140 1
A 92
S 99 F 2

118
80
V
R 2
1 T
2 97 211 142
P 3
111
L 85 98
70 H
146 101 U
M 3 B 86
75 138 4 3
120 90
4 D
C
G E
3 4
BFS and Brute-force
1. GraphSearch(problem)
2.
3. frontiers={initial}; explored={}
4.
5. loop:
6. if frontier is empty: return Fail
7.
8. path = frontiers.remove() //choose frontier
9. s=path.end; explored.add(s)
10.
11. if s is a goal: return path // test goal
12.
13. for a in actions(s): //expand the path
14. if result(s,a) ∉ explored and path.end(result(s,a)) ∉ frontiers
15. path.end(result(s,a))
16. frontiers.add(path)

• Why we test the goal (line 11) after choosing the frontier , not after
expanding the path???
• Does Breadth first search require this order?
• It depends on what “shortest” means, if it means length we can
enhance this order to terminate after expanding. However, if it
means the distance, this order becomes important.
• So the answer here is No, BFS don’t need this order and we can
test the goal directly after expanding.
Uniform-Cost Search
• Cheapest first search

146 291

O
71
151 N 87
75
Z
75
I
140 140
A 92
S 99 F 239

118
80
V
R 220
118 T
229 97 211 142
P 317
111
L 85 98
70 H
146 101 U
M 299 B
460 86
75 138 418

120 90
374 D
C
G E
366 455
UCS and Brute-force
1. GraphSearch(problem)
2.
3. frontiers={initial}; explored={}
4.
5. loop:
6. if frontier is empty: return Fail
7.
8. path = frontiers.remove() //choose frontier
9. s=path.end; explored.add(s)
10.
11. if s is a goal: return path // test goal
12.
13. for a in actions(s): //expand the path
14. if result(s,a) ∉ explored and path.end(result(s,a)) ∉ frontiers
15. path.end(result(s,a))
16. frontiers.add(path)

• Again: Why we test the goal (line 11) after choosing the frontier , not
after expanding the path???
• Does Uniform-Cost search require this order?
• Yes, this order is important here.
Depth First Search
• longest path first search

O
71
151 N 87
1
Z
1
75
I
140 3
A 92
S 99 F 4

118
80
V
R 4
1 T
2 97 211 142
P 3
111
L 85 98
70 H
146 101 U
M 3 B 86
75 138 4 5
120 90
4 D
C
G E
3 4
Optimality
• Which algorithm is optimal with respect to the
frontiers Selection Criteria ?

Breadth first Cheapest first Depth first

5 2

3 2 4 2

  
Memory
• Depth First search is not optimal, why we still using it?
▫ Because it saves the memory when we have a large tree.

Breadth first Cheapest first Depth first

1 1 1
2 2 2
3 3 3
. . .
. . .
. . .
n n n
Completeness
• Does Depth First guaranty to find a solution? (Completeness)
▫ No, because the solution depends on the problem space. In other words, if the problem
has an infinite space then Depth First could miss the right path forever.

Depth first

Infinite space
Refereeing to the Uniform-Cost Search
• In uniform-cost search the searching contour
with respect to the cost (distance) looks as
following:

s G
The Idea
• If we have some more information about the
distance between S and G we can direct the
search toward the goal.

s G

• This known as: Greedy best-first search


The Idea cont.

• Greedy best-first search depends on estimated


distance between S and the goal.

s G

• This would result to accept a longer path under


some conditions.
• Can we can combine the benefits of Uniform-Cost
search and Greedy best first search ?
A* search (best estimated total path cost first)
• Combines the benefits of Uniform-Cost search and
Greedy best first search with a new search function
f=g+h.
▫ g(path)=path cost
▫ h(path)=estimated distance to the goal.

g h
s x G

• Benefits:
▫ Minimizing ‘g’ keep the path cheap.
▫ Minimizing ‘h’ keep focus on finding the goal.
A* search
• best estimated total path cost first)

O
2 h
71
151 N 87
1
Z
75
I
140 1
A 92
S 99 F 2

118
80
V
R 2
1 T
2 97 211 142
P 3
111
L 85 98
70 H
146 101 U
M 3 B 86
75 138 4 3
120 90
4 D
C
G E
3 4
A* search
• Best estimated total path cost first)
• F=g+h

291
+380=671

O
h
71
75 151 N 87
+374=449 Z
75
140 I
+253=393
140
A 92
S 99 F 239
+178=417
118
80 220
+193=413
V
118
+329=447 T R
97 317 211 142
+98=415
111
L 85 98
P H
70
146 101 U
M B 86
75 418
138 450
+0=418
+0=450
120 90
D
C
366 455 G E
+160=426 +160=615
A* analysis
• Does A* always find the lost cost path?

Yes
No, depends on the problem

No, depends on h

• Lowest cost only if h(s)< true cost (s->g)


• This means ‘h’ never overestimate distance to the goal
• ‘h’ in this called optimistic
• Also ‘h’ is admissible to find the lowest cost path.
Vacuum cleaner world

2 * 28
Vacuum cleaner state space
• Goal formulation: intuitively, we want all the dirt cleaned up. Formally,
the goal is { state 7, state 8 }.

• Problem formulation: we already know what the set of all possible states
is. The actions/operators are "move left", "move right", and "vacuum".
Why we need search techniques?

• Power (On / Off / Sleep)


• Camera (On /Of)
• Brush Height (1, 2, 3, 4, 5)

• States=10 * 210 * 3 * 2 * 5 (Large state space)


Sliding blocks puzzle

• h1= no. of misplaced blocks

• h 2=
Sliding blocks puzzle

Which one is admissible ?


h1= no. of misplaced blocks

h2=

h1< h2 , thus h2 expand fewer pathes


Where is the Intelligence ?

• h1= no. of misplaced blocks


• h 2 =∑ .

• The intelligence if the agent was able to automatically


find a good heuristic function.
• e.g. the agent know that: a block can move from A to B
▫ If (A adjacent to B) h1
▫ If (B is blank) h2
Where is the Intelligence ? cont.

• h1= no. of misplaced blocks


• h 2 =∑ .

• So heuristic rules can be derived automatically from


the formal description of the problem.
• A good heuristic would be
▫ h = max (h1, h2)
Problem-solving works when:

• Fully Observable
• Discrete
• Deterministic
• Static
Implementation
s x G

• Path can be represented by data structure


“Node” State
Actions
Cost
Parent

S X G
Null SX XG
0 170 230
Null S X

You might also like