Coding Assignment-1 - Artificial Intelligence - G24ait2121
Coding Assignment-1 - Artificial Intelligence - G24ait2121
Question 1:
Introduction
This project simulates a warehouse environment where an autonomous agent collects and
delivers packages using a shortest-path algorithm. The warehouse is represented as an
8x8 grid, where obstacles, packages, and drop-off points are strategically placed. The
agent uses the Breadth-First Search (BFS) algorithm to find the shortest path for package
collection and delivery.
Warehouse Environment
Implementation
1. The BFS function takes in a start position, goal position, and the grid.
2. It explores neighboring cells in four possible directions (up, down, left, right).
3. A queue is maintained to store the paths, and a set keeps track of visited positions
to prevent loops.
4. The function returns the shortest path from the start to the goal.
1. The agent moves from the starting position to the nearest package using BFS.
2. Once the package is picked up, the agent finds the shortest path to the respective
drop-off location.
3. Each successful delivery earns a reward of 10 points, while movement incurs a
cost of 1 per step.
Each package delivery is logged, displaying the path taken for both pickup and drop-off. If
an obstacle prevents successful delivery, an error message is displayed.
Question 2 :-
Introduction
Finding an optimal meeting point between two individuals in different cities is a real-world
challenge. This project implements a Greedy Best-First Search (GBFS) algorithm.
Algorithm Overview
Haversine Formula
The algorithm uses the Haversine formula to calculate the great-circle distance between
two cities using latitude and longitude. This formula provides accurate distance
measurements based on Earth’s curvature.
City Graph Representation
The algorithm explores the search space based on the closest estimated distance between
two friends' locations. The key steps include:
1. Initialize the Priority Queue: Cities are prioritized based on their direct distance.
2. Expand the Closest Node: At each step, the closest city to the goal is selected.
3. Track Visited Cities: Keeps a record of explored nodes.
4. Terminate at the Meetup City: The algorithm stops when both friends reach the
same city.
Implementation Details
Data Handling
• Cities and their longitude and latitude are loaded in a CSV file.
• State, City, Latitude and Longitude value are present in the CSV file.
• Each city is connected to other nearby cities (within 100 km) to form a network.
Search Execution
When we use the A (A-Star) Search Algorithm* instead to help two friends find the best
city to meet. This approach is useful in real-life applications like GPS navigation and
logistics planning.
• g(n): The actual distance traveled from the start to the current point.
• h(n): The estimated distance from the current point to the goal (heuristic).
• f(n) = g(n) + h(n): The total estimated cost of reaching the goal.
A* ensures that the path chosen is the shortest possible by balancing the real travel cost
and the estimated remaining distance.
Setup
1. Create a graph where cities are nodes, and edges represent distances between
them.
2. Use A Search* to find the shortest paths for both friends.
3. Display results including:
a. The paths each friend takes.
b. The common city where they meet.
c. A visual representation using Folium maps.
Why A* Search?
• Greedy Best-First Search only considers the estimated remaining distance (h(n)),
which can lead to inefficient paths.
• A considers both the actual travel cost and the estimated distance*, making it more
reliable for finding the best route.
Conclusion
The A * algorithm is a powerful and efficient way to find the best meeting point for two
travelers. By balancing real and estimated distances, it ensures an optimal path, making it
an excellent choice for applications like GPS systems, delivery planning, and logistics.
Performance Comparison
Criteria Greedy Best-First Search A Search*
Slower, but guarantees the shortest
Efficiency Faster, but not always optimal
path
Path Cost May take longer, inefficient routes Always finds the most efficient path
Memory
Uses less memory Uses more memory for cost tracking
Usage
Best Use When speed is more important than When accuracy is critical (e.g., GPS
Case accuracy systems)
A * Search Output
Greedy Best First Search:-