100% found this document useful (1 vote)
2K views22 pages

CS23D017 Dsa Project

The document describes the design and implementation of a map navigation system using Dijkstra's algorithm. It outlines the key steps, including initializing a weighted graph to represent the map, initializing variables to track distances and paths, applying Dijkstra's algorithm to find the shortest path between points, handling user input, and printing the results. It provides details on representing the map as a graph, storing distances in an adjacency matrix, and implementing the core steps of Dijkstra's algorithm to iteratively find the optimal route.
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
100% found this document useful (1 vote)
2K views22 pages

CS23D017 Dsa Project

The document describes the design and implementation of a map navigation system using Dijkstra's algorithm. It outlines the key steps, including initializing a weighted graph to represent the map, initializing variables to track distances and paths, applying Dijkstra's algorithm to find the shortest path between points, handling user input, and printing the results. It provides details on representing the map as a graph, storing distances in an adjacency matrix, and implementing the core steps of Dijkstra's algorithm to iteratively find the optimal route.
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/ 22

PROJECT REPORT

On
“Map Navigator (Dijkstra’s Algorithm)”

Submitted By:
Sachin H. Rahangdale (CS23D017)

Guided By:
Dr. Ravindra N. Jogekar

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

S. B. JAIN INSTITUTE OF TECHNOLOGY


MANAGEMENT & RESEARCH, NAGPUR.
(An Autonomous Institute, Affiliated to RTMNU, Nagpur)

2023-2024
© S.B.J.I.T.M.R Nagpur 2023

i
S.B. JAIN INSTITUTE OF TECHNOLOGY MANAGEMENT &
RESEARCH, NAGPUR
(An Autonomous Institute, Affiliated to RTMNU, Nagpur)

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

SESSION 2023-2024

CERTIFICATE

This is to certify that the Project titled “Map Navigator (Dijkstra’s Algorithm)” is a bonafide
work of Sachin Rahangdale carried out for the partial fulfillment of course work of “Data
Structure & Algorithm”, 3rd Semester, Bachelor of Technology in Computer Science and
Engineering.

Dr. Ravindra N. Jogekar Dr. Mrudula Nimbarte


Associate Professor Head of Department
(Project Guide)

2
INDEX

CERTIFICATE

INDEX

LIST OF FIGURES

CHAPTER 1 INTRODUCTION

CHAPTER 2 METHODOLOGY

CHAPTER 3 TOOLS/PLATFORMS

CHAPTER 4 DESIGN & IMPLEMENTATION

4.1 ALGORITHM

4.2 FLOWCHART
4.3 MAP (GRAPH)
4.3 SOURCE CODE

CHAPTER 5 RESULT & DISCUSSION

5.1 OUTPUT

5.2 DISCUSSION

5.3 APPLICATION

CHAPTER 6 CONCLUSION

REFERENCES

7
LIST OF FIGURES

FIG. NO. TITLE OF FIGURE PAGE NO.

4.2.1 Flowchart

4.3.1 Map(Graph)

5.1.1 Output 1

5.1.2 Output 2

5.1.3 Output 3

5.1.4 Output 4

7
CHAPTER 1

INTRODUCTION

Dijkstra's Algorithm for Map Navigation

In the intricate landscape of map navigation, Dijkstra's algorithm emerges as a fundamental tool,
bearing the name of its visionary creator, Edsger W. Dijkstra. Esteemed for its proficiency in
determining the shortest path between two points on a graph, this algorithm finds application in
diverse scenarios, from urban exploration to intricate network routing. Its primary goal is to
minimize travel costs, making it an invaluable asset in the realm of efficient route planning.

The core of Dijkstra's algorithm lies in its graph representation, where locations are nodes and the
connections between them are edges. Each edge carries a weight, representing the cost or distance
between two locations. The initialization phase sets the foundation by assigning tentative distance
values to every node. Starting from the source node with a distance of 0, all other nodes are initially
marked with an infinite distance.

The algorithm's iterative exploration phase is where its power unfolds. It systematically selects
nodes with the smallest tentative distances, updating the distances of their neighbors by considering
the sum of the current distance and the edge weight. This meticulous process continues until the
destination node is reached, at which point the algorithm has successfully uncovered the shortest
path.

Dijkstra's algorithm boasts several advantages that contribute to its widespread use. It guarantees
optimality by maintaining a priority queue of nodes with the smallest tentative distances, ensuring
the reliability of the shortest path. Its versatility is evident in its applicability across various
domains, from GPS navigation systems guiding us through city streets to intricate network systems
determining the most efficient data routes. Moreover, the algorithm's implementation simplicity
renders it accessible for a broad range of applications.

However, it is essential to acknowledge certain considerations. Dijkstra's algorithm is designed for


graphs with non-negative edge weights, and its performance may falter in the presence of negative
weights. Additionally, in large-scale graphs, resource usage may impact its efficiency. Nevertheless,
with its simplicity, reliability, and versatility, Dijkstra's algorithm remains a cornerstone in the field
of map navigation, providing an optimal solution for those seeking the shortest path through the
complexity of interconnected nodes and edges.

2
CHAPTER 2
METHODOLOGY
Below is an outline of the various phases involved in managing a software project, from initiation to
closure, for the given codebase.

1. Define the Problem:

• Identify the scope of your map navigation system.


• Determine what features you want to include, such as displaying distances, providing
directions, handling user input, etc.

2. Choose Programming Language and Tools:

• Select a programming language that you are comfortable with. C, C++, Python, and Java are
common choices.
• Choose any additional tools or libraries you might need for graphical user interface (GUI), if
applicable.

3. Design the Data Structure:

• Represent the map as a graph where cities are nodes and roads are edges.
• Decide how to store city names and distances between cities.
• Choose appropriate data structures, such as arrays or matrices, to represent the graph.

4. Implement Dijkstra's Algorithm:

• Write functions or methods to implement Dijkstra's algorithm for finding the shortest path
between two cities.
• Handle input parameters like source city, destination city, and the graph itself.

5. Input Handling:

• Implement a user interface to take input from the user.


• Allow users to input source and destination cities.

6. Display Results:

• Print the distance and the path from the source to the destination.
• Display the path in a human-readable format, indicating each step of the journey.

7. Create a Graphical User Interface (Optional):

• If you want a graphical interface, consider using GUI libraries or tools to create a more user-
friendly application.
• Display the map and highlight the path.

7
8. Error Handling:

• Implement error handling for invalid inputs, such as non-existent cities or incorrect user
entries.

9. Testing:

• Test your program with various inputs to ensure that it produces accurate results.
• Handle edge cases and unexpected scenarios.

10. Documentation:

• Provide clear documentation for your code, explaining the structure, functions, and how to
use your map navigation system.

11. Refinement and Optimization:

• Optimize your code for efficiency if needed.


• Consider adding additional features, such as real-time updates, alternative routes, or
additional information about cities.

12. User Feedback:

• If possible, gather feedback from users and make improvements based on their suggestions.

13. Deployment:

• If applicable, package your application for deployment on the chosen platform (desktop,
web, mobile).

14. Future Enhancements:

• Consider future enhancements, such as integrating with external APIs for live traffic data,
incorporating additional map features, etc.

7
CHAPTER 3
TOOLS/PLATFORMS

3.1 SOFTWARE REQUIREMENT


a. CLIENT-SIDE TECHNOLOGY: C Language.

b. IDE / FRAMEWORK: Visual Studio, Dev C++

c. LIBRARIES: standard C library ‘stdio.h’, string C library ‘string.h’ c library limits.h

d. OPERATING SYSTEM: Windows 10, DOS.

3.2 HARDWEAR REQURMENT:


a. RAM:- Minimum 4GB.

b. Computer System:- Dual core processor.

c. Others:- Keyboard, Mouse, Hard Disk, etc.

7
CHAPTER 4
DESIGN & IMPLEMENTATION
4.1 ALGORITHM

