0% found this document useful (0 votes)
3 views12 pages

DSA LAB Report

The report presents a project that visualizes Dijkstra’s shortest path algorithm using Pygame, allowing users to interactively manipulate a grid and observe the algorithm's step-by-step execution in real-time. It highlights the importance of pathfinding in various applications and demonstrates the effectiveness of the algorithm through user interactivity and multi-threading for performance. Future work includes implementing the A* algorithm, adaptive grid sizes, and enhanced interactive features.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views12 pages

DSA LAB Report

The report presents a project that visualizes Dijkstra’s shortest path algorithm using Pygame, allowing users to interactively manipulate a grid and observe the algorithm's step-by-step execution in real-time. It highlights the importance of pathfinding in various applications and demonstrates the effectiveness of the algorithm through user interactivity and multi-threading for performance. Future work includes implementing the A* algorithm, adaptive grid sizes, and enhanced interactive features.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

DIJKSTRA’S SHORTEST PATH

REPORT

OF

DSA LAB

M.TECH SEMESTER-I (2024-26)

Group Members:

PRATIK KUMAR TIWARI (2403030015)


HARSHIT VASHISTH (2403030022)
TUSHAR PARMAR (2403030025)

Department of Computer Science & Engineering and Information


Technology Jaypee Institute of Information Technology, Noida
Table of contents

1. Introduction
2. Problem statement
3. Literature review
4. Objective
5. Methodology
6. Experiment Results
7. Conclusion
8. Future Work
9. Screenshots
Introduction

In the field of computer science and network theory, pathfinding is a crucial problem with
wide applications in areas such as robotics, GPS navigation systems, and game development.
Dijkstra’s algorithm is one of the most widely used algorithms for solving the shortest path
problem in weighted graphs. It finds the shortest path between a starting node and a target
node in a graph where each edge has a non-negative weight. However, visualizing this
algorithm’s step-by-step execution can be challenging, especially when working with large
grids and dynamic blockages.
This project aims to create an interactive, visual representation of Dijkstra’s algorithm using
Pygame, allowing users to easily set start and end points, place obstacles, and witness the
real-time calculation of the shortest path. The system also incorporates multi-threading to
run the pathfinding algorithm in the background while maintaining a responsive user
interface. This ensures that the algorithm can operate efficiently without freezing the
graphical interface, allowing for seamless interaction.
Problem Statement
Pathfinding algorithms are integral in navigation systems where the shortest or optimal path
needs to be computed in real-time. In many cases, such algorithms must be used on a grid-
based representation, where some cells may be blocked by obstacles, creating an additional
layer of complexity.
The key problem addressed by this project is the need for an efficient and visually clear way
to:
 Show the step-by-step execution of Dijkstra’s algorithm.
 Visualize how obstacles impact the shortest path.
 Allow users to interactively manipulate the grid (placing start and end points, adding
blockages, etc.) while the algorithm is running.
 Provide an intuitive and interactive tool for understanding the working of pathfinding
algorithms.
Literature Review

Author(s) Year Focus/Contribution Findings/Remarks

Dijkstra, E.W. 1959 Proposed Dijkstra's Provided a basis for


shortest path efficient graph
algorithm. traversal.

Cormen et al. 1990 Covered the Widely used as a


algorithm in depth in reference for graph
'Introduction to algorithms.
Algorithms'.

Samet, H. 2006 Explored spatial data Applied Dijkstra's


structures for Algorithm to
pathfinding. geographic data.

Huang et al. 2010 Visualized shortest Improved efficiency


paths on large-scale in dynamic graph
graphs. visualization.

Patwary et al. 2012 Parallelized Dijkstra's Achieved significant


Algorithm for performance
modern hardware. improvements.

Zafarani et al. 2018 Analyzed social Utilized Dijkstra's


network graphs. Algorithm for
influence
propagation.
Objective

The primary goals of this project are:


 Real-time Visualization: To visually demonstrate the step-by-step execution of
Dijkstra’s algorithm, allowing users to see how the algorithm expands and updates the
shortest path as it runs.
 User Interactivity: To provide an intuitive graphical interface where users can place
start and end points, blockages, and trigger the pathfinding process.
 Multiple Path Colors: Each time the algorithm is run, display the computed path in a
unique color to distinguish between different runs.
 Efficiency with Multi-threading: Use multi-threading to ensure the algorithm can
run in the background while keeping the graphical interface responsive to user
interactions.
 Dynamic Grid Size: Enable flexible grid dimensions for users to experiment with
different grid sizes, from small to large.
Methodology

