0% found this document useful (0 votes)
5 views8 pages

Coding Assignment-1 - Artificial Intelligence - G24ait2121

The document outlines two coding assignments focused on artificial intelligence, specifically simulating a warehouse environment using a Breadth-First Search (BFS) algorithm for package delivery and finding optimal meeting points between two cities using Greedy Best-First Search (GBFS) and A* algorithms. The warehouse simulation involves an 8x8 grid with obstacles, packages, and drop-off points, while the city meeting point project utilizes the Haversine formula for distance calculation and visualizes results on a map. A comparison of the two search algorithms highlights their efficiencies and best use cases, with A* being more reliable for optimal pathfinding.

Uploaded by

Lokender Sharma
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)
5 views8 pages

Coding Assignment-1 - Artificial Intelligence - G24ait2121

The document outlines two coding assignments focused on artificial intelligence, specifically simulating a warehouse environment using a Breadth-First Search (BFS) algorithm for package delivery and finding optimal meeting points between two cities using Greedy Best-First Search (GBFS) and A* algorithms. The warehouse simulation involves an 8x8 grid with obstacles, packages, and drop-off points, while the city meeting point project utilizes the Haversine formula for distance calculation and visualizes results on a map. A comparison of the two search algorithms highlights their efficiencies and best use cases, with A* being more reliable for optimal pathfinding.

Uploaded by

Lokender Sharma
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/ 8

Coding Assignment-1 :: Artificial Intelligence

Name – Lokender Sharma


Roll No- 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

The warehouse is structured as an 8x8 grid with the following elements:

• Warehouse Grid: Each cell in the grid is initialized as 0 (empty space).


• Agent (Assumed value 5): Starts at the position (0,0) and moves to pick up and
deliver packages.
• Packages (Assumed value 1): Randomly placed within the grid.
• Drop-off Points (Assumed value 2): Random locations where packages must be
delivered.
• Obstacles (Assumed value 7): Randomly placed elements that restrict movement.
BFS Approach
The BFS Algorithm is used to determine the shortest path from the agent’s position to the
package and then to the drop-off point.

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.

Package Delivery Process


The delivery process follows these steps:

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.

Results and Performance Evaluation


After executing the package delivery system, the following statistics were obtained:

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

• Each city is represented as a node containing:


o Name
o Latitude & Longitude
o Neighbors (cities within 100 km radius)
• A city’s distance to another is determined using the haversine function.
• Two friends start from different cities (assumed: Pune and Bengaluru).

Greedy Best-First Search (GBFS)

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

• The search starts with City A (Pune) and City B (Bengaluru).


• The algorithm iterates, finding the shortest path to a common meetup point.
• If a meetup city is found, the algorithm stops and returns the result.

Results and Performance


• Nodes Generated: The total number of nodes (cities) processed during execution.
• Visited Cities: A list of cities traversed in the search process.
• Meetup City: The final city where both individuals meet.
• Map Visualization: A folium-based interactive map highlights the explored cities
and the meetup location.

A Star Search Algorithm

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.

How A* Search Works

The A algorithm* is an advanced pathfinding method that combines:

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

The City Meetup Simulation

Setup

• Same as City Graph Representation.


• The algorithm finds the best meetup city by minimizing the total travel distance.

Steps in the Simulation

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?

A* search is better than Greedy Best-First Search because:

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

Results & Observations


• The algorithm successfully finds an optimal meetup city for the two friends.
• The paths taken are efficient, ensuring minimal travel distance.
• If no common meetup city is found, the algorithm reports that no valid path exists.

Conclusion

This implementation effectively demonstrates Greedy Best-First Search in a geographical


context. The results show how heuristic-driven approaches efficiently determine meeting
points between two locations.

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

You might also like