MODULE - 2-SIMP Problems: Map Information
MODULE - 2-SIMP Problems: Map Information
1.Apply the Greedy Best-First Search algorithm to find the best path from Arad to
Budapest based on the given heuristic (straight-line distance to Budapest). Use the
provided map and heuristic information.
Map Information:
- Arad to Zerind: 75 km
- Sibiu to Fagaras: 99 km
- Bucharest to Giurgiu: 90 km
- Lugoj to Mehadia: 70 km
- Mehadia to Drobeta: 75 km
- Calarasi to Giurgiu: 45 km
- Zerind: 374 km
- Oradea: 380 km
- Sibiu: 253 km
- Fagaras: 178 km
- Pitesti: 98 km
- Bucharest: 0 km
- Giurgiu: 77 km
- Timisoara: 329 km
- Lugoj: 244 km
- Mehadia: 241 km
- Drobeta: 242 km
- Craiova: 160 km
- Calarasi: 77 km
- Budapest: 0 km
Answer:
Using the Greedy Best-First Search algorithm:
- Arad -> Sibiu -> Rimnicu Vilcea -> Pitesti -> Bucharest -> Giurgiu -> Budapest
Total Distance:
- Bucharest to Giurgiu: 90 km
Result:
The best path from Arad to Budapest using the Greedy Best-First Search algorithm is:
Arad -> Sibiu -> Rimnicu Vilcea -> Pitesti -> Bucharest -> Giurgiu -> Budapest with a
total distance of 750 km.
2. Design and explain the A* Best-First Search algorithm to find the best path
from Arad to Bucharest. Consider the provided map and heuristic values from the
previous question.
Answer:
Algorithm Steps:
1. Initialization:
- Initialize an open list (priority queue) with the starting node (Arad) and set its
cost to reach as 0.
- Initialize a dictionary to store the parent node of each node to reconstruct the path
later.
- Dequeue the node with the lowest total cost (cost to reach the node + heuristic
value) from the open list.
- If the dequeued node is the goal node (Bucharest), stop the search and reconstruct
the path.
- Otherwise, expand the dequeued node:
- Calculate the cost to reach the adjacent node from the current node.
- Calculate the total cost (cost to reach the adjacent node + heuristic value of
the adjacent node).
- If the adjacent node is not in the open list or closed list, add it to the open list
with the calculated total cost.
- If the adjacent node is already in the open list but the new total cost is lower,
update its cost and parent.
3. Path Reconstruction:
- If a path from the start node to the goal node was found:
- Start from the goal node and traverse through the parent dictionary to
reconstruct the path.
- Arad: 366 km
- Zerind: 374 km
- Oradea: 380 km
- Sibiu: 253 km
- Fagaras: 178 km
- Pitesti: 98 km
- Bucharest: 0 km
The best path from Arad to Bucharest using the A* Best-First Search algorithm
is: Arad -> Timisoara -> Lugoj -> Mehadia -> Drobeta -> Craiova -> Pitesti ->
Bucharest with a total distance of 738 km.
3. Apply Greedy Best-First Search and A* algorithms to find the optimal path
from node S to node G in the provided graph. Use the given heuristic values for
each node.
Graph:
```
/\
B C
/ \
S D
\ /
E G
\/
```
Heuristic Values:
- H(S) = 7
- H(A) = 6
- H(B) = 2
- H(C) = 4
- H(D) = 3
- H(E) = 5
- H(F) = 4
- H(G) = 0
Let's apply both the Greedy Best-First Search and A* algorithms to find the optimal
path from S to G.
Algorithm Steps:
1. Initialization:
- Dequeue the node with the lowest heuristic value from the open list.
- If the dequeued node is the goal node (G), stop the search.
- If the adjacent node is not in the open or closed list, add it to the open list
with its heuristic value.
- Dequeue: S (7)
- Expand: E (5)
- Enqueue: E (5)
- Dequeue: E (5)
- Expand: F (4)
- Enqueue: F (4)
- Dequeue: F (4)
- Expand: G (0)
- Goal Reached!
Optimal Path:
A* Algorithm:
Algorithm Steps:
1. Initialization:
- Open List: [(S, 7 + 7)] (priority queue)
- Closed List: []
- S: 0
- A: Infinity
- B: Infinity
- C: Infinity
- D: Infinity
- E: Infinity
- F: Infinity
- G: Infinity
- Dequeue the node with the lowest total cost from the open list.
- If the dequeued node is the goal node (G), stop the search.
- Calculate the cost to reach the adjacent node from the current node.
- Calculate the total cost (cost to reach + heuristic value of the adjacent node).
- If the adjacent node is not in the open list or closed list, add it to the open list
with the calculated total cost.
- If the adjacent node is already in the open list but the new total cost is lower,
update its cost.
A* Algorithm Execution:
- Dequeue: S (14)
- Dequeue: B (9)
- Expand: E (14)
- Enqueue: E (14)
- Dequeue: A (13)
- Dequeue: D (10)
- Expand: F (10)
- Enqueue: F (10)
- Dequeue: C (11)
- Expand: G (11)
- Goal Reached!
Optimal Path:
A* Optimal Path: