u2
u2
By
Ms. Kalyani Akhade
CE Dept.
Unit-2: Problem-Solving
➢ Problem-Solving Agents
➢ Example Problems
➢ Search Algorithms
➢ Uninformed Search Strategies
➢ Informed (Heuristic) Search Strategies
➢ Heuristic Functions
➢ Search in Complex Environments
➢ Local Search and Optimization Problems
The state space for the vacuum world. Links denote actions: L = Left, R = Right, S = Suck.
Artificial Intelligence Prof. Kalyani Akhade (CE DEPT) 1/31/2025 15
Problems Solving Agents
➢ Toy Problems
➢ States: The state is determined by both the agent location and the dirt
locations. The agent is in one of two locations, each of which might or might
not contain dirt. Thus, there are 2 × 2^2 = 8 possible world states. A larger
environment with n locations has n x 2^n states.
➢ Initial state: Any state can be designated as the initial state.
➢ Actions: In this simple environment, each state has just three actions: Left,
Right, and Suck. Larger environments might also include Up and Down.
➢ Transition model: The actions have their expected effects
➢ Goal test: This checks whether all the squares are clean.
➢ Path cost: Each step costs 1, so the path cost is the number of steps in the
path.
Artificial Intelligence Prof. Kalyani Akhade (CE DEPT) 1/31/2025 16
Problems Solving Agents
➢ Toy Problems
Graph Details:
• Nodes: Sibiu, Rimnicu Vilcea, Fagaras, Pitesti, Bucharest.
• Edge Costs:
• Sibiu → Rimnicu Vilcea: 80
• Sibiu → Fagaras: 99
• Rimnicu Vilcea → Pitesti: 97
• Rimnicu Vilcea → Bucharest: Not connected
• Fagaras → Bucharest: 211
• Pitesti → Bucharest: 101
Final Path: Sibiu → Rimnicu Vilcea → Pitesti → Bucharest Total Cost: 278
Artificial Intelligence Prof. Kalyani Akhade (CE DEPT) 1/31/2025 34
Search Strategies
Uninformed Search Strategies
Uniform-cost Search
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.
5. Path Construction
Once the two searches meet at node 9, the algorithm reconstructs the path:
Forward Path: From 1 → 4 → 8 → 9.
Backward Path: From 9 → 10 → 12 → 16.
Combining these paths gives the full solution:
1→4→8→9→10→12→161→4→8→9→10→12→16
Figure. Stages in a greedy best-first tree search for Bucharest with the straight-line
distance heuristic hSLD. Nodes are labeled with their h-values.
Figure Stages in an A∗ search for Bucharest. Nodes are labeled with f = g +h.
Artificial Intelligence Prof. Kalyani Akhade (CE DEPT) 1/31/2025 64
Search Strategies
Informed Search Strategies
A* Search
➢ Advantages
➢ A* search algorithm is the best algorithm than other search algorithms.
➢ A* search algorithm is optimal and complete.
➢ This algorithm can solve very complex problems.
➢ Disadvantages:
➢ It does not always produce the shortest path as it mostly based on
heuristics and approximation.
➢ A* search algorithm has some complexity issues.
➢ The main drawback of A* is memory requirement as it keeps all generated
nodes in the memory, so it is not practical for various large-scale
problems.
Artificial Intelligence Prof. Kalyani Akhade (CE DEPT) 1/31/2025 65
Search Strategies
Informed Search Strategies
A* Search
➢ Time Complexity: The time complexity of A* search algorithm depends on
heuristic function, and the number of nodes expanded is exponential to the
depth of solution d. So the time complexity is O(b^d), where b is the
branching factor.
➢ Space Complexity: The space complexity of A* search algorithm is O(b^d)
➢ Complete: A* algorithm is complete as long as:
➢ Branching factor is finite.
➢ Cost at every action is fixed.
➢ Optimal: If the heuristic function is admissible (never overestimates the
actual cost), then A* tree search will always find the least cost.
1. Misplaced Tiles:
➢ h1 = the number of misplaced tiles. All of the eight tiles are out of position, so
the start state would have h1 = 8.
h1 is an admissible heuristic because it is clear that any tile that is out of
place must be moved at least once.
➢ Hill-climbing search
➢ Simulated annealing
➢ Local beam search
➢ Genetic algorithms
➢ Solution: The solution for the plateau is to take big steps or very little steps
while searching, to solve the problem. Randomly select a state which is far
away from the current state so it is possible that the algorithm could find
non-plateau region
Artificial Intelligence Prof. Kalyani Akhade (CE DEPT) 1/31/2025 89
Local Search and Optimization Problems
Problems in Hill-climbing search
➢ Ridges: A ridge is a special form of the local maximum. It has an area
which is higher than its surrounding areas, but itself has a slope, and cannot
be reached in a single move.
Figure The genetic algorithm, illustrated for digit strings representing 8-queens states.
The initial population in (a) is ranked by the fitness function in (b), resulting in pairs for
mating in (c). They produce offspring in (d), which are subject to mutation in (e).
Artificial Intelligence Prof. Kalyani Akhade (CE DEPT) 1/31/2025 94
Local Search and Optimization Problems
Genetic algorithms
Figure The 8-queens states corresponding to the first two parents in Figure (c) and
the first offspring in Figure(d). The shaded columns are lost in the crossover step
and the unshaded columns are retained.