Professional Documents
Culture Documents
com
1
Learning objectives: at the end of the class, you should be able
to:
•What is a Problem?
•Solving a problem
• Components of problem
•Searching
– Searching Algorithm Evaluation
2
– Search Strategies
What is a Problem?
• It is a gap between what actually is and what is desired.
– A problem exists when an individual becomes aware of the existence of
an obstacle which makes it difficult to achieve a desired goal or objective.
• A number of problems are addressed towards designing intelligent
agent:
– Toy problems: are problems that are useful to test and demonstrate
methodologies and can be used by researchers to compare the
performance of different algorithms.
• may require little or no ingenuity, good for games design
• e.g. 8-puzzle, n-queens, vacuum cleaner world, towers of Hanoi, river
crossing…
– Real-life problems: problems that have much greater
commercial/economic impact if solved.
• Such problems are more difficult and complex to solve, and there is
no single agreed-upon description.
• E.g. Route finding, Traveling sales person, etc. 3
Some more Real-world Problems
• Route finding Problem
• Traveling Salesman
Problem(TSP)
• VLSI Layout
• Assembly Sequencing
• Robot Navigation
Route Finding Problem
• Route Finding Problem - shortest path problem
– Defined in terms of locations and transitions along
links between them.
– Applications: automated travel advisory systems,
airline travel planning systems, military operations
planning,
General routing
Route in computer
Finding Algorithmnetworks,
1. Identify initial state as origin: Initial State
2. Expand to All Possible Locations: Successors
3. Choose Location with smallest cost/fastest route
4. Test Goal Function, is it the destiny? Goal Test
5. if yes, return location: Goal State
else, return to 2
Cont’d
• Route Finding Problem: Entire States - State Space
6
A simplified road map of part of Romania
Cont’d
• Route Finding Problem:
• A problem can be defined formally by five
components
– Initial State: The initial state that the agent starts in. For
example, the initial state for our agent in Romania might be
described as In(Arad)
11
Solving a problem…
Components of a Problem
o Initial State
- defines where the agent starts or begins its task
o Actions
- defines description of possible actions given a particular
state
o Transition Model
- describes each action a with respect to state.
o Goal Test
- determines the given state is goal or not
o Path Cost
- A function that assigns cost to each path. The cost
function in problem solving agents is their performance measure.
12
Solving a problem…
• Problem Formulation is the process of deciding what actions
and states to consider, given a goal.
• Define states
– States describe distinguishable stages during the problem-
solving process
– Example- What are the various states in route finding problem?
• The various places including the location of the agent
• Define operators/rules
– Identify the available operators for getting from one state to the
next
– Operators cause an action that brings transitions from one state
to another by applying on a current state
• Construct state space
– Suggest a suitable representation (such as graph, table,… or a
combination of them) to construct the state space
13
State Space of the Problem
• The state space defines the set of all relevant states reachable by (any)
sequence of actions from the initial state until the goal state is
reached.
• State space (also called search space/problem space) of the problem
includes the various states
– Initial State
• defines where the agent starts or begins its task
– Transition States
• other states in between initial and goal states
– Goal State
• defines the situation the agent attempts to achieve
15
Example: The 8 puzzle problem
1 2 3 1 2 3
4 8 4 5 6
7 6 5 7 8
1 2 3 1 2 3
8 4 5 8 4
7 6 7 6 517
Exercise : River Crossing Puzzles
Goat, Wolf and Cabbage Problem
• A farmer returns from the market, where he bought a goat, a
cabbage and a wolf. On the way home he must cross a river. His
boat is small and unable to transport more than one of his
purchases. He cannot leave the goat alone with the cabbage
(because the goat would eat it), nor he can leave the goat alone
with the wolf (because the goat would be eaten). How can the
farmer get everything safely on the other side?
1. Identify the set of possible states and operators
• Find solution:
– sequence of cities
leading from start to
goal state, e.g., Arad,
Sibiu, Fagaras,
Bucharest
• Execution
– drive from Arad to
Bucharest according
to the solution
Route Finding Problems
• Basic idea:
– Simulated
exploration of state
space by
generating
successors of
already explored
states (AKA
expanding states)
SidistKilo
(b) After expanding generating a new state
Sidist Kilo
AratKilo Giorgis ShiroMeda
choosing one SidistKilo
option
(c) After expanding AratKilo Giorgis ShiroMeda
Arat Kilo
MeskelSquare Piassa Megenagna
Uninformed (Blind) Search
gebrishab@gmail.com
Contents to be Covered
• Uninformed Searching Strategies
• Breadth First Search (BFS)
• Depth First Search (DFS)
• Depth Limited Search (DLS)
• Iterative Deepening Search (IDS)
• Uniform Cost Search (UCS)
Breadth First Search (BFS)
• Expand shallowest unexpanded node,
– i.e. expand all nodes on a given level of
the search tree before moving to the
next level
• Implementation: uses Queue(FIFO)
data structure to store the list:
– Expansion: put successors at the end of
queue
– Pop nodes from the front of the queue
• Properties:
– Takes space: keeps every node in
memory
– Optimal and complete: guarantees to
find solution
…Cont’d
• Example of Breadth First Search (BFS):
• Traversed path:
S---> A--->B---->C--->D---->G--->H--->E---->F---->I---->K
Exercise
• Apply BFS to find an optimal path from Start
Node (S) to Goal Node (G).
• BFS: S->B->C->D->E->G
Depth-First Search (DFS)
• Expand one of the node at the deepest
level of the tree.
– Only when the search hits a non-goal dead
end does the search go back and expand
nodes at shallower levels
…Cont’d
• Implementation: treat the list as Stack(LIFO)
– Expansion: push successors at the top of stack
– Pop nodes from the top of the stack
• Properties
– Incomplete and not optimal: fails in infinite-depth
spaces, spaces with loops.
• Modify to avoid repeated states along the path
– Takes less space (Linear): Only needs to remember
up to the depth expanded
…Cont’d
• Example of Depth First Search (DFS)
• Traversed path:
S---> A---> B---> D ---> E---> C---> G
Exercise
• Apply DFS to find an optimal path from Start
Node (S) to Goal Node(G).
Depth Limited Search (DLS)
• Depth Limited Search is similar to Depth First Search with a
predetermined limit ℓ.
• Depth-limited search can solve the drawback of the infinite path
in the Depth-first search.
• The node at the depth limit will treat as it has no successor
nodes further.
• Depth-limited search can be terminated with two Conditions of
failure:
• Standard failure value: It indicates that problem does not have
any solution.
• Cutoff failure value: It defines no solution for the problem
within a given depth limit.
…Cont’d
• Advantages:
– Memory efficient.
• Disadvantages:
– incompleteness.
– may not be optimal if problem has more than one solution.
…Cont’d
• Example of DLS
• Depth limit ℓ = 2
S--->A--->C--->D--->B--->I--->J
Exercise
• Apply DLS to find an optimal path from Start
Node (S) to Goal Node (G) with depth limit ℓ = 2
Iterative Deepening Search (IDS)
•IDS solves the issue of choosing the best depth limit by trying all
possible depth limit:
–Perform depth-first search to a bounded depth d, starting at d = 1 and
increasing it by 1 at each iteration.
Example: for route finding problem we can take the diameter of the
state space. In our example, at most 9 steps is enough to reach any
node
•This search combines the benefits of DFS and BFS
–DFS is efficient in space, but has no path-length guarantee
–BFS finds min-step path towards the goal, but requires memory space
–IDS performs a sequence of DFS searches with increasing depth-cutoff until
goal is found
Limit=0 Limit=1 Limit=2
…Cont’d
• Advantages:
– It combines the benefits of BFS and DFS search algorithm in
terms of fast search and memory efficiency.
• Disadvantages:
– The main drawback of IDS is that it repeats all the
work of the previous phase.
• Example:
– Following tree structure is showing the iterative deepening
depth-first search.
– IDS algorithm performs various iterations until it does not
find the goal node. The iteration performed by the algorithm
is given as:
…Cont’d
• Example of Iterative Deepening Search (IDS)
A
o Apply IDS to find Optimal Path from
o Initial State = A to Goal State = H
B C D
E G H
F
A B C
3 9
7 4 5
D E G
Exercise:
Apply Uninformed Search Strategies to find optimal
path. Initial State = S, Goal State = G, ℓ = 1
Find Optimal Path S
1.BFS? 1 5
8
2.DFS?
3.IDS? A B C
4.DLS: ℓ = 2? 3 9
7 4
5
5.UCS?
D E G
Comparing Uninformed Search Strategies
Time Space
Strategies Complete Optimal Complexity Complexity
• Implementation:
– expand 1st the node closest to the goal state, i.e. with evaluation
function f(n) = h(n)
– h(n) = 0 if node n is the goal state
– Otherwise h(n) ≥ 0; an estimated cost of the cheapest path from
the state at node n to a goal state
Example
Initial state
S
8
1 5 8
A B C
8 4 3
3 9
7 4 5
D E G
0
goal state
Greedy Search
• Greedy Best-First Search algorithm always selects the path which
appears best at that moment.
• It is the combination of BFS and DFS algorithms.
• It uses the heuristic function to search.
• Choose the most promising node at each step.
• In the best first search algorithm, we expand the node which is
closest to the goal node and the closest cost is estimated by
heuristic function, i.e.
f(n)= h(n).
• NB:
– At each point in the search space, only those node is expanded
which have the lowest value of f(n), and the algorithm
terminates when the goal node is found.
…Cont’d
• Example of A* Search:
– Traverse the given graph using the A* algorithm. The heuristic
value of all states is given in the below table. Calculate f(n) of
each state using the formula f(n)= g(n) + h(n), where g(n) is the
cost to reach any node from start state.
– Here we will use OPEN and CLOSED list.
…Cont’d
Heuristic Search Methods
Algorithm Time Space Optimal Complete
Comp. Comp.
Greedy O(bm) O(bm) No No
Solution:
Greedy: f(n) = h(n)
A*: f(n) = g(n) + h(n)
Solution: Search Space
• Informed Search (Heuristic Search) Strategies
• BFS (Greedy): f(n) = h(n)
1. S: f(n) = 13
2. S => A: f(n) = 12
S => B: f(n) = 4 (Lowest h, expand B)
3. S => B => E: f(n) = 8
S => B => F: f(n) = 2 (Lowest h, expand F)
4. S => B => F => I: f(n) = 9
S => B => F => G: f(n) = 0 (Lowest h, Reached Goal State)
Solution: Search Space
• Informed Search (Heuristic Search) Strategies
• A* Search: f(n) = g(n) + h(n)
1. S: f(n) = 0 + 13 = 13
2. S => A: f(n) = 3 + 12 = 15
S => B: f(n) = 2 + 4 = 6 (Lowest f-cost, expand via B)
3. S => B => E: f(n) = (2 + 3) + 8 = 13
S => B => F: f(n) = (2 + 1) + 2 = 5 (Lowest f-cost, expand via F)
4. S => B => F => I: f(n) = (2 + 1 + 2 + 3) + 9 = 17
S => B => F => G: f(n) = (2 + 1 + 3) + 0 = 6 (Lowest f-cost, Reached Goal)
Questions?