1. Initialize Graph:

• Define a weighted, non-directional graph representing distances between cities using an


adjacency matrix.
• The graph should have the number of cities as vertices, and distances as edge weights.

2. Initialize Variables:

• Define arrays distance[], sptSet[], and parent[] to store distance, processed vertices, and
parent nodes, respectively.
• Set all distances to infinity, sptSet[] to false, and parent[] to -1.

3. Initialize Source Vertex:

• Set the distance to the source city as 0.

4. Dijkstra's Algorithm:

• Iterate through all vertices:


• Find the vertex with the minimum distance (u) from the set of vertices not yet processed.
• Mark u as processed (sptSet[u] = 1).
• Update the distance values of adjacent vertices of u.
• until all vertices are processed.

5. Print Solution:

• Print the shortest distance from the source to the destination city.
• Print the path from the source to the destination city.

6. Input Handling:

• Receive user input for the destination city.

7. Main Function:

• Define city names and the graph.


• Get user input for the destination city.
• Find the index of the destination city.
• Perform Dijkstra's algorithm with the given graph, source (SB_JAIN), and destination.

7
4.2 FLOWCHART

Fig 4.2.1 Flowchart

7
4.3 MAP(GRAPH)

Map(Graph) for which we were designing a navigation system:

Fig 4.3.1 Map(Graph)

7
4.4 SOURCE CODE

#include <stdio.h>
#include <limits.h>
#include <string.h>

#define NUM_CITIES 6
#define MAX_NAME_LENGTH 20

// Function to find the vertex with the minimum distance value


int minDistance(int distance[], int sptSet[]) {
int min = INT_MAX, min_index;

for (int v = 0; v < NUM_CITIES; v++) {


if (sptSet[v] == 0 && distance[v] <= min) {
min = distance[v];
min_index = v;
}
}

return min_index;
}

// Function to print the solution (distance and path)


void printSolution(int distance[], int parent[], int destination, char
cities[NUM_CITIES][MAX_NAME_LENGTH]) {
printf("Distance to destination: %d\n", distance[destination]);
printf("Path: ");

int path[NUM_CITIES];
int pathLength = 0;

// Construct the path in reverse order


for (int i = destination; i != -1; i = parent[i]) {
path[pathLength++] = i;
7
}

// Print the path in the desired format


for (int i = pathLength - 1; i >= 0; i--) {
printf("%s", cities[path[i]]);
if (i > 0) {
printf(" -> ");
}
}
printf("\n");
}

// Function to implement Dijkstra's algorithm


void dijkstra(int graph[NUM_CITIES][NUM_CITIES], int source, int destination, char
cities[NUM_CITIES][MAX_NAME_LENGTH]) {
int distance[NUM_CITIES]; // The output array distance[i] holds the shortest distance from
source to i
int sptSet[NUM_CITIES]; // sptSet[i] is true if vertex i is included in the shortest path tree or
the shortest distance from source to i is finalized
int parent[NUM_CITIES]; // parent[i] holds the previous node in the shortest path from source
to i

// Initialize all distances as INFINITE, sptSet[] as false, and parent[] as -1


for (int i = 0; i < NUM_CITIES; i++) {
distance[i] = INT_MAX;
sptSet[i] = 0;
parent[i] = -1;
}

// Distance from source to itself is always 0


distance[source] = 0;

// Find the shortest path for all vertices


for (int count = 0; count < NUM_CITIES - 1; count++) {
// Pick the minimum distance vertex from the set of vertices not yet processed.
7
int u = minDistance(distance, sptSet);

// Mark the picked vertex as processed


sptSet[u] = 1;

// Update distance value of the adjacent vertices of the picked vertex


for (int v = 0; v < NUM_CITIES; v++) {
if (!sptSet[v] && graph[u][v] && distance[u] != INT_MAX && distance[u] + graph[u][v] <
distance[v]) {
distance[v] = distance[u] + graph[u][v];
parent[v] = u;
}
}
}

// Print the solution


printSolution(distance, parent, destination, cities);
}