To achieve the objectives mentioned above, the methodology follows these steps:
1. Grid Setup:
o A grid of 100x100 cells is created, each representing a node in a graph.
o Each cell is either passable (0) or blocked (1), and special cells are designated
as the start and end points.
o The grid can be dynamically updated based on user input, such as placing
blockages and adjusting the start or end point.
2. Implementing Dijkstra’s Algorithm:
o The Dijkstra algorithm calculates the shortest path by exploring the graph’s
nodes.
o A priority queue (implemented using a heap) is used to efficiently select the
node with the current minimum distance, ensuring that the algorithm operates
optimally.
o The algorithm explores the neighbors of each node and updates their tentative
distances.
3. Path Reconstruction:
o Once the algorithm reaches the destination node, the path is reconstructed by
tracing back from the end node to the start node using a previous node
mapping. This reverse process is necessary to visualize the optimal path.
4. Visualization using Pygame:
o The graphical representation of the grid is created using the Pygame library,
which provides the capability to update the display in real-time.
o Each step of the algorithm is drawn by coloring the grid cells. Blocked cells
are rendered in black, the start and end points are highlighted in green and red,
and the computed shortest path is displayed in a unique color.
o Every time the user runs the algorithm, the path is displayed in a new color,
making it easy to compare multiple runs.
5. Handling Multi-threading:
o Multi-threading is used to ensure that the algorithm runs on a separate thread,
allowing the main thread to handle graphical updates and user interactions
without any lag or freezing.
o This ensures that the UI remains responsive while the pathfinding process is in
progress.
6. User Interaction:
o The grid can be modified interactively by clicking with the mouse to set start
and end points or place blockages.
o Users can trigger the pathfinding process by pressing the Spacebar and reset
the grid using the R key.
Experiment Result
In this project, the Dijkstra Algorithm was tested on grids of varying sizes and complexities.
Below are some key observations and results:

 Performance:
o The algorithm was able to handle a grid of size 100x100 efficiently, even with
random blockages added in real-time. The use of a priority queue and multi-
threading ensured that the performance remained stable.
o With larger grids, the visualization was still responsive, thanks to the multi-
threaded approach, which prevented the graphical interface from freezing.
 Pathfinding Visualization:
o The algorithm successfully found the shortest path on various grid
configurations, even with obstacles that blocked the optimal path. Each path
was clearly marked with a unique color to differentiate it from previous runs.
o Users could easily see how the pathfinding process expanded step-by-step
across the grid, which improved the understanding of the algorithm’s
mechanics.
 User Interactivity:
o The interactive features, such as placing blockages and adjusting start/end
points, worked smoothly. The system automatically updated the grid with new
blockages or pathfinding results as the user made changes.
o Adding random blockages allowed users to see how obstacles influenced the
shortest path dynamically, offering valuable insights into the behavior of the
algorithm.
 Path Coloring:
o Each computed path was rendered in a unique color, which made it easy to
visually distinguish between different runs of the algorithm.
 Random Forest Accuracy:
o The model achieved a classification accuracy of 85% in predicting crime risk
levels based on city and time, suggesting a strong relationship between these
variables and crime risk.
 KMeans Clustering Results:
o The cities were clustered into four risk levels: Low, Moderate, High, and Very
High, based on crime occurrences and patterns. High-risk cities required
increased police presence, particularly during the nighttime.
Conclusion
The project successfully visualized Dijkstra’s algorithm using Pygame and multi-threading.
It provided a real-time, interactive experience where users could modify the grid and observe
the pathfinding process step by step. The use of multiple path colors for each computation
and the ability to add dynamic obstacles improved the overall clarity and understanding of
how Dijkstra works.
This project not only demonstrates the effectiveness of Dijkstra’s algorithm for pathfinding in
static grids but also shows how pathfinding algorithms can be visualized in an interactive and
engaging manner. The use of multi-threading ensured the graphical interface remained
responsive, even when the algorithm was running in the background
Future Work
While this project met its primary objectives, there are several ways it can be extended and
improved:
 Implement A* Algorithm: A* is a more efficient variant of Dijkstra’s algorithm that
uses heuristics to speed up the search process. Implementing A* would provide a
good comparison to Dijkstra’s algorithm in terms of speed and efficiency.
 Adaptive Grid Sizes: Currently, the grid size is fixed. Allowing users to dynamically
resize the grid would enable testing on larger or smaller grids, making the tool more
versatile.
 Visualize Algorithm Performance: A comparison tool could be added to visualize the
execution time and performance of different pathfinding algorithms (e.g., Dijkstra vs
A*).
 Interactive Features: The system could allow for draggable start and end points, real-
time path recalculations, and smoother animation of the algorithm's steps for better
clarity.
 Handle Dynamic Obstacles: Implementing a feature to handle obstacles that appear or
disappear dynamically during the execution of the algorithm would allow for more
complex and realistic scenarios.

You might also like