0% found this document useful (0 votes)
27 views14 pages

MODULE - 2-SIMP Problems: Map Information

The document describes applying greedy best-first search and A* algorithms to find optimal paths between nodes in graphs. It provides sample graphs and heuristic values, then shows the steps and results of running the algorithms on the graphs.

Uploaded by

prakashanand8848
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views14 pages

MODULE - 2-SIMP Problems: Map Information

The document describes applying greedy best-first search and A* algorithms to find optimal paths between nodes in graphs. It provides sample graphs and heuristic values, then shows the steps and results of running the algorithms on the graphs.

Uploaded by

prakashanand8848
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

MODULE -2-SIMP Problems

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:

- Cities: Arad, Zerind, Oradea, Sibiu, Fagaras, Rimnicu Vilcea, Pitesti,


Bucharest, Giurgiu, Timisoara, Lugoj, Mehadia, Drobeta, Craiova, Calarasi, and
Budapest.

- Roads with their respective distances:

- Arad to Zerind: 75 km

- Arad to Timisoara: 118 km


- Zerind to Oradea: 71 km

- Oradea to Sibiu: 151 km

- Sibiu to Fagaras: 99 km

- Sibiu to Rimnicu Vilcea: 80 km

- Fagaras to Bucharest: 211 km

- Rimnicu Vilcea to Pitesti: 97 km

- Pitesti to Bucharest: 101 km

- Bucharest to Giurgiu: 90 km

- Timisoara to Lugoj: 111 km

- Lugoj to Mehadia: 70 km

- Mehadia to Drobeta: 75 km

- Drobeta to Craiova: 120 km

- Craiova to Pitesti: 138 km

- Bucharest to Calarasi: 123 km

- Calarasi to Giurgiu: 45 km

- Giurgiu to Budapest: 242 km

Heuristic (Straight-Line Distance to Budapest):


- Arad: 366 km

- Zerind: 374 km

- Oradea: 380 km

- Sibiu: 253 km

- Fagaras: 178 km

- Rimnicu Vilcea: 193 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:

Path from Arad to Budapest:

- Arad -> Sibiu -> Rimnicu Vilcea -> Pitesti -> Bucharest -> Giurgiu -> Budapest

Total Distance:

- Arad to Sibiu: 140 km

- Sibiu to Rimnicu Vilcea: 80 km

- Rimnicu Vilcea to Pitesti: 97 km

- Pitesti to Bucharest: 101 km

- Bucharest to Giurgiu: 90 km

- Giurgiu to Budapest: 242 km

Total Distance = 140 km + 80 km + 97 km + 101 km + 90 km + 242 km = 750 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:

A* Best-First Search Algorithm

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 closed list to store visited nodes.

- Initialize a dictionary to store the parent node of each node to reconstruct the path
later.

2. While the open list is not empty:

- 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:

- For each adjacent 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.

- Add the dequeued node to the closed list.

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.

- Return the reconstructed path.

Heuristic Value (Straight-Line Distance to Bucharest):

- Arad: 366 km
- Zerind: 374 km

- Oradea: 380 km

- Sibiu: 253 km

- Fagaras: 178 km

- Rimnicu Vilcea: 193 km

- Pitesti: 98 km

- Bucharest: 0 km

Algorithm Execution and Result:

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.

Greedy Best-First Search Algorithm:

Algorithm Steps:

1. Initialization:

- Open List: [(S, 7)] (priority queue)


- Closed List: []

2. While the open list is not empty:

- Dequeue the node with the lowest heuristic value from the open list.

- If the dequeued node is the goal node (G), stop the search.

- Otherwise, expand the dequeued node:

- For each adjacent node:

- If the adjacent node is not in the open or closed list, add it to the open list
with its heuristic value.

- Add the dequeued node to the closed list.

Greedy Best-First Search Execution:

Open List: [(S, 7)]

- Dequeue: S (7)

- Expand: A (6), B (2)

- Enqueue: A (6), B (2)


- Dequeue: B (2)

- 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:

S -> B -> E -> F -> G

A* Algorithm:

Algorithm Steps:

1. Initialization:
- Open List: [(S, 7 + 7)] (priority queue)

- Closed List: []

- Cost from start to each node (G):

- S: 0

- A: Infinity

- B: Infinity

- C: Infinity

- D: Infinity

- E: Infinity

- F: Infinity

- G: Infinity

2. While the open list is not empty:

- Dequeue the node with the lowest total cost from the open list.

- If the dequeued node is the goal node (G), stop the search.

- Otherwise, expand the dequeued node:

- For each adjacent node:

- 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.

- Add the dequeued node to the closed list.

A* Algorithm Execution:

Open List: [(S, 14)]

- Dequeue: S (14)

- Expand: A (13), B (9)

- Enqueue: A (13), B (9)

- Dequeue: B (9)

- Expand: E (14)

- Enqueue: E (14)

- Dequeue: A (13)

- Expand: C (11), D (10)


- Enqueue: C (11), D (10)

- Dequeue: D (10)

- Expand: F (10)

- Enqueue: F (10)

- Dequeue: C (11)

- Expand: G (11)

- Goal Reached!

Optimal Path:

S -> B -> E -> A -> C -> G

Greedy Best-First Search Optimal Path:

S -> B -> E -> F -> G

A* Optimal Path:

S -> B -> E -> A -> C -> G

You might also like