UNIT 2 Problem-Solving Agents
UNIT 2 Problem-Solving Agents
UNIT 2 Problem-Solving Agents
UNIT 2
Search Algorithm Terminologies
• Search
• Search tree
• Actions
• Transition model
• Path Cost
• Solution
• Optimal Solution
Types of search algorithms
Breadth-first Search
5
Advantages:
• Uniform cost search is optimal because at
every state the path with the least cost is
chosen.
Disadvantages:
• It does not care about the number of steps
involve in searching and only concerned about
path cost. Due to which this algorithm may be
stuck in an infinite loop.
Iterative deepening depth-first Search:
1'st Iteration-----> A
2'nd Iteration----> A, B, C
3'rd Iteration------>A, B, D, E, C, F, G
4'th Iteration------>A, B, D, H, I, E, C, F, K, G
Bidirectional Search Algorithm
44
Search Types
– Backtracking state-space search
– Local Search and Optimization
45
Local Search and Optimization
• Previous searches: keep paths in memory,
and remember alternatives so search can
backtrack. Solution is a path to a goal.
• Path may be irrelevant, if only the final
configuration is needed (,8-Puzzle,8-queens,
Tic tac toe…)
46
Local Search
• Use a single current state and move only to
neighbors.
• Use little space
• Can find reasonable solutions in large or
infinite (continuous) state spaces for which
the other algorithms are not suitable
47
Optimization
• Local search is often suitable for optimization
problems. Search for best state by optimizing an
objective function.
• F(x) where often x is a vector of continuous or discrete
values
• Begin with a complete configuration
• A successor of state S is S with a single element
changed
• Move from the current state to a successor state
• Low memory requirements, because the search tree or
graph is not maintained in memory (paths are not
saved)
48
Tic-Tac-Toe game
8-Puzzle
50
8-Puzzle
Example: n-queens
• Put n queens on an n × n board with no two
queens on the same row, column, or diagonal
•
52
N-Queens problem
• 8 queens: find an arrangement of 8 queens on a
chess board such that no two queens are
attacking each other
• Start with some arrangement of the queens, one
per column
• X[j]: row of queen in column j
• Successors of a state: move one queen
• F: # pairs attacking each other
53
Examples
• Traveling salesman problem: visit each city
exactly once
• Start with some ordering of the cities
• State representation – order of the cities
visited (for eg)
• Successor state: a change to the current
ordering
• F: length of the route
54
Hillclimbing
(Greedy Local Search)
• Generate nearby successor states to the
current state
• Pick the best and replace the current state
with that one.
• Loop
55
Hill-climbing search problems
• Local maximum: a peak that is lower than the
highest peak, so a suboptimal solution is
returned
• Plateau: the evaluation function is flat,
resulting in a random walk
• Ridges: slopes very gently toward a peak, so
the search may oscillate from side to side
57
58
Types of Hill Climbing Algorithm
• Simple hill Climbing
• Steepest-Ascent hill-climbing
1. Simple Hill Climbing
• Simple hill climbing is the simplest way to implement a
hill climbing algorithm. It only evaluates the neighbor
node state at a time and selects the first one which
optimizes current cost and set it as a current state.
• It only checks it's one successor state, and if it finds
better than the current state, then move else be in the
same state.
• This algorithm has the following features:
• Less time consuming
• Less optimal solution and the solution is not
guaranteed
Algorithm for Simple Hill Climbing
• Step 1: Evaluate the initial state, if it is goal state then
return success and Stop.
• Step 2: Loop Until a solution is found or there is no
new operator left to apply.
• Step 3: Select and apply an operator to the current
state.
• Step 4: Check new state:
– If it is goal state, then return success and quit.
– Else if it is better than the current state then assign new
state as a current state.
– Else if not better than the current state, then return to step2.
• Step 5: Exit.
2. Steepest-Ascent hill climbing