int main() {
char cities[NUM_CITIES][MAX_NAME_LENGTH] = {
"SB_JAIN", "Nagpur", "Gondia", "Pune", "Mumbai", "Wardha"
};

int graph[NUM_CITIES][NUM_CITIES] = {
// Adjacency matrix representing the distances between cities
// SB_JAIN Nagpur Gondia Pune Mumbai Wardha
{0, 268, 450, 142, 0, 0}, // SB_JAIN
{268, 0, 160, 0, 118, 146}, // Nagpur
{450, 160, 0, 600, 0, 0}, // Gondia
{142, 0, 600, 0, 0, 110}, // Pune
{0, 118, 0, 0, 0, 45}, // Mumbai
{0, 146, 0, 110, 40, 0} // Wardha
};

7
// Print the statement
printf("Enter your destination from SB_JAIN: ");

char destination[MAX_NAME_LENGTH];
scanf("%s", destination);

// Find the index of the destination city


int destinationIndex = -1;
for (int i = 0; i < NUM_CITIES; i++) {
if (strcmp(destination, cities[i]) == 0) {
destinationIndex = i;
break;
}
}

// Check if the destination is valid


if (destinationIndex == -1) {
printf("Invalid destination\n");
return 1;
}

// Perform Dijkstra's algorithm


dijkstra(graph, 0, destinationIndex, cities);

return 0;
}

7
CHAPTER 5
RESULT & DISCUSSION
5.1 OUTPUT

Fig 5.1.1 Output 1

Fig 5.1.2 Output 2

7
Fig 5.1.3 Output 3

Fig 5.1.4 Output 4

7
5.2 DISCUSSION

1. Algorithmic Efficiency:
The choice of Dijkstra's algorithm for pathfinding in our map navigation system proved to be
effective. The algorithm systematically explores the network, ensuring that the shortest paths from
the source to all other locations are identified. However, it's essential to note that Dijkstra's
algorithm may not perform optimally in scenarios with negative edge weights or large graphs.

2. User Interaction and Input Handling:


The user interface, designed for simplicity and ease of use, facilitates user interaction. The system
prompts users to input the destination city from SB_JAIN, making it accessible to a broad audience.
Additionally, implementing input validation ensures that the system handles user inputs
appropriately.

3. Graph Representation:
The map was represented as an adjacency matrix, offering a straightforward way to capture the
relationships between cities. While this representation suits our current needs, future iterations
might explore alternative representations, such as adjacency lists, especially for larger and more
complex maps.

4. Real-world Applications:
The successful implementation of Dijkstra's algorithm in our project highlights its real-world
applicability. The map navigation system can find practical use in scenarios such as daily
commuting, emergency response planning, and logistics, showcasing the versatility of the
algorithm.

5. Challenges and Solutions:


Throughout the project, we encountered challenges related to data validation, user input, and
ensuring the accuracy of the algorithm. Implementing robust input validation and carefully
considering edge cases helped address many of these challenges. Ongoing testing and user feedback
can further refine the system.

6. Scalability and Future Enhancements:


While our current implementation is suitable for a small number of cities, scalability could be a
concern for larger maps. Future enhancements might include optimizations for scalability, as well as
the integration of additional features such as real-time data, alternate routes, and dynamic
considerations like traffic.

8. Learning Outcomes:
The micro project served as an excellent learning opportunity. We gained insights into algorithmic
design, data representation, and user interface considerations. Challenges encountered during the
project provided valuable experiences that contribute to our growth as developers.

In conclusion, the successful implementation of Dijkstra's algorithm in our map navigator


project demonstrates its practicality in solving real-world problems. Ongoing iterations and
enhancements can further refine the system, making it even more effective and user-friendly.

7
5.3 APPLICATION

Dijkstra's algorithm for map navigation has numerous applications in real-world scenarios. Here are
some common applications:

1. GPS Navigation Systems:

Dijkstra's algorithm is widely used in GPS navigation systems to find the shortest
path between a starting point and a destination. It helps drivers to navigate efficiently
by considering the current road conditions and traffic.

