AI (Exp 4)
AI (Exp 4)
Experiment 4
Experiment No. - 4
formation/correction/ Answer to
(03) (03)
5.1 Aim:
To implement the A* search algorithm to solve the 8-puzzle problem and find the optimal solution for a
given initial state and goal state.
CO 2: Apply the most suitable search strategy and represent a natural language description of statements
in logic and apply the inference rules to design problem-solving agents.
Given the 8-puzzle problem, implement the A* search algorithm to solve the puzzle. The 8-puzzle
problem consists of an initial configuration and a goal configuration. The objective is to rearrange the
tiles from the initial configuration to match the goal configuration using the fewest moves possible. Use
the Manhattan distance heuristic for this problem.
The 8-Puzzle Problem is a classic AI problem that consists of a 3x3 grid with eight numbered tiles and
one empty space. The goal is to rearrange the tiles from a given start configuration to a goal
configuration by sliding the tiles into the empty space.
A Search Algorithm*:
A* is an informed search algorithm that finds the shortest path from a start node to a goal node by
combining the advantages of both Depth-First Search (DFS) and Breadth-First Search (BFS).
It uses a heuristic function h(n) (which estimates the cost from the current node to the goal) and a cost
function g(n) (the actual cost from the start node to the current node).
The total cost function f(n) = g(n) + h(n) is used to prioritize nodes during the search.
The Manhattan distance heuristic calculates the sum of the vertical and horizontal distances of each tile
from its goal position. This heuristic ensures that A* searches optimally and efficiently for this type of
puzzle.
Example:
Initial Configuration:
1 2 3
4 0 6
7 5 8
Goal Configuration:
1 2 3
4 5 6
7 8 0
g(n): Cost to reach the current state from the start state (number of moves so far).
h(n): Heuristic estimate to reach the goal state. We'll use the Manhattan distance heuristic, which
calculates the sum of the distances each tile needs to move to reach its goal position.
f(n) = g(n) + h(n): Total cost function used to prioritize nodes in the open list.
1. Initial State:
1 2 3
4 0 6
7 5 8
Solution Summary:
5.5 Procedure:
5.6 Conclusion:
The implementation of the A* search algorithm to solve the 8-puzzle problem demonstrates an effective
approach to finding optimal solutions for rearranging tiles from an initial configuration to a specified goal
configuration. By utilizing the Manhattan distance heuristic, which quantifies the distance each tile is from its
target position, the algorithm efficiently guides the search process.
A* combines the advantages of both breadth-first and depth-first search methods, ensuring that it explores paths
in a way that minimizes total movement cost while also considering heuristic estimates. This results in a
systematic exploration of possible states, ultimately leading to the discovery of the optimal path with the fewest
moves.
The A* algorithm's reliance on admissible heuristics like Manhattan distance ensures that it never overestimates
the cost to reach the goal, making it both optimal and complete for solving the 8-puzzle problem. This
characteristic is crucial in AI applications where finding the most efficient solution is paramount.
5.7 Questions:
1. What is the 8-puzzle problem, and how does it represent a classic search problem?
2. Explain the A* search algorithm. Why is it considered optimal?
3. How is the Manhattan distance heuristic used in the A* search algorithm?
4. What are the advantages of using A* over other search algorithms like BFS and DFS for this problem?
5. Implement the 8-puzzle problem with a different heuristic (e.g., misplaced tiles) and compare the
performance with A* using the Manhattan distance heuristic.
6. How does the choice of heuristic affect the efficiency of the A* search?
7. Write a PROLOG program to solve the 8-puzzle problem using depth-first search (DFS).
8. What are the limitations of A* in solving larger versions of the 8-puzzle, such as the 15-puzzle?
9. Why is A* both complete and optimal for solving this problem?
10. How would the solution change if the puzzle size was increased from 8 tiles to 15 tiles?