2. Network Routing Protocols:

Dijkstra's algorithm is used in network routing protocols to find the shortest path for
data transmission between devices in computer networks. It ensures efficient data
flow through the network.

3. Telecommunications Networks:

Telecommunication companies use Dijkstra's algorithm to optimize the routing of


voice and data traffic between different nodes in their networks.

4. Public Transportation Planning:

For public transportation systems, such as buses or trains, Dijkstra's algorithm can be
applied to optimize routes, minimizing travel time and improving overall efficiency.

5. Logistics and Supply Chain Management:

Dijkstra's algorithm is used in logistics to optimize delivery routes, reducing


transportation costs and improving delivery time.

6. Robotics and Autonomous Vehicles:

In robotics and autonomous vehicles, Dijkstra's algorithm is employed for path


planning. Robots and vehicles can determine the most efficient path to reach their
destination while avoiding obstacles.

7. Urban Planning:

Urban planners use Dijkstra's algorithm to optimize traffic flow in cities. It helps in
designing efficient road networks and managing traffic congestion.

8. Emergency Response Planning:

During emergencies, such as natural disasters or accidents, Dijkstra's algorithm can


be applied to plan the quickest routes for emergency responders to reach affected
areas.

7
9. Resource Management in Cloud Computing:

Dijkstra's algorithm is used in cloud computing to optimize resource allocation and


data transfer between different nodes in a distributed system.

10. Pipeline and Utility Network Design:

In the design of utility networks, like gas pipelines or electrical grids, Dijkstra's
algorithm is used to determine the most cost-effective routes for connecting different
points.

In essence, any scenario where finding the shortest path between two points in a network is crucial
can benefit from the application of Dijkstra's algorithm. Its versatility makes it a fundamental tool in
various fields that involve optimizing routes and paths.

7
CHAPTER 6
CONCLUSION

In conclusion, the implementation of Dijkstra's algorithm in our map navigation project has proven
to be a valuable tool for finding the shortest paths between locations in a given network. Through
this project, we achieved the following:

1. Efficient Pathfinding:

Dijkstra's algorithm provided an efficient means of determining the shortest paths


between cities or locations in our map. This is crucial for optimizing navigation and
minimizing travel time.

2. User-Friendly Interface:

The user interface, designed to take input for source and destination cities, enhances
the usability of our map navigation system. Users can easily find the shortest path
and associated details by providing straightforward inputs.

3. Real-world Applications:

The application of Dijkstra's algorithm extends to various real-world scenarios,


including GPS navigation, network routing, logistics, and urban planning. Our
project demonstrates the adaptability and versatility of this algorithm across different
domains.

4. Graphical Representation:

While our project primarily focused on algorithmic functionality, future


enhancements could include graphical representations of the map and paths,
providing users with an intuitive visual experience.

5. Potential for Expansion:

The project lays the foundation for further enhancements and features. Integration
with real-time data, alternate path suggestions, and considerations for dynamic
factors like traffic could be explored to make the system more robust.

6. Challenges and Learning:

Throughout the project, we encountered challenges related to data representation,


input validation, and ensuring the accuracy of the algorithm. Addressing these
challenges provided valuable learning experiences, contributing to our understanding
of algorithmic design and implementation.

In conclusion, our map navigation project, powered by Dijkstra's algorithm, has successfully
demonstrated the effectiveness of this approach in solving real-world problems. The project serves
as a stepping stone for future developments in the realm of navigation systems and lays the
groundwork for further innovations in the field.

7
REFERENCE
[1] Book References :
MSBTE Data Structure Using C Book Tech Max Publication
[2] Link References :
https://www.wikipedia.org/
https://www.geeksforgeeks.org/dijkstras-shortest-path-algorithm-greedy-algo-7/
https://www.programiz.com/dsa/dijkstra-algorithm
https://www.freecodecamp.org/news/dijkstras-shortest-path-algorithm-visual-introduction/

You might also like